diff options
author | Anne Jan Brouwer <brouwer@annejan.com> | 2015-05-27 04:00:04 +0200 |
---|---|---|
committer | Anne Jan Brouwer <annejan@noprotocol.com> | 2015-05-27 04:00:04 +0200 |
commit | bf529491b6de6b981f920e354b2a82a597996f44 (patch) | |
tree | fe22d3dde74bfcaaf6fcf93e7789fea540d73d95 | |
parent | 4841cd5d596eefc150d6bfcf0286358abcc9fa48 (diff) |
reverted more reverts
-rw-r--r-- | dialog.cpp | 65 | ||||
-rw-r--r-- | dialog.h | 4 | ||||
-rw-r--r-- | dialog.ui | 140 | ||||
-rw-r--r-- | mainwindow.cpp | 81 | ||||
-rw-r--r-- | mainwindow.h | 5 | ||||
-rw-r--r-- | mainwindow.ui | 16 | ||||
-rw-r--r-- | qtpass.pro | 2 |
7 files changed, 273 insertions, 40 deletions
@@ -410,3 +410,68 @@ void Dialog::genKey(QString batch, QDialog *dialog) { mainWindow->genKey(batch, dialog); } + + +/** + * @brief Dialog::on_addButton_clicked + */ +void Dialog::on_addButton_clicked() +{ + QString name = ui->profileName->text(); + int n = 0; + bool newItem = true; + QAbstractItemModel *model = ui->profileTable->model(); + QModelIndexList matches = model->match( model->index(0,0), Qt::DisplayRole, name); + foreach(const QModelIndex &index, matches) + { + QTableWidgetItem *item = ui->profileTable->item(index.row(), index.column()); + n = item->row(); + qDebug() << "overwrite:" << item->text(); + newItem = false; + } + if (newItem) { + n = ui->profileTable->rowCount(); + ui->profileTable->insertRow(n); + } + ui->profileTable->setItem(n, 0, new QTableWidgetItem(name)); + ui->profileTable->setItem(n, 1, new QTableWidgetItem(ui->storePath->text())); + //qDebug() << ui->profileName->text(); + ui->profileTable->selectRow(n); + if (ui->profileTable->rowCount() < 1) { + ui->deleteButton->setEnabled(true); + } +} + +/** + * @brief Dialog::on_profileTable_currentItemChanged + * @param current + */ +void Dialog::on_profileTable_currentItemChanged(QTableWidgetItem *current) +{ + if (current == 0) { + return; + } + int n = current->row(); + ui->profileName->setText(ui->profileTable->item(n, 0)->text()); + ui->storePath->setText(ui->profileTable->item(n, 1)->text()); +} + +/** + * @brief Dialog::on_deleteButton_clicked + */ +void Dialog::on_deleteButton_clicked() +{ + QList<QTableWidgetItem*> selected = ui->profileTable->selectedItems(); + if (selected.count() == 0) { + QMessageBox::warning(this, tr("No profile selected"), + tr("No profile selected to delete")); + return; + } + for (int i = 0; i < selected.size(); ++i) { + QTableWidgetItem* item = selected.at(i); + ui->profileTable->removeRow(item->row()); + } + if (ui->profileTable->rowCount() < 1) { + ui->deleteButton->setEnabled(false); + } +} @@ -4,6 +4,7 @@ #include <QDialog> #include <QFileDialog> #include "mainwindow.h" +#include <QTableWidgetItem> namespace Ui { @@ -53,6 +54,9 @@ private slots: void on_toolButtonStore_clicked(); void on_checkBoxClipboard_clicked(); void on_checkBoxAutoclear_clicked(); + void on_addButton_clicked(); + void on_profileTable_currentItemChanged(QTableWidgetItem*); + void on_deleteButton_clicked(); private: QScopedPointer<Ui::Dialog> ui; @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>507</width> - <height>446</height> + <width>491</width> + <height>585</height> </rect> </property> <property name="windowTitle"> @@ -38,35 +38,35 @@ <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"> + <widget class="QLabel" name="labelGpgPath"> <property name="text"> - <string>Executable git</string> + <string>gpg</string> </property> </widget> </item> - <item row="1" column="0"> - <widget class="QLabel" name="labelGpgPath"> + <item row="1" column="2"> + <widget class="QToolButton" name="toolButtonGit"> <property name="text"> - <string>Executable gpg</string> + <string>...</string> </property> </widget> </item> - <item row="1" column="2"> - <widget class="QToolButton" name="toolButtonGpg"> + <item row="1" column="0"> + <widget class="QLabel" name="labelGitPath"> <property name="text"> - <string>...</string> + <string>git</string> </property> </widget> </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="gitPath"/> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="gpgPath"/> + </item> <item row="0" column="2"> - <widget class="QToolButton" name="toolButtonGit"> + <widget class="QToolButton" name="toolButtonGpg"> <property name="text"> <string>...</string> </property> @@ -91,7 +91,7 @@ <item row="0" column="0"> <widget class="QLabel" name="labelPassPath"> <property name="text"> - <string>Executable pass</string> + <string>pass</string> </property> </widget> </item> @@ -102,33 +102,95 @@ </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="QGridLayout" name="gridLayout_5"> + <layout class="QVBoxLayout" name="verticalLayout_4"> + <item> + <widget class="QTableWidget" name="profileTable"> + <property name="editTriggers"> + <set>QAbstractItemView::NoEditTriggers</set> + </property> + <property name="alternatingRowColors"> + <bool>true</bool> + </property> + <property name="selectionMode"> + <enum>QAbstractItemView::SingleSelection</enum> + </property> + <property name="selectionBehavior"> + <enum>QAbstractItemView::SelectRows</enum> + </property> + <property name="sortingEnabled"> + <bool>true</bool> + </property> + <column> + <property name="text"> + <string>Name</string> + </property> + </column> + <column> + <property name="text"> + <string>Path</string> + </property> + </column> + </widget> + </item> + <item> + <layout class="QGridLayout" name="gridLayout_11"> + <item row="2" column="4"> + <widget class="QToolButton" name="toolButtonStore"> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QLineEdit" name="profileName"/> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="labelName"> + <property name="text"> + <string>Profile name</string> + </property> + </widget> + </item> <item row="0" column="0"> - <widget class="QLabel" name="labelStorePath"> + <widget class="QToolButton" name="addButton"> <property name="text"> - <string>Folder password-store</string> + <string>Add/Edit</string> </property> </widget> </item> <item row="0" column="1"> + <widget class="QToolButton" name="deleteButton"> + <property name="text"> + <string>Delete</string> + </property> + </widget> + </item> + <item row="2" column="3"> <widget class="QLineEdit" name="storePath"/> </item> - <item row="0" column="2"> - <widget class="QToolButton" name="toolButtonStore"> + <item row="2" column="2"> + <widget class="QLabel" name="labelStorePath"> <property name="text"> - <string>...</string> + <string>password-store</string> </property> </widget> </item> </layout> </item> - <item row="1" column="0"> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="groupBox"> + <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"> @@ -200,32 +262,32 @@ <connections> <connection> <sender>buttonBox</sender> - <signal>accepted()</signal> + <signal>rejected()</signal> <receiver>Dialog</receiver> - <slot>accept()</slot> + <slot>reject()</slot> <hints> <hint type="sourcelabel"> - <x>248</x> - <y>254</y> + <x>316</x> + <y>260</y> </hint> <hint type="destinationlabel"> - <x>157</x> + <x>286</x> <y>274</y> </hint> </hints> </connection> <connection> <sender>buttonBox</sender> - <signal>rejected()</signal> + <signal>accepted()</signal> <receiver>Dialog</receiver> - <slot>reject()</slot> + <slot>accept()</slot> <hints> <hint type="sourcelabel"> - <x>316</x> - <y>260</y> + <x>248</x> + <y>254</y> </hint> <hint type="destinationlabel"> - <x>286</x> + <x>157</x> <y>274</y> </hint> </hints> diff --git a/mainwindow.cpp b/mainwindow.cpp index 381d4e18..562852b7 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -35,6 +35,7 @@ MainWindow::MainWindow(QWidget *parent) : execQueue = new QQueue<execQueueItem>; ui->statusBar->showMessage(tr("Welcome to QtPass %1").arg(VERSION), 2000); firstRun = true; + startupPhase = true; } /** @@ -161,6 +162,14 @@ bool MainWindow::checkConfig() { webDavUser = settings.value("webDavUser").toString(); webDavPassword = settings.value("webDavPassword").toString(); + profile = settings.value("profile").toString(); + settings.beginGroup("profiles"); + QStringList keys = settings.childKeys(); + foreach (QString key, keys) { + profiles[key] = settings.value(key).toString(); + } + settings.endGroup(); + if (Util::checkConfig(passStore, passExecutable, gpgExecutable)) { config(); if (firstRun && Util::checkConfig(passStore, passExecutable, gpgExecutable)) { @@ -218,6 +227,7 @@ bool MainWindow::checkConfig() { updateEnv(); ui->lineEdit->setFocus(); + startupPhase = false; return true; } @@ -1006,3 +1016,74 @@ void MainWindow::genKey(QString batch, QDialog *keygenWindow) currentAction = GPG_INTERNAL; executeWrapper(gpgExecutable , "--gen-key --no-tty --batch", batch); } + + +/** + * @brief MainWindow::updateProfileBox + */ +void MainWindow::updateProfileBox() +{ + qDebug() << profiles.size(); + if (profiles.isEmpty()) { + ui->profileBox->setVisible(false); + } else { + ui->profileBox->setVisible(true); + if (profiles.size() < 2) { + ui->profileBox->setEnabled(false); + } else { + ui->profileBox->setEnabled(true); + } + ui->profileBox->clear(); + QHashIterator<QString, QString> i(profiles); + while (i.hasNext()) { + i.next(); + if (!i.key().isEmpty()) { + ui->profileBox->addItem(i.key()); + } + } + } + int index = ui->profileBox->findText(profile); + if ( index != -1 ) { // -1 for not found + ui->profileBox->setCurrentIndex(index); + } +} + +/** + * @brief MainWindow::on_profileBox_currentIndexChanged + * @param name + */ +void MainWindow::on_profileBox_currentIndexChanged(QString name) +{ + if (startupPhase || name == profile) { + return; + } + profile = name; + + passStore = profiles[name]; + ui->statusBar->showMessage(tr("Profile changed to %1").arg(name), 2000); + + QSettings &settings(getSettings()); + + settings.setValue("profile", profile); + settings.setValue("passStore", passStore); + + // qDebug() << env; + QStringList store = env.filter("PASSWORD_STORE_DIR"); + // put PASSWORD_STORE_DIR in env + if (store.isEmpty()) { + //qDebug() << "Added PASSWORD_STORE_DIR"; + env.append("PASSWORD_STORE_DIR=" + passStore); + } else { + //qDebug() << "Update PASSWORD_STORE_DIR"; + env.replaceInStrings(store.first(), "PASSWORD_STORE_DIR=" + passStore); + } + + // update model and treeview + model.setRootPath(passStore); + proxyModel.setSourceModel(&model); + proxyModel.setModelAndStore(&model, passStore); + selectionModel.reset(new QItemSelectionModel(&proxyModel)); + model.fetchMore(model.setRootPath(passStore)); + model.sort(0, Qt::AscendingOrder); + ui->treeView->setModel(&proxyModel); +} diff --git a/mainwindow.h b/mainwindow.h index e5b8b337..5aafd89c 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -63,6 +63,7 @@ private slots: void on_editButton_clicked(); void on_usersButton_clicked(); void messageAvailable(QString message); + void on_profileBox_currentIndexChanged(QString); private: QApplication *QtPass; @@ -98,6 +99,9 @@ private: bool firstRun; QDialog *keygen = 0; QString currentDir; + QHash<QString, QString> profiles; + QString profile; + bool startupPhase; void updateText(); void executePass(QString, QString = QString()); void executeWrapper(QString, QString, QString = QString()); @@ -114,6 +118,7 @@ private: QString getRecipientString(QString for_file, QString separator = " ", int *count = NULL); void mountWebDav(); void updateEnv(); + void updateProfileBox(); }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index 233643ee..e6ccbf02 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -98,6 +98,22 @@ </property> </spacer> </item> + <item> + <widget class="QComboBox" name="profileBox"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>100</width> + <height>10</height> + </size> + </property> + </widget> + </item> </layout> </widget> </item> @@ -20,7 +20,7 @@ macx { } TEMPLATE = app -VERSION = 0.8.2 +VERSION = 0.8.3 SOURCES += main.cpp\ mainwindow.cpp \ |