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