summaryrefslogtreecommitdiffabout
path: root/libkdepim/addresseeview.cpp
Unidiff
Diffstat (limited to 'libkdepim/addresseeview.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libkdepim/addresseeview.cpp401
1 files changed, 0 insertions, 401 deletions
diff --git a/libkdepim/addresseeview.cpp b/libkdepim/addresseeview.cpp
deleted file mode 100644
index b4717d7..0000000
--- a/libkdepim/addresseeview.cpp
+++ b/dev/null
@@ -1,401 +0,0 @@
1/*
2 This file is part of libkdepim.
3
4 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
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
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20*/
21
22#include <kabc/address.h>
23#include <kabc/addressee.h>
24#include <kabc/phonenumber.h>
25#include <kglobal.h>
26//US#include <kglobalsettings.h>
27#include <kiconloader.h>
28#include <klocale.h>
29//US #include <kstringhandler.h>
30#include <qscrollview.h>
31#include <qregexp.h>
32#include <qfile.h>
33#include <qapplication.h>
34
35
36#include "externalapphandler.h"
37#include "addresseeview.h"
38
39
40//US #ifndef DESKTOP_VERSION
41//US #include <qtopia/qcopenvelope_qws.h>
42//US #include <qpe/qpeapplication.h>
43//US #endif
44
45//US static int kphoneInstalled = 0;
46
47using namespace KPIM;
48
49AddresseeView::AddresseeView( QWidget *parent, const char *name )
50//US : KTextBrowser( parent, name )
51 : QTextBrowser( parent, name )
52
53
54{
55//US setWrapPolicy( QTextEdit::AtWordBoundary );
56 setLinkUnderline( false );
57 // setVScrollBarMode( QScrollView::AlwaysOff );
58 //setHScrollBarMode( QScrollView::AlwaysOff );
59
60//US QStyleSheet *sheet = styleSheet();
61//US QStyleSheetItem *link = sheet->item( "a" );
62//US link->setColor( KGlobalSettings::linkColor() );
63
64}
65
66void AddresseeView::setSource(const QString& n)
67{
68 //qDebug("********AddresseeView::setSource %s", n.latin1());
69
70 if ( n.left( 6 ) == "mailto" )
71 ExternalAppHandler::instance()->mailToOneContact( n.mid(7) );
72 else if ( n.left( 7 ) == "phoneto" )
73 ExternalAppHandler::instance()->callByPhone( n.mid(8) );
74 else if ( n.left( 5 ) == "faxto" )
75 ExternalAppHandler::instance()->callByFax( n.mid(6) );
76 else if ( n.left( 5 ) == "smsto" )
77 ExternalAppHandler::instance()->callBySMS( n.mid(6) );
78 else if ( n.left( 7 ) == "pagerto" )
79 ExternalAppHandler::instance()->callByPager( n.mid(8) );
80 else if ( n.left( 5 ) == "sipto" )
81 ExternalAppHandler::instance()->callBySIP( n.mid(6) );
82
83}
84void AddresseeView::setAddressee( const KABC::Addressee& addr )
85{
86 ExternalAppHandler* eah = ExternalAppHandler::instance();
87 bool kemailAvail = eah->isEmailAppAvailable();
88 bool kphoneAvail = eah->isPhoneAppAvailable();
89 bool kfaxAvail = eah->isFaxAppAvailable();
90 bool ksmsAvail = eah->isSMSAppAvailable();
91 bool kpagerAvail = eah->isPagerAppAvailable();
92 bool ksipAvail = eah->isSIPAppAvailable();
93
94
95 mAddressee = addr;
96 // clear view
97 setText( QString::null );
98
99 if ( mAddressee.isEmpty() )
100 return;
101
102 QString name = ( mAddressee.assembledName().isEmpty() ?
103 mAddressee.formattedName() : mAddressee.assembledName() );
104
105 QString dynamicPart;
106
107 QStringList emails = mAddressee.emails();
108 QStringList::ConstIterator emailIt;
109 QString type = i18n( "Email" );
110 emailIt = emails.begin();
111 if ( emailIt != emails.end() ) {
112 if ( kemailAvail ) {
113 dynamicPart += QString(
114 "<tr><td align=\"right\"><b>%1</b></td>"
115 "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" )
116 .arg( type )
117 .arg( name )
118 .arg( *emailIt )
119 .arg( *emailIt );
120 ++emailIt;
121 } else {
122 dynamicPart += QString(
123 "<tr><td align=\"right\"><b>%1</b></td>"
124 "<td align=\"left\">%2</td></tr>" )
125 .arg( type )
126 .arg( *emailIt );
127 ++emailIt;
128 }
129 }
130 if ( mAddressee.birthday().date().isValid() ) {
131 dynamicPart += QString(
132 "<tr><td align=\"right\"><b>%1</b></td>"
133 "<td align=\"left\">%2</td></tr>" )
134 .arg( i18n ("Birthday") )
135 .arg( KGlobal::locale()->formatDate( mAddressee.birthday().date() ,true) );
136 }
137 KABC::PhoneNumber::List phones = mAddressee.phoneNumbers();
138 KABC::PhoneNumber::List::ConstIterator phoneIt;
139 QString extension;
140 int phonetype;
141 QString sms;
142 for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt ) {
143 phonetype = (*phoneIt).type();
144 if (ksmsAvail &&
145 (
146 ((phonetype & KABC::PhoneNumber::Car) == KABC::PhoneNumber::Car) ||
147 ((phonetype & KABC::PhoneNumber::Cell) == KABC::PhoneNumber::Cell)
148 )
149 )
150 {
151 sms = QString("<a href=\"smsto:%1 \">(sms)</a>" )
152 .arg( (*phoneIt).number() );
153
154 }
155 else
156 sms = "";
157
158 extension = QString::null;
159 if ((phonetype & KABC::PhoneNumber::Fax) == KABC::PhoneNumber::Fax) {
160 if (kfaxAvail) extension = "faxto:";
161 }
162 else if ((phonetype & KABC::PhoneNumber::Pager) == KABC::PhoneNumber::Pager) {
163 if (kpagerAvail) extension = "pagerto:";
164 }
165 else if ((phonetype & KABC::PhoneNumber::Sip) == KABC::PhoneNumber::Sip) {
166 if (ksipAvail) extension = "sipto:";
167 }
168 else if (kphoneAvail) {
169 extension = "phoneto:";
170 }
171 else
172 extension = QString::null;
173
174 if ( !extension.isEmpty() ) {
175 dynamicPart += QString(
176 "<tr><td align=\"right\"><b>%1</b></td>"
177 "<td align=\"left\"><a href=\"%2%3 \">%4</a> %5</td></tr>" )
178 .arg( KABC::PhoneNumber::typeLabel( phonetype ) )
179 .arg( extension )
180 .arg( (*phoneIt).number() )
181 .arg( (*phoneIt).number() )
182 .arg( sms );
183
184 } else {
185 dynamicPart += QString(
186 "<tr><td align=\"right\"><b>%1</b></td>"
187 "<td align=\"left\">%2 %3</td></tr>" )
188 .arg( KABC::PhoneNumber::typeLabel( phonetype ) )
189 .arg( (*phoneIt).number() )
190 .arg( sms );
191 }
192 }
193
194
195 for ( ; emailIt != emails.end(); ++emailIt ) {
196 if ( kemailAvail ) {
197 dynamicPart += QString(
198 "<tr><td align=\"right\"><b>%1</b></td>"
199 "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" )
200 .arg( type )
201 .arg( name )
202 .arg( *emailIt )
203 .arg( *emailIt );
204 } else {
205 dynamicPart += QString(
206 "<tr><td align=\"right\"><b>%1</b></td>"
207 "<td align=\"left\">%2</td></tr>" )
208 .arg( type )
209 .arg( *emailIt );
210 }
211 }
212
213 if ( !mAddressee.url().url().isEmpty() ) {
214 dynamicPart += QString(
215 "<tr><td align=\"right\"><b>%1</b></td>"
216 "<td align=\"left\">%2</td></tr>" )
217 .arg( i18n( "Homepage" ) )
218//US .arg( KStringHandler::tagURLs( mAddressee.url().url() ) );
219 .arg( mAddressee.url().url() );
220 //qDebug("AddresseeView::setAddressee has to be verified.");
221 }
222
223 KABC::Address::List addresses = mAddressee.addresses();
224 KABC::Address::List::ConstIterator addrIt;
225 for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) {
226 if ( true /*(*addrIt).label().isEmpty()*/ ) {
227 QString formattedAddress = (*addrIt).formattedAddress().stripWhiteSpace();
228//US formattedAddress = formattedAddress.replace( '\n', "<br>" );
229 //qDebug("adresss %s ",formattedAddress.latin1() );
230 formattedAddress = formattedAddress.replace( QRegExp("\n"), "<br>" );
231 //qDebug("AddresseeView::setAddressee has to be verified.");
232
233 dynamicPart += QString(
234 "<tr><td align=\"right\"><b>%1</b></td>"
235 "<td align=\"left\">%2</td></tr>" )
236 .arg( KABC::Address::typeLabel( (*addrIt).type() ) )
237 .arg( formattedAddress );
238 } else {
239
240 dynamicPart += QString(
241 "<tr><td align=\"right\"><b>%1</b></td>"
242 "<td align=\"left\">%2</td></tr>" )
243 .arg( KABC::Address::typeLabel( (*addrIt).type() ) )
244//US .arg( (*addrIt).label().replace( '\n', "<br>" ) );
245 .arg( (*addrIt).label() /*replace( QRegExp("\n"), "<br>" )*/ );
246
247 }
248 }
249
250 QString notes;
251 if ( !mAddressee.note().isEmpty() ) {
252 notes = QString(
253 "<tr>"
254 "<td align=\"right\" valign=\"top\"><b>%1</b></td>" // note label
255 "<td align=\"left\">%2</td>" // note
256 "</tr>" ).arg( i18n( "Notes" ) )
257//US .arg( mAddressee.note().replace( '\n', "<br>" ) );
258 .arg( mAddressee.note().replace( QRegExp("\n"), "<br>" ) );
259 //qDebug("AddresseeView::setAddressee has to be verified.");
260 }
261
262 QString aRole = "";
263 QString aOrga = "";
264 if ( true /*!mAddressee.role().isEmpty()*/ ) {
265 aRole = "<tr>"
266 "<td align=\"left\">" + mAddressee.role() + "</td>"
267 "</tr>";
268 }
269 if ( true /*!mAddressee.organization().isEmpty()*/ ) {
270 aOrga = "<tr>"
271 "<td align=\"left\">" + mAddressee.organization() + "</td>" ;
272 "</tr>";
273 }
274 mText = "";
275 QString picString = "";
276 KABC::Picture picture = mAddressee.photo();
277 bool picAvailintern = false;
278 bool picAvailUrl = false;
279 if (! picture.undefined() ) {
280 picAvailintern = (picture.isIntern() && !picture.data().isNull());
281 picAvailUrl = !picture.isIntern() && QFile::exists(picture.url() );
282 }
283 if ( picAvailUrl || picAvailintern || QApplication::desktop()->width() > 320 ) {
284 if ( picAvailintern ) {
285 QMimeSourceFactory::defaultFactory()->setImage( "myimage", picture.data() );
286 } else {
287 if ( picAvailUrl ) {
288 QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", QPixmap( picture.url() ));
289 } else {
290 QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", KGlobal::iconLoader()->loadIcon( "package_toys", KIcon::Desktop, 128 ) );
291 }
292 }
293 picString = "<img src=\"myimage\" width=\"50\" height=\"70\">";
294 mText = QString::fromLatin1(
295 "<html>"
296 "<body text=\"%1\" bgcolor=\"%2\">" // text and background color
297 "<table>"
298 "<tr>"
299 "<td rowspan=\"3\" align=\"right\" valign=\"top\">"
300 "%3"
301 "</td>"
302 "<td align=\"left\"><font size=\"+2\"><b>%4</b></font></td>" // name
303 "</tr>"
304 "%5" // role
305 "%6" // organization
306 "<td colspan=\"2\">&nbsp;</td>"
307 "%7" // dynamic part
308 "%8" // notes
309 "</table>"
310 "</body>"
311 "</html>")
312//US
313 .arg( /*KGlobalSettings::textColor().name()*/ "black" )
314//US
315 .arg( /*KGlobalSettings::baseColor().name()*/ "white" )
316 .arg( picString )
317 .arg( name )
318 .arg( aRole )
319 .arg( aOrga )
320 .arg( dynamicPart )
321 .arg( notes );
322
323 } else { // no picture!
324
325mText = "<table width=\"100%\">\n";
326 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>";
327#ifdef DESKTOP_VERSION
328 mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h1>";
329#else
330 mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h2>";
331#endif
332
333#ifdef DESKTOP_VERSION
334 mText += "<font color=\"#FFFFFF\"> <em>" + name+"</em></font></h1>";
335#else
336 mText += "<font color=\"#FFFFFF\"> <em>" + name +"</em></font></h2>";
337#endif
338 mText += "</td></tr>\n<tr bgcolor=\"#EAF8FA\"><td>";
339
340 mText += "<table><td colspan=\"2\">&nbsp;</td>";
341 /*
342 mText += QString("<tr><td align=\"right\"><b2>%1</b2></td>"
343 "<td align=\"left\"><b>%2</b></td></tr>" )
344 .arg( i18n(" ") )
345 .arg( name );
346 */
347 if ( ! mAddressee.role().isEmpty() )
348 mText += QString("<tr><td align=\"right\"><b>%1</b></td>"
349 "<td align=\"left\">%2</td></tr>" )
350 .arg( i18n(" ") )
351 .arg( mAddressee.role());
352 if ( ! mAddressee.organization().isEmpty() )
353 mText += QString("<tr><td align=\"right\"><b>%1</b></td>"
354 "<td align=\"left\">%2</td></tr>" )
355 .arg( i18n(" ") )
356 .arg( mAddressee.organization());
357 mText += dynamicPart;
358 mText += notes;
359 mText += "</table>";
360
361 }
362
363 // at last display it...
364 setText( mText );
365
366}
367
368KABC::Addressee AddresseeView::addressee() const
369{
370 return mAddressee;
371}
372void AddresseeView::addTag(const QString & tag,const QString & text)
373{
374 if ( text.isEmpty() )
375 return;
376 int number=text.contains("\n");
377 QString str = "<" + tag + ">";
378 QString tmpText=text;
379 QString tmpStr=str;
380 if(number !=-1)
381 {
382 if (number > 0) {
383 int pos=0;
384 QString tmp;
385 for(int i=0;i<=number;i++) {
386 pos=tmpText.find("\n");
387 tmp=tmpText.left(pos);
388 tmpText=tmpText.right(tmpText.length()-pos-1);
389 tmpStr+=tmp+"<br>";
390 }
391 }
392 else tmpStr += tmpText;
393 tmpStr+="</" + tag + ">";
394 mText.append(tmpStr);
395 }
396 else
397 {
398 str += text + "</" + tag + ">";
399 mText.append(str);
400 }
401}