summaryrefslogtreecommitdiff
path: root/noncore/net/mail/addresspicker.cpp
Unidiff
Diffstat (limited to 'noncore/net/mail/addresspicker.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/mail/addresspicker.cpp130
1 files changed, 130 insertions, 0 deletions
diff --git a/noncore/net/mail/addresspicker.cpp b/noncore/net/mail/addresspicker.cpp
new file mode 100644
index 0000000..2c15bb4
--- a/dev/null
+++ b/noncore/net/mail/addresspicker.cpp
@@ -0,0 +1,130 @@
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 "composemail.h"
12
13AddressPicker::AddressPicker( QWidget *parent, const char *name, bool modal, WFlags flags )
14 : AddressPickerUI( parent, name, modal, flags )
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 stream.setEncoding( QTextStream::UnicodeUTF8 );
28 QString content;
29 while ( !f.atEnd() ) {
30 content += stream.readLine() + "\n";
31 }
32 QStringList lines = QStringList::split( QRegExp( "\\n" ), content );
33 QStringList::Iterator it;
34 for ( it = lines.begin(); it != lines.end(); it++ ) {
35 if ( (*it).find( QRegExp( "^<Contact.*" ) ) != -1 ) {
36 int pos = (*it).find( "FirstName=\"" );
37 QString fname;
38 if ( pos != -1 ) {
39 int i = 1;
40 QChar c;
41 while ( c != '"' ) {
42 c = (*it)[pos + 10 + i];
43 if ( c != '"' ) fname += c;
44 i++;
45 }
46 }
47 pos = (*it).find( "LastName=\"" );
48 QString lname;
49 if ( pos != -1 ) {
50 int i = 1;
51 QChar c;
52 while ( c != '"' ) {
53 c = (*it)[pos + 9 + i];
54 if ( c != '"' ) lname += c;
55 i++;
56 }
57 }
58 pos = (*it).find( "DefaultEmail=\"" );
59 QString email;
60 if ( pos != -1 ) {
61 int i = 1;
62 QChar c;
63 while ( c != '"' ) {
64 c = (*it)[pos + 13 + i];
65 if ( c != '"' ) email += c;
66 i++;
67 }
68 }
69 QString tname, temail;
70 if ( !fname.isEmpty() ) {
71 tname += fname;
72 }
73 if ( !lname.isEmpty() ) {
74 tname += fname.isEmpty() ? lname : (" " + lname);
75 }
76 if ( !email.isEmpty() ) {
77 temail += tname.isEmpty() ? email : (" <" + email + ">");
78 }
79 if ( !email.isEmpty() ) {
80 addressList->insertItem( tname + temail );
81 }
82 }
83 }
84 }
85 if ( addressList->count() <= 0 ) {
86 addressList->insertItem(
87 tr( "There are no entries in the addressbook." ) );
88 addressList->setEnabled( false );
89 okButton->setEnabled( false );
90 }
91}
92
93void AddressPicker::accept()
94{
95 QListBoxItem *item = addressList->firstItem();
96 QString names;
97
98 while ( item ) {
99 if ( item->selected() )
100 names += item->text() + ", ";
101 item = item->next();
102 }
103 names.replace( names.length() - 2, 2, "" );
104
105 if ( names.isEmpty() ) {
106 QMessageBox::information(this, tr("Error"), tr("<p>You have to select"
107 " at least one address entry.</p>"), tr("Ok"));
108 return;
109 }
110
111 selectedNames = names;
112 QDialog::accept();
113}
114
115QString AddressPicker::getNames()
116{
117 QString names = 0;
118
119 AddressPicker picker(0, 0, true);
120 picker.showMaximized();
121 picker.show();
122
123 int ret = picker.exec();
124 if ( QDialog::Accepted == ret ) {
125 return picker.selectedNames;
126 }
127
128 return 0;
129}
130