28 #include <KMessageBox>
29 #include <KStandardDirs>
30 #include <KUrlRequester>
32 #include <QGridLayout>
33 #include <QHBoxLayout>
35 #include <QSpacerItem>
36 #include <QTextStream>
39 using namespace KgpgCore;
44 setCaption(i18n(
"KGpg Assistant"));
47 QGridLayout *gridLayout =
new QGridLayout(page);
48 gridLayout->setSpacing(6);
49 gridLayout->setMargin(11);
50 gridLayout->setContentsMargins(0, 0, 0, 0);
52 QLabel *label =
new QLabel(page);
53 QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
54 sizePolicy.setHorizontalStretch(0);
55 sizePolicy.setVerticalStretch(0);
56 sizePolicy.setHeightForWidth(label->sizePolicy().hasHeightForWidth());
57 label->setSizePolicy(sizePolicy);
58 label->setFrameShape(QFrame::NoFrame);
59 label->setFrameShadow(QFrame::Plain);
60 label->setScaledContents(
false);
61 label->setAlignment(Qt::AlignTop);
62 label->setWordWrap(
false);
64 gridLayout->addWidget(label, 0, 0, 3, 1);
66 label =
new QLabel(page);
67 label->setAlignment(Qt::AlignTop);
68 label->setWordWrap(
true);
69 label->setText(i18n(
"This assistant will first setup some basic configuration options required for KGpg to work properly. Next, it will allow you to create your own key pair, enabling you to encrypt your files and emails."));
71 gridLayout->addWidget(label, 0, 1, 1, 1);
73 QSpacerItem *spacerItem =
new QSpacerItem(20, 41, QSizePolicy::Minimum, QSizePolicy::Expanding);
75 gridLayout->addItem(spacerItem, 1, 1, 1, 1);
77 page_welcome = addPage(page, i18n(
"Welcome to the KGpg Assistant"));
81 gridLayout =
new QGridLayout(page);
82 gridLayout->setSpacing(6);
83 gridLayout->setMargin(11);
84 gridLayout->setContentsMargins(0, 0, 0, 0);
86 label =
new QLabel(page);
87 label->setAlignment(Qt::AlignTop);
88 label->setWordWrap(
true);
89 label->setText(i18n(
"KGpg needs to know which GnuPG binary to use."));
91 gridLayout->addWidget(label, 0, 1, 1, 1);
93 label =
new QLabel(page);
94 label->setAlignment(Qt::AlignTop);
95 label->setWordWrap(
true);
96 label->setText(i18n(
"Unless you want to try some unusual settings, just click on the \"next\" button."));
98 gridLayout->addWidget(label, 1, 1, 1, 1);
100 spacerItem =
new QSpacerItem(20, 60, QSizePolicy::Minimum, QSizePolicy::Expanding);
102 gridLayout->addItem(spacerItem, 4, 1, 1, 1);
104 txtGpgVersion =
new QLabel(page);
105 txtGpgVersion->setWordWrap(
true);
107 gridLayout->addWidget(txtGpgVersion, 3, 1, 1, 1);
109 binURL =
new KUrlRequester(page);
110 binURL->setFilter(i18nc(
"search filter for gpg binary",
"gpg|GnuPG binary\n*|All files"));
111 QString gpgBin = KStandardDirs::findExe(QLatin1String(
"gpg2"));
112 if (gpgBin.isEmpty())
113 gpgBin = KStandardDirs::findExe(QLatin1String(
"gpg"));
114 if (gpgBin.isEmpty())
115 gpgBin = QLatin1String(
"gpg");
116 binURL->setUrl(KUrl::fromPath(gpgBin));
118 connect(binURL, SIGNAL(textChanged(QString)), SLOT(slotBinaryChanged(QString)));
119 slotBinaryChanged(gpgBin);
121 gridLayout->addWidget(binURL, 2, 1, 1, 1);
123 page_binary = addPage(page, i18n(
"GnuPG Binary"));
127 gridLayout =
new QGridLayout(page);
128 gridLayout->setSpacing(6);
129 gridLayout->setMargin(11);
130 gridLayout->setContentsMargins(0, 0, 0, 0);
131 text_optionsfound =
new QLabel(page);
132 text_optionsfound->setAlignment(Qt::AlignTop);
133 text_optionsfound->setWordWrap(
true);
134 text_optionsfound->setText(i18n(
"Unless you want to try some unusual settings, just click on the \"next\" button."));
136 gridLayout->addWidget(text_optionsfound, 1, 1, 1, 1);
138 label =
new QLabel(page);
139 label->setAlignment(Qt::AlignTop);
140 label->setWordWrap(
true);
141 label->setText(i18n(
"KGpg needs to know where your GnuPG configuration file is stored."));
143 gridLayout->addWidget(label, 0, 1, 1, 1);
145 spacerItem =
new QSpacerItem(20, 60, QSizePolicy::Minimum, QSizePolicy::Expanding);
147 gridLayout->addItem(spacerItem, 4, 1, 1, 1);
149 pathURL =
new KUrlRequester(page);
151 gridLayout->addWidget(pathURL, 3, 1, 1, 1);
153 label =
new QLabel(page);
154 label->setAlignment(Qt::AlignVCenter);
155 label->setWordWrap(
true);
156 label->setText(i18n(
"Path to your GnuPG configuration file:"));
158 gridLayout->addWidget(label, 2, 1, 1, 1);
160 label =
new QLabel(page);
161 sizePolicy.setHeightForWidth(label->sizePolicy().hasHeightForWidth());
162 label->setSizePolicy(sizePolicy);
163 label->setFrameShape(QFrame::NoFrame);
164 label->setFrameShadow(QFrame::Plain);
165 label->setScaledContents(
false);
166 label->setAlignment(Qt::AlignTop);
167 label->setWordWrap(
false);
169 gridLayout->addWidget(label, 0, 0, 5, 1);
170 page_config = addPage(page, i18n(
"Configuration File"));
173 gridLayout =
new QGridLayout(page);
174 gridLayout->setSpacing(6);
175 gridLayout->setMargin(11);
176 gridLayout->setContentsMargins(0, 0, 0, 0);
178 QHBoxLayout *hboxLayout =
new QHBoxLayout();
179 hboxLayout->setSpacing(6);
180 label =
new QLabel(page);
181 label->setText(i18n(
"Your default key:"));
183 hboxLayout->addWidget(label);
185 CBdefault =
new KComboBox(page);
186 QSizePolicy sizePolicy1(QSizePolicy::Expanding, QSizePolicy::Fixed);
187 sizePolicy1.setHorizontalStretch(0);
188 sizePolicy1.setVerticalStretch(0);
189 sizePolicy1.setHeightForWidth(CBdefault->sizePolicy().hasHeightForWidth());
190 CBdefault->setSizePolicy(sizePolicy1);
192 hboxLayout->addWidget(CBdefault);
194 gridLayout->addLayout(hboxLayout, 0, 1, 1, 1);
196 spacerItem =
new QSpacerItem(20, 30, QSizePolicy::Minimum, QSizePolicy::Expanding);
198 gridLayout->addItem(spacerItem, 1, 1, 1, 1);
200 page_defaultkey = addPage(page, i18n(
"Default Key"));
204 gridLayout =
new QGridLayout(page);
205 gridLayout->setSpacing(6);
206 gridLayout->setMargin(11);
207 gridLayout->setContentsMargins(0, 0, 0, 0);
209 binlabel =
new QLabel(page);
211 gridLayout->addWidget(binlabel, 0, 1, 1, 1);
213 versionLabel =
new QLabel(page);
215 gridLayout->addWidget(versionLabel, 1, 1, 1, 1);
217 defaultkeylabel =
new QLabel(page);
219 gridLayout->addWidget(defaultkeylabel, 2, 1, 1, 1);
221 generateCB =
new QCheckBox(page);
222 generateCB->setText(i18n(
"Generate new key"));
224 gridLayout->addWidget(generateCB, 3, 1, 1, 1);
226 spacerItem =
new QSpacerItem(20, 30, QSizePolicy::Minimum, QSizePolicy::Expanding);
228 gridLayout->addItem(spacerItem, 4, 1, 1, 1);
230 autostartCB =
new QCheckBox(page);
231 autostartCB->setChecked(
true);
232 autostartCB->setText(i18n(
"Start KGpg automatically at KDE startup."));
234 gridLayout->addWidget(autostartCB, 5, 1, 1, 1);
236 page_done = addPage(page, i18n(
"Done"));
240 KGpgFirstAssistant::findConfigPath()
243 QString confPath = gpgHome + QLatin1String(
"gpg.conf" );
245 if (!QFile(confPath).exists()) {
246 confPath = gpgHome + QLatin1String(
"options" );
247 if (!QFile(confPath).exists()) {
248 if (KMessageBox::questionYesNo(0, i18n(
"<qt><b>The GnuPG configuration file was not found</b>. Should KGpg try to create a config file ?</qt>"), QString(), KGuiItem(i18n(
"Create Config")), KGuiItem(i18n(
"Do Not Create"))) == KMessageBox::Yes) {
249 confPath = gpgHome + QLatin1String(
"gpg.conf" );
250 QFile file(confPath);
251 if (file.open(QIODevice::WriteOnly)) {
252 QTextStream stream(&file);
253 stream <<
"# GnuPG config file created by KGpg" <<
"\n";
257 text_optionsfound->setText(i18n(
"<qt><b>The GnuPG configuration file was not found</b>.</qt>"));
263 pathURL->setUrl(confPath);
266 if (secids.isEmpty()) {
267 setAppropriate(page_defaultkey,
false);
268 generateCB->setChecked(
true);
269 defaultkeylabel->setVisible(
false);
275 generateCB->setChecked(
false);
276 setAppropriate(page_defaultkey,
true);
280 foreach (
const KgpgKey &k, publiclist) {
283 if (k.
email().isEmpty())
284 s = i18nc(
"Name: ID",
"%1: %2", k.
name(), k.
id());
286 s = i18nc(
"Name (Email): ID",
"%1 (%2): %3", k.
name(), k.
email(), k.
id());
291 CBdefault->setCurrentIndex(0);
297 if (currentPage() == page_binary) {
298 binlabel->setText(i18n(
"Your GnuPG binary is: %1", binURL->url().path()));
300 }
else if (currentPage() == page_config) {
302 m_confPath = pathURL->url().path();
306 if (!defaultID.isEmpty()) {
307 for (
int i = 0; i < CBdefault->count(); i++) {
308 if (defaultID == CBdefault->itemData(i).toString().right(defaultID.length())) {
309 CBdefault->setCurrentIndex(i);
314 versionLabel->setText(i18n(
"You have GnuPG version: %1", m_gpgVersion));
315 }
else if (currentPage() == page_defaultkey) {
316 defaultkeylabel->setVisible(
true);
317 defaultkeylabel->setText(i18n(
"Your default key is: %1", CBdefault->currentText()));
318 int i = CBdefault->currentIndex();
320 defaultkeylabel->setToolTip(CBdefault->itemData(i).toString());
323 KAssistantDialog::next();
329 return generateCB->isChecked();
341 int i = CBdefault->currentIndex();
345 return CBdefault->itemData(i).toString();
351 return autostartCB->isChecked();
355 KGpgFirstAssistant::slotBinaryChanged(
const QString &binary)
357 if (binary.isEmpty()) {
358 setValid(page_binary,
false);
363 setValid(page_binary, !m_gpgVersion.isEmpty());
364 if (!m_gpgVersion.isEmpty()) {
367 if (gpgver < 0x10400) {
368 txtGpgVersion->setText(i18n(
"Your GnuPG version (%1) seems to be too old.<br />Compatibility with versions before 1.4.0 is no longer guaranteed.", m_gpgVersion));
370 txtGpgVersion->setText(i18n(
"You have GnuPG version: %1", m_gpgVersion));
375 #include "kgpgfirstassistant.moc"
bool getAutoStart() const
check if KGpg autostart should be activated
static QString getGpgHome(const QString &binary)
find users GnuPG directory
QString getDefaultKey() const
get fingerprint of default key
const QString & fingerprint() const
KgpgCore::KgpgKeyList readPublicKeys(const QStringList &ids=QStringList())
static int gpgVersion(const QString &vstr)
parse GnuPG version string and return version as number
QString getConfigPath() const
get user selected GnuPG home directory
bool runKeyGenerate() const
check if key generation dialog should be started
KgpgCore::KgpgKeyList readSecretKeys(const QStringList &ids=QStringList())
virtual void next()
called when "next" button is pressed
static QString gpgVersionString(const QString &binary)
get the GnuPG version string of the given binary
KGpgFirstAssistant(QWidget *parent=0)
constructor of KGpgFirstAssistant
QString getGpgSetting(const QString &name, const QString &configfile)