summaryrefslogtreecommitdiffstats
path: root/korn/accountmanager.h
blob: 5d0f3293606fb9e75f189fd8a89f17e1627535d3 (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
/*
 * Copyright (C) 2004, Mart Kelder (mart.kde@hccnet.nl)
 *
 * 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 MK_ACCOUNTMANAGER_H
#define MK_ACCOUNTMANAGER_H

#include <tqobject.h>

class DCOPDrop;
class KornSubjectsDlg;
class KKioDrop;
class KMailDrop;

class KConfig;

template< class T > class TQPtrList;
template< class T, class W > class TQMap;


/**
 * This class manage the different accounts.
 *
 * This class reads the config and makes the accounts,
 * and it communicate with the boxes.
 */
class AccountManager : public QObject
{ Q_OBJECT
public:
	/**
	 * Constructor, parameters are directed to TQObject.
	 */
	AccountManager( TQObject * parent = 0, const char * name = 0 );

	/**
	 * Destructor
	 */
	~AccountManager();
	
	/**
	 * This function is used to read the config.
	 *
	 * @param config The KConfig instance to the configuration
	 * @param index The index of the box. As there are different boxes,
	 * every box have it's own index. This number is used to get the
	 * right config-information out of the config parameter.
	 */
	virtual void readConfig( KConfig* config, const int index );

	/**
	 * This write the configuration into a file. Things that must be right is
	 * for example the reset number. The configuration isn't saved through this
	 * method; configurations are saved in the configurations classes.
	 *
	 * @param config The KConfig instance to which the configuration is written.
	 * @param index The index of the box.
	 */
	virtual void writeConfig( KConfig* config, const int index );
	
	/**
	 * This method makes a TQString which can be used for a tooltip.
	 * In it, all accounts are summed and the number of new messages of
	 * every account is added.
	 *
	 * @return A string that can be used for the Tooltip of the box.
	 */
	TQString getTooltip() const;
protected:
	/**
	 * This function is called when the number of emails has changed.
	 * Boxes must override this method and update the information.
	 *
	 * @param numberOfNewMessages The number of unread messages.
	 * @param newMessages Are there any new messages (important for displaying it)?
	 */
	virtual void setCount( int numberOfNewMessages, bool newMessages ) = 0;

	/**
	 * This functions sets a new Tooltip. Boxes must override this method
	 * @param tooltip The tooltip to be set.
	 */
	virtual void setTooltip( const TQString& tooltip ) = 0;

	/**
	 * This funtion is called if @p command have to be executed.
	 * For example, if new email has arrived, and the user setuped KOrn
	 * to execute a command. Boxes must override this function.
	 */
	virtual void runCommand( const TQString& command ) = 0;
	
	/**
	 * This function can be called by classes that inherit this class.
	 * If this function is called, all account which are part of this
	 * box are rechecked.
	 */
	void doRecheck();
	
	/**
	 * If this method is called, the number of new messages of all of its account
	 * is resetted.
	 */
	void doReset();

	/**
	 * If this function is called, a windows with shows the message headers will popup.
	 */
	void doView();

	/**
	 * These functions are called if the user wants to start or stop the account being triggered.
	 */
	void doStartTimer();
	void doStopTimer();
	
private:
	struct Dropinfo
	{
		int index;
		int msgnr;
		bool newMessages;
		int reset;
	};
	
	TQPtrList< KMailDrop > *_kioList;
	TQPtrList< DCOPDrop > *_dcopList;
	
	TQMap< KMailDrop*, Dropinfo* > *_dropInfo;
	
	static KornSubjectsDlg *_subjectsDlg;
	
private:
	int totalMessages();
	bool hasNewMessages();
	void playSound( const TQString& );
private slots:
	void slotChanged( int, KMailDrop* );
	void slotValidChanged( bool );
};

#endif //MK_ACCOUNTMANAGER_H