diff --git a/kpdf/Makefile.am b/kpdf/Makefile.am index 067a73261..2cc8602e6 100644 --- a/kpdf/Makefile.am +++ b/kpdf/Makefile.am @@ -6,7 +6,7 @@ SUBDIRS = . INCLUDES = -I$(top_srcdir)/kpdf/goo -I$(top_srcdir)/kpdf/xpdf $(all_includes) # these are the headers for your project -noinst_HEADERS = kpdf.h kpdf_part.h +noinst_HEADERS = kpdf_shell.h kpdf_part.h kpdf_canvas.h kpdf_pagewidget.h # let automoc handle all of the meta source files (moc) METASOURCES = AUTO @@ -25,7 +25,7 @@ KDE_ICON = kpdf bin_PROGRAMS = kpdf # the application source, library search path, and link libraries -kpdf_SOURCES = main.cpp kpdf.cpp +kpdf_SOURCES = main.cpp kpdf_shell.cpp kpdf_LDFLAGS = $(KDE_RPATH) $(all_libraries) kpdf_LDADD = $(LIB_KPARTS) @@ -43,7 +43,7 @@ shellrc_DATA = kpdf_shell.rc kde_module_LTLIBRARIES = libkpdfpart.la # the Part's source, library search path, and link libraries -libkpdfpart_la_SOURCES = kpdf_part.cpp kpdf_pagewidget.cc +libkpdfpart_la_SOURCES = kpdf_canvas.cpp kpdf_part.cpp kpdf_pagewidget.cc libkpdfpart_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) libkpdfpart_la_LIBADD = ../xpdf/libxpdf.la $(LIB_KPARTS) $(LIB_KFILE) $(LIB_KDEPRINT) diff --git a/kpdf/kpdf_shell.cpp b/kpdf/kpdf_shell.cpp new file mode 100644 index 000000000..9430e1c6d --- /dev/null +++ b/kpdf/kpdf_shell.cpp @@ -0,0 +1,153 @@ +/* + * kpdf_shell.cpp + * + * Copyright (C) 2001 + */ +#include "kpdf_shell.h" +#include "kpdf_shell.moc" + +#include +#include +#include + +#include + +#include +#include + +#include +#include +#include + +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(); + + // and a status bar + statusBar()->show(); + + // 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 + KLibFactory *factory = KLibLoader::self()->factory("libkpdfpart"); + if (factory) + { + // now that the Part is loaded, we cast it to a Part to get + // our hands on it + m_part = static_cast( + 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() +{ + KStdAction::quit(kapp, SLOT(quit()), actionCollection()); + + m_toolbarAction = KStdAction::showToolbar(this, SLOT(optionsShowToolbar()), actionCollection()); + m_statusbarAction = KStdAction::showStatusbar(this, SLOT(optionsShowStatusbar()), actionCollection()); + + 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' +} + + void +Shell::optionsShowToolbar() +{ + // this is all very cut and paste code for showing/hiding the + // toolbar + if (m_toolbarAction->isChecked()) + toolBar()->show(); + else + toolBar()->hide(); +} + + void +Shell::optionsShowStatusbar() +{ + // this is all very cut and paste code for showing/hiding the + // statusbar + if (m_statusbarAction->isChecked()) + statusBar()->show(); + else + statusBar()->hide(); +} + + 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 diff --git a/kpdf/kpdf_shell.h b/kpdf/kpdf_shell.h new file mode 100644 index 000000000..0ddf04bbb --- /dev/null +++ b/kpdf/kpdf_shell.h @@ -0,0 +1,81 @@ +#ifndef _KPDF_SHELL_H_ +#define _KPDF_SHELL_H_ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +class KToggleAction; + +namespace KPDF +{ + + /** + * This is the application "Shell". It has a menubar, toolbar, and + * statusbar but relies on the "Part" to do all the real work. + * + * @short Application Shell + * @author Wilco Greven + * @version 0.1 + */ + class Shell : public KParts::MainWindow + { + Q_OBJECT + + public: + /** + * Default Constructor + */ + Shell(); + + /** + * Default Destructor + */ + virtual ~Shell(); + + /** + * Use this method to load whatever file/URL you have + */ + void load(const KURL& url); + + protected: + /** + * This method is called when it is time for the app to save its + * properties for session management purposes. + */ + void saveProperties(KConfig*); + + /** + * This method is called when this app is restored. The KConfig + * object points to the session management config file that was saved + * with @ref saveProperties + */ + void readProperties(KConfig*); + + private slots: + void optionsShowToolbar(); + void optionsShowStatusbar(); + void optionsConfigureKeys(); + void optionsConfigureToolbars(); + + void applyNewToolbarConfig(); + + private: + void setupAccel(); + void setupActions(); + + private: + KParts::ReadOnlyPart* m_part; + + KToggleAction* m_toolbarAction; + KToggleAction* m_statusbarAction; + }; + +} + +#endif + +// vim:ts=2:sw=2:tw=78:et diff --git a/kpdf/main.cpp b/kpdf/main.cpp index 366891486..198c26421 100644 --- a/kpdf/main.cpp +++ b/kpdf/main.cpp @@ -1,4 +1,4 @@ -#include "kpdf.h" +#include "kpdf_shell.h" #include #include #include @@ -25,7 +25,7 @@ int main(int argc, char** argv) // see if we are starting with session management if (app.isRestored()) - RESTORE(KPDF) + RESTORE(KPDF::Shell) else { // no session.. just start up normally @@ -33,14 +33,14 @@ int main(int argc, char** argv) if (args->count() == 0) { - KPDF* widget = new KPDF; + KPDF::Shell* widget = new KPDF::Shell; widget->show(); } else { for (int i = 0; i < args->count(); ++i) { - KPDF* widget = new KPDF; + KPDF::Shell* widget = new KPDF::Shell; widget->show(); widget->load(args->url(i)); }