Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/dialogs/kgpgkeyselectiondlg.cpp
Context not available. | |||||
3 | ------------------- | 3 | ------------------- | ||
---|---|---|---|---|---|
4 | copyright : (C) 2008 by Thomas Baumgart | 4 | copyright : (C) 2008 by Thomas Baumgart | ||
5 | email : ipwizard@users.sourceforge.net | 5 | email : ipwizard@users.sourceforge.net | ||
6 | (C) 2017 by Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> | ||||
6 | ***************************************************************************/ | 7 | ***************************************************************************/ | ||
7 | 8 | | |||
8 | /*************************************************************************** | 9 | /*************************************************************************** | ||
Context not available. | |||||
38 | #include <QDialogButtonBox> | 39 | #include <QDialogButtonBox> | ||
39 | #include <QPushButton> | 40 | #include <QPushButton> | ||
40 | 41 | | |||
42 | class KGpgKeySelectionDlgPrivate | ||||
43 | { | ||||
44 | Q_DISABLE_COPY(KGpgKeySelectionDlgPrivate) | ||||
45 | | ||||
46 | public: | ||||
47 | KGpgKeySelectionDlgPrivate() | ||||
48 | { | ||||
49 | } | ||||
50 | | ||||
51 | ~KGpgKeySelectionDlgPrivate() | ||||
52 | { | ||||
53 | } | ||||
54 | | ||||
55 | KEditListWidget* m_listWidget; | ||||
56 | KLed* m_keyLed; | ||||
57 | bool m_needCheckList; | ||||
58 | bool m_listOk; | ||||
59 | int m_checkCount; | ||||
60 | }; | ||||
61 | | ||||
62 | | ||||
41 | KGpgKeySelectionDlg::KGpgKeySelectionDlg(QWidget *parent) : | 63 | KGpgKeySelectionDlg::KGpgKeySelectionDlg(QWidget *parent) : | ||
42 | QDialog(parent), | 64 | QDialog(parent), | ||
43 | m_needCheckList(true), | 65 | d_ptr(new KGpgKeySelectionDlgPrivate) | ||
44 | m_listOk(false), | | |||
45 | m_checkCount(0) | | |||
46 | { | 66 | { | ||
67 | Q_D(KGpgKeySelectionDlg); | ||||
68 | d->m_needCheckList = true; | ||||
69 | d->m_listOk = false; | ||||
70 | d->m_checkCount = 0; | ||||
47 | // TODO: check port to kf5 | 71 | // TODO: check port to kf5 | ||
48 | setWindowTitle(i18n("Select additional keys")); | 72 | setWindowTitle(i18n("Select additional keys")); | ||
49 | QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); | 73 | QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); | ||
Context not available. | |||||
54 | QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); | 78 | QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); | ||
55 | okButton->setDefault(true); | 79 | okButton->setDefault(true); | ||
56 | okButton->setShortcut(Qt::CTRL | Qt::Key_Return); | 80 | okButton->setShortcut(Qt::CTRL | Qt::Key_Return); | ||
57 | connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); | 81 | connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); | ||
58 | connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); | 82 | connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); | ||
59 | buttonBox->button(QDialogButtonBox::Ok)->setDefault(true); | 83 | buttonBox->button(QDialogButtonBox::Ok)->setDefault(true); | ||
60 | setModal(true); | 84 | setModal(true); | ||
61 | QWidget* page = new QWidget(this); | 85 | QWidget* page = new QWidget(this); | ||
Context not available. | |||||
66 | QVBoxLayout *verticalLayout = new QVBoxLayout(listBox); | 90 | QVBoxLayout *verticalLayout = new QVBoxLayout(listBox); | ||
67 | verticalLayout->setSpacing(6); | 91 | verticalLayout->setSpacing(6); | ||
68 | verticalLayout->setContentsMargins(0, 0, 0, 0); | 92 | verticalLayout->setContentsMargins(0, 0, 0, 0); | ||
69 | m_listWidget = new KEditListWidget(listBox); | 93 | d->m_listWidget = new KEditListWidget(listBox); | ||
70 | m_listWidget->connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); | 94 | d->m_listWidget->connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); | ||
71 | m_listWidget->connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); | 95 | d->m_listWidget->connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); | ||
72 | m_listWidget->setWhatsThis(i18n("Enter the id of the key you want to use for data encryption. This can either be an e-mail address or the hexadecimal key id. In case of the key id, do not forget the leading 0x.")); | 96 | d->m_listWidget->setWhatsThis(i18n("Enter the id of the key you want to use for data encryption. This can either be an e-mail address or the hexadecimal key id. In case of the key id, do not forget the leading 0x.")); | ||
73 | verticalLayout->addWidget(m_listWidget); | 97 | verticalLayout->addWidget(d->m_listWidget); | ||
74 | 98 | | |||
75 | // add a LED for the availability of all keys | 99 | // add a LED for the availability of all keys | ||
76 | QHBoxLayout* ledBox = new QHBoxLayout(); | 100 | QHBoxLayout* ledBox = new QHBoxLayout(); | ||
Context not available. | |||||
78 | ledBox->setSpacing(6); | 102 | ledBox->setSpacing(6); | ||
79 | ledBox->setObjectName("ledBoxLayout"); | 103 | ledBox->setObjectName("ledBoxLayout"); | ||
80 | 104 | | |||
81 | m_keyLed = new KLed(page); | 105 | d->m_keyLed = new KLed(page); | ||
82 | mainLayout->addWidget(m_keyLed); | 106 | mainLayout->addWidget(d->m_keyLed); | ||
83 | m_keyLed->setShape(KLed::Circular); | 107 | d->m_keyLed->setShape(KLed::Circular); | ||
84 | m_keyLed->setLook(KLed::Sunken); | 108 | d->m_keyLed->setLook(KLed::Sunken); | ||
85 | 109 | | |||
86 | ledBox->addWidget(m_keyLed); | 110 | ledBox->addWidget(d->m_keyLed); | ||
87 | ledBox->addWidget(new QLabel(i18n("Keys for all of the above user ids found"), page)); | 111 | ledBox->addWidget(new QLabel(i18n("Keys for all of the above user ids found"), page)); | ||
88 | ledBox->addItem(new QSpacerItem(50, 20, QSizePolicy::Expanding, QSizePolicy::Minimum)); | 112 | ledBox->addItem(new QSpacerItem(50, 20, QSizePolicy::Expanding, QSizePolicy::Minimum)); | ||
89 | 113 | | |||
90 | verticalLayout->addLayout(ledBox); | 114 | verticalLayout->addLayout(ledBox); | ||
91 | 115 | | |||
92 | connect(m_listWidget, SIGNAL(changed()), this, SLOT(slotIdChanged())); | 116 | connect(d->m_listWidget, &KEditListWidget::changed, this, &KGpgKeySelectionDlg::slotIdChanged); | ||
93 | connect(m_listWidget, SIGNAL(added(QString)), this, SLOT(slotKeyListChanged())); | 117 | connect(d->m_listWidget, &KEditListWidget::added, this, &KGpgKeySelectionDlg::slotKeyListChanged); | ||
94 | connect(m_listWidget, SIGNAL(removed(QString)), this, SLOT(slotKeyListChanged())); | 118 | connect(d->m_listWidget, &KEditListWidget::removed, this, &KGpgKeySelectionDlg::slotKeyListChanged); | ||
119 | } | ||||
120 | | ||||
121 | KGpgKeySelectionDlg::~KGpgKeySelectionDlg() | ||||
122 | { | ||||
123 | Q_D(KGpgKeySelectionDlg); | ||||
124 | delete d; | ||||
95 | } | 125 | } | ||
96 | 126 | | |||
97 | void KGpgKeySelectionDlg::setKeys(const QStringList& list) | 127 | void KGpgKeySelectionDlg::setKeys(const QStringList& list) | ||
98 | { | 128 | { | ||
99 | m_listWidget->clear(); | 129 | Q_D(KGpgKeySelectionDlg); | ||
100 | m_listWidget->insertStringList(list); | 130 | d->m_listWidget->clear(); | ||
131 | d->m_listWidget->insertStringList(list); | ||||
101 | slotKeyListChanged(); | 132 | slotKeyListChanged(); | ||
102 | } | 133 | } | ||
103 | 134 | | |||
135 | QStringList KGpgKeySelectionDlg::keys() const | ||||
136 | { | ||||
137 | Q_D(const KGpgKeySelectionDlg); | ||||
138 | return d->m_listWidget->items(); | ||||
139 | } | ||||
140 | | ||||
104 | #if 0 | 141 | #if 0 | ||
105 | void KGpgKeySelectionDlg::slotShowHelp() | 142 | void KGpgKeySelectionDlg::slotShowHelp() | ||
106 | { | 143 | { | ||
Context not available. | |||||
114 | 151 | | |||
115 | void KGpgKeySelectionDlg::slotKeyListChanged() | 152 | void KGpgKeySelectionDlg::slotKeyListChanged() | ||
116 | { | 153 | { | ||
117 | m_needCheckList = true; | 154 | Q_D(KGpgKeySelectionDlg); | ||
155 | d->m_needCheckList = true; | ||||
118 | slotIdChanged(); | 156 | slotIdChanged(); | ||
119 | } | 157 | } | ||
120 | 158 | | |||
121 | void KGpgKeySelectionDlg::slotIdChanged() | 159 | void KGpgKeySelectionDlg::slotIdChanged() | ||
122 | { | 160 | { | ||
161 | Q_D(KGpgKeySelectionDlg); | ||||
123 | // this looks a bit awkward. Here's why: KGPGFile::keyAvailable() starts | 162 | // this looks a bit awkward. Here's why: KGPGFile::keyAvailable() starts | ||
124 | // an external task and processes UI events while it waits for the external | 163 | // an external task and processes UI events while it waits for the external | ||
125 | // process to finish. Thus, the first time we get here, the external process | 164 | // process to finish. Thus, the first time we get here, the external process | ||
Context not available. | |||||
129 | // The second invocation is counted, but the check is not started until the | 168 | // The second invocation is counted, but the check is not started until the | ||
130 | // first one finishes. Once the external process finishes, we check if we | 169 | // first one finishes. Once the external process finishes, we check if we | ||
131 | // were called in the meantime and restart the check. | 170 | // were called in the meantime and restart the check. | ||
132 | if (++m_checkCount == 1) { | 171 | if (++d->m_checkCount == 1) { | ||
133 | while (1) { | 172 | while (1) { | ||
134 | // first we check the current edit field if filled | 173 | // first we check the current edit field if filled | ||
135 | bool keysOk = true; | 174 | bool keysOk = true; | ||
136 | if (!m_listWidget->currentText().isEmpty()) { | 175 | if (!d->m_listWidget->currentText().isEmpty()) { | ||
137 | keysOk = KGPGFile::keyAvailable(m_listWidget->currentText()); | 176 | keysOk = KGPGFile::keyAvailable(d->m_listWidget->currentText()); | ||
138 | } | 177 | } | ||
139 | 178 | | |||
140 | // if it is available, then scan the current list if we need to | 179 | // if it is available, then scan the current list if we need to | ||
141 | if (keysOk) { | 180 | if (keysOk) { | ||
142 | if (m_needCheckList) { | 181 | if (d->m_needCheckList) { | ||
143 | QStringList keys = m_listWidget->items(); | 182 | QStringList keys = d->m_listWidget->items(); | ||
144 | QStringList::const_iterator it_s; | 183 | QStringList::const_iterator it_s; | ||
145 | for (it_s = keys.constBegin(); keysOk && it_s != keys.constEnd(); ++it_s) { | 184 | for (it_s = keys.constBegin(); keysOk && it_s != keys.constEnd(); ++it_s) { | ||
146 | if (!KGPGFile::keyAvailable(*it_s)) | 185 | if (!KGPGFile::keyAvailable(*it_s)) | ||
147 | keysOk = false; | 186 | keysOk = false; | ||
148 | } | 187 | } | ||
149 | m_listOk = keysOk; | 188 | d->m_listOk = keysOk; | ||
150 | m_needCheckList = false; | 189 | d->m_needCheckList = false; | ||
151 | 190 | | |||
152 | } else { | 191 | } else { | ||
153 | keysOk = m_listOk; | 192 | keysOk = d->m_listOk; | ||
154 | } | 193 | } | ||
155 | } | 194 | } | ||
156 | 195 | | |||
157 | // did we receive some more requests to check? | 196 | // did we receive some more requests to check? | ||
158 | if (m_checkCount > 1) { | 197 | if (d->m_checkCount > 1) { | ||
159 | m_checkCount = 1; | 198 | d->m_checkCount = 1; | ||
160 | continue; | 199 | continue; | ||
161 | } | 200 | } | ||
162 | 201 | | |||
163 | m_keyLed->setState(static_cast<KLed::State>(keysOk && (m_listWidget->items().count() != 0) ? KLed::On : KLed::Off)); | 202 | d->m_keyLed->setState(static_cast<KLed::State>(keysOk && (d->m_listWidget->items().count() != 0) ? KLed::On : KLed::Off)); | ||
164 | // TODO: port to kf5 | 203 | // TODO: port to kf5 | ||
165 | // okButton->setEnabled((m_listWidget->items().count() == 0) || (m_keyLed->state() == KLed::On)); | 204 | // okButton->setEnabled((m_listWidget->items().count() == 0) || (m_keyLed->state() == KLed::On)); | ||
166 | break; | 205 | break; | ||
167 | } | 206 | } | ||
168 | 207 | | |||
169 | --m_checkCount; | 208 | --d->m_checkCount; | ||
170 | } | 209 | } | ||
171 | } | 210 | } | ||
Context not available. |