1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
|
/***************************************************************************
dlgjabbervcard.cpp - vCard dialog
-------------------
begin : Thu Aug 08 2002
copyright : (C) 2002-2003 by Till Gerken <till@tantalo.net>
(C) 2005 by Michaƫl Larouche <michael.larouche@kdemail.net>
email : kopete-devel@kde.org
Rewritten version of the original dialog
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "dlgjabbervcard.h"
// TQt includes
#include <tqtextedit.h>
#include <tqwidgetstack.h>
#include <tqregexp.h>
#include <tqbuffer.h>
// KDE includes
#include <kdebug.h>
#include <kpushbutton.h>
#include <klineedit.h>
#include <klocale.h>
#include <kurllabel.h>
#include <kmessagebox.h>
#include <krun.h>
#include <tdeio/netaccess.h>
#include <tdefiledialog.h>
#include <kpixmapregionselectordialog.h>
#include <kstandarddirs.h>
// libiris(XMPP backend) includes
#include "im.h"
#include "xmpp.h"
#include "xmpp_tasks.h"
// Kopete includes
#include "jabberprotocol.h"
#include "jabbercontact.h"
#include "jabberaccount.h"
#include "jabbercontactpool.h"
#include "jabberbasecontact.h"
#include "jabberclient.h"
#include "dlgvcard.h"
/*
* Constructs a dlgJabberVCard which is a child of 'parent', with the
* name 'name'
*
*/
dlgJabberVCard::dlgJabberVCard (JabberAccount *account, JabberBaseContact *contact, TQWidget * parent, const char *name)
: KDialogBase (parent, name, false, i18n("Jabber vCard"), Close | User1 | User2, Close, false, i18n("&Save User Info"), i18n("&Fetch vCard") )
{
m_account = account;
m_contact = contact;
m_mainWidget = new dlgVCard(this);
setMainWidget(m_mainWidget);
connect (this, TQT_SIGNAL (user1Clicked()), this, TQT_SLOT (slotSaveVCard ()));
connect (this, TQT_SIGNAL( user2Clicked()), this, TQT_SLOT (slotGetVCard ()));
connect (m_mainWidget->btnSelectPhoto, TQT_SIGNAL (clicked()), this, TQT_SLOT (slotSelectPhoto()));
connect (m_mainWidget->btnClearPhoto, TQT_SIGNAL (clicked()), this, TQT_SLOT (slotClearPhoto()));
connect (m_mainWidget->urlHomeEmail, TQT_SIGNAL (leftClickedURL(const TQString &)), this, TQT_SLOT (slotOpenURL (const TQString &)));
connect (m_mainWidget->urlWorkEmail, TQT_SIGNAL (leftClickedURL(const TQString &)), this, TQT_SLOT (slotOpenURL (const TQString &)));
connect (m_mainWidget->urlHomepage, TQT_SIGNAL (leftClickedURL(const TQString &)), this, TQT_SLOT (slotOpenURL (const TQString &)));
assignContactProperties();
show ();
raise ();
slotGetVCard();
}
/*
* Destroys the object and frees any allocated resources
*/
dlgJabberVCard::~dlgJabberVCard ()
{
// no need to delete child widgets, TQt does it all for us
}
/*
* Activated when the close button gets pressed. Deletes the dialog.
*/
void dlgJabberVCard::slotClose()
{
kdDebug(JABBER_DEBUG_GLOBAL) << k_funcinfo << "Deleting dialog." << endl;
delayedDestruct();
}
/*
* Assign the contact properties to this dialog
*/
void dlgJabberVCard::assignContactProperties ()
{
// general tab
m_mainWidget->leNick->setText (m_contact->property(m_account->protocol()->propNickName).value().toString());
m_mainWidget->leName->setText (m_contact->property(m_account->protocol()->propFullName).value().toString());
// Guess the JID from the Kopete::Contact if the propJid is empty.
if( m_contact->property( m_account->protocol()->propJid ).value().toString().isEmpty() )
m_mainWidget->leJID->setText (m_contact->rosterItem().jid().full());
else
m_mainWidget->leJID->setText (m_contact->property(m_account->protocol()->propJid).value().toString());
m_mainWidget->leBirthday->setText (m_contact->property(m_account->protocol()->propBirthday).value().toString());
m_mainWidget->leTimezone->setText (m_contact->property(m_account->protocol()->propTimezone).value().toString());
TQString homepage = m_contact->property(m_account->protocol()->propHomepage).value().toString();
m_mainWidget->leHomepage->setText (homepage);
m_mainWidget->urlHomepage->setText (homepage);
m_mainWidget->urlHomepage->setURL (homepage);
m_mainWidget->urlHomepage->setUseCursor ( !homepage.isEmpty () );
// Set photo
m_photoPath = m_contact->property(m_account->protocol()->propPhoto).value().toString();
if( !m_photoPath.isEmpty() )
{
m_mainWidget->lblPhoto->setPixmap( TQPixmap(m_photoPath) );
}
// addresses
m_mainWidget->leWorkStreet->setText (m_contact->property(m_account->protocol()->propWorkStreet).value().toString());
m_mainWidget->leWorkExtAddr->setText (m_contact->property(m_account->protocol()->propWorkExtAddr).value().toString());
m_mainWidget->leWorkPOBox->setText (m_contact->property(m_account->protocol()->propWorkPOBox).value().toString());
m_mainWidget->leWorkCity->setText (m_contact->property(m_account->protocol()->propWorkCity).value().toString());
m_mainWidget->leWorkPostalCode->setText (m_contact->property(m_account->protocol()->propWorkPostalCode).value().toString());
m_mainWidget->leWorkCountry->setText (m_contact->property(m_account->protocol()->propWorkCountry).value().toString());
m_mainWidget->leHomeStreet->setText (m_contact->property(m_account->protocol()->propHomeStreet).value().toString());
m_mainWidget->leHomeExtAddr->setText (m_contact->property(m_account->protocol()->propHomeExtAddr).value().toString());
m_mainWidget->leHomePOBox->setText (m_contact->property(m_account->protocol()->propHomePOBox).value().toString());
m_mainWidget->leHomeCity->setText (m_contact->property(m_account->protocol()->propHomeCity).value().toString());
m_mainWidget->leHomePostalCode->setText (m_contact->property(m_account->protocol()->propHomePostalCode).value().toString());
m_mainWidget->leHomeCountry->setText (m_contact->property(m_account->protocol()->propHomeCountry).value().toString());
// email
m_mainWidget->urlWorkEmail->setUseCursor ( false );
m_mainWidget->urlHomeEmail->setUseCursor ( false );
TQString workEmail = m_contact->property(m_account->protocol()->propWorkEmailAddress).value().toString();
TQString homeEmail = m_contact->property(m_account->protocol()->propEmailAddress).value().toString();
m_mainWidget->leWorkEmail->setText (workEmail);
m_mainWidget->urlWorkEmail->setText (workEmail);
m_mainWidget->urlWorkEmail->setURL ("mailto:" + workEmail);
bool enableMail=!workEmail.stripWhiteSpace().isEmpty ();
m_mainWidget->urlWorkEmail->setUseCursor ( enableMail );
m_mainWidget->urlWorkEmail->setEnabled ( enableMail );
m_mainWidget->leHomeEmail->setText (homeEmail);
m_mainWidget->urlHomeEmail->setText (homeEmail);
enableMail=!homeEmail.stripWhiteSpace().isEmpty ();
m_mainWidget->urlHomeEmail->setURL ("mailto:" + homeEmail);
m_mainWidget->urlHomeEmail->setUseCursor ( enableMail );
m_mainWidget->urlHomeEmail->setEnabled ( enableMail );
// work information tab
m_mainWidget->leCompany->setText (m_contact->property(m_account->protocol()->propCompanyName).value().toString());
m_mainWidget->leDepartment->setText (m_contact->property(m_account->protocol()->propCompanyDepartement).value().toString());
m_mainWidget->lePosition->setText (m_contact->property(m_account->protocol()->propCompanyPosition).value().toString());
m_mainWidget->leRole->setText (m_contact->property(m_account->protocol()->propCompanyRole).value().toString());
// phone numbers tab
m_mainWidget->lePhoneFax->setText(m_contact->property(m_account->protocol()->propPhoneFax).value().toString());
m_mainWidget->lePhoneWork->setText(m_contact->property(m_account->protocol()->propWorkPhone).value().toString());
m_mainWidget->lePhoneCell->setText(m_contact->property(m_account->protocol()->propPrivateMobilePhone).value().toString());
m_mainWidget->lePhoneHome->setText(m_contact->property(m_account->protocol()->propPrivatePhone).value().toString());
// about tab
m_mainWidget->teAbout->setText (m_contact->property(m_account->protocol()->propAbout).value().toString());
if(m_account->myself() == m_contact)
setReadOnly (false);
else
setReadOnly (true);
}
void dlgJabberVCard::setReadOnly (bool state)
{
// general tab
m_mainWidget->leNick->setReadOnly (state);
m_mainWidget->leName->setReadOnly (state);
m_mainWidget->leJID->setReadOnly (state);
m_mainWidget->leBirthday->setReadOnly (state);
m_mainWidget->leTimezone->setReadOnly (state);
m_mainWidget->wsHomepage->raiseWidget(state ? 0 : 1);
// Disable photo buttons when read only
m_mainWidget->btnSelectPhoto->setEnabled(!state);
m_mainWidget->btnClearPhoto->setEnabled(!state);
// home address tab
m_mainWidget->leHomeStreet->setReadOnly (state);
m_mainWidget->leHomeExtAddr->setReadOnly (state);
m_mainWidget->leHomePOBox->setReadOnly (state);
m_mainWidget->leHomeCity->setReadOnly (state);
m_mainWidget->leHomePostalCode->setReadOnly (state);
m_mainWidget->leHomeCountry->setReadOnly (state);
m_mainWidget->wsHomeEmail->raiseWidget(state ? 0 : 1);
// work address tab
m_mainWidget->leWorkStreet->setReadOnly (state);
m_mainWidget->leWorkExtAddr->setReadOnly (state);
m_mainWidget->leWorkPOBox->setReadOnly (state);
m_mainWidget->leWorkCity->setReadOnly (state);
m_mainWidget->leWorkPostalCode->setReadOnly (state);
m_mainWidget->leWorkCountry->setReadOnly (state);
m_mainWidget->wsWorkEmail->raiseWidget(state ? 0 : 1);
// work information tab
m_mainWidget->leCompany->setReadOnly (state);
m_mainWidget->leDepartment->setReadOnly (state);
m_mainWidget->lePosition->setReadOnly (state);
m_mainWidget->leRole->setReadOnly (state);
// phone numbers tab
m_mainWidget->lePhoneHome->setReadOnly (state);
m_mainWidget->lePhoneWork->setReadOnly (state);
m_mainWidget->lePhoneFax->setReadOnly (state);
m_mainWidget->lePhoneCell->setReadOnly (state);
// about tab
m_mainWidget->teAbout->setReadOnly (state);
// save button
enableButton(User1, !state);
}
void dlgJabberVCard::setEnabled(bool state)
{
// general tab
m_mainWidget->leNick->setEnabled (state);
m_mainWidget->leName->setEnabled (state);
m_mainWidget->leJID->setEnabled (state);
m_mainWidget->leBirthday->setEnabled (state);
m_mainWidget->leTimezone->setEnabled (state);
m_mainWidget->wsHomepage->raiseWidget(state ? 1 : 0);
// Disable photo buttons when read only
m_mainWidget->btnSelectPhoto->setEnabled(state);
m_mainWidget->btnClearPhoto->setEnabled(state);
// home address tab
m_mainWidget->leHomeStreet->setEnabled (state);
m_mainWidget->leHomeExtAddr->setEnabled (state);
m_mainWidget->leHomePOBox->setEnabled (state);
m_mainWidget->leHomeCity->setEnabled (state);
m_mainWidget->leHomePostalCode->setEnabled (state);
m_mainWidget->leHomeCountry->setEnabled (state);
m_mainWidget->wsHomeEmail->raiseWidget(state ? 0 : 1);
// work address tab
m_mainWidget->leWorkStreet->setEnabled (state);
m_mainWidget->leWorkExtAddr->setEnabled (state);
m_mainWidget->leWorkPOBox->setEnabled (state);
m_mainWidget->leWorkCity->setEnabled (state);
m_mainWidget->leWorkPostalCode->setEnabled (state);
m_mainWidget->leWorkCountry->setEnabled (state);
m_mainWidget->wsWorkEmail->raiseWidget(state ? 0 : 1);
// work information tab
m_mainWidget->leCompany->setEnabled (state);
m_mainWidget->leDepartment->setEnabled (state);
m_mainWidget->lePosition->setEnabled (state);
m_mainWidget->leRole->setEnabled (state);
// phone numbers tab
m_mainWidget->lePhoneHome->setEnabled (state);
m_mainWidget->lePhoneWork->setEnabled (state);
m_mainWidget->lePhoneFax->setEnabled (state);
m_mainWidget->lePhoneCell->setEnabled (state);
// about tab
m_mainWidget->teAbout->setEnabled (state);
// save button
enableButton(User1, state);
enableButton(User2, state);
}
/*
* Saves a vCard to the contact properties
*/
void dlgJabberVCard::slotSaveVCard()
{
setEnabled(false);
m_mainWidget->lblStatus->setText( i18n("Saving vCard to server...") );
XMPP::VCard vCard;
XMPP::VCard::AddressList addressList;
XMPP::VCard::EmailList emailList;
XMPP::VCard::PhoneList phoneList;
// General information
vCard.setNickName( m_mainWidget->leNick->text() );
vCard.setFullName( m_mainWidget->leName->text() );
vCard.setJid( m_mainWidget->leJID->text() );
vCard.setBdayStr( m_mainWidget->leBirthday->text() );
vCard.setTimezone( m_mainWidget->leTimezone->text() );
vCard.setUrl( m_mainWidget->leHomepage->text() );
// home address tab
XMPP::VCard::Address homeAddress;
homeAddress.home = true;
homeAddress.street = m_mainWidget->leHomeStreet->text();
homeAddress.extaddr = m_mainWidget->leHomeExtAddr->text();
homeAddress.pobox = m_mainWidget->leHomePOBox->text();
homeAddress.locality = m_mainWidget->leHomeCity->text();
homeAddress.pcode = m_mainWidget->leHomePostalCode->text();
homeAddress.country = m_mainWidget->leHomeCountry->text();
// work address tab
XMPP::VCard::Address workAddress;
workAddress.work = true;
workAddress.street = m_mainWidget->leWorkStreet->text();
workAddress.extaddr = m_mainWidget->leWorkExtAddr->text();
workAddress.pobox = m_mainWidget->leWorkPOBox->text();
workAddress.locality = m_mainWidget->leWorkCity->text();
workAddress.pcode = m_mainWidget->leWorkPostalCode->text();
workAddress.country = m_mainWidget->leWorkCountry->text();
addressList.append(homeAddress);
addressList.append(workAddress);
vCard.setAddressList(addressList);
// home email
XMPP::VCard::Email homeEmail;
homeEmail.home = true;
homeEmail.userid = m_mainWidget->leHomeEmail->text();
// work email
XMPP::VCard::Email workEmail;
workEmail.work = true;
workEmail.userid = m_mainWidget->leWorkEmail->text();
emailList.append(homeEmail);
emailList.append(workEmail);
vCard.setEmailList(emailList);
// work information tab
XMPP::VCard::Org org;
org.name = m_mainWidget->leCompany->text();
org.unit = TQStringList::split(",", m_mainWidget->leDepartment->text());
vCard.setOrg(org);
vCard.setTitle( m_mainWidget->lePosition->text() );
vCard.setRole( m_mainWidget->leRole->text() );
// phone numbers tab
XMPP::VCard::Phone phoneHome;
phoneHome.home = true;
phoneHome.number = m_mainWidget->lePhoneHome->text();
XMPP::VCard::Phone phoneWork;
phoneWork.work = true;
phoneWork.number = m_mainWidget->lePhoneWork->text();
XMPP::VCard::Phone phoneFax;
phoneFax.fax = true;
phoneFax.number = m_mainWidget->lePhoneFax->text();
XMPP::VCard::Phone phoneCell;
phoneCell.cell = true;
phoneCell.number = m_mainWidget->lePhoneCell->text();
phoneList.append(phoneHome);
phoneList.append(phoneWork);
phoneList.append(phoneFax);
phoneList.append(phoneCell);
vCard.setPhoneList(phoneList);
// about tab
vCard.setDesc( m_mainWidget->teAbout->text() );
// Set contact photo as a binary value (if he has set a photo)
if( !m_photoPath.isEmpty() )
{
TQString photoPath = m_photoPath;
TQImage image( photoPath );
TQByteArray ba;
TQBuffer buffer( ba );
buffer.open( IO_WriteOnly );
image.save( &buffer, "PNG" );
vCard.setPhoto( ba );
}
vCard.setVersion("3.0");
vCard.setProdId("Kopete");
XMPP::JT_VCard *task = new XMPP::JT_VCard( m_account->client()->rootTask() );
// signal to ourselves when the vCard data arrived
TQObject::connect(task, TQT_SIGNAL(finished()), this, TQT_SLOT(slotVCardSaved()));
task->set(vCard);
task->go(true);
}
void dlgJabberVCard::slotVCardSaved()
{
XMPP::JT_VCard *vCard = (XMPP::JT_VCard*)sender();
if( vCard->success() )
{
m_mainWidget->lblStatus->setText( i18n("vCard save sucessful.") );
m_contact->setPropertiesFromVCard( vCard->vcard() );
}
else
{
m_mainWidget->lblStatus->setText( i18n("Error: Unable to save vCard.") );
}
setEnabled(true);
}
void dlgJabberVCard::slotGetVCard()
{
m_mainWidget->lblStatus->setText( i18n("Fetching contact vCard...") );
setReadOnly(true);
setEnabled(false);
XMPP::JT_VCard *task = new XMPP::JT_VCard ( m_account->client()->rootTask() );
// signal to ourselves when the vCard data arrived
TQObject::connect( task, TQT_SIGNAL ( finished () ), this, TQT_SLOT ( slotGotVCard () ) );
task->get ( m_contact->rosterItem().jid().full() );
task->go ( true );
}
void dlgJabberVCard::slotGotVCard()
{
XMPP::JT_VCard * vCard = (XMPP::JT_VCard *) sender ();
if( vCard->success() )
{
m_contact->setPropertiesFromVCard( vCard->vcard() );
setEnabled( true );
assignContactProperties();
m_mainWidget->lblStatus->setText( i18n("vCard fetching Done.") );
}
else
{
m_mainWidget->lblStatus->setText( i18n("Error: vCard could not be fetched correctly. Check connectivity with the Jabber server.") );
//it is maybe possible to anyway edit our own vCard (if it is new
if(m_account->myself() == m_contact)
setEnabled( true );
}
}
void dlgJabberVCard::slotSelectPhoto()
{
TQString path;
bool remoteFile = false;
KURL filePath = KFileDialog::getImageOpenURL( TQString(), this, i18n( "Jabber Photo" ) );
if( filePath.isEmpty() )
return;
if( !filePath.isLocalFile() )
{
if( !TDEIO::NetAccess::download( filePath, path, this ) )
{
KMessageBox::queuedMessageBox( this, KMessageBox::Sorry, i18n( "Downloading of Jabber contact photo failed!" ) );
return;
}
remoteFile = true;
}
else
path = filePath.path();
TQImage img( path );
img = KPixmapRegionSelectorDialog::getSelectedImage( TQPixmap(img), 96, 96, this );
if( !img.isNull() )
{
if(img.width() > 96 || img.height() > 96)
{
// Scale and crop the picture.
img = img.smoothScale( 96, 96, TQ_ScaleMin );
// crop image if not square
if(img.width() < img.height())
img = img.copy((img.width()-img.height())/2, 0, 96, 96);
else if (img.width() > img.height())
img = img.copy(0, (img.height()-img.width())/2, 96, 96);
}
else if (img.width() < 32 || img.height() < 32)
{
// Scale and crop the picture.
img = img.smoothScale( 32, 32, TQ_ScaleMin );
// crop image if not square
if(img.width() < img.height())
img = img.copy((img.width()-img.height())/2, 0, 32, 32);
else if (img.width() > img.height())
img = img.copy(0, (img.height()-img.width())/2, 32, 32);
}
else if (img.width() != img.height())
{
if(img.width() < img.height())
img = img.copy((img.width()-img.height())/2, 0, img.height(), img.height());
else if (img.width() > img.height())
img = img.copy(0, (img.height()-img.width())/2, img.height(), img.height());
}
m_photoPath = locateLocal("appdata", "jabberphotos/" + m_contact->rosterItem().jid().full().lower().replace(TQRegExp("[./~]"),"-") +".png");
if( img.save(m_photoPath, "PNG") )
{
m_mainWidget->lblPhoto->setPixmap( TQPixmap(img) );
}
else
{
m_photoPath = TQString();
}
}
else
{
KMessageBox::queuedMessageBox( this, KMessageBox::Sorry, i18n( "<qt>An error occurred when trying to change the photo.<br>"
"Make sure that you have selected a correct image file</qt>" ) );
}
if( remoteFile )
TDEIO::NetAccess::removeTempFile( path );
}
void dlgJabberVCard::slotClearPhoto()
{
m_mainWidget->lblPhoto->setPixmap( TQPixmap() );
m_photoPath = TQString();
}
void dlgJabberVCard::slotOpenURL(const TQString &url)
{
if ( !url.isEmpty () || (url == TQString::fromLatin1("mailto:") ) )
new KRun(KURL( url ) );
}
#include "dlgjabbervcard.moc"
/*
* Local variables:
* c-indentation-style: k&r
* c-basic-offset: 8
* indent-tabs-mode: t
* End:
*/
// vim: set noet ts=4 sts=4 sw=4:
|