almost working

This commit is contained in:
howard-stearns 2018-02-23 16:12:01 -08:00
parent 47b25740de
commit 53614a1d9f
6 changed files with 27 additions and 5 deletions

View file

@ -47,7 +47,7 @@ Rectangle {
} }
} else if (walletStatus === 1) { } else if (walletStatus === 1) {
if (root.activeView !== "walletSetup") { if (root.activeView !== "walletSetup") {
walletSetup(); walletResetSetup();
} }
} else if (walletStatus === 2) { } else if (walletStatus === 2) {
if (root.activeView != "preexisting") { if (root.activeView != "preexisting") {
@ -177,12 +177,13 @@ Rectangle {
proceedFunction: function (isReset) { proceedFunction: function (isReset) {
console.log(isReset ? "Reset wallet." : "Trying again with new wallet."); console.log(isReset ? "Reset wallet." : "Trying again with new wallet.");
if (isReset) { if (isReset) {
walletSetup(); walletResetSetup();
} else { } else {
root.activeView = "initialize"; root.activeView = "initialize";
Commerce.getWalletStatus(); Commerce.getWalletStatus();
} }
} }
copyFunction: Commerce.copyKeyFileFrom;
z: 997; z: 997;
visible: (root.activeView === "preexisting") || (root.activeView === "conflicting"); visible: (root.activeView === "preexisting") || (root.activeView === "conflicting");
activeView: root.activeView; activeView: root.activeView;
@ -789,7 +790,7 @@ Rectangle {
}); });
} }
function walletSetup() { function walletResetSetup() {
root.activeView = "walletSetup"; root.activeView = "walletSetup";
Commerce.resetLocalWalletOnly(); Commerce.resetLocalWalletOnly();
var timestamp = new Date(); var timestamp = new Date();

View file

@ -24,6 +24,7 @@ Item {
id: root; id: root;
property string activeView: "conflict"; property string activeView: "conflict";
property var proceedFunction: nil; property var proceedFunction: nil;
property var copyFunction: nil;
Image { Image {
anchors.fill: parent; anchors.fill: parent;
@ -272,8 +273,11 @@ Item {
console.log('WalletChoice.qml ignoring', e); console.log('WalletChoice.qml ignoring', e);
} }
if (filename) { if (filename) {
console.log("FIXME copy file to the right place"); if (copyFunction && copyFunction(filename)) {
proceed(false); proceed(false);
} else {
console.log("WalletChoice.qml copyFunction", copyFunction, "failed.");
}
} // Else we're still at WalletChoice } // Else we're still at WalletChoice
} }
function walletChooser() { function walletChooser() {

View file

@ -52,6 +52,11 @@ void QmlCommerce::getKeyFilePathIfExists() {
emit keyFilePathIfExistsResult(wallet->getKeyFilePath()); emit keyFilePathIfExistsResult(wallet->getKeyFilePath());
} }
bool QmlCommerce::copyKeyFileFrom(const QString& pathname) {
auto wallet = DependencyManager::get<Wallet>();
return wallet->copyKeyFileFrom(pathname);
}
void QmlCommerce::getWalletAuthenticatedStatus() { void QmlCommerce::getWalletAuthenticatedStatus() {
auto wallet = DependencyManager::get<Wallet>(); auto wallet = DependencyManager::get<Wallet>();
emit walletAuthenticatedStatusResult(wallet->walletIsAuthenticatedWithPassphrase()); emit walletAuthenticatedStatusResult(wallet->walletIsAuthenticatedWithPassphrase());

View file

@ -55,6 +55,7 @@ protected:
Q_INVOKABLE void getKeyFilePathIfExists(); Q_INVOKABLE void getKeyFilePathIfExists();
Q_INVOKABLE void getSecurityImage(); Q_INVOKABLE void getSecurityImage();
Q_INVOKABLE void getWalletAuthenticatedStatus(); Q_INVOKABLE void getWalletAuthenticatedStatus();
Q_INVOKABLE bool copyKeyFileFrom(const QString& pathname);
Q_INVOKABLE void chooseSecurityImage(const QString& imageFile); Q_INVOKABLE void chooseSecurityImage(const QString& imageFile);
Q_INVOKABLE void setPassphrase(const QString& passphrase); Q_INVOKABLE void setPassphrase(const QString& passphrase);

View file

@ -59,6 +59,16 @@ QString keyFilePath() {
auto accountManager = DependencyManager::get<AccountManager>(); auto accountManager = DependencyManager::get<AccountManager>();
return PathUtils::getAppDataFilePath(QString("%1.%2").arg(accountManager->getAccountInfo().getUsername(), KEY_FILE)); return PathUtils::getAppDataFilePath(QString("%1.%2").arg(accountManager->getAccountInfo().getUsername(), KEY_FILE));
} }
bool Wallet::copyKeyFileFrom(const QString& pathname) {
QString existing = getKeyFilePath();
if (!existing.isEmpty()) {
if (!QFile::rename(existing, existing + ".backup" + QDateTime::currentDateTime().toString(Qt::ISODate))) {
qCCritical(commerce) << "Unable to backup" << existing;
return false;
}
}
return QFile::copy(pathname, keyFilePath());
}
// use the cached _passphrase if it exists, otherwise we need to prompt // use the cached _passphrase if it exists, otherwise we need to prompt
int passwordCallback(char* password, int maxPasswordSize, int rwFlag, void* u) { int passwordCallback(char* password, int maxPasswordSize, int rwFlag, void* u) {

View file

@ -35,6 +35,7 @@ public:
void chooseSecurityImage(const QString& imageFile); void chooseSecurityImage(const QString& imageFile);
bool getSecurityImage(); bool getSecurityImage();
QString getKeyFilePath(); QString getKeyFilePath();
bool copyKeyFileFrom(const QString& pathname);
void setSalt(const QByteArray& salt) { _salt = salt; } void setSalt(const QByteArray& salt) { _salt = salt; }
QByteArray getSalt() { return _salt; } QByteArray getSalt() { return _salt; }