• 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
  • identity
accountidentitydialog.cpp
Go to the documentation of this file.
1 /*
2  accountidentitydialog.cpp - Kopete Add Identity Dialog
3 
4  Copyright (c) 2007 by Gustavo Pichorim Boiko <gustavo.boiko@kdemail.net>
5 
6  Kopete (c) 2003-2007 by the Kopete developers <kopete-devel@kde.org>
7 
8  *************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  *************************************************************************
16 */
17 
18 #include "accountidentitydialog.h"
19 #include "ui_accountidentitybase.h"
20 
21 #include <QHeaderView>
22 #include <QMap>
23 #include <QPointer>
24 #include <KIcon>
25 #include <KMessageBox>
26 
27 #include "kopeteidentity.h"
28 #include "kopeteidentitymanager.h"
29 #include "kopeteaccount.h"
30 #include "kopeteaccountmanager.h"
31 #include "kopeteprotocol.h"
32 
33 class AccountIdentityDialog::Private
34 {
35 public:
36  Private()
37  {
38  hiddenIdentity = 0;
39  currentIdentity = 0;
40  }
41 
42  QTreeWidgetItem* selectedIdentity();
43 
44  QMap<QTreeWidgetItem *, Kopete::Identity *> identityItems;
45  Ui::AccountIdentityBase ui;
46  Kopete::Identity *hiddenIdentity;
47  Kopete::Identity *currentIdentity;
48  QList<Kopete::Account*> accounts;
49 };
50 
51 AccountIdentityDialog::AccountIdentityDialog( QWidget *parent )
52  : KDialog(parent)
53  , d(new Private)
54 {
55  setButtons(KDialog::Ok | KDialog::Cancel);
56  d->ui.setupUi(mainWidget());
57  d->ui.identityList->setColumnCount( 1 );
58  d->ui.title->setPixmap(KIcon("identity").pixmap(22,22), KTitleWidget::ImageRight);
59 
60  QHeaderView *header = d->ui.identityList->header();
61  header->setVisible(false);
62 
63  // hook up the user input
64  connect(d->ui.identityList, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
65  this, SLOT(slotValidate()));
66  connect(d->ui.identityList, SIGNAL(itemSelectionChanged()),
67  this, SLOT(slotValidate()));
68  connect(d->ui.identityList, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),
69  this, SLOT(slotIdentityListDoubleClicked()));
70 
71  // identity manager signals
72  Kopete::IdentityManager *manager = Kopete::IdentityManager::self();
73  connect(manager, SIGNAL(identityRegistered(Kopete::Identity*)), this, SLOT(slotLoadIdentities()));
74  connect(manager, SIGNAL(identityUnregistered(const Kopete::Identity*)), this, SLOT(slotLoadIdentities()));
75 
76  // account manager signals
77  Kopete::AccountManager *acmanager = Kopete::AccountManager::self();
78  connect(acmanager, SIGNAL(accountOnlineStatusChanged(Kopete::Account*,Kopete::OnlineStatus,Kopete::OnlineStatus)),
79  this, SLOT(slotLoadAccounts()));
80  slotLoadIdentities();
81  slotValidate();
82 }
83 
84 QTreeWidgetItem* AccountIdentityDialog::Private::selectedIdentity()
85 {
86  QList<QTreeWidgetItem*> selectedItems = ui.identityList->selectedItems();
87  if(!selectedItems.empty())
88  return selectedItems.first();
89  return 0;
90 }
91 
92 void AccountIdentityDialog::slotValidate()
93 {
94  // if no identity was selected, we can't continue
95  enableButtonOk( d->selectedIdentity() );
96 }
97 
98 void AccountIdentityDialog::slotIdentityListDoubleClicked()
99 {
100  if (d->selectedIdentity())
101  accept();
102 }
103 
104 void AccountIdentityDialog::slotLoadIdentities()
105 {
106  // clear things before loading again
107  d->identityItems.clear();
108  d->ui.identityList->clear();
109 
110  //add the available identities to the list
111  foreach(Kopete::Identity *ident, Kopete::IdentityManager::self()->identities())
112  {
113  // if we were asked to hide an identity, do not show it
114  if (ident == d->hiddenIdentity)
115  continue;
116 
117  QTreeWidgetItem *identityItem = new QTreeWidgetItem(d->ui.identityList);
118  identityItem->setIcon(0, KIcon(ident->customIcon()));
119  identityItem->setText(0, ident->label());
120  d->identityItems.insert(identityItem, ident);
121  if (ident == d->currentIdentity)
122  identityItem->setSelected(true);
123  }
124 }
125 
126 void AccountIdentityDialog::slotLoadAccounts()
127 {
128  d->currentIdentity = 0;
129 
130  // set the accounts label
131  QString text;
132  foreach(Kopete::Account *account, d->accounts)
133  {
134  if (account->identity() != d->currentIdentity)
135  d->currentIdentity = account->identity();
136 
137  text += QString("<nobr><img src=\"kopete-account-icon:%3:%4\"> <b>%1:</b> %2 <br/>")
138  .arg(account->protocol()->displayName())
139  .arg(account->accountLabel())
140  .arg(QString(QUrl::toPercentEncoding( account->protocol()->pluginId() )))
141  .arg(QString(QUrl::toPercentEncoding( account->accountId() )));
142  }
143 
144  d->ui.accounts->setText(text);
145  slotLoadIdentities();
146 }
147 
148 void AccountIdentityDialog::accept()
149 {
150  Kopete::Identity *ident = d->identityItems[d->selectedIdentity()];
151  if (!ident)
152  return;
153 
154  foreach(Kopete::Account *account, d->accounts)
155  {
156  account->setIdentity(ident);
157  }
158 
159  KDialog::accept();
160 }
161 
162 void AccountIdentityDialog::reject()
163 {
164  KDialog::reject();
165 }
166 
167 AccountIdentityDialog::~AccountIdentityDialog()
168 {
169  delete d;
170 }
171 
172 void AccountIdentityDialog::setAccount( Kopete::Account *account )
173 {
174  d->accounts.clear();
175  d->accounts.append( account );
176  slotLoadAccounts();
177 }
178 
179 void AccountIdentityDialog::setAccounts( QList<Kopete::Account*> accountList )
180 {
181  d->accounts = accountList;
182  slotLoadAccounts();
183 }
184 
185 void AccountIdentityDialog::setMessage( const QString &text )
186 {
187  d->ui.selectText->setText( text );
188 }
189 
190 void AccountIdentityDialog::setHiddenIdentity( Kopete::Identity *ident )
191 {
192  d->hiddenIdentity = ident;
193  slotLoadIdentities();
194 }
195 
196 // static member functions
197 
198 bool AccountIdentityDialog::changeAccountIdentity( QWidget *parent, Kopete::Account *account,
199  Kopete::Identity *hidden_ident,
200  const QString &message )
201 {
202  QPointer <AccountIdentityDialog> dialog = new AccountIdentityDialog( parent );
203 
204  dialog->setAccount( account );
205  dialog->setHiddenIdentity( hidden_ident );
206  if ( !message.isEmpty() )
207  dialog->setMessage( message );
208 
209  int ret = dialog->exec();
210  delete dialog;
211  return ret;
212 }
213 
214 bool AccountIdentityDialog::changeAccountIdentity( QWidget *parent, QList<Kopete::Account*> accountList,
215  Kopete::Identity *hidden_ident,
216  const QString &message )
217 {
218  QPointer <AccountIdentityDialog> dialog = new AccountIdentityDialog( parent );
219 
220  dialog->setAccounts( accountList );
221  dialog->setHiddenIdentity( hidden_ident );
222  if ( !message.isEmpty() )
223  dialog->setMessage( message );
224 
225  int ret = dialog->exec();
226  delete dialog;
227  return ret;
228 }
229 
230 #include "accountidentitydialog.moc"
231 
232 // vim: set noet ts=4 sts=4 sw=4:
233 
AccountIdentityDialog::AccountIdentityDialog
AccountIdentityDialog(QWidget *parent=0)
Default constructor for the account identity dialog.
Definition: accountidentitydialog.cpp:51
QWidget
AccountIdentityDialog::setAccount
void setAccount(Kopete::Account *account)
Sets the account this dialog will change the identity of.
Definition: accountidentitydialog.cpp:172
QMap< QTreeWidgetItem *, Kopete::Identity * >
AccountIdentityDialog::accept
virtual void accept()
Definition: accountidentitydialog.cpp:148
manager
virtual Kopete::ChatSession * manager(Kopete::Contact::CanCreateFlags)
Definition: chatwindowconfig.cpp:94
QPointer
QTreeWidgetItem::setIcon
void setIcon(int column, const QIcon &icon)
QWidget::setVisible
virtual void setVisible(bool visible)
AccountIdentityDialog::reject
virtual void reject()
Definition: accountidentitydialog.cpp:162
KDialog
QList::empty
bool empty() const
QString::isEmpty
bool isEmpty() const
AccountIdentityDialog::setAccounts
void setAccounts(QList< Kopete::Account * > accountList)
Sets the accounts this dialog will change the identity of.
Definition: accountidentitydialog.cpp:179
AccountIdentityDialog::setHiddenIdentity
void setHiddenIdentity(Kopete::Identity *ident)
Sets the identity to be hidden.
Definition: accountidentitydialog.cpp:190
QList::first
T & first()
QString
QList< Kopete::Account * >
AccountIdentityDialog::setMessage
void setMessage(const QString &text)
Sets the text message to be displayed in the dialog.
Definition: accountidentitydialog.cpp:185
AccountIdentityDialog::~AccountIdentityDialog
~AccountIdentityDialog()
Definition: accountidentitydialog.cpp:167
QTreeWidgetItem
accountidentitydialog.h
QTreeWidgetItem::setSelected
void setSelected(bool select)
QTreeWidgetItem::setText
void setText(int column, const QString &text)
QUrl::toPercentEncoding
QByteArray toPercentEncoding(const QString &input, const QByteArray &exclude, const QByteArray &include)
QHeaderView
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
AccountIdentityDialog::changeAccountIdentity
static bool changeAccountIdentity(QWidget *parent, Kopete::Account *account, Kopete::Identity *hidden_ident=0, const QString &message=QString())
This is the easiest (and the recommended) way of changing the account identity.
Definition: accountidentitydialog.cpp:198
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