parent
2883b81cc3
commit
05008594c1
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<gresources>
|
||||||
|
<gresource prefix="/com/ublinux/ui">
|
||||||
|
<file>ubl-settings-resourcequota.glade</file>
|
||||||
|
</gresource>
|
||||||
|
<gresource prefix="/com/ublinux/css">
|
||||||
|
<file>ubl-settings-resourcequota.css</file>
|
||||||
|
</gresource>
|
||||||
|
<gresource prefix="/com/ublinux/images">
|
||||||
|
<file>ubl-settings-resourcequota-banner.png</file>
|
||||||
|
</gresource>
|
||||||
|
</gresources>
|
@ -0,0 +1,969 @@
|
|||||||
|
#include "philos_utils.h"
|
||||||
|
|
||||||
|
void philos_array_string_remove_char(char*** array, char* str_remove, int size) {
|
||||||
|
for (int index = 0; index < size; index++) {
|
||||||
|
(*array)[index] = yon_char_divide_search((*array)[index], str_remove, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void philos_set_pow_size_memory(char* str_find, int** array_size,int index, char** array_size_pow) {
|
||||||
|
char* STR_KB = array_size_pow[0];
|
||||||
|
char* STR_MB = array_size_pow[1];
|
||||||
|
char* STR_GB = array_size_pow[2];
|
||||||
|
char* STR_TB = array_size_pow[3];
|
||||||
|
size_t length = strlen(str_find);
|
||||||
|
if (strstr(str_find,"K") != NULL) {
|
||||||
|
*array_size = philos_int_append(*array_size, &index, 0);
|
||||||
|
str_find = yon_char_divide(str_find, length-1);
|
||||||
|
str_find = yon_char_unite(str_find, " ", STR_KB, NULL);
|
||||||
|
index--;
|
||||||
|
}
|
||||||
|
else if (strstr(str_find,"M") != NULL) {
|
||||||
|
*array_size = philos_int_append(*array_size, &index, 1);
|
||||||
|
str_find = yon_char_divide(str_find, length-1);
|
||||||
|
str_find = yon_char_unite(str_find," ", STR_MB, NULL);
|
||||||
|
index--;
|
||||||
|
}
|
||||||
|
else if (strstr(str_find,"G") != NULL) {
|
||||||
|
*array_size = philos_int_append(*array_size, &index, 2);
|
||||||
|
str_find = yon_char_divide(str_find, length-1);
|
||||||
|
str_find = yon_char_unite(str_find," ", STR_GB, NULL);
|
||||||
|
index--;
|
||||||
|
}
|
||||||
|
else if (strstr(str_find,"T") != NULL) {
|
||||||
|
*array_size = philos_int_append(*array_size, &index, 3);
|
||||||
|
str_find = yon_char_divide(str_find, length-1);
|
||||||
|
|
||||||
|
str_find = yon_char_unite(str_find," ", STR_TB, NULL);
|
||||||
|
index--;
|
||||||
|
}
|
||||||
|
else if (strstr(str_find,"%%") != NULL) {
|
||||||
|
*array_size = philos_int_append(*array_size, &index, -1);
|
||||||
|
str_find = yon_char_divide(str_find, length-1);
|
||||||
|
index--;
|
||||||
|
}
|
||||||
|
else if (strstr(str_find,"-") != NULL) {
|
||||||
|
*array_size = philos_int_append(*array_size, &index, -1);
|
||||||
|
index--;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void philos_set_size_memory_integer_char(char* str_find, char*** array_data, int index) {
|
||||||
|
char* simv_del_array[10] = {"K","M","G","T","k","m","g","t"," ","%"};
|
||||||
|
for (size_t i = 0; i < 10; i++) {
|
||||||
|
if (strstr(str_find, simv_del_array[i])) {
|
||||||
|
str_find = yon_char_divide_search(str_find, simv_del_array[i], -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (strstr(str_find, " ") != NULL) {
|
||||||
|
char* mem_s = yon_char_new(str_find);
|
||||||
|
yon_char_divide_search(mem_s, " ", -1);
|
||||||
|
*array_data = yon_char_parsed_append(*array_data, &index, mem_s);
|
||||||
|
}
|
||||||
|
if (strstr(str_find, "-") != NULL) {
|
||||||
|
*array_data = yon_char_parsed_append(*array_data, &index, "-");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (str_find[0] == '\"') {
|
||||||
|
yon_char_divide(str_find, 0);
|
||||||
|
size_t length = strlen(str_find);
|
||||||
|
str_find = yon_char_divide(str_find, length-2);
|
||||||
|
}
|
||||||
|
if (strstr(str_find, " ") == NULL) {
|
||||||
|
*array_data = yon_char_parsed_append(*array_data, &index, str_find);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void philos_free_string_array(char ***array, int size) {
|
||||||
|
if ((*array) == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < size; i++){
|
||||||
|
free((*array)[i]);
|
||||||
|
}
|
||||||
|
if (size!= 0) {
|
||||||
|
free(*array);
|
||||||
|
(*array) = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void philos_free_string_array_n3(char ****array, int size) {
|
||||||
|
if ((*array) == NULL || size == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int index_to_l2 = 0;
|
||||||
|
for (int i = 0; i < size; i++){
|
||||||
|
index_to_l2 = 0;
|
||||||
|
if ((*array)[i]!=NULL) {
|
||||||
|
while ((*array)[i][index_to_l2] != NULL) {
|
||||||
|
if ((*array)[i][index_to_l2] != NULL) {
|
||||||
|
free((*array)[i][index_to_l2]);
|
||||||
|
index_to_l2++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free((*array)[i]);
|
||||||
|
|
||||||
|
}
|
||||||
|
if (size!= 0) {
|
||||||
|
free(*array);
|
||||||
|
(*array) = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void philos_free_int_array(int **array, int size) {
|
||||||
|
if (size!= 0) {
|
||||||
|
free(*array);
|
||||||
|
*array = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void philos_free_int_array_n2(int ***array, int size) {
|
||||||
|
if ((*array) == NULL || size == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < size; i++){
|
||||||
|
free((*array)[i]);
|
||||||
|
}
|
||||||
|
if (size!= 0) {
|
||||||
|
free(*array);
|
||||||
|
(*array) = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
config_str philos_list_group(int* size) {
|
||||||
|
char* str_uid_min = "UID_MIN";
|
||||||
|
char* str_uid_max = "UID_MAX";
|
||||||
|
unsigned short uid_min = philos_read_uid_min_max(file_source_login_min_max, str_uid_min);
|
||||||
|
unsigned short uid_max = philos_read_uid_min_max(file_source_login_min_max, str_uid_max);
|
||||||
|
config_str str_users = malloc(1);
|
||||||
|
while (1) {
|
||||||
|
errno = 0; // so we can distinguish errors from no more entries
|
||||||
|
struct passwd* entry = getpwent();
|
||||||
|
if (!entry) {
|
||||||
|
if (errno) {
|
||||||
|
return str_users;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ((entry->pw_uid >= uid_min && entry->pw_uid < uid_max) || entry->pw_uid == 0) {
|
||||||
|
str_users = yon_char_parsed_append(str_users, size, entry->pw_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
endpwent();
|
||||||
|
return str_users;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned short philos_read_uid_min_max(char* filename, char* search) {
|
||||||
|
int uid = 0;
|
||||||
|
char* remove_tab = "\t";
|
||||||
|
char* remove_space = " ";
|
||||||
|
char* search_uid_min = "UID_MIN";
|
||||||
|
int buff_size = 255;
|
||||||
|
char* line = g_malloc0(buff_size);
|
||||||
|
char* search_true = yon_char_get_augumented("SYS_", search);
|
||||||
|
FILE *fp = fopen(filename, "r");
|
||||||
|
if(fp) {
|
||||||
|
while((fgets(line, buff_size, fp)) != NULL) {
|
||||||
|
try{
|
||||||
|
if (yon_char_find_count(line, search) != 0 && yon_char_find_count(line, search_true) == 0) {
|
||||||
|
line = philos_str_remove(line, search);
|
||||||
|
line = philos_str_remove(line, remove_space);
|
||||||
|
line = philos_str_remove(line, remove_tab);
|
||||||
|
uid = atoi(line);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
if (yon_char_find_count(search, search_uid_min) != 0){
|
||||||
|
uid = 1000;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
uid = 65534;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if (yon_char_find_count(search, search_uid_min) != 0) {
|
||||||
|
uid = 1000;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
uid = 65534;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
free(line);
|
||||||
|
free(search_true);
|
||||||
|
return uid;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
config_str philos_list_user(int* size) {
|
||||||
|
char* str_uid_min = "UID_MIN";
|
||||||
|
char* str_uid_max = "UID_MAX";
|
||||||
|
unsigned short uid_min = philos_read_uid_min_max(file_source_login_min_max, str_uid_min);
|
||||||
|
unsigned short uid_max = philos_read_uid_min_max(file_source_login_min_max, str_uid_max);
|
||||||
|
config_str str_users = malloc(1);
|
||||||
|
while (1) {
|
||||||
|
errno = 0; // so we can distinguish errors from no more entries
|
||||||
|
struct passwd* entry = getpwent();
|
||||||
|
if (!entry) {
|
||||||
|
if (errno) {
|
||||||
|
return str_users;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//if ((entry->pw_uid >= uid_min && entry->pw_uid < uid_max) || entry->pw_uid == 0) {
|
||||||
|
str_users = yon_char_parsed_append(str_users, size, entry->pw_name);
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
endpwent();
|
||||||
|
return str_users;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* philos_str_size_pow_byte(GtkWidget *combo_box_text) {
|
||||||
|
int menu_id = gtk_combo_box_get_active(GTK_COMBO_BOX(combo_box_text));
|
||||||
|
if (menu_id == 0) {
|
||||||
|
return "K";
|
||||||
|
}
|
||||||
|
else if (menu_id == 1) {
|
||||||
|
return "M";
|
||||||
|
}
|
||||||
|
else if (menu_id == 2) {
|
||||||
|
return "G";
|
||||||
|
}
|
||||||
|
else if (menu_id == 3) {
|
||||||
|
return "T";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char* philos_str_remove(char *str, const char *sub) {
|
||||||
|
size_t len = strlen(sub);
|
||||||
|
if (len > 0) {
|
||||||
|
char *p = str;
|
||||||
|
size_t size = 0;
|
||||||
|
while ((p = strstr(p, sub)) != NULL) {
|
||||||
|
size = (size == 0) ? (p - str) + strlen(p + len) + 1 : size - len;
|
||||||
|
memmove(p, p + len, size - (p - str));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void philos_split_size_memory(char* str_value, int* size, char* pow_memory) {
|
||||||
|
// pow_memory = yon_char_new(str_value);
|
||||||
|
(*size) = atoi(yon_char_divide_search(pow_memory, " ", -1));
|
||||||
|
}
|
||||||
|
|
||||||
|
char* philos_format_cfg_str_size_memory(char* str_key, int value, int pow_size_memory) {
|
||||||
|
if (value == -1 || value == -3 || pow_size_memory == -3) {
|
||||||
|
return yon_char_new("-");
|
||||||
|
}
|
||||||
|
char* str_value = yon_char_from_int(value);
|
||||||
|
str_value = yon_char_divide_search(str_value, " ", -1);
|
||||||
|
if (pow_size_memory==0) {
|
||||||
|
return yon_char_unite(str_key, str_value, "K" ,NULL);
|
||||||
|
}
|
||||||
|
else if (pow_size_memory==1) {
|
||||||
|
return yon_char_unite(str_key, str_value, "M" ,NULL);
|
||||||
|
}
|
||||||
|
else if (pow_size_memory==2){
|
||||||
|
return yon_char_unite(str_key, str_value, "G" ,NULL);
|
||||||
|
}
|
||||||
|
else if (pow_size_memory== 3) {
|
||||||
|
return yon_char_unite(str_key, str_value, "T" ,NULL);
|
||||||
|
}
|
||||||
|
else if (pow_size_memory== -1) {
|
||||||
|
return yon_char_unite(str_key, str_value, "%" ,NULL);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return yon_char_unite(str_key, str_value, "-" ,NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char** philos_str_split(char *parameters, int *size, char *divider) {
|
||||||
|
char** array_split = NULL;
|
||||||
|
char* ch= NULL;
|
||||||
|
ch = strtok(parameters, divider);
|
||||||
|
if (ch != NULL) {
|
||||||
|
array_split = yon_char_parsed_append(array_split, size, ch);
|
||||||
|
while (ch != NULL) {
|
||||||
|
ch = strtok(NULL, divider);
|
||||||
|
array_split = yon_char_parsed_append(array_split, size, ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(*size) -= 1;
|
||||||
|
return array_split;
|
||||||
|
}
|
||||||
|
|
||||||
|
void philos_array_str_copy(char*** source, char*** copy) {
|
||||||
|
int index = 0;
|
||||||
|
if (copy == NULL || source == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
while (1) {
|
||||||
|
if ((*copy)[index] != NULL) {
|
||||||
|
(*source) = yon_char_parsed_append((*source), &index, yon_char_new((*copy)[index]));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void philos_array_int_copy(int** source, int** copy) {
|
||||||
|
int * new_int = g_malloc0(sizeof(int)*2);
|
||||||
|
if ((*copy)[0] != -2) {
|
||||||
|
new_int[0] = (*copy)[0];
|
||||||
|
new_int[1] = -2;
|
||||||
|
int i = 2;
|
||||||
|
for (i=1;(*copy)[i]!=-2;i++) {
|
||||||
|
yon_int_array_append(&new_int,(*copy)[i]);
|
||||||
|
}
|
||||||
|
*source=new_int;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
new_int[0] = (*copy)[0];
|
||||||
|
*source=new_int;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
char** philos_pars_terminal_systemd_cgls(char* CMD_GET_SLICE_SERVICE, char* str_find, int* size_array_data) {
|
||||||
|
int size = 0;
|
||||||
|
char** terminal_print = yon_config_load(CMD_GET_SLICE_SERVICE, &size);
|
||||||
|
char** array_data = NULL;
|
||||||
|
for (int index = 0; index < size; index++) {
|
||||||
|
if (strstr(terminal_print[index], str_find) != NULL) {
|
||||||
|
yon_char_divide_search(terminal_print[index],"─",-1);
|
||||||
|
terminal_print[index] = yon_char_divide_search(terminal_print[index]," ", -1);
|
||||||
|
yon_char_divide(terminal_print[index],1);
|
||||||
|
array_data = yon_char_parsed_append(array_data, size_array_data, terminal_print[index]);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return array_data;
|
||||||
|
}
|
||||||
|
char* philos_pard_array_add_cmd(char* cmd, temp_config* _config, char* key, int* array_io, int* array_io_pow_size) {
|
||||||
|
char* split_simvol = g_malloc0(sizeof(char)*2);
|
||||||
|
int flag_format = 0;
|
||||||
|
char* cmd_old = yon_char_new(cmd);
|
||||||
|
if (_config->disk && _config->size && array_io && array_io_pow_size) {
|
||||||
|
int index_find = 0;
|
||||||
|
for (int index = 0; index < _config->size; index++) {
|
||||||
|
if (index==0) {
|
||||||
|
if (strlen(cmd)>1) {
|
||||||
|
cmd = yon_char_unite(cmd, ",", key, NULL);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cmd = yon_char_unite(cmd, key, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (array_io_pow_size[index] != -1 && array_io[index]!=-2 && array_io[index]!=-1) {
|
||||||
|
char* num_and_pow_size = philos_format_cfg_str_size_memory(" ", array_io[index], array_io_pow_size[index]);
|
||||||
|
cmd = yon_char_unite(cmd,
|
||||||
|
split_simvol,
|
||||||
|
_config->disk[index],
|
||||||
|
num_and_pow_size, NULL);
|
||||||
|
split_simvol[0] = ',';
|
||||||
|
split_simvol[1] = '\0';
|
||||||
|
flag_format = 1;
|
||||||
|
free(num_and_pow_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(split_simvol);
|
||||||
|
if (flag_format) {
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return cmd_old;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
int philos_check_activ_disk(temp_set_window *widgets, temp_config* _config) {
|
||||||
|
char* disk = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->cbtTempDevice));
|
||||||
|
disk = yon_char_divide_search(disk," ", -1);
|
||||||
|
int bool_read = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead));
|
||||||
|
int bool_write = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite));
|
||||||
|
if (disk == NULL || _config->size == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void philos_temp_generate_cmd(temp_set_window *widgets, temp_config* _config) {
|
||||||
|
char* str_cmd = "";
|
||||||
|
char* split_simvol = g_malloc0(sizeof(char)*2);
|
||||||
|
int size_bite = 0;
|
||||||
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chkSoftRestrictionTemp))) {
|
||||||
|
size_bite = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spiSevereRestrictionTemp));
|
||||||
|
str_cmd = yon_char_unite(str_cmd,
|
||||||
|
"MemoryHigh=",
|
||||||
|
yon_char_from_int(size_bite),
|
||||||
|
philos_str_size_pow_byte(widgets->cmSevereRestrictionTemp), NULL);
|
||||||
|
split_simvol[0] = ',';
|
||||||
|
split_simvol[1] = '\0';
|
||||||
|
}
|
||||||
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chkSevereRestrictionTemp))) {
|
||||||
|
size_bite = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinSevereRestrictionTemp));
|
||||||
|
str_cmd = yon_char_unite(str_cmd, split_simvol,
|
||||||
|
"MemoryMax=",
|
||||||
|
yon_char_from_int(size_bite),
|
||||||
|
philos_str_size_pow_byte(widgets->cmbSevereRestrictionTemp), NULL);
|
||||||
|
split_simvol[0] = ',';
|
||||||
|
split_simvol[1] = '\0';
|
||||||
|
}
|
||||||
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chkPaddingFLTemp))) {
|
||||||
|
size_bite = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinPaddingFLTemp));
|
||||||
|
str_cmd = yon_char_unite(str_cmd, split_simvol,
|
||||||
|
"MemorySwapMax=",
|
||||||
|
yon_char_from_int(size_bite),
|
||||||
|
philos_str_size_pow_byte(widgets->cmbPaddingFLTemp), NULL);
|
||||||
|
split_simvol[0] = ',';
|
||||||
|
split_simvol[1] = '\0';
|
||||||
|
}
|
||||||
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chkCPULimitTemp))) {
|
||||||
|
size_bite = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinCPULimitTemp));
|
||||||
|
str_cmd = yon_char_unite(str_cmd, split_simvol,
|
||||||
|
"CPUQuota=",
|
||||||
|
yon_char_from_int(size_bite),
|
||||||
|
"%", NULL);
|
||||||
|
split_simvol[0] = ',';
|
||||||
|
split_simvol[1] = '\0';
|
||||||
|
}
|
||||||
|
if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempDevice))!=-1) {
|
||||||
|
if (_config->size!=0) {
|
||||||
|
str_cmd = philos_pard_array_add_cmd(str_cmd, _config, "IOReadBandwidthMax=", _config->i_o_limit_read, _config->i_o_limit_read_size);
|
||||||
|
str_cmd = philos_pard_array_add_cmd(str_cmd, _config, "IOWriteBandwidthMax=", _config->i_o_limit_write, _config->i_o_limit_write_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
gtk_entry_set_text(GTK_ENTRY(widgets->entryTempCmd), str_cmd);
|
||||||
|
free(split_simvol);
|
||||||
|
}
|
||||||
|
void philos_temp_del_disk(temp_set_window *widgets, temp_config* _config) {
|
||||||
|
char* disk = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->cbtTempDevice));
|
||||||
|
disk = yon_char_divide_search(disk, " ", -1);
|
||||||
|
int bool_read = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead));
|
||||||
|
int bool_write = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite));
|
||||||
|
if (philos_check_activ_disk(widgets, _config) == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_config->disk && _config->size) {
|
||||||
|
int index_find = -1;
|
||||||
|
for (int index = 0; index < _config->size; index++) {
|
||||||
|
char* disk_cfg = _config->disk[index];
|
||||||
|
if (strstr(disk_cfg, disk) != NULL) {
|
||||||
|
index_find = index;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((bool_read == 0 && bool_write == 0 && index_find != -1)) {
|
||||||
|
_config->disk = yon_char_parsed_shrink(_config->disk,&_config->size, index_find);
|
||||||
|
_config->size++;
|
||||||
|
_config->i_o_limit_read_size = remove_element_int_array(_config->i_o_limit_read_size,&_config->size, index_find);
|
||||||
|
_config->size++;
|
||||||
|
_config->i_o_limit_write_size = remove_element_int_array(_config->i_o_limit_write_size,&_config->size, index_find);
|
||||||
|
_config->size++;
|
||||||
|
_config->i_o_limit_read = remove_element_int_array(_config->i_o_limit_read,&_config->size, index_find);
|
||||||
|
_config->size++;
|
||||||
|
_config->i_o_limit_write = remove_element_int_array(_config->i_o_limit_write,&_config->size, index_find);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void philos_temp_config_init(temp_config* _config) {
|
||||||
|
if (_config->size != 0) {
|
||||||
|
philos_free_string_array(&_config->disk, _config->size);
|
||||||
|
philos_free_int_array(&_config->i_o_limit_read, _config->size);
|
||||||
|
philos_free_int_array(&_config->i_o_limit_read_size, _config->size);
|
||||||
|
philos_free_int_array(&_config->i_o_limit_write, _config->size);
|
||||||
|
philos_free_int_array(&_config->i_o_limit_write_size, _config->size);
|
||||||
|
}
|
||||||
|
_config->disk = NULL;
|
||||||
|
_config->i_o_limit_read = NULL;
|
||||||
|
_config->i_o_limit_write = NULL;
|
||||||
|
_config->i_o_limit_read_size = NULL;
|
||||||
|
_config->i_o_limit_write_size = NULL;
|
||||||
|
_config->size = 0;
|
||||||
|
}
|
||||||
|
// flag_check_array = 0 READ
|
||||||
|
// flag_check_array = 1 WRITE
|
||||||
|
void philos_update_device_to_entry(temp_set_window *widgets, temp_config* _config, int flag_check_array) {
|
||||||
|
int disk_id = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempDevice));
|
||||||
|
char* disk = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->cbtTempDevice));
|
||||||
|
disk = yon_char_divide_search(disk, " ", -1);
|
||||||
|
if (disk_id != -1) {
|
||||||
|
int index_find = -1;
|
||||||
|
for (int index = 0; index < _config->size; index++) {
|
||||||
|
char* disk_cfg = _config->disk[index];
|
||||||
|
if (strstr(disk_cfg, disk) != NULL) {
|
||||||
|
index_find = index;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (index_find != -1) {
|
||||||
|
if (flag_check_array==0) {
|
||||||
|
if (_config->i_o_limit_read[index_find]==-2 || _config->i_o_limit_read[index_find]==-1) {
|
||||||
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead), 0);
|
||||||
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempRead), 0);
|
||||||
|
gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempRead), 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempRead), _config->i_o_limit_read[index_find]);
|
||||||
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead), 1);
|
||||||
|
gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempRead), _config->i_o_limit_read_size[index_find]);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (flag_check_array==1) {
|
||||||
|
if (_config->i_o_limit_write[index_find]==-2 || _config->i_o_limit_write[index_find]==-1) {
|
||||||
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite), 0);
|
||||||
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempWrite), 0);
|
||||||
|
gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempWrite), 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempWrite), _config->i_o_limit_write[index_find]);
|
||||||
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite), 1);
|
||||||
|
gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempWrite), _config->i_o_limit_write_size[index_find]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite), 0);
|
||||||
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempWrite), 0);
|
||||||
|
gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempWrite), 0);
|
||||||
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead), 0);
|
||||||
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempRead), 0);
|
||||||
|
gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempRead), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite), 0);
|
||||||
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempWrite), 0);
|
||||||
|
gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempWrite), 0);
|
||||||
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead), 0);
|
||||||
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempRead), 0);
|
||||||
|
gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempRead), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite), 0);
|
||||||
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempWrite), 0);
|
||||||
|
gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempWrite), 0);
|
||||||
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead), 0);
|
||||||
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(widgets->spinTempRead), 0);
|
||||||
|
gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->cbtTempRead), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void philos_temp_add_disk(temp_set_window *widgets, temp_config* _config) {
|
||||||
|
char* disk = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->cbtTempDevice));
|
||||||
|
disk = yon_char_divide_search(disk, " ", -1);
|
||||||
|
int disk_id = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempDevice));
|
||||||
|
int bool_read = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead));
|
||||||
|
int bool_write = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite));
|
||||||
|
if (disk_id >= 0 && _config->size !=0) {
|
||||||
|
int index_find = -1;
|
||||||
|
for (int index = 0; index < _config->size; index++) {
|
||||||
|
char* disk_cfg = _config->disk[index];
|
||||||
|
if (strstr(disk_cfg, disk) != NULL) {
|
||||||
|
index_find = index;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (index_find == -1) {
|
||||||
|
// Добавление
|
||||||
|
_config->disk = yon_char_parsed_append(_config->disk,&_config->size, disk);
|
||||||
|
_config->size--;
|
||||||
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead))) {
|
||||||
|
_config->i_o_limit_read_size = philos_int_append(_config->i_o_limit_read_size,&_config->size,(int)gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempRead)));
|
||||||
|
_config->size--;
|
||||||
|
_config->i_o_limit_read = philos_int_append(_config->i_o_limit_read,&_config->size,gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinTempRead)));
|
||||||
|
_config->size--;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_config->i_o_limit_read_size = philos_int_append(_config->i_o_limit_read_size,&_config->size,-3);
|
||||||
|
_config->size--;
|
||||||
|
_config->i_o_limit_read = philos_int_append(_config->i_o_limit_read,&_config->size,-3);
|
||||||
|
_config->size--;
|
||||||
|
}
|
||||||
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite))) {
|
||||||
|
_config->i_o_limit_write_size = philos_int_append(_config->i_o_limit_write_size,&_config->size,(int)gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempWrite)));
|
||||||
|
_config->size--;
|
||||||
|
_config->i_o_limit_write = philos_int_append(_config->i_o_limit_write,&_config->size,gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinTempWrite)));
|
||||||
|
_config->size--;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_config->i_o_limit_write_size = philos_int_append(_config->i_o_limit_write_size,&_config->size,-3);
|
||||||
|
_config->size--;
|
||||||
|
_config->i_o_limit_write = philos_int_append(_config->i_o_limit_write,&_config->size,-3);
|
||||||
|
_config->size--;
|
||||||
|
}
|
||||||
|
_config->size++;
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Редактирование
|
||||||
|
//_config->disk[index_find] = yon_char_new(disk);
|
||||||
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead))) {
|
||||||
|
_config->i_o_limit_read_size[index_find] =(int)gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempRead));
|
||||||
|
_config->i_o_limit_read[index_find] = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinTempRead));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_config->i_o_limit_read_size[index_find] = -3;
|
||||||
|
_config->i_o_limit_read[index_find] = -3;
|
||||||
|
}
|
||||||
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite))) {
|
||||||
|
_config->i_o_limit_write_size[index_find] = (int)gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempWrite));
|
||||||
|
_config->i_o_limit_write[index_find] = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinTempWrite));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_config->i_o_limit_write_size[index_find] = -3;
|
||||||
|
_config->i_o_limit_write[index_find] = -3;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (bool_read == 1 || bool_write == 1) {
|
||||||
|
_config->disk = yon_char_parsed_append(_config->disk,&_config->size, disk);
|
||||||
|
_config->size--;
|
||||||
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempRead))) {
|
||||||
|
_config->i_o_limit_read_size = philos_int_append(_config->i_o_limit_read_size,&_config->size,(int)gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempRead)));
|
||||||
|
_config->size--;
|
||||||
|
_config->i_o_limit_read = philos_int_append(_config->i_o_limit_read,&_config->size,gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinTempRead)));
|
||||||
|
_config->size--;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_config->i_o_limit_read_size = philos_int_append(_config->i_o_limit_read_size,&_config->size,-3);
|
||||||
|
_config->size--;
|
||||||
|
_config->i_o_limit_read = philos_int_append(_config->i_o_limit_read,&_config->size,-3);
|
||||||
|
_config->size--;
|
||||||
|
}
|
||||||
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->chbTempWrite))) {
|
||||||
|
_config->i_o_limit_write_size = philos_int_append(_config->i_o_limit_write_size,&_config->size,(int)gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtTempWrite)));
|
||||||
|
_config->size--;
|
||||||
|
_config->i_o_limit_write = philos_int_append(_config->i_o_limit_write,&_config->size,gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widgets->spinTempWrite)));
|
||||||
|
_config->size--;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_config->i_o_limit_write_size = philos_int_append(_config->i_o_limit_write_size,&_config->size,-3);
|
||||||
|
_config->size--;
|
||||||
|
_config->i_o_limit_write = philos_int_append(_config->i_o_limit_write,&_config->size,-3);
|
||||||
|
_config->size--;
|
||||||
|
}
|
||||||
|
_config->size++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int* philos_int_append(int* array, int* size, int value) {
|
||||||
|
array = yon_remalloc(array, (*size+1)*sizeof(int));
|
||||||
|
array[(*size)] = value;
|
||||||
|
(*size)++;
|
||||||
|
return array;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int* remove_element_int_array(int* array, int* size, int item_to_delete) {
|
||||||
|
int *new_int_parsed=NULL;
|
||||||
|
new_int_parsed=malloc(sizeof(int)*((*size)-1));
|
||||||
|
int flag = 0;
|
||||||
|
for (int i=0;i < (*size);i++){
|
||||||
|
if (i==item_to_delete) {
|
||||||
|
flag = 1;
|
||||||
|
}
|
||||||
|
if (flag == 0) {
|
||||||
|
memcpy(&(new_int_parsed[i]),&(array[i]),sizeof(int));
|
||||||
|
}
|
||||||
|
else if (flag == 1 && i!=item_to_delete) {
|
||||||
|
memcpy(&(new_int_parsed[i-1]),&(array[i]),sizeof(int));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(*size)=(*size)-1;
|
||||||
|
return new_int_parsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
int** remove_element_int_array_n3(int** array, int* size, int item_to_delete) {
|
||||||
|
int **new_int_parsed=NULL;
|
||||||
|
new_int_parsed=malloc(sizeof(int*)*((*size)-1));
|
||||||
|
int flag = 0;
|
||||||
|
for (int i=0;i < (*size);i++){
|
||||||
|
if (i==item_to_delete) {
|
||||||
|
flag = 1;
|
||||||
|
}
|
||||||
|
if (flag == 0) {
|
||||||
|
philos_array_int_copy(&new_int_parsed[i],&array[i]);
|
||||||
|
}
|
||||||
|
else if (flag == 1 && i!=item_to_delete) {
|
||||||
|
philos_array_int_copy(&new_int_parsed[i-1],&array[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(*size)=(*size)-1;
|
||||||
|
return new_int_parsed;
|
||||||
|
}
|
||||||
|
char* philos_get_size_bite(GtkWidget* chk_button, GtkWidget* spin, GtkWidget* combo_box_text) {
|
||||||
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(chk_button))) {
|
||||||
|
char* size_prifics = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(combo_box_text));
|
||||||
|
int size_bite = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
|
||||||
|
char* str_size_bute = yon_char_unite(yon_char_from_int(size_bite), " ", size_prifics, NULL);
|
||||||
|
return str_size_bute;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
char* str = (char*)malloc(sizeof(char*)*2);
|
||||||
|
str[0] = '-';
|
||||||
|
str[1] = '\0';
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void philos_fill_combo_box_text(GtkWidget *cbt, config_str list_data, int size) {
|
||||||
|
for (int index = 0; index < size; index++) {
|
||||||
|
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(cbt), list_data[index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Mem Size pow
|
||||||
|
void philos_set_spin_adjustment(GtkWidget *check, GtkWidget *spin, GtkWidget *combo, size_t value) {
|
||||||
|
gboolean active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check));
|
||||||
|
guint value_spin = gtk_spin_button_get_digits(GTK_SPIN_BUTTON(spin));
|
||||||
|
if (active != -1) {
|
||||||
|
GtkAdjustment* adjustment = NULL;
|
||||||
|
adjustment = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(spin));
|
||||||
|
gtk_adjustment_set_lower(adjustment, 0.0);
|
||||||
|
gtk_adjustment_set_page_increment(adjustment, 1.0);
|
||||||
|
if (combo == NULL) {
|
||||||
|
gtk_adjustment_set_upper(adjustment, (gdouble)(value*100));
|
||||||
|
if ((value*100)<value_spin) {
|
||||||
|
gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spin), (value*100));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int index = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
|
||||||
|
if (index == 0) {
|
||||||
|
float pow_mem_size = get_size_pow_memory(value, index);
|
||||||
|
gtk_adjustment_set_upper(adjustment, (gdouble)value);
|
||||||
|
if (value<value_spin) {
|
||||||
|
gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spin), value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (index == -1) {}
|
||||||
|
else {
|
||||||
|
float pow_mem_size = get_size_pow_memory(value, index);
|
||||||
|
gtk_adjustment_set_upper(adjustment, (gdouble)pow_mem_size);
|
||||||
|
if (pow_mem_size<value_spin) {
|
||||||
|
gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spin), pow_mem_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void philos_set_active_widgets(GtkWidget *check, GtkWidget *spin, GtkWidget *combo, int flag_cpu, char* cmd) {
|
||||||
|
gboolean active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check));
|
||||||
|
size_t value_spin = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
|
||||||
|
gtk_widget_set_sensitive(spin, active);
|
||||||
|
gtk_widget_set_sensitive(combo, active);
|
||||||
|
size_t resurs = get_resurs_total(cmd);
|
||||||
|
if (value_spin>0) {
|
||||||
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check),1);
|
||||||
|
}
|
||||||
|
else if (active == 0) {
|
||||||
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), 0);
|
||||||
|
}
|
||||||
|
if (flag_cpu == 0) {
|
||||||
|
philos_set_spin_adjustment(check, spin, combo, resurs);
|
||||||
|
if (value_spin>resurs) {
|
||||||
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), resurs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
philos_set_spin_adjustment(check, spin, NULL, resurs);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t get_resurs_total(char* cmd) {
|
||||||
|
int size = 0;
|
||||||
|
size_t size_memory = 0;
|
||||||
|
char **responce = yon_config_load(cmd, &size);
|
||||||
|
for (int index = 0; index < size; index++ ) {
|
||||||
|
char* mem_size_kb = yon_char_divide_search(responce[index], "\n", -1);
|
||||||
|
size_memory = atoll(mem_size_kb);
|
||||||
|
free(mem_size_kb);
|
||||||
|
}
|
||||||
|
philos_free_string_array(&responce, size);
|
||||||
|
return size_memory;
|
||||||
|
}
|
||||||
|
|
||||||
|
float get_size_pow_memory(size_t size_memory, int size) {
|
||||||
|
float res = size_memory;
|
||||||
|
for (size_t index = 0; index < size; index++) {
|
||||||
|
res = res/1024;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void philos_set_active_widgets_device_io(GtkWidget* combo_to_l2,GtkWidget *check, GtkWidget *spin, GtkWidget *combo) {
|
||||||
|
int menu_id = gtk_combo_box_get_active(GTK_COMBO_BOX(combo_to_l2));
|
||||||
|
if (menu_id != -1) {
|
||||||
|
gboolean active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check));
|
||||||
|
if (active == 0) {
|
||||||
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), 0);
|
||||||
|
}
|
||||||
|
else if (gtk_spin_button_get_digits(GTK_SPIN_BUTTON(spin))>0) {
|
||||||
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check),1);
|
||||||
|
}
|
||||||
|
gtk_widget_set_sensitive(spin, active);
|
||||||
|
gtk_widget_set_sensitive(combo, active);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), 0);
|
||||||
|
gtk_widget_set_sensitive(spin, 0);
|
||||||
|
gtk_widget_set_sensitive(combo, 0);
|
||||||
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), 0);
|
||||||
|
}
|
||||||
|
philos_set_spin_adjustment(check, spin, combo, 12582912);
|
||||||
|
}
|
||||||
|
char *yon_char_get_augumented(char *source, char *append)
|
||||||
|
{
|
||||||
|
if (source && append)
|
||||||
|
{
|
||||||
|
int size = strlen(source) + strlen(append) + 1;
|
||||||
|
char *final = malloc(size);
|
||||||
|
memset(final, 0, size);
|
||||||
|
if (strstr(source, "%%"))
|
||||||
|
sprintf(final, source, append);
|
||||||
|
else
|
||||||
|
sprintf(final, "%s%s", source, append);
|
||||||
|
return final;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
dictionary *yon_dictionary_create_with_data_connected(dictionary *dict, char *key, void *data) {
|
||||||
|
dictionary *dct = yon_dictionary_create_conneced(dict);
|
||||||
|
dct->key = yon_char_new(key);
|
||||||
|
dct->data = data;
|
||||||
|
dct->data_type = DICTIONARY_OTHER_TYPE;
|
||||||
|
return dct;
|
||||||
|
}
|
||||||
|
char **yon_char_parsed_shrink(char **char_string, int *size, int item_to_delete) {
|
||||||
|
char **new_char_parsed=NULL;
|
||||||
|
new_char_parsed=malloc(sizeof(char*)*((*size)-1));
|
||||||
|
int flag = 0;
|
||||||
|
for (int i=0;i < (*size);i++){
|
||||||
|
if (i==item_to_delete) {
|
||||||
|
flag = 1;
|
||||||
|
}
|
||||||
|
if (flag == 0) {
|
||||||
|
new_char_parsed[i]=yon_char_new(char_string[i]);
|
||||||
|
}
|
||||||
|
else if (flag == 1 && i!=item_to_delete) {
|
||||||
|
new_char_parsed[i-1]=yon_char_new(char_string[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(*size)=(*size)-1;
|
||||||
|
return new_char_parsed;
|
||||||
|
}
|
||||||
|
char*** yon_char_parsed_shrink_n3(char ***char_string, int *size, int item_to_delete) {
|
||||||
|
char ***new_char_parsed=NULL;
|
||||||
|
new_char_parsed=malloc(sizeof(char**)*((*size)-1));
|
||||||
|
int flag = 0;
|
||||||
|
for (int i=0;i < (*size);i++){
|
||||||
|
if (i==item_to_delete) {
|
||||||
|
flag = 1;
|
||||||
|
}
|
||||||
|
if (flag == 0) {
|
||||||
|
yon_char_parsed_copy(&new_char_parsed[i],&char_string[i]);
|
||||||
|
}
|
||||||
|
else if (flag == 1 && i!=item_to_delete) {
|
||||||
|
yon_char_parsed_copy(&new_char_parsed[i-1], &char_string[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(*size)=(*size)-1;
|
||||||
|
return new_char_parsed;
|
||||||
|
}
|
||||||
|
dictionary *yon_dictionary_create_empty() {
|
||||||
|
dictionary *dict = malloc(sizeof(dictionary));
|
||||||
|
dict->data = NULL;
|
||||||
|
dict->key = NULL;
|
||||||
|
dict->next = NULL;
|
||||||
|
dict->prev = NULL;
|
||||||
|
dict->first = dict;
|
||||||
|
dict->data_type = DICTIONARY_OTHER_TYPE;
|
||||||
|
return dict;
|
||||||
|
}
|
||||||
|
void yon_terminal_integrated_launch(GtkWidget *terminal, char* command, void *endwork_function, void* endwork_function_argument){
|
||||||
|
char **commands=new_arr(char*,2);
|
||||||
|
gchar **envp = g_get_environ();
|
||||||
|
commands[0]=(gchar *)g_strdup(g_environ_getenv(envp, "SHELL"));
|
||||||
|
commands[1]=NULL;
|
||||||
|
char **env=new_arr(char*,2);
|
||||||
|
env[0]="";
|
||||||
|
env[1]=NULL;
|
||||||
|
vte_terminal_set_size(VTE_TERMINAL(terminal),10,15);
|
||||||
|
VtePty *pty = vte_pty_new_sync(VTE_PTY_DEFAULT,NULL,NULL);
|
||||||
|
vte_terminal_set_pty(VTE_TERMINAL(terminal),pty);
|
||||||
|
char *install_command=yon_char_unite("tput cup 0 0 && tput ed; ",command, "; exit 0\n",NULL);
|
||||||
|
if(endwork_function)
|
||||||
|
g_signal_connect(G_OBJECT(terminal), "child-exited", G_CALLBACK(endwork_function), endwork_function_argument);
|
||||||
|
vte_terminal_spawn_async(VTE_TERMINAL(terminal),
|
||||||
|
VTE_PTY_DEFAULT,
|
||||||
|
NULL,
|
||||||
|
commands,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
NULL, NULL,
|
||||||
|
NULL,
|
||||||
|
-1,
|
||||||
|
NULL,
|
||||||
|
child_ready,
|
||||||
|
install_command);
|
||||||
|
vte_pty_spawn_async(pty,
|
||||||
|
NULL,
|
||||||
|
commands,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
NULL, NULL,
|
||||||
|
NULL,
|
||||||
|
-1,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
vte_terminal_set_scrollback_lines(VTE_TERMINAL(terminal), -1);
|
||||||
|
vte_terminal_set_scroll_on_output(VTE_TERMINAL(terminal), TRUE);
|
||||||
|
vte_terminal_set_scroll_on_keystroke(VTE_TERMINAL(terminal), TRUE);
|
||||||
|
gtk_widget_show_all(terminal);
|
||||||
|
}
|
||||||
|
dictionary *yon_dictionary_create_conneced(dictionary *targetdict)
|
||||||
|
{
|
||||||
|
targetdict = yon_dictionary_get_last(targetdict);
|
||||||
|
targetdict->next = yon_dictionary_create_empty();
|
||||||
|
targetdict->next->prev = targetdict;
|
||||||
|
targetdict->next->first = targetdict->first;
|
||||||
|
targetdict->next->data_type = DICTIONARY_OTHER_TYPE;
|
||||||
|
return targetdict->next;
|
||||||
|
}
|
||||||
|
void yon_int_array_append(int **source, int append){
|
||||||
|
int size=0;
|
||||||
|
for (size=0;(*source)[size]!=-2;size++);
|
||||||
|
*source = realloc(*source,(size+2)*sizeof(int));
|
||||||
|
(*source)[size] = append;
|
||||||
|
(*source)[size+1] = -2;
|
||||||
|
}
|
||||||
|
static void child_ready(VteTerminal *terminal, GPid pid, GError *error, gpointer user_data)
|
||||||
|
{
|
||||||
|
if (!terminal) return;
|
||||||
|
if (pid == -1) printf("Error\n\n\n");
|
||||||
|
else vte_terminal_feed_child(VTE_TERMINAL(terminal),(char*)user_data,strlen((char*)user_data));
|
||||||
|
}
|
@ -0,0 +1,111 @@
|
|||||||
|
#ifndef PHILOS_UTILS_H
|
||||||
|
#define PHILOS_UTILS_H
|
||||||
|
#include "ubl-utils.h"
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <locale.h>
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#include <gtk/gtkx.h>
|
||||||
|
#include <vte/vte.h>
|
||||||
|
#include <pwd.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#define catch(x) ExitJmp:if(__HadError)
|
||||||
|
#define throw(x) {__HadError=true;goto ExitJmp;}
|
||||||
|
#define file_source_login_min_max "/etc/login.defs"
|
||||||
|
static char** array_size_pow;
|
||||||
|
typedef struct {
|
||||||
|
char** disk;
|
||||||
|
int* i_o_limit_read;
|
||||||
|
int* i_o_limit_write;
|
||||||
|
int* i_o_limit_read_size;
|
||||||
|
int* i_o_limit_write_size;
|
||||||
|
int size;
|
||||||
|
} temp_config;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
|
||||||
|
GtkWidget* Window;
|
||||||
|
GtkWidget* btnSaveTempSave;
|
||||||
|
GtkWidget* btnTempCancel;
|
||||||
|
|
||||||
|
GtkWidget* entryTempCmd;
|
||||||
|
GtkWidget* chbTempRead;
|
||||||
|
GtkWidget* spinTempRead;
|
||||||
|
GtkWidget* cbtTempRead;
|
||||||
|
|
||||||
|
GtkWidget* chbTempWrite;
|
||||||
|
GtkWidget* spinTempWrite;
|
||||||
|
GtkWidget* cbtTempWrite;
|
||||||
|
|
||||||
|
GtkWidget* chkSoftRestrictionTemp;
|
||||||
|
GtkWidget* spiSevereRestrictionTemp;
|
||||||
|
GtkWidget* cmSevereRestrictionTemp;
|
||||||
|
|
||||||
|
GtkWidget* chkSevereRestrictionTemp;
|
||||||
|
GtkWidget* spinSevereRestrictionTemp;
|
||||||
|
GtkWidget* cmbSevereRestrictionTemp;
|
||||||
|
|
||||||
|
GtkWidget* chkPaddingFLTemp;
|
||||||
|
GtkWidget* spinPaddingFLTemp;
|
||||||
|
GtkWidget* cmbPaddingFLTemp;
|
||||||
|
|
||||||
|
GtkWidget* chkCPULimitTemp;
|
||||||
|
GtkWidget* spinCPULimitTemp;
|
||||||
|
GtkWidget* lblCPULimitTemp;
|
||||||
|
|
||||||
|
GtkWidget* cbtTempDevice;
|
||||||
|
GtkWidget* cbxTempQuotaObj;
|
||||||
|
GtkWidget* cbxTempQuotaLevel2;
|
||||||
|
GtkWidget* boxBlockGui;
|
||||||
|
} temp_set_window;
|
||||||
|
void philos_array_string_remove_char(char*** array, char* str_remove, int size);
|
||||||
|
void philos_set_pow_size_memory(char* str_find, int** array_size,int index, char** array_size_pow);
|
||||||
|
void philos_set_size_memory_integer_char(char* str_find, char*** array_data, int index);
|
||||||
|
void philos_free_string_array(char ***array, int size);
|
||||||
|
void philos_free_string_array_n3(char ****array, int size);
|
||||||
|
void philos_free_int_array(int **array, int size);
|
||||||
|
void philos_free_int_array_n2(int ***array, int size);
|
||||||
|
config_str philos_list_group(int* size);
|
||||||
|
unsigned short philos_read_uid_min_max(char* filename, char* search);
|
||||||
|
config_str philos_list_user(int* size);
|
||||||
|
char* philos_str_size_pow_byte(GtkWidget *combo_box_text);
|
||||||
|
char* philos_str_remove(char *str, const char *sub);
|
||||||
|
void philos_split_size_memory(char* str_value, int* size, char* pow_memory);
|
||||||
|
char* philos_format_cfg_str_size_memory(char* str_key, int value, int pow_size_memory);
|
||||||
|
char** philos_str_split(char *parameters, int *size, char *divider);
|
||||||
|
void philos_array_str_copy(char*** source, char*** copy);
|
||||||
|
void philos_array_int_copy(int** source, int** copy);
|
||||||
|
char** philos_pars_terminal_systemd_cgls(char* CMD_GET_SLICE_SERVICE, char* str_find, int* size_array_data);
|
||||||
|
char* philos_pard_array_add_cmd(char* cmd, temp_config* _config, char* key, int* array_io, int* array_io_pow_size);
|
||||||
|
int philos_check_activ_disk(temp_set_window *widgets, temp_config* _config);
|
||||||
|
void philos_temp_generate_cmd(temp_set_window *widgets, temp_config* _config);
|
||||||
|
void philos_temp_del_disk(temp_set_window *widgets, temp_config* _config);
|
||||||
|
void philos_temp_config_init(temp_config* _config);
|
||||||
|
void philos_update_device_to_entry(temp_set_window *widgets, temp_config* _config, int flag_check_array);
|
||||||
|
void philos_temp_add_disk(temp_set_window *widgets, temp_config* _config);
|
||||||
|
int* philos_int_append(int* array, int* size, int value);
|
||||||
|
int* remove_element_int_array(int* array, int* size, int item_to_delete);
|
||||||
|
int** remove_element_int_array_n3(int** array, int* size, int item_to_delete);
|
||||||
|
char* philos_get_size_bite(GtkWidget* chk_button, GtkWidget* spin, GtkWidget* combo_box_text);
|
||||||
|
void philos_fill_combo_box_text(GtkWidget *cbt, config_str list_data, int size);
|
||||||
|
void philos_set_spin_adjustment(GtkWidget *check, GtkWidget *spin, GtkWidget *combo, size_t value);
|
||||||
|
void philos_set_active_widgets(GtkWidget *check, GtkWidget *spin, GtkWidget *combo, int flag_cpu, char* cmd);
|
||||||
|
size_t get_resurs_total(char* cmd);
|
||||||
|
float get_size_pow_memory(size_t size_memory, int size);
|
||||||
|
void philos_set_active_widgets_device_io(GtkWidget* combo_to_l2,GtkWidget *check, GtkWidget *spin, GtkWidget *combo);
|
||||||
|
char *yon_char_get_augumented(char *source, char *append);
|
||||||
|
dictionary *yon_dictionary_create_with_data_connected(dictionary *dict, char *key, void *data);
|
||||||
|
char **yon_char_parsed_shrink(char **char_string, int *size, int item_to_delete);
|
||||||
|
char*** yon_char_parsed_shrink_n3(char ***char_string, int *size, int item_to_delete);
|
||||||
|
dictionary *yon_dictionary_create_empty();
|
||||||
|
void yon_terminal_integrated_launch(GtkWidget *terminal, char* command, void *endwork_function, void* endwork_function_argument);
|
||||||
|
dictionary *yon_dictionary_create_conneced(dictionary *targetdict);
|
||||||
|
void yon_int_array_append(int **source, int append);
|
||||||
|
static void child_ready(VteTerminal *terminal, GPid pid, GError *error, gpointer user_data);
|
||||||
|
#endif
|
@ -1 +0,0 @@
|
|||||||
#cmakedefine WEBKIT_FOUND
|
|
@ -0,0 +1 @@
|
|||||||
|
#cmakedefine WEBKIT_FOUND
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue