-rw-r--r-- | kabc/addresseeview.cpp | 66 |
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,401 +1,467 @@ | |||
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 | ||
47 | using namespace KPIM; | 52 | using namespace KPIM; |
48 | 53 | ||
49 | AddresseeView::AddresseeView( QWidget *parent, const char *name ) | 54 | AddresseeView::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 | ||
66 | void AddresseeView::setSource(const QString& n) | 71 | void 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 | } |
84 | void AddresseeView::setAddressee( const KABC::Addressee& addr ) | 89 | void 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 | } |
130 | if ( mAddressee.birthday().date().isValid() ) { | 135 | if ( mAddressee.birthday().date().isValid() ) { |
131 | dynamicPart += QString( | 136 | dynamicPart += QString( |
132 | "<tr><td align=\"right\"><b>%1</b></td>" | 137 | "<tr><td align=\"right\"><b>%1</b></td>" |
133 | "<td align=\"left\">%2</td></tr>" ) | 138 | "<td align=\"left\">%2</td></tr>" ) |
134 | .arg( i18n ("Birthday") ) | 139 | .arg( i18n ("Birthday") ) |
135 | .arg( KGlobal::locale()->formatDate( mAddressee.birthday().date() ,true) ); | 140 | .arg( KGlobal::locale()->formatDate( mAddressee.birthday().date() ,true) ); |
136 | } | 141 | } |
137 | KABC::PhoneNumber::List phones = mAddressee.phoneNumbers(); | 142 | KABC::PhoneNumber::List phones = mAddressee.phoneNumbers(); |
138 | KABC::PhoneNumber::List::ConstIterator phoneIt; | 143 | KABC::PhoneNumber::List::ConstIterator phoneIt; |
139 | QString extension; | 144 | QString extension; |
140 | int phonetype; | 145 | int phonetype; |
141 | QString sms; | 146 | QString sms; |
142 | for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt ) { | 147 | for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt ) { |
143 | phonetype = (*phoneIt).type(); | 148 | phonetype = (*phoneIt).type(); |
144 | if (ksmsAvail && | 149 | if (ksmsAvail && |
145 | ( | 150 | ( |
146 | ((phonetype & KABC::PhoneNumber::Car) == KABC::PhoneNumber::Car) || | 151 | ((phonetype & KABC::PhoneNumber::Car) == KABC::PhoneNumber::Car) || |
147 | ((phonetype & KABC::PhoneNumber::Cell) == KABC::PhoneNumber::Cell) | 152 | ((phonetype & KABC::PhoneNumber::Cell) == KABC::PhoneNumber::Cell) |
148 | ) | 153 | ) |
149 | ) | 154 | ) |
150 | { | 155 | { |
151 | sms = QString("<a href=\"smsto:%1 \">(sms)</a>" ) | 156 | sms = QString("<a href=\"smsto:%1 \">(sms)</a>" ) |
152 | .arg( (*phoneIt).number() ); | 157 | .arg( (*phoneIt).number() ); |
153 | 158 | ||
154 | } | 159 | } |
155 | else | 160 | else |
156 | sms = ""; | 161 | sms = ""; |
157 | 162 | ||
158 | extension = QString::null; | 163 | extension = QString::null; |
159 | if ((phonetype & KABC::PhoneNumber::Fax) == KABC::PhoneNumber::Fax) { | 164 | if ((phonetype & KABC::PhoneNumber::Fax) == KABC::PhoneNumber::Fax) { |
160 | if (kfaxAvail) extension = "faxto:"; | 165 | if (kfaxAvail) extension = "faxto:"; |
161 | } | 166 | } |
162 | else if ((phonetype & KABC::PhoneNumber::Pager) == KABC::PhoneNumber::Pager) { | 167 | else if ((phonetype & KABC::PhoneNumber::Pager) == KABC::PhoneNumber::Pager) { |
163 | if (kpagerAvail) extension = "pagerto:"; | 168 | if (kpagerAvail) extension = "pagerto:"; |
164 | } | 169 | } |
165 | else if ((phonetype & KABC::PhoneNumber::Sip) == KABC::PhoneNumber::Sip) { | 170 | else if ((phonetype & KABC::PhoneNumber::Sip) == KABC::PhoneNumber::Sip) { |
166 | if (ksipAvail) extension = "sipto:"; | 171 | if (ksipAvail) extension = "sipto:"; |
167 | } | 172 | } |
168 | else if (kphoneAvail) { | 173 | else if (kphoneAvail) { |
169 | extension = "phoneto:"; | 174 | extension = "phoneto:"; |
170 | } | 175 | } |
171 | else | 176 | else |
172 | extension = QString::null; | 177 | extension = QString::null; |
173 | 178 | ||
174 | if ( !extension.isEmpty() ) { | 179 | if ( !extension.isEmpty() ) { |
175 | dynamicPart += QString( | 180 | dynamicPart += QString( |
176 | "<tr><td align=\"right\"><b>%1</b></td>" | 181 | "<tr><td align=\"right\"><b>%1</b></td>" |
177 | "<td align=\"left\"><a href=\"%2%3 \">%4</a> %5</td></tr>" ) | 182 | "<td align=\"left\"><a href=\"%2%3 \">%4</a> %5</td></tr>" ) |
178 | .arg( KABC::PhoneNumber::typeLabel( phonetype ) ) | 183 | .arg( KABC::PhoneNumber::typeLabel( phonetype ) ) |
179 | .arg( extension ) | 184 | .arg( extension ) |
180 | .arg( (*phoneIt).number() ) | 185 | .arg( (*phoneIt).number() ) |
181 | .arg( (*phoneIt).number() ) | 186 | .arg( (*phoneIt).number() ) |
182 | .arg( sms ); | 187 | .arg( sms ); |
183 | 188 | ||
184 | } else { | 189 | } else { |
185 | dynamicPart += QString( | 190 | dynamicPart += QString( |
186 | "<tr><td align=\"right\"><b>%1</b></td>" | 191 | "<tr><td align=\"right\"><b>%1</b></td>" |
187 | "<td align=\"left\">%2 %3</td></tr>" ) | 192 | "<td align=\"left\">%2 %3</td></tr>" ) |
188 | .arg( KABC::PhoneNumber::typeLabel( phonetype ) ) | 193 | .arg( KABC::PhoneNumber::typeLabel( phonetype ) ) |
189 | .arg( (*phoneIt).number() ) | 194 | .arg( (*phoneIt).number() ) |
190 | .arg( sms ); | 195 | .arg( sms ); |
191 | } | 196 | } |
192 | } | 197 | } |
193 | 198 | ||
194 | 199 | ||
195 | for ( ; emailIt != emails.end(); ++emailIt ) { | 200 | for ( ; emailIt != emails.end(); ++emailIt ) { |
196 | if ( kemailAvail ) { | 201 | if ( kemailAvail ) { |
197 | dynamicPart += QString( | 202 | dynamicPart += QString( |
198 | "<tr><td align=\"right\"><b>%1</b></td>" | 203 | "<tr><td align=\"right\"><b>%1</b></td>" |
199 | "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" ) | 204 | "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" ) |
200 | .arg( type ) | 205 | .arg( type ) |
201 | .arg( name ) | 206 | .arg( name ) |
202 | .arg( *emailIt ) | 207 | .arg( *emailIt ) |
203 | .arg( *emailIt ); | 208 | .arg( *emailIt ); |
204 | } else { | 209 | } else { |
205 | dynamicPart += QString( | 210 | dynamicPart += QString( |
206 | "<tr><td align=\"right\"><b>%1</b></td>" | 211 | "<tr><td align=\"right\"><b>%1</b></td>" |
207 | "<td align=\"left\">%2</td></tr>" ) | 212 | "<td align=\"left\">%2</td></tr>" ) |
208 | .arg( type ) | 213 | .arg( type ) |
209 | .arg( *emailIt ); | 214 | .arg( *emailIt ); |
210 | } | 215 | } |
211 | } | 216 | } |
212 | 217 | ||
213 | if ( !mAddressee.url().url().isEmpty() ) { | 218 | if ( !mAddressee.url().url().isEmpty() ) { |
214 | dynamicPart += QString( | 219 | dynamicPart += QString( |
215 | "<tr><td align=\"right\"><b>%1</b></td>" | 220 | "<tr><td align=\"right\"><b>%1</b></td>" |
216 | "<td align=\"left\">%2</td></tr>" ) | 221 | "<td align=\"left\">%2</td></tr>" ) |
217 | .arg( i18n( "Homepage" ) ) | 222 | .arg( i18n( "Homepage" ) ) |
218 | //US .arg( KStringHandler::tagURLs( mAddressee.url().url() ) ); | 223 | //US .arg( KStringHandler::tagURLs( mAddressee.url().url() ) ); |
219 | .arg( mAddressee.url().url() ); | 224 | .arg( mAddressee.url().url() ); |
220 | //qDebug("AddresseeView::setAddressee has to be verified."); | 225 | //qDebug("AddresseeView::setAddressee has to be verified."); |
221 | } | 226 | } |
222 | 227 | ||
223 | KABC::Address::List addresses = mAddressee.addresses(); | 228 | KABC::Address::List addresses = mAddressee.addresses(); |
224 | KABC::Address::List::ConstIterator addrIt; | 229 | KABC::Address::List::ConstIterator addrIt; |
225 | for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) { | 230 | for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) { |
226 | if ( true /*(*addrIt).label().isEmpty()*/ ) { | 231 | if ( true /*(*addrIt).label().isEmpty()*/ ) { |
227 | QString formattedAddress = (*addrIt).formattedAddress().stripWhiteSpace(); | 232 | QString formattedAddress = (*addrIt).formattedAddress().stripWhiteSpace(); |
228 | //US formattedAddress = formattedAddress.replace( '\n', "<br>" ); | 233 | //US formattedAddress = formattedAddress.replace( '\n', "<br>" ); |
229 | //qDebug("adresss %s ",formattedAddress.latin1() ); | 234 | //qDebug("adresss %s ",formattedAddress.latin1() ); |
230 | formattedAddress = formattedAddress.replace( QRegExp("\n"), "<br>" ); | 235 | formattedAddress = formattedAddress.replace( QRegExp("\n"), "<br>" ); |
231 | //qDebug("AddresseeView::setAddressee has to be verified."); | 236 | //qDebug("AddresseeView::setAddressee has to be verified."); |
232 | 237 | ||
233 | dynamicPart += QString( | 238 | dynamicPart += QString( |
234 | "<tr><td align=\"right\"><b>%1</b></td>" | 239 | "<tr><td align=\"right\"><b>%1</b></td>" |
235 | "<td align=\"left\">%2</td></tr>" ) | 240 | "<td align=\"left\">%2</td></tr>" ) |
236 | .arg( KABC::Address::typeLabel( (*addrIt).type() ) ) | 241 | .arg( KABC::Address::typeLabel( (*addrIt).type() ) ) |
237 | .arg( formattedAddress ); | 242 | .arg( formattedAddress ); |
238 | } else { | 243 | } else { |
239 | 244 | ||
240 | dynamicPart += QString( | 245 | dynamicPart += QString( |
241 | "<tr><td align=\"right\"><b>%1</b></td>" | 246 | "<tr><td align=\"right\"><b>%1</b></td>" |
242 | "<td align=\"left\">%2</td></tr>" ) | 247 | "<td align=\"left\">%2</td></tr>" ) |
243 | .arg( KABC::Address::typeLabel( (*addrIt).type() ) ) | 248 | .arg( KABC::Address::typeLabel( (*addrIt).type() ) ) |
244 | //US .arg( (*addrIt).label().replace( '\n', "<br>" ) ); | 249 | //US .arg( (*addrIt).label().replace( '\n', "<br>" ) ); |
245 | .arg( (*addrIt).label() /*replace( QRegExp("\n"), "<br>" )*/ ); | 250 | .arg( (*addrIt).label() /*replace( QRegExp("\n"), "<br>" )*/ ); |
246 | 251 | ||
247 | } | 252 | } |
248 | } | 253 | } |
249 | 254 | ||
250 | QString notes; | 255 | QString notes; |
251 | if ( !mAddressee.note().isEmpty() ) { | 256 | if ( !mAddressee.note().isEmpty() ) { |
252 | notes = QString( | 257 | notes = QString( |
253 | "<tr>" | 258 | "<tr>" |
254 | "<td align=\"right\" valign=\"top\"><b>%1</b></td>" // note label | 259 | "<td align=\"right\" valign=\"top\"><b>%1</b></td>" // note label |
255 | "<td align=\"left\">%2</td>" // note | 260 | "<td align=\"left\">%2</td>" // note |
256 | "</tr>" ).arg( i18n( "Notes" ) ) | 261 | "</tr>" ).arg( i18n( "Notes" ) ) |
257 | //US .arg( mAddressee.note().replace( '\n', "<br>" ) ); | 262 | //US .arg( mAddressee.note().replace( '\n', "<br>" ) ); |
258 | .arg( mAddressee.note().replace( QRegExp("\n"), "<br>" ) ); | 263 | .arg( mAddressee.note().replace( QRegExp("\n"), "<br>" ) ); |
259 | //qDebug("AddresseeView::setAddressee has to be verified."); | 264 | //qDebug("AddresseeView::setAddressee has to be verified."); |
260 | } | 265 | } |
261 | 266 | ||
262 | QString aRole = ""; | 267 | QString aRole = ""; |
263 | QString aOrga = ""; | 268 | QString aOrga = ""; |
264 | if ( true /*!mAddressee.role().isEmpty()*/ ) { | 269 | if ( true /*!mAddressee.role().isEmpty()*/ ) { |
265 | aRole = "<tr>" | 270 | aRole = "<tr>" |
266 | "<td align=\"left\">" + mAddressee.role() + "</td>" | 271 | "<td align=\"left\">" + mAddressee.role() + "</td>" |
267 | "</tr>"; | 272 | "</tr>"; |
268 | } | 273 | } |
269 | if ( true /*!mAddressee.organization().isEmpty()*/ ) { | 274 | if ( true /*!mAddressee.organization().isEmpty()*/ ) { |
270 | aOrga = "<tr>" | 275 | aOrga = "<tr>" |
271 | "<td align=\"left\">" + mAddressee.organization() + "</td>" ; | 276 | "<td align=\"left\">" + mAddressee.organization() + "</td>" ; |
272 | "</tr>"; | 277 | "</tr>"; |
273 | } | 278 | } |
274 | mText = ""; | 279 | mText = ""; |
275 | QString picString = ""; | 280 | QString picString = ""; |
276 | KABC::Picture picture = mAddressee.photo(); | 281 | KABC::Picture picture = mAddressee.photo(); |
277 | bool picAvailintern = false; | 282 | bool picAvailintern = false; |
278 | bool picAvailUrl = false; | 283 | bool picAvailUrl = false; |
279 | if (! picture.undefined() ) { | 284 | if (! picture.undefined() ) { |
280 | picAvailintern = (picture.isIntern() && !picture.data().isNull()); | 285 | picAvailintern = (picture.isIntern() && !picture.data().isNull()); |
281 | picAvailUrl = !picture.isIntern() && QFile::exists(picture.url() ); | 286 | picAvailUrl = !picture.isIntern() && QFile::exists(picture.url() ); |
282 | } | 287 | } |
283 | if ( picAvailUrl || picAvailintern || QApplication::desktop()->width() > 320 ) { | 288 | if ( picAvailUrl || picAvailintern || QApplication::desktop()->width() > 320 ) { |
284 | if ( picAvailintern ) { | 289 | if ( picAvailintern ) { |
285 | QMimeSourceFactory::defaultFactory()->setImage( "myimage", picture.data() ); | 290 | QMimeSourceFactory::defaultFactory()->setImage( "myimage", picture.data() ); |
286 | } else { | 291 | } else { |
287 | if ( picAvailUrl ) { | 292 | if ( picAvailUrl ) { |
288 | QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", QPixmap( picture.url() )); | 293 | QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", QPixmap( picture.url() )); |
289 | } else { | 294 | } else { |
290 | QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", KGlobal::iconLoader()->loadIcon( "package_toys", KIcon::Desktop, 128 ) ); | 295 | QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", KGlobal::iconLoader()->loadIcon( "package_toys", KIcon::Desktop, 128 ) ); |
291 | } | 296 | } |
292 | } | 297 | } |
293 | picString = "<img src=\"myimage\" width=\"50\" height=\"70\">"; | 298 | picString = "<img src=\"myimage\" width=\"50\" height=\"70\">"; |
294 | mText = QString::fromLatin1( | 299 | mText = QString::fromLatin1( |
295 | "<html>" | 300 | "<html>" |
296 | "<body text=\"%1\" bgcolor=\"%2\">" // text and background color | 301 | "<body text=\"%1\" bgcolor=\"%2\">" // text and background color |
297 | "<table>" | 302 | "<table>" |
298 | "<tr>" | 303 | "<tr>" |
299 | "<td rowspan=\"3\" align=\"right\" valign=\"top\">" | 304 | "<td rowspan=\"3\" align=\"right\" valign=\"top\">" |
300 | "%3" | 305 | "%3" |
301 | "</td>" | 306 | "</td>" |
302 | "<td align=\"left\"><font size=\"+2\"><b>%4</b></font></td>" // name | 307 | "<td align=\"left\"><font size=\"+2\"><b>%4</b></font></td>" // name |
303 | "</tr>" | 308 | "</tr>" |
304 | "%5" // role | 309 | "%5" // role |
305 | "%6" // organization | 310 | "%6" // organization |
306 | "<td colspan=\"2\"> </td>" | 311 | "<td colspan=\"2\"> </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 | ||
325 | mText = "<table width=\"100%\">\n"; | 330 | mText = "<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\"> </td>"; | 345 | mText += "<table><td colspan=\"2\"> </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 | ||
368 | KABC::Addressee AddresseeView::addressee() const | 373 | KABC::Addressee AddresseeView::addressee() const |
369 | { | 374 | { |
370 | return mAddressee; | 375 | return mAddressee; |
371 | } | 376 | } |
372 | void AddresseeView::addTag(const QString & tag,const QString & text) | 377 | void 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 | |||
408 | AddresseeChooser::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 | |||
447 | int 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 | } | ||
458 | void AddresseeChooser::slot_remote() | ||
459 | { | ||
460 | mSyncResult = 2; | ||
461 | accept(); | ||
462 | } | ||
463 | void AddresseeChooser::slot_local() | ||
464 | { | ||
465 | mSyncResult = 1; | ||
466 | accept(); | ||
467 | } | ||