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

kopete/kopete

accountidentitydialog.cpp

Go to the documentation of this file.
00001 /*
00002     accountidentitydialog.cpp - Kopete Add Identity Dialog
00003 
00004     Copyright (c) 2007      by Gustavo Pichorim Boiko <gustavo.boiko@kdemail.net>
00005 
00006     Kopete    (c) 2003-2007 by the Kopete developers <kopete-devel@kde.org>
00007 
00008     *************************************************************************
00009     *                                                                       *
00010     * This program is free software; you can redistribute it and/or modify  *
00011     * it under the terms of the GNU General Public License as published by  *
00012     * the Free Software Foundation; either version 2 of the License, or     *
00013     * (at your option) any later version.                                   *
00014     *                                                                       *
00015     *************************************************************************
00016 */
00017 
00018 #include "accountidentitydialog.h"
00019 #include "ui_accountidentitybase.h"
00020 
00021 #include <QHeaderView>
00022 #include <QMap>
00023 #include <KIcon>
00024 #include <KMessageBox>
00025 
00026 #include "kopeteidentity.h"
00027 #include "kopeteidentitymanager.h"
00028 #include "kopeteaccount.h"
00029 #include "kopeteaccountmanager.h"
00030 #include "kopeteprotocol.h"
00031 
00032 class AccountIdentityDialog::Private
00033 {
00034 public:
00035     Private() 
00036     {
00037         hiddenIdentity = 0;
00038         currentIdentity = 0;
00039     }
00040 
00041     QTreeWidgetItem* selectedIdentity();
00042 
00043     QMap<QTreeWidgetItem *, Kopete::Identity *>  identityItems;
00044     Ui::AccountIdentityBase ui;
00045     Kopete::Identity *hiddenIdentity;
00046     Kopete::Identity *currentIdentity;
00047     QList<Kopete::Account*> accounts;
00048 };
00049 
00050 AccountIdentityDialog::AccountIdentityDialog( QWidget *parent )
00051     : KDialog(parent)
00052     , d(new Private)
00053 {
00054     setButtons(KDialog::Ok | KDialog::Cancel);
00055     d->ui.setupUi(mainWidget());
00056     d->ui.identityList->setColumnCount( 1 );
00057     d->ui.title->setPixmap(KIcon("identity").pixmap(22,22), KTitleWidget::ImageRight);
00058 
00059     QHeaderView *header = d->ui.identityList->header(); 
00060     header->setVisible(false);
00061     
00062     // hook up the user input
00063     connect(d->ui.identityList, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
00064         this, SLOT(slotValidate()));
00065     connect(d->ui.identityList, SIGNAL(itemSelectionChanged()),
00066         this, SLOT( slotValidate()));
00067     connect(d->ui.identityList, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
00068         this, SLOT(slotIdentityListDoubleClicked()));
00069 
00070     // identity manager signals
00071     Kopete::IdentityManager *manager = Kopete::IdentityManager::self();
00072     connect(manager, SIGNAL(identityRegistered(Kopete::Identity*)), this, SLOT(slotLoadIdentities()));
00073     connect(manager, SIGNAL(identityUnregistered(const Kopete::Identity*)), this, SLOT(slotLoadIdentities()));
00074     
00075     // account manager signals
00076     Kopete::AccountManager *acmanager = Kopete::AccountManager::self();
00077     connect(acmanager, SIGNAL(accountOnlineStatusChanged(Kopete::Account*, const Kopete::OnlineStatus&, const Kopete::OnlineStatus&)),
00078             this, SLOT(slotLoadAccounts()));
00079     slotLoadIdentities();
00080     slotValidate();
00081 }
00082 
00083 QTreeWidgetItem* AccountIdentityDialog::Private::selectedIdentity()
00084 {
00085     QList<QTreeWidgetItem*> selectedItems = ui.identityList->selectedItems();
00086     if(!selectedItems.empty())
00087         return selectedItems.first();
00088     return 0;
00089 }
00090 
00091 void AccountIdentityDialog::slotValidate()
00092 {
00093     // if no identity was selected, we can't continue
00094     enableButtonOk( d->selectedIdentity() );
00095 }
00096 
00097 void AccountIdentityDialog::slotIdentityListDoubleClicked()
00098 {
00099     if (d->selectedIdentity())
00100         accept();
00101 }
00102 
00103 void AccountIdentityDialog::slotLoadIdentities()
00104 {
00105     // clear things before loading again
00106     d->identityItems.clear();
00107     d->ui.identityList->clear();
00108 
00109     //add the available identities to the list
00110     foreach(Kopete::Identity *ident, Kopete::IdentityManager::self()->identities())
00111     {
00112         // if we were asked to hide an identity, do not show it
00113         if (ident == d->hiddenIdentity)
00114             continue;
00115 
00116         QTreeWidgetItem *identityItem = new QTreeWidgetItem(d->ui.identityList);
00117         identityItem->setIcon(0, KIcon(ident->customIcon()));
00118         identityItem->setText(0, ident->label());
00119         d->identityItems.insert(identityItem, ident);
00120         if (ident == d->currentIdentity)
00121             identityItem->setSelected(true);
00122     }
00123 }
00124 
00125 void AccountIdentityDialog::slotLoadAccounts()
00126 {
00127     d->currentIdentity = 0;
00128 
00129     // set the accounts label
00130     QString text;
00131     foreach(Kopete::Account *account, d->accounts)
00132     {
00133         if (account->identity() != d->currentIdentity)
00134             d->currentIdentity = account->identity();
00135 
00136         text += QString("<nobr><img src=\"kopete-account-icon:%3:%4\"> <b>%1:</b> %2 <br/>")
00137                     .arg(account->protocol()->displayName())
00138                     .arg(account->accountLabel())
00139                     .arg(QString(QUrl::toPercentEncoding( account->protocol()->pluginId() )))
00140                     .arg(QString(QUrl::toPercentEncoding( account->accountId() )));
00141     }
00142 
00143     d->ui.accounts->setText(text);
00144     slotLoadIdentities();
00145 }
00146 
00147 void AccountIdentityDialog::accept()
00148 {
00149     Kopete::Identity *ident = d->identityItems[d->selectedIdentity()]; 
00150     if (!ident)
00151         return;
00152 
00153     foreach(Kopete::Account *account, d->accounts)
00154     {
00155         account->setIdentity(ident);
00156     }
00157 
00158     KDialog::accept();
00159 }
00160 
00161 void AccountIdentityDialog::reject()
00162 {
00163     KDialog::reject();
00164 }
00165 
00166 AccountIdentityDialog::~AccountIdentityDialog()
00167 {
00168     delete d;
00169 }
00170 
00171 void AccountIdentityDialog::setAccount( Kopete::Account *account )
00172 {
00173     d->accounts.clear();
00174     d->accounts.append( account );
00175     slotLoadAccounts();
00176 }
00177 
00178 void AccountIdentityDialog::setAccounts( QList<Kopete::Account*> accountList )
00179 {
00180     d->accounts = accountList;
00181     slotLoadAccounts();
00182 }
00183 
00184 void AccountIdentityDialog::setMessage( const QString &text )
00185 {
00186     d->ui.selectText->setText( text );
00187 }
00188 
00189 void AccountIdentityDialog::setHiddenIdentity( Kopete::Identity *ident )
00190 {
00191     d->hiddenIdentity = ident;
00192     slotLoadIdentities();
00193 }
00194 
00195 // static member functions
00196 
00197 bool AccountIdentityDialog::changeAccountIdentity( QWidget *parent, Kopete::Account *account, 
00198                                                     Kopete::Identity *hidden_ident,
00199                                                     const QString &message )
00200 {
00201     AccountIdentityDialog dialog( parent );
00202 
00203     dialog.setAccount( account );
00204     dialog.setHiddenIdentity( hidden_ident );
00205     if ( !message.isEmpty() )
00206         dialog.setMessage( message );
00207 
00208     return dialog.exec();
00209 }
00210 
00211 bool AccountIdentityDialog::changeAccountIdentity( QWidget *parent, QList<Kopete::Account*> accountList, 
00212                                         Kopete::Identity *hidden_ident,
00213                                         const QString &message )
00214 {
00215     AccountIdentityDialog dialog( parent );
00216 
00217     dialog.setAccounts( accountList );
00218     dialog.setHiddenIdentity( hidden_ident );
00219     if ( !message.isEmpty() )
00220         dialog.setMessage( message );
00221 
00222     return dialog.exec();
00223 }
00224 
00225 #include "accountidentitydialog.moc"
00226 
00227 // vim: set noet ts=4 sts=4 sw=4:
00228 

kopete/kopete

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

kdenetwork

Skip menu "kdenetwork"
  • kget
  • kopete
  •   kopete
  •   libkopete
  •       libpapillon
  • krfb
Generated for kdenetwork by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal