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

List:       kde-commits
Subject:    playground/network/telepathy-accounts-kcm/src
From:       George Goldberg <grundleborg () googlemail ! com>
Date:       2009-08-03 13:19:58
Message-ID: 1249305598.920717.19275.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1006320 by gberg:

Show the apropriate parameter-edit-widgets in the edit account dialog. Does not yet \
prepopulate them with existing values.

 M  +126 -1    edit-account-dialog.cpp  


--- trunk/playground/network/telepathy-accounts-kcm/src/edit-account-dialog.cpp \
#1006319:1006320 @@ -20,18 +20,39 @@
 
 #include "edit-account-dialog.h"
 
+#include "mandatory-parameter-edit-widget.h"
+#include "optional-parameter-edit-widget.h"
+#include "plugin-manager.h"
+
+#include "libkcmtelepathyaccounts/abstract-account-parameters-widget.h"
+#include "libkcmtelepathyaccounts/abstract-account-ui.h"
+
 #include <KDebug>
+#include <KLocale>
+#include <KTabWidget>
 
+#include <QtCore/QList>
+
+#include <TelepathyQt4/ConnectionManager>
+
 class EditAccountDialog::Private
 {
 public:
     Private()
-            : item(0)
+            : item(0), tabWidget(0), mandatoryParametersWidget(0)
     {
         kDebug();
     }
 
     AccountItem *item;
+
+    Tp::ProtocolParameterList mandatoryProtocolParameters;
+    Tp::ProtocolParameterList optionalProtocolParameters;
+    QVariantMap parameterValues;
+
+    KTabWidget *tabWidget;
+    AbstractAccountParametersWidget *mandatoryParametersWidget;
+    QList<AbstractAccountParametersWidget*> optionalParametersWidgets;
 };
 
 EditAccountDialog::EditAccountDialog(AccountItem *item, QWidget *parent)
@@ -40,7 +61,111 @@
 {
     kDebug();
 
+    // Set up the tab widget.
+    d->tabWidget = new KTabWidget(this);
+    setMainWidget(d->tabWidget);
+    resize(400, 480);
+
     d->item = item;
+
+    // Get the protocol's parameters.
+    Tp::ProtocolInfo *protocolInfo = d->item->account()->protocolInfo();
+    Tp::ProtocolParameterList protocolParameters = protocolInfo->parameters();
+
+    foreach (Tp::ProtocolParameter *parameter, protocolParameters) {
+        if (parameter->isRequired()) {
+            d->mandatoryProtocolParameters.append(parameter);
+        } else {
+            d->optionalProtocolParameters.append(parameter);
+        }
+    }
+
+    // Get the parameter values.
+    d->parameterValues = d->item->account()->parameters();
+
+    // The rest of this method is based on code from add-account-assistant.cpp
+
+    // Get the AccountsUi for the plugin, and get the optional parameter widgets for \
it. +    AbstractAccountUi *ui = \
PluginManager::instance()->accountUiForProtocol(item->account()->cmName(), +          \
item->account()->protocol()); +
+    // Set up the Mandatory Parameters page
+    Tp::ProtocolParameterList mandatoryParametersLeft = \
d->mandatoryProtocolParameters; +
+    // Create the custom UI or generic UI depending on available parameters.
+    if (ui) {
+        // UI does exist, set it up.
+        AbstractAccountParametersWidget *widget = \
ui->mandatoryParametersWidget(d->mandatoryProtocolParameters); +        QMap<QString, \
QVariant::Type> manParams = ui->supportedMandatoryParameters(); +        \
QMap<QString, QVariant::Type>::const_iterator manIter = manParams.constBegin(); +     \
while(manIter != manParams.constEnd()) { +            foreach (Tp::ProtocolParameter \
*parameter, d->mandatoryProtocolParameters) { +                // 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;
+        }
+    }
+
+    if (!d->mandatoryParametersWidget) {
+        d->mandatoryParametersWidget = new \
MandatoryParameterEditWidget(d->mandatoryProtocolParameters, d->tabWidget); +    }
+
+    d->tabWidget->addTab(d->mandatoryParametersWidget, i18n("Mandatory \
Parameters")); +
+    // Get the list of parameters
+    Tp::ProtocolParameterList optionalParametersLeft = \
d->optionalProtocolParameters; +
+    // 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(d->optionalProtocolParameters); +
+        // 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, \
d->optionalProtocolParameters) { +                // 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"));
+        }
+    }
+
+    // Show the generic UI if optionalParameters is not empty.
+    if (optionalParametersLeft.size() > 0) {
+        OptionalParameterEditWidget *opew =
+                new OptionalParameterEditWidget(optionalParametersLeft, \
d->tabWidget); +        d->optionalParametersWidgets.append(opew);
+        d->tabWidget->addTab(opew, i18n("Optional Parameters"));
+    }
+
 }
 
 EditAccountDialog::~EditAccountDialog()


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

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