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

kopete/kopete

addaccountwizard.cpp

Go to the documentation of this file.
00001 /*
00002     addaccountwizard.cpp - Kopete Add Account Wizard
00003 
00004     Copyright (c) 2003-2006 by Olivier Goffart       <ogoffart@kde.org>
00005     Copyright (c) 2003      by Martijn Klingens      <klingens@kde.org>
00006 
00007     Kopete    (c) 2003-2006 by the Kopete developers <kopete-devel@kde.org>
00008 
00009     *************************************************************************
00010     *                                                                       *
00011     * This program is free software; you can redistribute it and/or modify  *
00012     * it under the terms of the GNU General Public License as published by  *
00013     * the Free Software Foundation; either version 2 of the License, or     *
00014     * (at your option) any later version.                                   *
00015     *                                                                       *
00016     *************************************************************************
00017 */
00018 
00019 #include "addaccountwizard.h"
00020 
00021 #include <qcheckbox.h>
00022 #include <qlabel.h>
00023 
00024 #include <kcolorbutton.h>
00025 #include <kdebug.h>
00026 #include <kiconloader.h>
00027 #include <k3listview.h>
00028 #include <klocale.h>
00029 #include <kmessagebox.h>
00030 #include <kplugininfo.h>
00031 #include <kvbox.h>
00032 
00033 #include "editaccountwidget.h"
00034 #include "kopeteaccount.h"
00035 #include "kopeteaccountmanager.h"
00036 #include "kopeteprotocol.h"
00037 #include "kopetepluginmanager.h"
00038 
00039 class AddAccountWizard::Private
00040 {
00041 public:
00042     Private()
00043         : accountPage(0)
00044         , proto(0)
00045         {
00046         }
00047 
00048     QTreeWidgetItem* selectedProtocol();
00049 
00050     QMap<QTreeWidgetItem *, KPluginInfo>  protocolItems;
00051     KopeteEditAccountWidget *accountPage;
00052     KVBox *accountPageWidget;
00053     QWidget *selectService;
00054     QWidget *finish;
00055     Ui::AddAccountWizardPage1 uiSelectService;
00056     Ui::AddAccountWizardPage2 uiFinish;
00057     Kopete::Protocol *proto;
00058     KPageWidgetItem *selectServiceItem;
00059 };
00060 
00061 AddAccountWizard::AddAccountWizard( QWidget *parent, bool firstRun )
00062     : KAssistantDialog(parent)
00063     , d(new Private)
00064 {
00065     // setup the select service page
00066     d->selectService = new QWidget(this);
00067     d->uiSelectService.setupUi(d->selectService);
00068     d->uiSelectService.protocolListView->setColumnCount( 2 );
00069     QStringList header;
00070     header << i18n("Name") << i18n("Description");
00071     d->uiSelectService.protocolListView->setHeaderLabels( header );
00072     if ( firstRun )
00073         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>") );
00074     
00075     d->selectServiceItem = addPage(d->selectService,d->selectService->windowTitle());
00076     setValid(d->selectServiceItem, false);
00077         
00078     d->accountPageWidget = new KVBox(this);
00079     addPage(d->accountPageWidget,i18n("Step Two: Account Information"));
00080 
00081     // setup the final page
00082     d->finish = new QWidget(this);
00083     d->uiFinish.setupUi(d->finish);
00084     if ( firstRun )
00085         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>") );
00086     addPage(d->finish,d->finish->windowTitle());
00087 
00088     // add the available messenger services to the dialogs list
00089     QList<KPluginInfo> protocols = Kopete::PluginManager::self()->availablePlugins("Protocols");
00090     qSort(protocols);
00091     for (QList<KPluginInfo>::Iterator it = protocols.begin(); it != protocols.end(); ++it)
00092     {
00093         QTreeWidgetItem *pluginItem = new QTreeWidgetItem(d->uiSelectService.protocolListView);
00094         pluginItem->setIcon(0, QIcon(SmallIcon(it->icon())));
00095         pluginItem->setText(0, it->name());
00096         pluginItem->setText(1, it->comment());
00097 
00098         d->protocolItems.insert(pluginItem, *it);
00099     }
00100 
00101     // focus the ListView
00102     QTreeWidget *protocol_list = d->uiSelectService.protocolListView;
00103     protocol_list->setFocus();
00104     
00105     
00106  
00107     // hook up the user input
00108     connect(d->uiSelectService.protocolListView, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
00109         this, SLOT(slotProtocolListClicked()));
00110     connect(d->uiSelectService.protocolListView, SIGNAL(itemSelectionChanged()),
00111         this, SLOT( slotProtocolListClicked()));
00112     connect(d->uiSelectService.protocolListView, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
00113         this, SLOT(slotProtocolListDoubleClicked()));
00114     setHelp(QString(),"kopete");
00115 }
00116 
00117 QTreeWidgetItem* AddAccountWizard::Private::selectedProtocol()
00118 {
00119     QList<QTreeWidgetItem*> selectedItems = uiSelectService.protocolListView->selectedItems();
00120     if(!selectedItems.empty())
00121         return selectedItems.first();
00122     return 0;
00123 }
00124 
00125 void AddAccountWizard::slotProtocolListClicked()
00126 {
00127     // Make sure a protocol is selected before allowing the user to continue
00128     setValid(d->selectServiceItem, d->selectedProtocol() != 0);
00129 }
00130 
00131 void AddAccountWizard::slotProtocolListDoubleClicked()
00132 {
00133     // proceed to the next wizard page if we double click a protocol
00134     next();
00135 }
00136 
00137 void AddAccountWizard::back()
00138 {
00139     if (currentPage()->widget() == d->accountPageWidget)
00140     {
00141         // Deletes the accountPage, K3Wizard does not like deleting pages
00142         // using different pointers, it only seems to watch its own pointer
00143         delete d->accountPage;
00144         d->accountPage = 0;
00145         d->proto       = 0;
00146 
00147         // removePage() already goes back to previous page, no back() needed
00148     }
00149     KAssistantDialog::back();
00150 }
00151 
00152 void AddAccountWizard::next()
00153 {
00154     if (currentPage()->widget() == d->selectService)
00155     {
00156         QTreeWidgetItem *lvi = d->selectedProtocol();
00157         if(!d->protocolItems[lvi].isValid())
00158         { //no item selected
00159             return;
00160         }
00161         d->proto = qobject_cast<Kopete::Protocol *>(Kopete::PluginManager::self()->loadPlugin(d->protocolItems[lvi].pluginName()));
00162         if (!d->proto)
00163         {
00164             KMessageBox::queuedMessageBox(this, KMessageBox::Error,
00165                 i18n("Cannot load the %1 protocol plugin.", d->protocolItems[lvi].name()),
00166                 i18n("Error While Adding Account"));
00167             return;
00168         }
00169 
00170         d->accountPage = d->proto->createEditAccountWidget(0, d->accountPageWidget);
00171         if (!d->accountPage)
00172         {
00173             KMessageBox::queuedMessageBox(this, KMessageBox::Error,
00174                 i18n("This protocol does not currently support adding accounts."),
00175                 i18n("Error While Adding Account"));
00176             return;
00177         }
00178     
00179         KAssistantDialog::next();
00180     }
00181     else if (currentPage()->widget() == d->accountPageWidget)
00182     {
00183         // check the data of the page is valid
00184         if (!d->accountPage->validateData())
00185         {
00186             return;
00187         }
00188 
00189         QColor col = Kopete::AccountManager::self()->guessColor(d->proto);
00190 
00191         d->uiFinish.mColorButton->setColor(col);
00192         d->uiFinish.mUseColor->setChecked(col.isValid());
00193         KAssistantDialog::next();
00194     }
00195     else 
00196     {
00197         kDebug(14100) << "Next pressed on misc page";
00198         KAssistantDialog::next();
00199     }
00200 
00201 }
00202 
00203 void AddAccountWizard::accept()
00204 {
00205     // registeredAccount shouldn't probably be called here. Anyway, if the account is already registered, 
00206     // it won't be registered twice
00207     Kopete::AccountManager *manager = Kopete::AccountManager::self();
00208     Kopete::Account        *account = manager->registerAccount(d->accountPage->apply());
00209 
00210     // if the account wasn't created correctly then leave
00211     if (!account)
00212     {
00213         reject();
00214         return;
00215     }
00216 
00217     // Make sure the protocol is correctly enabled.  This is not really needed, but still good
00218     const QString PROTO_NAME = d->proto->pluginId().remove("Protocol").toLower();
00219     Kopete::PluginManager::self()->setPluginEnabled(PROTO_NAME , true);
00220 
00221     // setup the custom colour
00222     if (d->uiFinish.mUseColor->isChecked())
00223     {
00224         account->setColor(d->uiFinish.mColorButton->color());
00225     }
00226 
00227     // connect if necessary
00228     if (d->uiFinish.mConnectNow->isChecked())
00229     {
00230         account->connect();
00231     }
00232 
00233     KAssistantDialog::accept();
00234 }
00235 
00236 void AddAccountWizard::reject()
00237 {
00238     // if we have a protocol plugin loaded and its not being used, unload it
00239     if (d->proto)
00240     {
00241         bool hasAccount=false;
00242         foreach( Kopete::Account *act, Kopete::AccountManager::self()->accounts() )
00243         {
00244             if( act->protocol() == d->proto )
00245             {
00246                 hasAccount=true;
00247                 break;
00248             }
00249         }
00250         if(hasAccount)
00251         {
00252             const QString PROTO_NAME = d->proto->pluginId().remove("Protocol").toLower();
00253             Kopete::PluginManager::self()->unloadPlugin(PROTO_NAME);
00254         }
00255     }
00256 
00257     KAssistantDialog::reject();
00258 }
00259 
00260 AddAccountWizard::~AddAccountWizard()
00261 {
00262     delete d;
00263 }
00264 
00265 #include "addaccountwizard.moc"
00266 
00267 // vim: set noet ts=4 sts=4 sw=4:
00268 

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