Skip to content

Commit

Permalink
Load from UI Settings if local zcash.conf is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
adityapk00 committed Oct 19, 2018
1 parent d7f6d2a commit 35f7950
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ int main(int argc, char *argv[])
qApp->setFont(QFont("Ubuntu", 11, QFont::Normal, false));
#endif

QCoreApplication::setOrganizationName("zcash-qt-wallet-org");
QCoreApplication::setApplicationName("zcash-qt-wallet");

Settings::init();
Expand Down
13 changes: 6 additions & 7 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ void MainWindow::setupSettingsModal() {
settings.rpcpassword->setEnabled(false);
}
else {
settings.confMsg->setText("No local zcash.conf found. Please configure manually.");
settings.hostname->setEnabled(true);
settings.port->setEnabled(true);
settings.rpcuser->setEnabled(true);
Expand All @@ -147,13 +148,11 @@ void MainWindow::setupSettingsModal() {
if (settingsDialog.exec() == QDialog::Accepted) {
if (zcashConfLocation.isEmpty()) {
// Save settings
QSettings s;
s.setValue("connection/host", settings.hostname->text());
s.setValue("connection/port", settings.port->text());
s.setValue("connection/rpcuser", settings.rpcuser->text());
s.setValue("connection/rpcpassword", settings.rpcpassword->text());

s.sync();
Settings::getInstance()->saveSettings(
settings.hostname->text(),
settings.port->text(),
settings.rpcuser->text(),
settings.rpcpassword->text());

// Then refresh everything.
this->rpc->reloadConnectionInfo();
Expand Down
21 changes: 17 additions & 4 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ Settings::~Settings() {
}

Settings* Settings::init() {
if (instance != nullptr) return instance;

instance = new Settings();
if (instance == nullptr)
instance = new Settings();

// There are 3 possible configurations
// 1. The defaults
Expand Down Expand Up @@ -74,13 +73,27 @@ bool Settings::loadFromSettings() {
return !username.isEmpty();
}

void Settings::saveSettings(const QString& host, const QString& port, const QString& username, const QString& password) {
QSettings s;

s.setValue("connection/host", host);
s.setValue("connection/port", port);
s.setValue("connection/rpcuser", username);
s.setValue("connection/rpcpassword", password);

s.sync();

// re-init to load correct settings
init();
}

bool Settings::loadFromFile() {
delete zcashconf;

#ifdef Q_OS_LINUX
confLocation = QStandardPaths::locate(QStandardPaths::HomeLocation, ".zcash/zcash.conf");
#else
confLocation = QStandardPaths::locate(QStandardPaths::AppDataLocation, "../Zcash/zcash.conf");
confLocation = QStandardPaths::locate(QStandardPaths::AppDataLocation, "../../Zcash/zcash.conf");
#endif

confLocation = QDir::cleanPath(confLocation);
Expand Down
2 changes: 2 additions & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Settings
bool loadFromSettings();
bool loadFromFile();

void saveSettings(const QString& host, const QString& port, const QString& username, const QString& password);

bool isTestnet();
void setTestnet(bool isTestnet);

Expand Down

0 comments on commit 35f7950

Please sign in to comment.