kpdf_shell.cpp 3.59 KB
Newer Older
1 2 3 4 5 6 7 8
/*
 * kpdf_shell.cpp
 *
 * Copyright (C) 2001  <kurt@granroth.org>
 */
#include "kpdf_shell.h"
#include "kpdf_shell.moc"

Wilco Greven's avatar
Wilco Greven committed
9
#include <kaction.h>
10 11
#include <kconfig.h>
#include <kedittoolbar.h>
Wilco Greven's avatar
Wilco Greven committed
12 13
#include <kfiledialog.h>
#include <kkeydialog.h>
14 15 16
#include <klibloader.h>
#include <kmessagebox.h>
#include <kstatusbar.h>
Wilco Greven's avatar
Wilco Greven committed
17 18
#include <kstdaction.h>
#include <kurl.h>
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

using namespace KPDF;

Shell::Shell()
  : KParts::MainWindow(0, "KPDF::Shell")
{
  // set the shell's ui resource file
  setXMLFile("kpdf_shell.rc");

  // then, setup our actions
  setupActions();

  // this routine will find and load our Part.  it finds the Part by
  // name which is a bad idea usually.. but it's alright in this
  // case since our Part is made for this Shell
Chris Cheney's avatar
Chris Cheney committed
34
  KLibFactory *factory = KLibLoader::self()->factory("libkpdfpart");
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
  if (factory)
  {
    // now that the Part is loaded, we cast it to a Part to get
    // our hands on it
    m_part = static_cast<KParts::ReadOnlyPart*>(
                factory->create(this, "kpdf_part", "KParts::ReadOnlyPart"));

    if (m_part)
    {
      // tell the KParts::MainWindow that this is indeed the main widget
      setCentralWidget(m_part->widget());

      // and integrate the part's GUI with the shell's
      createGUI(m_part);
    }
  }
  else
  {
    // if we couldn't find our Part, we exit since the Shell by
    // itself can't do anything useful
    KMessageBox::error(this, "Could not find our Part!");
    kapp->quit();
    // we return here, cause kapp->quit() only means "exit the
    // next time we enter the event loop...
    return;
  }
}

Shell::~Shell()
{
}

  void
Shell::load(const KURL& url)
{
  m_part->openURL( url );
}

  void
Shell::setupActions()
{
Wilco Greven's avatar
Wilco Greven committed
76 77
  KStdAction::open(this, SLOT(fileOpen()), actionCollection());
  KStdAction::saveAs(this, SLOT(fileSaveAs()), actionCollection());
78 79
  KStdAction::quit(kapp, SLOT(quit()), actionCollection());

80 81
  createStandardStatusBarAction();
  setStandardToolBarMenuEnabled(true);
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103

  KStdAction::keyBindings(this, SLOT(optionsConfigureKeys()), actionCollection());
  KStdAction::configureToolbars(this, SLOT(optionsConfigureToolbars()), actionCollection());
}

  void
Shell::saveProperties(KConfig* /*config*/)
{
  // the 'config' object points to the session managed
  // config file.  anything you write here will be available
  // later when this app is restored
}

  void
Shell::readProperties(KConfig* /*config*/)
{
  // the 'config' object points to the session managed
  // config file.  this function is automatically called whenever
  // the app is being restored.  read in here whatever you wrote
  // in 'saveProperties'
}

Wilco Greven's avatar
Wilco Greven committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
  void
Shell::fileOpen()
{
  // this slot is called whenever the File->Open menu is selected,
  // the Open shortcut is pressed (usually CTRL+O) or the Open toolbar
  // button is clicked
  QString file_name = KFileDialog::getOpenFileName();

  if (file_name.isEmpty() == false)
    load(file_name);
}

  void
Shell::fileSaveAs()
{
    // this slot is called whenever the File->Save As menu is selected,
    /*
    QString file_name = KFileDialog::getSaveFileName();
    if (file_name.isEmpty() == false)
        saveAs(file_name);
    */
}

127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
  void
Shell::optionsConfigureKeys()
{
  KKeyDialog::configureKeys(actionCollection(), "kpdf_shell.rc");
}

  void
Shell::optionsConfigureToolbars()
{
  saveMainWindowSettings(KGlobal::config(), "MainWindow");

  // use the standard toolbar editor
  KEditToolbar dlg(factory());
  connect(&dlg, SIGNAL(newToolbarConfig()),
      this, SLOT(applyNewToolbarConfig()));
  dlg.exec();
}

  void
Shell::applyNewToolbarConfig()
{
  applyMainWindowSettings(KGlobal::config(), "MainWindow");
}

// vim:ts=2:sw=2:tw=78:et