summaryrefslogtreecommitdiffstats
path: root/kmail/kmkernel.h
blob: 0a3c4a9e7b612cf06d994307a1e454c12ceef86d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
// -*- mode: C++; c-file-style: "gnu" -*-

#ifndef _KMCONTROL
#define _KMCONTROL

#include <tqobject.h>
#include <tqstring.h>
#include <tqguardedptr.h>
#include <weaver.h>
#include <weaverlogger.h>

#include <tdeconfig.h>
#include <tdeversion.h>
#include <tdeimproxy.h>
#include <tdepimmacros.h>

#include "kmailIface.h"
#include "kmmsgbase.h"
#include "globalsettings.h"

#define kmkernel KMKernel::self()
#define kmconfig KMKernel::config()

namespace TDEIO {
  class Job;
}
namespace KWallet {
  class Wallet;
}

/** The KMail namespace contains classes used for KMail.
* This is to keep them out of the way from all the other
* un-namespaced classes in libs and the rest of PIM.
*/
namespace KMail {
  class MailServiceImpl;
  class UndoStack;
  class JobScheduler;
  class MessageSender;
  class AccountManager;
}
namespace KPIM { class ProgressDialog; }
using KMail::MailServiceImpl;
using KMail::AccountManager;
using KMail::UndoStack;
using KMail::JobScheduler;
using KPIM::ProgressDialog;
class KMMsgIndex;
class TQLabel;
class KMFolder;
class KMFolderMgr;
class KMFilterMgr;
class KMFilterActionDict;
class KMSender;
namespace KPIM {
  class Identity;
  class IdentityManager;
}
class KMKernel;
class TDEProcess;
class KProgressDialog;
class TDEInstance;
class TQTimer;
class KProgress;
class KPassivePopup;
class KMMainWin;
class TDEMainWindow;
class KMailICalIfaceImpl;
class KMReaderWin;
class KSystemTray;
class KMMainWidget;
class ConfigureDialog;

/**
 * @short Central point of coordination in KMail
 *
 * The KMKernel class represents the core of KMail, where the different parts
 * come together and are coordinated. It is currently also the class which exports
 * KMail's main DCOP interfaces. The kernel is responsible for creating various
 * (singleton) objects such as the UndoStack, the folder managers and filter
 * manager, etc.
 */
class KDE_EXPORT KMKernel : public TQObject, virtual public KMailIface
{
  Q_OBJECT
  

public:
  KMKernel (TQObject *parent=0, const char *name=0);
  ~KMKernel ();

  /** dcop callable stuff */

  void checkMail ();
  TQStringList accounts();
  void checkAccount (const TQString &account);
  /** returns id of composer if more are opened */
  int openComposer (const TQString &to, const TQString &cc, const TQString &bcc,
                    const TQString &subject, const TQString &body, int hidden,
                    const KURL &messageFile, const KURL::List &attachURLs,
                    const QCStringList &customHeaders);
  /** For backward compatibility */
  int openComposer (const TQString &to, const TQString &cc, const TQString &bcc,
                    const TQString &subject, const TQString &body, int hidden,
                    const KURL &messageFile, const KURL::List &attachURLs)
  {
    QCStringList noCustomHeaders;
    return openComposer(to, cc, bcc, subject, body, hidden, messageFile, attachURLs, noCustomHeaders);
  }
  /** For backward compatibility */
  int openComposer (const TQString &to, const TQString &cc, const TQString &bcc,
                    const TQString &subject, const TQString &body, int hidden,
                    const KURL &messageFile, const KURL& attachURL)
  {
    return openComposer(to, cc, bcc, subject, body, hidden, messageFile, KURL::List(attachURL));
  }
  /** For backward compatibility */
  int openComposer (const TQString &to, const TQString &cc, const TQString &bcc,
                    const TQString &subject, const TQString &body, int hidden,
                    const KURL &messageFile)
  {
    return openComposer(to, cc, bcc, subject, body, hidden, messageFile, KURL::List());
  }
  /** For backward compatibility
   * @deprecated
   */
  int openComposer (const TQString &to, const TQString &cc,
                    const TQString &bcc, const TQString &subject,
                    const TQString &body, int hidden,
                    const TQString &attachName,
                    const TQCString &attachCte,
                    const TQCString &attachData,
                    const TQCString &attachType,
                    const TQCString &attachSubType,
                    const TQCString &attachParamAttr,
                    const TQString &attachParamValue,
                    const TQCString &attachContDisp);

