GUI-FreeRDP/gui.c

186 lines
7.1 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"
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)
{
fprintf(stderr, "ERROR 1\n");
Hosts *hosts = dbGetHostsList();
fprintf(stderr, "ERROR 2\n");
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);
}
fprintf(stderr, "ERROR 3\n");
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-адрес или имя удаленного сервера (обязательно)");
fprintf(stderr, "guiStart 1\n");
createHostsList(inputServer);
fprintf(stderr, "guiStart 2\n");
IupSetAttribute(inputServer, "SIZE", "100");
IupSetAttribute(inputServer, "EDITBOX", "YES");
IupSetAttribute(inputServer, "DROPDOWN", "YES");
hBoxServer = IupHbox(labelServer, inputServer, NULL);
IupSetAttribute(hBoxServer, "MARGIN", "10x10");
fprintf(stderr, "guiStart 3\n");
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");
fprintf(stderr, "guiStart 4\n");
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");
fprintf(stderr, "guiStart 5\n");
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");
fprintf(stderr, "guiStart 6\n");
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");
fprintf(stderr, "guiStart 7\n");
btnSettings = IupButton("Настройки", NULL);
IupSetAttribute(btnSettings, "NAME", "SETTINGS");
IupSetAttribute(btnSettings, "TIP", "Перейти в настройки");
IupSetAttribute(btnSettings, "BGCOLOR", "0 136 204");
IupSetAttribute(btnSettings, "FGCOLOR", "255 255 255");
fprintf(stderr, "guiStart 8\n");
hBoxButtons = IupHbox(IupFill(), btnSettings, btnConnect, btnClose, IupFill(), NULL);
IupSetAttribute(hBoxButtons, "ALIGNMENT", "ACENTER:ACENTER");
IupSetAttribute(hBoxButtons, "GAP", "10");
IupSetAttribute(hBoxButtons, "MARGIN", "10x10");
fprintf(stderr, "guiStart 9\n");
vBoxMain = IupVbox(labelImage, hBoxServer, hBoxUser, hBoxPassword, hBoxButtons, NULL);
IupSetCallback(btnConnect, "ACTION", (Icallback) guiConnect);
IupSetCallback(btnClose, "ACTION", (Icallback) guiExit);
IupSetCallback(btnSettings, "ACTION", (Icallback) settingsMainWindow);
fprintf(stderr, "guiStart 10\n");
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");
fprintf(stderr, "guiStart 11\n");
return dlg;
}