Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qt: Add option to choose not to start the wallet minimized #1804

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/qt/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,6 @@ int StartGridcoinQt(int argc, char *argv[])

try
{
// Regenerate startup link, to fix links to old versions
if (GUIUtil::GetStartOnSystemStartup())
GUIUtil::SetStartOnSystemStartup(true);

BitcoinGUI window;
guiref = &window;

Expand Down Expand Up @@ -504,6 +500,9 @@ int StartGridcoinQt(int argc, char *argv[])

LogPrintf("GUI loaded.");

// Regenerate startup link, to fix links to old versions
GUIUtil::SetStartOnSystemStartup(optionsModel.getStartAtStartup(), optionsModel.getStartMin());

app.exec();

window.hide();
Expand Down
29 changes: 20 additions & 9 deletions src/qt/forms/optionsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>540</width>
<height>380</height>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -77,14 +77,25 @@
</layout>
</item>
<item>
<widget class="QCheckBox" name="gridcoinAtStartup">
<property name="toolTip">
<string>Automatically start Gridcoin after logging in to the system.</string>
</property>
<property name="text">
<string>&amp;Start Gridcoin on system login</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayoutGridcoinStartup">
<item>
<widget class="QCheckBox" name="gridcoinAtStartup">
<property name="toolTip">
<string>Automatically start Gridcoin after logging in to the system.</string>
</property>
<property name="text">
<string>&amp;Start Gridcoin on system login</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="gridcoinAtStartupMinimised">
<property name="text">
<string>Start minimized</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="detachDatabases">
Expand Down
38 changes: 25 additions & 13 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <QDoubleValidator>
#include <QFont>
#include <QLineEdit>
//#include <QUrl>
#include <QTextDocument> // For Qt::escape
#include <QUrlQuery>
#include <QAbstractItemView>
Expand Down Expand Up @@ -385,7 +384,7 @@ struct AutoStartupArguments
std::string arguments;
};

AutoStartupArguments GetAutoStartupArguments()
AutoStartupArguments GetAutoStartupArguments(bool fStartMin = true)
{
// This helper function checks for the presence of certain startup arguments
// to the current running instance that should be relevant for automatic restart
Expand All @@ -402,24 +401,28 @@ AutoStartupArguments GetAutoStartupArguments()
// shortcut, so use false in GetDataDir().
result.data_dir = GetDataDir(false);

result.arguments = "-min";
result.arguments = {};

if (fTestNet)
{
result.link_name_suffix += "-testnet";
result.arguments += " -testnet";
result.arguments = "-testnet";
}
else
{
result.link_name_suffix += "-mainnet";
}

if (fStartMin)
{
result.arguments += " -min";
}

for (const auto& flag : { "-scraper", "-explorer", "-usenewnn" })
{
if (GetBoolArg(flag))
{
(result.arguments += " ") += flag;
result.link_name_suffix += flag;
}
}

Expand All @@ -446,7 +449,7 @@ bool GetStartOnSystemStartup()
return boost::filesystem::exists(StartupShortcutPath());
}

