Diffstat (limited to 'noncore/net/mail/settings.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/settings.cpp | 403 |
1 files changed, 0 insertions, 403 deletions
diff --git a/noncore/net/mail/settings.cpp b/noncore/net/mail/settings.cpp deleted file mode 100644 index 17aa1b0..0000000 --- a/noncore/net/mail/settings.cpp +++ b/dev/null | |||
@@ -1,403 +0,0 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <qdir.h> | ||
3 | |||
4 | #include <qpe/config.h> | ||
5 | |||
6 | #include "settings.h" | ||
7 | #include "defines.h" | ||
8 | |||
9 | Settings::Settings() | ||
10 | : QObject() | ||
11 | { | ||
12 | updateAccounts(); | ||
13 | } | ||
14 | |||
15 | void Settings::checkDirectory() | ||
16 | { | ||
17 | if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) { | ||
18 | system( "mkdir -p $HOME/Applications/opiemail" ); | ||
19 | qDebug( "$HOME/Applications/opiemail created" ); | ||
20 | } | ||
21 | } | ||
22 | |||
23 | QList<Account> Settings::getAccounts() | ||
24 | { | ||
25 | return accounts; | ||
26 | } | ||
27 | |||
28 | void Settings::addAccount( Account *account ) | ||
29 | { | ||
30 | accounts.append( account ); | ||
31 | } | ||
32 | |||
33 | void Settings::delAccount( Account *account ) | ||
34 | { | ||
35 | accounts.remove( account ); | ||
36 | account->remove(); | ||
37 | } | ||
38 | |||
39 | void Settings::updateAccounts() | ||
40 | { | ||
41 | accounts.clear(); | ||
42 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | ||
43 | QStringList::Iterator it; | ||
44 | |||
45 | QStringList imap = dir.entryList( "imap-*" ); | ||
46 | for ( it = imap.begin(); it != imap.end(); it++ ) { | ||
47 | qDebug( "Added IMAP account" ); | ||
48 | IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") ); | ||
49 | accounts.append( account ); | ||
50 | } | ||
51 | |||
52 | QStringList pop3 = dir.entryList( "pop3-*" ); | ||
53 | for ( it = pop3.begin(); it != pop3.end(); it++ ) { | ||
54 | qDebug( "Added POP account" ); | ||
55 | POP3account *account = new POP3account( (*it).replace(0, 5, "") ); | ||
56 | accounts.append( account ); | ||
57 | } | ||
58 | |||
59 | QStringList smtp = dir.entryList( "smtp-*" ); | ||
60 | for ( it = smtp.begin(); it != smtp.end(); it++ ) { | ||
61 | qDebug( "Added SMTP account" ); | ||
62 | SMTPaccount *account = new SMTPaccount( (*it).replace(0, 5, "") ); | ||
63 | accounts.append( account ); | ||
64 | } | ||
65 | |||
66 | QStringList nntp = dir.entryList( "nntp-*" ); | ||
67 | for ( it = nntp.begin(); it != nntp.end(); it++ ) { | ||
68 | qDebug( "Added NNTP account" ); | ||
69 | NNTPaccount *account = new NNTPaccount( (*it).replace(0, 5, "") ); | ||
70 | accounts.append( account ); | ||
71 | } | ||
72 | |||
73 | readAccounts(); | ||
74 | } | ||
75 | |||
76 | void Settings::saveAccounts() | ||
77 | { | ||
78 | checkDirectory(); | ||
79 | Account *it; | ||
80 | |||
81 | for ( it = accounts.first(); it; it = accounts.next() ) { | ||
82 | it->save(); | ||
83 | } | ||
84 | } | ||
85 | |||
86 | void Settings::readAccounts() | ||
87 | { | ||
88 | checkDirectory(); | ||
89 | Account *it; | ||
90 | |||
91 | for ( it = accounts.first(); it; it = accounts.next() ) { | ||
92 | it->read(); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | Account::Account() | ||
97 | { | ||
98 | accountName = "changeMe"; | ||
99 | type = "changeMe"; | ||
100 | ssl = false; | ||
101 | } | ||
102 | |||
103 | void Account::remove() | ||
104 | { | ||
105 | QFile file( getFileName() ); | ||
106 | file.remove(); | ||
107 | } | ||
108 | |||
109 | IMAPaccount::IMAPaccount() | ||
110 | : Account() | ||
111 | { | ||
112 | file = IMAPaccount::getUniqueFileName(); | ||
113 | accountName = "New IMAP Account"; | ||
114 | ssl = false; | ||
115 | type = "IMAP"; | ||
116 | port = IMAP_PORT; | ||
117 | } | ||
118 | |||
119 | IMAPaccount::IMAPaccount( QString filename ) | ||
120 | : Account() | ||
121 | { | ||
122 | file = filename; | ||
123 | accountName = "New IMAP Account"; | ||
124 | ssl = false; | ||
125 | type = "IMAP"; | ||
126 | port = IMAP_PORT; | ||
127 | } | ||
128 | |||
129 | QString IMAPaccount::getUniqueFileName() | ||
130 | { | ||
131 | int num = 0; | ||
132 | QString unique; | ||
133 | |||
134 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | ||
135 | |||
136 | QStringList imap = dir.entryList( "imap-*" ); | ||
137 | do { | ||
138 | unique.setNum( num++ ); | ||
139 | } while ( imap.contains( "imap-" + unique ) > 0 ); | ||
140 | |||
141 | return unique; | ||
142 | } | ||
143 | |||
144 | void IMAPaccount::read() | ||
145 | { | ||
146 | Config *conf = new Config( getFileName(), Config::File ); | ||
147 | conf->setGroup( "IMAP Account" ); | ||
148 | accountName = conf->readEntry( "Account","" ); | ||
149 | if (accountName.isNull()) accountName = ""; | ||
150 | server = conf->readEntry( "Server","" ); | ||
151 | if (server.isNull()) server=""; | ||
152 | port = conf->readEntry( "Port","" ); | ||
153 | if (port.isNull()) port="143"; | ||
154 | ssl = conf->readBoolEntry( "SSL",false ); | ||
155 | user = conf->readEntry( "User","" ); | ||
156 | if (user.isNull()) user = ""; | ||
157 | password = conf->readEntryCrypt( "Password","" ); | ||
158 | if (password.isNull()) password = ""; | ||
159 | prefix = conf->readEntry("MailPrefix",""); | ||
160 | if (prefix.isNull()) prefix = ""; | ||
161 | } | ||
162 | |||
163 | void IMAPaccount::save() | ||
164 | { | ||
165 | qDebug( "saving " + getFileName() ); | ||
166 | Settings::checkDirectory(); | ||
167 | |||
168 | Config *conf = new Config( getFileName(), Config::File ); | ||
169 | conf->setGroup( "IMAP Account" ); | ||
170 | conf->writeEntry( "Account", accountName ); | ||
171 | conf->writeEntry( "Server", server ); | ||
172 | conf->writeEntry( "Port", port ); | ||
173 | conf->writeEntry( "SSL", ssl ); | ||
174 | conf->writeEntry( "User", user ); | ||
175 | conf->writeEntryCrypt( "Password", password ); | ||
176 | conf->writeEntry( "MailPrefix",prefix); | ||
177 | conf->write(); | ||
178 | } | ||
179 | |||
180 | |||
181 | QString IMAPaccount::getFileName() | ||
182 | { | ||
183 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/imap-" + file; | ||
184 | } | ||
185 | |||
186 | POP3account::POP3account() | ||
187 | : Account() | ||
188 | { | ||
189 | file = POP3account::getUniqueFileName(); | ||
190 | accountName = "New POP3 Account"; | ||
191 | ssl = false; | ||
192 | type = "POP3"; | ||
193 | port = POP3_PORT; | ||
194 | } | ||
195 | |||
196 | POP3account::POP3account( QString filename ) | ||
197 | : Account() | ||
198 | { | ||
199 | file = filename; | ||
200 | accountName = "New POP3 Account"; | ||
201 | ssl = false; | ||
202 | type = "POP3"; | ||
203 | port = POP3_PORT; | ||
204 | } | ||
205 | |||
206 | QString POP3account::getUniqueFileName() | ||
207 | { | ||
208 | int num = 0; | ||
209 | QString unique; | ||
210 | |||
211 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | ||
212 | |||
213 | QStringList imap = dir.entryList( "pop3-*" ); | ||
214 | do { | ||
215 | unique.setNum( num++ ); | ||
216 | } while ( imap.contains( "pop3-" + unique ) > 0 ); | ||
217 | |||
218 | return unique; | ||
219 | } | ||
220 | |||
221 | void POP3account::read() | ||
222 | { | ||
223 | Config *conf = new Config( getFileName(), Config::File ); | ||
224 | conf->setGroup( "POP3 Account" ); | ||
225 | accountName = conf->readEntry( "Account" ); | ||
226 | server = conf->readEntry( "Server" ); | ||
227 | port = conf->readEntry( "Port" ); | ||
228 | ssl = conf->readBoolEntry( "SSL" ); | ||
229 | user = conf->readEntry( "User" ); | ||
230 | password = conf->readEntryCrypt( "Password" ); | ||
231 | } | ||
232 | |||
233 | void POP3account::save() | ||
234 | { | ||
235 | qDebug( "saving " + getFileName() ); | ||
236 | Settings::checkDirectory(); | ||
237 | |||
238 | Config *conf = new Config( getFileName(), Config::File ); | ||
239 | conf->setGroup( "POP3 Account" ); | ||
240 | conf->writeEntry( "Account", accountName ); | ||
241 | conf->writeEntry( "Server", server ); | ||
242 | conf->writeEntry( "Port", port ); | ||
243 | conf->writeEntry( "SSL", ssl ); | ||
244 | conf->writeEntry( "User", user ); | ||
245 | conf->writeEntryCrypt( "Password", password ); | ||
246 | conf->write(); | ||
247 | } | ||
248 | |||
249 | |||
250 | QString POP3account::getFileName() | ||
251 | { | ||
252 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/pop3-" + file; | ||
253 | } | ||
254 | |||
255 | SMTPaccount::SMTPaccount() | ||
256 | : Account() | ||
257 | { | ||
258 | file = SMTPaccount::getUniqueFileName(); | ||
259 | accountName = "New SMTP Account"; | ||
260 | ssl = false; | ||
261 | login = false; | ||
262 | useCC = false; | ||
263 | useBCC = false; | ||
264 | useReply = false; | ||
265 | type = "SMTP"; | ||
266 | port = SMTP_PORT; | ||
267 | } | ||
268 | |||
269 | SMTPaccount::SMTPaccount( QString filename ) | ||
270 | : Account() | ||
271 | { | ||
272 | file = filename; | ||
273 | accountName = "New SMTP Account"; | ||
274 | ssl = false; | ||
275 | login = false; | ||
276 | type = "SMTP"; | ||
277 | port = SMTP_PORT; | ||
278 | } | ||
279 | |||
280 | QString SMTPaccount::getUniqueFileName() | ||
281 | { | ||
282 | int num = 0; | ||
283 | QString unique; | ||
284 | |||
285 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | ||
286 | |||
287 | QStringList imap = dir.entryList( "smtp-*" ); | ||
288 | do { | ||
289 | unique.setNum( num++ ); | ||
290 | } while ( imap.contains( "smtp-" + unique ) > 0 ); | ||
291 | |||
292 | return unique; | ||
293 | } | ||
294 | |||
295 | void SMTPaccount::read() | ||
296 | { | ||
297 | Config *conf = new Config( getFileName(), Config::File ); | ||
298 | conf->setGroup( "SMTP Account" ); | ||
299 | accountName = conf->readEntry( "Account" ); | ||
300 | server = conf->readEntry( "Server" ); | ||
301 | port = conf->readEntry( "Port" ); | ||
302 | ssl = conf->readBoolEntry( "SSL" ); | ||
303 | login = conf->readBoolEntry( "Login" ); | ||
304 | user = conf->readEntry( "User" ); | ||
305 | password = conf->readEntryCrypt( "Password" ); | ||
306 | } | ||
307 | |||
308 | void SMTPaccount::save() | ||
309 | { | ||
310 | qDebug( "saving " + getFileName() ); | ||
311 | Settings::checkDirectory(); | ||
312 | |||
313 | Config *conf = new Config( getFileName(), Config::File ); | ||
314 | conf->setGroup( "SMTP Account" ); | ||
315 | conf->writeEntry( "Account", accountName ); | ||
316 | conf->writeEntry( "Server", server ); | ||
317 | conf->writeEntry( "Port", port ); | ||
318 | conf->writeEntry( "SSL", ssl ); | ||
319 | conf->writeEntry( "Login", login ); | ||
320 | conf->writeEntry( "User", user ); | ||
321 | conf->writeEntryCrypt( "Password", password ); | ||
322 | conf->write(); | ||
323 | } | ||
324 | |||
325 | |||
326 | QString SMTPaccount::getFileName() | ||
327 | { | ||
328 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/smtp-" + file; | ||
329 | } | ||
330 | |||
331 | NNTPaccount::NNTPaccount() | ||
332 | : Account() | ||
333 | { | ||
334 | file = NNTPaccount::getUniqueFileName(); | ||
335 | accountName = "New NNTP Account"; | ||
336 | ssl = false; | ||
337 | login = false; | ||
338 | type = "NNTP"; | ||
339 | port = NNTP_PORT; | ||
340 | } | ||
341 | |||
342 | NNTPaccount::NNTPaccount( QString filename ) | ||
343 | : Account() | ||
344 | { | ||
345 | file = filename; | ||
346 | accountName = "New NNTP Account"; | ||
347 | ssl = false; | ||
348 | login = false; | ||
349 | type = "NNTP"; | ||
350 | port = NNTP_PORT; | ||
351 | } | ||
352 | |||
353 | QString NNTPaccount::getUniqueFileName() | ||
354 | { | ||
355 | int num = 0; | ||
356 | QString unique; | ||
357 | |||
358 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | ||
359 | |||
360 | QStringList imap = dir.entryList( "nntp-*" ); | ||
361 | do { | ||
362 | unique.setNum( num++ ); | ||
363 | } while ( imap.contains( "nntp-" + unique ) > 0 ); | ||
364 | |||
365 | return unique; | ||
366 | } | ||
367 | |||
368 | void NNTPaccount::read() | ||
369 | { | ||
370 | Config *conf = new Config( getFileName(), Config::File ); | ||
371 | conf->setGroup( "NNTP Account" ); | ||
372 | accountName = conf->readEntry( "Account" ); | ||
373 | server = conf->readEntry( "Server" ); | ||
374 | port = conf->readEntry( "Port" ); | ||
375 | ssl = conf->readBoolEntry( "SSL" ); | ||
376 | login = conf->readBoolEntry( "Login" ); | ||
377 | user = conf->readEntry( "User" ); | ||
378 | password = conf->readEntryCrypt( "Password" ); | ||
379 | } | ||
380 | |||
381 | void NNTPaccount::save() | ||
382 | { | ||
383 | qDebug( "saving " + getFileName() ); | ||
384 | Settings::checkDirectory(); | ||
385 | |||
386 | Config *conf = new Config( getFileName(), Config::File ); | ||
387 | conf->setGroup( "NNTP Account" ); | ||
388 | conf->writeEntry( "Account", accountName ); | ||
389 | conf->writeEntry( "Server", server ); | ||
390 | conf->writeEntry( "Port", port ); | ||
391 | conf->writeEntry( "SSL", ssl ); | ||
392 | conf->writeEntry( "Login", login ); | ||
393 | conf->writeEntry( "User", user ); | ||
394 | conf->writeEntryCrypt( "Password", password ); | ||
395 | conf->write(); | ||
396 | } | ||
397 | |||
398 | |||
399 | QString NNTPaccount::getFileName() | ||
400 | { | ||
401 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/nntp-" + file; | ||
402 | } | ||
403 | |||