From kde-commits Thu Jun 14 17:28:34 2012 From: Giorgos Tsiapaliwkas Date: Thu, 14 Jun 2012 17:28:34 +0000 To: kde-commits Subject: [plasmate] publisher: Fix the ui of signingwidget Message-Id: <20120614172834.792A8A60A9 () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=133969512809273 Git commit c5c69d66f659d5e09495a2470bfdcb772004b0e0 by Giorgos Tsiapaliwkas. Committed on 14/06/2012 at 19:27. Pushed by tsiapaliwkas into branch 'master'. Fix the ui of signingwidget M +61 -21 publisher/signingwidget.cpp M +3 -2 publisher/signingwidget.h http://commits.kde.org/plasmate/c5c69d66f659d5e09495a2470bfdcb772004b0e0 diff --git a/publisher/signingwidget.cpp b/publisher/signingwidget.cpp index e63dbbd..5b471c4 100644 --- a/publisher/signingwidget.cpp +++ b/publisher/signingwidget.cpp @@ -111,7 +111,8 @@ private: = SigningWidget::SigningWidget(QWidget* parent) : QWidget(parent), - m_treeWidget(0) + m_treeWidget(0), + m_noSigningButton(0) { loadConfig(); initUI(); @@ -139,6 +140,8 @@ void SigningWidget::initUI() m_treeWidget =3D new QTreeWidget(this); m_treeWidget->setHeaderLabel("Select one key from the list below:"); = + m_noSigningButton =3D new QRadioButton("No signing key.", this); + m_createKeyButton =3D new QPushButton(this); m_createKeyButton->setText("Create new Key ..."); m_createKeyButton->setIcon(KIcon("dialog-password")); @@ -148,25 +151,26 @@ void SigningWidget::initUI() m_deleteKeyButton->setText("Delete selected key"); m_deleteKeyButton->setIcon(KIcon("edit-delete")); = - m_signCheckBox =3D new QCheckBox("Enable plasmoid signing.", this); - m_signCheckBox->setChecked(m_signingEnabled); - buttonLayout->addWidget(m_createKeyButton); buttonLayout->addWidget(m_deleteKeyButton); = - mainlLayout->addWidget(m_signCheckBox); mainlLayout->addWidget(m_treeWidget); mainlLayout->addLayout(buttonLayout); setLayout(mainlLayout); = - setEnabled(m_signingEnabled); - connect(m_createKeyButton, SIGNAL(clicked()), this, SLOT(showCreateKeyDialog())); connect(m_deleteKeyButton, SIGNAL(clicked()), this, SLOT(deleteKey())); - connect(m_signCheckBox, SIGNAL(clicked(bool)), - this, SLOT(setEnabled(bool))); + + connect(m_noSigningButton, SIGNAL(clicked(bool)), this, SLOT(setEnable= d())); + + //disable the delete button when the m_noSigningButton is clicked + //we don't want the m_noSigningButton to be deleted ever! + connect(m_noSigningButton, SIGNAL(clicked(bool)), m_deleteKeyButton, S= LOT(setDisabled(bool))); + + + m_deleteKeyButton->setDisabled(m_noSigningButton->isChecked()); } = void SigningWidget::initGpgContext() @@ -224,16 +228,24 @@ QString SigningWidget::mapKeyToString(const QMap &map, const return result; } = -void SigningWidget::setEnabled(const bool enabled) +void SigningWidget::setEnabled() { - m_signingEnabled =3D enabled; + //Q: Why there is no parameter. + //A: Because we enable disable the feature according to + //m_noSigningButton's state. + + //this method will be called every time + //that the user clicks the m_noSigningButton + //so if the button is checked we don't want the signing feature, + //otherwise we do. + //Also when the button(this is every key that the user + //has in his computer) is clicked this slot will be called, + //this means that we need the signing feature. + + m_signingEnabled =3D !m_noSigningButton->isChecked(); + KConfigGroup cg(KGlobal::config(), "Signing Options"); cg.writeEntry("signingEnabled", m_signingEnabled); - cg.sync(); - - m_treeWidget->setEnabled(m_signingEnabled); - //m_createKeyButton->setEnabled(m_signingEnabled); - m_deleteKeyButton->setEnabled(m_signingEnabled); } = bool SigningWidget::signingEnabled() const @@ -355,21 +367,49 @@ void SigningWidget::deleteKey() void SigningWidget::loadKeys() { m_treeWidget->clear(); + QTreeWidgetItem *item =3D new QTreeWidgetItem(m_treeWidget); + + //add the no singing button + QVBoxLayout *l =3D new QVBoxLayout(); + l->addWidget(m_noSigningButton); + QList< QMap > entries =3D gpgEntryList(true); + for (int i =3D 0; i < entries.count(); ++i) { QMap entry =3D entries.at(i); - QTreeWidgetItem *item =3D new QTreeWidgetItem(m_treeWidget); QRadioButton *button =3D new QRadioButton(mapKeyToString(entry, fa= lse), this); button->setObjectName(mapKeyToString(entry)); if (!m_currentKey.isNull() || m_currentKey.isEmpty()) { - if (m_currentKey =3D=3D mapKeyToString(entry)) + + //First check if this is the key that we want + //and then check if the signing option is enabled. + if (m_currentKey =3D=3D mapKeyToString(entry) && signingEnable= d()) { + //yes this is the right key and the signing option is enab= led + //so checkk the right button button->setChecked(true); + } else { + //either the signing option isn't enabled + //or there is no right key, in both cases + //we want the m_noSigningButton to be checked + m_noSigningButton->setChecked(true); + } } - m_treeWidget->setItemWidget(item, 0, button); + l->addWidget(button); + + connect(button, SIGNAL(clicked(bool)), this, SLOT(updateCurrentKey= ())); = - connect(button, SIGNAL(clicked(bool)), - this, SLOT(updateCurrentKey())); + //enable the signing feature + connect(button, SIGNAL(clicked(bool)), this, SLOT(setEnabled())); + + //enable the m_deleteKeyButton + //we want the user to be able to delete a key, so enable the m_del= eteKeyButton + connect(button, SIGNAL(clicked(bool)), m_deleteKeyButton, SLOT(set= Enabled(bool))); } + + //add the widgets into the treewidget + QWidget *tmpWidget =3D new QWidget(); + tmpWidget->setLayout(l); + m_treeWidget->setItemWidget(item, 0, tmpWidget); } = void SigningWidget::updateCurrentKey() diff --git a/publisher/signingwidget.h b/publisher/signingwidget.h index 501752e..adf5b2b 100644 --- a/publisher/signingwidget.h +++ b/publisher/signingwidget.h @@ -25,6 +25,7 @@ = class QTreeWidget; class QPushButton; +class QRadioButton; class QStringList; class QCheckBox; class QStringList; @@ -47,7 +48,7 @@ public: bool sign(const KUrl &path); = public Q_SLOTS: - void setEnabled(const bool enabled); + void setEnabled(); void createKey(const QString ¶m); = private: @@ -61,7 +62,7 @@ private: QTreeWidget *m_treeWidget; QPushButton *m_createKeyButton; QPushButton *m_deleteKeyButton; - QCheckBox* m_signCheckBox; + QRadioButton *m_noSigningButton; = QString m_currentKey; GpgME::Context *m_gpgContext;