summaryrefslogtreecommitdiffstats
path: root/kmail/accountmanager.h
blob: 2fac30c366dc64800faa2c337ec04db530efe942 (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
/* -*- mode: C++ -*-
 * kmail: KDE mail client
 * Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */
#ifndef accountmanager_h
#define accountmanager_h

#include <tqobject.h>
#include "kmaccount.h"
#include <kdepimmacros.h>

class TQString;
class TQStringList;

namespace KMail {
/**
 * The account manager is responsible for creating accounts of various types
 * via the factory method create() and for keeping track of them.
 */
class KDE_EXPORT AccountManager: public TQObject
{
  Q_OBJECT
  TQ_OBJECT
  friend class ::KMAccount;

public:
    /** Initializes the account manager. readConfig() needs to be called in
     * order to fill it with persisted account information from the config file. */
  AccountManager();
  ~AccountManager();

  /** Completely reload accounts from config. */
  void readConfig(void);

  /** Write accounts to config. */
  void writeConfig( bool withSync=true );

  /** Create a new account of given type with given name. Currently
   the types "local" for local mail folders and "pop" are supported. */
  KMAccount* create( const TQString& type,
                             const TQString& name = TQString(),
                             uint id = 0);

  /** Adds an account to the list of accounts */
  void add( KMAccount *account );

  /** Find account by name. Returns 0 if account does not exist.
    Search is done case sensitive. */
  KMAccount* findByName( const TQString& name ) const;

  /** Find account by id. Returns 0 if account does not exist.
   */
  KMAccount* tqfind( const uint id ) const;

  /** Physically remove account. Also deletes the given account object !
      Returns FALSE and does nothing if the account cannot be removed. */
  bool remove( KMAccount* );

  /** First account of the list */
  const KMAccount* first() const { return first(); }
  KMAccount* first();

  /** Next account of the list */
  const KMAccount* next() const { return next(); }
  KMAccount* next();

  /** Processes all accounts looking for new mail */
  void checkMail( bool interactive = true );

  /** Delete all IMAP folders and resync them */
  void invalidateIMAPFolders();

  TQStringList getAccounts() const;

  /// Called on exit (KMMainWin::queryExit)
  void cancelMailCheck();

  /** Read passwords of all accounts from the wallet */
  void readPasswords();

public slots:
  void singleCheckMail( KMAccount *, bool interactive = true );
  void singleInvalidateIMAPFolders( KMAccount * );

  void intCheckMail( int, bool interactive = true );
  void processNextCheck( bool newMail );

  /** this slot increases the count of new mails to show a total number
  after checking in multiple accounts. */
  void addToTotalNewMailCount( const TQMap<TQString, int> & newInFolder );


signals:
  /**
   * Emitted if new mail has been collected.
   * @param newMail true if there was new mail
   * @param interactive true if the mail check was initiated by the user
   * @param newInFolder number of new messages for each folder
   **/
  void checkedMail( bool newMail, bool interactive,
                          const TQMap<TQString, int> & newInFolder );
  /** emitted when an account is removed */
  void accountRemoved( KMAccount* account );
  /** emitted when an account is added */
  void accountAdded( KMAccount* account );

private:
   /** Create a new unique ID */
  uint createId();

  AccountList   mAcctList;
  AccountList::Iterator mPtrListInterfaceProxyIterator;
  AccountList   mAcctChecking;
  AccountList   mAcctTodo;
  bool mNewMailArrived;
  bool mInteractive;
  int  mTotalNewMailsArrived;

  // for detailed (per folder) new mail notification
  TQMap<TQString, int> mTotalNewInFolder;

  // if a summary should be displayed
  bool mDisplaySummary;
};

} // namespace KMail
#endif /*accountmanager_h*/