summaryrefslogtreecommitdiff
path: root/core/pim/addressbook/addressbook.cpp
Unidiff
Diffstat (limited to 'core/pim/addressbook/addressbook.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/pim/addressbook/addressbook.cpp43
1 files changed, 42 insertions, 1 deletions
diff --git a/core/pim/addressbook/addressbook.cpp b/core/pim/addressbook/addressbook.cpp
index 3466801..39d8321 100644
--- a/core/pim/addressbook/addressbook.cpp
+++ b/core/pim/addressbook/addressbook.cpp
@@ -59,59 +59,65 @@
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 doNotifyWrapAround(true), 81 doNotifyWrapAround(true),
82 caseSensitive(false), 82 caseSensitive(false),
83 m_useQtMail(true),
84 m_useOpieMail(false),
83 bAbEditFirstTime(TRUE), 85 bAbEditFirstTime(TRUE),
84 syncing(FALSE) 86 syncing(FALSE)
85{ 87{
86 isLoading = true; 88 isLoading = true;
87 89
88 // Read Config settings 90 // Read Config settings
89 Config cfg("AddressBook"); 91 Config cfg("AddressBook");
90 cfg.setGroup("Search"); 92 cfg.setGroup("Search");
91 useRegExp = cfg.readBoolEntry( "useRegExp" ); 93 useRegExp = cfg.readBoolEntry( "useRegExp" );
92 caseSensitive = cfg.readBoolEntry( "caseSensitive" ); 94 caseSensitive = cfg.readBoolEntry( "caseSensitive" );
93 doNotifyWrapAround = cfg.readBoolEntry( "doNotifyWrapAround" ); 95 doNotifyWrapAround = cfg.readBoolEntry( "doNotifyWrapAround" );
96 cfg.setGroup("Mail");
97 m_useQtMail = cfg.readBoolEntry( "useQtMail" );
98 m_useOpieMail=cfg.readBoolEntry( "useOpieMail" );
99
94 100
95 initFields(); 101 initFields();
96 102
97 setCaption( tr("Contacts") ); 103 setCaption( tr("Contacts") );
98 setIcon( Resource::loadPixmap( "AddressBook" ) ); 104 setIcon( Resource::loadPixmap( "AddressBook" ) );
99 105
100 setToolBarsMovable( FALSE ); 106 setToolBarsMovable( FALSE );
101 107
102 // Create Toolbars 108 // Create Toolbars
103 109
104 QPEToolBar *bar = new QPEToolBar( this ); 110 QPEToolBar *bar = new QPEToolBar( this );
105 bar->setHorizontalStretchable( TRUE ); 111 bar->setHorizontalStretchable( TRUE );
106 112
107 QPEMenuBar *mbList = new QPEMenuBar( bar ); 113 QPEMenuBar *mbList = new QPEMenuBar( bar );
108 mbList->setMargin( 0 ); 114 mbList->setMargin( 0 );
109 115
110 QPopupMenu *edit = new QPopupMenu( this ); 116 QPopupMenu *edit = new QPopupMenu( this );
111 mbList->insertItem( tr( "Contact" ), edit ); 117 mbList->insertItem( tr( "Contact" ), edit );
112 118
113 listTools = new QPEToolBar( this, "list operations" ); 119 listTools = new QPEToolBar( this, "list operations" );
114 120
115 121
116 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 122 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null,
117 0, this, 0 ); 123 0, this, 0 );
@@ -148,49 +154,49 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name,
148 actionFind = a; 154 actionFind = a;
149 connect( a, SIGNAL(activated()), this, SLOT( slotFindOpen()) ); 155 connect( a, SIGNAL(activated()), this, SLOT( slotFindOpen()) );
150 a->addTo( edit ); 156 a->addTo( edit );
151 a->addTo( listTools ); 157 a->addTo( listTools );
152 158
153 // Much better search widget, taken from QTReader.. (se) 159 // Much better search widget, taken from QTReader.. (se)
154 searchBar = new OFloatBar( "Search", this, QMainWindow::Top, TRUE ); 160 searchBar = new OFloatBar( "Search", this, QMainWindow::Top, TRUE );
155 searchBar->setHorizontalStretchable( TRUE ); 161 searchBar->setHorizontalStretchable( TRUE );
156 searchBar->hide(); 162 searchBar->hide();
157 searchEdit = new QLineEdit( searchBar, "searchEdit" ); 163 searchEdit = new QLineEdit( searchBar, "searchEdit" );
158// QFont f("unifont", 16 /*, QFont::Bold*/); 164// QFont f("unifont", 16 /*, QFont::Bold*/);
159// searchEdit->setFont( f ); 165// searchEdit->setFont( f );
160 searchBar->setStretchableWidget( searchEdit ); 166 searchBar->setStretchableWidget( searchEdit );
161 connect( searchEdit, SIGNAL( returnPressed( ) ), 167 connect( searchEdit, SIGNAL( returnPressed( ) ),
162 this, SLOT( slotFind( ) ) ); 168 this, SLOT( slotFind( ) ) );
163 169
164 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); 170 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 );
165 connect( a, SIGNAL( activated() ), this, SLOT( slotFindNext() ) ); 171 connect( a, SIGNAL( activated() ), this, SLOT( slotFindNext() ) );
166 a->addTo( searchBar ); 172 a->addTo( searchBar );
167 173
168 a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); 174 a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
169 connect( a, SIGNAL( activated() ), this, SLOT( slotFindClose() ) ); 175 connect( a, SIGNAL( activated() ), this, SLOT( slotFindClose() ) );
170 a->addTo( searchBar ); 176 a->addTo( searchBar );
171 177
172 a = new QAction( tr( "Write Mail To" ), Resource::loadPixmap( "qtmail/reply" ), 178 a = new QAction( tr( "Write Mail To" ), Resource::loadPixmap( "mail/sendmail" ),
173 QString::null, 0, this, 0 ); 179 QString::null, 0, this, 0 );
174 //a->setEnabled( FALSE ); we got support for it now :) zecke 180 //a->setEnabled( FALSE ); we got support for it now :) zecke
175 actionMail = a; 181 actionMail = a;
176 connect( a, SIGNAL( activated() ), this, SLOT( writeMail() ) ); 182 connect( a, SIGNAL( activated() ), this, SLOT( writeMail() ) );
177 a->addTo( edit ); 183 a->addTo( edit );
178 a->addTo( listTools ); 184 a->addTo( listTools );
179 185
180 186
181 187
182 if ( Ir::supported() ) { 188 if ( Ir::supported() ) {
183 a = new QAction( tr ("Beam Entry" ), Resource::loadPixmap( "beam" ), QString::null, 189 a = new QAction( tr ("Beam Entry" ), Resource::loadPixmap( "beam" ), QString::null,
184 0, this, 0 ); 190 0, this, 0 );
185 actionBeam = a; 191 actionBeam = a;
186 connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) ); 192 connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) );
187 a->addTo( edit ); 193 a->addTo( edit );
188 a->addTo( listTools ); 194 a->addTo( listTools );
189 } 195 }
190 196
191 edit->insertSeparator(); 197 edit->insertSeparator();
192 198
193 a = new QAction( tr("Import vCard"), QString::null, 0, 0, 0, TRUE ); 199 a = new QAction( tr("Import vCard"), QString::null, 0, 0, 0, TRUE );
194 actionPersonal = a; 200 actionPersonal = a;
195 connect( a, SIGNAL( activated() ), this, SLOT( importvCard() ) ); 201 connect( a, SIGNAL( activated() ), this, SLOT( importvCard() ) );
196 a->addTo( edit ); 202 a->addTo( edit );
@@ -261,54 +267,58 @@ AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name,
261 fontMenu->insertItem(tr( "Normal" ), 1); 267 fontMenu->insertItem(tr( "Normal" ), 1);
262 fontMenu->insertItem(tr( "Large" ), 2); 268 fontMenu->insertItem(tr( "Large" ), 2);
263 269
264 defaultFont = new QFont( abList->font() ); 270 defaultFont = new QFont( abList->font() );
265 271
266 slotSetFont(startFontSize); 272 slotSetFont(startFontSize);
267 273
268 mbList->insertItem( tr("Font"), fontMenu); 274 mbList->insertItem( tr("Font"), fontMenu);
269 setCentralWidget(listContainer); 275 setCentralWidget(listContainer);
270 276
271 // qDebug("adressbook contrsuction: t=%d", t.elapsed() ); 277 // qDebug("adressbook contrsuction: t=%d", t.elapsed() );
272 278
273 abList->setCurrentCell( 0, 0 ); 279 abList->setCurrentCell( 0, 0 );
274 280
275 isLoading = false; 281 isLoading = false;
276} 282}
277 283
278 284
279void AddressbookWindow::slotConfig() 285void AddressbookWindow::slotConfig()
280{ 286{
281 ConfigDlg* dlg = new ConfigDlg( this, "Config" ); 287 ConfigDlg* dlg = new ConfigDlg( this, "Config" );
282 dlg -> setUseRegExp ( useRegExp ); 288 dlg -> setUseRegExp ( useRegExp );
283 dlg -> setBeCaseSensitive( caseSensitive ); 289 dlg -> setBeCaseSensitive( caseSensitive );
284 dlg -> setSignalWrapAround( doNotifyWrapAround ); 290 dlg -> setSignalWrapAround( doNotifyWrapAround );
291 dlg -> setQtMail ( m_useQtMail );
292 dlg -> setOpieMail ( m_useOpieMail );
285 dlg -> showMaximized(); 293 dlg -> showMaximized();
286 if ( dlg -> exec() ) { 294 if ( dlg -> exec() ) {
287 qWarning ("Config Dialog accepted !"); 295 qWarning ("Config Dialog accepted !");
288 useRegExp = dlg -> useRegExp(); 296 useRegExp = dlg -> useRegExp();
289 caseSensitive = dlg -> beCaseSensitive(); 297 caseSensitive = dlg -> beCaseSensitive();
290 doNotifyWrapAround = dlg -> signalWrapAround(); 298 doNotifyWrapAround = dlg -> signalWrapAround();
299 m_useQtMail = dlg -> useQtMail();
300 m_useOpieMail= dlg -> useOpieMail();
291 } 301 }
292 302
293 delete dlg; 303 delete dlg;
294} 304}
295 305
296 306
297void AddressbookWindow::slotSetFont( int size ) { 307void AddressbookWindow::slotSetFont( int size ) {
298 308
299 if (size > 2 || size < 0) 309 if (size > 2 || size < 0)
300 size = 1; 310 size = 1;
301 311
302 startFontSize = size; 312 startFontSize = size;
303 313
304 QFont *currentFont; 314 QFont *currentFont;
305 315
306 switch (size) { 316 switch (size) {
307 case 0: 317 case 0:
308 fontMenu->setItemChecked(0, true); 318 fontMenu->setItemChecked(0, true);
309 fontMenu->setItemChecked(1, false); 319 fontMenu->setItemChecked(1, false);
310 fontMenu->setItemChecked(2, false); 320 fontMenu->setItemChecked(2, false);
311 abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) ); 321 abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) );
312 currentFont = new QFont (abList->font()); 322 currentFont = new QFont (abList->font());
313 // abList->resizeRows(currentFont->pixelSize() + 7); 323 // abList->resizeRows(currentFont->pixelSize() + 7);
314 abList->resizeRows(); 324 abList->resizeRows();
@@ -359,48 +369,51 @@ void AddressbookWindow::setDocument( const QString &filename )
359 } 369 }
360 370
361} 371}
362 372
363void AddressbookWindow::resizeEvent( QResizeEvent *e ) 373void AddressbookWindow::resizeEvent( QResizeEvent *e )
364{ 374{
365 QMainWindow::resizeEvent( e ); 375 QMainWindow::resizeEvent( e );
366 376
367 if ( centralWidget() == listContainer ) 377 if ( centralWidget() == listContainer )
368 showList(); 378 showList();
369 else if ( centralWidget() == mView ) 379 else if ( centralWidget() == mView )
370 showView(); 380 showView();
371} 381}
372 382
373AddressbookWindow::~AddressbookWindow() 383AddressbookWindow::~AddressbookWindow()
374{ 384{
375 Config cfg("AddressBook"); 385 Config cfg("AddressBook");
376 cfg.setGroup("Font"); 386 cfg.setGroup("Font");
377 cfg.writeEntry("fontSize", startFontSize); 387 cfg.writeEntry("fontSize", startFontSize);
378 388
379 cfg.setGroup("Search"); 389 cfg.setGroup("Search");
380 cfg.writeEntry("useRegExp", useRegExp); 390 cfg.writeEntry("useRegExp", useRegExp);
381 cfg.writeEntry("caseSensitive", caseSensitive); 391 cfg.writeEntry("caseSensitive", caseSensitive);
382 cfg.writeEntry("doNotifyWrapAround", doNotifyWrapAround); 392 cfg.writeEntry("doNotifyWrapAround", doNotifyWrapAround);
393 cfg.setGroup("Mail");
394 cfg.writeEntry( "useQtMail", m_useQtMail );
395 cfg.writeEntry( "useOpieMail", m_useOpieMail);
383} 396}
384 397
385void AddressbookWindow::slotUpdateToolbar() 398void AddressbookWindow::slotUpdateToolbar()
386{ 399{
387 OContact ce = abList->currentEntry(); 400 OContact ce = abList->currentEntry();
388 actionMail->setEnabled( !ce.defaultEmail().isEmpty() ); 401 actionMail->setEnabled( !ce.defaultEmail().isEmpty() );
389} 402}
390 403
391void AddressbookWindow::showList() 404void AddressbookWindow::showList()
392{ 405{
393 bool visiblemView; 406 bool visiblemView;
394 407
395 visiblemView = false; 408 visiblemView = false;
396 if ( mView ) { 409 if ( mView ) {
397 mView->hide(); 410 mView->hide();
398 visiblemView = true; 411 visiblemView = true;
399 } 412 }
400 setCentralWidget( listContainer ); 413 setCentralWidget( listContainer );
401 listContainer->show(); 414 listContainer->show();
402 // update our focues... (or use a stack widget!); 415 // update our focues... (or use a stack widget!);
403 abList->setFocus(); 416 abList->setFocus();
404 417
405 // This makes sure we are scrolled all the way to the left 418 // This makes sure we are scrolled all the way to the left
406 abList->setContentsPos( 0, abList->contentsY() ); 419 abList->setContentsPos( 0, abList->contentsY() );
@@ -473,50 +486,78 @@ void AddressbookWindow::slotViewBack()
473 486
474void AddressbookWindow::slotViewEdit() 487void AddressbookWindow::slotViewEdit()
475{ 488{
476 if(!syncing) { 489 if(!syncing) {
477 if (actionPersonal->isOn()) { 490 if (actionPersonal->isOn()) {
478 editPersonal(); 491 editPersonal();
479 } else { 492 } else {
480 if ( !bAbEditFirstTime ) 493 if ( !bAbEditFirstTime )
481 abEditor->setEntry( abList->currentEntry() ); 494 abEditor->setEntry( abList->currentEntry() );
482 editEntry( EditEntry ); 495 editEntry( EditEntry );
483 } 496 }
484 } else { 497 } else {
485 QMessageBox::warning( this, tr("Contacts"), 498 QMessageBox::warning( this, tr("Contacts"),
486 tr("Can not edit data, currently syncing") ); 499 tr("Can not edit data, currently syncing") );
487 } 500 }
488} 501}
489 502
490 503
491 504
492void AddressbookWindow::writeMail() 505void AddressbookWindow::writeMail()
493{ 506{
494 OContact c = abList->currentEntry(); 507 OContact c = abList->currentEntry();
495 QString name = c.fileAs(); 508 QString name = c.fileAs();
496 QString email = c.defaultEmail(); 509 QString email = c.defaultEmail();
510
511 // I prefer the OPIE-Environment variable before the
512 // QPE-one..
513 QString basepath = QString::fromLatin1( getenv("OPIEDIR") );
514 if ( basepath.isEmpty() )
515 basepath = QString::fromLatin1( getenv("QPEDIR") );
516
517 // Try to access the preferred. If not possible, try to
518 // switch to the other one..
519 if ( m_useQtMail ){
520 qWarning ("Accessing: %s", (basepath + "/bin/qtmail").latin1());
521 if ( QFile::exists( basepath + "/bin/qtmail" ) ){
522 qWarning ("QCop");
497 QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)"); 523 QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)");
498 e << name << email; 524 e << name << email;
525 return;
526 } else
527 m_useOpieMail = true;
528 }
529 if ( m_useOpieMail ){
530 qWarning ("Accessing: %s", (basepath + "/bin/mail").latin1());
531 if ( QFile::exists( basepath + "/bin/mail" ) ){
532 qWarning ("QCop");
533 QCopEnvelope e("QPE/Application/mail", "writeMail(QString,QString)");
534 e << name << email;
535 return;
536 } else
537 m_useQtMail = true;
538 }
539
499} 540}
500 541
501static const char * beamfile = "/tmp/obex/contact.vcf"; 542static const char * beamfile = "/tmp/obex/contact.vcf";
502 543
503void AddressbookWindow::slotBeam() 544void AddressbookWindow::slotBeam()
504{ 545{
505 QString filename; 546 QString filename;
506 OContact c; 547 OContact c;
507 if ( actionPersonal->isOn() ) { 548 if ( actionPersonal->isOn() ) {
508 filename = addressbookPersonalVCardName(); 549 filename = addressbookPersonalVCardName();
509 if (!QFile::exists(filename)) 550 if (!QFile::exists(filename))
510 return; // can't beam a non-existent file 551 return; // can't beam a non-existent file
511 c = OContact::readVCard( filename )[0]; 552 c = OContact::readVCard( filename )[0];
512 } else { 553 } else {
513 unlink( beamfile ); // delete if exists 554 unlink( beamfile ); // delete if exists
514 c = abList->currentEntry(); 555 c = abList->currentEntry();
515 mkdir("/tmp/obex/", 0755); 556 mkdir("/tmp/obex/", 0755);
516 OContact::writeVCard( beamfile, c ); 557 OContact::writeVCard( beamfile, c );
517 filename = beamfile; 558 filename = beamfile;
518 } 559 }
519 Ir *ir = new Ir( this ); 560 Ir *ir = new Ir( this );
520 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 561 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
521 QString description = c.fullName(); 562 QString description = c.fullName();
522 ir->send( filename, description, "text/x-vCard" ); 563 ir->send( filename, description, "text/x-vCard" );