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