summaryrefslogtreecommitdiffabout
path: root/libkdepim/addresseeview.cpp
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /libkdepim/addresseeview.cpp
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'libkdepim/addresseeview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/addresseeview.cpp282
1 files changed, 282 insertions, 0 deletions
diff --git a/libkdepim/addresseeview.cpp b/libkdepim/addresseeview.cpp
new file mode 100644
index 0000000..deafd34
--- a/dev/null
+++ b/libkdepim/addresseeview.cpp
@@ -0,0 +1,282 @@
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 "addresseeview.h"
37
38using namespace KPIM;
39
40AddresseeView::AddresseeView( QWidget *parent, const char *name )
41//US : KTextBrowser( parent, name )
42 : QTextBrowser( parent, name )
43
44
45{
46//US setWrapPolicy( QTextEdit::AtWordBoundary );
47 setLinkUnderline( false );
48 // setVScrollBarMode( QScrollView::AlwaysOff );
49 //setHScrollBarMode( QScrollView::AlwaysOff );
50
51//US QStyleSheet *sheet = styleSheet();
52//US QStyleSheetItem *link = sheet->item( "a" );
53//US link->setColor( KGlobalSettings::linkColor() );
54
55}
56
57void AddresseeView::setAddressee( const KABC::Addressee& addr )
58{
59 mAddressee = addr;
60
61 // clear view
62 setText( QString::null );
63
64 if ( mAddressee.isEmpty() )
65 return;
66
67 QString name = ( mAddressee.formattedName().isEmpty() ?
68 mAddressee.assembledName() : mAddressee.formattedName() );
69
70 QString dynamicPart;
71
72 KABC::PhoneNumber::List phones = mAddressee.phoneNumbers();
73 KABC::PhoneNumber::List::ConstIterator phoneIt;
74 for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt ) {
75 dynamicPart += QString(
76 "<tr><td align=\"right\"><b>%1</b></td>"
77 "<td align=\"left\">%2</td></tr>" )
78 .arg( KABC::PhoneNumber::typeLabel( (*phoneIt).type() ) )
79 .arg( (*phoneIt).number() );
80 }
81
82 QStringList emails = mAddressee.emails();
83 QStringList::ConstIterator emailIt;
84 QString type = i18n( "Email" );
85 for ( emailIt = emails.begin(); emailIt != emails.end(); ++emailIt ) {
86 dynamicPart += QString(
87 "<tr><td align=\"right\"><b>%1</b></td>"
88 "<td align=\"left\"><a href=\"mailto:%2\">%3</a></td></tr>" )
89 .arg( type )
90 .arg( *emailIt )
91 .arg( *emailIt );
92 type = i18n( "Other" );
93 }
94
95 if ( !mAddressee.url().url().isEmpty() ) {
96 dynamicPart += QString(
97 "<tr><td align=\"right\"><b>%1</b></td>"
98 "<td align=\"left\">%2</td></tr>" )
99 .arg( i18n( "Homepage" ) )
100//US .arg( KStringHandler::tagURLs( mAddressee.url().url() ) );
101 .arg( mAddressee.url().url() );
102 //qDebug("AddresseeView::setAddressee has to be verified.");
103 }
104
105 KABC::Address::List addresses = mAddressee.addresses();
106 KABC::Address::List::ConstIterator addrIt;
107 for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) {
108 if ( true /*(*addrIt).label().isEmpty()*/ ) {
109 QString formattedAddress = (*addrIt).formattedAddress().stripWhiteSpace();
110//US formattedAddress = formattedAddress.replace( '\n', "<br>" );
111 //qDebug("adresss %s ",formattedAddress.latin1() );
112 formattedAddress = formattedAddress.replace( QRegExp("\n"), "<br>" );
113 //qDebug("AddresseeView::setAddressee has to be verified.");
114
115 dynamicPart += QString(
116 "<tr><td align=\"right\"><b>%1</b></td>"
117 "<td align=\"left\">%2</td></tr>" )
118 .arg( KABC::Address::typeLabel( (*addrIt).type() ) )
119 .arg( formattedAddress );
120 } else {
121
122 dynamicPart += QString(
123 "<tr><td align=\"right\"><b>%1</b></td>"
124 "<td align=\"left\">%2</td></tr>" )
125 .arg( KABC::Address::typeLabel( (*addrIt).type() ) )
126//US .arg( (*addrIt).label().replace( '\n', "<br>" ) );
127 .arg( (*addrIt).label() /*replace( QRegExp("\n"), "<br>" )*/ );
128
129 }
130 }
131
132 QString notes;
133 if ( !mAddressee.note().isEmpty() ) {
134 notes = QString(
135 "<tr>"
136 "<td align=\"right\" valign=\"top\"><b>%1:</b></td>" // note label
137 "<td align=\"left\">%2</td>" // note
138 "</tr>" ).arg( i18n( "Notes" ) )
139//US .arg( mAddressee.note().replace( '\n', "<br>" ) );
140 .arg( mAddressee.note().replace( QRegExp("\n"), "<br>" ) );
141 //qDebug("AddresseeView::setAddressee has to be verified.");
142 }
143
144 QString aRole = "";
145 QString aOrga = "";
146 if ( true /*!mAddressee.role().isEmpty()*/ ) {
147 aRole = "<tr>"
148 "<td align=\"left\">" + mAddressee.role() + "</td>"
149 "</tr>";
150 }
151 if ( true /*!mAddressee.organization().isEmpty()*/ ) {
152 aOrga = "<tr>"
153 "<td align=\"left\">" + mAddressee.organization() + "</td>" ;
154 "</tr>";
155 }
156 mText = "";
157 QString picString = "";
158 KABC::Picture picture = mAddressee.photo();
159 bool picAvailintern = false;
160 bool picAvailUrl = false;
161 if (! picture.undefined() ) {
162 picAvailintern = (picture.isIntern() && !picture.data().isNull());
163 picAvailUrl = !picture.isIntern() && QFile::exists(picture.url() );
164 }
165 if ( picAvailUrl || picAvailintern || QApplication::desktop()->width() > 320 ) {
166 if ( picAvailintern ) {
167 QMimeSourceFactory::defaultFactory()->setImage( "myimage", picture.data() );
168 } else {
169 if ( picAvailUrl ) {
170 QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", QPixmap( picture.url() ));
171 } else {
172 QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", KGlobal::iconLoader()->loadIcon( "package_toys", KIcon::Desktop, 128 ) );
173 }
174 }
175 picString = "<img src=\"myimage\" width=\"50\" height=\"70\">";
176 mText = QString::fromLatin1(
177 "<html>"
178 "<body text=\"%1\" bgcolor=\"%2\">" // text and background color
179 "<table>"
180 "<tr>"
181 "<td rowspan=\"3\" align=\"right\" valign=\"top\">"
182 "%3"
183 "</td>"
184 "<td align=\"left\"><font size=\"+2\"><b>%4</b></font></td>" // name
185 "</tr>"
186 "%5" // role
187 "%6" // organization
188 "<td colspan=\"2\">&nbsp;</td>"
189 "%7" // dynamic part
190 "%8" // notes
191 "</table>"
192 "</body>"
193 "</html>")
194//US
195 .arg( /*KGlobalSettings::textColor().name()*/ "black" )
196//US
197 .arg( /*KGlobalSettings::baseColor().name()*/ "white" )
198 .arg( picString )
199 .arg( name )
200 .arg( aRole )
201 .arg( aOrga )
202 .arg( dynamicPart )
203 .arg( notes );
204
205 } else { // no picture!
206
207mText = "<table width=\"100%\">\n";
208 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>";
209#ifdef DESKTOP_VERSION
210 mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h1>";
211#else
212 mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h2>";
213#endif
214
215#ifdef DESKTOP_VERSION
216 mText += "<font color=\"#FFFFFF\"> <em>" + name+"</em></font></h1>";
217#else
218 mText += "<font color=\"#FFFFFF\"> <em>" + name +"</em></font></h2>";
219#endif
220 mText += "</td></tr>\n<tr bgcolor=\"#EAF8FA\"><td>";
221
222 mText += "<table><td colspan=\"2\">&nbsp;</td>";
223 /*
224 mText += QString("<tr><td align=\"right\"><b2>%1</b2></td>"
225 "<td align=\"left\"><b>%2</b></td></tr>" )
226 .arg( i18n(" ") )
227 .arg( name );
228 */
229 if ( ! mAddressee.role().isEmpty() )
230 mText += QString("<tr><td align=\"right\"><b>%1</b></td>"
231 "<td align=\"left\">%2</td></tr>" )
232 .arg( i18n(" ") )
233 .arg( mAddressee.role());
234 if ( ! mAddressee.organization().isEmpty() )
235 mText += QString("<tr><td align=\"right\"><b>%1</b></td>"
236 "<td align=\"left\">%2</td></tr>" )
237 .arg( i18n(" ") )
238 .arg( mAddressee.organization());
239 mText += dynamicPart;
240 mText += notes;
241 mText += "</table>";
242
243 }
244
245 // at last display it...
246 setText( mText );
247}
248
249KABC::Addressee AddresseeView::addressee() const
250{
251 return mAddressee;
252}
253void AddresseeView::addTag(const QString & tag,const QString & text)
254{
255 if ( text.isEmpty() )
256 return;
257 int number=text.contains("\n");
258 QString str = "<" + tag + ">";
259 QString tmpText=text;
260 QString tmpStr=str;
261 if(number !=-1)
262 {
263 if (number > 0) {
264 int pos=0;
265 QString tmp;
266 for(int i=0;i<=number;i++) {
267 pos=tmpText.find("\n");
268 tmp=tmpText.left(pos);
269 tmpText=tmpText.right(tmpText.length()-pos-1);
270 tmpStr+=tmp+"<br>";
271 }
272 }
273 else tmpStr += tmpText;
274 tmpStr+="</" + tag + ">";
275 mText.append(tmpStr);
276 }
277 else
278 {
279 str += text + "</" + tag + ">";
280 mText.append(str);
281 }
282}