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