  /** For backward compatibility
   * @deprecated
   */
  int openComposer (const TQString &to, const TQString &cc,
                    const TQString &bcc, const TQString &subject,
                    const TQString &body, int hidden,
                    const TQString &attachName,
                    const TQCString &attachCte,
                    const TQCString &attachData,
                    const TQCString &attachType,
                    const TQCString &attachSubType,
                    const TQCString &attachParamAttr,
                    const TQString &attachParamValue,
                    const TQCString &attachContDisp,
                    const TQCString &attachCharset);

  int openComposer (const TQString &to, const TQString &cc,
                    const TQString &bcc, const TQString &subject,
                    const TQString &body, int hidden,
                    const TQString &attachName,
                    const TQCString &attachCte,
                    const TQCString &attachData,
                    const TQCString &attachType,
                    const TQCString &attachSubType,
                    const TQCString &attachParamAttr,
                    const TQString &attachParamValue,
                    const TQCString &attachContDisp,
                    const TQCString &attachCharset,
                    unsigned int identity);

  DCOPRef openComposer(const TQString &to, const TQString &cc,
                       const TQString &bcc, const TQString &subject,
                       const TQString &body,bool hidden);

  /** DCOP call used to set the default transport. */

  void setDefaultTransport( const TQString & transport );

  /** DCOP call used by the Kontact plugin to create a new message. */
  DCOPRef newMessage(const TQString &to,
                     const TQString &cc,
                     const TQString &bcc,
                     bool hidden,
                     bool useFolderId,
                     const KURL &messageFile,
                     const KURL &attachURL);

  int sendCertificate( const TQString& to, const TQByteArray& certData );

  void openReader() { openReader( false ); }

  int dcopAddMessage(const TQString & foldername, const TQString & messagefile,
                     const TQString & MsgStatusFlags = TQString());
  int dcopAddMessage(const TQString & foldername, const KURL & messagefile,
                     const TQString & MsgStatusFlags = TQString());
  void dcopResetAddMessage();
  /** add messages without rejecting duplicates */
  int dcopAddMessage_fastImport(const TQString & foldername, const TQString & messagefile,
                                const TQString & MsgStatusFlags = TQString());
  int dcopAddMessage_fastImport(const TQString & foldername, const KURL & messagefile,
                                const TQString & MsgStatusFlags = TQString());
  void showImportArchiveDialog();

  TQStringList folderList() const;
  DCOPRef getFolder( const TQString& vpath );
  void selectFolder( TQString folder );
  int timeOfLastMessageCountChange() const;
  virtual bool showMail( TQ_UINT32 serialNumber, TQString messageId );
  virtual TQString getFrom( TQ_UINT32 serialNumber );
  virtual TQString debugScheduler();
  virtual TQString debugSernum( TQ_UINT32 serialNumber );
  int viewMessage( const KURL & messageFile );

  /**
   * Pauses all background jobs and does not
   * allow new background jobs to be started.
  */
  virtual void pauseBackgroundJobs();

  /**
   * Resumes all background jobs and allows
   * new jobs to be started.
  */
  virtual void resumeBackgroundJobs();

  /**
   * Stops all network related jobs and enter offline mode
   * New network jobs cannot be started.
  */
  void stopNetworkJobs();

  /**
   * Resumes all network related jobs and enter online mode
   * New network jobs can be started.
  */
  void resumeNetworkJobs();

  /** A static helper function that asks the user
   * if they want to go online.
   * @return true if the user wants to go online
   * @return false if the user wants to stay offline
   */
  static bool askToGoOnline();

  /** Checks if the current network state is online or offline
   * @return true if the network state is offline
   * @return false if the network state is online
   */
  static bool isOffline();

  /** normal control stuff */

  static KMKernel *self() { return mySelf; }
  static TDEConfig *config();

  void init();
  void readConfig();
  void cleanupImapFolders();
  void recreateCorruptIndexFiles();
  void testDir(const char *_name);
  void recoverDeadLetters();
  void initFolders(TDEConfig* cfg);
  void closeAllKMailWindows();
  void cleanup(void);
  void quit();
  /**
   * Returns true if the transfer was successful, otherwise false. In any case
   * destinationDir contains the path to the current mail storage when the
   * method returns.
   */
  bool transferMail( TQString & destinationDir );
  void ungrabPtrKb(void);
  void kmailMsgHandler(TQtMsgType aType, const char* aMsg);
  bool doSessionManagement();
  bool firstInstance() { return the_firstInstance; }
  void setFirstInstance(bool value) { the_firstInstance = value; }
  void action (bool mailto, bool check, const TQString &to, const TQString &cc,
               const TQString &bcc, const TQString &subj, const TQString &body,
               const KURL &messageFile, const KURL::List &attach,
               const QCStringList &customHeaders);
  void byteArrayToRemoteFile(const TQByteArray&, const KURL&,
			     bool overwrite = FALSE);
  bool folderIsDraftOrOutbox( const KMFolder * );
  bool folderIsDrafts( const KMFolder * );
  bool folderIsTemplates( const KMFolder * );
  bool folderIsTrash( KMFolder * );
  /**
   * Returns true if the folder is one of the sent-mail folders.
   */
  bool folderIsSentMailFolder( const KMFolder * );
  /**
   * Find a folder by ID string in all folder managers
   */
  KMFolder* findFolderById( const TQString& idString );

