summaryrefslogtreecommitdiff
path: root/core/pim/addressbook/addressbook.cpp
Unidiff
Diffstat (limited to 'core/pim/addressbook/addressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/addressbook/addressbook.cpp70
1 files changed, 51 insertions, 19 deletions
diff --git a/core/pim/addressbook/addressbook.cpp b/core/pim/addressbook/addressbook.cpp
index f7e4c95..3466801 100644
--- a/core/pim/addressbook/addressbook.cpp
+++ b/core/pim/addressbook/addressbook.cpp
@@ -33,392 +33,398 @@
33#include <qpe/config.h> 33#include <qpe/config.h>
34#include <opie/ocontact.h> 34#include <opie/ocontact.h>
35 35
36#include <qpe/global.h> 36#include <qpe/global.h>
37#include <qpe/resource.h> 37#include <qpe/resource.h>
38#include <qpe/ir.h> 38#include <qpe/ir.h>
39#include <qpe/qpemessagebox.h> 39#include <qpe/qpemessagebox.h>
40#include <qpe/qcopenvelope_qws.h> 40#include <qpe/qcopenvelope_qws.h>
41 41
42#include <qaction.h> 42#include <qaction.h>
43#include <qdialog.h> 43#include <qdialog.h>
44#include <qdir.h> 44#include <qdir.h>
45#include <qfile.h> 45#include <qfile.h>
46#include <qimage.h> 46#include <qimage.h>
47#include <qlayout.h> 47#include <qlayout.h>
48#include <qpe/qpemenubar.h> 48#include <qpe/qpemenubar.h>
49#include <qmessagebox.h> 49#include <qmessagebox.h>
50#include <qpixmap.h> 50#include <qpixmap.h>
51#include <qpopupmenu.h> 51#include <qpopupmenu.h>
52#include <qpe/qpetoolbar.h> 52#include <qpe/qpetoolbar.h>
53#include <qstringlist.h> 53#include <qstringlist.h>
54#include <qtoolbutton.h> 54#include <qtoolbutton.h>
55#include <qwhatsthis.h> 55#include <qwhatsthis.h>
56 56
57#include <stdlib.h> 57#include <stdlib.h>
58#include <sys/stat.h> 58#include <sys/stat.h>
59#include <sys/types.h> 59#include <sys/types.h>
60#include <fcntl.h> 60#include <fcntl.h>
61#include <unistd.h> 61#include <unistd.h>
62 62
63#include <qdatetime.h> 63#include <qdatetime.h>
64 64
65#include "picker.h" 65#include "picker.h"
66#include "configdlg.h" 66#include "configdlg.h"
67 67
68static QString addressbookPersonalVCardName() 68static QString addressbookPersonalVCardName()
69{ 69{
70 QString filename = Global::applicationFileName("addressbook", 70 QString filename = Global::applicationFileName("addressbook",
71 "businesscard.vcf"); 71 "businesscard.vcf");
72 return filename; 72 return filename;
73} 73}
74 74
75 75
76AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, 76AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name,
77 WFlags f ) 77 WFlags f )
78 : QMainWindow( parent, name, f ), 78 : QMainWindow( parent, name, f ),
79 abEditor(0), 79 abEditor(0),
80 useRegExp(false), 80 useRegExp(false),
81 DoSignalWrapAround(false), 81 doNotifyWrapAround(true),
82 caseSensitive(false), 82 caseSensitive(false),
83 bAbEditFirstTime(TRUE), 83 bAbEditFirstTime(TRUE),
84 syncing(FALSE) 84 syncing(FALSE)
85{ 85{
86 isLoading = true; 86 isLoading = true;
87 87
88 // Read Config settings
89 Config cfg("AddressBook");
90 cfg.setGroup("Search");
91 useRegExp = cfg.readBoolEntry( "useRegExp" );
92 caseSensitive = cfg.readBoolEntry( "caseSensitive" );
93 doNotifyWrapAround = cfg.readBoolEntry( "doNotifyWrapAround" );
94
88 initFields(); 95 initFields();
89 96
90 setCaption( tr("Contacts") ); 97 setCaption( tr("Contacts") );
91 setIcon( Resource::loadPixmap( "AddressBook" ) ); 98 setIcon( Resource::loadPixmap( "AddressBook" ) );
92 99
93 setToolBarsMovable( FALSE ); 100 setToolBarsMovable( FALSE );
94 101
95 // Create Toolbars 102 // Create Toolbars
96 103
97 QPEToolBar *bar = new QPEToolBar( this ); 104 QPEToolBar *bar = new QPEToolBar( this );
98 bar->setHorizontalStretchable( TRUE ); 105 bar->setHorizontalStretchable( TRUE );
99 106
100 QPEMenuBar *mbList = new QPEMenuBar( bar ); 107 QPEMenuBar *mbList = new QPEMenuBar( bar );
101 mbList->setMargin( 0 ); 108 mbList->setMargin( 0 );
102 109
103 QPopupMenu *edit = new QPopupMenu( this ); 110 QPopupMenu *edit = new QPopupMenu( this );
104 mbList->insertItem( tr( "Contact" ), edit ); 111 mbList->insertItem( tr( "Contact" ), edit );
105 112
106 listTools = new QPEToolBar( this, "list operations" ); 113 listTools = new QPEToolBar( this, "list operations" );
107 114
108 115
109 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 116 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null,
110 0, this, 0 ); 117 0, this, 0 );
111 actionNew = a; 118 actionNew = a;
112 connect( a, SIGNAL( activated() ), this, SLOT( slotListNew() ) ); 119 connect( a, SIGNAL( activated() ), this, SLOT( slotListNew() ) );
113 a->addTo( edit ); 120 a->addTo( edit );
114 a->addTo( listTools ); 121 a->addTo( listTools );
115 122
116 a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null, 123 a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null,
117 0, this, 0 ); 124 0, this, 0 );
118 actionEdit = a; 125 actionEdit = a;
119 connect( a, SIGNAL( activated() ), this, SLOT( slotViewEdit() ) ); 126 connect( a, SIGNAL( activated() ), this, SLOT( slotViewEdit() ) );
120 a->addTo( edit ); 127 a->addTo( edit );
121 a->addTo( listTools ); 128 a->addTo( listTools );
122 129
123 a = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 130 a = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null,
124 0, this, 0 ); 131 0, this, 0 );
125 actionTrash = a; 132 actionTrash = a;
126 connect( a, SIGNAL( activated() ), this, SLOT( slotListDelete() ) ); 133 connect( a, SIGNAL( activated() ), this, SLOT( slotListDelete() ) );
127 a->addTo( edit ); 134 a->addTo( edit );
128 a->addTo( listTools ); 135 a->addTo( listTools );
129 136
130 137
131 // make it possible to go directly to businesscard via qcop call 138 // make it possible to go directly to businesscard via qcop call
132#if defined(Q_WS_QWS) 139#if defined(Q_WS_QWS)
133#if !defined(QT_NO_COP) 140#if !defined(QT_NO_COP)
134 QCopChannel *addressChannel = new QCopChannel("QPE/Addressbook" , this ); 141 QCopChannel *addressChannel = new QCopChannel("QPE/Addressbook" , this );
135 connect (addressChannel, SIGNAL( received(const QCString &, const QByteArray &)), 142 connect (addressChannel, SIGNAL( received(const QCString &, const QByteArray &)),
136 this, SLOT ( appMessage(const QCString &, const QByteArray &) ) ); 143 this, SLOT ( appMessage(const QCString &, const QByteArray &) ) );
137#endif 144#endif
138#endif 145#endif
139 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), 146 a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ),
140 QString::null, 0, this, 0 ); 147 QString::null, 0, this, 0 );
141 actionFind = a; 148 actionFind = a;
142 connect( a, SIGNAL(activated()), this, SLOT( slotFindOpen()) ); 149 connect( a, SIGNAL(activated()), this, SLOT( slotFindOpen()) );
143 a->addTo( edit ); 150 a->addTo( edit );
144 a->addTo( listTools ); 151 a->addTo( listTools );
145 152
146 // Much better search widget, taken from QTReader.. (se) 153 // Much better search widget, taken from QTReader.. (se)
147 searchBar = new OFloatBar( "Search", this, QMainWindow::Top, TRUE ); 154 searchBar = new OFloatBar( "Search", this, QMainWindow::Top, TRUE );
148 searchBar->setHorizontalStretchable( TRUE ); 155 searchBar->setHorizontalStretchable( TRUE );
149 searchBar->hide(); 156 searchBar->hide();
150 searchEdit = new QLineEdit( searchBar, "searchEdit" ); 157 searchEdit = new QLineEdit( searchBar, "searchEdit" );
151// QFont f("unifont", 16 /*, QFont::Bold*/); 158// QFont f("unifont", 16 /*, QFont::Bold*/);
152// searchEdit->setFont( f ); 159// searchEdit->setFont( f );
153 searchBar->setStretchableWidget( searchEdit ); 160 searchBar->setStretchableWidget( searchEdit );
154 connect( searchEdit, SIGNAL( returnPressed( ) ), 161 connect( searchEdit, SIGNAL( returnPressed( ) ),
155 this, SLOT( slotFind( ) ) ); 162 this, SLOT( slotFind( ) ) );
156 163
157 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); 164 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 );
158 connect( a, SIGNAL( activated() ), this, SLOT( slotFindNext() ) ); 165 connect( a, SIGNAL( activated() ), this, SLOT( slotFindNext() ) );
159 a->addTo( searchBar ); 166 a->addTo( searchBar );
160 167
161 a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); 168 a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
162 connect( a, SIGNAL( activated() ), this, SLOT( slotFindClose() ) ); 169 connect( a, SIGNAL( activated() ), this, SLOT( slotFindClose() ) );
163 a->addTo( searchBar ); 170 a->addTo( searchBar );
164 171
165 a = new QAction( tr( "Write Mail To" ), Resource::loadPixmap( "qtmail/reply" ), 172 a = new QAction( tr( "Write Mail To" ), Resource::loadPixmap( "qtmail/reply" ),
166 QString::null, 0, this, 0 ); 173 QString::null, 0, this, 0 );
167 //a->setEnabled( FALSE ); we got support for it now :) zecke 174 //a->setEnabled( FALSE ); we got support for it now :) zecke
168 actionMail = a; 175 actionMail = a;
169 connect( a, SIGNAL( activated() ), this, SLOT( writeMail() ) ); 176 connect( a, SIGNAL( activated() ), this, SLOT( writeMail() ) );
170 a->addTo( edit ); 177 a->addTo( edit );
171 a->addTo( listTools ); 178 a->addTo( listTools );
172 179
173 180
174 181
175 if ( Ir::supported() ) { 182 if ( Ir::supported() ) {
176 a = new QAction( tr ("Beam Entry" ), Resource::loadPixmap( "beam" ), QString::null, 183 a = new QAction( tr ("Beam Entry" ), Resource::loadPixmap( "beam" ), QString::null,
177 0, this, 0 ); 184 0, this, 0 );
178 actionBeam = a; 185 actionBeam = a;
179 connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) ); 186 connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) );
180 a->addTo( edit ); 187 a->addTo( edit );
181 a->addTo( listTools ); 188 a->addTo( listTools );
182 } 189 }
183 190
184 edit->insertSeparator(); 191 edit->insertSeparator();
185 192
186 a = new QAction( tr("Import vCard"), QString::null, 0, 0, 0, TRUE ); 193 a = new QAction( tr("Import vCard"), QString::null, 0, 0, 0, TRUE );
187 actionPersonal = a; 194 actionPersonal = a;
188 connect( a, SIGNAL( activated() ), this, SLOT( importvCard() ) ); 195 connect( a, SIGNAL( activated() ), this, SLOT( importvCard() ) );
189 a->addTo( edit ); 196 a->addTo( edit );
190 197
191 edit->insertSeparator(); 198 edit->insertSeparator();
192 199
193 a = new QAction( tr("My Personal Details"), QString::null, 0, 0, 0, TRUE ); 200 a = new QAction( tr("My Personal Details"), QString::null, 0, 0, 0, TRUE );
194 actionPersonal = a; 201 actionPersonal = a;
195 connect( a, SIGNAL( activated() ), this, SLOT( slotPersonalView() ) ); 202 connect( a, SIGNAL( activated() ), this, SLOT( slotPersonalView() ) );
196 a->addTo( edit ); 203 a->addTo( edit );
197 204
198 // Do we need this function ? (se) 205 // Do we need this function ? (se)
199 // a = new QAction( tr( "Arrange Edit Fields"), QString::null, 0, 0 ); 206 // a = new QAction( tr( "Arrange Edit Fields"), QString::null, 0, 0 );
200 // connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); 207 // connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) );
201 // a->addTo( edit ); 208 // a->addTo( edit );
202 209
203 210
204#ifdef __DEBUG_RELEASE 211#ifdef __DEBUG_RELEASE
205 // Remove this function for public Release ! This is only 212 // Remove this function for public Release ! This is only
206 // for debug purposes .. 213 // for debug purposes ..
207 a = new QAction( tr( "Save all Data"), QString::null, 0, 0 ); 214 a = new QAction( tr( "Save all Data"), QString::null, 0, 0 );
208 connect( a, SIGNAL( activated() ), this , SLOT( slotSave() ) ); 215 connect( a, SIGNAL( activated() ), this , SLOT( slotSave() ) );
209 a->addTo( edit ); 216 a->addTo( edit );
210#endif 217#endif
211 a = new QAction( tr( "Config" ), Resource::loadPixmap( "today/config" ), QString::null, 218 a = new QAction( tr( "Config" ), Resource::loadPixmap( "today/config" ), QString::null,
212 0, this, 0 ); 219 0, this, 0 );
213 connect( a, SIGNAL( activated() ), this, SLOT( slotConfig() ) ); 220 connect( a, SIGNAL( activated() ), this, SLOT( slotConfig() ) );
214 a->addTo( edit ); 221 a->addTo( edit );
215 222
216 // Create Views 223 // Create Views
217 listContainer = new QWidget( this ); 224 listContainer = new QWidget( this );
218 225
219 QVBoxLayout *vb = new QVBoxLayout( listContainer ); 226 QVBoxLayout *vb = new QVBoxLayout( listContainer );
220 227
221 abList = new AbTable( &orderedFields, listContainer, "table" ); 228 abList = new AbTable( &orderedFields, listContainer, "table" );
222 vb->addWidget(abList); 229 vb->addWidget(abList);
223 // abList->setHScrollBarMode( QScrollView::AlwaysOff ); 230 // abList->setHScrollBarMode( QScrollView::AlwaysOff );
224 connect( abList, SIGNAL( empty( bool ) ), this, SLOT( listIsEmpty( bool ) ) ); 231 connect( abList, SIGNAL( empty( bool ) ), this, SLOT( listIsEmpty( bool ) ) );
225 connect( abList, SIGNAL( details() ), this, SLOT( slotListView() ) ); 232 connect( abList, SIGNAL( details() ), this, SLOT( slotListView() ) );
226 connect( abList, SIGNAL(currentChanged(int,int)), this, SLOT(slotUpdateToolbar()) ); 233 connect( abList, SIGNAL( currentChanged(int,int) ), this, SLOT( slotUpdateToolbar() ) );
234 connect( abList, SIGNAL( signalSearchNext() ), this, SLOT( slotFindNext() ) );
235 connect( abList, SIGNAL( signalSearchBackward() ), this, SLOT( slotFindPrevious() ) );
236
237 // Maybe we should react on Wraparound and notfound ?
238 QObject::connect( abList, SIGNAL(signalNotFound()), this, SLOT(slotNotFound()) );
239 QObject::connect( abList, SIGNAL(signalWrapAround()), this, SLOT(slotWrapAround()) );
227 240
228 mView = 0; 241 mView = 0;
229 242
230 abList->load(); 243 abList->load();
231 244
232 pLabel = new LetterPicker( listContainer ); 245 pLabel = new LetterPicker( listContainer );
233 connect(pLabel, SIGNAL(letterClicked(char)), this, SLOT(slotSetLetter(char))); 246 connect(pLabel, SIGNAL(letterClicked(char)), this, SLOT(slotSetLetter(char)));
234 vb->addWidget(pLabel); 247 vb->addWidget(pLabel);
235 catMenu = new QPopupMenu( this ); 248 catMenu = new QPopupMenu( this );
236 catMenu->setCheckable( TRUE ); 249 catMenu->setCheckable( TRUE );
237 connect( catMenu, SIGNAL(activated(int)), this, SLOT(slotSetCategory(int)) ); 250 connect( catMenu, SIGNAL(activated(int)), this, SLOT(slotSetCategory(int)) );
238 populateCategories(); 251 populateCategories();
239 252
240 mbList->insertItem( tr("View"), catMenu ); 253 mbList->insertItem( tr("View"), catMenu );
241 // setCentralWidget( listContainer ); 254 // setCentralWidget( listContainer );
242 255
243 fontMenu = new QPopupMenu(this); 256 fontMenu = new QPopupMenu(this);
244 fontMenu->setCheckable( true ); 257 fontMenu->setCheckable( true );
245 connect( fontMenu, SIGNAL(activated(int)), this, SLOT(slotSetFont(int))); 258 connect( fontMenu, SIGNAL(activated(int)), this, SLOT(slotSetFont(int)));
246 259
247 fontMenu->insertItem(tr( "Small" ), 0); 260 fontMenu->insertItem(tr( "Small" ), 0);
248 fontMenu->insertItem(tr( "Normal" ), 1); 261 fontMenu->insertItem(tr( "Normal" ), 1);
249 fontMenu->insertItem(tr( "Large" ), 2); 262 fontMenu->insertItem(tr( "Large" ), 2);
250 263
251 defaultFont = new QFont( abList->font() ); 264 defaultFont = new QFont( abList->font() );
252 265
253 slotSetFont(startFontSize); 266 slotSetFont(startFontSize);
254 267
255 mbList->insertItem( tr("Font"), fontMenu); 268 mbList->insertItem( tr("Font"), fontMenu);
256 setCentralWidget(listContainer); 269 setCentralWidget(listContainer);
257 270
258 // qDebug("adressbook contrsuction: t=%d", t.elapsed() ); 271 // qDebug("adressbook contrsuction: t=%d", t.elapsed() );
259 272
260 abList->setCurrentCell( 0, 0 ); 273 abList->setCurrentCell( 0, 0 );
261
262 // Read Config settings
263 Config cfg("AddressBook");
264 cfg.setGroup("Search");
265 useRegExp = cfg.readBoolEntry( "useRegExp" );
266 caseSensitive = cfg.readBoolEntry( "caseSensitive" );
267 DoSignalWrapAround = cfg.readBoolEntry( "signalWrapAround" );
268 274
269 isLoading = false; 275 isLoading = false;
270} 276}
271 277
272 278
273void AddressbookWindow::slotConfig() 279void AddressbookWindow::slotConfig()
274{ 280{
275 ConfigDlg* dlg = new ConfigDlg( this, "Config" ); 281 ConfigDlg* dlg = new ConfigDlg( this, "Config" );
276 dlg -> setUseRegExp ( useRegExp ); 282 dlg -> setUseRegExp ( useRegExp );
277 dlg -> setBeCaseSensitive( caseSensitive ); 283 dlg -> setBeCaseSensitive( caseSensitive );
278 dlg -> setSignalWrapAround( DoSignalWrapAround ); 284 dlg -> setSignalWrapAround( doNotifyWrapAround );
279 dlg -> showMaximized(); 285 dlg -> showMaximized();
280 if ( dlg -> exec() ) { 286 if ( dlg -> exec() ) {
281 qWarning ("Config Dialog accepted !"); 287 qWarning ("Config Dialog accepted !");
282 useRegExp = dlg -> useRegExp(); 288 useRegExp = dlg -> useRegExp();
283 caseSensitive = dlg -> beCaseSensitive(); 289 caseSensitive = dlg -> beCaseSensitive();
284 DoSignalWrapAround = dlg -> signalWrapAround(); 290 doNotifyWrapAround = dlg -> signalWrapAround();
285 } 291 }
286 292
287 delete dlg; 293 delete dlg;
288} 294}
289 295
290 296
291void AddressbookWindow::slotSetFont( int size ) { 297void AddressbookWindow::slotSetFont( int size ) {
292 298
293 if (size > 2 || size < 0) 299 if (size > 2 || size < 0)
294 size = 1; 300 size = 1;
295 301
296 startFontSize = size; 302 startFontSize = size;
297 303
298 QFont *currentFont; 304 QFont *currentFont;
299 305
300 switch (size) { 306 switch (size) {
301 case 0: 307 case 0:
302 fontMenu->setItemChecked(0, true); 308 fontMenu->setItemChecked(0, true);
303 fontMenu->setItemChecked(1, false); 309 fontMenu->setItemChecked(1, false);
304 fontMenu->setItemChecked(2, false); 310 fontMenu->setItemChecked(2, false);
305 abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) ); 311 abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) );
306 currentFont = new QFont (abList->font()); 312 currentFont = new QFont (abList->font());
307 // abList->resizeRows(currentFont->pixelSize() + 7); 313 // abList->resizeRows(currentFont->pixelSize() + 7);
308 abList->resizeRows(); 314 abList->resizeRows();
309 break; 315 break;
310 case 1: 316 case 1:
311 fontMenu->setItemChecked(0, false); 317 fontMenu->setItemChecked(0, false);
312 fontMenu->setItemChecked(1, true); 318 fontMenu->setItemChecked(1, true);
313 fontMenu->setItemChecked(2, false); 319 fontMenu->setItemChecked(2, false);
314 abList->setFont( *defaultFont ); 320 abList->setFont( *defaultFont );
315 currentFont = new QFont (abList->font()); 321 currentFont = new QFont (abList->font());
316 // abList->resizeRows(currentFont->pixelSize() + 7); 322 // abList->resizeRows(currentFont->pixelSize() + 7);
317 abList->resizeRows(); 323 abList->resizeRows();
318 break; 324 break;
319 case 2: 325 case 2:
320 fontMenu->setItemChecked(0, false); 326 fontMenu->setItemChecked(0, false);
321 fontMenu->setItemChecked(1, false); 327 fontMenu->setItemChecked(1, false);
322 fontMenu->setItemChecked(2, true); 328 fontMenu->setItemChecked(2, true);
323 abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() + 2 ) ); 329 abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() + 2 ) );
324 currentFont = new QFont (abList->font()); 330 currentFont = new QFont (abList->font());
325 //abList->resizeRows(currentFont->pixelSize() + 7); 331 //abList->resizeRows(currentFont->pixelSize() + 7);
326 abList->resizeRows(); 332 abList->resizeRows();
327 break; 333 break;
328 } 334 }
329} 335}
330 336
331 337
332 338
333void AddressbookWindow::importvCard() { 339void AddressbookWindow::importvCard() {
334 QString str = OFileDialog::getOpenFileName( 1,"/");//,"", "*", this ); 340 QString str = OFileDialog::getOpenFileName( 1,"/");//,"", "*", this );
335 if(!str.isEmpty() ) 341 if(!str.isEmpty() )
336 setDocument((const QString&) str ); 342 setDocument((const QString&) str );
337 343
338} 344}
339 345
340void AddressbookWindow::setDocument( const QString &filename ) 346void AddressbookWindow::setDocument( const QString &filename )
341{ 347{
342 if ( filename.find(".vcf") != int(filename.length()) - 4 ) 348 if ( filename.find(".vcf") != int(filename.length()) - 4 )
343 return; 349 return;
344 350
345 QValueList<OContact> cl = OContact::readVCard( filename ); 351 QValueList<OContact> cl = OContact::readVCard( filename );
346 for( QValueList<OContact>::Iterator it = cl.begin(); it != cl.end(); ++it ) { 352 for( QValueList<OContact>::Iterator it = cl.begin(); it != cl.end(); ++it ) {
347 // QString msg = tr("You received a vCard for\n%1.\nDo You want to add it to your\naddressbook?") 353 // QString msg = tr("You received a vCard for\n%1.\nDo You want to add it to your\naddressbook?")
348 // .arg( (*it).fullName() ); 354 // .arg( (*it).fullName() );
349 // if ( QMessageBox::information( this, tr("received contact"), msg, QMessageBox::Ok, QMessageBox::Cancel ) == 355 // if ( QMessageBox::information( this, tr("received contact"), msg, QMessageBox::Ok, QMessageBox::Cancel ) ==
350 // QMessageBox::Ok ) { 356 // QMessageBox::Ok ) {
351 abList->addEntry( *it ); 357 abList->addEntry( *it );
352 // } 358 // }
353 } 359 }
354 360
355} 361}
356 362
357void AddressbookWindow::resizeEvent( QResizeEvent *e ) 363void AddressbookWindow::resizeEvent( QResizeEvent *e )
358{ 364{
359 QMainWindow::resizeEvent( e ); 365 QMainWindow::resizeEvent( e );
360 366
361 if ( centralWidget() == listContainer ) 367 if ( centralWidget() == listContainer )
362 showList(); 368 showList();
363 else if ( centralWidget() == mView ) 369 else if ( centralWidget() == mView )
364 showView(); 370 showView();
365} 371}
366 372
367AddressbookWindow::~AddressbookWindow() 373AddressbookWindow::~AddressbookWindow()
368{ 374{
369 Config cfg("AddressBook"); 375 Config cfg("AddressBook");
370 cfg.setGroup("Font"); 376 cfg.setGroup("Font");
371 cfg.writeEntry("fontSize", startFontSize); 377 cfg.writeEntry("fontSize", startFontSize);
372 378
373 cfg.setGroup("Search"); 379 cfg.setGroup("Search");
374 cfg.writeEntry("useRegExp", useRegExp); 380 cfg.writeEntry("useRegExp", useRegExp);
375 cfg.writeEntry("caseSensitive", caseSensitive); 381 cfg.writeEntry("caseSensitive", caseSensitive);
376 cfg.writeEntry("signalWrapAround", DoSignalWrapAround); 382 cfg.writeEntry("doNotifyWrapAround", doNotifyWrapAround);
377} 383}
378 384
379void AddressbookWindow::slotUpdateToolbar() 385void AddressbookWindow::slotUpdateToolbar()
380{ 386{
381 OContact ce = abList->currentEntry(); 387 OContact ce = abList->currentEntry();
382 actionMail->setEnabled( !ce.defaultEmail().isEmpty() ); 388 actionMail->setEnabled( !ce.defaultEmail().isEmpty() );
383} 389}
384 390
385void AddressbookWindow::showList() 391void AddressbookWindow::showList()
386{ 392{
387 bool visiblemView; 393 bool visiblemView;
388 394
389 visiblemView = false; 395 visiblemView = false;
390 if ( mView ) { 396 if ( mView ) {
391 mView->hide(); 397 mView->hide();
392 visiblemView = true; 398 visiblemView = true;
393 } 399 }
394 setCentralWidget( listContainer ); 400 setCentralWidget( listContainer );
395 listContainer->show(); 401 listContainer->show();
396 // update our focues... (or use a stack widget!); 402 // update our focues... (or use a stack widget!);
397 abList->setFocus(); 403 abList->setFocus();
398 404
399 // This makes sure we are scrolled all the way to the left 405 // This makes sure we are scrolled all the way to the left
400 abList->setContentsPos( 0, abList->contentsY() ); 406 abList->setContentsPos( 0, abList->contentsY() );
401 407
402 //if ( visiblemView && abList->showBook() == "Cards" ) 408 //if ( visiblemView && abList->showBook() == "Cards" )
403 //abList->setShowCategory( abList->showBook(), abList->showCategory() ); 409 //abList->setShowCategory( abList->showBook(), abList->showCategory() );
404 410
405} 411}
406 412
407void AddressbookWindow::showView() 413void AddressbookWindow::showView()
408{ 414{
409 if ( abList->numRows() > 0 ) { 415 if ( abList->numRows() > 0 ) {
410 listContainer->hide(); 416 listContainer->hide();
411 setCentralWidget( abView() ); 417 setCentralWidget( abView() );
412 mView->show(); 418 mView->show();
413 mView->setFocus(); 419 mView->setFocus();
414 } 420 }
415} 421}
416 422
417void AddressbookWindow::slotListNew() 423void AddressbookWindow::slotListNew()
418{ 424{
419 OContact cnt; 425 OContact cnt;
420 if( !syncing ) { 426 if( !syncing ) {
421 if ( abEditor ) 427 if ( abEditor )
422 abEditor->setEntry( cnt ); 428 abEditor->setEntry( cnt );
423 abView()->init( cnt ); 429 abView()->init( cnt );
424 editEntry( NewEntry ); 430 editEntry( NewEntry );
@@ -611,99 +617,97 @@ void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data)
611 QCopEnvelope e(ch,m); 617 QCopEnvelope e(ch,m);
612 i=0; 618 i=0;
613 for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) { 619 for (QStringList::ConstIterator it = types.begin(); it!=types.end(); ++it) {
614 QStringList sel = picker.selection(i++); 620 QStringList sel = picker.selection(i++);
615 e << sel; 621 e << sel;
616 } 622 }
617 } 623 }
618#endif 624#endif
619 625
620} 626}
621 627
622void AddressbookWindow::editPersonal() 628void AddressbookWindow::editPersonal()
623{ 629{
624 QString filename = addressbookPersonalVCardName(); 630 QString filename = addressbookPersonalVCardName();
625 OContact me; 631 OContact me;
626 if (QFile::exists(filename)) 632 if (QFile::exists(filename))
627 me = OContact::readVCard( filename )[0]; 633 me = OContact::readVCard( filename )[0];
628 if (bAbEditFirstTime) { 634 if (bAbEditFirstTime) {
629 abEditor = new ContactEditor( me, &orderedFields, &slOrderedFields, 635 abEditor = new ContactEditor( me, &orderedFields, &slOrderedFields,
630 this, "editor" ); 636 this, "editor" );
631 // don't create a new editor every time 637 // don't create a new editor every time
632 bAbEditFirstTime = FALSE; 638 bAbEditFirstTime = FALSE;
633 } else 639 } else
634 abEditor->setEntry( me ); 640 abEditor->setEntry( me );
635 641
636 abEditor->setCaption(tr("Edit My Personal Details")); 642 abEditor->setCaption(tr("Edit My Personal Details"));
637 abEditor->showMaximized(); 643 abEditor->showMaximized();
638 644
639 // fix the foxus... 645 // fix the foxus...
640 abEditor->setNameFocus(); 646 abEditor->setNameFocus();
641 if ( abEditor->exec() ) { 647 if ( abEditor->exec() ) {
642 setFocus(); 648 setFocus();
643 OContact new_personal = abEditor->entry(); 649 OContact new_personal = abEditor->entry();
644 QString fname = addressbookPersonalVCardName(); 650 QString fname = addressbookPersonalVCardName();
645 OContact::writeVCard( fname, new_personal ); 651 OContact::writeVCard( fname, new_personal );
646 abView()->init(new_personal); 652 abView()->init(new_personal);
647 abView()->sync(); 653 abView()->sync();
648 } 654 }
649 abEditor->setCaption( tr("Edit Address") ); 655 abEditor->setCaption( tr("Edit Address") );
650} 656}
651 657
652void AddressbookWindow::slotPersonalView() 658void AddressbookWindow::slotPersonalView()
653{ 659{
654 if (!actionPersonal->isOn()) { 660 if (!actionPersonal->isOn()) {
655 // we just turned it off 661 // we just turned it off
656 setCaption( tr("Contacts") ); 662 setCaption( tr("Contacts") );
657 actionNew->setEnabled(TRUE); 663 actionNew->setEnabled(TRUE);
658 actionTrash->setEnabled(TRUE); 664 actionTrash->setEnabled(TRUE);
659#ifndef MAKE_FOR_SHARP_ROM
660 actionFind->setEnabled(TRUE); 665 actionFind->setEnabled(TRUE);
661#endif
662 slotUpdateToolbar(); // maybe some of the above could be moved there 666 slotUpdateToolbar(); // maybe some of the above could be moved there
663 showList(); 667 showList();
664 return; 668 return;
665 } 669 }
666 670
667 // XXX need to disable some QActions. 671 // XXX need to disable some QActions.
668 actionNew->setEnabled(FALSE); 672 actionNew->setEnabled(FALSE);
669 actionTrash->setEnabled(FALSE); 673 actionTrash->setEnabled(FALSE);
670#ifndef MAKE_FOR_SHARP_ROM 674#ifndef MAKE_FOR_SHARP_ROM
671 actionFind->setEnabled(FALSE); 675 actionFind->setEnabled(FALSE);
672#endif 676#endif
673 actionMail->setEnabled(FALSE); 677 actionMail->setEnabled(FALSE);
674 678
675 setCaption( tr("Contacts - My Personal Details") ); 679 setCaption( tr("Contacts - My Personal Details") );
676 QString filename = addressbookPersonalVCardName(); 680 QString filename = addressbookPersonalVCardName();
677 OContact me; 681 OContact me;
678 if (QFile::exists(filename)) 682 if (QFile::exists(filename))
679 me = OContact::readVCard( filename )[0]; 683 me = OContact::readVCard( filename )[0];
680 684
681 abView()->init( me ); 685 abView()->init( me );
682 abView()->sync(); 686 abView()->sync();
683 listContainer->hide(); 687 listContainer->hide();
684 setCentralWidget( abView() ); 688 setCentralWidget( abView() );
685 mView->show(); 689 mView->show();
686 mView->setFocus(); 690 mView->setFocus();
687} 691}
688 692
689void AddressbookWindow::editEntry( EntryMode entryMode ) 693void AddressbookWindow::editEntry( EntryMode entryMode )
690{ 694{
691 OContact entry; 695 OContact entry;
692 if ( bAbEditFirstTime ) { 696 if ( bAbEditFirstTime ) {
693 abEditor = new ContactEditor( entry, &orderedFields, &slOrderedFields, 697 abEditor = new ContactEditor( entry, &orderedFields, &slOrderedFields,
694 this, "editor" ); 698 this, "editor" );
695 bAbEditFirstTime = FALSE; 699 bAbEditFirstTime = FALSE;
696 if ( entryMode == EditEntry ) 700 if ( entryMode == EditEntry )
697 abEditor->setEntry( abList->currentEntry() ); 701 abEditor->setEntry( abList->currentEntry() );
698 } 702 }
699 // other things may chane the caption. 703 // other things may chane the caption.
700 abEditor->setCaption( tr("Edit Address") ); 704 abEditor->setCaption( tr("Edit Address") );
701 705
702#if defined(Q_WS_QWS) || defined(_WS_QWS_) 706#if defined(Q_WS_QWS) || defined(_WS_QWS_)
703 abEditor->showMaximized(); 707 abEditor->showMaximized();
704#endif 708#endif
705 // fix the foxus... 709 // fix the foxus...
706 abEditor->setNameFocus(); 710 abEditor->setNameFocus();
707 if ( abEditor->exec() ) { 711 if ( abEditor->exec() ) {
708 setFocus(); 712 setFocus();
709 if ( entryMode == NewEntry ) { 713 if ( entryMode == NewEntry ) {
@@ -883,127 +887,155 @@ void AddressbookWindow::initFields()
883 itVis != visibleFields.end() && itVl != allFields.end(); 887 itVis != visibleFields.end() && itVl != allFields.end();
884 ++itVis, ++itVl ) { 888 ++itVis, ++itVl ) {
885 if ( *it == *itVis && itVl != allFields.end() ) { 889 if ( *it == *itVis && itVl != allFields.end() ) {
886 orderedFields.append( *itVl ); 890 orderedFields.append( *itVl );
887 } 891 }
888 } 892 }
889 } 893 }
890 } else { 894 } else {
891 QValueList<int>::ConstIterator it; 895 QValueList<int>::ConstIterator it;
892 for ( it = allFields.begin(); it != allFields.end(); ++it ) 896 for ( it = allFields.begin(); it != allFields.end(); ++it )
893 orderedFields.append( *it ); 897 orderedFields.append( *it );
894 898
895 slOrderedFields = visibleFields; 899 slOrderedFields = visibleFields;
896 orderedFields.remove( Qtopia::AddressUid ); 900 orderedFields.remove( Qtopia::AddressUid );
897 orderedFields.remove( Qtopia::Title ); 901 orderedFields.remove( Qtopia::Title );
898 orderedFields.remove( Qtopia::Groups ); 902 orderedFields.remove( Qtopia::Groups );
899 orderedFields.remove( Qtopia::AddressCategory ); 903 orderedFields.remove( Qtopia::AddressCategory );
900 orderedFields.remove( Qtopia::FirstName ); 904 orderedFields.remove( Qtopia::FirstName );
901 orderedFields.remove( Qtopia::LastName ); 905 orderedFields.remove( Qtopia::LastName );
902 orderedFields.remove( Qtopia::DefaultEmail ); 906 orderedFields.remove( Qtopia::DefaultEmail );
903 orderedFields.remove( Qtopia::FileAs ); 907 orderedFields.remove( Qtopia::FileAs );
904 orderedFields.remove( Qtopia::Notes ); 908 orderedFields.remove( Qtopia::Notes );
905 orderedFields.remove( Qtopia::Gender ); 909 orderedFields.remove( Qtopia::Gender );
906 slOrderedFields.remove( "Name Title" ); 910 slOrderedFields.remove( "Name Title" );
907 slOrderedFields.remove( "First Name" ); 911 slOrderedFields.remove( "First Name" );
908 slOrderedFields.remove( "Last Name" ); 912 slOrderedFields.remove( "Last Name" );
909 slOrderedFields.remove( "File As" ); 913 slOrderedFields.remove( "File As" );
910 slOrderedFields.remove( "Default Email" ); 914 slOrderedFields.remove( "Default Email" );
911 slOrderedFields.remove( "Notes" ); 915 slOrderedFields.remove( "Notes" );
912 slOrderedFields.remove( "Gender" ); 916 slOrderedFields.remove( "Gender" );
913 917
914 } 918 }
915} 919}
916 920
917 921
918AbLabel *AddressbookWindow::abView() 922AbLabel *AddressbookWindow::abView()
919{ 923{
920 if ( !mView ) { 924 if ( !mView ) {
921 mView = new AbLabel( this, "viewer" ); 925 mView = new AbLabel( this, "viewer" );
922 mView->init( OContact() ); 926 mView->init( OContact() );
923 connect( mView, SIGNAL( okPressed() ), this, SLOT( slotListView() ) ); 927 connect( mView, SIGNAL( okPressed() ), this, SLOT( slotListView() ) );
924 } 928 }
925 return mView; 929 return mView;
926} 930}
927 931
928void AddressbookWindow::slotFindOpen() 932void AddressbookWindow::slotFindOpen()
929{ 933{
930 searchBar->show(); 934 searchBar->show();
935 abList -> inSearch();
931 searchEdit->setFocus(); 936 searchEdit->setFocus();
932} 937}
933void AddressbookWindow::slotFindClose() 938void AddressbookWindow::slotFindClose()
934{ 939{
935 searchBar->hide(); 940 searchBar->hide();
941 abList -> offSearch();
936 abList->setFocus(); 942 abList->setFocus();
937} 943}
938void AddressbookWindow::slotFindNext() 944void AddressbookWindow::slotFindNext()
939{ 945{
940 if ( centralWidget() == abView() ) 946 if ( centralWidget() == abView() )
941 showList(); 947 showList();
942 948
943 // Maybe we should react on Wraparound and notfound ?
944 // QObject::connect( abList, SIGNAL(signalNotFound()), &frmFind, SLOT(slotNotFound()) );
945 // QObject::connect( abList, SIGNAL(signalWrapAround()), &frmFind, SLOT(slotWrapAround()) );
946
947 abList->slotDoFind( searchEdit->text(), caseSensitive, useRegExp, false); 949 abList->slotDoFind( searchEdit->text(), caseSensitive, useRegExp, false);
948 950
951 searchEdit->clearFocus();
952 abList->setFocus();
953 if ( abList->numSelections() )
954 abList->clearSelection();
955
956}
957void AddressbookWindow::slotFindPrevious()
958{
959 if ( centralWidget() == abView() )
960 showList();
961
962 abList->slotDoFind( searchEdit->text(), caseSensitive, useRegExp, true);
949 963
950 if ( abList->numSelections() ) 964 if ( abList->numSelections() )
951 abList->clearSelection(); 965 abList->clearSelection();
952 966
953} 967}
954 968
955void AddressbookWindow::slotFind() 969void AddressbookWindow::slotFind()
956{ 970{
957 971
958 abList->clearFindRow(); 972 abList->clearFindRow();
959 slotFindNext(); 973 slotFindNext();
960} 974}
961 975
976void AddressbookWindow::slotNotFound()
977{
978 qWarning("Got notfound signal !");
979 QMessageBox::information( this, tr( "Not Found" ),
980 tr( "Unable to find a contact for this" ) + "\n"
981 + tr( "search pattern !" ) );
982
983
984}
985void AddressbookWindow::slotWrapAround()
986{
987 qWarning("Got wrap signal !");
988 if ( doNotifyWrapAround )
989 QMessageBox::information( this, tr( "End of list" ),
990 tr( "End of list. Wrap around now.. !" ) + "\n" );
991
992}
993
962void AddressbookWindow::slotSetCategory( int c ) 994void AddressbookWindow::slotSetCategory( int c )
963{ 995{
964 996
965 QString cat, book; 997 QString cat, book;
966 998
967 if ( c <= 0 ) 999 if ( c <= 0 )
968 return; 1000 return;
969 1001
970 // Set checkItem for selected one 1002 // Set checkItem for selected one
971 for ( unsigned int i = 1; i < catMenu->count(); i++ ) 1003 for ( unsigned int i = 1; i < catMenu->count(); i++ )
972 catMenu->setItemChecked( i, c == (int)i ); 1004 catMenu->setItemChecked( i, c == (int)i );
973 1005
974 for ( unsigned int i = 1; i < catMenu->count(); i++ ) { 1006 for ( unsigned int i = 1; i < catMenu->count(); i++ ) {
975 if (catMenu->isItemChecked( i )) { 1007 if (catMenu->isItemChecked( i )) {
976 if ( i == 1 ) // default List view 1008 if ( i == 1 ) // default List view
977 book = QString::null; 1009 book = QString::null;
978 else if ( i == 2 ) 1010 else if ( i == 2 )
979 book = "Phone"; 1011 book = "Phone";
980 else if ( i == 3 ) 1012 else if ( i == 3 )
981 book = "Company"; 1013 book = "Company";
982 else if ( i == 4 ) 1014 else if ( i == 4 )
983 book = "Email"; 1015 book = "Email";
984 else if ( i == 5 ) 1016 else if ( i == 5 )
985 book = "Cards"; 1017 book = "Cards";
986 else if ( i == 6 ) // default All Categories 1018 else if ( i == 6 ) // default All Categories
987 cat = QString::null; 1019 cat = QString::null;
988 else if ( i == (unsigned int)catMenu->count() ) // last menu option will be Unfiled 1020 else if ( i == (unsigned int)catMenu->count() ) // last menu option will be Unfiled
989 cat = "Unfiled"; 1021 cat = "Unfiled";
990 else 1022 else
991 cat = abList->categories()[i - 7]; 1023 cat = abList->categories()[i - 7];
992 } 1024 }
993 } 1025 }
994 1026
995 abList->setShowCategory( book, cat ); 1027 abList->setShowCategory( book, cat );
996 1028
997 if ( book.isEmpty() ) 1029 if ( book.isEmpty() )
998 book = "List"; 1030 book = "List";
999 if ( cat.isEmpty() ) 1031 if ( cat.isEmpty() )
1000 cat = "All"; 1032 cat = "All";
1001 1033
1002 setCaption( tr( "Contacts" ) + " - " + tr( book ) + " - " + tr( cat ) ); 1034 setCaption( tr( "Contacts" ) + " - " + tr( book ) + " - " + tr( cat ) );
1003} 1035}
1004 1036
1005void AddressbookWindow::slotSetLetter( char c ) { 1037void AddressbookWindow::slotSetLetter( char c ) {
1006 1038
1007 abList->setShowByLetter( c ); 1039 abList->setShowByLetter( c );
1008 1040
1009} 1041}