diff options
author | Anne Jan Brouwer <brouwer@annejan.com> | 2015-05-08 00:56:45 +0200 |
---|---|---|
committer | Anne Jan Brouwer <annejan@noprotocol.com> | 2015-05-08 00:56:45 +0200 |
commit | dbb6a34f7da86dfc2cd3d024bbc1cd781cf88ce8 (patch) | |
tree | ab108c84f1a8f76cad9b69fc70938c98817aaa4c | |
parent | 5cf845de674b29c836247fe2c0cb3465f5b2e58d (diff) |
Basic profile framework
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | dialog.cpp | 26 | ||||
-rw-r--r-- | dialog.h | 2 | ||||
-rw-r--r-- | dialog.ui | 232 | ||||
-rw-r--r-- | mainwindow.cpp | 60 | ||||
-rw-r--r-- | mainwindow.h | 4 |
6 files changed, 230 insertions, 95 deletions
@@ -55,6 +55,7 @@ Planned features * Templates (username, url etc) in Add / Edit screen (configurable templates) * Colour coding or disabling of people you can't encrypt for (trust settings) in User management * Colour coding folders (possibly disabling folders you can't decrypt) +* Trayicon support * WebDAV (configuration) support * Optional table view of decrypted folder contents * Opening of (basic auth) urls in default browser? Possibly with helper plugin for filling out forms? @@ -348,3 +348,29 @@ void Dialog::addGPGId(bool addGPGId) { ui->checkBoxAddGPGId->setChecked(addGPGId); } + +/** + * @brief Dialog::setProfiles + * @param profiles + */ +void Dialog::setProfiles(QHash<QString, QString> profiles) +{ + QHashIterator<QString, QString> i(profiles); + while (i.hasNext()) { + i.next(); + // TODO + ui->profileName->setText(i.key()); + ui->storePath->setText(i.value()); + } +} + +/** + * @brief Dialog::getProfiles + * @return + */ +QHash<QString, QString> Dialog::getProfiles() +{ + QHash<QString, QString> profiles; + profiles.insert(ui->profileName->text(), ui->storePath->text()); + return profiles; +} @@ -19,6 +19,7 @@ public: void setGitPath(QString); void setGpgPath(QString); void setStorePath(QString); + void setProfiles(QHash<QString, QString>); void usePass(bool); void useClipboard(bool); void useAutoclear(bool); @@ -30,6 +31,7 @@ public: QString getGitPath(); QString getGpgPath(); QString getStorePath(); + QHash<QString,QString> getProfiles(); bool usePass(); bool useClipboard(); bool useAutoclear(); @@ -6,7 +6,7 @@ <rect> <x>0</x> <y>0</y> - <width>507</width> + <width>660</width> <height>446</height> </rect> </property> @@ -15,120 +15,176 @@ </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> - <layout class="QHBoxLayout" name="horizontalLayout_5"> + <widget class="QFrame" name="frame"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>QFrame::NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Plain</enum> + </property> + <property name="lineWidth"> + <number>0</number> + </property> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_5"> + <item> + <widget class="QRadioButton" name="radioButtonNative"> + <property name="text"> + <string>&Native git/gpg</string> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="radioButtonPass"> + <property name="text"> + <string>&Use pass</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_3"> <item> - <widget class="QRadioButton" name="radioButtonNative"> - <property name="text"> - <string>&Native git/gpg</string> + <widget class="QGroupBox" name="groupBoxNative"> + <property name="title"> + <string>Native</string> </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="labelGitPath"> + <property name="text"> + <string>Executable git</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="gpgPath"/> + </item> + <item row="0" column="2"> + <widget class="QToolButton" name="toolButtonGit"> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="labelGpgPath"> + <property name="text"> + <string>Executable gpg</string> + </property> + </widget> + </item> + <item row="1" column="2"> + <widget class="QToolButton" name="toolButtonGpg"> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="gitPath"/> + </item> + </layout> </widget> </item> <item> - <widget class="QRadioButton" name="radioButtonPass"> - <property name="text"> - <string>&Use pass</string> + <widget class="QGroupBox" name="groupBoxPass"> + <property name="title"> + <string>Pass</string> </property> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="0" column="2"> + <widget class="QToolButton" name="toolButtonPass"> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="labelPassPath"> + <property name="text"> + <string>Executable pass</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="passPath"/> + </item> + </layout> </widget> </item> </layout> </item> <item> - <widget class="QGroupBox" name="groupBoxNative"> - <property name="title"> - <string>Native</string> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="1" column="1"> - <widget class="QLineEdit" name="gpgPath"/> - </item> - <item row="0" column="1"> - <widget class="QLineEdit" name="gitPath"/> - </item> - <item row="0" column="0"> - <widget class="QLabel" name="labelGitPath"> - <property name="text"> - <string>Executable git</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="labelGpgPath"> - <property name="text"> - <string>Executable gpg</string> - </property> - </widget> - </item> - <item row="1" column="2"> - <widget class="QToolButton" name="toolButtonGpg"> - <property name="text"> - <string>...</string> - </property> - </widget> - </item> - <item row="0" column="2"> - <widget class="QToolButton" name="toolButtonGit"> - <property name="text"> - <string>...</string> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item> - <widget class="QGroupBox" name="groupBoxPass"> - <property name="title"> - <string>Pass</string> - </property> - <layout class="QGridLayout" name="gridLayout_2"> - <item row="0" column="2"> - <widget class="QToolButton" name="toolButtonPass"> - <property name="text"> - <string>...</string> - </property> - </widget> - </item> - <item row="0" column="0"> - <widget class="QLabel" name="labelPassPath"> - <property name="text"> - <string>Executable pass</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QLineEdit" name="passPath"/> - </item> - </layout> - </widget> - </item> - <item> - <widget class="QGroupBox" name="groupBox"> + <widget class="QGroupBox" name="groupBoxProfiles"> <property name="title"> - <string>Other</string> + <string>Profiles</string> </property> - <layout class="QGridLayout" name="gridLayout_6"> - <item row="0" column="0"> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> <layout class="QGridLayout" name="gridLayout_5"> - <item row="0" column="0"> + <item row="1" column="3"> + <widget class="QLineEdit" name="storePath"/> + </item> + <item row="1" column="4"> + <widget class="QToolButton" name="toolButtonStore"> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + <item row="1" column="2"> <widget class="QLabel" name="labelStorePath"> <property name="text"> <string>Folder password-store</string> </property> </widget> </item> - <item row="0" column="1"> - <widget class="QLineEdit" name="storePath"/> + <item row="1" column="1"> + <widget class="QLineEdit" name="profileName"/> </item> - <item row="0" column="2"> - <widget class="QToolButton" name="toolButtonStore"> + <item row="1" column="0"> + <widget class="QLabel" name="labelName"> <property name="text"> - <string>...</string> + <string>Profile name</string> </property> </widget> </item> </layout> </item> - <item row="1" column="0"> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="groupBoxOther"> + <property name="title"> + <string>Other</string> + </property> + <layout class="QGridLayout" name="gridLayout_6"> + <item row="0" column="0"> <layout class="QGridLayout" name="gridLayout_7"> <item row="0" column="0"> <widget class="QCheckBox" name="checkBoxClipboard"> diff --git a/mainwindow.cpp b/mainwindow.cpp index dba55668..f19c1aa0 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -164,7 +164,13 @@ void MainWindow::checkConfig() { webDavUrl = settings.value("webDavUrl").toString(); webDavUser = settings.value("webDavUser").toString(); webDavPassword = settings.value("webDavPassword").toString(); - profiles = settings.value("profiles").toStringList(); + + settings.beginGroup("profiles"); + QStringList keys = settings.childKeys(); + foreach (QString key, keys) { + profiles[key] = settings.value(key).toString(); + } + settings.endGroup(); if (passExecutable == "" && (gitExecutable == "" || gpgExecutable == "")) { config(); @@ -196,11 +202,8 @@ void MainWindow::checkConfig() { ui->treeView->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); ui->textBrowser->setOpenExternalLinks(true); - if (profiles.isEmpty()) { - ui->profileBox->setEnabled(false); - } else { - ui->profileBox->addItems(profiles); - } + + updateProfileBox(); env = QProcess::systemEnvironment(); if (!gpgHome.isEmpty()) { @@ -241,6 +244,7 @@ void MainWindow::config() { d->hidePassword(hidePassword); d->hideContent(hideContent); d->addGPGId(addGPGId); + d->setProfiles(profiles); if (d->exec()) { if (d->result() == QDialog::Accepted) { @@ -256,6 +260,7 @@ void MainWindow::config() { hidePassword = d->hidePassword(); hideContent = d->hideContent(); addGPGId = d->addGPGId(); + profiles = d->getProfiles(); QSettings &settings(getSettings()); @@ -270,7 +275,25 @@ void MainWindow::config() { settings.setValue("hidePassword", hidePassword ? "true" : "false"); settings.setValue("hideContent", hideContent ? "true" : "false"); settings.setValue("addGPGId", addGPGId ? "true" : "false"); + settings.beginGroup("profiles"); + settings.remove(""); + bool profileExists = false; + QHashIterator<QString, QString> i(profiles); + while (i.hasNext()) { + i.next(); + //qDebug() << i.key() + "|" + i.value(); + if (i.key() == profile) { + profileExists = true; + } + settings.setValue(i.key(), i.value()); + } + if (!profileExists) { + // just take the last one + profile = i.key(); + } + settings.endGroup(); + updateProfileBox(); ui->treeView->setRootIndex(model.setRootPath(passStore)); } } @@ -884,3 +907,28 @@ void MainWindow::setText(QString text) { ui->lineEdit->setText(text); } + +/** + * @brief MainWindow::updateProfileBox + */ +void MainWindow::updateProfileBox() +{ + if (profiles.isEmpty()) { + ui->profileBox->setVisible(false); + } else { + ui->profileBox->setVisible(true); + if (profiles.size() < 2) { + ui->profileBox->setEnabled(false); + } + ui->profileBox->clear(); + QHashIterator<QString, QString> i(profiles); + while (i.hasNext()) { + i.next(); + ui->profileBox->addItem(i.key()); + } + } + int index = ui->profileBox->findData(profile); + if ( index != -1 ) { // -1 for not found + ui->profileBox->setCurrentIndex(index); + } +} diff --git a/mainwindow.h b/mainwindow.h index 1d11c692..dbea7dfd 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -88,8 +88,9 @@ private: QString lastDecrypt; bool wrapperRunning; QStringList env; - QStringList profiles; + QHash<QString, QString> profiles; QQueue<execQueueItem> *execQueue; + QString profile; void updateText(); void executePass(QString, QString = QString()); void executeWrapper(QString, QString, QString = QString()); @@ -106,6 +107,7 @@ private: QStringList getRecipientList(QString for_file); QString getRecipientString(QString for_file, QString separator = " ", int *count = NULL); void mountWebDav(); + void updateProfileBox(); }; #endif // MAINWINDOW_H |