Добавлено: статическая связка с sqlite, улучшено оформление

This commit is contained in:
Alexander Zhirov 2022-07-14 13:40:51 +03:00
parent 3fcfc8783f
commit a36ac928a0
10 changed files with 12941 additions and 16 deletions

46
db.c
View File

@ -6,9 +6,10 @@
*/
#include <stdbool.h>
#include <sqlite3.h>
#include "sqlite3.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "db.h"
#include "node_settings.h"
@ -57,7 +58,7 @@ static int dbLoad(void *NotUsed, int argc, char **argv, char **azColName)
parameters[8] ? getParameter(atoi(parameters[8])) : NULL);
}
if (parameters[4])
if (parameters[4] && parameters[5])
{
addParameterValue(atoi(parameters[0]), atoi(parameters[4]), parameters[5], atoi(parameters[6]));
}
@ -84,7 +85,7 @@ bool dbLoadData()
if (sqlite3_exec(db, sql, dbLoad, 0, &err_msg) != SQLITE_OK)
{
fprintf(stderr, "SQL error: %s\n", err_msg);
fprintf(stderr, "Ошибка выполнения запроса: %s\n", err_msg);
sqlite3_free(err_msg);
sqlite3_close(db);
return false;
@ -167,3 +168,42 @@ bool dbWriteValue(Value name, bool set)
return true;
}
bool dbSetValueCurrent(Value name, char *current)
{
sqlite3 *db = dbGetBase("freerdp.db");
if (!db)
{
return false;
}
char *text = strlen(current) ? current : NULL;
sqlite3_stmt *res;
char *sql = "UPDATE `values` set `data` = ?, `set` = ? where id = ?";
if (sqlite3_prepare_v2(db, sql, -1, &res, 0) == SQLITE_OK)
{
sqlite3_bind_text(res, 1, text, -1, 0);
sqlite3_bind_int(res, 2, text ? true : false);
sqlite3_bind_int(res, 3, name);
}
if (sqlite3_step(res) == SQLITE_BUSY)
{
fprintf(stderr, "[ЗАНЯТО] %s - \"%s\"\n", text ? "установлено" : "очищено", getParameter(name)->key);
}
if (sqlite3_step(res) == SQLITE_ERROR)
{
fprintf(stderr, "[ОШИБКА] %s - \"%s\"\n", text ? "установлено" : "очищено", getParameter(name)->key);
}
if (sqlite3_step(res) == SQLITE_DONE)
{
fprintf(stdout, "[УСПЕШНО] %s - \"%s\"\n", text ? "установлено" : "очищено", getParameter(name)->key);
}
sqlite3_finalize(res);
sqlite3_close(db);
return true;
}

1
db.h
View File

@ -14,5 +14,6 @@
bool dbLoadData();
bool dbWriteParameter(Parameter name, bool set);
bool dbWriteValue(Value name, bool set);
bool dbSetValueCurrent(Value name, char *current);
#endif /* DB_H_ */

Binary file not shown.

23
gui.c
View File

@ -15,6 +15,8 @@
#include "images.h"
#include "arguments.h"
#include "db.h"
static int guiExit(Ihandle *self)
{
return IUP_CLOSE;
@ -23,7 +25,9 @@ static int guiExit(Ihandle *self)
static int guiConnect(Ihandle *self)
{
setParameterValue(PARAMETER_SERVER, VALUE_SERVER, IupGetAttribute(IupGetDialogChild(self, "SERVER"), "LINEVALUE"));
dbSetValueCurrent(VALUE_SERVER, IupGetAttribute(IupGetDialogChild(self, "SERVER"), "LINEVALUE"));
setParameterValue(PARAMETER_USERNAME, VALUE_USERNAME, IupGetAttribute(IupGetDialogChild(self, "USER"), "LINEVALUE"));
dbSetValueCurrent(VALUE_USERNAME, IupGetAttribute(IupGetDialogChild(self, "USER"), "LINEVALUE"));
setParameterValue(PARAMETER_PASSWORD, VALUE_PASSWORD, IupGetAttribute(IupGetDialogChild(self, "PASSWORD"), "LINEVALUE"));
Arguments args;
@ -64,6 +68,8 @@ Ihandle* guiStart()
IupSetAttribute(labelServer, "PADDING", "5");
inputServer = IupText(NULL);
IupSetAttribute(inputServer, "NAME", "SERVER");
IupSetAttribute(inputServer, "TIP", "IP-адрес или имя удаленного сервера (обязательно)");
IupSetAttribute(inputServer, "VALUE", getSetValueCurrent(PARAMETER_SERVER));
// IupSetAttribute(inputServer, "BORDER", "NO");
IupSetAttribute(inputServer, "SIZE", "100");
// IupSetAttribute(inputServer, "PADDING", "10x");
@ -76,6 +82,8 @@ Ihandle* guiStart()
IupSetAttribute(labelUser, "PADDING", "5");
inputUser = IupText(NULL);
IupSetAttribute(inputUser, "NAME", "USER");
IupSetAttribute(inputUser, "TIP", "<домен>\\<имя пользователя> (обязательно)");
IupSetAttribute(inputUser, "VALUE", getSetValueCurrent(PARAMETER_USERNAME));
IupSetAttribute(inputUser, "SIZE", "100");
// IupSetAttribute(inputUser, "PADDING", "10x10");
hBoxUser = IupHbox(labelUser, inputUser, NULL);
@ -89,6 +97,8 @@ Ihandle* guiStart()
IupSetAttribute(inputPassword, "SIZE", "100");
// IupSetAttribute(inputPassword, "PADDING", "10x10");
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");
@ -96,13 +106,24 @@ Ihandle* guiStart()
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(), btnConnect, btnClose, btnSettings, IupFill(), NULL);
hBoxButtons = IupHbox(IupFill(), btnSettings, btnConnect, btnClose, IupFill(), NULL);
IupSetAttribute(hBoxButtons, "ALIGNMENT", "ACENTER:ACENTER");
IupSetAttribute(hBoxButtons, "GAP", "10");
IupSetAttribute(hBoxButtons, "MARGIN", "10x10");

View File

@ -272,6 +272,26 @@ NodeValue* getSetNodeValue(NodeParameter *node)
return NULL;
}
char *getSetValueCurrent(Parameter name)
{
NodeParameter *nodeParameter = getNodeParameter(name);
if (!nodeParameter)
{
return NULL;
}
for (NodeValue *head = nodeParameter->value; head; head = head->next)
{
if (head->set)
{
return head->current;
}
}
return NULL;
}
////////////////////////////////////////////////////////////////
void setParameterValue(Parameter pName, Value vName, char *current)

