author | tux_mike <tux_mike> | 2002-04-10 03:29:24 (UTC) |
---|---|---|
committer | tux_mike <tux_mike> | 2002-04-10 03:29:24 (UTC) |
commit | 4eb2a1b8698fdcca7a2c74a3fe9a88a297607754 (patch) (unidiff) | |
tree | 0787600f2d3e0d4bb314124fff55fa3046bfb2f5 | |
parent | 0d5d67ab1225446f1796a08d97c0cc025922958f (diff) | |
download | opie-4eb2a1b8698fdcca7a2c74a3fe9a88a297607754.zip opie-4eb2a1b8698fdcca7a2c74a3fe9a88a297607754.tar.gz opie-4eb2a1b8698fdcca7a2c74a3fe9a88a297607754.tar.bz2 |
Made rows resize with fonts.
-rw-r--r-- | core/pim/addressbook/abtable.cpp | 11 | ||||
-rw-r--r-- | core/pim/addressbook/abtable.h | 1 | ||||
-rw-r--r-- | core/pim/addressbook/addressbook.cpp | 8 |
3 files changed, 20 insertions, 0 deletions
diff --git a/core/pim/addressbook/abtable.cpp b/core/pim/addressbook/abtable.cpp index 0911edf..17277b4 100644 --- a/core/pim/addressbook/abtable.cpp +++ b/core/pim/addressbook/abtable.cpp | |||
@@ -1,1091 +1,1102 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
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 | 20 | ||
21 | #define QTOPIA_INTERNAL_CONTACT_MRE | ||
22 | |||
21 | #include <qpe/categoryselect.h> | 23 | #include <qpe/categoryselect.h> |
22 | #include <qpe/config.h> | 24 | #include <qpe/config.h> |
23 | #include <qpe/stringutil.h> | 25 | #include <qpe/stringutil.h> |
24 | #include <qpe/qcopenvelope_qws.h> | 26 | #include <qpe/qcopenvelope_qws.h> |
25 | 27 | ||
26 | #include <qasciidict.h> | 28 | #include <qasciidict.h> |
27 | #include <qdatetime.h> | 29 | #include <qdatetime.h> |
28 | #include <qfile.h> | 30 | #include <qfile.h> |
29 | 31 | ||
30 | #include "abtable.h" | 32 | #include "abtable.h" |
31 | 33 | ||
32 | #include <errno.h> | 34 | #include <errno.h> |
33 | #include <fcntl.h> | 35 | #include <fcntl.h> |
34 | #include <unistd.h> | 36 | #include <unistd.h> |
35 | #include <stdlib.h> | 37 | #include <stdlib.h> |
36 | 38 | ||
37 | #include <ctype.h> //toupper() for key hack | 39 | #include <ctype.h> //toupper() for key hack |
38 | 40 | ||
39 | static bool contactCompare( const Contact &cnt, const QRegExp &r, int category ); | 41 | static bool contactCompare( const Contact &cnt, const QRegExp &r, int category ); |
40 | 42 | ||
41 | //### qtmail/addresslist.cpp hardcodes this filename as well | 43 | //### qtmail/addresslist.cpp hardcodes this filename as well |
42 | static QString journalFileName() | 44 | static QString journalFileName() |
43 | { | 45 | { |
44 | QString str = getenv("HOME"); | 46 | QString str = getenv("HOME"); |
45 | str +="/.abjournal"; | 47 | str +="/.abjournal"; |
46 | return str; | 48 | return str; |
47 | } | 49 | } |
48 | 50 | ||
49 | 51 | ||
50 | 52 | ||
51 | /*! | 53 | /*! |
52 | \class AbTableItem abtable.h | 54 | \class AbTableItem abtable.h |
53 | 55 | ||
54 | \brief QTableItem based class for showing a field of an entry | 56 | \brief QTableItem based class for showing a field of an entry |
55 | */ | 57 | */ |
56 | 58 | ||
57 | AbTableItem::AbTableItem( QTable *t, EditType et, const QString &s, | 59 | AbTableItem::AbTableItem( QTable *t, EditType et, const QString &s, |
58 | const QString &secondSortKey) | 60 | const QString &secondSortKey) |
59 | : QTableItem( t, et, s ) | 61 | : QTableItem( t, et, s ) |
60 | { | 62 | { |
61 | // sortKey = s.lower() + QChar( '\0' ) + secondSortKey.lower(); | 63 | // sortKey = s.lower() + QChar( '\0' ) + secondSortKey.lower(); |
62 | sortKey = Qtopia::buildSortKey( s, secondSortKey ); | 64 | sortKey = Qtopia::buildSortKey( s, secondSortKey ); |
63 | } | 65 | } |
64 | 66 | ||
65 | int AbTableItem::alignment() const | 67 | int AbTableItem::alignment() const |
66 | { | 68 | { |
67 | return AlignLeft|AlignVCenter; | 69 | return AlignLeft|AlignVCenter; |
68 | } | 70 | } |
69 | 71 | ||
70 | QString AbTableItem::key() const | 72 | QString AbTableItem::key() const |
71 | { | 73 | { |
72 | return sortKey; | 74 | return sortKey; |
73 | } | 75 | } |
74 | 76 | ||
75 | // A way to reset the item, without out doing a delete or a new... | 77 | // A way to reset the item, without out doing a delete or a new... |
76 | void AbTableItem::setItem( const QString &txt, const QString &secondKey ) | 78 | void AbTableItem::setItem( const QString &txt, const QString &secondKey ) |
77 | { | 79 | { |
78 | setText( txt ); | 80 | setText( txt ); |
79 | sortKey = Qtopia::buildSortKey( txt, secondKey ); | 81 | sortKey = Qtopia::buildSortKey( txt, secondKey ); |
80 | 82 | ||
81 | // sortKey = txt.lower() + QChar( '\0' ) + secondKey.lower(); | 83 | // sortKey = txt.lower() + QChar( '\0' ) + secondKey.lower(); |
82 | } | 84 | } |
83 | 85 | ||
84 | /*! | 86 | /*! |
85 | \class AbPickItem abtable.h | 87 | \class AbPickItem abtable.h |
86 | 88 | ||
87 | \brief QTableItem based class for showing slection of an entry | 89 | \brief QTableItem based class for showing slection of an entry |
88 | */ | 90 | */ |
89 | 91 | ||
90 | AbPickItem::AbPickItem( QTable *t ) : | 92 | AbPickItem::AbPickItem( QTable *t ) : |
91 | QTableItem(t, WhenCurrent, "?") | 93 | QTableItem(t, WhenCurrent, "?") |
92 | { | 94 | { |
93 | } | 95 | } |
94 | 96 | ||
95 | QWidget *AbPickItem::createEditor() const | 97 | QWidget *AbPickItem::createEditor() const |
96 | { | 98 | { |
97 | QComboBox* combo = new QComboBox( table()->viewport() ); | 99 | QComboBox* combo = new QComboBox( table()->viewport() ); |
98 | ( (AbPickItem*)this )->cb = combo; | 100 | ( (AbPickItem*)this )->cb = combo; |
99 | AbTable* t = static_cast<AbTable*>(table()); | 101 | AbTable* t = static_cast<AbTable*>(table()); |
100 | QStringList c = t->choiceNames(); | 102 | QStringList c = t->choiceNames(); |
101 | int cur = 0; | 103 | int cur = 0; |
102 | for (QStringList::ConstIterator it = c.begin(); it!=c.end(); ++it) { | 104 | for (QStringList::ConstIterator it = c.begin(); it!=c.end(); ++it) { |
103 | if ( *it == text() ) | 105 | if ( *it == text() ) |
104 | cur = combo->count(); | 106 | cur = combo->count(); |
105 | combo->insertItem(*it); | 107 | combo->insertItem(*it); |
106 | } | 108 | } |
107 | combo->setCurrentItem(cur); | 109 | combo->setCurrentItem(cur); |
108 | return combo; | 110 | return combo; |
109 | } | 111 | } |
110 | 112 | ||
111 | void AbPickItem::setContentFromEditor( QWidget *w ) | 113 | void AbPickItem::setContentFromEditor( QWidget *w ) |
112 | { | 114 | { |
113 | if ( w->inherits("QComboBox") ) | 115 | if ( w->inherits("QComboBox") ) |
114 | setText( ( (QComboBox*)w )->currentText() ); | 116 | setText( ( (QComboBox*)w )->currentText() ); |
115 | else | 117 | else |
116 | QTableItem::setContentFromEditor( w ); | 118 | QTableItem::setContentFromEditor( w ); |
117 | } | 119 | } |
118 | 120 | ||
119 | /*! | 121 | /*! |
120 | \class AbTable abtable.h | 122 | \class AbTable abtable.h |
121 | 123 | ||
122 | \brief QTable based class for showing a list of entries | 124 | \brief QTable based class for showing a list of entries |
123 | */ | 125 | */ |
124 | 126 | ||
125 | AbTable::AbTable( const QValueList<int> *order, QWidget *parent, const char *name ) | 127 | AbTable::AbTable( const QValueList<int> *order, QWidget *parent, const char *name ) |
126 | // #ifdef QT_QTABLE_NOHEADER_CONSTRUCTOR | 128 | // #ifdef QT_QTABLE_NOHEADER_CONSTRUCTOR |
127 | // : QTable( 0, 0, parent, name, TRUE ), | 129 | // : QTable( 0, 0, parent, name, TRUE ), |
128 | // #else | 130 | // #else |
129 | : QTable( parent, name ), | 131 | : QTable( parent, name ), |
130 | // #endif | 132 | // #endif |
131 | lastSortCol( -1 ), | 133 | lastSortCol( -1 ), |
132 | asc( TRUE ), | 134 | asc( TRUE ), |
133 | intFields( order ), | 135 | intFields( order ), |
134 | currFindRow( -2 ), | 136 | currFindRow( -2 ), |
135 | mCat( 0 ) | 137 | mCat( 0 ) |
136 | { | 138 | { |
137 | mCat.load( categoryFileName() ); | 139 | mCat.load( categoryFileName() ); |
138 | setSelectionMode( NoSelection ); | 140 | setSelectionMode( NoSelection ); |
139 | init(); | 141 | init(); |
140 | setSorting( TRUE ); | 142 | setSorting( TRUE ); |
141 | connect( this, SIGNAL(clicked(int,int,int,const QPoint &)), | 143 | connect( this, SIGNAL(clicked(int,int,int,const QPoint &)), |
142 | this, SLOT(itemClicked(int,int)) ); | 144 | this, SLOT(itemClicked(int,int)) ); |
143 | } | 145 | } |
144 | 146 | ||
145 | AbTable::~AbTable() | 147 | AbTable::~AbTable() |
146 | { | 148 | { |
147 | } | 149 | } |
148 | 150 | ||
149 | void AbTable::init() | 151 | void AbTable::init() |
150 | { | 152 | { |
151 | setNumRows( 0 ); | 153 | setNumRows( 0 ); |
152 | setNumCols( 2 ); | 154 | setNumCols( 2 ); |
153 | 155 | ||
154 | horizontalHeader()->setLabel( 0, tr( "Full Name" )); | 156 | horizontalHeader()->setLabel( 0, tr( "Full Name" )); |
155 | horizontalHeader()->setLabel( 1, tr( "Contact" )); | 157 | horizontalHeader()->setLabel( 1, tr( "Contact" )); |
156 | setLeftMargin( 0 ); | 158 | setLeftMargin( 0 ); |
157 | verticalHeader()->hide(); | 159 | verticalHeader()->hide(); |
158 | } | 160 | } |
159 | 161 | ||
160 | void AbTable::columnClicked( int col ) | 162 | void AbTable::columnClicked( int col ) |
161 | { | 163 | { |
162 | if ( !sorting() ) | 164 | if ( !sorting() ) |
163 | return; | 165 | return; |
164 | 166 | ||
165 | if ( lastSortCol == -1 ) | 167 | if ( lastSortCol == -1 ) |
166 | lastSortCol = col; | 168 | lastSortCol = col; |
167 | 169 | ||
168 | if ( col == lastSortCol ) { | 170 | if ( col == lastSortCol ) { |
169 | asc = !asc; | 171 | asc = !asc; |
170 | } else { | 172 | } else { |
171 | lastSortCol = col; | 173 | lastSortCol = col; |
172 | asc = TRUE; | 174 | asc = TRUE; |
173 | } | 175 | } |
174 | resort(); | 176 | resort(); |
175 | } | 177 | } |
176 | 178 | ||
177 | void AbTable::resort() | 179 | void AbTable::resort() |
178 | { | 180 | { |
179 | if ( sorting() ) { | 181 | if ( sorting() ) { |
180 | if ( lastSortCol == -1 ) | 182 | if ( lastSortCol == -1 ) |
181 | lastSortCol = 0; | 183 | lastSortCol = 0; |
182 | sortColumn( lastSortCol, asc, TRUE ); | 184 | sortColumn( lastSortCol, asc, TRUE ); |
183 | updateVisible(); | 185 | updateVisible(); |
184 | } | 186 | } |
185 | } | 187 | } |
186 | 188 | ||
187 | Contact AbTable::currentEntry() | 189 | Contact AbTable::currentEntry() |
188 | { | 190 | { |
189 | Contact cnt; | 191 | Contact cnt; |
190 | AbTableItem *abItem; | 192 | AbTableItem *abItem; |
191 | abItem = static_cast<AbTableItem*>(item( currentRow(), 0 )); | 193 | abItem = static_cast<AbTableItem*>(item( currentRow(), 0 )); |
192 | if ( abItem ) { | 194 | if ( abItem ) { |
193 | cnt = contactList[abItem]; | 195 | cnt = contactList[abItem]; |
194 | } | 196 | } |
195 | return cnt; | 197 | return cnt; |
196 | } | 198 | } |
197 | 199 | ||
198 | void AbTable::replaceCurrentEntry( const Contact &newContact ) | 200 | void AbTable::replaceCurrentEntry( const Contact &newContact ) |
199 | { | 201 | { |
200 | int row = currentRow(); | 202 | int row = currentRow(); |
201 | updateJournal( newContact, Contact::ACTION_REPLACE, row ); | 203 | updateJournal( newContact, Contact::ACTION_REPLACE, row ); |
202 | updateVisible(); | 204 | updateVisible(); |
203 | 205 | ||
204 | journalFreeReplace( newContact, row ); | 206 | journalFreeReplace( newContact, row ); |
205 | } | 207 | } |
206 | 208 | ||
207 | void AbTable::deleteCurrentEntry() | 209 | void AbTable::deleteCurrentEntry() |
208 | { | 210 | { |
209 | int row = currentRow(); | 211 | int row = currentRow(); |
210 | AbTableItem *abItem; | 212 | AbTableItem *abItem; |
211 | abItem = static_cast<AbTableItem*>(item( row, 0 )); | 213 | abItem = static_cast<AbTableItem*>(item( row, 0 )); |
212 | Contact oldContact; | 214 | Contact oldContact; |
213 | oldContact = contactList[abItem]; | 215 | oldContact = contactList[abItem]; |
214 | updateJournal( oldContact, Contact::ACTION_REMOVE, row ); | 216 | updateJournal( oldContact, Contact::ACTION_REMOVE, row ); |
215 | 217 | ||
216 | // a little wasteful, but it ensure's there is only one place | 218 | // a little wasteful, but it ensure's there is only one place |
217 | // where we delete. | 219 | // where we delete. |
218 | journalFreeRemove( row ); | 220 | journalFreeRemove( row ); |
219 | updateVisible(); | 221 | updateVisible(); |
220 | 222 | ||
221 | if ( numRows() == 0 ) | 223 | if ( numRows() == 0 ) |
222 | emit empty( TRUE ); | 224 | emit empty( TRUE ); |
223 | } | 225 | } |
224 | 226 | ||
225 | void AbTable::clear() | 227 | void AbTable::clear() |
226 | { | 228 | { |
227 | contactList.clear(); | 229 | contactList.clear(); |
228 | for ( int r = 0; r < numRows(); ++r ) { | 230 | for ( int r = 0; r < numRows(); ++r ) { |
229 | for ( int c = 0; c < numCols(); ++c ) { | 231 | for ( int c = 0; c < numCols(); ++c ) { |
230 | if ( cellWidget( r, c ) ) | 232 | if ( cellWidget( r, c ) ) |
231 | clearCellWidget( r, c ); | 233 | clearCellWidget( r, c ); |
232 | clearCell( r, c ); | 234 | clearCell( r, c ); |
233 | } | 235 | } |
234 | } | 236 | } |
235 | setNumRows( 0 ); | 237 | setNumRows( 0 ); |
236 | } | 238 | } |
237 | 239 | ||
238 | void AbTable::refresh() | 240 | void AbTable::refresh() |
239 | { | 241 | { |
240 | int rows = numRows(); | 242 | int rows = numRows(); |
241 | QString value; | 243 | QString value; |
242 | AbTableItem *abi; | 244 | AbTableItem *abi; |
243 | for ( int r = 0; r < rows; ++r ) { | 245 | for ( int r = 0; r < rows; ++r ) { |
244 | abi = static_cast<AbTableItem*>( item(r, 0) ); | 246 | abi = static_cast<AbTableItem*>( item(r, 0) ); |
245 | value = findContactContact( contactList[abi] ); | 247 | value = findContactContact( contactList[abi] ); |
246 | static_cast<AbTableItem*>( item(r, 1) )->setItem( value, abi->text() ); | 248 | static_cast<AbTableItem*>( item(r, 1) )->setItem( value, abi->text() ); |
247 | } | 249 | } |
248 | resort(); | 250 | resort(); |
249 | } | 251 | } |
250 | 252 | ||
251 | void AbTable::keyPressEvent( QKeyEvent *e ) | 253 | void AbTable::keyPressEvent( QKeyEvent *e ) |
252 | { | 254 | { |
253 | char key = toupper( e->ascii() ); | 255 | char key = toupper( e->ascii() ); |
254 | 256 | ||
255 | if ( key >= 'A' && key <= 'Z' ) | 257 | if ( key >= 'A' && key <= 'Z' ) |
256 | moveTo( key ); | 258 | moveTo( key ); |
257 | 259 | ||
258 | switch( e->key() ) { | 260 | switch( e->key() ) { |
259 | case Qt::Key_Space: | 261 | case Qt::Key_Space: |
260 | case Qt::Key_Return: | 262 | case Qt::Key_Return: |
261 | case Qt::Key_Enter: | 263 | case Qt::Key_Enter: |
262 | emit details(); | 264 | emit details(); |
263 | break; | 265 | break; |
264 | default: | 266 | default: |
265 | QTable::keyPressEvent( e ); | 267 | QTable::keyPressEvent( e ); |
266 | } | 268 | } |
267 | } | 269 | } |
268 | 270 | ||
269 | void AbTable::moveTo( char c ) | 271 | void AbTable::moveTo( char c ) |
270 | { | 272 | { |
271 | 273 | ||
272 | int rows = numRows(); | 274 | int rows = numRows(); |
273 | QString value; | 275 | QString value; |
274 | AbTableItem *abi; | 276 | AbTableItem *abi; |
275 | int r; | 277 | int r; |
276 | if ( asc ) { | 278 | if ( asc ) { |
277 | r = 0; | 279 | r = 0; |
278 | while ( r < rows-1) { | 280 | while ( r < rows-1) { |
279 | abi = static_cast<AbTableItem*>( item(r, 0) ); | 281 | abi = static_cast<AbTableItem*>( item(r, 0) ); |
280 | QChar first = abi->key()[0]; | 282 | QChar first = abi->key()[0]; |
281 | //### is there a bug in QChar to char comparison??? | 283 | //### is there a bug in QChar to char comparison??? |
282 | if ( first.row() || first.cell() >= c ) | 284 | if ( first.row() || first.cell() >= c ) |
283 | break; | 285 | break; |
284 | r++; | 286 | r++; |
285 | } | 287 | } |
286 | } else { | 288 | } else { |
287 | //### should probably disable reverse sorting instead | 289 | //### should probably disable reverse sorting instead |
288 | r = rows - 1; | 290 | r = rows - 1; |
289 | while ( r > 0 ) { | 291 | while ( r > 0 ) { |
290 | abi = static_cast<AbTableItem*>( item(r, 0) ); | 292 | abi = static_cast<AbTableItem*>( item(r, 0) ); |
291 | QChar first = abi->key()[0]; | 293 | QChar first = abi->key()[0]; |
292 | //### is there a bug in QChar to char comparison??? | 294 | //### is there a bug in QChar to char comparison??? |
293 | if ( first.row() || first.cell() >= c ) | 295 | if ( first.row() || first.cell() >= c ) |
294 | break; | 296 | break; |
295 | r--; | 297 | r--; |
296 | } | 298 | } |
297 | } | 299 | } |
298 | setCurrentCell( r, currentColumn() ); | 300 | setCurrentCell( r, currentColumn() ); |
299 | } | 301 | } |
300 | 302 | ||
301 | 303 | ||
302 | QString AbTable::findContactName( const Contact &entry ) | 304 | QString AbTable::findContactName( const Contact &entry ) |
303 | { | 305 | { |
304 | // We use the fileAs, then company, defaultEmail | 306 | // We use the fileAs, then company, defaultEmail |
305 | QString str; | 307 | QString str; |
306 | str = entry.fileAs(); | 308 | str = entry.fileAs(); |
307 | if ( str.isEmpty() ) { | 309 | if ( str.isEmpty() ) { |
308 | str = entry.company(); | 310 | str = entry.company(); |
309 | if ( str.isEmpty() ) { | 311 | if ( str.isEmpty() ) { |
310 | str = entry.defaultEmail(); | 312 | str = entry.defaultEmail(); |
311 | } | 313 | } |
312 | } | 314 | } |
313 | return str; | 315 | return str; |
314 | } | 316 | } |
315 | 317 | ||
316 | QString AbTable::findContactContact( const Contact &entry ) | 318 | QString AbTable::findContactContact( const Contact &entry ) |
317 | { | 319 | { |
318 | QString value; | 320 | QString value; |
319 | value = ""; | 321 | value = ""; |
320 | for ( QValueList<int>::ConstIterator it = intFields->begin(); | 322 | for ( QValueList<int>::ConstIterator it = intFields->begin(); |
321 | it != intFields->end(); ++it ) { | 323 | it != intFields->end(); ++it ) { |
322 | switch ( *it ) { | 324 | switch ( *it ) { |
323 | default: | 325 | default: |
324 | break; | 326 | break; |
325 | case Qtopia::Title: | 327 | case Qtopia::Title: |
326 | value = entry.title(); | 328 | value = entry.title(); |
327 | break; | 329 | break; |
328 | case Qtopia::Suffix: | 330 | case Qtopia::Suffix: |
329 | value = entry.suffix(); | 331 | value = entry.suffix(); |
330 | break; | 332 | break; |
331 | case Qtopia::FileAs: | 333 | case Qtopia::FileAs: |
332 | value = entry.fileAs(); | 334 | value = entry.fileAs(); |
333 | break; | 335 | break; |
334 | case Qtopia::DefaultEmail: | 336 | case Qtopia::DefaultEmail: |
335 | value = entry.defaultEmail(); | 337 | value = entry.defaultEmail(); |
336 | case Qtopia::Emails: | 338 | case Qtopia::Emails: |
337 | value = entry.emails(); | 339 | value = entry.emails(); |
338 | break; | 340 | break; |
339 | case Qtopia::HomeStreet: | 341 | case Qtopia::HomeStreet: |
340 | value = entry.homeStreet(); | 342 | value = entry.homeStreet(); |
341 | break; | 343 | break; |
342 | case Qtopia::HomeCity: | 344 | case Qtopia::HomeCity: |
343 | value = entry.homeCity(); | 345 | value = entry.homeCity(); |
344 | break; | 346 | break; |
345 | case Qtopia::HomeState: | 347 | case Qtopia::HomeState: |
346 | value = entry.homeState(); | 348 | value = entry.homeState(); |
347 | break; | 349 | break; |
348 | case Qtopia::HomeZip: | 350 | case Qtopia::HomeZip: |
349 | value = entry.homeZip(); | 351 | value = entry.homeZip(); |
350 | break; | 352 | break; |
351 | case Qtopia::HomeCountry: | 353 | case Qtopia::HomeCountry: |
352 | value = entry.homeCountry(); | 354 | value = entry.homeCountry(); |
353 | break; | 355 | break; |
354 | case Qtopia::HomePhone: | 356 | case Qtopia::HomePhone: |
355 | value = entry.homePhone(); | 357 | value = entry.homePhone(); |
356 | break; | 358 | break; |
357 | case Qtopia::HomeFax: | 359 | case Qtopia::HomeFax: |
358 | value = entry.homeFax(); | 360 | value = entry.homeFax(); |
359 | break; | 361 | break; |
360 | case Qtopia::HomeMobile: | 362 | case Qtopia::HomeMobile: |
361 | value = entry.homeMobile(); | 363 | value = entry.homeMobile(); |
362 | break; | 364 | break; |
363 | case Qtopia::HomeWebPage: | 365 | case Qtopia::HomeWebPage: |
364 | value = entry.homeWebpage(); | 366 | value = entry.homeWebpage(); |
365 | break; | 367 | break; |
366 | case Qtopia::Company: | 368 | case Qtopia::Company: |
367 | value = entry.company(); | 369 | value = entry.company(); |
368 | break; | 370 | break; |
369 | case Qtopia::BusinessCity: | 371 | case Qtopia::BusinessCity: |
370 | value = entry.businessCity(); | 372 | value = entry.businessCity(); |
371 | break; | 373 | break; |
372 | case Qtopia::BusinessStreet: | 374 | case Qtopia::BusinessStreet: |
373 | value = entry.businessStreet(); | 375 | value = entry.businessStreet(); |
374 | break; | 376 | break; |
375 | case Qtopia::BusinessZip: | 377 | case Qtopia::BusinessZip: |
376 | value = entry.businessZip(); | 378 | value = entry.businessZip(); |
377 | break; | 379 | break; |
378 | case Qtopia::BusinessCountry: | 380 | case Qtopia::BusinessCountry: |
379 | value = entry.businessCountry(); | 381 | value = entry.businessCountry(); |
380 | break; | 382 | break; |
381 | case Qtopia::BusinessWebPage: | 383 | case Qtopia::BusinessWebPage: |
382 | value = entry.businessWebpage(); | 384 | value = entry.businessWebpage(); |
383 | break; | 385 | break; |
384 | case Qtopia::JobTitle: | 386 | case Qtopia::JobTitle: |
385 | value = entry.jobTitle(); | 387 | value = entry.jobTitle(); |
386 | break; | 388 | break; |
387 | case Qtopia::Department: | 389 | case Qtopia::Department: |
388 | value = entry.department(); | 390 | value = entry.department(); |
389 | break; | 391 | break; |
390 | case Qtopia::Office: | 392 | case Qtopia::Office: |
391 | value = entry.office(); | 393 | value = entry.office(); |
392 | break; | 394 | break; |
393 | case Qtopia::BusinessPhone: | 395 | case Qtopia::BusinessPhone: |
394 | value = entry.businessPhone(); | 396 | value = entry.businessPhone(); |
395 | break; | 397 | break; |
396 | case Qtopia::BusinessFax: | 398 | case Qtopia::BusinessFax: |
397 | value = entry.businessFax(); | 399 | value = entry.businessFax(); |
398 | break; | 400 | break; |
399 | case Qtopia::BusinessMobile: | 401 | case Qtopia::BusinessMobile: |
400 | value = entry.businessMobile(); | 402 | value = entry.businessMobile(); |
401 | break; | 403 | break; |
402 | case Qtopia::BusinessPager: | 404 | case Qtopia::BusinessPager: |
403 | value = entry.businessPager(); | 405 | value = entry.businessPager(); |
404 | break; | 406 | break; |
405 | case Qtopia::Profession: | 407 | case Qtopia::Profession: |
406 | value = entry.profession(); | 408 | value = entry.profession(); |
407 | break; | 409 | break; |
408 | case Qtopia::Assistant: | 410 | case Qtopia::Assistant: |
409 | value = entry.assistant(); | 411 | value = entry.assistant(); |
410 | break; | 412 | break; |
411 | case Qtopia::Manager: | 413 | case Qtopia::Manager: |
412 | value = entry.manager(); | 414 | value = entry.manager(); |
413 | break; | 415 | break; |
414 | case Qtopia::Spouse: | 416 | case Qtopia::Spouse: |
415 | value = entry.spouse(); | 417 | value = entry.spouse(); |
416 | break; | 418 | break; |
417 | case Qtopia::Gender: | 419 | case Qtopia::Gender: |
418 | value = entry.gender(); | 420 | value = entry.gender(); |
419 | break; | 421 | break; |
420 | case Qtopia::Birthday: | 422 | case Qtopia::Birthday: |
421 | value = entry.birthday(); | 423 | value = entry.birthday(); |
422 | break; | 424 | break; |
423 | case Qtopia::Anniversary: | 425 | case Qtopia::Anniversary: |
424 | value = entry.anniversary(); | 426 | value = entry.anniversary(); |
425 | break; | 427 | break; |
426 | case Qtopia::Nickname: | 428 | case Qtopia::Nickname: |
427 | value = entry.nickname(); | 429 | value = entry.nickname(); |
428 | break; | 430 | break; |
429 | case Qtopia::Children: | 431 | case Qtopia::Children: |
430 | value = entry.children(); | 432 | value = entry.children(); |
431 | break; | 433 | break; |
432 | case Qtopia::Notes: | 434 | case Qtopia::Notes: |
433 | value = entry.notes(); | 435 | value = entry.notes(); |
434 | break; | 436 | break; |
435 | } | 437 | } |
436 | if ( !value.isEmpty() ) | 438 | if ( !value.isEmpty() ) |
437 | break; | 439 | break; |
438 | } | 440 | } |
439 | return value; | 441 | return value; |
440 | } | 442 | } |
441 | 443 | ||
442 | void AbTable::addEntry( const Contact &newCnt ) | 444 | void AbTable::addEntry( const Contact &newCnt ) |
443 | { | 445 | { |
444 | int row = numRows(); | 446 | int row = numRows(); |
445 | setNumRows( row + 1 ); | 447 | setNumRows( row + 1 ); |
446 | updateJournal( newCnt, Contact::ACTION_ADD ); | 448 | updateJournal( newCnt, Contact::ACTION_ADD ); |
447 | insertIntoTable( newCnt, row ); | 449 | insertIntoTable( newCnt, row ); |
448 | setCurrentCell( row, 0 ); | 450 | setCurrentCell( row, 0 ); |
449 | updateVisible(); | 451 | updateVisible(); |
450 | } | 452 | } |
451 | 453 | ||
454 | void AbTable::resizeRows( int size ) { | ||
455 | |||
456 | if (numRows()) { | ||
457 | for (int i = 0; i < numRows(); i++) { | ||
458 | setRowHeight( i, size ); | ||
459 | } | ||
460 | } | ||
461 | } | ||
462 | |||
452 | void AbTable::updateJournal( const Contact &cnt, | 463 | void AbTable::updateJournal( const Contact &cnt, |
453 | Contact::journal_action action, int row ) | 464 | Contact::journal_action action, int row ) |
454 | { | 465 | { |
455 | QFile f( journalFileName() ); | 466 | QFile f( journalFileName() ); |
456 | if ( !f.open(IO_WriteOnly|IO_Append) ) | 467 | if ( !f.open(IO_WriteOnly|IO_Append) ) |
457 | return; | 468 | return; |
458 | QString buf; | 469 | QString buf; |
459 | QCString str; | 470 | QCString str; |
460 | buf = "<Contact "; | 471 | buf = "<Contact "; |
461 | cnt.save( buf ); | 472 | cnt.save( buf ); |
462 | buf += " action=\"" + QString::number( (int)action ) + "\" "; | 473 | buf += " action=\"" + QString::number( (int)action ) + "\" "; |
463 | if ( action == Contact::ACTION_REMOVE || action == Contact::ACTION_REPLACE) | 474 | if ( action == Contact::ACTION_REMOVE || action == Contact::ACTION_REPLACE) |
464 | buf += " actionrow=\"" + QString::number(row) + "\" "; | 475 | buf += " actionrow=\"" + QString::number(row) + "\" "; |
465 | buf += "/>\n"; | 476 | buf += "/>\n"; |
466 | QCString cstr = buf.utf8(); | 477 | QCString cstr = buf.utf8(); |
467 | f.writeBlock( cstr.data(), cstr.length() ); | 478 | f.writeBlock( cstr.data(), cstr.length() ); |
468 | QCopEnvelope( "QPE/PIM", "addressbookUpdated()" ); | 479 | QCopEnvelope( "QPE/PIM", "addressbookUpdated()" ); |
469 | } | 480 | } |
470 | 481 | ||
471 | bool AbTable::save( const QString &fn ) | 482 | bool AbTable::save( const QString &fn ) |
472 | { | 483 | { |
473 | // QTime t; | 484 | // QTime t; |
474 | // t.start(); | 485 | // t.start(); |
475 | 486 | ||
476 | QString strNewFile = fn + ".new"; | 487 | QString strNewFile = fn + ".new"; |
477 | QFile f( strNewFile ); | 488 | QFile f( strNewFile ); |
478 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) | 489 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) |
479 | return false; | 490 | return false; |
480 | 491 | ||
481 | int total_written; | 492 | int total_written; |
482 | QString out; | 493 | QString out; |
483 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" | 494 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" |
484 | " <Groups>\n" | 495 | " <Groups>\n" |
485 | " </Groups>\n" | 496 | " </Groups>\n" |
486 | " <Contacts>\n"; | 497 | " <Contacts>\n"; |
487 | QMapIterator<AbTableItem*, Contact> it; | 498 | QMapIterator<AbTableItem*, Contact> it; |
488 | for ( it = contactList.begin(); it != contactList.end(); ++it ) { | 499 | for ( it = contactList.begin(); it != contactList.end(); ++it ) { |
489 | out += "<Contact "; | 500 | out += "<Contact "; |
490 | it.data().save( out ); | 501 | it.data().save( out ); |
491 | out += "/>\n"; | 502 | out += "/>\n"; |
492 | QCString cstr = out.utf8(); | 503 | QCString cstr = out.utf8(); |
493 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 504 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
494 | if ( total_written != int(cstr.length()) ) { | 505 | if ( total_written != int(cstr.length()) ) { |
495 | f.close(); | 506 | f.close(); |
496 | QFile::remove( strNewFile ); | 507 | QFile::remove( strNewFile ); |
497 | return false; | 508 | return false; |
498 | } | 509 | } |
499 | out = ""; | 510 | out = ""; |
500 | } | 511 | } |
501 | out += " </Contacts>\n</AddressBook>\n"; | 512 | out += " </Contacts>\n</AddressBook>\n"; |
502 | 513 | ||
503 | QCString cstr = out.utf8(); | 514 | QCString cstr = out.utf8(); |
504 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 515 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
505 | if ( total_written != int(cstr.length()) ) { | 516 | if ( total_written != int(cstr.length()) ) { |
506 | f.close(); | 517 | f.close(); |
507 | QFile::remove( strNewFile ); | 518 | QFile::remove( strNewFile ); |
508 | return false; | 519 | return false; |
509 | } | 520 | } |
510 | f.close(); | 521 | f.close(); |
511 | 522 | ||
512 | // qDebug("saving: %d", t.elapsed() ); | 523 | // qDebug("saving: %d", t.elapsed() ); |
513 | 524 | ||
514 | // move the file over, I'm just going to use the system call | 525 | // move the file over, I'm just going to use the system call |
515 | // because, I don't feel like using QDir. | 526 | // because, I don't feel like using QDir. |
516 | if ( ::rename( strNewFile.latin1(), fn.latin1() ) < 0 ) { | 527 | if ( ::rename( strNewFile.latin1(), fn.latin1() ) < 0 ) { |
517 | qWarning( "problem renaming file %s to %s, errno: %d", | 528 | qWarning( "problem renaming file %s to %s, errno: %d", |
518 | strNewFile.latin1(), fn.latin1(), errno ); | 529 | strNewFile.latin1(), fn.latin1(), errno ); |
519 | // remove the tmp file... | 530 | // remove the tmp file... |
520 | QFile::remove( strNewFile ); | 531 | QFile::remove( strNewFile ); |
521 | } | 532 | } |
522 | // remove the journal... | 533 | // remove the journal... |
523 | QFile::remove( journalFileName() ); | 534 | QFile::remove( journalFileName() ); |
524 | return true; | 535 | return true; |
525 | } | 536 | } |
526 | 537 | ||
527 | void AbTable::load( const QString &fn ) | 538 | void AbTable::load( const QString &fn ) |
528 | { | 539 | { |
529 | setSorting( false ); | 540 | setSorting( false ); |
530 | loadFile( fn, false ); | 541 | loadFile( fn, false ); |
531 | // merge in the journal | 542 | // merge in the journal |
532 | if ( QFile::exists( journalFileName() ) ) { | 543 | if ( QFile::exists( journalFileName() ) ) { |
533 | loadFile( journalFileName(), true ); | 544 | loadFile( journalFileName(), true ); |
534 | save( fn ); | 545 | save( fn ); |
535 | } | 546 | } |
536 | setSorting( true ); | 547 | setSorting( true ); |
537 | resort(); | 548 | resort(); |
538 | } | 549 | } |
539 | 550 | ||
540 | void AbTable::loadFile( const QString &strFile, bool journalFile ) | 551 | void AbTable::loadFile( const QString &strFile, bool journalFile ) |
541 | { | 552 | { |
542 | // QTime t; | 553 | // QTime t; |
543 | // t.start(); | 554 | // t.start(); |
544 | QFile f( strFile ); | 555 | QFile f( strFile ); |
545 | if ( !f.open(IO_ReadOnly) ) | 556 | if ( !f.open(IO_ReadOnly) ) |
546 | return; | 557 | return; |
547 | QList<Contact> list; | 558 | QList<Contact> list; |
548 | list.setAutoDelete( TRUE ); | 559 | list.setAutoDelete( TRUE ); |
549 | QByteArray ba = f.readAll(); | 560 | QByteArray ba = f.readAll(); |
550 | f.close(); | 561 | f.close(); |
551 | char *uc = ba.data();//(QChar *)data.unicode(); | 562 | char *uc = ba.data();//(QChar *)data.unicode(); |
552 | int len = ba.size();//data.length(); | 563 | int len = ba.size();//data.length(); |
553 | bool foundAction = false; | 564 | bool foundAction = false; |
554 | Contact::journal_action action; | 565 | Contact::journal_action action; |
555 | bool foundKey = false; | 566 | bool foundKey = false; |
556 | int journalKey = 0; | 567 | int journalKey = 0; |
557 | 568 | ||
558 | const int JOURNALACTION = Qtopia::Notes + 1; | 569 | const int JOURNALACTION = Qtopia::Notes + 1; |
559 | const int JOURNALROW = JOURNALACTION + 1; | 570 | const int JOURNALROW = JOURNALACTION + 1; |
560 | 571 | ||
561 | // ********************************** | 572 | // ********************************** |
562 | // CHANGE THE SIZE OF THE DICT IF YOU ADD ANY MORE FIELDS!!!! | 573 | // CHANGE THE SIZE OF THE DICT IF YOU ADD ANY MORE FIELDS!!!! |
563 | // ********************************** | 574 | // ********************************** |
564 | QAsciiDict<int> dict( 47 ); | 575 | QAsciiDict<int> dict( 47 ); |
565 | dict.setAutoDelete( TRUE ); | 576 | dict.setAutoDelete( TRUE ); |
566 | dict.insert( "Uid", new int(Qtopia::AddressUid) ); | 577 | dict.insert( "Uid", new int(Qtopia::AddressUid) ); |
567 | dict.insert( "Title", new int(Qtopia::Title) ); | 578 | dict.insert( "Title", new int(Qtopia::Title) ); |
568 | dict.insert( "FirstName", new int(Qtopia::FirstName) ); | 579 | dict.insert( "FirstName", new int(Qtopia::FirstName) ); |
569 | dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); | 580 | dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); |
570 | dict.insert( "LastName", new int(Qtopia::LastName) ); | 581 | dict.insert( "LastName", new int(Qtopia::LastName) ); |
571 | dict.insert( "Suffix", new int(Qtopia::Suffix) ); | 582 | dict.insert( "Suffix", new int(Qtopia::Suffix) ); |
572 | dict.insert( "FileAs", new int(Qtopia::FileAs) ); | 583 | dict.insert( "FileAs", new int(Qtopia::FileAs) ); |
573 | dict.insert( "Categories", new int(Qtopia::AddressCategory) ); | 584 | dict.insert( "Categories", new int(Qtopia::AddressCategory) ); |
574 | dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); | 585 | dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); |
575 | dict.insert( "Emails", new int(Qtopia::Emails) ); | 586 | dict.insert( "Emails", new int(Qtopia::Emails) ); |
576 | dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); | 587 | dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); |
577 | dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); | 588 | dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); |
578 | dict.insert( "HomeState", new int(Qtopia::HomeState) ); | 589 | dict.insert( "HomeState", new int(Qtopia::HomeState) ); |
579 | dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); | 590 | dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); |
580 | dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); | 591 | dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); |
581 | dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); | 592 | dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); |
582 | dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); | 593 | dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); |
583 | dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); | 594 | dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); |
584 | dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); | 595 | dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); |
585 | dict.insert( "Company", new int(Qtopia::Company) ); | 596 | dict.insert( "Company", new int(Qtopia::Company) ); |
586 | dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); | 597 | dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); |
587 | dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); | 598 | dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); |
588 | dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); | 599 | dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); |
589 | dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); | 600 | dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); |
590 | dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); | 601 | dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); |
591 | dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); | 602 | dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); |
592 | dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); | 603 | dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); |
593 | dict.insert( "Department", new int(Qtopia::Department) ); | 604 | dict.insert( "Department", new int(Qtopia::Department) ); |
594 | dict.insert( "Office", new int(Qtopia::Office) ); | 605 | dict.insert( "Office", new int(Qtopia::Office) ); |
595 | dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); | 606 | dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); |
596 | dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); | 607 | dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); |
597 | dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); | 608 | dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); |
598 | dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); | 609 | dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); |
599 | dict.insert( "Profession", new int(Qtopia::Profession) ); | 610 | dict.insert( "Profession", new int(Qtopia::Profession) ); |
600 | dict.insert( "Assistant", new int(Qtopia::Assistant) ); | 611 | dict.insert( "Assistant", new int(Qtopia::Assistant) ); |
601 | dict.insert( "Manager", new int(Qtopia::Manager) ); | 612 | dict.insert( "Manager", new int(Qtopia::Manager) ); |
602 | dict.insert( "Spouse", new int(Qtopia::Spouse) ); | 613 | dict.insert( "Spouse", new int(Qtopia::Spouse) ); |
603 | dict.insert( "Children", new int(Qtopia::Children) ); | 614 | dict.insert( "Children", new int(Qtopia::Children) ); |
604 | dict.insert( "Gender", new int(Qtopia::Gender) ); | 615 | dict.insert( "Gender", new int(Qtopia::Gender) ); |
605 | dict.insert( "Birthday", new int(Qtopia::Birthday) ); | 616 | dict.insert( "Birthday", new int(Qtopia::Birthday) ); |
606 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); | 617 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); |
607 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); | 618 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); |
608 | dict.insert( "Notes", new int(Qtopia::Notes) ); | 619 | dict.insert( "Notes", new int(Qtopia::Notes) ); |
609 | dict.insert( "action", new int(JOURNALACTION) ); | 620 | dict.insert( "action", new int(JOURNALACTION) ); |
610 | dict.insert( "actionrow", new int(JOURNALROW) ); | 621 | dict.insert( "actionrow", new int(JOURNALROW) ); |
611 | 622 | ||
612 | int i = 0; | 623 | int i = 0; |
613 | int num = 0; | 624 | int num = 0; |
614 | char *point; | 625 | char *point; |
615 | while ( (point = strstr( uc+i, "<Contact " ) ) != NULL ) { | 626 | while ( (point = strstr( uc+i, "<Contact " ) ) != NULL ) { |
616 | i = point - uc; | 627 | i = point - uc; |
617 | // if we are reading the standard file, we just need to | 628 | // if we are reading the standard file, we just need to |
618 | // insert info, so just say we'll do an insert... | 629 | // insert info, so just say we'll do an insert... |
619 | action = Contact::ACTION_ADD; | 630 | action = Contact::ACTION_ADD; |
620 | // new Contact | 631 | // new Contact |
621 | Contact *cnt = new Contact; | 632 | Contact *cnt = new Contact; |
622 | i += 9; | 633 | i += 9; |
623 | while ( 1 ) { | 634 | while ( 1 ) { |
624 | while ( i < len && (uc[i] == ' ' || uc[i] == '\n' || uc[i] == '\r') ) | 635 | while ( i < len && (uc[i] == ' ' || uc[i] == '\n' || uc[i] == '\r') ) |
625 | i++; | 636 | i++; |
626 | if ( i >= len-2 || (uc[i] == '/' && uc[i+1] == '>') ) | 637 | if ( i >= len-2 || (uc[i] == '/' && uc[i+1] == '>') ) |
627 | break; | 638 | break; |
628 | // we have another attribute read it. | 639 | // we have another attribute read it. |
629 | int j = i; | 640 | int j = i; |
630 | while ( j < len && uc[j] != '=' ) | 641 | while ( j < len && uc[j] != '=' ) |
631 | j++; | 642 | j++; |
632 | char *attr = uc+i; | 643 | char *attr = uc+i; |
633 | uc[j] = '\0'; | 644 | uc[j] = '\0'; |
634 | //qDebug("attr=%s", attr.latin1() ); | 645 | //qDebug("attr=%s", attr.latin1() ); |
635 | i = ++j; // skip = | 646 | i = ++j; // skip = |
636 | while ( i < len && uc[i] != '"' ) | 647 | while ( i < len && uc[i] != '"' ) |
637 | i++; | 648 | i++; |
638 | j = ++i; | 649 | j = ++i; |
639 | bool haveEnt = FALSE; | 650 | bool haveEnt = FALSE; |
640 | bool haveUtf = FALSE; | 651 | bool haveUtf = FALSE; |
641 | while ( j < len && uc[j] != '"' ) { | 652 | while ( j < len && uc[j] != '"' ) { |
642 | if ( uc[j] == '&' ) | 653 | if ( uc[j] == '&' ) |
643 | haveEnt = TRUE; | 654 | haveEnt = TRUE; |
644 | if ( ((unsigned char)uc[j]) > 0x7f ) | 655 | if ( ((unsigned char)uc[j]) > 0x7f ) |
645 | haveUtf = TRUE; | 656 | haveUtf = TRUE; |
646 | j++; | 657 | j++; |
647 | } | 658 | } |
648 | 659 | ||
649 | if ( j == i ) { | 660 | if ( j == i ) { |
650 | // empty value | 661 | // empty value |
651 | i = j + 1; | 662 | i = j + 1; |
652 | continue; | 663 | continue; |
653 | } | 664 | } |
654 | 665 | ||
655 | QString value = haveUtf ? QString::fromUtf8( uc+i, j-i ) | 666 | QString value = haveUtf ? QString::fromUtf8( uc+i, j-i ) |
656 | : QString::fromLatin1( uc+i, j-i ); | 667 | : QString::fromLatin1( uc+i, j-i ); |
657 | if ( haveEnt ) | 668 | if ( haveEnt ) |
658 | value = Qtopia::plainString( value ); | 669 | value = Qtopia::plainString( value ); |
659 | i = j + 1; | 670 | i = j + 1; |
660 | 671 | ||
661 | int *find = dict[ attr ]; | 672 | int *find = dict[ attr ]; |
662 | if ( !find ) { | 673 | if ( !find ) { |
663 | cnt->setCustomField(attr, value); | 674 | cnt->setCustomField(attr, value); |
664 | continue; | 675 | continue; |
665 | } | 676 | } |
666 | #if 1 | 677 | #if 1 |
667 | switch( *find ) { | 678 | switch( *find ) { |
668 | case Qtopia::AddressUid: | 679 | case Qtopia::AddressUid: |
669 | cnt->setUid( value.toInt() ); | 680 | cnt->setUid( value.toInt() ); |
670 | break; | 681 | break; |
671 | case Qtopia::AddressCategory: | 682 | case Qtopia::AddressCategory: |
672 | cnt->setCategories( Qtopia::Record::idsFromString( value )); | 683 | cnt->setCategories( Qtopia::Record::idsFromString( value )); |
673 | break; | 684 | break; |
674 | case JOURNALACTION: | 685 | case JOURNALACTION: |
675 | action = Contact::journal_action(value.toInt()); | 686 | action = Contact::journal_action(value.toInt()); |
676 | break; | 687 | break; |
677 | case JOURNALROW: | 688 | case JOURNALROW: |
678 | journalKey = value.toInt(); | 689 | journalKey = value.toInt(); |
679 | break; | 690 | break; |
680 | 691 | ||
681 | default: | 692 | default: |
682 | cnt->insert( *find, value ); | 693 | cnt->insert( *find, value ); |
683 | break; | 694 | break; |
684 | } | 695 | } |
685 | #endif | 696 | #endif |
686 | } | 697 | } |
687 | 698 | ||
688 | // sadly we can't delay adding of items from the journal to get | 699 | // sadly we can't delay adding of items from the journal to get |
689 | // the proper effect, but then, the journal should _never_ be | 700 | // the proper effect, but then, the journal should _never_ be |
690 | // that huge, and recovering from a crash is not necessarily | 701 | // that huge, and recovering from a crash is not necessarily |
691 | // a *fast* thing. | 702 | // a *fast* thing. |
692 | switch ( action ) { | 703 | switch ( action ) { |
693 | case Contact::ACTION_ADD: | 704 | case Contact::ACTION_ADD: |
694 | if ( journalFile ) { | 705 | if ( journalFile ) { |
695 | int myrows = numRows(); | 706 | int myrows = numRows(); |
696 | setNumRows( myrows + 1 ); | 707 | setNumRows( myrows + 1 ); |
697 | insertIntoTable( *cnt, myrows ); | 708 | insertIntoTable( *cnt, myrows ); |
698 | delete cnt; | 709 | delete cnt; |
699 | } | 710 | } |
700 | else | 711 | else |
701 | list.append( cnt ); | 712 | list.append( cnt ); |
702 | break; | 713 | break; |
703 | case Contact::ACTION_REMOVE: | 714 | case Contact::ACTION_REMOVE: |
704 | // yup, we don't use the entry to remove the object... | 715 | // yup, we don't use the entry to remove the object... |
705 | journalFreeRemove( journalKey ); | 716 | journalFreeRemove( journalKey ); |
706 | delete cnt; | 717 | delete cnt; |
707 | break; | 718 | break; |
708 | case Contact::ACTION_REPLACE: | 719 | case Contact::ACTION_REPLACE: |
709 | journalFreeReplace( *cnt, journalKey ); | 720 | journalFreeReplace( *cnt, journalKey ); |
710 | delete cnt; | 721 | delete cnt; |
711 | break; | 722 | break; |
712 | default: | 723 | default: |
713 | break; | 724 | break; |
714 | } | 725 | } |
715 | num++; | 726 | num++; |
716 | foundAction = false; | 727 | foundAction = false; |
717 | foundKey = false; | 728 | foundKey = false; |
718 | // if ( num % 100 == 0 ) { | 729 | // if ( num % 100 == 0 ) { |
719 | // qDebug("loading file, num=%d, t=%d", num, t.elapsed() ); | 730 | // qDebug("loading file, num=%d, t=%d", num, t.elapsed() ); |
720 | // } | 731 | // } |
721 | } | 732 | } |
722 | if ( list.count() > 0 ) { | 733 | if ( list.count() > 0 ) { |
723 | internalAddEntries( list ); | 734 | internalAddEntries( list ); |
724 | } | 735 | } |
725 | // qDebug("done loading %d, t=%d", num, t.elapsed() ); | 736 | // qDebug("done loading %d, t=%d", num, t.elapsed() ); |
726 | 737 | ||
727 | } | 738 | } |
728 | 739 | ||
729 | void AbTable::realignTable( int row ) | 740 | void AbTable::realignTable( int row ) |
730 | { | 741 | { |
731 | QTableItem *ti1, | 742 | QTableItem *ti1, |
732 | *ti2; | 743 | *ti2; |
733 | int totalRows = numRows(); | 744 | int totalRows = numRows(); |
734 | for ( int curr = row; curr < totalRows - 1; curr++ ) { | 745 | for ( int curr = row; curr < totalRows - 1; curr++ ) { |
735 | // the same info from the todo list still applies, but I | 746 | // the same info from the todo list still applies, but I |
736 | // don't think it is _too_ bad. | 747 | // don't think it is _too_ bad. |
737 | ti1 = item( curr + 1, 0 ); | 748 | ti1 = item( curr + 1, 0 ); |
738 | ti2 = item( curr + 1, 1 ); | 749 | ti2 = item( curr + 1, 1 ); |
739 | takeItem( ti1 ); | 750 | takeItem( ti1 ); |
740 | takeItem( ti2 ); | 751 | takeItem( ti2 ); |
741 | setItem( curr, 0, ti1 ); | 752 | setItem( curr, 0, ti1 ); |
742 | setItem( curr, 1, ti2 ); | 753 | setItem( curr, 1, ti2 ); |
743 | } | 754 | } |
744 | setNumRows( totalRows - 1 ); | 755 | setNumRows( totalRows - 1 ); |
745 | resort(); | 756 | resort(); |
746 | } | 757 | } |
747 | 758 | ||
748 | void AbTable::insertIntoTable( const Contact &cnt, int row ) | 759 | void AbTable::insertIntoTable( const Contact &cnt, int row ) |
749 | { | 760 | { |
750 | QString strName, | 761 | QString strName, |
751 | strContact; | 762 | strContact; |
752 | 763 | ||
753 | strName = findContactName( cnt ); | 764 | strName = findContactName( cnt ); |
754 | strContact = findContactContact( cnt ); | 765 | strContact = findContactContact( cnt ); |
755 | 766 | ||
756 | AbTableItem *ati; | 767 | AbTableItem *ati; |
757 | ati = new AbTableItem( this, QTableItem::Never, strName, strContact); | 768 | ati = new AbTableItem( this, QTableItem::Never, strName, strContact); |
758 | contactList.insert( ati, cnt ); | 769 | contactList.insert( ati, cnt ); |
759 | setItem( row, 0, ati ); | 770 | setItem( row, 0, ati ); |
760 | ati = new AbTableItem( this, QTableItem::Never, strContact, strName); | 771 | ati = new AbTableItem( this, QTableItem::Never, strContact, strName); |
761 | setItem( row, 1, ati ); | 772 | setItem( row, 1, ati ); |
762 | 773 | ||
763 | //### cannot do this; table only has two columns at this point | 774 | //### cannot do this; table only has two columns at this point |
764 | // setItem( row, 2, new AbPickItem( this ) ); | 775 | // setItem( row, 2, new AbPickItem( this ) ); |
765 | 776 | ||
766 | // resort at some point? | 777 | // resort at some point? |
767 | } | 778 | } |
768 | 779 | ||
769 | void AbTable::internalAddEntries( QList<Contact> &list ) | 780 | void AbTable::internalAddEntries( QList<Contact> &list ) |
770 | { | 781 | { |
771 | setUpdatesEnabled( FALSE ); | 782 | setUpdatesEnabled( FALSE ); |
772 | setNumRows( list.count() ); | 783 | setNumRows( list.count() ); |
773 | int row = 0; | 784 | int row = 0; |
774 | Contact *it; | 785 | Contact *it; |
775 | for ( it = list.first(); it; it = list.next() ) | 786 | for ( it = list.first(); it; it = list.next() ) |
776 | insertIntoTable( *it, row++ ); | 787 | insertIntoTable( *it, row++ ); |
777 | resort(); | 788 | resort(); |
778 | setUpdatesEnabled( TRUE ); | 789 | setUpdatesEnabled( TRUE ); |
779 | } | 790 | } |
780 | 791 | ||
781 | 792 | ||
782 | void AbTable::journalFreeReplace( const Contact &cnt, int row ) | 793 | void AbTable::journalFreeReplace( const Contact &cnt, int row ) |
783 | { | 794 | { |
784 | QString strName, | 795 | QString strName, |
785 | strContact; | 796 | strContact; |
786 | AbTableItem *ati; | 797 | AbTableItem *ati; |
787 | 798 | ||
788 | strName = findContactName( cnt ); | 799 | strName = findContactName( cnt ); |
789 | strContact = findContactContact( cnt ); | 800 | strContact = findContactContact( cnt ); |
790 | ati = static_cast<AbTableItem*>(item(row, 0)); | 801 | ati = static_cast<AbTableItem*>(item(row, 0)); |
791 | contactList.remove( ati ); | 802 | contactList.remove( ati ); |
792 | ati->setItem( strName, strContact ); | 803 | ati->setItem( strName, strContact ); |
793 | contactList.insert( ati, cnt ); | 804 | contactList.insert( ati, cnt ); |
794 | 805 | ||
795 | ati = static_cast<AbTableItem*>(item(row, 1)); | 806 | ati = static_cast<AbTableItem*>(item(row, 1)); |
796 | ati->setItem( strContact, strName ); | 807 | ati->setItem( strContact, strName ); |
797 | } | 808 | } |
798 | 809 | ||
799 | void AbTable::journalFreeRemove( int row ) | 810 | void AbTable::journalFreeRemove( int row ) |
800 | { | 811 | { |
801 | AbTableItem *ati; | 812 | AbTableItem *ati; |
802 | ati = static_cast<AbTableItem*>(item(row, 0)); | 813 | ati = static_cast<AbTableItem*>(item(row, 0)); |
803 | if ( !ati ) | 814 | if ( !ati ) |
804 | return; | 815 | return; |
805 | contactList.remove( ati ); | 816 | contactList.remove( ati ); |
806 | realignTable( row ); | 817 | realignTable( row ); |
807 | } | 818 | } |
808 | 819 | ||
809 | #if QT_VERSION <= 230 | 820 | #if QT_VERSION <= 230 |
810 | #ifndef SINGLE_APP | 821 | #ifndef SINGLE_APP |
811 | void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch ) | 822 | void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch ) |
812 | { | 823 | { |
813 | // Region of the rect we should draw | 824 | // Region of the rect we should draw |
814 | QRegion reg( QRect( cx, cy, cw, ch ) ); | 825 | QRegion reg( QRect( cx, cy, cw, ch ) ); |
815 | // Subtract the table from it | 826 | // Subtract the table from it |
816 | reg = reg.subtract( QRect( QPoint( 0, 0 ), tableSize() ) ); | 827 | reg = reg.subtract( QRect( QPoint( 0, 0 ), tableSize() ) ); |
817 | // And draw the rectangles (transformed as needed) | 828 | // And draw the rectangles (transformed as needed) |
818 | QArray<QRect> r = reg.rects(); | 829 | QArray<QRect> r = reg.rects(); |
819 | for (unsigned int i=0; i<r.count(); i++) | 830 | for (unsigned int i=0; i<r.count(); i++) |
820 | p->fillRect( r[i], colorGroup().brush( QColorGroup::Base ) ); | 831 | p->fillRect( r[i], colorGroup().brush( QColorGroup::Base ) ); |
821 | } | 832 | } |
822 | #endif | 833 | #endif |
823 | #endif | 834 | #endif |
824 | 835 | ||
825 | 836 | ||
826 | // int AbTable::rowHeight( int ) const | 837 | // int AbTable::rowHeight( int ) const |
827 | // { | 838 | // { |
828 | // return 18; | 839 | // return 18; |
829 | // } | 840 | // } |
830 | 841 | ||
831 | // int AbTable::rowPos( int row ) const | 842 | // int AbTable::rowPos( int row ) const |
832 | // { | 843 | // { |
833 | // return 18*row; | 844 | // return 18*row; |
834 | // } | 845 | // } |
835 | 846 | ||
836 | // int AbTable::rowAt( int pos ) const | 847 | // int AbTable::rowAt( int pos ) const |
837 | // { | 848 | // { |
838 | // return QMIN( pos/18, numRows()-1 ); | 849 | // return QMIN( pos/18, numRows()-1 ); |
839 | // } | 850 | // } |
840 | 851 | ||
841 | void AbTable::slotDoFind( const QString &findString, bool caseSensitive, | 852 | void AbTable::slotDoFind( const QString &findString, bool caseSensitive, |
842 | bool backwards, int category ) | 853 | bool backwards, int category ) |
843 | { | 854 | { |
844 | if ( currFindRow < -1 ) | 855 | if ( currFindRow < -1 ) |
845 | currFindRow = currentRow() - 1; | 856 | currFindRow = currentRow() - 1; |
846 | clearSelection( TRUE ); | 857 | clearSelection( TRUE ); |
847 | int rows, | 858 | int rows, |
848 | row; | 859 | row; |
849 | AbTableItem *ati; | 860 | AbTableItem *ati; |
850 | QRegExp r( findString ); | 861 | QRegExp r( findString ); |
851 | r.setCaseSensitive( caseSensitive ); | 862 | r.setCaseSensitive( caseSensitive ); |
852 | rows = numRows(); | 863 | rows = numRows(); |
853 | static bool wrapAround = true; | 864 | static bool wrapAround = true; |
854 | 865 | ||
855 | if ( !backwards ) { | 866 | if ( !backwards ) { |
856 | for ( row = currFindRow + 1; row < rows; row++ ) { | 867 | for ( row = currFindRow + 1; row < rows; row++ ) { |
857 | ati = static_cast<AbTableItem*>( item(row, 0) ); | 868 | ati = static_cast<AbTableItem*>( item(row, 0) ); |
858 | if ( contactCompare( contactList[ati], r, category ) ) | 869 | if ( contactCompare( contactList[ati], r, category ) ) |
859 | break; | 870 | break; |
860 | 871 | ||
861 | } | 872 | } |
862 | } else { | 873 | } else { |
863 | for ( row = currFindRow - 1; row > -1; row-- ) { | 874 | for ( row = currFindRow - 1; row > -1; row-- ) { |
864 | ati = static_cast<AbTableItem*>( item(row, 0) ); | 875 | ati = static_cast<AbTableItem*>( item(row, 0) ); |
865 | if ( contactCompare( contactList[ati], r, category ) ) | 876 | if ( contactCompare( contactList[ati], r, category ) ) |
866 | break; | 877 | break; |
867 | } | 878 | } |
868 | } | 879 | } |
869 | if ( row >= rows || row < 0 ) { | 880 | if ( row >= rows || row < 0 ) { |
870 | if ( row < 0 ) | 881 | if ( row < 0 ) |
871 | currFindRow = rows; | 882 | currFindRow = rows; |
872 | else | 883 | else |
873 | currFindRow = -1; | 884 | currFindRow = -1; |
874 | 885 | ||
875 | if ( wrapAround ) | 886 | if ( wrapAround ) |
876 | emit signalWrapAround(); | 887 | emit signalWrapAround(); |
877 | else | 888 | else |
878 | emit signalNotFound(); | 889 | emit signalNotFound(); |
879 | 890 | ||
880 | wrapAround = !wrapAround; | 891 | wrapAround = !wrapAround; |
881 | } else { | 892 | } else { |
882 | currFindRow = row; | 893 | currFindRow = row; |
883 | QTableSelection foundSelection; | 894 | QTableSelection foundSelection; |
884 | foundSelection.init( currFindRow, 0 ); | 895 | foundSelection.init( currFindRow, 0 ); |
885 | foundSelection.expandTo( currFindRow, numCols() - 1 ); | 896 | foundSelection.expandTo( currFindRow, numCols() - 1 ); |
886 | addSelection( foundSelection ); | 897 | addSelection( foundSelection ); |
887 | setCurrentCell( currFindRow, numCols() - 1 ); | 898 | setCurrentCell( currFindRow, numCols() - 1 ); |
888 | wrapAround = true; | 899 | wrapAround = true; |
889 | } | 900 | } |
890 | } | 901 | } |
891 | 902 | ||
892 | static bool contactCompare( const Contact &cnt, const QRegExp &r, int category ) | 903 | static bool contactCompare( const Contact &cnt, const QRegExp &r, int category ) |
893 | { | 904 | { |
894 | bool returnMe; | 905 | bool returnMe; |
895 | QArray<int> cats; | 906 | QArray<int> cats; |
896 | cats = cnt.categories(); | 907 | cats = cnt.categories(); |
897 | 908 | ||
898 | returnMe = false; | 909 | returnMe = false; |
899 | if ( (category == -1 && cats.count() == 0) || category == -2 ) | 910 | if ( (category == -1 && cats.count() == 0) || category == -2 ) |
900 | returnMe = cnt.match( r ); | 911 | returnMe = cnt.match( r ); |
901 | else { | 912 | else { |
902 | int i; | 913 | int i; |
903 | for ( i = 0; i < int(cats.count()); i++ ) { | 914 | for ( i = 0; i < int(cats.count()); i++ ) { |
904 | if ( cats[i] == category ) { | 915 | if ( cats[i] == category ) { |
905 | returnMe = cnt.match( r ); | 916 | returnMe = cnt.match( r ); |
906 | break; | 917 | break; |
907 | } | 918 | } |
908 | } | 919 | } |
909 | } | 920 | } |
910 | return returnMe; | 921 | return returnMe; |
911 | } | 922 | } |
912 | 923 | ||
913 | void AbTable::fitColumns() | 924 | void AbTable::fitColumns() |
914 | { | 925 | { |
915 | int contentsWidth = visibleWidth(); | 926 | int contentsWidth = visibleWidth(); |
916 | int n = numCols(); | 927 | int n = numCols(); |
917 | int pw = n == 3 ? columnWidth(2) : 0; | 928 | int pw = n == 3 ? columnWidth(2) : 0; |
918 | setColumnWidth( 0, contentsWidth - contentsWidth / 2 ); | 929 | setColumnWidth( 0, contentsWidth - contentsWidth / 2 ); |
919 | setColumnWidth( 1, contentsWidth / 2 - pw ); | 930 | setColumnWidth( 1, contentsWidth / 2 - pw ); |
920 | } | 931 | } |
921 | 932 | ||
922 | void AbTable::show() | 933 | void AbTable::show() |
923 | { | 934 | { |
924 | fitColumns(); | 935 | fitColumns(); |
925 | QTable::show(); | 936 | QTable::show(); |
926 | } | 937 | } |
927 | 938 | ||
928 | void AbTable::setChoiceNames( const QStringList& list) | 939 | void AbTable::setChoiceNames( const QStringList& list) |
929 | { | 940 | { |
930 | choicenames = list; | 941 | choicenames = list; |
931 | if ( choicenames.isEmpty() ) { | 942 | if ( choicenames.isEmpty() ) { |
932 | // hide pick column | 943 | // hide pick column |
933 | setNumCols( 2 ); | 944 | setNumCols( 2 ); |
934 | } else { | 945 | } else { |
935 | // show pick column | 946 | // show pick column |
936 | setNumCols( 3 ); | 947 | setNumCols( 3 ); |
937 | setColumnWidth( 2, fontMetrics().width(tr( "Pick" ))+8 ); | 948 | setColumnWidth( 2, fontMetrics().width(tr( "Pick" ))+8 ); |
938 | horizontalHeader()->setLabel( 2, tr( "Pick" )); | 949 | horizontalHeader()->setLabel( 2, tr( "Pick" )); |
939 | } | 950 | } |
940 | fitColumns(); | 951 | fitColumns(); |
941 | } | 952 | } |
942 | 953 | ||
943 | void AbTable::itemClicked(int,int col) | 954 | void AbTable::itemClicked(int,int col) |
944 | { | 955 | { |
945 | if ( col == 2 ) { | 956 | if ( col == 2 ) { |
946 | return; | 957 | return; |
947 | } else { | 958 | } else { |
948 | emit details(); | 959 | emit details(); |
949 | } | 960 | } |
950 | } | 961 | } |
951 | 962 | ||
952 | QStringList AbTable::choiceNames() const | 963 | QStringList AbTable::choiceNames() const |
953 | { | 964 | { |
954 | return choicenames; | 965 | return choicenames; |
955 | } | 966 | } |
956 | 967 | ||
957 | void AbTable::setChoiceSelection(int /*index*/, const QStringList& /*list*/) | 968 | void AbTable::setChoiceSelection(int /*index*/, const QStringList& /*list*/) |
958 | { | 969 | { |
959 | /* ###### | 970 | /* ###### |
960 | 971 | ||
961 | QString selname = choicenames.at(index); | 972 | QString selname = choicenames.at(index); |
962 | for (each row) { | 973 | for (each row) { |
963 | Contact *c = contactForRow(row); | 974 | Contact *c = contactForRow(row); |
964 | if ( list.contains(c->email) ) { | 975 | if ( list.contains(c->email) ) { |
965 | list.remove(c->email); | 976 | list.remove(c->email); |
966 | setText(row, 2, selname); | 977 | setText(row, 2, selname); |
967 | } | 978 | } |
968 | } | 979 | } |
969 | for (remaining list items) { | 980 | for (remaining list items) { |
970 | Contact *c = new contact(item); | 981 | Contact *c = new contact(item); |
971 | setText(newrow, 2, selname); | 982 | setText(newrow, 2, selname); |
972 | } | 983 | } |
973 | 984 | ||
974 | */ | 985 | */ |
975 | } | 986 | } |
976 | 987 | ||
977 | QStringList AbTable::choiceSelection(int /*index*/) const | 988 | QStringList AbTable::choiceSelection(int /*index*/) const |
978 | { | 989 | { |
979 | QStringList r; | 990 | QStringList r; |
980 | /* ###### | 991 | /* ###### |
981 | 992 | ||
982 | QString selname = choicenames.at(index); | 993 | QString selname = choicenames.at(index); |
983 | for (each row) { | 994 | for (each row) { |
984 | Contact *c = contactForRow(row); | 995 | Contact *c = contactForRow(row); |
985 | if ( text(row,2) == selname ) { | 996 | if ( text(row,2) == selname ) { |
986 | r.append(c->email); | 997 | r.append(c->email); |
987 | } | 998 | } |
988 | } | 999 | } |
989 | 1000 | ||
990 | */ | 1001 | */ |
991 | return r; | 1002 | return r; |
992 | } | 1003 | } |
993 | 1004 | ||
994 | void AbTable::setShowCategory( const QString &c ) | 1005 | void AbTable::setShowCategory( const QString &c ) |
995 | { | 1006 | { |
996 | showCat = c; | 1007 | showCat = c; |
997 | updateVisible(); | 1008 | updateVisible(); |
998 | } | 1009 | } |
999 | 1010 | ||
1000 | QString AbTable::showCategory() const | 1011 | QString AbTable::showCategory() const |
1001 | { | 1012 | { |
1002 | return showCat; | 1013 | return showCat; |
1003 | } | 1014 | } |
1004 | 1015 | ||
1005 | 1016 | ||
1006 | QStringList AbTable::categories() | 1017 | QStringList AbTable::categories() |
1007 | { | 1018 | { |
1008 | mCat.load( categoryFileName() ); | 1019 | mCat.load( categoryFileName() ); |
1009 | QStringList categoryList = mCat.labels( "Contacts" ); | 1020 | QStringList categoryList = mCat.labels( "Contacts" ); |
1010 | return categoryList; | 1021 | return categoryList; |
1011 | } | 1022 | } |
1012 | 1023 | ||
1013 | void AbTable::updateVisible() | 1024 | void AbTable::updateVisible() |
1014 | { | 1025 | { |
1015 | int visible, | 1026 | int visible, |
1016 | totalRows, | 1027 | totalRows, |
1017 | id, | 1028 | id, |
1018 | totalCats, | 1029 | totalCats, |
1019 | it, | 1030 | it, |
1020 | row; | 1031 | row; |
1021 | bool hide; | 1032 | bool hide; |
1022 | AbTableItem *ati; | 1033 | AbTableItem *ati; |
1023 | Contact *cnt; | 1034 | Contact *cnt; |
1024 | visible = 0; | 1035 | visible = 0; |
1025 | 1036 | ||
1026 | setPaintingEnabled( FALSE ); | 1037 | setPaintingEnabled( FALSE ); |
1027 | 1038 | ||
1028 | totalRows = numRows(); | 1039 | totalRows = numRows(); |
1029 | id = mCat.id( "Contacts", showCat ); | 1040 | id = mCat.id( "Contacts", showCat ); |
1030 | QArray<int> cats; | 1041 | QArray<int> cats; |
1031 | for ( row = 0; row < totalRows; row++ ) { | 1042 | for ( row = 0; row < totalRows; row++ ) { |
1032 | ati = static_cast<AbTableItem*>( item(row, 0) ); | 1043 | ati = static_cast<AbTableItem*>( item(row, 0) ); |
1033 | cnt = &contactList[ati]; | 1044 | cnt = &contactList[ati]; |
1034 | cats = cnt->categories(); | 1045 | cats = cnt->categories(); |
1035 | hide = false; | 1046 | hide = false; |
1036 | if ( !showCat.isEmpty() ) { | 1047 | if ( !showCat.isEmpty() ) { |
1037 | if ( showCat == tr( "Unfiled" ) ) { | 1048 | if ( showCat == tr( "Unfiled" ) ) { |
1038 | if ( cats.count() > 0 ) | 1049 | if ( cats.count() > 0 ) |
1039 | hide = true; | 1050 | hide = true; |
1040 | } else { | 1051 | } else { |
1041 | // do some comparing | 1052 | // do some comparing |
1042 | if ( !hide ) { | 1053 | if ( !hide ) { |
1043 | hide = true; | 1054 | hide = true; |
1044 | totalCats = int(cats.count()); | 1055 | totalCats = int(cats.count()); |
1045 | for ( it = 0; it < totalCats; it++ ) { | 1056 | for ( it = 0; it < totalCats; it++ ) { |
1046 | if ( cats[it] == id ) { | 1057 | if ( cats[it] == id ) { |
1047 | hide = false; | 1058 | hide = false; |
1048 | break; | 1059 | break; |
1049 | } | 1060 | } |
1050 | } | 1061 | } |
1051 | } | 1062 | } |
1052 | } | 1063 | } |
1053 | } | 1064 | } |
1054 | if ( hide ) { | 1065 | if ( hide ) { |
1055 | if ( currentRow() == row ) | 1066 | if ( currentRow() == row ) |
1056 | setCurrentCell( -1, 0 ); | 1067 | setCurrentCell( -1, 0 ); |
1057 | if ( rowHeight(row) > 0 ) | 1068 | if ( rowHeight(row) > 0 ) |
1058 | hideRow( row ); | 1069 | hideRow( row ); |
1059 | } else { | 1070 | } else { |
1060 | if ( rowHeight(row) == 0 ) { | 1071 | if ( rowHeight(row) == 0 ) { |
1061 | showRow( row ); | 1072 | showRow( row ); |
1062 | adjustRow( row ); | 1073 | adjustRow( row ); |
1063 | } | 1074 | } |
1064 | visible++; | 1075 | visible++; |
1065 | } | 1076 | } |
1066 | } | 1077 | } |
1067 | if ( !visible ) | 1078 | if ( !visible ) |
1068 | setCurrentCell( -1, 0 ); | 1079 | setCurrentCell( -1, 0 ); |
1069 | 1080 | ||
1070 | setPaintingEnabled( TRUE ); | 1081 | setPaintingEnabled( TRUE ); |
1071 | } | 1082 | } |
1072 | 1083 | ||
1073 | 1084 | ||
1074 | void AbTable::setPaintingEnabled( bool e ) | 1085 | void AbTable::setPaintingEnabled( bool e ) |
1075 | { | 1086 | { |
1076 | if ( e != enablePainting ) { | 1087 | if ( e != enablePainting ) { |
1077 | if ( !enablePainting ) { | 1088 | if ( !enablePainting ) { |
1078 | enablePainting = true; | 1089 | enablePainting = true; |
1079 | rowHeightChanged( 0 ); | 1090 | rowHeightChanged( 0 ); |
1080 | viewport()->update(); | 1091 | viewport()->update(); |
1081 | } else { | 1092 | } else { |
1082 | enablePainting = false; | 1093 | enablePainting = false; |
1083 | } | 1094 | } |
1084 | } | 1095 | } |
1085 | } | 1096 | } |
1086 | 1097 | ||
1087 | void AbTable::rowHeightChanged( int row ) | 1098 | void AbTable::rowHeightChanged( int row ) |
1088 | { | 1099 | { |
1089 | if ( enablePainting ) | 1100 | if ( enablePainting ) |
1090 | QTable::rowHeightChanged( row ); | 1101 | QTable::rowHeightChanged( row ); |
1091 | } | 1102 | } |
diff --git a/core/pim/addressbook/abtable.h b/core/pim/addressbook/abtable.h index 9b96997..53635ee 100644 --- a/core/pim/addressbook/abtable.h +++ b/core/pim/addressbook/abtable.h | |||
@@ -1,140 +1,141 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
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 | 20 | ||
21 | #ifndef ABTABLE_H | 21 | #ifndef ABTABLE_H |
22 | #define ABTABLE_H | 22 | #define ABTABLE_H |
23 | 23 | ||
24 | #include <qpe/categories.h> | 24 | #include <qpe/categories.h> |
25 | #include <qpe/contact.h> | 25 | #include <qpe/contact.h> |
26 | 26 | ||
27 | #include <qmap.h> | 27 | #include <qmap.h> |
28 | #include <qtable.h> | 28 | #include <qtable.h> |
29 | #include <qstringlist.h> | 29 | #include <qstringlist.h> |
30 | #include <qcombobox.h> | 30 | #include <qcombobox.h> |
31 | 31 | ||
32 | class AbTableItem : public QTableItem | 32 | class AbTableItem : public QTableItem |
33 | { | 33 | { |
34 | public: | 34 | public: |
35 | AbTableItem( QTable *t, EditType et, const QString &s, | 35 | AbTableItem( QTable *t, EditType et, const QString &s, |
36 | const QString &secondSortKey); | 36 | const QString &secondSortKey); |
37 | QString entryKey() const; | 37 | QString entryKey() const; |
38 | void setEntryKey( const QString & k ); | 38 | void setEntryKey( const QString & k ); |
39 | virtual int alignment() const; | 39 | virtual int alignment() const; |
40 | virtual QString key() const; | 40 | virtual QString key() const; |
41 | void setItem( const QString &txt, const QString &secondKey ); | 41 | void setItem( const QString &txt, const QString &secondKey ); |
42 | 42 | ||
43 | private: | 43 | private: |
44 | QString sortKey; | 44 | QString sortKey; |
45 | }; | 45 | }; |
46 | 46 | ||
47 | class AbPickItem : public QTableItem | 47 | class AbPickItem : public QTableItem |
48 | { | 48 | { |
49 | public: | 49 | public: |
50 | AbPickItem( QTable *t ); | 50 | AbPickItem( QTable *t ); |
51 | 51 | ||
52 | QWidget *createEditor() const; | 52 | QWidget *createEditor() const; |
53 | void setContentFromEditor( QWidget *w ); | 53 | void setContentFromEditor( QWidget *w ); |
54 | 54 | ||
55 | private: | 55 | private: |
56 | QGuardedPtr<QComboBox> cb; | 56 | QGuardedPtr<QComboBox> cb; |
57 | }; | 57 | }; |
58 | 58 | ||
59 | class AbTable : public QTable | 59 | class AbTable : public QTable |
60 | { | 60 | { |
61 | Q_OBJECT | 61 | Q_OBJECT |
62 | 62 | ||
63 | public: | 63 | public: |
64 | AbTable( const QValueList<int> *ordered, QWidget *parent, const char *name=0 ); | 64 | AbTable( const QValueList<int> *ordered, QWidget *parent, const char *name=0 ); |
65 | ~AbTable(); | 65 | ~AbTable(); |
66 | // NEW | 66 | // NEW |
67 | void addEntry( const Contact &newContact ); | 67 | void addEntry( const Contact &newContact ); |
68 | Contact currentEntry(); | 68 | Contact currentEntry(); |
69 | void replaceCurrentEntry( const Contact &newContact ); | 69 | void replaceCurrentEntry( const Contact &newContact ); |
70 | 70 | ||
71 | void init(); | 71 | void init(); |
72 | 72 | ||
73 | void deleteCurrentEntry(); | 73 | void deleteCurrentEntry(); |
74 | void clear(); | 74 | void clear(); |
75 | void clearFindRow() { currFindRow = -2; } | 75 | void clearFindRow() { currFindRow = -2; } |
76 | void loadFields(); | 76 | void loadFields(); |
77 | void refresh(); | 77 | void refresh(); |
78 | bool save( const QString &fn ); | 78 | bool save( const QString &fn ); |
79 | void load( const QString &fn ); | 79 | void load( const QString &fn ); |
80 | 80 | ||
81 | // addresspicker mode | 81 | // addresspicker mode |
82 | void setChoiceNames( const QStringList& list); | 82 | void setChoiceNames( const QStringList& list); |
83 | QStringList choiceNames() const; | 83 | QStringList choiceNames() const; |
84 | void setChoiceSelection(int index, const QStringList& list); | 84 | void setChoiceSelection(int index, const QStringList& list); |
85 | QStringList choiceSelection(int index) const; | 85 | QStringList choiceSelection(int index) const; |
86 | void setShowCategory( const QString &c ); | 86 | void setShowCategory( const QString &c ); |
87 | QString showCategory() const; | 87 | QString showCategory() const; |
88 | QStringList categories(); | 88 | QStringList categories(); |
89 | void resizeRows( int size ); | ||
89 | 90 | ||
90 | void show(); | 91 | void show(); |
91 | void setPaintingEnabled( bool e ); | 92 | void setPaintingEnabled( bool e ); |
92 | 93 | ||
93 | public slots: | 94 | public slots: |
94 | void slotDoFind( const QString &str, bool caseSensitive, bool backwards, | 95 | void slotDoFind( const QString &str, bool caseSensitive, bool backwards, |
95 | int category ); | 96 | int category ); |
96 | signals: | 97 | signals: |
97 | void empty( bool ); | 98 | void empty( bool ); |
98 | void details(); | 99 | void details(); |
99 | void signalNotFound(); | 100 | void signalNotFound(); |
100 | void signalWrapAround(); | 101 | void signalWrapAround(); |
101 | 102 | ||
102 | protected: | 103 | protected: |
103 | virtual void keyPressEvent( QKeyEvent *e ); | 104 | virtual void keyPressEvent( QKeyEvent *e ); |
104 | 105 | ||
105 | // int rowHeight( int ) const; | 106 | // int rowHeight( int ) const; |
106 | // int rowPos( int row ) const; | 107 | // int rowPos( int row ) const; |
107 | // virtual int rowAt( int pos ) const; | 108 | // virtual int rowAt( int pos ) const; |
108 | 109 | ||
109 | 110 | ||
110 | protected slots: | 111 | protected slots: |
111 | void moveTo( char ); | 112 | void moveTo( char ); |
112 | virtual void columnClicked( int col ); | 113 | virtual void columnClicked( int col ); |
113 | void itemClicked(int,int col); | 114 | void itemClicked(int,int col); |
114 | void rowHeightChanged( int row ); | 115 | void rowHeightChanged( int row ); |
115 | 116 | ||
116 | private: | 117 | private: |
117 | void loadFile( const QString &strFile, bool journalFile ); | 118 | void loadFile( const QString &strFile, bool journalFile ); |
118 | void fitColumns(); | 119 | void fitColumns(); |
119 | void resort(); | 120 | void resort(); |
120 | void updateJournal( const Contact &contact, Contact::journal_action action, | 121 | void updateJournal( const Contact &contact, Contact::journal_action action, |
121 | int row = -1 ); | 122 | int row = -1 ); |
122 | void insertIntoTable( const Contact &contact, int row ); | 123 | void insertIntoTable( const Contact &contact, int row ); |
123 | void internalAddEntries( QList<Contact> &list ); | 124 | void internalAddEntries( QList<Contact> &list ); |
124 | QString findContactName( const Contact &entry ); | 125 | QString findContactName( const Contact &entry ); |
125 | QString findContactContact( const Contact &entry ); | 126 | QString findContactContact( const Contact &entry ); |
126 | void journalFreeReplace( const Contact &cnt, int row ); | 127 | void journalFreeReplace( const Contact &cnt, int row ); |
127 | void journalFreeRemove( int row ); | 128 | void journalFreeRemove( int row ); |
128 | void realignTable( int ); | 129 | void realignTable( int ); |
129 | void updateVisible(); | 130 | void updateVisible(); |
130 | int lastSortCol; | 131 | int lastSortCol; |
131 | bool asc; | 132 | bool asc; |
132 | QMap<AbTableItem*, Contact> contactList; | 133 | QMap<AbTableItem*, Contact> contactList; |
133 | const QValueList<int> *intFields; | 134 | const QValueList<int> *intFields; |
134 | int currFindRow; | 135 | int currFindRow; |
135 | QString showCat; | 136 | QString showCat; |
136 | QStringList choicenames; | 137 | QStringList choicenames; |
137 | bool enablePainting; | 138 | bool enablePainting; |
138 | Categories mCat; | 139 | Categories mCat; |
139 | }; | 140 | }; |
140 | #endif // ABTABLE_H | 141 | #endif // ABTABLE_H |
diff --git a/core/pim/addressbook/addressbook.cpp b/core/pim/addressbook/addressbook.cpp index b7b35bc..95a8521 100644 --- a/core/pim/addressbook/addressbook.cpp +++ b/core/pim/addressbook/addressbook.cpp | |||
@@ -1,900 +1,908 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
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 | 20 | ||
21 | #define QTOPIA_INTERNAL_FD | 21 | #define QTOPIA_INTERNAL_FD |
22 | 22 | ||
23 | #include "contacteditor.h" | 23 | #include "contacteditor.h" |
24 | #include "ablabel.h" | 24 | #include "ablabel.h" |
25 | #include "abtable.h" | 25 | #include "abtable.h" |
26 | #include "addresssettings.h" | 26 | #include "addresssettings.h" |
27 | #include "addressbook.h" | 27 | #include "addressbook.h" |
28 | 28 | ||
29 | #include <qpe/qpeapplication.h> | 29 | #include <qpe/qpeapplication.h> |
30 | #include <qpe/config.h> | 30 | #include <qpe/config.h> |
31 | #include <qpe/contact.h> | 31 | #include <qpe/contact.h> |
32 | 32 | ||
33 | #ifndef MAKE_FOR_SHARP_ROM | 33 | #ifndef MAKE_FOR_SHARP_ROM |
34 | #include <qpe/finddialog.h> | 34 | #include <qpe/finddialog.h> |
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | #include <qpe/global.h> | 37 | #include <qpe/global.h> |
38 | #include <qpe/resource.h> | 38 | #include <qpe/resource.h> |
39 | #include <qpe/ir.h> | 39 | #include <qpe/ir.h> |
40 | #include <qpe/qpemessagebox.h> | 40 | #include <qpe/qpemessagebox.h> |
41 | #include <qpe/qcopenvelope_qws.h> | 41 | #include <qpe/qcopenvelope_qws.h> |
42 | 42 | ||
43 | #include <qaction.h> | 43 | #include <qaction.h> |
44 | #include <qdialog.h> | 44 | #include <qdialog.h> |
45 | #include <qdir.h> | 45 | #include <qdir.h> |
46 | #include <qfile.h> | 46 | #include <qfile.h> |
47 | #include <qimage.h> | 47 | #include <qimage.h> |
48 | #include <qlayout.h> | 48 | #include <qlayout.h> |
49 | #include <qpe/qpemenubar.h> | 49 | #include <qpe/qpemenubar.h> |
50 | #include <qmessagebox.h> | 50 | #include <qmessagebox.h> |
51 | #include <qpixmap.h> | 51 | #include <qpixmap.h> |
52 | #include <qpopupmenu.h> | 52 | #include <qpopupmenu.h> |
53 | #include <qpe/qpetoolbar.h> | 53 | #include <qpe/qpetoolbar.h> |
54 | #include <qstringlist.h> | 54 | #include <qstringlist.h> |
55 | #include <qtoolbutton.h> | 55 | #include <qtoolbutton.h> |
56 | #include <qwhatsthis.h> | 56 | #include <qwhatsthis.h> |
57 | 57 | ||
58 | #include <stdlib.h> | 58 | #include <stdlib.h> |
59 | #include <sys/stat.h> | 59 | #include <sys/stat.h> |
60 | #include <sys/types.h> | 60 | #include <sys/types.h> |
61 | #include <fcntl.h> | 61 | #include <fcntl.h> |
62 | #include <unistd.h> | 62 | #include <unistd.h> |
63 | 63 | ||
64 | #include <qdatetime.h> | 64 | #include <qdatetime.h> |
65 | 65 | ||
66 | static QString addressbookOldXMLFilename() | 66 | static QString addressbookOldXMLFilename() |
67 | { | 67 | { |
68 | QString filename = QPEApplication::documentDir() + "addressbook.xml"; | 68 | QString filename = QPEApplication::documentDir() + "addressbook.xml"; |
69 | return filename; | 69 | return filename; |
70 | } | 70 | } |
71 | 71 | ||
72 | static QString addressbookXMLFilename() | 72 | static QString addressbookXMLFilename() |
73 | { | 73 | { |
74 | QString filename = Global::applicationFileName("addressbook", | 74 | QString filename = Global::applicationFileName("addressbook", |
75 | "addressbook.xml"); | 75 | "addressbook.xml"); |
76 | return filename; | 76 | return filename; |
77 | } | 77 | } |
78 | 78 | ||
79 | static QString addressbookPersonalVCardName() | 79 | static QString addressbookPersonalVCardName() |
80 | { | 80 | { |
81 | QString filename = Global::applicationFileName("addressbook", | 81 | QString filename = Global::applicationFileName("addressbook", |
82 | "businesscard.vcf"); | 82 | "businesscard.vcf"); |
83 | return filename; | 83 | return filename; |
84 | } | 84 | } |
85 | 85 | ||
86 | 86 | ||
87 | AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, | 87 | AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, |
88 | WFlags f ) | 88 | WFlags f ) |
89 | : QMainWindow( parent, name, f ), | 89 | : QMainWindow( parent, name, f ), |
90 | abEditor(0), | 90 | abEditor(0), |
91 | bAbEditFirstTime(TRUE), | 91 | bAbEditFirstTime(TRUE), |
92 | syncing(FALSE) | 92 | syncing(FALSE) |
93 | { | 93 | { |
94 | initFields(); | 94 | initFields(); |
95 | 95 | ||
96 | setCaption( tr("Contacts") ); | 96 | setCaption( tr("Contacts") ); |
97 | setIcon( Resource::loadPixmap( "AddressBook" ) ); | 97 | setIcon( Resource::loadPixmap( "AddressBook" ) ); |
98 | 98 | ||
99 | setToolBarsMovable( FALSE ); | 99 | setToolBarsMovable( FALSE ); |
100 | 100 | ||
101 | // Create Toolbars | 101 | // Create Toolbars |
102 | 102 | ||
103 | QPEToolBar *bar = new QPEToolBar( this ); | 103 | QPEToolBar *bar = new QPEToolBar( this ); |
104 | bar->setHorizontalStretchable( TRUE ); | 104 | bar->setHorizontalStretchable( TRUE ); |
105 | 105 | ||
106 | QPEMenuBar *mbList = new QPEMenuBar( bar ); | 106 | QPEMenuBar *mbList = new QPEMenuBar( bar ); |
107 | mbList->setMargin( 0 ); | 107 | mbList->setMargin( 0 ); |
108 | 108 | ||
109 | QPopupMenu *edit = new QPopupMenu( this ); | 109 | QPopupMenu *edit = new QPopupMenu( this ); |
110 | mbList->insertItem( tr( "Contact" ), edit ); | 110 | mbList->insertItem( tr( "Contact" ), edit ); |
111 | 111 | ||
112 | listTools = new QPEToolBar( this, "list operations" ); | 112 | listTools = new QPEToolBar( this, "list operations" ); |
113 | 113 | ||
114 | 114 | ||
115 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, | 115 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, |
116 | 0, this, 0 ); | 116 | 0, this, 0 ); |
117 | actionNew = a; | 117 | actionNew = a; |
118 | connect( a, SIGNAL( activated() ), this, SLOT( slotListNew() ) ); | 118 | connect( a, SIGNAL( activated() ), this, SLOT( slotListNew() ) ); |
119 | a->addTo( edit ); | 119 | a->addTo( edit ); |
120 | a->addTo( listTools ); | 120 | a->addTo( listTools ); |
121 | 121 | ||
122 | a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null, | 122 | a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null, |
123 | 0, this, 0 ); | 123 | 0, this, 0 ); |
124 | actionEdit = a; | 124 | actionEdit = a; |
125 | connect( a, SIGNAL( activated() ), this, SLOT( slotViewEdit() ) ); | 125 | connect( a, SIGNAL( activated() ), this, SLOT( slotViewEdit() ) ); |
126 | a->addTo( edit ); | 126 | a->addTo( edit ); |
127 | a->addTo( listTools ); | 127 | a->addTo( listTools ); |
128 | 128 | ||
129 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, | 129 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, |
130 | 0, this, 0 ); | 130 | 0, this, 0 ); |
131 | actionTrash = a; | 131 | actionTrash = a; |
132 | connect( a, SIGNAL( activated() ), this, SLOT( slotListDelete() ) ); | 132 | connect( a, SIGNAL( activated() ), this, SLOT( slotListDelete() ) ); |
133 | a->addTo( edit ); | 133 | a->addTo( edit ); |
134 | a->addTo( listTools ); | 134 | a->addTo( listTools ); |
135 | 135 | ||
136 | #ifndef MAKE_FOR_SHARP_ROM | 136 | #ifndef MAKE_FOR_SHARP_ROM |
137 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), | 137 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), |
138 | QString::null, 0, this, 0 ); | 138 | QString::null, 0, this, 0 ); |
139 | actionFind = a; | 139 | actionFind = a; |
140 | connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); | 140 | connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); |
141 | a->addTo( edit ); | 141 | a->addTo( edit ); |
142 | a->addTo( listTools ); | 142 | a->addTo( listTools ); |
143 | #endif | 143 | #endif |
144 | 144 | ||
145 | 145 | ||
146 | a = new QAction( tr( "Write Mail To" ), Resource::loadPixmap( "qtmail/reply" ), | 146 | a = new QAction( tr( "Write Mail To" ), Resource::loadPixmap( "qtmail/reply" ), |
147 | QString::null, 0, this, 0 ); | 147 | QString::null, 0, this, 0 ); |
148 | //a->setEnabled( FALSE ); we got support for it now :) zecke | 148 | //a->setEnabled( FALSE ); we got support for it now :) zecke |
149 | actionMail = a; | 149 | actionMail = a; |
150 | connect( a, SIGNAL( activated() ), this, SLOT( writeMail() ) ); | 150 | connect( a, SIGNAL( activated() ), this, SLOT( writeMail() ) ); |
151 | a->addTo( edit ); | 151 | a->addTo( edit ); |
152 | a->addTo( listTools ); | 152 | a->addTo( listTools ); |
153 | 153 | ||
154 | 154 | ||
155 | 155 | ||
156 | if ( Ir::supported() ) { | 156 | if ( Ir::supported() ) { |
157 | a = new QAction( tr ("Beam Entry" ), Resource::loadPixmap( "beam" ), QString::null, | 157 | a = new QAction( tr ("Beam Entry" ), Resource::loadPixmap( "beam" ), QString::null, |
158 | 0, this, 0 ); | 158 | 0, this, 0 ); |
159 | actionBeam = a; | 159 | actionBeam = a; |
160 | connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) ); | 160 | connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) ); |
161 | a->addTo( edit ); | 161 | a->addTo( edit ); |
162 | a->addTo( listTools ); | 162 | a->addTo( listTools ); |
163 | } | 163 | } |
164 | 164 | ||
165 | edit->insertSeparator(); | 165 | edit->insertSeparator(); |
166 | 166 | ||
167 | a = new QAction( tr("My Personal Details"), QString::null, 0, 0, 0, TRUE ); | 167 | a = new QAction( tr("My Personal Details"), QString::null, 0, 0, 0, TRUE ); |
168 | actionPersonal = a; | 168 | actionPersonal = a; |
169 | connect( a, SIGNAL( activated() ), this, SLOT( slotPersonalView() ) ); | 169 | connect( a, SIGNAL( activated() ), this, SLOT( slotPersonalView() ) ); |
170 | a->addTo( edit ); | 170 | a->addTo( edit ); |
171 | 171 | ||
172 | 172 | ||
173 | a = new QAction( tr( "Arrange Edit Fields"), QString::null, 0, 0 ); | 173 | a = new QAction( tr( "Arrange Edit Fields"), QString::null, 0, 0 ); |
174 | connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); | 174 | connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); |
175 | a->addTo( edit ); | 175 | a->addTo( edit ); |
176 | 176 | ||
177 | // Create Views | 177 | // Create Views |
178 | 178 | ||
179 | // This is safe to call without checking to see if it exists... | 179 | // This is safe to call without checking to see if it exists... |
180 | // not to mention it also does the necessary stuff for the | 180 | // not to mention it also does the necessary stuff for the |
181 | // journaling... | 181 | // journaling... |
182 | QString str = addressbookXMLFilename(); | 182 | QString str = addressbookXMLFilename(); |
183 | if ( str.isNull() ) { | 183 | if ( str.isNull() ) { |
184 | QMessageBox::warning( this, tr("Out of Space"), | 184 | QMessageBox::warning( this, tr("Out of Space"), |
185 | tr("There is not enough space to create\n" | 185 | tr("There is not enough space to create\n" |
186 | "neccessary startup files.\n" | 186 | "neccessary startup files.\n" |
187 | "\nFree up some space before\nentering data!") | 187 | "\nFree up some space before\nentering data!") |
188 | ); | 188 | ); |
189 | } | 189 | } |
190 | 190 | ||
191 | abList = new AbTable( &orderedFields, this, "table" ); | 191 | abList = new AbTable( &orderedFields, this, "table" ); |
192 | abList->setHScrollBarMode( QScrollView::AlwaysOff ); | 192 | abList->setHScrollBarMode( QScrollView::AlwaysOff ); |
193 | connect( abList, SIGNAL( empty( bool ) ), | 193 | connect( abList, SIGNAL( empty( bool ) ), |
194 | this, SLOT( listIsEmpty( bool ) ) ); | 194 | this, SLOT( listIsEmpty( bool ) ) ); |
195 | connect( abList, SIGNAL( details() ), | 195 | connect( abList, SIGNAL( details() ), |
196 | this, SLOT( slotListView() ) ); | 196 | this, SLOT( slotListView() ) ); |
197 | connect( abList, SIGNAL(currentChanged(int,int)), | 197 | connect( abList, SIGNAL(currentChanged(int,int)), |
198 | this, SLOT(slotUpdateToolbar()) ); | 198 | this, SLOT(slotUpdateToolbar()) ); |
199 | 199 | ||
200 | mView = 0; | 200 | mView = 0; |
201 | 201 | ||
202 | abList->load( addressbookXMLFilename() ); | 202 | abList->load( addressbookXMLFilename() ); |
203 | if ( QFile::exists(addressbookOldXMLFilename()) ) { | 203 | if ( QFile::exists(addressbookOldXMLFilename()) ) { |
204 | abList->load( addressbookOldXMLFilename() ); | 204 | abList->load( addressbookOldXMLFilename() ); |
205 | QFile::remove(addressbookOldXMLFilename()); | 205 | QFile::remove(addressbookOldXMLFilename()); |
206 | } | 206 | } |
207 | 207 | ||
208 | catMenu = new QPopupMenu( this ); | 208 | catMenu = new QPopupMenu( this ); |
209 | catMenu->setCheckable( TRUE ); | 209 | catMenu->setCheckable( TRUE ); |
210 | connect( catMenu, SIGNAL(activated(int)), this, SLOT(slotSetCategory(int)) ); | 210 | connect( catMenu, SIGNAL(activated(int)), this, SLOT(slotSetCategory(int)) ); |
211 | populateCategories(); | 211 | populateCategories(); |
212 | 212 | ||
213 | mbList->insertItem( tr("View"), catMenu ); | 213 | mbList->insertItem( tr("View"), catMenu ); |
214 | setCentralWidget( abList ); | 214 | setCentralWidget( abList ); |
215 | 215 | ||
216 | fontMenu = new QPopupMenu(this); | 216 | fontMenu = new QPopupMenu(this); |
217 | fontMenu->setCheckable( true ); | 217 | fontMenu->setCheckable( true ); |
218 | connect( fontMenu, SIGNAL(activated(int)), this, SLOT(slotSetFont(int))); | 218 | connect( fontMenu, SIGNAL(activated(int)), this, SLOT(slotSetFont(int))); |
219 | 219 | ||
220 | fontMenu->insertItem("Small", 0); | 220 | fontMenu->insertItem("Small", 0); |
221 | fontMenu->insertItem("Normal", 1); | 221 | fontMenu->insertItem("Normal", 1); |
222 | fontMenu->insertItem("Large", 2); | 222 | fontMenu->insertItem("Large", 2); |
223 | 223 | ||
224 | defaultFont = new QFont( abList->font() ); | 224 | defaultFont = new QFont( abList->font() ); |
225 | 225 | ||
226 | slotSetFont(startFontSize); | 226 | slotSetFont(startFontSize); |
227 | 227 | ||
228 | mbList->insertItem( tr("Font"), fontMenu); | 228 | mbList->insertItem( tr("Font"), fontMenu); |
229 | setCentralWidget(abList); | 229 | setCentralWidget(abList); |
230 | 230 | ||
231 | // qDebug("adressbook contrsuction: t=%d", t.elapsed() ); | 231 | // qDebug("adressbook contrsuction: t=%d", t.elapsed() ); |
232 | } | 232 | } |
233 | void AddressbookWindow::slotSetFont( int size ) { | 233 | void AddressbookWindow::slotSetFont( int size ) { |
234 | 234 | ||
235 | if (size > 2 || size < 0) | 235 | if (size > 2 || size < 0) |
236 | size = 1; | 236 | size = 1; |
237 | 237 | ||
238 | startFontSize = size; | 238 | startFontSize = size; |
239 | 239 | ||
240 | QFont *currentFont; | ||
241 | |||
240 | switch (size) { | 242 | switch (size) { |
241 | case 0: | 243 | case 0: |
242 | fontMenu->setItemChecked(0, true); | 244 | fontMenu->setItemChecked(0, true); |
243 | fontMenu->setItemChecked(1, false); | 245 | fontMenu->setItemChecked(1, false); |
244 | fontMenu->setItemChecked(2, false); | 246 | fontMenu->setItemChecked(2, false); |
245 | abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) ); | 247 | abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) ); |
248 | currentFont = new QFont (abList->font()); | ||
249 | abList->resizeRows(currentFont->pixelSize() + 7); | ||
246 | break; | 250 | break; |
247 | case 1: | 251 | case 1: |
248 | fontMenu->setItemChecked(0, false); | 252 | fontMenu->setItemChecked(0, false); |
249 | fontMenu->setItemChecked(1, true); | 253 | fontMenu->setItemChecked(1, true); |
250 | fontMenu->setItemChecked(2, false); | 254 | fontMenu->setItemChecked(2, false); |
251 | abList->setFont( *defaultFont ); | 255 | abList->setFont( *defaultFont ); |
256 | currentFont = new QFont (abList->font()); | ||
257 | abList->resizeRows(currentFont->pixelSize() + 7); | ||
252 | break; | 258 | break; |
253 | case 2: | 259 | case 2: |
254 | fontMenu->setItemChecked(0, false); | 260 | fontMenu->setItemChecked(0, false); |
255 | fontMenu->setItemChecked(1, false); | 261 | fontMenu->setItemChecked(1, false); |
256 | fontMenu->setItemChecked(2, true); | 262 | fontMenu->setItemChecked(2, true); |
257 | abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() + 2 ) ); | 263 | abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() + 2 ) ); |
264 | currentFont = new QFont (abList->font()); | ||
265 | abList->resizeRows(currentFont->pixelSize() + 7); | ||
258 | break; | 266 | break; |
259 | } | 267 | } |
260 | } | 268 | } |
261 | 269 | ||
262 | 270 | ||
263 | void AddressbookWindow::setDocument( const QString &filename ) | 271 | void AddressbookWindow::setDocument( const QString &filename ) |
264 | { | 272 | { |
265 | if ( filename.find(".vcf") != int(filename.length()) - 4 ) return; | 273 | if ( filename.find(".vcf") != int(filename.length()) - 4 ) return; |
266 | 274 | ||
267 | QValueList<Contact> cl = Contact::readVCard( filename ); | 275 | QValueList<Contact> cl = Contact::readVCard( filename ); |
268 | for( QValueList<Contact>::Iterator it = cl.begin(); it != cl.end(); ++it ) { | 276 | for( QValueList<Contact>::Iterator it = cl.begin(); it != cl.end(); ++it ) { |
269 | // QString msg = tr("You received a vCard for\n%1.\nDo You want to add it to your\naddressbook?") | 277 | // QString msg = tr("You received a vCard for\n%1.\nDo You want to add it to your\naddressbook?") |
270 | // .arg( (*it).fullName() ); | 278 | // .arg( (*it).fullName() ); |
271 | // if ( QMessageBox::information( this, tr("received contact"), msg, QMessageBox::Ok, QMessageBox::Cancel ) == | 279 | // if ( QMessageBox::information( this, tr("received contact"), msg, QMessageBox::Ok, QMessageBox::Cancel ) == |
272 | // QMessageBox::Ok ) { | 280 | // QMessageBox::Ok ) { |
273 | abList->addEntry( *it ); | 281 | abList->addEntry( *it ); |
274 | // } | 282 | // } |
275 | } | 283 | } |
276 | 284 | ||
277 | } | 285 | } |
278 | 286 | ||
279 | void AddressbookWindow::resizeEvent( QResizeEvent *e ) | 287 | void AddressbookWindow::resizeEvent( QResizeEvent *e ) |
280 | { | 288 | { |
281 | QMainWindow::resizeEvent( e ); | 289 | QMainWindow::resizeEvent( e ); |
282 | 290 | ||
283 | if ( centralWidget() == abList ) | 291 | if ( centralWidget() == abList ) |
284 | showList(); | 292 | showList(); |
285 | else if ( centralWidget() == mView ) | 293 | else if ( centralWidget() == mView ) |
286 | showView(); | 294 | showView(); |
287 | } | 295 | } |
288 | 296 | ||
289 | AddressbookWindow::~AddressbookWindow() | 297 | AddressbookWindow::~AddressbookWindow() |
290 | { | 298 | { |
291 | Config cfg("AddressBook"); | 299 | Config cfg("AddressBook"); |
292 | cfg.setGroup("Font"); | 300 | cfg.setGroup("Font"); |
293 | cfg.writeEntry("fontSize", startFontSize); | 301 | cfg.writeEntry("fontSize", startFontSize); |
294 | } | 302 | } |
295 | 303 | ||
296 | void AddressbookWindow::slotUpdateToolbar() | 304 | void AddressbookWindow::slotUpdateToolbar() |
297 | { | 305 | { |
298 | Contact ce = abList->currentEntry(); | 306 | Contact ce = abList->currentEntry(); |
299 | actionMail->setEnabled( !ce.defaultEmail().isEmpty() ); | 307 | actionMail->setEnabled( !ce.defaultEmail().isEmpty() ); |
300 | } | 308 | } |
301 | 309 | ||
302 | void AddressbookWindow::showList() | 310 | void AddressbookWindow::showList() |
303 | { | 311 | { |
304 | if ( mView ) mView->hide(); | 312 | if ( mView ) mView->hide(); |
305 | setCentralWidget( abList ); | 313 | setCentralWidget( abList ); |
306 | abList->show(); | 314 | abList->show(); |
307 | // update our focues... (or use a stack widget!); | 315 | // update our focues... (or use a stack widget!); |
308 | abList->setFocus(); | 316 | abList->setFocus(); |
309 | } | 317 | } |
310 | 318 | ||
311 | void AddressbookWindow::showView() | 319 | void AddressbookWindow::showView() |
312 | { | 320 | { |
313 | if ( abList->numRows() > 0 ) { | 321 | if ( abList->numRows() > 0 ) { |
314 | abList->hide(); | 322 | abList->hide(); |
315 | setCentralWidget( abView() ); | 323 | setCentralWidget( abView() ); |
316 | mView->show(); | 324 | mView->show(); |
317 | mView->setFocus(); | 325 | mView->setFocus(); |
318 | } | 326 | } |
319 | } | 327 | } |
320 | 328 | ||
321 | void AddressbookWindow::slotListNew() | 329 | void AddressbookWindow::slotListNew() |
322 | { | 330 | { |
323 | Contact cnt; | 331 | Contact cnt; |
324 | if( !syncing ) { | 332 | if( !syncing ) { |
325 | if ( abEditor ) | 333 | if ( abEditor ) |
326 | abEditor->setEntry( cnt ); | 334 | abEditor->setEntry( cnt ); |
327 | abView()->init( cnt ); | 335 | abView()->init( cnt ); |
328 | editEntry( NewEntry ); | 336 | editEntry( NewEntry ); |
329 | } else { | 337 | } else { |
330 | QMessageBox::warning(this, tr("Contacts"), | 338 | QMessageBox::warning(this, tr("Contacts"), |
331 | tr("Can not edit data, currently syncing")); | 339 | tr("Can not edit data, currently syncing")); |
332 | } | 340 | } |
333 | } | 341 | } |
334 | 342 | ||
335 | void AddressbookWindow::slotListView() | 343 | void AddressbookWindow::slotListView() |
336 | { | 344 | { |
337 | abView()->init( abList->currentEntry() ); | 345 | abView()->init( abList->currentEntry() ); |
338 | mView->sync(); | 346 | mView->sync(); |
339 | showView(); | 347 | showView(); |
340 | } | 348 | } |
341 | 349 | ||
342 | void AddressbookWindow::slotListDelete() | 350 | void AddressbookWindow::slotListDelete() |
343 | { | 351 | { |
344 | if(!syncing) { | 352 | if(!syncing) { |
345 | Contact tmpEntry = abList->currentEntry(); | 353 | Contact tmpEntry = abList->currentEntry(); |
346 | 354 | ||
347 | // get a name, do the best we can... | 355 | // get a name, do the best we can... |
348 | QString strName = tmpEntry.fullName(); | 356 | QString strName = tmpEntry.fullName(); |
349 | if ( strName.isEmpty() ) { | 357 | if ( strName.isEmpty() ) { |
350 | strName = tmpEntry.company(); | 358 | strName = tmpEntry.company(); |
351 | if ( strName.isEmpty() ) | 359 | if ( strName.isEmpty() ) |
352 | strName = "No Name"; | 360 | strName = "No Name"; |
353 | } | 361 | } |
354 | 362 | ||
355 | 363 | ||
356 | if ( QPEMessageBox::confirmDelete( this, tr( "Contacts" ), | 364 | if ( QPEMessageBox::confirmDelete( this, tr( "Contacts" ), |
357 | strName ) ) { | 365 | strName ) ) { |
358 | abList->deleteCurrentEntry(); | 366 | abList->deleteCurrentEntry(); |
359 | showList(); | 367 | showList(); |
360 | } | 368 | } |
361 | } else { | 369 | } else { |
362 | QMessageBox::warning( this, tr("Contacts"), | 370 | QMessageBox::warning( this, tr("Contacts"), |
363 | tr("Can not edit data, currently syncing") ); | 371 | tr("Can not edit data, currently syncing") ); |
364 | } | 372 | } |
365 | } | 373 | } |
366 | 374 | ||
367 | void AddressbookWindow::slotViewBack() | 375 | void AddressbookWindow::slotViewBack() |
368 | { | 376 | { |
369 | showList(); | 377 | showList(); |
370 | } | 378 | } |
371 | 379 | ||
372 | void AddressbookWindow::slotViewEdit() | 380 | void AddressbookWindow::slotViewEdit() |
373 | { | 381 | { |
374 | if(!syncing) { | 382 | if(!syncing) { |
375 | if (actionPersonal->isOn()) { | 383 | if (actionPersonal->isOn()) { |
376 | editPersonal(); | 384 | editPersonal(); |
377 | } else { | 385 | } else { |
378 | if ( !bAbEditFirstTime ) | 386 | if ( !bAbEditFirstTime ) |
379 | abEditor->setEntry( abList->currentEntry() ); | 387 | abEditor->setEntry( abList->currentEntry() ); |
380 | editEntry( EditEntry ); | 388 | editEntry( EditEntry ); |
381 | } | 389 | } |
382 | } else { | 390 | } else { |
383 | QMessageBox::warning( this, tr("Contacts"), | 391 | QMessageBox::warning( this, tr("Contacts"), |
384 | tr("Can not edit data, currently syncing") ); | 392 | tr("Can not edit data, currently syncing") ); |
385 | } | 393 | } |
386 | } | 394 | } |
387 | 395 | ||
388 | 396 | ||
389 | 397 | ||
390 | void AddressbookWindow::writeMail() | 398 | void AddressbookWindow::writeMail() |
391 | { | 399 | { |
392 | Contact c = abList->currentEntry(); | 400 | Contact c = abList->currentEntry(); |
393 | QString name = c.fileAs(); | 401 | QString name = c.fileAs(); |
394 | QString email = c.defaultEmail(); | 402 | QString email = c.defaultEmail(); |
395 | QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)"); | 403 | QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)"); |
396 | e << name << email; | 404 | e << name << email; |
397 | } | 405 | } |
398 | 406 | ||
399 | 407 | ||
400 | 408 | ||
401 | 409 | ||
402 | static const char * beamfile = "/tmp/obex/contact.vcf"; | 410 | static const char * beamfile = "/tmp/obex/contact.vcf"; |
403 | 411 | ||
404 | void AddressbookWindow::slotBeam() | 412 | void AddressbookWindow::slotBeam() |
405 | { | 413 | { |
406 | QString filename; | 414 | QString filename; |
407 | Contact c; | 415 | Contact c; |
408 | if ( actionPersonal->isOn() ) { | 416 | if ( actionPersonal->isOn() ) { |
409 | filename = addressbookPersonalVCardName(); | 417 | filename = addressbookPersonalVCardName(); |
410 | if (!QFile::exists(filename)) | 418 | if (!QFile::exists(filename)) |
411 | return; // can't beam a non-existent file | 419 | return; // can't beam a non-existent file |
412 | c = Contact::readVCard( filename )[0]; | 420 | c = Contact::readVCard( filename )[0]; |
413 | } else { | 421 | } else { |
414 | unlink( beamfile ); // delete if exists | 422 | unlink( beamfile ); // delete if exists |
415 | c = abList->currentEntry(); | 423 | c = abList->currentEntry(); |
416 | mkdir("/tmp/obex/", 0755); | 424 | mkdir("/tmp/obex/", 0755); |
417 | Contact::writeVCard( beamfile, c ); | 425 | Contact::writeVCard( beamfile, c ); |
418 | filename = beamfile; | 426 | filename = beamfile; |
419 | } | 427 | } |
420 | Ir *ir = new Ir( this ); | 428 | Ir *ir = new Ir( this ); |
421 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); | 429 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); |
422 | QString description = c.fullName(); | 430 | QString description = c.fullName(); |
423 | ir->send( filename, description, "text/x-vCard" ); | 431 | ir->send( filename, description, "text/x-vCard" ); |
424 | } | 432 | } |
425 | 433 | ||
426 | void AddressbookWindow::beamDone( Ir *ir ) | 434 | void AddressbookWindow::beamDone( Ir *ir ) |
427 | { | 435 | { |
428 | delete ir; | 436 | delete ir; |
429 | unlink( beamfile ); | 437 | unlink( beamfile ); |
430 | } | 438 | } |
431 | 439 | ||
432 | 440 | ||
433 | static void parseName( const QString& name, QString *first, QString *middle, | 441 | static void parseName( const QString& name, QString *first, QString *middle, |
434 | QString * last ) | 442 | QString * last ) |
435 | { | 443 | { |
436 | 444 | ||
437 | int comma = name.find ( "," ); | 445 | int comma = name.find ( "," ); |
438 | QString rest; | 446 | QString rest; |
439 | if ( comma > 0 ) { | 447 | if ( comma > 0 ) { |
440 | *last = name.left( comma ); | 448 | *last = name.left( comma ); |
441 | comma++; | 449 | comma++; |
442 | while ( comma < int(name.length()) && name[comma] == ' ' ) | 450 | while ( comma < int(name.length()) && name[comma] == ' ' ) |
443 | comma++; | 451 | comma++; |
444 | rest = name.mid( comma ); | 452 | rest = name.mid( comma ); |
445 | } else { | 453 | } else { |
446 | int space = name.findRev( ' ' ); | 454 | int space = name.findRev( ' ' ); |
447 | *last = name.mid( space+1 ); | 455 | *last = name.mid( space+1 ); |
448 | rest = name.left( space ); | 456 | rest = name.left( space ); |
449 | } | 457 | } |
450 | int space = rest.find( ' ' ); | 458 | int space = rest.find( ' ' ); |
451 | if ( space <= 0 ) { | 459 | if ( space <= 0 ) { |
452 | *first = rest; | 460 | *first = rest; |
453 | } else { | 461 | } else { |
454 | *first = rest.left( space ); | 462 | *first = rest.left( space ); |
455 | *middle = rest.mid( space+1 ); | 463 | *middle = rest.mid( space+1 ); |
456 | } | 464 | } |
457 | 465 | ||
458 | } | 466 | } |
459 | 467 | ||
460 | 468 | ||
461 | void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data) | 469 | void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data) |
462 | { | 470 | { |
463 | if (msg == "editPersonal()") { | 471 | if (msg == "editPersonal()") { |
464 | editPersonal(); | 472 | editPersonal(); |
465 | } else if (msg == "editPersonalAndClose()") { | 473 | } else if (msg == "editPersonalAndClose()") { |
466 | editPersonal(); | 474 | editPersonal(); |
467 | close(); | 475 | close(); |
468 | } else if ( msg == "addContact(QString,QString)" ) { | 476 | } else if ( msg == "addContact(QString,QString)" ) { |
469 | QDataStream stream(data,IO_ReadOnly); | 477 | QDataStream stream(data,IO_ReadOnly); |
470 | QString name, email; | 478 | QString name, email; |
471 | stream >> name >> email; | 479 | stream >> name >> email; |
472 | 480 | ||
473 | Contact cnt; | 481 | Contact cnt; |
474 | QString fn, mn, ln; | 482 | QString fn, mn, ln; |
475 | parseName( name, &fn, &mn, &ln ); | 483 | parseName( name, &fn, &mn, &ln ); |
476 | //qDebug( " %s - %s - %s", fn.latin1(), mn.latin1(), ln.latin1() ); | 484 | //qDebug( " %s - %s - %s", fn.latin1(), mn.latin1(), ln.latin1() ); |
477 | cnt.setFirstName( fn ); | 485 | cnt.setFirstName( fn ); |
478 | cnt.setMiddleName( mn ); | 486 | cnt.setMiddleName( mn ); |
479 | cnt.setLastName( ln ); | 487 | cnt.setLastName( ln ); |
480 | cnt.setEmails( email ); | 488 | cnt.setEmails( email ); |
481 | cnt.setDefaultEmail( email ); | 489 | cnt.setDefaultEmail( email ); |
482 | cnt.setFileAs(); | 490 | cnt.setFileAs(); |
483 | 491 | ||
484 | if ( bAbEditFirstTime ) { | 492 | if ( bAbEditFirstTime ) { |
485 | abEditor = new ContactEditor( cnt, &orderedFields, &slOrderedFields, | 493 | abEditor = new ContactEditor( cnt, &orderedFields, &slOrderedFields, |
486 | this, "editor" ); | 494 | this, "editor" ); |
487 | bAbEditFirstTime = FALSE; | 495 | bAbEditFirstTime = FALSE; |
488 | } else { | 496 | } else { |
489 | abEditor->setEntry( cnt ); | 497 | abEditor->setEntry( cnt ); |
490 | } | 498 | } |
491 | abView()->init( cnt ); | 499 | abView()->init( cnt ); |
492 | editEntry( NewEntry ); | 500 | editEntry( NewEntry ); |
493 | 501 | ||
494 | 502 | ||
495 | 503 | ||
496 | } | 504 | } |
497 | #if 0 | 505 | #if 0 |
498 | else if (msg == "pickAddresses(QCString,QCString,QStringList,...)" ) { | 506 | else if (msg == "pickAddresses(QCString,QCString,QStringList,...)" ) { |
499 | QDataStream stream(data,IO_ReadOnly); | 507 | QDataStream stream(data,IO_ReadOnly); |
500 | QCString ch,m; | 508 | QCString ch,m; |
501 | QStringList types; | 509 | QStringList types; |
502 | stream >> ch >> m >> types; | 510 | stream >> ch >> m >> types; |
503 | AddressPicker picker(abList,this,0,TRUE); | 511 | AddressPicker picker(abList,this,0,TRUE); |
504 | picker.showMaximized(); | 512 | picker.showMaximized(); |
505 | picker.setChoiceNames(types); | 513 | picker.setChoiceNames(types); |
506 | int i=0; | 514 | int i=0; |
507 | for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) { | 515 | for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) { |
508 | QStringList sel; | 516 | QStringList sel; |
509 | stream >> sel; | 517 | stream >> sel; |
510 | picker.setSelection(i++,sel); | 518 | picker.setSelection(i++,sel); |
511 | } | 519 | } |
512 | picker.showMaximized(); | 520 | picker.showMaximized(); |
513 | picker.exec(); | 521 | picker.exec(); |
514 | 522 | ||
515 | // ###### note: contacts may have been added - save here! | 523 | // ###### note: contacts may have been added - save here! |
516 | 524 | ||
517 | setCentralWidget(abList); | 525 | setCentralWidget(abList); |
518 | QCopEnvelope e(ch,m); | 526 | QCopEnvelope e(ch,m); |
519 | i=0; | 527 | i=0; |
520 | for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) { | 528 | for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) { |
521 | QStringList sel = picker.selection(i++); | 529 | QStringList sel = picker.selection(i++); |
522 | e << sel; | 530 | e << sel; |
523 | } | 531 | } |
524 | } | 532 | } |
525 | #endif | 533 | #endif |
526 | 534 | ||
527 | } | 535 | } |
528 | 536 | ||
529 | void AddressbookWindow::editPersonal() | 537 | void AddressbookWindow::editPersonal() |
530 | { | 538 | { |
531 | QString filename = addressbookPersonalVCardName(); | 539 | QString filename = addressbookPersonalVCardName(); |
532 | Contact me; | 540 | Contact me; |
533 | if (QFile::exists(filename)) | 541 | if (QFile::exists(filename)) |
534 | me = Contact::readVCard( filename )[0]; | 542 | me = Contact::readVCard( filename )[0]; |
535 | if (bAbEditFirstTime) { | 543 | if (bAbEditFirstTime) { |
536 | abEditor = new ContactEditor( me, &orderedFields, &slOrderedFields, | 544 | abEditor = new ContactEditor( me, &orderedFields, &slOrderedFields, |
537 | this, "editor" ); | 545 | this, "editor" ); |
538 | // don't create a new editor every time | 546 | // don't create a new editor every time |
539 | bAbEditFirstTime = FALSE; | 547 | bAbEditFirstTime = FALSE; |
540 | } else | 548 | } else |
541 | abEditor->setEntry( me ); | 549 | abEditor->setEntry( me ); |
542 | 550 | ||
543 | abEditor->setCaption(tr("Edit My Personal Details")); | 551 | abEditor->setCaption(tr("Edit My Personal Details")); |
544 | abEditor->showMaximized(); | 552 | abEditor->showMaximized(); |
545 | 553 | ||
546 | // fix the foxus... | 554 | // fix the foxus... |
547 | abEditor->setNameFocus(); | 555 | abEditor->setNameFocus(); |
548 | if ( abEditor->exec() ) { | 556 | if ( abEditor->exec() ) { |
549 | setFocus(); | 557 | setFocus(); |
550 | Contact new_personal = abEditor->entry(); | 558 | Contact new_personal = abEditor->entry(); |
551 | QString fname = addressbookPersonalVCardName(); | 559 | QString fname = addressbookPersonalVCardName(); |
552 | Contact::writeVCard( fname, new_personal ); | 560 | Contact::writeVCard( fname, new_personal ); |
553 | abView()->init(new_personal); | 561 | abView()->init(new_personal); |
554 | abView()->sync(); | 562 | abView()->sync(); |
555 | } | 563 | } |
556 | abEditor->setCaption( tr("Edit Address") ); | 564 | abEditor->setCaption( tr("Edit Address") ); |
557 | } | 565 | } |
558 | 566 | ||
559 | void AddressbookWindow::slotPersonalView() | 567 | void AddressbookWindow::slotPersonalView() |
560 | { | 568 | { |
561 | if (!actionPersonal->isOn()) { | 569 | if (!actionPersonal->isOn()) { |
562 | // we just turned it off | 570 | // we just turned it off |
563 | setCaption( tr("Contacts") ); | 571 | setCaption( tr("Contacts") ); |
564 | actionNew->setEnabled(TRUE); | 572 | actionNew->setEnabled(TRUE); |
565 | actionTrash->setEnabled(TRUE); | 573 | actionTrash->setEnabled(TRUE); |
566 | #ifndef MAKE_FOR_SHARP_ROM | 574 | #ifndef MAKE_FOR_SHARP_ROM |
567 | actionFind->setEnabled(TRUE); | 575 | actionFind->setEnabled(TRUE); |
568 | #endif | 576 | #endif |
569 | slotUpdateToolbar(); // maybe some of the above could be moved there | 577 | slotUpdateToolbar(); // maybe some of the above could be moved there |
570 | showList(); | 578 | showList(); |
571 | return; | 579 | return; |
572 | } | 580 | } |
573 | 581 | ||
574 | // XXX need to disable some QActions. | 582 | // XXX need to disable some QActions. |
575 | actionNew->setEnabled(FALSE); | 583 | actionNew->setEnabled(FALSE); |
576 | actionTrash->setEnabled(FALSE); | 584 | actionTrash->setEnabled(FALSE); |
577 | #ifndef MAKE_FOR_SHARP_ROM | 585 | #ifndef MAKE_FOR_SHARP_ROM |
578 | actionFind->setEnabled(FALSE); | 586 | actionFind->setEnabled(FALSE); |
579 | #endif | 587 | #endif |
580 | actionMail->setEnabled(FALSE); | 588 | actionMail->setEnabled(FALSE); |
581 | 589 | ||
582 | setCaption( tr("Contacts - My Personal Details") ); | 590 | setCaption( tr("Contacts - My Personal Details") ); |
583 | QString filename = addressbookPersonalVCardName(); | 591 | QString filename = addressbookPersonalVCardName(); |
584 | Contact me; | 592 | Contact me; |
585 | if (QFile::exists(filename)) | 593 | if (QFile::exists(filename)) |
586 | me = Contact::readVCard( filename )[0]; | 594 | me = Contact::readVCard( filename )[0]; |
587 | 595 | ||
588 | abView()->init( me ); | 596 | abView()->init( me ); |
589 | abView()->sync(); | 597 | abView()->sync(); |
590 | abList->hide(); | 598 | abList->hide(); |
591 | setCentralWidget( abView() ); | 599 | setCentralWidget( abView() ); |
592 | mView->show(); | 600 | mView->show(); |
593 | mView->setFocus(); | 601 | mView->setFocus(); |
594 | } | 602 | } |
595 | 603 | ||
596 | void AddressbookWindow::editEntry( EntryMode entryMode ) | 604 | void AddressbookWindow::editEntry( EntryMode entryMode ) |
597 | { | 605 | { |
598 | Contact entry; | 606 | Contact entry; |
599 | if ( bAbEditFirstTime ) { | 607 | if ( bAbEditFirstTime ) { |
600 | abEditor = new ContactEditor( entry, &orderedFields, &slOrderedFields, | 608 | abEditor = new ContactEditor( entry, &orderedFields, &slOrderedFields, |
601 | this, "editor" ); | 609 | this, "editor" ); |
602 | bAbEditFirstTime = FALSE; | 610 | bAbEditFirstTime = FALSE; |
603 | if ( entryMode == EditEntry ) | 611 | if ( entryMode == EditEntry ) |
604 | abEditor->setEntry( abList->currentEntry() ); | 612 | abEditor->setEntry( abList->currentEntry() ); |
605 | } | 613 | } |
606 | // other things may chane the caption. | 614 | // other things may chane the caption. |
607 | abEditor->setCaption( tr("Edit Address") ); | 615 | abEditor->setCaption( tr("Edit Address") ); |
608 | 616 | ||
609 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 617 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
610 | abEditor->showMaximized(); | 618 | abEditor->showMaximized(); |
611 | #endif | 619 | #endif |
612 | // fix the foxus... | 620 | // fix the foxus... |
613 | abEditor->setNameFocus(); | 621 | abEditor->setNameFocus(); |
614 | if ( abEditor->exec() ) { | 622 | if ( abEditor->exec() ) { |
615 | setFocus(); | 623 | setFocus(); |
616 | if ( entryMode == NewEntry ) { | 624 | if ( entryMode == NewEntry ) { |
617 | Contact insertEntry = abEditor->entry(); | 625 | Contact insertEntry = abEditor->entry(); |
618 | insertEntry.assignUid(); | 626 | insertEntry.assignUid(); |
619 | abList->addEntry( insertEntry ); | 627 | abList->addEntry( insertEntry ); |
620 | } else { | 628 | } else { |
621 | Contact replaceEntry = abEditor->entry(); | 629 | Contact replaceEntry = abEditor->entry(); |
622 | if ( !replaceEntry.isValidUid() ) | 630 | if ( !replaceEntry.isValidUid() ) |
623 | replaceEntry.assignUid(); | 631 | replaceEntry.assignUid(); |
624 | abList->replaceCurrentEntry( replaceEntry ); | 632 | abList->replaceCurrentEntry( replaceEntry ); |
625 | } | 633 | } |
626 | } | 634 | } |
627 | populateCategories(); | 635 | populateCategories(); |
628 | showList(); | 636 | showList(); |
629 | } | 637 | } |
630 | 638 | ||
631 | void AddressbookWindow::listIsEmpty( bool empty ) | 639 | void AddressbookWindow::listIsEmpty( bool empty ) |
632 | { | 640 | { |
633 | if ( !empty ) { | 641 | if ( !empty ) { |
634 | deleteButton->setEnabled( TRUE ); | 642 | deleteButton->setEnabled( TRUE ); |
635 | } | 643 | } |
636 | } | 644 | } |
637 | 645 | ||
638 | void AddressbookWindow::reload() | 646 | void AddressbookWindow::reload() |
639 | { | 647 | { |
640 | syncing = FALSE; | 648 | syncing = FALSE; |
641 | abList->clear(); | 649 | abList->clear(); |
642 | abList->load( addressbookXMLFilename() ); | 650 | abList->load( addressbookXMLFilename() ); |
643 | } | 651 | } |
644 | 652 | ||
645 | void AddressbookWindow::flush() | 653 | void AddressbookWindow::flush() |
646 | { | 654 | { |
647 | syncing = TRUE; | 655 | syncing = TRUE; |
648 | abList->save( addressbookXMLFilename() ); | 656 | abList->save( addressbookXMLFilename() ); |
649 | } | 657 | } |
650 | 658 | ||
651 | 659 | ||
652 | void AddressbookWindow::closeEvent( QCloseEvent *e ) | 660 | void AddressbookWindow::closeEvent( QCloseEvent *e ) |
653 | { | 661 | { |
654 | if ( centralWidget() == mView ) { | 662 | if ( centralWidget() == mView ) { |
655 | if (actionPersonal->isOn()) { | 663 | if (actionPersonal->isOn()) { |
656 | // pretend we clicked it off | 664 | // pretend we clicked it off |
657 | actionPersonal->setOn(FALSE); | 665 | actionPersonal->setOn(FALSE); |
658 | slotPersonalView(); | 666 | slotPersonalView(); |
659 | } else { | 667 | } else { |
660 | showList(); | 668 | showList(); |
661 | } | 669 | } |
662 | e->ignore(); | 670 | e->ignore(); |
663 | return; | 671 | return; |
664 | } | 672 | } |
665 | 673 | ||
666 | if(syncing) { | 674 | if(syncing) { |
667 | /* shouldn't we save, I hear you say? well its already been set | 675 | /* shouldn't we save, I hear you say? well its already been set |
668 | so that an edit can not occur during a sync, and we flushed | 676 | so that an edit can not occur during a sync, and we flushed |
669 | at the start of the sync, so there is no need to save | 677 | at the start of the sync, so there is no need to save |
670 | Saving however itself would cause problems. */ | 678 | Saving however itself would cause problems. */ |
671 | e->accept(); | 679 | e->accept(); |
672 | return; | 680 | return; |
673 | } | 681 | } |
674 | //################## shouldn't always save | 682 | //################## shouldn't always save |
675 | if ( save() ) | 683 | if ( save() ) |
676 | e->accept(); | 684 | e->accept(); |
677 | else | 685 | else |
678 | e->ignore(); | 686 | e->ignore(); |
679 | } | 687 | } |
680 | 688 | ||
681 | /* | 689 | /* |
682 | Returns TRUE if it is OK to exit | 690 | Returns TRUE if it is OK to exit |
683 | */ | 691 | */ |
684 | 692 | ||
685 | bool AddressbookWindow::save() | 693 | bool AddressbookWindow::save() |
686 | { | 694 | { |
687 | QString str = addressbookXMLFilename(); | 695 | QString str = addressbookXMLFilename(); |
688 | if ( str.isNull() ) { | 696 | if ( str.isNull() ) { |
689 | if ( QMessageBox::critical( 0, tr("Out of space"), | 697 | if ( QMessageBox::critical( 0, tr("Out of space"), |
690 | tr("Unable to save information.\n" | 698 | tr("Unable to save information.\n" |
691 | "Free up some space\n" | 699 | "Free up some space\n" |
692 | "and try again.\n" | 700 | "and try again.\n" |
693 | "\nQuit anyway?"), | 701 | "\nQuit anyway?"), |
694 | QMessageBox::Yes|QMessageBox::Escape, | 702 | QMessageBox::Yes|QMessageBox::Escape, |
695 | QMessageBox::No|QMessageBox::Default ) | 703 | QMessageBox::No|QMessageBox::Default ) |
696 | != QMessageBox::No ) | 704 | != QMessageBox::No ) |
697 | return TRUE; | 705 | return TRUE; |
698 | else | 706 | else |
699 | return FALSE; | 707 | return FALSE; |
700 | } else { | 708 | } else { |
701 | if ( !abList->save( str ) ) { | 709 | if ( !abList->save( str ) ) { |
702 | if ( QMessageBox::critical( 0, tr( "Out of space" ), | 710 | if ( QMessageBox::critical( 0, tr( "Out of space" ), |
703 | tr("Unable to save information.\n" | 711 | tr("Unable to save information.\n" |
704 | "Free up some space\n" | 712 | "Free up some space\n" |
705 | "and try again.\n" | 713 | "and try again.\n" |
706 | "\nQuit anyway?"), | 714 | "\nQuit anyway?"), |
707 | QMessageBox::Yes|QMessageBox::Escape, | 715 | QMessageBox::Yes|QMessageBox::Escape, |
708 | QMessageBox::No|QMessageBox::Default ) | 716 | QMessageBox::No|QMessageBox::Default ) |
709 | != QMessageBox::No ) | 717 | != QMessageBox::No ) |
710 | return TRUE; | 718 | return TRUE; |
711 | else | 719 | else |
712 | return FALSE; | 720 | return FALSE; |
713 | } | 721 | } |
714 | } | 722 | } |
715 | return TRUE; | 723 | return TRUE; |
716 | } | 724 | } |
717 | 725 | ||
718 | void AddressbookWindow::slotSettings() | 726 | void AddressbookWindow::slotSettings() |
719 | { | 727 | { |
720 | AddressSettings frmSettings( this ); | 728 | AddressSettings frmSettings( this ); |
721 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 729 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
722 | frmSettings.showMaximized(); | 730 | frmSettings.showMaximized(); |
723 | #endif | 731 | #endif |
724 | 732 | ||
725 | if ( frmSettings.exec() ) { | 733 | if ( frmSettings.exec() ) { |
726 | allFields.clear(); | 734 | allFields.clear(); |
727 | orderedFields.clear(); | 735 | orderedFields.clear(); |
728 | slOrderedFields.clear(); | 736 | slOrderedFields.clear(); |
729 | initFields(); | 737 | initFields(); |
730 | if ( abEditor ) | 738 | if ( abEditor ) |
731 | abEditor->loadFields(); | 739 | abEditor->loadFields(); |
732 | abList->refresh(); | 740 | abList->refresh(); |
733 | } | 741 | } |
734 | } | 742 | } |
735 | 743 | ||
736 | 744 | ||
737 | void AddressbookWindow::initFields() | 745 | void AddressbookWindow::initFields() |
738 | { | 746 | { |
739 | // we really don't need the things from the configuration, anymore | 747 | // we really don't need the things from the configuration, anymore |
740 | // only thing that is important are the important categories. So, | 748 | // only thing that is important are the important categories. So, |
741 | // Call the contact functions that correspond to these old functions... | 749 | // Call the contact functions that correspond to these old functions... |
742 | 750 | ||
743 | QStringList xmlFields = Contact::fields(); | 751 | QStringList xmlFields = Contact::fields(); |
744 | QStringList visibleFields = Contact::trfields(); | 752 | QStringList visibleFields = Contact::trfields(); |
745 | xmlFields.remove( "Title" ); | 753 | xmlFields.remove( "Title" ); |
746 | visibleFields.remove( tr("Name Title") ); | 754 | visibleFields.remove( tr("Name Title") ); |
747 | visibleFields.remove( tr("Notes") ); | 755 | visibleFields.remove( tr("Notes") ); |
748 | 756 | ||
749 | int i, | 757 | int i, |
750 | version; | 758 | version; |
751 | Config cfg( "AddressBook" ); | 759 | Config cfg( "AddressBook" ); |
752 | QString zn; | 760 | QString zn; |
753 | 761 | ||
754 | // ### Write a function to keep this from happening again... | 762 | // ### Write a function to keep this from happening again... |
755 | QStringList::ConstIterator it; | 763 | QStringList::ConstIterator it; |
756 | for ( i = 0, it = xmlFields.begin(); it != xmlFields.end(); ++it, i++ ) { | 764 | for ( i = 0, it = xmlFields.begin(); it != xmlFields.end(); ++it, i++ ) { |
757 | allFields.append( i + 3 ); | 765 | allFields.append( i + 3 ); |
758 | } | 766 | } |
759 | 767 | ||
760 | cfg.setGroup( "Version" ); | 768 | cfg.setGroup( "Version" ); |
761 | version = cfg.readNumEntry( "version" ); | 769 | version = cfg.readNumEntry( "version" ); |
762 | i = 0; | 770 | i = 0; |
763 | startFontSize = 1; | 771 | startFontSize = 1; |
764 | 772 | ||
765 | if ( version >= ADDRESSVERSION ) { | 773 | if ( version >= ADDRESSVERSION ) { |
766 | 774 | ||
767 | cfg.setGroup( "ImportantCategory" ); | 775 | cfg.setGroup( "ImportantCategory" ); |
768 | 776 | ||
769 | zn = cfg.readEntry( "Category" + QString::number(i), QString::null ); | 777 | zn = cfg.readEntry( "Category" + QString::number(i), QString::null ); |
770 | while ( !zn.isNull() ) { | 778 | while ( !zn.isNull() ) { |
771 | if ( zn.contains( tr("Work") ) || zn.contains( tr("Mb") ) ) { | 779 | if ( zn.contains( tr("Work") ) || zn.contains( tr("Mb") ) ) { |
772 | slOrderedFields.clear(); | 780 | slOrderedFields.clear(); |
773 | break; | 781 | break; |
774 | } | 782 | } |
775 | slOrderedFields.append( zn ); | 783 | slOrderedFields.append( zn ); |
776 | zn = cfg.readEntry( "Category" + QString::number(++i), QString::null ); | 784 | zn = cfg.readEntry( "Category" + QString::number(++i), QString::null ); |
777 | } | 785 | } |
778 | cfg.setGroup( "Font" ); | 786 | cfg.setGroup( "Font" ); |
779 | startFontSize = cfg.readNumEntry( "fontSize", 1 ); | 787 | startFontSize = cfg.readNumEntry( "fontSize", 1 ); |
780 | 788 | ||
781 | 789 | ||
782 | } else { | 790 | } else { |
783 | QString str; | 791 | QString str; |
784 | str = getenv("HOME"); | 792 | str = getenv("HOME"); |
785 | str += "/Settings/AddressBook.conf"; | 793 | str += "/Settings/AddressBook.conf"; |
786 | QFile::remove( str ); | 794 | QFile::remove( str ); |
787 | } | 795 | } |
788 | if ( slOrderedFields.count() > 0 ) { | 796 | if ( slOrderedFields.count() > 0 ) { |
789 | for( QStringList::ConstIterator it = slOrderedFields.begin(); | 797 | for( QStringList::ConstIterator it = slOrderedFields.begin(); |
790 | it != slOrderedFields.end(); ++it ) { | 798 | it != slOrderedFields.end(); ++it ) { |
791 | QValueList<int>::ConstIterator itVl; | 799 | QValueList<int>::ConstIterator itVl; |
792 | QStringList::ConstIterator itVis; | 800 | QStringList::ConstIterator itVis; |
793 | itVl = allFields.begin(); | 801 | itVl = allFields.begin(); |
794 | for ( itVis = visibleFields.begin(); | 802 | for ( itVis = visibleFields.begin(); |
795 | itVis != visibleFields.end() && itVl != allFields.end(); | 803 | itVis != visibleFields.end() && itVl != allFields.end(); |
796 | ++itVis, ++itVl ) { | 804 | ++itVis, ++itVl ) { |
797 | if ( *it == *itVis && itVl != allFields.end() ) { | 805 | if ( *it == *itVis && itVl != allFields.end() ) { |
798 | orderedFields.append( *itVl ); | 806 | orderedFields.append( *itVl ); |
799 | } | 807 | } |
800 | } | 808 | } |
801 | } | 809 | } |
802 | } else { | 810 | } else { |
803 | QValueList<int>::ConstIterator it; | 811 | QValueList<int>::ConstIterator it; |
804 | for ( it = allFields.begin(); it != allFields.end(); ++it ) | 812 | for ( it = allFields.begin(); it != allFields.end(); ++it ) |
805 | orderedFields.append( *it ); | 813 | orderedFields.append( *it ); |
806 | 814 | ||
807 | slOrderedFields = visibleFields; | 815 | slOrderedFields = visibleFields; |
808 | orderedFields.remove( Qtopia::AddressUid ); | 816 | orderedFields.remove( Qtopia::AddressUid ); |
809 | orderedFields.remove( Qtopia::Title ); | 817 | orderedFields.remove( Qtopia::Title ); |
810 | orderedFields.remove( Qtopia::Groups ); | 818 | orderedFields.remove( Qtopia::Groups ); |
811 | orderedFields.remove( Qtopia::AddressCategory ); | 819 | orderedFields.remove( Qtopia::AddressCategory ); |
812 | orderedFields.remove( Qtopia::FirstName ); | 820 | orderedFields.remove( Qtopia::FirstName ); |
813 | orderedFields.remove( Qtopia::LastName ); | 821 | orderedFields.remove( Qtopia::LastName ); |
814 | orderedFields.remove( Qtopia::DefaultEmail ); | 822 | orderedFields.remove( Qtopia::DefaultEmail ); |
815 | orderedFields.remove( Qtopia::FileAs ); | 823 | orderedFields.remove( Qtopia::FileAs ); |
816 | orderedFields.remove( Qtopia::Notes ); | 824 | orderedFields.remove( Qtopia::Notes ); |
817 | orderedFields.remove( Qtopia::Gender ); | 825 | orderedFields.remove( Qtopia::Gender ); |
818 | slOrderedFields.remove( tr("Name Title") ); | 826 | slOrderedFields.remove( tr("Name Title") ); |
819 | slOrderedFields.remove( tr("First Name") ); | 827 | slOrderedFields.remove( tr("First Name") ); |
820 | slOrderedFields.remove( tr("Last Name") ); | 828 | slOrderedFields.remove( tr("Last Name") ); |
821 | slOrderedFields.remove( tr("File As") ); | 829 | slOrderedFields.remove( tr("File As") ); |
822 | slOrderedFields.remove( tr("Default Email") ); | 830 | slOrderedFields.remove( tr("Default Email") ); |
823 | slOrderedFields.remove( tr("Notes") ); | 831 | slOrderedFields.remove( tr("Notes") ); |
824 | slOrderedFields.remove( tr("Gender") ); | 832 | slOrderedFields.remove( tr("Gender") ); |
825 | 833 | ||
826 | } | 834 | } |
827 | } | 835 | } |
828 | 836 | ||
829 | 837 | ||
830 | AbLabel *AddressbookWindow::abView() | 838 | AbLabel *AddressbookWindow::abView() |
831 | { | 839 | { |
832 | if ( !mView ) { | 840 | if ( !mView ) { |
833 | mView = new AbLabel( this, "viewer" ); | 841 | mView = new AbLabel( this, "viewer" ); |
834 | mView->init( Contact() ); | 842 | mView->init( Contact() ); |
835 | connect( mView, SIGNAL( okPressed() ), this, SLOT( slotListView() ) ); | 843 | connect( mView, SIGNAL( okPressed() ), this, SLOT( slotListView() ) ); |
836 | } | 844 | } |
837 | return mView; | 845 | return mView; |
838 | } | 846 | } |
839 | 847 | ||
840 | void AddressbookWindow::slotFind() | 848 | void AddressbookWindow::slotFind() |
841 | { | 849 | { |
842 | #ifndef MAKE_FOR_SHARP_ROM | 850 | #ifndef MAKE_FOR_SHARP_ROM |
843 | if ( centralWidget() == abView() ) | 851 | if ( centralWidget() == abView() ) |
844 | showList(); | 852 | showList(); |
845 | 853 | ||
846 | FindDialog frmFind( "Contacts", this ); | 854 | FindDialog frmFind( "Contacts", this ); |
847 | QObject::connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), abList, SLOT(slotDoFind( const QString&,bool,bool,int))); | 855 | QObject::connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), abList, SLOT(slotDoFind( const QString&,bool,bool,int))); |
848 | QObject::connect( abList, SIGNAL(signalNotFound()), &frmFind, SLOT(slotNotFound()) ); | 856 | QObject::connect( abList, SIGNAL(signalNotFound()), &frmFind, SLOT(slotNotFound()) ); |
849 | QObject::connect( abList, SIGNAL(signalWrapAround()), &frmFind, SLOT(slotWrapAround()) ); | 857 | QObject::connect( abList, SIGNAL(signalWrapAround()), &frmFind, SLOT(slotWrapAround()) ); |
850 | 858 | ||
851 | frmFind.exec(); | 859 | frmFind.exec(); |
852 | 860 | ||
853 | if ( abList->numSelections() ) | 861 | if ( abList->numSelections() ) |
854 | abList->clearSelection(); | 862 | abList->clearSelection(); |
855 | 863 | ||
856 | abList->clearFindRow(); | 864 | abList->clearFindRow(); |
857 | #endif | 865 | #endif |
858 | } | 866 | } |
859 | 867 | ||
860 | void AddressbookWindow::slotSetCategory( int c ) | 868 | void AddressbookWindow::slotSetCategory( int c ) |
861 | { | 869 | { |
862 | if ( c <= 0 ) | 870 | if ( c <= 0 ) |
863 | return; | 871 | return; |
864 | for ( unsigned int i = 1; i < catMenu->count(); i++ ) | 872 | for ( unsigned int i = 1; i < catMenu->count(); i++ ) |
865 | catMenu->setItemChecked( i, c == (int)i ); | 873 | catMenu->setItemChecked( i, c == (int)i ); |
866 | if ( c == 1 ) { | 874 | if ( c == 1 ) { |
867 | abList->setShowCategory( QString::null ); | 875 | abList->setShowCategory( QString::null ); |
868 | setCaption( tr("Contacts") + " - " + tr ( "All" ) ); | 876 | setCaption( tr("Contacts") + " - " + tr ( "All" ) ); |
869 | } else if ( c == (int)catMenu->count() ) { | 877 | } else if ( c == (int)catMenu->count() ) { |
870 | abList->setShowCategory( tr( "Unfiled" ) ); | 878 | abList->setShowCategory( tr( "Unfiled" ) ); |
871 | setCaption( tr("Contacts") + " - " + tr( "Unfiled" ) ); | 879 | setCaption( tr("Contacts") + " - " + tr( "Unfiled" ) ); |
872 | } else { | 880 | } else { |
873 | QString cat = abList->categories()[c - 2]; | 881 | QString cat = abList->categories()[c - 2]; |
874 | abList->setShowCategory( cat ); | 882 | abList->setShowCategory( cat ); |
875 | setCaption( tr("Contacts") + " - " + cat ); | 883 | setCaption( tr("Contacts") + " - " + cat ); |
876 | } | 884 | } |
877 | } | 885 | } |
878 | 886 | ||
879 | void AddressbookWindow::populateCategories() | 887 | void AddressbookWindow::populateCategories() |
880 | { | 888 | { |
881 | catMenu->clear(); | 889 | catMenu->clear(); |
882 | 890 | ||
883 | int id, | 891 | int id, |
884 | rememberId; | 892 | rememberId; |
885 | id = 1; | 893 | id = 1; |
886 | catMenu->insertItem( tr( "All" ), id++ ); | 894 | catMenu->insertItem( tr( "All" ), id++ ); |
887 | QStringList categories = abList->categories(); | 895 | QStringList categories = abList->categories(); |
888 | categories.append( tr( "Unfiled" ) ); | 896 | categories.append( tr( "Unfiled" ) ); |
889 | for ( QStringList::Iterator it = categories.begin(); | 897 | for ( QStringList::Iterator it = categories.begin(); |
890 | it != categories.end(); ++it ) { | 898 | it != categories.end(); ++it ) { |
891 | catMenu->insertItem( *it, id ); | 899 | catMenu->insertItem( *it, id ); |
892 | if ( *it == abList->showCategory() ) | 900 | if ( *it == abList->showCategory() ) |
893 | rememberId = id; | 901 | rememberId = id; |
894 | ++id; | 902 | ++id; |
895 | } | 903 | } |
896 | if ( abList->showCategory().isEmpty() ) | 904 | if ( abList->showCategory().isEmpty() ) |
897 | slotSetCategory( 1 ); | 905 | slotSetCategory( 1 ); |
898 | else | 906 | else |
899 | slotSetCategory( rememberId ); | 907 | slotSetCategory( rememberId ); |
900 | } | 908 | } |