Рабочая версия мез мультипараметров

This commit is contained in:
Alexander Zhirov 2022-07-07 19:35:48 +03:00
parent bcbb10ea18
commit 3b6a0a433a
7 changed files with 209 additions and 76 deletions

View File

@ -7,6 +7,7 @@
#include <stdlib.h>
#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);
}

View File

@ -8,8 +8,6 @@
#ifndef ARGUMENTS_H_
#define ARGUMENTS_H_
#include "node_settings.h"
typedef struct
{
int argc;

29
gui.c
View File

@ -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");

View File

@ -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);

View File

@ -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_ */

View File

@ -6,83 +6,169 @@
*/
#include <iup.h>
#include <stdlib.h>
#include <stdbool.h>
#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);

View File

@ -8,6 +8,6 @@
#ifndef SETTINGS_H_
#define SETTINGS_H_
int settingsWindow(Ihandle *self);
int settingsMainWindow(Ihandle *self);
#endif /* SETTINGS_H_ */