From 6289e18f6cf7cc7c85c799940099b90081273c4c Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 3 Feb 2016 16:37:10 +0100 Subject: fix for window drag bug on ubuntu, only tested on windows --- main.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index b1bd1a72..ecc8b626 100644 --- a/main.cpp +++ b/main.cpp @@ -31,6 +31,7 @@ #include #include "clipboardAdapter.h" #include "filter.h" +#include "oscursor.h" int main(int argc, char *argv[]) { @@ -41,6 +42,10 @@ int main(int argc, char *argv[]) qmlRegisterType("moneroComponents", 1, 0, "Clipboard"); QQmlApplicationEngine engine; + + OSCursor cursor; + engine.rootContext()->setContextProperty("globalCursor", &cursor); + engine.rootContext()->setContextProperty("applicationDirectory", QApplication::applicationDirPath()); engine.load(QUrl(QStringLiteral("qrc:///main.qml"))); QObject *rootObject = engine.rootObjects().first(); -- cgit v1.2.3 From e555631b40972b0264962f5bbd780ddd3aef5a7c Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Mon, 8 Feb 2016 10:58:01 +0300 Subject: wallet directrory in "Documents" for Windows and in "home" for *nix --- main.cpp | 15 +++++++++++++++ wizard/WizardManageWalletUI.qml | 6 ++++-- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index ecc8b626..af429df3 100644 --- a/main.cpp +++ b/main.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include "clipboardAdapter.h" #include "filter.h" #include "oscursor.h" @@ -46,6 +47,20 @@ int main(int argc, char *argv[]) OSCursor cursor; engine.rootContext()->setContextProperty("globalCursor", &cursor); +// export to QML monero accounts root directory +// wizard is talking about where +// to save the wallet file (.keys, .bin), they have to be user-accessible for +// backups - I reckon we save that in My Documents\Monero Accounts\ on +// Windows, ~/Monero Accounts/ on nix / osx +#ifdef Q_OS_WIN + QStringList moneroAccountsRootDir = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation); +#elif defined(Q_OS_UNIX) + QStringList moneroAccountsRootDir = QStandardPaths::standardLocations(QStandardPaths::HomeLocation); +#endif + if (!moneroAccountsRootDir.empty()) { + engine.rootContext()->setContextProperty("moneroAccountsDir", moneroAccountsRootDir.at(0) + "/Monero Accounts"); + } + engine.rootContext()->setContextProperty("applicationDirectory", QApplication::applicationDirPath()); engine.load(QUrl(QStringLiteral("qrc:///main.qml"))); QObject *rootObject = engine.rootObjects().first(); diff --git a/wizard/WizardManageWalletUI.qml b/wizard/WizardManageWalletUI.qml index 651c7081..6ea9ea44 100644 --- a/wizard/WizardManageWalletUI.qml +++ b/wizard/WizardManageWalletUI.qml @@ -204,10 +204,12 @@ Item { color: "#6B0072" verticalAlignment: Text.AlignVCenter selectByMouse: true - text: "~/.monero/mywallet/" + + text: moneroAccountsDir + "/My Wallet" onFocusChanged: { if(focus) { - fileDialog.visible = true + fileDialog.folder = text + fileDialog.open() } } } -- cgit v1.2.3 From 1195a89d06956dd91f274182b07774dae8a1c0d2 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Tue, 23 Feb 2016 18:59:26 +0300 Subject: started integrating wallet library --- Wallet.cpp | 6 ++++++ Wallet.h | 17 +++++++++++++++++ Wallet2Service.cpp | 6 ++++++ Wallet2Service.h | 17 +++++++++++++++++ WalletManager.cpp | 6 ++++++ WalletManager.h | 17 +++++++++++++++++ lang/languages.xml | 22 +++++++++++----------- main.cpp | 5 +++++ monero-core.pro | 13 +++++++++++-- wizard/WizardCreateWallet.qml | 7 ++++++- wizard/WizardMain.qml | 2 ++ wizard/WizardMemoTextInput.qml | 2 +- 12 files changed, 105 insertions(+), 15 deletions(-) create mode 100644 Wallet.cpp create mode 100644 Wallet.h create mode 100644 Wallet2Service.cpp create mode 100644 Wallet2Service.h create mode 100644 WalletManager.cpp create mode 100644 WalletManager.h (limited to 'main.cpp') diff --git a/Wallet.cpp b/Wallet.cpp new file mode 100644 index 00000000..89e448fd --- /dev/null +++ b/Wallet.cpp @@ -0,0 +1,6 @@ +#include "Wallet.h" + +Wallet::Wallet(QObject *parent) : QObject(parent) +{ + +} diff --git a/Wallet.h b/Wallet.h new file mode 100644 index 00000000..130712e6 --- /dev/null +++ b/Wallet.h @@ -0,0 +1,17 @@ +#ifndef WALLET_H +#define WALLET_H + +#include + +class Wallet : public QObject +{ + Q_OBJECT +public: + explicit Wallet(QObject *parent = 0); + +signals: + +public slots: +}; + +#endif // WALLET_H \ No newline at end of file diff --git a/Wallet2Service.cpp b/Wallet2Service.cpp new file mode 100644 index 00000000..9637d31a --- /dev/null +++ b/Wallet2Service.cpp @@ -0,0 +1,6 @@ +#include "Wallet2Service.h" + +Wallet2Service::Wallet2Service(QObject *parent) : QObject(parent) +{ + +} diff --git a/Wallet2Service.h b/Wallet2Service.h new file mode 100644 index 00000000..9ed5ad9b --- /dev/null +++ b/Wallet2Service.h @@ -0,0 +1,17 @@ +#ifndef WALLET2SERVICE_H +#define WALLET2SERVICE_H + +#include + +class Wallet2Service : public QObject +{ + Q_OBJECT +public: + explicit Wallet2Service(QObject *parent = 0); + +signals: + +public slots: +}; + +#endif // WALLET2SERVICE_H \ No newline at end of file diff --git a/WalletManager.cpp b/WalletManager.cpp new file mode 100644 index 00000000..7812ed34 --- /dev/null +++ b/WalletManager.cpp @@ -0,0 +1,6 @@ +#include "WalletManager.h" + +WalletManager::WalletManager(QObject *parent) : QObject(parent) +{ + +} diff --git a/WalletManager.h b/WalletManager.h new file mode 100644 index 00000000..b6153385 --- /dev/null +++ b/WalletManager.h @@ -0,0 +1,17 @@ +#ifndef WALLETMANAGER_H +#define WALLETMANAGER_H + +#include + +class WalletManager : public QObject +{ + Q_OBJECT +public: + explicit WalletManager(QObject *parent = 0); + +signals: + +public slots: +}; + +#endif // WALLETMANAGER_H \ No newline at end of file diff --git a/lang/languages.xml b/lang/languages.xml index eacfcad5..efb84c9c 100644 --- a/lang/languages.xml +++ b/lang/languages.xml @@ -1,13 +1,13 @@ - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + diff --git a/main.cpp b/main.cpp index af429df3..e3917f80 100644 --- a/main.cpp +++ b/main.cpp @@ -33,6 +33,9 @@ #include "clipboardAdapter.h" #include "filter.h" #include "oscursor.h" +#include "WalletManager.h" +#include "Wallet.h" + int main(int argc, char *argv[]) { @@ -41,11 +44,13 @@ int main(int argc, char *argv[]) app.installEventFilter(eventFilter); qmlRegisterType("moneroComponents", 1, 0, "Clipboard"); + qmlRegisterType("moneroWallet", 1, 0, "Wallet"); QQmlApplicationEngine engine; OSCursor cursor; engine.rootContext()->setContextProperty("globalCursor", &cursor); + engine.rootContext()->setContextProperty("walletManager", WalletManager::instance()); // export to QML monero accounts root directory // wizard is talking about where diff --git a/monero-core.pro b/monero-core.pro index dc2a500a..f021449c 100644 --- a/monero-core.pro +++ b/monero-core.pro @@ -2,16 +2,22 @@ TEMPLATE = app QT += qml quick widgets + HEADERS += \ filter.h \ clipboardAdapter.h \ - oscursor.h + oscursor.h \ + Wallet2Adaptor.h \ + WalletManager.h \ + Wallet.h SOURCES += main.cpp \ filter.cpp \ clipboardAdapter.cpp \ - oscursor.cpp + oscursor.cpp \ + WalletManager.cpp \ + Wallet.cpp lupdate_only { SOURCES = *.qml \ @@ -63,6 +69,9 @@ OTHER_FILES += \ monero-core_de.ts \ monero-core_en.ts +DISTFILES += \ + notes.txt + diff --git a/wizard/WizardCreateWallet.qml b/wizard/WizardCreateWallet.qml index 65e2e989..8ce4e760 100644 --- a/wizard/WizardCreateWallet.qml +++ b/wizard/WizardCreateWallet.qml @@ -46,6 +46,12 @@ Item { settingsObject['wallet_path'] = uiItem.walletPath } + function createWallet(settingsObject) { + // print ("Language: " + settingsObject.language); + var wallet = walletManager.createWallet(uiItem.accountNameText, "", settingsObject.language); + uiItem.wordsTextItem.memoText = wallet.seed + } + WizardManageWalletUI { id: uiItem titleText: qsTr("A new wallet has been created for you") @@ -53,6 +59,5 @@ Item { wordsTextItem.clipboardButtonVisible: true wordsTextItem.tipTextVisible: true wordsTextItem.memoTextReadOnly: true - } } diff --git a/wizard/WizardMain.qml b/wizard/WizardMain.qml index eeefbf17..5f51cec8 100644 --- a/wizard/WizardMain.qml +++ b/wizard/WizardMain.qml @@ -99,7 +99,9 @@ Rectangle { currentPath = "create_wallet" pages = paths[currentPath] currentPage = pages.indexOf(createWalletPage) + createWalletPage.createWallet(settings) handlePageChanged() + } function openRecoveryWalletPage() { diff --git a/wizard/WizardMemoTextInput.qml b/wizard/WizardMemoTextInput.qml index 89eadb15..39f9211b 100644 --- a/wizard/WizardMemoTextInput.qml +++ b/wizard/WizardMemoTextInput.qml @@ -25,7 +25,7 @@ Column { TextEdit { id: memoTextInput textMargin: 8 - text: "bound class paint gasp task soul forgot past pleasure physical circle appear shore bathroom glove women crap busy beauty bliss idea give needle burden" + text: "" font.family: "Arial" font.pointSize: 16 wrapMode: TextInput.Wrap -- cgit v1.2.3 From 625041df1823f2ce98b53fa054bab47876717c15 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Wed, 24 Feb 2016 13:25:20 +0300 Subject: integrating cpp wallet mockups with QML --- Wallet.cpp | 27 ++++++++++++- Wallet.h | 18 +++++++-- Wallet2Service.cpp | 6 --- Wallet2Service.h | 17 -------- WalletManager.cpp | 87 +++++++++++++++++++++++++++++++++++++++++ WalletManager.h | 15 ++++++- main.cpp | 7 +++- monero-core.pro | 1 - wizard/WizardCreateWallet.qml | 23 +++++++++-- wizard/WizardMain.qml | 2 + wizard/WizardManageWalletUI.qml | 5 ++- 11 files changed, 172 insertions(+), 36 deletions(-) delete mode 100644 Wallet2Service.cpp delete mode 100644 Wallet2Service.h (limited to 'main.cpp') diff --git a/Wallet.cpp b/Wallet.cpp index 89e448fd..5507f531 100644 --- a/Wallet.cpp +++ b/Wallet.cpp @@ -1,6 +1,31 @@ #include "Wallet.h" -Wallet::Wallet(QObject *parent) : QObject(parent) +struct WalletImpl { + // TODO +}; + + +Wallet::Wallet(QObject *parent) + : QObject(parent) +{ + +} + + +QString Wallet::getSeed() const +{ + return "bound class paint gasp task soul forgot past pleasure physical circle " + " appear shore bathroom glove women crap busy beauty bliss idea give needle burden"; +} + +QString Wallet::getSeedLanguage() const +{ + return "English"; +} + +void Wallet::setSeedLaguage(const QString &lang) +{ + // TODO; } diff --git a/Wallet.h b/Wallet.h index 130712e6..14018a66 100644 --- a/Wallet.h +++ b/Wallet.h @@ -3,15 +3,27 @@ #include +struct WalletImpl; + class Wallet : public QObject { Q_OBJECT + Q_PROPERTY(QString seed READ getSeed) public: explicit Wallet(QObject *parent = 0); - + QString getSeed() const; + QString getSeedLanguage() const; + void setSeedLaguage(const QString &lang); signals: - public slots: + +private: + + + friend class WalletManager; + WalletImpl * m_pimpl; + + }; -#endif // WALLET_H \ No newline at end of file +#endif // WALLET_H diff --git a/Wallet2Service.cpp b/Wallet2Service.cpp deleted file mode 100644 index 9637d31a..00000000 --- a/Wallet2Service.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "Wallet2Service.h" - -Wallet2Service::Wallet2Service(QObject *parent) : QObject(parent) -{ - -} diff --git a/Wallet2Service.h b/Wallet2Service.h deleted file mode 100644 index 9ed5ad9b..00000000 --- a/Wallet2Service.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef WALLET2SERVICE_H -#define WALLET2SERVICE_H - -#include - -class Wallet2Service : public QObject -{ - Q_OBJECT -public: - explicit Wallet2Service(QObject *parent = 0); - -signals: - -public slots: -}; - -#endif // WALLET2SERVICE_H \ No newline at end of file diff --git a/WalletManager.cpp b/WalletManager.cpp index 7812ed34..992dfa4d 100644 --- a/WalletManager.cpp +++ b/WalletManager.cpp @@ -1,6 +1,93 @@ #include "WalletManager.h" +#include "Wallet.h" +#include +#include +#include +#include +#include + +WalletManager * WalletManager::m_instance = nullptr; + + +namespace { + bool createFileWrapper(const QString &filename) + { + QFile file(filename); + // qDebug("%s: about to create file: %s", __FUNCTION__, qPrintable(filename)); + bool result = file.open(QIODevice::WriteOnly); + if (!result ){ + qWarning("%s: error creating file '%s' : '%s'", + __FUNCTION__, + qPrintable(filename), + qPrintable(file.errorString())); + } + return result; + } +} + + +WalletManager *WalletManager::instance() +{ + if (!m_instance) { + m_instance = new WalletManager; + } + + return m_instance; +} + +Wallet *WalletManager::createWallet(const QString &path, const QString &password, + const QString &language) +{ + Wallet * wallet = new Wallet(this); + // Create dummy files for testing + QFileInfo fi(path); + QDir tempDir; + tempDir.mkpath(fi.absolutePath()); + createFileWrapper(path); + createFileWrapper(path + ".keys"); + createFileWrapper(path + ".address.txt"); + return wallet; +} + +Wallet *WalletManager::openWallet(const QString &path, const QString &language) +{ + return nullptr; +} + +bool WalletManager::moveWallet(const QString &src, const QString &dst_) +{ + QFile walletFile(src); + if (!walletFile.exists()) { + qWarning("%s: source file [%s] doesn't exits", __FUNCTION__, + qPrintable(src)); + return false; + } + QString dst = QUrl(dst_).toLocalFile(); + QString walletKeysFile = src + ".keys"; + QString walletAddressFile = src + ".address.txt"; + + QString dstWalletKeysFile = dst + ".keys"; + QString dstWalletAddressFile = dst + ".address.txt"; + + if (!walletFile.rename(dst)) { + qWarning("Error renaming file: '%s' to '%s' : (%s)", + qPrintable(src), + qPrintable(dst), + qPrintable(walletFile.errorString())); + return false; + } + QFile::rename(walletKeysFile, dstWalletKeysFile); + QFile::rename(walletAddressFile, dstWalletAddressFile); + + return QFile::exists(dst) && QFile::exists(dstWalletKeysFile) + && QFile::exists(dstWalletAddressFile); + + +} WalletManager::WalletManager(QObject *parent) : QObject(parent) { } + + diff --git a/WalletManager.h b/WalletManager.h index b6153385..ffb498d7 100644 --- a/WalletManager.h +++ b/WalletManager.h @@ -3,15 +3,26 @@ #include +class Wallet; + class WalletManager : public QObject { Q_OBJECT public: - explicit WalletManager(QObject *parent = 0); + static WalletManager * instance(); + Q_INVOKABLE Wallet * createWallet(const QString &path, const QString &password, + const QString &language); + Q_INVOKABLE Wallet * openWallet(const QString &path, const QString &language); + Q_INVOKABLE bool moveWallet(const QString &src, const QString &dst); signals: public slots: + +private: + explicit WalletManager(QObject *parent = 0); + static WalletManager * m_instance; + }; -#endif // WALLETMANAGER_H \ No newline at end of file +#endif // WALLETMANAGER_H diff --git a/main.cpp b/main.cpp index e3917f80..0e996b84 100644 --- a/main.cpp +++ b/main.cpp @@ -57,13 +57,18 @@ int main(int argc, char *argv[]) // to save the wallet file (.keys, .bin), they have to be user-accessible for // backups - I reckon we save that in My Documents\Monero Accounts\ on // Windows, ~/Monero Accounts/ on nix / osx + #ifdef Q_OS_WIN QStringList moneroAccountsRootDir = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation); #elif defined(Q_OS_UNIX) QStringList moneroAccountsRootDir = QStandardPaths::standardLocations(QStandardPaths::HomeLocation); #endif + if (!moneroAccountsRootDir.empty()) { - engine.rootContext()->setContextProperty("moneroAccountsDir", moneroAccountsRootDir.at(0) + "/Monero Accounts"); + QString moneroAccountsDir = moneroAccountsRootDir.at(0) + "/Monero Accounts"; + QDir tempDir; + tempDir.mkpath(moneroAccountsDir); + engine.rootContext()->setContextProperty("moneroAccountsDir", moneroAccountsDir); } engine.rootContext()->setContextProperty("applicationDirectory", QApplication::applicationDirPath()); diff --git a/monero-core.pro b/monero-core.pro index f021449c..bee7eb17 100644 --- a/monero-core.pro +++ b/monero-core.pro @@ -7,7 +7,6 @@ HEADERS += \ filter.h \ clipboardAdapter.h \ oscursor.h \ - Wallet2Adaptor.h \ WalletManager.h \ Wallet.h diff --git a/wizard/WizardCreateWallet.qml b/wizard/WizardCreateWallet.qml index 8ce4e760..91b7447e 100644 --- a/wizard/WizardCreateWallet.qml +++ b/wizard/WizardCreateWallet.qml @@ -44,12 +44,29 @@ Item { settingsObject['account_name'] = uiItem.accountNameText settingsObject['words'] = uiItem.wordsTexttext settingsObject['wallet_path'] = uiItem.walletPath + + + var new_wallet_filename = settingsObject.wallet_path + "/" + + settingsObject.account_name; + + // moving wallet files to the new destination, if user changed it + if (new_wallet_filename !== settingsObject.wallet_filename) { + walletManager.moveWallet(settingsObject.wallet_filename, new_wallet_filename); + } } function createWallet(settingsObject) { - // print ("Language: " + settingsObject.language); - var wallet = walletManager.createWallet(uiItem.accountNameText, "", settingsObject.language); - uiItem.wordsTextItem.memoText = wallet.seed + var wallet_filename = uiItem.walletPath + "/" + uiItem.accountNameText + if (typeof settingsObject.wallet === 'undefined') { + var wallet = walletManager.createWallet(wallet_filename, "", settingsObject.language) + uiItem.wordsTextItem.memoText = wallet.seed + // saving wallet in "global" settings object + // TODO: wallet should have a property pointing to the file where it stored or loaded from + settingsObject.wallet = wallet + } else { + print("wallet already created. we just stepping back"); + } + settingsObject.wallet_filename = wallet_filename } WizardManageWalletUI { diff --git a/wizard/WizardMain.qml b/wizard/WizardMain.qml index 5f51cec8..51e0baf3 100644 --- a/wizard/WizardMain.qml +++ b/wizard/WizardMain.qml @@ -67,6 +67,7 @@ Rectangle { function handlePageChanged() { var nextButtonVisible = pages[currentPage] !== optionsPage; nextButton.visible = nextButtonVisible; + print ("next button visible: " + nextButtonVisible); switch (pages[currentPage]) { case passwordPage: // disable "next" button until passwords match @@ -87,6 +88,7 @@ Rectangle { // nextButton.enabled = false; break default: + nextButton.enabled = true } diff --git a/wizard/WizardManageWalletUI.qml b/wizard/WizardManageWalletUI.qml index 6ea9ea44..ce035f0a 100644 --- a/wizard/WizardManageWalletUI.qml +++ b/wizard/WizardManageWalletUI.qml @@ -183,9 +183,10 @@ Item { FileDialog { id: fileDialog selectMultiple: false - title: "Please choose a file" + selectFolder: true + title: "Please choose a directory" onAccepted: { - fileUrlInput.text = fileDialog.fileUrl + fileUrlInput.text = fileDialog.folder fileDialog.visible = false } onRejected: { -- cgit v1.2.3 From 493e290956453ad068aa43b9a2fbefacd3550192 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Fri, 3 Jun 2016 17:30:19 +0300 Subject: libwallet integration --- Wallet.cpp | 194 -------------------------------------- Wallet.h | 44 --------- WalletManager.cpp | 116 ----------------------- WalletManager.h | 48 ---------- main.cpp | 3 +- monero-core.pro | 11 ++- src/libwalletqt/Wallet.cpp | 194 ++++++++++++++++++++++++++++++++++++++ src/libwalletqt/Wallet.h | 44 +++++++++ src/libwalletqt/WalletManager.cpp | 116 +++++++++++++++++++++++ src/libwalletqt/WalletManager.h | 48 ++++++++++ 10 files changed, 410 insertions(+), 408 deletions(-) delete mode 100644 Wallet.cpp delete mode 100644 Wallet.h delete mode 100644 WalletManager.cpp delete mode 100644 WalletManager.h create mode 100644 src/libwalletqt/Wallet.cpp create mode 100644 src/libwalletqt/Wallet.h create mode 100644 src/libwalletqt/WalletManager.cpp create mode 100644 src/libwalletqt/WalletManager.h (limited to 'main.cpp') diff --git a/Wallet.cpp b/Wallet.cpp deleted file mode 100644 index 61998ab5..00000000 --- a/Wallet.cpp +++ /dev/null @@ -1,194 +0,0 @@ -#include "Wallet.h" -#include -#include -#include -#include - -namespace { - QString TEST_SEED = "bound class paint gasp task soul forgot past pleasure physical circle " - " appear shore bathroom glove women crap busy beauty bliss idea give needle burden"; - - namespace { - bool createFileWrapper(const QString &filename) - { - QFile file(filename); - // qDebug("%s: about to create file: %s", __FUNCTION__, qPrintable(filename)); - bool result = file.open(QIODevice::WriteOnly); - if (!result ){ - qWarning("%s: error creating file '%s' : '%s'", - __FUNCTION__, - qPrintable(filename), - qPrintable(file.errorString())); - } - return result; - } - } - -} - -struct WalletImpl -{ - - QString basename() const; - void setBasename(const QString &name); - - QString keysName() const; - QString addressName() const; - -// Bitmonero::Wallet * m_walletImpl; - QString m_basename; - QString m_seed; - QString m_password; - QString m_language; - - static QString keysName(const QString &basename); - static QString addressName(const QString &basename); - -}; - - -QString WalletImpl::basename() const -{ - return m_basename; -} - -void WalletImpl::setBasename(const QString &name) -{ - m_basename = name; -} - -QString WalletImpl::keysName() const -{ - return keysName(m_basename); -} - -QString WalletImpl::addressName() const -{ - return addressName(m_basename); -} - -QString WalletImpl::keysName(const QString &basename) -{ - return basename + ".keys"; -} - -QString WalletImpl::addressName(const QString &basename) -{ - return basename + ".address.txt"; -} - - -Wallet::Wallet(QObject *parent) - : QObject(parent) -{ - -} - -QString Wallet::getSeed() const -{ - return m_pimpl->m_seed; -} - -QString Wallet::getSeedLanguage() const -{ - return "English"; -} - -//void Wallet::setSeedLaguage(const QString &lang) -//{ -// // TODO: call libwallet's appropriate method -//} - -bool Wallet::setPassword(const QString &password) -{ - // set/change password implies: - // recovery wallet with existing path, seed and lang - qDebug("%s: recovering wallet with path=%s, seed=%s, lang=%s and new password=%s", - __FUNCTION__, - qPrintable(this->getBasename()), - qPrintable(this->getSeed()), - qPrintable(this->getSeedLanguage()), - qPrintable(password)); - return true; -} - -QString Wallet::getPassword() const -{ - return m_pimpl->m_password; -} - -bool Wallet::rename(const QString &name) -{ - - QString dst = QUrl(name).toLocalFile(); - - if (dst.isEmpty()) - dst = name; - - qDebug("%s: renaming '%s' to '%s'", - __FUNCTION__, - qPrintable(m_pimpl->basename()), - qPrintable(dst)); - - QString walletKeysFile = m_pimpl->keysName(); - QString walletAddressFile = m_pimpl->addressName(); - - QString dstWalletKeysFile = WalletImpl::keysName(dst); - QString dstWalletAddressFile = WalletImpl::addressName(dst); - - QFile walletFile(this->getBasename()); - - if (!walletFile.rename(dst)) { - qWarning("Error renaming file: '%s' to '%s' : (%s)", - qPrintable(m_pimpl->basename()), - qPrintable(dst), - qPrintable(walletFile.errorString())); - return false; - } - QFile::rename(walletKeysFile, dstWalletKeysFile); - QFile::rename(walletAddressFile, dstWalletAddressFile); - - bool result = QFile::exists(dst) && QFile::exists(dstWalletKeysFile) - && QFile::exists(dstWalletAddressFile); - - if (result) { - m_pimpl->m_basename = dst; - } - - return result; -} - -QString Wallet::getBasename() const -{ - return m_pimpl->basename(); -} - -int Wallet::error() const -{ - return 0; -} - -QString Wallet::errorString() const -{ - return m_pimpl->m_seed; -} - -Wallet::Wallet(const QString &path, const QString &password, const QString &language) -{ - m_pimpl = new WalletImpl; - m_pimpl->m_basename = path; - m_pimpl->m_password = password; - m_pimpl->m_language = language; - m_pimpl->m_seed = TEST_SEED; - - // Create dummy files for testing - QFileInfo fi(path); - QDir tempDir; - tempDir.mkpath(fi.absolutePath()); - createFileWrapper(m_pimpl->basename()); - createFileWrapper(m_pimpl->keysName()); - createFileWrapper(m_pimpl->addressName()); -} - - - diff --git a/Wallet.h b/Wallet.h deleted file mode 100644 index 221d3d43..00000000 --- a/Wallet.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef WALLET_H -#define WALLET_H - -#include - -struct WalletImpl; -class Wallet : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString seed READ getSeed) -public: - explicit Wallet(QObject *parent = 0); - - //! returns mnemonic seed - Q_INVOKABLE QString getSeed() const; - - //! returns seed language - Q_INVOKABLE QString getSeedLanguage() const; - - - //! changes the password using existing parameters (path, seed, seed lang) - Q_INVOKABLE bool setPassword(const QString &password); - //! returns curret wallet password - Q_INVOKABLE QString getPassword() const; - - //! renames/moves wallet files - Q_INVOKABLE bool rename(const QString &name); - - //! returns current wallet name (basename, as wallet consists of several files) - Q_INVOKABLE QString getBasename() const; - - Q_INVOKABLE int error() const; - Q_INVOKABLE QString errorString() const; - -private: - Wallet(const QString &path, const QString &password, const QString &language); - -private: - friend class WalletManager; - //! pimpl wrapper for libwallet; - WalletImpl * m_pimpl; -}; - -#endif // WALLET_H diff --git a/WalletManager.cpp b/WalletManager.cpp deleted file mode 100644 index cb0ffbac..00000000 --- a/WalletManager.cpp +++ /dev/null @@ -1,116 +0,0 @@ -#include "WalletManager.h" -#include "Wallet.h" -#include "wallet/wallet2_api.h" -#include -#include -#include -#include -#include - -WalletManager * WalletManager::m_instance = nullptr; - - - - - -WalletManager *WalletManager::instance() -{ - if (!m_instance) { - m_instance = new WalletManager; - } - // Checking linkage (doesn't work, TODO: have every dependencies linked statically into libwallet) - Bitmonero::WalletManager * wallet_manager_impl = Bitmonero::WalletManagerFactory::getWalletManager(); - - return m_instance; -} - -Wallet *WalletManager::createWallet(const QString &path, const QString &password, - const QString &language) -{ - QFileInfo fi(path); - if (fi.exists()) { - qCritical("%s: already exists", __FUNCTION__); - // TODO: set error and error string - // return nullptr; - } - Wallet * wallet = new Wallet(path, password, language); - return wallet; -} - -Wallet *WalletManager::openWallet(const QString &path, const QString &language, const QString &password) -{ - QFileInfo fi(path); - if (fi.exists()) { - qCritical("%s: not exists", __FUNCTION__); - // TODO: set error and error string - // return nullptr; - } - // TODO: call the libwallet api here; - Wallet * wallet = new Wallet(path, password, language); - - return wallet; -} - -Wallet *WalletManager::recoveryWallet(const QString &path, const QString &memo, const QString &language) -{ - // TODO: call the libwallet api here; - - return nullptr; -} - -bool WalletManager::moveWallet(const QString &src, const QString &dst_) -{ - // TODO: move this to libwallet; - QFile walletFile(src); - if (!walletFile.exists()) { - qWarning("%s: source file [%s] doesn't exits", __FUNCTION__, - qPrintable(src)); - return false; - } - QString dst = QUrl(dst_).toLocalFile(); - QString walletKeysFile = src + ".keys"; - QString walletAddressFile = src + ".address.txt"; - - QString dstWalletKeysFile = dst + ".keys"; - QString dstWalletAddressFile = dst + ".address.txt"; - - if (!walletFile.rename(dst)) { - qWarning("Error renaming file: '%s' to '%s' : (%s)", - qPrintable(src), - qPrintable(dst), - qPrintable(walletFile.errorString())); - return false; - } - QFile::rename(walletKeysFile, dstWalletKeysFile); - QFile::rename(walletAddressFile, dstWalletAddressFile); - - return QFile::exists(dst) && QFile::exists(dstWalletKeysFile) - && QFile::exists(dstWalletAddressFile); -} - -void WalletManager::closeWallet(Wallet *wallet) -{ - delete wallet; -} - -QString WalletManager::walletLanguage(const QString &locale) -{ - return "English"; -} - -int WalletManager::error() const -{ - return 0; -} - -QString WalletManager::errorString() const -{ - return tr("Unknown error"); -} - -WalletManager::WalletManager(QObject *parent) : QObject(parent) -{ - -} - - diff --git a/WalletManager.h b/WalletManager.h deleted file mode 100644 index 231f104c..00000000 --- a/WalletManager.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef WALLETMANAGER_H -#define WALLETMANAGER_H - -#include - -class Wallet; - -class WalletManager : public QObject -{ - Q_OBJECT -public: - static WalletManager * instance(); - // wizard: createWallet path; - Q_INVOKABLE Wallet * createWallet(const QString &path, const QString &password, - const QString &language); - // just for future use - Q_INVOKABLE Wallet * openWallet(const QString &path, const QString &language, - const QString &password); - - // wizard: recoveryWallet path; hint: internally it recorvers wallet and set password = "" - Q_INVOKABLE Wallet * recoveryWallet(const QString &path, const QString &memo, - const QString &language); - - // wizard: both "create" and "recovery" paths. - // TODO: probably move it to "Wallet" interface - Q_INVOKABLE bool moveWallet(const QString &src, const QString &dst); - - //! utils: close wallet to free memory - Q_INVOKABLE void closeWallet(Wallet * wallet); - - //! returns libwallet language name for given locale - Q_INVOKABLE QString walletLanguage(const QString &locale); - - //! returns last error happened in WalletManager - Q_INVOKABLE int error() const; - - //! returns error description in human language - Q_INVOKABLE QString errorString() const; -signals: - -public slots: - -private: - explicit WalletManager(QObject *parent = 0); - static WalletManager * m_instance; -}; - -#endif // WALLETMANAGER_H diff --git a/main.cpp b/main.cpp index 0e996b84..b486c5f0 100644 --- a/main.cpp +++ b/main.cpp @@ -44,7 +44,8 @@ int main(int argc, char *argv[]) app.installEventFilter(eventFilter); qmlRegisterType("moneroComponents", 1, 0, "Clipboard"); - qmlRegisterType("moneroWallet", 1, 0, "Wallet"); + //qmlRegisterType("moneroWallet", 1, 0, "Wallet"); + qmlRegisterType(); QQmlApplicationEngine engine; diff --git a/monero-core.pro b/monero-core.pro index 4b071fb1..7b05829f 100644 --- a/monero-core.pro +++ b/monero-core.pro @@ -6,23 +6,24 @@ WALLET_ROOT=$$PWD/bitmonero CONFIG += c++11 -INCLUDEPATH += $$WALLET_ROOT/include +INCLUDEPATH += $$WALLET_ROOT/include \ + $$PWD/src/libwalletqt HEADERS += \ filter.h \ clipboardAdapter.h \ oscursor.h \ - WalletManager.h \ - Wallet.h + src/libwalletqt/WalletManager.h \ + src/libwalletqt/Wallet.h SOURCES += main.cpp \ filter.cpp \ clipboardAdapter.cpp \ oscursor.cpp \ - WalletManager.cpp \ - Wallet.cpp + src/libwalletqt/WalletManager.cpp \ + src/libwalletqt/Wallet.cpp lupdate_only { SOURCES = *.qml \ diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp new file mode 100644 index 00000000..61998ab5 --- /dev/null +++ b/src/libwalletqt/Wallet.cpp @@ -0,0 +1,194 @@ +#include "Wallet.h" +#include +#include +#include +#include + +namespace { + QString TEST_SEED = "bound class paint gasp task soul forgot past pleasure physical circle " + " appear shore bathroom glove women crap busy beauty bliss idea give needle burden"; + + namespace { + bool createFileWrapper(const QString &filename) + { + QFile file(filename); + // qDebug("%s: about to create file: %s", __FUNCTION__, qPrintable(filename)); + bool result = file.open(QIODevice::WriteOnly); + if (!result ){ + qWarning("%s: error creating file '%s' : '%s'", + __FUNCTION__, + qPrintable(filename), + qPrintable(file.errorString())); + } + return result; + } + } + +} + +struct WalletImpl +{ + + QString basename() const; + void setBasename(const QString &name); + + QString keysName() const; + QString addressName() const; + +// Bitmonero::Wallet * m_walletImpl; + QString m_basename; + QString m_seed; + QString m_password; + QString m_language; + + static QString keysName(const QString &basename); + static QString addressName(const QString &basename); + +}; + + +QString WalletImpl::basename() const +{ + return m_basename; +} + +void WalletImpl::setBasename(const QString &name) +{ + m_basename = name; +} + +QString WalletImpl::keysName() const +{ + return keysName(m_basename); +} + +QString WalletImpl::addressName() const +{ + return addressName(m_basename); +} + +QString WalletImpl::keysName(const QString &basename) +{ + return basename + ".keys"; +} + +QString WalletImpl::addressName(const QString &basename) +{ + return basename + ".address.txt"; +} + + +Wallet::Wallet(QObject *parent) + : QObject(parent) +{ + +} + +QString Wallet::getSeed() const +{ + return m_pimpl->m_seed; +} + +QString Wallet::getSeedLanguage() const +{ + return "English"; +} + +//void Wallet::setSeedLaguage(const QString &lang) +//{ +// // TODO: call libwallet's appropriate method +//} + +bool Wallet::setPassword(const QString &password) +{ + // set/change password implies: + // recovery wallet with existing path, seed and lang + qDebug("%s: recovering wallet with path=%s, seed=%s, lang=%s and new password=%s", + __FUNCTION__, + qPrintable(this->getBasename()), + qPrintable(this->getSeed()), + qPrintable(this->getSeedLanguage()), + qPrintable(password)); + return true; +} + +QString Wallet::getPassword() const +{ + return m_pimpl->m_password; +} + +bool Wallet::rename(const QString &name) +{ + + QString dst = QUrl(name).toLocalFile(); + + if (dst.isEmpty()) + dst = name; + + qDebug("%s: renaming '%s' to '%s'", + __FUNCTION__, + qPrintable(m_pimpl->basename()), + qPrintable(dst)); + + QString walletKeysFile = m_pimpl->keysName(); + QString walletAddressFile = m_pimpl->addressName(); + + QString dstWalletKeysFile = WalletImpl::keysName(dst); + QString dstWalletAddressFile = WalletImpl::addressName(dst); + + QFile walletFile(this->getBasename()); + + if (!walletFile.rename(dst)) { + qWarning("Error renaming file: '%s' to '%s' : (%s)", + qPrintable(m_pimpl->basename()), + qPrintable(dst), + qPrintable(walletFile.errorString())); + return false; + } + QFile::rename(walletKeysFile, dstWalletKeysFile); + QFile::rename(walletAddressFile, dstWalletAddressFile); + + bool result = QFile::exists(dst) && QFile::exists(dstWalletKeysFile) + && QFile::exists(dstWalletAddressFile); + + if (result) { + m_pimpl->m_basename = dst; + } + + return result; +} + +QString Wallet::getBasename() const +{ + return m_pimpl->basename(); +} + +int Wallet::error() const +{ + return 0; +} + +QString Wallet::errorString() const +{ + return m_pimpl->m_seed; +} + +Wallet::Wallet(const QString &path, const QString &password, const QString &language) +{ + m_pimpl = new WalletImpl; + m_pimpl->m_basename = path; + m_pimpl->m_password = password; + m_pimpl->m_language = language; + m_pimpl->m_seed = TEST_SEED; + + // Create dummy files for testing + QFileInfo fi(path); + QDir tempDir; + tempDir.mkpath(fi.absolutePath()); + createFileWrapper(m_pimpl->basename()); + createFileWrapper(m_pimpl->keysName()); + createFileWrapper(m_pimpl->addressName()); +} + + + diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h new file mode 100644 index 00000000..221d3d43 --- /dev/null +++ b/src/libwalletqt/Wallet.h @@ -0,0 +1,44 @@ +#ifndef WALLET_H +#define WALLET_H + +#include + +struct WalletImpl; +class Wallet : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString seed READ getSeed) +public: + explicit Wallet(QObject *parent = 0); + + //! returns mnemonic seed + Q_INVOKABLE QString getSeed() const; + + //! returns seed language + Q_INVOKABLE QString getSeedLanguage() const; + + + //! changes the password using existing parameters (path, seed, seed lang) + Q_INVOKABLE bool setPassword(const QString &password); + //! returns curret wallet password + Q_INVOKABLE QString getPassword() const; + + //! renames/moves wallet files + Q_INVOKABLE bool rename(const QString &name); + + //! returns current wallet name (basename, as wallet consists of several files) + Q_INVOKABLE QString getBasename() const; + + Q_INVOKABLE int error() const; + Q_INVOKABLE QString errorString() const; + +private: + Wallet(const QString &path, const QString &password, const QString &language); + +private: + friend class WalletManager; + //! pimpl wrapper for libwallet; + WalletImpl * m_pimpl; +}; + +#endif // WALLET_H diff --git a/src/libwalletqt/WalletManager.cpp b/src/libwalletqt/WalletManager.cpp new file mode 100644 index 00000000..cb0ffbac --- /dev/null +++ b/src/libwalletqt/WalletManager.cpp @@ -0,0 +1,116 @@ +#include "WalletManager.h" +#include "Wallet.h" +#include "wallet/wallet2_api.h" +#include +#include +#include +#include +#include + +WalletManager * WalletManager::m_instance = nullptr; + + + + + +WalletManager *WalletManager::instance() +{ + if (!m_instance) { + m_instance = new WalletManager; + } + // Checking linkage (doesn't work, TODO: have every dependencies linked statically into libwallet) + Bitmonero::WalletManager * wallet_manager_impl = Bitmonero::WalletManagerFactory::getWalletManager(); + + return m_instance; +} + +Wallet *WalletManager::createWallet(const QString &path, const QString &password, + const QString &language) +{ + QFileInfo fi(path); + if (fi.exists()) { + qCritical("%s: already exists", __FUNCTION__); + // TODO: set error and error string + // return nullptr; + } + Wallet * wallet = new Wallet(path, password, language); + return wallet; +} + +Wallet *WalletManager::openWallet(const QString &path, const QString &language, const QString &password) +{ + QFileInfo fi(path); + if (fi.exists()) { + qCritical("%s: not exists", __FUNCTION__); + // TODO: set error and error string + // return nullptr; + } + // TODO: call the libwallet api here; + Wallet * wallet = new Wallet(path, password, language); + + return wallet; +} + +Wallet *WalletManager::recoveryWallet(const QString &path, const QString &memo, const QString &language) +{ + // TODO: call the libwallet api here; + + return nullptr; +} + +bool WalletManager::moveWallet(const QString &src, const QString &dst_) +{ + // TODO: move this to libwallet; + QFile walletFile(src); + if (!walletFile.exists()) { + qWarning("%s: source file [%s] doesn't exits", __FUNCTION__, + qPrintable(src)); + return false; + } + QString dst = QUrl(dst_).toLocalFile(); + QString walletKeysFile = src + ".keys"; + QString walletAddressFile = src + ".address.txt"; + + QString dstWalletKeysFile = dst + ".keys"; + QString dstWalletAddressFile = dst + ".address.txt"; + + if (!walletFile.rename(dst)) { + qWarning("Error renaming file: '%s' to '%s' : (%s)", + qPrintable(src), + qPrintable(dst), + qPrintable(walletFile.errorString())); + return false; + } + QFile::rename(walletKeysFile, dstWalletKeysFile); + QFile::rename(walletAddressFile, dstWalletAddressFile); + + return QFile::exists(dst) && QFile::exists(dstWalletKeysFile) + && QFile::exists(dstWalletAddressFile); +} + +void WalletManager::closeWallet(Wallet *wallet) +{ + delete wallet; +} + +QString WalletManager::walletLanguage(const QString &locale) +{ + return "English"; +} + +int WalletManager::error() const +{ + return 0; +} + +QString WalletManager::errorString() const +{ + return tr("Unknown error"); +} + +WalletManager::WalletManager(QObject *parent) : QObject(parent) +{ + +} + + diff --git a/src/libwalletqt/WalletManager.h b/src/libwalletqt/WalletManager.h new file mode 100644 index 00000000..231f104c --- /dev/null +++ b/src/libwalletqt/WalletManager.h @@ -0,0 +1,48 @@ +#ifndef WALLETMANAGER_H +#define WALLETMANAGER_H + +#include + +class Wallet; + +class WalletManager : public QObject +{ + Q_OBJECT +public: + static WalletManager * instance(); + // wizard: createWallet path; + Q_INVOKABLE Wallet * createWallet(const QString &path, const QString &password, + const QString &language); + // just for future use + Q_INVOKABLE Wallet * openWallet(const QString &path, const QString &language, + const QString &password); + + // wizard: recoveryWallet path; hint: internally it recorvers wallet and set password = "" + Q_INVOKABLE Wallet * recoveryWallet(const QString &path, const QString &memo, + const QString &language); + + // wizard: both "create" and "recovery" paths. + // TODO: probably move it to "Wallet" interface + Q_INVOKABLE bool moveWallet(const QString &src, const QString &dst); + + //! utils: close wallet to free memory + Q_INVOKABLE void closeWallet(Wallet * wallet); + + //! returns libwallet language name for given locale + Q_INVOKABLE QString walletLanguage(const QString &locale); + + //! returns last error happened in WalletManager + Q_INVOKABLE int error() const; + + //! returns error description in human language + Q_INVOKABLE QString errorString() const; +signals: + +public slots: + +private: + explicit WalletManager(QObject *parent = 0); + static WalletManager * m_instance; +}; + +#endif // WALLETMANAGER_H -- cgit v1.2.3 From da1b74a707da4e21a1c749c372ab9c8b1df1e5e1 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Tue, 7 Jun 2016 16:26:25 +0300 Subject: Start in normal mode if wallet exists. Resolves #9 --- main.cpp | 4 +- main.qml | 11 +++ src/libwalletqt/Wallet.cpp | 173 +++++--------------------------------- src/libwalletqt/Wallet.h | 34 +++++--- src/libwalletqt/WalletManager.cpp | 92 ++++++++------------ src/libwalletqt/WalletManager.h | 33 +++++--- 6 files changed, 111 insertions(+), 236 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index b486c5f0..6c529ed0 100644 --- a/main.cpp +++ b/main.cpp @@ -44,8 +44,8 @@ int main(int argc, char *argv[]) app.installEventFilter(eventFilter); qmlRegisterType("moneroComponents", 1, 0, "Clipboard"); - //qmlRegisterType("moneroWallet", 1, 0, "Wallet"); - qmlRegisterType(); + qmlRegisterInterface("Wallet"); + QQmlApplicationEngine engine; diff --git a/main.qml b/main.qml index c1a1d5ec..a36a3755 100644 --- a/main.qml +++ b/main.qml @@ -110,6 +110,15 @@ ApplicationWindow { } + function walletsFound() { + var wallets = walletManager.findWallets(moneroAccountsDir); + if (wallets.length === 0) { + wallets = walletManager.findWallets(applicationDirectory); + } + print(wallets); + return wallets.length > 0; + } + visible: true width: rightPanelExpanded ? 1269 : 1269 - 300 height: 800 @@ -120,6 +129,8 @@ ApplicationWindow { Component.onCompleted: { x = (Screen.width - width) / 2 y = (Screen.height - height) / 2 + // + rootItem.state = walletsFound() ? "normal" : "wizard"; } Item { diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index 61998ab5..2ede062c 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -1,194 +1,61 @@ #include "Wallet.h" +#include "wallet/wallet2_api.h" + #include #include #include #include namespace { - QString TEST_SEED = "bound class paint gasp task soul forgot past pleasure physical circle " - " appear shore bathroom glove women crap busy beauty bliss idea give needle burden"; - - namespace { - bool createFileWrapper(const QString &filename) - { - QFile file(filename); - // qDebug("%s: about to create file: %s", __FUNCTION__, qPrintable(filename)); - bool result = file.open(QIODevice::WriteOnly); - if (!result ){ - qWarning("%s: error creating file '%s' : '%s'", - __FUNCTION__, - qPrintable(filename), - qPrintable(file.errorString())); - } - return result; - } - } - -} - -struct WalletImpl -{ - - QString basename() const; - void setBasename(const QString &name); - - QString keysName() const; - QString addressName() const; -// Bitmonero::Wallet * m_walletImpl; - QString m_basename; - QString m_seed; - QString m_password; - QString m_language; - static QString keysName(const QString &basename); - static QString addressName(const QString &basename); - -}; - - -QString WalletImpl::basename() const -{ - return m_basename; } -void WalletImpl::setBasename(const QString &name) -{ - m_basename = name; -} -QString WalletImpl::keysName() const -{ - return keysName(m_basename); -} - -QString WalletImpl::addressName() const -{ - return addressName(m_basename); -} - -QString WalletImpl::keysName(const QString &basename) +QString Wallet::getSeed() const { - return basename + ".keys"; + return QString::fromStdString(m_walletImpl->seed()); } -QString WalletImpl::addressName(const QString &basename) +QString Wallet::getSeedLanguage() const { - return basename + ".address.txt"; + return QString::fromStdString(m_walletImpl->getSeedLanguage()); } - -Wallet::Wallet(QObject *parent) - : QObject(parent) +int Wallet::status() const { - + return m_walletImpl->status(); } -QString Wallet::getSeed() const -{ - return m_pimpl->m_seed; -} - -QString Wallet::getSeedLanguage() const +QString Wallet::errorString() const { - return "English"; + return QString::fromStdString(m_walletImpl->errorString()); } -//void Wallet::setSeedLaguage(const QString &lang) -//{ -// // TODO: call libwallet's appropriate method -//} - bool Wallet::setPassword(const QString &password) { - // set/change password implies: - // recovery wallet with existing path, seed and lang - qDebug("%s: recovering wallet with path=%s, seed=%s, lang=%s and new password=%s", - __FUNCTION__, - qPrintable(this->getBasename()), - qPrintable(this->getSeed()), - qPrintable(this->getSeedLanguage()), - qPrintable(password)); - return true; + return m_walletImpl->setPassword(password.toStdString()); } -QString Wallet::getPassword() const +QString Wallet::address() const { - return m_pimpl->m_password; + return QString::fromStdString(m_walletImpl->address()); } -bool Wallet::rename(const QString &name) +bool Wallet::store(const QString &path) { - - QString dst = QUrl(name).toLocalFile(); - - if (dst.isEmpty()) - dst = name; - - qDebug("%s: renaming '%s' to '%s'", - __FUNCTION__, - qPrintable(m_pimpl->basename()), - qPrintable(dst)); - - QString walletKeysFile = m_pimpl->keysName(); - QString walletAddressFile = m_pimpl->addressName(); - - QString dstWalletKeysFile = WalletImpl::keysName(dst); - QString dstWalletAddressFile = WalletImpl::addressName(dst); - - QFile walletFile(this->getBasename()); - - if (!walletFile.rename(dst)) { - qWarning("Error renaming file: '%s' to '%s' : (%s)", - qPrintable(m_pimpl->basename()), - qPrintable(dst), - qPrintable(walletFile.errorString())); - return false; - } - QFile::rename(walletKeysFile, dstWalletKeysFile); - QFile::rename(walletAddressFile, dstWalletAddressFile); - - bool result = QFile::exists(dst) && QFile::exists(dstWalletKeysFile) - && QFile::exists(dstWalletAddressFile); - - if (result) { - m_pimpl->m_basename = dst; - } - - return result; + return m_walletImpl->store(path.toStdString()); } -QString Wallet::getBasename() const -{ - return m_pimpl->basename(); -} -int Wallet::error() const -{ - return 0; -} -QString Wallet::errorString() const +Wallet::Wallet(Bitmonero::Wallet *w, QObject *parent) + : QObject(parent), m_walletImpl(w) { - return m_pimpl->m_seed; + } -Wallet::Wallet(const QString &path, const QString &password, const QString &language) +Wallet::~Wallet() { - m_pimpl = new WalletImpl; - m_pimpl->m_basename = path; - m_pimpl->m_password = password; - m_pimpl->m_language = language; - m_pimpl->m_seed = TEST_SEED; - - // Create dummy files for testing - QFileInfo fi(path); - QDir tempDir; - tempDir.mkpath(fi.absolutePath()); - createFileWrapper(m_pimpl->basename()); - createFileWrapper(m_pimpl->keysName()); - createFileWrapper(m_pimpl->addressName()); + Bitmonero::WalletManagerFactory::getWalletManager()->closeWallet(m_walletImpl); } - - - diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index 221d3d43..79655cb4 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -3,13 +3,18 @@ #include -struct WalletImpl; +namespace Bitmonero { + class Wallet; // forward declaration +} class Wallet : public QObject { Q_OBJECT Q_PROPERTY(QString seed READ getSeed) public: - explicit Wallet(QObject *parent = 0); + enum Status { + Status_Ok = 0, + Status_Error = 1 + }; //! returns mnemonic seed Q_INVOKABLE QString getSeed() const; @@ -17,28 +22,31 @@ public: //! returns seed language Q_INVOKABLE QString getSeedLanguage() const; + //! returns last operation's status + Q_INVOKABLE int status() const; + + //! returns last operation's error message + Q_INVOKABLE QString errorString() const; //! changes the password using existing parameters (path, seed, seed lang) Q_INVOKABLE bool setPassword(const QString &password); - //! returns curret wallet password - Q_INVOKABLE QString getPassword() const; - //! renames/moves wallet files - Q_INVOKABLE bool rename(const QString &name); + //! returns wallet's public address + Q_INVOKABLE QString address() const; + + //! saves wallet to the file by given path + Q_INVOKABLE bool store(const QString &path); - //! returns current wallet name (basename, as wallet consists of several files) - Q_INVOKABLE QString getBasename() const; - Q_INVOKABLE int error() const; - Q_INVOKABLE QString errorString() const; private: - Wallet(const QString &path, const QString &password, const QString &language); + Wallet(Bitmonero::Wallet *w, QObject * parent = 0); + ~Wallet(); private: friend class WalletManager; - //! pimpl wrapper for libwallet; - WalletImpl * m_pimpl; + //! libwallet's + Bitmonero::Wallet * m_walletImpl; }; #endif // WALLET_H diff --git a/src/libwalletqt/WalletManager.cpp b/src/libwalletqt/WalletManager.cpp index cb0ffbac..646e47f5 100644 --- a/src/libwalletqt/WalletManager.cpp +++ b/src/libwalletqt/WalletManager.cpp @@ -7,6 +7,8 @@ #include #include + + WalletManager * WalletManager::m_instance = nullptr; @@ -18,89 +20,55 @@ WalletManager *WalletManager::instance() if (!m_instance) { m_instance = new WalletManager; } - // Checking linkage (doesn't work, TODO: have every dependencies linked statically into libwallet) - Bitmonero::WalletManager * wallet_manager_impl = Bitmonero::WalletManagerFactory::getWalletManager(); return m_instance; } Wallet *WalletManager::createWallet(const QString &path, const QString &password, - const QString &language) + const QString &language, bool testnet) { - QFileInfo fi(path); - if (fi.exists()) { - qCritical("%s: already exists", __FUNCTION__); - // TODO: set error and error string - // return nullptr; - } - Wallet * wallet = new Wallet(path, password, language); + Bitmonero::Wallet * w = m_pimpl->createWallet(path.toStdString(), password.toStdString(), + language.toStdString(), testnet); + Wallet * wallet = new Wallet(w); return wallet; } -Wallet *WalletManager::openWallet(const QString &path, const QString &language, const QString &password) +Wallet *WalletManager::openWallet(const QString &path, const QString &password, bool testnet) { - QFileInfo fi(path); - if (fi.exists()) { - qCritical("%s: not exists", __FUNCTION__); - // TODO: set error and error string - // return nullptr; - } // TODO: call the libwallet api here; - Wallet * wallet = new Wallet(path, password, language); + Bitmonero::Wallet * w = m_pimpl->openWallet(path.toStdString(), password.toStdString(), testnet); + Wallet * wallet = new Wallet(w); return wallet; } -Wallet *WalletManager::recoveryWallet(const QString &path, const QString &memo, const QString &language) -{ - // TODO: call the libwallet api here; - - return nullptr; -} -bool WalletManager::moveWallet(const QString &src, const QString &dst_) +Wallet *WalletManager::recoveryWallet(const QString &path, const QString &memo, bool testnet) { - // TODO: move this to libwallet; - QFile walletFile(src); - if (!walletFile.exists()) { - qWarning("%s: source file [%s] doesn't exits", __FUNCTION__, - qPrintable(src)); - return false; - } - QString dst = QUrl(dst_).toLocalFile(); - QString walletKeysFile = src + ".keys"; - QString walletAddressFile = src + ".address.txt"; - - QString dstWalletKeysFile = dst + ".keys"; - QString dstWalletAddressFile = dst + ".address.txt"; - - if (!walletFile.rename(dst)) { - qWarning("Error renaming file: '%s' to '%s' : (%s)", - qPrintable(src), - qPrintable(dst), - qPrintable(walletFile.errorString())); - return false; - } - QFile::rename(walletKeysFile, dstWalletKeysFile); - QFile::rename(walletAddressFile, dstWalletAddressFile); - - return QFile::exists(dst) && QFile::exists(dstWalletKeysFile) - && QFile::exists(dstWalletAddressFile); + Bitmonero::Wallet * w = m_pimpl->recoveryWallet(path.toStdString(), memo.toStdString(), testnet); + Wallet * wallet = new Wallet(w); + return wallet; } + void WalletManager::closeWallet(Wallet *wallet) { delete wallet; } -QString WalletManager::walletLanguage(const QString &locale) +bool WalletManager::walletExists(const QString &path) const { - return "English"; + return m_pimpl->walletExists(path.toStdString()); } -int WalletManager::error() const +QStringList WalletManager::findWallets(const QString &path) { - return 0; + std::vector found_wallets = m_pimpl->findWallets(path.toStdString()); + QStringList result; + for (const auto &w : found_wallets) { + result.append(QString::fromStdString(w)); + } + return result; } QString WalletManager::errorString() const @@ -108,9 +76,21 @@ QString WalletManager::errorString() const return tr("Unknown error"); } -WalletManager::WalletManager(QObject *parent) : QObject(parent) +bool WalletManager::moveWallet(const QString &src, const QString &dst) { + return true; +} + +QString WalletManager::walletLanguage(const QString &locale) +{ + return "English"; +} + + +WalletManager::WalletManager(QObject *parent) : QObject(parent) +{ + m_pimpl = Bitmonero::WalletManagerFactory::getWalletManager(); } diff --git a/src/libwalletqt/WalletManager.h b/src/libwalletqt/WalletManager.h index 231f104c..c40fec54 100644 --- a/src/libwalletqt/WalletManager.h +++ b/src/libwalletqt/WalletManager.h @@ -4,6 +4,9 @@ #include class Wallet; +namespace Bitmonero { + class WalletManager; +} class WalletManager : public QObject { @@ -12,37 +15,43 @@ public: static WalletManager * instance(); // wizard: createWallet path; Q_INVOKABLE Wallet * createWallet(const QString &path, const QString &password, - const QString &language); + const QString &language, bool testnet = false); // just for future use - Q_INVOKABLE Wallet * openWallet(const QString &path, const QString &language, - const QString &password); + Q_INVOKABLE Wallet * openWallet(const QString &path, const QString &password, bool testnet = false); // wizard: recoveryWallet path; hint: internally it recorvers wallet and set password = "" Q_INVOKABLE Wallet * recoveryWallet(const QString &path, const QString &memo, - const QString &language); - - // wizard: both "create" and "recovery" paths. - // TODO: probably move it to "Wallet" interface - Q_INVOKABLE bool moveWallet(const QString &src, const QString &dst); + bool testnet = false); //! utils: close wallet to free memory Q_INVOKABLE void closeWallet(Wallet * wallet); - //! returns libwallet language name for given locale - Q_INVOKABLE QString walletLanguage(const QString &locale); + //! checks is given filename is a wallet; + Q_INVOKABLE bool walletExists(const QString &path) const; - //! returns last error happened in WalletManager - Q_INVOKABLE int error() const; + //! returns list with wallet's filenames, if found by given path + Q_INVOKABLE QStringList findWallets(const QString &path); //! returns error description in human language Q_INVOKABLE QString errorString() const; + + + // wizard: both "create" and "recovery" paths. + // TODO: probably move it to "Wallet" interface + Q_INVOKABLE bool moveWallet(const QString &src, const QString &dst); + //! returns libwallet language name for given locale + Q_INVOKABLE QString walletLanguage(const QString &locale); + signals: public slots: private: + explicit WalletManager(QObject *parent = 0); static WalletManager * m_instance; + Bitmonero::WalletManager * m_pimpl; + }; #endif // WALLETMANAGER_H -- cgit v1.2.3 From fd50e6f9a3bc445cb3c0d21b7a0f584e95b44450 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Fri, 10 Jun 2016 16:41:13 +0300 Subject: new wallet wizard: wallet created in temporary directory and moved to the destination at the final step --- get_libwallet_api.sh | 3 +++ lang/languages.xml | 20 ++++++++++---------- main.cpp | 6 ++++++ monero-core.pro | 6 ++++-- oshelper.cpp | 24 ++++++++++++++++++++++++ oshelper.h | 22 ++++++++++++++++++++++ wizard/WizardCreateWallet.qml | 25 ++++++++++++++++++++----- wizard/WizardDonation.qml | 2 +- wizard/WizardMain.qml | 7 +++---- wizard/WizardManageWalletUI.qml | 2 +- wizard/WizardPassword.qml | 2 +- wizard/WizardRecoveryWallet.qml | 2 +- wizard/WizardWelcome.qml | 13 +++++++++---- 13 files changed, 105 insertions(+), 29 deletions(-) create mode 100644 oshelper.cpp create mode 100644 oshelper.h (limited to 'main.cpp') diff --git a/get_libwallet_api.sh b/get_libwallet_api.sh index 34c2e6b3..c9f67ff8 100755 --- a/get_libwallet_api.sh +++ b/get_libwallet_api.sh @@ -13,6 +13,9 @@ BITMONERO_DIR=$ROOT_DIR/bitmonero if [ ! -d $BITMONERO_DIR ]; then git clone --depth=1 $BITMONERO_URL $BITMONERO_DIR +else + cd $BITMONERO_DIR; + git pull; fi rm -fr $BITMONERO_DIR/build diff --git a/lang/languages.xml b/lang/languages.xml index efb84c9c..449d415c 100644 --- a/lang/languages.xml +++ b/lang/languages.xml @@ -1,13 +1,13 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/main.cpp b/main.cpp index 6c529ed0..39e4635d 100644 --- a/main.cpp +++ b/main.cpp @@ -33,10 +33,13 @@ #include "clipboardAdapter.h" #include "filter.h" #include "oscursor.h" +#include "oshelper.h" #include "WalletManager.h" #include "Wallet.h" + + int main(int argc, char *argv[]) { QApplication app(argc, argv); @@ -51,6 +54,9 @@ int main(int argc, char *argv[]) OSCursor cursor; engine.rootContext()->setContextProperty("globalCursor", &cursor); + OSHelper osHelper; + engine.rootContext()->setContextProperty("oshelper", &osHelper); + engine.rootContext()->setContextProperty("walletManager", WalletManager::instance()); // export to QML monero accounts root directory diff --git a/monero-core.pro b/monero-core.pro index f521c9ec..8ce4a16a 100644 --- a/monero-core.pro +++ b/monero-core.pro @@ -18,7 +18,8 @@ HEADERS += \ src/libwalletqt/Wallet.h \ src/libwalletqt/PendingTransaction.h \ src/libwalletqt/TransactionHistory.h \ - src/libwalletqt/TransactionInfo.h + src/libwalletqt/TransactionInfo.h \ + oshelper.h SOURCES += main.cpp \ @@ -29,7 +30,8 @@ SOURCES += main.cpp \ src/libwalletqt/Wallet.cpp \ src/libwalletqt/PendingTransaction.cpp \ src/libwalletqt/TransactionHistory.cpp \ - src/libwalletqt/TransactionInfo.cpp + src/libwalletqt/TransactionInfo.cpp \ + oshelper.cpp lupdate_only { SOURCES = *.qml \ diff --git a/oshelper.cpp b/oshelper.cpp new file mode 100644 index 00000000..cecae38e --- /dev/null +++ b/oshelper.cpp @@ -0,0 +1,24 @@ +#include "oshelper.h" +#include +#include + +OSHelper::OSHelper(QObject *parent) : QObject(parent) +{ + +} + +QString OSHelper::temporaryFilename() const +{ + QString tempFileName; + { + QTemporaryFile f; + f.open(); + tempFileName = f.fileName(); + } + return tempFileName; +} + +QString OSHelper::temporaryPath() const +{ + return QDir::tempPath(); +} diff --git a/oshelper.h b/oshelper.h new file mode 100644 index 00000000..809058cb --- /dev/null +++ b/oshelper.h @@ -0,0 +1,22 @@ +#ifndef OSHELPER_H +#define OSHELPER_H + +#include +/** + * @brief The OSHelper class - exports to QML some OS-related functions + */ +class OSHelper : public QObject +{ + Q_OBJECT +public: + explicit OSHelper(QObject *parent = 0); + + Q_INVOKABLE QString temporaryFilename() const; + Q_INVOKABLE QString temporaryPath() const; + +signals: + +public slots: +}; + +#endif // OSHELPER_H diff --git a/wizard/WizardCreateWallet.qml b/wizard/WizardCreateWallet.qml index 346627dc..653db251 100644 --- a/wizard/WizardCreateWallet.qml +++ b/wizard/WizardCreateWallet.qml @@ -40,18 +40,23 @@ Item { onOpacityChanged: visible = opacity !== 0 - function saveSettings(settingsObject) { + //! function called each time we display this page + + function onPageClosed(settingsObject) { settingsObject['account_name'] = uiItem.accountNameText settingsObject['words'] = uiItem.wordsTexttext settingsObject['wallet_path'] = uiItem.walletPath + // put wallet files to the subdirectory with the same name as + // wallet name var new_wallet_filename = settingsObject.wallet_path + "/" + + settingsObject.account_name + "/" + settingsObject.account_name; // moving wallet files to the new destination, if user changed it if (new_wallet_filename !== settingsObject.wallet_filename) { // using previously saved wallet; - settingsObject.wallet.rename(new_wallet_filename); + settingsObject.wallet.store(new_wallet_filename); //walletManager.moveWallet(settingsObject.wallet_filename, new_wallet_filename); } @@ -59,10 +64,18 @@ Item { settingsObject['wallet_filename'] = new_wallet_filename; } + //! function called each time we hide this page + // + + function createWallet(settingsObject) { - var wallet_filename = uiItem.walletPath + "/" + uiItem.accountNameText + // TODO: create wallet in temporary filename and a) move it to the path specified by user after the final + // page submitted or b) delete it when program closed before reaching final page + + var wallet_filename = oshelper.temporaryFilename(); if (typeof settingsObject.wallet === 'undefined') { - var wallet = walletManager.createWallet(wallet_filename, "", settingsObject.locale) + //var wallet = walletManager.createWallet(wallet_filename, "", settingsObject.language) + var wallet = walletManager.createWallet(wallet_filename, "", settingsObject.wallet_language) uiItem.wordsTextItem.memoText = wallet.seed // saving wallet in "global" settings object // TODO: wallet should have a property pointing to the file where it stored or loaded from @@ -70,10 +83,12 @@ Item { } else { print("wallet already created. we just stepping back"); } - settingsObject.wallet_filename = wallet_filename } + + + WizardManageWalletUI { id: uiItem titleText: qsTr("A new wallet has been created for you") diff --git a/wizard/WizardDonation.qml b/wizard/WizardDonation.qml index d42c266e..51a28029 100644 --- a/wizard/WizardDonation.qml +++ b/wizard/WizardDonation.qml @@ -38,7 +38,7 @@ Item { onOpacityChanged: visible = opacity !== 0 - function saveSettings(settingsObject) { + function onPageClosed(settingsObject) { settingsObject['auto_donations_enabled'] = enableAutoDonationCheckBox.checked; settingsObject['auto_donations_amount'] = autoDonationAmountText.text; settingsObject['allow_background_mining'] = allowBackgroundMiningCheckBox.checked; diff --git a/wizard/WizardMain.qml b/wizard/WizardMain.qml index 51e0baf3..a19c622c 100644 --- a/wizard/WizardMain.qml +++ b/wizard/WizardMain.qml @@ -49,8 +49,8 @@ Rectangle { function switchPage(next) { // save settings for current page; - if (typeof pages[currentPage].saveSettings !== 'undefined') { - pages[currentPage].saveSettings(settings); + if (typeof pages[currentPage].onPageClosed !== 'undefined') { + pages[currentPage].onPageClosed(settings); } print ("switchpage: start: currentPage: ", currentPage); @@ -61,7 +61,6 @@ Rectangle { pages[currentPage].opacity = 1; handlePageChanged(); } - } function handlePageChanged() { @@ -91,9 +90,9 @@ Rectangle { nextButton.enabled = true } - } + function openCreateWalletPage() { print ("show create wallet page"); pages[currentPage].opacity = 0; diff --git a/wizard/WizardManageWalletUI.qml b/wizard/WizardManageWalletUI.qml index ce035f0a..58f4e59a 100644 --- a/wizard/WizardManageWalletUI.qml +++ b/wizard/WizardManageWalletUI.qml @@ -206,7 +206,7 @@ Item { verticalAlignment: Text.AlignVCenter selectByMouse: true - text: moneroAccountsDir + "/My Wallet" + text: moneroAccountsDir + "/" onFocusChanged: { if(focus) { fileDialog.folder = text diff --git a/wizard/WizardPassword.qml b/wizard/WizardPassword.qml index 1bcc6213..aca45d4d 100644 --- a/wizard/WizardPassword.qml +++ b/wizard/WizardPassword.qml @@ -43,7 +43,7 @@ Item { onOpacityChanged: visible = opacity !== 0 - function saveSettings(settingsObject) { + function onPageClosed(settingsObject) { settingsObject.wallet.setPassword(passwordItem.password) } diff --git a/wizard/WizardRecoveryWallet.qml b/wizard/WizardRecoveryWallet.qml index 572d776b..e7fd6c0d 100644 --- a/wizard/WizardRecoveryWallet.qml +++ b/wizard/WizardRecoveryWallet.qml @@ -40,7 +40,7 @@ Item { onOpacityChanged: visible = opacity !== 0 - function saveSettings(settingsObject) { + function onPageClosed(settingsObject) { settingsObject['account_name'] = uiItem.accountNameText settingsObject['words'] = uiItem.wordsTexttext settingsObject['wallet_path'] = uiItem.walletPath diff --git a/wizard/WizardWelcome.qml b/wizard/WizardWelcome.qml index 208a7994..bdd88b70 100644 --- a/wizard/WizardWelcome.qml +++ b/wizard/WizardWelcome.qml @@ -36,8 +36,11 @@ Item { onOpacityChanged: visible = opacity !== 0 - function saveSettings(settingsObject) { - settingsObject['language'] = languagesModel.get(gridView.currentIndex).name + function onPageClosed(settingsObject) { + var lang = languagesModel.get(gridView.currentIndex); + settingsObject['language'] = lang.display_name; + settingsObject['wallet_language'] = lang.wallet_name; + settingsObject['locale'] = lang.locale; } Column { @@ -78,7 +81,9 @@ Item { source: "/lang/languages.xml" query: "/languages/language" - XmlRole { name: "name"; query: "@name/string()" } + XmlRole { name: "display_name"; query: "@display_name/string()" } + XmlRole { name: "locale"; query: "@locale/string()" } + XmlRole { name: "wallet_name"; query: "@wallet_name/string()" } XmlRole { name: "flag"; query: "@flag/string()" } // TODO: XmlListModel is read only, we should store current language somewhere else // and set current language accordingly @@ -126,7 +131,7 @@ Item { font.bold: gridView.currentIndex === index elide: Text.ElideRight color: "#3F3F3F" - text: name + text: display_name } MouseArea { id: delegateArea -- cgit v1.2.3 From 1eac46ae734d31df568cf0f51dd1d5b7e7244cdc Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Tue, 14 Jun 2016 16:09:14 +0300 Subject: "new wallet" and "recovery wallet" flows are implemented using libwallet api --- main.cpp | 2 +- wizard/WizardCreateWallet.qml | 5 +---- wizard/WizardDonation.qml | 17 ++--------------- wizard/WizardFinish.qml | 2 ++ wizard/WizardMain.qml | 40 ++++++++++++++++++++++++++++++++++++---- wizard/WizardPassword.qml | 1 + wizard/WizardRecoveryWallet.qml | 22 ++++++++++++++++++---- wizard/WizardWelcome.qml | 1 + 8 files changed, 62 insertions(+), 28 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 39e4635d..a4a79947 100644 --- a/main.cpp +++ b/main.cpp @@ -47,7 +47,7 @@ int main(int argc, char *argv[]) app.installEventFilter(eventFilter); qmlRegisterType("moneroComponents", 1, 0, "Clipboard"); - qmlRegisterInterface("Wallet"); + qmlRegisterUncreatableType("Bitmonero.Wallet", 1, 0, "Wallet", "Wallet can't be instantiated directly"); QQmlApplicationEngine engine; diff --git a/wizard/WizardCreateWallet.qml b/wizard/WizardCreateWallet.qml index 2332dd5c..0aad0052 100644 --- a/wizard/WizardCreateWallet.qml +++ b/wizard/WizardCreateWallet.qml @@ -46,10 +46,7 @@ Item { settingsObject['account_name'] = uiItem.accountNameText settingsObject['words'] = uiItem.wordsTexttext settingsObject['wallet_path'] = uiItem.walletPath - - // put wallet files to the subdirectory with the same name as - // wallet name - + return true; } //! function called each time we hide this page diff --git a/wizard/WizardDonation.qml b/wizard/WizardDonation.qml index 8cfc68f2..e0b73df8 100644 --- a/wizard/WizardDonation.qml +++ b/wizard/WizardDonation.qml @@ -43,22 +43,9 @@ Item { settingsObject['auto_donations_amount'] = autoDonationAmountText.text; settingsObject['allow_background_mining'] = allowBackgroundMiningCheckBox.checked; - // here we need to actually move wallet to the new location - // put wallet files to the subdirectory with the same name as - // wallet name - var new_wallet_filename = settingsObject.wallet_path + "/" - + settingsObject.account_name + "/" - + settingsObject.account_name; - - // moving wallet files to the new destination, if user changed it - if (new_wallet_filename !== settingsObject.wallet_filename) { - // using previously saved wallet; - settingsObject.wallet.store(new_wallet_filename); - //walletManager.moveWallet(settingsObject.wallet_filename, new_wallet_filename); - } - // saving wallet_filename; - settingsObject['wallet_filename'] = new_wallet_filename; + + return true; } Row { diff --git a/wizard/WizardFinish.qml b/wizard/WizardFinish.qml index 311dfd62..427a2340 100644 --- a/wizard/WizardFinish.qml +++ b/wizard/WizardFinish.qml @@ -53,6 +53,8 @@ Item { + buildSettingsString(); } + + Row { id: dotsRow anchors.top: parent.top diff --git a/wizard/WizardMain.qml b/wizard/WizardMain.qml index a19c622c..da3a9824 100644 --- a/wizard/WizardMain.qml +++ b/wizard/WizardMain.qml @@ -49,8 +49,12 @@ Rectangle { function switchPage(next) { // save settings for current page; - if (typeof pages[currentPage].onPageClosed !== 'undefined') { - pages[currentPage].onPageClosed(settings); + if (next && typeof pages[currentPage].onPageClosed !== 'undefined') { + if (pages[currentPage].onPageClosed(settings) !== true) { + print ("Can't go to the next page"); + return; + }; + } print ("switchpage: start: currentPage: ", currentPage); @@ -59,6 +63,10 @@ Rectangle { var step_value = next ? 1 : -1 currentPage += step_value pages[currentPage].opacity = 1; + + if (next && typeof pages[currentPage].onPageOpened !== 'undefined') { + pages[currentPage].onPageOpened(settings) + } handlePageChanged(); } } @@ -84,7 +92,7 @@ Rectangle { break; case recoveryWalletPage: // TODO: disable "next button" until 25 words private key entered - // nextButton.enabled = false; + nextButton.enabled = false break default: nextButton.enabled = true @@ -115,6 +123,27 @@ Rectangle { handlePageChanged() } + //! actually writes the wallet + function applySettings() { + print ("Here we apply the settings"); + // here we need to actually move wallet to the new location + // put wallet files to the subdirectory with the same name as + // wallet name + var new_wallet_filename = settings.wallet_path + "/" + + settings.account_name + "/" + + settings.account_name; + + // moving wallet files to the new destination, if user changed it + if (new_wallet_filename !== settings.wallet_filename) { + // using previously saved wallet; + settings.wallet.store(new_wallet_filename); + //walletManager.moveWallet(settingsObject.wallet_filename, new_wallet_filename); + } + + // saving wallet_filename; + settings['wallet_filename'] = new_wallet_filename; + } + @@ -255,6 +284,9 @@ Rectangle { releasedColor: "#FF6C3C" pressedColor: "#FF4304" visible: parent.paths[currentPath][currentPage] === finishPage - onClicked: wizard.useMoneroClicked() + onClicked: { + wizard.applySettings(); + wizard.useMoneroClicked() + } } } diff --git a/wizard/WizardPassword.qml b/wizard/WizardPassword.qml index aca45d4d..6b14dae9 100644 --- a/wizard/WizardPassword.qml +++ b/wizard/WizardPassword.qml @@ -45,6 +45,7 @@ Item { function onPageClosed(settingsObject) { settingsObject.wallet.setPassword(passwordItem.password) + return true } function handlePassword() { diff --git a/wizard/WizardRecoveryWallet.qml b/wizard/WizardRecoveryWallet.qml index e7fd6c0d..19530157 100644 --- a/wizard/WizardRecoveryWallet.qml +++ b/wizard/WizardRecoveryWallet.qml @@ -29,6 +29,7 @@ import QtQuick 2.2 import moneroComponents 1.0 import QtQuick.Dialogs 1.2 +import Bitmonero.Wallet 1.0 Item { opacity: 0 @@ -42,12 +43,25 @@ Item { function onPageClosed(settingsObject) { settingsObject['account_name'] = uiItem.accountNameText - settingsObject['words'] = uiItem.wordsTexttext + settingsObject['words'] = cleanWordsInput(uiItem.wordsTextItem.memoText) settingsObject['wallet_path'] = uiItem.walletPath + return recoveryWallet(settingsObject) } - function recoveryWallet() { + function recoveryWallet(settingsObject) { + var testnet = true; + var wallet = walletManager.recoveryWallet(oshelper.temporaryFilename(), settingsObject.words, testnet); + var success = wallet.status === Wallet.Status_Ok; + if (success) { + settingsObject['wallet'] = wallet; + } else { + walletManager.closeWallet(wallet); + } + return success; + } + function cleanWordsInput(text) { + return text.trim().replace(/(\r\n|\n|\r)/gm, " "); } WizardManageWalletUI { @@ -60,8 +74,8 @@ Item { wordsTextItem.memoTextReadOnly: false wordsTextItem.memoText: "" wordsTextItem.onMemoTextChanged: { - var wordsArray = wordsTextItem.memoText.trim().split(" ") - //wizard.nextButton.enabled = wordsArray.length === 25 + var wordsArray = cleanWordsInput(wordsTextItem.memoText).split(" "); + wizard.nextButton.enabled = wordsArray.length === 25 } } } diff --git a/wizard/WizardWelcome.qml b/wizard/WizardWelcome.qml index bdd88b70..8917d212 100644 --- a/wizard/WizardWelcome.qml +++ b/wizard/WizardWelcome.qml @@ -41,6 +41,7 @@ Item { settingsObject['language'] = lang.display_name; settingsObject['wallet_language'] = lang.wallet_name; settingsObject['locale'] = lang.locale; + return true } Column { -- cgit v1.2.3 From 2151f1395c28027f867d8e640b0c0be4cd4e0a23 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Wed, 15 Jun 2016 13:25:45 +0300 Subject: Persistent storage for common settings. closes #10 --- main.cpp | 5 +++++ main.qml | 2 ++ wizard/WizardDonation.qml | 12 ++++++++---- wizard/WizardMain.qml | 26 ++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 4 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index a4a79947..7331a4e4 100644 --- a/main.cpp +++ b/main.cpp @@ -43,6 +43,11 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); + + app.setApplicationName("monero-core"); + app.setOrganizationDomain("getmonero.org"); + app.setOrganizationName("The Monero Project"); + filter *eventFilter = new filter; app.installEventFilter(eventFilter); diff --git a/main.qml b/main.qml index a36a3755..0eb87b2e 100644 --- a/main.qml +++ b/main.qml @@ -30,6 +30,8 @@ import QtQuick 2.2 import QtQuick.Window 2.0 import QtQuick.Controls 1.1 import QtQuick.Controls.Styles 1.1 + + import "components" import "wizard" diff --git a/wizard/WizardDonation.qml b/wizard/WizardDonation.qml index e0b73df8..80ebd78b 100644 --- a/wizard/WizardDonation.qml +++ b/wizard/WizardDonation.qml @@ -38,13 +38,17 @@ Item { onOpacityChanged: visible = opacity !== 0 + function onPageOpened(settingsObject) { + enableAutoDonationCheckBox.checked = settingsObject.auto_donations_enabled + autoDonationAmountText.text = settingsObject.auto_donations_amount + allowBackgroundMiningCheckBox.checked = settingsObject.allow_background_mining + + } + function onPageClosed(settingsObject) { settingsObject['auto_donations_enabled'] = enableAutoDonationCheckBox.checked; - settingsObject['auto_donations_amount'] = autoDonationAmountText.text; + settingsObject['auto_donations_amount'] = parseInt(autoDonationAmountText.text); settingsObject['allow_background_mining'] = allowBackgroundMiningCheckBox.checked; - - - return true; } diff --git a/wizard/WizardMain.qml b/wizard/WizardMain.qml index da3a9824..940243cb 100644 --- a/wizard/WizardMain.qml +++ b/wizard/WizardMain.qml @@ -27,6 +27,8 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import QtQuick 2.2 +import Qt.labs.settings 1.0 + import "../components" Rectangle { @@ -142,10 +144,34 @@ Rectangle { // saving wallet_filename; settings['wallet_filename'] = new_wallet_filename; + + // persist settings + persistentSettings.language = settings.language + persistentSettings.account_name = settings.account_name + persistentSettings.wallet_path = settings.wallet_path + persistentSettings.allow_background_mining = settings.allow_background_mining + persistentSettings.auto_donations_enabled = settings.auto_donations_enabled + persistentSettings.auto_donations_amount = settings.auto_donations_amount } + // reading settings from persistent storage + Component.onCompleted: { + settings['allow_background_mining'] = persistentSettings.allow_background_mining + settings['auto_donations_enabled'] = persistentSettings.auto_donations_enabled + settings['auto_donations_amount'] = persistentSettings.auto_donations_amount + } + Settings { + id: persistentSettings + + property string language + property string account_name + property string wallet_path + property bool auto_donations_enabled : true + property int auto_donations_amount : 50 + property bool allow_background_mining : true + } Rectangle { id: nextButton -- cgit v1.2.3 From eaf59243b2cbe3d7ea6de1d8dcd18493df9f365d Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Thu, 16 Jun 2016 17:13:46 +0300 Subject: basic "send money" functionality implemented in GUI --- LeftPanel.qml | 2 ++ MiddlePanel.qml | 14 ++++++++++++++ components/LineEdit.qml | 3 +++ main.cpp | 3 +++ main.qml | 25 +++++++++++++++++++++++++ pages/Transfer.qml | 27 +++++++++++++++++++++------ src/libwalletqt/PendingTransaction.h | 2 ++ src/libwalletqt/WalletManager.cpp | 9 +++++++++ src/libwalletqt/WalletManager.h | 3 +++ 9 files changed, 82 insertions(+), 6 deletions(-) (limited to 'main.cpp') diff --git a/LeftPanel.qml b/LeftPanel.qml index 1eddf019..95b5aa6f 100644 --- a/LeftPanel.qml +++ b/LeftPanel.qml @@ -56,6 +56,7 @@ Rectangle { width: 260 color: "#FFFFFF" + // Item with monero logo Item { id: logoItem anchors.left: parent.left @@ -85,6 +86,7 @@ Rectangle { } } + Column { id: column1 anchors.left: parent.left diff --git a/MiddlePanel.qml b/MiddlePanel.qml index 62072af9..28d6f137 100644 --- a/MiddlePanel.qml +++ b/MiddlePanel.qml @@ -30,6 +30,7 @@ import QtQuick 2.2 Rectangle { color: "#F0EEEE" + signal paymentClicked(string address, string paymentId, double amount, double fee, int privacyLevel) states: [ State { @@ -72,6 +73,19 @@ Rectangle { anchors.right: parent.right anchors.top: styledRow.bottom anchors.bottom: parent.bottom + onLoaded: { + console.log("Loaded " + item); + } + + } + + Connections { + ignoreUnknownSignals: false + target: loader.item + onPaymentClicked : { + console.log("MiddlePanel: paymentClicked") + paymentClicked(address, paymentId, amount, fee, privacyLevel) + } } Rectangle { diff --git a/components/LineEdit.qml b/components/LineEdit.qml index 6994b75f..37c2390d 100644 --- a/components/LineEdit.qml +++ b/components/LineEdit.qml @@ -31,7 +31,9 @@ import QtQuick 2.0 Item { property alias placeholderText: input.placeholderText property alias text: input.text + property alias validator: input.validator property int fontSize: 18 + height: 37 Rectangle { @@ -54,5 +56,6 @@ Item { anchors.leftMargin: 4 anchors.rightMargin: 4 font.pixelSize: parent.fontSize + } } diff --git a/main.cpp b/main.cpp index 7331a4e4..70390a80 100644 --- a/main.cpp +++ b/main.cpp @@ -36,6 +36,7 @@ #include "oshelper.h" #include "WalletManager.h" #include "Wallet.h" +#include "PendingTransaction.h" @@ -53,6 +54,8 @@ int main(int argc, char *argv[]) qmlRegisterType("moneroComponents", 1, 0, "Clipboard"); qmlRegisterUncreatableType("Bitmonero.Wallet", 1, 0, "Wallet", "Wallet can't be instantiated directly"); + qmlRegisterUncreatableType("Bitmonero.PendingTransaction", 1, 0, "PendingTransaction", + "PendingTransaction can't be instantiated directly"); QQmlApplicationEngine engine; diff --git a/main.qml b/main.qml index 3b79d1ec..d6109339 100644 --- a/main.qml +++ b/main.qml @@ -32,6 +32,7 @@ import QtQuick.Controls 1.1 import QtQuick.Controls.Styles 1.1 import Qt.labs.settings 1.0 import Bitmonero.Wallet 1.0 +import Bitmonero.PendingTransaction 1.0 import "components" import "wizard" @@ -120,6 +121,8 @@ ApplicationWindow { function initialize() { + middlePanel.paymentClicked.connect(handlePayment); + if (typeof wizard.settings['wallet'] !== 'undefined') { wallet = wizard.settings['wallet']; } else { @@ -157,6 +160,27 @@ ApplicationWindow { return wallets.length > 0; } + function handlePayment(address, paymentId, amount, fee, privacyLevel) { + console.log("Process payment here: ", address, paymentId, amount, fee, privacyLevel) + // TODO: handle payment id + // TODO: handle fee; + // TODO: handle mixins + var amountxmr = walletManager.amountFromString(amount); + + console.log("integer amount: ", amountxmr); + var pendingTransaction = wallet.createTransaction(address, amountxmr); + if (pendingTransaction.status !== PendingTransaction.Status_Ok) { + console.error("Can't create transaction: ", pendingTransaction.errorString); + } else { + console.log("Transaction created, amount: " + walletManager.displayAmount(pendingTransaction.amount) + + ", fee: " + walletManager.displayAmount(pendingTransaction.fee)); + if (!pendingTransaction.commit()) { + console.log("Error committing transaction: " + pendingTransaction.errorString); + } + } + wallet.disposeTransaction(pendingTransaction); + } + visible: true width: rightPanelExpanded ? 1269 : 1269 - 300 height: 800 @@ -423,6 +447,7 @@ ApplicationWindow { } property var previousPosition + onPressed: { previousPosition = globalCursor.getPosition() } diff --git a/pages/Transfer.qml b/pages/Transfer.qml index 2535b8fe..df0a5b20 100644 --- a/pages/Transfer.qml +++ b/pages/Transfer.qml @@ -30,8 +30,11 @@ import QtQuick 2.0 import "../components" Rectangle { + signal paymentClicked(string address, string paymentId, double amount, double fee, int privacyLevel) + color: "#F0EEEE" + Label { id: amountLabel anchors.left: parent.left @@ -67,8 +70,9 @@ Rectangle { source: "../images/moneroIcon.png" } } - + // Amount input LineEdit { + id: amountLine placeholderText: qsTr("Amount...") width: parent.width - 37 - 17 } @@ -133,7 +137,7 @@ Rectangle { onLinkActivated: appWindow.showPageRequest("AddressBook") } - + // recipient address input LineEdit { id: addressLine anchors.left: parent.left @@ -142,10 +146,11 @@ Rectangle { anchors.leftMargin: 17 anchors.rightMargin: 17 anchors.topMargin: 5 + // validator: RegExpValidator { regExp: /[0-9A-Fa-f]{95}/g } } Label { - id: paymentLabel + id: paymentIdLabel anchors.left: parent.left anchors.right: parent.right anchors.top: addressLine.bottom @@ -156,21 +161,23 @@ Rectangle { text: qsTr("Payment ID ( Optional )") } + // payment id input LineEdit { - id: paymentLine + id: paymentIdLine anchors.left: parent.left anchors.right: parent.right - anchors.top: paymentLabel.bottom + anchors.top: paymentIdLabel.bottom anchors.leftMargin: 17 anchors.rightMargin: 17 anchors.topMargin: 5 + // validator: DoubleValidator { top: 0.0 } } Label { id: descriptionLabel anchors.left: parent.left anchors.right: parent.right - anchors.top: paymentLine.bottom + anchors.top: paymentIdLine.bottom anchors.leftMargin: 17 anchors.rightMargin: 17 anchors.topMargin: 17 @@ -200,5 +207,13 @@ Rectangle { shadowPressedColor: "#B32D00" releasedColor: "#FF6C3C" pressedColor: "#FF4304" + onClicked: { + // do more smart validation + + if (addressLine.text.length > 0 && amountLine.text.length > 0) { + console.log("paymentClicked") + paymentClicked(addressLine.text, paymentIdLine.text, amountLine.text, 0.0002, 1) + } + } } } diff --git a/src/libwalletqt/PendingTransaction.h b/src/libwalletqt/PendingTransaction.h index 29fa7cb4..d8c4ec1e 100644 --- a/src/libwalletqt/PendingTransaction.h +++ b/src/libwalletqt/PendingTransaction.h @@ -24,6 +24,8 @@ public: Status_Error = Bitmonero::PendingTransaction::Status_Error }; + Q_ENUM(Status) + Status status() const; QString errorString() const; Q_INVOKABLE bool commit(); diff --git a/src/libwalletqt/WalletManager.cpp b/src/libwalletqt/WalletManager.cpp index 6ad81e2a..a7742bca 100644 --- a/src/libwalletqt/WalletManager.cpp +++ b/src/libwalletqt/WalletManager.cpp @@ -92,6 +92,15 @@ QString WalletManager::displayAmount(quint64 amount) return QString::fromStdString(Bitmonero::Wallet::displayAmount(amount)); } +quint64 WalletManager::amountFromString(const QString &amount) +{ + return Bitmonero::Wallet::amountFromString(amount.toStdString()); +} + +quint64 WalletManager::amountFromDouble(double amount) +{ + return Bitmonero::Wallet::amountFromDouble(amount); +} WalletManager::WalletManager(QObject *parent) : QObject(parent) { diff --git a/src/libwalletqt/WalletManager.h b/src/libwalletqt/WalletManager.h index 30e6b02a..29df9048 100644 --- a/src/libwalletqt/WalletManager.h +++ b/src/libwalletqt/WalletManager.h @@ -45,6 +45,9 @@ public: //! since we can't call static method from QML, move it to this class Q_INVOKABLE QString displayAmount(quint64 amount); + Q_INVOKABLE quint64 amountFromString(const QString &amount); + Q_INVOKABLE quint64 amountFromDouble(double amount); + signals: public slots: -- cgit v1.2.3 From 39cb75e58c2823e6a25e229596af4e276d77b2ae Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Tue, 28 Jun 2016 22:37:14 +0300 Subject: Send money: confirmation popups added --- main.cpp | 1 + main.qml | 79 +++++++++++++++++++++++++++++----- src/libwalletqt/PendingTransaction.cpp | 1 + src/libwalletqt/Wallet.h | 2 +- 4 files changed, 71 insertions(+), 12 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 70390a80..7b2799d4 100644 --- a/main.cpp +++ b/main.cpp @@ -56,6 +56,7 @@ int main(int argc, char *argv[]) qmlRegisterUncreatableType("Bitmonero.Wallet", 1, 0, "Wallet", "Wallet can't be instantiated directly"); qmlRegisterUncreatableType("Bitmonero.PendingTransaction", 1, 0, "PendingTransaction", "PendingTransaction can't be instantiated directly"); + qRegisterMetaType(); QQmlApplicationEngine engine; diff --git a/main.qml b/main.qml index a4a8b3ff..721c69e4 100644 --- a/main.qml +++ b/main.qml @@ -30,6 +30,7 @@ import QtQuick 2.2 import QtQuick.Window 2.0 import QtQuick.Controls 1.1 import QtQuick.Controls.Styles 1.1 +import QtQuick.Dialogs 1.2 import Qt.labs.settings 1.0 import Bitmonero.Wallet 1.0 import Bitmonero.PendingTransaction 1.0 @@ -47,6 +48,7 @@ ApplicationWindow { property bool osx: false property alias persistentSettings : persistentSettings property var wallet; + property var transaction; function altKeyReleased() { ctrlPressed = false; } @@ -133,6 +135,10 @@ ApplicationWindow { wallet = walletManager.openWallet(wallet_path, "", persistentSettings.testnet); if (wallet.status !== Wallet.Status_Ok) { console.log("Error opening wallet: ", wallet.errorString); + informationPopup.title = qsTr("Error"); + informationPopup.text = qsTr("Couldn't open wallet: ") + wallet.errorString; + informationPopup.icon = StandardIcon.Critical + informationPopup.open() return; } console.log("Wallet opened successfully: ", wallet.errorString); @@ -169,6 +175,8 @@ ApplicationWindow { return wallets.length > 0; } + + // called on "transfer" function handlePayment(address, paymentId, amount, mixinCount, priority) { console.log("Creating transaction: ") console.log("\taddress: ", address, @@ -180,22 +188,53 @@ ApplicationWindow { var amountxmr = walletManager.amountFromString(amount); console.log("integer amount: ", amountxmr); - var pendingTransaction = wallet.createTransaction(address, paymentId, amountxmr, mixinCount, priority); - if (pendingTransaction.status !== PendingTransaction.Status_Ok) { - console.error("Can't create transaction: ", pendingTransaction.errorString); + transaction = wallet.createTransaction(address, paymentId, amountxmr, mixinCount, priority); + if (transaction.status !== PendingTransaction.Status_Ok) { + console.error("Can't create transaction: ", transaction.errorString); + informationPopup.title = qsTr("Error"); + informationPopup.text = qsTr("Can't create transaction: ") + transaction.errorString + informationPopup.icon = StandardIcon.Critical + informationPopup.open(); + // deleting transaction object, we don't want memleaks + wallet.disposeTransaction(transaction); + } else { - console.log("Transaction created, amount: " + walletManager.displayAmount(pendingTransaction.amount) - + ", fee: " + walletManager.displayAmount(pendingTransaction.fee)); - if (!pendingTransaction.commit()) { - console.log("Error committing transaction: " + pendingTransaction.errorString); - } else { - wallet.refresh(); - } + console.log("Transaction created, amount: " + walletManager.displayAmount(transaction.amount) + + ", fee: " + walletManager.displayAmount(transaction.fee)); + + // here we show confirmation popup; + + transactionConfirmationPopup.title = qsTr("Confirmation") + transactionConfirmationPopup.text = qsTr("Please confirm transaction:\n\n") + + "\naddress: " + address + + "\npayment id: " + paymentId + + "\namount: " + walletManager.displayAmount(transaction.amount) + + "\nfee: " + walletManager.displayAmount(transaction.fee) + transactionConfirmationPopup.icon = StandardIcon.Question + transactionConfirmationPopup.open() + // committing transaction + } + } + + // called after user confirms transaction + function handleTransactionConfirmed() { + if (!transaction.commit()) { + console.log("Error committing transaction: " + transaction.errorString); + informationPopup.title = qsTr("Error"); + informationPopup.text = qsTr("Couldn't send the money: ") + transaction.errorString + informationPopup.icon = StandardIcon.Critical + } else { + informationPopup.title = qsTr("Information") + informationPopup.text = qsTr("Money sent successfully") + informationPopup.icon = StandardIcon.Information } - wallet.disposeTransaction(pendingTransaction); + informationPopup.open() + wallet.refresh() + wallet.disposeTransaction(transaction) } + visible: true width: rightPanelExpanded ? 1269 : 1269 - 300 height: 800 @@ -232,6 +271,24 @@ ApplicationWindow { property string payment_id } + // TODO: replace with customized popups + + // Information dialog + MessageDialog { + id: informationPopup + standardButtons: StandardButton.Ok + } + + // Confrirmation aka question dialog + MessageDialog { + id: transactionConfirmationPopup + standardButtons: StandardButton.Ok + StandardButton.Cancel + onAccepted: { + handleTransactionConfirmed() + } + } + + Item { id: rootItem anchors.fill: parent diff --git a/src/libwalletqt/PendingTransaction.cpp b/src/libwalletqt/PendingTransaction.cpp index a5dc458d..8c0d8c29 100644 --- a/src/libwalletqt/PendingTransaction.cpp +++ b/src/libwalletqt/PendingTransaction.cpp @@ -1,5 +1,6 @@ #include "PendingTransaction.h" + PendingTransaction::Status PendingTransaction::status() const { return static_cast(m_pimpl->status()); diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index a62c0f14..241b89d8 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -80,7 +80,7 @@ public: //! creates transaction Q_INVOKABLE PendingTransaction * createTransaction(const QString &dst_addr, const QString &payment_id, quint64 amount, quint32 mixin_count, - PendingTransaction::Priority priority = PendingTransaction::Priority_Low); + PendingTransaction::Priority priority); //! deletes transaction and frees memory Q_INVOKABLE void disposeTransaction(PendingTransaction * t); -- cgit v1.2.3 From d9f031ec2a3b6dc256ea138a8aa8326e41130e4b Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Wed, 13 Jul 2016 15:24:40 +0300 Subject: Async API integration in progress --- main.cpp | 1 + main.qml | 43 ++++++++++++++++++++++++++++++++++--------- src/libwalletqt/Wallet.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/libwalletqt/Wallet.h | 9 +++++++++ 4 files changed, 88 insertions(+), 9 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 7b2799d4..43ef8186 100644 --- a/main.cpp +++ b/main.cpp @@ -56,6 +56,7 @@ int main(int argc, char *argv[]) qmlRegisterUncreatableType("Bitmonero.Wallet", 1, 0, "Wallet", "Wallet can't be instantiated directly"); qmlRegisterUncreatableType("Bitmonero.PendingTransaction", 1, 0, "PendingTransaction", "PendingTransaction can't be instantiated directly"); + qRegisterMetaType(); diff --git a/main.qml b/main.qml index e890a75b..b96b5dea 100644 --- a/main.qml +++ b/main.qml @@ -35,6 +35,7 @@ import Qt.labs.settings 1.0 import Bitmonero.Wallet 1.0 import Bitmonero.PendingTransaction 1.0 + import "components" import "wizard" @@ -50,6 +51,7 @@ ApplicationWindow { property var wallet; property var transaction; + function altKeyReleased() { ctrlPressed = false; } function showPageRequest(page) { @@ -122,7 +124,7 @@ ApplicationWindow { function initialize() { - + console.log("initializing..") middlePanel.paymentClicked.connect(handlePayment); if (typeof wizard.settings['wallet'] !== 'undefined') { @@ -143,24 +145,34 @@ ApplicationWindow { } console.log("Wallet opened successfully: ", wallet.errorString); } + // display splash screen... + console.log("initializing with daemon address..") if (!wallet.init(persistentSettings.daemon_address, 0)) { console.log("Error initialize wallet: ", wallet.errorString); return } + console.log("Wallet initialized successfully") + // TODO: update network indicator // subscribing for wallet updates wallet.updated.connect(onWalletUpdate); - + wallet.refreshed.connect(onWalletRefresh); + console.log("refreshing wallet async") // TODO: refresh asynchronously without blocking UI, implement signal(s) - wallet.refresh(); - + wallet.refreshAsync(); console.log("wallet balance: ", wallet.balance) } function onWalletUpdate() { - console.log("wallet updated") + console.log(">>> wallet updated") + leftPanel.unlockedBalanceText = walletManager.displayAmount(wallet.unlockedBalance); + leftPanel.balanceText = walletManager.displayAmount(wallet.balance); + } + + function onWalletRefresh() { + console.log(">>> wallet refreshed") leftPanel.unlockedBalanceText = walletManager.displayAmount(wallet.unlockedBalance); leftPanel.balanceText = walletManager.displayAmount(wallet.balance); } @@ -206,10 +218,10 @@ ApplicationWindow { transactionConfirmationPopup.title = qsTr("Confirmation") transactionConfirmationPopup.text = qsTr("Please confirm transaction:\n\n") - + "\nAddress: " + address - + "\nPayment ID: " + paymentId - + "\nAmount: " + walletManager.displayAmount(transaction.amount) - + "\nFee: " + walletManager.displayAmount(transaction.fee) + + qsTr("\nAddress: ") + address + + qsTr("\nPayment ID: ") + paymentId + + qsTr("\nAmount: ") + walletManager.displayAmount(transaction.amount) + + qsTr("\nFee: ") + walletManager.displayAmount(transaction.fee) transactionConfirmationPopup.icon = StandardIcon.Question transactionConfirmationPopup.open() // committing transaction @@ -288,6 +300,19 @@ ApplicationWindow { } } + Window { + id: walletInitializationSplash + modality: Qt.ApplicationModal + flags: Qt.SplashScreen + height: 100 + width: 250 + Text { + anchors.fill: parent + text: qsTr("Initializing Wallet..."); + } + + } + Item { id: rootItem diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index e6368ad2..3697984e 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -14,6 +14,45 @@ namespace { } +class WalletListenerImpl : public Bitmonero::WalletListener +{ +public: + WalletListenerImpl(Wallet * w) + : m_wallet(w) + { + + } + + virtual void moneySpent(const std::string &txId, uint64_t amount) + { + // TODO + Q_UNUSED(txId) + Q_UNUSED(amount) + } + + virtual void moneyReceived(const std::string &txId, uint64_t amount) + { + // TODO + Q_UNUSED(txId) + Q_UNUSED(amount) + } + + virtual void updated() + { + emit m_wallet->updated(); + } + + // called when wallet refreshed by background thread or explicitly + virtual void refreshed() + { + emit m_wallet->refreshed(); + } + +private: + Wallet * m_wallet; +}; + + QString Wallet::getSeed() const { @@ -88,6 +127,11 @@ bool Wallet::refresh() return result; } +void Wallet::refreshAsync() +{ + m_walletImpl->refreshAsync(); +} + PendingTransaction *Wallet::createTransaction(const QString &dst_addr, const QString &payment_id, quint64 amount, quint32 mixin_count, PendingTransaction::Priority priority) diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index 241b89d8..4d6a1ea0 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -77,6 +77,10 @@ public: //! refreshes the wallet Q_INVOKABLE bool refresh(); + + //! refreshes the wallet asynchronously + Q_INVOKABLE void refreshAsync(); + //! creates transaction Q_INVOKABLE PendingTransaction * createTransaction(const QString &dst_addr, const QString &payment_id, quint64 amount, quint32 mixin_count, @@ -103,6 +107,10 @@ public: signals: void updated(); + // emitted when refresh process finished (could take a long time) + // signalling only after we + void refreshed(); + private: Wallet(Bitmonero::Wallet *w, QObject * parent = 0); @@ -110,6 +118,7 @@ private: private: friend class WalletManager; + friend class WalletListenerImpl; //! libwallet's Bitmonero::Wallet * m_walletImpl; // history lifetime managed by wallet; -- cgit v1.2.3 From a9339838ac295a4d045433c1b20fd5666fb35575 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Tue, 19 Jul 2016 23:31:09 +0300 Subject: TranslationManager, Russian translation example --- TranslationManager.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++ TranslationManager.h | 29 +++++++++++++++++++ get_libwallet_api.sh | 2 +- lang/languages.xml | 33 ++++++++++++++-------- main.cpp | 11 ++++++++ monero-core.pro | 18 ++++++------ translations/monero-core_de.ts | 5 ++-- translations/monero-core_en.ts | 5 ++-- translations/monero-core_it.ts | 5 ++-- translations/monero-core_pl.ts | 5 ++-- translations/monero-core_ru.ts | 11 ++++---- translations/monero-core_zh.ts | 5 ++-- wizard/WizardWelcome.qml | 39 +++++++++++++++++++++++--- 13 files changed, 192 insertions(+), 39 deletions(-) create mode 100644 TranslationManager.cpp create mode 100644 TranslationManager.h (limited to 'main.cpp') diff --git a/TranslationManager.cpp b/TranslationManager.cpp new file mode 100644 index 00000000..69448ce2 --- /dev/null +++ b/TranslationManager.cpp @@ -0,0 +1,63 @@ +#include "TranslationManager.h" + +#include +#include +#include +#include +#include + + +TranslationManager * TranslationManager::m_instance = nullptr; + + +TranslationManager::TranslationManager(QObject *parent) : QObject(parent) +{ + m_translator = new QTranslator(this); +} + +bool TranslationManager::setLanguage(const QString &language) +{ + qDebug() << __FUNCTION__ << " " << language; + // if language is "en", remove translator + if (language.toLower() == "en") { + qApp->removeTranslator(m_translator); + emit languageChanged(); + return true; + } + + // we expecting to have translation files in "i18n" directory + QString dir = qApp->applicationDirPath() + QDir::separator() + "i18n"; + + QString filename = "monero-core_" + language; + + qDebug("%s: loading translation file '%s' from '%s", + __FUNCTION__, qPrintable(filename), qPrintable(dir)); + + + if (m_translator->load(filename, dir)) { + qDebug("%s: translation for language '%s' loaded successfully", + __FUNCTION__, qPrintable(language)); + // TODO: apply locale? + qApp->installTranslator(m_translator); + emit languageChanged(); + return true; + } else { + qCritical("%s: error loading translation for language '%s'", + __FUNCTION__, qPrintable(language)); + return false; + } +} + +TranslationManager *TranslationManager::instance() +{ + if (!m_instance) { + m_instance = new TranslationManager(); + } + return m_instance; +} + +QString TranslationManager::emptyString() +{ + return ""; +} + diff --git a/TranslationManager.h b/TranslationManager.h new file mode 100644 index 00000000..94d0e50e --- /dev/null +++ b/TranslationManager.h @@ -0,0 +1,29 @@ +#ifndef TRANSLATIONMANAGER_H +#define TRANSLATIONMANAGER_H + +#include + +class QTranslator; +class TranslationManager : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString emptyString READ emptyString NOTIFY languageChanged) +public: + Q_INVOKABLE bool setLanguage(const QString &language); + static TranslationManager *instance(); + + QString emptyString(); + +signals: + void languageChanged(); + +private: + explicit TranslationManager(QObject *parent = 0); + +private: + static TranslationManager * m_instance; + QTranslator * m_translator; + +}; + +#endif // TRANSLATIONMANAGER_H diff --git a/get_libwallet_api.sh b/get_libwallet_api.sh index 9e69235e..53ae9268 100755 --- a/get_libwallet_api.sh +++ b/get_libwallet_api.sh @@ -2,7 +2,7 @@ BITMONERO_URL=https://github.com/mbg033/bitmonero.git -BITMONERO_BRANCH=devel +BITMONERO_BRANCH=master # thanks to SO: http://stackoverflow.com/a/20283965/4118915 CPU_CORE_COUNT=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) pushd $(pwd) diff --git a/lang/languages.xml b/lang/languages.xml index 8f5120a7..cc47eaa1 100644 --- a/lang/languages.xml +++ b/lang/languages.xml @@ -1,14 +1,25 @@ - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/main.cpp b/main.cpp index 43ef8186..030a21c3 100644 --- a/main.cpp +++ b/main.cpp @@ -37,6 +37,7 @@ #include "WalletManager.h" #include "Wallet.h" #include "PendingTransaction.h" +#include "TranslationManager.h" @@ -53,10 +54,18 @@ int main(int argc, char *argv[]) app.installEventFilter(eventFilter); qmlRegisterType("moneroComponents", 1, 0, "Clipboard"); + qmlRegisterUncreatableType("Bitmonero.Wallet", 1, 0, "Wallet", "Wallet can't be instantiated directly"); + qmlRegisterUncreatableType("Bitmonero.PendingTransaction", 1, 0, "PendingTransaction", "PendingTransaction can't be instantiated directly"); + qmlRegisterUncreatableType("Bitmonero.WalletManager", 1, 0, "WalletManager", + "WalletManager can't be instantiated directly"); + + qmlRegisterUncreatableType("moneroComponents", 1, 0, "TranslationManager", + "TranslationManager can't be instantiated directly"); + qRegisterMetaType(); @@ -69,6 +78,8 @@ int main(int argc, char *argv[]) engine.rootContext()->setContextProperty("walletManager", WalletManager::instance()); + engine.rootContext()->setContextProperty("translationManager", TranslationManager::instance()); + // export to QML monero accounts root directory // wizard is talking about where // to save the wallet file (.keys, .bin), they have to be user-accessible for diff --git a/monero-core.pro b/monero-core.pro index 845e0501..a5b170e5 100644 --- a/monero-core.pro +++ b/monero-core.pro @@ -19,7 +19,8 @@ HEADERS += \ src/libwalletqt/PendingTransaction.h \ src/libwalletqt/TransactionHistory.h \ src/libwalletqt/TransactionInfo.h \ - oshelper.h + oshelper.h \ + TranslationManager.h SOURCES += main.cpp \ @@ -31,7 +32,8 @@ SOURCES += main.cpp \ src/libwalletqt/PendingTransaction.cpp \ src/libwalletqt/TransactionHistory.cpp \ src/libwalletqt/TransactionInfo.cpp \ - oshelper.cpp + oshelper.cpp \ + TranslationManager.cpp lupdate_only { SOURCES = *.qml \ @@ -101,11 +103,11 @@ macx { # translations files; TRANSLATIONS = $$PWD/translations/monero-core_en.ts \ # English (could be untranslated) - $$PWD/translations/monero-core_de.ts \ # Deutsch - $$PWD/translations/monero-core_zh.ts \ # Chineese - $$PWD/translations/monero-core_ru.ts \ # Russian - $$PWD/translations/monero-core_it.ts \ # Italian - $$PWD/translations/monero-core_pl.ts \ # Polish + $$PWD/translations/monero-core_de.ts \ # Deutsch + $$PWD/translations/monero-core_zh.ts \ # Chineese + $$PWD/translations/monero-core_ru.ts \ # Russian + $$PWD/translations/monero-core_it.ts \ # Italian + $$PWD/translations/monero-core_pl.ts \ # Polish @@ -117,7 +119,7 @@ trans_update.depends = $$_PRO_FILE_ trans_release.commands = lrelease $$_PRO_FILE_ trans_release.depends = trans_update $$TRANSLATIONS -translate.commands = $(COPY) $$PWD/*.qm ${DESTDIR} +translate.commands = $(MKDIR) ${DESTDIR}/i18n && $(COPY) $$PWD/translations/*.qm ${DESTDIR}/i18n translate.depends = trans_release QMAKE_EXTRA_TARGETS += trans_update trans_release translate diff --git a/translations/monero-core_de.ts b/translations/monero-core_de.ts index 09e96e70..53c8bef3 100644 --- a/translations/monero-core_de.ts +++ b/translations/monero-core_de.ts @@ -666,12 +666,13 @@ WizardWelcome - + + Welcome - + Please choose a language and regional format. diff --git a/translations/monero-core_en.ts b/translations/monero-core_en.ts index 307233ba..957bfdd0 100644 --- a/translations/monero-core_en.ts +++ b/translations/monero-core_en.ts @@ -666,12 +666,13 @@ WizardWelcome - + + Welcome - + Please choose a language and regional format. diff --git a/translations/monero-core_it.ts b/translations/monero-core_it.ts index e59d65eb..a24a0501 100644 --- a/translations/monero-core_it.ts +++ b/translations/monero-core_it.ts @@ -666,12 +666,13 @@ WizardWelcome - + + Welcome - + Please choose a language and regional format. diff --git a/translations/monero-core_pl.ts b/translations/monero-core_pl.ts index 237bf62b..67e8a0aa 100644 --- a/translations/monero-core_pl.ts +++ b/translations/monero-core_pl.ts @@ -666,12 +666,13 @@ WizardWelcome - + + Welcome - + Please choose a language and regional format. diff --git a/translations/monero-core_ru.ts b/translations/monero-core_ru.ts index a5c61585..ab0d509c 100644 --- a/translations/monero-core_ru.ts +++ b/translations/monero-core_ru.ts @@ -6,7 +6,7 @@ Add new entry - + Новая запись @@ -666,14 +666,15 @@ WizardWelcome - + + Welcome - + Добро пожаловать - + Please choose a language and regional format. - + Пожалуйста выберите язык и региональный формат. diff --git a/translations/monero-core_zh.ts b/translations/monero-core_zh.ts index 5dc6440a..d47f1c24 100644 --- a/translations/monero-core_zh.ts +++ b/translations/monero-core_zh.ts @@ -666,12 +666,13 @@ WizardWelcome - + + Welcome - + Please choose a language and regional format. diff --git a/wizard/WizardWelcome.qml b/wizard/WizardWelcome.qml index 31bdbcb7..72bf27cc 100644 --- a/wizard/WizardWelcome.qml +++ b/wizard/WizardWelcome.qml @@ -39,11 +39,25 @@ Item { function onPageClosed(settingsObject) { var lang = languagesModel.get(gridView.currentIndex); settingsObject['language'] = lang.display_name; - settingsObject['wallet_language'] = lang.wallet_name; + settingsObject['wallet_language'] = lang.wallet_language; settingsObject['locale'] = lang.locale; return true } + +// function retranslateUi() { +// welcomeText.text = qsTr("Welcome") +// } + + +// Connections { +// target: translationManager +// onEmptyStringChanged: { +// console.log("languageChanged") +// retranslateUi() +// } +// } + Column { id: headerColumn anchors.left: parent.left @@ -55,6 +69,7 @@ Item { spacing: 24 Text { + id: welcomeText anchors.left: parent.left anchors.right: parent.right font.family: "Arial" @@ -62,10 +77,14 @@ Item { //renderType: Text.NativeRendering color: "#3F3F3F" wrapMode: Text.Wrap - text: qsTr("Welcome") + // hack to implement dynamic translation + // https://wiki.qt.io/How_to_do_dynamic_translation_in_QML + text: qsTr("Welcome") + + translationManager.emptyString } Text { + id: selectLanguageText anchors.left: parent.left anchors.right: parent.right font.family: "Arial" @@ -74,6 +93,7 @@ Item { color: "#4A4646" wrapMode: Text.Wrap text: qsTr("Please choose a language and regional format.") + + translationManager.emptyString } } @@ -84,11 +104,13 @@ Item { XmlRole { name: "display_name"; query: "@display_name/string()" } XmlRole { name: "locale"; query: "@locale/string()" } - XmlRole { name: "wallet_name"; query: "@wallet_name/string()" } + XmlRole { name: "wallet_language"; query: "@wallet_language/string()" } XmlRole { name: "flag"; query: "@flag/string()" } // TODO: XmlListModel is read only, we should store current language somewhere else // and set current language accordingly XmlRole { name: "isCurrent"; query: "@enabled/string()" } + + } GridView { @@ -111,6 +133,8 @@ Item { height: gridView.cellHeight + + Rectangle { id: flagRect width: 60; height: 60 @@ -139,8 +163,15 @@ Item { anchors.fill: parent onClicked: { gridView.currentIndex = index + var data = languagesModel.get(gridView.currentIndex); + if (data !== null || data !== undefined) { + var locale = data.locale + translationManager.setLanguage(locale.split("_")[0]); + } } } - } + } // delegate + + } } -- cgit v1.2.3 From 9cd73dfbbed6e200852ca9e1c1494ea3e5eae6c3 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Wed, 27 Jul 2016 22:32:33 +0300 Subject: Translations are separate qm files --- .gitignore | 1 + TranslationManager.cpp | 6 +++- build.sh | 9 ++++-- main.cpp | 3 ++ monero-core.pro | 86 +++++++++++++++++++++++++++++--------------------- qml.qrc | 6 ---- 6 files changed, 65 insertions(+), 46 deletions(-) (limited to 'main.cpp') diff --git a/.gitignore b/.gitignore index a2ce1444..f2bec9c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.user *.user.* +translations/*.qm diff --git a/TranslationManager.cpp b/TranslationManager.cpp index afd04ef6..fa39d35a 100644 --- a/TranslationManager.cpp +++ b/TranslationManager.cpp @@ -26,7 +26,11 @@ bool TranslationManager::setLanguage(const QString &language) } // translations are compiled into app binary - QString dir = ":/translations"; +#ifdef Q_OS_MACX + QString dir = qApp->applicationDirPath() + "/../Resources/translations"; +#else + QString dir = qApp->applicationDirPath() + "/translations"; +#endif QString filename = "monero-core_" + language; diff --git a/build.sh b/build.sh index 5cfea74d..3c3260f5 100755 --- a/build.sh +++ b/build.sh @@ -2,14 +2,17 @@ pushd $(pwd) ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +BITMOMERO_DIR=bitmonero -#$SHELL get_libwallet_api.sh +if [ ! -d $BITMOMERO_DIR ]; then + $SHELL get_libwallet_api.sh +fi if [ ! -d build ]; then mkdir build; fi cd build echo $(pwd) -qmake ../monero-core.pro "CONFIG += release" -make release +qmake ../monero-core.pro "CONFIG+=release" +make make deploy popd diff --git a/main.cpp b/main.cpp index 030a21c3..9f109e01 100644 --- a/main.cpp +++ b/main.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include "clipboardAdapter.h" #include "filter.h" #include "oscursor.h" @@ -46,6 +47,8 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); + qDebug() << "app startd"; + app.setApplicationName("monero-core"); app.setOrganizationDomain("getmonero.org"); app.setOrganizationName("The Monero Project"); diff --git a/monero-core.pro b/monero-core.pro index 0997d2bd..668cecdb 100644 --- a/monero-core.pro +++ b/monero-core.pro @@ -5,7 +5,6 @@ QT += qml quick widgets WALLET_ROOT=$$PWD/bitmonero CONFIG += c++11 -CONFIG += debug_and_release # cleaning "auto-generated" bitmonero directory on "make distclean" QMAKE_DISTCLEAN += -r $$WALLET_ROOT @@ -13,8 +12,6 @@ QMAKE_DISTCLEAN += -r $$WALLET_ROOT INCLUDEPATH += $$WALLET_ROOT/include \ $$PWD/src/libwalletqt - - HEADERS += \ filter.h \ clipboardAdapter.h \ @@ -104,51 +101,59 @@ macx { -lcrypto \ -ldl - deploy.commands += macdeployqt $$sprintf("%1/release/%2.app", $$OUT_PWD,$$TARGET) } -deploy.commands += - -# translations files; -TRANSLATIONS = $$PWD/translations/monero-core_en.ts \ # English (could be untranslated) - $$PWD/translations/monero-core_de.ts \ # Deutsch - $$PWD/translations/monero-core_zh.ts \ # Chineese - $$PWD/translations/monero-core_ru.ts \ # Russian - $$PWD/translations/monero-core_it.ts \ # Italian - $$PWD/translations/monero-core_pl.ts \ # Polish - - - -# extra make targets for lupdate and lrelease invocation -# use "make lupdate" to update *.ts files and "make lrelease" to generate *.qm files -trans_update.commands = lupdate $$_PRO_FILE_ -trans_update.depends = $$_PRO_FILE_ - -trans_release.commands = lrelease $$_PRO_FILE_ -trans_release.depends = trans_update $$TRANSLATIONS - -#translate.commands = $(MKDIR) ${DESTDIR}/i18n && $(COPY) $$PWD/translations/*.qm ${DESTDIR}/i18n -translate.depends = trans_release - +# translation stuff +TRANSLATIONS = \ # English is default language, no explicit translation file + $$PWD/translations/monero-core_de.ts \ # Deutsch + $$PWD/translations/monero-core_zh.ts \ # Chineese + $$PWD/translations/monero-core_ru.ts \ # Russian + $$PWD/translations/monero-core_it.ts \ # Italian + $$PWD/translations/monero-core_pl.ts \ # Polish +CONFIG(release, debug|release) { + DESTDIR = release + LANGUPD_OPTIONS = -locations relative -no-ui-lines + LANGREL_OPTIONS = -compress -nounfinished -removeidentical + +} else { + DESTDIR = debug + LANGUPD_OPTIONS = + LANGREL_OPTIONS = -markuntranslated "MISS_TR " +} -QMAKE_EXTRA_TARGETS += trans_update trans_release translate deploy +TARGET_FULL_PATH = $$OUT_PWD/$$DESTDIR -# updating transations only in release mode as this is requires to re-link project -# even if no changes were made. +macx { + TARGET_FULL_PATH = $$sprintf("%1/%2/%3.app", $$OUT_PWD, $$DESTDIR, $$TARGET) +} -#PRE_TARGETDEPS += translate +TRANSLATION_TARGET_DIR = $$TARGET_FULL_PATH/Contents/Resources/translations -CONFIG(release, debug|release) { - DESTDIR=release - PRE_TARGETDEPS += translate +isEmpty(QMAKE_LUPDATE) { + win32:LANGUPD = $$[QT_INSTALL_BINS]\lupdate.exe + else:LANGUPD = $$[QT_INSTALL_BINS]/lupdate } -CONFIG(debug, debug|release) { - DESTDIR=debug +isEmpty(QMAKE_LRELEASE) { + win32:LANGREL = $$[QT_INSTALL_BINS]\lrelease.exe + else:LANGREL = $$[QT_INSTALL_BINS]/lrelease } +langupd.command = \ + $$LANGUPD $$LANGUPD_OPTIONS $$shell_path($$_PRO_FILE) -ts $$_PRO_FILE_PWD/$$TRANSLATIONS + +langrel.depends = langupd +langrel.input = TRANSLATIONS +langrel.output = $$TRANSLATION_TARGET_DIR/${QMAKE_FILE_BASE}.qm +langrel.commands = \ + $$LANGREL $$LANGREL_OPTIONS ${QMAKE_FILE_IN} -qm $$TRANSLATION_TARGET_DIR/${QMAKE_FILE_BASE}.qm +langrel.CONFIG += no_link + +QMAKE_EXTRA_TARGETS += langupd deploy +QMAKE_EXTRA_COMPILERS += langrel +PRE_TARGETDEPS += langupd compiler_langrel_make_all RESOURCES += qml.qrc @@ -157,6 +162,14 @@ QML_IMPORT_PATH = # Default rules for deployment. include(deployment.pri) +macx { + deploy.commands += macdeployqt $$sprintf("%1/%2/%3.app", $$OUT_PWD, $$DESTDIR, $$TARGET) +} + +win32 { + deploy.commands += windeployqt $$sprintf("%1/%2/%3", $$OUT_PWD, $$DESTDIR, $$TARGET) +} + @@ -167,3 +180,4 @@ OTHER_FILES += \ DISTFILES += \ notes.txt + diff --git a/qml.qrc b/qml.qrc index 152ea8f2..eca9f561 100644 --- a/qml.qrc +++ b/qml.qrc @@ -114,11 +114,5 @@ pages/Receive.qml components/IconButton.qml lang/flags/italy.png - translations/monero-core_de.qm - translations/monero-core_en.qm - translations/monero-core_it.qm - translations/monero-core_pl.qm - translations/monero-core_ru.qm - translations/monero-core_zh.qm -- cgit v1.2.3 From 6b9afcf291cb5ab5db78f358a6213b1afc6081af Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Tue, 23 Aug 2016 10:32:01 +0300 Subject: extra debug logging --- main.cpp | 2 ++ src/libwalletqt/WalletManager.cpp | 17 ++++++++--------- src/libwalletqt/WalletManager.h | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 9 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 9f109e01..d0e9e085 100644 --- a/main.cpp +++ b/main.cpp @@ -111,5 +111,7 @@ int main(int argc, char *argv[]) QObject::connect(eventFilter, SIGNAL(mousePressed(QVariant,QVariant,QVariant)), rootObject, SLOT(mousePressed(QVariant,QVariant,QVariant))); QObject::connect(eventFilter, SIGNAL(mouseReleased(QVariant,QVariant,QVariant)), rootObject, SLOT(mouseReleased(QVariant,QVariant,QVariant))); + WalletManager::instance()->setLogLevel(WalletManager::LogLevel_Max); + return app.exec(); } diff --git a/src/libwalletqt/WalletManager.cpp b/src/libwalletqt/WalletManager.cpp index da5c4cd7..947ccbfb 100644 --- a/src/libwalletqt/WalletManager.cpp +++ b/src/libwalletqt/WalletManager.cpp @@ -8,14 +8,9 @@ #include #include - - WalletManager * WalletManager::m_instance = nullptr; - - - WalletManager *WalletManager::instance() { if (!m_instance) { @@ -36,9 +31,11 @@ Wallet *WalletManager::createWallet(const QString &path, const QString &password Wallet *WalletManager::openWallet(const QString &path, const QString &password, bool testnet) { - // TODO: call the libwallet api here; + qDebug("%s: opening wallet at %s, testnet = %d ", + __PRETTY_FUNCTION__, qPrintable(path), testnet); Bitmonero::Wallet * w = m_pimpl->openWallet(path.toStdString(), password.toStdString(), testnet); + qDebug("%s: opened wallet: %s, status: %d", __PRETTY_FUNCTION__, w->address().c_str(), w->status()); Wallet * wallet = new Wallet(w); // move wallet to the GUI thread. Otherwise it wont be emitting signals @@ -46,7 +43,6 @@ Wallet *WalletManager::openWallet(const QString &path, const QString &password, wallet->moveToThread(qApp->thread()); } - return wallet; } @@ -141,9 +137,12 @@ quint64 WalletManager::amountFromDouble(double amount) return Bitmonero::Wallet::amountFromDouble(amount); } +void WalletManager::setLogLevel(int logLevel) +{ + Bitmonero::WalletManagerFactory::setLogLevel(logLevel); +} + WalletManager::WalletManager(QObject *parent) : QObject(parent) { m_pimpl = Bitmonero::WalletManagerFactory::getWalletManager(); } - - diff --git a/src/libwalletqt/WalletManager.h b/src/libwalletqt/WalletManager.h index 27224b5f..1866b7cd 100644 --- a/src/libwalletqt/WalletManager.h +++ b/src/libwalletqt/WalletManager.h @@ -2,6 +2,7 @@ #define WALLETMANAGER_H #include +#include class Wallet; namespace Bitmonero { @@ -12,6 +13,17 @@ class WalletManager : public QObject { Q_OBJECT public: + enum LogLevel { + LogLevel_Silent = Bitmonero::WalletManagerFactory::LogLevel_Silent, + LogLevel_0 = Bitmonero::WalletManagerFactory::LogLevel_0, + LogLevel_1 = Bitmonero::WalletManagerFactory::LogLevel_1, + LogLevel_2 = Bitmonero::WalletManagerFactory::LogLevel_2, + LogLevel_3 = Bitmonero::WalletManagerFactory::LogLevel_3, + LogLevel_4 = Bitmonero::WalletManagerFactory::LogLevel_4, + LogLevel_Min = Bitmonero::WalletManagerFactory::LogLevel_Min, + LogLevel_Max = Bitmonero::WalletManagerFactory::LogLevel_Max, + }; + static WalletManager * instance(); // wizard: createWallet path; Q_INVOKABLE Wallet * createWallet(const QString &path, const QString &password, @@ -71,6 +83,8 @@ public: Q_INVOKABLE quint64 amountFromString(const QString &amount); Q_INVOKABLE quint64 amountFromDouble(double amount); + void setLogLevel(int logLevel); + signals: void walletOpened(Wallet * wallet); -- cgit v1.2.3 From 376db6cf16910b0facf10c90afcdfe2a50fc1045 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Tue, 23 Aug 2016 11:55:51 +0300 Subject: Display "processing.." splashscreen while wallet initializing --- components/PasswordDialog.qml | 28 ++++++++++++++++++ components/ProcessingSplash.qml | 63 +++++++++++++++++++++++++++++++++++++++++ main.cpp | 3 ++ main.qml | 44 +++++++++++++++++----------- qml.qrc | 1 + 5 files changed, 122 insertions(+), 17 deletions(-) create mode 100644 components/ProcessingSplash.qml (limited to 'main.cpp') diff --git a/components/PasswordDialog.qml b/components/PasswordDialog.qml index cd66d461..a8ff294a 100644 --- a/components/PasswordDialog.qml +++ b/components/PasswordDialog.qml @@ -1,3 +1,31 @@ +// Copyright (c) 2014-2015, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + import QtQuick 2.0 import QtQuick.Controls 1.4 import QtQuick.Dialogs 1.2 diff --git a/components/ProcessingSplash.qml b/components/ProcessingSplash.qml new file mode 100644 index 00000000..f98feb3b --- /dev/null +++ b/components/ProcessingSplash.qml @@ -0,0 +1,63 @@ +// Copyright (c) 2014-2015, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import QtQuick 2.0 +import QtQuick.Window 2.1 +import QtQuick.Controls 1.4 +import QtQuick.Layouts 1.1 + +Window { + id: splash + modality: Qt.ApplicationModal + flags: Qt.SplashScreen + property alias message: message.text + width: 200 + height: 100 + opacity: 0.5 + + ColumnLayout { + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + + BusyIndicator { + running: parent.visible + Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter + } + + Text { + id: message + text: "Please wait..." + font { + pointSize: 22 + } + horizontalAlignment: Text.AlignHCenter + } + } + + +} diff --git a/main.cpp b/main.cpp index d0e9e085..387c4b13 100644 --- a/main.cpp +++ b/main.cpp @@ -72,6 +72,8 @@ int main(int argc, char *argv[]) qRegisterMetaType(); + + QQmlApplicationEngine engine; OSCursor cursor; @@ -83,6 +85,7 @@ int main(int argc, char *argv[]) engine.rootContext()->setContextProperty("translationManager", TranslationManager::instance()); + // export to QML monero accounts root directory // wizard is talking about where // to save the wallet file (.keys, .bin), they have to be user-accessible for diff --git a/main.qml b/main.qml index f589c666..636945e8 100644 --- a/main.qml +++ b/main.qml @@ -147,11 +147,11 @@ ApplicationWindow { walletManager.openWalletAsync(wallet_path, appWindow.password, persistentSettings.testnet); } - } function connectWallet(wallet) { + showProcessingSplash() currentWallet = wallet currentWallet.refreshed.connect(onWalletRefresh) currentWallet.updated.connect(onWalletUpdate) @@ -167,7 +167,6 @@ ApplicationWindow { function onWalletOpened(wallet) { console.log(">>> wallet opened: " + wallet) - if (wallet.status !== Wallet.Status_Ok) { if (appWindow.password === '') { console.error("Error opening wallet with empty password: ", wallet.errorString); @@ -188,7 +187,6 @@ ApplicationWindow { informationPopup.onCloseCallback = function() { passwordDialog.open() } - } return; } @@ -212,6 +210,10 @@ ApplicationWindow { function onWalletRefresh() { console.log(">>> wallet refreshed") + if (splash.visible) { + hideProcessingSplash() + } + leftPanel.networkStatus.connected = currentWallet.connected onWalletUpdate(); } @@ -297,6 +299,19 @@ ApplicationWindow { basicPanel.enabled = enable; } + function showProcessingSplash(message) { + console.log("Displaying processing splash") + if (typeof message != 'undefined') { + splash.message = message + } + splash.show() + } + + function hideProcessingSplash() { + console.log("Hiding processing splash") + splash.hide() + } + objectName: "appWindow" visible: true @@ -371,10 +386,6 @@ ApplicationWindow { onAccepted: { appWindow.currentWallet = null appWindow.initialize(); - -// var wallet_path = walletPath(); -// console.log("opening wallet with password: ", wallet_path); -// walletManager.openWalletAsync(wallet_path, password, persistentSettings.testnet); } onRejected: { appWindow.enableUI(false) @@ -384,19 +395,18 @@ ApplicationWindow { } } - Window { - id: walletInitializationSplash - modality: Qt.ApplicationModal - flags: Qt.SplashScreen - height: 100 - width: 250 - Text { - anchors.fill: parent - text: qsTr("Initializing Wallet..."); - } + + ProcessingSplash { + id: splash + width: appWindow.width / 2 + height: appWindow.height / 2 + x: (appWindow.width - width) / 2 + appWindow.x + y: (appWindow.height - height) / 2 + appWindow.y + message: qsTr("Please wait...") } + Item { id: rootItem anchors.fill: parent diff --git a/qml.qrc b/qml.qrc index dcf4b9b1..a44266b9 100644 --- a/qml.qrc +++ b/qml.qrc @@ -115,5 +115,6 @@ components/IconButton.qml lang/flags/italy.png components/PasswordDialog.qml + components/ProcessingSplash.qml -- cgit v1.2.3 From 4fa8ad3b199483094cf9988f33da1ab6343d7c8a Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Tue, 23 Aug 2016 16:07:52 +0300 Subject: Transfer page: validate amount --- components/StandardButton.qml | 11 +++++++++-- main.cpp | 2 +- main.qml | 27 +++++++++++++++++++++------ pages/Transfer.qml | 27 ++++++++++++++++----------- src/libwalletqt/WalletManager.cpp | 16 +++++++++++++--- src/libwalletqt/WalletManager.h | 11 ++++++++--- 6 files changed, 68 insertions(+), 26 deletions(-) (limited to 'main.cpp') diff --git a/components/StandardButton.qml b/components/StandardButton.qml index 208d90d3..5a088fbf 100644 --- a/components/StandardButton.qml +++ b/components/StandardButton.qml @@ -47,7 +47,10 @@ Item { height: parent.height - 1 y: buttonArea.pressed ? 0 : 1 //radius: 4 - color: buttonArea.pressed ? parent.shadowPressedColor : parent.shadowReleasedColor + color: { + parent.enabled ? (buttonArea.pressed ? parent.shadowPressedColor : parent.shadowReleasedColor) + : Qt.lighter(parent.shadowReleasedColor) + } } Rectangle { @@ -55,7 +58,11 @@ Item { anchors.right: parent.right height: parent.height - 1 y: buttonArea.pressed ? 1 : 0 - color: buttonArea.pressed ? parent.pressedColor : parent.releasedColor + color: { + parent.enabled ? (buttonArea.pressed ? parent.pressedColor : parent.releasedColor) + : Qt.lighter(parent.releasedColor) + + } //radius: 4 } diff --git a/main.cpp b/main.cpp index 387c4b13..e356659c 100644 --- a/main.cpp +++ b/main.cpp @@ -114,7 +114,7 @@ int main(int argc, char *argv[]) QObject::connect(eventFilter, SIGNAL(mousePressed(QVariant,QVariant,QVariant)), rootObject, SLOT(mousePressed(QVariant,QVariant,QVariant))); QObject::connect(eventFilter, SIGNAL(mouseReleased(QVariant,QVariant,QVariant)), rootObject, SLOT(mouseReleased(QVariant,QVariant,QVariant))); - WalletManager::instance()->setLogLevel(WalletManager::LogLevel_Max); + WalletManager::instance()->setLogLevel(WalletManager::LogLevel_Silent); return app.exec(); } diff --git a/main.qml b/main.qml index 636945e8..6d57b634 100644 --- a/main.qml +++ b/main.qml @@ -135,7 +135,7 @@ ApplicationWindow { } middlePanel.paymentClicked.connect(handlePayment); - basicPanel.paymentClicked.connect(handlePayment); + // basicPanel.paymentClicked.connect(handlePayment); // wallet already opened with wizard, we just need to initialize it @@ -240,10 +240,25 @@ ApplicationWindow { ", mixins: ", mixinCount, ", priority: ", priority); - var amountxmr = walletManager.amountFromString(amount); + // validate amount; + var amountxmr = walletManager.amountFromString(amount); console.log("integer amount: ", amountxmr); - transaction = wallet.createTransaction(address, paymentId, amountxmr, mixinCount, priority); + if (amountxmr <= 0) { + informationPopup.title = qsTr("Error") + translationManager.emptyString; + informationPopup.text = qsTr("Amount is wrong: expected number from %1 to %2") + .arg(walletManager.displayAmount(0)) + .arg(walletManager.maximumAllowedAmountAsSting()) + + translationManager.emptyString + + informationPopup.icon = StandardIcon.Critical + informationPopup.onCloseCallback = null + informationPopup.open() + return; + } + + // validate address; + transaction = currentWallet.createTransaction(address, paymentId, amountxmr, mixinCount, priority); if (transaction.status !== PendingTransaction.Status_Ok) { console.error("Can't create transaction: ", transaction.errorString); informationPopup.title = qsTr("Error") + translationManager.emptyString; @@ -252,7 +267,7 @@ ApplicationWindow { informationPopup.onCloseCallback = null informationPopup.open(); // deleting transaction object, we don't want memleaks - wallet.disposeTransaction(transaction); + currentWallet.disposeTransaction(transaction); } else { console.log("Transaction created, amount: " + walletManager.displayAmount(transaction.amount) @@ -287,8 +302,8 @@ ApplicationWindow { } informationPopup.onCloseCallback = null informationPopup.open() - wallet.refresh() - wallet.disposeTransaction(transaction) + currentWallet.refresh() + currentWallet.disposeTransaction(transaction) } // blocks UI if wallet can't be opened or no connection to the daemon diff --git a/pages/Transfer.qml b/pages/Transfer.qml index 70fde050..508b32af 100644 --- a/pages/Transfer.qml +++ b/pages/Transfer.qml @@ -32,6 +32,7 @@ import "../components" Rectangle { + id: root signal paymentClicked(string address, string paymentId, double amount, int mixinCount, int priority) @@ -88,6 +89,11 @@ Rectangle { id: amountLine placeholderText: qsTr("Amount...") + translationManager.emptyString width: parent.width - 37 - 17 + validator: DoubleValidator { + bottom: 0.0 + notation: DoubleValidator.StandardNotation + locale: "C" + } } } @@ -170,7 +176,7 @@ Rectangle { textFormat: Text.RichText text: qsTr("\ Address ( Type in or select from Address book )") - + translationManager.emptyString + + translationManager.emptyString onLinkActivated: appWindow.showPageRequest("AddressBook") } @@ -220,7 +226,7 @@ Rectangle { anchors.topMargin: 17 fontSize: 14 text: qsTr("Description ( An optional description that will be saved to the local address book if entered )") - + translationManager.emptyString + + translationManager.emptyString } LineEdit { @@ -245,16 +251,15 @@ Rectangle { shadowPressedColor: "#B32D00" releasedColor: "#FF6C3C" pressedColor: "#FF4304" + enabled : addressLine.text.length > 0 && amountLine.text.length > 0 onClicked: { - // do more smart validation - - if (addressLine.text.length > 0 && amountLine.text.length > 0) { - console.log("paymentClicked") - var priority = priorityModel.get(priorityDropdown.currentIndex).priority - console.log("priority: " + priority) - paymentClicked(addressLine.text, paymentIdLine.text, amountLine.text, scaleValueToMixinCount(privacyLevelItem.fillLevel), - priority) - } + console.log("Transfer: paymentClicked") + var priority = priorityModel.get(priorityDropdown.currentIndex).priority + console.log("priority: " + priority) + console.log("amount: " + amountLine.text) + root.paymentClicked(addressLine.text, paymentIdLine.text, amountLine.text, scaleValueToMixinCount(privacyLevelItem.fillLevel), + priority) } } } + diff --git a/src/libwalletqt/WalletManager.cpp b/src/libwalletqt/WalletManager.cpp index 947ccbfb..a9f332a3 100644 --- a/src/libwalletqt/WalletManager.cpp +++ b/src/libwalletqt/WalletManager.cpp @@ -122,17 +122,27 @@ QString WalletManager::walletLanguage(const QString &locale) return "English"; } -QString WalletManager::displayAmount(quint64 amount) +quint64 WalletManager::maximumAllowedAmount() const +{ + return Bitmonero::Wallet::maximumAllowedAmount(); +} + +QString WalletManager::maximumAllowedAmountAsSting() const +{ + return WalletManager::displayAmount(WalletManager::maximumAllowedAmount()); +} + +QString WalletManager::displayAmount(quint64 amount) const { return QString::fromStdString(Bitmonero::Wallet::displayAmount(amount)); } -quint64 WalletManager::amountFromString(const QString &amount) +quint64 WalletManager::amountFromString(const QString &amount) const { return Bitmonero::Wallet::amountFromString(amount.toStdString()); } -quint64 WalletManager::amountFromDouble(double amount) +quint64 WalletManager::amountFromDouble(double amount) const { return Bitmonero::Wallet::amountFromDouble(amount); } diff --git a/src/libwalletqt/WalletManager.h b/src/libwalletqt/WalletManager.h index 1866b7cd..3629242a 100644 --- a/src/libwalletqt/WalletManager.h +++ b/src/libwalletqt/WalletManager.h @@ -12,6 +12,7 @@ namespace Bitmonero { class WalletManager : public QObject { Q_OBJECT + public: enum LogLevel { LogLevel_Silent = Bitmonero::WalletManagerFactory::LogLevel_Silent, @@ -79,9 +80,13 @@ public: //! since we can't call static method from QML, move it to this class - Q_INVOKABLE QString displayAmount(quint64 amount); - Q_INVOKABLE quint64 amountFromString(const QString &amount); - Q_INVOKABLE quint64 amountFromDouble(double amount); + Q_INVOKABLE QString displayAmount(quint64 amount) const; + Q_INVOKABLE quint64 amountFromString(const QString &amount) const; + Q_INVOKABLE quint64 amountFromDouble(double amount) const; + Q_INVOKABLE quint64 maximumAllowedAmount() const; + + // QML JS engine doesn't support unsigned integers + Q_INVOKABLE QString maximumAllowedAmountAsSting() const; void setLogLevel(int logLevel); -- cgit v1.2.3