GUI-FreeRDP/gui.c

184 lines
6.7 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* 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"
#include "address.h"
#include "db.h"
#include "xrdp.h"
//#include "../xfreerdp.h"
static int guiExit(Ihandle *self)
{
return IUP_CLOSE;
}
static int guiConnect(Ihandle *self)
{
char *result = getHostIP(IupGetAttribute(IupGetDialogChild(self, "SERVER"), "VALUE"));
if (!result)
return IUP_DEFAULT;
setParameterValue(PARAMETER_SERVER, VALUE_SERVER, result);
setParameterValue(PARAMETER_USERNAME, VALUE_USERNAME, IupGetAttribute(IupGetDialogChild(self, "USER"), "LINEVALUE"));
setParameterValue(PARAMETER_PASSWORD, VALUE_PASSWORD, IupGetAttribute(IupGetDialogChild(self, "PASSWORD"), "LINEVALUE"));
Arguments args;
buildArguments(&args);
for (int i = 0; i < args.argc; ++i)
{
printf("%s\n", args.argv[i]);
}
// if (free_rdp_connect(args.argc, args.argv) != XF_EXIT_DNS_NAME_NOT_FOUND)
// {
if (!dbAddServer(result, IupGetAttribute(IupGetDialogChild(self, "SERVER"), "VALUE")))
{
IupSetAttribute(IupGetDialogChild(self, "SERVER"), "APPENDITEM", IupGetAttribute(IupGetDialogChild(self, "SERVER"), "VALUE"));
}
dbSetUserNameCurrent(IupGetAttribute(IupGetDialogChild(self, "USER"), "LINEVALUE"));
// }
freeArguments(&args);
return IUP_DEFAULT;
}
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];
size_t size = strlen(host->data[0]) + 1;
indexItem = (char *)malloc(sizeof(char) * size);
strncpy(indexItem, host->data[0], size);
size = strlen(host->data[1]) + 1;
serverName = (char *)malloc(sizeof(char) * size);
strncpy(serverName, host->data[1], size);
IupSetAttribute(iupList, indexItem, serverName);
if (atoi(host->data[2]))
IupSetAttribute(iupList, "VALUE", serverName);
}
dbFreeHosts(hosts);
}
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");
inputServer = IupList(NULL);
IupSetAttribute(inputServer, "NAME", "SERVER");
IupSetAttribute(inputServer, "TIP", "IP-адрес или имя удаленного сервера (обязательно)");
createHostsList(inputServer);
IupSetAttribute(inputServer, "SIZE", "100");
IupSetAttribute(inputServer, "EDITBOX", "YES");
IupSetAttribute(inputServer, "DROPDOWN", "YES");
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");
IupSetAttribute(inputUser, "TIP", "<домен>\\<имя пользователя> (обязательно)");
IupSetAttribute(inputUser, "VALUE", getSetValueCurrent(PARAMETER_USERNAME));
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");
IupSetAttribute(inputPassword, "TIP", "Пароль пользователя (необязательно)");
IupSetAttribute(inputPassword, "VALUE", getSetValueCurrent(PARAMETER_PASSWORD));
IupSetAttribute(inputPassword, "PASSWORD", "YES");
hBoxPassword = IupHbox(labelPassword, inputPassword, NULL);
IupSetAttribute(hBoxPassword, "MARGIN", "10x10");
btnConnect = IupButton("Подключение", NULL);
IupSetHandle("CONNECT", btnConnect);
IupSetAttribute(btnConnect, "NAME", "CONNECT");
IupSetAttribute(btnConnect, "TIP", "Выполнить подключение");
IupSetAttribute(btnConnect, "BGCOLOR", "0 179 0");
IupSetAttribute(btnConnect, "FGCOLOR", "255 255 255");
btnClose = IupButton("Закрыть", NULL);
IupSetHandle("CLOSE", btnClose);
IupSetAttribute(btnClose, "NAME", "CLOSE");
IupSetAttribute(btnClose, "TIP", "Закрыть FreeRDP");
IupSetAttribute(btnClose, "BGCOLOR", "204 0 0");
IupSetAttribute(btnClose, "FGCOLOR", "255 255 255");
btnSettings = IupButton("Настройки", NULL);
IupSetAttribute(btnSettings, "NAME", "SETTINGS");
IupSetAttribute(btnSettings, "TIP", "Перейти в настройки");
IupSetAttribute(btnSettings, "BGCOLOR", "0 136 204");
IupSetAttribute(btnSettings, "FGCOLOR", "255 255 255");
hBoxButtons = IupHbox(IupFill(), btnSettings, btnConnect, btnClose, IupFill(), NULL);
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);
IupSetCallback(btnSettings, "ACTION", (Icallback) settingsMainWindow);
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;
}