2022-07-06 17:51:51 +00:00
|
|
|
|
/*
|
|
|
|
|
* gui.c
|
|
|
|
|
*
|
|
|
|
|
* Created on: 6 июл. 2022 г.
|
|
|
|
|
* Author: alexander
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
#include "gui.h"
|
|
|
|
|
#include "settings.h"
|
|
|
|
|
#include "node_settings.h"
|
|
|
|
|
#include "images.h"
|
|
|
|
|
#include "arguments.h"
|
2022-07-15 14:16:58 +00:00
|
|
|
|
#include "address.h"
|
2022-07-06 17:51:51 +00:00
|
|
|
|
|
2022-07-14 10:40:51 +00:00
|
|
|
|
#include "db.h"
|
|
|
|
|
|
2022-07-06 17:51:51 +00:00
|
|
|
|
static int guiExit(Ihandle *self)
|
|
|
|
|
{
|
|
|
|
|
return IUP_CLOSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int guiConnect(Ihandle *self)
|
|
|
|
|
{
|
2022-07-15 14:16:58 +00:00
|
|
|
|
char *result = getHostIP(IupGetAttribute(IupGetDialogChild(self, "SERVER"), "VALUE"));
|
|
|
|
|
|
|
|
|
|
if (!result)
|
|
|
|
|
return IUP_DEFAULT;
|
|
|
|
|
|
|
|
|
|
setParameterValue(PARAMETER_SERVER, VALUE_SERVER, result);
|
2022-07-08 16:45:45 +00:00
|
|
|
|
setParameterValue(PARAMETER_USERNAME, VALUE_USERNAME, IupGetAttribute(IupGetDialogChild(self, "USER"), "LINEVALUE"));
|
|
|
|
|
setParameterValue(PARAMETER_PASSWORD, VALUE_PASSWORD, IupGetAttribute(IupGetDialogChild(self, "PASSWORD"), "LINEVALUE"));
|
2022-07-06 17:51:51 +00:00
|
|
|
|
|
2022-07-08 16:45:45 +00:00
|
|
|
|
Arguments args;
|
|
|
|
|
buildArguments(&args);
|
|
|
|
|
for (int i = 0; i < args.argc; ++i)
|
2022-07-06 17:51:51 +00:00
|
|
|
|
{
|
2022-07-08 16:45:45 +00:00
|
|
|
|
printf("%s\n", args.argv[i]);
|
2022-07-06 17:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
printf("\n");
|
2022-07-08 16:45:45 +00:00
|
|
|
|
freeArguments(&args);
|
2022-07-06 17:51:51 +00:00
|
|
|
|
|
2022-07-15 14:16:58 +00:00
|
|
|
|
if (!dbAddServer(result, IupGetAttribute(IupGetDialogChild(self, "SERVER"), "VALUE")))
|
|
|
|
|
{
|
|
|
|
|
IupSetAttribute(IupGetDialogChild(self, "SERVER"), "APPENDITEM", IupGetAttribute(IupGetDialogChild(self, "SERVER"), "VALUE"));
|
|
|
|
|
}
|
|
|
|
|
// if (free_rdp_connect(args.argc, args.argv) != XF_EXIT_DNS_NAME_NOT_FOUND)
|
|
|
|
|
// {
|
|
|
|
|
// dbSetValueCurrent(VALUE_SERVER, IupGetAttribute(IupGetDialogChild(self, "SERVER"), "LINEVALUE"));
|
|
|
|
|
dbSetUserNameCurrent(IupGetAttribute(IupGetDialogChild(self, "USER"), "LINEVALUE"));
|
|
|
|
|
// }
|
|
|
|
|
|
2022-07-06 17:51:51 +00:00
|
|
|
|
return IUP_DEFAULT;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-15 14:16:58 +00:00
|
|
|
|
static void createHostsList(Ihandle *iupList)
|
|
|
|
|
{
|
|
|
|
|
Hosts *hosts = dbGetHostsList();
|
|
|
|
|
char *indexItem = NULL;
|
|
|
|
|
char *serverName = NULL;
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < hosts->size; ++i)
|
|
|
|
|
{
|
|
|
|
|
Host *host = hosts->host[i];
|
|
|
|
|
indexItem = (char *)malloc(sizeof(char) * strlen(host->data[0]));
|
|
|
|
|
strcpy(indexItem, host->data[0]);
|
|
|
|
|
serverName = (char *)malloc(sizeof(char) * strlen(host->data[1]));
|
|
|
|
|
strcpy(serverName, host->data[1]);
|
|
|
|
|
|
|
|
|
|
IupSetAttribute(iupList, indexItem, serverName);
|
|
|
|
|
if (atoi(host->data[2]))
|
|
|
|
|
IupSetAttribute(iupList, "VALUE", serverName);
|
|
|
|
|
}
|
|
|
|
|
dbFreeHosts(hosts);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 17:51:51 +00:00
|
|
|
|
Ihandle* guiStart()
|
|
|
|
|
{
|
|
|
|
|
Ihandle *dlg;
|
|
|
|
|
Ihandle *icon, *bgHead;
|
|
|
|
|
Ihandle *vBoxMain, *hBoxServer, *hBoxUser, *hBoxPassword, *hBoxButtons; // Boxes
|
|
|
|
|
Ihandle *labelImage;
|
|
|
|
|
Ihandle *labelServer, *inputServer;
|
|
|
|
|
Ihandle *labelUser, *inputUser;
|
|
|
|
|
Ihandle *labelPassword, *inputPassword;
|
|
|
|
|
Ihandle *btnConnect, *btnClose, *btnSettings;
|
|
|
|
|
|
|
|
|
|
icon = IupImageRGBA(64, 64, idata_icon);
|
|
|
|
|
IupSetHandle("icon", icon);
|
|
|
|
|
|
|
|
|
|
labelImage = IupLabel(NULL);
|
|
|
|
|
|
|
|
|
|
bgHead = IupImageRGBA(405, 72, idata_head);
|
|
|
|
|
IupSetAttributeHandle(labelImage, "IMAGE", bgHead);
|
|
|
|
|
|
|
|
|
|
labelServer = IupLabel("Компьютер:");
|
|
|
|
|
IupSetAttribute(labelServer, "SIZE", "80x16");
|
|
|
|
|
IupSetAttribute(labelServer, "ALIGNMENT", "ARIGHT:ACENTER");
|
|
|
|
|
IupSetAttribute(labelServer, "PADDING", "5");
|
2022-07-15 14:16:58 +00:00
|
|
|
|
|
|
|
|
|
inputServer = IupList(NULL);
|
2022-07-06 17:51:51 +00:00
|
|
|
|
IupSetAttribute(inputServer, "NAME", "SERVER");
|
2022-07-14 10:40:51 +00:00
|
|
|
|
IupSetAttribute(inputServer, "TIP", "IP-адрес или имя удаленного сервера (обязательно)");
|
2022-07-15 14:16:58 +00:00
|
|
|
|
createHostsList(inputServer);
|
2022-07-06 17:51:51 +00:00
|
|
|
|
IupSetAttribute(inputServer, "SIZE", "100");
|
2022-07-15 14:16:58 +00:00
|
|
|
|
IupSetAttribute(inputServer, "EDITBOX", "YES");
|
|
|
|
|
IupSetAttribute(inputServer, "DROPDOWN", "YES");
|
2022-07-06 17:51:51 +00:00
|
|
|
|
hBoxServer = IupHbox(labelServer, inputServer, NULL);
|
|
|
|
|
IupSetAttribute(hBoxServer, "MARGIN", "10x10");
|
|
|
|
|
|
|
|
|
|
labelUser = IupLabel("Пользователь:");
|
|
|
|
|
IupSetAttribute(labelUser, "SIZE", "80x16");
|
|
|
|
|
IupSetAttribute(labelUser, "ALIGNMENT", "ARIGHT:ACENTER");
|
|
|
|
|
IupSetAttribute(labelUser, "PADDING", "5");
|
|
|
|
|
inputUser = IupText(NULL);
|
|
|
|
|
IupSetAttribute(inputUser, "NAME", "USER");
|
2022-07-14 10:40:51 +00:00
|
|
|
|
IupSetAttribute(inputUser, "TIP", "<домен>\\<имя пользователя> (обязательно)");
|
|
|
|
|
IupSetAttribute(inputUser, "VALUE", getSetValueCurrent(PARAMETER_USERNAME));
|
2022-07-06 17:51:51 +00:00
|
|
|
|
IupSetAttribute(inputUser, "SIZE", "100");
|
|
|
|
|
hBoxUser = IupHbox(labelUser, inputUser, NULL);
|
|
|
|
|
IupSetAttribute(hBoxUser, "MARGIN", "10x0");
|
|
|
|
|
|
|
|
|
|
labelPassword = IupLabel("Пароль:");
|
|
|
|
|
IupSetAttribute(labelPassword, "SIZE", "80x16");
|
|
|
|
|
IupSetAttribute(labelPassword, "ALIGNMENT", "ARIGHT:ACENTER");
|
|
|
|
|
IupSetAttribute(labelPassword, "PADDING", "5");
|
|
|
|
|
inputPassword = IupText(NULL);
|
|
|
|
|
IupSetAttribute(inputPassword, "SIZE", "100");
|
|
|
|
|
IupSetAttribute(inputPassword, "NAME", "PASSWORD");
|
2022-07-14 10:40:51 +00:00
|
|
|
|
IupSetAttribute(inputPassword, "TIP", "Пароль пользователя (необязательно)");
|
|
|
|
|
IupSetAttribute(inputPassword, "VALUE", getSetValueCurrent(PARAMETER_PASSWORD));
|
2022-07-06 17:51:51 +00:00
|
|
|
|
IupSetAttribute(inputPassword, "PASSWORD", "YES");
|
|
|
|
|
hBoxPassword = IupHbox(labelPassword, inputPassword, NULL);
|
|
|
|
|
IupSetAttribute(hBoxPassword, "MARGIN", "10x10");
|
|
|
|
|
|
|
|
|
|
btnConnect = IupButton("Подключение", NULL);
|
|
|
|
|
IupSetHandle("CONNECT", btnConnect);
|
|
|
|
|
IupSetAttribute(btnConnect, "NAME", "CONNECT");
|
2022-07-14 10:40:51 +00:00
|
|
|
|
IupSetAttribute(btnConnect, "TIP", "Выполнить подключение");
|
|
|
|
|
IupSetAttribute(btnConnect, "BGCOLOR", "0 179 0");
|
|
|
|
|
IupSetAttribute(btnConnect, "FGCOLOR", "255 255 255");
|
|
|
|
|
|
2022-07-06 17:51:51 +00:00
|
|
|
|
btnClose = IupButton("Закрыть", NULL);
|
|
|
|
|
IupSetHandle("CLOSE", btnClose);
|
|
|
|
|
IupSetAttribute(btnClose, "NAME", "CLOSE");
|
2022-07-14 10:40:51 +00:00
|
|
|
|
IupSetAttribute(btnClose, "TIP", "Закрыть FreeRDP");
|
|
|
|
|
IupSetAttribute(btnClose, "BGCOLOR", "204 0 0");
|
|
|
|
|
IupSetAttribute(btnClose, "FGCOLOR", "255 255 255");
|
|
|
|
|
|
2022-07-06 17:51:51 +00:00
|
|
|
|
btnSettings = IupButton("Настройки", NULL);
|
|
|
|
|
IupSetAttribute(btnSettings, "NAME", "SETTINGS");
|
2022-07-14 10:40:51 +00:00
|
|
|
|
IupSetAttribute(btnSettings, "TIP", "Перейти в настройки");
|
|
|
|
|
IupSetAttribute(btnSettings, "BGCOLOR", "0 136 204");
|
|
|
|
|
IupSetAttribute(btnSettings, "FGCOLOR", "255 255 255");
|
2022-07-13 17:49:49 +00:00
|
|
|
|
|
2022-07-14 10:40:51 +00:00
|
|
|
|
hBoxButtons = IupHbox(IupFill(), btnSettings, btnConnect, btnClose, IupFill(), NULL);
|
2022-07-06 17:51:51 +00:00
|
|
|
|
IupSetAttribute(hBoxButtons, "ALIGNMENT", "ACENTER:ACENTER");
|
|
|
|
|
IupSetAttribute(hBoxButtons, "GAP", "10");
|
|
|
|
|
IupSetAttribute(hBoxButtons, "MARGIN", "10x10");
|
|
|
|
|
|
|
|
|
|
vBoxMain = IupVbox(labelImage, hBoxServer, hBoxUser, hBoxPassword, hBoxButtons, NULL);
|
|
|
|
|
|
|
|
|
|
IupSetCallback(btnConnect, "ACTION", (Icallback) guiConnect);
|
|
|
|
|
IupSetCallback(btnClose, "ACTION", (Icallback) guiExit);
|
2022-07-07 16:35:48 +00:00
|
|
|
|
IupSetCallback(btnSettings, "ACTION", (Icallback) settingsMainWindow);
|
2022-07-06 17:51:51 +00:00
|
|
|
|
|
|
|
|
|
dlg = IupDialog(vBoxMain);
|
|
|
|
|
IupSetAttribute(dlg, "IMAGE", "BG_HEAD");
|
|
|
|
|
IupSetAttribute(dlg, "ICON", "icon");
|
|
|
|
|
IupSetAttribute(dlg, "TITLE", "GUI FreeRDP");
|
|
|
|
|
IupSetAttribute(dlg, "RESIZE", "NO");
|
|
|
|
|
IupSetAttribute(dlg, "PARENTDIALOG", "MAIN_WINDOW");
|
|
|
|
|
IupSetAttribute(dlg, "DEFAULTENTER", "CONNECT");
|
|
|
|
|
IupSetAttribute(dlg, "DEFAULTESC", "CLOSE");
|
|
|
|
|
|
|
|
|
|
return dlg;
|
|
|
|
|
}
|