[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/network/telepathy-accounts-kcm/src
From:       Matteo Nardi <91.matteo () gmail ! com>
Date:       2009-08-06 19:00:52
Message-ID: 1249585252.799903.19122.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1008048 by nardi:

-Enable the next button only when a protocol is selected on the first page of the add \
                account assistant.
-Go to next page when a protocol is double clicked.


 M  +100 -90   add-account-assistant.cpp  
 M  +1 -0      add-account-assistant.h  
 M  +7 -4      protocol-select-widget.cpp  
 M  +4 -2      protocol-select-widget.h  


--- trunk/playground/network/telepathy-accounts-kcm/src/add-account-assistant.cpp \
#1008047:1008048 @@ -75,6 +75,14 @@
     d->protocolSelectWidget = new ProtocolSelectWidget(this);
     d->pageOne = new KPageWidgetItem(d->protocolSelectWidget);
     d->pageOne->setHeader(i18n("Step 1: Select an Instant Messaging Network."));
+    setValid(d->pageOne, false);
+    connect(d->protocolSelectWidget,
+            SIGNAL(protocolGotSelected(bool)),
+            SLOT(onProtocolSelected(bool)));
+    connect(d->protocolSelectWidget,
+            SIGNAL(protocolDoubleClicked()),
+            SLOT(next()));
+
     d->tabWidget = new KTabWidget(this);
     d->pageTwo = new KPageWidgetItem(d->tabWidget);
     d->pageTwo->setHeader(i18n("Step 2: Fill in the required Parameters."));
@@ -102,124 +110,120 @@
     // Check which page we are on.
     if (currentPage() == d->pageOne) {
         kDebug() << "Current page: Page 1.";
-        // Page 1
 
-        // Check if the protocol is selected. If it is, set up the next page and \
                continue to it.
-        if (d->protocolSelectWidget->selectedProtocol()) {
-            kDebug() << "Protocol is selected. Set up and continue to the next \
page."; +        Q_ASSERT(d->protocolSelectWidget->selectedProtocol());
 
-            // Set up the next page.
-            ProtocolItem *item = d->protocolSelectWidget->selectedProtocol();
+        // Set up the next page.
+        ProtocolItem *item = d->protocolSelectWidget->selectedProtocol();
 
-            ConnectionManagerItem *cmItem = \
                qobject_cast<ConnectionManagerItem*>(item->parent());
-            if (!cmItem) {
-                kWarning() << "cmItem is invalid.";
-            }
+        ConnectionManagerItem *cmItem = \
qobject_cast<ConnectionManagerItem*>(item->parent()); +        if (!cmItem) {
+            kWarning() << "cmItem is invalid.";
+        }
 
-            QString connectionManager = cmItem->connectionManager()->name();
-            QString protocol = item->protocol();
+        QString connectionManager = cmItem->connectionManager()->name();
+        QString protocol = item->protocol();
 
-            // Get the AccountsUi for the plugin, and get the optional parameter \
                widgets for it.
-            AbstractAccountUi *ui = \
                PluginManager::instance()->accountUiForProtocol(connectionManager,
-                                                                                    \
protocol); +        // Get the AccountsUi for the plugin, and get the optional \
parameter widgets for it. +        AbstractAccountUi *ui = \
PluginManager::instance()->accountUiForProtocol(connectionManager, +                  \
protocol);  
-            // Delete the widgets for the next page if they already exist
-            if (d->mandatoryParametersWidget) {
-                d->mandatoryParametersWidget->deleteLater();
-                d->mandatoryParametersWidget = 0;
-            }
+        // Delete the widgets for the next page if they already exist
+        if (d->mandatoryParametersWidget) {
+            d->mandatoryParametersWidget->deleteLater();
+            d->mandatoryParametersWidget = 0;
+        }
 
-            foreach (AbstractAccountParametersWidget *w, \
                d->optionalParametersWidgets) {
-                if (w) {
-                    w->deleteLater();
-                }
+        foreach (AbstractAccountParametersWidget *w, d->optionalParametersWidgets) {
+            if (w) {
+                w->deleteLater();
             }
-            d->optionalParametersWidgets.clear();
+        }
+        d->optionalParametersWidgets.clear();
 
-            // Set up the Mandatory Parameters page
-            Tp::ProtocolParameterList mandatoryParameters = \
                item->mandatoryParameters();
-            Tp::ProtocolParameterList mandatoryParametersLeft = \
item->mandatoryParameters(); +        // Set up the Mandatory Parameters page
+        Tp::ProtocolParameterList mandatoryParameters = item->mandatoryParameters();
+        Tp::ProtocolParameterList mandatoryParametersLeft = \
item->mandatoryParameters();  
-            // Create the custom UI or generic UI depending on available parameters.
-            if (ui) {
-                // UI does exist, set it up.
-                AbstractAccountParametersWidget *widget = \
                ui->mandatoryParametersWidget(mandatoryParameters);
-                QMap<QString, QVariant::Type> manParams = \
                ui->supportedMandatoryParameters();
-                QMap<QString, QVariant::Type>::const_iterator manIter = \
                manParams.constBegin();
-                while(manIter != manParams.constEnd()) {
-                    foreach (Tp::ProtocolParameter *parameter, mandatoryParameters) \
                {
-                        // If the parameter is not
-                        if ((parameter->name() == manIter.key()) &&
-                            (parameter->type() == manIter.value())) {
-                            mandatoryParametersLeft.removeAll(parameter);
-                        }
+        // Create the custom UI or generic UI depending on available parameters.
+        if (ui) {
+            // UI does exist, set it up.
+            AbstractAccountParametersWidget *widget = \
ui->mandatoryParametersWidget(mandatoryParameters); +            QMap<QString, \
QVariant::Type> manParams = ui->supportedMandatoryParameters(); +            \
QMap<QString, QVariant::Type>::const_iterator manIter = manParams.constBegin(); +     \
while(manIter != manParams.constEnd()) { +                foreach \
(Tp::ProtocolParameter *parameter, mandatoryParameters) { +                    // If \
the parameter is not +                    if ((parameter->name() == manIter.key()) &&
+                        (parameter->type() == manIter.value())) {
+                        mandatoryParametersLeft.removeAll(parameter);
                     }
-
-                    ++manIter;
                 }
 
-                if (mandatoryParametersLeft.isEmpty()) {
-                    d->mandatoryParametersWidget = widget;
-                } else {
-                    // FIXME: At the moment, if the custom widget can't handle all \
                the mandatory
-                    // parameters we fall back to the generic one for all of them. \
                It might be nicer
-                    // to have the custom UI for as many as possible, and stick a \
                small generic one
-                    // underneath for those parameters it doesn't handle.
-                    widget->deleteLater();
-                    widget = 0;
-                }
+                ++manIter;
             }
 
-            if (!d->mandatoryParametersWidget) {
-                d->mandatoryParametersWidget = new MandatoryParameterEditWidget(
-                        item->mandatoryParameters(), QVariantMap(), d->tabWidget);
+            if (mandatoryParametersLeft.isEmpty()) {
+                d->mandatoryParametersWidget = widget;
+            } else {
+                // FIXME: At the moment, if the custom widget can't handle all the \
mandatory +                // parameters we fall back to the generic one for all of \
them. It might be nicer +                // to have the custom UI for as many as \
possible, and stick a small generic one +                // underneath for those \
parameters it doesn't handle. +                widget->deleteLater();
+                widget = 0;
             }
+        }
 
-            d->tabWidget->addTab(d->mandatoryParametersWidget, i18n("Mandatory \
Parameters")); +        if (!d->mandatoryParametersWidget) {
+            d->mandatoryParametersWidget = new MandatoryParameterEditWidget(
+                    item->mandatoryParameters(), QVariantMap(), d->tabWidget);
+        }
 
-            // Get the list of parameters
-            Tp::ProtocolParameterList optionalParameters = \
                item->optionalParameters();
-            Tp::ProtocolParameterList optionalParametersLeft = \
item->optionalParameters(); +        \
d->tabWidget->addTab(d->mandatoryParametersWidget, i18n("Mandatory Parameters"));  
-            // Check if the AbstractAccountUi exists. If not then we use the \
                autogenerated UI for
-            // everything.
-            if (ui) {
-                // UI Does exist, set it up.
-                QList<AbstractAccountParametersWidget*> widgets = \
ui->optionalParametersWidgets(optionalParameters); +        // Get the list of \
parameters +        Tp::ProtocolParameterList optionalParameters = \
item->optionalParameters(); +        Tp::ProtocolParameterList optionalParametersLeft \
= item->optionalParameters();  
-                // Remove all handled parameters from the optionalParameters list.
-                QMap<QString, QVariant::Type> opParams = \
                ui->supportedOptionalParameters();
-                QMap<QString, QVariant::Type>::const_iterator opIter = \
                opParams.constBegin();
-                while(opIter != opParams.constEnd()) {
-                    foreach (Tp::ProtocolParameter *parameter, optionalParameters) {
-                        // If the parameter is not
-                        if ((parameter->name() == opIter.key()) &&
-                            (parameter->type() == opIter.value())) {
-                            optionalParametersLeft.removeAll(parameter);
-                        }
+        // Check if the AbstractAccountUi exists. If not then we use the \
autogenerated UI for +        // everything.
+        if (ui) {
+            // UI Does exist, set it up.
+            QList<AbstractAccountParametersWidget*> widgets = \
ui->optionalParametersWidgets(optionalParameters); +
+            // Remove all handled parameters from the optionalParameters list.
+            QMap<QString, QVariant::Type> opParams = \
ui->supportedOptionalParameters(); +            QMap<QString, \
QVariant::Type>::const_iterator opIter = opParams.constBegin(); +            \
while(opIter != opParams.constEnd()) { +                foreach \
(Tp::ProtocolParameter *parameter, optionalParameters) { +                    // If \
the parameter is not +                    if ((parameter->name() == opIter.key()) &&
+                        (parameter->type() == opIter.value())) {
+                        optionalParametersLeft.removeAll(parameter);
                     }
-
-                    ++opIter;
                 }
 
-                foreach (AbstractAccountParametersWidget *widget, widgets) {
-                    d->optionalParametersWidgets.append(widget);
-                    d->tabWidget->addTab(widget, i18n("Optional Parameters"));
-                }
+                ++opIter;
             }
 
-            // Show the generic UI if optionalParameters is not empty.
-            if (optionalParametersLeft.size() > 0) {
-                OptionalParameterEditWidget *opew =
-                        new OptionalParameterEditWidget(optionalParametersLeft,
-                                                        QVariantMap(),
-                                                        d->tabWidget);
-                d->optionalParametersWidgets.append(opew);
-                d->tabWidget->addTab(opew, i18n("Optional Parameters"));
+            foreach (AbstractAccountParametersWidget *widget, widgets) {
+                d->optionalParametersWidgets.append(widget);
+                d->tabWidget->addTab(widget, i18n("Optional Parameters"));
             }
+        }
 
-            KAssistantDialog::next();
+        // Show the generic UI if optionalParameters is not empty.
+        if (optionalParametersLeft.size() > 0) {
+            OptionalParameterEditWidget *opew =
+                    new OptionalParameterEditWidget(optionalParametersLeft,
+                                                    QVariantMap(),
+                                                    d->tabWidget);
+            d->optionalParametersWidgets.append(opew);
+            d->tabWidget->addTab(opew, i18n("Optional Parameters"));
         }
+
+        KAssistantDialog::next();
     }
 }
 
@@ -331,6 +335,12 @@
     KAssistantDialog::accept();
 }
 
+void AddAccountAssistant::onProtocolSelected(bool value)
+{
+    //if a protocol is selected, enable the next button on the first page
+    setValid(d->pageOne, value);
+}
 
+
 #include "add-account-assistant.moc"
 
--- trunk/playground/network/telepathy-accounts-kcm/src/add-account-assistant.h \
#1008047:1008048 @@ -47,6 +47,7 @@
 
 private Q_SLOTS:
     void onAccountCreated(Tp::PendingOperation *op);
+    void onProtocolSelected(bool value);
 
 private:
     class Private;
--- trunk/playground/network/telepathy-accounts-kcm/src/protocol-select-widget.cpp \
#1008047:1008048 @@ -59,8 +59,11 @@
     d->ui->protocolListView->setModel(d->model);
 
     connect(d->ui->protocolListView->selectionModel(),
-            SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
-            SLOT(onCurrentChanged(const QModelIndex &)));
+            SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection \
&)), +            SLOT(onSelectionChanged(const QItemSelection &)));
+    connect(d->ui->protocolListView,
+            SIGNAL(doubleClicked(QModelIndex)),
+            SIGNAL(protocolDoubleClicked()));
 
     // Load the list of all installed Telepathy Connection Managers Asynchronously
     QTimer::singleShot(0, this, SLOT(getConnectionManagerList()));
@@ -131,11 +134,11 @@
     return d->model->itemForIndex(selectedIndexes.at(0));
 }
 
-void ProtocolSelectWidget::onCurrentChanged(const QModelIndex &current)
+void ProtocolSelectWidget::onSelectionChanged(const QItemSelection &selected)
 {
     kDebug();
 
-    Q_EMIT selectedProtocolChanged(d->model->itemForIndex(current));
+    Q_EMIT protocolGotSelected(!selected.isEmpty());
 }
 
 
--- trunk/playground/network/telepathy-accounts-kcm/src/protocol-select-widget.h \
#1008047:1008048 @@ -24,6 +24,7 @@
 #include <QtGui/QWidget>
 
 class ProtocolItem;
+class QItemSelection;
 
 class QModelIndex;
 
@@ -44,10 +45,11 @@
 private Q_SLOTS:
     void getConnectionManagerList();
     void onConnectionManagerListGot(Tp::PendingOperation *op);
-    void onCurrentChanged(const QModelIndex &current);
+    void onSelectionChanged(const QItemSelection &selected);
 
 Q_SIGNALS:
-    void selectedProtocolChanged(ProtocolItem *item);
+    void protocolGotSelected(bool selected);
+    void protocolDoubleClicked();
 
 private:
     class Private;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic