summaryrefslogtreecommitdiff
path: root/core/pim/addressbook/addressbook.cpp
authoreilers <eilers>2002-10-08 12:33:52 (UTC)
committer eilers <eilers>2002-10-08 12:33:52 (UTC)
commita194611bf645fe7e2e9e83733ababc587fd42f1d (patch) (unidiff)
tree2c21a5576bce48dba2fe83f6c849c0d16025a848 /core/pim/addressbook/addressbook.cpp
parent333fec32d47ea32de9fb4c8cd378a519785a1ff8 (diff)
downloadopie-a194611bf645fe7e2e9e83733ababc587fd42f1d.zip
opie-a194611bf645fe7e2e9e83733ababc587fd42f1d.tar.gz
opie-a194611bf645fe7e2e9e83733ababc587fd42f1d.tar.bz2
Joined development branch: It uses the new PIM API
Some features in "View" added by Darwin Zins, but they are not finished..
Diffstat (limited to 'core/pim/addressbook/addressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/addressbook/addressbook.cpp1493
1 files changed, 782 insertions, 711 deletions
diff --git a/core/pim/addressbook/addressbook.cpp b/core/pim/addressbook/addressbook.cpp
index 3255269..cf2eddf 100644
--- a/core/pim/addressbook/addressbook.cpp
+++ b/core/pim/addressbook/addressbook.cpp
@@ -10,13 +10,13 @@
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** OContact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#define QTOPIA_INTERNAL_FD 21#define QTOPIA_INTERNAL_FD
22 22
@@ -66,894 +66,965 @@
66 66
67#include <qdatetime.h> 67#include <qdatetime.h>
68 68
69#include "picker.h" 69#include "picker.h"
70static QString addressbookOldXMLFilename() 70static QString addressbookOldXMLFilename()
71{ 71{
72 QString filename = QPEApplication::documentDir() + "addressbook.xml"; 72 QString filename = QPEApplication::documentDir() + "addressbook.xml";
73 return filename; 73 return filename;
74} 74}
75 75
76static QString addressbookXMLFilename() 76static QString addressbookXMLFilename()
77{ 77{
78 QString filename = Global::applicationFileName("addressbook", 78 QString filename = Global::applicationFileName("addressbook",
79 "addressbook.xml"); 79 "addressbook.xml");
80 return filename; 80 return filename;
81} 81}
82 82
83static QString addressbookPersonalVCardName() 83static QString addressbookPersonalVCardName()
84{ 84{
85 QString filename = Global::applicationFileName("addressbook", 85 QString filename = Global::applicationFileName("addressbook",
86 "businesscard.vcf"); 86 "businesscard.vcf");
87 return filename; 87 return filename;
88} 88}
89 89
90 90
91AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, 91AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name,
92 WFlags f ) 92 WFlags f )
93 : QMainWindow( parent, name, f ), 93 : QMainWindow( parent, name, f ),
94 abEditor(0), 94 abEditor(0),
95 bAbEditFirstTime(TRUE), 95 bAbEditFirstTime(TRUE),
96 syncing(FALSE) 96 syncing(FALSE)
97{ 97{
98 initFields(); 98 isLoading = true;
99 99
100 setCaption( tr("Contacts") ); 100 initFields();
101 setIcon( Resource::loadPixmap( "AddressBook" ) ); 101
102 102 setCaption( tr("Contacts") );
103 setToolBarsMovable( FALSE ); 103 setIcon( Resource::loadPixmap( "AddressBook" ) );
104 104
105 // Create Toolbars 105 setToolBarsMovable( FALSE );
106 106
107 QPEToolBar *bar = new QPEToolBar( this ); 107 // Create Toolbars
108 bar->setHorizontalStretchable( TRUE ); 108
109 109 QPEToolBar *bar = new QPEToolBar( this );
110 QPEMenuBar *mbList = new QPEMenuBar( bar ); 110 bar->setHorizontalStretchable( TRUE );
111 mbList->setMargin( 0 ); 111
112 112 QPEMenuBar *mbList = new QPEMenuBar( bar );
113 QPopupMenu *edit = new QPopupMenu( this ); 113 mbList->setMargin( 0 );
114 mbList->insertItem( tr( "Contact" ), edit ); 114
115 115 QPopupMenu *edit = new QPopupMenu( this );
116 listTools = new QPEToolBar( this, "list operations" ); 116 mbList->insertItem( tr( "Contact" ), edit );
117 117
118 118 listTools = new QPEToolBar( this, "list operations" );
119 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 119
120 0, this, 0 ); 120
121 actionNew = a; 121 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null,
122 connect( a, SIGNAL( activated() ), this, SLOT( slotListNew() ) ); 122 0, this, 0 );
123 a->addTo( edit ); 123 actionNew = a;
124 a->addTo( listTools ); 124 connect( a, SIGNAL( activated() ), this, SLOT( slotListNew() ) );
125 125 a->addTo( edit );
126 a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null, 126 a->addTo( listTools );
127 0, this, 0 ); 127
128 actionEdit = a; 128 a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null,
129 connect( a, SIGNAL( activated() ), this, SLOT( slotViewEdit() ) ); 129 0, this, 0 );
130 a->addTo( edit ); 130 actionEdit = a;
131 a->addTo( listTools ); 131 connect( a, SIGNAL( activated() ), this, SLOT( slotViewEdit() ) );
132 132 a->addTo( edit );
133 a = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 133 a->addTo( listTools );
134 0, this, 0 ); 134
135 actionTrash = a; 135 a = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null,
136 connect( a, SIGNAL( activated() ), this, SLOT( slotListDelete() ) ); 136 0, this, 0 );
137 a->addTo( edit ); 137 actionTrash = a;
138 a->addTo( listTools ); 138 connect( a, SIGNAL( activated() ), this, SLOT( slotListDelete() ) );
139 139 a->addTo( edit );
140 140 a->addTo( listTools );
141 // make it possible to go directly to businesscard via qcop call 141
142
143 // make it possible to go directly to businesscard via qcop call
142#if defined(Q_WS_QWS) 144#if defined(Q_WS_QWS)
143#if !defined(QT_NO_COP) 145#if !defined(QT_NO_COP)
144 QCopChannel *addressChannel = new QCopChannel("QPE/Addressbook" , this ); 146 QCopChannel *addressChannel = new QCopChannel("QPE/Addressbook" , this );
145 connect (addressChannel, SIGNAL( received(const QCString &, const QByteArray &)), 147 connect (addressChannel, SIGNAL( received(const QCString &, const QByteArray &)),
146 this, SLOT ( appMessage(const QCString &, const QByteArray &) ) ); 148 this, SLOT ( appMessage(const QCString &, const QByteArray &) ) );
147#endif 149#endif
148#endif 150#endif
149 151
150 152
151 153
152 154
153 155
154#ifndef MAKE_FOR_SHARP_ROM 156#ifndef MAKE_FOR_SHARP_ROM
155 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), 157 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ),
156 QString::null, 0, this, 0 ); 158 QString::null, 0, this, 0 );
157 actionFind = a; 159 actionFind = a;
158 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); 160 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) );
159 a->addTo( edit ); 161 a->addTo( edit );
160 a->addTo( listTools ); 162 a->addTo( listTools );
161#endif 163#endif
162 164
163 165
164 a = new QAction( tr( "Write Mail To" ), Resource::loadPixmap( "qtmail/reply" ), 166 a = new QAction( tr( "Write Mail To" ), Resource::loadPixmap( "qtmail/reply" ),
165 QString::null, 0, this, 0 ); 167 QString::null, 0, this, 0 );
166 //a->setEnabled( FALSE ); we got support for it now :) zecke 168 //a->setEnabled( FALSE ); we got support for it now :) zecke
167 actionMail = a; 169 actionMail = a;
168 connect( a, SIGNAL( activated() ), this, SLOT( writeMail() ) ); 170 connect( a, SIGNAL( activated() ), this, SLOT( writeMail() ) );
169 a->addTo( edit ); 171 a->addTo( edit );
170 a->addTo( listTools ); 172 a->addTo( listTools );
171 173
172 174
173 175
174 if ( Ir::supported() ) { 176 if ( Ir::supported() ) {
175 a = new QAction( tr ("Beam Entry" ), Resource::loadPixmap( "beam" ), QString::null, 177 a = new QAction( tr ("Beam Entry" ), Resource::loadPixmap( "beam" ), QString::null,
176 0, this, 0 ); 178 0, this, 0 );
177 actionBeam = a; 179 actionBeam = a;
178 connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) ); 180 connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) );
179 a->addTo( edit ); 181 a->addTo( edit );
180 a->addTo( listTools ); 182 a->addTo( listTools );
181 } 183 }
182 184
183 edit->insertSeparator(); 185 edit->insertSeparator();
184 186
185 a = new QAction( tr("Import vCard"), QString::null, 0, 0, 0, TRUE ); 187 a = new QAction( tr("Import vCard"), QString::null, 0, 0, 0, TRUE );
186 actionPersonal = a; 188 actionPersonal = a;
187 connect( a, SIGNAL( activated() ), this, SLOT( importvCard() ) ); 189 connect( a, SIGNAL( activated() ), this, SLOT( importvCard() ) );
188 a->addTo( edit ); 190 a->addTo( edit );
189 191
190 192 edit->insertSeparator();
191 edit->insertSeparator(); 193
192 194 a = new QAction( tr("My Personal Details"), QString::null, 0, 0, 0, TRUE );
193 a = new QAction( tr("My Personal Details"), QString::null, 0, 0, 0, TRUE ); 195 actionPersonal = a;
194 actionPersonal = a; 196 connect( a, SIGNAL( activated() ), this, SLOT( slotPersonalView() ) );
195 connect( a, SIGNAL( activated() ), this, SLOT( slotPersonalView() ) ); 197 a->addTo( edit );
196 a->addTo( edit ); 198
197 199
198 200 a = new QAction( tr( "Arrange Edit Fields"), QString::null, 0, 0 );
199 a = new QAction( tr( "Arrange Edit Fields"), QString::null, 0, 0 ); 201 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) );
200 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); 202 a->addTo( edit );
201 a->addTo( edit ); 203
202 204 // Create Views
203 // Create Views 205
204 206 // This is safe to call without checking to see if it exists...
205 // This is safe to call without checking to see if it exists... 207 // not to mention it also does the necessary stuff for the
206 // not to mention it also does the necessary stuff for the 208 // journaling...
207 // journaling... 209 QString str = addressbookXMLFilename();
208 QString str = addressbookXMLFilename(); 210 if ( str.isNull() ) {
209 if ( str.isNull() ) { 211 QMessageBox::warning(
210 QMessageBox::warning( this, tr("Out of Space"), 212 this,
211 tr("There is not enough space to create\n" 213 tr("Out of Space"),
212 "neccessary startup files.\n" 214 tr("There is not enough space to create\n"
213 "\nFree up some space before\nentering data!") 215 "neccessary startup files.\n"
214 ); 216 "\nFree up some space before\nentering data!")
215 } 217 );
216 218 }
217 listContainer = new QWidget( this ); 219
218 220 listContainer = new QWidget( this );
219 QVBoxLayout *vb = new QVBoxLayout( listContainer ); 221
220 222 QVBoxLayout *vb = new QVBoxLayout( listContainer );
221 abList = new AbTable( &orderedFields, listContainer, "table" ); 223
222 vb->addWidget(abList); 224 abList = new AbTable( &orderedFields, listContainer, "table" );
223 abList->setHScrollBarMode( QScrollView::AlwaysOff ); 225 vb->addWidget(abList);
224 connect( abList, SIGNAL( empty( bool ) ), 226 // abList->setHScrollBarMode( QScrollView::AlwaysOff );
225 this, SLOT( listIsEmpty( bool ) ) ); 227 connect( abList, SIGNAL( empty( bool ) ), this, SLOT( listIsEmpty( bool ) ) );
226 connect( abList, SIGNAL( details() ), 228 connect( abList, SIGNAL( details() ), this, SLOT( slotListView() ) );
227 this, SLOT( slotListView() ) ); 229 connect( abList, SIGNAL(currentChanged(int,int)), this, SLOT(slotUpdateToolbar()) );
228 connect( abList, SIGNAL(currentChanged(int,int)), 230
229 this, SLOT(slotUpdateToolbar()) ); 231 mView = 0;
230 232
231 mView = 0; 233 abList->load( addressbookXMLFilename() );
232 234 if ( QFile::exists(addressbookOldXMLFilename()) ) {
233 abList->load( addressbookXMLFilename() ); 235 abList->load( addressbookOldXMLFilename() );
234 if ( QFile::exists(addressbookOldXMLFilename()) ) { 236 QFile::remove(addressbookOldXMLFilename());
235 abList->load( addressbookOldXMLFilename() ); 237 }
236 QFile::remove(addressbookOldXMLFilename()); 238
237 } 239 pLabel = new LetterPicker( listContainer );
238 240 connect(pLabel, SIGNAL(letterClicked(char)), this, SLOT(slotSetLetter(char)));
239 pLabel = new LetterPicker( listContainer ); 241 vb->addWidget(pLabel);
240 connect(pLabel, SIGNAL(letterClicked(char)), this, SLOT(slotSetLetter(char))); 242 catMenu = new QPopupMenu( this );
241 vb->addWidget(pLabel); 243 catMenu->setCheckable( TRUE );
242 catMenu = new QPopupMenu( this ); 244 connect( catMenu, SIGNAL(activated(int)), this, SLOT(slotSetCategory(int)) );
243 catMenu->setCheckable( TRUE ); 245 populateCategories();
244 connect( catMenu, SIGNAL(activated(int)), this, SLOT(slotSetCategory(int)) ); 246
245 populateCategories(); 247 mbList->insertItem( tr("View"), catMenu );
246 248 // setCentralWidget( listContainer );
247 mbList->insertItem( tr("View"), catMenu ); 249
248 setCentralWidget( listContainer ); 250 fontMenu = new QPopupMenu(this);
249 251 fontMenu->setCheckable( true );
250 fontMenu = new QPopupMenu(this); 252 connect( fontMenu, SIGNAL(activated(int)), this, SLOT(slotSetFont(int)));
251 fontMenu->setCheckable( true ); 253
252 connect( fontMenu, SIGNAL(activated(int)), this, SLOT(slotSetFont(int))); 254 fontMenu->insertItem(tr( "Small" ), 0);
253 255 fontMenu->insertItem(tr( "Normal" ), 1);
254 fontMenu->insertItem(tr( "Small" ), 0); 256 fontMenu->insertItem(tr( "Large" ), 2);
255 fontMenu->insertItem(tr( "Normal" ), 1); 257
256 fontMenu->insertItem(tr( "Large" ), 2); 258 defaultFont = new QFont( abList->font() );
257 259
258 defaultFont = new QFont( abList->font() ); 260 slotSetFont(startFontSize);
259 261
260 slotSetFont(startFontSize); 262 mbList->insertItem( tr("Font"), fontMenu);
261 263 setCentralWidget(listContainer);
262 mbList->insertItem( tr("Font"), fontMenu); 264
263 setCentralWidget(listContainer); 265 // qDebug("adressbook contrsuction: t=%d", t.elapsed() );
264 266
265 // qDebug("adressbook contrsuction: t=%d", t.elapsed() ); 267 abList->setCurrentCell( 0, 0 );
268
269 isLoading = false;
266} 270}
267 271
268 272
269void AddressbookWindow::slotSetFont( int size ) { 273void AddressbookWindow::slotSetFont( int size ) {
270 274
271 if (size > 2 || size < 0) 275 if (size > 2 || size < 0)
272 size = 1; 276 size = 1;
273 277
274 startFontSize = size; 278 startFontSize = size;
275 279
276 QFont *currentFont; 280 QFont *currentFont;
277 281
278 switch (size) { 282 switch (size) {
279 case 0: 283 case 0:
280 fontMenu->setItemChecked(0, true); 284 fontMenu->setItemChecked(0, true);
281 fontMenu->setItemChecked(1, false); 285 fontMenu->setItemChecked(1, false);
282 fontMenu->setItemChecked(2, false); 286 fontMenu->setItemChecked(2, false);
283 abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) ); 287 abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) );
284 currentFont = new QFont (abList->font()); 288 currentFont = new QFont (abList->font());
285 abList->resizeRows(currentFont->pixelSize() + 7); 289 // abList->resizeRows(currentFont->pixelSize() + 7);
286 break; 290 abList->resizeRows();
287 case 1: 291 break;
288 fontMenu->setItemChecked(0, false); 292 case 1:
289 fontMenu->setItemChecked(1, true); 293 fontMenu->setItemChecked(0, false);
290 fontMenu->setItemChecked(2, false); 294 fontMenu->setItemChecked(1, true);
291 abList->setFont( *defaultFont ); 295 fontMenu->setItemChecked(2, false);
292 currentFont = new QFont (abList->font()); 296 abList->setFont( *defaultFont );
293 abList->resizeRows(currentFont->pixelSize() + 7); 297 currentFont = new QFont (abList->font());
294 break; 298 // abList->resizeRows(currentFont->pixelSize() + 7);
295 case 2: 299 abList->resizeRows();
296 fontMenu->setItemChecked(0, false); 300 break;
297 fontMenu->setItemChecked(1, false); 301 case 2:
298 fontMenu->setItemChecked(2, true); 302 fontMenu->setItemChecked(0, false);
299 abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() + 2 ) ); 303 fontMenu->setItemChecked(1, false);
300 currentFont = new QFont (abList->font()); 304 fontMenu->setItemChecked(2, true);
301 abList->resizeRows(currentFont->pixelSize() + 7); 305 abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() + 2 ) );
302 break; 306 currentFont = new QFont (abList->font());
303 } 307 //abList->resizeRows(currentFont->pixelSize() + 7);
308 abList->resizeRows();
309 break;
310 }
304} 311}
305 312
306 313
307 314
308void AddressbookWindow::importvCard() { 315void AddressbookWindow::importvCard() {
309 QString str = OFileDialog::getOpenFileName( 1,"/");//,"", "*", this ); 316 QString str = OFileDialog::getOpenFileName( 1,"/");//,"", "*", this );
310 if(!str.isEmpty() ) 317 if(!str.isEmpty() )
311 setDocument((const QString&) str ); 318 setDocument((const QString&) str );
312 319
313} 320}
314 321
315void AddressbookWindow::setDocument( const QString &filename ) 322void AddressbookWindow::setDocument( const QString &filename )
316{ 323{
317 if ( filename.find(".vcf") != int(filename.length()) - 4 ) return; 324 if ( filename.find(".vcf") != int(filename.length()) - 4 )
318 325 return;
319 QValueList<Contact> cl = Contact::readVCard( filename ); 326
320 for( QValueList<Contact>::Iterator it = cl.begin(); it != cl.end(); ++it ) { 327 QValueList<OContact> cl = OContact::readVCard( filename );
321// QString msg = tr("You received a vCard for\n%1.\nDo You want to add it to your\naddressbook?") 328 for( QValueList<OContact>::Iterator it = cl.begin(); it != cl.end(); ++it ) {
322// .arg( (*it).fullName() ); 329 // QString msg = tr("You received a vCard for\n%1.\nDo You want to add it to your\naddressbook?")
323// if ( QMessageBox::information( this, tr("received contact"), msg, QMessageBox::Ok, QMessageBox::Cancel ) == 330 // .arg( (*it).fullName() );
324// QMessageBox::Ok ) { 331 // if ( QMessageBox::information( this, tr("received contact"), msg, QMessageBox::Ok, QMessageBox::Cancel ) ==
325 abList->addEntry( *it ); 332 // QMessageBox::Ok ) {
326// } 333 abList->addEntry( *it );
327 } 334 // }
328 335 }
336
329} 337}
330 338
331void AddressbookWindow::resizeEvent( QResizeEvent *e ) 339void AddressbookWindow::resizeEvent( QResizeEvent *e )
332{ 340{
333 QMainWindow::resizeEvent( e ); 341 QMainWindow::resizeEvent( e );
334 342
335 if ( centralWidget() == listContainer ) 343 if ( centralWidget() == listContainer )
336 showList(); 344 showList();
337 else if ( centralWidget() == mView ) 345 else if ( centralWidget() == mView )
338 showView(); 346 showView();
339} 347}
340 348
341AddressbookWindow::~AddressbookWindow() 349AddressbookWindow::~AddressbookWindow()
342{ 350{
343 Config cfg("AddressBook"); 351 Config cfg("AddressBook");
344 cfg.setGroup("Font"); 352 cfg.setGroup("Font");
345 cfg.writeEntry("fontSize", startFontSize); 353 cfg.writeEntry("fontSize", startFontSize);
346} 354}
347 355
348void AddressbookWindow::slotUpdateToolbar() 356void AddressbookWindow::slotUpdateToolbar()
349{ 357{
350 Contact ce = abList->currentEntry(); 358 OContact ce = abList->currentEntry();
351 actionMail->setEnabled( !ce.defaultEmail().isEmpty() ); 359 actionMail->setEnabled( !ce.defaultEmail().isEmpty() );
352} 360}
353 361
354void AddressbookWindow::showList() 362void AddressbookWindow::showList()
355{ 363{
356 if ( mView ) mView->hide(); 364 bool visiblemView;
357 setCentralWidget( listContainer ); 365
358 listContainer->show(); 366 visiblemView = false;
359 // update our focues... (or use a stack widget!); 367 if ( mView ) {
360 abList->setFocus(); 368 mView->hide();
369 visiblemView = true;
370 }
371 setCentralWidget( listContainer );
372 listContainer->show();
373 // update our focues... (or use a stack widget!);
374 abList->setFocus();
375
376 // This makes sure we are scrolled all the way to the left
377 abList->setContentsPos( 0, abList->contentsY() );
378
379 //if ( visiblemView && abList->showBook() == "Cards" )
380 //abList->setShowCategory( abList->showBook(), abList->showCategory() );
381
361} 382}
362 383
363void AddressbookWindow::showView() 384void AddressbookWindow::showView()
364{ 385{
365 if ( abList->numRows() > 0 ) { 386 if ( abList->numRows() > 0 ) {
366 listContainer->hide(); 387 listContainer->hide();
367 setCentralWidget( abView() ); 388 setCentralWidget( abView() );
368 mView->show(); 389 mView->show();
369 mView->setFocus(); 390 mView->setFocus();
370 } 391 }
371} 392}
372 393
373void AddressbookWindow::slotListNew() 394void AddressbookWindow::slotListNew()
374{ 395{
375 Contact cnt; 396 OContact cnt;
376 if( !syncing ) { 397 if( !syncing ) {
377 if ( abEditor ) 398 if ( abEditor )
378 abEditor->setEntry( cnt ); 399 abEditor->setEntry( cnt );
379 abView()->init( cnt ); 400 abView()->init( cnt );
380 editEntry( NewEntry ); 401 editEntry( NewEntry );
381 } else { 402 } else {
382 QMessageBox::warning(this, tr("Contacts"), 403 QMessageBox::warning(this, tr("OContacts"),
383 tr("Can not edit data, currently syncing")); 404 tr("Can not edit data, currently syncing"));
384 } 405 }
385} 406}
386 407
387void AddressbookWindow::slotListView() 408void AddressbookWindow::slotListView()
388{ 409{
389 abView()->init( abList->currentEntry() ); 410 abView()->init( abList->currentEntry() );
390 mView->sync(); 411 mView->sync();
391 showView(); 412 showView();
392} 413}
393 414
394void AddressbookWindow::slotListDelete() 415void AddressbookWindow::slotListDelete()
395{ 416{
396 if(!syncing) { 417 if(!syncing) {
397 Contact tmpEntry = abList->currentEntry(); 418 OContact tmpEntry = abList->currentEntry();
398 419
399 // get a name, do the best we can... 420 // get a name, do the best we can...
400 QString strName = tmpEntry.fullName(); 421 QString strName = tmpEntry.fullName();
401 if ( strName.isEmpty() ) { 422 if ( strName.isEmpty() ) {
402 strName = tmpEntry.company(); 423 strName = tmpEntry.company();
403 if ( strName.isEmpty() ) 424 if ( strName.isEmpty() )
404 strName = "No Name"; 425 strName = "No Name";
405 } 426 }
406 427
407 428
408 if ( QPEMessageBox::confirmDelete( this, tr( "Contacts" ), 429 if ( QPEMessageBox::confirmDelete( this, tr( "Contacts" ),
409 strName ) ) { 430 strName ) ) {
410 abList->deleteCurrentEntry(); 431 abList->deleteCurrentEntry();
411 showList(); 432 showList();
412 } 433 }
413 } else { 434 } else {
414 QMessageBox::warning( this, tr("Contacts"), 435 QMessageBox::warning( this, tr("Contacts"),
415 tr("Can not edit data, currently syncing") ); 436 tr("Can not edit data, currently syncing") );
416 } 437 }
417} 438}
418 439
419void AddressbookWindow::slotViewBack() 440void AddressbookWindow::slotViewBack()
420{ 441{
421 showList(); 442 showList();
422} 443}
423 444
424void AddressbookWindow::slotViewEdit() 445void AddressbookWindow::slotViewEdit()
425{ 446{
426 if(!syncing) { 447 if(!syncing) {
427 if (actionPersonal->isOn()) { 448 if (actionPersonal->isOn()) {
428 editPersonal(); 449 editPersonal();
429 } else { 450 } else {
430 if ( !bAbEditFirstTime ) 451 if ( !bAbEditFirstTime )
431 abEditor->setEntry( abList->currentEntry() ); 452 abEditor->setEntry( abList->currentEntry() );
432 editEntry( EditEntry ); 453 editEntry( EditEntry );
433 } 454 }
434 } else { 455 } else {
435 QMessageBox::warning( this, tr("Contacts"), 456 QMessageBox::warning( this, tr("Contacts"),
436 tr("Can not edit data, currently syncing") ); 457 tr("Can not edit data, currently syncing") );
437 } 458 }
438} 459}
439 460
440 461
441 462
442void AddressbookWindow::writeMail() 463void AddressbookWindow::writeMail()
443{ 464{
444 Contact c = abList->currentEntry(); 465 OContact c = abList->currentEntry();
445 QString name = c.fileAs(); 466 QString name = c.fileAs();
446 QString email = c.defaultEmail(); 467 QString email = c.defaultEmail();
447 QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)"); 468 QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)");
448 e << name << email; 469 e << name << email;
449} 470}
450 471
451
452
453
454static const char * beamfile = "/tmp/obex/contact.vcf"; 472static const char * beamfile = "/tmp/obex/contact.vcf";
455 473
456void AddressbookWindow::slotBeam() 474void AddressbookWindow::slotBeam()
457{ 475{
458 QString filename; 476 QString filename;
459 Contact c; 477 OContact c;
460 if ( actionPersonal->isOn() ) { 478 if ( actionPersonal->isOn() ) {
461 filename = addressbookPersonalVCardName(); 479 filename = addressbookPersonalVCardName();
462 if (!QFile::exists(filename)) 480 if (!QFile::exists(filename))
463 return; // can't beam a non-existent file 481 return; // can't beam a non-existent file
464 c = Contact::readVCard( filename )[0]; 482 c = OContact::readVCard( filename )[0];
465 } else { 483 } else {
466 unlink( beamfile ); // delete if exists 484 unlink( beamfile ); // delete if exists
467 c = abList->currentEntry(); 485 c = abList->currentEntry();
468 mkdir("/tmp/obex/", 0755); 486 mkdir("/tmp/obex/", 0755);
469 Contact::writeVCard( beamfile, c ); 487 OContact::writeVCard( beamfile, c );
470 filename = beamfile; 488 filename = beamfile;
471 } 489 }
472 Ir *ir = new Ir( this ); 490 Ir *ir = new Ir( this );
473 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 491 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
474 QString description = c.fullName(); 492 QString description = c.fullName();
475 ir->send( filename, description, "text/x-vCard" ); 493 ir->send( filename, description, "text/x-vCard" );
476} 494}
477 495
478void AddressbookWindow::beamDone( Ir *ir ) 496void AddressbookWindow::beamDone( Ir *ir )
479{ 497{
480 delete ir; 498 delete ir;
481 unlink( beamfile ); 499 unlink( beamfile );
482} 500}
483 501
484 502
485static void parseName( const QString& name, QString *first, QString *middle, 503static void parseName( const QString& name, QString *first, QString *middle,
486 QString * last ) 504 QString * last )
487{ 505{
488 506
489 int comma = name.find ( "," ); 507 int comma = name.find ( "," );
490 QString rest; 508 QString rest;
491 if ( comma > 0 ) { 509 if ( comma > 0 ) {
492 *last = name.left( comma ); 510 *last = name.left( comma );
493 comma++; 511 comma++;
494 while ( comma < int(name.length()) && name[comma] == ' ' ) 512 while ( comma < int(name.length()) && name[comma] == ' ' )
495 comma++; 513 comma++;
496 rest = name.mid( comma ); 514 rest = name.mid( comma );
497 } else { 515 } else {
498 int space = name.findRev( ' ' ); 516 int space = name.findRev( ' ' );
499 *last = name.mid( space+1 ); 517 *last = name.mid( space+1 );
500 rest = name.left( space ); 518 rest = name.left( space );
501 } 519 }
502 int space = rest.find( ' ' ); 520 int space = rest.find( ' ' );
503 if ( space <= 0 ) { 521 if ( space <= 0 ) {
504 *first = rest; 522 *first = rest;
505 } else { 523 } else {
506 *first = rest.left( space ); 524 *first = rest.left( space );
507 *middle = rest.mid( space+1 ); 525 *middle = rest.mid( space+1 );
508 } 526 }
509 527
510} 528}
511 529
512 530
513void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data) 531void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data)
514{ 532{
515 if (msg == "editPersonal()") { 533 if (msg == "editPersonal()") {
516 editPersonal(); 534 editPersonal();
517 } else if (msg == "editPersonalAndClose()") { 535 } else if (msg == "editPersonalAndClose()") {
518 editPersonal(); 536 editPersonal();
519 close(); 537 close();
520 } else if ( msg == "addContact(QString,QString)" ) { 538 } else if ( msg == "addContact(QString,QString)" ) {
521 QDataStream stream(data,IO_ReadOnly); 539 QDataStream stream(data,IO_ReadOnly);
522 QString name, email; 540 QString name, email;
523 stream >> name >> email; 541 stream >> name >> email;
524 542
525 Contact cnt; 543 OContact cnt;
526 QString fn, mn, ln; 544 QString fn, mn, ln;
527 parseName( name, &fn, &mn, &ln ); 545 parseName( name, &fn, &mn, &ln );
528 // qDebug( " %s - %s - %s", fn.latin1(), mn.latin1(), ln.latin1() ); 546 // qDebug( " %s - %s - %s", fn.latin1(), mn.latin1(), ln.latin1() );
529 cnt.setFirstName( fn ); 547 cnt.setFirstName( fn );
530 cnt.setMiddleName( mn ); 548 cnt.setMiddleName( mn );
531 cnt.setLastName( ln ); 549 cnt.setLastName( ln );
532 cnt.insertEmails( email ); 550 cnt.insertEmails( email );
533 cnt.setDefaultEmail( email ); 551 cnt.setDefaultEmail( email );
534 cnt.setFileAs(); 552 cnt.setFileAs();
535 553
536 if ( bAbEditFirstTime ) { 554 if ( bAbEditFirstTime ) {
537 abEditor = new ContactEditor( cnt, &orderedFields, &slOrderedFields, 555 abEditor = new ContactEditor( cnt, &orderedFields, &slOrderedFields,
538 this, "editor" ); 556 this, "editor" );
539 bAbEditFirstTime = FALSE; 557 bAbEditFirstTime = FALSE;
540 } else { 558 } else {
541 abEditor->setEntry( cnt ); 559 abEditor->setEntry( cnt );
542 } 560 }
543 abView()->init( cnt ); 561 abView()->init( cnt );
544 editEntry( NewEntry ); 562 editEntry( NewEntry );
545 563
546 564
547 565
548 } 566 }
549#if 0 567#if 0
550 else if (msg == "pickAddresses(QCString,QCString,QStringList,...)" ) { 568 else if (msg == "pickAddresses(QCString,QCString,QStringList,...)" ) {
551 QDataStream stream(data,IO_ReadOnly); 569 QDataStream stream(data,IO_ReadOnly);
552 QCString ch,m; 570 QCString ch,m;
553 QStringList types; 571 QStringList types;
554 stream >> ch >> m >> types; 572 stream >> ch >> m >> types;
555 AddressPicker picker(abList,this,0,TRUE); 573 AddressPicker picker(abList,this,0,TRUE);
556 picker.showMaximized(); 574 picker.showMaximized();
557 picker.setChoiceNames(types); 575 picker.setChoiceNames(types);
558 int i=0; 576 int i=0;
559 for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) { 577 for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) {
560 QStringList sel; 578 QStringList sel;
561 stream >> sel; 579 stream >> sel;
562 picker.setSelection(i++,sel); 580 picker.setSelection(i++,sel);
563 } 581 }
564 picker.showMaximized(); 582 picker.showMaximized();
565 picker.exec(); 583 picker.exec();
566 584
567 // ###### note: contacts may have been added - save here! 585 // ###### note: contacts may have been added - save here!
568 586
569 setCentralWidget(abList); 587 setCentralWidget(abList);
570 QCopEnvelope e(ch,m); 588 QCopEnvelope e(ch,m);
571 i=0; 589 i=0;
572 for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) { 590 for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) {
573 QStringList sel = picker.selection(i++); 591 QStringList sel = picker.selection(i++);
574 e << sel; 592 e << sel;
575 } 593 }
576 } 594 }
577#endif 595#endif
578 596
579} 597}
580 598
581void AddressbookWindow::editPersonal() 599void AddressbookWindow::editPersonal()
582{ 600{
583 QString filename = addressbookPersonalVCardName(); 601 QString filename = addressbookPersonalVCardName();
584 Contact me; 602 OContact me;
585 if (QFile::exists(filename)) 603 if (QFile::exists(filename))
586 me = Contact::readVCard( filename )[0]; 604 me = OContact::readVCard( filename )[0];
587 if (bAbEditFirstTime) { 605 if (bAbEditFirstTime) {
588 abEditor = new ContactEditor( me, &orderedFields, &slOrderedFields, 606 abEditor = new ContactEditor( me, &orderedFields, &slOrderedFields,
589 this, "editor" ); 607 this, "editor" );
590 // don't create a new editor every time 608 // don't create a new editor every time
591 bAbEditFirstTime = FALSE; 609 bAbEditFirstTime = FALSE;
592 } else 610 } else
593 abEditor->setEntry( me ); 611 abEditor->setEntry( me );
594 612
595 abEditor->setCaption(tr("Edit My Personal Details")); 613 abEditor->setCaption(tr("Edit My Personal Details"));
596 abEditor->showMaximized(); 614 abEditor->showMaximized();
597 615
598 // fix the foxus... 616 // fix the foxus...
599 abEditor->setNameFocus(); 617 abEditor->setNameFocus();
600 if ( abEditor->exec() ) { 618 if ( abEditor->exec() ) {
601 setFocus(); 619 setFocus();
602 Contact new_personal = abEditor->entry(); 620 OContact new_personal = abEditor->entry();
603 QString fname = addressbookPersonalVCardName(); 621 QString fname = addressbookPersonalVCardName();
604 Contact::writeVCard( fname, new_personal ); 622 OContact::writeVCard( fname, new_personal );
605 abView()->init(new_personal); 623 abView()->init(new_personal);
606 abView()->sync(); 624 abView()->sync();
607 } 625 }
608 abEditor->setCaption( tr("Edit Address") ); 626 abEditor->setCaption( tr("Edit Address") );
609} 627}
610 628
611void AddressbookWindow::slotPersonalView() 629void AddressbookWindow::slotPersonalView()
612{ 630{
613 if (!actionPersonal->isOn()) { 631 if (!actionPersonal->isOn()) {
614 // we just turned it off 632 // we just turned it off
615 setCaption( tr("Contacts") ); 633 setCaption( tr("Contacts") );
616 actionNew->setEnabled(TRUE); 634 actionNew->setEnabled(TRUE);
617 actionTrash->setEnabled(TRUE); 635 actionTrash->setEnabled(TRUE);
618#ifndef MAKE_FOR_SHARP_ROM 636#ifndef MAKE_FOR_SHARP_ROM
619 actionFind->setEnabled(TRUE); 637 actionFind->setEnabled(TRUE);
620#endif 638#endif
621 slotUpdateToolbar(); // maybe some of the above could be moved there 639 slotUpdateToolbar(); // maybe some of the above could be moved there
622 showList(); 640 showList();
623 return; 641 return;
624 } 642 }
625 643
626 // XXX need to disable some QActions. 644 // XXX need to disable some QActions.
627 actionNew->setEnabled(FALSE); 645 actionNew->setEnabled(FALSE);
628 actionTrash->setEnabled(FALSE); 646 actionTrash->setEnabled(FALSE);
629#ifndef MAKE_FOR_SHARP_ROM 647#ifndef MAKE_FOR_SHARP_ROM
630 actionFind->setEnabled(FALSE); 648 actionFind->setEnabled(FALSE);
631#endif 649#endif
632 actionMail->setEnabled(FALSE); 650 actionMail->setEnabled(FALSE);
633 651
634 setCaption( tr("Contacts - My Personal Details") ); 652 setCaption( tr("Contacts - My Personal Details") );
635 QString filename = addressbookPersonalVCardName(); 653 QString filename = addressbookPersonalVCardName();
636 Contact me; 654 OContact me;
637 if (QFile::exists(filename)) 655 if (QFile::exists(filename))
638 me = Contact::readVCard( filename )[0]; 656 me = OContact::readVCard( filename )[0];
639 657
640 abView()->init( me ); 658 abView()->init( me );
641 abView()->sync(); 659 abView()->sync();
642 listContainer->hide(); 660 listContainer->hide();
643 setCentralWidget( abView() ); 661 setCentralWidget( abView() );
644 mView->show(); 662 mView->show();
645 mView->setFocus(); 663 mView->setFocus();
646} 664}
647 665
648void AddressbookWindow::editEntry( EntryMode entryMode ) 666void AddressbookWindow::editEntry( EntryMode entryMode )
649{ 667{
650 Contact entry; 668 OContact entry;
651 if ( bAbEditFirstTime ) { 669 if ( bAbEditFirstTime ) {
652 abEditor = new ContactEditor( entry, &orderedFields, &slOrderedFields, 670 abEditor = new ContactEditor( entry, &orderedFields, &slOrderedFields,
653 this, "editor" ); 671 this, "editor" );
654 bAbEditFirstTime = FALSE; 672 bAbEditFirstTime = FALSE;
655 if ( entryMode == EditEntry ) 673 if ( entryMode == EditEntry )
656 abEditor->setEntry( abList->currentEntry() ); 674 abEditor->setEntry( abList->currentEntry() );
657 } 675 }
658 // other things may chane the caption. 676 // other things may chane the caption.
659 abEditor->setCaption( tr("Edit Address") ); 677 abEditor->setCaption( tr("Edit Address") );
660 678
661#if defined(Q_WS_QWS) || defined(_WS_QWS_) 679#if defined(Q_WS_QWS) || defined(_WS_QWS_)
662 abEditor->showMaximized(); 680 abEditor->showMaximized();
663#endif 681#endif
664 // fix the foxus... 682 // fix the foxus...
665 abEditor->setNameFocus(); 683 abEditor->setNameFocus();
666 if ( abEditor->exec() ) { 684 if ( abEditor->exec() ) {
667 setFocus(); 685 setFocus();
668 if ( entryMode == NewEntry ) { 686 if ( entryMode == NewEntry ) {
669 Contact insertEntry = abEditor->entry(); 687 OContact insertEntry = abEditor->entry();
670 insertEntry.assignUid(); 688 insertEntry.assignUid();
671 abList->addEntry( insertEntry ); 689 abList->addEntry( insertEntry );
672 } else { 690 } else {
673 Contact replaceEntry = abEditor->entry(); 691 OContact replaceEntry = abEditor->entry();
674 if ( !replaceEntry.isValidUid() ) 692 if ( !replaceEntry.isValidUid() )
675 replaceEntry.assignUid(); 693 replaceEntry.assignUid();
676 abList->replaceCurrentEntry( replaceEntry ); 694 abList->replaceCurrentEntry( replaceEntry );
677 } 695 }
678 } 696 }
679 populateCategories(); 697 populateCategories();
680 showList(); 698 showList();
681} 699}
682 700
683void AddressbookWindow::listIsEmpty( bool empty ) 701void AddressbookWindow::listIsEmpty( bool empty )
684{ 702{
685 if ( !empty ) { 703 if ( !empty ) {
686 deleteButton->setEnabled( TRUE ); 704 deleteButton->setEnabled( TRUE );
687 } 705 }
688} 706}
689 707
690void AddressbookWindow::reload() 708void AddressbookWindow::reload()
691{ 709{
692 syncing = FALSE; 710 syncing = FALSE;
693 abList->clear(); 711 abList->clear();
694 abList->load( addressbookXMLFilename() ); 712 abList->load( addressbookXMLFilename() );
695} 713}
696 714
697void AddressbookWindow::flush() 715void AddressbookWindow::flush()
698{ 716{
699 syncing = TRUE; 717 syncing = TRUE;
700 abList->save( addressbookXMLFilename() ); 718 abList->save( addressbookXMLFilename() );
701} 719}
702 720
703 721
704void AddressbookWindow::closeEvent( QCloseEvent *e ) 722void AddressbookWindow::closeEvent( QCloseEvent *e )
705{ 723{
706 if ( centralWidget() == mView ) { 724 if ( centralWidget() == mView ) {
707 if (actionPersonal->isOn()) { 725 if (actionPersonal->isOn()) {
708 // pretend we clicked it off 726 // pretend we clicked it off
709 actionPersonal->setOn(FALSE); 727 actionPersonal->setOn(FALSE);
710 slotPersonalView(); 728 slotPersonalView();
711 } else { 729 } else {
712 showList(); 730 showList();
713 } 731 }
714 e->ignore(); 732 e->ignore();
715 return; 733 return;
716 } 734 }
717 735
718 if(syncing) { 736 if(syncing) {
719 /* shouldn't we save, I hear you say? well its already been set 737 /* shouldn't we save, I hear you say? well its already been set
720 so that an edit can not occur during a sync, and we flushed 738 so that an edit can not occur during a sync, and we flushed
721 at the start of the sync, so there is no need to save 739 at the start of the sync, so there is no need to save
722 Saving however itself would cause problems. */ 740 Saving however itself would cause problems. */
723 e->accept(); 741 e->accept();
724 return; 742 return;
725 } 743 }
726//################## shouldn't always save 744 //################## shouldn't always save
727 if ( save() ) 745 // True, but the database handles this automatically ! (se)
728 e->accept(); 746 if ( save() )
729 else 747 e->accept();
730 e->ignore(); 748 else
749 e->ignore();
731} 750}
732 751
733/* 752/*
734 Returns TRUE if it is OK to exit 753 Returns TRUE if it is OK to exit
735 */ 754*/
736 755
737bool AddressbookWindow::save() 756bool AddressbookWindow::save()
738{ 757{
739 QString str = addressbookXMLFilename(); 758 QString str = addressbookXMLFilename();
740 if ( str.isNull() ) { 759 if ( str.isNull() ) {
741 if ( QMessageBox::critical( 0, tr("Out of space"), 760 if ( QMessageBox::critical( 0, tr("Out of space"),
742 tr("Unable to save information.\n" 761 tr("Unable to save information.\n"
743 "Free up some space\n" 762 "Free up some space\n"
744 "and try again.\n" 763 "and try again.\n"
745 "\nQuit anyway?"), 764 "\nQuit anyway?"),
746 QMessageBox::Yes|QMessageBox::Escape, 765 QMessageBox::Yes|QMessageBox::Escape,
747 QMessageBox::No|QMessageBox::Default ) 766 QMessageBox::No|QMessageBox::Default )
748 != QMessageBox::No ) 767 != QMessageBox::No )
749 return TRUE; 768 return TRUE;
750 else 769 else
751 return FALSE; 770 return FALSE;
752 } else { 771 } else {
753 if ( !abList->save( str ) ) { 772 if ( !abList->save( str ) ) {
754 if ( QMessageBox::critical( 0, tr( "Out of space" ), 773 if ( QMessageBox::critical( 0, tr( "Out of space" ),
755 tr("Unable to save information.\n" 774 tr("Unable to save information.\n"
756 "Free up some space\n" 775 "Free up some space\n"
757 "and try again.\n" 776 "and try again.\n"
758 "\nQuit anyway?"), 777 "\nQuit anyway?"),
759 QMessageBox::Yes|QMessageBox::Escape, 778 QMessageBox::Yes|QMessageBox::Escape,
760 QMessageBox::No|QMessageBox::Default ) 779 QMessageBox::No|QMessageBox::Default )
761 != QMessageBox::No ) 780 != QMessageBox::No )
762 return TRUE; 781 return TRUE;
763 else 782 else
764 return FALSE; 783 return FALSE;
765 } 784 }
766 } 785 }
767 return TRUE; 786 return TRUE;
768} 787}
769 788
770void AddressbookWindow::slotSettings() 789void AddressbookWindow::slotSettings()
771{ 790{
772 AddressSettings frmSettings( this ); 791 AddressSettings frmSettings( this );
773#if defined(Q_WS_QWS) || defined(_WS_QWS_) 792#if defined(Q_WS_QWS) || defined(_WS_QWS_)
774 frmSettings.showMaximized(); 793 frmSettings.showMaximized();
775#endif 794#endif
776 795
777 if ( frmSettings.exec() ) { 796 if ( frmSettings.exec() ) {
778 allFields.clear(); 797 allFields.clear();
779 orderedFields.clear(); 798 orderedFields.clear();
780 slOrderedFields.clear(); 799 slOrderedFields.clear();
781 initFields(); 800 initFields();
782 if ( abEditor ) 801 if ( abEditor )
783 abEditor->loadFields(); 802 abEditor->loadFields();
784 abList->refresh(); 803 abList->refresh();
785 } 804 }
786} 805}
787 806
788 807
789void AddressbookWindow::initFields() 808void AddressbookWindow::initFields()
790{ 809{
791 // we really don't need the things from the configuration, anymore 810 // we really don't need the things from the configuration, anymore
792 // only thing that is important are the important categories. So, 811 // only thing that is important are the important categories. So,
793 // Call the contact functions that correspond to these old functions... 812 // Call the contact functions that correspond to these old functions...
794 813
795 QStringList xmlFields = Contact::fields(); 814 QStringList xmlFields = OContact::fields();
796 QStringList visibleFields = Contact::trfields(); 815 QStringList visibleFields = OContact::trfields();
797 xmlFields.remove( "Title" ); 816 xmlFields.remove( "Title" );
798 visibleFields.remove( tr("Name Title") ); 817 visibleFields.remove( tr("Name Title") );
799 visibleFields.remove( tr("Notes") ); 818 visibleFields.remove( tr("Notes") );
800 819
801 int i, 820 int i, version;
802 version; 821 Config cfg( "AddressBook" );
803 Config cfg( "AddressBook" ); 822 QString zn;
804 QString zn; 823
805 824 // ### Write a function to keep this from happening again...
806 // ### Write a function to keep this from happening again... 825 QStringList::ConstIterator it;
807 QStringList::ConstIterator it; 826 for ( i = 0, it = xmlFields.begin(); it != xmlFields.end(); ++it, i++ ) {
808 for ( i = 0, it = xmlFields.begin(); it != xmlFields.end(); ++it, i++ ) { 827 allFields.append( i + 3 );
809 allFields.append( i + 3 ); 828 }
810 } 829
811 830 cfg.setGroup( "Version" );
812 cfg.setGroup( "Version" ); 831 version = cfg.readNumEntry( "version" );
813 version = cfg.readNumEntry( "version" ); 832 i = 0;
814 i = 0; 833 startFontSize = 1;
815 startFontSize = 1; 834
816 835 if ( version >= ADDRESSVERSION ) {
817 if ( version >= ADDRESSVERSION ) { 836
818 837 cfg.setGroup( "ImportantCategory" );
819 cfg.setGroup( "ImportantCategory" ); 838
820 839 zn = cfg.readEntry( "Category" + QString::number(i), QString::null );
821 zn = cfg.readEntry( "Category" + QString::number(i), QString::null ); 840 while ( !zn.isNull() ) {
822 while ( !zn.isNull() ) { 841 if ( zn.contains( tr("Work") ) || zn.contains( tr("Mb") ) ) {
823 if ( zn.contains( tr("Work") ) || zn.contains( tr("Mb") ) ) { 842 slOrderedFields.clear();
824 slOrderedFields.clear(); 843 break;
825 break; 844 }
826 } 845 slOrderedFields.append( zn );
827 slOrderedFields.append( zn ); 846 zn = cfg.readEntry( "Category" + QString::number(++i), QString::null );
828 zn = cfg.readEntry( "Category" + QString::number(++i), QString::null ); 847 }
829 } 848 cfg.setGroup( "Font" );
830 cfg.setGroup( "Font" ); 849 startFontSize = cfg.readNumEntry( "fontSize", 1 );
831 startFontSize = cfg.readNumEntry( "fontSize", 1 ); 850
832 851
833 852 } else {
834 } else { 853 QString str;
835 QString str; 854 str = getenv("HOME");
836 str = getenv("HOME"); 855 str += "/Settings/AddressBook.conf";
837 str += "/Settings/AddressBook.conf"; 856 QFile::remove( str );
838 QFile::remove( str ); 857 }
839 } 858 if ( slOrderedFields.count() > 0 ) {
840 if ( slOrderedFields.count() > 0 ) { 859 for( QStringList::ConstIterator it = slOrderedFields.begin();
841 for( QStringList::ConstIterator it = slOrderedFields.begin(); 860 it != slOrderedFields.end(); ++it ) {
842 it != slOrderedFields.end(); ++it ) { 861 QValueList<int>::ConstIterator itVl;
843 QValueList<int>::ConstIterator itVl; 862 QStringList::ConstIterator itVis;
844 QStringList::ConstIterator itVis; 863 itVl = allFields.begin();
845 itVl = allFields.begin(); 864 for ( itVis = visibleFields.begin();
846 for ( itVis = visibleFields.begin(); 865 itVis != visibleFields.end() && itVl != allFields.end();
847 itVis != visibleFields.end() && itVl != allFields.end(); 866 ++itVis, ++itVl ) {
848 ++itVis, ++itVl ) { 867 if ( *it == *itVis && itVl != allFields.end() ) {
849 if ( *it == *itVis && itVl != allFields.end() ) { 868 orderedFields.append( *itVl );
850 orderedFields.append( *itVl ); 869 }
851 } 870 }
852 } 871 }
853 } 872 } else {
854 } else { 873 QValueList<int>::ConstIterator it;
855 QValueList<int>::ConstIterator it; 874 for ( it = allFields.begin(); it != allFields.end(); ++it )
856 for ( it = allFields.begin(); it != allFields.end(); ++it ) 875 orderedFields.append( *it );
857 orderedFields.append( *it ); 876
858 877 slOrderedFields = visibleFields;
859 slOrderedFields = visibleFields; 878 orderedFields.remove( Qtopia::AddressUid );
860 orderedFields.remove( Qtopia::AddressUid ); 879 orderedFields.remove( Qtopia::Title );
861 orderedFields.remove( Qtopia::Title ); 880 orderedFields.remove( Qtopia::Groups );
862 orderedFields.remove( Qtopia::Groups ); 881 orderedFields.remove( Qtopia::AddressCategory );
863 orderedFields.remove( Qtopia::AddressCategory ); 882 orderedFields.remove( Qtopia::FirstName );
864 orderedFields.remove( Qtopia::FirstName ); 883 orderedFields.remove( Qtopia::LastName );
865 orderedFields.remove( Qtopia::LastName ); 884 orderedFields.remove( Qtopia::DefaultEmail );
866 orderedFields.remove( Qtopia::DefaultEmail ); 885 orderedFields.remove( Qtopia::FileAs );
867 orderedFields.remove( Qtopia::FileAs ); 886 orderedFields.remove( Qtopia::Notes );
868 orderedFields.remove( Qtopia::Notes ); 887 orderedFields.remove( Qtopia::Gender );
869 orderedFields.remove( Qtopia::Gender ); 888 slOrderedFields.remove( tr("Name Title") );
870 slOrderedFields.remove( tr("Name Title") ); 889 slOrderedFields.remove( tr("First Name") );
871 slOrderedFields.remove( tr("First Name") ); 890 slOrderedFields.remove( tr("Last Name") );
872 slOrderedFields.remove( tr("Last Name") ); 891 slOrderedFields.remove( tr("File As") );
873 slOrderedFields.remove( tr("File As") ); 892 slOrderedFields.remove( tr("Default Email") );
874 slOrderedFields.remove( tr("Default Email") ); 893 slOrderedFields.remove( tr("Notes") );
875 slOrderedFields.remove( tr("Notes") ); 894 slOrderedFields.remove( tr("Gender") );
876 slOrderedFields.remove( tr("Gender") ); 895
877 896 }
878 }
879} 897}
880 898
881 899
882AbLabel *AddressbookWindow::abView() 900AbLabel *AddressbookWindow::abView()
883{ 901{
884 if ( !mView ) { 902 if ( !mView ) {
885 mView = new AbLabel( this, "viewer" ); 903 mView = new AbLabel( this, "viewer" );
886 mView->init( Contact() ); 904 mView->init( OContact() );
887 connect( mView, SIGNAL( okPressed() ), this, SLOT( slotListView() ) ); 905 connect( mView, SIGNAL( okPressed() ), this, SLOT( slotListView() ) );
888 } 906 }
889 return mView; 907 return mView;
890} 908}
891 909
892void AddressbookWindow::slotFind() 910void AddressbookWindow::slotFind()
893{ 911{
894#ifndef MAKE_FOR_SHARP_ROM 912#ifndef MAKE_FOR_SHARP_ROM
895 if ( centralWidget() == abView() ) 913 if ( centralWidget() == abView() )
896 showList(); 914 showList();
897 915
898 FindDialog frmFind( "Contacts", this ); 916 FindDialog frmFind( "Contacts", this );
899 QObject::connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), abList, SLOT(slotDoFind( const QString&,bool,bool,int))); 917 QObject::connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), abList, SLOT(slotDoFind( const QString&,bool,bool,int)));
900 QObject::connect( abList, SIGNAL(signalNotFound()), &frmFind, SLOT(slotNotFound()) ); 918 QObject::connect( abList, SIGNAL(signalNotFound()), &frmFind, SLOT(slotNotFound()) );
901 QObject::connect( abList, SIGNAL(signalWrapAround()), &frmFind, SLOT(slotWrapAround()) ); 919 QObject::connect( abList, SIGNAL(signalWrapAround()), &frmFind, SLOT(slotWrapAround()) );
902 920
903 frmFind.exec(); 921 frmFind.exec();
904 922
905 if ( abList->numSelections() ) 923 if ( abList->numSelections() )
906 abList->clearSelection(); 924 abList->clearSelection();
907 925
908 abList->clearFindRow(); 926 abList->clearFindRow();
909#endif 927#endif
910} 928}
911 929
912void AddressbookWindow::slotSetCategory( int c ) 930void AddressbookWindow::slotSetCategory( int c )
913{ 931{
914 if ( c <= 0 ) 932
915 return; 933 QString cat, book;
916 for ( unsigned int i = 1; i < catMenu->count(); i++ ) 934
917 catMenu->setItemChecked( i, c == (int)i ); 935 if ( c <= 0 )
918 if ( c == 1 ) { 936 return;
919 abList->setShowCategory( QString::null ); 937
920 setCaption( tr("Contacts") + " - " + tr ( "All" ) ); 938 // Checkmark Book Menu Item Selected
921 } else if ( c == (int)catMenu->count() ) { 939 if ( c < 6 )
922 abList->setShowCategory( tr( "Unfiled" ) ); 940 for ( unsigned int i = 1; i < 6; i++ )
923 setCaption( tr("Contacts") + " - " + tr( "Unfiled" ) ); 941 catMenu->setItemChecked( i, c == (int)i );
924 } else { 942
925 QString cat = abList->categories()[c - 2]; 943 // Checkmark Category Menu Item Selected
926 abList->setShowCategory( cat ); 944 else
927 setCaption( tr("Contacts") + " - " + cat ); 945 for ( unsigned int i = 6; i < catMenu->count(); i++ )
928 } 946 catMenu->setItemChecked( i, c == (int)i );
947
948 for ( unsigned int i = 1; i < catMenu->count(); i++ ) {
949 if (catMenu->isItemChecked( i )) {
950 if ( i == 1 ) // default List view
951 book = QString::null;
952 else if ( i == 2 )
953 book = "Phone";
954 else if ( i == 3 )
955 book = "Company";
956 else if ( i == 4 )
957 book = "Email";
958 else if ( i == 5 )
959 book = "Cards";
960 else if ( i == 6 ) // default All Categories
961 cat = QString::null;
962 else if ( i == (unsigned int)catMenu->count() ) // last menu option will be Unfiled
963 cat = "Unfiled";
964 else
965 cat = abList->categories()[i - 7];
966 }
967 }
968
969 abList->setShowCategory( book, cat );
970
971 if ( book.isEmpty() )
972 book = "List";
973 if ( cat.isEmpty() )
974 cat = "All";
975
976 setCaption( tr( "Contacts" ) + " - " + tr( book ) + " - " + tr( cat ) );
929} 977}
930 978
931void AddressbookWindow::slotSetLetter( char c ) { 979void AddressbookWindow::slotSetLetter( char c ) {
932 980
933 abList->setShowByLetter( c ); 981 abList->setShowByLetter( c );
934 982
935} 983}
936 984
937void AddressbookWindow::populateCategories() 985void AddressbookWindow::populateCategories()
938{ 986{
939 catMenu->clear(); 987 catMenu->clear();
940 988
941 int id, 989 int id, rememberId;
942 rememberId; 990 id = 1;
943 id = 1; 991 rememberId = 0;
944 rememberId = 0; 992
945 catMenu->insertItem( tr( "All" ), id++ ); 993 catMenu->insertItem( tr( "List" ), id++ );
946 QStringList categories = abList->categories(); 994 catMenu->insertItem( tr( "Phone Book" ), id++ );
947 categories.append( tr( "Unfiled" ) ); 995 catMenu->insertItem( tr( "Company Book" ), id++ );
948 for ( QStringList::Iterator it = categories.begin(); 996 catMenu->insertItem( tr( "Email Book" ), id++ );
949 it != categories.end(); ++it ) { 997 catMenu->insertItem( tr( "Cards" ), id++ );
950 catMenu->insertItem( *it, id ); 998 catMenu->insertSeparator();
951 if ( *it == abList->showCategory() ) 999
952 rememberId = id; 1000 catMenu->insertItem( tr( "All" ), id++ );
953 ++id; 1001 QStringList categories = abList->categories();
954 } 1002 categories.append( tr( "Unfiled" ) );
955 if ( abList->showCategory().isEmpty() ) 1003 for ( QStringList::Iterator it = categories.begin();
956 slotSetCategory( 1 ); 1004 it != categories.end(); ++it ) {
957 else 1005 catMenu->insertItem( *it, id );
958 slotSetCategory( rememberId ); 1006 if ( *it == abList->showCategory() )
1007 rememberId = id;
1008 ++id;
1009 }
1010
1011 if ( abList->showBook().isEmpty() ) {
1012 catMenu->setItemChecked( 1, true );
1013 } else if ( abList->showBook() == "Phone" ) {
1014 catMenu->setItemChecked( 2, true );
1015 } else if ( abList->showBook() == "Company" ) {
1016 catMenu->setItemChecked( 3, true );
1017 } else if ( abList->showBook() == "Email" ) {
1018 catMenu->setItemChecked( 4, true );
1019 } else if ( abList->showBook() == "Cards" ) {
1020 catMenu->setItemChecked( 5, true );
1021 }
1022
1023 if ( abList->showCategory().isEmpty() ) {
1024 slotSetCategory( 6 );
1025 }
1026 else {
1027 slotSetCategory( rememberId );
1028 }
959} 1029}
1030