View File

@ -53,6 +53,7 @@ void addParameterValue(Parameter pName, Value vName, char *current, bool set);
void freeSettings();
NodeValue *getSetNodeValue(NodeParameter *node);
char *getSetValueCurrent(Parameter name);
bool getSetParameter(Parameter name);
bool getSetValue(Parameter pName, Value vName);
int getCountValue(Parameter name);

View File

@ -21,9 +21,9 @@ typedef enum
PARAMETER_FONTS,
PARAMETER_SOUND,
PARAMETER_COMPRESSION,
PARAMETER_FULLSCREEN,
PARAMETER_MONITORS,
PARAMETER_MULTIMONITOR,
PARAMETER_FULLSCREEN,
PARAMETER_AUTHENTICATION,
PARAMETER_SECURITY,
PARAMETER_BITSPERPIXEL,

View File

@ -227,20 +227,20 @@ static Ihandle* settingsBoxCheckbox()
return IupSetAttributes(
IupFrame(
IupVbox(
IupSetCallbacks(IupSetAttributes(tglAuthentication, "NAME=SETTINGS_TGL_AUTHENTICATION"), "ACTION",
IupSetCallbacks(IupSetAttributes(tglAuthentication, "NAME=SETTINGS_TGL_AUTHENTICATION, TIP=\"Получить окно входа авторизации\""), "ACTION",
(Icallback) settingsTglAuthentication, NULL),
IupSetCallbacks(IupSetAttributes(tglCertIgnore, "NAME=SETTINGS_TGL_AUTHENTICATION"), "ACTION",
IupSetCallbacks(IupSetAttributes(tglCertIgnore, "NAME=SETTINGS_TGL_AUTHENTICATION, TIP=\"Игнорировать подтверждение принятия сертификата\""), "ACTION",
(Icallback) settingsTglCertIgnore, NULL),
IupSetCallbacks(IupSetAttributes(tglThemes, "NAME=SETTINGS_TGL_THEMES"), "ACTION", (Icallback) settingsTglThemes,
IupSetCallbacks(IupSetAttributes(tglThemes, "NAME=SETTINGS_TGL_THEMES, TIP=\"Отключить поддержку тем оформления (улучшает скорость соединения)\""), "ACTION", (Icallback) settingsTglThemes,
NULL),
IupSetCallbacks(IupSetAttributes(tglWallpaper, "NAME=SETTINGS_TGL_WALLPAPER"), "ACTION", (Icallback) settingsTglWallpaper,
NULL), IupSetCallbacks(IupSetAttributes(tglSound, "NAME=SETTINGS_TGL_SOUND"), "ACTION", (Icallback) settingsTglSound,
NULL), IupSetCallbacks(IupSetAttributes(tglFonts, "NAME=SETTINGS_TGL_FONTS"), "ACTION", (Icallback) settingsTglFonts,
IupSetCallbacks(IupSetAttributes(tglWallpaper, "NAME=SETTINGS_TGL_WALLPAPER, TIP=\"Отключить поддержку обои рабочего стола (улучшает скорость соединения)\""), "ACTION", (Icallback) settingsTglWallpaper,
NULL), IupSetCallbacks(IupSetAttributes(tglSound, "NAME=SETTINGS_TGL_SOUND, TIP=\"Включить поддержку звука с удаленного сервера\""), "ACTION", (Icallback) settingsTglSound,
NULL), IupSetCallbacks(IupSetAttributes(tglFonts, "NAME=SETTINGS_TGL_FONTS, TIP=\"Отключить прорисовку шрифтов (улучшает скорость соединения)\""), "ACTION", (Icallback) settingsTglFonts,
NULL),
IupSetCallbacks(IupSetAttributes(tglEncryption, "NAME=SETTINGS_TGL_ENCRYPTION"), "ACTION",
IupSetCallbacks(IupSetAttributes(tglEncryption, "NAME=SETTINGS_TGL_ENCRYPTION, TIP=\"Отключить шифрование данных\""), "ACTION",
(Icallback) settingsTglEncryption,
NULL),
IupSetCallbacks(IupSetAttributes(tglCompression, "NAME=SETTINGS_TGL_COMPRESSION"), "ACTION",
IupSetCallbacks(IupSetAttributes(tglCompression, "NAME=SETTINGS_TGL_COMPRESSION, TIP=\"Включить сжатие данных (улучшает скорость соединения)\""), "ACTION",
(Icallback) settingsTglCompression,
NULL),
NULL)), "TITLE=\"Общие\", MARGIN=10x10");
@ -254,6 +254,7 @@ static Ihandle* settingsBoxSecurity()
tglSecurity = IupToggle("Использовать", NULL);
IupSetInt(tglSecurity, "VALUE", getSetParameter(PARAMETER_SECURITY));
IupSetAttribute(tglSecurity, "TIP", "Выбрать конкретный протокол передачи данных");
IupSetCallback(tglSecurity, "ACTION", (Icallback) settingsUseSecurity);
tglTLS = IupToggle("TLS", NULL);
@ -288,6 +289,7 @@ static Ihandle* settingsBoxBitsPerPixel()
tglBitsPerPixel = IupToggle("Использовать", NULL);
IupSetInt(tglBitsPerPixel, "VALUE", getSetParameter(PARAMETER_BITSPERPIXEL));
IupSetAttribute(tglBitsPerPixel, "TIP", "Выбрать конкретную глубину цвета (меньше глубина - выше скорость и хуже качество)");
IupSetCallback(tglBitsPerPixel, "ACTION", (Icallback) settingsUseBitsPerPixel);
tgl8 = IupToggle("8 бит", NULL);
@ -346,11 +348,11 @@ static Ihandle* settingsBoxMonitor()
return IupSetAttributes(
IupFrame(
IupVbox(
IupSetCallbacks(IupSetAttributes(tglFullscreen, "NAME=SETTINGS_TGL_FULLSCREEN, EXPAND=YES"), "ACTION",
IupSetCallbacks(IupSetAttributes(tglFullscreen, "NAME=SETTINGS_TGL_FULLSCREEN, EXPAND=YES, TIP=\"Выполнить подключение на весь экран\""), "ACTION",
(Icallback) settingsTglFullscreen, NULL),
IupSetCallbacks(IupSetAttributes(tglMultimonitor, "NAME=SETTINGS_TGL_MULTIMONITOR"), "ACTION",
IupSetCallbacks(IupSetAttributes(tglMultimonitor, "NAME=SETTINGS_TGL_MULTIMONITOR, TIP=\"Задействовать все подключенные мониторы\""), "ACTION",
(Icallback) settingsTglMultimonitor, NULL),
IupSetCallbacks(IupSetAttributes(ddMonitor, "NAME=MONITORS, DROPDOWN=YES, EXPAND=YES"), "ACTION",
IupSetCallbacks(IupSetAttributes(ddMonitor, "NAME=MONITORS, DROPDOWN=YES, EXPAND=YES, TIP=\"Выбрать конкретный монитор для подключения\""), "ACTION",
(Icallback) settingsChooseMonitor, NULL),
NULL)), "TITLE=\"Монитор\", MARGIN=10x10, CGAP=5");
}
@ -371,10 +373,14 @@ static Ihandle* settingsHorizontalBoxButtons()
btnSave = IupButton("Сохранить", NULL);
IupSetAttribute(btnSave, "NAME", "SETTIGS_BTN_SAVE");
IupSetAttribute(btnSave, "TIP", "Сохранить настройки");
IupSetAttribute(btnSave, "BGCOLOR", "0 179 0");
IupSetAttribute(btnSave, "FGCOLOR", "255 255 255");
btnClose = IupButton("Закрыть", NULL);
IupSetAttribute(btnClose, "NAME", "SETTIGS_BTN_CLOSE");
IupSetAttribute(btnClose, "TIP", "Отменить изменения");
IupSetAttribute(btnClose, "BGCOLOR", "204 0 0");
IupSetAttribute(btnClose, "FGCOLOR", "255 255 255");
IupSetHandle("btnClosePointer", btnClose);

BIN
sqlite3.a Normal file

Binary file not shown.

12836
sqlite3.h Normal file

File diff suppressed because it is too large Load Diff