core.cpp
00001 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- 00023 #include "core.h" 00024 00025 #include "pluginmanager.h" 00026 #include "editor.h" 00027 #include "plugin.h" 00028 00029 #include <ksettings/dialog.h> 00030 #include <kplugininfo.h> 00031 #include <kapplication.h> 00032 #include <kconfig.h> 00033 #include <ktrader.h> 00034 #include <klibloader.h> 00035 #include <kstdaction.h> 00036 #include <klistbox.h> 00037 #include <kiconloader.h> 00038 #include <kstandarddirs.h> 00039 #include <kshortcut.h> 00040 #include <klocale.h> 00041 #include <kstatusbar.h> 00042 #include <kguiitem.h> 00043 #include <kpopupmenu.h> 00044 #include <kshortcut.h> 00045 #include <kcmultidialog.h> 00046 #include <kaction.h> 00047 #include <kstdaccel.h> 00048 #include <kdebug.h> 00049 00050 #include <tqwidgetstack.h> 00051 #include <tqhbox.h> 00052 #include <tqwidget.h> 00053 00054 using namespace Komposer; 00055 00056 Core::Core( TQWidget *parent, const char *name ) 00057 : KomposerIface( "KomposerIface" ), 00058 KMainWindow( parent, name ), m_currentEditor( 0 ) 00059 { 00060 initWidgets(); 00061 initCore(); 00062 initConnections(); 00063 setInstance( new KInstance( "komposer" ) ); 00064 00065 createActions(); 00066 setXMLFile( "komposerui.rc" ); 00067 00068 createGUI( 0 ); 00069 00070 resize( 600, 400 ); // initial size 00071 setAutoSaveSettings(); 00072 00073 loadSettings(); 00074 } 00075 00076 Core::~Core() 00077 { 00078 saveSettings(); 00079 00080 //Prefs::self()->writeConfig(); 00081 } 00082 00083 void 00084 Core::addEditor( Komposer::Editor *editor ) 00085 { 00086 if ( editor->widget() ) { 00087 m_stack->addWidget( editor->widget() ); 00088 m_stack->raiseWidget( editor->widget() ); 00089 editor->widget()->show(); 00090 m_currentEditor = editor; 00091 } 00092 00093 // merge the editors GUI into the main window 00094 //insertChildClient( editor ); 00095 guiFactory()->addClient( editor ); 00096 } 00097 00098 void 00099 Core::addPlugin( Komposer::Plugin *plugin ) 00100 { 00101 //insertChildClient( plugin ); 00102 guiFactory()->addClient( plugin ); 00103 } 00104 00105 void 00106 Core::slotPluginLoaded( Plugin *plugin ) 00107 { 00108 kdDebug() << "Plugin loaded "<<endl; 00109 00110 Editor *editor = dynamic_cast<Editor*>( plugin ); 00111 if ( editor ) { 00112 addEditor( editor ); 00113 } else { 00114 addPlugin( plugin ); 00115 } 00116 } 00117 00118 void 00119 Core::slotAllPluginsLoaded() 00120 { 00121 TQValueList<KPluginInfo*> plugins = m_pluginManager->availablePlugins(); 00122 kdDebug()<<"Number of available plugins is "<< plugins.count() <<endl; 00123 for ( TQValueList<KPluginInfo*>::iterator it = plugins.begin(); it != plugins.end(); ++it ) { 00124 KPluginInfo *i = ( *it ); 00125 kdDebug()<<"\tAvailable plugin "<< i->pluginName() 00126 <<", comment = "<< i->comment() <<endl; 00127 } 00128 00129 if ( !m_stack->visibleWidget() ) { 00130 m_pluginManager->loadPlugin( "komposer_defaulteditor", PluginManager::LoadAsync ); 00131 } 00132 } 00133 00134 #if 0 00135 void 00136 Core::slotActivePartChanged( KParts::Part *part ) 00137 { 00138 if ( !part ) { 00139 createGUI( 0 ); 00140 return; 00141 } 00142 00143 kdDebug() << "Part activated: " << part << " with stack id. " 00144 << m_stack->id( part->widget() )<< endl; 00145 00146 createGUI( part ); 00147 } 00148 00149 void 00150 Core::selectEditor( Komposer::Editor *editor ) 00151 { 00152 if ( !editor ) 00153 return; 00154 00155 KParts::Part *part = editor->part(); 00156 00157 editor->select(); 00158 00159 TQPtrList<KParts::Part> *partList = const_cast<TQPtrList<KParts::Part>*>( 00160 m_partManager->parts() ); 00161 if ( partList->find( part ) == -1 ) 00162 addPart( part ); 00163 00164 m_partManager->setActivePart( part ); 00165 TQWidget *view = part->widget(); 00166 Q_ASSERT( view ); 00167 00168 kdDebug()<<"Raising view "<<view<<endl; 00169 if ( view ) 00170 { 00171 m_stack->raiseWidget( view ); 00172 view->show(); 00173 view->setFocus(); 00174 m_currentEditor = editor; 00175 } 00176 } 00177 00178 void 00179 Core::selectEditor( const TQString &editorName ) 00180 { 00181 00182 } 00183 #endif 00184 00185 void 00186 Core::loadSettings() 00187 { 00188 //kdDebug()<<"Trying to select "<< Prefs::self()->m_activeEditor <<endl; 00189 //selectEditor( Prefs::self()->m_activeEditor ); 00190 00191 //m_activeEditors = Prefs::self()->m_activeEditors; 00192 } 00193 00194 void 00195 Core::saveSettings() 00196 { 00197 //if ( m_currentEditor ) 00198 //Prefs::self()->m_activeEditor = m_currentEditor->identifier(); 00199 } 00200 00201 void 00202 Core::slotQuit() 00203 { 00204 kdDebug()<<"exit"<<endl; 00205 m_pluginManager->shutdown(); 00206 } 00207 00208 void 00209 Core::slotPreferences() 00210 { 00211 if ( m_dlg == 0 ) 00212 m_dlg = new KSettings::Dialog( this ); 00213 m_dlg->show(); 00214 } 00215 00216 void 00217 Core::initWidgets() 00218 { 00219 statusBar()->show(); 00220 TQHBox *topWidget = new TQHBox( this ); 00221 setCentralWidget( topWidget ); 00222 m_stack = new TQWidgetStack( topWidget ); 00223 } 00224 00225 void 00226 Core::initCore() 00227 { 00228 m_pluginManager = new PluginManager( this ); 00229 connect( m_pluginManager, TQT_SIGNAL(pluginLoaded(Plugin*)), 00230 TQT_SLOT(slotPluginLoaded(Plugin*)) ); 00231 connect( m_pluginManager, TQT_SIGNAL(allPluginsLoaded()), 00232 TQT_SLOT(slotAllPluginsLoaded()) ); 00233 00234 00235 m_pluginManager->loadAllPlugins(); 00236 kdDebug()<<"Loading"<<endl; 00237 } 00238 00239 void 00240 Core::initConnections() 00241 { 00242 connect( kapp, TQT_SIGNAL(shutDown()), 00243 TQT_SLOT(slotQuit()) ); 00244 } 00245 00246 void 00247 Core::createActions() 00248 { 00249 KStdAction::close( this, TQT_SLOT(slotClose()), actionCollection() ); 00250 00251 (void) new KAction( i18n( "&Send" ), "mail_send", CTRL+Key_Return, 00252 this, TQT_SLOT(slotSendNow()), actionCollection(), 00253 "send_default" ); 00254 00255 (void) new KAction( i18n( "&Queue" ), "queue", 0, 00256 this, TQT_SLOT(slotSendLater()), 00257 actionCollection(), "send_alternative" ); 00258 00259 (void) new KAction( i18n( "Save in &Drafts Folder" ), "filesave", 0, 00260 this, TQT_SLOT(slotSaveDraft()), 00261 actionCollection(), "save_in_drafts" ); 00262 (void) new KAction( i18n( "&Insert File..." ), "fileopen", 0, 00263 this, TQT_SLOT(slotInsertFile()), 00264 actionCollection(), "insert_file" ); 00265 (void) new KAction( i18n( "&Address Book" ), "contents",0, 00266 this, TQT_SLOT(slotAddrBook()), 00267 actionCollection(), "addressbook" ); 00268 (void) new KAction( i18n( "&New Composer" ), "mail_new", 00269 KStdAccel::shortcut( KStdAccel::New ), 00270 this, TQT_SLOT(slotNewComposer()), 00271 actionCollection(), "new_composer" ); 00272 00273 (void) new KAction( i18n( "&Attach File..." ), "attach", 00274 0, this, TQT_SLOT(slotAttachFile()), 00275 actionCollection(), "attach_file" ); 00276 } 00277 00278 void 00279 Core::slotClose() 00280 { 00281 close( false ); 00282 } 00283 00284 void 00285 Core::slotSendNow() 00286 { 00287 00288 } 00289 00290 void 00291 Core::slotSendLater() 00292 { 00293 00294 } 00295 00296 void 00297 Core::slotSaveDraft() 00298 { 00299 00300 } 00301 00302 void 00303 Core::slotInsertFile() 00304 { 00305 00306 } 00307 00308 void 00309 Core::slotAddrBook() 00310 { 00311 00312 } 00313 00314 void 00315 Core::slotNewComposer() 00316 { 00317 00318 } 00319 00320 void 00321 Core::slotAttachFile() 00322 { 00323 00324 } 00325 00326 void 00327 Core::send( int how ) 00328 { 00329 00330 } 00331 00332 void 00333 Core::addAttachment( const KURL &url, const TQString &comment ) 00334 { 00335 00336 } 00337 00338 void 00339 Core::setBody( const TQString &body ) 00340 { 00341 m_currentEditor->setText( body ); 00342 } 00343 00344 void 00345 Core::addAttachment( const TQString &name, 00346 const TQCString &cte, 00347 const TQByteArray &data, 00348 const TQCString &type, 00349 const TQCString &subType, 00350 const TQCString ¶mAttr, 00351 const TQString ¶mValue, 00352 const TQCString &contDisp ) 00353 { 00354 00355 } 00356 00357 #include "core.moc"