diff options
author | Anne Jan Brouwer <annejan@noprotocol.com> | 2015-05-08 08:02:52 +0200 |
---|---|---|
committer | Anne Jan Brouwer <annejan@noprotocol.com> | 2015-05-08 08:02:52 +0200 |
commit | d28220ccb72150fa986838351f2955f63886bd65 (patch) | |
tree | 412979769770f4757bc04623219e33a6054edc4b | |
parent | 560ee22239e4636872bc256336ab39720dc9f82f (diff) |
Profile UI mostly done
-rw-r--r-- | dialog.cpp | 93 | ||||
-rw-r--r-- | dialog.h | 4 | ||||
-rw-r--r-- | dialog.ui | 30 | ||||
-rw-r--r-- | mainwindow.cpp | 35 | ||||
-rw-r--r-- | mainwindow.h | 2 |
5 files changed, 149 insertions, 15 deletions
@@ -1,5 +1,7 @@ #include "dialog.h" #include "ui_dialog.h" +#include <QDebug> +#include <QMessageBox> /** * @brief Dialog::Dialog @@ -10,6 +12,8 @@ Dialog::Dialog(QWidget *parent) : ui(new Ui::Dialog) { ui->setupUi(this); + ui->profileTable->verticalHeader()->hide(); + ui->profileTable->horizontalHeader()->setStretchLastSection(true); } /** @@ -352,18 +356,25 @@ void Dialog::addGPGId(bool addGPGId) /** * @brief Dialog::setProfiles * @param profiles + * @param profile */ void Dialog::setProfiles(QHash<QString, QString> profiles, QString profile) { + ui->profileTable->setRowCount(profiles.count()); QHashIterator<QString, QString> i(profiles); + int n = 0; while (i.hasNext()) { i.next(); - // TODO - //ui->profileTable-> - if (i.key() == profile) { - ui->profileName->setText(i.key()); - ui->storePath->setText(i.value()); + if (!i.value().isEmpty()) { + ui->profileTable->setItem(n, 0, new QTableWidgetItem(i.key())); + ui->profileTable->setItem(n, 1, new QTableWidgetItem(i.value())); + //qDebug() << "naam:" + i.key(); + if (i.key() == profile) { + ui->profileName->setText(i.key()); + ui->storePath->setText(i.value()); + } } + n++; } } @@ -374,6 +385,76 @@ void Dialog::setProfiles(QHash<QString, QString> profiles, QString profile) QHash<QString, QString> Dialog::getProfiles() { QHash<QString, QString> profiles; - profiles.insert(ui->profileName->text(), ui->storePath->text()); + for (int i = 0; i < ui->profileTable->rowCount(); i++) { + QString path = ui->profileTable->item(i, 1)->text(); + if (!path.isEmpty()) { + profiles.insert(ui->profileTable->item(i, 0)->text(), + path); + } + } return profiles; } + +/** + * @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); + } +} @@ -3,6 +3,7 @@ #include <QDialog> #include <QFileDialog> +#include <QTableWidgetItem> namespace Ui { class Dialog; @@ -49,6 +50,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; @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>660</width> - <height>446</height> + <height>490</height> </rect> </property> <property name="windowTitle"> @@ -146,6 +146,21 @@ <layout class="QVBoxLayout" name="verticalLayout_2"> <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> @@ -188,17 +203,22 @@ </widget> </item> <item row="0" column="0"> - <widget class="QToolButton" name="toolButton"> + <widget class="QToolButton" name="addButton"> <property name="text"> - <string>Add</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> </layout> </item> </layout> - <zorder>labelStorePath</zorder> - <zorder></zorder> <zorder>profileTable</zorder> <zorder></zorder> </widget> diff --git a/mainwindow.cpp b/mainwindow.cpp index d74b8171..a1e7bc15 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -32,7 +32,8 @@ MainWindow::MainWindow(QWidget *parent) : enableUiElements(true); wrapperRunning = false; execQueue = new QQueue<execQueueItem>; - ui->statusBar->showMessage(tr("Welcome to QtPass ") + VERSION, 2000); + ui->statusBar->showMessage(tr("Welcome to QtPass %1").arg(VERSION), 2000); + startupPhase = true; } /** @@ -225,6 +226,7 @@ void MainWindow::checkConfig() { //QMessageBox::information(this, "env", env.join("\n")); ui->lineEdit->setFocus(); + startupPhase = false; } /** @@ -447,7 +449,7 @@ void MainWindow::readyRead(bool finished = false) { output.replace(QRegExp("((http|https|ftp)\\://[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\\-\\._\\?\\,\\'/\\\\+&%\\$#\\=~])*)"), "<a href=\"\\1\">\\1</a>"); output.replace(QRegExp("\n"), "<br />"); - if (ui->textBrowser->toPlainText() != "") { + if (!ui->textBrowser->toPlainText().isEmpty()) { output = ui->textBrowser->toHtml() + output; } ui->textBrowser->setHtml(output); @@ -914,22 +916,47 @@ void MainWindow::setText(QString text) */ 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(); - ui->profileBox->addItem(i.key()); + if (!i.key().isEmpty()) { + ui->profileBox->addItem(i.key()); + } } } - int index = ui->profileBox->findData(profile); + 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); +} diff --git a/mainwindow.h b/mainwindow.h index dbea7dfd..90c0b145 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -58,6 +58,7 @@ private slots: void on_editButton_clicked(); void on_usersButton_clicked(); void messageAvailable(QString message); + void on_profileBox_currentIndexChanged(QString); private: QScopedPointer<QSettings> settings; @@ -91,6 +92,7 @@ private: QHash<QString, QString> profiles; QQueue<execQueueItem> *execQueue; QString profile; + bool startupPhase; void updateText(); void executePass(QString, QString = QString()); void executeWrapper(QString, QString, QString = QString()); |