summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnne Jan Brouwer <annejan@noprotocol.com>2015-05-27 04:28:21 +0200
committerAnne Jan Brouwer <annejan@noprotocol.com>2015-05-27 04:28:21 +0200
commit3cd9eccbafc149157b56341b5c6fe04df8383457 (patch)
treeed4874e2a40633cd356e7c133824491f6596d2f6
parent1e7d73761321c0c1f7733deb927631495d6869c3 (diff)
working profiles, needs some love in dialog
-rw-r--r--dialog.cpp43
-rw-r--r--dialog.h2
-rw-r--r--mainwindow.cpp31
3 files changed, 68 insertions, 8 deletions
diff --git a/dialog.cpp b/dialog.cpp
index 7c7fe22e..a313d245 100644
--- a/dialog.cpp
+++ b/dialog.cpp
@@ -16,6 +16,8 @@ Dialog::Dialog(MainWindow *parent) :
{
mainWindow = parent;
ui->setupUi(this);
+ ui->profileTable->verticalHeader()->hide();
+ ui->profileTable->horizontalHeader()->setStretchLastSection(true);
}
/**
@@ -411,6 +413,47 @@ void Dialog::genKey(QString batch, QDialog *dialog)
mainWindow->genKey(batch, dialog);
}
+/**
+ * @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();
+ 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++;
+ }
+}
+
+/**
+ * @brief Dialog::getProfiles
+ * @return
+ */
+QHash<QString, QString> Dialog::getProfiles()
+{
+ QHash<QString, QString> profiles;
+ 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
diff --git a/dialog.h b/dialog.h
index 031f6969..5d2c12ed 100644
--- a/dialog.h
+++ b/dialog.h
@@ -24,6 +24,7 @@ public:
void setGitPath(QString);
void setGpgPath(QString);
void setStorePath(QString);
+ void setProfiles(QHash<QString, QString>, QString);
void usePass(bool);
void useClipboard(bool);
void useAutoclear(bool);
@@ -35,6 +36,7 @@ public:
QString getGitPath();
QString getGpgPath();
QString getStorePath();
+ QHash<QString,QString> getProfiles();
bool usePass();
bool useClipboard();
bool useAutoclear();
diff --git a/mainwindow.cpp b/mainwindow.cpp
index 562852b7..aaf76e30 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -206,6 +206,8 @@ bool MainWindow::checkConfig() {
ui->textBrowser->setOpenExternalLinks(true);
+ updateProfileBox();
+
env = QProcess::systemEnvironment();
if (!gpgHome.isEmpty()) {
QDir absHome(gpgHome);
@@ -249,6 +251,7 @@ void MainWindow::config() {
d->hidePassword(hidePassword);
d->hideContent(hideContent);
d->addGPGId(addGPGId);
+ d->setProfiles(profiles, profile);
d->wizard(); // does shit
if (d->exec()) {
@@ -264,6 +267,7 @@ void MainWindow::config() {
hidePassword = d->hidePassword();
hideContent = d->hideContent();
addGPGId = d->addGPGId();
+ profiles = d->getProfiles();
QSettings &settings(getSettings());
@@ -278,7 +282,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(proxyModel.mapFromSource(model.setRootPath(passStore)));
if (firstRun && Util::checkConfig(passStore, passExecutable, gpgExecutable)) {
@@ -1078,12 +1100,5 @@ void MainWindow::on_profileBox_currentIndexChanged(QString name)
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);
+ ui->treeView->setRootIndex(proxyModel.mapFromSource(model.setRootPath(passStore)));
}