• 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.12
  • kdenetwork
  • kopete
  • kopete
  • addaccountwizard
addaccountwizard.cpp
Go to the documentation of this file.
1 /*
2  addaccountwizard.cpp - Kopete Add Account Wizard
3 
4  Copyright (c) 2003-2006 by Olivier Goffart <ogoffart@kde.org>
5  Copyright (c) 2003 by Martijn Klingens <klingens@kde.org>
6 
7  Kopete (c) 2003-2006 by the Kopete developers <kopete-devel@kde.org>
8 
9  *************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  *************************************************************************
17 */
18 
19 #include "addaccountwizard.h"
20 
21 #include <qcheckbox.h>
22 #include <qlabel.h>
23 
24 #include <kcolorbutton.h>
25 #include <kdebug.h>
26 #include <kiconloader.h>
27 #include <k3listview.h>
28 #include <klocale.h>
29 #include <kmessagebox.h>
30 #include <kplugininfo.h>
31 #include <kvbox.h>
32 
33 #include "editaccountwidget.h"
34 #include "kopeteaccount.h"
35 #include "kopeteaccountmanager.h"
36 #include "kopeteprotocol.h"
37 #include "kopetepluginmanager.h"
38 #include "kopeteidentity.h"
39 #include "kopeteidentitymanager.h"
40 
41 class AddAccountWizard::Private
42 {
43 public:
44  Private()
45  : accountPage(0)
46  , proto(0)
47  , identity(0L)
48  {
49  }
50 
51  QTreeWidgetItem* selectedProtocol();
52 
53  QMap<QTreeWidgetItem *, KPluginInfo> protocolItems;
54  KopeteEditAccountWidget *accountPage;
55  KVBox *accountPageWidget;
56  QWidget *selectService;
57  QWidget *finish;
58  Ui::AddAccountWizardPage1 uiSelectService;
59  Ui::AddAccountWizardPage2 uiFinish;
60  Kopete::Protocol *proto;
61  KPageWidgetItem *selectServiceItem;
62  Kopete::Identity *identity;
63 };
64 
65 AddAccountWizard::AddAccountWizard( QWidget *parent, bool firstRun )
66  : KAssistantDialog(parent)
67  , d(new Private)
68 {
69  // setup the select service page
70  d->selectService = new QWidget(this);
71  d->uiSelectService.setupUi(d->selectService);
72  d->uiSelectService.protocolListView->setColumnCount( 2 );
73  QStringList header;
74  header << i18n("Name") << i18n("Description");
75  d->uiSelectService.protocolListView->setHeaderLabels( header );
76  if ( firstRun )
77  d->uiSelectService.m_header->setText( i18nc( "1st message shown to users on first run of Kopete. Please keep the formatting.", "<h2>Welcome to Kopete</h2><p>Which messaging service do you want to connect to?</p>") );
78 
79  d->selectServiceItem = addPage(d->selectService,d->selectService->windowTitle());
80  setValid(d->selectServiceItem, false);
81 
82  d->accountPageWidget = new KVBox(this);
83  addPage(d->accountPageWidget,i18n("Step Two: Account Information"));
84 
85  // setup the final page
86  d->finish = new QWidget(this);
87  d->uiFinish.setupUi(d->finish);
88  if ( firstRun )
89  d->uiFinish.m_header->setText( i18nc( "2nd message shown to users on first run of Kopete. Please keep the formatting.", "<h2>Congratulations</h2><p>You have finished configuring the account. You can add more accounts with <i>Settings->Configure</i>. Please click the \"Finish\" button.</p>") );
90  addPage(d->finish,d->finish->windowTitle());
91 
92  // add the available messenger services to the dialogs list
93  QList<KPluginInfo> protocols = Kopete::PluginManager::self()->availablePlugins("Protocols");
94  qSort(protocols);
95  for (QList<KPluginInfo>::Iterator it = protocols.begin(); it != protocols.end(); ++it)
96  {
97  QTreeWidgetItem *pluginItem = new QTreeWidgetItem(d->uiSelectService.protocolListView);
98  pluginItem->setIcon(0, QIcon(SmallIcon(it->icon())));
99  pluginItem->setText(0, it->name());
100  pluginItem->setText(1, it->comment());
101 
102  d->protocolItems.insert(pluginItem, *it);
103  }
104 
105  // focus the ListView
106  QTreeWidget *protocol_list = d->uiSelectService.protocolListView;
107  protocol_list->setFocus();
108 
109 
110 
111  // hook up the user input
112  connect(d->uiSelectService.protocolListView, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
113  this, SLOT(slotProtocolListClicked()));
114  connect(d->uiSelectService.protocolListView, SIGNAL(itemSelectionChanged()),
115  this, SLOT(slotProtocolListClicked()));
116  connect(d->uiSelectService.protocolListView, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),
117  this, SLOT(slotProtocolListDoubleClicked()));
118  setHelp(QString(),"kopete");
119 }
120 
121 QTreeWidgetItem* AddAccountWizard::Private::selectedProtocol()
122 {
123  QList<QTreeWidgetItem*> selectedItems = uiSelectService.protocolListView->selectedItems();
124  if(!selectedItems.empty())
125  return selectedItems.first();
126  return 0;
127 }
128 
129 void AddAccountWizard::slotProtocolListClicked()
130 {
131  // Make sure a protocol is selected before allowing the user to continue
132  setValid(d->selectServiceItem, d->selectedProtocol() != 0);
133 }
134 
135 void AddAccountWizard::slotProtocolListDoubleClicked()
136 {
137  // proceed to the next wizard page if we double click a protocol
138  next();
139 }
140 
141 void AddAccountWizard::back()
142 {
143  if (currentPage()->widget() == d->accountPageWidget)
144  {
145  // Deletes the accountPage, K3Wizard does not like deleting pages
146  // using different pointers, it only seems to watch its own pointer
147  delete d->accountPage;
148  d->accountPage = 0;
149  d->proto = 0;
150 
151  // removePage() already goes back to previous page, no back() needed
152  }
153  KAssistantDialog::back();
154 }
155 
156 void AddAccountWizard::next()
157 {
158  if (currentPage()->widget() == d->selectService)
159  {
160  QTreeWidgetItem *lvi = d->selectedProtocol();
161  if(!d->protocolItems[lvi].isValid())
162  { //no item selected
163  return;
164  }
165  d->proto = qobject_cast<Kopete::Protocol *>(Kopete::PluginManager::self()->loadPlugin(d->protocolItems[lvi].pluginName()));
166  if (!d->proto)
167  {
168  KMessageBox::queuedMessageBox(this, KMessageBox::Error,
169  i18n("Cannot load the %1 protocol plugin.", d->protocolItems[lvi].name()),
170  i18n("Error While Adding Account"));
171  return;
172  }
173 
174  d->accountPage = d->proto->createEditAccountWidget(0, d->accountPageWidget);
175  if (!d->accountPage)
176  {
177  KMessageBox::queuedMessageBox(this, KMessageBox::Error,
178  i18n("This protocol does not currently support adding accounts."),
179  i18n("Error While Adding Account"));
180  return;
181  }
182 
183  KAssistantDialog::next();
184  }
185  else if (currentPage()->widget() == d->accountPageWidget)
186  {
187  // check the data of the page is valid
188  if (!d->accountPage->validateData())
189  {
190  return;
191  }
192 
193  QColor col = Kopete::AccountManager::self()->guessColor(d->proto);
194 
195  d->uiFinish.mColorButton->setColor(col);
196  d->uiFinish.mUseColor->setChecked(col.isValid());
197  KAssistantDialog::next();
198  }
199  else
200  {
201  kDebug(14100) << "Next pressed on misc page";
202  KAssistantDialog::next();
203  }
204 
205 }
206 
207 void AddAccountWizard::accept()
208 {
209  // registeredAccount shouldn't probably be called here. Anyway, if the account is already registered,
210  // it won't be registered twice
211  Kopete::AccountManager *manager = Kopete::AccountManager::self();
212  Kopete::Account *account = d->accountPage->apply();
213 
214  // if the account wasn't created correctly then leave
215  if (!account)
216  {
217  reject();
218  return;
219  }
220 
221  // Set a valid identity before registering the account
222  if (!d->identity)
223  {
224  account->setIdentity(Kopete::IdentityManager::self()->defaultIdentity());
225  }
226  else
227  {
228  account->setIdentity(d->identity);
229  }
230 
231  account = manager->registerAccount(account);
232  // if the account wasn't created correctly then leave
233  if (!account)
234  {
235  reject();
236  return;
237  }
238 
239  // Make sure the protocol is correctly enabled. This is not really needed, but still good
240  const QString PROTO_NAME = d->proto->pluginId().remove("Protocol").toLower();
241  Kopete::PluginManager::self()->setPluginEnabled(PROTO_NAME , true);
242 
243  // setup the custom colour
244  if (d->uiFinish.mUseColor->isChecked())
245  {
246  account->setColor(d->uiFinish.mColorButton->color());
247  }
248 
249  // connect if necessary
250  if (d->uiFinish.mConnectNow->isChecked())
251  {
252  account->connect();
253  }
254 
255  KAssistantDialog::accept();
256 }
257 
258 void AddAccountWizard::reject()
259 {
260  // if we have a protocol plugin loaded and it is not being used, unload it
261  if (d->proto)
262  {
263  bool hasAccount=false;
264  foreach( Kopete::Account *act, Kopete::AccountManager::self()->accounts() )
265  {
266  if( act->protocol() == d->proto )
267  {
268  hasAccount=true;
269  break;
270  }
271  }
272  if(hasAccount)
273  {
274  const QString PROTO_NAME = d->proto->pluginId().remove("Protocol").toLower();
275  Kopete::PluginManager::self()->unloadPlugin(PROTO_NAME);
276  }
277  }
278 
279  KAssistantDialog::reject();
280 }
281 
282 AddAccountWizard::~AddAccountWizard()
283 {
284  delete d;
285 }
286 
287 void AddAccountWizard::setIdentity( Kopete::Identity *identity )
288 {
289  d->identity = identity;
290 }
291 
292 
293 #include "addaccountwizard.moc"
294 
295 // vim: set noet ts=4 sts=4 sw=4:
296 
KVBox
QTreeWidget
AddAccountWizard::~AddAccountWizard
~AddAccountWizard()
Definition: addaccountwizard.cpp:282
AddAccountWizard::setIdentity
void setIdentity(Kopete::Identity *identity)
Set the identity assigned to the account.
Definition: addaccountwizard.cpp:287
AddAccountWizard::reject
virtual void reject()
Definition: addaccountwizard.cpp:258
QWidget
manager
virtual Kopete::ChatSession * manager(Kopete::Contact::CanCreateFlags)
Definition: chatwindowconfig.cpp:94
addaccountwizard.h
KAssistantDialog
AddAccountWizard::back
virtual void back()
Definition: addaccountwizard.cpp:141
QTreeWidgetItem
AddAccountWizard::next
virtual void next()
Definition: addaccountwizard.cpp:156
AddAccountWizard::accept
virtual void accept()
Definition: addaccountwizard.cpp:207
AddAccountWizard::AddAccountWizard
AddAccountWizard(QWidget *parent=0, bool firstRun=false)
Definition: addaccountwizard.cpp:65
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:40 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