summaryrefslogtreecommitdiffstats
path: root/kshowmail/configlist.h
blob: 158c66512cefb2c8b7c18244a5439c2a1434012f (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
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
/***************************************************************************
                          configlist.h  -  description
                             -------------------
    begin                : Tue May 9 2000
    copyright            : (C) 2000-2001 by Eggert Ehmke
                           (C) 2007 by Ulrich Weigelt
    email                : eggert.ehmke@berlin.de
                           ulrich.weigelt@gmx.de

    26 Sep 2002 - Allow for columns to be hidden. Allistar Melville
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef CONFIGLIST_H
#define CONFIGLIST_H

//TQt header
#include <ntqptrlist.h>
#include <ntqlistview.h>
#include <ntqobject.h>

//KDE headers
#include <kcombobox.h>
#include <kprocess.h>
#include <kdebug.h>

//KShowmail headers
#include "configelem.h"
#include "constants.h"
#include "kshowmailview.h"
#include "types.h"
#include "encryption.h"
#include "tdewalletaccess.h"
#include "filteritem.h"
#include "headerfilter.h"
#include "filterlog.h"

using namespace Constants;
using namespace Types;
using namespace Encryption;

class ConfigElem;
class KshowmailView;

/**
 * Contains the application and account settings. The account
 * settings are stored in ConfigElem objects.
 * @author Eggert Ehmke
 * @author Ulrich Weigelt
 */
class ConfigList : public TQObject, public TQPtrList<ConfigElem>
{

  Q_OBJECT

  public:

    /**
    * Constructor.
    */
    ConfigList ();

    /**
    * Destructor
    */
    virtual ~ConfigList () {};

    /**
     * Reads the setup from the configuration file (kshowmailrc) and
     * sets the properties.
     * @param view pointer to the account list view
     */
    void refreshSetup( TDEListView* view );

    /**
     * Reloads the filter settings
     */
    void refreshFilterSetup();

    /**
    * Returns the auto refresh time interval.
    * @return refresh time interval [minutes]
    */
    int getRefreshTimeInterval() const;

    /**
    * Sets the auto refresh time interval.
    * @param interval the new time interval [minutes]
    */
    void setRefreshTimeInterval( unsigned int interval );

    /**
    * Returns whether auto refresh is on.
    * @return TRUE - auto refresh is on; FALSE - auto refresh is off
    */
    bool AutoRefreshOn() const;

    /**
     * Sets whether the user has to confirm a deletion.
     * @param confirm TRUE - user has to confirm; FALSE - the user does not have to confirm
     */
    void setConfirmDeletion( bool confirm );

    /**
     * Returns whether the user has to confirm a deletion.
     * @return TRUE - the user has to confirm
     * @return FALSE - the user does not have to confirm
     */
    bool confirmDeletion();

    /**
     * Returns whether the user has to confirm window close.
     * @return TRUE - user has to confirm
     * @return FALSE - user does not have to confirm
     */
    bool confirmClose() const;

    /**
     * Returns whether the app shall start minimized.
     * @return TRUE - start minimized
     * @return FALSE - don't start minimized
     */
    bool startMinimized() const;

    /**
     * Returns whether the close button leaves the application running in tray.
     * @return TRUE - leaves running
     * @return FALSE - app will be closed
     */
    bool closeToTray() const;

    /**
     * Returns whether minimizes to the tray rather than to the taskbar.
     * @return TRUE - minimizes to the tray
     * @return FALSE - minimizes to the taskbar
     */
    bool minimizesToTray() const;

    /**
     * Returns whether connection errors will be shown during refresh.
     * @return TRUE - show errors
     * @return FALSE - don't show errors
     */
    bool showConnectionErrors() const;

    /**
     * Sets whether the mail show dialog has to use HTML.
     * @param allowHTML TRUE - the dialog has to use HTML; FALSE - the dialog must not use HTML
     * @see m_bAllowHTML
     * */
    void setAllowHTML( bool allowHTML );

    /**
     * Returns whether the mail show dialog has to use HTML.
     * @return TRUE - the dialog has to use HTML
     * @return FALSE - the dialog must not use HTML
     * @see m_bAllowHTML
     */
    bool allowHTML() const;

    /**
     * Returns whether there are active accounts.
     * Doesn't set the current account.
     * @return TRUE - Yes, there are active accounts (at least one :o) ); FALSE - no active accounts
     */
    bool hasActiveAccounts();

    /**
     * Returns the number of seconds the application will be wait for a pop3 job.
     * @return seconds to timeout
     */
    uint getTimeoutTime() const;

    /**
     * Sets the number of seconds the application will be wait for a pop3 job.
     * Minimum time is POP3_MINIMUM_TIMEOUT_TIME seconds.
     * @param time seconds to timeout
     * @see constants.h
     */
    void setTimeoutTime( uint time );

    /**
     * Returns the first account, for which an appropriate item is
     * selected in the account list view.
     * @return pointer to the selected account object
     * @return NULL - no account is selected
     */
    ConfigElem* getSelectedAccount();

    /**
     * Deletes all selected mails from the servers and the mail lists.
     * This just starts the deletion and returns after then. When all
     * accounts are ready the signal sigDeleteReady will be emitted.
     */
    void deleteSelectedMails();

    /**
     * Connects the signals of the accounts with the slots of this
     * class.
     * It is necessary to do this after an account has been appended to the
     * list and it is a good idea to call this method before you invoke
     * an operation on an account that may emit a signal.
     * The reason is that the pointer list seemingly often changes the
     * adresses of the inserted accounts. After that the connections are corrupt.
     */
    void connectAccounts();

    /**
     * Returns the subjects of the selected mails.
     * @return subjects of selected mails
     */
    TQStringList getSelectedSubjects() const;

    /**
     * Returns whether there are mails in this list which are selected
     * in the list view.
     * @return TRUE - there are selected mails
     * @return FALSE - there aren't selected mails
     */
    bool hasSelectedMails();

    /**
     * Downloads and shows the bodies of the selected mails.
     * This just starts the download and returns after then. When all
     * bodies are downloaded and shown the signal sigShowBodiesReady will be
     * emitted.
     */
    void showSelectedMails();

    /**
     * Refreshes the mail list of all accounts.
     * This just starts the refresh and returns after then. When all
     * accounts have refreshed their mail list the signal sigRefreshReady will be
     * emitted.
     * @param log Pointer to the filter log.
     */
    void refreshMailLists( FilterLog* log = NULL );

    /**
     * Returns the number of new mails.
     * @return number of new mails
     */
    int getNumberNewMails();

    /**
     * Returns the number of mails.
     * @return number of mails
     */
    int getNumberMails();

    /**
     * Returns the total size of all mails.
     * @return total size
     */
    long getTotalSize();

    /**
     * Creates for every mail a list view item and inserts it
     * into the mail list view.
     * @param view pointer to the application view
     */
    void fillMailListView( KshowmailView* view );

    /**
     * Returns whether the main window will be shown, if
     * new mails was received.
     * @return TRUE - main window will be shown
     * @return FALSE - main window will not be shown
     */
    bool showMainWindowForNewMails();

    /**
     * Returns whether an alert message will be shown if
     * new mails were received.
     * @return TRUE - will be shown
     * @return FALSE - will not be shown
     */
    bool showAlertMessageForNewMails();

    /**
     * Returns whether the app will be terminated if
     * no new mails were received.
     * @return TRUE - will be terminated
     * @return FALSE - will not be terminated
     */
    bool quitNoNewMails();

    /**
     * Returns whether the main window will be minimized, if
     * no new mails were received.
     * @return TRUE - main window will be minimized
     * @return FALSE - main window will not be minimized
     */
    bool minimizeMainWindowNoNewMails();

    /**
     * Returns the configured time to the first refresh.
     * @return time to the first refresh (seconds)
     */
    int getInitTime();

    /**
     * Sets the time to the first refresh.
     * @param time time (seconds) to the first refresh
     */
    void setInitTime( int time );

    /**
     * Returns whether a time to first refresh is configured.
     * @return TRUE - init time configured
     * @return FALSE - no init time configured
     */
    bool hasInitTime();

    /**
     * Refreshes the account list (number of mails and total size).
     */
    void refreshAccountList();

    /**
     * Kills all running pop3 jobs.
     */
    void killPOP3Jobs();

    /**
     * Shows the headers of all selected mails.
     */
    void showSelectedHeaders();

    /**
     * Executes the configure new mail command.
     * Does nothing, if the command option is switched off (m_bCommand == false).
     */
    void executeNewMailCommand();

    /**
     * Returns whether all new mails will keep new status until the app is closed.
     * @return TRUE - mails keep new status at next refresh
     * @return FALSE - mails don't keep new status at next refresh
     */
    bool keepNew();

    /**
     * Prints the setup.
     */
    void printSetup();

    /**
     * Saves the current mails data and the account setups.
     * The mails data will be saved into an XML file (kshowmail.xml).
     * The account setups will be saved into the application config file (kshowmailrc).
     */
    void saveOptions();

    /**
     * Reads stored mails data.
     * At every setup saving (e.g. at exit) the mails data will be stored into the file kshowmail.xml.
     * At application start we read this file to identify mails which are not new at first refresh.
     */
    void readStoredMails();

    /**
     * Returns the action to used on spam mails
     * @return action to used on spam mails
     */
     FilterAction_Type getSpamAction();

    /**
     * Returns the mailbox for spam mails
     * @return mailbox for spam
     */
     TQString getSpamMailbox();

    /**
      * Returns the number of deleted mails by last refresh.
      * @return number of deleted mails by last refresh
      */
     int numberDeletedMailsLastRefresh();

    /**
      * Returns the number of deleted mails since start.
      * @return number of deleted mails since start
      */
     int numberDeletedMailsStart();

    /**
      * Returns the number of moved mails by last refresh.
      * @return number of moved mails by last refresh
      */
     int numberMovedMailsLastRefresh();

    /**
      * Returns the number of moved mails since start.
      * @return number of moved mails since start
      */
     int numberMovedMailsStart();

    /**
      * Returns the number of ignored mails by last refresh.
      * @return number of ignored mails by last refresh
      */
     int numberIgnoredMails();

    /**
     * Returns the senders of the selected mails
     * @return senders of the selected mails
     */
     TQStringList getSelectedSenders() const;

	bool setItem (const char* item);
	void setList (TQListView* list);
	void beep ();
	void playSound ();
	void playSound (const char* file);


  private:

    /**
     * Connector to the configuration file
     */
    TDEConfig* config;

    /**
     * Time in minutes to the next automatic refresh.
     */
    int m_nIntervalTimer;

    /**
     * Number of seconds the application will wait for a pop3 job to complete.
     */
    uint m_nPop3Timer;

    /**
     * This map is used by the delete methods.
     * deleteSelectedMails() clears it and after that inserts for every account
     * an item. The Key is the account name and the data is TRUE.
     * When slotCheckDeletionState() is invoked by a signal sent by an account,
     * this slot will set the appropriate item data to FALSE. If the data of all
     * items are set to FALSE, the method will know all accounts have ended the
     * deletion and will emit sigDeleteReady.
     * @see deleteSelectedMails()
     * @see slotCheckDeletionState()
     */
    AccountTaskMap_Type AccountDeletionMap;

    /**
     * This map is used by the methods to show the mail body.
     * showSelectedMails() clears it and after that inserts for every account
     * an item. The Key is the account name and the data is TRUE.
     * When slotCheckShowBodiesState() is invoked by a signal sent by an account,
     * this slot will set the appropriate item data to FALSE. If the data of all
     * items are set to FALSE, the method will know all accounts have shown the
     * mail body and will emit sigShowBodiesReady.
     * @see showSelectedMails()
     * @see slotCheckShowBodiesState()
     */
    AccountTaskMap_Type AccountShowBodiesMap;

    /**
     * This map is used by the methods to refresh the account mail lists.
     * refreshMailLists() clears it and after that inserts for every account
     * an item. The Key ist the account name and the data is TRUE.
     * When slotCheckRefreshState() is invoked by a signal sent by an account,
     * this slot will set the appropriate item data to FALSE. If the data of all
     * items are set to FALSE, the method will know all accounts have refreshed their
     * mail list and will emit sigRefreshReady.
     * @see refreshMailLists()
     * @see slotCheckRefreshState()
     */
    AccountTaskMap_Type AccountRefreshMap;

    /**
     * TRUE - the user has to confirm a deletion,
     * FALSE - the user does not have to confirm a deletion
     */
    bool m_bConfirmDelete;

    /**
     * TRUE - allow HTML formatting in the mail show dialog box
     * FALSE - don't allow HTML formatting
     * @see setAllowHTML()
     * @see allowHTML()
     */
    bool m_bAllowHTML;

    /**
     * Number of windows, which have been opened by the accounts to show mails.
     * Used by slotMessageWindowOpened() and slotMessageWindowClosed().
     * @see slotMessageWindowOpened
     * @see slotMessageWindowClosed
     */
    int ctrOpenMessageWindows;

    /**
     * Contains the time (seconds) to first refresh.
     * @see setInitTime()
     * @see getInitTime()
     */
    int m_nInitTimer;

    /**
     * TRUE - If a new mail is arrived an alert window will be shown.
     */
    bool m_bShowMessage;

    /**
     * TRUE - If a new mail is arrived the main window will be shown.
     */
    bool m_bShowMainWindow;

    /**
     * TRUE - If a new mail is arrived the system will beep.
     */
    bool m_bBeep;

    /**
     * TRUE - If a new mail is arrived a sound will be played.
     */
    bool m_bSound;

    /**
     * Sound file which will be played if a new mail is arrived.
     */
    TQString m_strSoundFile;

    /**
     * TRUE - If a new mail is arrived a command will be executed.
     */
    bool m_bCommand;

    /**
     * Path to command which will be executed if a new mail is arrived.
     */
    TQString m_strCommandPath;

    /**
     * TRUE - If no new mail is arrived the application will be ended.
     */
    bool m_bTerminate;

    /**
     * TRUE - If no new mail is arrived the main window will be minimized.
     */
    bool m_bMinimize;

    /**
     * TRUE - If a connection error occures during refresh an error message will be shown.
     */
    bool m_bShowConnectionErrors;

    /**
     * TRUE - The user has to confirm window close.
     */
    bool m_bConfirmClose;

    /**
     * TRUE - the app starts minimized.
     */
    bool m_bStartMinimized;

    /**
     * TRUE - the close button leaves the application running in tray
     */
    bool m_bCloseMinimizes;

    /**
     * TRUE - minimizes to the tray rather than to the taskbar
     */
    bool m_bMinimizeToTray;

    /**
     * TRUE - mails keep new until termination
     */
    bool m_bKeepNew;

    /**
     * Mailbox for Spam, if configured
     */
     TQString spamMailbox;

    /**
     * Action which shall be done, if the mail is Spam
     */
      FilterAction_Type spamAction;


  protected:

    /**
     * Makes a copy from the given account object and returns the pointer to it.
     * Reimplementation of TQPtrList::newItem().
     * Used by TQPtrList to add new items.
     * @param item account object
     * @return pointer to the new account object
     */
    virtual TQCollection::Item newItem( TQCollection::Item item );

    /**
     * Compares two ConfigElem objects.
     * Reimplementation of TQPtrList::compareItems(). Used by inSort().
     * @param item1 account 1
     * @param item2 account 2
     * @return 0 if account name 1 == account name 2
     * @return nonzero if account name 2 != account name 2
     */
    virtual int compareItems( TQCollection::Item item1, TQCollection::Item item2 );

    /**
     * Returns whether the given account is in the list
     * @param name name of the searched account
     * @return TRUE - account is existent
     * @return FALSE - account is not existent
     */
    bool hasAccount( const TQString& name ) const;

    /**
     * Returns the pointer to the account named like the given name.
     * @param name of the searched account
     * @return account or NULL, if the account was not found
     */
    ConfigElem* getAccount( const TQString& name ) const;

  protected slots:

    /**
     * Connected with signal sigConfigChanged of all accounts.
     * Emits the signal sigConfigChanged.
     */
    void slotAccountConfigChanged();

    /**
     * Connected with signal sigDeleteReady of all accounts.
     * When an account has sent this signal its appropriate item
     * in AccountDeletionMap will set to FALSE.
     * When all accounts have done the deletion it will emit signal
     * sigDeleteReady.
     * @param account name of the account which has emitted the signal
     * @see AccountDeletionMap
     */
    void slotCheckDeletionState( TQString account );

    /**
     * Connected with signal sigShowBodiesReady of all accounts.
     * When an account has sent this signal its appropriate item
     * in AccountShowBodiesMap will set to FALSE.
     * When all accounts have shown the mail it will emit signal
     * sigShowBodiesReady.
     * @param account name of the account which has emitted the signal
     * @see AccountShowBodiesMap
     */
    void slotCheckShowBodiesState( TQString account );

    /**
     * Connected with signal sigMessageWindowOpened of all accounts.
     * When an account has sent this signal the counter ctrOpenMessageWindows
     * will be incremented.
     * When the counter was incremented from zero (the first window was opened)
     * the signal sigMessageWindowOpened will be emitted.
     * @see ctrOpenMessageWindows
     * @see sigMessageWindowOpened
     */
    void slotMessageWindowOpened();

    /**
     * Connected with signal sigMessageWindowClosed of all accounts.
     * When an account has sent this signal the counter ctrOpenMessageWindows
     * will be decremented.
     * When the counter has reached zero the signal sigAllMessageWindowsClosed
     * will be emitted.
     * @see ctrOpenMessageWindows
     * @see sigAllMessageWindowsClosed
     */
    void slotMessageWindowClosed();

    /**
     * Connected with signal sigRefreshReady of all accounts.
     * When an account has sent this signal its appropriate item
     * in AccountRefreshMap will set to FALSE.
     * When all accounts have refreshed their mail list it will emit
     * signal sigRefreshReady.
     * @param account name of the account which has emitted the signal
     * @see AccountRefreshMap
     */
    void slotCheckRefreshState( TQString account );

  signals:

    /**
     * Will be emitted when the configuration of an account or of the app
     * was changed.
     */
    void sigConfigChanged();

    /**
     * Will be emitted when all selected mails are deleted.
     */
    void sigDeleteReady();

    /**
     * Will be emitted when all selected mails are shown.
     */
    void sigShowBodiesReady();

    /**
     * Will be emitted by slotMessageWindowOpened when an account has
     * opened a window to show a mail.
     * @see slotMessageWindowOpened
     */
    void sigMessageWindowOpened();

    /**
     * Will be emitted by slotMessageWindowClosed when all accounts have
     * closed their windows to show mails.
     * @see slotMessageWindowClosed
     */
    void sigAllMessageWindowsClosed();

    /**
     * Will be emitted, when all accounts have refreshed their mail list.
     */
    void sigRefreshReady();

};

#endif