summaryrefslogtreecommitdiff
path: root/noncore/net/mail/opiemail.cpp
Unidiff
Diffstat (limited to 'noncore/net/mail/opiemail.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/opiemail.cpp113
1 files changed, 71 insertions, 42 deletions
diff --git a/noncore/net/mail/opiemail.cpp b/noncore/net/mail/opiemail.cpp
index 0795436..abf93dc 100644
--- a/noncore/net/mail/opiemail.cpp
+++ b/noncore/net/mail/opiemail.cpp
@@ -1,25 +1,31 @@
1#include <qmessagebox.h> 1
2#include "settingsdialog.h" 2#include "settingsdialog.h"
3#include "opiemail.h" 3#include "opiemail.h"
4#include "editaccounts.h" 4#include "editaccounts.h"
5#include "composemail.h" 5#include "composemail.h"
6#include "mailistviewitem.h"
7#include "viewmail.h"
8#include "selectstore.h"
9#include "selectsmtp.h"
10
11/* OPIE */
6#include <libmailwrapper/smtpwrapper.h> 12#include <libmailwrapper/smtpwrapper.h>
13#include <libmailwrapper/mailtypes.h>
14#include <libmailwrapper/abstractmail.h>
7#include <qpe/qcopenvelope_qws.h> 15#include <qpe/qcopenvelope_qws.h>
8#include <qpe/resource.h> 16#include <qpe/resource.h>
17#include <qpe/qpeapplication.h>
18
19/* QT */
20#include <qmessagebox.h>
9#include <qaction.h> 21#include <qaction.h>
10#include <qapplication.h> 22#include <qapplication.h>
11#include <libmailwrapper/mailtypes.h>
12#include <libmailwrapper/abstractmail.h>
13#include "mailistviewitem.h"
14#include "viewmail.h"
15#include "selectstore.h"
16#include "selectsmtp.h"
17 23
18OpieMail::OpieMail( QWidget *parent, const char *name, WFlags flags ) 24OpieMail::OpieMail( QWidget *parent, const char *name, WFlags flags )
19 : MainWindow( parent, name, WStyle_ContextHelp ) 25 : MainWindow( parent, name, WStyle_ContextHelp )
20{ 26{
21 settings = new Settings(); 27 settings = new Settings();
22 28
23 folderView->populate( settings->getAccounts() ); 29 folderView->populate( settings->getAccounts() );
24} 30}
25 31
@@ -28,36 +34,42 @@ OpieMail::~OpieMail()
28 if (settings) delete settings; 34 if (settings) delete settings;
29} 35}
30 36
31void OpieMail::appMessage(const QCString &msg, const QByteArray &data) 37void OpieMail::appMessage(const QCString &msg, const QByteArray &data)
32{ 38{
33 // copied from old mail2 39 // copied from old mail2
34 if (msg == "writeMail(QString,QString)") { 40 if (msg == "writeMail(QString,QString)")
41 {
35 QDataStream stream(data,IO_ReadOnly); 42 QDataStream stream(data,IO_ReadOnly);
36 QString name, email; 43 QString name, email;
37 stream >> name >> email; 44 stream >> name >> email;
38 // removing the whitespaces at beginning and end is needed! 45 // removing the whitespaces at beginning and end is needed!
39 slotwriteMail(name.stripWhiteSpace(),email.stripWhiteSpace()); 46 slotwriteMail(name.stripWhiteSpace(),email.stripWhiteSpace());
40 } else if (msg == "newMail()") { 47 }
48 else if (msg == "newMail()")
49 {
41 slotComposeMail(); 50 slotComposeMail();
42 } 51 }
43} 52}
44 53
45void OpieMail::slotwriteMail(const QString&name,const QString&email) 54void OpieMail::slotwriteMail(const QString&name,const QString&email)
46{ 55{
47 ComposeMail compose( settings, this, 0, true , WStyle_ContextHelp ); 56 ComposeMail compose( settings, this, 0, true , WStyle_ContextHelp );
48 if (!email.isEmpty()) { 57 if (!email.isEmpty())
49 if (!name.isEmpty()) { 58 {
59 if (!name.isEmpty())
60 {
50 compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">"); 61 compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">");
51 } else { 62 }
63 else
64 {
52 compose.setTo(email); 65 compose.setTo(email);
53 } 66 }
54 } 67 }
55 compose.showMaximized();
56 compose.slotAdjustColumns(); 68 compose.slotAdjustColumns();
57 compose.exec(); 69 QPEApplication::execDialog( &compose );
58} 70}
59 71
60void OpieMail::slotComposeMail() 72void OpieMail::slotComposeMail()
61{ 73{
62 qDebug( "Compose Mail" ); 74 qDebug( "Compose Mail" );
63 slotwriteMail(0l,0l); 75 slotwriteMail(0l,0l);
@@ -69,36 +81,44 @@ void OpieMail::slotSendQueued()
69 SMTPaccount *smtp = 0; 81 SMTPaccount *smtp = 0;
70 82
71 QList<Account> list = settings->getAccounts(); 83 QList<Account> list = settings->getAccounts();
72 QList<SMTPaccount> smtpList; 84 QList<SMTPaccount> smtpList;
73 smtpList.setAutoDelete(false); 85 smtpList.setAutoDelete(false);
74 Account *it; 86 Account *it;
75 for ( it = list.first(); it; it = list.next() ) { 87 for ( it = list.first(); it; it = list.next() )
76 if ( it->getType().compare( "SMTP" ) == 0 ) { 88 {
89 if ( it->getType().compare( "SMTP" ) == 0 )
90 {
77 smtp = static_cast<SMTPaccount *>(it); 91 smtp = static_cast<SMTPaccount *>(it);
78 smtpList.append(smtp); 92 smtpList.append(smtp);
79 } 93 }
80 } 94 }
81 if (smtpList.count()==0) { 95 if (smtpList.count()==0)
96 {
82 QMessageBox::information(0,tr("Info"),tr("Define a smtp account first")); 97 QMessageBox::information(0,tr("Info"),tr("Define a smtp account first"));
83 return; 98 return;
84 } 99 }
85 if (smtpList.count()==1) { 100 if (smtpList.count()==1)
101 {
86 smtp = smtpList.at(0); 102 smtp = smtpList.at(0);
87 } else { 103 }
104 else
105 {
88 smtp = 0; 106 smtp = 0;
89 selectsmtp selsmtp; 107 selectsmtp selsmtp;
90 selsmtp.setSelectionlist(&smtpList); 108 selsmtp.setSelectionlist(&smtpList);
91 selsmtp.showMaximized(); 109 if ( QPEApplication::execDialog( &selsmtp ) == QDialog::Accepted )
92 if (selsmtp.exec()==QDialog::Accepted) { 110 {
93 smtp = selsmtp.selected_smtp(); 111 smtp = selsmtp.selected_smtp();
94 } 112 }
95 } 113 }
96 if (smtp) { 114 if (smtp)
115 {
97 SMTPwrapper * wrap = new SMTPwrapper(smtp); 116 SMTPwrapper * wrap = new SMTPwrapper(smtp);
98 if ( wrap->flushOutbox() ) { 117 if ( wrap->flushOutbox() )
118 {
99 QMessageBox::information(0,tr("Info"),tr("Mail queue flushed")); 119 QMessageBox::information(0,tr("Info"),tr("Mail queue flushed"));
100 } 120 }
101 delete wrap; 121 delete wrap;
102 } 122 }
103} 123}
104 124
@@ -107,23 +127,21 @@ void OpieMail::slotSearchMails()
107 qDebug( "Search Mails" ); 127 qDebug( "Search Mails" );
108} 128}
109 129
110void OpieMail::slotEditSettings() 130void OpieMail::slotEditSettings()
111{ 131{
112 SettingsDialog settingsDialog( this, 0, true, WStyle_ContextHelp ); 132 SettingsDialog settingsDialog( this, 0, true, WStyle_ContextHelp );
113 settingsDialog.showMaximized(); 133 QPEApplication::execDialog( &settingsDialog );
114 settingsDialog.exec();
115} 134}
116 135
117void OpieMail::slotEditAccounts() 136void OpieMail::slotEditAccounts()
118{ 137{
119 qDebug( "Edit Accounts" ); 138 qDebug( "Edit Accounts" );
120 EditAccounts eaDialog( settings, this, 0, true, WStyle_ContextHelp ); 139 EditAccounts eaDialog( settings, this, 0, true, WStyle_ContextHelp );
121 eaDialog.showMaximized();
122 eaDialog.slotAdjustColumns(); 140 eaDialog.slotAdjustColumns();
123 eaDialog.exec(); 141 QPEApplication::execDialog( &eaDialog );
124 if ( settings ) delete settings; 142 if ( settings ) delete settings;
125 settings = new Settings(); 143 settings = new Settings();
126 144
127 folderView->populate( settings->getAccounts() ); 145 folderView->populate( settings->getAccounts() );
128} 146}
129 147
@@ -136,63 +154,72 @@ void OpieMail::displayMail()
136 ViewMail readMail( this,"", Qt::WType_Modal | WStyle_ContextHelp ); 154 ViewMail readMail( this,"", Qt::WType_Modal | WStyle_ContextHelp );
137 readMail.setBody( body ); 155 readMail.setBody( body );
138 readMail.setMail( mail ); 156 readMail.setMail( mail );
139 readMail.showMaximized(); 157 readMail.showMaximized();
140 readMail.exec(); 158 readMail.exec();
141 159
142 if ( readMail.deleted ) { 160 if ( readMail.deleted )
143 folderView->refreshCurrent(); 161 {
144 } else { 162 folderView->refreshCurrent();
163 }
164 else
165 {
145 ( (MailListViewItem*)item )->setPixmap( 0, Resource::loadPixmap( "" ) ); 166 ( (MailListViewItem*)item )->setPixmap( 0, Resource::loadPixmap( "" ) );
146 } 167 }
147} 168}
148 169
149void OpieMail::slotDeleteMail() 170void OpieMail::slotDeleteMail()
150{ 171{
151 if (!mailView->currentItem()) return; 172 if (!mailView->currentItem()) return;
152 RecMail mail = ((MailListViewItem*)mailView->currentItem() )->data(); 173 RecMail mail = ((MailListViewItem*)mailView->currentItem() )->data();
153 if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail.getFrom() + " - " + mail.getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { 174 if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail.getFrom() + " - " + mail.getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
154 mail.Wrapper()->deleteMail( mail ); 175 {
155 folderView->refreshCurrent(); 176 mail.Wrapper()->deleteMail( mail );
177 folderView->refreshCurrent();
156 } 178 }
157} 179}
158 180
159void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int ) 181void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int )
160{ 182{
161 /* just the RIGHT button - or hold on pda */ 183 /* just the RIGHT button - or hold on pda */
162 if (button!=2) {return;} 184 if (button!=2) {return;}
163 qDebug("Event right/hold"); 185 qDebug("Event right/hold");
164 if (!item) return; 186 if (!item) return;
165 QPopupMenu *m = new QPopupMenu(0); 187 QPopupMenu *m = new QPopupMenu(0);
166 if (m) { 188 if (m)
189 {
167 m->insertItem(tr("Read this mail"),this,SLOT(displayMail())); 190 m->insertItem(tr("Read this mail"),this,SLOT(displayMail()));
168 m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail())); 191 m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail()));
169 m->insertItem(tr("Copy/Move this mail"),this,SLOT(slotMoveCopyMail())); 192 m->insertItem(tr("Copy/Move this mail"),this,SLOT(slotMoveCopyMail()));
170 m->setFocus(); 193 m->setFocus();
171 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); 194 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) );
172 delete m; 195 delete m;
173 } 196 }
174} 197}
175 198
176void OpieMail::slotShowFolders( bool show ) 199void OpieMail::slotShowFolders( bool show )
177{ 200{
178 qDebug( "Show Folders" ); 201 qDebug( "Show Folders" );
179 if ( show && folderView->isHidden() ) { 202 if ( show && folderView->isHidden() )
203 {
180 qDebug( "-> showing" ); 204 qDebug( "-> showing" );
181 folderView->show(); 205 folderView->show();
182 } else if ( !show && !folderView->isHidden() ) { 206 }
207 else if ( !show && !folderView->isHidden() )
208 {
183 qDebug( "-> hiding" ); 209 qDebug( "-> hiding" );
184 folderView->hide(); 210 folderView->hide();
185 } 211 }
186} 212}
187 213
188void OpieMail::refreshMailView(QList<RecMail>*list) 214void OpieMail::refreshMailView(QList<RecMail>*list)
189{ 215{
190 MailListViewItem*item = 0; 216 MailListViewItem*item = 0;
191 mailView->clear(); 217 mailView->clear();
192 for (unsigned int i = 0; i < list->count();++i) { 218 for (unsigned int i = 0; i < list->count();++i)
219 {
193 item = new MailListViewItem(mailView,item); 220 item = new MailListViewItem(mailView,item);
194 item->storeData(*(list->at(i))); 221 item->storeData(*(list->at(i)));
195 item->showEntry(); 222 item->showEntry();
196 } 223 }
197} 224}
198 225
@@ -213,17 +240,19 @@ void OpieMail::slotMoveCopyMail()
213 Selectstore sels; 240 Selectstore sels;
214 folderView->setupFolderselect(&sels); 241 folderView->setupFolderselect(&sels);
215 if (!sels.exec()) return; 242 if (!sels.exec()) return;
216 targetMail = sels.currentMail(); 243 targetMail = sels.currentMail();
217 targetFolder = sels.currentFolder(); 244 targetFolder = sels.currentFolder();
218 if ( (mail.Wrapper()==targetMail && mail.getMbox()==targetFolder) || 245 if ( (mail.Wrapper()==targetMail && mail.getMbox()==targetFolder) ||
219 targetFolder.isEmpty()) { 246 targetFolder.isEmpty())
247 {
220 return; 248 return;
221 } 249 }
222 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) { 250 if (sels.newFolder() && !targetMail->createMbox(targetFolder))
251 {
223 QMessageBox::critical(0,tr("Error creating new Folder"), 252 QMessageBox::critical(0,tr("Error creating new Folder"),
224 tr("<center>Error while creating<br>new folder - breaking.</center>")); 253 tr("<center>Error while creating<br>new folder - breaking.</center>"));
225 return; 254 return;
226 } 255 }
227 mail.Wrapper()->mvcpMail(mail,targetFolder,targetMail,sels.moveMails()); 256 mail.Wrapper()->mvcpMail(mail,targetFolder,targetMail,sels.moveMails());
228 folderView->refreshCurrent(); 257 folderView->refreshCurrent();
229} 258}