summaryrefslogtreecommitdiffabout
path: root/kabc/addresseeview.cpp
Unidiff
Diffstat (limited to 'kabc/addresseeview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addresseeview.cpp38
1 files changed, 33 insertions, 5 deletions
diff --git a/kabc/addresseeview.cpp b/kabc/addresseeview.cpp
index 7a4336b..e85991e 100644
--- a/kabc/addresseeview.cpp
+++ b/kabc/addresseeview.cpp
@@ -1,134 +1,162 @@
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> 33#include <qvbox.h>
34#include <qlabel.h> 34#include <qlabel.h>
35#include <qwidget.h> 35#include <qwidget.h>
36#include <qlayout.h> 36#include <qlayout.h>
37#include <qapplication.h> 37#include <qapplication.h>
38#include <qpushbutton.h> 38#include <qpushbutton.h>
39#ifdef DESKTOP_VERSION
40#include <qpaintdevicemetrics.h>
41#include <qprinter.h>
42#include <qpainter.h>
43#endif
39 44
40 45
41#include "externalapphandler.h" 46#include "externalapphandler.h"
42#include "addresseeview.h" 47#include <kabc/addresseeview.h>
43 48
44 49
45//US #ifndef DESKTOP_VERSION 50//US #ifndef DESKTOP_VERSION
46//US #include <qtopia/qcopenvelope_qws.h> 51//US #include <qtopia/qcopenvelope_qws.h>
47//US #include <qpe/qpeapplication.h> 52//US #include <qpe/qpeapplication.h>
48//US #endif 53//US #endif
49 54
50//US static int kphoneInstalled = 0; 55//US static int kphoneInstalled = 0;
51 56
52using namespace KPIM; 57using namespace KABC;
53 58
54AddresseeView::AddresseeView( QWidget *parent, const char *name ) 59AddresseeView::AddresseeView( QWidget *parent, const char *name )
55//US : KTextBrowser( parent, name )
56 : QTextBrowser( parent, name ) 60 : QTextBrowser( parent, name )
57 61
58 62
59{ 63{
60//US setWrapPolicy( QTextEdit::AtWordBoundary ); 64//US setWrapPolicy( QTextEdit::AtWordBoundary );
61 setLinkUnderline( false ); 65 setLinkUnderline( false );
62 // setVScrollBarMode( QScrollView::AlwaysOff ); 66 // setVScrollBarMode( QScrollView::AlwaysOff );
63 //setHScrollBarMode( QScrollView::AlwaysOff ); 67 //setHScrollBarMode( QScrollView::AlwaysOff );
64 68
65//US QStyleSheet *sheet = styleSheet(); 69//US QStyleSheet *sheet = styleSheet();
66//US QStyleSheetItem *link = sheet->item( "a" ); 70//US QStyleSheetItem *link = sheet->item( "a" );
67//US link->setColor( KGlobalSettings::linkColor() ); 71//US link->setColor( KGlobalSettings::linkColor() );
68 72
69} 73}
70 74void AddresseeView::printMe()
75{
76#ifdef DESKTOP_VERSION
77 QPrinter printer;
78 if (!printer.setup() )
79 return;
80 QPainter p;
81 p.begin ( &printer );
82 QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer );
83 float dx, dy;
84 int wid = (m.width() * 9)/10;
85 dx = (float) wid/(float)contentsWidth ();
86 dy = (float)(m.height()) / (float)contentsHeight ();
87 float scale;
88 // scale to fit the width or height of the paper
89 if ( dx < dy )
90 scale = dx;
91 else
92 scale = dy;
93 p.translate( m.width()/10,0 );
94 p.scale( scale, scale );
95 drawContents ( &p, 0,0, contentsWidth (), contentsHeight () );
96 p.end();
97#endif
98}
71void AddresseeView::setSource(const QString& n) 99void AddresseeView::setSource(const QString& n)
72{ 100{
73 //qDebug("********AddresseeView::setSource %s", n.latin1()); 101 //qDebug("********AddresseeView::setSource %s", n.latin1());
74 102
75 if ( n.left( 6 ) == "mailto" ) 103 if ( n.left( 6 ) == "mailto" )
76 ExternalAppHandler::instance()->mailToOneContact( n.mid(7) ); 104 ExternalAppHandler::instance()->mailToOneContact( n.mid(7) );
77 else if ( n.left( 7 ) == "phoneto" ) 105 else if ( n.left( 7 ) == "phoneto" )
78 ExternalAppHandler::instance()->callByPhone( n.mid(8) ); 106 ExternalAppHandler::instance()->callByPhone( n.mid(8) );
79 else if ( n.left( 5 ) == "faxto" ) 107 else if ( n.left( 5 ) == "faxto" )
80 ExternalAppHandler::instance()->callByFax( n.mid(6) ); 108 ExternalAppHandler::instance()->callByFax( n.mid(6) );
81 else if ( n.left( 5 ) == "smsto" ) 109 else if ( n.left( 5 ) == "smsto" )
82 ExternalAppHandler::instance()->callBySMS( n.mid(6) ); 110 ExternalAppHandler::instance()->callBySMS( n.mid(6) );
83 else if ( n.left( 7 ) == "pagerto" ) 111 else if ( n.left( 7 ) == "pagerto" )
84 ExternalAppHandler::instance()->callByPager( n.mid(8) ); 112 ExternalAppHandler::instance()->callByPager( n.mid(8) );
85 else if ( n.left( 5 ) == "sipto" ) 113 else if ( n.left( 5 ) == "sipto" )
86 ExternalAppHandler::instance()->callBySIP( n.mid(6) ); 114 ExternalAppHandler::instance()->callBySIP( n.mid(6) );
87 115
88} 116}
89void AddresseeView::setAddressee( const KABC::Addressee& mAddressee ) 117void AddresseeView::setAddressee( const KABC::Addressee& mAddressee )
90{ 118{
91 bool kemailAvail = ExternalAppHandler::instance()->isEmailAppAvailable(); 119 bool kemailAvail = ExternalAppHandler::instance()->isEmailAppAvailable();
92 // mAddressee = addr; 120 // mAddressee = addr;
93 // clear view 121 // clear view
94 //setText( QString::null ); 122 //setText( QString::null );
95 123
96 if ( mAddressee.isEmpty() ) { 124 if ( mAddressee.isEmpty() ) {
97 setText( QString::null); 125 setText( QString::null);
98 return; 126 return;
99 } 127 }
100 QString name = ( mAddressee.assembledName().isEmpty() ? 128 QString name = ( mAddressee.assembledName().isEmpty() ?
101 mAddressee.formattedName() : mAddressee.assembledName() ); 129 mAddressee.formattedName() : mAddressee.assembledName() );
102 130
103 QString dynamicPart; 131 QString dynamicPart;
104 132
105 dynamicPart += getPhoneNumbers( mAddressee.phoneNumbers(),true ); 133 dynamicPart += getPhoneNumbers( mAddressee.phoneNumbers(),true );
106 QStringList emails = mAddressee.emails(); 134 QStringList emails = mAddressee.emails();
107 QStringList::ConstIterator emailIt; 135 QStringList::ConstIterator emailIt;
108 QString type = i18n( "Email" ); 136 QString type = i18n( "Email" );
109 emailIt = emails.begin(); 137 emailIt = emails.begin();
110 if ( emailIt != emails.end() ) { 138 if ( emailIt != emails.end() ) {
111 if ( kemailAvail ) { 139 if ( kemailAvail ) {
112 dynamicPart += QString( 140 dynamicPart += QString(
113 "<tr><td align=\"right\"><b>%1</b></td>" 141 "<tr><td align=\"right\"><b>%1</b></td>"
114 "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" ) 142 "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" )
115 .arg( type ) 143 .arg( type )
116 .arg( name ) 144 .arg( name )
117 .arg( *emailIt ) 145 .arg( *emailIt )
118 .arg( *emailIt ); 146 .arg( *emailIt );
119 ++emailIt; 147 ++emailIt;
120 } else { 148 } else {
121 dynamicPart += QString( 149 dynamicPart += QString(
122 "<tr><td align=\"right\"><b>%1</b></td>" 150 "<tr><td align=\"right\"><b>%1</b></td>"
123 "<td align=\"left\">%2</td></tr>" ) 151 "<td align=\"left\">%2</td></tr>" )
124 .arg( type ) 152 .arg( type )
125 .arg( *emailIt ); 153 .arg( *emailIt );
126 ++emailIt; 154 ++emailIt;
127 } 155 }
128 } 156 }
129 if ( mAddressee.birthday().date().isValid() ) { 157 if ( mAddressee.birthday().date().isValid() ) {
130 dynamicPart += QString( 158 dynamicPart += QString(
131 "<tr><td align=\"right\"><b>%1</b></td>" 159 "<tr><td align=\"right\"><b>%1</b></td>"
132 "<td align=\"left\">%2</td></tr>" ) 160 "<td align=\"left\">%2</td></tr>" )
133 .arg( i18n ("Birthday") ) 161 .arg( i18n ("Birthday") )
134 .arg( KGlobal::locale()->formatDate( mAddressee.birthday().date() ,true) ); 162 .arg( KGlobal::locale()->formatDate( mAddressee.birthday().date() ,true) );
@@ -150,129 +178,129 @@ void AddresseeView::setAddressee( const KABC::Addressee& mAddressee )
150 "<td align=\"left\">%2</td></tr>" ) 178 "<td align=\"left\">%2</td></tr>" )
151 .arg( type ) 179 .arg( type )
152 .arg( *emailIt ); 180 .arg( *emailIt );
153 } 181 }
154 } 182 }
155 183
156 if ( !mAddressee.url().url().isEmpty() ) { 184 if ( !mAddressee.url().url().isEmpty() ) {
157 dynamicPart += QString( 185 dynamicPart += QString(
158 "<tr><td align=\"right\"><b>%1</b></td>" 186 "<tr><td align=\"right\"><b>%1</b></td>"
159 "<td align=\"left\">%2</td></tr>" ) 187 "<td align=\"left\">%2</td></tr>" )
160 .arg( i18n( "Homepage" ) ) 188 .arg( i18n( "Homepage" ) )
161//US .arg( KStringHandler::tagURLs( mAddressee.url().url() ) ); 189//US .arg( KStringHandler::tagURLs( mAddressee.url().url() ) );
162 .arg( mAddressee.url().url() ); 190 .arg( mAddressee.url().url() );
163 //qDebug("AddresseeView::setAddressee has to be verified."); 191 //qDebug("AddresseeView::setAddressee has to be verified.");
164 } 192 }
165 193
166 KABC::Address::List addresses = mAddressee.addresses(); 194 KABC::Address::List addresses = mAddressee.addresses();
167 KABC::Address::List::ConstIterator addrIt; 195 KABC::Address::List::ConstIterator addrIt;
168 for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) { 196 for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) {
169 if ( true /*(*addrIt).label().isEmpty()*/ ) { 197 if ( true /*(*addrIt).label().isEmpty()*/ ) {
170 QString formattedAddress = (*addrIt).formattedAddress().stripWhiteSpace(); 198 QString formattedAddress = (*addrIt).formattedAddress().stripWhiteSpace();
171//US formattedAddress = formattedAddress.replace( '\n', "<br>" ); 199//US formattedAddress = formattedAddress.replace( '\n', "<br>" );
172 //qDebug("adresss %s ",formattedAddress.latin1() ); 200 //qDebug("adresss %s ",formattedAddress.latin1() );
173 formattedAddress = formattedAddress.replace( QRegExp("\n"), "<br>" ); 201 formattedAddress = formattedAddress.replace( QRegExp("\n"), "<br>" );
174 //qDebug("AddresseeView::setAddressee has to be verified."); 202 //qDebug("AddresseeView::setAddressee has to be verified.");
175 203
176 dynamicPart += QString( 204 dynamicPart += QString(
177 "<tr><td align=\"right\"><b>%1</b></td>" 205 "<tr><td align=\"right\"><b>%1</b></td>"
178 "<td align=\"left\">%2</td></tr>" ) 206 "<td align=\"left\">%2</td></tr>" )
179 .arg( KABC::Address::typeLabel( (*addrIt).type() ) ) 207 .arg( KABC::Address::typeLabel( (*addrIt).type() ) )
180 .arg( formattedAddress ); 208 .arg( formattedAddress );
181 } else { 209 } else {
182 210
183 dynamicPart += QString( 211 dynamicPart += QString(
184 "<tr><td align=\"right\"><b>%1</b></td>" 212 "<tr><td align=\"right\"><b>%1</b></td>"
185 "<td align=\"left\">%2</td></tr>" ) 213 "<td align=\"left\">%2</td></tr>" )
186 .arg( KABC::Address::typeLabel( (*addrIt).type() ) ) 214 .arg( KABC::Address::typeLabel( (*addrIt).type() ) )
187//US .arg( (*addrIt).label().replace( '\n', "<br>" ) ); 215//US .arg( (*addrIt).label().replace( '\n', "<br>" ) );
188 .arg( (*addrIt).label() /*replace( QRegExp("\n"), "<br>" )*/ ); 216 .arg( (*addrIt).label() /*replace( QRegExp("\n"), "<br>" )*/ );
189 217
190 } 218 }
191 } 219 }
192 220
193 QString notes; 221 QString notes;
194 if ( !mAddressee.note().isEmpty() ) { 222 if ( !mAddressee.note().isEmpty() ) {
195 notes = QString( 223 notes = QString(
196 "<tr>" 224 "<tr>"
197 "<td align=\"right\" valign=\"top\"><b>%1</b></td>" // note label 225 "<td align=\"right\" valign=\"top\"><b>%1</b></td>" // note label
198 "<td align=\"left\">%2</td>" // note 226 "<td align=\"left\">%2</td>" // note
199 "</tr>" ).arg( i18n( "Notes" ) ) 227 "</tr>" ).arg( i18n( "Notes" ) )
200//US .arg( mAddressee.note().replace( '\n', "<br>" ) ); 228//US .arg( mAddressee.note().replace( '\n', "<br>" ) );
201 .arg( mAddressee.note().replace( QRegExp("\n"), "<br>" ) ); 229 .arg( mAddressee.note().replace( QRegExp("\n"), "<br>" ) );
202 //qDebug("AddresseeView::setAddressee has to be verified."); 230 //qDebug("AddresseeView::setAddressee has to be verified.");
203 } 231 }
204 232
205 QString aRole = ""; 233 QString aRole = "";
206 QString aOrga = ""; 234 QString aOrga = "";
207 if ( true /*!mAddressee.role().isEmpty()*/ ) { 235 if ( true /*!mAddressee.role().isEmpty()*/ ) {
208 aRole = "<tr>" 236 aRole = "<tr>"
209 "<td align=\"left\">" + mAddressee.role() + "</td>" 237 "<td align=\"left\">" + mAddressee.role() + "</td>"
210 "</tr>"; 238 "</tr>";
211 } 239 }
212 if ( true /*!mAddressee.organization().isEmpty()*/ ) { 240 if ( true /*!mAddressee.organization().isEmpty()*/ ) {
213 aOrga = "<tr>" 241 aOrga = "<tr>"
214 "<td align=\"left\">" + mAddressee.organization() + "</td>" ; 242 "<td align=\"left\">" + mAddressee.organization() + "</td>"
215 "</tr>"; 243 "</tr>";
216 } 244 }
217 mText = ""; 245 mText = "";
218 QString picString = ""; 246 QString picString = "";
219 KABC::Picture picture = mAddressee.photo(); 247 KABC::Picture picture = mAddressee.photo();
220 bool picAvailintern = false; 248 bool picAvailintern = false;
221 bool picAvailUrl = false; 249 bool picAvailUrl = false;
222 if (! picture.undefined() ) { 250 if (! picture.undefined() ) {
223 picAvailintern = (picture.isIntern() && !picture.data().isNull()); 251 picAvailintern = (picture.isIntern() && !picture.data().isNull());
224 picAvailUrl = !picture.isIntern() && QFile::exists(picture.url() ); 252 picAvailUrl = !picture.isIntern() && QFile::exists(picture.url() );
225 } 253 }
226 if ( picAvailUrl || picAvailintern || QApplication::desktop()->width() > 320 ) { 254 if ( picAvailUrl || picAvailintern || QApplication::desktop()->width() > 320 ) {
227 if ( picAvailintern ) { 255 if ( picAvailintern ) {
228 QMimeSourceFactory::defaultFactory()->setImage( "myimage", picture.data() ); 256 QMimeSourceFactory::defaultFactory()->setImage( "myimage", picture.data() );
229 } else { 257 } else {
230 if ( picAvailUrl ) { 258 if ( picAvailUrl ) {
231 QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", QPixmap( picture.url() )); 259 QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", QPixmap( picture.url() ));
232 } else { 260 } else {
233 QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", KGlobal::iconLoader()->loadIcon( "package_toys", KIcon::Desktop, 128 ) ); 261 QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", KGlobal::iconLoader()->loadIcon( "package_toys", KIcon::Desktop, 128 ) );
234 } 262 }
235 } 263 }
236 picString = "<img src=\"myimage\" width=\"50\" height=\"70\">"; 264 picString = "<img src=\"myimage\" width=\"50\" height=\"70\">";
237 mText = QString::fromLatin1( 265 mText = QString::fromLatin1(
238 "<html>" 266 "<html>"
239 "<body text=\"%1\" bgcolor=\"%2\">" // text and background color 267 "<body text=\"%1\" bgcolor=\"%2\">" // text and background color
240 "<table>" 268 "<table>"
241 "<tr>" 269 "<tr>"
242 "<td rowspan=\"3\" align=\"right\" valign=\"top\">" 270 "<td rowspan=\"3\" align=\"right\" valign=\"top\">"
243 "%3" 271 "%3"
244 "</td>" 272 "</td>"
245 "<td align=\"left\"><font size=\"+2\"><b>%4</b></font></td>" // name 273 "<td align=\"left\"><font size=\"+2\"><b>%4</b></font></td>" // name
246 "</tr>" 274 "</tr>"
247 "%5" // role 275 "%5" // role
248 "%6" // organization 276 "%6" // organization
249 "<td colspan=\"2\">&nbsp;</td>" 277 "<td colspan=\"2\">&nbsp;</td>"
250 "%7" // dynamic part 278 "%7" // dynamic part
251 "%8" // notes 279 "%8" // notes
252 "</table>" 280 "</table>"
253 "</body>" 281 "</body>"
254 "</html>") 282 "</html>")
255//US 283//US
256 .arg( /*KGlobalSettings::textColor().name()*/ "black" ) 284 .arg( /*KGlobalSettings::textColor().name()*/ "black" )
257//US 285//US
258 .arg( /*KGlobalSettings::baseColor().name()*/ "white" ) 286 .arg( /*KGlobalSettings::baseColor().name()*/ "white" )
259 .arg( picString ) 287 .arg( picString )
260 .arg( name ) 288 .arg( name )
261 .arg( aRole ) 289 .arg( aRole )
262 .arg( aOrga ) 290 .arg( aOrga )
263 .arg( dynamicPart ) 291 .arg( dynamicPart )
264 .arg( notes ); 292 .arg( notes );
265 293
266 } else { // no picture! 294 } else { // no picture!
267 295
268mText = "<table width=\"100%\">\n"; 296mText = "<table width=\"100%\">\n";
269 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>"; 297 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>";
270#ifdef DESKTOP_VERSION 298#ifdef DESKTOP_VERSION
271 mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h1>"; 299 mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h1>";
272 mText += "<font color=\"#FFFFFF\">" + name +"</font></h1>"; 300 mText += "<font color=\"#FFFFFF\">" + name +"</font></h1>";
273#else 301#else
274 mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h3>"; 302 mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h3>";
275 mText += "<font color=\"#FFFFFF\"> " + name +"</font></h3>"; 303 mText += "<font color=\"#FFFFFF\"> " + name +"</font></h3>";
276#endif 304#endif
277 305
278 mText += "</td></tr>\n<tr bgcolor=\"#EAF8FA\"><td>"; 306 mText += "</td></tr>\n<tr bgcolor=\"#EAF8FA\"><td>";