~ubuntu-branches/debian/experimental/quassel/experimental

« back to all changes in this revision

Viewing changes to src/qtui/coreconfigwizard.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Mueller
  • Date: 2009-10-05 23:13:06 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20091005231306-ngiajv5r0gbxjfoq
Tags: 0.5.0~rc2-1
* New upstream release (rc2)
* Make puiparts happy (closes: #538182)
* manageusers.py added (closes: #549296)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include <QDebug>
22
22
#include <QAbstractButton>
 
23
#include <QFormLayout>
 
24
#include <QSpinBox>
23
25
 
24
26
#include "coreconfigwizard.h"
25
27
#include "iconloader.h"
30
32
  setPage(AdminUserPage, new CoreConfigWizardPages::AdminUserPage(this));
31
33
  setPage(StorageSelectionPage, new CoreConfigWizardPages::StorageSelectionPage(_backends, this));
32
34
  syncPage = new CoreConfigWizardPages::SyncPage(this);
33
 
  connect(syncPage, SIGNAL(setupCore(const QString &)), this, SLOT(prepareCoreSetup(const QString &)));
 
35
  connect(syncPage, SIGNAL(setupCore(const QString &, const QVariantMap &)), this, SLOT(prepareCoreSetup(const QString &, const QVariantMap &)));
34
36
  setPage(SyncPage, syncPage);
35
37
  syncRelayPage = new CoreConfigWizardPages::SyncRelayPage(this);
36
38
  connect(syncRelayPage, SIGNAL(startOver()), this, SLOT(startOver()));
63
65
  return _backends;
64
66
}
65
67
 
66
 
void CoreConfigWizard::prepareCoreSetup(const QString &backend) {
 
68
void CoreConfigWizard::prepareCoreSetup(const QString &backend, const QVariantMap &properties) {
67
69
  // Prevent the user from changing any settings he already specified...
68
 
  foreach(int idx, visitedPages()) page(idx)->setEnabled(false);
 
70
  foreach(int idx, visitedPages())
 
71
    page(idx)->setEnabled(false);
 
72
 
69
73
  QVariantMap foo;
70
74
  foo["AdminUser"] = field("adminUser.user").toString();
71
75
  foo["AdminPasswd"] = field("adminUser.password").toString();
72
76
  foo["Backend"] = backend;
 
77
  foo["ConnectionProperties"] = properties;
73
78
  emit setupCore(foo);
74
79
}
75
80
 
91
96
  //foreach(int idx, visitedPages()) page(idx)->setEnabled(true);
92
97
  //setStartId(SyncPage);
93
98
  //restart();
94
 
 
95
99
}
96
100
 
97
101
void CoreConfigWizard::startOver() {
158
162
 
159
163
/*** Storage Selection Page ***/
160
164
 
161
 
StorageSelectionPage::StorageSelectionPage(const QHash<QString, QVariant> &backends, QWidget *parent) : QWizardPage(parent) {
 
165
StorageSelectionPage::StorageSelectionPage(const QHash<QString, QVariant> &backends, QWidget *parent)
 
166
  : QWizardPage(parent),
 
167
    _connectionBox(0),
 
168
    _backends(backends)
 
169
{
162
170
  ui.setupUi(this);
163
 
  _backends = backends;
164
171
 
165
172
  setTitle(tr("Select Storage Backend"));
166
173
  setSubTitle(tr("Please select a database backend for the Quassel Core storage to store the backlog and other data in."));
183
190
  return ui.backendList->currentText();
184
191
}
185
192
 
 
193
QVariantMap StorageSelectionPage::connectionProperties() const {
 
194
  QString backend = ui.backendList->itemData(ui.backendList->currentIndex()).toString();
 
195
 
 
196
  QVariantMap properties;
 
197
  QStringList setupKeys = _backends[backend].toMap()["SetupKeys"].toStringList();
 
198
  if(!setupKeys.isEmpty()) {
 
199
    QVariantMap defaults = _backends[backend].toMap()["SetupDefaults"].toMap();
 
200
    foreach(QString key, setupKeys) {
 
201
      QWidget *widget = _connectionBox->findChild<QWidget *>(key);
 
202
      QVariant def;
 
203
      if(defaults.contains(key)) {
 
204
        def = defaults[key];
 
205
      }
 
206
      switch(def.type()) {
 
207
      case QVariant::Int:
 
208
        {
 
209
          QSpinBox *spinbox = qobject_cast<QSpinBox *>(widget);
 
210
          Q_ASSERT(spinbox);
 
211
          def = QVariant(spinbox->value());
 
212
        }
 
213
        break;
 
214
      default:
 
215
        {
 
216
          QLineEdit *lineEdit = qobject_cast<QLineEdit *>(widget);
 
217
          Q_ASSERT(lineEdit);
 
218
          def = QVariant(lineEdit->text());
 
219
        }
 
220
      }
 
221
      properties[key] = def;
 
222
    }
 
223
  }
 
224
  qDebug() << properties;
 
225
 
 
226
 
 
227
//   QVariantMap properties = _backends[backend].toMap()["ConnectionProperties"].toMap();
 
228
//   if(!properties.isEmpty() && _connectionBox) {
 
229
//     QVariantMap::iterator propertyIter = properties.begin();
 
230
//     while(propertyIter != properties.constEnd()) {
 
231
//       QWidget *widget = _connectionBox->findChild<QWidget *>(propertyIter.key());
 
232
//       switch(propertyIter.value().type()) {
 
233
//       case QVariant::Int:
 
234
//      {
 
235
//        QSpinBox *spinbox = qobject_cast<QSpinBox *>(widget);
 
236
//        Q_ASSERT(spinbox);
 
237
//        propertyIter.value() = QVariant(spinbox->value());
 
238
//      }
 
239
//      break;
 
240
//       default:
 
241
//      {
 
242
//        QLineEdit *lineEdit = qobject_cast<QLineEdit *>(widget);
 
243
//        Q_ASSERT(lineEdit);
 
244
//        propertyIter.value() = QVariant(lineEdit->text());
 
245
//      }
 
246
//       }
 
247
//       propertyIter++;
 
248
//     }
 
249
//   }
 
250
  return properties;
 
251
}
 
252
 
186
253
void StorageSelectionPage::on_backendList_currentIndexChanged() {
187
254
  QString backend = ui.backendList->itemData(ui.backendList->currentIndex()).toString();
188
255
  ui.description->setText(_backends[backend].toMap()["Description"].toString());
 
256
 
 
257
  if(_connectionBox) {
 
258
    layout()->removeWidget(_connectionBox);
 
259
    _connectionBox->deleteLater();
 
260
    _connectionBox = 0;
 
261
  }
 
262
 
 
263
  QStringList setupKeys = _backends[backend].toMap()["SetupKeys"].toStringList();
 
264
  if(!setupKeys.isEmpty()) {
 
265
    QVariantMap defaults = _backends[backend].toMap()["SetupDefaults"].toMap();
 
266
    QGroupBox *propertyBox = new QGroupBox(this);
 
267
    propertyBox->setTitle(tr("Connection Properties"));
 
268
    QFormLayout *formlayout = new QFormLayout;
 
269
 
 
270
    foreach(QString key, setupKeys) {
 
271
      QWidget *widget = 0;
 
272
      QVariant def;
 
273
      if(defaults.contains(key)) {
 
274
        def = defaults[key];
 
275
      }
 
276
      switch(def.type()) {
 
277
      case QVariant::Int:
 
278
        {
 
279
          QSpinBox *spinbox = new QSpinBox(propertyBox);
 
280
          spinbox->setMaximum(64000);
 
281
          spinbox->setValue(def.toInt());
 
282
          widget = spinbox;
 
283
        }
 
284
        break;
 
285
      default:
 
286
        {
 
287
          QLineEdit *lineEdit = new QLineEdit(def.toString(), propertyBox);
 
288
          if(key.toLower().contains("password")) {
 
289
            lineEdit->setEchoMode(QLineEdit::Password);
 
290
          }
 
291
          widget = lineEdit;
 
292
        }
 
293
      }
 
294
      widget->setObjectName(key);
 
295
      formlayout->addRow(key + ":", widget);
 
296
    }
 
297
    propertyBox->setLayout(formlayout);
 
298
    static_cast<QVBoxLayout *>(layout())->insertWidget(layout()->indexOf(ui.descriptionBox) + 1, propertyBox);
 
299
    _connectionBox = propertyBox;
 
300
  }
189
301
}
190
302
 
191
303
/*** Sync Page ***/
199
311
void SyncPage::initializePage() {
200
312
  complete = false;
201
313
  hasError = false;
202
 
  QString backend = qobject_cast<StorageSelectionPage *>(wizard()->page(CoreConfigWizard::StorageSelectionPage))->selectedBackend();
 
314
 
 
315
  StorageSelectionPage *storagePage = qobject_cast<StorageSelectionPage *>(wizard()->page(CoreConfigWizard::StorageSelectionPage));
 
316
  QString backend = storagePage->selectedBackend();
 
317
  QVariantMap properties = storagePage->connectionProperties();
203
318
  Q_ASSERT(!backend.isEmpty());
204
319
  ui.user->setText(wizard()->field("adminUser.user").toString());
205
320
  ui.backend->setText(backend);
206
 
  emit setupCore(backend);
 
321
  emit setupCore(backend, properties);
207
322
}
208
323
 
209
324
int SyncPage::nextId() const {