Diffstat (limited to 'noncore/net/mailit/addresslist.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mailit/addresslist.cpp | 161 |
1 files changed, 0 insertions, 161 deletions
diff --git a/noncore/net/mailit/addresslist.cpp b/noncore/net/mailit/addresslist.cpp deleted file mode 100644 index f2b027c..0000000 --- a/noncore/net/mailit/addresslist.cpp +++ b/dev/null | |||
@@ -1,161 +0,0 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2001 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qt Palmtop Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #include <qfile.h> | ||
21 | #include <qtextstream.h> | ||
22 | #include <opie/ocontactaccess.h> | ||
23 | #include <opie/ocontact.h> | ||
24 | |||
25 | #include "addresslist.h" | ||
26 | |||
27 | AddressList::AddressList() | ||
28 | { | ||
29 | addresses.setAutoDelete(TRUE); | ||
30 | read(); | ||
31 | dirty = FALSE; | ||
32 | } | ||
33 | |||
34 | AddressList::~AddressList() | ||
35 | { | ||
36 | addresses.clear(); | ||
37 | } | ||
38 | |||
39 | void AddressList::addContact(const QString &email, const QString &name) | ||
40 | { | ||
41 | //skip if not a valid email address, | ||
42 | if (email.find( '@') == -1) | ||
43 | return; | ||
44 | |||
45 | if ( ! containsEmail(email) ) { | ||
46 | AContact *in = new AContact; | ||
47 | in->email = email; | ||
48 | in->name = name; | ||
49 | addresses.append(in); | ||
50 | dirty = TRUE; | ||
51 | } | ||
52 | } | ||
53 | |||
54 | bool AddressList::containsEmail(const QString &email) | ||
55 | { | ||
56 | return ( getEmailRef(email) != -1 ); | ||
57 | } | ||
58 | |||
59 | bool AddressList::containsName(const QString &name) | ||
60 | { | ||
61 | return ( getNameRef(name) != -1 ); | ||
62 | } | ||
63 | |||
64 | QString AddressList::getNameByEmail(const QString &email) | ||
65 | { | ||
66 | int pos = getEmailRef(email); | ||
67 | if (pos != -1) { | ||
68 | AContact *ptr = addresses.at(pos); | ||
69 | return ptr->name; | ||
70 | } | ||
71 | |||
72 | return QString::null; | ||
73 | } | ||
74 | |||
75 | QString AddressList::getEmailByName(const QString &name) | ||
76 | { | ||
77 | int pos = getNameRef(name); | ||
78 | if (pos != -1) { | ||
79 | AContact *ptr = addresses.at(pos); | ||
80 | return ptr->email; | ||
81 | } | ||
82 | |||
83 | return QString::null; | ||
84 | } | ||
85 | |||
86 | int AddressList::getEmailRef(const QString &email) | ||
87 | { | ||
88 | int pos = 0; | ||
89 | AContact *ptr; | ||
90 | |||
91 | for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) { | ||
92 | if (ptr->email == email) | ||
93 | return pos; | ||
94 | pos++; | ||
95 | } | ||
96 | return -1; | ||
97 | } | ||
98 | |||
99 | int AddressList::getNameRef(const QString &name) | ||
100 | { | ||
101 | int pos = 0; | ||
102 | AContact *ptr; | ||
103 | |||
104 | for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) { | ||
105 | if (ptr->name == name) | ||
106 | return pos; | ||
107 | pos++; | ||
108 | } | ||
109 | return -1; | ||
110 | } | ||
111 | |||
112 | QList<AContact>* AddressList::getContactList() | ||
113 | { | ||
114 | return &addresses; | ||
115 | } | ||
116 | |||
117 | void AddressList::read() | ||
118 | { | ||
119 | OContactAccess::List::Iterator it; | ||
120 | |||
121 | QString lineEmail, lineName, email, name; | ||
122 | OContactAccess m_contactdb("mailit"); | ||
123 | OContactAccess::List m_list = m_contactdb.sorted( true, 0, 0, 0 ); | ||
124 | //OContact* oc;(*it).defaultEmail() | ||
125 | |||
126 | for ( it = m_list.begin(); it != m_list.end(); ++it ) | ||
127 | { | ||
128 | //oc=(OContact*) it; | ||
129 | if ((*it).defaultEmail().length()!=0) | ||
130 | addContact((*it).defaultEmail(),(*it).fileAs()); | ||
131 | } | ||
132 | |||
133 | /*if (! f.open(IO_ReadOnly) ) | ||
134 | return; | ||
135 | |||
136 | QTextStream stream(&f); | ||
137 | |||
138 | while (! stream.atEnd() ) { | ||
139 | lineEmail = stream.readLine(); | ||
140 | if (! stream.atEnd() ) | ||
141 | lineName = stream.readLine(); | ||
142 | else return; | ||
143 | |||
144 | email = getRightString(lineEmail); | ||
145 | name = getRightString(lineName); | ||
146 | addContact(email, name); | ||
147 | } | ||
148 | f.close();*/ | ||
149 | } | ||
150 | |||
151 | QString AddressList::getRightString(const QString &in) | ||
152 | { | ||
153 | QString out = ""; | ||
154 | |||
155 | int pos = in.find('='); | ||
156 | if (pos != -1) { | ||
157 | out = in.mid(pos+1).stripWhiteSpace(); | ||
158 | } | ||
159 | return out; | ||
160 | } | ||
161 | |||