commit 789d035d7ab590592a739f395a45cde726aefccc
parent e503d71b9ced390b7553cb4eae863330ed1ad38a
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sat, 18 Jun 2016 21:36:49 -0400
create network settings dialog
Diffstat:
7 files changed, 91 insertions(+), 12 deletions(-)
diff --git a/src/dialog.cpp b/src/dialog.cpp
@@ -283,6 +283,17 @@ HWND Dialog::getControl(const int idc)
return GetDlgItem(m_handle, idc);
}
+string Dialog::getText(HWND handle)
+{
+ auto_string buffer(4096, 0);
+ GetWindowText(handle, &buffer[0], (int)buffer.size());
+
+ // remove extra nulls from the string
+ buffer.resize(buffer.find(AUTO_STR('\0')));
+
+ return from_autostring(buffer);
+}
+
void Dialog::onInit()
{
}
diff --git a/src/dialog.hpp b/src/dialog.hpp
@@ -91,6 +91,8 @@ public:
void stopTimer(int id);
void setClipboard(const std::string &);
void setClipboard(const std::vector<std::string> &);
+ HWND getControl(int idc);
+ std::string getText(HWND);
void setCloseHandler(const CloseHandler &cb) { m_closeHandler = cb; }
@@ -104,8 +106,6 @@ protected:
Dialog(int templateId);
virtual ~Dialog();
- HWND getControl(int idc);
-
template<class T, class... Args>
T *createControl(int id, Args&&... args)
{
diff --git a/src/import.cpp b/src/import.cpp
@@ -79,11 +79,7 @@ void Import::fetch()
if(m_download)
return;
- auto_string url(4096, 0);
- GetWindowText(m_url, &url[0], (int)url.size());
-
- // remove extra nulls from the string
- url.resize(url.find(AUTO_STR('\0')));
+ const string &url = getText(m_url);
if(url.empty()) {
close();
@@ -93,7 +89,7 @@ void Import::fetch()
setWaiting(true);
const DownloadOpts &opts = *m_reapack->config()->download();
- Download *dl = m_download = new Download({}, from_autostring(url), opts);
+ Download *dl = m_download = new Download({}, url, opts);
dl->onFinish([=] {
const Download::State state = dl->state();
diff --git a/src/manager.cpp b/src/manager.cpp
@@ -17,12 +17,9 @@
#include "manager.hpp"
-#include "about.hpp"
#include "config.hpp"
#include "encoding.hpp"
-#include "errors.hpp"
#include "import.hpp"
-#include "index.hpp"
#include "menu.hpp"
#include "reapack.hpp"
#include "remote.hpp"
@@ -33,7 +30,8 @@ using namespace std;
enum { ACTION_ENABLE = 80, ACTION_DISABLE, ACTION_UNINSTALL, ACTION_ABOUT,
ACTION_REFRESH, ACTION_COPYURL, ACTION_SELECT, ACTION_UNSELECT,
- ACTION_AUTOINSTALL, ACTION_BLEEDINGEDGE, ACTION_RESETCONFIG };
+ ACTION_AUTOINSTALL, ACTION_BLEEDINGEDGE, ACTION_NETCONFIG,
+ ACTION_RESETCONFIG };
Manager::Manager(ReaPack *reapack)
: Dialog(IDD_CONFIG_DIALOG),
@@ -95,6 +93,9 @@ void Manager::onCommand(const int id, int)
case ACTION_BLEEDINGEDGE:
toggle(m_bleedingEdge, m_config->install()->bleedingEdge);
break;
+ case ACTION_NETCONFIG:
+ setupNetwork();
+ break;
case ACTION_RESETCONFIG:
m_config->resetOptions();
m_config->restoreDefaultRemotes();
@@ -384,6 +385,8 @@ void Manager::options()
if(m_bleedingEdge.value_or(m_config->install()->bleedingEdge))
menu.check(index);
+ menu.addAction(AUTO_STR("&Network settings..."), ACTION_NETCONFIG);
+
menu.addSeparator();
menu.addAction(AUTO_STR("&Restore default settings"), ACTION_RESETCONFIG);
@@ -391,6 +394,15 @@ void Manager::options()
menu.show(rect.left, rect.bottom - 1, handle());
}
+void Manager::setupNetwork()
+{
+ const auto ret = Dialog::Show<NetworkConfig>(instance(), handle(),
+ m_config->download());
+
+ if(ret == IDOK)
+ m_config->write();
+}
+
bool Manager::confirm() const
{
if(m_uninstall.empty())
@@ -474,3 +486,31 @@ Remote Manager::getRemote(const int index) const
return m_config->remotes()->get(remoteName);
}
+
+NetworkConfig::NetworkConfig(DownloadOpts *opts)
+ : Dialog(IDD_NETCONF_DIALOG), m_opts(opts)
+{
+}
+
+void NetworkConfig::onInit()
+{
+ m_proxy = getControl(IDC_PROXY);
+ SetWindowText(m_proxy, make_autostring(m_opts->proxy).c_str());
+}
+
+void NetworkConfig::onCommand(const int id, int)
+{
+ switch(id) {
+ case IDOK:
+ apply();
+ // then close
+ case IDCANCEL:
+ close(id);
+ break;
+ }
+}
+
+void NetworkConfig::apply()
+{
+ m_opts->proxy = getText(m_proxy);
+}
diff --git a/src/manager.hpp b/src/manager.hpp
@@ -29,6 +29,7 @@
class Config;
class ReaPack;
class Remote;
+struct DownloadOpts;
class Manager : public Dialog {
public:
@@ -56,6 +57,7 @@ private:
void copyUrl();
void launchBrowser();
void options();
+ void setupNetwork();
void setChange(int);
bool confirm() const;
@@ -76,4 +78,19 @@ private:
boost::optional<bool> m_bleedingEdge;
};
+class NetworkConfig : public Dialog {
+public:
+ NetworkConfig(DownloadOpts *);
+
+protected:
+ void onInit() override;
+ void onCommand(int, int) override;
+
+private:
+ void apply();
+
+ DownloadOpts *m_opts;
+ HWND m_proxy;
+};
+
#endif
diff --git a/src/resource.hpp b/src/resource.hpp
@@ -40,6 +40,7 @@
#define IDD_ABOUT_DIALOG 103
#define IDD_IMPORT_DIALOG 104
#define IDD_BROWSER_DIALOG 105
+#define IDD_NETCONF_DIALOG 106
#define IDC_LABEL 200
#define IDC_LABEL2 201
@@ -65,5 +66,6 @@
#define IDC_OPTIONS 228
#define IDC_ACTIONS 229
#define IDC_BROWSE 230
+#define IDC_PROXY 231
#endif
diff --git a/src/resource.rc b/src/resource.rc
@@ -99,3 +99,16 @@ BEGIN
PUSHBUTTON "&Cancel", IDCANCEL, 412, 231, 40, 14
PUSHBUTTON "&Apply", IDAPPLY, 455, 231, 40, 14
END
+
+IDD_NETCONF_DIALOG DIALOGEX 0, 0, 210, 54
+STYLE DIALOG_STYLE
+FONT DIALOG_FONT
+CAPTION "ReaPack: Network Settings"
+BEGIN
+ RTEXT "Proxy:", IDC_LABEL, 5, 8, 30, 10
+ EDITTEXT IDC_PROXY, 40, 5, 165, 14, ES_AUTOHSCROLL
+ LTEXT "Example: host:port, [ipv6]:port or scheme://host:port",
+ IDC_LABEL2, 40, 22, 220, 10
+ DEFPUSHBUTTON "&OK", IDOK, 122, 35, 40, 14
+ PUSHBUTTON "&Cancel", IDCANCEL, 165, 35, 40, 14
+END