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

kopete/libkopete

  • sources
  • kde-4.14
  • kdenetwork
  • kopete
  • libkopete
  • ui
accountselector.cpp
Go to the documentation of this file.
1 /*
2  accountselector.cpp - An Accountselector
3 
4  Copyright (c) 2004 by Stefan Gehn <metz AT gehn.net>
5 
6  Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
7 
8  *************************************************************************
9  * *
10  * This library is free software; you can redistribute it and/or *
11  * modify it under the terms of the GNU Lesser General Public *
12  * License as published by the Free Software Foundation; either *
13  * version 2 of the License, or (at your option) any later version. *
14  * *
15  *************************************************************************
16 */
17 
18 #include "accountselector.h"
19 #include "kopeteaccount.h"
20 #include "kopeteaccountmanager.h"
21 
22 #include <q3header.h>
23 #include <qlayout.h>
24 #include <qpixmap.h>
25 #include <QVBoxLayout>
26 
27 #include <kdebug.h>
28 #include <k3listview.h>
29 
30 class AccountListViewItem : public K3ListViewItem
31 {
32  private:
33  Kopete::Account *mAccount;
34 
35  public:
36  AccountListViewItem(Q3ListView *parent, Kopete::Account *acc)
37  : K3ListViewItem(parent)
38  {
39  if (acc==0)
40  return;
41 
42  /*kDebug(14010) <<
43  "account name = " << acc->accountId() << endl;*/
44  mAccount = acc;
45  setText(0, mAccount->accountId());
46  setPixmap(0, mAccount->accountIcon());
47  }
48 
49  Kopete::Account *account()
50  {
51  return mAccount;
52  }
53 };
54 
55 
56 // ----------------------------------------------------------------------------
57 
58 class AccountSelectorPrivate
59 {
60  public:
61  K3ListView *lv;
62  Kopete::Protocol *proto;
63 };
64 
65 
66 AccountSelector::AccountSelector(QWidget *parent)
67  : QWidget(parent)
68 {
69  //kDebug(14010) << "for no special protocol";
70  d = new AccountSelectorPrivate;
71  d->proto = 0;
72  initUI();
73 }
74 
75 
76 AccountSelector::AccountSelector(Kopete::Protocol *proto, QWidget *parent) : QWidget(parent)
77 {
78  //kDebug(14010) << " for protocol " << proto->pluginId();
79  d = new AccountSelectorPrivate;
80  d->proto = proto;
81  initUI();
82 }
83 
84 
85 AccountSelector::~AccountSelector()
86 {
87  kDebug(14010) ;
88  delete d;
89 }
90 
91 
92 void AccountSelector::initUI()
93 {
94  kDebug(14010) ;
95  QVBoxLayout *layout = new QVBoxLayout(this);
96  d->lv = new K3ListView(this);
97  d->lv->setFullWidth(true);
98  d->lv->addColumn(QString::fromLatin1(""));
99  d->lv->header()->hide();
100  layout->addWidget(d->lv);
101  setLayout(layout);
102  kDebug(14010) << "creating list of all accounts";
103  foreach(Kopete::Account *account , Kopete::AccountManager::self()->accounts() )
104  {
105  if( !d->proto || account->protocol() == d->proto )
106  new AccountListViewItem(d->lv, account);
107  }
108 
109  connect(d->lv, SIGNAL(selectionChanged(Q3ListViewItem*)),
110  this, SLOT(slotSelectionChanged(Q3ListViewItem*)));
111 }
112 
113 
114 void AccountSelector::setSelected(Kopete::Account *account)
115 {
116  if (account==0)
117  return;
118 
119  Q3ListViewItemIterator it(d->lv);
120  while (it.current())
121  {
122  if(static_cast<AccountListViewItem *>(it.current())->account() == account)
123  {
124  it.current()->setSelected(true);
125  return;
126  }
127  }
128 }
129 
130 
131 bool AccountSelector::isSelected(Kopete::Account *account)
132 {
133  if (account==0)
134  return false;
135 
136  Q3ListViewItemIterator it(d->lv);
137  while (it.current())
138  {
139  if(static_cast<AccountListViewItem *>(it.current())->account() == account)
140  return true;
141  }
142  return false;
143 }
144 
145 
146 Kopete::Account *AccountSelector::selectedItem()
147 {
148  //kDebug(14010) ;
149 
150  if (d->lv->selectedItem() != 0)
151  return static_cast<AccountListViewItem *>(d->lv->selectedItem())->account();
152  return 0;
153 }
154 
155 
156 void AccountSelector::slotSelectionChanged(Q3ListViewItem *item)
157 {
158  //kDebug(14010) ;
159  if (item != 0)
160  {
161  Kopete::Account *account = static_cast<AccountListViewItem *>(item)->account();
162  if (account != 0)
163  {
164  emit selectionChanged(account);
165  return;
166  }
167  }
168 
169  emit selectionChanged(0);
170 }
171 
172 #include "accountselector.moc"
173 // vim: set noet ts=4 sts=4 sw=4:
QWidget::layout
QLayout * layout() const
Kopete::Account::protocol
Protocol * protocol() const
Definition: kopeteaccount.cpp:216
QWidget
AccountSelector::~AccountSelector
~AccountSelector()
Destructor.
Definition: accountselector.cpp:85
kopeteaccount.h
Kopete::Protocol
base class of every protocol.
Definition: kopeteprotocol.h:62
AccountSelector::selectedItem
Kopete::Account * selectedItem()
Definition: accountselector.cpp:146
Kopete::AccountManager::self
static AccountManager * self()
Retrieve the instance of AccountManager.
Definition: kopeteaccountmanager.cpp:77
AccountSelector::setSelected
void setSelected(Kopete::Account *account)
Select account in the list, in case it's part of the list.
Definition: accountselector.cpp:114
Q3ListViewItemIterator
Q3ListViewItemIterator::current
Q3ListViewItem * current() const
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
Q3ListViewItem::setSelected
virtual void setSelected(bool s)
Q3ListViewItem
QWidget::setLayout
void setLayout(QLayout *layout)
QVBoxLayout
K3ListView
kopeteaccountmanager.h
QString::fromLatin1
QString fromLatin1(const char *str, int size)
AccountSelector::selectionChanged
void selectionChanged(Kopete::Account *acc)
Emitted whenever the selection changed, acc is a pointer to the newly selected account.
AccountSelector::isSelected
bool isSelected(Kopete::Account *account)
Returns true in case account is in the list and the currently selected item, false otherwise...
Definition: accountselector.cpp:131
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Kopete::Account
The Kopete::Account class handles one account.
Definition: kopeteaccount.h:72
Q3ListView
accountselector.h
AccountSelector::AccountSelector
AccountSelector(QWidget *parent=0)
Constructor.
Definition: accountselector.cpp:66
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:29:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kopete/libkopete

Skip menu "kopete/libkopete"
  • 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