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