From c6471e47f900dd9cbaa825c92f7cea341d39276d Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Thu, 2 Feb 2023 08:47:23 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F:=20=20=20=20=20-=20=D1=81=D0=B1=D1=80?= =?UTF-8?q?=D0=BE=D1=81=20=D0=BF=D0=BE=D0=BB=D1=8F=20=D0=BF=D0=B0=D1=80?= =?UTF-8?q?=D0=BE=D0=BB=D1=8F=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20=D1=83?= =?UTF-8?q?=D0=B4=D0=B0=D1=87=D0=BD=D0=BE=D0=B3=D0=BE=20=D1=81=D0=BE=D0=B5?= =?UTF-8?q?=D0=B4=D0=B8=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81=20RDP=20=20?= =?UTF-8?q?=20=20=20-=20=D0=BE=D0=B1=D1=8F=D0=B7=D0=B0=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D0=BE=D0=B5=20=D0=B7=D0=B0=D0=BF=D0=BE=D0=BB=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=BE=D0=BB=D0=B5=D0=B9=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BF=D1=8C=D1=8E=D1=82=D0=B5=D1=80=D0=B0=20?= =?UTF-8?q?=D0=B8=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82?= =?UTF-8?q?=D0=B5=D0=BB=D1=8F=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5:=20=20=20=20=20-=20=D1=84=D0=BB=D0=B0=D0=B3?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=B8=D0=BB=D1=8F=D1=86=D0=B8=D0=B8?= =?UTF-8?q?=20WITH=5FCOLOR=5FBUTTONS=20=D0=B4=D0=BB=D1=8F=20=D1=86=D0=B2?= =?UTF-8?q?=D0=B5=D1=82=D0=BD=D1=8B=D1=85=20=D0=BA=D0=BD=D0=BE=D0=BF=D0=BE?= =?UTF-8?q?=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + CMakeLists.txt | 7 ++++-- gui.c | 65 +++++++++++++++++++++++++++++++++++++++++++------- settings.c | 4 ++++ 4 files changed, 66 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index c4f75b5..cfd208f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /Debug /.settings +/.vscode .project .cproject diff --git a/CMakeLists.txt b/CMakeLists.txt index 73179f5..ee79ee1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,8 +33,7 @@ target_link_libraries(xfree glib-2.0 X11 Xrandr - m - + m dl pthread @@ -42,3 +41,7 @@ target_link_libraries(xfree /root/SQLite/sqlite3.a ) #target_link_libraries(xfree iup X11 Xrandr m sqlite3 -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lX11 -lXrandr -lm) + +if(WITH_COLOR_BUTTONS) + add_definitions(-DWITH_COLOR_BUTTONS) +endif() diff --git a/gui.c b/gui.c index a8612c0..5e87e7a 100644 --- a/gui.c +++ b/gui.c @@ -25,14 +25,48 @@ static int guiExit(Ihandle *self) return IUP_CLOSE; } +int isEmptyFieldServerUser(Ihandle *self) +{ + char *name = IupGetAttribute(self, "NAME"); + if (!strcmp(name, "SERVER")) + return !strcmp(IupGetAttribute(IupGetDialogChild(self, "USER"), "LINEVALUE"), "\0"); + else + return !strcmp(IupGetAttribute(IupGetDialogChild(self, "SERVER"), "VALUE"), "\0"); +} + +static int activeBtnConnect(Ihandle *self, int c, char *value) +{ + if (!strcmp(value, "\0") || isEmptyFieldServerUser(self)) + { + IupSetInt(IupGetDialogChild(self, "CONNECT"), "ACTIVE", 0); +#ifdef WITH_COLOR_BUTTONS + IupSetAttribute(IupGetDialogChild(self, "CONNECT"), "BGCOLOR", "49 54 61"); + IupSetAttribute(IupGetDialogChild(self, "CONNECT"), "FGCOLOR", "238 238 238"); +#endif + } + else + { + IupSetInt(IupGetDialogChild(self, "CONNECT"), "ACTIVE", 1); +#ifdef WITH_COLOR_BUTTONS + IupSetAttribute(IupGetDialogChild(self, "CONNECT"), "BGCOLOR", "0 179 0"); + IupSetAttribute(IupGetDialogChild(self, "CONNECT"), "FGCOLOR", "255 255 255"); +#endif + } + return IUP_DEFAULT; +} + static int guiConnect(Ihandle *self) { char *host = IupGetAttribute(IupGetDialogChild(self, "SERVER"), "VALUE"); - char *login = IupGetAttribute(IupGetDialogChild(self, "USER"), "LINEVALUE"); char *result = getHostIP(host); if (!result) - return IUP_DEFAULT; + return IUP_IGNORE; + + char *login = IupGetAttribute(IupGetDialogChild(self, "USER"), "LINEVALUE"); + + if (!strcmp(login, "\0")) + return IUP_IGNORE; setParameterValue(PARAMETER_SERVER, VALUE_SERVER, result); setParameterValue(PARAMETER_USERNAME, VALUE_USERNAME, login); @@ -45,16 +79,19 @@ static int guiConnect(Ihandle *self) printf("%s\n", args.argv[i]); } -// if (free_rdp_connect(args.argc, args.argv) != XF_EXIT_DNS_NAME_NOT_FOUND) -// { + enum XF_EXIT_CODE xCode = free_rdp_connect(args.argc, args.argv); + + if (!(xCode == XF_EXIT_DNS_NAME_NOT_FOUND || xCode == XF_EXIT_CONNECT_FAILED || xCode == XF_EXIT_TLS_CONNECT_FAILED)) + { + IupSetAttribute(IupGetDialogChild(self, "PASSWORD"), "VALUE", ""); + if (!dbAddServer(result, host)) { + dbInsertHistory(login, host); IupSetAttribute(IupGetDialogChild(self, "SERVER"), "APPENDITEM", host); } - - dbInsertHistory(login, host); dbSetUserNameCurrent(login); -// } + } freeArguments(&args); @@ -110,11 +147,13 @@ Ihandle* guiStart() inputServer = IupList(NULL); IupSetAttribute(inputServer, "NAME", "SERVER"); - IupSetAttribute(inputServer, "TIP", "IP-адрес или имя удаленного сервера (обязательно)"); + IupSetAttribute(inputServer, "TIP", "IP-адрес или имя удаленного сервера\n(обязательное для заполнения поле)"); createHostsList(inputServer); IupSetAttribute(inputServer, "SIZE", "100"); IupSetAttribute(inputServer, "EDITBOX", "YES"); IupSetAttribute(inputServer, "DROPDOWN", "YES"); + IupSetAttribute(inputServer, "MASK", "[A-Za-z0-9/./-]*"); + IupSetCallback(inputServer, "EDIT_CB", (Icallback) activeBtnConnect); hBoxServer = IupHbox(labelServer, inputServer, NULL); IupSetAttribute(hBoxServer, "MARGIN", "10x10"); @@ -124,9 +163,11 @@ Ihandle* guiStart() IupSetAttribute(labelUser, "PADDING", "5"); inputUser = IupText(NULL); IupSetAttribute(inputUser, "NAME", "USER"); - IupSetAttribute(inputUser, "TIP", "<домен>\\<имя пользователя> (обязательно)"); + IupSetAttribute(inputUser, "TIP", "<домен>\\<имя пользователя>\n<имя пользователя>@<домен>\n(обязательное для заполнения поле)") IupSetAttribute(inputUser, "VALUE", getSetValueCurrent(PARAMETER_USERNAME)); IupSetAttribute(inputUser, "SIZE", "100"); + IupSetAttribute(inputUser, "MASK", "(/w|[/./\\/@/-])*"); + IupSetCallback(inputUser, "ACTION", (Icallback) activeBtnConnect); hBoxUser = IupHbox(labelUser, inputUser, NULL); IupSetAttribute(hBoxUser, "MARGIN", "10x0"); @@ -147,21 +188,27 @@ Ihandle* guiStart() IupSetHandle("CONNECT", btnConnect); IupSetAttribute(btnConnect, "NAME", "CONNECT"); IupSetAttribute(btnConnect, "TIP", "Выполнить подключение"); +#ifdef WITH_COLOR_BUTTONS IupSetAttribute(btnConnect, "BGCOLOR", "0 179 0"); IupSetAttribute(btnConnect, "FGCOLOR", "255 255 255"); +#endif btnClose = IupButton("Закрыть", NULL); IupSetHandle("CLOSE", btnClose); IupSetAttribute(btnClose, "NAME", "CLOSE"); IupSetAttribute(btnClose, "TIP", "Закрыть FreeRDP"); +#ifdef WITH_COLOR_BUTTONS IupSetAttribute(btnClose, "BGCOLOR", "204 0 0"); IupSetAttribute(btnClose, "FGCOLOR", "255 255 255"); +#endif btnSettings = IupButton("Настройки", NULL); IupSetAttribute(btnSettings, "NAME", "SETTINGS"); IupSetAttribute(btnSettings, "TIP", "Перейти в настройки"); +#ifdef WITH_COLOR_BUTTONS IupSetAttribute(btnSettings, "BGCOLOR", "0 136 204"); IupSetAttribute(btnSettings, "FGCOLOR", "255 255 255"); +#endif hBoxButtons = IupHbox(IupFill(), btnSettings, btnConnect, btnClose, IupFill(), NULL); IupSetAttribute(hBoxButtons, "ALIGNMENT", "ACENTER:ACENTER"); diff --git a/settings.c b/settings.c index 2286f84..80200ec 100644 --- a/settings.c +++ b/settings.c @@ -368,14 +368,18 @@ static Ihandle* settingsHorizontalBoxButtons() btnSave = IupButton("Сохранить", NULL); IupSetAttribute(btnSave, "NAME", "SETTIGS_BTN_SAVE"); IupSetAttribute(btnSave, "TIP", "Сохранить настройки"); +#ifdef WITH_COLOR_BUTTONS IupSetAttribute(btnSave, "BGCOLOR", "0 179 0"); IupSetAttribute(btnSave, "FGCOLOR", "255 255 255"); +#endif btnClose = IupButton("Закрыть", NULL); IupSetAttribute(btnClose, "NAME", "SETTIGS_BTN_CLOSE"); IupSetAttribute(btnClose, "TIP", "Отменить изменения"); +#ifdef WITH_COLOR_BUTTONS IupSetAttribute(btnClose, "BGCOLOR", "204 0 0"); IupSetAttribute(btnClose, "FGCOLOR", "255 255 255"); +#endif IupSetHandle("btnClosePointer", btnClose);