From 3b6a0a433aedf881dda26cb5566524f46e7bda6e Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Thu, 7 Jul 2022 19:35:48 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=87=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20=D0=BC=D0=B5=D0=B7=20?= =?UTF-8?q?=D0=BC=D1=83=D0=BB=D1=8C=D1=82=D0=B8=D0=BF=D0=B0=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arguments.c | 13 +++- arguments.h | 2 - gui.c | 29 +------- node_settings.c | 53 +++++++++++++++ node_settings.h | 14 +++- settings.c | 172 ++++++++++++++++++++++++++++++++++++------------ settings.h | 2 +- 7 files changed, 209 insertions(+), 76 deletions(-) diff --git a/arguments.c b/arguments.c index d227e5b..ddff463 100644 --- a/arguments.c +++ b/arguments.c @@ -7,6 +7,7 @@ #include #include "arguments.h" +#include "node_settings.h" void settingsLoad() { @@ -16,6 +17,13 @@ void settingsLoad() settingsAddKey(PARAMETER_PASSWORD, "/p:", true, true); settingsAddKey(PARAMETER_MULTIMONITOR, "/multimon", false, true); settingsAddKey(PARAMETER_FULLSCREEN, "/f", false, true); + settingsAddKey(PARAMETER_AUTHENTICATION, "-authentication", false, true); + settingsAddKey(PARAMETER_SECURITY, "/sec:", false, true); + +// settingsAddKey(PARAMETER_SECURITY_TLS, "-authentication", false, true); +// settingsAddKey(PARAMETER_SECURITY_RDP, "-authentication", false, true); +// settingsAddKey(PARAMETER_SECURITY_NLA, "-authentication", false, true); +// settingsAddKey(PARAMETER_SECURITY_EXT, "-authentication", false, true); } Arguments *buildArguments() @@ -43,7 +51,8 @@ Arguments *buildArguments() return args; } -void freeArguments() +void freeArguments(Arguments *args) { - + free(args->argv); + free(args); } diff --git a/arguments.h b/arguments.h index 2f187af..7beefdb 100644 --- a/arguments.h +++ b/arguments.h @@ -8,8 +8,6 @@ #ifndef ARGUMENTS_H_ #define ARGUMENTS_H_ -#include "node_settings.h" - typedef struct { int argc; diff --git a/gui.c b/gui.c index 1738973..0cba38f 100644 --- a/gui.c +++ b/gui.c @@ -33,32 +33,7 @@ static int guiConnect(Ihandle *self) } printf("\n"); - -// char *program = "xfreerdp"; -// char *domain = "/d:agrohold"; -// char *certignore = "/cert-ignore"; -// -// char **argv = (char**) malloc(sizeof(char*) * 8); -// -// argv[0] = program; -// argv[1] = server; -// argv[2] = domain; -// argv[3] = user; -// argv[4] = password; -// argv[5] = certignore; -// -// Ihandle *child = IupGetDialogChild(self, "SETTINGS_WINDOW"); -// -// if (!strcmp(IupGetAttribute(IupGetDialogChild(child, "SETTINGS_FULLSCREEN"), "VALUE"), "ON")) -// { -// argv[6] = "/f\0"; -// } -// -// if (!strcmp(IupGetAttribute(IupGetDialogChild(child, "SETTINGS_MULTIMONITOR"), "VALUE"), "ON")) -// { -// argv[7] = "/multimon\0"; -// } -// + freeArguments(args); return IUP_DEFAULT; } @@ -135,7 +110,7 @@ Ihandle* guiStart() IupSetCallback(btnConnect, "ACTION", (Icallback) guiConnect); IupSetCallback(btnClose, "ACTION", (Icallback) guiExit); - IupSetCallback(btnSettings, "ACTION", (Icallback) settingsWindow); + IupSetCallback(btnSettings, "ACTION", (Icallback) settingsMainWindow); dlg = IupDialog(vBoxMain); IupSetAttribute(dlg, "IMAGE", "BG_HEAD"); diff --git a/node_settings.c b/node_settings.c index 7d9d9c8..8316604 100644 --- a/node_settings.c +++ b/node_settings.c @@ -65,6 +65,7 @@ void settingsAddKey(SettingsParameters parameter, char *key, bool isValue, bool Node *newNode = settingsCreateNode(); newNode->parameter = parameter; newNode->enable = enable; + newNode->change = false; SettingsData *data = newNode->data; data->isValue = isValue; @@ -160,6 +161,58 @@ void settingsToggleEnable(SettingsParameters parameter) currentNode->enable = !currentNode->enable; } +void settingsToggleChange(SettingsParameters parameter) +{ + Node *currentNode = settingsGetNode(parameter); + if (!currentNode) + { + return; + } + currentNode->change = !currentNode->change; +} + +void settingsResetChange() +{ + if (!settings.countAll) + { + return; + } + + for (Node *head = settings.next; head; head = head->next) + { + if (head->change) + { + head->change = false; + } + } +} + +void settingsSaveSettings() +{ + if (!settings.countAll) + { + return; + } + + for (Node *head = settings.next; head; head = head->next) + { + if (head->change) + { + head->change = false; + + if (head->enable) + { + --settings.countEnable; + } + else + { + ++settings.countEnable; + } + head->enable = !head->enable; + } + } +} + bool settingsGetEnable(SettingsParameters parameter) { Node *currentNode = settingsGetNode(parameter); diff --git a/node_settings.h b/node_settings.h index bbe4cdd..fcaa59e 100644 --- a/node_settings.h +++ b/node_settings.h @@ -12,7 +12,15 @@ typedef enum { - PARAMETER_NULL, PARAMETER_XFREERDP, PARAMETER_USERNAME, PARAMETER_SERVER, PARAMETER_PASSWORD, PARAMETER_MULTIMONITOR, PARAMETER_FULLSCREEN + PARAMETER_NULL, + PARAMETER_XFREERDP, + PARAMETER_USERNAME, + PARAMETER_SERVER, + PARAMETER_PASSWORD, + PARAMETER_MULTIMONITOR, + PARAMETER_FULLSCREEN, + PARAMETER_AUTHENTICATION, + PARAMETER_SECURITY } SettingsParameters; typedef struct @@ -26,6 +34,7 @@ typedef struct typedef struct Node { SettingsParameters parameter; + bool change; bool enable; SettingsData *data; struct Node *next; @@ -49,7 +58,10 @@ void settingsAddKey(SettingsParameters parameter, char *key, bool isValue, bool void settingsSetValue(SettingsParameters parameter, char *value); void settingsSetEnable(SettingsParameters parameter, bool enable); void settingsToggleEnable(SettingsParameters parameter); +void settingsToggleChange(SettingsParameters parameter); bool settingsGetEnable(SettingsParameters parameter); void settingsFree(); +void settingsSaveSettings(); +void settingsResetChange(); #endif /* SETTINGS_H_ */ diff --git a/settings.c b/settings.c index c2f5d9c..00cbdf5 100644 --- a/settings.c +++ b/settings.c @@ -6,83 +6,169 @@ */ #include + #include #include #include "settings.h" #include "arguments.h" +#include "node_settings.h" -static int settingsClose(Ihandle *bt_close) +static int settingsClose(Ihandle *self) { - IupSetAttribute(IupGetDialog(bt_close), "SIMULATEMODAL", "OFF"); - IupHide(IupGetDialog(bt_close)); + settingsResetChange(); + IupSetAttribute(IupGetDialog(self), "SIMULATEMODAL", "OFF"); + IupHide(IupGetDialog(self)); return IUP_DEFAULT; } static int settingsSave(Ihandle *self) { + settingsSaveSettings(); + IupSetAttribute(IupGetDialog(self), "SIMULATEMODAL", "OFF"); + IupHide(IupGetDialog(self)); return IUP_DEFAULT; } static int settingsTglMultimonitor(Ihandle *self) { - settingsToggleEnable(PARAMETER_MULTIMONITOR); + settingsToggleChange(PARAMETER_MULTIMONITOR); return IUP_DEFAULT; } static int settingsTglFullscreen(Ihandle *self) { - settingsToggleEnable(PARAMETER_FULLSCREEN); + settingsToggleChange(PARAMETER_FULLSCREEN); return IUP_DEFAULT; } -int settingsWindow(Ihandle *self) +static int settingsTglAuthentication(Ihandle *self) { - Ihandle *dlg; - Ihandle *vBoxMain, *hBoxToggles, *hSettingsBoxButtons; - Ihandle *btnSettingsClose, *btnSettingsSave; - Ihandle *tglMultimonitor, *tglFullscreen; + settingsToggleChange(PARAMETER_AUTHENTICATION); + return IUP_DEFAULT; +} + +/* + * Блок настроек + */ +static Ihandle* getFrmCheckbox() +{ + Ihandle *tglMultimonitor, *tglFullscreen, *tglAuthentication; tglMultimonitor = IupToggle("Мультиэкран", NULL); - IupSetAttribute(tglMultimonitor, "VALUE", (settingsGetEnable(PARAMETER_MULTIMONITOR) ? "ON" : "OFF")); - IupSetAttribute(tglMultimonitor, "NAME", "SETTINGS_MULTIMONITOR"); tglFullscreen = IupToggle("На весь экран", NULL); - IupSetAttribute(tglFullscreen, "NAME", "SETTINGS_FULLSCREEN"); - IupSetAttribute(tglFullscreen, "VALUE", (settingsGetEnable(PARAMETER_FULLSCREEN) ? "ON" : "OFF")); - hBoxToggles = IupHbox(IupFill(), tglFullscreen, tglMultimonitor, IupFill(), NULL); - IupSetAttribute(hBoxToggles, "GAP", "10"); - IupSetAttribute(hBoxToggles, "MARGIN", "10x10"); + tglAuthentication = IupToggle("Аутентификация", NULL); - btnSettingsSave = IupButton("Сохранить", NULL); - IupSetAttribute(btnSettingsSave, "NAME", "SETTIGS_SAVE"); - btnSettingsClose = IupButton("Закрыть", NULL); - IupSetHandle("SETTIGS_CLOSE", btnSettingsClose); - IupSetAttribute(btnSettingsClose, "NAME", "SETTIGS_CLOSE"); - hSettingsBoxButtons = IupHbox(IupFill(), btnSettingsClose, btnSettingsSave, IupFill(), NULL); - IupSetAttribute(hSettingsBoxButtons, "ALIGNMENT", "ACENTER:ACENTER"); - IupSetAttribute(hSettingsBoxButtons, "GAP", "10"); - IupSetAttribute(hSettingsBoxButtons, "MARGIN", "10x10"); + IupSetInt(tglMultimonitor, "VALUE", settingsGetEnable(PARAMETER_MULTIMONITOR)); + IupSetInt(tglFullscreen, "VALUE", settingsGetEnable(PARAMETER_FULLSCREEN)); + IupSetInt(tglAuthentication, "VALUE", settingsGetEnable(PARAMETER_AUTHENTICATION)); - vBoxMain = IupVbox(hBoxToggles, hSettingsBoxButtons, NULL); + return IupVbox( + IupSetCallbacks(IupSetAttributes(tglMultimonitor, "NAME=SETTINGS_TGL_MULTIMONITOR"), "ACTION", + (Icallback) settingsTglMultimonitor, NULL), + IupSetCallbacks(IupSetAttributes(tglFullscreen, "NAME=SETTINGS_TGL_FULLSCREEN"), "ACTION", + (Icallback) settingsTglFullscreen, NULL), + IupSetCallbacks(IupSetAttributes(tglAuthentication, "NAME=SETTINGS_TGL_AUTHENTICATION"), "ACTION", + (Icallback) settingsTglAuthentication, NULL), + NULL); +} + +//void tool_action_cb(Ihandle *self, int state) +//{ +// if (state == 1) +// { +// int tool_index = IupGetInt(self, "TOOLINDEX"); +// switch (tool_index) +// { +// case 0: +// { +// settingsSetValue(PARAMETER_SECURITY, "tls"); +// break; +// } +// case 1: +// { +// settingsSetValue(PARAMETER_SECURITY, "rdp"); +// break; +// } +// case 2: +// { +// settingsSetValue(PARAMETER_SECURITY, "nla"); +// break; +// } +// case 3: +// { +// settingsSetValue(PARAMETER_SECURITY, "ext"); +// break; +// } +// } +// } +//} +// +//static Ihandle* getFrmSecurity() +//{ +// Ihandle *frmSettings; +// Ihandle *grdSecurity; +// +// grdSecurity = IupGridBox( +// IupSetCallbacks(IupSetAttributes(IupToggle(NULL, NULL), "TITLE=TLS, TOOLINDEX=0, VALUE=ON"), "ACTION", (Icallback)tool_action_cb, NULL), +// IupSetCallbacks(IupSetAttributes(IupToggle(NULL, NULL), "TITLE=RDP, TOOLINDEX=1"), "ACTION", (Icallback)tool_action_cb, NULL), +// IupSetCallbacks(IupSetAttributes(IupToggle(NULL, NULL), "TITLE=NLA, TOOLINDEX=2"), "ACTION", (Icallback)tool_action_cb, NULL), +// IupSetCallbacks(IupSetAttributes(IupToggle(NULL, NULL), "TITLE=EXT, TOOLINDEX=3"), "ACTION", (Icallback)tool_action_cb, NULL), +// NULL); +// +//// tglTLS = IupToggle("TLS", NULL); +//// tglRDP = IupToggle("RDP", NULL); +//// tglNLA = IupToggle("NLA", NULL); +//// tglEXT = IupToggle("EXT", NULL); +// +// frmSettings = IupSetAttributes(IupFrame(IupSetAttributes(getFrmCheckbox(), "MARGIN=3x2, GAP=2, ALIGNMENT=ALEFT")), "TITLE=\"Настройки\""); +// +// return frmSettings; +//} + +static Ihandle* getHorBoxSettings() +{ + Ihandle *frmSettings; + + frmSettings = IupSetAttributes(IupFrame(IupSetAttributes(getFrmCheckbox(), "MARGIN=3x2, GAP=2, ALIGNMENT=ALEFT")), "TITLE=\"Настройки\""); + return IupHbox(frmSettings, NULL); +} + +/* + * Блок кнопок + */ +static Ihandle* getHorBoxButtons() +{ + Ihandle *btnSave, *btnClose; + + btnSave = IupButton("Сохранить", NULL); + IupSetAttribute(btnSave, "NAME", "SETTIGS_BTN_SAVE"); + IupSetAttribute(btnSave, "TIP", "Сохранить настройки"); + + btnClose = IupButton("Закрыть", NULL); + IupSetAttribute(btnClose, "NAME", "SETTIGS_BTN_CLOSE"); + + IupSetHandle("btnClosePointer", btnClose); + + return IupSetAttributes( + IupHbox(IupFill(), IupSetCallbacks(btnSave, "ACTION", (Icallback) settingsSave, NULL), + IupSetCallbacks(btnClose, "ACTION", (Icallback) settingsClose, NULL), IupFill(), + NULL), "ALIGNMENT=ACENTER:ACENTER, GAP=10, MARGIN=10x10"); +} + +int settingsMainWindow(Ihandle *self) +{ + Ihandle *dlg; + Ihandle *vBoxMain; + + vBoxMain = IupSetAttributes(IupVbox(getHorBoxSettings(), getHorBoxButtons(), NULL), "NMARGIN=2x2, ALIGNMENT=ACENTER"); dlg = IupDialog(vBoxMain); IupSetAttribute(dlg, "TITLE", "Настройки"); - IupSetAttribute(dlg, "ICON", "icon"); - IupSetAttribute(dlg, "DIALOGFRAME", "ON"); - IupSetAttribute(dlg, "SIMULATEMODAL", "ON"); - IupSetAttribute(dlg, "DEFAULTESC", "SETTIGS_CLOSE"); - IupSetAttribute(dlg, "TOPMOST", "YES"); - IupSetAttribute(dlg, "BRINGFRONT", "YES"); - IupSetAttribute(dlg, "NAME", "SETTINGS_WINDOW"); - - IupSetCallback(dlg, "CLOSE_CB", (Icallback) settingsClose); - -// IupSetAttribute(dlg, "RESIZE", "NO"); - - IupSetCallback(btnSettingsClose, "ACTION", (Icallback) settingsClose); - IupSetCallback(btnSettingsSave, "ACTION", (Icallback) settingsSave); - IupSetCallback(tglFullscreen, "ACTION", (Icallback) settingsTglFullscreen); - IupSetCallback(tglMultimonitor, "ACTION", (Icallback) settingsTglMultimonitor); + IupSetCallback( + IupSetAttributes(dlg, + "ICON=icon, DIALOGFRAME=ON, SIMULATEMODAL=ON, DEFAULTESC=btnClosePointer, TOPMOST=YES, BRINGFRONT=YES, NAME=SETTINGS_MAIN_WINDOW"), + "CLOSE_CB", (Icallback) settingsClose); IupShowXY(dlg, IUP_CURRENT, IUP_CURRENT); diff --git a/settings.h b/settings.h index ca1d9d8..6fd0485 100644 --- a/settings.h +++ b/settings.h @@ -8,6 +8,6 @@ #ifndef SETTINGS_H_ #define SETTINGS_H_ -int settingsWindow(Ihandle *self); +int settingsMainWindow(Ihandle *self); #endif /* SETTINGS_H_ */