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