bool SetStartOnSystemStartup(bool fAutoStart)
bool SetStartOnSystemStartup(bool fAutoStart, bool fStartMin)
{
// Remove the legacy shortcut unconditionally.
boost::filesystem::remove(StartupShortcutLegacyPath());
Expand All @@ -455,7 +458,7 @@ bool SetStartOnSystemStartup(bool fAutoStart)
boost::filesystem::remove(StartupShortcutPath());

// Get auto startup arguments
AutoStartupArguments autostartup = GetAutoStartupArguments();
AutoStartupArguments autostartup = GetAutoStartupArguments(fStartMin);

if (fAutoStart)
{
Expand Down Expand Up @@ -491,7 +494,16 @@ bool SetStartOnSystemStartup(bool fAutoStart)
psl->SetPath(pszExePath);
PathRemoveFileSpecW(pszExePath);
psl->SetWorkingDirectory(pszExePath);
psl->SetShowCmd(SW_SHOWMINNOACTIVE);

if (fStartMin)
{
psl->SetShowCmd(SW_SHOWMINNOACTIVE);
}
else
{
psl->SetShowCmd(SW_SHOWNORMAL);
}

psl->SetArguments(pszArgs);

// Query IShellLink for the IPersistFile interface for
Expand Down Expand Up @@ -564,7 +576,7 @@ bool GetStartOnSystemStartup()
return true;
}

bool SetStartOnSystemStartup(bool fAutoStart)
bool SetStartOnSystemStartup(bool fAutoStart, bool fStartMin)
{
// Remove legacy autostart path if it exists.
if (boost::filesystem::exists(GetAutostartLegacyFilePath()))
Expand All @@ -581,7 +593,7 @@ bool SetStartOnSystemStartup(bool fAutoStart)
if (readlink("/proc/self/exe", pszExePath, sizeof(pszExePath)-1) == -1)
return false;

AutoStartupArguments autostartup = GetAutoStartupArguments();
AutoStartupArguments autostartup = GetAutoStartupArguments(fStartMin);

boost::filesystem::create_directories(GetAutostartDir());

Expand All @@ -592,11 +604,11 @@ bool SetStartOnSystemStartup(bool fAutoStart)
optionFile << "[Desktop Entry]\n";
optionFile << "Type=Application\n";
optionFile << "Name=Gridcoin" + autostartup.link_name_suffix + "\n";
optionFile << "Exec=" << pszExePath;
optionFile << "Exec=" << static_cast<boost::filesystem::path>(pszExePath);

if (!autostartup.data_dir.empty())
{
optionFile << " -datadir='" << autostartup.data_dir << "'";
optionFile << " -datadir=" << autostartup.data_dir;
}

optionFile << " " << autostartup.arguments << "\n";
Expand All @@ -612,7 +624,7 @@ bool SetStartOnSystemStartup(bool fAutoStart)
// https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPSystemStartup/Articles/CustomLogin.html

bool GetStartOnSystemStartup() { return false; }
bool SetStartOnSystemStartup(bool fAutoStart) { return false; }
bool SetStartOnSystemStartup(bool fAutoStart, bool fStartMin) { return false; }

#endif

Expand Down
2 changes: 1 addition & 1 deletion src/qt/guiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ namespace GUIUtil


bool GetStartOnSystemStartup();
bool SetStartOnSystemStartup(bool fAutoStart);
bool SetStartOnSystemStartup(bool fAutoStart, bool fStartMin);

/** Help message for Bitcoin-Qt, shown with --help. */
class HelpMessageBox : public QMessageBox
Expand Down
17 changes: 15 additions & 2 deletions src/qt/optionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,12 @@ OptionsDialog::OptionsDialog(QWidget *parent) :
/* setup/change UI elements when proxy IP is invalid/valid */
connect(this, SIGNAL(proxyIpValid(QValidatedLineEdit *, bool)), this, SLOT(handleProxyIpValid(QValidatedLineEdit *, bool)));

if (fTestNet)
ui->disableUpdateCheck->setHidden(true);
if (fTestNet) ui->disableUpdateCheck->setHidden(true);

ui->gridcoinAtStartupMinimised->setHidden(!ui->gridcoinAtStartup->isChecked());

connect(ui->gridcoinAtStartup, SIGNAL(toggled(bool)), this, SLOT(hideStartMinimized()));
connect(ui->gridcoinAtStartupMinimised, SIGNAL(toggled(bool)), this, SLOT(hideStartMinimized()));
}

OptionsDialog::~OptionsDialog()
Expand Down Expand Up @@ -129,6 +133,7 @@ void OptionsDialog::setMapper()
/* Main */
mapper->addMapping(ui->reserveBalance, OptionsModel::ReserveBalance);
mapper->addMapping(ui->gridcoinAtStartup, OptionsModel::StartAtStartup);
mapper->addMapping(ui->gridcoinAtStartupMinimised, OptionsModel::StartMin);
mapper->addMapping(ui->disableUpdateCheck, OptionsModel::DisableUpdateCheck);

/* Network */
Expand Down Expand Up @@ -239,6 +244,14 @@ void OptionsDialog::updateStyle()
}
}

