Compare commits
No commits in common. "d74ba6de54f8ee1c41effbe7522fc670bff4224d" and "b565b3d58b1d0e26356c05aebf2930620a093a3c" have entirely different histories.
d74ba6de54
...
b565b3d58b
|
@ -1,44 +0,0 @@
|
|||
cmake_minimum_required(VERSION 2.8)
|
||||
project(xfree)
|
||||
#include_directories(/home/alexander/repositories/iup/include)
|
||||
include_directories(/root/iup/include)
|
||||
set(SOURCE_EXE
|
||||
address.c
|
||||
arguments.c
|
||||
concat.c
|
||||
db.c
|
||||
gui.c
|
||||
images.c
|
||||
monitor.c
|
||||
node_settings.c
|
||||
rxrandr_broker.c
|
||||
rxrandr.c
|
||||
settings.c
|
||||
xfreerdp.c
|
||||
xrdp.c
|
||||
)
|
||||
add_executable(xfree ${SOURCE_EXE})
|
||||
#target_link_libraries(xfree iup X11 Xrandr m /home/alexander/programming/c/iup/sqlite3.a)
|
||||
target_link_libraries(xfree
|
||||
gtk-3
|
||||
gdk-3
|
||||
pangocairo-1.0
|
||||
pango-1.0
|
||||
atk-1.0
|
||||
cairo-gobject
|
||||
cairo
|
||||
gdk_pixbuf-2.0
|
||||
gio-2.0
|
||||
gobject-2.0
|
||||
glib-2.0
|
||||
X11
|
||||
Xrandr
|
||||
m
|
||||
|
||||
dl
|
||||
pthread
|
||||
|
||||
/root/iup/lib/Linux515/libiup.a
|
||||
/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)
|
|
@ -21,9 +21,8 @@ char *getHostIP(char *dnsName)
|
|||
if (he)
|
||||
{
|
||||
char *ip = inet_ntoa(*(struct in_addr*)he->h_addr);
|
||||
size_t size = strlen(ip) + 1;
|
||||
result = (char *)malloc(sizeof(char) * size);
|
||||
strncpy(result, ip, size);
|
||||
result = (char *)malloc(sizeof(char) * strlen(ip));
|
||||
strcpy(result, ip);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
50
arguments.c
50
arguments.c
|
@ -10,23 +10,51 @@
|
|||
#include "node_settings.h"
|
||||
#include "concat.h"
|
||||
|
||||
#include "rxrandr.h"
|
||||
#include "xrandr.h"
|
||||
#include "db.h"
|
||||
#include "monitor.h"
|
||||
|
||||
void settingsLoad(char *pathDB)
|
||||
void settingsLoad()
|
||||
{
|
||||
getPathDB(pathDB);
|
||||
|
||||
dbLoadData();
|
||||
|
||||
Monitors *monitors = loadMonitors();
|
||||
for (size_t i = 0; i < monitors->size; ++i)
|
||||
// dbGetHostsList();
|
||||
if (!dbLoadData())
|
||||
{
|
||||
addParameterValue(PARAMETER_MONITORS, i, monitors->monitor[i]->data[3], !i);
|
||||
addParameterKey(PARAMETER_XFREERDP, "xfreerdp", true, true, NULL, NULL);
|
||||
addParameterKey(PARAMETER_SERVER, "/v:", true, true, NULL, NULL);
|
||||
addParameterKey(PARAMETER_USERNAME, "/u:", true, true, NULL, NULL);
|
||||
addParameterKey(PARAMETER_PASSWORD, "/p:", true, true, NULL, NULL);
|
||||
addParameterKey(PARAMETER_CERTIGNORE, "/cert-ignore", true, true, NULL, NULL);
|
||||
addParameterKey(PARAMETER_THEMES, "-themes", false, true, NULL, NULL);
|
||||
addParameterKey(PARAMETER_WALLPAPER, "-wallpaper", false, true, NULL, NULL);
|
||||
addParameterKey(PARAMETER_ENCRYPTION, "-encryption", false, true, NULL, NULL);
|
||||
addParameterKey(PARAMETER_FONTS, "-fonts", false, true, NULL, NULL);
|
||||
addParameterKey(PARAMETER_SOUND, "/sound", false, true, NULL, NULL);
|
||||
addParameterKey(PARAMETER_COMPRESSION, "+compression", false, true, NULL, NULL);
|
||||
addParameterKey(PARAMETER_FULLSCREEN, "/f", false, true, NULL, NULL);
|
||||
addParameterKey(PARAMETER_MULTIMONITOR, "/multimon", false, true, getParameter(PARAMETER_FULLSCREEN), NULL);
|
||||
addParameterKey(PARAMETER_AUTHENTICATION, "-authentication", true, true, NULL, NULL);
|
||||
addParameterKey(PARAMETER_SECURITY, "/sec:", true, true, NULL, NULL);
|
||||
addParameterValue(PARAMETER_SECURITY, VALUE_SECURITY_TLS, "tls", true);
|
||||
addParameterValue(PARAMETER_SECURITY, VALUE_SECURITY_RDP, "rdp", false);
|
||||
addParameterValue(PARAMETER_SECURITY, VALUE_SECURITY_NLA, "nla", false);
|
||||
addParameterValue(PARAMETER_SECURITY, VALUE_SECURITY_EXT, "ext", false);
|
||||
addParameterKey(PARAMETER_BITSPERPIXEL, "/bpp:", true, true, NULL, NULL);
|
||||
addParameterValue(PARAMETER_BITSPERPIXEL, VALUES_BITSPERPIXEL_8, "8", true);
|
||||
addParameterValue(PARAMETER_BITSPERPIXEL, VALUES_BITSPERPIXEL_16, "16", false);
|
||||
addParameterValue(PARAMETER_BITSPERPIXEL, VALUES_BITSPERPIXEL_24, "24", false);
|
||||
addParameterValue(PARAMETER_BITSPERPIXEL, VALUES_BITSPERPIXEL_32, "32", false);
|
||||
|
||||
addParameterKey(PARAMETER_USB, "/a:drive,USB,", true, true, NULL, NULL);
|
||||
addParameterValue(PARAMETER_USB, VALUES_USB_DRIVE, "/mnt/usbdevice", true);
|
||||
|
||||
addParameterKey(PARAMETER_MONITORS, "/monitors:", false, true, getParameter(PARAMETER_FULLSCREEN), getParameter(PARAMETER_MULTIMONITOR));
|
||||
}
|
||||
|
||||
dbFreeMonitors(monitors);
|
||||
x_info *monitors = getXInfo();
|
||||
for (size_t i = 0; i < monitors->count; ++i)
|
||||
{
|
||||
addParameterValue(PARAMETER_MONITORS, i, monitors->monitor[i].ptrIndexMonitor, !i);
|
||||
}
|
||||
freeXInfo(monitors);
|
||||
}
|
||||
|
||||
void settingsFree()
|
||||
|
|
|
@ -17,7 +17,7 @@ typedef struct
|
|||
void buildArguments(Arguments *args);
|
||||
void freeArguments(Arguments *args);
|
||||
|
||||
void settingsLoad(char *pathDB);
|
||||
void settingsLoad();
|
||||
void settingsFree();
|
||||
|
||||
#endif /* ARGUMENTS_H_ */
|
||||
|
|
4
concat.c
4
concat.c
|
@ -26,11 +26,11 @@ char* concat(char *s1, char *s2)
|
|||
|
||||
if (s1)
|
||||
{
|
||||
strncpy(result, s1, (len1 + 1));
|
||||
strcpy(result, s1);
|
||||
}
|
||||
if (s2)
|
||||
{
|
||||
strncpy(result + len1, s2, (len2 + 1));
|
||||
strcpy(result + len1, s2);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
237
db.c
237
db.c
|
@ -5,25 +5,15 @@
|
|||
* Author: alexander
|
||||
*/
|
||||
|
||||
#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"
|
||||
|
||||
char* getPathDB(char *path)
|
||||
{
|
||||
static char *current = NULL;
|
||||
if (path && !current)
|
||||
{
|
||||
current = path;
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
static sqlite3 *dbGetBase(char *path)
|
||||
{
|
||||
sqlite3 *db = NULL;
|
||||
|
@ -52,24 +42,35 @@ static sqlite3* dbGetBase(char *path)
|
|||
*/
|
||||
static int dbLoad(void *NotUsed, int argc, char **argv, char **azColName)
|
||||
{
|
||||
if (!getParameter(atoi(argv[0])))
|
||||
NotUsed = 0;
|
||||
|
||||
char **parameters = (char **) malloc(sizeof(char*) * argc);
|
||||
|
||||
for (int i = 0; i < argc; i++)
|
||||
{
|
||||
addParameterKey(atoi(argv[0]), argv[1], atoi(argv[2]), atoi(argv[3]),
|
||||
(argv[7] ? getParameter(atoi(argv[7])) : NULL),
|
||||
(argv[8] ? getParameter(atoi(argv[8])) : NULL));
|
||||
parameters[i] = argv[i];
|
||||
}
|
||||
|
||||
if (argv[4] && argv[5])
|
||||
if (!getParameter(atoi(parameters[0])))
|
||||
{
|
||||
addParameterValue(atoi(argv[0]), atoi(argv[4]), argv[5], atoi(argv[6]));
|
||||
addParameterKey(atoi(parameters[0]), parameters[1], atoi(parameters[2]), atoi(parameters[3]),
|
||||
parameters[7] ? getParameter(atoi(parameters[7])) : NULL,
|
||||
parameters[8] ? getParameter(atoi(parameters[8])) : NULL);
|
||||
}
|
||||
|
||||
if (parameters[4] && parameters[5])
|
||||
{
|
||||
addParameterValue(atoi(parameters[0]), atoi(parameters[4]), parameters[5], atoi(parameters[6]));
|
||||
}
|
||||
|
||||
free(parameters);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool dbLoadData()
|
||||
{
|
||||
sqlite3 *db = dbGetBase(getPathDB(NULL));
|
||||
sqlite3 *db = dbGetBase("freerdp.db");
|
||||
if (!db)
|
||||
{
|
||||
return false;
|
||||
|
@ -106,9 +107,8 @@ static int dbCreateHostsList(void *answer, int argc, char **argv, char **azColNa
|
|||
|
||||
for (int i = 0; i < argc; i++)
|
||||
{
|
||||
size_t size = strlen(argv[i]) + 1;
|
||||
host->data[i] = (char*) malloc(sizeof(char) * size);
|
||||
strncpy(host->data[i], argv[i], size);
|
||||
host->data[i] = (char *) malloc(sizeof(char) * strlen(argv[i]));
|
||||
strcpy(host->data[i], argv[i]);
|
||||
}
|
||||
|
||||
Host **tmp = hosts->host;
|
||||
|
@ -128,7 +128,7 @@ static int dbCreateHostsList(void *answer, int argc, char **argv, char **azColNa
|
|||
|
||||
Hosts *dbGetHostsList()
|
||||
{
|
||||
sqlite3 *db = dbGetBase(getPathDB(NULL));
|
||||
sqlite3 *db = dbGetBase("freerdp.db");
|
||||
if (!db)
|
||||
{
|
||||
return false;
|
||||
|
@ -136,6 +136,7 @@ Hosts* dbGetHostsList()
|
|||
|
||||
char *err_msg = 0;
|
||||
char *sql = "SELECT ROW_NUMBER () OVER (ORDER BY `hosts`.`ip`) `item`, `hosts`.`dns` as `dns`, `hosts`.`set` as `set` FROM `hosts` as `hosts`";
|
||||
|
||||
Hosts *hosts = (Hosts *) malloc(sizeof(Hosts));
|
||||
hosts->size = 0;
|
||||
hosts->host = NULL;
|
||||
|
@ -147,7 +148,9 @@ Hosts* dbGetHostsList()
|
|||
sqlite3_close(db);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
sqlite3_close(db);
|
||||
|
||||
return hosts;
|
||||
}
|
||||
|
||||
|
@ -159,7 +162,6 @@ void dbFreeHosts(Hosts *hosts)
|
|||
{
|
||||
free(hosts->host[i]->data[j]);
|
||||
}
|
||||
free(hosts->host[i]->data);
|
||||
free(hosts->host[i]);
|
||||
}
|
||||
free(hosts);
|
||||
|
@ -167,7 +169,7 @@ void dbFreeHosts(Hosts *hosts)
|
|||
|
||||
bool dbWriteParameter(Parameter name, bool set)
|
||||
{
|
||||
sqlite3 *db = dbGetBase(getPathDB(NULL));
|
||||
sqlite3 *db = dbGetBase("freerdp.db");
|
||||
if (!db)
|
||||
{
|
||||
return false;
|
||||
|
@ -182,6 +184,7 @@ bool dbWriteParameter(Parameter name, bool set)
|
|||
sqlite3_bind_int(res, 2, name);
|
||||
}
|
||||
|
||||
|
||||
if (sqlite3_step(res) == SQLITE_BUSY)
|
||||
{
|
||||
fprintf(stderr, "[ЗАНЯТО] %s - \"%s\"\n", set ? "включено" : "выключено", getParameter(name)->key);
|
||||
|
@ -203,7 +206,7 @@ bool dbWriteParameter(Parameter name, bool set)
|
|||
|
||||
bool dbWriteValue(Value name, bool set)
|
||||
{
|
||||
sqlite3 *db = dbGetBase(getPathDB(NULL));
|
||||
sqlite3 *db = dbGetBase("freerdp.db");
|
||||
if (!db)
|
||||
{
|
||||
return false;
|
||||
|
@ -244,7 +247,7 @@ int dbAddServer(char *ip, char *dns)
|
|||
if (!(ip && strlen(ip) && dns && strlen(dns)))
|
||||
return -1;
|
||||
|
||||
sqlite3 *db = dbGetBase(getPathDB(NULL));
|
||||
sqlite3 *db = dbGetBase("freerdp.db");
|
||||
if (!db)
|
||||
{
|
||||
return -2;
|
||||
|
@ -348,7 +351,7 @@ int dbAddServer(char *ip, char *dns)
|
|||
|
||||
bool dbSetUserNameCurrent(char *current)
|
||||
{
|
||||
sqlite3 *db = dbGetBase(getPathDB(NULL));
|
||||
sqlite3 *db = dbGetBase("freerdp.db");
|
||||
if (!db)
|
||||
{
|
||||
return false;
|
||||
|
@ -383,181 +386,3 @@ bool dbSetUserNameCurrent(char *current)
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
static int dbCreateMonitorsList(void *answer, int argc, char **argv, char **azColName)
|
||||
{
|
||||
Monitors *monitors = *(Monitors**) answer;
|
||||
Monitor *monitor = (Monitor*) malloc(sizeof(Monitor));
|
||||
monitor->data = (char**) malloc(sizeof(char*) * argc);
|
||||
monitor->size = argc;
|
||||
|
||||
for (int i = 0; i < argc; i++)
|
||||
{
|
||||
size_t size = strlen(argv[i]) + 1;
|
||||
monitor->data[i] = (char*) malloc(sizeof(char) * size);
|
||||
strncpy(monitor->data[i], argv[i], size);
|
||||
}
|
||||
|
||||
Monitor **tmp = monitors->monitor;
|
||||
monitors->monitor = (Monitor**) malloc(sizeof(Monitor*) * ++monitors->size);
|
||||
for (size_t i = 0; i < monitors->size - 1; ++i)
|
||||
{
|
||||
monitors->monitor[i] = tmp[i];
|
||||
}
|
||||
if (tmp)
|
||||
{
|
||||
free(tmp);
|
||||
}
|
||||
monitors->monitor[monitors->size - 1] = monitor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Monitors* dbGetMonitorsList()
|
||||
{
|
||||
sqlite3 *db = dbGetBase(getPathDB(NULL));
|
||||
if (!db)
|
||||
{
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
char *err_msg = 0;
|
||||
char *sql =
|
||||
"SELECT ROW_NUMBER () OVER (ORDER BY `monitors`.`set` DESC) `item`, `monitors`.`name` as `name`, `monitors`.`set` as `set`, (ROW_NUMBER () OVER (ORDER BY `monitors`.`id`)) - 1 `item` FROM `monitors` as `monitors`";
|
||||
|
||||
Monitors *monitors = (Monitors*) malloc(sizeof(Monitors));
|
||||
monitors->size = 0;
|
||||
monitors->monitor = NULL;
|
||||
|
||||
if (sqlite3_exec(db, sql, dbCreateMonitorsList, &monitors, &err_msg) != SQLITE_OK)
|
||||
{
|
||||
fprintf(stderr, "Получение списка мониторов. Ошибка выполнения запроса: %s\n", err_msg);
|
||||
sqlite3_free(err_msg);
|
||||
sqlite3_close(db);
|
||||
exit(-2);
|
||||
}
|
||||
|
||||
sqlite3_close(db);
|
||||
|
||||
return monitors;
|
||||
}
|
||||
|
||||
void dbFreeMonitors(Monitors *monitors)
|
||||
{
|
||||
for (size_t i = 0; i < monitors->size; ++i)
|
||||
{
|
||||
for (size_t j = 0; j < monitors->monitor[i]->size; ++j)
|
||||
{
|
||||
free(monitors->monitor[i]->data[j]);
|
||||
}
|
||||
free(monitors->monitor[i]->data);
|
||||
free(monitors->monitor[i]);
|
||||
}
|
||||
free(monitors);
|
||||
}
|
||||
|
||||
bool deleteAllMonitors()
|
||||
{
|
||||
sqlite3 *db = dbGetBase(getPathDB(NULL));
|
||||
if (!db)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
char *sql = "DELETE FROM `monitors`";
|
||||
|
||||
if (sqlite3_exec(db, sql, NULL, NULL, NULL) == SQLITE_OK)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
sqlite3_close(db);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int dbAddMonitor(char *monitor, bool set)
|
||||
{
|
||||
if (!(monitor && strlen(monitor)))
|
||||
return -1;
|
||||
|
||||
sqlite3 *db = dbGetBase(getPathDB(NULL));
|
||||
if (!db)
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
|
||||
sqlite3_stmt *res;
|
||||
char *sql = "INSERT INTO `monitors` (`name`, `set`) VALUES (?, ?)";
|
||||
if (sqlite3_prepare_v2(db, sql, -1, &res, 0) == SQLITE_OK)
|
||||
{
|
||||
sqlite3_bind_text(res, 1, monitor, -1, 0);
|
||||
sqlite3_bind_int(res, 2, set);
|
||||
}
|
||||
|
||||
// if (sqlite3_step(res) == SQLITE_BUSY)
|
||||
// {
|
||||
// fprintf(stderr, "[ЗАНЯТО] %s - \"%s\"\n", text ? "установлено" : "очищено", text ? getValue(VALUE_USERNAME)->current : "");
|
||||
// }
|
||||
// if (sqlite3_step(res) == SQLITE_ERROR)
|
||||
// {
|
||||
// fprintf(stderr, "[ОШИБКА] %s - \"%s\"\n", text ? "установлено" : "очищено", text ? getValue(VALUE_USERNAME)->current : "");
|
||||
// }
|
||||
if (sqlite3_step(res) == SQLITE_DONE)
|
||||
{
|
||||
fprintf(stdout, "[УСПЕШНО] %s - \"%s\"\n", monitor ? "установлено" : "очищено", monitor ? monitor : "");
|
||||
return 0;
|
||||
}
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
|
||||
return -3;
|
||||
}
|
||||
|
||||
int dbSaveMonitors(char *name)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if (!(name && strlen(name)))
|
||||
return -1;
|
||||
|
||||
sqlite3 *db = dbGetBase(getPathDB(NULL));
|
||||
if (!db)
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
|
||||
char *sql = "UPDATE `monitors` set `set` = 0";
|
||||
if (sqlite3_exec(db, sql, NULL, NULL, NULL) == SQLITE_OK)
|
||||
{
|
||||
sqlite3_stmt *res;
|
||||
sql = "UPDATE `monitors` SET `set` = 1 WHERE `name` = ?";
|
||||
if (sqlite3_prepare_v2(db, sql, -1, &res, 0) == SQLITE_OK)
|
||||
{
|
||||
sqlite3_bind_text(res, 1, name, -1, 0);
|
||||
}
|
||||
|
||||
if (sqlite3_step(res) == SQLITE_BUSY)
|
||||
{
|
||||
fprintf(stderr, "[ЗАНЯТО] %s - \"%s\"\n", name ? "установлено" : "очищено", name);
|
||||
result = 2;
|
||||
}
|
||||
if (sqlite3_step(res) == SQLITE_ERROR)
|
||||
{
|
||||
fprintf(stderr, "[ОШИБКА] %s - \"%s\"\n", name ? "установлено" : "очищено", name);
|
||||
result = 1;
|
||||
}
|
||||
if (sqlite3_step(res) == SQLITE_DONE)
|
||||
{
|
||||
fprintf(stdout, "[УСПЕШНО] %s - \"%s\"\n", name ? "установлено" : "очищено", name);
|
||||
result = 0;
|
||||
}
|
||||
sqlite3_finalize(res);
|
||||
}
|
||||
|
||||
sqlite3_close(db);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
22
db.h
22
db.h
|
@ -8,9 +8,6 @@
|
|||
#ifndef DB_H_
|
||||
#define DB_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "parameter.h"
|
||||
#include "value.h"
|
||||
|
||||
|
@ -26,28 +23,9 @@ typedef struct Hosts
|
|||
size_t size;
|
||||
} Hosts;
|
||||
|
||||
typedef struct Monitor
|
||||
{
|
||||
char **data;
|
||||
size_t size;
|
||||
} Monitor;
|
||||
|
||||
typedef struct Monitors
|
||||
{
|
||||
Monitor **monitor;
|
||||
size_t size;
|
||||
} Monitors;
|
||||
|
||||
char *getPathDB(char *path);
|
||||
|
||||
bool dbLoadData();
|
||||
Hosts *dbGetHostsList();
|
||||
void dbFreeHosts(Hosts *hosts);
|
||||
Monitors *dbGetMonitorsList();
|
||||
void dbFreeMonitors(Monitors *monitors);
|
||||
bool deleteAllMonitors();
|
||||
int dbAddMonitor(char *monitor, bool set);
|
||||
int dbSaveMonitors(char *name);
|
||||
bool dbWriteParameter(Parameter name, bool set);
|
||||
bool dbWriteValue(Value name, bool set);
|
||||
bool dbSetUserNameCurrent(char *current);
|
||||
|
|
BIN
freerdp.db
BIN
freerdp.db
Binary file not shown.
10
gui.c
10
gui.c
|
@ -65,12 +65,10 @@ static void createHostsList(Ihandle *iupList)
|
|||
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);
|
||||
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]))
|
||||
|
|
84
monitor.c
84
monitor.c
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
* monitor.c
|
||||
*
|
||||
* Created on: 18 июл. 2022 г.
|
||||
* Author: alexander
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "monitor.h"
|
||||
#include "rxrandr.h"
|
||||
|
||||
static bool checkMonitor(Monitors *dbMonitors, x_info *pcMonitors)
|
||||
{
|
||||
if (!dbMonitors->size || !pcMonitors->count ||
|
||||
!(dbMonitors->size == pcMonitors->count))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool compare = false;
|
||||
|
||||
for (size_t i = 0; i < dbMonitors->size; ++i)
|
||||
{
|
||||
for (size_t j = 0; j < pcMonitors->count; ++j)
|
||||
{
|
||||
if (!strcmp(pcMonitors->monitor[j].name, dbMonitors->monitor[i]->data[1]))
|
||||
{
|
||||
compare = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!compare)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
compare = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Monitors *loadMonitors()
|
||||
{
|
||||
Monitors *dbMonitors = dbGetMonitorsList();
|
||||
x_info *pcMonitors = getXInfo();
|
||||
if (!checkMonitor(dbMonitors, pcMonitors)) // Если строки не равны, произвести перезапись в БД
|
||||
{
|
||||
if (dbMonitors)
|
||||
dbFreeMonitors(dbMonitors);
|
||||
|
||||
if (!deleteAllMonitors())
|
||||
{
|
||||
fprintf(stderr, "Не удалось удалить записи мониторов из БД\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < pcMonitors->count; ++i)
|
||||
{
|
||||
dbAddMonitor(pcMonitors->monitor[i].name, pcMonitors->monitor[i].primary);
|
||||
}
|
||||
freeXInfo(pcMonitors);
|
||||
|
||||
return dbGetMonitorsList();
|
||||
}
|
||||
|
||||
freeXInfo(pcMonitors);
|
||||
|
||||
return dbMonitors;
|
||||
}
|
||||
|
||||
void freeMonitors(Monitors *monitors)
|
||||
{
|
||||
for (size_t i = 0; i < monitors->size; ++i)
|
||||
{
|
||||
free(monitors->monitor[i]->data[2]);
|
||||
free(monitors->monitor[i]->data[3]);
|
||||
free(monitors->monitor[i]->data);
|
||||
free(monitors->monitor[i]);
|
||||
}
|
||||
free(monitors);
|
||||
}
|
16
monitor.h
16
monitor.h
|
@ -1,16 +0,0 @@
|
|||
/*
|
||||
* monitor.h
|
||||
*
|
||||
* Created on: 18 июл. 2022 г.
|
||||
* Author: alexander
|
||||
*/
|
||||
|
||||
#ifndef MONITOR_H_
|
||||
#define MONITOR_H_
|
||||
|
||||
#include "db.h"
|
||||
|
||||
Monitors *loadMonitors();
|
||||
void freeMonitors(Monitors *monitors);
|
||||
|
||||
#endif /* MONITOR_H_ */
|
|
@ -24,9 +24,8 @@ static NodeValue* newNodeValue(Value name, char *current, bool set)
|
|||
node->change = false;
|
||||
node->next = NULL;
|
||||
|
||||
size_t size = strlen(current) + 1;
|
||||
node->current = (char*) malloc(sizeof(char) * size);
|
||||
strncpy(node->current, current, size);
|
||||
node->current = (char*) malloc(sizeof(char) * strlen(current));
|
||||
strcpy(node->current, current);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
@ -64,9 +63,8 @@ static NodeParameter* newNodeParameter(Parameter name, char *key, bool set, bool
|
|||
node->conflict = conflict;
|
||||
node->next = NULL;
|
||||
|
||||
size_t size = strlen(key) + 1;
|
||||
node->key = (char*) malloc(sizeof(char) * size);
|
||||
strncpy(node->key, key, size);
|
||||
node->key = (char*) malloc(sizeof(char) * strlen(key));
|
||||
strcpy(node->key, key);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
@ -306,7 +304,7 @@ void setParameterValue(Parameter pName, Value vName, char *current)
|
|||
return;
|
||||
}
|
||||
|
||||
size_t length = strlen(current) + 1;
|
||||
size_t length = strlen(current);
|
||||
|
||||
if (!length)
|
||||
{
|
||||
|
@ -340,7 +338,7 @@ void setParameterValue(Parameter pName, Value vName, char *current)
|
|||
{
|
||||
free(nodeValue->current);
|
||||
nodeValue->current = (char*) malloc(sizeof(char) * length);
|
||||
strncpy(nodeValue->current, current, length);
|
||||
strcpy(nodeValue->current, current);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -22,8 +22,8 @@ typedef enum
|
|||
PARAMETER_SOUND,
|
||||
PARAMETER_COMPRESSION,
|
||||
PARAMETER_FULLSCREEN,
|
||||
PARAMETER_MULTIMONITOR,
|
||||
PARAMETER_MONITORS,
|
||||
PARAMETER_MULTIMONITOR,
|
||||
PARAMETER_AUTHENTICATION,
|
||||
PARAMETER_SECURITY,
|
||||
PARAMETER_BITSPERPIXEL,
|
||||
|
|
25
settings.c
25
settings.c
|
@ -10,7 +10,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "monitor.h"
|
||||
#include "xrandr.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "settings.h"
|
||||
|
@ -33,7 +33,6 @@ static int settingsClose(Ihandle *self)
|
|||
static int settingsSave(Ihandle *self)
|
||||
{
|
||||
saveChangeSettings();
|
||||
dbSaveMonitors(IupGetAttribute(IupGetDialogChild(self, "MONITORS"), "VALUESTRING"));
|
||||
IupSetAttribute(IupGetDialog(self), "SIMULATEMODAL", "OFF");
|
||||
IupHide(IupGetDialog(self));
|
||||
return IUP_DEFAULT;
|
||||
|
@ -325,21 +324,27 @@ static Ihandle* settingsBoxMonitor()
|
|||
tglFullscreen = IupToggle("На весь экран", NULL);
|
||||
ddMonitor = IupList(NULL);
|
||||
|
||||
Monitors *monitors = loadMonitors();
|
||||
for (size_t i = 0; i < monitors->size; ++i)
|
||||
{
|
||||
IupSetAttribute(ddMonitor, monitors->monitor[i]->data[0], monitors->monitor[i]->data[1]);
|
||||
if (monitors->monitor[i]->data[2][0] == '1')
|
||||
IupSetAttribute(ddMonitor, "VALUE", monitors->monitor[i]->data[0]);
|
||||
}
|
||||
freeMonitors(monitors);
|
||||
x_info *monitors = getXInfo();
|
||||
char *allMonitorIndex = (char*) malloc(sizeof(char) * 3);
|
||||
sprintf(allMonitorIndex, "%hu", monitors->count + 1);
|
||||
size_t setValueIndex = 0;
|
||||
|
||||
for (short i = 0; i < monitors->count; ++i)
|
||||
{
|
||||
IupSetAttribute(ddMonitor, monitors->monitor[i].ptrIndexItem, monitors->monitor[i].ptrName);
|
||||
if (getSetValue(PARAMETER_MONITORS, i))
|
||||
setValueIndex = i + 1;
|
||||
}
|
||||
|
||||
IupSetInt(ddMonitor, "VALUE", setValueIndex ? setValueIndex : 1);
|
||||
IupSetInt(tglMultimonitor, "VALUE", getSetParameter(PARAMETER_MULTIMONITOR));
|
||||
IupSetInt(tglFullscreen, "VALUE", getSetParameter(PARAMETER_FULLSCREEN));
|
||||
|
||||
IupSetInt(tglMultimonitor, "ACTIVE", getSetParameter(PARAMETER_FULLSCREEN));
|
||||
IupSetInt(ddMonitor, "ACTIVE", getSetParameter(PARAMETER_FULLSCREEN) && !getSetParameter(PARAMETER_MULTIMONITOR));
|
||||
|
||||
free(monitors);
|
||||
|
||||
return IupSetAttributes(
|
||||
IupFrame(
|
||||
IupVbox(
|
||||
|
|
|
@ -6,10 +6,7 @@
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc > 1)
|
||||
settingsLoad(argv[1]);
|
||||
else
|
||||
settingsLoad("/etc/freerdp/freerdp.db");
|
||||
settingsLoad();
|
||||
|
||||
IupOpen(&argc, &argv);
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "rxrandr.h"
|
||||
#include "xrandr.h"
|
||||
|
||||
static char *program_name;
|
||||
static Display *dpy;
|
|
@ -5,7 +5,7 @@
|
|||
* Author: alexander
|
||||
*/
|
||||
|
||||
#include "rxrandr.h"
|
||||
#include "xrandr.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
@ -14,18 +14,15 @@
|
|||
x_info *getXInfo()
|
||||
{
|
||||
x_info *monitors = (x_info *) malloc(sizeof(x_info));
|
||||
monitors->count = 0;
|
||||
XInfo(monitors);
|
||||
|
||||
for (int i = 0; i < monitors->count; ++i)
|
||||
{
|
||||
size_t size = strlen(monitors->monitor[i].name) + 1;
|
||||
|
||||
monitors->monitor[i].ptrName = (char *)malloc(sizeof(char) * size);
|
||||
monitors->monitor[i].ptrName = (char *)malloc(sizeof(char) * strlen(monitors->monitor[i].name));
|
||||
monitors->monitor[i].ptrIndexItem = (char *)malloc(sizeof(char) * 3);
|
||||
monitors->monitor[i].ptrIndexMonitor = (char *)malloc(sizeof(char) * 3);
|
||||
|
||||
strncpy(monitors->monitor[i].ptrName, monitors->monitor[i].name, size);
|
||||
strcpy(monitors->monitor[i].ptrName, monitors->monitor[i].name);
|
||||
sprintf(monitors->monitor[i].ptrIndexItem, "%d", i + 1);
|
||||
sprintf(monitors->monitor[i].ptrIndexMonitor, "%d", i);
|
||||
}
|
Loading…
Reference in New Issue