  TDEInstance *xmlGuiInstance() { return mXmlGuiInstance; }
  void setXmlGuiInstance( TDEInstance *instance ) { mXmlGuiInstance = instance; }

  KMFolder *inboxFolder() { return the_inboxFolder; }
  KMFolder *outboxFolder() { return the_outboxFolder; }
  KMFolder *sentFolder() { return the_sentFolder; }
  KMFolder *trashFolder() { return the_trashFolder; }
  KMFolder *draftsFolder() { return the_draftsFolder; }
  KMFolder *templatesFolder() { return the_templatesFolder; }

  KMFolderMgr *folderMgr() { return the_folderMgr; }
  KMFolderMgr *imapFolderMgr() { return the_imapFolderMgr; }
  KMFolderMgr *dimapFolderMgr() { return the_dimapFolderMgr; }
  KMFolderMgr *searchFolderMgr() { return the_searchFolderMgr; }
  UndoStack *undoStack() { return the_undoStack; }
  AccountManager *acctMgr() { return the_acctMgr; }
  KMFilterMgr *filterMgr() { return the_filterMgr; }
  KMFilterMgr *popFilterMgr() { return the_popFilterMgr; }
  KMFilterActionDict *filterActionDict() { return the_filterActionDict; }
  KMail::MessageSender *msgSender();
  KMMsgIndex *msgIndex();

  KPIM::ThreadWeaver::Weaver *weaver() { return the_weaver; }
  /** return the pointer to the identity manager */
  KPIM::IdentityManager *identityManager();

  JobScheduler* jobScheduler() { return mJobScheduler; }

  /** Compact all folders, used for the gui action (and from DCOP) */
  void compactAllFolders();
  /** Expire all folders, used for the gui action */
  void expireAllFoldersNow();

  KMailICalIfaceImpl& iCalIface();

  bool firstStart() { return the_firstStart; }
  TQString previousVersion() { return the_previousVersion; }
  bool startingUp() { return the_startingUp; }
  void setStartingUp (bool flag) { the_startingUp = flag; }
  bool shuttingDown() { return the_shuttingDown; }
  void setShuttingDown(bool flag) { the_shuttingDown = flag; }
  void serverReady (bool flag) { the_server_is_ready = flag; }

  /** Returns the full path of the user's local data directory for KMail.
      The path ends with '/'.
  */
  static TQString localDataPath();

  /** Returns true if we have a system tray applet. This is needed in order
   *  to know whether the application should be allowed to exit in case the
   *  last visible composer or separate message window is closed.
   */
  bool haveSystemTrayApplet();

  bool registerSystemTrayApplet( const KSystemTray* );
  bool unregisterSystemTrayApplet( const KSystemTray* );

  /// Reimplemented from KMailIface
  bool handleCommandLine( bool noArgsOpensReader );
  void emergencyExit( const TQString& reason );

  /** Returns a message serial number that hasn't been used yet. */
  unsigned long getNextMsgSerNum();
  TQTextCodec *networkCodec() { return netCodec; }

  /** returns a reference to the first Mainwin or a temporary Mainwin */
  TDEMainWindow* mainWin();

  // ### The mContextMenuShown flag is necessary to work around bug# 56693
  // ### (kmail freeze with the complete desktop while pinentry-qt appears)
  // ### FIXME: Once the encryption support is asynchron this can be removed
  // ### again.
  void setContextMenuShown( bool flag ) { mContextMenuShown = flag; }
  bool contextMenuShown() const { return mContextMenuShown; }

  /**
   * Get a reference to KMail's KIMProxy instance
   * @return a pointer to a valid KIMProxy
   */
  ::KIMProxy* imProxy();

  /**
   * Returns true IFF the user has requested that the current mail checks
   * should be aborted. Needs to be periodically polled.
   */
  bool mailCheckAborted() const;
  /**  Set the state of the abort requested variable to false,
   * i.e. enable mail checking again
   */
  void enableMailCheck();
  /**
   * Set the state of the abort requested variable to true,
   * (to let the current jobs run, but stop when possible).
   * This is used to cancel mail checks when closing the last mainwindow
   */
  void abortMailCheck();

