summaryrefslogtreecommitdiff
authorzecke <zecke>2002-03-03 01:12:20 (UTC)
committer zecke <zecke>2002-03-03 01:12:20 (UTC)
commit0e245156b28b70be5cd98a58a9256fe5e2739562 (patch) (unidiff)
treef24fb55bca70820d6d30444ec128d1afd8e32cd3
parent1b89006f83e7516e13f808742d118e209377abcc (diff)
downloadopie-0e245156b28b70be5cd98a58a9256fe5e2739562.zip
opie-0e245156b28b70be5cd98a58a9256fe5e2739562.tar.gz
opie-0e245156b28b70be5cd98a58a9256fe5e2739562.tar.bz2
*** empty log message ***
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/addressbook/addressbook.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/core/pim/addressbook/addressbook.cpp b/core/pim/addressbook/addressbook.cpp
index b694e4f..a2b8276 100644
--- a/core/pim/addressbook/addressbook.cpp
+++ b/core/pim/addressbook/addressbook.cpp
@@ -1,524 +1,526 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#define QTOPIA_INTERNAL_FD
22
21#include "abeditor.h" 23#include "abeditor.h"
22#include "ablabel.h" 24#include "ablabel.h"
23#include "abtable.h" 25#include "abtable.h"
24#include "addresssettings.h" 26#include "addresssettings.h"
25#include "addressbook.h" 27#include "addressbook.h"
26 28
27#include <qpe/qpeapplication.h> 29#include <qpe/qpeapplication.h>
28#include <qpe/config.h> 30#include <qpe/config.h>
29#include <qpe/contact.h> 31#include <qpe/contact.h>
30#include <qpe/finddialog.h> 32#include <qpe/finddialog.h>
31#include <qpe/global.h> 33#include <qpe/global.h>
32#include <qpe/resource.h> 34#include <qpe/resource.h>
33#include <qpe/ir.h> 35#include <qpe/ir.h>
34#include <qpe/qpemessagebox.h> 36#include <qpe/qpemessagebox.h>
35#include <qpe/qcopenvelope_qws.h> 37#include <qpe/qcopenvelope_qws.h>
36 38
37#include <qaction.h> 39#include <qaction.h>
38#include <qdialog.h> 40#include <qdialog.h>
39#include <qdir.h> 41#include <qdir.h>
40#include <qfile.h> 42#include <qfile.h>
41#include <qimage.h> 43#include <qimage.h>
42#include <qlayout.h> 44#include <qlayout.h>
43#include <qpe/qpemenubar.h> 45#include <qpe/qpemenubar.h>
44#include <qmessagebox.h> 46#include <qmessagebox.h>
45#include <qpixmap.h> 47#include <qpixmap.h>
46#include <qpopupmenu.h> 48#include <qpopupmenu.h>
47#include <qpe/qpetoolbar.h> 49#include <qpe/qpetoolbar.h>
48#include <qstringlist.h> 50#include <qstringlist.h>
49#include <qtoolbutton.h> 51#include <qtoolbutton.h>
50#include <qwhatsthis.h> 52#include <qwhatsthis.h>
51 53
52#include <stdlib.h> 54#include <stdlib.h>
53#include <sys/stat.h> 55#include <sys/stat.h>
54#include <sys/types.h> 56#include <sys/types.h>
55#include <fcntl.h> 57#include <fcntl.h>
56#include <unistd.h> 58#include <unistd.h>
57 59
58#include <qdatetime.h> 60#include <qdatetime.h>
59 61
60static QString addressbookOldXMLFilename() 62static QString addressbookOldXMLFilename()
61{ 63{
62 QString filename = QPEApplication::documentDir() + "addressbook.xml"; 64 QString filename = QPEApplication::documentDir() + "addressbook.xml";
63 return filename; 65 return filename;
64} 66}
65 67
66static QString addressbookXMLFilename() 68static QString addressbookXMLFilename()
67{ 69{
68 QString filename = Global::applicationFileName("addressbook", 70 QString filename = Global::applicationFileName("addressbook",
69 "addressbook.xml"); 71 "addressbook.xml");
70 return filename; 72 return filename;
71} 73}
72 74
73static QString addressbookPersonalVCardName() 75static QString addressbookPersonalVCardName()
74{ 76{
75 QString filename = Global::applicationFileName("addressbook", 77 QString filename = Global::applicationFileName("addressbook",
76 "businesscard.vcf"); 78 "businesscard.vcf");
77 return filename; 79 return filename;
78} 80}
79 81
80 82
81AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, 83AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name,
82 WFlags f ) 84 WFlags f )
83 : QMainWindow( parent, name, f ), 85 : QMainWindow( parent, name, f ),
84 abEditor(0), 86 abEditor(0),
85 bAbEditFirstTime(TRUE), 87 bAbEditFirstTime(TRUE),
86 syncing(FALSE) 88 syncing(FALSE)
87{ 89{
88 initFields(); 90 initFields();
89 91
90 setCaption( tr("Contacts") ); 92 setCaption( tr("Contacts") );
91 setIcon( Resource::loadPixmap( "AddressBook" ) ); 93 setIcon( Resource::loadPixmap( "AddressBook" ) );
92 94
93 setToolBarsMovable( FALSE ); 95 setToolBarsMovable( FALSE );
94 96
95 // Create Toolbars 97 // Create Toolbars
96 98
97 QPEToolBar *bar = new QPEToolBar( this ); 99 QPEToolBar *bar = new QPEToolBar( this );
98 bar->setHorizontalStretchable( TRUE ); 100 bar->setHorizontalStretchable( TRUE );
99 101
100 QPEMenuBar *mbList = new QPEMenuBar( bar ); 102 QPEMenuBar *mbList = new QPEMenuBar( bar );
101 mbList->setMargin( 0 ); 103 mbList->setMargin( 0 );
102 104
103 QPopupMenu *edit = new QPopupMenu( this ); 105 QPopupMenu *edit = new QPopupMenu( this );
104 mbList->insertItem( tr( "Contact" ), edit ); 106 mbList->insertItem( tr( "Contact" ), edit );
105 107
106 listTools = new QPEToolBar( this, "list operations" ); 108 listTools = new QPEToolBar( this, "list operations" );
107 109
108 110
109 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 111 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null,
110 0, this, 0 ); 112 0, this, 0 );
111 actionNew = a; 113 actionNew = a;
112 connect( a, SIGNAL( activated() ), this, SLOT( slotListNew() ) ); 114 connect( a, SIGNAL( activated() ), this, SLOT( slotListNew() ) );
113 a->addTo( edit ); 115 a->addTo( edit );
114 a->addTo( listTools ); 116 a->addTo( listTools );
115 117
116 a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null, 118 a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null,
117 0, this, 0 ); 119 0, this, 0 );
118 actionEdit = a; 120 actionEdit = a;
119 connect( a, SIGNAL( activated() ), this, SLOT( slotViewEdit() ) ); 121 connect( a, SIGNAL( activated() ), this, SLOT( slotViewEdit() ) );
120 a->addTo( edit ); 122 a->addTo( edit );
121 a->addTo( listTools ); 123 a->addTo( listTools );
122 124
123 a = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 125 a = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null,
124 0, this, 0 ); 126 0, this, 0 );
125 actionTrash = a; 127 actionTrash = a;
126 connect( a, SIGNAL( activated() ), this, SLOT( slotListDelete() ) ); 128 connect( a, SIGNAL( activated() ), this, SLOT( slotListDelete() ) );
127 a->addTo( edit ); 129 a->addTo( edit );
128 a->addTo( listTools ); 130 a->addTo( listTools );
129 131
130 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), 132 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ),
131 QString::null, 0, this, 0 ); 133 QString::null, 0, this, 0 );
132 actionFind = a; 134 actionFind = a;
133 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); 135 connect( a, SIGNAL(activated()), this, SLOT(slotFind()) );
134 a->addTo( edit ); 136 a->addTo( edit );
135 a->addTo( listTools ); 137 a->addTo( listTools );
136 138
137 139
138 a = new QAction( tr( "Write Mail To" ), Resource::loadPixmap( "qtmail/reply" ), 140 a = new QAction( tr( "Write Mail To" ), Resource::loadPixmap( "qtmail/reply" ),
139 QString::null, 0, this, 0 ); 141 QString::null, 0, this, 0 );
140 a->setEnabled( FALSE ); 142 //a->setEnabled( FALSE ); we got support for it now :) zecke
141 actionMail = a; 143 actionMail = a;
142 connect( a, SIGNAL( activated() ), this, SLOT( writeMail() ) ); 144 connect( a, SIGNAL( activated() ), this, SLOT( writeMail() ) );
143 a->addTo( edit ); 145 a->addTo( edit );
144 a->addTo( listTools ); 146 a->addTo( listTools );
145 147
146 148
147 149
148 if ( Ir::supported() ) { 150 if ( Ir::supported() ) {
149 a = new QAction( tr ("Beam Entry" ), Resource::loadPixmap( "beam" ), QString::null, 151 a = new QAction( tr ("Beam Entry" ), Resource::loadPixmap( "beam" ), QString::null,
150 0, this, 0 ); 152 0, this, 0 );
151 actionBeam = a; 153 actionBeam = a;
152 connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) ); 154 connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) );
153 a->addTo( edit ); 155 a->addTo( edit );
154 a->addTo( listTools ); 156 a->addTo( listTools );
155 } 157 }
156 158
157 edit->insertSeparator(); 159 edit->insertSeparator();
158 160
159 a = new QAction( tr("My Personal Details"), QString::null, 0, 0, 0, TRUE ); 161 a = new QAction( tr("My Personal Details"), QString::null, 0, 0, 0, TRUE );
160 actionPersonal = a; 162 actionPersonal = a;
161 connect( a, SIGNAL( activated() ), this, SLOT( slotPersonalView() ) ); 163 connect( a, SIGNAL( activated() ), this, SLOT( slotPersonalView() ) );
162 a->addTo( edit ); 164 a->addTo( edit );
163 165
164 166
165 a = new QAction( tr( "Arrange Edit Fields"), QString::null, 0, 0 ); 167 a = new QAction( tr( "Arrange Edit Fields"), QString::null, 0, 0 );
166 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); 168 connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) );
167 a->addTo( edit ); 169 a->addTo( edit );
168 170
169 // Create Views 171 // Create Views
170 172
171 // This is safe to call without checking to see if it exists... 173 // This is safe to call without checking to see if it exists...
172 // not to mention it also does the necessary stuff for the 174 // not to mention it also does the necessary stuff for the
173 // journaling... 175 // journaling...
174 QString str = addressbookXMLFilename(); 176 QString str = addressbookXMLFilename();
175 if ( str.isNull() ) { 177 if ( str.isNull() ) {
176 QMessageBox::warning( this, tr("Out of Space"), 178 QMessageBox::warning( this, tr("Out of Space"),
177 tr("There is not enough space to create\n" 179 tr("There is not enough space to create\n"
178 "neccessary startup files.\n" 180 "neccessary startup files.\n"
179 "\nFree up some space before\nentering data!") 181 "\nFree up some space before\nentering data!")
180 ); 182 );
181 } 183 }
182 184
183 abList = new AbTable( &orderedFields, this, "table" ); 185 abList = new AbTable( &orderedFields, this, "table" );
184 abList->setHScrollBarMode( QScrollView::AlwaysOff ); 186 abList->setHScrollBarMode( QScrollView::AlwaysOff );
185 connect( abList, SIGNAL( empty( bool ) ), 187 connect( abList, SIGNAL( empty( bool ) ),
186 this, SLOT( listIsEmpty( bool ) ) ); 188 this, SLOT( listIsEmpty( bool ) ) );
187 connect( abList, SIGNAL( details() ), 189 connect( abList, SIGNAL( details() ),
188 this, SLOT( slotListView() ) ); 190 this, SLOT( slotListView() ) );
189 connect( abList, SIGNAL(currentChanged(int,int)), 191 connect( abList, SIGNAL(currentChanged(int,int)),
190 this, SLOT(slotUpdateToolbar()) ); 192 this, SLOT(slotUpdateToolbar()) );
191 193
192 mView = 0; 194 mView = 0;
193 195
194 abList->load( addressbookXMLFilename() ); 196 abList->load( addressbookXMLFilename() );
195 if ( QFile::exists(addressbookOldXMLFilename()) ) { 197 if ( QFile::exists(addressbookOldXMLFilename()) ) {
196 abList->load( addressbookOldXMLFilename() ); 198 abList->load( addressbookOldXMLFilename() );
197 QFile::remove(addressbookOldXMLFilename()); 199 QFile::remove(addressbookOldXMLFilename());
198 } 200 }
199 201
200 catMenu = new QPopupMenu( this ); 202 catMenu = new QPopupMenu( this );
201 catMenu->setCheckable( TRUE ); 203 catMenu->setCheckable( TRUE );
202 connect( catMenu, SIGNAL(activated(int)), this, SLOT(slotSetCategory(int)) ); 204 connect( catMenu, SIGNAL(activated(int)), this, SLOT(slotSetCategory(int)) );
203 populateCategories(); 205 populateCategories();
204 206
205 mbList->insertItem( tr("View"), catMenu ); 207 mbList->insertItem( tr("View"), catMenu );
206 setCentralWidget( abList ); 208 setCentralWidget( abList );
207 209
208 // qDebug("adressbook contrsuction: t=%d", t.elapsed() ); 210 // qDebug("adressbook contrsuction: t=%d", t.elapsed() );
209} 211}
210 212
211void AddressbookWindow::setDocument( const QString &filename ) 213void AddressbookWindow::setDocument( const QString &filename )
212{ 214{
213 if ( filename.find(".vcf") != int(filename.length()) - 4 ) return; 215 if ( filename.find(".vcf") != int(filename.length()) - 4 ) return;
214 216
215 QValueList<Contact> cl = Contact::readVCard( filename ); 217 QValueList<Contact> cl = Contact::readVCard( filename );
216 for( QValueList<Contact>::Iterator it = cl.begin(); it != cl.end(); ++it ) { 218 for( QValueList<Contact>::Iterator it = cl.begin(); it != cl.end(); ++it ) {
217 // QString msg = tr("You received a vCard for\n%1.\nDo You want to add it to your\naddressbook?") 219 // QString msg = tr("You received a vCard for\n%1.\nDo You want to add it to your\naddressbook?")
218 // .arg( (*it).fullName() ); 220 // .arg( (*it).fullName() );
219 // if ( QMessageBox::information( this, tr("received contact"), msg, QMessageBox::Ok, QMessageBox::Cancel ) == 221 // if ( QMessageBox::information( this, tr("received contact"), msg, QMessageBox::Ok, QMessageBox::Cancel ) ==
220 // QMessageBox::Ok ) { 222 // QMessageBox::Ok ) {
221 abList->addEntry( *it ); 223 abList->addEntry( *it );
222 // } 224 // }
223 } 225 }
224 226
225} 227}
226 228
227void AddressbookWindow::resizeEvent( QResizeEvent *e ) 229void AddressbookWindow::resizeEvent( QResizeEvent *e )
228{ 230{
229 QMainWindow::resizeEvent( e ); 231 QMainWindow::resizeEvent( e );
230 232
231 if ( centralWidget() == abList ) 233 if ( centralWidget() == abList )
232 showList(); 234 showList();
233 else if ( centralWidget() == mView ) 235 else if ( centralWidget() == mView )
234 showView(); 236 showView();
235} 237}
236 238
237AddressbookWindow::~AddressbookWindow() 239AddressbookWindow::~AddressbookWindow()
238{ 240{
239} 241}
240 242
241void AddressbookWindow::slotUpdateToolbar() 243void AddressbookWindow::slotUpdateToolbar()
242{ 244{
243 Contact ce = abList->currentEntry(); 245 Contact ce = abList->currentEntry();
244 actionMail->setEnabled( !ce.defaultEmail().isEmpty() ); 246 actionMail->setEnabled( !ce.defaultEmail().isEmpty() );
245} 247}
246 248
247void AddressbookWindow::showList() 249void AddressbookWindow::showList()
248{ 250{
249 if ( mView ) mView->hide(); 251 if ( mView ) mView->hide();
250 setCentralWidget( abList ); 252 setCentralWidget( abList );
251 abList->show(); 253 abList->show();
252 // update our focues... (or use a stack widget!); 254 // update our focues... (or use a stack widget!);
253 abList->setFocus(); 255 abList->setFocus();
254} 256}
255 257
256void AddressbookWindow::showView() 258void AddressbookWindow::showView()
257{ 259{
258 if ( abList->numRows() > 0 ) { 260 if ( abList->numRows() > 0 ) {
259 abList->hide(); 261 abList->hide();
260 setCentralWidget( abView() ); 262 setCentralWidget( abView() );
261 mView->show(); 263 mView->show();
262 mView->setFocus(); 264 mView->setFocus();
263 } 265 }
264} 266}
265 267
266void AddressbookWindow::slotListNew() 268void AddressbookWindow::slotListNew()
267{ 269{
268 Contact cnt; 270 Contact cnt;
269 if( !syncing ) { 271 if( !syncing ) {
270 if ( abEditor ) 272 if ( abEditor )
271 abEditor->setEntry( cnt ); 273 abEditor->setEntry( cnt );
272 abView()->init( cnt ); 274 abView()->init( cnt );
273 editEntry( NewEntry ); 275 editEntry( NewEntry );
274 } else { 276 } else {
275 QMessageBox::warning(this, tr("Contacts"), 277 QMessageBox::warning(this, tr("Contacts"),
276 tr("Can not edit data, currently syncing")); 278 tr("Can not edit data, currently syncing"));
277 } 279 }
278} 280}
279 281
280void AddressbookWindow::slotListView() 282void AddressbookWindow::slotListView()
281{ 283{
282 abView()->init( abList->currentEntry() ); 284 abView()->init( abList->currentEntry() );
283 mView->sync(); 285 mView->sync();
284 showView(); 286 showView();
285} 287}
286 288
287void AddressbookWindow::slotListDelete() 289void AddressbookWindow::slotListDelete()
288{ 290{
289 if(!syncing) { 291 if(!syncing) {
290 Contact tmpEntry = abList->currentEntry(); 292 Contact tmpEntry = abList->currentEntry();
291 293
292 // get a name, do the best we can... 294 // get a name, do the best we can...
293 QString strName = tmpEntry.fullName(); 295 QString strName = tmpEntry.fullName();
294 if ( strName.isEmpty() ) { 296 if ( strName.isEmpty() ) {
295 strName = tmpEntry.company(); 297 strName = tmpEntry.company();
296 if ( strName.isEmpty() ) 298 if ( strName.isEmpty() )
297 strName = "No Name"; 299 strName = "No Name";
298 } 300 }
299 301
300 302
301 if ( QPEMessageBox::confirmDelete( this, tr( "Contacts" ), 303 if ( QPEMessageBox::confirmDelete( this, tr( "Contacts" ),
302 strName ) ) { 304 strName ) ) {
303 abList->deleteCurrentEntry(); 305 abList->deleteCurrentEntry();
304 showList(); 306 showList();
305 } 307 }
306 } else { 308 } else {
307 QMessageBox::warning( this, tr("Contacts"), 309 QMessageBox::warning( this, tr("Contacts"),
308 tr("Can not edit data, currently syncing") ); 310 tr("Can not edit data, currently syncing") );
309 } 311 }
310} 312}
311 313
312void AddressbookWindow::slotViewBack() 314void AddressbookWindow::slotViewBack()
313{ 315{
314 showList(); 316 showList();
315} 317}
316 318
317void AddressbookWindow::slotViewEdit() 319void AddressbookWindow::slotViewEdit()
318{ 320{
319 if(!syncing) { 321 if(!syncing) {
320 if (actionPersonal->isOn()) { 322 if (actionPersonal->isOn()) {
321 editPersonal(); 323 editPersonal();
322 } else { 324 } else {
323 if ( !bAbEditFirstTime ) 325 if ( !bAbEditFirstTime )
324 abEditor->setEntry( abList->currentEntry() ); 326 abEditor->setEntry( abList->currentEntry() );
325 editEntry( EditEntry ); 327 editEntry( EditEntry );
326 } 328 }
327 } else { 329 } else {
328 QMessageBox::warning( this, tr("Contacts"), 330 QMessageBox::warning( this, tr("Contacts"),
329 tr("Can not edit data, currently syncing") ); 331 tr("Can not edit data, currently syncing") );
330 } 332 }
331} 333}
332 334
333 335
334 336
335void AddressbookWindow::writeMail() 337void AddressbookWindow::writeMail()
336{ 338{
337 Contact c = abList->currentEntry(); 339 Contact c = abList->currentEntry();
338 QString name = c.fileAs(); 340 QString name = c.fileAs();
339 QString email = c.defaultEmail(); 341 QString email = c.defaultEmail();
340 QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)"); 342 QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)");
341 e << name << email; 343 e << name << email;
342} 344}
343 345
344 346
345 347
346 348
347static const char * beamfile = "/tmp/obex/contact.vcf"; 349static const char * beamfile = "/tmp/obex/contact.vcf";
348 350
349void AddressbookWindow::slotBeam() 351void AddressbookWindow::slotBeam()
350{ 352{
351 QString filename; 353 QString filename;
352 Contact c; 354 Contact c;
353 if ( actionPersonal->isOn() ) { 355 if ( actionPersonal->isOn() ) {
354 filename = addressbookPersonalVCardName(); 356 filename = addressbookPersonalVCardName();
355 if (!QFile::exists(filename)) 357 if (!QFile::exists(filename))
356 return; // can't beam a non-existent file 358 return; // can't beam a non-existent file
357 c = Contact::readVCard( filename )[0]; 359 c = Contact::readVCard( filename )[0];
358 } else { 360 } else {
359 unlink( beamfile ); // delete if exists 361 unlink( beamfile ); // delete if exists
360 c = abList->currentEntry(); 362 c = abList->currentEntry();
361 mkdir("/tmp/obex/", 0755); 363 mkdir("/tmp/obex/", 0755);
362 Contact::writeVCard( beamfile, c ); 364 Contact::writeVCard( beamfile, c );
363 filename = beamfile; 365 filename = beamfile;
364 } 366 }
365 Ir *ir = new Ir( this ); 367 Ir *ir = new Ir( this );
366 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 368 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
367 QString description = c.fullName(); 369 QString description = c.fullName();
368 ir->send( filename, description, "text/x-vCard" ); 370 ir->send( filename, description, "text/x-vCard" );
369} 371}
370 372
371void AddressbookWindow::beamDone( Ir *ir ) 373void AddressbookWindow::beamDone( Ir *ir )
372{ 374{
373 delete ir; 375 delete ir;
374 unlink( beamfile ); 376 unlink( beamfile );
375} 377}
376 378
377 379
378static void parseName( const QString& name, QString *first, QString *middle, 380static void parseName( const QString& name, QString *first, QString *middle,
379 QString * last ) 381 QString * last )
380{ 382{
381 383
382 int comma = name.find ( "," ); 384 int comma = name.find ( "," );
383 QString rest; 385 QString rest;
384 if ( comma > 0 ) { 386 if ( comma > 0 ) {
385 *last = name.left( comma ); 387 *last = name.left( comma );
386 comma++; 388 comma++;
387 while ( comma < int(name.length()) && name[comma] == ' ' ) 389 while ( comma < int(name.length()) && name[comma] == ' ' )
388 comma++; 390 comma++;
389 rest = name.mid( comma ); 391 rest = name.mid( comma );
390 } else { 392 } else {
391 int space = name.findRev( ' ' ); 393 int space = name.findRev( ' ' );
392 *last = name.mid( space+1 ); 394 *last = name.mid( space+1 );
393 rest = name.left( space ); 395 rest = name.left( space );
394 } 396 }
395 int space = rest.find( ' ' ); 397 int space = rest.find( ' ' );
396 if ( space <= 0 ) { 398 if ( space <= 0 ) {
397 *first = rest; 399 *first = rest;
398 } else { 400 } else {
399 *first = rest.left( space ); 401 *first = rest.left( space );
400 *middle = rest.mid( space+1 ); 402 *middle = rest.mid( space+1 );
401 } 403 }
402 404
403} 405}
404 406
405 407
406void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data) 408void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data)
407{ 409{
408 if (msg == "editPersonal()") { 410 if (msg == "editPersonal()") {
409 editPersonal(); 411 editPersonal();
410 } else if (msg == "editPersonalAndClose()") { 412 } else if (msg == "editPersonalAndClose()") {
411 editPersonal(); 413 editPersonal();
412 close(); 414 close();
413 } else if ( msg == "addContact(QString,QString)" ) { 415 } else if ( msg == "addContact(QString,QString)" ) {
414 QDataStream stream(data,IO_ReadOnly); 416 QDataStream stream(data,IO_ReadOnly);
415 QString name, email; 417 QString name, email;
416 stream >> name >> email; 418 stream >> name >> email;
417 419
418 Contact cnt; 420 Contact cnt;
419 QString fn, mn, ln; 421 QString fn, mn, ln;
420 parseName( name, &fn, &mn, &ln ); 422 parseName( name, &fn, &mn, &ln );
421 //qDebug( " %s - %s - %s", fn.latin1(), mn.latin1(), ln.latin1() ); 423 //qDebug( " %s - %s - %s", fn.latin1(), mn.latin1(), ln.latin1() );
422 cnt.setFirstName( fn ); 424 cnt.setFirstName( fn );
423 cnt.setMiddleName( mn ); 425 cnt.setMiddleName( mn );
424 cnt.setLastName( ln ); 426 cnt.setLastName( ln );
425 cnt.setEmails( email ); 427 cnt.setEmails( email );
426 cnt.setDefaultEmail( email ); 428 cnt.setDefaultEmail( email );
427 cnt.setFileAs(); 429 cnt.setFileAs();
428 430
429 if ( bAbEditFirstTime ) { 431 if ( bAbEditFirstTime ) {
430 abEditor = new AbEditor( cnt, &orderedFields, &slOrderedFields, 432 abEditor = new AbEditor( cnt, &orderedFields, &slOrderedFields,
431 this, "editor" ); 433 this, "editor" );
432 bAbEditFirstTime = FALSE; 434 bAbEditFirstTime = FALSE;
433 } else { 435 } else {
434 abEditor->setEntry( cnt ); 436 abEditor->setEntry( cnt );
435 } 437 }
436 abView()->init( cnt ); 438 abView()->init( cnt );
437 editEntry( NewEntry ); 439 editEntry( NewEntry );
438 440
439 441
440 442
441 } 443 }
442#if 0 444#if 0
443 else if (msg == "pickAddresses(QCString,QCString,QStringList,...)" ) { 445 else if (msg == "pickAddresses(QCString,QCString,QStringList,...)" ) {
444 QDataStream stream(data,IO_ReadOnly); 446 QDataStream stream(data,IO_ReadOnly);
445 QCString ch,m; 447 QCString ch,m;
446 QStringList types; 448 QStringList types;
447 stream >> ch >> m >> types; 449 stream >> ch >> m >> types;
448 AddressPicker picker(abList,this,0,TRUE); 450 AddressPicker picker(abList,this,0,TRUE);
449 picker.showMaximized(); 451 picker.showMaximized();
450 picker.setChoiceNames(types); 452 picker.setChoiceNames(types);
451 int i=0; 453 int i=0;
452 for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) { 454 for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) {
453 QStringList sel; 455 QStringList sel;
454 stream >> sel; 456 stream >> sel;
455 picker.setSelection(i++,sel); 457 picker.setSelection(i++,sel);
456 } 458 }
457 picker.showMaximized(); 459 picker.showMaximized();
458 picker.exec(); 460 picker.exec();
459 461
460 // ###### note: contacts may have been added - save here! 462 // ###### note: contacts may have been added - save here!
461 463
462 setCentralWidget(abList); 464 setCentralWidget(abList);
463 QCopEnvelope e(ch,m); 465 QCopEnvelope e(ch,m);
464 i=0; 466 i=0;
465 for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) { 467 for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) {
466 QStringList sel = picker.selection(i++); 468 QStringList sel = picker.selection(i++);
467 e << sel; 469 e << sel;
468 } 470 }
469 } 471 }
470#endif 472#endif
471 473
472} 474}
473 475
474void AddressbookWindow::editPersonal() 476void AddressbookWindow::editPersonal()
475{ 477{
476 QString filename = addressbookPersonalVCardName(); 478 QString filename = addressbookPersonalVCardName();
477 Contact me; 479 Contact me;
478 if (QFile::exists(filename)) 480 if (QFile::exists(filename))
479 me = Contact::readVCard( filename )[0]; 481 me = Contact::readVCard( filename )[0];
480 if (bAbEditFirstTime) { 482 if (bAbEditFirstTime) {
481 abEditor = new AbEditor( me, &orderedFields, &slOrderedFields, 483 abEditor = new AbEditor( me, &orderedFields, &slOrderedFields,
482 this, "editor" ); 484 this, "editor" );
483 // don't create a new editor every time 485 // don't create a new editor every time
484 bAbEditFirstTime = FALSE; 486 bAbEditFirstTime = FALSE;
485 } else 487 } else
486 abEditor->setEntry( me ); 488 abEditor->setEntry( me );
487 489
488 abEditor->setCaption(tr("Edit My Personal Details")); 490 abEditor->setCaption(tr("Edit My Personal Details"));
489 abEditor->showMaximized(); 491 abEditor->showMaximized();
490 492
491 // fix the foxus... 493 // fix the foxus...
492 abEditor->setNameFocus(); 494 abEditor->setNameFocus();
493 if ( abEditor->exec() ) { 495 if ( abEditor->exec() ) {
494 setFocus(); 496 setFocus();
495 Contact new_personal = abEditor->entry(); 497 Contact new_personal = abEditor->entry();
496 QString fname = addressbookPersonalVCardName(); 498 QString fname = addressbookPersonalVCardName();
497 Contact::writeVCard( fname, new_personal ); 499 Contact::writeVCard( fname, new_personal );
498 abView()->init(new_personal); 500 abView()->init(new_personal);
499 abView()->sync(); 501 abView()->sync();
500 } 502 }
501 abEditor->setCaption( tr("Edit Address") ); 503 abEditor->setCaption( tr("Edit Address") );
502} 504}
503 505
504void AddressbookWindow::slotPersonalView() 506void AddressbookWindow::slotPersonalView()
505{ 507{
506 if (!actionPersonal->isOn()) { 508 if (!actionPersonal->isOn()) {
507 // we just turned it off 509 // we just turned it off
508 setCaption( tr("Contacts") ); 510 setCaption( tr("Contacts") );
509 actionNew->setEnabled(TRUE); 511 actionNew->setEnabled(TRUE);
510 actionTrash->setEnabled(TRUE); 512 actionTrash->setEnabled(TRUE);
511 actionFind->setEnabled(TRUE); 513 actionFind->setEnabled(TRUE);
512 slotUpdateToolbar(); // maybe some of the above could be moved there 514 slotUpdateToolbar(); // maybe some of the above could be moved there
513 showList(); 515 showList();
514 return; 516 return;
515 } 517 }
516 518
517 // XXX need to disable some QActions. 519 // XXX need to disable some QActions.
518 actionNew->setEnabled(FALSE); 520 actionNew->setEnabled(FALSE);
519 actionTrash->setEnabled(FALSE); 521 actionTrash->setEnabled(FALSE);
520 actionFind->setEnabled(FALSE); 522 actionFind->setEnabled(FALSE);
521 actionMail->setEnabled(FALSE); 523 actionMail->setEnabled(FALSE);
522 524
523 setCaption( tr("Contacts - My Personal Details") ); 525 setCaption( tr("Contacts - My Personal Details") );
524 QString filename = addressbookPersonalVCardName(); 526 QString filename = addressbookPersonalVCardName();