Skip to content
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ compiler:
before_install:
- sudo add-apt-repository ppa:likemartinma/devel -y
- sudo apt-get update -qq
- sudo apt-get install -qq libqt4-dev libsqlite3-dev libsqlcipher-dev libantlr-dev
- sudo apt-get --force-yes install -qq libqt4-dev libsqlite3-dev libsqlcipher-dev libantlr-dev
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this into a separate pull request? I think it makes more sense to have this separated because it's not directly related to the cipher stuff we're doing here, and this way we can merge it sooner, too 😃

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll have to tell me how to do this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@revolter just open another pull request.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@innermous, And can I remove the latest commit from this PR too?


script:
- mkdir build
Expand Down
17 changes: 17 additions & 0 deletions src/CipherDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ CipherDialog::CipherDialog(QWidget* parent, bool encrypt) :
{
ui->setupUi(this);

savedPageSize = 0;

if(encrypt)
{
ui->labelDialogDescription->setText(tr("Please set a key to encrypt the database.\nNote that if you change any of the other, optional, settings you'll need "
Expand All @@ -31,14 +33,29 @@ CipherDialog::~CipherDialog()

QString CipherDialog::password() const
{
if (savedPassword != NULL)
{
return savedPassword;
}

return ui->editPassword->text();
}

int CipherDialog::pageSize() const
{
if (savedPageSize > 0)
{
return savedPageSize;
}

return ui->spinPageSize->value();
}

bool CipherDialog::isSavePasswordEnabled() const
{
return ui->savePasswordCheckBox->isChecked();
}

void CipherDialog::checkInputFields()
{
bool valid = true;
Expand Down
5 changes: 5 additions & 0 deletions src/CipherDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ class CipherDialog : public QDialog
explicit CipherDialog(QWidget* parent, bool encrypt);
~CipherDialog();

// Set these to the values from the preferences settings
QString savedPassword;
int savedPageSize;

// Allow read access to the input fields
QString password() const;
int pageSize() const;
bool isSavePasswordEnabled() const;

private:
Ui::CipherDialog* ui;
Expand Down
12 changes: 11 additions & 1 deletion src/CipherDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>712</width>
<height>147</height>
<height>202</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -79,6 +79,16 @@
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="savePasswordLabel">
<property name="text">
<string>Save password</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="savePasswordCheckBox"/>
</item>
</layout>
</item>
<item>
Expand Down
115 changes: 115 additions & 0 deletions src/PreferencesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,33 @@ void PreferencesDialog::loadSettings()
ui->spinPrefetchSize->setValue(getSettingsValue("db", "prefetchsize").toInt());
ui->editDatabaseDefaultSqlText->setText(getSettingsValue("db", "defaultsqltext").toString());

DatabasePasswordsMap databasePasswords = getSettingsValue("db", "databasepasswords").toMap();
QMapIterator<QString, QVariant> databasePasswordsIterator(databasePasswords);

while (databasePasswordsIterator.hasNext())
{
databasePasswordsIterator.next();

QString fileName = databasePasswordsIterator.key();

QVariantList value = databasePasswordsIterator.value().toList();

QString password = value.at(0).toString();
int pageSize = value.at(1).toInt();

QTableWidgetItem *fileNameItem = new QTableWidgetItem(fileName);
QTableWidgetItem *passwordItem = new QTableWidgetItem(password);
QTableWidgetItem *pageSizeItem = new QTableWidgetItem(QString::number(pageSize));

int newRowIndex = ui->tableWidgetDatabasePasswords->rowCount();

ui->tableWidgetDatabasePasswords->insertRow(newRowIndex);

ui->tableWidgetDatabasePasswords->setItem(newRowIndex, 0, fileNameItem);
ui->tableWidgetDatabasePasswords->setItem(newRowIndex, 1, passwordItem);
ui->tableWidgetDatabasePasswords->setItem(newRowIndex, 2, pageSizeItem);
}

ui->comboDataBrowserFont->setCurrentIndex(ui->comboEditorFont->findText(getSettingsValue("databrowser", "font").toString()));
ui->spinDataBrowserFontSize->setValue(getSettingsValue("databrowser", "fontsize").toInt());
loadColorSetting(ui->fr_null_fg, "null_fg");
Expand Down Expand Up @@ -115,6 +142,55 @@ void PreferencesDialog::saveSettings()
setSettingsValue("db", "prefetchsize", ui->spinPrefetchSize->value());
setSettingsValue("db", "defaultsqltext", ui->editDatabaseDefaultSqlText->text());

ui->tableWidgetDatabasePasswords->setCurrentIndex(QModelIndex()); // saves the current editing QTableWidgetItem

DatabasePasswordsMap databasePasswords;

for(int rowIndex = 0; rowIndex < ui->tableWidgetDatabasePasswords->rowCount(); ++rowIndex)
{
QTableWidgetItem *fileNameItem = ui->tableWidgetDatabasePasswords->item(rowIndex, 0);
QTableWidgetItem *passwordItem = ui->tableWidgetDatabasePasswords->item(rowIndex, 1);
QTableWidgetItem *pageSizeItem = ui->tableWidgetDatabasePasswords->item(rowIndex, 2);

if (!fileNameItem)
{
continue;
}

if (!passwordItem)
{
continue;
}

if (!pageSizeItem)
{
continue;
}

QString fileName = fileNameItem->text();
QString password = passwordItem->text();
int pageSize = pageSizeItem->text().toInt();

if (fileName == NULL || fileName.isEmpty())
{
continue;
}

if (password == NULL || password.isEmpty())
{
continue;
}

QVariantList value;

value.append(QVariant(password));
value.append(QVariant(pageSize));

databasePasswords.insert(fileName, value);
}

setSettingsValue("db", "databasepasswords", QVariant(databasePasswords));

setSettingsValue("checkversion", "enabled", ui->checkUpdates->isChecked());

setSettingsValue("databrowser", "font", ui->comboDataBrowserFont->currentText());
Expand Down Expand Up @@ -440,6 +516,45 @@ void PreferencesDialog::removeExtension()
ui->listExtensions->takeItem(ui->listExtensions->currentIndex().row());
}

void PreferencesDialog::on_buttonAddPassword_clicked()
{
int newRowIndex = ui->tableWidgetDatabasePasswords->rowCount();

ui->tableWidgetDatabasePasswords->insertRow(newRowIndex);

QTableWidgetItem *defaultPageSizeItem = new QTableWidgetItem("1024");

ui->tableWidgetDatabasePasswords->setItem(newRowIndex, 2, defaultPageSizeItem);

QString filePath = FileDialog::getOpenFileName(
this,
tr("Choose a database file")
#ifndef Q_OS_MAC // Filters on OS X are buggy
, FileDialog::getSqlDatabaseFileFilter()
#endif
);

QFile databaseFile(filePath);
QFileInfo databaseFileInfo(databaseFile);
QString databaseFileName(databaseFileInfo.fileName());

QTableWidgetItem *databaseFileNameItem = new QTableWidgetItem(databaseFileName);

ui->tableWidgetDatabasePasswords->setItem(newRowIndex, 0, databaseFileNameItem);
}

void PreferencesDialog::on_buttonDeletePassword_clicked()
{
QList<QTableWidgetItem *> selectedRowItems = ui->tableWidgetDatabasePasswords->selectedItems();

for (int index = 0; index < selectedRowItems.size(); ++index)
{
int selectedRowIndex = selectedRowItems.at(index)->row();

ui->tableWidgetDatabasePasswords->removeRow(selectedRowIndex);
}
}

void PreferencesDialog::fillLanguageBox()
{
QDir translationsDir(QCoreApplication::applicationDirPath() + "/translations",
Expand Down
6 changes: 6 additions & 0 deletions src/PreferencesDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <QVariant>
#include <QHash>

typedef QMultiMap<QString, QVariant> DatabasePasswordsMap;
Q_DECLARE_METATYPE(DatabasePasswordsMap)

class QTreeWidgetItem;
class QFrame;

Expand Down Expand Up @@ -33,6 +36,9 @@ private slots:
virtual void addExtension();
virtual void removeExtension();

virtual void on_buttonAddPassword_clicked();
virtual void on_buttonDeletePassword_clicked();

private:
Ui::PreferencesDialog *ui;

Expand Down
Loading