[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/network/telepathy-accounts-kcm/src
From: Gustavo P. Boiko <gustavo.boiko () kdemail ! net>
Date: 2010-09-23 13:49:59
Message-ID: 20100923134959.B1E44AC888 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1178681 by boiko:
Make the dialogs modal and use a simpler method to set the config pages' \
title. This commit also makes the editting of accounts a resposibility of \
the kcm module instead of doing that in the item itself.
The sideeffect of this commit is that it also fixes the account list not \
being refreshed sometimes.
BUG: 252053
M +1 -38 account-item.cpp
M +0 -4 account-item.h
M +9 -21 accounts-list-model.cpp
M +1 -1 accounts-list-model.h
M +9 -45 add-account-assistant.cpp
M +0 -5 add-account-assistant.h
M +13 -26 edit-account-dialog.cpp
M +1 -6 edit-account-dialog.h
M +8 -61 kcm-telepathy-accounts.cpp
M +0 -4 kcm-telepathy-accounts.h
--- trunk/playground/network/telepathy-accounts-kcm/src/account-item.cpp \
#1178680:1178681 @@ -36,8 +36,7 @@
AccountItem::AccountItem(const Tp::AccountPtr &account, AccountsListModel \
*parent) : QObject(parent),
m_account(account),
- m_icon(new KIcon()),
- m_editAccountDialog(0)
+ m_icon(new KIcon())
{
kDebug();
@@ -80,32 +79,6 @@
return m_account;
}
-void AccountItem::edit()
-{
- kDebug();
-
- // If the edit dialog already exists, focus it.
- if (m_editAccountDialog) {
- m_editAccountDialog->focusWidget();
- return;
- }
-
- // FIXME: There should be a driving test for those who want to become \
parents... :'(
- QWidget *p = qobject_cast<QWidget*>(parent()->parent());
- m_editAccountDialog = new EditAccountDialog(this, p); // FIXME: Argh \
I'm going to jump off a bridge
-
- // Connect to the dialog's signals.
- connect(m_editAccountDialog,
- SIGNAL(finished()),
- SLOT(onAccountEdited()));
- connect(m_editAccountDialog, SIGNAL(protocolSelected(QString, QString)),
- this, SIGNAL(protocolSelected(QString, QString)));
- connect(this, SIGNAL(setTitleForCustomPages(QString, QList<QString>)),
- m_editAccountDialog, SLOT(onTitleForCustomPages(QString, \
QList<QString>)));
-
- m_editAccountDialog->show();
-}
-
void AccountItem::remove()
{
kDebug() << "Account about to be removed";
@@ -177,16 +150,6 @@
Q_EMIT removed();
}
-void AccountItem::onAccountEdited()
-{
- kDebug();
-
- m_editAccountDialog->deleteLater();
- m_editAccountDialog = 0;
-
- Q_EMIT updated();
-}
-
void AccountItem::onTitleForCustomPages(QString mandatoryPage, \
QList<QString> optionalPage) {
kDebug();
--- trunk/playground/network/telepathy-accounts-kcm/src/account-item.h \
#1178680:1178681 @@ -28,7 +28,6 @@
class KIcon;
class AccountsListModel;
-class EditAccountDialog;
namespace Tp {
class PendingOperation;
@@ -43,7 +42,6 @@
explicit AccountItem(const Tp::AccountPtr &account, AccountsListModel \
*parent = 0); virtual ~AccountItem();
Tp::AccountPtr account() const;
- void edit();
void remove();
const KIcon& icon() const;
@@ -61,12 +59,10 @@
void generateIcon();
void onAccountReady(Tp::PendingOperation *op);
void onAccountRemoved(Tp::PendingOperation *op);
- void onAccountEdited();
private:
Tp::AccountPtr m_account;
KIcon* m_icon;
- EditAccountDialog *m_editAccountDialog;
};
--- trunk/playground/network/telepathy-accounts-kcm/src/accounts-list-model.cpp \
#1178680:1178681 @@ -140,44 +140,32 @@
}
}
-void AccountsListModel::editAccount(const QModelIndex &index)
+void AccountsListModel::removeAccount(const QModelIndex &index)
{
kDebug();
if(!index.isValid()) {
- kWarning() << "Can't edit Account: Invalid index.";
+ kDebug() << "Can't remove Account: Invalid index";
return;
}
-
AccountItem *accountItem = m_readyAccounts.at(index.row());
- if (!accountItem) {
- kWarning() << "Account item is null.";
- return;
- }
+ Q_ASSERT(accountItem);
- accountItem->disconnect();
- connect(accountItem, SIGNAL(protocolSelected(QString, QString)),
- this, SIGNAL(protocolSelected(QString, QString)));
- connect(this, SIGNAL(setTitleForCustomPages(QString, QList<QString>)),
- accountItem, SLOT(onTitleForCustomPages(QString, QList<QString>)));
-
- accountItem->edit();
+ accountItem->remove();
}
-void AccountsListModel::removeAccount(const QModelIndex &index)
+AccountItem* AccountsListModel::itemForIndex(const QModelIndex &index)
{
kDebug();
if(!index.isValid()) {
- kDebug() << "Can't remove Account: Invalid index";
- return;
+ kWarning() << "Invalid index" << index;
+ return 0;
}
- AccountItem *accountItem = m_readyAccounts.at(index.row());
- Q_ASSERT(accountItem);
-
- accountItem->remove();
+ AccountItem *accountItem = m_readyAccounts.at(index.row());
+ return accountItem;
}
void AccountsListModel::onAccountItemReady()
--- trunk/playground/network/telepathy-accounts-kcm/src/accounts-list-model.h \
#1178680:1178681 @@ -40,8 +40,8 @@
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
virtual bool setData(const QModelIndex &index, const QVariant &value, \
int role); void addAccount(const Tp::AccountPtr &account);
- void editAccount(const QModelIndex &index);
void removeAccount(const QModelIndex &index);
+ AccountItem* itemForIndex(const QModelIndex &index);
Q_SIGNALS:
void protocolSelected(QString, QString);
--- trunk/playground/network/telepathy-accounts-kcm/src/add-account-assistant.cpp \
#1178680:1178681 @@ -61,8 +61,6 @@
QList<AbstractAccountParametersWidget*> optionalParametersWidgets;
KPageWidgetItem *pageOne;
KPageWidgetItem *pageTwo;
- QString mandatoryPageDesc;
- QList<QString> optionalPageDesc;
};
AddAccountAssistant::AddAccountAssistant(Tp::AccountManagerPtr \
accountManager, QWidget *parent) @@ -83,8 +81,7 @@
SLOT(onProtocolSelected(bool)));
connect(d->protocolSelectWidget,
SIGNAL(protocolDoubleClicked()),
- SLOT(onProtocolDoubleClicked()),
- Qt::DirectConnection);
+ SLOT(next()));
d->tabWidget = new KTabWidget(this);
d->pageTwo = new KPageWidgetItem(d->tabWidget);
@@ -206,12 +203,11 @@
item->mandatoryParameters(), QVariantMap(), \
d->tabWidget); }
- if(d->mandatoryPageDesc.isEmpty())
- d->tabWidget->addTab(d->mandatoryParametersWidget, \
i18n("Mandatory Parameters"));
- else
- d->tabWidget->addTab(d->mandatoryParametersWidget, \
d->mandatoryPageDesc); + QString title = \
d->mandatoryParametersWidget->windowTitle(); + if (title.isEmpty())
+ title = i18n("Mandatory Parameters");
- int pageIndex = 0;
+ d->tabWidget->addTab(d->mandatoryParametersWidget, title);
// Check if the AbstractAccountUi exists. If not then we use the \
autogenerated UI for // everything.
@@ -236,13 +232,10 @@
foreach (AbstractAccountParametersWidget *widget, widgets) {
d->optionalParametersWidgets.append(widget);
- int indexOf = widgets.indexOf(widget);
- QString description = i18n("Optional parameter");
- if(indexOf < d->optionalPageDesc.size())
- description = d->optionalPageDesc.at(indexOf);
-
- d->tabWidget->addTab(widget, description);
- pageIndex++;
+ title = widget->windowTitle();
+ if (title.isEmpty())
+ title = i18n("Optional Parameters");
+ d->tabWidget->addTab(widget, title);
}
}
@@ -253,9 +246,6 @@
QVariantMap(),
d->tabWidget);
d->optionalParametersWidgets.append(opew);
- if(pageIndex < d->optionalPageDesc.size())
- d->tabWidget->addTab(opew, d->optionalPageDesc.at(pageIndex));
- else
d->tabWidget->addTab(opew, i18n("Optional Parameters"));
}
@@ -429,33 +419,7 @@
kDebug();
//if a protocol is selected, enable the next button on the first page
setValid(d->pageOne, value);
-
- if(value)
- {
- ProtocolItem *item = d->protocolSelectWidget->selectedProtocol();
- emit protocolSelected(item->protocol(), item->localizedName());
}
-}
-void AddAccountAssistant::onProtocolDoubleClicked()
-{
- kDebug();
-
- ProtocolItem *item = d->protocolSelectWidget->selectedProtocol();
- emit protocolSelected(item->protocol(), item->localizedName());
- next();
-}
-
-void AddAccountAssistant::onTitleForCustomPages(QString mandatoryPage, \
QList<QString> optionalPage)
-{
- kDebug();
- d->mandatoryPageDesc.clear();
- d->optionalPageDesc.clear();
-
- d->mandatoryPageDesc = mandatoryPage;
- d->optionalPageDesc = optionalPage;
-}
-
-
#include "add-account-assistant.moc"
--- trunk/playground/network/telepathy-accounts-kcm/src/add-account-assistant.h \
#1178680:1178681 @@ -44,16 +44,11 @@
Q_SIGNALS:
void cancelled();
- void protocolSelected(QString, QString);
-public Q_SLOTS:
- void onTitleForCustomPages(QString mandatoryPage, QList<QString> \
optionalPage);
-
private Q_SLOTS:
void onAccountCreated(Tp::PendingOperation *op);
void onSetEnabledFinished(Tp::PendingOperation *op);
void onProtocolSelected(bool value);
- void onProtocolDoubleClicked();
private:
class Private;
--- trunk/playground/network/telepathy-accounts-kcm/src/edit-account-dialog.cpp \
#1178680:1178681 @@ -67,14 +67,8 @@
resize(400, 480);
d->item = item;
-}
-void EditAccountDialog::show()
-{
- emit protocolSelected(d->item->account()->protocol(),
- d->item->account()->cmName());
-
- KDialog::show();
+ loadPages();
}
EditAccountDialog::~EditAccountDialog()
@@ -213,10 +207,8 @@
emit finished();
}
-void EditAccountDialog::onTitleForCustomPages(QString mandatoryPageDesc, \
QList<QString> optionalPageDesc) +void EditAccountDialog::loadPages()
{
- kDebug();
-
// Get the protocol's parameters.
Tp::ProtocolInfo *protocolInfo = d->item->account()->protocolInfo();
Tp::ProtocolParameterList protocolParameters = \
protocolInfo->parameters(); @@ -283,16 +275,16 @@
d->tabWidget);
}
- if(mandatoryPageDesc.isEmpty())
- d->tabWidget->addTab(d->mandatoryParametersWidget, i18n("Mandatory \
Parameters"));
- else
- d->tabWidget->addTab(d->mandatoryParametersWidget, mandatoryPageDesc);
+ // Get the custom title for the page, if any
+ QString title = d->mandatoryParametersWidget->windowTitle();
+ if (title.isEmpty())
+ title = i18n("Mandatory Parameters");
- // Get the list of parameters
+ d->tabWidget->addTab(d->mandatoryParametersWidget, title);
+
+ // Get the list of optional parameters
Tp::ProtocolParameterList optionalParametersLeft = \
d->optionalProtocolParameters;
- int pageIndex = 0;
-
// Check if the AbstractAccountUi exists. If not then we use the \
autogenerated UI for // everything.
if (ui) {
@@ -318,13 +310,11 @@
foreach (AbstractAccountParametersWidget *widget, widgets) {
d->optionalParametersWidgets.append(widget);
- int indexOf = widgets.indexOf(widget);
- QString description = i18n("Optional parameter");
- if(indexOf < optionalPageDesc.size())
- description = optionalPageDesc.at(indexOf);
+ title = widget->windowTitle();
+ if (title.isEmpty())
+ title = i18n("Optional parameters");
- d->tabWidget->addTab(widget, description);
- pageIndex++;
+ d->tabWidget->addTab(widget, title);
}
}
@@ -335,9 +325,6 @@
\
d->item->account()->parameters(), d->tabWidget);
d->optionalParametersWidgets.append(opew);
- if(pageIndex < optionalPageDesc.size())
- d->tabWidget->addTab(opew, optionalPageDesc.at(pageIndex));
- else
d->tabWidget->addTab(opew, i18n("Optional Parameters"));
}
}
--- trunk/playground/network/telepathy-accounts-kcm/src/edit-account-dialog.h \
#1178680:1178681 @@ -35,13 +35,7 @@
explicit EditAccountDialog(AccountItem *item, QWidget *parent = 0);
virtual ~EditAccountDialog();
-Q_SIGNALS:
- void protocolSelected(QString, QString);
-public Q_SLOTS:
- void onTitleForCustomPages(QString, QList<QString>);
- void show();
-
protected Q_SLOTS:
virtual void slotButtonClicked(int button);
@@ -51,6 +45,7 @@
private:
Q_DISABLE_COPY(EditAccountDialog);
+ void loadPages();
void accept();
class Private;
--- trunk/playground/network/telepathy-accounts-kcm/src/kcm-telepathy-accounts.cpp \
#1178680:1178681 @@ -22,6 +22,7 @@
#include "accounts-list-model.h"
#include "add-account-assistant.h"
+#include "edit-account-dialog.h"
#include <KGenericFactory>
#include <KIcon>
@@ -78,9 +79,6 @@
connect(m_accountsListView->selectionModel(),
SIGNAL(currentChanged(QModelIndex, QModelIndex)),
SLOT(onSelectedItemChanged()));
- connect(this, SIGNAL(setTitleForCustomPages(QString, \
QList<QString>)),
- m_accountsListModel, SLOT(onTitleForCustomPages(QString, \
QList<QString>)));
-
}
KCMTelepathyAccounts::~KCMTelepathyAccounts()
@@ -144,31 +142,11 @@
return;
}
- // Ensure that there is not already an instance of the \
AddAccountAssistant before we create one.";
- if (!m_addAccountAssistant) {
-
- // Create an AddAccountAssistant instance
- m_addAccountAssistant = new AddAccountAssistant(m_accountManager, \
this);
-
- // Connect to its completion signals...
- connect(m_addAccountAssistant, SIGNAL(cancelled()),
- this, SLOT(onAddAccountAssistantClosed()));
- connect(m_addAccountAssistant, SIGNAL(accepted()),
- this, SLOT(onAddAccountAssistantClosed()));
- connect(m_addAccountAssistant, SIGNAL(protocolSelected(QString, \
QString)),
- this, SLOT(onProtocolSelected(QString, QString)));
- connect(this, SIGNAL(setTitleForCustomPages(QString, QList<QString>)),
- m_addAccountAssistant, SLOT(onTitleForCustomPages(QString, \
QList<QString>)));
-
- // ...and finally show it.
- m_addAccountAssistant->show();
-
- return;
+ // ...and finally exec it.
+ AddAccountAssistant assistant(m_accountManager, this);
+ assistant.exec();
}
- kWarning() << "Cannot create a new AddAccountAssistant. One already \
exists.";
-}
-
void KCMTelepathyAccounts::onEditAccountClicked()
{
kDebug();
@@ -179,18 +157,14 @@
}
QModelIndex index = m_accountsListView->currentIndex();
+ AccountItem *item = m_accountsListModel->itemForIndex(index);
- // A valid account must be selected in the list to allow editing
- if (!index.isValid()) {
+ if (!item)
return;
- }
// Item is OK. Edit the item.
- m_accountsListModel->disconnect();
- connect(m_accountsListModel, SIGNAL(protocolSelected(QString, QString)),
- this, SLOT(onProtocolSelected(QString, QString)));
-
- m_accountsListModel->editAccount(index);
+ EditAccountDialog dialog(item, this);
+ dialog.exec();
}
void KCMTelepathyAccounts::onRemoveAccountClicked()
@@ -206,32 +180,5 @@
}
}
-void KCMTelepathyAccounts::onAddAccountAssistantClosed()
-{
- kDebug();
-
- // Add account assistant has been cancelled. Delete it.
- m_addAccountAssistant->deleteLater();
- m_addAccountAssistant = 0;
-}
-
-void KCMTelepathyAccounts::onProtocolSelected(QString protocol, QString \
localizedName)
-{
- kDebug() << protocol << localizedName;
-
- QString mandatoryPage;
- QList<QString> optionalPage;
-
- if(protocol == "jabber")
- {
- mandatoryPage = i18n("Basic setup");
- optionalPage.push_back(i18n("Account preferences"));
- optionalPage.push_back(i18n("Connection settings"));
- optionalPage.push_back(i18n("Advanced options"));
- }
-
- emit setTitleForCustomPages(mandatoryPage, optionalPage);
-}
-
#include "kcm-telepathy-accounts.moc"
--- trunk/playground/network/telepathy-accounts-kcm/src/kcm-telepathy-accounts.h \
#1178680:1178681 @@ -44,8 +44,6 @@
const QVariantList& args = \
QVariantList()); virtual ~KCMTelepathyAccounts();
-Q_SIGNALS:
- void setTitleForCustomPages(QString mandatoryPage, QList<QString> \
optionalPage);
public Q_SLOTS:
virtual void load();
@@ -58,8 +56,6 @@
void onAddAccountClicked();
void onEditAccountClicked();
void onRemoveAccountClicked();
- void onAddAccountAssistantClosed();
- void onProtocolSelected(QString protocol, QString localizedName);
private:
Tp::AccountManagerPtr m_accountManager;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic