summaryrefslogtreecommitdiff
authoreilers <eilers>2002-10-16 11:11:30 (UTC)
committer eilers <eilers>2002-10-16 11:11:30 (UTC)
commitfdc4abb0d38e6d5dce98961e47b552ff56c89976 (patch) (unidiff)
tree19201b896894949c3ae62bace1b555dd96874241
parent2bfae6336f88a460311abaf727256c3413b27f67 (diff)
downloadopie-fdc4abb0d38e6d5dce98961e47b552ff56c89976.zip
opie-fdc4abb0d38e6d5dce98961e47b552ff56c89976.tar.gz
opie-fdc4abb0d38e6d5dce98961e47b552ff56c89976.tar.bz2
Temporarely added save function..
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,702 +1,715 @@
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;