aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/settings/SettingsKeyServer.cpp
blob: ade33a46dd54fb5b2ef599988c3dcdd008b6d39d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
 * This file is part of GPGFrontend.
 *
 * GPGFrontend is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Foobar is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Foobar.  If not, see <https://www.gnu.org/licenses/>.
 *
 * The initial version of the source code is inherited from gpg4usb-team.
 * Their source code version also complies with GNU General Public License.
 *
 * The source code version of this software was modified and released
 * by Saturneric<[email protected]> starting on May 12, 2021.
 *
 */

#include "ui/SettingsDialog.h"

KeyserverTab::KeyserverTab(QWidget *parent)
: QWidget(parent), appPath(qApp->applicationDirPath()),
settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
         QSettings::IniFormat) {

    auto keyServerList = settings.value("keyserver/keyServerList").toStringList();

    auto *mainLayout = new QVBoxLayout(this);

    auto *label = new QLabel(tr("Default Key Server for import:"));
    comboBox = new QComboBox;
    comboBox->setEditable(false);
    comboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);

    for (const auto &keyServer : keyServerList) {
        comboBox->addItem(keyServer);
        qDebug() << "KeyserverTab Get ListItemText" << keyServer;
    }

    comboBox->setCurrentText(
            settings.value("keyserver/defaultKeyServer").toString());

    auto *addKeyServerBox = new QWidget(this);
    auto *addKeyServerLayout = new QHBoxLayout(addKeyServerBox);
    auto *http = new QLabel("URL: ");
    newKeyServerEdit = new QLineEdit(this);
    auto *newKeyServerButton = new QPushButton(tr("Add"), this);
    connect(newKeyServerButton, SIGNAL(clicked()), this, SLOT(addKeyServer()));
    addKeyServerLayout->addWidget(http);
    addKeyServerLayout->addWidget(newKeyServerEdit);
    addKeyServerLayout->addWidget(newKeyServerButton);

    mainLayout->addWidget(label);
    mainLayout->addWidget(comboBox);
    mainLayout->addWidget(addKeyServerBox);
    mainLayout->addStretch(1);

    // Read keylist from ini-file and fill it into combobox
    setSettings();
}

/**********************************
 * Read the settings from config
 * and set the buttons and checkboxes
 * appropriately
 **********************************/
void KeyserverTab::setSettings() {
    auto *keyServerList = new QStringList();
    for (int i = 0; i < comboBox->count(); i++) {
        keyServerList->append(comboBox->itemText(i));
        qDebug() << "KeyserverTab ListItemText" << comboBox->itemText(i);
    }
    settings.setValue("keyserver/keyServerList", *keyServerList);
    delete keyServerList;
    settings.setValue("keyserver/defaultKeyServer", comboBox->currentText());
}

void KeyserverTab::addKeyServer() {
    if (newKeyServerEdit->text().startsWith("http://") ||
    newKeyServerEdit->text().startsWith("https://")) {
        comboBox->addItem(newKeyServerEdit->text());
    } else {
        comboBox->addItem("http://" + newKeyServerEdit->text());
    }
    comboBox->setCurrentIndex(comboBox->count() - 1);
}

/***********************************
 * get the values of the buttons and
 * write them to settings-file
 *************************************/
void KeyserverTab::applySettings() {
    settings.setValue("keyserver/defaultKeyServer", comboBox->currentText());
}