author | conber <conber> | 2002-06-15 09:46:14 (UTC) |
---|---|---|
committer | conber <conber> | 2002-06-15 09:46:14 (UTC) |
commit | 7f2eef29708380844922f34f59ba4e9beefbf7c3 (patch) (unidiff) | |
tree | f57125fbaabddecc35d6677f1b9e48a4594165d5 /noncore/unsupported/mail2/mailtable.cpp | |
parent | 0acbdd392814589df303b6e50c79d9822e3db27a (diff) | |
download | opie-7f2eef29708380844922f34f59ba4e9beefbf7c3.zip opie-7f2eef29708380844922f34f59ba4e9beefbf7c3.tar.gz opie-7f2eef29708380844922f34f59ba4e9beefbf7c3.tar.bz2 |
initial checkin
Diffstat (limited to 'noncore/unsupported/mail2/mailtable.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/unsupported/mail2/mailtable.cpp | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/noncore/unsupported/mail2/mailtable.cpp b/noncore/unsupported/mail2/mailtable.cpp new file mode 100644 index 0000000..fd179f0 --- a/dev/null +++ b/noncore/unsupported/mail2/mailtable.cpp | |||
@@ -0,0 +1,171 @@ | |||
1 | #include <qmessagebox.h> | ||
2 | #include <qpopupmenu.h> | ||
3 | #include <qheader.h> | ||
4 | #include <qtimer.h> | ||
5 | |||
6 | #include "folderwidget.h" | ||
7 | #include "imaphandler.h" | ||
8 | #include "mailtable.h" | ||
9 | |||
10 | MailTableItem::MailTableItem(QListView *parent, IMAPResponseFETCH fetch) | ||
11 | : QListViewItem(parent), _fetch(fetch) | ||
12 | { | ||
13 | _draft = false; | ||
14 | _new = false; | ||
15 | _unseen = true; | ||
16 | |||
17 | QValueList<IMAPResponseEnums::IMAPResponseFlags>::Iterator it; | ||
18 | QValueList<IMAPResponseEnums::IMAPResponseFlags> flags = fetch.flags(); | ||
19 | for (it = flags.begin(); it != flags.end(); it++) { | ||
20 | if (*it == IMAPResponseEnums::Draft) _draft = true; | ||
21 | else if (*it == IMAPResponseEnums::Recent) _new = true; | ||
22 | else if (*it == IMAPResponseEnums::Seen) _unseen = false; | ||
23 | } | ||
24 | |||
25 | setText(0, fetch.envelope().from()[0].name().isEmpty() ? QObject::tr("(no from)") : fetch.envelope().from()[0].name()); | ||
26 | setText(1, fetch.envelope().subject().isEmpty() ? QObject::tr("(no subject)") : fetch.envelope().subject()); | ||
27 | setText(2, fetch.envelope().mailDate().isEmpty() ? QObject::tr("(no date)") : fetch.envelope().mailDate()); | ||
28 | } | ||
29 | |||
30 | void MailTableItem::paintCell(QPainter *painter, const QColorGroup &cg, int col, int width, int align) | ||
31 | { | ||
32 | QColor color = cg.color(QColorGroup::Text); | ||
33 | QFont font = painter->font(); | ||
34 | if (_draft) { | ||
35 | color = QColor("#707070"); | ||
36 | } else if (_new) { | ||
37 | color = QColor("#ff0000"); | ||
38 | font.setBold(true); | ||
39 | } else if (_unseen) { | ||
40 | font.setBold(true); | ||
41 | } | ||
42 | |||
43 | painter->setFont(font); | ||
44 | QColorGroup cg_(cg); | ||
45 | cg_.setColor(QColorGroup::Text, color); | ||
46 | |||
47 | QListViewItem::paintCell(painter, cg_, col, width, align); | ||
48 | } | ||
49 | |||
50 | MailTable::MailTable(QWidget *parent, const char *name, WFlags fl) | ||
51 | : ListViewPlus(parent, name, fl), _parent(parent) | ||
52 | { | ||
53 | _stopped = false; | ||
54 | |||
55 | setSorting(-1); | ||
56 | |||
57 | setAllColumnsShowFocus(true); | ||
58 | addColumn(tr("From"), 100); | ||
59 | addColumn(tr("Subject"), 100); | ||
60 | addColumn(tr("Date"), 100); | ||
61 | |||
62 | QPopupMenu *menu = new QPopupMenu(this); | ||
63 | menu->insertItem(tr("Copy"), MENU_COPY); | ||
64 | |||
65 | QPopupMenu *markMenu = new QPopupMenu(this); | ||
66 | markMenu->insertItem(tr("Seen"), MENU_MARK_READ); | ||
67 | markMenu->insertItem(tr("Unseen"), MENU_MARK_UNREAD); | ||
68 | markMenu->insertSeparator(); | ||
69 | markMenu->insertItem(tr("Marked"), MENU_MARK_MARKED); | ||
70 | markMenu->insertItem(tr("Unmarked"), MENU_MARK_UNMARKED); | ||
71 | |||
72 | menu->insertItem(tr("Mark as..."), markMenu, MENU_MARK); | ||
73 | menu->insertSeparator(); | ||
74 | menu->insertItem(tr("Delete Mail"), MENU_DELETE); | ||
75 | setPopup(menu); | ||
76 | |||
77 | connect(this, SIGNAL(clicked(QListViewItem *)), SLOT(itemClicked(QListViewItem *))); | ||
78 | } | ||
79 | |||
80 | void MailTable::setFolder(Folder folder) | ||
81 | { | ||
82 | folder.topFolder().handler()->iSelect(folder.fullName()); | ||
83 | _handler = folder.topFolder().handler(); | ||
84 | connect(folder.topFolder().handler(), SIGNAL(gotResponse(IMAPResponse &)), SLOT(slotIMAPSelect(IMAPResponse &))); | ||
85 | } | ||
86 | |||
87 | void MailTable::setHeaders(QValueList<IMAPResponseFETCH> response) | ||
88 | { | ||
89 | clear(); | ||
90 | QValueList<IMAPResponseFETCH>::Iterator it; | ||
91 | for (it = response.begin(); it != response.end(); it++) { | ||
92 | (void) new MailTableItem(this, *it); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | void MailTable::slotIMAPSelect(IMAPResponse &response) | ||
97 | { | ||
98 | disconnect(response.imapHandler(), SIGNAL(gotResponse(IMAPResponse &)), this, SLOT(slotIMAPSelect(IMAPResponse &))); | ||
99 | |||
100 | if (response.statusResponse().status() == IMAPResponseEnums::OK) { | ||
101 | clear(); | ||
102 | QString mails = response.EXISTS()[0].mails(); | ||
103 | if (mails.toInt() == 0) { | ||
104 | emit status(tr("Mailbox contained no mails.")); | ||
105 | return; | ||
106 | } | ||
107 | int a = mails.toInt() / 5; | ||
108 | int b = mails.toInt() % 5; | ||
109 | |||
110 | _downloadSteps = a; | ||
111 | if (b > 0) _downloadSteps++; | ||
112 | _lastStep = b; | ||
113 | _currentProgress = 0; | ||
114 | |||
115 | emit totalSteps(_downloadSteps); | ||
116 | emit progress(_currentProgress); | ||
117 | emit stopEnabled(true); | ||
118 | |||
119 | response.imapHandler()->iFetch(QString("1:%1").arg((a == 0) ? b : 5), "ENVELOPE FLAGS UID"); | ||
120 | emit status(tr("Getting mail headers...")); | ||
121 | connect(response.imapHandler(), SIGNAL(gotResponse(IMAPResponse &)), SLOT(slotIMAPFetch(IMAPResponse &))); | ||
122 | } else { | ||
123 | QMessageBox::warning(this, tr("Error"), tr("<p>An error occoured during the selection of the mailbox. (Server said: %1)</p>").arg(response.statusResponse().comment()), tr("Ok")); | ||
124 | } | ||
125 | } | ||
126 | |||
127 | void MailTable::slotIMAPFetch(IMAPResponse &response) | ||
128 | { | ||
129 | disconnect(response.imapHandler(), SIGNAL(gotResponse(IMAPResponse &)), this, SLOT(slotIMAPFetch(IMAPResponse &))); | ||
130 | |||
131 | if (response.statusResponse().status() == IMAPResponseEnums::OK) { | ||
132 | QValueList<IMAPResponseFETCH>::Iterator it; | ||
133 | QValueList<IMAPResponseFETCH> fetch = response.FETCH(); | ||
134 | for (it = fetch.begin(); it != fetch.end(); it++) { | ||
135 | (void) new MailTableItem(this, *it); | ||
136 | } | ||
137 | emit progress(++_currentProgress); | ||
138 | |||
139 | if (_currentProgress != _downloadSteps) { | ||
140 | if (_stopped) { | ||
141 | _currentProgress = 0; | ||
142 | _downloadSteps = 0; | ||
143 | _lastStep = 0; | ||
144 | _stopped = false; | ||
145 | emit status(tr("Stopped")); | ||
146 | emit resetProgress(); | ||
147 | emit stopEnabled(false); | ||
148 | } else { | ||
149 | response.imapHandler()->iFetch(QString("%1:%2").arg(_currentProgress * 5 + 1).arg((_currentProgress + 1 == _downloadSteps) ? _currentProgress * 5 + _lastStep : _currentProgress * 5 + 5), "ENVELOPE FLAGS UID"); | ||
150 | connect(response.imapHandler(), SIGNAL(gotResponse(IMAPResponse &)), SLOT(slotIMAPFetch(IMAPResponse &))); | ||
151 | } | ||
152 | } else { | ||
153 | _currentProgress = 0; | ||
154 | _downloadSteps = 0; | ||
155 | _lastStep = 0; | ||
156 | emit status(tr("Got all mail headers.")); | ||
157 | emit resetProgress(); | ||
158 | emit stopEnabled(false); | ||
159 | } | ||
160 | } else { | ||
161 | emit status(tr("<font color=#ff0000>Couldn't fetch mail.")); | ||
162 | } | ||
163 | } | ||
164 | |||
165 | void MailTable::itemClicked(QListViewItem *item) | ||
166 | { | ||
167 | if (item == NULL) return; | ||
168 | emit mailClicked(((MailTableItem *)item)->fetch(), _handler); | ||
169 | } | ||
170 | |||
171 | |||