From 4efbda3f257bd8e635715377d85862d322c57c4b Mon Sep 17 00:00:00 2001 From: sje397 Date: Tue, 14 Feb 2012 23:14:43 +1100 Subject: [PATCH] Added 'Backup Wallet' menu option - icon from the LGPL Nuvola set (like the tick) - http://www.icon-king.com/projects/nuvola/ - include 'boost/version.hpp' in db.cpp so that the overwrite version of copy can be used - catch exceptions in BackupWallet (e.g. filesystem_error thrown when trying to overwrite without the overwrite flag set) - include db.h in walletmodel.cpp for BackupWallet function - updated doc/assets-attribution.txt and contrib/debian/copyright with copyright info for new icon --- contrib/debian/copyright | 2 +- doc/assets-attribution.txt | 2 +- src/db.cpp | 16 +++++++++++----- src/qt/bitcoin.qrc | 1 + src/qt/bitcoingui.cpp | 17 +++++++++++++++++ src/qt/bitcoingui.h | 3 +++ src/qt/res/icons/filesave.png | Bin 0 -> 1741 bytes src/qt/walletmodel.cpp | 6 ++++++ src/qt/walletmodel.h | 2 ++ 9 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 src/qt/res/icons/filesave.png diff --git a/contrib/debian/copyright b/contrib/debian/copyright index 5db418df..71fa77cf 100644 --- a/contrib/debian/copyright +++ b/contrib/debian/copyright @@ -37,7 +37,7 @@ Files: src/qt/res/icons/address-book.png, src/qt/res/icons/export.png, src/qt/res/icons/history.png, src/qt/res/icons/key.png, src/qt/res/icons/lock_*.png, src/qt/res/icons/overview.png, src/qt/res/icons/receive.png, src/qt/res/icons/send.png, - src/qt/res/icons/synced.png + src/qt/res/icons/synced.png, src/qt/res/icons/filesave.png Copyright: David Vignoni (david@icon-king.com) ICON KING - www.icon-king.com License: LGPL diff --git a/doc/assets-attribution.txt b/doc/assets-attribution.txt index 5cf0a734..fabcdeea 100644 --- a/doc/assets-attribution.txt +++ b/doc/assets-attribution.txt @@ -7,7 +7,7 @@ Icon: src/qt/res/icons/address-book.png, src/qt/res/icons/export.png, src/qt/res/icons/history.png, src/qt/res/icons/key.png, src/qt/res/icons/lock_*.png, src/qt/res/icons/overview.png, src/qt/res/icons/receive.png, src/qt/res/icons/send.png, - src/qt/res/icons/synced.png + src/qt/res/icons/synced.png, src/qt/res/icons/filesave.png Icon Pack: NUVOLA ICON THEME for KDE 3.x Designer: David Vignoni (david@icon-king.com) ICON KING - www.icon-king.com diff --git a/src/db.cpp b/src/db.cpp index 3bdda615..9a904ec2 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -6,6 +6,7 @@ #include "headers.h" #include "db.h" #include "net.h" +#include #include #include @@ -1064,14 +1065,19 @@ bool BackupWallet(const CWallet& wallet, const string& strDest) filesystem::path pathDest(strDest); if (filesystem::is_directory(pathDest)) pathDest = pathDest / wallet.strWalletFile; + + try { #if BOOST_VERSION >= 104000 - filesystem::copy_file(pathSrc, pathDest, filesystem::copy_option::overwrite_if_exists); + filesystem::copy_file(pathSrc, pathDest, filesystem::copy_option::overwrite_if_exists); #else - filesystem::copy_file(pathSrc, pathDest); + filesystem::copy_file(pathSrc, pathDest); #endif - printf("copied wallet.dat to %s\n", pathDest.string().c_str()); - - return true; + printf("copied wallet.dat to %s\n", pathDest.string().c_str()); + return true; + } catch(const filesystem::filesystem_error &e) { + printf("error copying wallet.dat to %s - %s\n", pathDest.string().c_str(), e.what()); + return false; + } } } Sleep(100); diff --git a/src/qt/bitcoin.qrc b/src/qt/bitcoin.qrc index 5693ae18..d823752c 100644 --- a/src/qt/bitcoin.qrc +++ b/src/qt/bitcoin.qrc @@ -37,6 +37,7 @@ res/icons/lock_closed.png res/icons/lock_open.png res/icons/key.png + res/icons/filesave.png res/images/about.png diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index b72f1282..f3b1d0e4 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -46,6 +46,8 @@ #include #include #include +#include +#include #include #include @@ -243,6 +245,8 @@ void BitcoinGUI::createActions() encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet"), this); encryptWalletAction->setToolTip(tr("Encrypt or decrypt wallet")); encryptWalletAction->setCheckable(true); + backupWalletAction = new QAction(QIcon(":/icons/filesave"), tr("&Backup Wallet"), this); + backupWalletAction->setToolTip(tr("Backup wallet to another location")); changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase"), this); changePassphraseAction->setToolTip(tr("Change the passphrase used for wallet encryption")); @@ -252,6 +256,7 @@ void BitcoinGUI::createActions() connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); connect(openBitcoinAction, SIGNAL(triggered()), this, SLOT(showNormal())); connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool))); + connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet())); connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase())); } @@ -277,6 +282,7 @@ void BitcoinGUI::createMenuBar() QMenu *settings = appMenuBar->addMenu(tr("&Settings")); settings->addAction(encryptWalletAction); settings->addAction(changePassphraseAction); + settings->addAction(backupWalletAction); settings->addSeparator(); settings->addAction(optionsAction); @@ -778,6 +784,17 @@ void BitcoinGUI::encryptWallet(bool status) setEncryptionStatus(walletModel->getEncryptionStatus()); } +void BitcoinGUI::backupWallet() +{ + QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation); + QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)")); + if(!filename.isEmpty()) { + if(!walletModel->backupWallet(filename)) { + QMessageBox::warning(this, tr("Backup Failed"), tr("There was an error trying to save the wallet data to the new location.")); + } + } +} + void BitcoinGUI::changePassphrase() { AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this); diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 37ab1257..a5224290 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -86,6 +86,7 @@ private: QAction *openBitcoinAction; QAction *exportAction; QAction *encryptWalletAction; + QAction *backupWalletAction; QAction *changePassphraseAction; QAction *aboutQtAction; @@ -162,6 +163,8 @@ private slots: void incomingTransaction(const QModelIndex & parent, int start, int end); /** Encrypt the wallet */ void encryptWallet(bool status); + /** Backup the wallet */ + void backupWallet(); /** Change encrypted wallet passphrase */ void changePassphrase(); /** Ask for pass phrase to unlock wallet temporarily */ diff --git a/src/qt/res/icons/filesave.png b/src/qt/res/icons/filesave.png new file mode 100644 index 0000000000000000000000000000000000000000..ae13a151d5ad11239194edd1fd91199f8dd72f4e GIT binary patch literal 1741 zcmV;;1~U1HP)|f|?2FH71}*ARmH#2?}N;pMop}hB72t{zDuGi6Vp; z*sOoQ8Ke~T8Duq#8UFwMgOTL`0&qnJNdSN#2-Ga6|36rhED|7bcOl0=`Q_o}VI6Wd+pB9(8B07A<3e@GgD6;jMt%3Xi}!bpU$-~=T?Mn*J8FhW8CB>ESUY2b$ZgQf3(&}<4$ zsEpt!fTa-@EDit&AdED?0L=v~u)K!_fKoFo3o=0yBsdX5qXsPYAL2@o17HOtHsb&S z2qO)^asd-C!oGg_!SL(fFJSQf162$RpnBmytXKwSe300`e-I3k`wR3cSS={k1NqFr zqL`JHg#lD(#W#n3o}6;g1={6~ZsObx_Q;0g(xRsQ^E zX7~wAI7}?qLjWLvFdP61LQtGN`~=htOlhCL154E3h};3A|3cFWm=7%lL4^`1de~VJ zYW_j%4PH)22%`gl0K%FGK?No=Q0B$`-wfRE-ZRLE0v+)eQQ09^zlbWBfdLrW4EJ9! zF&w|j&cH9k%phsN$-oFqOMm|0PJ{pfgpmedK?-s`-*<+iXMo23f)+r~90996(E&gJv7qHLuutGY4CMU;`ux{F7KXPUe=__6 zN^r6=GjMRQVa*+^z@P(#o}eHD13w=VymEp?9k!wvAb^f;_k9AEaK9M7f5*h%zWoB{1U_CS25xR9c>4jCNU?#W^@rU8Z4=mvcDhGh_{J;=k=VoMh4NcI0 zp^23dixz+YV!;&!;2IAY1;2qI@bf3o$3G!e;O{>W{?DIGSRDXzARiAC11m5J{(WPF zG*qB1Dr_MD5J1@51OFhY1C(&S{rJW3<^wZ>x7jxaJ%vvUYLb5$-o9rB=XrGS8`xj~ zrvW}-9l#091>Zm=A|t$>z?KF80tnRsOpGj`77ftTz}7H?{_^<;!`pWZ4B83|3|^aL$)Sv_DA>hJ$QzZp2bKLZx6pmLv)U@r$4 z*bG1Zu`~SRkpLzaU=I2VZNjlKFh9Qj;^E~JkIVo6FWrf(2OxkL2fA+v5I_UoHv|Zv j0e1jE01dbU00ImEejxC)$7P#?00000NkvXXu0mjfTPNqK literal 0 HcmV?d00001 diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index f028f10f..8344a653 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -5,6 +5,7 @@ #include "transactiontablemodel.h" #include "headers.h" +#include "db.h" // for BackupWallet #include #include @@ -239,6 +240,11 @@ bool WalletModel::changePassphrase(const SecureString &oldPass, const SecureStri return retval; } +bool WalletModel::backupWallet(const QString &filename) +{ + return BackupWallet(*wallet, filename.toLocal8Bit().data()); +} + // WalletModel::UnlockContext implementation WalletModel::UnlockContext WalletModel::requestUnlock() { diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 89e8cdd2..4123240e 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -77,6 +77,8 @@ public: // Passphrase only needed when unlocking bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString()); bool changePassphrase(const SecureString &oldPass, const SecureString &newPass); + // Wallet backup + bool backupWallet(const QString &filename); // RAI object for unlocking wallet, returned by requestUnlock() class UnlockContext