Diffstat (limited to 'noncore/unsupported/mailit/readmail.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/unsupported/mailit/readmail.cpp | 64 |
1 files changed, 48 insertions, 16 deletions
diff --git a/noncore/unsupported/mailit/readmail.cpp b/noncore/unsupported/mailit/readmail.cpp index 4eae7f6..1682675 100644 --- a/noncore/unsupported/mailit/readmail.cpp +++ b/noncore/unsupported/mailit/readmail.cpp | |||
@@ -1,182 +1,204 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2001 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2001 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qt Palmtop Environment. | 4 | ** This file is part of Qt Palmtop Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include "readmail.h" | 20 | #include "readmail.h" |
21 | #include <qimage.h> | 21 | #include <qimage.h> |
22 | #include <qwhatsthis.h> | ||
22 | #include <qmime.h> | 23 | #include <qmime.h> |
23 | #include <qaction.h> | 24 | #include <qaction.h> |
25 | #include <qpopupmenu.h> | ||
24 | #include <qpe/resource.h> | 26 | #include <qpe/resource.h> |
25 | 27 | ||
26 | ReadMail::ReadMail( QWidget* parent, const char* name, WFlags fl ) | 28 | ReadMail::ReadMail( QWidget* parent, const char* name, WFlags fl ) |
27 | : QMainWindow(parent, name, fl) | 29 | : QMainWindow(parent, name, fl) |
28 | { | 30 | { |
29 | plainTxt = FALSE; | 31 | plainTxt = FALSE; |
30 | 32 | ||
31 | init(); | 33 | init(); |
32 | viewAtt = new ViewAtt(0, "View Attatchments"); | 34 | viewAtt = new ViewAtt(0, "View Attatchments"); |
33 | } | 35 | } |
34 | 36 | ||
35 | ReadMail::~ReadMail() | 37 | ReadMail::~ReadMail() |
36 | { | 38 | { |
37 | delete emailView->mimeSourceFactory(); | 39 | delete emailView->mimeSourceFactory(); |
38 | delete viewAtt; | 40 | delete viewAtt; |
39 | } | 41 | } |
40 | 42 | ||
41 | void ReadMail::init() | 43 | void ReadMail::init() |
42 | { | 44 | { |
43 | setToolBarsMovable(FALSE); | 45 | setToolBarsMovable(FALSE); |
44 | 46 | ||
47 | QPopupMenu* mailaction=new QPopupMenu(this); | ||
48 | |||
45 | bar = new QToolBar(this); | 49 | bar = new QToolBar(this); |
46 | bar->setHorizontalStretchable( TRUE ); | 50 | bar->setHorizontalStretchable( TRUE ); |
47 | 51 | ||
48 | menu = new QMenuBar( bar ); | 52 | menu = new QMenuBar( bar ); |
49 | 53 | ||
50 | viewMenu = new QPopupMenu(menu); | 54 | viewMenu = new QPopupMenu(menu); |
51 | menu->insertItem( tr( "&View" ), viewMenu); | 55 | menu->insertItem( tr( "&View" ), viewMenu); |
52 | 56 | ||
53 | mailMenu = new QPopupMenu(menu); | 57 | mailMenu = new QPopupMenu(menu); |
54 | menu->insertItem( tr( "&Mail" ), mailMenu); | 58 | menu->insertItem( tr( "&Mail" ), mailMenu); |
55 | 59 | ||
56 | bar = new QToolBar(this); | 60 | bar = new QToolBar(this); |
57 | 61 | ||
58 | //reply dependant on viewing inbox | 62 | downloadButton = new QAction( tr( "Download" ), Resource::loadPixmap( "mailit/download" ),QString::null, 0, this, 0 ); |
59 | replyButton = new QAction( tr( "Reply" ), Resource::loadPixmap( "mailit/reply" ), | 63 | connect(downloadButton, SIGNAL(activated()), this, SLOT(download()) ); |
60 | QString::null, 0, this, 0 ); | 64 | downloadButton->setWhatsThis(tr("Click here to download the selected mail")); |
61 | connect(replyButton, SIGNAL(activated()), this, SLOT(reply()) ); | ||
62 | replyButton->setWhatsThis(tr("Click here to reply to the selected mail")); | ||
63 | |||
64 | forwardButton = new QAction( tr( "Forward" ), Resource::loadPixmap( "mailit/forward" ), | ||
65 | QString::null, 0, this, 0 ); | ||
66 | connect(forwardButton, SIGNAL(activated()), this, SLOT(forward()) ); | ||
67 | forwardButton->setWhatsThis(tr("Click here to forward the selected mail")); | ||
68 | 65 | ||
66 | |||
69 | previousButton = new QAction( tr( "Previous" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 ); | 67 | previousButton = new QAction( tr( "Previous" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 ); |
70 | connect( previousButton, SIGNAL( activated() ), this, SLOT( previous() ) ); | 68 | connect( previousButton, SIGNAL( activated() ), this, SLOT( previous() ) ); |
71 | previousButton->addTo(bar); | 69 | previousButton->addTo(bar); |
72 | previousButton->addTo(viewMenu); | 70 | previousButton->addTo(viewMenu); |
73 | previousButton->setWhatsThis(tr("Read the previous mail in the list")); | 71 | previousButton->setWhatsThis(tr("Read the previous mail in the list")); |
74 | 72 | ||
75 | nextButton = new QAction( tr( "Next" ), Resource::loadPixmap( "forward" ), QString::null, 0, this, 0 ); | 73 | nextButton = new QAction( tr( "Next" ), Resource::loadPixmap( "forward" ), QString::null, 0, this, 0 ); |
76 | connect( nextButton, SIGNAL( activated() ), this, SLOT( next() ) ); | 74 | connect( nextButton, SIGNAL( activated() ), this, SLOT( next() ) ); |
77 | nextButton->addTo(bar); | 75 | nextButton->addTo(bar); |
78 | nextButton->addTo(viewMenu); | 76 | nextButton->addTo(viewMenu); |
79 | previousButton->setWhatsThis(tr("Read the next mail in the list")); | 77 | previousButton->setWhatsThis(tr("Read the next mail in the list")); |
80 | 78 | ||
81 | attachmentButton = new QAction( tr( "Attatchments" ), Resource::loadPixmap( "mailit/attach" ), QString::null, 0, this, 0 ); | 79 | attachmentButton = new QAction( tr( "Attatchments" ), Resource::loadPixmap( "mailit/attach" ), QString::null, 0, this, 0 ); |
82 | connect( attachmentButton, SIGNAL( activated() ), this, | 80 | connect( attachmentButton, SIGNAL( activated() ), this, |
83 | SLOT( viewAttachments() ) ); | 81 | SLOT( viewAttachments() ) ); |
84 | attachmentButton->addTo(bar); | 82 | attachmentButton->addTo(bar); |
85 | attachmentButton->addTo(viewMenu); | 83 | attachmentButton->addTo(viewMenu); |
86 | attachmentButton->setWhatsThis(tr("Click here to add attachments to your mail")); | 84 | attachmentButton->setWhatsThis(tr("Click here to add attachments to your mail")); |
87 | 85 | ||
88 | plainTextButton = new QAction( tr( "Text Format" ), Resource::loadPixmap( "DocsIcon" ), QString::null, 0, this, 0, TRUE); | 86 | plainTextButton = new QAction( tr( "Text Format" ), Resource::loadPixmap( "DocsIcon" ), QString::null, 0, this, 0, TRUE); |
89 | connect( plainTextButton, SIGNAL( activated() ), this, SLOT( shiftText() ) ); | 87 | connect( plainTextButton, SIGNAL( activated() ), this, SLOT( shiftText() ) ); |
90 | plainTextButton->addTo(bar); | 88 | plainTextButton->addTo(bar); |
91 | plainTextButton->addTo(viewMenu); | 89 | plainTextButton->addTo(viewMenu); |
92 | plainTextButton->setWhatsThis(tr("The mail view has 2 modes:\n" | 90 | plainTextButton->setWhatsThis(tr("The mail view has 2 modes:\n" |
93 | "<LI><B>RichText</B> shows the mail as HTML with reach features (no standard line breaks)</LI>" | 91 | "<LI><B>RichText</B> shows the mail as HTML with reach features (no standard line breaks)</LI>" |
94 | "<LI><B>Plain</B> shows the mail as standard plain text</LI>" | 92 | "<LI><B>Plain</B> shows the mail as standard plain text</LI>" |
95 | "Click here to switch between those view modes" )); | 93 | "Click here to switch between those view modes" )); |
96 | 94 | ||
95 | //reply dependant on viewing inbox | ||
96 | replyButton = new QToolButton(Resource::loadPixmap("mailit/reply"),tr("reply"),tr("reply to mail"), this,SLOT(reply()),bar); | ||
97 | QWhatsThis::add(replyButton,tr("Click here to reply to the selected mail\nPress and hold for more options.")); | ||
98 | replyButton->setPopup(mailaction); | ||
99 | |||
100 | replyAllButton = new QAction( tr( "Reply all" ), Resource::loadPixmap( "mailit/reply" ),QString::null, 0, this, 0 ); | ||
101 | connect(replyAllButton, SIGNAL(activated()), this, SLOT(replyAll())); | ||
102 | replyAllButton->setWhatsThis(tr("Click here to reply to the selected mail to CC: addresses also")); | ||
103 | replyAllButton->addTo(mailaction); | ||
104 | |||
105 | forwardButton = new QAction( tr( "Forward" ), Resource::loadPixmap( "mailit/forward" ), | ||
106 | QString::null, 0, this, 0 ); | ||
107 | connect(forwardButton, SIGNAL(activated()), this, SLOT(forward())); | ||
108 | forwardButton->setWhatsThis(tr("Click here to forward the selected mail")); | ||
109 | forwardButton->addTo(mailaction); | ||
110 | |||
111 | |||
97 | deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 ); | 112 | deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 ); |
98 | connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) ); | 113 | connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) ); |
99 | deleteButton->addTo(bar); | 114 | deleteButton->addTo(bar); |
100 | deleteButton->addTo(mailMenu); | 115 | deleteButton->addTo(mailMenu); |
101 | deleteButton->setWhatsThis(tr("Click here to remove the selected mail")); | 116 | deleteButton->setWhatsThis(tr("Click here to remove the selected mail")); |
102 | 117 | ||
103 | viewMenu->insertItem(Resource::loadPixmap("close"), "Close", this, SLOT(close())); | 118 | viewMenu->insertItem(Resource::loadPixmap("close"), "Close", this, SLOT(close())); |
104 | 119 | ||
105 | emailView = new QTextView( this, "emailView" ); | 120 | emailView = new QTextView( this, "emailView" ); |
106 | 121 | ||
107 | setCentralWidget(emailView); | 122 | setCentralWidget(emailView); |
108 | 123 | ||
109 | mime = new QMimeSourceFactory(); | 124 | mime = new QMimeSourceFactory(); |
110 | emailView->setMimeSourceFactory(mime); | 125 | emailView->setMimeSourceFactory(mime); |
111 | } | 126 | } |
112 | 127 | ||
113 | void ReadMail::updateView() | 128 | void ReadMail::updateView() |
114 | { | 129 | { |
115 | Enclosure *ePtr; | 130 | Enclosure *ePtr; |
116 | QString mailStringSize; | 131 | QString mailStringSize; |
117 | QString text, temp; | 132 | QString text, temp; |
118 | 133 | ||
119 | mail->read = TRUE; //mark as read | 134 | mail->read = TRUE; //mark as read |
120 | inbox = mail->received; | 135 | inbox = mail->received; |
121 | 136 | ||
122 | replyButton->removeFrom(mailMenu); | 137 | replyButton->setEnabled(false); |
123 | replyButton->removeFrom(bar); | 138 | /*replyButton->removeFrom(bar); |
124 | forwardButton->removeFrom(mailMenu); | 139 | forwardButton->removeFrom(mailMenu); |
125 | forwardButton->removeFrom(bar); | 140 | forwardButton->removeFrom(bar);*/ |
141 | downloadButton->removeFrom(bar); | ||
142 | |||
143 | //downloadButton->setEnabled(!mail->downloaded); | ||
126 | 144 | ||
145 | |||
127 | if (inbox == TRUE) { | 146 | if (inbox == TRUE) { |
128 | replyButton->addTo(bar); | 147 | replyButton->setEnabled(true); |
129 | replyButton->addTo(mailMenu); | 148 | /*replyButton->addTo(mailMenu); |
130 | forwardButton->addTo(bar); | 149 | forwardButton->addTo(bar); |
131 | forwardButton->addTo(mailMenu); | 150 | forwardButton->addTo(mailMenu);*/ |
132 | 151 | ||
133 | 152 | ||
134 | if (!mail->downloaded) { | 153 | if (!mail->downloaded) { |
154 | |||
155 | downloadButton->addTo(bar); | ||
156 | |||
135 | //report currently viewed mail so that it will be | 157 | //report currently viewed mail so that it will be |
136 | //placed first in the queue of new mails to download | 158 | //placed first in the queue of new mails to download |
137 | emit viewingMail(mail); | 159 | emit viewingMail(mail); |
138 | 160 | ||
139 | double mailSize = (double) mail->size; | 161 | double mailSize = (double) mail->size; |
140 | if (mailSize < 1024) { | 162 | if (mailSize < 1024) { |
141 | mailStringSize.setNum(mailSize); | 163 | mailStringSize.setNum(mailSize); |
142 | mailStringSize += " Bytes"; | 164 | mailStringSize += " Bytes"; |
143 | } else if (mailSize < 1024*1024) { | 165 | } else if (mailSize < 1024*1024) { |
144 | mailStringSize.setNum( (mailSize / 1024), 'g', 2 ); | 166 | mailStringSize.setNum( (mailSize / 1024), 'g', 2 ); |
145 | mailStringSize += " Kb"; | 167 | mailStringSize += " Kb"; |
146 | } else { | 168 | } else { |
147 | mailStringSize.setNum( (mailSize / (1024*1024)), 'g', 3); | 169 | mailStringSize.setNum( (mailSize / (1024*1024)), 'g', 3); |
148 | mailStringSize += " Mb"; | 170 | mailStringSize += " Mb"; |
149 | } | 171 | } |
150 | } | 172 | } |
151 | } | 173 | } |
152 | 174 | ||
153 | QMimeSourceFactory *mime = emailView->mimeSourceFactory(); | 175 | QMimeSourceFactory *mime = emailView->mimeSourceFactory(); |
154 | 176 | ||
155 | if (! plainTxt) { //use RichText, inline pics etc. | 177 | if (! plainTxt) { //use RichText, inline pics etc. |
156 | emailView->setTextFormat(QTextView::RichText); | 178 | emailView->setTextFormat(QTextView::RichText); |
157 | text = "<b><big><center><font color=\"blue\">" + mail->subject | 179 | text = "<b><big><center><font color=\"blue\">" + mail->subject |
158 | +"</font></center></big></b><br>"; | 180 | +"</font></center></big></b><br>"; |
159 | text += "<b>From: </b>" + mail->from + " <i>" + | 181 | text += "<b>From: </b>" + mail->from + " <i>" + |
160 | mail->fromMail + "</i><br>"; | 182 | mail->fromMail + "</i><br>"; |
161 | 183 | ||
162 | text +="<b>To: </b>"; | 184 | text +="<b>To: </b>"; |
163 | for (QStringList::Iterator it = mail->recipients.begin(); | 185 | for (QStringList::Iterator it = mail->recipients.begin(); |
164 | it != mail->recipients.end(); ++it ) { | 186 | it != mail->recipients.end(); ++it ) { |
165 | text += *it + " "; | 187 | text += *it + " "; |
166 | } | 188 | } |
167 | 189 | ||
168 | text +="<br><b>CC: </b>"; | 190 | text +="<br><b>CC: </b>"; |
169 | for (QStringList::Iterator it = mail->carbonCopies.begin(); | 191 | for (QStringList::Iterator it = mail->carbonCopies.begin(); |
170 | it != mail->carbonCopies.end(); ++it ) { | 192 | it != mail->carbonCopies.end(); ++it ) { |
171 | text += *it + " "; | 193 | text += *it + " "; |
172 | } | 194 | } |
173 | 195 | ||
174 | text += "<br>" + mail->date; | 196 | text += "<br>" + mail->date; |
175 | 197 | ||
176 | if (mail->files.count() > 0) { | 198 | if (mail->files.count() > 0) { |
177 | text += "<br><b>Attatchments: </b>"; | 199 | text += "<br><b>Attatchments: </b>"; |
178 | 200 | ||
179 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { | 201 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { |
180 | text += ePtr->originalName + " "; | 202 | text += ePtr->originalName + " "; |
181 | } | 203 | } |
182 | text += "<hr><br>" + mail->body; | 204 | text += "<hr><br>" + mail->body; |
@@ -312,56 +334,66 @@ void ReadMail::previous() | |||
312 | 334 | ||
313 | //deletes item, tries bringing up next or previous, exits if unsucessful | 335 | //deletes item, tries bringing up next or previous, exits if unsucessful |
314 | void ReadMail::deleteItem() | 336 | void ReadMail::deleteItem() |
315 | { | 337 | { |
316 | EmailListItem *temp = item; | 338 | EmailListItem *temp = item; |
317 | temp = (EmailListItem *) item->nextSibling();//trybelow | 339 | temp = (EmailListItem *) item->nextSibling();//trybelow |
318 | if (temp == NULL) | 340 | if (temp == NULL) |
319 | temp = (EmailListItem *) item->itemAbove(); //try above | 341 | temp = (EmailListItem *) item->itemAbove(); //try above |
320 | 342 | ||
321 | emit removeItem(item, inbox); | 343 | emit removeItem(item, inbox); |
322 | 344 | ||
323 | item = temp; | 345 | item = temp; |
324 | if (item != NULL) { //more items in list | 346 | if (item != NULL) { //more items in list |
325 | mail = item->getMail(); | 347 | mail = item->getMail(); |
326 | updateView(); | 348 | updateView(); |
327 | updateButtons(); | 349 | updateButtons(); |
328 | } else close(); //no more items to see | 350 | } else close(); //no more items to see |
329 | } | 351 | } |
330 | 352 | ||
331 | void ReadMail::updateButtons() | 353 | void ReadMail::updateButtons() |
332 | { | 354 | { |
333 | EmailListItem *temp; | 355 | EmailListItem *temp; |
334 | 356 | ||
335 | temp = item; | 357 | temp = item; |
336 | if ((EmailListItem *) temp->nextSibling() == NULL) | 358 | if ((EmailListItem *) temp->nextSibling() == NULL) |
337 | nextButton->setEnabled(FALSE); | 359 | nextButton->setEnabled(FALSE); |
338 | else nextButton->setEnabled(TRUE); | 360 | else nextButton->setEnabled(TRUE); |
339 | 361 | ||
340 | temp = item; | 362 | temp = item; |
341 | if ((EmailListItem *) temp->itemAbove() == NULL) | 363 | if ((EmailListItem *) temp->itemAbove() == NULL) |
342 | previousButton->setEnabled(FALSE); | 364 | previousButton->setEnabled(FALSE); |
343 | else previousButton->setEnabled(TRUE); | 365 | else previousButton->setEnabled(TRUE); |
344 | } | 366 | } |
345 | 367 | ||
346 | void ReadMail::shiftText() | 368 | void ReadMail::shiftText() |
347 | { | 369 | { |
348 | plainTxt = ! plainTxt; | 370 | plainTxt = ! plainTxt; |
349 | updateView(); | 371 | updateView(); |
350 | } | 372 | } |
351 | 373 | ||
352 | void ReadMail::viewAttachments() | 374 | void ReadMail::viewAttachments() |
353 | { | 375 | { |
354 | viewAtt->update(mail, inbox); | 376 | viewAtt->update(mail, inbox); |
355 | viewAtt->showMaximized(); | 377 | viewAtt->showMaximized(); |
356 | } | 378 | } |
357 | 379 | ||
358 | void ReadMail::reply() | 380 | void ReadMail::reply() |
359 | { | 381 | { |
382 | emit replyRequested(*mail, (bool&)FALSE); | ||
383 | } | ||
384 | |||
385 | void ReadMail::replyAll() | ||
386 | { | ||
360 | emit replyRequested(*mail, (bool&)TRUE); | 387 | emit replyRequested(*mail, (bool&)TRUE); |
361 | } | 388 | } |
362 | 389 | ||
363 | void ReadMail::forward() | 390 | void ReadMail::forward() |
364 | { | 391 | { |
365 | emit forwardRequested(*mail); | 392 | emit forwardRequested(*mail); |
366 | } | 393 | } |
367 | 394 | ||
395 | void ReadMail::download() | ||
396 | { | ||
397 | emit download(mail); | ||
398 | } | ||
399 | |||