cipher: Show encryption status in the main window statusbar · jackyspeed/sqlitebrowser@8fb9176 · GitHub
Skip to content

Commit 8fb9176

Browse files
committed
cipher: Show encryption status in the main window statusbar
Add a note to the status bar of the main window when an encrpyted database is opened. Also make some methods in the CipherDialog class const.
1 parent e12f625 commit 8fb9176

6 files changed

Lines changed: 21 additions & 4 deletions

File tree

‎src/CipherDialog.cpp‎

Lines changed: 2 additions & 2 deletions

‎src/CipherDialog.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class CipherDialog : public QDialog
1818
~CipherDialog();
1919

2020
// Allow read access tothe input fields
21-
QString password();
22-
int pageSize();
21+
QString password() const;
22+
int pageSize() const;
2323

2424
private:
2525
Ui::CipherDialog* ui;

‎src/MainWindow.cpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ void MainWindow::init()
133133
statusEncodingLabel->setToolTip(tr("Database encoding"));
134134
ui->statusbar->addPermanentWidget(statusEncodingLabel);
135135

136+
statusEncryptionLabel = new QLabel(ui->statusbar);
137+
statusEncryptionLabel->setEnabled(false);
138+
statusEncryptionLabel->setVisible(false);
139+
statusEncryptionLabel->setText("Encrypted");
140+
statusEncryptionLabel->setToolTip(tr("Database is encrypted using SQLCipher"));
141+
ui->statusbar->addPermanentWidget(statusEncryptionLabel);
142+
136143
// Connect some more signals and slots
137144
connect(ui->dataTable->filterHeader(), SIGNAL(sectionClicked(int)), this, SLOT(browseTableHeaderClicked(int)));
138145
connect(ui->dataTable->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(setRecordsetLabel()));
@@ -204,6 +211,7 @@ bool MainWindow::fileOpen(const QString& fileName, bool dontAddToRecentFiles)
204211
if(db.open(wFile))
205212
{
206213
statusEncodingLabel->setText(db.getPragma("encoding"));
214+
statusEncryptionLabel->setVisible(db.encrypted());
207215
setCurrentFile(wFile);
208216
if(!dontAddToRecentFiles)
209217
addToRecentFilesMenu(wFile);
@@ -408,6 +416,7 @@ void MainWindow::fileClose()
408416
resetBrowser();
409417
populateStructure();
410418
loadPragmas();
419+
statusEncryptionLabel->setVisible(false);
411420

412421
// Delete the model for the Browse tab and create a new one
413422
delete m_browseTableModel;

‎src/MainWindow.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class MainWindow : public QMainWindow
7373
QMenu *recentFilesMenu;
7474

7575
QLabel* statusEncodingLabel;
76+
QLabel* statusEncryptionLabel;
7677

7778
SQLiteSyntaxHighlighter* sqliteHighlighterLogUser;
7879
SQLiteSyntaxHighlighter* sqliteHighlighterLogApp;

‎src/sqlitedb.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ bool DBBrowserDB::open(const QString& db)
5454

5555
lastErrorMessage = QObject::tr("no error");
5656

57+
isEncrypted = false;
58+
5759
// Open database file
5860
if(sqlite3_open_v2(db.toUtf8(), &_db, SQLITE_OPEN_READWRITE, NULL) != SQLITE_OK)
5961
{
@@ -78,9 +80,11 @@ bool DBBrowserDB::open(const QString& db)
7880
{
7981
sqlite3_key(_db, cipher.password().toUtf8(), cipher.password().toUtf8().length());
8082
sqlite3_exec(_db, QString("PRAGMA cipher_page_size = %1;").arg(cipher.pageSize()).toUtf8(), NULL, NULL, NULL);
83+
isEncrypted = true;
8184
} else {
8285
sqlite3_close(_db);
8386
_db = 0;
87+
isEncrypted = false;
8488
return false;
8589
}
8690
#else

‎src/sqlitedb.h‎

Lines changed: 3 additions & 0 deletions

0 commit comments

Comments
 (0)