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