summaryrefslogtreecommitdiff
path: root/noncore/unsupported/mail2/addresspicker.cpp
authorconber <conber>2002-06-15 09:46:14 (UTC)
committer conber <conber>2002-06-15 09:46:14 (UTC)
commit7f2eef29708380844922f34f59ba4e9beefbf7c3 (patch) (unidiff)
treef57125fbaabddecc35d6677f1b9e48a4594165d5 /noncore/unsupported/mail2/addresspicker.cpp
parent0acbdd392814589df303b6e50c79d9822e3db27a (diff)
downloadopie-7f2eef29708380844922f34f59ba4e9beefbf7c3.zip
opie-7f2eef29708380844922f34f59ba4e9beefbf7c3.tar.gz
opie-7f2eef29708380844922f34f59ba4e9beefbf7c3.tar.bz2
initial checkin
Diffstat (limited to 'noncore/unsupported/mail2/addresspicker.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/mail2/addresspicker.cpp117
1 files changed, 117 insertions, 0 deletions
diff --git a/noncore/unsupported/mail2/addresspicker.cpp b/noncore/unsupported/mail2/addresspicker.cpp
new file mode 100644
index 0000000..178fe27
--- a/dev/null
+++ b/noncore/unsupported/mail2/addresspicker.cpp
@@ -0,0 +1,117 @@
1#include <qpushbutton.h>
2#include <qmessagebox.h>
3#include <qtextstream.h>
4#include <qlistbox.h>
5#include <qfile.h>
6
7#include <qpe/resource.h>
8
9#include <stdlib.h>
10
11#include "addresspicker.h"
12
13AddressPicker::AddressPicker(QWidget *parent, const char *name, bool modal,
14 WFlags fl) : AddressPickerBase(parent, name, modal, fl)
15{
16 okButton->setIconSet(Resource::loadPixmap("enter"));
17 cancelButton->setIconSet(Resource::loadPixmap("editdelete"));
18
19 connect(okButton, SIGNAL(clicked()), SLOT(accept()));
20 connect(cancelButton, SIGNAL(clicked()), SLOT(close()));
21
22 QFile f((QString) getenv("HOME") + "/Applications/"
23 + "addressbook/addressbook.xml");
24
25 if (f.open(IO_ReadOnly)) {
26 QTextStream stream(&f);
27 QString content;
28 while (!f.atEnd()) content += stream.readLine() + "\n";
29 QStringList lines = QStringList::split(QRegExp("\\n"), content);
30 QStringList::Iterator it;
31 for (it = lines.begin(); it != lines.end(); it++) {
32 if ((*it).find(QRegExp("^<Contact.*")) != -1) {
33 int pos = (*it).find("FirstName=\"");
34 QString fname;
35 if (pos != -1) {
36 int i = 1;
37 QChar c;
38 while (c != '"') {
39 c = (*it)[pos + 10 + i];
40 if (c != '"') fname += c;
41 i++;
42 }
43 }
44 pos = (*it).find("LastName=\"");
45 QString lname;
46 if (pos != -1) {
47 int i = 1;
48 QChar c;
49 while (c != '"') {
50 c = (*it)[pos + 9 + i];
51 if (c != '"') lname += c;
52 i++;
53 }
54 }
55 pos = (*it).find("DefaultEmail=\"");
56 QString email;
57 if (pos != -1) {
58 int i = 1;
59 QChar c;
60 while (c != '"') {
61 c = (*it)[pos + 13 + i];
62 if (c != '"') email += c;
63 i++;
64 }
65 }
66 QString tname, temail;
67 if (!fname.isEmpty()) tname += fname;
68 if (!lname.isEmpty()) tname += fname.isEmpty() ? lname : (" " + lname);
69 if (!email.isEmpty()) temail += tname.isEmpty() ? email : (" <" + email + ">");
70 if (!email.isEmpty()) addressList->insertItem(tname + temail);
71 }
72 }
73 }
74 if (addressList->count() <= 0) {
75 addressList->insertItem(tr("There are no entries in the addressbook."));
76 addressList->setEnabled(false);
77 okButton->setEnabled(false);
78 }
79}
80
81void AddressPicker::accept()
82{
83 QListBoxItem *item = addressList->firstItem();
84 QString names;
85
86 while (item) {
87 if (item->selected())
88 names += item->text() + ", ";
89 item = item->next();
90 }
91 names.replace(names.length() - 2, 2, "");
92
93 if (names.isEmpty()) {
94 QMessageBox::information(this, tr("Error"), tr("<p>You have to select"
95 " at least one address entry.</p>"), tr("Ok"));
96 return;
97 }
98
99 selectedNames = names;
100 QDialog::accept();
101}
102
103QString AddressPicker::getNames()
104{
105 QString names = 0;
106
107 AddressPicker *picker = new AddressPicker(0, 0, true);
108 picker->showMaximized();
109 picker->show();
110
111 int ret = picker->exec();
112 if (QDialog::Accepted == ret) {
113 return picker->selectedNames;
114 }
115 return 0;
116}
117