feat: add --reset option to gpclient

This commit is contained in:
Kevin Yue 2022-06-14 21:14:16 +08:00
parent 5788474d7e
commit fe64b2cd19
3 changed files with 8 additions and 15 deletions

View File

@ -40,14 +40,6 @@ GPClient::GPClient(QWidget *parent, IVpn *vpn)
initVpnStatus(); initVpnStatus();
} }
GPClient::~GPClient()
{
delete ui;
delete vpn;
delete settingsDialog;
delete settingsButton;
}
void GPClient::setupSettings() void GPClient::setupSettings()
{ {
settingsButton = new QPushButton(this); settingsButton = new QPushButton(this);
@ -112,7 +104,7 @@ void GPClient::initSystemTrayIcon()
connectAction = contextMenu->addAction(QIcon::fromTheme("preferences-system-network"), "Connect", this, &GPClient::doConnect); connectAction = contextMenu->addAction(QIcon::fromTheme("preferences-system-network"), "Connect", this, &GPClient::doConnect);
contextMenu->addMenu(gatewaySwitchMenu); contextMenu->addMenu(gatewaySwitchMenu);
contextMenu->addSeparator(); contextMenu->addSeparator();
clearAction = contextMenu->addAction(QIcon::fromTheme("edit-clear"), "Reset", this, &GPClient::clearSettings); clearAction = contextMenu->addAction(QIcon::fromTheme("edit-clear"), "Reset", this, &GPClient::reset);
quitAction = contextMenu->addAction(QIcon::fromTheme("application-exit"), "Quit", this, &GPClient::quit); quitAction = contextMenu->addAction(QIcon::fromTheme("application-exit"), "Quit", this, &GPClient::quit);
systemTrayIcon->show(); systemTrayIcon->show();
@ -478,7 +470,7 @@ void GPClient::setCurrentGateway(const GPGateway gateway)
populateGatewayMenu(); populateGatewayMenu();
} }
void GPClient::clearSettings() void GPClient::reset()
{ {
settings::clear(); settings::clear();
populateGatewayMenu(); populateGatewayMenu();

View File

@ -21,7 +21,6 @@ class GPClient : public QMainWindow
public: public:
GPClient(QWidget *parent, IVpn *vpn); GPClient(QWidget *parent, IVpn *vpn);
~GPClient();
void activate(); void activate();
void quit(); void quit();
@ -33,6 +32,7 @@ public:
void setCurrentGateway(const GPGateway gateway); void setCurrentGateway(const GPGateway gateway);
void doConnect(); void doConnect();
void reset();
private slots: private slots:
void onSettingsButtonClicked(); void onSettingsButtonClicked();
@ -81,8 +81,6 @@ private:
SettingsDialog *settingsDialog; SettingsDialog *settingsDialog;
QPushButton *settingsButton; QPushButton *settingsButton;
GatewayAuthenticator *gatewayAuthenticator;
bool isQuickConnect { false }; bool isQuickConnect { false };
bool isSwitchingGateway { false }; bool isSwitchingGateway { false };
PortalConfigResponse portalConfig; PortalConfigResponse portalConfig;
@ -102,7 +100,5 @@ private:
QList<GPGateway> allGateways() const; QList<GPGateway> allGateways() const;
void setAllGateways(QList<GPGateway> gateways); void setAllGateways(QList<GPGateway> gateways);
void clearSettings();
}; };
#endif // GPCLIENT_H #endif // GPCLIENT_H

View File

@ -46,6 +46,7 @@ int main(int argc, char *argv[])
{"json", "Write the result of the handshake with the GlobalConnect server to stdout as JSON and terminate. Useful for scripting."}, {"json", "Write the result of the handshake with the GlobalConnect server to stdout as JSON and terminate. Useful for scripting."},
{"now", "Do not show the dialog with the connect button; connect immediately instead."}, {"now", "Do not show the dialog with the connect button; connect immediately instead."},
{"start-minimized", "Launch the client minimized."}, {"start-minimized", "Launch the client minimized."},
{"reset", "Reset the client's settings."},
}); });
parser.process(app); parser.process(app);
@ -55,7 +56,11 @@ int main(int argc, char *argv[])
? static_cast<IVpn*>(new VpnJson(nullptr)) // Print to stdout and exit ? static_cast<IVpn*>(new VpnJson(nullptr)) // Print to stdout and exit
: static_cast<IVpn*>(new VpnDbus(nullptr)); // Contact GPService daemon via dbus : static_cast<IVpn*>(new VpnDbus(nullptr)); // Contact GPService daemon via dbus
GPClient w(nullptr, vpn); GPClient w(nullptr, vpn);
parser.isSet("start-minimized") ? w.showMinimized() : w.show(); parser.isSet("start-minimized") ? w.showMinimized() : w.show();
if (parser.isSet("reset")) {
w.reset();
}
if (positional.size() > 0) { if (positional.size() > 0) {
w.portal(positional.at(0)); w.portal(positional.at(0));