• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kopete/kopete

  • sources
  • kde-4.14
  • kdenetwork
  • kopete
  • kopete
  • contactlist
kopetelviprops.cpp
Go to the documentation of this file.
1 /*
2  kopetelviprops.cpp
3 
4  Kopete Contactlist Properties GUI for Groups and MetaContacts
5 
6  Copyright (c) 2002-2003 by Stefan Gehn <metz@gehn.net>
7  Copyright (c) 2004 by Will Stephenson <wstephenson@kde.org>
8  Copyright (c) 2004-2005 by Duncan Mac-Vicar P. <duncan@kde.org>
9 
10  Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org>
11 
12  *************************************************************************
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * *
19  *************************************************************************
20 */
21 
22 #include "kopetelviprops.h"
23 
24 #include <kdebug.h>
25 
26 #include <qapplication.h>
27 #include <qcheckbox.h>
28 #include <qlabel.h>
29 #include <qlayout.h>
30 #include <qpushbutton.h>
31 #include <qradiobutton.h>
32 #include <qtabwidget.h>
33 #include <qcombobox.h>
34 #include <QPixmap>
35 #include <QVBoxLayout>
36 #include <QHBoxLayout>
37 #include <QBoxLayout>
38 #include <QSize>
39 
40 #include <kfiledialog.h>
41 #include <kicondialog.h>
42 #include <kiconloader.h>
43 #include <klocale.h>
44 #include <kmessagebox.h>
45 #include <kurlrequester.h>
46 #include <kabc/addresseedialog.h>
47 #include <kabc/stdaddressbook.h>
48 #include <kabc/addressee.h>
49 #include <kstandarddirs.h>
50 
51 #include "kabcpersistence.h"
52 #include "kopeteaddrbookexport.h"
53 #include "kopetecontact.h"
54 #include "kopetegroup.h"
55 #include "kopeteaccount.h"
56 #include "kopeteprotocol.h"
57 #include "addressbooklinkwidget.h"
58 #include "avatardialog.h"
59 
60 #include "customnotificationprops.h"
61 
62 const QLatin1String MC_OFF( "user-offline" );
63 const QLatin1String MC_ON( "user-online" );
64 const QLatin1String MC_AW( "user-away" );
65 const QLatin1String MC_UNK( "metacontact_unknown" );
66 
67 // KDE4 port notes:
68 // setIcon has changed, so it has been commented out.
69 // also cmbPhotoUrl is gone completely. Let's pray for it
70 
71 KopeteGVIProps::KopeteGVIProps(Kopete::Group *group, QWidget *parent)
72 : KDialog(parent), mGroup( group )
73 {
74  setCaption( i18n("Properties of Group %1", mGroup->displayName()) );
75  setButtons( Ok | Cancel );
76 
77  mainWidget = new QWidget( this );
78  mainWidget->setObjectName( "mainWidget" );
79  ui_mainWidget = new Ui::KopeteGVIPropsWidget;
80  ui_mainWidget->setupUi( mainWidget );
81 
82  ui_mainWidget->icnbOpen->setIconSize(QSize(KIconLoader::SizeSmall,KIconLoader::SizeSmall));
83  ui_mainWidget->icnbClosed->setIconSize(QSize(KIconLoader::SizeSmall,KIconLoader::SizeSmall));
84  QPair<QString,QString> context=qMakePair( QString::fromLatin1("group") , QString::number(mGroup->groupId() ) );
85  mNotificationProps = new CustomNotificationProps( this, context );
86 
87  QWidget* npMainWidget = new QWidget();
88  QVBoxLayout* vbLayout = new QVBoxLayout( npMainWidget );
89  vbLayout->addWidget( mNotificationProps->widget() );
90  ui_mainWidget->tabWidget->addTab( npMainWidget, i18n( "Custom &Notifications" ) );
91 
92  setMainWidget(mainWidget);
93  m_dirty = false;
94 
95  ui_mainWidget->edtDisplayName->setText( mGroup->displayName() );
96 
97  ui_mainWidget->chkUseCustomIcons->setChecked( mGroup->useCustomIcon() );
98 
99 // QString openName = mGroup->icon( Kopete::ContactListElement::Open );
100 // if(openName.isEmpty())
101 // openName = KOPETE_GROUP_DEFAULT_OPEN_ICON;
102 // QString closeName = mGroup->icon( Kopete::ContactListElement::Closed );
103 // if(closeName.isEmpty())
104 // closeName = KOPETE_GROUP_DEFAULT_CLOSED_ICON;
105 // ui_mainWidget->icnbOpen->setIcon( openName );
106 // ui_mainWidget->icnbClosed->setIcon( closeName );
107 
108  connect( this, SIGNAL(okClicked()), this, SLOT(slotOkClicked()) );
109  connect( ui_mainWidget->chkUseCustomIcons, SIGNAL(toggled(bool)),
110  this, SLOT(slotUseCustomIconsToggled(bool)) );
111  connect( ui_mainWidget->icnbOpen, SIGNAL(iconChanged(QString)),
112  SLOT(slotIconChanged()) );
113  connect( ui_mainWidget->icnbClosed, SIGNAL(iconChanged(QString)),
114  SLOT(slotIconChanged()) );
115  slotUseCustomIconsToggled( ui_mainWidget->chkUseCustomIcons->isChecked() );
116 }
117 
118 KopeteGVIProps::~KopeteGVIProps()
119 {
120  delete ui_mainWidget;
121 }
122 
123 void KopeteGVIProps::slotOkClicked()
124 {
125  if( ui_mainWidget->edtDisplayName->text() != mGroup->displayName() )
126  {
127  mGroup->setDisplayName( ui_mainWidget->edtDisplayName->text() );
128  }
129 
130  mGroup->setUseCustomIcon( ui_mainWidget->chkUseCustomIcons->isChecked() );
131 
132  // only call setIcon if the icon was changed
133  if( m_dirty )
134  {
135 /* mGroup->setIcon( ui_mainWidget->icnbOpen->icon(),
136  Kopete::ContactListElement::Open );
137 
138  mGroup->setIcon( ui_mainWidget->icnbClosed->icon(),
139  Kopete::ContactListElement::Closed );
140 */ }
141 
142  mNotificationProps->storeCurrentCustoms();
143 }
144 
145 void KopeteGVIProps::slotUseCustomIconsToggled(bool on)
146 {
147  ui_mainWidget->lblOpen->setEnabled( on );
148  ui_mainWidget->icnbOpen->setEnabled( on );
149  ui_mainWidget->lblClosed->setEnabled( on );
150  ui_mainWidget->icnbClosed->setEnabled( on );
151 }
152 
153 void KopeteGVIProps::slotIconChanged()
154 {
155  m_dirty = true;
156 }
157 
158 // =============================================================================
159 
160 
161 KopeteMetaLVIProps::KopeteMetaLVIProps(Kopete::MetaContact *metaContact, QWidget *parent)
162 : KDialog(parent), mMetaContact( metaContact )
163 {
164  setCaption( i18n("Properties of Meta Contact %1", mMetaContact->displayName()) );
165  setButtons( Ok | Cancel );
166  m_countPhotoCapable = 0;
167 
168  mainWidget = new QWidget( this );
169  mainWidget->setObjectName( "mainWidget" );
170  ui_mainWidget = new Ui::KopeteMetaLVIPropsWidget;
171  ui_mainWidget->setupUi( mainWidget );
172 
173  ui_mainWidget->icnbOffline->setIconSize( QSize(KIconLoader::SizeSmall,KIconLoader::SizeSmall) );
174  ui_mainWidget->icnbOnline->setIconSize( QSize(KIconLoader::SizeSmall,KIconLoader::SizeSmall) );
175  ui_mainWidget->icnbAway->setIconSize( QSize(KIconLoader::SizeSmall,KIconLoader::SizeSmall) );
176  ui_mainWidget->icnbUnknown->setIconSize( QSize(KIconLoader::SizeSmall,KIconLoader::SizeSmall) );
177 
178  QPair<QString,QString> context=qMakePair( QString::fromLatin1("contact"), mMetaContact->metaContactId().toString() );
179  mNotificationProps = new CustomNotificationProps( this, context );
180  // add a button to the notification props to get the sound from KABC
181  // the widget's vert box layout, horiz box layout containing button, spacer, followed by a spacer
182  QBoxLayout * vb = static_cast<QVBoxLayout*>( mNotificationProps->widget()->layout() );
183 
184  QHBoxLayout* hb = new QHBoxLayout();
185  vb->addItem( hb );
186  hb->setMargin( -1 );
187  hb->setObjectName( "soundFromKABClayout" );
188 
189  mFromKABC = new QPushButton( i18n( "Sync KABC..." ), mNotificationProps->widget() );
190  mFromKABC->setObjectName( QLatin1String("getSoundFromKABC") );
191  hb->addWidget( mFromKABC ); // [ [Button] <-xxxxx-> ]
192  hb->addStretch();
193  vb->addStretch(); // vert spacer keeps the rest snug
194 
195  QWidget* npMainWidget = new QWidget();
196  QVBoxLayout* vbLayout = new QVBoxLayout( npMainWidget );
197  vbLayout->addWidget( mNotificationProps->widget() );
198 
199  ui_mainWidget->tabWidget->addTab( npMainWidget, i18n( "Custom &Notifications" ) );
200  setMainWidget( mainWidget );
201 
202  connect( ui_mainWidget->radioNameKABC, SIGNAL(toggled(bool)), SLOT(slotEnableAndDisableWidgets()));
203  connect( ui_mainWidget->radioNameContact, SIGNAL(toggled(bool)), SLOT(slotEnableAndDisableWidgets()));
204  connect( ui_mainWidget->radioNameCustom, SIGNAL(toggled(bool)), SLOT(slotEnableAndDisableWidgets()));
205  connect( ui_mainWidget->radioPhotoKABC, SIGNAL(toggled(bool)), SLOT(slotEnableAndDisableWidgets()));
206  connect( ui_mainWidget->radioPhotoContact, SIGNAL(toggled(bool)), SLOT(slotEnableAndDisableWidgets()));
207  connect( ui_mainWidget->radioPhotoCustom, SIGNAL(toggled(bool)), SLOT(slotEnableAndDisableWidgets()));
208  connect( ui_mainWidget->cmbAccountPhoto, SIGNAL(activated(int)), SLOT(slotEnableAndDisableWidgets()));
209 
210 
211  ui_mainWidget->btnClearPhoto->setIcon( KIcon( (QApplication::layoutDirection() == Qt::RightToLeft) ? "edit-clear-locationbar-ltr" : "edit-clear-locationbar-rtl" ) );
212  connect( ui_mainWidget->btnClearPhoto, SIGNAL(clicked()), this, SLOT(slotClearPhotoClicked()) );
213  connect( ui_mainWidget->widAddresseeLink, SIGNAL(addresseeChanged(KABC::Addressee)), SLOT(slotAddresseeChanged(KABC::Addressee)) );
214  connect( ui_mainWidget->btnChoosePhoto, SIGNAL(clicked()), this, SLOT(slotSelectPhoto()));
215  ui_mainWidget->chkUseCustomIcons->setChecked( mMetaContact->useCustomIcon() );
216 
217  QString offlineName = mMetaContact->icon( Kopete::ContactListElement::Offline );
218  if(offlineName.isEmpty())
219  offlineName = MC_OFF; // Default
220 
221  QString onlineName = mMetaContact->icon( Kopete::ContactListElement::Online );
222  if(onlineName.isEmpty())
223  onlineName = MC_ON; // Default
224 
225  QString awayName = mMetaContact->icon( Kopete::ContactListElement::Away );
226  if(awayName.isEmpty())
227  awayName = MC_AW; // Default
228 
229  QString unknownName = mMetaContact->icon( Kopete::ContactListElement::Unknown );
230  if(unknownName.isEmpty())
231  unknownName = MC_UNK; // Default
232 
233 // ui_mainWidget->icnbOffline->setIcon( offlineName );
234 // ui_mainWidget->icnbOnline->setIcon( onlineName );
235 // ui_mainWidget->icnbAway->setIcon( awayName );
236 // ui_mainWidget->icnbUnknown->setIcon( unknownName );
237 
238  ui_mainWidget->widAddresseeLink->setMetaContact( mMetaContact );
239 
240  mAddressBookUid = mMetaContact->kabcId();
241 
242  mExport = 0L;
243 
244  if ( !mAddressBookUid.isEmpty() )
245  {
246  KABC::AddressBook *ab = Kopete::KABCPersistence::self()->addressBook();
247  KABC::Addressee a = ab->findByUid( mAddressBookUid );
248  ui_mainWidget->widAddresseeLink->setAddressee( a );
249 
250  if ( !a.isEmpty() )
251  {
252  ui_mainWidget->btnImportKABC->setEnabled( true );
253  ui_mainWidget->btnExportKABC->setEnabled( true );
254  mExport = new KopeteAddressBookExport( this, mMetaContact );
255 
256  mSound = a.sound();
257  mFromKABC->setEnabled( !( mSound.isIntern() || mSound.url().isEmpty() ) );
258  }
259  }
260 
261  slotLoadNameSources();
262  slotLoadPhotoSources();
263 
264  connect( this, SIGNAL(okClicked()), this, SLOT(slotOkClicked()) );
265  connect( ui_mainWidget->chkUseCustomIcons, SIGNAL(toggled(bool)),
266  this, SLOT(slotUseCustomIconsToggled(bool)) );
267  connect( ui_mainWidget->btnImportKABC, SIGNAL(clicked()),
268  this, SLOT(slotImportClicked()) );
269  connect( ui_mainWidget->btnExportKABC, SIGNAL(clicked()),
270  this, SLOT(slotExportClicked()) );
271  connect( mFromKABC, SIGNAL(clicked()),
272  this, SLOT(slotFromKABCClicked()) );
273 
274  slotUseCustomIconsToggled( ui_mainWidget->chkUseCustomIcons->isChecked() );
275  slotEnableAndDisableWidgets();
276 }
277 
278 KopeteMetaLVIProps::~KopeteMetaLVIProps()
279 {
280  delete ui_mainWidget;
281 }
282 
283 
284 void KopeteMetaLVIProps::slotLoadNameSources()
285 {
286  Kopete::Contact* trackingName = mMetaContact->displayNameSourceContact();
287  QList<Kopete::Contact*> cList = mMetaContact->contacts();
288  QList<Kopete::Contact*>::iterator it = cList.begin();
289  ui_mainWidget->cmbAccountName->clear();
290  for( ; it != cList.end(); ++it )
291  {
292  QString acct;
293  QVariant acctData;
294  QVariant acctContact = QVariant::fromValue(static_cast<QObject *>(*it));
295  QIcon acctIcon = QPixmap((*it)->account()->accountIcon());
296  bool isTrackingName = ((*it) == trackingName);
297 
298  acct = (*it)->customName() + " <" + (*it)->contactId() + "> " + i18n("(custom name)");
299  acctData = QVariantList() << acctContact << QVariant((uint)Kopete::Contact::CustomName);
300  ui_mainWidget->cmbAccountName->addItem( acctIcon, acct, acctData );
301  if (isTrackingName && (*it)->preferredNameType() == Kopete::Contact::CustomName)
302  ui_mainWidget->cmbAccountName->setCurrentIndex( ui_mainWidget->cmbAccountName->count() - 1 );
303 
304  acct = (*it)->nickName() + " <" + (*it)->contactId() + "> " + i18n("(nick name)");
305  acctData = QVariantList() << acctContact << QVariant((uint)Kopete::Contact::NickName);
306  ui_mainWidget->cmbAccountName->addItem( acctIcon, acct, acctData );
307  if (isTrackingName && (*it)->preferredNameType() == Kopete::Contact::NickName)
308  ui_mainWidget->cmbAccountName->setCurrentIndex( ui_mainWidget->cmbAccountName->count() - 1 );
309 
310  acct = (*it)->formattedName() + " <" + (*it)->contactId() + "> " + i18n("(formatted name)");
311  acctData = QVariantList() << acctContact << QVariant((uint)Kopete::Contact::FormattedName);
312  ui_mainWidget->cmbAccountName->addItem( acctIcon, acct, acctData );
313  if (isTrackingName && (*it)->preferredNameType() == Kopete::Contact::FormattedName)
314  ui_mainWidget->cmbAccountName->setCurrentIndex( ui_mainWidget->cmbAccountName->count() - 1 );
315 
316  acct = (*it)->contactId() + " " + i18n("(contact id)");
317  acctData = QVariantList() << acctContact << QVariant((uint)Kopete::Contact::ContactId);
318  ui_mainWidget->cmbAccountName->addItem( acctIcon, acct, acctData );
319  if (isTrackingName && (*it)->preferredNameType() == Kopete::Contact::ContactId)
320  ui_mainWidget->cmbAccountName->setCurrentIndex( ui_mainWidget->cmbAccountName->count() - 1 );
321  }
322 
323  ui_mainWidget->edtDisplayName->setText( mMetaContact->customDisplayName() );
324 
325  Kopete::MetaContact::PropertySource nameSource = mMetaContact->displayNameSource();
326 
327  ui_mainWidget->radioNameContact->setChecked(nameSource == Kopete::MetaContact::SourceContact);
328  ui_mainWidget->radioNameKABC->setChecked(nameSource == Kopete::MetaContact::SourceKABC);
329  ui_mainWidget->radioNameCustom->setChecked(nameSource == Kopete::MetaContact::SourceCustom);
330 
331 }
332 
333 void KopeteMetaLVIProps::slotLoadPhotoSources()
334 {
335  // fill photo contact sources
336  QList<Kopete::Contact*> cList = mMetaContact->contacts();
337  m_withPhotoContacts.clear();
338  Kopete::Contact* trackingPhoto = mMetaContact->photoSourceContact();
339  ui_mainWidget->cmbAccountPhoto->clear();
340  QList<Kopete::Contact*>::iterator itp = cList.begin();
341  for( ; itp != cList.end(); ++itp )
342  {
343  Kopete::Contact *citem = (*itp);
344  if ( citem->hasProperty( Kopete::Global::Properties::self()->photo().key() ) )
345  {
346  QString acct = citem->displayName() + " <" + citem->contactId() + '>';
347  QPixmap acctIcon = citem->account()->accountIcon();
348  ui_mainWidget->cmbAccountPhoto->addItem( QIcon(acctIcon), acct );
349 
350  // Select this item if it's the one we're tracking.
351  if( citem == trackingPhoto )
352  {
353  ui_mainWidget->cmbAccountPhoto->setCurrentIndex( ui_mainWidget->cmbAccountPhoto->count() - 1 );
354  }
355  m_withPhotoContacts.insert(ui_mainWidget->cmbAccountPhoto->count() - 1 , citem );
356  }
357  }
358 
359  m_photoPath = mMetaContact->customPhoto().path();
360 
361  Kopete::MetaContact::PropertySource photoSource = mMetaContact->photoSource();
362 
363  ui_mainWidget->radioPhotoContact->setChecked(photoSource == Kopete::MetaContact::SourceContact);
364  ui_mainWidget->radioPhotoKABC->setChecked(photoSource == Kopete::MetaContact::SourceKABC);
365  ui_mainWidget->radioPhotoCustom->setChecked(photoSource == Kopete::MetaContact::SourceCustom);
366 
367  ui_mainWidget->chkSyncPhoto->setChecked(mMetaContact->isPhotoSyncedWithKABC());
368 }
369 
370 void KopeteMetaLVIProps::slotSelectPhoto()
371 {
372  const QString path = Kopete::UI::AvatarDialog::getAvatar(this, m_photoPath);
373  if (path.isNull())
374  return;
375 
376  m_photoPath = path;
377  slotEnableAndDisableWidgets();
378 }
379 
380 void KopeteMetaLVIProps::slotEnableAndDisableWidgets()
381 {
382  KABC::AddressBook *ab = Kopete::KABCPersistence::self()->addressBook();
383  KABC::Addressee a = ab->findByUid( mAddressBookUid );
384  bool validLink = ! a.isEmpty();
385  // kabc source requires a kabc link
386  ui_mainWidget->radioNameKABC->setEnabled(validLink);
387  // kabc source requires a kabc link
388  ui_mainWidget->radioPhotoKABC->setEnabled(validLink);
389  // sync with kabc has no sense if we use kabc as source (sync kabc with kabc? uh?)
390  // it has also no sense if they are no kabc link
391  if( selectedPhotoSource() == Kopete::MetaContact::SourceKABC || !validLink )
392  {
393  ui_mainWidget->chkSyncPhoto->setEnabled(false);
394  }
395  else
396  {
397  ui_mainWidget->chkSyncPhoto->setEnabled(true);
398  }
399 
400  ui_mainWidget->radioNameContact->setEnabled(mMetaContact->contacts().count());
401  ui_mainWidget->radioPhotoContact->setEnabled(!m_withPhotoContacts.isEmpty());
402 
403  ui_mainWidget->cmbAccountName->setEnabled(selectedNameSource() == Kopete::MetaContact::SourceContact);
404  ui_mainWidget->edtDisplayName->setEnabled(selectedNameSource() == Kopete::MetaContact::SourceCustom);
405 
406  ui_mainWidget->cmbAccountPhoto->setEnabled(selectedPhotoSource() == Kopete::MetaContact::SourceContact);
407  ui_mainWidget->btnChoosePhoto->setEnabled(selectedPhotoSource() == Kopete::MetaContact::SourceCustom);
408 
409  if ( m_withPhotoContacts.isEmpty() )
410  {
411  ui_mainWidget->cmbAccountPhoto->clear();
412  ui_mainWidget->cmbAccountPhoto->addItem(i18n("No Contacts with Photo Support"));
413  ui_mainWidget->cmbAccountPhoto->setEnabled(false);
414  }
415 
416  QImage photo;
417  switch ( selectedPhotoSource() )
418  {
419  case Kopete::MetaContact::SourceKABC:
420  photo = Kopete::photoFromKABC(mAddressBookUid);
421  break;
422  case Kopete::MetaContact::SourceContact:
423  photo = Kopete::photoFromContact(selectedPhotoSourceContact());
424  break;
425  case Kopete::MetaContact::SourceCustom:
426  photo = QImage(m_photoPath);
427  break;
428  }
429  if( !photo.isNull() )
430  ui_mainWidget->photoLabel->setPixmap(QPixmap::fromImage(photo.scaled(96, 96)));
431  else
432  ui_mainWidget->photoLabel->setPixmap( QPixmap() );
433 }
434 
435 Kopete::MetaContact::PropertySource KopeteMetaLVIProps::selectedNameSource() const
436 {
437  if ( ui_mainWidget->radioNameKABC->isChecked() )
438  return Kopete::MetaContact::SourceKABC;
439  if ( ui_mainWidget->radioNameContact->isChecked() )
440  return Kopete::MetaContact::SourceContact;
441  if ( ui_mainWidget->radioNameCustom->isChecked() )
442  return Kopete::MetaContact::SourceCustom;
443  else
444  return Kopete::MetaContact::SourceCustom;
445 }
446 
447 Kopete::MetaContact::PropertySource KopeteMetaLVIProps::selectedPhotoSource() const
448 {
449  if ( ui_mainWidget->radioPhotoKABC->isChecked() )
450  return Kopete::MetaContact::SourceKABC;
451  if ( ui_mainWidget->radioPhotoContact->isChecked() )
452  return Kopete::MetaContact::SourceContact;
453  if ( ui_mainWidget->radioPhotoCustom->isChecked() )
454  return Kopete::MetaContact::SourceCustom;
455  else
456  return Kopete::MetaContact::SourceCustom;
457 }
458 
459 Kopete::Contact* KopeteMetaLVIProps::selectedNameSourceContact() const
460 {
461  QVariantList data = ui_mainWidget->cmbAccountName->itemData(ui_mainWidget->cmbAccountName->currentIndex()).toList();
462  QObject *object = data.at(0).value<QObject *>();
463  return static_cast<Kopete::Contact *>(object);
464 }
465 
466 void KopeteMetaLVIProps::setContactsNameTypes()
467 {
468  QVariantList data = ui_mainWidget->cmbAccountName->itemData(ui_mainWidget->cmbAccountName->currentIndex()).toList();
469  QObject *object = data.at(0).value<QObject *>();
470  Kopete::Contact *contact = static_cast<Kopete::Contact *>(object);
471  Kopete::Contact::NameType nameType = (Kopete::Contact::NameType)data.at(1).toUInt();
472  Kopete::MetaContact::PropertySource nameSource = selectedNameSource();
473 
474  QList<Kopete::Contact*> cList = mMetaContact->contacts();
475  QList<Kopete::Contact*>::iterator it = cList.begin();
476  for( ; it != cList.end(); ++it )
477  {
478  if (nameSource == Kopete::MetaContact::SourceContact && (*it) == contact)
479  contact->setPreferredNameType(nameType);
480  else
481  contact->setPreferredNameType(Kopete::Contact::CustomName);
482  }
483 
484 }
485 
486 Kopete::Contact* KopeteMetaLVIProps::selectedPhotoSourceContact() const
487 {
488  return m_withPhotoContacts.value( ui_mainWidget->cmbAccountPhoto->currentIndex(), 0 );
489 }
490 
491 void KopeteMetaLVIProps::slotOkClicked()
492 {
493  // update meta contact's UID
494  mMetaContact->setKabcId( mAddressBookUid );
495  //this has to be done first, in the case something is synced with KABC (see bug 109494)
496 
497  // set custom display name
498  if( ui_mainWidget->edtDisplayName->text() != mMetaContact->customDisplayName() )
499  mMetaContact->setDisplayName( ui_mainWidget->edtDisplayName->text() );
500 
501  mMetaContact->setDisplayNameSource(selectedNameSource());
502  mMetaContact->setDisplayNameSourceContact( selectedNameSourceContact() );
503 
504  setContactsNameTypes();
505 
506  // set photo source
507  mMetaContact->setPhotoSource(selectedPhotoSource());
508  mMetaContact->setPhotoSourceContact( selectedPhotoSourceContact() );
509  if ( !m_photoPath.isEmpty())
510  mMetaContact->setPhoto(KUrl(m_photoPath));
511  mMetaContact->setPhotoSyncedWithKABC( ui_mainWidget->chkSyncPhoto->isChecked() );
512 
513  mMetaContact->setUseCustomIcon(
514  ui_mainWidget->chkUseCustomIcons->isChecked() );
515 
516  // only call setIcon if any of the icons is not set to default icon
517 /*
518  if(
519  ui_mainWidget->icnbOffline->icon() != MC_OFF ||
520  ui_mainWidget->icnbOnline->icon() != MC_ON ||
521  ui_mainWidget->icnbAway->icon() != MC_AW ||
522  ui_mainWidget->icnbUnknown->icon() != MC_UNK )
523  {
524  mMetaContact->setIcon( ui_mainWidget->icnbOffline->icon(),
525  Kopete::ContactListElement::Offline );
526 
527  mMetaContact->setIcon( ui_mainWidget->icnbOnline->icon(),
528  Kopete::ContactListElement::Online );
529 
530  mMetaContact->setIcon( ui_mainWidget->icnbAway->icon(),
531  Kopete::ContactListElement::Away );
532 
533  mMetaContact->setIcon( ui_mainWidget->icnbUnknown->icon(),
534  Kopete::ContactListElement::Unknown );
535  }
536 */
537  mNotificationProps->storeCurrentCustoms();
538 }
539 
540 void KopeteMetaLVIProps::slotUseCustomIconsToggled(bool on)
541 {
542  ui_mainWidget->lblOffline->setEnabled( on );
543  ui_mainWidget->lblOnline->setEnabled( on );
544  ui_mainWidget->lblAway->setEnabled( on );
545  ui_mainWidget->lblUnknown->setEnabled( on );
546 
547  ui_mainWidget->icnbOffline->setEnabled( on );
548  ui_mainWidget->icnbOnline->setEnabled( on );
549  ui_mainWidget->icnbAway->setEnabled( on );
550  ui_mainWidget->icnbUnknown->setEnabled( on );
551 }
552 
553 void KopeteMetaLVIProps::slotAddresseeChanged( const KABC::Addressee & a )
554 {
555  if ( !a.isEmpty() )
556  {
557  mSound = a.sound();
558  mFromKABC->setEnabled( !( mSound.isIntern() || mSound.url().isEmpty() ) );
559  ui_mainWidget->btnExportKABC->setEnabled( true );
560  ui_mainWidget->btnImportKABC->setEnabled( true );
561  // set/update the MC's addressee uin field
562  mAddressBookUid = a.uid();
563  }
564  else
565  {
566  ui_mainWidget->btnExportKABC->setEnabled( false );
567  ui_mainWidget->btnImportKABC->setEnabled( false );
568  mAddressBookUid.clear();
569  ui_mainWidget->radioNameContact->setChecked( true );
570  ui_mainWidget->radioPhotoContact->setChecked( true );
571  }
572  slotEnableAndDisableWidgets();
573 }
574 
575 void KopeteMetaLVIProps::slotExportClicked()
576 {
577  mMetaContact->setKabcId( mAddressBookUid );
578  delete mExport;
579  mExport = new KopeteAddressBookExport( this, mMetaContact );
580  if ( mExport->showDialog() == QDialog::Accepted )
581  mExport->exportData();
582 }
583 
584 void KopeteMetaLVIProps::slotImportClicked()
585 {
586  mMetaContact->setKabcId( mAddressBookUid );
587  if ( Kopete::KABCPersistence::self()->syncWithKABC( mMetaContact ) )
588  KMessageBox::queuedMessageBox( this, KMessageBox::Information,
589  i18n( "No contacts were imported from the address book." ),
590  i18n( "No Change" ) );
591 }
592 
593 void KopeteMetaLVIProps::slotFromKABCClicked()
594 {
595 #if 0
596  mNotificationProps->widget()->customSound->setUrl( mSound.url() );
597 #endif
598 }
599 
600 void KopeteMetaLVIProps::slotOpenSoundDialog( KUrlRequester *requester )
601 {
602  // taken from kdelibs/kio/kfile/knotifydialog.cpp
603  // only need to init this once
604  requester->disconnect( SIGNAL(openFileDialog(KUrlRequester*)),
605  this, SLOT(slotOpenSoundDialog(KUrlRequester*)));
606 
607  KFileDialog *fileDialog = requester->fileDialog();
608  //fileDialog->setCaption( i18n("Select Sound File") );
609  QStringList filters;
610  filters << "audio/x-wav" << "audio/mpeg" << "application/ogg"
611  << "audio/x-adpcm";
612  fileDialog->setMimeFilter( filters );
613 
614  // find the first "sound"-resource that contains files
615  QStringList soundDirs =
616  KGlobal::dirs()->findDirs("data", "kopete/sounds");
617  soundDirs += KGlobal::dirs()->resourceDirs( "sound" );
618 
619  if ( !soundDirs.isEmpty() ) {
620  KUrl soundURL;
621  QDir dir;
622  dir.setFilter( QDir::Files | QDir::Readable );
623  QStringList::ConstIterator it = soundDirs.constBegin();
624  while ( it != soundDirs.constEnd() ) {
625  dir = *it;
626  if ( dir.isReadable() && dir.count() > 2 ) {
627  soundURL.setPath( *it );
628  fileDialog->setUrl( soundURL );
629  break;
630  }
631  ++it;
632  }
633  }
634 }
635 
636 void KopeteMetaLVIProps::slotClearPhotoClicked()
637 {
638  m_photoPath.clear();
639  mMetaContact->setPhoto( KUrl() );
640 
641  slotEnableAndDisableWidgets();
642 }
643 
644 #include "kopetelviprops.moc"
QWidget
KopeteAddressBookExport
Definition: kopeteaddrbookexport.h:40
KopeteAddressBookExport::exportData
void exportData()
Export the data to KABC if changed, omitting any duplicates.
Definition: kopeteaddrbookexport.cpp:199
QApplication::layoutDirection
Qt::LayoutDirection layoutDirection()
CustomNotificationProps::storeCurrentCustoms
void storeCurrentCustoms()
Definition: customnotificationprops.cpp:55
QHBoxLayout
QPixmap::fromImage
QPixmap fromImage(const QImage &image, QFlags< Qt::ImageConversionFlag > flags)
KDialog
KopeteAddressBookExport::showDialog
int showDialog()
Display the dialog.
Definition: kopeteaddrbookexport.cpp:168
QImage::isNull
bool isNull() const
QDir::isReadable
bool isReadable() const
kopetelviprops.h
QMap::clear
void clear()
QString::isNull
bool isNull() const
QDir::count
uint count() const
CustomNotificationProps::widget
QWidget * widget()
Definition: customnotificationprops.cpp:61
QString::clear
void clear()
KopeteGVIProps::KopeteGVIProps
KopeteGVIProps(Kopete::Group *group, QWidget *parent)
Definition: kopetelviprops.cpp:71
kopeteaddrbookexport.h
Kopete::Items::MetaContact
Definition: kopeteitembase.h:57
QDir::setFilter
void setFilter(QFlags< QDir::Filter > filters)
QWidget::setEnabled
void setEnabled(bool)
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QString::number
QString number(int n, int base)
Kopete::Items::Group
Definition: kopeteitembase.h:57
QObject
QList::isEmpty
bool isEmpty() const
QBoxLayout::addItem
virtual void addItem(QLayoutItem *item)
QObject::setObjectName
void setObjectName(const QString &name)
QString::isEmpty
bool isEmpty() const
QVBoxLayout
QString
QList
KopeteMetaLVIProps::KopeteMetaLVIProps
KopeteMetaLVIProps(Kopete::MetaContact *metaContact, QWidget *parent)
Definition: kopetelviprops.cpp:161
QLayout::setMargin
void setMargin(int margin)
QList::iterator
MC_OFF
const QLatin1String MC_OFF("user-offline")
QStringList
MC_AW
const QLatin1String MC_AW("user-away")
QPair< QString, QString >
QPixmap
QList::end
iterator end()
QSize
QVariant::fromValue
QVariant fromValue(const T &value)
QImage
MC_ON
const QLatin1String MC_ON("user-online")
QDir
MC_UNK
const QLatin1String MC_UNK("metacontact_unknown")
QLatin1String
QBoxLayout::addStretch
void addStretch(int stretch)
CustomNotificationProps
Definition: customnotificationprops.h:30
QList::ConstIterator
typedef ConstIterator
QString::fromLatin1
QString fromLatin1(const char *str, int size)
customnotificationprops.h
QPushButton
QMap::insert
iterator insert(const Key &key, const T &value)
QMap::isEmpty
bool isEmpty() const
QList::constEnd
const_iterator constEnd() const
QList::constBegin
const_iterator constBegin() const
KopeteGVIProps::~KopeteGVIProps
~KopeteGVIProps()
Definition: kopetelviprops.cpp:118
QBoxLayout
QList::begin
iterator begin()
QImage::scaled
QImage scaled(int width, int height, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformMode) const
QDir::setPath
void setPath(const QString &path)
QIcon
KopeteMetaLVIProps::~KopeteMetaLVIProps
~KopeteMetaLVIProps()
Definition: kopetelviprops.cpp:278
QMap::value
const T value(const Key &key) const
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:29:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kopete/kopete

Skip menu "kopete/kopete"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal