summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/statusmail.cpp83
-rw-r--r--noncore/net/mail/libmailwrapper/statusmail.h31
2 files changed, 114 insertions, 0 deletions
diff --git a/noncore/net/mail/libmailwrapper/statusmail.cpp b/noncore/net/mail/libmailwrapper/statusmail.cpp
new file mode 100644
index 0000000..3e1d8d1
--- a/dev/null
+++ b/noncore/net/mail/libmailwrapper/statusmail.cpp
@@ -0,0 +1,83 @@
1#include "statusmail.h"
2#include "mailtypes.h"
3#include "abstractmail.h"
4#include <qlist.h>
5
6StatusMail::StatusMail(QList<Account>*list)
7{
8 currentImapStat.message_count=0;
9 currentImapStat.message_unseen=0;
10 currentImapStat.message_recent=0;
11 lastPop3Stat = currentImapStat;
12 currentPop3Stat = currentImapStat;
13 connectionList.setAutoDelete(true);
14 connectionList.clear();
15 initAccounts(list);
16}
17
18StatusMail::~StatusMail()
19{
20}
21
22void StatusMail::initAccounts(QList<Account>*accounts)
23{
24 if (!accounts) return;
25 Account *it;
26 folderStat currentStat;
27 AbstractMail * current = 0;
28 for ( it = accounts->first(); it; it = accounts->next() ) {
29 if ( it->getType().compare( "IMAP" ) == 0 ) {
30 IMAPaccount*ima = static_cast<IMAPaccount *>(it);
31 current = AbstractMail::getWrapper(ima);
32 connectionList.append(current);
33 current->statusFolder(currentStat);
34 currentImapStat.message_count+=currentStat.message_unseen;
35 currentImapStat.message_count+=currentStat.message_recent;
36 currentImapStat.message_count+=currentStat.message_count;
37 } else if ( it->getType().compare( "POP3" ) == 0 ) {
38 POP3account *pop3 = static_cast<POP3account *>(it);
39 current = AbstractMail::getWrapper(pop3);
40 connectionList.append(current);
41 current->statusFolder(currentStat);
42 currentPop3Stat.message_count+=currentStat.message_unseen;
43 currentPop3Stat.message_count+=currentStat.message_recent;
44 currentPop3Stat.message_count+=currentStat.message_count;
45 }
46 current->logout();
47 }
48 lastPop3Stat = currentPop3Stat;
49}
50
51void StatusMail::reset_status()
52{
53 lastPop3Stat = currentPop3Stat;
54}
55
56void StatusMail::check_current_stat(folderStat&targetStat)
57{
58 AbstractMail*it = 0;
59 folderStat currentStat;
60 currentPop3Stat.message_recent = 0;
61 currentPop3Stat.message_count = 0;
62 currentPop3Stat.message_unseen = 0;
63 currentImapStat = currentPop3Stat;
64 for ( it = connectionList.first(); it; it = connectionList.next() ) {
65 it->statusFolder(currentStat);
66 it->logout();
67 if (it->getType().lower()=="imap") {
68 currentImapStat.message_unseen+=currentStat.message_unseen;
69 currentImapStat.message_recent+=currentStat.message_recent;
70 currentImapStat.message_count+=currentStat.message_count;
71 } else if (it->getType().lower()=="pop3") {
72 currentPop3Stat.message_count+=currentStat.message_count;
73 }
74 }
75 if (currentPop3Stat.message_count > lastPop3Stat.message_count) {
76 currentPop3Stat.message_recent = currentPop3Stat.message_count - lastPop3Stat.message_count;
77 currentPop3Stat.message_unseen = currentPop3Stat.message_recent;
78 }
79 targetStat = currentImapStat;
80 targetStat.message_unseen+=currentPop3Stat.message_unseen;
81 targetStat.message_recent+=currentPop3Stat.message_recent;
82 targetStat.message_count+=currentPop3Stat.message_count;
83}
diff --git a/noncore/net/mail/libmailwrapper/statusmail.h b/noncore/net/mail/libmailwrapper/statusmail.h
new file mode 100644
index 0000000..498f7a3
--- a/dev/null
+++ b/noncore/net/mail/libmailwrapper/statusmail.h
@@ -0,0 +1,31 @@
1#ifndef __MAIL_STATUS_H
2#define __MAIL_STATUS_H
3
4#include <settings.h>
5#include <abstractmail.h>
6#include <mailtypes.h>
7
8class StatusMail
9{
10public:
11 StatusMail(QList<Account>*list);
12 virtual ~StatusMail();
13
14 /* this should be called if opiemail is starte or a mailbox touched - may be trough
15 a qcop signal or if tab on the taskbar applet*/
16 virtual void reset_status();
17 virtual void check_current_stat(folderStat&targetStat);
18
19protected:
20 void initAccounts(QList<Account>*list);
21 /* this must be cause we have to calculate the recent for pop3*/
22 folderStat currentImapStat;
23 /* currentPop3Stat is the sum of messages in POP3 accounts in CURRENT loop
24 the recent are calculated to the difference of the LAST loop */
25 folderStat currentPop3Stat;
26 /* lastPop3Stat is the sum of messages in LAST loop */
27 folderStat lastPop3Stat;
28 QList<AbstractMail> connectionList;
29};
30
31#endif