keduca
keduca.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "keduca.h"
00019 #include "keduca.moc"
00020 #include "keduca_part.h"
00021 #include "../libkeduca/kgallerydialog.h"
00022
00023 #include <kapplication.h>
00024 #include <klocale.h>
00025 #include <kstandarddirs.h>
00026 #include <kfiledialog.h>
00027 #include <kdebug.h>
00028
00029 #include <kparts/componentfactory.h>
00030
00031 #include <qlabel.h>
00032
00033 Keduca::Keduca( QWidget* parent, const char *name, WFlags f )
00034 : KParts::MainWindow( parent, name, f ), _part( 0 )
00035 {
00036 setXMLFile( "keducaui.rc" );
00037
00038 _part = KParts::ComponentFactory::createPartInstanceFromLibrary< KParts::ReadOnlyPart >
00039 ( "libkeducapart", this, name, this, "KEducaPart" );
00040
00041 if ( _part )
00042 {
00043 setCentralWidget( _part->widget() );
00044
00045 setupActions();
00046
00047 configRead();
00048
00049 createGUI( _part );
00050 }
00051 else
00052 {
00053 kdFatal() << "The library \"libkeducapart\" could not be found. Aborting." << endl;
00054 }
00055 if (!initialGeometrySet())
00056 resize( QSize(550, 450).expandedTo(minimumSizeHint()));
00057 }
00058
00059 Keduca::~Keduca()
00060 {
00061 }
00062
00063
00064 void Keduca::setupActions()
00065 {
00066 KStdAction::open( this, SLOT( slotFileOpen() ), actionCollection() );
00067 (void)new KAction( i18n( "Open &Gallery..." ), 0, 0, this, SLOT( slotGallery() ),
00068 actionCollection(), "open_gallery" );
00069 _recentFiles = KStdAction::openRecent(this, SLOT ( slotFileOpenURL(const KURL &) ),
00070 actionCollection());
00071 KStdAction::quit(kapp, SLOT( quit() ), actionCollection());
00072 }
00073
00074 void Keduca::slotFileOpen()
00075 {
00076 KURL url = KFileDialog::getOpenURL( QString::null, "application/x-edu", this, i18n("Open Educa File") );
00077 if( !url.isEmpty() )
00078 slotFileOpenURL( url );
00079 }
00080
00081 void Keduca::slotFileOpenURL( const KURL &url )
00082 {
00083 if( !_part->openURL(url) ) return;
00084 _recentFiles->addURL( url );
00085 }
00086
00087
00088
00089
00090
00091
00092 bool Keduca::queryClose()
00093 {
00094 configWrite();
00095 return( TRUE );
00096 }
00097
00098 void Keduca::configRead()
00099 {
00100 KConfig *config = KGlobal::config();
00101 config->setGroup( "keduca" );
00102 applyMainWindowSettings( config, "keduca" );
00103 _recentFiles->loadEntries(config);
00104 }
00105
00106 void Keduca::configWrite()
00107 {
00108 KConfig *config = KGlobal::config();
00109
00110 config->setGroup( "keduca" );
00111 saveMainWindowSettings( config, "keduca" );
00112 _recentFiles->saveEntries(config);
00113 config->sync();
00114 }
00115
00116 void Keduca::slotGallery()
00117 {
00118 initGallery();
00119 }
00120
00121 void Keduca::initGallery(const KURL &urlFile)
00122 {
00123 KGalleryDialog galleries;
00124
00125 if( !urlFile.url().isEmpty() )
00126 galleries.putURL( urlFile );
00127
00128 if( galleries.exec() == QDialog::Accepted )
00129 slotFileOpenURL( galleries.getURL() );
00130 }