  bool canQueryClose();

  /**
   * Called by the folder tree if the count of unread/total messages changed.
   */
  void messageCountChanged();

  /** Open KDE wallet and set it to kmail folder */
  KWallet::Wallet *wallet();

  /** Get first mainwidget */
  KMMainWidget *getKMMainWidget();

  /** @return a list of all folders from all folder managers. */
  TQValueList< TQGuardedPtr<KMFolder> > allFolders();

  void raise();

  void loadProfile( const TQString& path );

  void saveToProfile( const TQString& path ) const;

  bool isCodecAsciiCompatible( const TQTextCodec *codec );
public slots:

  /// Save contents of all open composer widnows to ~/dead.letter
  void dumpDeadLetters();

  /** Call this slot instead of directly TDEConfig::sync() to
      minimize the overall config writes. Calling this slot will
      schedule a sync of the application config file using a timer, so
      that many consecutive calls can be condensed into a single
      sync, which is more efficient. */
  void slotRequestConfigSync();

  /** empty all the trash bins */
  void slotEmptyTrash();

  void slotShowConfigurationDialog();
  void slotRunBackgroundTasks();

  void slotConfigChanged();

protected slots:
  void slotDataReq(TDEIO::Job*,TQByteArray&);
  void slotResult(TDEIO::Job*);

signals:
  void configChanged();
  void folderRemoved( KMFolder* aFolder );
  void onlineStatusChanged( GlobalSettings::EnumNetworkState::type );

private:
  void openReader( bool onlyCheck );
  KMMsgStatus strToStatus(const TQString &flags);
  KMFolder *currentFolder();

  KMFolder *the_inboxFolder;
  KMFolder *the_outboxFolder;
  KMFolder *the_sentFolder;
  KMFolder *the_trashFolder;
  KMFolder *the_draftsFolder;
  KMFolder *the_templatesFolder;

  KMFolderMgr *the_folderMgr;
  KMFolderMgr *the_imapFolderMgr;
  KMFolderMgr *the_dimapFolderMgr;
  KMFolderMgr *the_searchFolderMgr;
  UndoStack *the_undoStack;
  AccountManager *the_acctMgr;
  KMFilterMgr *the_filterMgr;
  KMFilterMgr *the_popFilterMgr;
  KMFilterActionDict *the_filterActionDict;
  mutable KPIM::IdentityManager *mIdentityManager;
  KMSender *the_msgSender;
  KMMsgIndex *the_msgIndex;
  struct putData
  {
    KURL url;
    TQByteArray data;
    int offset;
  };
  TQMap<TDEIO::Job *, putData> mPutJobs;
  /** previous KMail version. If different from current,
      the user has just updated. read from config */
  TQString the_previousVersion;
  /** is this the first start?  read from config */
  bool the_firstStart;
  /** are we starting up? set in main.cpp directly before kapp->exec() */
  bool the_startingUp;
  /** are we going down? set from here */
  bool the_shuttingDown;
  /** are we in the middle of network operations (needed?) */
  bool the_server_is_ready;
  /** true unles kmail is closed by session management */
  bool closed_by_user;
  bool the_firstInstance;
  bool mMailCheckAborted;
  static KMKernel *mySelf;
  TDESharedConfig::Ptr mConfig;
  TQTextCodec *netCodec;
  TDEInstance* mXmlGuiInstance;
  ConfigureDialog *mConfigureDialog;

  TQTimer *mBackgroundTasksTimer;
  KMailICalIfaceImpl* mICalIface;
  JobScheduler* mJobScheduler;
  // temporary mainwin
  KMMainWin *mWin;
  MailServiceImpl *mMailService;

  // the time of the last change of the unread or total count of a folder;
  // this can be queried via DCOP in order to determine whether the counts
  // need to be updated (e.g. in the Summary in Kontact)
  int mTimeOfLastMessageCountChange;

  // true if the context menu of KMFolderTree or KMHeaders is shown
  // this is necessary to know in order to prevent a dead lock between the
  // context menus and the pinentry program
  bool mContextMenuShown;

  TQValueList<const KSystemTray*> systemTrayApplets;
  TQValueList<const TQTextCodec*> mNonAsciiCompatibleCodecs;

  /* Weaver */
  KPIM::ThreadWeaver::Weaver *the_weaver;
  KPIM::ThreadWeaver::WeaverThreadLogger *the_weaverLogger;

  KWallet::Wallet *mWallet;

  // variables used by dcopAddMessage()
  TQStringList mAddMessageMsgIds;
  TQString     mAddMessageLastFolder;
  KMFolder    *mAddMsgCurrentFolder;
};

#endif