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