Skip to content

Commit

Permalink
Begins adding settings, begins writing of new XML file
Browse files Browse the repository at this point in the history
  • Loading branch information
dannygb committed Jun 17, 2019
1 parent f875cd4 commit a2f5026
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 6 deletions.
3 changes: 3 additions & 0 deletions KeePit/KeePit.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@
<qresource prefix="/">
<file>qml/PasswordInput.qml</file>
</qresource>
<qresource prefix="/">
<file>qml/Settings.qml</file>
</qresource>
</RCC>
17 changes: 16 additions & 1 deletion KeePit/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <fstream>
#include <string>
#include <QVariant>
#include <QString>
#include <vector>

#include "aes.h"
Expand Down Expand Up @@ -106,7 +107,21 @@ Database::~Database() {
}

void Database::createNewDatabase(QString filePath) {
WriteXmlFile::CreateNewDatabase(filePath);
// Create the XML (the file should also be SALSA'ed)
/*QString db = WriteXmlFile::CreateNewDatabase(filePath);
//GZIP the string
char * cpy = new char[db.size()];
strncpy(cpy, db.toStdString().c_str(), db.size());
CA2GZIP gzip(cpy, db.size());
LPGZIP pgzip = gzip.pgzip; // zipped data pointer
// Generate encryption aes keys and IV
// Encrypt it
//pgzip.
//Save it
*/
}

///
Expand Down
15 changes: 15 additions & 0 deletions KeePit/qml/ListEntryItems.qml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ Page {
}
}

// onCompleted: {
// themeAction.iconName = switchTheme()
// }

// Could be the name of the group
header: PageHeader {
id: pageHeader
Expand All @@ -72,6 +76,15 @@ Page {
}
}
},
Action {
id: themeAction
iconName: ""
text: i18n.tr("Swap")
onTriggered: {
switchTheme()
//iconName = iconName == "torch-off" ? "torch-on" : "torch-off"
}
},
/*Action {
text: i18n.tr("Settings")
iconName: "settings"
Expand Down Expand Up @@ -117,9 +130,11 @@ Page {
width: 40
height: 40
name: getIconName(model)
color: theme.palette.normal.baseText
}
Text {
text: title
color: theme.palette.normal.baseText
}
}

Expand Down
22 changes: 20 additions & 2 deletions KeePit/qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ MainView {
property string keyFileName
property date currentDate: new Date()
property var locale: Qt.locale()

property var selectedDatabaseToDelete: ({});

Database {
Expand All @@ -72,7 +71,10 @@ MainView {

PageStack {
id: pageStack
Component.onCompleted: push(databaseListView)
Component.onCompleted: {
theme.name = settings.getSetting("theme")
push(databaseListView)
}
onCurrentPageChanged: {
if(currentPage != null) {
currentPage.forceActiveFocus()
Expand Down Expand Up @@ -126,6 +128,10 @@ MainView {
CreateDatabase {
id: createDatabase
}

Settings {
id: settings
}
}

/*Component {
Expand Down Expand Up @@ -243,4 +249,16 @@ MainView {
function resetLogoutTimer() {
//resetTimer.restart();
}

function switchTheme() {
theme.name = (theme.name == "Ubuntu.Components.Themes.SuruDark")
? "Ubuntu.Components.Themes.Ambiance"
: "Ubuntu.Components.Themes.SuruDark"

settings.saveSetting("theme", theme.name);

return (theme.name == "Ubuntu.Components.Themes.SuruDark")
? "torch-off"
: "torch-on"
}
}
1 change: 1 addition & 0 deletions KeePit/qml/Selector.qml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ Page {
anchors.leftMargin: units.gu(2)
anchors.rightMargin: units.gu(2)
text: fileName
color: theme.palette.normal.baseText
}

MouseArea {
Expand Down
62 changes: 62 additions & 0 deletions KeePit/qml/Settings.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* This file is part of KeePit
*
* Copyright (C) 2019 Dan Beavon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import QtQuick 2.4
import QtQuick.LocalStorage 2.0

Item {
property var db: null

function openDB() {
if(db !== null) return;

db = LocalStorage.openDatabaseSync(appTitle, "0.1", "KeepIt Password Safe", 100000);

try {
db.transaction(function(tx){
tx.executeSql('CREATE TABLE IF NOT EXISTS settings(key TEXT UNIQUE, value TEXT)');
var table = tx.executeSql("SELECT * FROM settings");
// Seed the table with default values
if (table.rows.length == 0) {
tx.executeSql('INSERT INTO settings VALUES(?, ?)', ["theme", "Ubuntu.Components.Themes.SuruDark"]);
console.log('Settings table added');
};
});
} catch (err) {
console.log("Error creating table in database: " + err);
};
}

function saveSetting(key, value) {
openDB();
db.transaction( function(tx){
tx.executeSql('INSERT OR REPLACE INTO settings VALUES(?, ?)', [key, value]);
});
}

function getSetting(key) {
openDB();
var res = "";
db.transaction(function(tx) {
var rs = tx.executeSql('SELECT value FROM settings WHERE key=?;', [key]);
res = rs.rows.item(0).value;
});
return res;
}
}
9 changes: 7 additions & 2 deletions KeePit/writexmlfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ WriteXmlFile::~WriteXmlFile()
/// \brief WriteXmlFile::ToString
/// \return
///
void WriteXmlFile::CreateNewDatabase(QString filePath)
QString WriteXmlFile::CreateNewDatabase(QString filePath)
{
Base64 base64;

Expand Down Expand Up @@ -288,5 +288,10 @@ void WriteXmlFile::CreateNewDatabase(QString filePath)
lastTopVisibleEntry->SetText(UUID::EMPTYUUIDSTRING);
group->InsertEndChild( lastTopVisibleEntry );

doc.SaveFile( filePath.toLocal8Bit().data() );
//doc.SaveFile( filePath.toLocal8Bit().data() );
XMLPrinter printer;
doc.Accept( &printer );
QString qStr(printer.CStr());

return qStr;
}
2 changes: 1 addition & 1 deletion KeePit/writexmlfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class WriteXmlFile
public:
WriteXmlFile(const char*, size_t, Salsa20*);
~WriteXmlFile();
static void CreateNewDatabase(QString fileName);
static QString CreateNewDatabase(QString fileName);

private:
size_t m_size;
Expand Down

0 comments on commit a2f5026

Please sign in to comment.