summaryrefslogtreecommitdiff
path: root/noncore/net/mailit/addresslist.cpp
Unidiff
Diffstat (limited to 'noncore/net/mailit/addresslist.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mailit/addresslist.cpp22
1 files changed, 1 insertions, 21 deletions
diff --git a/noncore/net/mailit/addresslist.cpp b/noncore/net/mailit/addresslist.cpp
index 43e3830..9fe558a 100644
--- a/noncore/net/mailit/addresslist.cpp
+++ b/noncore/net/mailit/addresslist.cpp
@@ -3,59 +3,57 @@
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 <qfile.h> 20#include <qfile.h>
21#include <qtextstream.h> 21#include <qtextstream.h>
22#include <opie/ocontactaccess.h> 22#include <opie/ocontactaccess.h>
23#include <opie/ocontact.h> 23#include <opie/ocontact.h>
24 24
25#include "addresslist.h" 25#include "addresslist.h"
26 26
27AddressList::AddressList(QString file) 27AddressList::AddressList()
28{ 28{
29 addresses.setAutoDelete(TRUE); 29 addresses.setAutoDelete(TRUE);
30 filename = file;
31 read(); 30 read();
32 dirty = FALSE; 31 dirty = FALSE;
33} 32}
34 33
35AddressList::~AddressList() 34AddressList::~AddressList()
36{ 35{
37 write();
38 addresses.clear(); 36 addresses.clear();
39} 37}
40 38
41void AddressList::addContact(QString email, QString name) 39void AddressList::addContact(QString email, QString name)
42{ 40{
43 //skip if not a valid email address, 41 //skip if not a valid email address,
44 if (email.find( '@') == -1) 42 if (email.find( '@') == -1)
45 return; 43 return;
46 44
47 if ( ! containsEmail(email) ) { 45 if ( ! containsEmail(email) ) {
48 Contact *in = new Contact; 46 Contact *in = new Contact;
49 in->email = email; 47 in->email = email;
50 in->name = name; 48 in->name = name;
51 addresses.append(in); 49 addresses.append(in);
52 dirty = TRUE; 50 dirty = TRUE;
53 } 51 }
54} 52}
55 53
56bool AddressList::containsEmail(QString email) 54bool AddressList::containsEmail(QString email)
57{ 55{
58 return ( getEmailRef(email) != -1 ); 56 return ( getEmailRef(email) != -1 );
59} 57}
60 58
61bool AddressList::containsName(QString name) 59bool AddressList::containsName(QString name)
@@ -99,83 +97,65 @@ int AddressList::getEmailRef(QString email)
99} 97}
100 98
101int AddressList::getNameRef(QString name) 99int AddressList::getNameRef(QString name)
102{ 100{
103 int pos = 0; 101 int pos = 0;
104 Contact *ptr; 102 Contact *ptr;
105 103
106 for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) { 104 for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) {
107 if (ptr->name == name) 105 if (ptr->name == name)
108 return pos; 106 return pos;
109 pos++; 107 pos++;
110 } 108 }
111 return -1; 109 return -1;
112} 110}
113 111
114QList<Contact>* AddressList::getContactList() 112QList<Contact>* AddressList::getContactList()
115{ 113{
116 return &addresses; 114 return &addresses;
117} 115}
118 116
119void AddressList::read() 117void AddressList::read()
120{ 118{
121 OContactAccess::List::Iterator it; 119 OContactAccess::List::Iterator it;
122 120
123 //QFile f(filename);
124 QString lineEmail, lineName, email, name; 121 QString lineEmail, lineName, email, name;
125 OContactAccess m_contactdb("mailit"); 122 OContactAccess m_contactdb("mailit");
126 OContactAccess::List m_list = m_contactdb.sorted( true, 0, 0, 0 ); 123 OContactAccess::List m_list = m_contactdb.sorted( true, 0, 0, 0 );
127 //OContact* oc; 124 //OContact* oc;
128 125
129 for ( it = m_list.begin(); it != m_list.end(); ++it ) 126 for ( it = m_list.begin(); it != m_list.end(); ++it )
130 { 127 {
131 //oc=(OContact*) it; 128 //oc=(OContact*) it;
132 if ((*it).defaultEmail().length()!=0) 129 if ((*it).defaultEmail().length()!=0)
133 addContact((*it).defaultEmail(),(*it).fullName()); 130 addContact((*it).defaultEmail(),(*it).fullName());
134 } 131 }
135 132
136 /*if (! f.open(IO_ReadOnly) ) 133 /*if (! f.open(IO_ReadOnly) )
137 return; 134 return;
138 135
139 QTextStream stream(&f); 136 QTextStream stream(&f);
140 137
141 while (! stream.atEnd() ) { 138 while (! stream.atEnd() ) {
142 lineEmail = stream.readLine(); 139 lineEmail = stream.readLine();
143 if (! stream.atEnd() ) 140 if (! stream.atEnd() )
144 lineName = stream.readLine(); 141 lineName = stream.readLine();
145 else return; 142 else return;
146 143
147 email = getRightString(lineEmail); 144 email = getRightString(lineEmail);
148 name = getRightString(lineName); 145 name = getRightString(lineName);
149 addContact(email, name); 146 addContact(email, name);
150 } 147 }
151 f.close();*/ 148 f.close();*/
152} 149}
153 150
154QString AddressList::getRightString(QString in) 151QString AddressList::getRightString(QString in)
155{ 152{
156 QString out = ""; 153 QString out = "";
157 154
158 int pos = in.find('='); 155 int pos = in.find('=');
159 if (pos != -1) { 156 if (pos != -1) {
160 out = in.mid(pos+1).stripWhiteSpace(); 157 out = in.mid(pos+1).stripWhiteSpace();
161 } 158 }
162 return out; 159 return out;
163} 160}
164 161
165void AddressList::write()
166{
167 if ( (addresses.count() == 0) || (!dirty) )
168 return;
169
170 QFile f(filename);
171 if (! f.open(IO_WriteOnly) )
172 return;
173
174 QTextStream stream(&f);
175 Contact *ptr;
176 for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) {
177 stream << "email = " + ptr->email + "\n";
178 stream << "name = " + ptr->name + "\n";
179 }
180 f.close();
181}