21 #include <qcheckbox.h>
24 #include <kcolorbutton.h>
26 #include <kiconloader.h>
27 #include <k3listview.h>
29 #include <kmessagebox.h>
30 #include <kplugininfo.h>
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"
41 class AddAccountWizard::Private
54 KopeteEditAccountWidget *accountPage;
55 KVBox *accountPageWidget;
58 Ui::AddAccountWizardPage1 uiSelectService;
59 Ui::AddAccountWizardPage2 uiFinish;
60 Kopete::Protocol *proto;
61 KPageWidgetItem *selectServiceItem;
62 Kopete::Identity *identity;
70 d->selectService =
new QWidget(
this);
71 d->uiSelectService.setupUi(d->selectService);
72 d->uiSelectService.protocolListView->setColumnCount( 2 );
74 header << i18n(
"Name") << i18n(
"Description");
75 d->uiSelectService.protocolListView->setHeaderLabels( header );
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>") );
79 d->selectServiceItem = addPage(d->selectService,d->selectService->windowTitle());
80 setValid(d->selectServiceItem,
false);
82 d->accountPageWidget =
new KVBox(
this);
83 addPage(d->accountPageWidget,i18n(
"Step Two: Account Information"));
87 d->uiFinish.setupUi(d->finish);
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());
93 QList<KPluginInfo> protocols = Kopete::PluginManager::self()->availablePlugins(
"Protocols");
99 pluginItem->
setText(0, it->name());
100 pluginItem->
setText(1, it->comment());
102 d->protocolItems.insert(pluginItem, *it);
106 QTreeWidget *protocol_list = d->uiSelectService.protocolListView;
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()));
124 if(!selectedItems.
empty())
125 return selectedItems.
first();
129 void AddAccountWizard::slotProtocolListClicked()
132 setValid(d->selectServiceItem, d->selectedProtocol() != 0);
135 void AddAccountWizard::slotProtocolListDoubleClicked()
143 if (currentPage()->widget() == d->accountPageWidget)
147 delete d->accountPage;
153 KAssistantDialog::back();
158 if (currentPage()->widget() == d->selectService)
161 if(!d->protocolItems[lvi].isValid())
165 d->proto = qobject_cast<Kopete::Protocol *>(Kopete::PluginManager::self()->loadPlugin(d->protocolItems[lvi].pluginName()));
168 KMessageBox::queuedMessageBox(
this, KMessageBox::Error,
169 i18n(
"Cannot load the %1 protocol plugin.", d->protocolItems[lvi].name()),
170 i18n(
"Error While Adding Account"));
174 d->accountPage = d->proto->createEditAccountWidget(0, d->accountPageWidget);
177 KMessageBox::queuedMessageBox(
this, KMessageBox::Error,
178 i18n(
"This protocol does not currently support adding accounts."),
179 i18n(
"Error While Adding Account"));
183 KAssistantDialog::next();
185 else if (currentPage()->widget() == d->accountPageWidget)
188 if (!d->accountPage->validateData())
193 QColor col = Kopete::AccountManager::self()->guessColor(d->proto);
195 d->uiFinish.mColorButton->setColor(col);
196 d->uiFinish.mUseColor->setChecked(col.
isValid());
197 KAssistantDialog::next();
201 kDebug(14100) <<
"Next pressed on misc page";
202 KAssistantDialog::next();
211 Kopete::AccountManager *
manager = Kopete::AccountManager::self();
212 Kopete::Account *account = d->accountPage->apply();
224 account->setIdentity(Kopete::IdentityManager::self()->defaultIdentity());
228 account->setIdentity(d->identity);
231 account = manager->registerAccount(account);
240 const QString PROTO_NAME = d->proto->pluginId().remove(
"Protocol").toLower();
241 Kopete::PluginManager::self()->setPluginEnabled(PROTO_NAME ,
true);
244 if (d->uiFinish.mUseColor->isChecked())
246 account->setColor(d->uiFinish.mColorButton->color());
250 if (d->uiFinish.mConnectNow->isChecked())
255 KAssistantDialog::accept();
263 bool hasAccount=
false;
264 foreach( Kopete::Account *act, Kopete::AccountManager::self()->accounts() )
266 if( act->protocol() == d->proto )
274 const QString PROTO_NAME = d->proto->pluginId().remove(
"Protocol").toLower();
275 Kopete::PluginManager::self()->unloadPlugin(PROTO_NAME);
279 KAssistantDialog::reject();
289 d->identity = identity;
293 #include "addaccountwizard.moc"
void setIdentity(Kopete::Identity *identity)
Set the identity assigned to the account.
virtual Kopete::ChatSession * manager(Kopete::Contact::CanCreateFlags)
void setText(int column, const QString &text)
AddAccountWizard(QWidget *parent=0, bool firstRun=false)