void OptionsDialog::hideStartMinimized()
{
if (model)
{
ui->gridcoinAtStartupMinimised->setHidden(!ui->gridcoinAtStartup->isChecked());
}
}

void OptionsDialog::handleProxyIpValid(QValidatedLineEdit *object, bool fState)
{
// this is used in a check before re-enabling the save buttons
Expand Down
1 change: 1 addition & 0 deletions src/qt/optionsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ private slots:
void showRestartWarning_Lang();
void updateDisplayUnit();
void updateStyle();
void hideStartMinimized();
void handleProxyIpValid(QValidatedLineEdit *object, bool fState);

signals:
Expand Down
31 changes: 29 additions & 2 deletions src/qt/optionsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ void OptionsModel::Init()

// These are Qt-only settings:
nDisplayUnit = settings.value("nDisplayUnit", BitcoinUnits::BTC).toInt();
fStartAtStartup = settings.value("fStartAtStartup", false).toBool();
fStartMin = settings.value("fStartMin", true).toBool();
fMinimizeToTray = settings.value("fMinimizeToTray", false).toBool();
fDisableTrxNotifications = settings.value("fDisableTrxNotifications", false).toBool();
bDisplayAddresses = settings.value("bDisplayAddresses", false).toBool();
Expand Down Expand Up @@ -76,7 +78,9 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
switch(index.row())
{
case StartAtStartup:
return QVariant(GUIUtil::GetStartOnSystemStartup());
return QVariant(fStartAtStartup);
case StartMin:
return QVariant(fStartMin);
case MinimizeToTray:
return QVariant(fMinimizeToTray);
case DisableTrxNotifications:
Expand Down Expand Up @@ -133,7 +137,20 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
switch(index.row())
{
case StartAtStartup:
successful = GUIUtil::SetStartOnSystemStartup(value.toBool());
if (fStartAtStartup != value.toBool())
{
fStartAtStartup = value.toBool();
settings.setValue("fStartAtStartup", fStartAtStartup);
successful = GUIUtil::SetStartOnSystemStartup(fStartAtStartup, fStartMin);
}
break;
case StartMin:
if (fStartMin != value.toBool())
{
fStartMin = value.toBool();
settings.setValue("fStartMin", fStartMin);
successful = GUIUtil::SetStartOnSystemStartup(fStartAtStartup, fStartMin);
}
break;
case MinimizeToTray:
fMinimizeToTray = value.toBool();
Expand Down Expand Up @@ -243,6 +260,16 @@ bool OptionsModel::getCoinControlFeatures()
return fCoinControlFeatures;
}

bool OptionsModel::getStartAtStartup()
{
return fStartAtStartup;
}

bool OptionsModel::getStartMin()
{
return fStartMin;
}

bool OptionsModel::getMinimizeToTray()
{
return fMinimizeToTray;
Expand Down
5 changes: 5 additions & 0 deletions src/qt/optionsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class OptionsModel : public QAbstractListModel
enum OptionID {
StartAtStartup, // bool
MinimizeToTray, // bool
StartMin, // bool
DisableTrxNotifications, // bool
MapPortUPnP, // bool
MinimizeOnClose, // bool
Expand All @@ -45,6 +46,8 @@ class OptionsModel : public QAbstractListModel
/* Explicit getters */
qint64 getTransactionFee();
qint64 getReserveBalance();
bool getStartAtStartup();
bool getStartMin();
bool getMinimizeToTray();
bool getDisableTrxNotifications();
bool getMinimizeOnClose();
Expand All @@ -57,6 +60,8 @@ class OptionsModel : public QAbstractListModel
private:
int nDisplayUnit;
bool fMinimizeToTray;
bool fStartAtStartup;
bool fStartMin;
bool fDisableTrxNotifications;
bool bDisplayAddresses;
bool fMinimizeOnClose;
Expand Down