summaryrefslogtreecommitdiffabout
path: root/kabc/addresseeview.cpp
authorzautrix <zautrix>2004-09-18 18:46:29 (UTC)
committer zautrix <zautrix>2004-09-18 18:46:29 (UTC)
commitec8099bf369e5b8327ca6cfd78b34366353e3abf (patch) (unidiff)
tree551c515124f7b1c47b2860803efa3922f494f938 /kabc/addresseeview.cpp
parent3f16c7aa0ab6badf304c537a6981ece743138821 (diff)
downloadkdepimpi-ec8099bf369e5b8327ca6cfd78b34366353e3abf.zip
kdepimpi-ec8099bf369e5b8327ca6cfd78b34366353e3abf.tar.gz
kdepimpi-ec8099bf369e5b8327ca6cfd78b34366353e3abf.tar.bz2
More AB sync
Diffstat (limited to 'kabc/addresseeview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addresseeview.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/kabc/addresseeview.cpp b/kabc/addresseeview.cpp
index b4717d7..487e8a5 100644
--- a/kabc/addresseeview.cpp
+++ b/kabc/addresseeview.cpp
@@ -1,129 +1,134 @@
1/* 1/*
2 This file is part of libkdepim. 2 This file is part of libkdepim.
3 3
4 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 4 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#include <kabc/address.h> 22#include <kabc/address.h>
23#include <kabc/addressee.h> 23#include <kabc/addressee.h>
24#include <kabc/phonenumber.h> 24#include <kabc/phonenumber.h>
25#include <kglobal.h> 25#include <kglobal.h>
26//US#include <kglobalsettings.h> 26//US#include <kglobalsettings.h>
27#include <kiconloader.h> 27#include <kiconloader.h>
28#include <klocale.h> 28#include <klocale.h>
29//US #include <kstringhandler.h> 29//US #include <kstringhandler.h>
30#include <qscrollview.h> 30#include <qscrollview.h>
31#include <qregexp.h> 31#include <qregexp.h>
32#include <qfile.h> 32#include <qfile.h>
33#include <qvbox.h>
34#include <qlabel.h>
35#include <qwidget.h>
36#include <qlayout.h>
33#include <qapplication.h> 37#include <qapplication.h>
38#include <qpushbutton.h>
34 39
35 40
36#include "externalapphandler.h" 41#include "externalapphandler.h"
37#include "addresseeview.h" 42#include "addresseeview.h"
38 43
39 44
40//US #ifndef DESKTOP_VERSION 45//US #ifndef DESKTOP_VERSION
41//US #include <qtopia/qcopenvelope_qws.h> 46//US #include <qtopia/qcopenvelope_qws.h>
42//US #include <qpe/qpeapplication.h> 47//US #include <qpe/qpeapplication.h>
43//US #endif 48//US #endif
44 49
45//US static int kphoneInstalled = 0; 50//US static int kphoneInstalled = 0;
46 51
47using namespace KPIM; 52using namespace KPIM;
48 53
49AddresseeView::AddresseeView( QWidget *parent, const char *name ) 54AddresseeView::AddresseeView( QWidget *parent, const char *name )
50//US : KTextBrowser( parent, name ) 55//US : KTextBrowser( parent, name )
51 : QTextBrowser( parent, name ) 56 : QTextBrowser( parent, name )
52 57
53 58
54{ 59{
55//US setWrapPolicy( QTextEdit::AtWordBoundary ); 60//US setWrapPolicy( QTextEdit::AtWordBoundary );
56 setLinkUnderline( false ); 61 setLinkUnderline( false );
57 // setVScrollBarMode( QScrollView::AlwaysOff ); 62 // setVScrollBarMode( QScrollView::AlwaysOff );
58 //setHScrollBarMode( QScrollView::AlwaysOff ); 63 //setHScrollBarMode( QScrollView::AlwaysOff );
59 64
60//US QStyleSheet *sheet = styleSheet(); 65//US QStyleSheet *sheet = styleSheet();
61//US QStyleSheetItem *link = sheet->item( "a" ); 66//US QStyleSheetItem *link = sheet->item( "a" );
62//US link->setColor( KGlobalSettings::linkColor() ); 67//US link->setColor( KGlobalSettings::linkColor() );
63 68
64} 69}
65 70
66void AddresseeView::setSource(const QString& n) 71void AddresseeView::setSource(const QString& n)
67{ 72{
68 //qDebug("********AddresseeView::setSource %s", n.latin1()); 73 //qDebug("********AddresseeView::setSource %s", n.latin1());
69 74
70 if ( n.left( 6 ) == "mailto" ) 75 if ( n.left( 6 ) == "mailto" )
71 ExternalAppHandler::instance()->mailToOneContact( n.mid(7) ); 76 ExternalAppHandler::instance()->mailToOneContact( n.mid(7) );
72 else if ( n.left( 7 ) == "phoneto" ) 77 else if ( n.left( 7 ) == "phoneto" )
73 ExternalAppHandler::instance()->callByPhone( n.mid(8) ); 78 ExternalAppHandler::instance()->callByPhone( n.mid(8) );
74 else if ( n.left( 5 ) == "faxto" ) 79 else if ( n.left( 5 ) == "faxto" )
75 ExternalAppHandler::instance()->callByFax( n.mid(6) ); 80 ExternalAppHandler::instance()->callByFax( n.mid(6) );
76 else if ( n.left( 5 ) == "smsto" ) 81 else if ( n.left( 5 ) == "smsto" )
77 ExternalAppHandler::instance()->callBySMS( n.mid(6) ); 82 ExternalAppHandler::instance()->callBySMS( n.mid(6) );
78 else if ( n.left( 7 ) == "pagerto" ) 83 else if ( n.left( 7 ) == "pagerto" )
79 ExternalAppHandler::instance()->callByPager( n.mid(8) ); 84 ExternalAppHandler::instance()->callByPager( n.mid(8) );
80 else if ( n.left( 5 ) == "sipto" ) 85 else if ( n.left( 5 ) == "sipto" )
81 ExternalAppHandler::instance()->callBySIP( n.mid(6) ); 86 ExternalAppHandler::instance()->callBySIP( n.mid(6) );
82 87
83} 88}
84void AddresseeView::setAddressee( const KABC::Addressee& addr ) 89void AddresseeView::setAddressee( const KABC::Addressee& addr )
85{ 90{
86 ExternalAppHandler* eah = ExternalAppHandler::instance(); 91 ExternalAppHandler* eah = ExternalAppHandler::instance();
87 bool kemailAvail = eah->isEmailAppAvailable(); 92 bool kemailAvail = eah->isEmailAppAvailable();
88 bool kphoneAvail = eah->isPhoneAppAvailable(); 93 bool kphoneAvail = eah->isPhoneAppAvailable();
89 bool kfaxAvail = eah->isFaxAppAvailable(); 94 bool kfaxAvail = eah->isFaxAppAvailable();
90 bool ksmsAvail = eah->isSMSAppAvailable(); 95 bool ksmsAvail = eah->isSMSAppAvailable();
91 bool kpagerAvail = eah->isPagerAppAvailable(); 96 bool kpagerAvail = eah->isPagerAppAvailable();
92 bool ksipAvail = eah->isSIPAppAvailable(); 97 bool ksipAvail = eah->isSIPAppAvailable();
93 98
94 99
95 mAddressee = addr; 100 mAddressee = addr;
96 // clear view 101 // clear view
97 setText( QString::null ); 102 setText( QString::null );
98 103
99 if ( mAddressee.isEmpty() ) 104 if ( mAddressee.isEmpty() )
100 return; 105 return;
101 106
102 QString name = ( mAddressee.assembledName().isEmpty() ? 107 QString name = ( mAddressee.assembledName().isEmpty() ?
103 mAddressee.formattedName() : mAddressee.assembledName() ); 108 mAddressee.formattedName() : mAddressee.assembledName() );
104 109
105 QString dynamicPart; 110 QString dynamicPart;
106 111
107 QStringList emails = mAddressee.emails(); 112 QStringList emails = mAddressee.emails();
108 QStringList::ConstIterator emailIt; 113 QStringList::ConstIterator emailIt;
109 QString type = i18n( "Email" ); 114 QString type = i18n( "Email" );
110 emailIt = emails.begin(); 115 emailIt = emails.begin();
111 if ( emailIt != emails.end() ) { 116 if ( emailIt != emails.end() ) {
112 if ( kemailAvail ) { 117 if ( kemailAvail ) {
113 dynamicPart += QString( 118 dynamicPart += QString(
114 "<tr><td align=\"right\"><b>%1</b></td>" 119 "<tr><td align=\"right\"><b>%1</b></td>"
115 "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" ) 120 "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" )
116 .arg( type ) 121 .arg( type )
117 .arg( name ) 122 .arg( name )
118 .arg( *emailIt ) 123 .arg( *emailIt )
119 .arg( *emailIt ); 124 .arg( *emailIt );
120 ++emailIt; 125 ++emailIt;
121 } else { 126 } else {
122 dynamicPart += QString( 127 dynamicPart += QString(
123 "<tr><td align=\"right\"><b>%1</b></td>" 128 "<tr><td align=\"right\"><b>%1</b></td>"
124 "<td align=\"left\">%2</td></tr>" ) 129 "<td align=\"left\">%2</td></tr>" )
125 .arg( type ) 130 .arg( type )
126 .arg( *emailIt ); 131 .arg( *emailIt );
127 ++emailIt; 132 ++emailIt;
128 } 133 }
129 } 134 }
@@ -306,96 +311,157 @@ void AddresseeView::setAddressee( const KABC::Addressee& addr )
306 "<td colspan=\"2\">&nbsp;</td>" 311 "<td colspan=\"2\">&nbsp;</td>"
307 "%7" // dynamic part 312 "%7" // dynamic part
308 "%8" // notes 313 "%8" // notes
309 "</table>" 314 "</table>"
310 "</body>" 315 "</body>"
311 "</html>") 316 "</html>")
312//US 317//US
313 .arg( /*KGlobalSettings::textColor().name()*/ "black" ) 318 .arg( /*KGlobalSettings::textColor().name()*/ "black" )
314//US 319//US
315 .arg( /*KGlobalSettings::baseColor().name()*/ "white" ) 320 .arg( /*KGlobalSettings::baseColor().name()*/ "white" )
316 .arg( picString ) 321 .arg( picString )
317 .arg( name ) 322 .arg( name )
318 .arg( aRole ) 323 .arg( aRole )
319 .arg( aOrga ) 324 .arg( aOrga )
320 .arg( dynamicPart ) 325 .arg( dynamicPart )
321 .arg( notes ); 326 .arg( notes );
322 327
323 } else { // no picture! 328 } else { // no picture!
324 329
325mText = "<table width=\"100%\">\n"; 330mText = "<table width=\"100%\">\n";
326 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>"; 331 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>";
327#ifdef DESKTOP_VERSION 332#ifdef DESKTOP_VERSION
328 mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h1>"; 333 mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h1>";
329#else 334#else
330 mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h2>"; 335 mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h2>";
331#endif 336#endif
332 337
333#ifdef DESKTOP_VERSION 338#ifdef DESKTOP_VERSION
334 mText += "<font color=\"#FFFFFF\"> <em>" + name+"</em></font></h1>"; 339 mText += "<font color=\"#FFFFFF\"> <em>" + name+"</em></font></h1>";
335#else 340#else
336 mText += "<font color=\"#FFFFFF\"> <em>" + name +"</em></font></h2>"; 341 mText += "<font color=\"#FFFFFF\"> <em>" + name +"</em></font></h2>";
337#endif 342#endif
338 mText += "</td></tr>\n<tr bgcolor=\"#EAF8FA\"><td>"; 343 mText += "</td></tr>\n<tr bgcolor=\"#EAF8FA\"><td>";
339 344
340 mText += "<table><td colspan=\"2\">&nbsp;</td>"; 345 mText += "<table><td colspan=\"2\">&nbsp;</td>";
341 /* 346 /*
342 mText += QString("<tr><td align=\"right\"><b2>%1</b2></td>" 347 mText += QString("<tr><td align=\"right\"><b2>%1</b2></td>"
343 "<td align=\"left\"><b>%2</b></td></tr>" ) 348 "<td align=\"left\"><b>%2</b></td></tr>" )
344 .arg( i18n(" ") ) 349 .arg( i18n(" ") )
345 .arg( name ); 350 .arg( name );
346 */ 351 */
347 if ( ! mAddressee.role().isEmpty() ) 352 if ( ! mAddressee.role().isEmpty() )
348 mText += QString("<tr><td align=\"right\"><b>%1</b></td>" 353 mText += QString("<tr><td align=\"right\"><b>%1</b></td>"
349 "<td align=\"left\">%2</td></tr>" ) 354 "<td align=\"left\">%2</td></tr>" )
350 .arg( i18n(" ") ) 355 .arg( i18n(" ") )
351 .arg( mAddressee.role()); 356 .arg( mAddressee.role());
352 if ( ! mAddressee.organization().isEmpty() ) 357 if ( ! mAddressee.organization().isEmpty() )
353 mText += QString("<tr><td align=\"right\"><b>%1</b></td>" 358 mText += QString("<tr><td align=\"right\"><b>%1</b></td>"
354 "<td align=\"left\">%2</td></tr>" ) 359 "<td align=\"left\">%2</td></tr>" )
355 .arg( i18n(" ") ) 360 .arg( i18n(" ") )
356 .arg( mAddressee.organization()); 361 .arg( mAddressee.organization());
357 mText += dynamicPart; 362 mText += dynamicPart;
358 mText += notes; 363 mText += notes;
359 mText += "</table>"; 364 mText += "</table>";
360 365
361 } 366 }
362 367
363 // at last display it... 368 // at last display it...
364 setText( mText ); 369 setText( mText );
365 370
366} 371}
367 372
368KABC::Addressee AddresseeView::addressee() const 373KABC::Addressee AddresseeView::addressee() const
369{ 374{
370 return mAddressee; 375 return mAddressee;
371} 376}
372void AddresseeView::addTag(const QString & tag,const QString & text) 377void AddresseeView::addTag(const QString & tag,const QString & text)
373{ 378{
374 if ( text.isEmpty() ) 379 if ( text.isEmpty() )
375 return; 380 return;
376 int number=text.contains("\n"); 381 int number=text.contains("\n");
377 QString str = "<" + tag + ">"; 382 QString str = "<" + tag + ">";
378 QString tmpText=text; 383 QString tmpText=text;
379 QString tmpStr=str; 384 QString tmpStr=str;
380 if(number !=-1) 385 if(number !=-1)
381 { 386 {
382 if (number > 0) { 387 if (number > 0) {
383 int pos=0; 388 int pos=0;
384 QString tmp; 389 QString tmp;
385 for(int i=0;i<=number;i++) { 390 for(int i=0;i<=number;i++) {
386 pos=tmpText.find("\n"); 391 pos=tmpText.find("\n");
387 tmp=tmpText.left(pos); 392 tmp=tmpText.left(pos);
388 tmpText=tmpText.right(tmpText.length()-pos-1); 393 tmpText=tmpText.right(tmpText.length()-pos-1);
389 tmpStr+=tmp+"<br>"; 394 tmpStr+=tmp+"<br>";
390 } 395 }
391 } 396 }
392 else tmpStr += tmpText; 397 else tmpStr += tmpText;
393 tmpStr+="</" + tag + ">"; 398 tmpStr+="</" + tag + ">";
394 mText.append(tmpStr); 399 mText.append(tmpStr);
395 } 400 }
396 else 401 else
397 { 402 {
398 str += text + "</" + tag + ">"; 403 str += text + "</" + tag + ">";
399 mText.append(str); 404 mText.append(str);
400 } 405 }
401} 406}
407
408AddresseeChooser::AddresseeChooser( KABC::Addressee loc, KABC::Addressee rem, bool takeloc, QWidget *parent, const char *name ) : KDialogBase(parent,name,
409 true ,i18n("Conflict! Please choose Adressee!"),Ok|User1|Close,Close, false)
410{
411 findButton( Close )->setText( i18n("Cancel Sync"));
412 findButton( Ok )->setText( i18n("Remote"));
413 findButton( User1 )->setText( i18n("Local"));
414 QWidget* topframe = new QWidget( this );
415 //QVBox* topframe = new QVBox( this );
416 setMainWidget( topframe );
417 QBoxLayout* bl;
418 if ( QApplication::desktop()->width() < 640 ) {
419 bl = new QVBoxLayout( topframe );
420
421 } else {
422 bl = new QHBoxLayout( topframe );
423
424 }
425 QVBox* subframe = new QVBox( topframe );
426 bl->addWidget(subframe );
427 QLabel* lab = new QLabel( i18n("Local Addressee"), subframe );
428 AddresseeView * av = new AddresseeView( subframe );
429 av->setAddressee( loc );
430 subframe = new QVBox( topframe );
431 bl->addWidget(subframe );
432 lab = new QLabel( i18n("Remote Addressee"), subframe );
433 av = new AddresseeView( subframe );
434 av->setAddressee( rem );
435
436 QObject::connect(findButton( Ok ),SIGNAL(clicked()),
437 SLOT(slot_remote()));
438 QObject::connect(this,SIGNAL(user1Clicked()),
439 SLOT(slot_local()));
440#ifndef DESKTOP_VERSION
441 showMaximized();
442#else
443 resize ( 640, 400 );
444#endif
445}
446
447int AddresseeChooser::executeD( bool local )
448{
449 mSyncResult = 3;
450 if ( local )
451 findButton( User1 )->setFocus();
452 else
453 findButton( Ok )->setFocus();
454 exec();
455 qDebug("returning %d ",mSyncResult );
456 return mSyncResult;
457}
458void AddresseeChooser::slot_remote()
459{
460 mSyncResult = 2;
461 accept();
462}
463void AddresseeChooser::slot_local()
464{
465 mSyncResult = 1;
466 accept();
467}