Diffstat (limited to 'noncore/net/mailit/emailclient.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mailit/emailclient.cpp | 140 |
1 files changed, 102 insertions, 38 deletions
diff --git a/noncore/net/mailit/emailclient.cpp b/noncore/net/mailit/emailclient.cpp index dff1888..2cedc51 100644 --- a/noncore/net/mailit/emailclient.cpp +++ b/noncore/net/mailit/emailclient.cpp | |||
@@ -1,552 +1,573 @@ | |||
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 <qapplication.h> | 20 | #include <qapplication.h> |
21 | #include <qmessagebox.h> | 21 | #include <qmessagebox.h> |
22 | #include <qvbox.h> | ||
22 | #include <qfile.h> | 23 | #include <qfile.h> |
23 | #include <qcheckbox.h> | 24 | #include <qcheckbox.h> |
24 | #include <qmenubar.h> | 25 | #include <qmenubar.h> |
25 | #include <qaction.h> | 26 | #include <qaction.h> |
26 | #include <qwhatsthis.h> | 27 | #include <qwhatsthis.h> |
27 | #include <qpe/resource.h> | 28 | #include <qpe/resource.h> |
28 | #include "emailclient.h" | 29 | #include "emailclient.h" |
30 | #include "writemail.h" | ||
29 | 31 | ||
30 | QCollection::Item AccountList::newItem(QCollection::Item d) | 32 | QCollection::Item AccountList::newItem(QCollection::Item d) |
31 | { | 33 | { |
32 | return dupl( (MailAccount *) d); | 34 | return dupl( (MailAccount *) d); |
33 | } | 35 | } |
34 | 36 | ||
35 | MailAccount* AccountList::dupl(MailAccount *in) | 37 | MailAccount* AccountList::dupl(MailAccount *in) |
36 | { | 38 | { |
37 | ac = new MailAccount(*in); | 39 | ac = new MailAccount(*in); |
38 | return ac; | 40 | return ac; |
39 | } | 41 | } |
40 | 42 | ||
41 | EmailClient::EmailClient( QWidget* parent, const char* name, WFlags fl ) | 43 | EmailClient::EmailClient( QWidget* parent, const char* name, WFlags fl ) |
42 | : QMainWindow( parent, name, fl ) | 44 | : QMainWindow( parent, name, fl ) |
43 | { | 45 | { |
44 | emailHandler = new EmailHandler(); | 46 | emailHandler = new EmailHandler(); |
45 | addressList = new AddressList(); | 47 | addressList = new AddressList(); |
46 | 48 | ||
47 | sending = FALSE; | 49 | sending = FALSE; |
48 | receiving = FALSE; | 50 | receiving = FALSE; |
49 | previewingMail = FALSE; | 51 | previewingMail = FALSE; |
50 | mailIdCount = 1; | 52 | mailIdCount = 1; |
51 | accountIdCount = 1; | 53 | accountIdCount = 1; |
52 | allAccounts = FALSE; | 54 | allAccounts = FALSE; |
53 | 55 | ||
54 | init(); | 56 | init(); |
55 | 57 | ||
58 | |||
59 | |||
56 | connect(emailHandler, SIGNAL(mailSent()), this, SLOT(mailSent()) ); | 60 | connect(emailHandler, SIGNAL(mailSent()), this, SLOT(mailSent()) ); |
57 | 61 | ||
58 | connect(emailHandler, SIGNAL(smtpError(int)), this, | 62 | connect(emailHandler, SIGNAL(smtpError(int)), this, |
59 | SLOT(smtpError(int)) ); | 63 | SLOT(smtpError(int)) ); |
60 | connect(emailHandler, SIGNAL(popError(int)), this, | 64 | connect(emailHandler, SIGNAL(popError(int)), this, |
61 | SLOT(popError(int)) ); | 65 | SLOT(popError(int)) ); |
62 | 66 | ||
63 | connect(inboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(inboxItemSelected()) ); | 67 | connect(inboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(inboxItemSelected()) ); |
64 | connect(outboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(outboxItemSelected()) ); | 68 | connect(outboxView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(outboxItemSelected()) ); |
65 | 69 | ||
66 | connect(inboxView, SIGNAL(pressed(QListViewItem *)), this, SLOT(inboxItemPressed()) ); | 70 | connect(inboxView, SIGNAL(pressed(QListViewItem *)), this, SLOT(inboxItemPressed()) ); |
67 | connect(inboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(inboxItemReleased()) ); | 71 | connect(inboxView, SIGNAL(clicked(QListViewItem *)), this, SLOT(inboxItemReleased()) ); |
68 | 72 | ||
69 | |||
70 | connect(emailHandler, SIGNAL(mailArrived(const Email &, bool)), this, | 73 | connect(emailHandler, SIGNAL(mailArrived(const Email &, bool)), this, |
71 | SLOT(mailArrived(const Email &, bool)) ); | 74 | SLOT(mailArrived(const Email &, bool)) ); |
72 | connect(emailHandler, SIGNAL(mailTransfered(int)), this, | 75 | connect(emailHandler, SIGNAL(mailTransfered(int)), this, |
73 | SLOT(allMailArrived(int)) ); | 76 | SLOT(allMailArrived(int)) ); |
74 | 77 | ||
75 | mailconf = new Config("mailit"); | 78 | mailconf = new Config("mailit"); |
76 | //In case Synchronize is not defined in settings.txt | 79 | //In case Synchronize is not defined in settings.txt |
77 | 80 | ||
78 | readSettings(); | 81 | readSettings(); |
79 | 82 | ||
80 | updateAccounts(); | 83 | updateAccounts(); |
81 | 84 | ||
82 | lineShift = "\n"; | 85 | lineShift = "\n"; |
83 | readMail(); | 86 | readMail(); |
84 | lineShift = "\r\n"; | 87 | lineShift = "\r\n"; |
85 | 88 | ||
86 | mailboxView->setCurrentTab(0); //ensure that inbox has focus | 89 | mailboxView->setCurrentTab(0); //ensure that inbox has focus |
90 | |||
91 | /*channel = new QCopChannel( "QPE/Application/mailit", this ); | ||
92 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | ||
93 | this, SLOT(receive(const QCString&, const QByteArray&)) );*/ | ||
94 | |||
87 | } | 95 | } |
88 | 96 | ||
89 | 97 | ||
90 | EmailClient::~EmailClient() | 98 | EmailClient::~EmailClient() |
91 | { | 99 | { |
92 | //needs to be moved from destructor to closewindow event | 100 | //needs to be moved from destructor to closewindow event |
93 | saveMail(getPath(FALSE) + "inbox.txt", inboxView); | 101 | saveMail(getPath(FALSE) + "inbox.txt", inboxView); |
94 | //does not currently work. Defining outbox in the same | 102 | //does not currently work. Defining outbox in the same |
95 | //format as inbox is not a good solution as they have | 103 | //format as inbox is not a good solution as they have |
96 | //different properties | 104 | //different properties |
97 | saveMail(getPath(FALSE) + "outbox.txt", outboxView); | 105 | saveMail(getPath(FALSE) + "outbox.txt", outboxView); |
98 | saveSettings(); | 106 | saveSettings(); |
99 | 107 | ||
100 | mailconf->write(); | 108 | mailconf->write(); |
101 | delete mailconf; | 109 | delete mailconf; |
102 | 110 | ||
103 | } | 111 | } |
104 | 112 | ||
105 | void EmailClient::init() | 113 | void EmailClient::init() |
106 | { | 114 | { |
107 | statusBar = new QStatusBar(this); | 115 | initStatusBar(this); |
108 | statusBar->setSizeGripEnabled(FALSE); | 116 | |
109 | |||
110 | status1Label = new QLabel( tr("Idle"), statusBar); | ||
111 | status2Label = new QLabel("", statusBar); | ||
112 | connect(emailHandler, SIGNAL(updatePopStatus(const QString &)), | ||
113 | status2Label, SLOT(setText(const QString &)) ); | ||
114 | connect(emailHandler, SIGNAL(updateSmtpStatus(const QString &)), | ||
115 | status2Label, SLOT(setText(const QString &)) ); | ||
116 | |||
117 | progressBar = new QProgressBar(statusBar); | ||
118 | |||
119 | connect(emailHandler, SIGNAL(mailboxSize(int)), | ||
120 | this, SLOT(setTotalSize(int)) ); | ||
121 | connect(emailHandler, SIGNAL(currentMailSize(int)), | ||
122 | this, SLOT(setMailSize(int)) ); | ||
123 | connect(emailHandler, SIGNAL(downloadedSize(int)), | ||
124 | this, SLOT(setDownloadedSize(int)) ); | ||
125 | |||
126 | statusBar->addWidget(status1Label); | ||
127 | statusBar->addWidget(progressBar); | ||
128 | statusBar->addWidget(status2Label); | ||
129 | |||
130 | setToolBarsMovable(FALSE); | 117 | setToolBarsMovable(FALSE); |
131 | 118 | ||
132 | bar = new QToolBar(this); | 119 | bar = new QToolBar(this); |
133 | QWhatsThis::add(bar,tr("Main operation toolbar")); | 120 | QWhatsThis::add(bar,tr("Main operation toolbar")); |
134 | bar->setHorizontalStretchable( TRUE ); | 121 | bar->setHorizontalStretchable( TRUE ); |
135 | 122 | ||
136 | mb = new QMenuBar( bar ); | 123 | mb = new QMenuBar( bar ); |
137 | 124 | ||
138 | QPopupMenu *mail = new QPopupMenu(mb); | 125 | QPopupMenu *mail = new QPopupMenu(mb); |
139 | mb->insertItem( tr( "&Mail" ), mail); | 126 | mb->insertItem( tr( "&Mail" ), mail); |
140 | 127 | ||
141 | QPopupMenu *configure = new QPopupMenu(mb); | 128 | QPopupMenu *configure = new QPopupMenu(mb); |
142 | mb->insertItem( tr( "Accounts" ), configure); | 129 | mb->insertItem( tr( "Accounts" ), configure); |
143 | 130 | ||
144 | selectAccountMenu = new QPopupMenu(mb); | 131 | selectAccountMenu = new QPopupMenu(mb); |
145 | editAccountMenu = new QPopupMenu(mb); | 132 | editAccountMenu = new QPopupMenu(mb); |
146 | deleteAccountMenu = new QPopupMenu(mb); | 133 | deleteAccountMenu = new QPopupMenu(mb); |
147 | 134 | ||
148 | mail->insertItem(tr("Get Mail in"), selectAccountMenu); | 135 | mail->insertItem(tr("Get Mail in"), selectAccountMenu); |
149 | configure->insertItem(tr("Edit account"), editAccountMenu); | 136 | configure->insertItem(tr("Edit account"), editAccountMenu); |
150 | configure->insertItem(tr("Delete account"), deleteAccountMenu); | 137 | configure->insertItem(tr("Delete account"), deleteAccountMenu); |
151 | 138 | ||
152 | bar = new QToolBar(this); | 139 | bar = new QToolBar(this); |
153 | 140 | ||
154 | getMailButton = new QToolButton(Resource::loadPixmap("mailit/getmail"),tr("getMail"),tr("select account"), this,SLOT(getAllNewMail()),bar); | 141 | getMailButton = new QToolButton(Resource::loadPixmap("mailit/getmail"),tr("getMail"),tr("select account"), this,SLOT(getAllNewMail()),bar); |
155 | QWhatsThis::add(getMailButton,tr("Click to download mail via all available accounts.\n Press and hold to select the desired account.")); | 142 | QWhatsThis::add(getMailButton,tr("Click to download mail via all available accounts.\n Press and hold to select the desired account.")); |
156 | 143 | ||
157 | getMailButton->setPopup(selectAccountMenu); | 144 | getMailButton->setPopup(selectAccountMenu); |
158 | 145 | ||
159 | sendMailButton = new QAction(tr("Send mail"), Resource::loadPixmap("mailit/sendqueue"), QString::null, 0, this, 0); | 146 | sendMailButton = new QAction(tr("Send mail"), Resource::loadPixmap("mailit/sendqueue"), QString::null, 0, this, 0); |
160 | connect(sendMailButton, SIGNAL(activated()), this, SLOT(sendQuedMail()) ); | 147 | connect(sendMailButton, SIGNAL(activated()), this, SLOT(sendQuedMail()) ); |
161 | sendMailButton->addTo(bar); | 148 | sendMailButton->addTo(bar); |
162 | sendMailButton->addTo(mail); | 149 | sendMailButton->addTo(mail); |
163 | sendMailButton->setWhatsThis("Send mail queued in the outbox"); | 150 | sendMailButton->setWhatsThis("Send mail queued in the outbox"); |
164 | 151 | ||
165 | composeButton = new QAction(tr("Compose"), Resource::loadPixmap("new"), QString::null, 0, this, 0); | 152 | composeButton = new QAction(tr("Compose"), Resource::loadPixmap("new"), QString::null, 0, this, 0); |
166 | connect(composeButton, SIGNAL(activated()), this, SLOT(compose()) ); | 153 | connect(composeButton, SIGNAL(activated()), this, SLOT(compose()) ); |
167 | composeButton->addTo(bar); | 154 | composeButton->addTo(bar); |
168 | composeButton->addTo(mail); | 155 | composeButton->addTo(mail); |
169 | composeButton->setWhatsThis("Compose a new mail"); | 156 | composeButton->setWhatsThis("Compose a new mail"); |
170 | 157 | ||
171 | cancelButton = new QAction(tr("Cancel transfer"), Resource::loadPixmap("close"), QString::null, 0, this, 0); | 158 | cancelButton = new QAction(tr("Cancel transfer"), Resource::loadPixmap("close"), QString::null, 0, this, 0); |
172 | connect(cancelButton, SIGNAL(activated()), this, SLOT(cancel()) ); | 159 | connect(cancelButton, SIGNAL(activated()), this, SLOT(cancel()) ); |
173 | cancelButton->addTo(mail); | 160 | cancelButton->addTo(mail); |
174 | cancelButton->addTo(bar); | 161 | cancelButton->addTo(bar); |
175 | cancelButton->setEnabled(FALSE); | 162 | cancelButton->setEnabled(FALSE); |
176 | cancelButton->setWhatsThis("Stop the currently active mail transfer"); | 163 | cancelButton->setWhatsThis("Stop the currently active mail transfer"); |
177 | 164 | ||
178 | 165 | ||
179 | deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 ); | 166 | deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 ); |
180 | connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) ); | 167 | connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) ); |
181 | deleteButton->addTo(bar); | 168 | deleteButton->addTo(bar); |
182 | deleteButton->setWhatsThis("Remove the currently selected eMail(s)"); | 169 | deleteButton->setWhatsThis("Remove the currently selected eMail(s)"); |
183 | 170 | ||
184 | mailboxView = new OTabWidget( this, "mailboxView" ); | 171 | mailboxView = new OTabWidget( this, "mailboxView" ); |
185 | 172 | ||
186 | QWidget* widget = new QWidget( mailboxView, "widget" ); | 173 | QWidget* widget = new QWidget( mailboxView, "widget" ); |
187 | grid_2 = new QGridLayout( widget ); | 174 | grid_2 = new QGridLayout( widget ); |
188 | // grid_2->setSpacing(6); | 175 | // grid_2->setSpacing(6); |
189 | // grid_2->setMargin( 11 ); | 176 | // grid_2->setMargin( 11 ); |
190 | 177 | ||
191 | inboxView = new QListView( widget, "inboxView" ); | 178 | inboxView = new QListView( widget, "inboxView" ); |
192 | inboxView->addColumn( tr( "From" ) ); | 179 | inboxView->addColumn( tr( "From" ) ); |
193 | inboxView->addColumn( tr( "Subject" ) ); | 180 | inboxView->addColumn( tr( "Subject" ) ); |
194 | inboxView->addColumn( tr( "Date" ) ); | 181 | inboxView->addColumn( tr( "Date" ) ); |
195 | inboxView->setMinimumSize( QSize( 0, 0 ) ); | 182 | inboxView->setMinimumSize( QSize( 0, 0 ) ); |
196 | inboxView->setAllColumnsShowFocus(TRUE); | 183 | inboxView->setAllColumnsShowFocus(TRUE); |
197 | QWhatsThis::add(inboxView,QWidget::tr("This is the inbox view.\n It keeps the fetched mail which can be viewed by double clicking the entry.\n" | 184 | QWhatsThis::add(inboxView,QWidget::tr("This is the inbox view.\n" |
198 | " A blue attachment icon shows whether this mail has attachments.")); | 185 | "It keeps the fetched mail which can be \n" |
186 | "viewed by double clicking the entry.\n" | ||
187 | "blue attachment icon shows whether this \n" | ||
188 | "mailhas attachments.\n")); | ||
199 | 189 | ||
200 | grid_2->addWidget( inboxView, 2, 0 ); | 190 | grid_2->addWidget( inboxView, 2, 0 ); |
201 | mailboxView->addTab( widget, "mailit/inbox", tr( "Inbox" ) ); | 191 | mailboxView->addTab( widget, "mailit/inbox", tr( "Inbox" ) ); |
202 | 192 | ||
203 | QWidget* widget_2 = new QWidget( mailboxView, "widget_2" ); | 193 | QWidget* widget_2 = new QWidget( mailboxView, "widget_2" ); |
204 | grid_3 = new QGridLayout( widget_2 ); | 194 | grid_3 = new QGridLayout( widget_2 ); |
205 | // grid_3->setSpacing(6); | 195 | // grid_3->setSpacing(6); |
206 | // grid_3->setMargin( 11 ); | 196 | // grid_3->setMargin( 11 ); |
207 | 197 | ||
208 | outboxView = new QListView( widget_2, "outboxView" ); | 198 | outboxView = new QListView( widget_2, "outboxView" ); |
209 | outboxView->addColumn( tr( "To" ) ); | 199 | outboxView->addColumn( tr( "To" ) ); |
210 | outboxView->addColumn( tr( "Subject" ) ); | 200 | outboxView->addColumn( tr( "Subject" ) ); |
211 | outboxView->setAllColumnsShowFocus(TRUE); | 201 | outboxView->setAllColumnsShowFocus(TRUE); |
212 | 202 | ||
213 | QWhatsThis::add(outboxView,QWidget::tr("This is the oubox view.\n It keeps the queued mails to send which can be reviewed by double clicking the entry.")); | 203 | QWhatsThis::add(outboxView,QWidget::tr("This is the outbox view.\n" |
204 | "It keeps the queued mails to send which can be \n" | ||
205 | "reviewed by double clicking the entry.")); | ||
214 | grid_3->addWidget( outboxView, 0, 0 ); | 206 | grid_3->addWidget( outboxView, 0, 0 ); |
215 | mailboxView->addTab( widget_2,"mailit/outbox", tr( "Outbox" ) ); | 207 | mailboxView->addTab( widget_2,"mailit/outbox", tr( "Outbox" ) ); |
216 | 208 | ||
217 | setCentralWidget(mailboxView); | 209 | setCentralWidget(mailboxView); |
218 | 210 | ||
219 | } | 211 | } |
220 | 212 | ||
213 | void EmailClient::initStatusBar(QWidget* parent) | ||
214 | { | ||
215 | statusBar = new QStatusBar(parent); | ||
216 | statusBar->setSizeGripEnabled(FALSE); | ||
217 | |||
218 | status1Label = new QLabel( tr("Idle"), statusBar); | ||
219 | status2Label = new QLabel("", statusBar); | ||
220 | connect(emailHandler, SIGNAL(updatePopStatus(const QString &)), | ||
221 | status2Label, SLOT(setText(const QString &)) ); | ||
222 | connect(emailHandler, SIGNAL(updateSmtpStatus(const QString &)), | ||
223 | status2Label, SLOT(setText(const QString &)) ); | ||
224 | |||
225 | progressBar = new QProgressBar(statusBar); | ||
226 | |||
227 | connect(emailHandler, SIGNAL(mailboxSize(int)), | ||
228 | this, SLOT(setTotalSize(int)) ); | ||
229 | connect(emailHandler, SIGNAL(currentMailSize(int)), | ||
230 | this, SLOT(setMailSize(int)) ); | ||
231 | connect(emailHandler, SIGNAL(downloadedSize(int)), | ||
232 | this, SLOT(setDownloadedSize(int)) ); | ||
233 | |||
234 | statusBar->addWidget(status1Label); | ||
235 | statusBar->addWidget(progressBar); | ||
236 | statusBar->addWidget(status2Label); | ||
237 | |||
238 | } | ||
239 | |||
221 | void EmailClient::compose() | 240 | void EmailClient::compose() |
222 | { | 241 | { |
223 | emit composeRequested(); | 242 | emit composeRequested(); |
224 | } | 243 | } |
225 | 244 | ||
226 | void EmailClient::cancel() | 245 | void EmailClient::cancel() |
227 | { | 246 | { |
228 | emailHandler->cancel(); | 247 | emailHandler->cancel(); |
229 | } | 248 | } |
230 | 249 | ||
231 | AddressList* EmailClient::getAdrListRef() | 250 | AddressList* EmailClient::getAdrListRef() |
232 | { | 251 | { |
233 | return addressList; | 252 | return addressList; |
234 | } | 253 | } |
235 | 254 | ||
236 | //this needs to be rewritten to syncronize with outboxView | 255 | //this needs to be rewritten to syncronize with outboxView |
237 | void EmailClient::enqueMail(const Email &mail) | 256 | void EmailClient::enqueMail(const Email &mail) |
238 | { | 257 | { |
239 | if (accountList.count() == 0) { | 258 | if (accountList.count() == 0) { |
240 | QMessageBox::warning(qApp->activeWindow(), | 259 | QMessageBox::warning(qApp->activeWindow(), |
241 | tr("No account selected"), tr("You must create an account"), "OK\n"); | 260 | tr("No account selected"), tr("You must create an account"), "OK\n"); |
242 | return; | 261 | return; |
243 | } | 262 | } |
244 | 263 | ||
245 | if (accountList.count() > 0) { | 264 | if (accountList.count() > 0) { |
246 | currentAccount = accountList.first(); | 265 | currentAccount = accountList.first(); |
247 | qWarning("using account " + currentAccount->name); | 266 | qWarning("using account " + currentAccount->name); |
248 | } | 267 | } |
249 | 268 | ||
250 | Email addMail = mail; | 269 | Email addMail = mail; |
251 | addMail.from = currentAccount->name; | 270 | addMail.from = currentAccount->name; |
252 | addMail.fromMail = currentAccount->emailAddress; | 271 | addMail.fromMail = currentAccount->emailAddress; |
253 | addMail.rawMail.prepend("From: " + addMail.from + "<" + addMail.fromMail + ">\n"); | 272 | addMail.rawMail.prepend("From: " + addMail.from + "<" + addMail.fromMail + ">\n"); |
254 | item = new EmailListItem(outboxView, addMail, false); | 273 | item = new EmailListItem(outboxView, addMail, false); |
255 | 274 | ||
256 | mailboxView->setCurrentTab(1); | 275 | mailboxView->setCurrentTab(1); |
257 | 276 | ||
258 | } | 277 | } |
259 | 278 | ||
260 | void EmailClient::sendQuedMail() | 279 | void EmailClient::sendQuedMail() |
261 | { | 280 | { |
262 | int count = 0; | 281 | int count = 0; |
263 | 282 | ||
264 | if (accountList.count() == 0) { | 283 | if (accountList.count() == 0) { |
265 | QMessageBox::warning(qApp->activeWindow(), "No account selected", "You must create an account", "OK\n"); | 284 | QMessageBox::warning(qApp->activeWindow(), "No account selected", "You must create an account", "OK\n"); |
266 | return; | 285 | return; |
267 | } | 286 | } |
268 | //traverse listview, find messages to send | 287 | //traverse listview, find messages to send |
269 | if (! sending) { | 288 | if (! sending) { |
270 | item = (EmailListItem *) outboxView->firstChild(); | 289 | item = (EmailListItem *) outboxView->firstChild(); |
271 | if (item != NULL) { | 290 | if (item != NULL) { |
272 | while (item != NULL) { | 291 | while (item != NULL) { |
273 | quedMessages.append(item->getMail()); | 292 | quedMessages.append(item->getMail()); |
274 | item = (EmailListItem *) item->nextSibling(); | 293 | item = (EmailListItem *) item->nextSibling(); |
275 | count++; | 294 | count++; |
276 | } | 295 | } |
277 | setMailAccount(); | 296 | setMailAccount(); |
278 | emailHandler->sendMail(&quedMessages); | 297 | emailHandler->sendMail(&quedMessages); |
279 | sending = TRUE; | 298 | sending = TRUE; |
280 | sendMailButton->setEnabled(FALSE); | 299 | sendMailButton->setEnabled(FALSE); |
281 | cancelButton->setEnabled(TRUE); | 300 | cancelButton->setEnabled(TRUE); |
282 | } else { | 301 | } else { |
283 | qWarning("sendQuedMail(): no messages to send"); | 302 | qWarning("sendQuedMail(): no messages to send"); |
284 | } | 303 | } |
285 | } | 304 | } |
286 | } | 305 | } |
287 | 306 | ||
288 | void EmailClient::setMailAccount() | 307 | void EmailClient::setMailAccount() |
289 | { | 308 | { |
290 | emailHandler->setAccount(*currentAccount); | 309 | emailHandler->setAccount(*currentAccount); |
291 | } | 310 | } |
292 | 311 | ||
293 | void EmailClient::mailSent() | 312 | void EmailClient::mailSent() |
294 | { | 313 | { |
295 | sending = FALSE; | 314 | sending = FALSE; |
296 | sendMailButton->setEnabled(TRUE); | 315 | sendMailButton->setEnabled(TRUE); |
297 | 316 | ||
298 | quedMessages.clear(); | 317 | quedMessages.clear(); |
299 | outboxView->clear(); //should be moved to an sentBox | 318 | outboxView->clear(); //should be moved to an sentBox |
300 | } | 319 | } |
301 | 320 | ||
302 | void EmailClient::getNewMail() { | 321 | void EmailClient::getNewMail() { |
303 | 322 | ||
304 | if (accountList.count() == 0) { | 323 | if (accountList.count() == 0) { |
305 | QMessageBox::warning(qApp->activeWindow(),"No account selected", | 324 | QMessageBox::warning(qApp->activeWindow(),"No account selected", |
306 | "You must create an account", "OK\n"); | 325 | "You must create an account", "OK\n"); |
307 | return; | 326 | return; |
308 | } | 327 | } |
309 | 328 | ||
310 | setMailAccount(); | 329 | setMailAccount(); |
311 | 330 | ||
312 | receiving = TRUE; | 331 | receiving = TRUE; |
313 | previewingMail = TRUE; | 332 | previewingMail = TRUE; |
314 | getMailButton->setEnabled(FALSE); | 333 | getMailButton->setEnabled(FALSE); |
315 | cancelButton->setEnabled(TRUE); | 334 | cancelButton->setEnabled(TRUE); |
316 | selectAccountMenu->setEnabled(FALSE); | 335 | selectAccountMenu->setEnabled(FALSE); |
317 | 336 | ||
318 | status1Label->setText(currentAccount->accountName + " headers"); | 337 | status1Label->setText(currentAccount->accountName + " headers"); |
319 | progressBar->reset(); | 338 | progressBar->reset(); |
320 | 339 | ||
321 | //get any previous mails not downloaded and add to queue | 340 | //get any previous mails not downloaded and add to queue |
322 | mailDownloadList.clear(); | 341 | /*mailDownloadList.clear(); |
323 | Email *mailPtr; | 342 | Email *mailPtr; |
324 | item = (EmailListItem *) inboxView->firstChild(); | 343 | item = (EmailListItem *) inboxView->firstChild(); |
325 | while (item != NULL) { | 344 | while (item != NULL) { |
326 | mailPtr = item->getMail(); | 345 | mailPtr = item->getMail(); |
327 | if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) { | 346 | if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) { |
328 | mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size); | 347 | mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size); |
329 | } | 348 | } |
330 | item = (EmailListItem *) item->nextSibling(); | 349 | item = (EmailListItem *) item->nextSibling(); |
331 | } | 350 | }*/ |
332 | 351 | ||
333 | emailHandler->getMailHeaders(); | 352 | emailHandler->getMailHeaders(); |
334 | 353 | ||
335 | } | 354 | } |
336 | 355 | ||
337 | void EmailClient::getAllNewMail() | 356 | void EmailClient::getAllNewMail() |
338 | { | 357 | { |
339 | allAccounts = TRUE; | 358 | allAccounts = TRUE; |
340 | currentAccount = accountList.first(); | 359 | currentAccount = accountList.first(); |
341 | getNewMail(); | 360 | getNewMail(); |
342 | } | 361 | } |
343 | 362 | ||
344 | void EmailClient::mailArrived(const Email &mail, bool fromDisk) | 363 | void EmailClient::mailArrived(const Email &mail, bool fromDisk) |
345 | { | 364 | { |
346 | Enclosure *ePtr; | 365 | Enclosure *ePtr; |
347 | Email newMail; | 366 | Email newMail; |
348 | int thisMailId; | 367 | int thisMailId; |
349 | emailHandler->parse(mail.rawMail, lineShift, &newMail); | 368 | emailHandler->parse(mail.rawMail, lineShift, &newMail); |
350 | mailconf->setGroup(newMail.id); | 369 | mailconf->setGroup(newMail.id); |
351 | 370 | ||
352 | if (fromDisk) | 371 | if (fromDisk) |
353 | { | 372 | { |
373 | |||
354 | newMail.downloaded = mailconf->readBoolEntry("downloaded"); | 374 | newMail.downloaded = mailconf->readBoolEntry("downloaded"); |
355 | newMail.size = mailconf->readNumEntry("size"); | 375 | newMail.size = mailconf->readNumEntry("size"); |
356 | newMail.serverId = mailconf->readNumEntry("serverid"); | 376 | newMail.serverId = mailconf->readNumEntry("serverid"); |
357 | newMail.fromAccountId = mailconf->readNumEntry("fromaccountid"); | 377 | newMail.fromAccountId = mailconf->readNumEntry("fromaccountid"); |
358 | } | 378 | } |
359 | else | 379 | else |
360 | { //mail arrived from server | 380 | { //mail arrived from server |
381 | |||
361 | newMail.serverId = mail.serverId; | 382 | newMail.serverId = mail.serverId; |
362 | newMail.size = mail.size; | 383 | newMail.size = mail.size; |
363 | newMail.downloaded = mail.downloaded; | 384 | newMail.downloaded = mail.downloaded; |
364 | 385 | ||
365 | newMail.fromAccountId = emailHandler->getAccount()->id; | 386 | newMail.fromAccountId = emailHandler->getAccount()->id; |
366 | mailconf->writeEntry("fromaccountid", newMail.fromAccountId); | 387 | mailconf->writeEntry("fromaccountid", newMail.fromAccountId); |
367 | } | 388 | } |
368 | 389 | ||
369 | //add if read or not | 390 | //add if read or not |
370 | newMail.read = mailconf->readBoolEntry("mailread"); | 391 | newMail.read = mailconf->readBoolEntry("mailread"); |
371 | 392 | ||
372 | //check if new mail | 393 | //check if new mail |
373 | if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) { | 394 | if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) { |
374 | thisMailId = mailIdCount; | 395 | thisMailId = mailIdCount; |
375 | mailIdCount++; | 396 | mailIdCount++; |
376 | 397 | ||
377 | //set server count, so that if the user aborts, the new | 398 | //set server count, so that if the user aborts, the new |
378 | //header is not reloaded | 399 | //header is not reloaded |
379 | if ((currentAccount)&&(currentAccount->synchronize)) | 400 | if ((currentAccount)&&(currentAccount->synchronize)) |
380 | currentAccount->lastServerMailCount++; | 401 | currentAccount->lastServerMailCount++; |
381 | 402 | ||
382 | mailconf->writeEntry("internalmailid", thisMailId); | 403 | mailconf->writeEntry("internalmailid", thisMailId); |
383 | mailconf->writeEntry("downloaded", newMail.downloaded); | 404 | mailconf->writeEntry("downloaded", newMail.downloaded); |
384 | mailconf->writeEntry("size", (int) newMail.size); | 405 | mailconf->writeEntry("size", (int) newMail.size); |
385 | mailconf->writeEntry("serverid", newMail.serverId); | 406 | mailconf->writeEntry("serverid", newMail.serverId); |
386 | 407 | ||
387 | //addressList->addContact(newMail.fromMail, newMail.from); | 408 | //addressList->addContact(newMail.fromMail, newMail.from); |
388 | } | 409 | } |
389 | 410 | ||
390 | mailconf->writeEntry("downloaded", newMail.downloaded); | 411 | mailconf->writeEntry("downloaded", newMail.downloaded); |
391 | 412 | ||
392 | QString stringMailId; | 413 | QString stringMailId; |
393 | stringMailId.setNum(thisMailId); | 414 | stringMailId.setNum(thisMailId); |
394 | //see if any attatchments needs to be stored | 415 | //see if any attatchments needs to be stored |
395 | 416 | ||
396 | for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) { | 417 | for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) { |
397 | QString stringId; | 418 | QString stringId; |
398 | stringId.setNum(ePtr->id); | 419 | stringId.setNum(ePtr->id); |
399 | 420 | ||
400 | int id = mailconf->readNumEntry("enclosureid_" + stringId); | 421 | int id = mailconf->readNumEntry("enclosureid_" + stringId); |
401 | if (id != ePtr->id) { //new entry | 422 | if (id != ePtr->id) { //new entry |
402 | mailconf->writeEntry("enclosureid_" + stringId, ePtr->id); | 423 | mailconf->writeEntry("enclosureid_" + stringId, ePtr->id); |
403 | mailconf->writeEntry("name_" + stringId, ePtr->originalName); | 424 | mailconf->writeEntry("name_" + stringId, ePtr->originalName); |
404 | mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType); | 425 | mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType); |
405 | mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute); | 426 | mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute); |
406 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); | 427 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); |
407 | mailconf->writeEntry("installed_" + stringId, FALSE); | 428 | mailconf->writeEntry("installed_" + stringId, FALSE); |
408 | 429 | ||
409 | ePtr->name = stringMailId + "_" + stringId; | 430 | ePtr->name = stringMailId + "_" + stringId; |
410 | ePtr->path = getPath(TRUE); | 431 | ePtr->path = getPath(TRUE); |
411 | if (emailHandler->getEnclosure(ePtr)) { //file saved | 432 | if (emailHandler->getEnclosure(ePtr)) { //file saved |
412 | ePtr->saved = TRUE; | 433 | ePtr->saved = TRUE; |
413 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); | 434 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); |
414 | mailconf->writeEntry("filename_" + stringId, ePtr->name); | 435 | mailconf->writeEntry("filename_" + stringId, ePtr->name); |
415 | mailconf->writeEntry("path_" + stringId, ePtr->path); | 436 | mailconf->writeEntry("path_" + stringId, ePtr->path); |
416 | } else { | 437 | } else { |
417 | ePtr->saved = FALSE; | 438 | ePtr->saved = FALSE; |
418 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); | 439 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); |
419 | } | 440 | } |
420 | } else { | 441 | } else { |
421 | ePtr->saved = mailconf->readBoolEntry("saved_" + stringId); | 442 | ePtr->saved = mailconf->readBoolEntry("saved_" + stringId); |
422 | ePtr->installed = mailconf->readBoolEntry("installed_" + stringId); | 443 | ePtr->installed = mailconf->readBoolEntry("installed_" + stringId); |
423 | if (ePtr->saved) { | 444 | if (ePtr->saved) { |
424 | ePtr->name = mailconf->readEntry("filename_" + stringId); | 445 | ePtr->name = mailconf->readEntry("filename_" + stringId); |
425 | ePtr->path = mailconf->readEntry("path_" + stringId); | 446 | ePtr->path = mailconf->readEntry("path_" + stringId); |
426 | } | 447 | } |
427 | } | 448 | } |
428 | } | 449 | } |
429 | 450 | ||
430 | bool found=false; | 451 | bool found=false; |
431 | 452 | ||
432 | if (!fromDisk) | 453 | if (!fromDisk) |
433 | { | 454 | { |
434 | 455 | ||
435 | Email *mailPtr; | 456 | Email *mailPtr; |
436 | item = (EmailListItem *) inboxView->firstChild(); | 457 | item = (EmailListItem *) inboxView->firstChild(); |
437 | while ((item != NULL)&&(!found)) | 458 | while ((item != NULL)&&(!found)) |
438 | { | 459 | { |
439 | mailPtr = item->getMail(); | 460 | mailPtr = item->getMail(); |
440 | if (mailPtr->id == newMail.id) { | 461 | if (mailPtr->id == newMail.id) { |
441 | item->setMail(newMail); | 462 | item->setMail(newMail); |
442 | emit mailUpdated(item->getMail()); | 463 | emit mailUpdated(item->getMail()); |
443 | found = true; | 464 | found = true; |
444 | } | 465 | } |
445 | item = (EmailListItem *) item->nextSibling(); | 466 | item = (EmailListItem *) item->nextSibling(); |
446 | } | 467 | } |
447 | } | 468 | } |
448 | if ((!found)||(fromDisk)) item = new EmailListItem(inboxView, newMail, TRUE); | 469 | if ((!found)||(fromDisk)) item = new EmailListItem(inboxView, newMail, TRUE); |
449 | 470 | ||
450 | /*if (!newMail.downloaded) | 471 | /*if (!newMail.downloaded) |
451 | mailDownloadList.sizeInsert(newMail.serverId, newMail.size);*/ | 472 | mailDownloadList.sizeInsert(newMail.serverId, newMail.size);*/ |
452 | 473 | ||
453 | mailboxView->setCurrentTab(0); | 474 | mailboxView->setCurrentTab(0); |
454 | 475 | ||
455 | } | 476 | } |
456 | 477 | ||
457 | void EmailClient::allMailArrived(int count) | 478 | void EmailClient::allMailArrived(int count) |
458 | { | 479 | { |
459 | // not previewing means all mailtransfer has been done | 480 | // not previewing means all mailtransfer has been done |
460 | /*if (!previewingMail) {*/ | 481 | /*if (!previewingMail) {*/ |
461 | if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { | 482 | if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { |
462 | emit newCaption("Mailit - " + currentAccount->accountName); | 483 | emit newCaption("Mailit - " + currentAccount->accountName); |
463 | getNewMail(); | 484 | getNewMail(); |
464 | return; | 485 | return; |
465 | } else { | 486 | } else { |
466 | allAccounts = FALSE; | 487 | allAccounts = FALSE; |
467 | receiving = FALSE; | 488 | receiving = FALSE; |
468 | getMailButton->setEnabled(TRUE); | 489 | getMailButton->setEnabled(TRUE); |
469 | cancelButton->setEnabled(FALSE); | 490 | cancelButton->setEnabled(FALSE); |
470 | selectAccountMenu->setEnabled(TRUE); | 491 | selectAccountMenu->setEnabled(TRUE); |
471 | status1Label->setText("Idle"); | 492 | status1Label->setText("Idle"); |
472 | 493 | ||
473 | progressBar->reset(); | 494 | progressBar->reset(); |
474 | return; | 495 | return; |
475 | } | 496 | } |
476 | //} | 497 | //} |
477 | 498 | ||
478 | // all headers downloaded from server, start downloading remaining mails | 499 | // all headers downloaded from server, start downloading remaining mails |
479 | previewingMail = FALSE; | 500 | previewingMail = FALSE; |
480 | status1Label->setText(currentAccount->accountName); | 501 | status1Label->setText(currentAccount->accountName); |
481 | progressBar->reset(); | 502 | progressBar->reset(); |
482 | 503 | ||
483 | 504 | ||
484 | mailboxView->setCurrentTab(0); | 505 | mailboxView->setCurrentTab(0); |
485 | } | 506 | } |
486 | 507 | ||
487 | 508 | ||
488 | void EmailClient::moveMailFront(Email *mailPtr) | 509 | void EmailClient::moveMailFront(Email *mailPtr) |
489 | { | 510 | { |
490 | if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) { | 511 | if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) { |
491 | mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size); | 512 | mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size); |
492 | } | 513 | } |
493 | } | 514 | } |
494 | 515 | ||
495 | void EmailClient::smtpError(int code) | 516 | void EmailClient::smtpError(int code) |
496 | { | 517 | { |
497 | QString temp; | 518 | QString temp; |
498 | 519 | ||
499 | if (code == ErrUnknownResponse) | 520 | if (code == ErrUnknownResponse) |
500 | temp = "Unknown response from server"; | 521 | temp = "Unknown response from server"; |
501 | 522 | ||
502 | if (code == QSocket::ErrHostNotFound) | 523 | if (code == QSocket::ErrHostNotFound) |
503 | temp = "host not found"; | 524 | temp = "host not found"; |
504 | if (code == QSocket::ErrConnectionRefused) | 525 | if (code == QSocket::ErrConnectionRefused) |
505 | temp = "connection refused"; | 526 | temp = "connection refused"; |
506 | if (code == QSocket::ErrSocketRead) | 527 | if (code == QSocket::ErrSocketRead) |
507 | temp = "socket packet error"; | 528 | temp = "socket packet error"; |
508 | 529 | ||
509 | if (code != ErrCancel) { | 530 | if (code != ErrCancel) { |
510 | QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n"); | 531 | QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n"); |
511 | } else { | 532 | } else { |
512 | status2Label->setText("Aborted by user"); | 533 | status2Label->setText("Aborted by user"); |
513 | } | 534 | } |
514 | 535 | ||
515 | sending = FALSE; | 536 | sending = FALSE; |
516 | sendMailButton->setEnabled(TRUE); | 537 | sendMailButton->setEnabled(TRUE); |
517 | cancelButton->setEnabled(FALSE); | 538 | cancelButton->setEnabled(FALSE); |
518 | quedMessages.clear(); | 539 | quedMessages.clear(); |
519 | } | 540 | } |
520 | 541 | ||
521 | void EmailClient::popError(int code) | 542 | void EmailClient::popError(int code) |
522 | { | 543 | { |
523 | QString temp; | 544 | QString temp; |
524 | 545 | ||
525 | if (code == ErrUnknownResponse) | 546 | if (code == ErrUnknownResponse) |
526 | temp = "Unknown response from server"; | 547 | temp = "Unknown response from server"; |
527 | if (code == ErrLoginFailed) | 548 | if (code == ErrLoginFailed) |
528 | temp = "Login failed\nCheck user name and password"; | 549 | temp = "Login failed\nCheck user name and password"; |
529 | 550 | ||
530 | if (code == QSocket::ErrHostNotFound) | 551 | if (code == QSocket::ErrHostNotFound) |
531 | temp = "host not found"; | 552 | temp = "host not found"; |
532 | if (code == QSocket::ErrConnectionRefused) | 553 | if (code == QSocket::ErrConnectionRefused) |
533 | temp = "connection refused"; | 554 | temp = "connection refused"; |
534 | if (code == QSocket::ErrSocketRead) | 555 | if (code == QSocket::ErrSocketRead) |
535 | temp = "socket packet error"; | 556 | temp = "socket packet error"; |
536 | 557 | ||
537 | if (code != ErrCancel) { | 558 | if (code != ErrCancel) { |
538 | QMessageBox::warning(qApp->activeWindow(), "Receiving error", temp, "OK\n"); | 559 | QMessageBox::warning(qApp->activeWindow(), "Receiving error", temp, "OK\n"); |
539 | } else { | 560 | } else { |
540 | status2Label->setText("Aborted by user"); | 561 | status2Label->setText("Aborted by user"); |
541 | } | 562 | } |
542 | 563 | ||
543 | receiving = FALSE; | 564 | receiving = FALSE; |
544 | getMailButton->setEnabled(TRUE); | 565 | getMailButton->setEnabled(TRUE); |
545 | cancelButton->setEnabled(FALSE); | 566 | cancelButton->setEnabled(FALSE); |
546 | selectAccountMenu->setEnabled(TRUE); | 567 | selectAccountMenu->setEnabled(TRUE); |
547 | } | 568 | } |
548 | 569 | ||
549 | void EmailClient::inboxItemSelected() | 570 | void EmailClient::inboxItemSelected() |
550 | { | 571 | { |
551 | //killTimer(timerID); | 572 | //killTimer(timerID); |
552 | 573 | ||
@@ -729,240 +750,283 @@ void EmailClient::saveSettings() | |||
729 | mailconf->writeEntry("POPServer",accountPtr->popServer); | 750 | mailconf->writeEntry("POPServer",accountPtr->popServer); |
730 | mailconf->writeEntry("SMTPServer",accountPtr->smtpServer); | 751 | mailconf->writeEntry("SMTPServer",accountPtr->smtpServer); |
731 | mailconf->writeEntry("AccountId",accountPtr->id); | 752 | mailconf->writeEntry("AccountId",accountPtr->id); |
732 | if (accountPtr->synchronize) | 753 | if (accountPtr->synchronize) |
733 | { | 754 | { |
734 | mailconf->writeEntry("Synchronize","Yes"); | 755 | mailconf->writeEntry("Synchronize","Yes"); |
735 | mailconf->writeEntry("HeaderLimit",accountPtr->syncLimit); | 756 | mailconf->writeEntry("HeaderLimit",accountPtr->syncLimit); |
736 | mailconf->writeEntry("LastServerMailCount",accountPtr->lastServerMailCount); | 757 | mailconf->writeEntry("LastServerMailCount",accountPtr->lastServerMailCount); |
737 | } | 758 | } |
738 | else | 759 | else |
739 | { | 760 | { |
740 | mailconf->writeEntry("Synchronize", "No"); | 761 | mailconf->writeEntry("Synchronize", "No"); |
741 | } | 762 | } |
742 | } | 763 | } |
743 | 764 | ||
744 | mailconf->setGroup("mailitglobal"); | 765 | mailconf->setGroup("mailitglobal"); |
745 | mailconf->writeEntry("Accounts",acc_count); | 766 | mailconf->writeEntry("Accounts",acc_count); |
746 | mailconf->writeEntry("mailidcount", mailIdCount); | 767 | mailconf->writeEntry("mailidcount", mailIdCount); |
747 | mailconf->writeEntry("accountidcount", accountIdCount); | 768 | mailconf->writeEntry("accountidcount", accountIdCount); |
748 | } | 769 | } |
749 | 770 | ||
750 | void EmailClient::selectAccount(int id) | 771 | void EmailClient::selectAccount(int id) |
751 | { | 772 | { |
752 | if (accountList.count() > 0) { | 773 | if (accountList.count() > 0) { |
753 | currentAccount = accountList.at(id); | 774 | currentAccount = accountList.at(id); |
754 | emit newCaption("Mailit - " + currentAccount->accountName); | 775 | emit newCaption("Mailit - " + currentAccount->accountName); |
755 | getNewMail(); | 776 | getNewMail(); |
756 | } else { | 777 | } else { |
757 | emit newCaption("Mailit ! No account defined"); | 778 | emit newCaption("Mailit ! No account defined"); |
758 | } | 779 | } |
759 | } | 780 | } |
760 | 781 | ||
761 | void EmailClient::editAccount(int id) | 782 | void EmailClient::editAccount(int id) |
762 | { | 783 | { |
763 | MailAccount *newAccount; | 784 | MailAccount *newAccount; |
764 | 785 | ||
765 | editAccountView = new EditAccount(this, "account", TRUE); | 786 | editAccountView = new EditAccount(this, "account", TRUE); |
766 | if (id == newAccountId) { //new account | 787 | if (id == newAccountId) { //new account |
767 | newAccount = new MailAccount; | 788 | newAccount = new MailAccount; |
768 | editAccountView->setAccount(newAccount); | 789 | editAccountView->setAccount(newAccount); |
769 | } else { | 790 | } else { |
770 | newAccount = accountList.at(id); | 791 | newAccount = accountList.at(id); |
771 | editAccountView->setAccount(newAccount, FALSE); | 792 | editAccountView->setAccount(newAccount, FALSE); |
772 | } | 793 | } |
773 | 794 | ||
774 | editAccountView->showMaximized(); | 795 | editAccountView->showMaximized(); |
775 | editAccountView->exec(); | 796 | editAccountView->exec(); |
776 | 797 | ||
777 | if (editAccountView->result() == QDialog::Accepted) { | 798 | if (editAccountView->result() == QDialog::Accepted) { |
778 | if (id == newAccountId) { | 799 | if (id == newAccountId) { |
779 | newAccount->id = accountIdCount; | 800 | newAccount->id = accountIdCount; |
780 | accountIdCount++; | 801 | accountIdCount++; |
781 | accountList.append(newAccount); | 802 | accountList.append(newAccount); |
782 | updateAccounts(); | 803 | updateAccounts(); |
783 | } else { | 804 | } else { |
784 | updateAccounts(); | 805 | updateAccounts(); |
785 | } | 806 | } |
786 | } | 807 | } |
787 | 808 | ||
788 | delete editAccountView; | 809 | delete editAccountView; |
789 | } | 810 | } |
790 | 811 | ||
791 | void EmailClient::deleteAccount(int id) | 812 | void EmailClient::deleteAccount(int id) |
792 | { | 813 | { |
793 | MailAccount *newAccount; | 814 | MailAccount *newAccount; |
794 | QString message; | 815 | QString message; |
795 | 816 | ||
796 | newAccount = accountList.at(id); | 817 | newAccount = accountList.at(id); |
797 | message = "Delete account:\n" + newAccount->accountName; | 818 | message = "Delete account:\n" + newAccount->accountName; |
798 | switch( QMessageBox::warning( this, "Mailit", message, | 819 | switch( QMessageBox::warning( this, "Mailit", message, |
799 | "Yes", "No", 0, 0, 1 ) ) { | 820 | "Yes", "No", 0, 0, 1 ) ) { |
800 | 821 | ||
801 | case 0: accountList.remove(id); | 822 | case 0: accountList.remove(id); |
802 | updateAccounts(); | 823 | updateAccounts(); |
803 | break; | 824 | break; |
804 | case 1: | 825 | case 1: |
805 | break; | 826 | break; |
806 | } | 827 | } |
807 | } | 828 | } |
808 | 829 | ||
809 | void EmailClient::updateAccounts() | 830 | void EmailClient::updateAccounts() |
810 | { | 831 | { |
811 | MailAccount *accountPtr; | 832 | MailAccount *accountPtr; |
812 | 833 | ||
813 | //rebuild menus, clear all first | 834 | //rebuild menus, clear all first |
814 | editAccountMenu->clear(); | 835 | editAccountMenu->clear(); |
815 | selectAccountMenu->clear(); | 836 | selectAccountMenu->clear(); |
816 | deleteAccountMenu->clear(); | 837 | deleteAccountMenu->clear(); |
817 | 838 | ||
818 | newAccountId = editAccountMenu->insertItem("New", this, | 839 | newAccountId = editAccountMenu->insertItem("New", this, |
819 | SLOT(editAccount(int)) ); | 840 | SLOT(editAccount(int)) ); |
820 | editAccountMenu->insertSeparator(); | 841 | editAccountMenu->insertSeparator(); |
821 | 842 | ||
822 | idCount = 0; | 843 | idCount = 0; |
823 | for (accountPtr = accountList.first(); accountPtr != 0; | 844 | for (accountPtr = accountList.first(); accountPtr != 0; |
824 | accountPtr = accountList.next()) { | 845 | accountPtr = accountList.next()) { |
825 | 846 | ||
826 | editAccountMenu->insertItem(accountPtr->accountName, | 847 | editAccountMenu->insertItem(accountPtr->accountName, |
827 | this, SLOT(editAccount(int)), 0, idCount); | 848 | this, SLOT(editAccount(int)), 0, idCount); |
828 | selectAccountMenu->insertItem(accountPtr->accountName, | 849 | selectAccountMenu->insertItem(accountPtr->accountName, |
829 | this, SLOT(selectAccount(int)), 0, idCount); | 850 | this, SLOT(selectAccount(int)), 0, idCount); |
830 | deleteAccountMenu->insertItem(accountPtr->accountName, | 851 | deleteAccountMenu->insertItem(accountPtr->accountName, |
831 | this, SLOT(deleteAccount(int)), 0, idCount); | 852 | this, SLOT(deleteAccount(int)), 0, idCount); |
832 | idCount++; | 853 | idCount++; |
833 | } | 854 | } |
834 | } | 855 | } |
835 | 856 | ||
836 | void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox) | 857 | void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox) |
837 | { | 858 | { |
838 | Email *mPtr; | 859 | Email *mPtr; |
839 | Enclosure *ePtr; | 860 | Enclosure *ePtr; |
840 | 861 | ||
841 | if (inbox) | 862 | if (inbox) |
842 | { | 863 | { |
843 | mPtr = mailItem->getMail(); | 864 | mPtr = mailItem->getMail(); |
844 | 865 | ||
845 | //if mail is in queue for download, remove it from | 866 | //if mail is in queue for download, remove it from |
846 | //queue if possible | 867 | //queue if possible |
847 | if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) { | 868 | if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) { |
848 | if ( !mPtr->downloaded ) | 869 | if ( !mPtr->downloaded ) |
849 | mailDownloadList.remove(mPtr->serverId, mPtr->size); | 870 | mailDownloadList.remove(mPtr->serverId, mPtr->size); |
850 | } | 871 | } |
851 | 872 | ||
852 | mailconf->setGroup(mPtr->id); | 873 | mailconf->setGroup(mPtr->id); |
853 | mailconf->clearGroup(); | 874 | mailconf->clearGroup(); |
854 | 875 | ||
855 | //delete any temporary attatchemnts storing | 876 | //delete any temporary attatchemnts storing |
856 | for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) { | 877 | for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) { |
857 | if (ePtr->saved) { | 878 | if (ePtr->saved) { |
858 | QFile::remove( (ePtr->path + ePtr->name) ); | 879 | QFile::remove( (ePtr->path + ePtr->name) ); |
859 | } | 880 | } |
860 | } | 881 | } |
861 | inboxView->takeItem(mailItem); | 882 | inboxView->takeItem(mailItem); |
862 | } | 883 | } |
863 | else | 884 | else |
864 | { | 885 | { |
865 | outboxView->takeItem(mailItem); | 886 | outboxView->takeItem(mailItem); |
866 | } | 887 | } |
867 | } | 888 | } |
868 | 889 | ||
869 | void EmailClient::setMailSize(int size) | 890 | void EmailClient::setMailSize(int size) |
870 | { | 891 | { |
871 | progressBar->reset(); | 892 | progressBar->reset(); |
872 | progressBar->setTotalSteps(size); | 893 | progressBar->setTotalSteps(size); |
873 | } | 894 | } |
874 | 895 | ||
875 | void EmailClient::setTotalSize(int size) | 896 | void EmailClient::setTotalSize(int size) |
876 | { | 897 | { |
877 | 898 | ||
878 | } | 899 | } |
879 | 900 | ||
880 | void EmailClient::setDownloadedSize(int size) | 901 | void EmailClient::setDownloadedSize(int size) |
881 | { | 902 | { |
882 | int total = progressBar->totalSteps(); | 903 | int total = progressBar->totalSteps(); |
883 | 904 | ||
884 | if (size < total) { | 905 | if (size < total) { |
885 | progressBar->setProgress(size); | 906 | progressBar->setProgress(size); |
886 | } else { | 907 | } else { |
887 | progressBar->setProgress(total); | 908 | progressBar->setProgress(total); |
888 | } | 909 | } |
889 | } | 910 | } |
890 | 911 | ||
891 | void EmailClient::deleteItem() | 912 | void EmailClient::deleteItem() |
892 | { | 913 | { |
893 | bool inbox=mailboxView->currentTab()==0; | 914 | bool inbox=mailboxView->currentTab()==0; |
894 | QListView* box; | 915 | QListView* box; |
895 | 916 | ||
896 | EmailListItem* eli; | 917 | EmailListItem* eli; |
897 | int pos; | 918 | int pos; |
898 | 919 | ||
899 | inbox ? box=inboxView : box=outboxView; | 920 | inbox ? box=inboxView : box=outboxView; |
900 | 921 | ||
901 | eli=(EmailListItem*)box->selectedItem(); | 922 | eli=(EmailListItem*)box->selectedItem(); |
902 | 923 | ||
903 | if (eli) | 924 | if (eli) |
904 | { | 925 | { |
905 | box->setSelected(eli->itemBelow(),true);//select the previous item | 926 | box->setSelected(eli->itemBelow(),true);//select the previous item |
906 | 927 | ||
907 | deleteMail(eli,(bool&)inbox); //remove mail entry | 928 | deleteMail(eli,(bool&)inbox); //remove mail entry |
908 | } | 929 | } |
909 | } | 930 | } |
910 | 931 | ||
911 | void EmailClient::inboxItemPressed() | 932 | void EmailClient::inboxItemPressed() |
912 | { | 933 | { |
913 | //timerID=startTimer(500); | 934 | //timerID=startTimer(500); |
914 | } | 935 | } |
915 | 936 | ||
916 | void EmailClient::inboxItemReleased() | 937 | void EmailClient::inboxItemReleased() |
917 | { | 938 | { |
918 | //killTimer(timerID); | 939 | //killTimer(timerID); |
919 | } | 940 | } |
920 | 941 | ||
921 | void EmailClient::timerEvent(QTimerEvent *e) | 942 | /*void EmailClient::timerEvent(QTimerEvent *e) |
922 | { | 943 | { |
923 | /*killTimer(timerID); | 944 | /*killTimer(timerID); |
924 | 945 | ||
925 | 946 | ||
926 | QPopupMenu *action = new QPopupMenu(this); | 947 | QPopupMenu *action = new QPopupMenu(this); |
927 | 948 | ||
928 | int reply=0; | 949 | int reply=0; |
929 | 950 | ||
930 | action->insertItem(tr( "Reply To" ),this,SLOT(reply())); | 951 | action->insertItem(tr( "Reply To" ),this,SLOT(reply())); |
931 | action->insertItem( tr( "Reply All" ),this,SLOT(replyAll())); | 952 | action->insertItem( tr( "Reply All" ),this,SLOT(replyAll())); |
932 | action->insertItem( tr( "Forward" ), this,SLOT(forward())); | 953 | action->insertItem( tr( "Forward" ), this,SLOT(forward())); |
933 | action->insertItem( tr( "Remove Mail" ), this,SLOT(remove())); | 954 | action->insertItem( tr( "Remove Mail" ), this,SLOT(remove())); |
934 | 955 | ||
935 | action->exec(QCursor::pos()); | 956 | action->exec(QCursor::pos()); |
936 | 957 | ||
937 | if (action) delete action; | 958 | if (action) delete action; |
938 | */ | 959 | |
939 | } | 960 | }*/ |
940 | 961 | ||
941 | Email* EmailClient::getCurrentMail() | 962 | Email* EmailClient::getCurrentMail() |
942 | { | 963 | { |
943 | EmailListItem *eli=(EmailListItem* ) (inboxView->selectedItem()); | 964 | EmailListItem *eli=(EmailListItem* ) (inboxView->selectedItem()); |
944 | if (eli!=NULL) | 965 | if (eli!=NULL) |
945 | return eli->getMail(); | 966 | return eli->getMail(); |
946 | else | 967 | else |
947 | return NULL; | 968 | return NULL; |
948 | } | 969 | } |
949 | 970 | ||
950 | void EmailClient::download(Email* mail) | 971 | void EmailClient::download(Email* mail) |
951 | { | 972 | { |
952 | MailAccount* acc=0; | 973 | MailAccount* acc=0; |
953 | 974 | ||
954 | tempMailDownloadList.clear(); | 975 | tempMailDownloadList.clear(); |
955 | tempMailDownloadList.sizeInsert(mail->serverId, mail->size); | 976 | tempMailDownloadList.sizeInsert(mail->serverId, mail->size); |
956 | if (accountList.count()>0) | ||
957 | qDebug("Accounts present"); | ||
958 | 977 | ||
959 | acc=accountList.at(mail->fromAccountId-1); | 978 | acc=accountList.at(mail->fromAccountId-1); |
960 | if (acc) | 979 | if (acc) |
961 | { | 980 | { |
962 | emailHandler->setAccount(*acc); | 981 | emailHandler->setAccount(*acc); |
963 | emailHandler->getMailByList(&tempMailDownloadList); | 982 | emailHandler->getMailByList(&tempMailDownloadList); |
964 | } | 983 | } |
965 | else | 984 | else |
966 | QMessageBox::warning(qApp->activeWindow(), | 985 | QMessageBox::warning(qApp->activeWindow(), |
967 | tr("No account associated"), tr("There is no active account \nassociated to this mail\n it can not be downloaded"), "Abort\n"); | 986 | tr("No account associated"), tr("There is no active account \nassociated to this mail\n it can not be downloaded"), "Abort\n"); |
968 | } | 987 | } |
988 | |||
989 | void EmailClient::receive(const QCString& msg, const QByteArray& data) | ||
990 | { | ||
991 | /*if (msg=="getMail()") | ||
992 | { | ||
993 | /*QDialog qd(qApp->activeWindow(),"Getting mail",true); | ||
994 | QVBoxLayout *vbProg = new QVBoxLayout( &qd ); | ||
995 | |||
996 | initStatusBar(&qd); | ||
997 | |||
998 | if (statusBar==0) | ||
999 | { | ||
1000 | qDebug("No Bar ..."); | ||
1001 | //statusBar=new ProgressBar(&qd); | ||
1002 | } | ||
1003 | statusBar->show(); | ||
1004 | vbProg->addWidget(statusBar); | ||
1005 | qd.showMaximized(); | ||
1006 | qd.show(); | ||
1007 | emit getAllNewMail(); | ||
1008 | //qd.exec(); | ||
1009 | } | ||
1010 | else if (msg=="compose()") | ||
1011 | { | ||
1012 | QDialog qd(qApp->activeWindow(),"Getting mail",true); | ||
1013 | |||
1014 | WriteMail wm(&qd,"write new mail"); | ||
1015 | QVBoxLayout vbProg( &qd ); | ||
1016 | |||
1017 | wm.showMaximized(); | ||
1018 | vbProg.addWidget(&wm); | ||
1019 | |||
1020 | qd.showMaximized(); | ||
1021 | |||
1022 | emit composeRequested(); | ||
1023 | qd.exec(); | ||
1024 | |||
1025 | QMessageBox::warning(qApp->activeWindow(),tr("Info"), tr("Info"), "OK\n"); | ||
1026 | } | ||
1027 | |||
1028 | else if (msg=="dialog()") | ||
1029 | { | ||
1030 | QMessageBox::warning(qApp->activeWindow(),tr("Info"), tr("Info"), "OK\n"); | ||
1031 | }*/ | ||
1032 | } | ||