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