libkdepim Library API Documentation

core.cpp

00001 00022 #include "core.h" 00023 #include "editor.h" 00024 #include "prefs.h" 00025 00026 #include <kparts/partmanager.h> 00027 #include <kparts/part.h> 00028 #include <kparts/componentfactory.h> 00029 #include <kapplication.h> 00030 #include <kconfig.h> 00031 #include <ktrader.h> 00032 #include <klibloader.h> 00033 #include <kstdaction.h> 00034 #include <klistbox.h> 00035 #include <kiconloader.h> 00036 #include <kstandarddirs.h> 00037 #include <kshortcut.h> 00038 #include <kparts/componentfactory.h> 00039 #include <klocale.h> 00040 #include <kstatusbar.h> 00041 #include <kguiitem.h> 00042 #include <kpopupmenu.h> 00043 #include <kshortcut.h> 00044 #include <kcmultidialog.h> 00045 #include <kdebug.h> 00046 00047 #include <qwidgetstack.h> 00048 #include <qhbox.h> 00049 #include <qwidget.h> 00050 00051 using namespace Komposer; 00052 00053 Core::Core( QWidget *parent, const char *name ) 00054 : KParts::MainWindow( parent, name ), m_currentEditor( 0 ) 00055 { 00056 m_editors.setAutoDelete( true ); 00057 statusBar()->show(); 00058 00059 initWidgets(); 00060 00061 // prepare the part manager 00062 m_partManager = new KParts::PartManager( this ); 00063 connect( m_partManager, SIGNAL( activePartChanged( KParts::Part* ) ), 00064 this, SLOT( slotActivePartChanged( KParts::Part* ) ) ); 00065 00066 loadEditors(); 00067 00068 setXMLFile( "komposerui.rc" ); 00069 00070 createGUI( 0 ); 00071 00072 resize( 600, 400 ); // initial size 00073 setAutoSaveSettings(); 00074 00075 loadSettings(); 00076 } 00077 00078 Core::~Core() 00079 { 00080 saveSettings(); 00081 00082 QPtrList<KParts::Part> parts = *m_partManager->parts(); 00083 parts.setAutoDelete( true ); 00084 parts.clear(); 00085 00086 Prefs::self()->writeConfig(); 00087 } 00088 00089 void 00090 Core::loadEditors() 00091 { 00092 KTrader::OfferList offers = KTrader::self()->query( QString::fromLatin1( "Komposer/Editor" ), 00093 QString::fromLatin1("[X-KDE-KomposerEditorVersion] == 1")); 00094 00095 QPtrList<Editor> editors; 00096 00097 uint i; 00098 00099 kdDebug()<<"Offers = "<< offers.count() << endl; 00100 QStringList activeEditors = Prefs::self()->m_activeEditors; 00101 kdDebug()<<"Active editor " << activeEditors <<endl; 00102 for ( KTrader::OfferList::ConstIterator it = offers.begin(); it != offers.end(); ++it ) 00103 { 00104 kdDebug(5600) << "Loading Editor: " << (*it)->name() << endl; 00105 Komposer::Editor *editor = KParts::ComponentFactory 00106 ::createInstanceFromService<Komposer::Editor>( *it, this ); 00107 00108 if ( !editor ) { 00109 kdWarning()<<"Problem with " << (*it)->name() << endl; 00110 continue; 00111 } 00112 00113 QString identifier = (*it)->property( "X-KDE-KomposerIdentifier" ).toString(); 00114 kdDebug()<<"Identifier "<<identifier<<endl; 00115 if ( !activeEditors.contains( identifier ) ) 00116 continue; 00117 00118 editor->setIdentifier( identifier ); 00119 00120 for( i = 0; i < editors.count(); ++i ) { 00121 Editor *p = editors.at( i ); 00122 if ( editor->weight() < p->weight() ) break; 00123 } 00124 00125 editors.insert( i, editor ); 00126 } 00127 00128 for( i = 0; i < editors.count(); ++ i ) { 00129 Editor *editor = editors.at( i ); 00130 00131 addEditor( editor ); 00132 } 00133 } 00134 void 00135 Core::unloadEditors() 00136 { 00137 QPtrList<KParts::Part> parts = *m_partManager->parts(); 00138 parts.setAutoDelete( true ); 00139 parts.clear(); 00140 00141 for( uint i = 0; i < m_editors.count(); ++ i ) { 00142 Editor *editor = m_editors.at( i ); 00143 00144 removeChildClient( editor ); 00145 } 00146 00147 m_editors.clear(); 00148 } 00149 00150 void 00151 Core::addEditor( Komposer::Editor *editor ) 00152 { 00153 kdDebug(5600) << "Added editor" << endl; 00154 00155 m_editors.append( editor ); 00156 00157 // merge the editors GUI into the main window 00158 insertChildClient( editor ); 00159 } 00160 00161 void 00162 Core::addPart( KParts::Part* part ) 00163 { 00164 kdDebug()<<"Part = "<< part << " widget = "<< part->widget() <<endl; 00165 if ( part->widget() ) 00166 m_stack->addWidget( part->widget(), 0 ); 00167 00168 m_partManager->addPart( part, false ); 00169 } 00170 00171 void 00172 Core::slotActivePartChanged( KParts::Part* part ) 00173 { 00174 if ( !part ) { 00175 createGUI( 0 ); 00176 return; 00177 } 00178 00179 kdDebug() << "Part activated: " << part << " with stack id. " 00180 << m_stack->id( part->widget() )<< endl; 00181 00182 createGUI( part ); 00183 } 00184 00185 void 00186 Core::selectEditor( Komposer::Editor *editor ) 00187 { 00188 if ( !editor ) 00189 return; 00190 00191 KParts::Part *part = editor->part(); 00192 00193 editor->select(); 00194 00195 QPtrList<KParts::Part> *partList = const_cast<QPtrList<KParts::Part>*>( m_partManager->parts() ); 00196 if ( partList->find( part ) == -1 ) 00197 addPart( part ); 00198 00199 m_partManager->setActivePart( part ); 00200 QWidget *view = part->widget(); 00201 Q_ASSERT( view ); 00202 00203 kdDebug()<<"Raising view "<<view<<endl; 00204 if ( view ) 00205 { 00206 m_stack->raiseWidget( view ); 00207 view->show(); 00208 view->setFocus(); 00209 m_currentEditor = editor; 00210 } 00211 } 00212 00213 void 00214 Core::selectEditor( const QString &editorName ) 00215 { 00216 kdDebug()<<"Sectionee = "<< m_editors.count() <<endl; 00217 for ( Komposer::Editor *editor = m_editors.first(); editor; editor = m_editors.next() ) { 00218 kdDebug()<<"X " << editor->identifier() << " == " << editorName << endl; 00219 if ( editor->identifier() == editorName ) { 00220 selectEditor( editor ); 00221 return; 00222 } 00223 } 00224 } 00225 00226 void 00227 Core::loadSettings() 00228 { 00229 kdDebug()<<"Trying to select "<< Prefs::self()->m_activeEditor <<endl; 00230 selectEditor( Prefs::self()->m_activeEditor ); 00231 00232 //m_activeEditors = Prefs::self()->m_activeEditors; 00233 } 00234 00235 void 00236 Core::saveSettings() 00237 { 00238 if ( m_currentEditor ) 00239 Prefs::self()->m_activeEditor = m_currentEditor->identifier(); 00240 } 00241 00242 void 00243 Core::slotQuit() 00244 { 00245 close(); 00246 } 00247 00248 void 00249 Core::slotPreferences() 00250 { 00251 KCMultiDialog *dialog = new KCMultiDialog( this, "KomposerPreferences" ); 00252 connect( dialog, SIGNAL( applyClicked() ), SLOT( updateConfig() ) ); 00253 connect( dialog, SIGNAL( okClicked() ), SLOT( updateConfig() ) ); 00254 00255 QStringList modules; 00256 00257 modules.append( "PIM/komposerconfig.desktop" ); 00258 00259 // find all all modules for all editors 00260 QPtrListIterator<Komposer::Editor> pit( m_editors ); 00261 for( ; pit.current(); ++pit ) 00262 { 00263 QStringList tmp; 00264 //QStringList tmp = pit.current()->configModules(); 00265 if( !tmp.isEmpty() ) 00266 modules += tmp; 00267 } 00268 00269 // add them all 00270 QStringList::iterator mit; 00271 for ( mit = modules.begin(); mit != modules.end(); ++mit ) 00272 dialog->addModule( *mit ); 00273 00274 dialog->show(); 00275 dialog->raise(); 00276 } 00277 00278 KParts::ReadWritePart* 00279 Core::createPart( const char *libname ) 00280 { 00281 kdDebug() << "Core:createPart(): " << libname << endl; 00282 00283 QMap<QCString,KParts::ReadWritePart *>::ConstIterator it; 00284 00285 it = m_parts.find( libname ); 00286 00287 if ( it != m_parts.end() ) 00288 return it.data(); 00289 00290 kdDebug() << "Creating new KPart" << endl; 00291 00292 KParts::ReadWritePart *part = 00293 KParts::ComponentFactory:: 00294 createPartInstanceFromLibrary<KParts::ReadWritePart> 00295 ( libname, this, 0, this, "komposer" ); 00296 00297 if ( part ) 00298 m_parts.insert( libname, part ); 00299 00300 return part; 00301 } 00302 00303 void 00304 Core::initWidgets() 00305 { 00306 QHBox *topWidget = new QHBox( this ); 00307 setCentralWidget( topWidget ); 00308 m_stack = new QWidgetStack( topWidget ); 00309 } 00310 00311 #include "core.moc"
KDE Logo
This file is part of the documentation for libkdepim Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:57:46 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003