File indexing completed on 2022-08-04 16:24:17

0001 /*
0002     SPDX-FileCopyrightText: 2002 Jean-Baptiste Mardelle <bj@altern.org>
0003     SPDX-FileCopyrightText: 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Rolf Eike Beer <kde@opensource.sf-tec.de>
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "kgpgoptions.h"
0008 
0009 #include "kgpg_general_debug.h"
0010 #include "kgpgsettings.h"
0011 #include "kgpginterface.h"
0012 #include "conf_encryption.h"
0013 #include "core/images.h"
0014 #include "model/gpgservermodel.h"
0015 #include "model/keylistproxymodel.h"
0016 #include "model/kgpgitemmodel.h"
0017 
0018 #include <kwidgetsaddons_version.h>
0019 #include <KConfig>
0020 #include <KConfigGroup>
0021 #include <KDesktopFile>
0022 #include <KFontChooser>
0023 #include <KLocalizedString>
0024 #include <KMessageBox>
0025 #include <KProcess>
0026 #include <QUrl>
0027 
0028 #include <QCheckBox>
0029 
0030 #include <QFile>
0031 #include <QFileDialog>
0032 #include <QInputDialog>
0033 #include <QTextStream>
0034 #include <QVBoxLayout>
0035 #include <QRegularExpression>
0036 #include <QStandardPaths>
0037 
0038 using namespace KgpgCore;
0039 
0040 //   main window
0041 kgpgOptions::kgpgOptions(QWidget *parent, KGpgItemModel *model)
0042            : KConfigDialog(parent, QLatin1String( "settings" ), KGpgSettings::self()),
0043        m_config(new KConfig( QLatin1String( "kgpgrc" ), KConfig::SimpleConfig)),
0044        m_page1(new Encryption()),
0045        m_page2(new Decryption()),
0046        m_page3(new UIConf()),
0047        m_page4(new GPGConf()),
0048        m_page6(new ServerConf()),
0049        m_page7(new MiscConf()),
0050        m_serverModel(new GpgServerModel(m_page6)),
0051        m_fontchooser(new KFontChooser(KFontChooser::NoDisplayFlags, m_page3->tabWidget3->widget(1))),
0052        m_model(model),
0053        m_combomodel(new KeyListProxyModel(this, KeyListProxyModel::SingleColumnIdFirst))
0054 {
0055     m_page7->EmailTemplateEdit->setPlainText(KGpgSettings::emailTemplate());
0056 
0057     m_combomodel->setKeyModel(m_model);
0058     m_combomodel->setTrustFilter(KgpgCore::TRUST_MARGINAL);
0059     m_combomodel->setEncryptionKeyFilter(true);
0060     m_combomodel->sort(0);
0061 
0062     // Initialize the default server and the default server list.
0063     defaultKeyServer = QLatin1String("hkp://keyserver.ubuntu.com");
0064     defaultServerList << defaultKeyServer
0065             << QLatin1String("hkp://keys.openpgp.org")
0066             << QLatin1String("hkp://subkeys.pgp.net")
0067             << QLatin1String("hkp://wwwkeys.pgp.net");
0068 
0069     // Read the default keyserver from the GnuPG settings.
0070     keyServer = KgpgInterface::getGpgSetting(QLatin1String( "keyserver" ), KGpgSettings::gpgConfigPath());
0071 
0072     // Read the servers stored in kgpgrc
0073     serverList = KGpgSettings::keyServers();
0074 
0075     // Remove everything after a whitespace. This will normally be
0076     // ' (Default)' from KDE 3.x.x
0077     serverList.replaceInStrings(QRegularExpression(QStringLiteral(" .*")), QString());
0078 
0079     m_serverModel->setStringList(serverList);
0080     // if the server from GnuPG config is set and is not in the list of servers put it there
0081     if (!keyServer.isEmpty() && !serverList.contains(keyServer))
0082         serverList.prepend(keyServer);
0083     m_page6->ServerBox->setModel(m_serverModel);
0084 
0085     defaultConfigPath = QUrl::fromLocalFile(gpgConfigPath).fileName();
0086     defaultHomePath = QUrl::fromLocalFile(gpgConfigPath).adjusted(QUrl::RemoveFilename).path();
0087     defaultBinPath = KGpgSettings::gpgBinaryPath();
0088 
0089     m_showsystray = KGpgSettings::showSystray();
0090     m_trayaction = KGpgSettings::leftClick();
0091     m_mailUats = KGpgSettings::mailUats();
0092 
0093     QVBoxLayout *fontlayout = new QVBoxLayout(m_page3->tabWidget3->widget(1));
0094 
0095     m_fontchooser->setObjectName( QLatin1String("kcfg_Font" ));
0096     fontlayout->addWidget(m_fontchooser);
0097 
0098     m_page3->kcfg_EmailSorting->addItem(i18n("Left to right, account first")); ///< KGpgSettings::EnumEmailSorting::Alphabetical
0099     m_page3->kcfg_EmailSorting->addItem(i18n("Right to left, TLD first")); ///< KGpgSettings::EnumEmailSorting::TLDfirst
0100     m_page3->kcfg_EmailSorting->addItem(i18n("Right to left, domain first")); ///< KGpgSettings::EnumEmailSorting::DomainFirst
0101     m_page3->kcfg_EmailSorting->addItem(i18n("Right to left, FQDN first")); ///< KGpgSettings::EnumEmailSorting::FQDNFirst
0102     m_emailSortingIndex = KGpgSettings::emailSorting();
0103 
0104     addPage(m_page1, i18n("Encryption"), QLatin1String( "document-encrypt" ));
0105     addPage(m_page2, i18n("Decryption"), QLatin1String( "document-decrypt") );
0106     addPage(m_page3, i18n("Appearance"), QLatin1String( "preferences-desktop-theme" ));
0107     addPage(m_page4, i18n("GnuPG Settings"), QLatin1String( "kgpg" ));
0108     addPage(m_page6, i18n("Key Servers"), QLatin1String( "network-wired" ));
0109     addPage(m_page7, i18n("Misc"), QLatin1String( "preferences-other" ));
0110 
0111     // The following widgets are managed manually.
0112     connect(m_page1->encrypt_to_always, &QCheckBox::toggled, this, &kgpgOptions::slotChangeEncryptTo);
0113     connect(m_page4->changeHome, &QPushButton::clicked, this, &kgpgOptions::slotChangeHome);
0114     connect(m_page6->server_add, &QPushButton::clicked, this, &kgpgOptions::slotAddKeyServer);
0115     connect(m_page6->server_del, &QPushButton::clicked, this, &kgpgOptions::slotDelKeyServer);
0116     connect(m_page6->server_edit, &QPushButton::clicked, this, QOverload<>::of(&kgpgOptions::slotEditKeyServer));
0117     connect(m_page6->server_default, &QPushButton::clicked, this, &kgpgOptions::slotDefaultKeyServer);
0118     connect(m_page6->ServerBox->selectionModel(), &QItemSelectionModel::selectionChanged, this, &kgpgOptions::slotChangeKeyServerButtonEnable);
0119     connect(m_page6->ServerBox, &QListView::doubleClicked, this, QOverload<const QModelIndex &>::of(&kgpgOptions::slotEditKeyServer));
0120     connect(m_page7->kcfg_ShowSystray, &QPushButton::clicked, this, &kgpgOptions::slotSystrayEnable);
0121 
0122     keyUltimate = KGpgSettings::colorUltimate();
0123     keyGood = KGpgSettings::colorGood();
0124     keyMarginal = KGpgSettings::colorMarginal();
0125     keyExpired = KGpgSettings::colorExpired();
0126     keyUnknown = KGpgSettings::colorUnknown();
0127     keyRev = KGpgSettings::colorRev();
0128     keyBad = KGpgSettings::colorBad();
0129 }
0130 
0131 kgpgOptions::~kgpgOptions()
0132 {
0133     delete m_config;
0134     delete m_page1;
0135     delete m_page2;
0136     delete m_page3;
0137     delete m_page4;
0138     delete m_page6;
0139     delete m_page7;
0140 }
0141 
0142 void kgpgOptions::slotChangeHome()
0143 {
0144     QString gpgHome = QFileDialog::getExistingDirectory(this, i18n("New GnuPG Home Location"), m_page4->gpg_home_path->text());
0145     if (gpgHome.isEmpty())
0146         return;
0147 
0148     if (!gpgHome.endsWith(QLatin1Char( '/' )))
0149         gpgHome.append(QLatin1Char( '/' ));
0150 
0151     QString confPath = QLatin1String( "options" );
0152     if (!QFile(gpgHome + confPath).exists()) {
0153         confPath = QLatin1String( "gpg.conf" );
0154         if (!QFile(gpgHome + confPath).exists()) {
0155             // Try to create config File by running gpg once
0156             if (KMessageBox::Yes == KMessageBox::questionYesNo(this,
0157                     i18n("No configuration file was found in the selected location.\nDo you want to create it now?\n\nWithout a configuration file, neither KGpg nor GnuPG will work properly."),
0158                     i18n("No Configuration File Found"),
0159                     KGuiItem(i18n("Create")),
0160                     KGuiItem(i18n("Ignore")))) {
0161                 // start GnuPG so that it will create a config file
0162                 QString gpgbin = m_page4->kcfg_GpgBinaryPath->text();
0163                 if (!QFile::exists(gpgbin))
0164                     gpgbin = QLatin1String( "gpg" );
0165 
0166                 KProcess p;
0167                 p << gpgbin << QLatin1String( "--homedir" ) << gpgHome << QLatin1String( "--no-tty" ) << QLatin1String( "--list-secret-keys" );
0168                 p.execute();
0169                 // end of creating config file
0170 
0171                 confPath = QLatin1String( "gpg.conf" );
0172                 QFile confFile(gpgHome + confPath);
0173                 if (!confFile.open(QIODevice::WriteOnly)) {
0174                     KMessageBox::error(this, i18n("Cannot create configuration file. Please check if destination media is mounted and if you have write access."));
0175                     return;
0176                 } else {
0177                     QTextStream stream(&confFile);
0178                     stream << "#  Config file created by KGpg\n\n";
0179                     confFile.close();
0180                 }
0181             } else {
0182                 confPath.clear();
0183             }
0184         }
0185     }
0186 
0187     m_page4->gpg_conf_path->setText(confPath);
0188     m_page4->gpg_home_path->setText(gpgHome);
0189 }
0190 
0191 bool kgpgOptions::isValidKeyserver(const QString &server)
0192 {
0193     if (server.isEmpty())
0194         return false;
0195 
0196     if (server.contains(QLatin1Char( ' ' ))) {
0197         KMessageBox::error(this, i18n("Key server URLs may not contain whitespace."));
0198         return false;
0199     }
0200 
0201     if (serverList.contains(server)) {
0202         KMessageBox::error(this, i18n("Key server already in the list."));
0203         return false;
0204     }
0205 
0206     return true;
0207 }
0208 
0209 void kgpgOptions::slotAddKeyServer()
0210 {
0211     const QString newServer(QInputDialog::getText(this, i18n("Add New Key Server"), i18n("Server URL:")));
0212 
0213     if (!isValidKeyserver(newServer))
0214         return;
0215 
0216     m_serverModel->setStringList(m_serverModel->stringList() << newServer);
0217     settingsChangedSlot();
0218 }
0219 
0220 void kgpgOptions::slotChangeEncryptTo()
0221 {
0222     settingsChangedSlot();
0223 }
0224 
0225 void kgpgOptions::slotDelKeyServer()
0226 {
0227     QModelIndex cur = m_page6->ServerBox->selectionModel()->currentIndex();
0228     m_serverModel->removeRows(cur.row(), 1);
0229 
0230     settingsChangedSlot();
0231 }
0232 
0233 void kgpgOptions::slotEditKeyServer()
0234 {
0235     slotEditKeyServer(m_page6->ServerBox->selectionModel()->currentIndex());
0236 }
0237 
0238 void kgpgOptions::slotEditKeyServer(const QModelIndex &index)
0239 {
0240     if (!index.isValid())
0241         return;
0242 
0243     m_page6->ServerBox->edit(index);
0244 
0245     settingsChangedSlot();
0246 }
0247 
0248 void kgpgOptions::slotDefaultKeyServer()
0249 {
0250     QModelIndex cur = m_page6->ServerBox->selectionModel()->currentIndex();
0251 
0252     m_serverModel->setDefault(cur.row());
0253 
0254     settingsChangedSlot();
0255 }
0256 
0257 void kgpgOptions::slotChangeKeyServerButtonEnable()
0258 {
0259     QModelIndex cur = m_page6->ServerBox->selectionModel()->currentIndex();
0260 
0261     m_page6->server_del->setEnabled(cur.isValid());
0262     m_page6->server_edit->setEnabled(cur.isValid());
0263     m_page6->server_default->setEnabled(cur.isValid() &&
0264             (cur.row() != m_serverModel->defaultRow()));
0265 }
0266 
0267 void kgpgOptions::updateWidgets()
0268 {
0269     alwaysKeyID = KgpgInterface::getGpgSetting(QLatin1String( "encrypt-to" ), KGpgSettings::gpgConfigPath());
0270 
0271     m_page7->EmailTemplateEdit->setPlainText(KGpgSettings::emailTemplate());
0272 
0273     m_encrypttoalways = !alwaysKeyID.isEmpty();
0274     m_defaultencrypttoalways = false;
0275 
0276     m_page1->encrypt_to_always->setChecked(m_encrypttoalways);
0277 
0278     listKeys();
0279     fileEncryptionKey = KGpgSettings::fileEncryptionKey();
0280     // the contents are totally mess. There were key id, name and email stored
0281     // try to extract the key id, that's the only thing we really need
0282     if (!fileEncryptionKey.isEmpty()) {
0283         int idpos = m_page1->file_key->findText(fileEncryptionKey);
0284         if (idpos == -1) {
0285             idpos = fileEncryptionKey.indexOf(QRegularExpression(QStringLiteral("([0-9A-Fa-f]{8})+")));
0286             if (idpos >= 0) {
0287                 QString fileId = fileEncryptionKey.mid(idpos);
0288                 idpos = fileId.indexOf(QRegularExpression(QStringLiteral("[^a-fA-F0-9]")));
0289                 if (idpos >= 0) {
0290                     fileId.truncate(idpos);
0291                     fileId.chop(fileId.length() % 8);
0292                 }
0293 
0294                 KGpgKeyNode *anode = m_combomodel->getModel()->findKeyNode(fileId);
0295 
0296                 if (anode != nullptr)
0297                     idpos = m_combomodel->nodeIndex(anode).row();
0298             }
0299         }
0300         m_page1->file_key->setCurrentIndex(idpos);
0301     }
0302 
0303     if (!alwaysKeyID.isEmpty()) {
0304         KGpgKeyNode *anode = m_combomodel->getModel()->findKeyNode(alwaysKeyID);
0305         if (anode != nullptr) {
0306             const QModelIndex midx(m_combomodel->nodeIndex(anode));
0307             m_page1->always_key->setCurrentIndex(midx.row());
0308         }
0309     }
0310 
0311     gpgConfigPath = KGpgSettings::gpgConfigPath();
0312     m_page4->gpg_conf_path->setText(QUrl::fromLocalFile(gpgConfigPath).fileName());
0313     m_page4->gpg_home_path->setText(QUrl::fromLocalFile(gpgConfigPath).adjusted(QUrl::RemoveFilename).path());
0314 
0315     m_useagent = KgpgInterface::getGpgBoolSetting(QLatin1String( "use-agent" ), KGpgSettings::gpgConfigPath());
0316     m_defaultuseagent = false;
0317 
0318     m_page4->use_agent->setChecked(m_useagent);
0319 
0320     m_emailSortingIndex = KGpgSettings::emailSorting();
0321     m_page3->kcfg_EmailSorting->setCurrentIndex(m_emailSortingIndex);
0322 
0323     m_serverModel->setStringList(serverList);
0324     if (!serverList.isEmpty())
0325         m_serverModel->setDefault(keyServer);
0326 
0327     qCDebug(KGPG_LOG_GENERAL) << "Finishing options";
0328 }
0329 
0330 void kgpgOptions::updateWidgetsDefault()
0331 {
0332     m_page7->EmailTemplateEdit->setPlainText(m_emailTemplate);
0333 
0334     m_page1->encrypt_to_always->setChecked(m_defaultencrypttoalways);
0335     m_page4->use_agent->setChecked(m_defaultuseagent);
0336 
0337     m_page4->gpg_conf_path->setText(defaultConfigPath);
0338     m_page4->gpg_home_path->setText(defaultHomePath);
0339 
0340     m_serverModel->setStringList(defaultServerList);
0341     m_serverModel->setDefault(0);
0342 
0343     m_page3->kcfg_EmailSorting->setCurrentIndex(KGpgSettings::EnumEmailSorting::Alphabetical);
0344 
0345     qCDebug(KGPG_LOG_GENERAL) << "Finishing default options" ;
0346 }
0347 
0348 void kgpgOptions::updateSettings()
0349 {
0350     // Update config path first!
0351     const QString newConfigFile = m_page4->gpg_home_path->text() + m_page4->gpg_conf_path->text();
0352     if (newConfigFile != gpgConfigPath) {
0353         KGpgSettings::setGpgConfigPath(newConfigFile);
0354         Q_EMIT homeChanged();
0355 
0356         gpgConfigPath = newConfigFile;
0357     }
0358 
0359     // save selected keys for file encryption & always encrypt with
0360     if (m_page1->kcfg_EncryptFilesTo->isChecked())
0361         fileEncryptionKey = m_page1->file_key->itemData(m_page1->file_key->currentIndex(), Qt::ToolTipRole).toString();
0362     else
0363         fileEncryptionKey.clear();
0364 
0365     if (fileEncryptionKey != KGpgSettings::fileEncryptionKey())
0366         KGpgSettings::setFileEncryptionKey(fileEncryptionKey);
0367 
0368     m_encrypttoalways = m_page1->encrypt_to_always->isChecked();
0369 
0370     if (m_encrypttoalways)
0371         alwaysKeyID = m_page1->always_key->itemData(m_page1->always_key->currentIndex(), Qt::ToolTipRole).toString();
0372     else
0373         alwaysKeyID.clear();
0374 
0375     KgpgInterface::setGpgSetting(QLatin1String( "encrypt-to" ), alwaysKeyID, KGpgSettings::gpgConfigPath());
0376 
0377     Q_EMIT changeFont(m_fontchooser->font());
0378 
0379     // install service menus
0380     if (m_page7->kcfg_SignMenu->currentIndex() == KGpgSettings::EnumSignMenu::AllFiles)
0381         slotInstallSign(QLatin1String( "application/octet-stream" ));
0382     else
0383         slotRemoveMenu(QLatin1String( "signfile.desktop" ));
0384 
0385     if (m_page7->kcfg_DecryptMenu->currentIndex() == KGpgSettings::EnumDecryptMenu::AllFiles)
0386         slotInstallDecrypt(QLatin1String( "application/octet-stream" ));
0387     else
0388     if (m_page7->kcfg_DecryptMenu->currentIndex() == KGpgSettings::EnumDecryptMenu::EncryptedFiles)
0389         slotInstallDecrypt(QLatin1String( "application/pgp-encrypted,application/pgp-signature,application/pgp-keys" ));
0390     else
0391         slotRemoveMenu(QLatin1String( "decryptfile.desktop" ));
0392 
0393     m_useagent = m_page4->use_agent->isChecked();
0394 
0395     if (m_useagent) {
0396         KgpgInterface::setGpgBoolSetting(QLatin1String( "use-agent" ), true, KGpgSettings::gpgConfigPath());
0397         KgpgInterface::setGpgBoolSetting(QLatin1String( "no-use-agent" ), false, KGpgSettings::gpgConfigPath());
0398     } else {
0399         KgpgInterface::setGpgBoolSetting(QLatin1String( "use-agent" ), false, KGpgSettings::gpgConfigPath());
0400     }
0401 
0402     // Store the default server in ~/.gnupg
0403     KgpgInterface::setGpgSetting(QLatin1String("keyserver"), m_serverModel->defaultServer(), KGpgSettings::gpgConfigPath());
0404 
0405     // Store additional servers in kgpgrc.
0406     serverList = m_serverModel->stringList();
0407     int defaultRow = m_serverModel->defaultRow();
0408     if (!serverList.isEmpty())
0409         serverList.move(defaultRow, 0);
0410 
0411     KGpgSettings::setKeyServers(serverList);
0412 
0413     if (keyUltimate != m_page3->kcfg_ColorUltimate->color())
0414         Q_EMIT refreshTrust(TRUST_ULTIMATE, m_page3->kcfg_ColorUltimate->color());
0415 
0416     if (keyGood != m_page3->kcfg_ColorGood->color())
0417         Q_EMIT refreshTrust(TRUST_FULL, m_page3->kcfg_ColorGood->color());
0418 
0419     if (keyExpired != m_page3->kcfg_ColorExpired->color())
0420         Q_EMIT refreshTrust(TRUST_EXPIRED, m_page3->kcfg_ColorExpired->color());
0421 
0422     if (keyMarginal != m_page3->kcfg_ColorMarginal->color())
0423         Q_EMIT refreshTrust(TRUST_MARGINAL, m_page3->kcfg_ColorMarginal->color());
0424 
0425     if (keyBad != m_page3->kcfg_ColorBad->color()) {
0426         Q_EMIT refreshTrust(TRUST_INVALID, m_page3->kcfg_ColorBad->color());
0427         Q_EMIT refreshTrust(TRUST_DISABLED, m_page3->kcfg_ColorBad->color());
0428     }
0429 
0430     if (keyUnknown != m_page3->kcfg_ColorUnknown->color()) {
0431         Q_EMIT refreshTrust(TRUST_UNDEFINED, m_page3->kcfg_ColorUnknown->color());
0432         Q_EMIT refreshTrust(TRUST_NONE, m_page3->kcfg_ColorUnknown->color());
0433         Q_EMIT refreshTrust(TRUST_UNKNOWN, m_page3->kcfg_ColorUnknown->color());
0434     }
0435 
0436     if (keyRev != m_page3->kcfg_ColorRev->color())
0437         Q_EMIT refreshTrust(TRUST_REVOKED, m_page3->kcfg_ColorRev->color());
0438 
0439     m_showsystray = m_page7->kcfg_ShowSystray->isChecked();
0440     KGpgSettings::setShowSystray(m_showsystray);
0441 
0442     m_trayaction = m_page7->kcfg_LeftClick->currentIndex();
0443     KGpgSettings::setLeftClick(m_trayaction);
0444 
0445     m_mailUats = m_page7->kcfg_MailUats->currentIndex();
0446     KGpgSettings::setMailUats(m_mailUats);
0447 
0448     m_emailTemplate = m_page7->EmailTemplateEdit->toPlainText();
0449     KGpgSettings::setEmailTemplate(m_emailTemplate);
0450 
0451     m_emailSortingIndex = m_page3->kcfg_EmailSorting->currentIndex();
0452     KGpgSettings::setEmailSorting(m_emailSortingIndex);
0453 
0454     KGpgSettings::self()->save();
0455     m_config->sync();
0456 
0457     Q_EMIT settingsUpdated();
0458 }
0459 
0460 void kgpgOptions::listKeys()
0461 {
0462     if (m_model->rowCount(QModelIndex()) == 0) {
0463         ids += QLatin1String("0");
0464         m_page1->file_key->addItem(i18nc("no key available", "none"));
0465         m_page1->file_key->setModel(nullptr);
0466         m_page1->always_key->addItem(i18nc("no key available", "none"));
0467         m_page1->always_key->setModel(nullptr);
0468     } else {
0469         m_page1->file_key->setModel(m_combomodel);
0470         m_page1->always_key->setModel(m_combomodel);
0471     }
0472 }
0473 
0474 void kgpgOptions::slotInstallDecrypt(const QString &mimetype)
0475 {
0476     const QString path(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/konqueror/servicemenus/decryptfile.desktop" ));
0477     KDesktopFile configl2(path);
0478     if (!configl2.isImmutable()) {
0479         KConfigGroup gr(configl2.group("Desktop Entry"));
0480 
0481         gr.writeXdgListEntry("MimeType", QStringList(mimetype));
0482         gr.writeEntry("X-KDE-ServiceTypes", "KonqPopupMenu/Plugin");
0483         gr.writeEntry("Actions", "decrypt");
0484 
0485         gr = configl2.group("Desktop Action decrypt");
0486         gr.writeEntry("Name", i18n("Decrypt File"));
0487         //gr.writeEntry("Icon", "decrypt_file");
0488         gr.writeEntry("Exec", "kgpg %U");
0489     }
0490 }
0491 
0492 void kgpgOptions::slotInstallSign(const QString &mimetype)
0493 {
0494     QString path(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kde5/services/") + QLatin1String( "ServiceMenus/signfile.desktop" ));
0495     KDesktopFile configl2(path);
0496     if (!configl2.isImmutable()) {
0497         KConfigGroup gr = configl2.group("Desktop Entry");
0498         gr.writeXdgListEntry("MimeType", QStringList(mimetype));
0499         gr.writeEntry("X-KDE-ServiceTypes", "KonqPopupMenu/Plugin");
0500         gr.writeEntry("Actions", "sign");
0501 
0502         gr = configl2.group("Desktop Action sign");
0503         gr.writeEntry("Name", i18n("Sign File"));
0504         //gr.writeEntry("Icon", "sign_file");
0505         gr.writeEntry("Exec","kgpg -S %F");
0506     }
0507 }
0508 
0509 void kgpgOptions::slotRemoveMenu(const QString &menu)
0510 {
0511     QString path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kde5/services/") + QLatin1String( "ServiceMenus/" ) + menu;
0512     QFile qfile(path);
0513     if (qfile.exists())
0514         qfile.remove();
0515 }
0516 
0517 bool kgpgOptions::hasChanged()
0518 {
0519     if (m_page1->kcfg_EncryptFilesTo->isChecked() && (m_page1->file_key->currentText() != fileEncryptionKey))
0520         return true;
0521 
0522     if (m_page1->encrypt_to_always->isChecked() != m_encrypttoalways)
0523         return true;
0524 
0525     if (m_page1->encrypt_to_always->isChecked() &&
0526             (m_page1->always_key->itemData(m_page1->always_key->currentIndex(), Qt::ToolTipRole).toString()) != alwaysKeyID)
0527         return true;
0528 
0529     if (m_page4->gpg_conf_path->text() != QUrl::fromLocalFile(gpgConfigPath).fileName())
0530         return true;
0531 
0532     if (m_page4->gpg_home_path->text() != QUrl::fromLocalFile(gpgConfigPath).adjusted(QUrl::RemoveFilename).path())
0533         return true;
0534 
0535     if (m_page4->use_agent->isChecked() != m_useagent)
0536         return true;
0537 
0538     // Did the default server change
0539     if (m_serverModel->defaultServer() != keyServer)
0540         return true;
0541 
0542     // Did the servers change?
0543     if (m_serverModel->stringList() != serverList)
0544         return true;
0545 
0546     if (m_page7->kcfg_ShowSystray->isChecked() != m_showsystray)
0547         return true;
0548 
0549     if (m_page7->kcfg_LeftClick->currentIndex() != m_trayaction)
0550         return true;
0551 
0552     if (m_page7->kcfg_MailUats->currentIndex() != m_mailUats)
0553         return true;
0554 
0555     if (m_page3->kcfg_EmailSorting->currentIndex() != m_emailSortingIndex)
0556         return true;
0557 
0558     return false;
0559 }
0560 
0561 bool kgpgOptions::isDefault()
0562 {
0563     if (m_page1->encrypt_to_always->isChecked() != m_defaultencrypttoalways)
0564         return false;
0565 
0566     if (m_page4->gpg_conf_path->text() != defaultConfigPath)
0567         return false;
0568 
0569     if (m_page4->gpg_home_path->text() != defaultHomePath)
0570         return false;
0571 
0572     if (m_page4->use_agent->isChecked() != m_defaultuseagent)
0573         return false;
0574 
0575     if (m_serverModel->defaultServer() != defaultKeyServer)
0576         return false;
0577 
0578     if (m_serverModel->stringList() != defaultServerList)
0579         return false;
0580 
0581     if (m_page7->kcfg_ShowSystray->isChecked() != m_showsystray)
0582         return false;
0583 
0584     if (m_page7->kcfg_LeftClick->currentIndex() != KGpgSettings::EnumLeftClick::KeyManager)
0585         return false;
0586 
0587     if (m_page7->kcfg_MailUats->currentIndex() != KGpgSettings::EnumMailUats::All)
0588         return false;
0589 
0590     if (m_page3->kcfg_EmailSorting->currentIndex() != KGpgSettings::EnumEmailSorting::Alphabetical)
0591         return false;
0592 
0593     return true;
0594 }
0595 
0596 void kgpgOptions::slotSystrayEnable()
0597 {
0598     m_page7->kcfg_LeftClick->setEnabled(m_page7->kcfg_ShowSystray->isChecked());
0599 }