Commit de4bb37f authored by Andrea Scarpino's avatar Andrea Scarpino

Store name and algorithm version

parent 72a7536b
......@@ -30,6 +30,15 @@ Page {
allowedOrientations: Orientation.All
Connections {
target: manager
onGeneratedMasterKey: {
site.enabled = true;
password.text = "";
}
}
SilicaFlickable {
anchors.fill: parent
contentHeight: column.height
......@@ -73,6 +82,7 @@ Page {
width: parent.width
inputMethodHints: Qt.ImhUrlCharactersOnly
placeholderText: qsTr("Site name (e.g. google.com)")
enabled: false
EnterKey.enabled: site.text.length > 0 && counter.text.length > 0
EnterKey.onClicked: getPassword()
......@@ -83,6 +93,7 @@ Page {
width: parent.width
text: "1"
inputMethodHints: Qt.ImhDigitsOnly
validator: RegExpValidator { regExp: /^[0-9]+$/ }
placeholderText: qsTr("Counter")
EnterKey.enabled: site.text.length > 0 && counter.text.length > 0
......@@ -113,25 +124,13 @@ Page {
color: Theme.secondaryColor
horizontalAlignment: TextInput.AlignHCenter
wrapMode: Text.Wrap
text: qsTr("Please fill your name and master password in the Settings page!")
}
}
VerticalScrollDecorator {}
}
onStatusChanged: {
if (status === PageStatus.Activating) {
var isReady = manager.getName() !== "";
site.enabled = isReady;
if (!isReady) {
password.text = qsTr("Please fill your name and master password in the Settings page!");
} else {
password.text = "";
}
}
}
function getPassword() {
password.text = manager.getPassword(site.text, type.currentIndex, counter.text);
copy.enabled = true;
......
......@@ -26,6 +26,8 @@ import QtQuick 2.0
import Sailfish.Silica 1.0
Page {
id: page
allowedOrientations: Orientation.All
Connections {
......@@ -39,9 +41,9 @@ Page {
}
Column {
id: column
x: Theme.horizontalPageMargin
width: parent.width - Theme.horizontalPageMargin * 2
spacing: Theme.paddingMedium
PageHeader {
title: qsTr("Settings")
......@@ -50,13 +52,15 @@ Page {
TextField {
id: name
width: parent.width
focus: true
text: manager.getName
focus: text.length === 0
placeholderText: qsTr("Full name")
}
TextField {
id: password
width: parent.width
focus: name.text.length > 0 && text.length === 0
placeholderText: qsTr("Master password")
echoMode: TextInput.Password
}
......@@ -64,7 +68,8 @@ Page {
ComboBox {
id: version
label: qsTr("Algorithm version")
currentIndex: 3
currentIndex: manager.getAlgorithmVersion()
width: page.width
menu: ContextMenu {
MenuItem { text: qsTr("V0") }
......
......@@ -24,19 +24,27 @@
#include "mpwmanager.h"
#include <QCoreApplication>
#include <QDebug>
#include <QSettings>
#include <QThread>
#include "asyncmasterkey.h"
MPWManager::MPWManager(QObject *parent) :
m_key(0), QObject(parent)
QObject(parent)
, m_key(0)
{
m_settings = new QSettings(QCoreApplication::applicationName(), QCoreApplication::applicationName(), this);
m_name = m_settings->value("Name").toString();
m_algVersion = algVersionFromInt(m_settings->value("Algorithm").toUInt());
}
MPWManager::~MPWManager()
{
delete m_key;
delete m_settings;
}
MPWManager::AlgorithmVersion MPWManager::getAlgorithmVersion() const
......@@ -54,11 +62,13 @@ void MPWManager::setAlgorithmVersion(AlgorithmVersion version)
qDebug() << "Using algorithm version:" << version;
m_algVersion = version;
m_settings->setValue("Algorithm", version);
}
void MPWManager::setName(const QString &name)
{
m_name = name;
m_settings->setValue("Name", name);
}
void MPWManager::generateMasterKey(const QString &name, const QString &password, AlgorithmVersion version)
......@@ -79,7 +89,7 @@ void MPWManager::generateMasterKey(const QString &name, const QString &password,
void MPWManager::gotMasterKey(QByteArray *key)
{
qDebug() << "Storing master key.";
qDebug() << "Storing master key";
m_key = key;
Q_EMIT generatedMasterKey();
......@@ -94,7 +104,7 @@ QString MPWManager::getPassword(const QString &site, PasswordType type, const ui
if (p) {
return QString::fromUtf8(p);
} else {
qCritical() << "Error during password generation.";
qCritical() << "Error during password generation";
return QString();
}
}
......@@ -130,3 +140,16 @@ MPSiteType MPWManager::toMPSiteType(PasswordType type)
return t;
}
MPWManager::AlgorithmVersion MPWManager::algVersionFromInt(const uint &version)
{
if (version == 0) {
return V0;
} else if (version == 1) {
return V1;
} else if (version == 2) {
return V2;
} else {
return V3;
}
}
......@@ -35,6 +35,8 @@ extern "C"
#endif
}
class QSettings;
class MPWManager : public QObject
{
Q_OBJECT
......@@ -70,9 +72,12 @@ protected Q_SLOTS:
void gotMasterKey(QByteArray *key);
private:
AlgorithmVersion algVersionFromInt(const uint &version);
QString m_name;
AlgorithmVersion m_algVersion;
QByteArray *m_key;
QSettings *m_settings;
};
#endif // MPWMANAGER_H
......@@ -4,77 +4,77 @@
<context>
<name>MainPage</name>
<message>
<location filename="../qml/pages/MainPage.qml" line="40"/>
<location filename="../qml/pages/MainPage.qml" line="49"/>
<source>Settings</source>
<translation>Impostazioni</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="53"/>
<location filename="../qml/pages/MainPage.qml" line="62"/>
<source>Copy to clipboard</source>
<translation>Copia negli appunti</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="46"/>
<location filename="../qml/pages/MainPage.qml" line="55"/>
<source>Clear</source>
<translation>Cancella</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="75"/>
<location filename="../qml/pages/MainPage.qml" line="84"/>
<source>Site name (e.g. google.com)</source>
<translation>Sito web (google.com, ...)</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="86"/>
<location filename="../qml/pages/MainPage.qml" line="97"/>
<source>Counter</source>
<translation>Contatore</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="95"/>
<location filename="../qml/pages/MainPage.qml" line="106"/>
<source>Password type</source>
<translation>Tipologia password</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="104"/>
<location filename="../qml/pages/MainPage.qml" line="115"/>
<source>PIN</source>
<translation>PIN</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="128"/>
<location filename="../qml/pages/MainPage.qml" line="127"/>
<source>Please fill your name and master password in the Settings page!</source>
<translation>Perfavore immetti il tuo nome e password nella pagina Impostazioni!</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="103"/>
<location filename="../qml/pages/MainPage.qml" line="114"/>
<source>Short</source>
<translation>Corta</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="102"/>
<location filename="../qml/pages/MainPage.qml" line="113"/>
<source>Basic</source>
<translation>Semplice</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="101"/>
<location filename="../qml/pages/MainPage.qml" line="112"/>
<source>Medium</source>
<translation>Media</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="100"/>
<location filename="../qml/pages/MainPage.qml" line="111"/>
<source>Long</source>
<translation>Lunga</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="99"/>
<location filename="../qml/pages/MainPage.qml" line="110"/>
<source>Maximum</source>
<translation>Massima</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="105"/>
<location filename="../qml/pages/MainPage.qml" line="116"/>
<source>Name</source>
<translation>Nome</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="106"/>
<location filename="../qml/pages/MainPage.qml" line="117"/>
<source>Phrase</source>
<translation>Frase</translation>
</message>
......@@ -82,47 +82,47 @@
<context>
<name>Settings</name>
<message>
<location filename="../qml/pages/Settings.qml" line="47"/>
<location filename="../qml/pages/Settings.qml" line="49"/>
<source>Settings</source>
<translation>Impostazioni</translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="54"/>
<location filename="../qml/pages/Settings.qml" line="57"/>
<source>Full name</source>
<translation>Nome completo</translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="60"/>
<location filename="../qml/pages/Settings.qml" line="64"/>
<source>Master password</source>
<translation>Master password</translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="66"/>
<location filename="../qml/pages/Settings.qml" line="70"/>
<source>Algorithm version</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="70"/>
<location filename="../qml/pages/Settings.qml" line="75"/>
<source>V0</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="71"/>
<location filename="../qml/pages/Settings.qml" line="76"/>
<source>V1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="72"/>
<location filename="../qml/pages/Settings.qml" line="77"/>
<source>V2</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="73"/>
<location filename="../qml/pages/Settings.qml" line="78"/>
<source>V3</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="85"/>
<location filename="../qml/pages/Settings.qml" line="90"/>
<source>Save</source>
<translation>Salva</translation>
</message>
......
......@@ -4,77 +4,77 @@
<context>
<name>MainPage</name>
<message>
<location filename="../qml/pages/MainPage.qml" line="40"/>
<location filename="../qml/pages/MainPage.qml" line="49"/>
<source>Settings</source>
<translation>Inställningar</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="53"/>
<location filename="../qml/pages/MainPage.qml" line="62"/>
<source>Copy to clipboard</source>
<translation>Kopiera till urklipp</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="46"/>
<location filename="../qml/pages/MainPage.qml" line="55"/>
<source>Clear</source>
<translation>Rensa</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="75"/>
<location filename="../qml/pages/MainPage.qml" line="84"/>
<source>Site name (e.g. google.com)</source>
<translation>Sidnamn (ex. google.com)</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="86"/>
<location filename="../qml/pages/MainPage.qml" line="97"/>
<source>Counter</source>
<translation>Räknare</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="95"/>
<location filename="../qml/pages/MainPage.qml" line="106"/>
<source>Password type</source>
<translation>Lösenordstyp</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="104"/>
<location filename="../qml/pages/MainPage.qml" line="115"/>
<source>PIN</source>
<translation>PIN</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="128"/>
<location filename="../qml/pages/MainPage.qml" line="127"/>
<source>Please fill your name and master password in the Settings page!</source>
<translation>Ange ditt namn och huvudlösenord i inställningar!</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="103"/>
<location filename="../qml/pages/MainPage.qml" line="114"/>
<source>Short</source>
<translation>Kort</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="102"/>
<location filename="../qml/pages/MainPage.qml" line="113"/>
<source>Basic</source>
<translation>Enkelt</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="101"/>
<location filename="../qml/pages/MainPage.qml" line="112"/>
<source>Medium</source>
<translation>Medium</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="100"/>
<location filename="../qml/pages/MainPage.qml" line="111"/>
<source>Long</source>
<translation>Långt</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="99"/>
<location filename="../qml/pages/MainPage.qml" line="110"/>
<source>Maximum</source>
<translation>Maximalt</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="105"/>
<location filename="../qml/pages/MainPage.qml" line="116"/>
<source>Name</source>
<translation>Namn</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="106"/>
<location filename="../qml/pages/MainPage.qml" line="117"/>
<source>Phrase</source>
<translation>Fras</translation>
</message>
......@@ -82,47 +82,47 @@
<context>
<name>Settings</name>
<message>
<location filename="../qml/pages/Settings.qml" line="47"/>
<location filename="../qml/pages/Settings.qml" line="49"/>
<source>Settings</source>
<translation>Inställningar</translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="54"/>
<location filename="../qml/pages/Settings.qml" line="57"/>
<source>Full name</source>
<translation>Fullständigt namn</translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="60"/>
<location filename="../qml/pages/Settings.qml" line="64"/>
<source>Master password</source>
<translation>Huvudlösenord</translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="66"/>
<location filename="../qml/pages/Settings.qml" line="70"/>
<source>Algorithm version</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="70"/>
<location filename="../qml/pages/Settings.qml" line="75"/>
<source>V0</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="71"/>
<location filename="../qml/pages/Settings.qml" line="76"/>
<source>V1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="72"/>
<location filename="../qml/pages/Settings.qml" line="77"/>
<source>V2</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="73"/>
<location filename="../qml/pages/Settings.qml" line="78"/>
<source>V3</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="85"/>
<location filename="../qml/pages/Settings.qml" line="90"/>
<source>Save</source>
<translation>Spara</translation>
</message>
......
......@@ -4,77 +4,77 @@
<context>
<name>MainPage</name>
<message>
<location filename="../qml/pages/MainPage.qml" line="40"/>
<location filename="../qml/pages/MainPage.qml" line="49"/>
<source>Settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="53"/>
<location filename="../qml/pages/MainPage.qml" line="62"/>
<source>Copy to clipboard</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="46"/>
<location filename="../qml/pages/MainPage.qml" line="55"/>
<source>Clear</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="75"/>
<location filename="../qml/pages/MainPage.qml" line="84"/>
<source>Site name (e.g. google.com)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="86"/>
<location filename="../qml/pages/MainPage.qml" line="97"/>
<source>Counter</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="95"/>
<location filename="../qml/pages/MainPage.qml" line="106"/>
<source>Password type</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="104"/>
<location filename="../qml/pages/MainPage.qml" line="115"/>
<source>PIN</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="128"/>
<location filename="../qml/pages/MainPage.qml" line="127"/>
<source>Please fill your name and master password in the Settings page!</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="103"/>
<location filename="../qml/pages/MainPage.qml" line="114"/>
<source>Short</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="102"/>
<location filename="../qml/pages/MainPage.qml" line="113"/>
<source>Basic</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="101"/>
<location filename="../qml/pages/MainPage.qml" line="112"/>
<source>Medium</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="100"/>
<location filename="../qml/pages/MainPage.qml" line="111"/>
<source>Long</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="99"/>
<location filename="../qml/pages/MainPage.qml" line="110"/>
<source>Maximum</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="105"/>
<location filename="../qml/pages/MainPage.qml" line="116"/>
<source>Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="106"/>
<location filename="../qml/pages/MainPage.qml" line="117"/>
<source>Phrase</source>
<translation type="unfinished"></translation>
</message>
......@@ -82,47 +82,47 @@
<context>
<name>Settings</name>
<message>
<location filename="../qml/pages/Settings.qml" line="47"/>
<location filename="../qml/pages/Settings.qml" line="49"/>
<source>Settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="54"/>
<location filename="../qml/pages/Settings.qml" line="57"/>
<source>Full name</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="60"/>
<location filename="../qml/pages/Settings.qml" line="64"/>
<source>Master password</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="66"/>
<location filename="../qml/pages/Settings.qml" line="70"/>
<source>Algorithm version</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="70"/>
<location filename="../qml/pages/Settings.qml" line="75"/>
<source>V0</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="71"/>
<location filename="../qml/pages/Settings.qml" line="76"/>
<source>V1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="72"/>
<location filename="../qml/pages/Settings.qml" line="77"/>
<source>V2</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="73"/>
<location filename="../qml/pages/Settings.qml" line="78"/>
<source>V3</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="85"/>
<location filename="../qml/pages/Settings.qml" line="90"/>
<source>Save</source>
<translation type="unfinished"></translation>
</message>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment