summaryrefslogtreecommitdiff
path: root/core/pim/addressbook/addressbook.cpp
Unidiff
Diffstat (limited to 'core/pim/addressbook/addressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/addressbook/addressbook.cpp829
1 files changed, 829 insertions, 0 deletions
diff --git a/core/pim/addressbook/addressbook.cpp b/core/pim/addressbook/addressbook.cpp
new file mode 100644
index 0000000..b694e4f
--- a/dev/null
+++ b/core/pim/addressbook/addressbook.cpp
@@ -0,0 +1,829 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "abeditor.h"
22#include "ablabel.h"
23#include "abtable.h"
24#include "addresssettings.h"
25#include "addressbook.h"
26
27#include <qpe/qpeapplication.h>
28#include <qpe/config.h>
29#include <qpe/contact.h>
30#include <qpe/finddialog.h>
31#include <qpe/global.h>
32#include <qpe/resource.h>
33#include <qpe/ir.h>
34#include <qpe/qpemessagebox.h>
35#include <qpe/qcopenvelope_qws.h>
36
37#include <qaction.h>
38#include <qdialog.h>
39#include <qdir.h>
40#include <qfile.h>
41#include <qimage.h>
42#include <qlayout.h>
43#include <qpe/qpemenubar.h>
44#include <qmessagebox.h>
45#include <qpixmap.h>
46#include <qpopupmenu.h>
47#include <qpe/qpetoolbar.h>
48#include <qstringlist.h>
49#include <qtoolbutton.h>
50#include <qwhatsthis.h>
51
52#include <stdlib.h>
53#include <sys/stat.h>
54#include <sys/types.h>
55#include <fcntl.h>
56#include <unistd.h>
57
58#include <qdatetime.h>
59
60static QString addressbookOldXMLFilename()
61{
62 QString filename = QPEApplication::documentDir() + "addressbook.xml";
63 return filename;
64}
65
66static QString addressbookXMLFilename()
67{
68 QString filename = Global::applicationFileName("addressbook",
69 "addressbook.xml");
70 return filename;
71}
72
73static QString addressbookPersonalVCardName()
74{
75 QString filename = Global::applicationFileName("addressbook",
76 "businesscard.vcf");
77 return filename;
78}
79
80
81AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name,
82 WFlags f )
83 : QMainWindow( parent, name, f ),
84 abEditor(0),
85 bAbEditFirstTime(TRUE),
86 syncing(FALSE)
87{
88 initFields();
89
90 setCaption( tr("Contacts") );
91 setIcon( Resource::loadPixmap( "AddressBook" ) );
92
93 setToolBarsMovable( FALSE );
94
95 // Create Toolbars
96
97 QPEToolBar *bar = new QPEToolBar( this );
98 bar->setHorizontalStretchable( TRUE );
99
100 QPEMenuBar *mbList = new QPEMenuBar( bar );
101 mbList->setMargin( 0 );
102
103 QPopupMenu *edit = new QPopupMenu( this );
104 mbList->insertItem( tr( "Contact" ), edit );
105
106 listTools = new QPEToolBar( this, "list operations" );
107
108
109 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null,
110 0, this, 0 );
111 actionNew = a;
112 connect( a, SIGNAL( activated() ), this, SLOT( slotListNew() ) );
113 a->addTo( edit );
114 a->addTo( listTools );
115
116 a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null,
117 0, this, 0 );
118 actionEdit = a;
119 connect( a, SIGNAL( activated() ), this, SLOT( slotViewEdit() ) );
120 a->addTo( edit );
121 a->addTo( listTools );
122
123 a = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null,
124 0, this, 0 );
125 actionTrash = a;
126 connect( a, SIGNAL( activated() ), this, SLOT( slotListDelete() ) );
127 a->addTo( edit );
128 a->addTo( listTools );
129
130 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ),
131 QString::null, 0, this, 0 );
132 actionFind = a;
133 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) );
134 a->addTo( edit );
135 a->addTo( listTools );
136
137
138 a = new QAction( tr( "Write Mail To" ), Resource::loadPixmap( "qtmail/reply" ),
139 QString::null, 0, this, 0 );
140 a->setEnabled( FALSE );
141 actionMail = a;
142 connect( a, SIGNAL( activated() ), this, SLOT( writeMail() ) );
143 a->addTo( edit );
144 a->addTo( listTools );
145
146
147
148 if ( Ir::supported() ) {
149 a = new QAction( tr ("Beam Entry" ), Resource::loadPixmap( "beam" ), QString::null,
150 0, this, 0 );
151 actionBeam = a;
152 connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) );
153 a->addTo( edit );
154 a->addTo( listTools );
155 }
156
157 edit->insertSeparator();
158
159 a = new QAction( tr("My Personal Details"), QString::null, 0, 0, 0, TRUE );
160 actionPersonal = a;
161 connect( a, SIGNAL( activated() ), this, SLOT( slotPersonalView() ) );
162 a->addTo( edit );
163
164
165 a = new QAction( tr( "Arrange Edit Fields"), QString::null, 0, 0 );
166 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) );
167 a->addTo( edit );
168
169 // Create Views
170
171 // This is safe to call without checking to see if it exists...
172 // not to mention it also does the necessary stuff for the
173 // journaling...
174 QString str = addressbookXMLFilename();
175 if ( str.isNull() ) {
176 QMessageBox::warning( this, tr("Out of Space"),
177 tr("There is not enough space to create\n"
178 "neccessary startup files.\n"
179 "\nFree up some space before\nentering data!")
180 );
181 }
182
183 abList = new AbTable( &orderedFields, this, "table" );
184 abList->setHScrollBarMode( QScrollView::AlwaysOff );
185 connect( abList, SIGNAL( empty( bool ) ),
186 this, SLOT( listIsEmpty( bool ) ) );
187 connect( abList, SIGNAL( details() ),
188 this, SLOT( slotListView() ) );
189 connect( abList, SIGNAL(currentChanged(int,int)),
190 this, SLOT(slotUpdateToolbar()) );
191
192 mView = 0;
193
194 abList->load( addressbookXMLFilename() );
195 if ( QFile::exists(addressbookOldXMLFilename()) ) {
196 abList->load( addressbookOldXMLFilename() );
197 QFile::remove(addressbookOldXMLFilename());
198 }
199
200 catMenu = new QPopupMenu( this );
201 catMenu->setCheckable( TRUE );
202 connect( catMenu, SIGNAL(activated(int)), this, SLOT(slotSetCategory(int)) );
203 populateCategories();
204
205 mbList->insertItem( tr("View"), catMenu );
206 setCentralWidget( abList );
207
208 // qDebug("adressbook contrsuction: t=%d", t.elapsed() );
209}
210
211void AddressbookWindow::setDocument( const QString &filename )
212{
213 if ( filename.find(".vcf") != int(filename.length()) - 4 ) return;
214
215 QValueList<Contact> cl = Contact::readVCard( filename );
216 for( QValueList<Contact>::Iterator it = cl.begin(); it != cl.end(); ++it ) {
217 // QString msg = tr("You received a vCard for\n%1.\nDo You want to add it to your\naddressbook?")
218 // .arg( (*it).fullName() );
219 // if ( QMessageBox::information( this, tr("received contact"), msg, QMessageBox::Ok, QMessageBox::Cancel ) ==
220 // QMessageBox::Ok ) {
221 abList->addEntry( *it );
222 // }
223 }
224
225}
226
227void AddressbookWindow::resizeEvent( QResizeEvent *e )
228{
229 QMainWindow::resizeEvent( e );
230
231 if ( centralWidget() == abList )
232 showList();
233 else if ( centralWidget() == mView )
234 showView();
235}
236
237AddressbookWindow::~AddressbookWindow()
238{
239}
240
241void AddressbookWindow::slotUpdateToolbar()
242{
243 Contact ce = abList->currentEntry();
244 actionMail->setEnabled( !ce.defaultEmail().isEmpty() );
245}
246
247void AddressbookWindow::showList()
248{
249 if ( mView ) mView->hide();
250 setCentralWidget( abList );
251 abList->show();
252 // update our focues... (or use a stack widget!);
253 abList->setFocus();
254}
255
256void AddressbookWindow::showView()
257{
258 if ( abList->numRows() > 0 ) {
259 abList->hide();
260 setCentralWidget( abView() );
261 mView->show();
262 mView->setFocus();
263 }
264}
265
266void AddressbookWindow::slotListNew()
267{
268 Contact cnt;
269 if( !syncing ) {
270 if ( abEditor )
271 abEditor->setEntry( cnt );
272 abView()->init( cnt );
273 editEntry( NewEntry );
274 } else {
275 QMessageBox::warning(this, tr("Contacts"),
276 tr("Can not edit data, currently syncing"));
277 }
278}
279
280void AddressbookWindow::slotListView()
281{
282 abView()->init( abList->currentEntry() );
283 mView->sync();
284 showView();
285}
286
287void AddressbookWindow::slotListDelete()
288{
289 if(!syncing) {
290 Contact tmpEntry = abList->currentEntry();
291
292 // get a name, do the best we can...
293 QString strName = tmpEntry.fullName();
294 if ( strName.isEmpty() ) {
295 strName = tmpEntry.company();
296 if ( strName.isEmpty() )
297 strName = "No Name";
298 }
299
300
301 if ( QPEMessageBox::confirmDelete( this, tr( "Contacts" ),
302 strName ) ) {
303 abList->deleteCurrentEntry();
304 showList();
305 }
306 } else {
307 QMessageBox::warning( this, tr("Contacts"),
308 tr("Can not edit data, currently syncing") );
309 }
310}
311
312void AddressbookWindow::slotViewBack()
313{
314 showList();
315}
316
317void AddressbookWindow::slotViewEdit()
318{
319 if(!syncing) {
320 if (actionPersonal->isOn()) {
321 editPersonal();
322 } else {
323 if ( !bAbEditFirstTime )
324 abEditor->setEntry( abList->currentEntry() );
325 editEntry( EditEntry );
326 }
327 } else {
328 QMessageBox::warning( this, tr("Contacts"),
329 tr("Can not edit data, currently syncing") );
330 }
331}
332
333
334
335void AddressbookWindow::writeMail()
336{
337 Contact c = abList->currentEntry();
338 QString name = c.fileAs();
339 QString email = c.defaultEmail();
340 QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)");
341 e << name << email;
342}
343
344
345
346
347static const char * beamfile = "/tmp/obex/contact.vcf";
348
349void AddressbookWindow::slotBeam()
350{
351 QString filename;
352 Contact c;
353 if ( actionPersonal->isOn() ) {
354 filename = addressbookPersonalVCardName();
355 if (!QFile::exists(filename))
356 return; // can't beam a non-existent file
357 c = Contact::readVCard( filename )[0];
358 } else {
359 unlink( beamfile ); // delete if exists
360 c = abList->currentEntry();
361 mkdir("/tmp/obex/", 0755);
362 Contact::writeVCard( beamfile, c );
363 filename = beamfile;
364 }
365 Ir *ir = new Ir( this );
366 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
367 QString description = c.fullName();
368 ir->send( filename, description, "text/x-vCard" );
369}
370
371void AddressbookWindow::beamDone( Ir *ir )
372{
373 delete ir;
374 unlink( beamfile );
375}
376
377
378static void parseName( const QString& name, QString *first, QString *middle,
379 QString * last )
380{
381
382 int comma = name.find ( "," );
383 QString rest;
384 if ( comma > 0 ) {
385 *last = name.left( comma );
386 comma++;
387 while ( comma < int(name.length()) && name[comma] == ' ' )
388 comma++;
389 rest = name.mid( comma );
390 } else {
391 int space = name.findRev( ' ' );
392 *last = name.mid( space+1 );
393 rest = name.left( space );
394 }
395 int space = rest.find( ' ' );
396 if ( space <= 0 ) {
397 *first = rest;
398 } else {
399 *first = rest.left( space );
400 *middle = rest.mid( space+1 );
401 }
402
403}
404
405
406void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data)
407{
408 if (msg == "editPersonal()") {
409 editPersonal();
410 } else if (msg == "editPersonalAndClose()") {
411 editPersonal();
412 close();
413 } else if ( msg == "addContact(QString,QString)" ) {
414 QDataStream stream(data,IO_ReadOnly);
415 QString name, email;
416 stream >> name >> email;
417
418 Contact cnt;
419 QString fn, mn, ln;
420 parseName( name, &fn, &mn, &ln );
421 //qDebug( " %s - %s - %s", fn.latin1(), mn.latin1(), ln.latin1() );
422 cnt.setFirstName( fn );
423 cnt.setMiddleName( mn );
424 cnt.setLastName( ln );
425 cnt.setEmails( email );
426 cnt.setDefaultEmail( email );
427 cnt.setFileAs();
428
429 if ( bAbEditFirstTime ) {
430 abEditor = new AbEditor( cnt, &orderedFields, &slOrderedFields,
431 this, "editor" );
432 bAbEditFirstTime = FALSE;
433 } else {
434 abEditor->setEntry( cnt );
435 }
436 abView()->init( cnt );
437 editEntry( NewEntry );
438
439
440
441 }
442#if 0
443 else if (msg == "pickAddresses(QCString,QCString,QStringList,...)" ) {
444 QDataStream stream(data,IO_ReadOnly);
445 QCString ch,m;
446 QStringList types;
447 stream >> ch >> m >> types;
448 AddressPicker picker(abList,this,0,TRUE);
449 picker.showMaximized();
450 picker.setChoiceNames(types);
451 int i=0;
452 for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) {
453 QStringList sel;
454 stream >> sel;
455 picker.setSelection(i++,sel);
456 }
457 picker.showMaximized();
458 picker.exec();
459
460 // ###### note: contacts may have been added - save here!
461
462 setCentralWidget(abList);
463 QCopEnvelope e(ch,m);
464 i=0;
465 for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) {
466 QStringList sel = picker.selection(i++);
467 e << sel;
468 }
469 }
470#endif
471
472}
473
474void AddressbookWindow::editPersonal()
475{
476 QString filename = addressbookPersonalVCardName();
477 Contact me;
478 if (QFile::exists(filename))
479 me = Contact::readVCard( filename )[0];
480 if (bAbEditFirstTime) {
481 abEditor = new AbEditor( me, &orderedFields, &slOrderedFields,
482 this, "editor" );
483 // don't create a new editor every time
484 bAbEditFirstTime = FALSE;
485 } else
486 abEditor->setEntry( me );
487
488 abEditor->setCaption(tr("Edit My Personal Details"));
489 abEditor->showMaximized();
490
491 // fix the foxus...
492 abEditor->setNameFocus();
493 if ( abEditor->exec() ) {
494 setFocus();
495 Contact new_personal = abEditor->entry();
496 QString fname = addressbookPersonalVCardName();
497 Contact::writeVCard( fname, new_personal );
498 abView()->init(new_personal);
499 abView()->sync();
500 }
501 abEditor->setCaption( tr("Edit Address") );
502}
503
504void AddressbookWindow::slotPersonalView()
505{
506 if (!actionPersonal->isOn()) {
507 // we just turned it off
508 setCaption( tr("Contacts") );
509 actionNew->setEnabled(TRUE);
510 actionTrash->setEnabled(TRUE);
511 actionFind->setEnabled(TRUE);
512 slotUpdateToolbar(); // maybe some of the above could be moved there
513 showList();
514 return;
515 }
516
517 // XXX need to disable some QActions.
518 actionNew->setEnabled(FALSE);
519 actionTrash->setEnabled(FALSE);
520 actionFind->setEnabled(FALSE);
521 actionMail->setEnabled(FALSE);
522
523 setCaption( tr("Contacts - My Personal Details") );
524 QString filename = addressbookPersonalVCardName();
525 Contact me;
526 if (QFile::exists(filename))
527 me = Contact::readVCard( filename )[0];
528
529 abView()->init( me );
530 abView()->sync();
531 abList->hide();
532 setCentralWidget( abView() );
533 mView->show();
534 mView->setFocus();
535}
536
537void AddressbookWindow::editEntry( EntryMode entryMode )
538{
539 Contact entry;
540 if ( bAbEditFirstTime ) {
541 abEditor = new AbEditor( entry, &orderedFields, &slOrderedFields,
542 this, "editor" );
543 bAbEditFirstTime = FALSE;
544 if ( entryMode == EditEntry )
545 abEditor->setEntry( abList->currentEntry() );
546 }
547 // other things may chane the caption.
548 abEditor->setCaption( tr("Edit Address") );
549
550#if defined(Q_WS_QWS) || defined(_WS_QWS_)
551 abEditor->showMaximized();
552#endif
553 // fix the foxus...
554 abEditor->setNameFocus();
555 if ( abEditor->exec() ) {
556 setFocus();
557 if ( entryMode == NewEntry ) {
558 Contact insertEntry = abEditor->entry();
559 insertEntry.assignUid();
560 abList->addEntry( insertEntry );
561 } else {
562 Contact replaceEntry = abEditor->entry();
563 if ( !replaceEntry.isValidUid() )
564 replaceEntry.assignUid();
565 abList->replaceCurrentEntry( replaceEntry );
566 }
567 }
568 populateCategories();
569 showList();
570}
571
572void AddressbookWindow::listIsEmpty( bool empty )
573{
574 if ( !empty ) {
575 deleteButton->setEnabled( TRUE );
576 }
577}
578
579void AddressbookWindow::reload()
580{
581 syncing = FALSE;
582 abList->clear();
583 abList->load( addressbookXMLFilename() );
584}
585
586void AddressbookWindow::flush()
587{
588 syncing = TRUE;
589 abList->save( addressbookXMLFilename() );
590}
591
592
593void AddressbookWindow::closeEvent( QCloseEvent *e )
594{
595 if ( centralWidget() == mView ) {
596 if (actionPersonal->isOn()) {
597 // pretend we clicked it off
598 actionPersonal->setOn(FALSE);
599 slotPersonalView();
600 } else {
601 showList();
602 }
603 e->ignore();
604 return;
605 }
606
607 if(syncing) {
608 /* shouldn't we save, I hear you say? well its already been set
609 so that an edit can not occur during a sync, and we flushed
610 at the start of the sync, so there is no need to save
611 Saving however itself would cause problems. */
612 e->accept();
613 return;
614 }
615//################## shouldn't always save
616 if ( save() )
617 e->accept();
618 else
619 e->ignore();
620}
621
622/*
623 Returns TRUE if it is OK to exit
624 */
625
626bool AddressbookWindow::save()
627{
628 QString str = addressbookXMLFilename();
629 if ( str.isNull() ) {
630 if ( QMessageBox::critical( 0, tr("Out of space"),
631 tr("Unable to save information.\n"
632 "Free up some space\n"
633 "and try again.\n"
634 "\nQuit anyway?"),
635 QMessageBox::Yes|QMessageBox::Escape,
636 QMessageBox::No|QMessageBox::Default )
637 != QMessageBox::No )
638 return TRUE;
639 else
640 return FALSE;
641 } else {
642 if ( !abList->save( str ) ) {
643 if ( QMessageBox::critical( 0, tr( "Out of space" ),
644 tr("Unable to save information.\n"
645 "Free up some space\n"
646 "and try again.\n"
647 "\nQuit anyway?"),
648 QMessageBox::Yes|QMessageBox::Escape,
649 QMessageBox::No|QMessageBox::Default )
650 != QMessageBox::No )
651 return TRUE;
652 else
653 return FALSE;
654 }
655 }
656 return TRUE;
657}
658
659void AddressbookWindow::slotSettings()
660{
661 AddressSettings frmSettings( this );
662#if defined(Q_WS_QWS) || defined(_WS_QWS_)
663 frmSettings.showMaximized();
664#endif
665
666 if ( frmSettings.exec() ) {
667 allFields.clear();
668 orderedFields.clear();
669 slOrderedFields.clear();
670 initFields();
671 if ( abEditor )
672 abEditor->loadFields();
673 abList->refresh();
674 }
675}
676
677
678void AddressbookWindow::initFields()
679{
680 // we really don't need the things from the configuration, anymore
681 // only thing that is important are the important categories. So,
682 // Call the contact functions that correspond to these old functions...
683
684 QStringList xmlFields = Contact::fields();
685 QStringList visibleFields = Contact::trfields();
686 xmlFields.remove( "Title" );
687 visibleFields.remove( tr("Name Title") );
688 visibleFields.remove( tr("Notes") );
689
690 int i,
691 version;
692 Config cfg( "AddressBook" );
693 QString zn;
694
695 // ### Write a function to keep this from happening again...
696 QStringList::ConstIterator it;
697 for ( i = 0, it = xmlFields.begin(); it != xmlFields.end(); ++it, i++ ) {
698 allFields.append( i + 3 );
699 }
700
701 cfg.setGroup( "Version" );
702 version = cfg.readNumEntry( "version" );
703 i = 0;
704 if ( version >= ADDRESSVERSION ) {
705
706 cfg.setGroup( "ImportantCategory" );
707
708 zn = cfg.readEntry( "Category" + QString::number(i), QString::null );
709 while ( !zn.isNull() ) {
710 if ( zn.contains( tr("Work") ) || zn.contains( tr("Mb") ) ) {
711 slOrderedFields.clear();
712 break;
713 }
714 slOrderedFields.append( zn );
715 zn = cfg.readEntry( "Category" + QString::number(++i), QString::null );
716 }
717 } else {
718 QString str;
719 str = getenv("HOME");
720 str += "/Settings/AddressBook.conf";
721 QFile::remove( str );
722 }
723 if ( slOrderedFields.count() > 0 ) {
724 for( QStringList::ConstIterator it = slOrderedFields.begin();
725 it != slOrderedFields.end(); ++it ) {
726 QValueList<int>::ConstIterator itVl;
727 QStringList::ConstIterator itVis;
728 itVl = allFields.begin();
729 for ( itVis = visibleFields.begin();
730 itVis != visibleFields.end() && itVl != allFields.end();
731 ++itVis, ++itVl ) {
732 if ( *it == *itVis && itVl != allFields.end() ) {
733 orderedFields.append( *itVl );
734 }
735 }
736 }
737 } else {
738 QValueList<int>::ConstIterator it;
739 for ( it = allFields.begin(); it != allFields.end(); ++it )
740 orderedFields.append( *it );
741
742 slOrderedFields = visibleFields;
743 orderedFields.remove( Qtopia::AddressUid );
744 orderedFields.remove( Qtopia::Title );
745 orderedFields.remove( Qtopia::Groups );
746 orderedFields.remove( Qtopia::AddressCategory );
747 orderedFields.remove( Qtopia::FirstName );
748 orderedFields.remove( Qtopia::LastName );
749 orderedFields.remove( Qtopia::DefaultEmail );
750 orderedFields.remove( Qtopia::FileAs );
751 orderedFields.remove( Qtopia::Notes );
752 orderedFields.remove( Qtopia::Gender );
753 slOrderedFields.remove( tr("Name Title") );
754 slOrderedFields.remove( tr("First Name") );
755 slOrderedFields.remove( tr("Last Name") );
756 slOrderedFields.remove( tr("File As") );
757 slOrderedFields.remove( tr("Default Email") );
758 slOrderedFields.remove( tr("Notes") );
759 slOrderedFields.remove( tr("Gender") );
760
761 }
762}
763
764
765AbLabel *AddressbookWindow::abView()
766{
767 if ( !mView ) {
768 mView = new AbLabel( this, "viewer" );
769 mView->init( Contact() );
770 connect( mView, SIGNAL( okPressed() ), this, SLOT( slotListView() ) );
771 }
772 return mView;
773}
774
775void AddressbookWindow::slotFind()
776{
777 if ( centralWidget() == abView() )
778 showList();
779 FindDialog frmFind( "Contacts", this );
780 QObject::connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), abList, SLOT(slotDoFind( const QString&,bool,bool,int)));
781 QObject::connect( abList, SIGNAL(signalNotFound()), &frmFind, SLOT(slotNotFound()) );
782 QObject::connect( abList, SIGNAL(signalWrapAround()), &frmFind, SLOT(slotWrapAround()) );
783 frmFind.exec();
784 if ( abList->numSelections() )
785 abList->clearSelection();
786 abList->clearFindRow();
787}
788
789void AddressbookWindow::slotSetCategory( int c )
790{
791 if ( c <= 0 )
792 return;
793 for ( unsigned int i = 1; i < catMenu->count(); i++ )
794 catMenu->setItemChecked( i, c == (int)i );
795 if ( c == 1 ) {
796 abList->setShowCategory( QString::null );
797 setCaption( tr("Contacts") + " - " + tr ( "All" ) );
798 } else if ( c == (int)catMenu->count() ) {
799 abList->setShowCategory( tr( "Unfiled" ) );
800 setCaption( tr("Contacts") + " - " + tr( "Unfiled" ) );
801 } else {
802 QString cat = abList->categories()[c - 2];
803 abList->setShowCategory( cat );
804 setCaption( tr("Contacts") + " - " + cat );
805 }
806}
807
808void AddressbookWindow::populateCategories()
809{
810 catMenu->clear();
811
812 int id,
813 rememberId;
814 id = 1;
815 catMenu->insertItem( tr( "All" ), id++ );
816 QStringList categories = abList->categories();
817 categories.append( tr( "Unfiled" ) );
818 for ( QStringList::Iterator it = categories.begin();
819 it != categories.end(); ++it ) {
820 catMenu->insertItem( *it, id );
821 if ( *it == abList->showCategory() )
822 rememberId = id;
823 ++id;
824 }
825 if ( abList->showCategory().isEmpty() )
826 slotSetCategory( 1 );
827 else
828 slotSetCategory( rememberId );
829}