summaryrefslogtreecommitdiffabout
path: root/kmicromail/opiemail.cpp
Unidiff
Diffstat (limited to 'kmicromail/opiemail.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/opiemail.cpp38
1 files changed, 37 insertions, 1 deletions
diff --git a/kmicromail/opiemail.cpp b/kmicromail/opiemail.cpp
index 6e54bf4..760e3b0 100644
--- a/kmicromail/opiemail.cpp
+++ b/kmicromail/opiemail.cpp
@@ -1,602 +1,638 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2// CHANGED 2004-08-06 Lutz Rogowski 2// CHANGED 2004-08-06 Lutz Rogowski
3 3
4 4
5#define protected public 5#define protected public
6#include <qwidget.h> 6#include <qwidget.h>
7#undef protected 7#undef protected
8#include "koprefsdialog.h" 8#include "koprefsdialog.h"
9#include <kapplication.h> 9#include <kapplication.h>
10#include <libkdepim/externalapphandler.h> 10#include <libkdepim/externalapphandler.h>
11#include <libkdepim/kpimglobalprefs.h> 11#include <libkdepim/kpimglobalprefs.h>
12#ifdef MINIKDE_KDIALOG_H 12#ifdef MINIKDE_KDIALOG_H
13#undef MINIKDE_KDIALOG_H 13#undef MINIKDE_KDIALOG_H
14#endif 14#endif
15#include "settingsdialog.h" 15#include "settingsdialog.h"
16#include "opiemail.h" 16#include "opiemail.h"
17#include "editaccounts.h" 17#include "editaccounts.h"
18#include "composemail.h" 18#include "composemail.h"
19#include "mailistviewitem.h" 19#include "mailistviewitem.h"
20#include "viewmail.h" 20#include "viewmail.h"
21#include "selectstore.h" 21#include "selectstore.h"
22#include "selectsmtp.h" 22#include "selectsmtp.h"
23#include "accountitem.h" 23#include "accountitem.h"
24#include "accountview.h"
24#include "klocale.h" 25#include "klocale.h"
25 26
26#include <qmessagebox.h> 27#include <qmessagebox.h>
27#include <qtimer.h> 28#include <qtimer.h>
28#include <qcursor.h> 29#include <qcursor.h>
29#include <qtextbrowser.h> 30#include <qtextbrowser.h>
30#include <qregexp.h> 31#include <qregexp.h>
31#include <qpe/global.h> 32#include <qpe/global.h>
32 33
33#ifdef DESKTOP_VERSION 34#ifdef DESKTOP_VERSION
34#include <qapplication.h> 35#include <qapplication.h>
35#else 36#else
36#include <qpe/qpeapplication.h> 37#include <qpe/qpeapplication.h>
37#endif 38#endif
38#include <libmailwrapper/smtpwrapper.h> 39#include <libmailwrapper/smtpwrapper.h>
39#include <libmailwrapper/mailtypes.h> 40#include <libmailwrapper/mailtypes.h>
40#include <libmailwrapper/abstractmail.h> 41#include <libmailwrapper/abstractmail.h>
41#include "koprefs.h" 42#include "koprefs.h"
42 43
43//using namespace Opie::Core; 44//using namespace Opie::Core;
44 45
45OpieMail::OpieMail( QWidget *parent, const char *name ) 46OpieMail::OpieMail( QWidget *parent, const char *name )
46 : MainWindow( parent, name) //, WStyle_ContextHelp ) 47 : MainWindow( parent, name) //, WStyle_ContextHelp )
47{ 48{
48 settings = new Settings(); 49 settings = new Settings();
49 tb = 0; 50 tb = 0;
50 setIcon(SmallIcon( "kmicromail" ) ); 51 setIcon(SmallIcon( "kmicromail" ) );
51 folderView->populate( settings->getAccounts() ); 52 folderView->populate( settings->getAccounts() );
52 53
53} 54}
54 55
55OpieMail::~OpieMail() 56OpieMail::~OpieMail()
56{ 57{
57 if (settings) delete settings; 58 if (settings) delete settings;
58 if ( tb ) 59 if ( tb )
59 delete tb; 60 delete tb;
60} 61}
61 62
62void OpieMail::appMessage(const QCString &msg, const QByteArray &data) 63void OpieMail::appMessage(const QCString &msg, const QByteArray &data)
63{ 64{
64 65
65} 66}
66#include <stdlib.h> 67#include <stdlib.h>
67void OpieMail::message(const QCString &msg, const QByteArray &data) 68void OpieMail::message(const QCString &msg, const QByteArray &data)
68{ 69{
69 // copied from old mail2 70 // copied from old mail2
70 static int ii = 0; 71 static int ii = 0;
71 //qDebug("QCOP CALL ############################# %d ", ii); 72 //qDebug("QCOP CALL ############################# %d ", ii);
72 //QString mess ( msg ); 73 //QString mess ( msg );
73 //qDebug("Message = %s ",mess.latin1()); 74 //qDebug("Message = %s ",mess.latin1());
74 ++ii; 75 ++ii;
75 //qDebug("KM:appMessage %d *%s* %x", ii, msg.data(), this); 76 //qDebug("KM:appMessage %d *%s* %x", ii, msg.data(), this);
76 77
77 mPendingEmail = QString::null; 78 mPendingEmail = QString::null;
78 mPendingName = QString::null; 79 mPendingName = QString::null;
79 if (msg == "writeMail(QString,QString)") 80 if (msg == "writeMail(QString,QString)")
80 { 81 {
81 //qDebug("writeMail(QString,QString) "); 82 //qDebug("writeMail(QString,QString) ");
82 QDataStream stream(data,IO_ReadOnly); 83 QDataStream stream(data,IO_ReadOnly);
83 stream >> mPendingName >> mPendingEmail; 84 stream >> mPendingName >> mPendingEmail;
84 // removing the whitespaces at beginning and end is needed! 85 // removing the whitespaces at beginning and end is needed!
85 QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) ); 86 QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) );
86 } 87 }
87 else if (msg == "newMail()") 88 else if (msg == "newMail()")
88 { 89 {
89 //qDebug("slotComposeMail() "); 90 //qDebug("slotComposeMail() ");
90 // we cannot call slotComposeMail(); directly, because may be executing a QCOP call 91 // we cannot call slotComposeMail(); directly, because may be executing a QCOP call
91 // and a QCOP call does not like a processevents in his execution 92 // and a QCOP call does not like a processevents in his execution
92 // with the Qtimer we call slotComposeMail() after we reached the main event loop 93 // with the Qtimer we call slotComposeMail() after we reached the main event loop
93 QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) ); 94 QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) );
94 // slotComposeMail(); 95 // slotComposeMail();
95 } 96 }
96 else if (msg == "newMail(QString)") 97 else if (msg == "newMail(QString)")
97 { 98 {
98 //qDebug(" newMail(QString)"); 99 //qDebug(" newMail(QString)");
99 QDataStream stream(data,IO_ReadOnly); 100 QDataStream stream(data,IO_ReadOnly);
100 stream >> mPendingName; 101 stream >> mPendingName;
101 // the format is 102 // the format is
102 // NAME <EMAIL>:SUBJECT 103 // NAME <EMAIL>:SUBJECT
103 QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) ); 104 QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) );
104 } else { 105 } else {
105 mPendingData = data; 106 mPendingData = data;
106 mPendingMessage = msg; 107 mPendingMessage = msg;
107 QTimer::singleShot ( 50, this, SLOT(slotExtAppHandler() ) ); 108 QTimer::singleShot ( 50, this, SLOT(slotExtAppHandler() ) );
108 } 109 }
109 110
110 //qDebug("END OpieMail::message "); 111 //qDebug("END OpieMail::message ");
111} 112}
112void OpieMail::slotExtAppHandler() 113void OpieMail::slotExtAppHandler()
113{ 114{
114 ExternalAppHandler::instance()->appMessage ( mPendingMessage, mPendingData ); 115 ExternalAppHandler::instance()->appMessage ( mPendingMessage, mPendingData );
115} 116}
116void OpieMail::slotwriteMail2(const QString& namemail ) 117void OpieMail::slotwriteMail2(const QString& namemail )
117{ 118{
118 //qDebug("OpieMail::slotwriteMail2 "); 119 //qDebug("OpieMail::slotwriteMail2 ");
119 //qApp->processEvents(); 120 //qApp->processEvents();
120 ComposeMail compose( settings, this, 0, true ); 121 ComposeMail compose( settings, this, 0, true );
121 if ( !namemail.isEmpty() ) { 122 if ( !namemail.isEmpty() ) {
122 QString to = namemail; 123 QString to = namemail;
123 if ( namemail.find( " <") > 1 ) { 124 if ( namemail.find( " <") > 1 ) {
124 to = "\"" +to.replace( QRegExp( " <"), "\" <") ; 125 to = "\"" +to.replace( QRegExp( " <"), "\" <") ;
125 } else 126 } else
126 if ( namemail.find( "<") > 1 ) { 127 if ( namemail.find( "<") > 1 ) {
127 to = "\"" +to.replace( QRegExp( "<"), "\" <") ; 128 to = "\"" +to.replace( QRegExp( "<"), "\" <") ;
128 } 129 }
129 int sub = to.find( ">:"); 130 int sub = to.find( ">:");
130 if ( sub > 0 ) { 131 if ( sub > 0 ) {
131 compose.setTo( to.left(sub+1) ); 132 compose.setTo( to.left(sub+1) );
132 compose.setSubject( to.mid(sub+2) ); 133 compose.setSubject( to.mid(sub+2) );
133 } else 134 } else
134 compose.setTo( to ); 135 compose.setTo( to );
135 } 136 }
136 compose.slotAdjustColumns(); 137 compose.slotAdjustColumns();
137#ifndef DESKTOP_VERSION 138#ifndef DESKTOP_VERSION
138 compose.showMaximized(); 139 compose.showMaximized();
139#endif 140#endif
140 compose.exec(); 141 compose.exec();
141 raise(); 142 raise();
142 //qDebug("retttich "); 143 //qDebug("retttich ");
143} 144}
144void OpieMail::slotwriteMail(const QString&name,const QString&email) 145void OpieMail::slotwriteMail(const QString&name,const QString&email)
145{ 146{
146 // qDebug("OpieMail::slotwriteMail "); 147 // qDebug("OpieMail::slotwriteMail ");
147 ComposeMail compose( settings, this, 0, true ); 148 ComposeMail compose( settings, this, 0, true );
148 if (!email.isEmpty()) 149 if (!email.isEmpty())
149 { 150 {
150 if (!name.isEmpty()) 151 if (!name.isEmpty())
151 { 152 {
152 compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">"); 153 compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">");
153 } 154 }
154 else 155 else
155 { 156 {
156 compose.setTo(email); 157 compose.setTo(email);
157 } 158 }
158 } 159 }
159 compose.slotAdjustColumns(); 160 compose.slotAdjustColumns();
160#ifndef DESKTOP_VERSION 161#ifndef DESKTOP_VERSION
161 compose.showMaximized(); 162 compose.showMaximized();
162#endif 163#endif
163 compose.exec(); 164 compose.exec();
164 raise(); 165 raise();
165} 166}
166 167
167void OpieMail::slotComposeMail() 168void OpieMail::slotComposeMail()
168{ 169{
169 if ( mPendingEmail == QString::null && mPendingName == QString::null) 170 if ( mPendingEmail == QString::null && mPendingName == QString::null)
170 slotwriteMail2( QString () ); 171 slotwriteMail2( QString () );
171 else { 172 else {
172 if ( mPendingEmail == QString::null ) 173 if ( mPendingEmail == QString::null )
173 slotwriteMail2( mPendingName ); 174 slotwriteMail2( mPendingName );
174 else 175 else
175 slotwriteMail( mPendingName, mPendingEmail ); 176 slotwriteMail( mPendingName, mPendingEmail );
176 } 177 }
177 //slotwriteMail(0l,0l); 178 //slotwriteMail(0l,0l);
178} 179}
179 180
180void OpieMail::slotSendQueued() 181void OpieMail::slotSendQueued()
181{ 182{
182 SMTPaccount *smtp = 0; 183 SMTPaccount *smtp = 0;
183 184
184 QList<Account> list = settings->getAccounts(); 185 QList<Account> list = settings->getAccounts();
185 QList<SMTPaccount> smtpList; 186 QList<SMTPaccount> smtpList;
186 smtpList.setAutoDelete(false); 187 smtpList.setAutoDelete(false);
187 Account *it; 188 Account *it;
188 for ( it = list.first(); it; it = list.next() ) 189 for ( it = list.first(); it; it = list.next() )
189 { 190 {
190 if ( it->getType() == MAILLIB::A_SMTP ) 191 if ( it->getType() == MAILLIB::A_SMTP )
191 { 192 {
192 smtp = static_cast<SMTPaccount *>(it); 193 smtp = static_cast<SMTPaccount *>(it);
193 smtpList.append(smtp); 194 smtpList.append(smtp);
194 } 195 }
195 } 196 }
196 if (smtpList.count()==0) 197 if (smtpList.count()==0)
197 { 198 {
198 QMessageBox::information(0,i18n("Info"),i18n("Define a smtp account first!\n")); 199 QMessageBox::information(0,i18n("Info"),i18n("Define a smtp account first!\n"));
199 return; 200 return;
200 } 201 }
201 if ( QMessageBox::warning(this, i18n("Sending all mails"), i18n("Do you really want to send\nall queued mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No ) 202 if ( QMessageBox::warning(this, i18n("Sending all mails"), i18n("Do you really want to send\nall queued mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No )
202 return; 203 return;
203 if (smtpList.count()==1) 204 if (smtpList.count()==1)
204 { 205 {
205 smtp = smtpList.at(0); 206 smtp = smtpList.at(0);
206 } 207 }
207 else 208 else
208 { 209 {
209 smtp = 0; 210 smtp = 0;
210 selectsmtp selsmtp; 211 selectsmtp selsmtp;
211 selsmtp.setSelectionlist(&smtpList); 212 selsmtp.setSelectionlist(&smtpList);
212#ifndef DESKTOP_VERSION 213#ifndef DESKTOP_VERSION
213 selsmtp.showMaximized(); 214 selsmtp.showMaximized();
214#endif 215#endif
215 if ( selsmtp.exec() == QDialog::Accepted ) 216 if ( selsmtp.exec() == QDialog::Accepted )
216 { 217 {
217 smtp = selsmtp.selected_smtp(); 218 smtp = selsmtp.selected_smtp();
218 } 219 }
219 } 220 }
220 if (smtp) 221 if (smtp)
221 { 222 {
222 223
223 Global::statusMessage("Sending mails...!"); 224 Global::statusMessage("Sending mails...!");
224 SMTPwrapper * wrap = new SMTPwrapper(smtp); 225 SMTPwrapper * wrap = new SMTPwrapper(smtp);
225 if ( wrap->flushOutbox() ) 226 if ( wrap->flushOutbox() )
226 { 227 {
227 Global::statusMessage("Mails sent!"); 228 Global::statusMessage("Mails sent!");
228 } 229 }
229 delete wrap; 230 delete wrap;
230 } 231 }
231 // pending refresh list view, if outgoing is displayed 232 // pending refresh list view, if outgoing is displayed
232} 233}
233 234
234void OpieMail::slotSearchMails() 235void OpieMail::slotSearchMails()
235{ 236{
236 qDebug("OpieMail::slotSearchMails():not implemented "); 237 qDebug("OpieMail::slotSearchMails():not implemented ");
237} 238}
238 239
239void OpieMail::slotEditSettings() 240void OpieMail::slotEditSettings()
240{ 241{
241 242
242 KOPrefsDialog settingsDialog( this, "koprefs", true ); 243 KOPrefsDialog settingsDialog( this, "koprefs", true );
243#ifndef DESKTOP_VERSION 244#ifndef DESKTOP_VERSION
244 settingsDialog.showMaximized(); 245 settingsDialog.showMaximized();
245#endif 246#endif
246 settingsDialog.exec(); 247 settingsDialog.exec();
247 248
248 slotSetCodec( KOPrefs::instance()->mCurrentCodec ); 249 slotSetCodec( KOPrefs::instance()->mCurrentCodec );
249 // KApplication::execDialog(settingsDialog); 250 // KApplication::execDialog(settingsDialog);
250} 251}
251 252
252void OpieMail::slotEditAccounts() 253void OpieMail::slotEditAccounts()
253{ 254{
254 EditAccounts eaDialog( settings, this, 0, true ); 255 EditAccounts eaDialog( settings, this, 0, true );
255 eaDialog.slotAdjustColumns(); 256 eaDialog.slotAdjustColumns();
256#ifndef DESKTOP_VERSION 257#ifndef DESKTOP_VERSION
257 eaDialog.showMaximized(); 258 eaDialog.showMaximized();
258#endif 259#endif
259 eaDialog.exec(); 260 eaDialog.exec();
260 if ( settings ) delete settings; 261 if ( settings ) delete settings;
261 settings = new Settings(); 262 settings = new Settings();
262 263
263 folderView->populate( settings->getAccounts() ); 264 folderView->populate( settings->getAccounts() );
264} 265}
265void OpieMail::replyMail() 266void OpieMail::replyMail()
266{ 267{
267 268
268 QListViewItem*item = mailView->currentItem(); 269 QListViewItem*item = mailView->currentItem();
269 if (!item) return; 270 if (!item) return;
270 RecMailP mail = ((MailListViewItem*)item)->data(); 271 RecMailP mail = ((MailListViewItem*)item)->data();
271 RecBodyP body = folderView->fetchBody(mail); 272 RecBodyP body = folderView->fetchBody(mail);
272 273
273 QString rtext; 274 QString rtext;
274 rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose 275 rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose
275 .arg( mail->getFrom()) 276 .arg( mail->getFrom())
276 .arg( mail->getDate()); 277 .arg( mail->getDate());
277 278
278 QString text = body->Bodytext(); 279 QString text = body->Bodytext();
279 QStringList lines = QStringList::split(QRegExp("\\n"), text); 280 QStringList lines = QStringList::split(QRegExp("\\n"), text);
280 QStringList::Iterator it; 281 QStringList::Iterator it;
281 for (it = lines.begin(); it != lines.end(); it++) 282 for (it = lines.begin(); it != lines.end(); it++)
282 { 283 {
283 rtext += "> " + *it + "\n"; 284 rtext += "> " + *it + "\n";
284 } 285 }
285 rtext += "\n"; 286 rtext += "\n";
286 287
287 QString prefix; 288 QString prefix;
288 if ( mail->getSubject().find(QRegExp("^Re: .*$")) != -1) prefix = ""; 289 if ( mail->getSubject().find(QRegExp("^Re: .*$")) != -1) prefix = "";
289 else prefix = "Re: "; // no i18n on purpose 290 else prefix = "Re: "; // no i18n on purpose
290 291
291 Settings *settings = new Settings(); 292 Settings *settings = new Settings();
292 ComposeMail composer( settings ,this, 0, true); 293 ComposeMail composer( settings ,this, 0, true);
293 if (mail->Replyto().isEmpty()) { 294 if (mail->Replyto().isEmpty()) {
294 composer.setTo( mail->getFrom()); 295 composer.setTo( mail->getFrom());
295 } else { 296 } else {
296 composer.setTo( mail->Replyto()); 297 composer.setTo( mail->Replyto());
297 } 298 }
298 composer.setSubject( prefix + mail->getSubject()); 299 composer.setSubject( prefix + mail->getSubject());
299 composer.setMessage( rtext ); 300 composer.setMessage( rtext );
300 composer.setInReplyTo( mail->Msgid()); 301 composer.setInReplyTo( mail->Msgid());
301 composer.setCharset( body->getCharset() ); 302 composer.setCharset( body->getCharset() );
302 if ( QDialog::Accepted == KApplication::execDialog( &composer ) ) 303 if ( QDialog::Accepted == KApplication::execDialog( &composer ) )
303 { 304 {
304 mail->Wrapper()->answeredMail(mail); 305 mail->Wrapper()->answeredMail(mail);
305 } 306 }
306 delete settings; 307 delete settings;
307 308
308} 309}
309void OpieMail::closeViewMail(ViewMail * vm) 310void OpieMail::closeViewMail(ViewMail * vm)
310{ 311{
311 vm->hide(); 312 vm->hide();
312} 313}
313 314
314void OpieMail::slotDownloadMail( ) 315void OpieMail::slotDownloadMail( )
315{ 316{
316 qDebug("slotDownloadMail( ) "); 317 QListViewItem*item = mailView->currentItem();
318 if (!item ) {
319 Global::statusMessage("Error: No item slected!");
320 return;
321 }
322 RecMailP mail = ((MailListViewItem*)item)->data();
323 Account * acc = mail->Wrapper()->getAccount();
324 if ( !acc ) {
325 Global::statusMessage("Mail is already stored locally!");
326 return;
327 }
328 QString lfName = acc->getLocalFolder();
329 //qDebug("local folder " + lfName );
330 if ( lfName.isEmpty() )
331 lfName = acc->getAccountName();
332 AbstractMail* targetMail = folderView->allAccounts()[0]->getWrapper();
333 //qDebug("target %d %d ",targetMail,mail->Wrapper() );
334 if ( targetMail == mail->Wrapper() ) {
335 Global::statusMessage("Mail is already locally stored!");
336 return;
337 }
338 if ( !targetMail->createMbox(lfName)) {
339 Global::statusMessage("Error creating folder!");
340 return;
341 }
342 Global::statusMessage("Fetching mail...please wait!");
343 qApp->processEvents();
344 encodedString*st = 0;
345 st = mail->Wrapper()->fetchRawBody(mail);
346 if ( st ) {
347 targetMail->storeMessage(st->Content(),st->Length(),lfName);
348 Global::statusMessage("Mail stored in "+ lfName);
349 delete st;
350 } else {
351 Global::statusMessage("Error: Cannot fetch mail!");
352 }
317} 353}
318 354
319 355
320void OpieMail::deleteAndDisplayNextMail(ViewMail * vm) 356void OpieMail::deleteAndDisplayNextMail(ViewMail * vm)
321{ 357{
322 QListViewItem*item = mailView->currentItem(); 358 QListViewItem*item = mailView->currentItem();
323 if (!item ) { 359 if (!item ) {
324 closeViewMail(vm); 360 closeViewMail(vm);
325 return; 361 return;
326 } 362 }
327 RecMailP mail = ((MailListViewItem*)item)->data(); 363 RecMailP mail = ((MailListViewItem*)item)->data();
328 mail->Wrapper()->deleteMail( mail ); 364 mail->Wrapper()->deleteMail( mail );
329 item = item->itemBelow(); 365 item = item->itemBelow();
330 if (!item ) { 366 if (!item ) {
331 closeViewMail(vm); 367 closeViewMail(vm);
332 return; 368 return;
333 } 369 }
334 mailView->setCurrentItem(item); 370 mailView->setCurrentItem(item);
335 mail = ((MailListViewItem*)item)->data(); 371 mail = ((MailListViewItem*)item)->data();
336 RecBodyP body = folderView->fetchBody(mail); 372 RecBodyP body = folderView->fetchBody(mail);
337 vm->setBody( body ); 373 vm->setBody( body );
338 vm->setMail( mail ); 374 vm->setMail( mail );
339} 375}
340void OpieMail::displayNextMail(ViewMail * vm) 376void OpieMail::displayNextMail(ViewMail * vm)
341{ 377{
342 QListViewItem*item = mailView->currentItem(); 378 QListViewItem*item = mailView->currentItem();
343 if (!item) return; 379 if (!item) return;
344 ( (MailListViewItem*)item )->setPixmap( 0, QPixmap() ); 380 ( (MailListViewItem*)item )->setPixmap( 0, QPixmap() );
345 item = item->itemBelow(); 381 item = item->itemBelow();
346 if (!item) { 382 if (!item) {
347 vm->setCaption(i18n("End of List" )); 383 vm->setCaption(i18n("End of List" ));
348 return; 384 return;
349 } 385 }
350 mailView->setCurrentItem(item); 386 mailView->setCurrentItem(item);
351 RecMailP mail = ((MailListViewItem*)item)->data(); 387 RecMailP mail = ((MailListViewItem*)item)->data();
352 RecBodyP body = folderView->fetchBody(mail); 388 RecBodyP body = folderView->fetchBody(mail);
353 vm->setBody( body ); 389 vm->setBody( body );
354 vm->setMail( mail ); 390 vm->setMail( mail );
355} 391}
356void OpieMail::displayMail() 392void OpieMail::displayMail()
357{ 393{
358 QListViewItem*item = mailView->currentItem(); 394 QListViewItem*item = mailView->currentItem();
359 if (!item) return; 395 if (!item) return;
360 RecMailP mail = ((MailListViewItem*)item)->data(); 396 RecMailP mail = ((MailListViewItem*)item)->data();
361 RecBodyP body = folderView->fetchBody(mail); 397 RecBodyP body = folderView->fetchBody(mail);
362 ViewMail readMail( this,"", Qt::WType_Modal ); 398 ViewMail readMail( this,"", Qt::WType_Modal );
363 readMail.setBody( body ); 399 readMail.setBody( body );
364 readMail.setMail( mail ); 400 readMail.setMail( mail );
365#ifndef DESKTOP_VERSION 401#ifndef DESKTOP_VERSION
366 readMail.showMaximized(); 402 readMail.showMaximized();
367#else 403#else
368 readMail.resize( 640, 480); 404 readMail.resize( 640, 480);
369#endif 405#endif
370 connect( &readMail,SIGNAL( showNextMail(ViewMail *) ), this, SLOT( displayNextMail(ViewMail *) ) ); 406 connect( &readMail,SIGNAL( showNextMail(ViewMail *) ), this, SLOT( displayNextMail(ViewMail *) ) );
371 connect( &readMail,SIGNAL( deleteAndDisplayNextMail(ViewMail *) ), this, SLOT(deleteAndDisplayNextMail(ViewMail *) ) ); 407 connect( &readMail,SIGNAL( deleteAndDisplayNextMail(ViewMail *) ), this, SLOT(deleteAndDisplayNextMail(ViewMail *) ) );
372 connect( &readMail,SIGNAL( signalDownloadMail() ), this, SLOT( slotDownloadMail() ) ); 408 connect( &readMail,SIGNAL( signalDownloadMail() ), this, SLOT( slotDownloadMail() ) );
373 409
374 readMail.exec(); 410 readMail.exec();
375 411
376 if ( readMail.deleted ) 412 if ( readMail.deleted )
377 { 413 {
378 folderView->refreshCurrent(); 414 folderView->refreshCurrent();
379 } 415 }
380 else 416 else
381 { 417 {
382 ( (MailListViewItem*)item )->setPixmap( 0, QPixmap() ); 418 ( (MailListViewItem*)item )->setPixmap( 0, QPixmap() );
383 } 419 }
384} 420}
385void OpieMail::slotGetAllMail() 421void OpieMail::slotGetAllMail()
386{ 422{
387 QListViewItem * item = folderView->firstChild(); 423 QListViewItem * item = folderView->firstChild();
388 while ( item ){ 424 while ( item ){
389 ((AccountViewItem *)item)->contextMenuSelected( 101 ); 425 ((AccountViewItem *)item)->contextMenuSelected( 101 );
390 item = item->nextSibling (); 426 item = item->nextSibling ();
391 } 427 }
392} 428}
393void OpieMail::slotGetMail() 429void OpieMail::slotGetMail()
394{ 430{
395 QListViewItem * item = folderView->currentItem(); 431 QListViewItem * item = folderView->currentItem();
396 if ( ! item ) return; 432 if ( ! item ) return;
397 ((AccountViewItem *)item)->contextMenuSelected( 101 ); 433 ((AccountViewItem *)item)->contextMenuSelected( 101 );
398} 434}
399void OpieMail::slotDeleteMail() 435void OpieMail::slotDeleteMail()
400{ 436{
401 if (!mailView->currentItem()) return; 437 if (!mailView->currentItem()) return;
402 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); 438 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data();
403 if ( QMessageBox::warning(this, i18n("Delete Mail"), QString( i18n("<p>Do you really want to delete this mail? <br><br>" ) + mail->getFrom() + " - " + mail->getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) 439 if ( QMessageBox::warning(this, i18n("Delete Mail"), QString( i18n("<p>Do you really want to delete this mail? <br><br>" ) + mail->getFrom() + " - " + mail->getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
404 { 440 {
405 mail->Wrapper()->deleteMail( mail ); 441 mail->Wrapper()->deleteMail( mail );
406 folderView->refreshCurrent(); 442 folderView->refreshCurrent();
407 } 443 }
408} 444}
409void OpieMail::slotDeleteAllMail() 445void OpieMail::slotDeleteAllMail()
410{ 446{
411 447
412 QValueList<RecMailP> t; 448 QValueList<RecMailP> t;
413 if ( QMessageBox::warning(this, i18n("Delete All Mails"), i18n("Do you really want to delete\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) 449 if ( QMessageBox::warning(this, i18n("Delete All Mails"), i18n("Do you really want to delete\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
414 { 450 {
415 MailListViewItem* item = (MailListViewItem*)mailView->firstChild (); 451 MailListViewItem* item = (MailListViewItem*)mailView->firstChild ();
416 while ( item ) { 452 while ( item ) {
417 if ( item->isSelected() ) { 453 if ( item->isSelected() ) {
418 t.append( item->data() ); 454 t.append( item->data() );
419 } 455 }
420 item = (MailListViewItem*)item->nextSibling(); 456 item = (MailListViewItem*)item->nextSibling();
421 } 457 }
422 } 458 }
423 else 459 else
424 return; 460 return;
425 if ( t.count() == 0 ) 461 if ( t.count() == 0 )
426 return; 462 return;
427 RecMailP mail = t.first(); 463 RecMailP mail = t.first();
428 mail->Wrapper()->deleteMailList(t); 464 mail->Wrapper()->deleteMailList(t);
429 folderView->refreshCurrent(); 465 folderView->refreshCurrent();
430 466
431 467
432} 468}
433void OpieMail::clearSelection() 469void OpieMail::clearSelection()
434{ 470{
435 mailView->clearSelection(); 471 mailView->clearSelection();
436 472
437} 473}
438 474
439void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int ) 475void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int )
440{ 476{
441 if (!mailView->currentItem()) return; 477 if (!mailView->currentItem()) return;
442 MAILLIB::ATYPE mailtype = ((MailListViewItem*)mailView->currentItem() )->wrapperType(); 478 MAILLIB::ATYPE mailtype = ((MailListViewItem*)mailView->currentItem() )->wrapperType();
443 /* just the RIGHT button - or hold on pda */ 479 /* just the RIGHT button - or hold on pda */
444 if (button!=2) {return;} 480 if (button!=2) {return;}
445 if (!item) return; 481 if (!item) return;
446 QPopupMenu *m = new QPopupMenu(0); 482 QPopupMenu *m = new QPopupMenu(0);
447 if (m) 483 if (m)
448 { 484 {
449 if (mailtype==MAILLIB::A_NNTP) { 485 if (mailtype==MAILLIB::A_NNTP) {
450 m->insertItem(i18n("Read this posting"),this,SLOT(displayMail())); 486 m->insertItem(i18n("Read this posting"),this,SLOT(displayMail()));
451 m->insertItem(i18n("Copy this posting"),this,SLOT(slotMoveCopyMail())); 487 m->insertItem(i18n("Copy this posting"),this,SLOT(slotMoveCopyMail()));
452 m->insertSeparator(); 488 m->insertSeparator();
453 m->insertItem(i18n("Copy all selected postings"),this,SLOT(slotMoveCopyAllMail())); 489 m->insertItem(i18n("Copy all selected postings"),this,SLOT(slotMoveCopyAllMail()));
454 m->insertItem(i18n("Clear selection"),this,SLOT(clearSelection())); 490 m->insertItem(i18n("Clear selection"),this,SLOT(clearSelection()));
455 } else { 491 } else {
456 if (folderView->currentisDraft()) { 492 if (folderView->currentisDraft()) {
457 m->insertItem(i18n("Edit this mail"),this,SLOT(reEditMail())); 493 m->insertItem(i18n("Edit this mail"),this,SLOT(reEditMail()));
458 } 494 }
459 m->insertItem(i18n("Reply to this mail"),this,SLOT(replyMail())); 495 m->insertItem(i18n("Reply to this mail"),this,SLOT(replyMail()));
460 m->insertSeparator(); 496 m->insertSeparator();
461 m->insertItem(i18n("Read this mail"),this,SLOT(displayMail())); 497 m->insertItem(i18n("Read this mail"),this,SLOT(displayMail()));
462 m->insertItem(i18n("Move/Copy this mail"),this,SLOT(slotMoveCopyMail())); 498 m->insertItem(i18n("Move/Copy this mail"),this,SLOT(slotMoveCopyMail()));
463 m->insertItem(i18n("Delete this mail"),this,SLOT(slotDeleteMail())); 499 m->insertItem(i18n("Delete this mail"),this,SLOT(slotDeleteMail()));
464 m->insertSeparator(); 500 m->insertSeparator();
465 m->insertItem(i18n("Move/Copy all selected mail"),this,SLOT(slotMoveCopyAllMail())); 501 m->insertItem(i18n("Move/Copy all selected mail"),this,SLOT(slotMoveCopyAllMail()));
466 m->insertItem(i18n("Delete all selected mails"),this,SLOT(slotDeleteAllMail())); 502 m->insertItem(i18n("Delete all selected mails"),this,SLOT(slotDeleteAllMail()));
467 m->insertItem(i18n("Clear selection"),this,SLOT(clearSelection())); 503 m->insertItem(i18n("Clear selection"),this,SLOT(clearSelection()));
468 } 504 }
469 m->setFocus(); 505 m->setFocus();
470 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); 506 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) );
471 delete m; 507 delete m;
472 } 508 }
473} 509}
474 510
475void OpieMail::slotShowFolders( bool show ) 511void OpieMail::slotShowFolders( bool show )
476{ 512{
477 if ( show && folderView->isHidden() ) 513 if ( show && folderView->isHidden() )
478 { 514 {
479 folderView->show(); 515 folderView->show();
480 } 516 }
481 else if ( !show && !folderView->isHidden() ) 517 else if ( !show && !folderView->isHidden() )
482 { 518 {
483 folderView->hide(); 519 folderView->hide();
484 } 520 }
485} 521}
486 522
487void OpieMail::refreshMailView(const QValueList<RecMailP>&list) 523void OpieMail::refreshMailView(const QValueList<RecMailP>&list)
488{ 524{
489 MailListViewItem*item = 0; 525 MailListViewItem*item = 0;
490 mailView->clear(); 526 mailView->clear();
491 527
492 QValueList<RecMailP>::ConstIterator it; 528 QValueList<RecMailP>::ConstIterator it;
493 for (it = list.begin(); it != list.end();++it) 529 for (it = list.begin(); it != list.end();++it)
494 { 530 {
495 item = new MailListViewItem(mailView,item); 531 item = new MailListViewItem(mailView,item);
496 item->storeData((*it)); 532 item->storeData((*it));
497 item->showEntry(); 533 item->showEntry();
498 } 534 }
499 mailView->setSorting ( 4, false ); 535 mailView->setSorting ( 4, false );
500} 536}
501 537
502void OpieMail::mailLeftClicked( QListViewItem *item ) 538void OpieMail::mailLeftClicked( QListViewItem *item )
503{ 539{
504 mailView->clearSelection(); 540 mailView->clearSelection();
505 /* just LEFT button - or tap with stylus on pda */ 541 /* just LEFT button - or tap with stylus on pda */
506 //if (button!=1) return; 542 //if (button!=1) return;
507 if (!item) return; 543 if (!item) return;
508 if (folderView->currentisDraft()) { 544 if (folderView->currentisDraft()) {
509 reEditMail(); 545 reEditMail();
510 } else { 546 } else {
511 displayMail(); 547 displayMail();
512 } 548 }
513} 549}
514 550
515void OpieMail::slotMoveCopyMail() 551void OpieMail::slotMoveCopyMail()
516{ 552{
517 if (!mailView->currentItem()) return; 553 if (!mailView->currentItem()) return;
518 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); 554 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data();
519 AbstractMail*targetMail = 0; 555 AbstractMail*targetMail = 0;
520 QString targetFolder = ""; 556 QString targetFolder = "";
521 Selectstore sels; 557 Selectstore sels;
522 folderView->setupFolderselect(&sels); 558 folderView->setupFolderselect(&sels);
523 if (!sels.exec()) return; 559 if (!sels.exec()) return;
524 targetMail = sels.currentMail(); 560 targetMail = sels.currentMail();
525 targetFolder = sels.currentFolder(); 561 targetFolder = sels.currentFolder();
526 if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) || 562 if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) ||
527 targetFolder.isEmpty()) 563 targetFolder.isEmpty())
528 { 564 {
529 return; 565 return;
530 } 566 }
531 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) 567 if (sels.newFolder() && !targetMail->createMbox(targetFolder))
532 { 568 {
533 QMessageBox::critical(0,i18n("Error creating new Folder"), 569 QMessageBox::critical(0,i18n("Error creating new Folder"),
534 i18n("<center>Error while creating<br>new folder - breaking.</center>")); 570 i18n("<center>Error while creating<br>new folder - breaking.</center>"));
535 return; 571 return;
536 } 572 }
537 sels.hide(); 573 sels.hide();
538 qApp->processEvents(); 574 qApp->processEvents();
539 // qDebug("hiding sels "); 575 // qDebug("hiding sels ");
540 mail->Wrapper()->mvcpMail(mail,targetFolder,targetMail,sels.moveMails()); 576 mail->Wrapper()->mvcpMail(mail,targetFolder,targetMail,sels.moveMails());
541 folderView->refreshCurrent(); 577 folderView->refreshCurrent();
542} 578}
543 579
544void OpieMail::slotMoveCopyAllMail() 580void OpieMail::slotMoveCopyAllMail()
545{ 581{
546 582
547 if (!mailView->currentItem()) return; 583 if (!mailView->currentItem()) return;
548 QValueList<RecMailP> t; 584 QValueList<RecMailP> t;
549 // if ( QMessageBox::warning(this, i18n("Move/Copy all selected mails"), i18n("Do you really want to copy/move\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) 585 // if ( QMessageBox::warning(this, i18n("Move/Copy all selected mails"), i18n("Do you really want to copy/move\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
550 { 586 {
551 MailListViewItem* item = (MailListViewItem*)mailView->firstChild (); 587 MailListViewItem* item = (MailListViewItem*)mailView->firstChild ();
552 while ( item ) { 588 while ( item ) {
553 if ( item->isSelected() ) { 589 if ( item->isSelected() ) {
554 t.append( item->data() ); 590 t.append( item->data() );
555 } 591 }
556 item = (MailListViewItem*)item->nextSibling(); 592 item = (MailListViewItem*)item->nextSibling();
557 } 593 }
558 } 594 }
559 // else 595 // else
560 // return; 596 // return;
561 if ( t.count() == 0 ) 597 if ( t.count() == 0 )
562 return; 598 return;
563 RecMailP mail = t.first(); 599 RecMailP mail = t.first();
564 AbstractMail*targetMail = 0; 600 AbstractMail*targetMail = 0;
565 QString targetFolder = ""; 601 QString targetFolder = "";
566 Selectstore sels; 602 Selectstore sels;
567 folderView->setupFolderselect(&sels); 603 folderView->setupFolderselect(&sels);
568 if (!sels.exec()) return; 604 if (!sels.exec()) return;
569 targetMail = sels.currentMail(); 605 targetMail = sels.currentMail();
570 targetFolder = sels.currentFolder(); 606 targetFolder = sels.currentFolder();
571 if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) || 607 if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) ||
572 targetFolder.isEmpty()) 608 targetFolder.isEmpty())
573 { 609 {
574 return; 610 return;
575 } 611 }
576 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) 612 if (sels.newFolder() && !targetMail->createMbox(targetFolder))
577 { 613 {
578 QMessageBox::critical(0,i18n("Error creating new Folder"), 614 QMessageBox::critical(0,i18n("Error creating new Folder"),
579 i18n("<center>Error while creating<br>new folder - breaking.</center>")); 615 i18n("<center>Error while creating<br>new folder - breaking.</center>"));
580 return; 616 return;
581 } 617 }
582 sels.hide(); 618 sels.hide();
583 qApp->processEvents(); 619 qApp->processEvents();
584 //qDebug("hiding sels "); 620 //qDebug("hiding sels ");
585 mail->Wrapper()->mvcpMailList(t,targetFolder,targetMail,sels.moveMails()); 621 mail->Wrapper()->mvcpMailList(t,targetFolder,targetMail,sels.moveMails());
586 folderView->refreshCurrent(); 622 folderView->refreshCurrent();
587} 623}
588 624
589void OpieMail::reEditMail() 625void OpieMail::reEditMail()
590{ 626{
591 if (!mailView->currentItem()) return; 627 if (!mailView->currentItem()) return;
592 628
593 ComposeMail compose( settings, this, 0, true ); 629 ComposeMail compose( settings, this, 0, true );
594 compose.reEditMail(((MailListViewItem*)mailView->currentItem() )->data()); 630 compose.reEditMail(((MailListViewItem*)mailView->currentItem() )->data());
595 compose.slotAdjustColumns(); 631 compose.slotAdjustColumns();
596#ifndef DESKTOP_VERSION 632#ifndef DESKTOP_VERSION
597 compose.showMaximized(); 633 compose.showMaximized();
598#else 634#else
599 compose.resize(640,480); 635 compose.resize(640,480);
600#endif 636#endif
601 compose.exec(); 637 compose.exec();
602} 638}