Browse Source

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
0.8
sje397 13 years ago
parent
commit
4efbda3f25
  1. 2
      contrib/debian/copyright
  2. 2
      doc/assets-attribution.txt
  3. 16
      src/db.cpp
  4. 1
      src/qt/bitcoin.qrc
  5. 17
      src/qt/bitcoingui.cpp
  6. 3
      src/qt/bitcoingui.h
  7. BIN
      src/qt/res/icons/filesave.png
  8. 6
      src/qt/walletmodel.cpp
  9. 2
      src/qt/walletmodel.h

2
contrib/debian/copyright vendored

@ -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/history.png, src/qt/res/icons/key.png,
src/qt/res/icons/lock_*.png, src/qt/res/icons/overview.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/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) Copyright: David Vignoni (david@icon-king.com)
ICON KING - www.icon-king.com ICON KING - www.icon-king.com
License: LGPL License: LGPL

2
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/history.png, src/qt/res/icons/key.png,
src/qt/res/icons/lock_*.png, src/qt/res/icons/overview.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/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 Icon Pack: NUVOLA ICON THEME for KDE 3.x
Designer: David Vignoni (david@icon-king.com) Designer: David Vignoni (david@icon-king.com)
ICON KING - www.icon-king.com ICON KING - www.icon-king.com

16
src/db.cpp

@ -6,6 +6,7 @@
#include "headers.h" #include "headers.h"
#include "db.h" #include "db.h"
#include "net.h" #include "net.h"
#include <boost/version.hpp>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
@ -1064,14 +1065,19 @@ bool BackupWallet(const CWallet& wallet, const string& strDest)
filesystem::path pathDest(strDest); filesystem::path pathDest(strDest);
if (filesystem::is_directory(pathDest)) if (filesystem::is_directory(pathDest))
pathDest = pathDest / wallet.strWalletFile; pathDest = pathDest / wallet.strWalletFile;
try {
#if BOOST_VERSION >= 104000 #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 #else
filesystem::copy_file(pathSrc, pathDest); filesystem::copy_file(pathSrc, pathDest);
#endif #endif
printf("copied wallet.dat to %s\n", pathDest.string().c_str()); printf("copied wallet.dat to %s\n", pathDest.string().c_str());
return true;
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); Sleep(100);

1
src/qt/bitcoin.qrc

@ -37,6 +37,7 @@
<file alias="lock_closed">res/icons/lock_closed.png</file> <file alias="lock_closed">res/icons/lock_closed.png</file>
<file alias="lock_open">res/icons/lock_open.png</file> <file alias="lock_open">res/icons/lock_open.png</file>
<file alias="key">res/icons/key.png</file> <file alias="key">res/icons/key.png</file>
<file alias="filesave">res/icons/filesave.png</file>
</qresource> </qresource>
<qresource prefix="/images"> <qresource prefix="/images">
<file alias="about">res/images/about.png</file> <file alias="about">res/images/about.png</file>

17
src/qt/bitcoingui.cpp

@ -46,6 +46,8 @@
#include <QStackedWidget> #include <QStackedWidget>
#include <QDateTime> #include <QDateTime>
#include <QMovie> #include <QMovie>
#include <QFileDialog>
#include <QDesktopServices>
#include <QDragEnterEvent> #include <QDragEnterEvent>
#include <QUrl> #include <QUrl>
@ -243,6 +245,8 @@ void BitcoinGUI::createActions()
encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet"), this); encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet"), this);
encryptWalletAction->setToolTip(tr("Encrypt or decrypt wallet")); encryptWalletAction->setToolTip(tr("Encrypt or decrypt wallet"));
encryptWalletAction->setCheckable(true); 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 = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase"), this);
changePassphraseAction->setToolTip(tr("Change the passphrase used for wallet encryption")); 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(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
connect(openBitcoinAction, SIGNAL(triggered()), this, SLOT(showNormal())); connect(openBitcoinAction, SIGNAL(triggered()), this, SLOT(showNormal()));
connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool))); connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool)));
connect(backupWalletAction, SIGNAL(triggered()), this, SLOT(backupWallet()));
connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase())); connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase()));
} }
@ -277,6 +282,7 @@ void BitcoinGUI::createMenuBar()
QMenu *settings = appMenuBar->addMenu(tr("&Settings")); QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
settings->addAction(encryptWalletAction); settings->addAction(encryptWalletAction);
settings->addAction(changePassphraseAction); settings->addAction(changePassphraseAction);
settings->addAction(backupWalletAction);
settings->addSeparator(); settings->addSeparator();
settings->addAction(optionsAction); settings->addAction(optionsAction);
@ -778,6 +784,17 @@ void BitcoinGUI::encryptWallet(bool status)
setEncryptionStatus(walletModel->getEncryptionStatus()); 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() void BitcoinGUI::changePassphrase()
{ {
AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this); AskPassphraseDialog dlg(AskPassphraseDialog::ChangePass, this);

3
src/qt/bitcoingui.h

@ -86,6 +86,7 @@ private:
QAction *openBitcoinAction; QAction *openBitcoinAction;
QAction *exportAction; QAction *exportAction;
QAction *encryptWalletAction; QAction *encryptWalletAction;
QAction *backupWalletAction;
QAction *changePassphraseAction; QAction *changePassphraseAction;
QAction *aboutQtAction; QAction *aboutQtAction;
@ -162,6 +163,8 @@ private slots:
void incomingTransaction(const QModelIndex & parent, int start, int end); void incomingTransaction(const QModelIndex & parent, int start, int end);
/** Encrypt the wallet */ /** Encrypt the wallet */
void encryptWallet(bool status); void encryptWallet(bool status);
/** Backup the wallet */
void backupWallet();
/** Change encrypted wallet passphrase */ /** Change encrypted wallet passphrase */
void changePassphrase(); void changePassphrase();
/** Ask for pass phrase to unlock wallet temporarily */ /** Ask for pass phrase to unlock wallet temporarily */

BIN
src/qt/res/icons/filesave.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

6
src/qt/walletmodel.cpp

@ -5,6 +5,7 @@
#include "transactiontablemodel.h" #include "transactiontablemodel.h"
#include "headers.h" #include "headers.h"
#include "db.h" // for BackupWallet
#include <QTimer> #include <QTimer>
#include <QSet> #include <QSet>
@ -239,6 +240,11 @@ bool WalletModel::changePassphrase(const SecureString &oldPass, const SecureStri
return retval; return retval;
} }
bool WalletModel::backupWallet(const QString &filename)
{
return BackupWallet(*wallet, filename.toLocal8Bit().data());
}
// WalletModel::UnlockContext implementation // WalletModel::UnlockContext implementation
WalletModel::UnlockContext WalletModel::requestUnlock() WalletModel::UnlockContext WalletModel::requestUnlock()
{ {

2
src/qt/walletmodel.h

@ -77,6 +77,8 @@ public:
// Passphrase only needed when unlocking // Passphrase only needed when unlocking
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString()); bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString());
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass); bool changePassphrase(const SecureString &oldPass, const SecureString &newPass);
// Wallet backup
bool backupWallet(const QString &filename);
// RAI object for unlocking wallet, returned by requestUnlock() // RAI object for unlocking wallet, returned by requestUnlock()
class UnlockContext class UnlockContext

Loading…
Cancel
Save