Browse Source

Add backup wallet option

recurring
adityapk00 6 years ago
parent
commit
0bce364f0b
  1. 3
      src/connection.cpp
  2. 1
      src/connection.h
  3. 23
      src/mainwindow.cpp
  4. 2
      src/mainwindow.h
  5. 14
      src/mainwindow.ui
  6. 6
      src/settings.h

3
src/connection.cpp

@ -478,6 +478,7 @@ std::shared_ptr<ConnectionConfig> ConnectionLoader::autoDetectZcashConf() {
zcashconf->host = "127.0.0.1";
zcashconf->connType = ConnectionType::DetectedConfExternalZcashD;
zcashconf->usingZcashConf = true;
zcashconf->zcashDir = QFileInfo(confLocation).absoluteDir().absolutePath();
Settings::getInstance()->setUsingZcashConf(confLocation);
@ -526,7 +527,7 @@ std::shared_ptr<ConnectionConfig> ConnectionLoader::loadFromSettings() {
if (username.isEmpty() || password.isEmpty())
return nullptr;
auto uiConfig = new ConnectionConfig{ host, port, username, password, false, ConnectionType::UISettingsZCashD };
auto uiConfig = new ConnectionConfig{ host, port, username, password, false, "", ConnectionType::UISettingsZCashD};
return std::shared_ptr<ConnectionConfig>(uiConfig);
}

1
src/connection.h

@ -21,6 +21,7 @@ struct ConnectionConfig {
QString rpcuser;
QString rpcpassword;
bool usingZcashConf;
QString zcashDir;
ConnectionType connType;
};

23
src/mainwindow.cpp

@ -48,6 +48,9 @@ MainWindow::MainWindow(QWidget *parent) :
// Export All Private Keys
QObject::connect(ui->actionExport_All_Private_Keys, &QAction::triggered, this, &MainWindow::exportAllKeys);
// Backup wallet.dat
QObject::connect(ui->actionBackup_wallet_dat, &QAction::triggered, this, &MainWindow::backupWalletDat);
// z-Board.net
QObject::connect(ui->actionz_board_net, &QAction::triggered, this, &MainWindow::postToZBoard);
@ -633,6 +636,26 @@ void MainWindow::importPrivKey() {
}
}
void MainWindow::backupWalletDat() {
QFile wallet(QDir(rpc->getConnection()->config->zcashDir).filePath("wallet.dat"));
if (!wallet.exists()) {
QMessageBox::critical(this, "No wallet.dat", "Couldn't find the wallet.dat on this computer."
"You need to backup it up from the machine zcashd is running on", QMessageBox::Ok);
return;
}
QUrl backupName = QFileDialog::getSaveFileUrl(this, "Backup wallet.dat",
"zcash-wallet-backup-" + QDateTime::currentDateTime().toString("yyyyMMdd") + ".dat",
"Data file (*.dat)");
if (backupName.isEmpty())
return;
if (!wallet.copy(backupName.toLocalFile())) {
QMessageBox::critical(this, "Couldn't backup", "Couldn't backup the wallet.dat file."
"You need to backup it up manually.", QMessageBox::Ok);
}
}
void MainWindow::exportAllKeys() {
QDialog d(this);
Ui_PrivKey pui;

2
src/mainwindow.h

@ -89,6 +89,8 @@ private:
void postToZBoard();
void importPrivKey();
void exportAllKeys();
void backupWalletDat();
void doImport(QList<QString>* keys);
void restoreSavedStates();

14
src/mainwindow.ui

@ -316,8 +316,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>920</width>
<height>334</height>
<width>928</width>
<height>380</height>
</rect>
</property>
<layout class="QVBoxLayout" name="sendToLayout">
@ -849,7 +849,7 @@
<x>0</x>
<y>0</y>
<width>968</width>
<height>22</height>
<height>19</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@ -858,6 +858,7 @@
</property>
<addaction name="actionImport_Private_Key"/>
<addaction name="actionExport_All_Private_Keys"/>
<addaction name="actionBackup_wallet_dat"/>
<addaction name="separator"/>
<addaction name="actionExit"/>
</widget>
@ -932,7 +933,7 @@
</action>
<action name="actionExport_All_Private_Keys">
<property name="text">
<string>Export all private keys</string>
<string>&amp;Export all private keys</string>
</property>
</action>
<action name="actionz_board_net">
@ -951,6 +952,11 @@
<string>Ctrl+B</string>
</property>
</action>
<action name="actionBackup_wallet_dat">
<property name="text">
<string>&amp;Backup wallet.dat</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>

6
src/settings.h

@ -16,8 +16,8 @@ struct Tx;
class Settings
{
public:
static Settings* init();
static Settings* getInstance();
static Settings* init();
static Settings* getInstance();
Config getSettings();
void saveSettings(const QString& host, const QString& port, const QString& username, const QString& password);
@ -78,7 +78,7 @@ public:
static const int updateSpeed = 20 * 1000; // 20 sec
static const int quickUpdateSpeed = 5 * 1000; // 5 sec
static const int priceRefreshSpeed = 60 * 60 * 1000; // 1 hr
static const int priceRefreshSpeed = 60 * 60 * 1000; // 1 hr
private:
// This class can only be accessed through Settings::getInstance()

Loading…
Cancel
Save