core.cpp
1 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
23 #include "core.h"
24 
25 #include "pluginmanager.h"
26 #include "editor.h"
27 #include "plugin.h"
28 
29 #include <ksettings/dialog.h>
30 #include <kplugininfo.h>
31 #include <tdeapplication.h>
32 #include <tdeconfig.h>
33 #include <ktrader.h>
34 #include <klibloader.h>
35 #include <kstdaction.h>
36 #include <tdelistbox.h>
37 #include <kiconloader.h>
38 #include <kstandarddirs.h>
39 #include <tdeshortcut.h>
40 #include <tdelocale.h>
41 #include <kstatusbar.h>
42 #include <kguiitem.h>
43 #include <tdepopupmenu.h>
44 #include <tdeshortcut.h>
45 #include <kcmultidialog.h>
46 #include <tdeaction.h>
47 #include <tdestdaccel.h>
48 #include <kdebug.h>
49 
50 #include <tqwidgetstack.h>
51 #include <tqhbox.h>
52 #include <tqwidget.h>
53 
54 using namespace Komposer;
55 
56 Core::Core( TQWidget *parent, const char *name )
57  : KomposerIface( "KomposerIface" ),
58  TDEMainWindow( parent, name ), m_currentEditor( 0 )
59 {
60  initWidgets();
61  initCore();
62  initConnections();
63  setInstance( new TDEInstance( "komposer" ) );
64 
65  createActions();
66  setXMLFile( "komposerui.rc" );
67 
68  createGUI( 0 );
69 
70  resize( 600, 400 ); // initial size
71  setAutoSaveSettings();
72 
73  loadSettings();
74 }
75 
76 Core::~Core()
77 {
78  saveSettings();
79 
80  //Prefs::self()->writeConfig();
81 }
82 
83 void
84 Core::addEditor( Komposer::Editor *editor )
85 {
86  if ( editor->widget() ) {
87  m_stack->addWidget( editor->widget() );
88  m_stack->raiseWidget( editor->widget() );
89  editor->widget()->show();
90  m_currentEditor = editor;
91  }
92 
93  // merge the editors GUI into the main window
94  //insertChildClient( editor );
95  guiFactory()->addClient( editor );
96 }
97 
98 void
99 Core::addPlugin( Komposer::Plugin *plugin )
100 {
101  //insertChildClient( plugin );
102  guiFactory()->addClient( plugin );
103 }
104 
105 void
106 Core::slotPluginLoaded( Plugin *plugin )
107 {
108  kdDebug() << "Plugin loaded "<<endl;
109 
110  Editor *editor = dynamic_cast<Editor*>( plugin );
111  if ( editor ) {
112  addEditor( editor );
113  } else {
114  addPlugin( plugin );
115  }
116 }
117 
118 void
119 Core::slotAllPluginsLoaded()
120 {
121  TQValueList<KPluginInfo*> plugins = m_pluginManager->availablePlugins();
122  kdDebug()<<"Number of available plugins is "<< plugins.count() <<endl;
123  for ( TQValueList<KPluginInfo*>::iterator it = plugins.begin(); it != plugins.end(); ++it ) {
124  KPluginInfo *i = ( *it );
125  kdDebug()<<"\tAvailable plugin "<< i->pluginName()
126  <<", comment = "<< i->comment() <<endl;
127  }
128 
129  if ( !m_stack->visibleWidget() ) {
130  m_pluginManager->loadPlugin( "komposer_defaulteditor", PluginManager::LoadAsync );
131  }
132 }
133 
134 #if 0
135 void
136 Core::slotActivePartChanged( KParts::Part *part )
137 {
138  if ( !part ) {
139  createGUI( 0 );
140  return;
141  }
142 
143  kdDebug() << "Part activated: " << part << " with stack id. "
144  << m_stack->id( part->widget() )<< endl;
145 
146  createGUI( part );
147 }
148 
149 void
150 Core::selectEditor( Komposer::Editor *editor )
151 {
152  if ( !editor )
153  return;
154 
155  KParts::Part *part = editor->part();
156 
157  editor->select();
158 
159  TQPtrList<KParts::Part> *partList = const_cast<TQPtrList<KParts::Part>*>(
160  m_partManager->parts() );
161  if ( partList->find( part ) == -1 )
162  addPart( part );
163 
164  m_partManager->setActivePart( part );
165  TQWidget *view = part->widget();
166  Q_ASSERT( view );
167 
168  kdDebug()<<"Raising view "<<view<<endl;
169  if ( view )
170  {
171  m_stack->raiseWidget( view );
172  view->show();
173  view->setFocus();
174  m_currentEditor = editor;
175  }
176 }
177 
178 void
179 Core::selectEditor( const TQString &editorName )
180 {
181 
182 }
183 #endif
184 
185 void
186 Core::loadSettings()
187 {
188  //kdDebug()<<"Trying to select "<< Prefs::self()->m_activeEditor <<endl;
189  //selectEditor( Prefs::self()->m_activeEditor );
190 
191  //m_activeEditors = Prefs::self()->m_activeEditors;
192 }
193 
194 void
195 Core::saveSettings()
196 {
197  //if ( m_currentEditor )
198  //Prefs::self()->m_activeEditor = m_currentEditor->identifier();
199 }
200 
201 void
202 Core::slotQuit()
203 {
204  kdDebug()<<"exit"<<endl;
205  m_pluginManager->shutdown();
206 }
207 
208 void
209 Core::slotPreferences()
210 {
211  if ( m_dlg == 0 )
212  m_dlg = new KSettings::Dialog( this );
213  m_dlg->show();
214 }
215 
216 void
217 Core::initWidgets()
218 {
219  statusBar()->show();
220  TQHBox *topWidget = new TQHBox( this );
221  setCentralWidget( topWidget );
222  m_stack = new TQWidgetStack( topWidget );
223 }
224 
225 void
226 Core::initCore()
227 {
228  m_pluginManager = new PluginManager( this );
229  connect( m_pluginManager, TQT_SIGNAL(pluginLoaded(Plugin*)),
230  TQT_SLOT(slotPluginLoaded(Plugin*)) );
231  connect( m_pluginManager, TQT_SIGNAL(allPluginsLoaded()),
232  TQT_SLOT(slotAllPluginsLoaded()) );
233 
234 
235  m_pluginManager->loadAllPlugins();
236  kdDebug()<<"Loading"<<endl;
237 }
238 
239 void
240 Core::initConnections()
241 {
242  connect( kapp, TQT_SIGNAL(shutDown()),
243  TQT_SLOT(slotQuit()) );
244 }
245 
246 void
247 Core::createActions()
248 {
249  KStdAction::close( this, TQT_SLOT(slotClose()), actionCollection() );
250 
251  (void) new TDEAction( i18n( "&Send" ), "mail-send", CTRL+Key_Return,
252  this, TQT_SLOT(slotSendNow()), actionCollection(),
253  "send_default" );
254 
255  (void) new TDEAction( i18n( "&Queue" ), "queue", 0,
256  this, TQT_SLOT(slotSendLater()),
257  actionCollection(), "send_alternative" );
258 
259  (void) new TDEAction( i18n( "Save in &Drafts Folder" ), "document-save", 0,
260  this, TQT_SLOT(slotSaveDraft()),
261  actionCollection(), "save_in_drafts" );
262  (void) new TDEAction( i18n( "&Insert File..." ), "document-open", 0,
263  this, TQT_SLOT(slotInsertFile()),
264  actionCollection(), "insert_file" );
265  (void) new TDEAction( i18n( "&Address Book" ), "contents",0,
266  this, TQT_SLOT(slotAddrBook()),
267  actionCollection(), "addressbook" );
268  (void) new TDEAction( i18n( "&New Composer" ), "mail-message-new",
269  TDEStdAccel::shortcut( TDEStdAccel::New ),
270  this, TQT_SLOT(slotNewComposer()),
271  actionCollection(), "new_composer" );
272 
273  (void) new TDEAction( i18n( "&Attach File..." ), "attach",
274  0, this, TQT_SLOT(slotAttachFile()),
275  actionCollection(), "attach_file" );
276 }
277 
278 void
279 Core::slotClose()
280 {
281  close( false );
282 }
283 
284 void
285 Core::slotSendNow()
286 {
287 
288 }
289 
290 void
291 Core::slotSendLater()
292 {
293 
294 }
295 
296 void
297 Core::slotSaveDraft()
298 {
299 
300 }
301 
302 void
303 Core::slotInsertFile()
304 {
305 
306 }
307 
308 void
309 Core::slotAddrBook()
310 {
311 
312 }
313 
314 void
315 Core::slotNewComposer()
316 {
317 
318 }
319 
320 void
321 Core::slotAttachFile()
322 {
323 
324 }
325 
326 void
327 Core::send( int how )
328 {
329 
330 }
331 
332 void
333 Core::addAttachment( const KURL &url, const TQString &comment )
334 {
335 
336 }
337 
338 void
339 Core::setBody( const TQString &body )
340 {
341  m_currentEditor->setText( body );
342 }
343 
344 void
345 Core::addAttachment( const TQString &name,
346  const TQCString &cte,
347  const TQByteArray &data,
348  const TQCString &type,
349  const TQCString &subType,
350  const TQCString &paramAttr,
351  const TQString &paramValue,
352  const TQCString &contDisp )
353 {
354 
355 }
356 
357 #include "core.moc"
DCOP interface for mail composer window.
Definition: komposerIface.h:36
attachment.h
Definition: attachment.h:29