|
|
#include "ubl-settings-resourcequota.h"
|
|
|
|
|
|
config main_config;
|
|
|
|
|
|
//signal emmit handlers - no header initialization
|
|
|
|
|
|
/**on_close_subwindow(GtkWidget *self)
|
|
|
* [EN]
|
|
|
* Closes window in which [self] is contained.
|
|
|
* [RU]
|
|
|
* Закрывает окно, в котором расположен виджет [self].
|
|
|
*/
|
|
|
void on_close_subwindow(GtkWidget *self){
|
|
|
gtk_widget_destroy(gtk_widget_get_toplevel(self));
|
|
|
}
|
|
|
|
|
|
/**yon_open_browser(GtkWidget *self, char *link)
|
|
|
* [EN]
|
|
|
* Opens browser with [link] link.
|
|
|
* [RU]
|
|
|
* Открывает браузер с [link] ссылкой.
|
|
|
*/
|
|
|
void yon_open_browser(GtkWidget *self, char *link){
|
|
|
yon_ubl_browser_window_open(link,TITLE_LABEL);
|
|
|
}
|
|
|
|
|
|
/**on_open_documentation_confirmation(GtkWidget *self, char *link)
|
|
|
* [EN]
|
|
|
* Opens confirmation window for [link] link.
|
|
|
* [RU]
|
|
|
* Открывает окно подтверждение перехода по ссылке [link].
|
|
|
*/
|
|
|
void on_open_documentation_confirmation(GtkWidget *self, char *link){
|
|
|
if (main_config.always_open_documentation==0){
|
|
|
GtkBuilder *builder = gtk_builder_new_from_resource(glade_path);
|
|
|
documentation_confirmation_window *widgets = malloc(sizeof(documentation_confirmation_window));
|
|
|
widgets->Window = yon_gtk_builder_get_widget(builder,"helpConfirmationWindow");
|
|
|
widgets->AcceptButton = yon_gtk_builder_get_widget(builder,"ReadHelpButton");
|
|
|
widgets->CloseButton = yon_gtk_builder_get_widget(builder,"CancelHelpButton");
|
|
|
widgets->HatText = yon_gtk_builder_get_widget(builder,"webHeaderNameLabel");
|
|
|
widgets->HeaderText = yon_gtk_builder_get_widget(builder,"helpHeader");
|
|
|
widgets->InfoText = yon_gtk_builder_get_widget(builder,"helpText");
|
|
|
widgets->AlwaysOpenCheck = yon_gtk_builder_get_widget(builder,"AlwaysOpenDocumentationCheckbox");
|
|
|
gtk_label_set_text(GTK_LABEL(widgets->HatText),TITLE_LABEL);
|
|
|
gtk_label_set_text(GTK_LABEL(widgets->HeaderText),HELP_TITLE_LABEL);
|
|
|
gtk_label_set_text(GTK_LABEL(widgets->InfoText),HELP_INFO_LABEL);
|
|
|
gtk_button_set_label(GTK_BUTTON(widgets->AcceptButton),OPEN_HELP_LABEL);
|
|
|
gtk_button_set_label(GTK_BUTTON(widgets->AlwaysOpenCheck),HELP_ALWAYS_OPEN_LABEL);
|
|
|
gtk_button_set_label(GTK_BUTTON(widgets->CloseButton),CANCEL_LABEL);
|
|
|
gtk_widget_show_all(widgets->Window);
|
|
|
g_signal_connect(G_OBJECT(widgets->CloseButton),"clicked",G_CALLBACK(on_close_subwindow),NULL);
|
|
|
g_signal_connect(G_OBJECT(widgets->AcceptButton),"clicked",G_CALLBACK(yon_open_browser),yon_char_new(link));
|
|
|
g_signal_connect(G_OBJECT(widgets->AcceptButton),"clicked",G_CALLBACK(on_close_subwindow),NULL);
|
|
|
|
|
|
|
|
|
} else {
|
|
|
yon_open_browser(self,link);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**on_link(GtkWidget *self, char* uri, gpointer user_data)
|
|
|
* [EN]
|
|
|
* Signal for hadnling AboutDialog links.
|
|
|
* Connect to "activate-link" signal.
|
|
|
* [self] is AboutDialog window;
|
|
|
* [uri] is activated link;
|
|
|
* [user_data] is pointer for user data, hasn't used in standard handler;
|
|
|
* [RU]
|
|
|
* Функция для обработки сигнала нажатия на ссылку окна AboutDialog.
|
|
|
* Присоединять к сигналу "activate-link".
|
|
|
* [self] - окно AboutDialog;
|
|
|
* [uri] - ссылка, по которой совершается переход;
|
|
|
* [user_data] - указатель на любые другие данные, не используется в стандартном обработчике;
|
|
|
*/
|
|
|
void on_link(GtkWidget *self, char* uri, gpointer user_data){
|
|
|
gtk_widget_destroy(self);
|
|
|
on_open_documentation_confirmation(self,uri);
|
|
|
}
|
|
|
|
|
|
/**on_about()
|
|
|
* [EN]
|
|
|
* Function for setting up and showing AboutDialog.
|
|
|
* Connect it to "activate" signal of Documentation MenuItem.
|
|
|
* [RU]
|
|
|
* Функиця для настройки и показа окна AboutDialog.
|
|
|
* Присоединять к сигналу "activate" кнопки справки типа MenuItem.
|
|
|
*/
|
|
|
void on_about(){
|
|
|
GtkBuilder *builder=gtk_builder_new_from_resource(glade_path);
|
|
|
GtkWidget *window=yon_gtk_builder_get_widget(builder,"AboutWindow");
|
|
|
GtkWidget *title=yon_gtk_builder_get_widget(builder,"headerAboutTopic");
|
|
|
GtkWidget *hideButtonBox=yon_gtk_builder_get_widget(builder,"buttonBoxHide");
|
|
|
gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(window),version_application);
|
|
|
gtk_about_dialog_set_website_label(GTK_ABOUT_DIALOG(window),PROJECT_HOME_LABEL);
|
|
|
gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(window),TITLE_LABEL);
|
|
|
gtk_label_set_text(GTK_LABEL(title),TITLE_LABEL);
|
|
|
g_signal_connect(G_OBJECT(window),"activate-link",G_CALLBACK(on_link),NULL);
|
|
|
gtk_widget_set_visible(hideButtonBox,0);
|
|
|
gtk_widget_destroy(hideButtonBox);
|
|
|
gtk_widget_show(window);
|
|
|
}
|
|
|
|
|
|
//functions
|
|
|
|
|
|
char *get_size_mod(GtkComboBox *combo){
|
|
|
char *size_modifier = NULL;
|
|
|
switch (gtk_combo_box_get_active(combo)){
|
|
|
case 0: size_modifier = "K";
|
|
|
break;
|
|
|
case 1: size_modifier = "M";
|
|
|
break;
|
|
|
case 2: size_modifier = "G";
|
|
|
break;
|
|
|
case 3: size_modifier = "T";
|
|
|
break;
|
|
|
}
|
|
|
return size_modifier;
|
|
|
}
|
|
|
|
|
|
void on_device_limits_update(GtkWidget *self, quota_window *window){
|
|
|
if (window->devices->data){
|
|
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->DeviceLimitReadCheck)))
|
|
|
yon_dictionary_get_data(window->devices,device_limits*)->read=yon_char_append(yon_char_from_long(gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->DeviceLimitReadSpin))),get_size_mod(GTK_COMBO_BOX(window->DeviceLimitReadCombo)));
|
|
|
else yon_dictionary_get_data(window->devices,device_limits*)->read = NULL;
|
|
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->DeviceLimitWriteCheck)))
|
|
|
yon_dictionary_get_data(window->devices,device_limits*)->write=yon_char_append(yon_char_from_long(gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->DeviceLimitWriteSpin))),get_size_mod(GTK_COMBO_BOX(window->DeviceLimitWriteCombo)));
|
|
|
else yon_dictionary_get_data(window->devices,device_limits*)->write = NULL;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void on_quota_configuration_update(GtkWidget *self, quota_window *window){
|
|
|
char *output_line = NULL;
|
|
|
char *size_modifier=NULL;
|
|
|
on_device_limits_update(self,window);
|
|
|
char *soft_limit = yon_char_unite("MemoryHigh=",yon_char_from_long((long)gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->SoftRestrictionSpin))),get_size_mod(GTK_COMBO_BOX(window->SoftRestrictionCombo)),NULL);
|
|
|
char *hard_limit = yon_char_unite("MemoryMax=",yon_char_from_long((long)gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->HardRestrictionSpin))),get_size_mod(GTK_COMBO_BOX(window->HardRestrictionCombo)),NULL);
|
|
|
char *paging_limit = yon_char_unite("MemorySwapMax=",yon_char_from_long((long)gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->PagingLimitSpin))),get_size_mod(GTK_COMBO_BOX(window->PagingLimitCombo)),NULL);
|
|
|
char *cpu_limit = yon_char_unite("CPUQuota=",yon_char_from_long((long)gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->CpuLimitSpin))),"%",NULL);
|
|
|
|
|
|
char *read_limit = "";
|
|
|
char *read_devices = "";
|
|
|
dictionary *dict;
|
|
|
for_dictionaries(dict,window->devices){
|
|
|
if (dict->data&&yon_dictionary_get_data(dict,device_limits*)->read)
|
|
|
read_devices = yon_char_unite(read_devices,"IOReadBandwidthMax=",yon_char_divide_search(yon_char_new(dict->key)," ",-1)," ",yon_dictionary_get_data(dict,device_limits*)->read,",",NULL);
|
|
|
}
|
|
|
if (read_devices[strlen(read_devices)-1]==',') read_devices[strlen(read_devices)-1]='\0';
|
|
|
read_limit = yon_char_unite(read_limit,read_devices,NULL);
|
|
|
|
|
|
|
|
|
char *write_limit = "";
|
|
|
char *write_devices = "";
|
|
|
for_dictionaries(dict,window->devices){
|
|
|
if (dict->data&&yon_dictionary_get_data(dict,device_limits*)->write)
|
|
|
write_devices = yon_char_unite(write_devices,"IOWriteBandwidthMax=",yon_char_divide_search(yon_char_new(dict->key)," ",-1)," ",yon_dictionary_get_data(dict,device_limits*)->write,",",NULL);
|
|
|
}
|
|
|
if (write_devices[strlen(write_devices)-1]==',') write_devices[strlen(write_devices)-1]='\0';
|
|
|
write_limit = yon_char_unite(write_limit,write_devices,NULL);
|
|
|
|
|
|
output_line = yon_char_unite(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->SoftRestrictionCheck))? yon_char_append(soft_limit,","): "",
|
|
|
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->HardRestrictionCheck))? yon_char_append(hard_limit,","):"",
|
|
|
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->PagingLimitCheck))? yon_char_append(paging_limit,","):"",
|
|
|
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->CpuLimitCheck))? yon_char_append(cpu_limit,","):"",
|
|
|
(read_devices && strcmp(read_devices,"")!=0 ) ? yon_char_append(read_limit,","):"",
|
|
|
(write_devices && strcmp(write_devices,"")!=0 ) ? yon_char_append(write_limit,","):"",NULL);
|
|
|
if (output_line&&strcmp(output_line,"")!=0&&output_line[strlen(output_line)-1] == ',') output_line[strlen(output_line)-1] = '\0';
|
|
|
gtk_entry_set_text(GTK_ENTRY(window->ManualInputEntry),output_line);
|
|
|
}
|
|
|
|
|
|
void on_limit_manual_input(GtkWidget *self, double *new_value, quota_window *window){
|
|
|
on_quota_configuration_update(self, window);
|
|
|
}
|
|
|
|
|
|
void on_check_maximum(GtkWidget *self, GtkWidget *pair){
|
|
|
if (GTK_IS_SPIN_BUTTON(self)){
|
|
|
if (GTK_IS_COMBO_BOX(pair)){
|
|
|
int required_size = gtk_combo_box_get_active(GTK_COMBO_BOX(pair));
|
|
|
if (main_config.avaliable_ram==0){
|
|
|
struct sysinfo inf;
|
|
|
sysinfo(&inf);
|
|
|
main_config.avaliable_ram=inf.totalram;
|
|
|
main_config.avaliable_swap=inf.totalswap;
|
|
|
}
|
|
|
double cur_ram = main_config.avaliable_ram;
|
|
|
double cur_value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(self));
|
|
|
for (int i=0;i<required_size;i++)
|
|
|
cur_ram=cur_ram/1024;
|
|
|
GtkAdjustment *adj = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(self));
|
|
|
gtk_adjustment_set_upper(adj,cur_ram);
|
|
|
if (cur_value>cur_ram)
|
|
|
gtk_adjustment_set_value(adj,cur_ram);
|
|
|
}
|
|
|
} else if (GTK_IS_SPIN_BUTTON(pair)){
|
|
|
if (GTK_IS_COMBO_BOX(self)){
|
|
|
int required_size = gtk_combo_box_get_active(GTK_COMBO_BOX(self));
|
|
|
if (main_config.avaliable_ram==0){
|
|
|
struct sysinfo inf;
|
|
|
sysinfo(&inf);
|
|
|
main_config.avaliable_ram=inf.totalram;
|
|
|
main_config.avaliable_swap=inf.totalswap;
|
|
|
}
|
|
|
double cur_ram = main_config.avaliable_ram;
|
|
|
double cur_value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(pair));
|
|
|
for (int i=0;i<required_size+1;i++)
|
|
|
cur_ram=cur_ram/1024;
|
|
|
GtkAdjustment *adj = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(pair));
|
|
|
gtk_adjustment_set_upper(adj,(long)cur_ram);
|
|
|
if (cur_value>cur_ram)
|
|
|
gtk_adjustment_set_value(adj,cur_ram);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void on_check_maximum_cpu(GtkWidget *self, GtkWidget *pair){
|
|
|
if (GTK_IS_SPIN_BUTTON(self)){
|
|
|
if (GTK_IS_COMBO_BOX(pair)){
|
|
|
int required_size = gtk_combo_box_get_active(GTK_COMBO_BOX(pair));
|
|
|
if (main_config.avaliable_ram==0){
|
|
|
struct sysinfo inf;
|
|
|
sysinfo(&inf);
|
|
|
main_config.avaliable_swap=inf.totalswap;
|
|
|
}
|
|
|
double cur_ram = main_config.avaliable_swap;
|
|
|
double cur_value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(self));
|
|
|
for (int i=0;i<required_size;i++)
|
|
|
cur_ram=cur_ram/1024;
|
|
|
GtkAdjustment *adj = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(self));
|
|
|
gtk_adjustment_set_upper(adj,cur_ram);
|
|
|
if (cur_value>cur_ram)
|
|
|
gtk_adjustment_set_value(adj,cur_ram);
|
|
|
}
|
|
|
} else if (GTK_IS_SPIN_BUTTON(pair)){
|
|
|
if (GTK_IS_COMBO_BOX(self)){
|
|
|
int required_size = gtk_combo_box_get_active(GTK_COMBO_BOX(self));
|
|
|
if (main_config.avaliable_swap==0){
|
|
|
struct sysinfo inf;
|
|
|
sysinfo(&inf);
|
|
|
main_config.avaliable_swap=inf.totalswap;
|
|
|
}
|
|
|
double cur_ram = main_config.avaliable_swap;
|
|
|
double cur_value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(pair));
|
|
|
for (int i=0;i<required_size+1;i++)
|
|
|
cur_ram=cur_ram/1024;
|
|
|
GtkAdjustment *adj = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(pair));
|
|
|
gtk_adjustment_set_upper(adj,(long)cur_ram);
|
|
|
if (cur_value>cur_ram)
|
|
|
gtk_adjustment_set_value(adj,cur_ram);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void on_quota_target_type_changed(GtkWidget *self, quota_window *window){
|
|
|
int active = gtk_combo_box_get_active(GTK_COMBO_BOX(self));
|
|
|
if (active == 0) {
|
|
|
gtk_combo_box_text_remove_all(GTK_COMBO_BOX_TEXT(window->TargetCombo));
|
|
|
for (int i=0; i<main_config.users_size;i++){
|
|
|
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(window->TargetCombo),main_config.users[i]);
|
|
|
}
|
|
|
}
|
|
|
if (active == 1) {
|
|
|
gtk_combo_box_text_remove_all(GTK_COMBO_BOX_TEXT(window->TargetCombo));
|
|
|
for (int i=0; i<main_config.processes_size;i++){
|
|
|
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(window->TargetCombo),main_config.processes[i]);
|
|
|
}
|
|
|
}
|
|
|
if (active == 2) {
|
|
|
gtk_combo_box_text_remove_all(GTK_COMBO_BOX_TEXT(window->TargetCombo));
|
|
|
for (int i=0; i<main_config.slices_size;i++){
|
|
|
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(window->TargetCombo),main_config.slices[i]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void on_target_check_chosen(GtkWidget *self, quota_window *window){
|
|
|
if (gtk_combo_box_get_active(GTK_COMBO_BOX(self))!=-1)
|
|
|
gtk_widget_set_sensitive(window->BlockUiBox,1);
|
|
|
else
|
|
|
gtk_widget_set_sensitive(window->BlockUiBox,0);
|
|
|
}
|
|
|
|
|
|
void yon_get_devices(quota_window *window){
|
|
|
int size=0;
|
|
|
config_str devices_parsed = yon_config_load(get_devices_command,&size);
|
|
|
yon_char_parsed_remove_newline_symbols(devices_parsed,&size);
|
|
|
for (int i=0; i<size;i++){
|
|
|
yon_dictionary_add_or_create_if_exists_with_data(window->devices,devices_parsed[i],NULL);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void on_device_current_changed(GtkWidget *self, quota_window *window){
|
|
|
char *chosen = (char*)gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(window->DeviceLimitCombo));
|
|
|
if (!window->devices->data){
|
|
|
printf("%s\n",gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(window->DeviceLimitCombo)));
|
|
|
yon_dictionary_get(&window->devices,chosen);
|
|
|
if (!window->devices->data)
|
|
|
window->devices->data = g_malloc0(sizeof(device_limits));
|
|
|
((device_limits*)window->devices->data)->write=NULL;
|
|
|
((device_limits*)window->devices->data)->read=NULL;
|
|
|
} else {
|
|
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->DeviceLimitReadCheck)))
|
|
|
yon_dictionary_get_data(window->devices,device_limits*)->read=yon_char_append(yon_char_from_long(gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->DeviceLimitReadSpin))),get_size_mod(GTK_COMBO_BOX(window->DeviceLimitReadCombo)));
|
|
|
else yon_dictionary_get_data(window->devices,device_limits*)->read = NULL;
|
|
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->DeviceLimitWriteCheck)))
|
|
|
yon_dictionary_get_data(window->devices,device_limits*)->write=yon_char_append(yon_char_from_long(gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->DeviceLimitWriteSpin))),get_size_mod(GTK_COMBO_BOX(window->DeviceLimitWriteCombo)));
|
|
|
else yon_dictionary_get_data(window->devices,device_limits*)->write = NULL;
|
|
|
yon_dictionary_get(&window->devices,chosen);
|
|
|
if (!window->devices->data)
|
|
|
window->devices->data = g_malloc0(sizeof(device_limits));
|
|
|
((device_limits*)window->devices->data)->write=NULL;
|
|
|
((device_limits*)window->devices->data)->read=NULL;
|
|
|
char *read = yon_dictionary_get_data(window->devices,device_limits*)->read;
|
|
|
char *write = yon_dictionary_get_data(window->devices,device_limits*)->write;
|
|
|
if (read) {
|
|
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->DeviceLimitReadSpin),atoi(read));
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->DeviceLimitReadCheck),1);
|
|
|
switch (read[strlen(read)-1]){
|
|
|
case 'K': gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitReadCombo),0);
|
|
|
break;
|
|
|
case 'M': gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitReadCombo),1);
|
|
|
break;
|
|
|
case 'G': gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitReadCombo),2);
|
|
|
break;
|
|
|
case 'T': gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitReadCombo),3);
|
|
|
break;
|
|
|
}
|
|
|
} else {
|
|
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->DeviceLimitReadSpin),0);
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->DeviceLimitReadCheck),0);
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitReadCombo),0);
|
|
|
}
|
|
|
if (write) {
|
|
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->DeviceLimitWriteSpin),atoi(write));
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->DeviceLimitWriteCheck),1);
|
|
|
switch (write[strlen(write)-1]){
|
|
|
case 'K': gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitWriteCombo),0);
|
|
|
break;
|
|
|
case 'M': gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitWriteCombo),1);
|
|
|
break;
|
|
|
case 'G': gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitWriteCombo),2);
|
|
|
break;
|
|
|
case 'T': gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitWriteCombo),3);
|
|
|
break;
|
|
|
}
|
|
|
} else {
|
|
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->DeviceLimitWriteSpin),0);
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->DeviceLimitWriteCheck),0);
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitWriteCombo),0);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void on_quotas_save(GtkWidget *self, dictionary *windows){
|
|
|
quota_window *window = yon_dictionary_get_data(windows->first,quota_window*);
|
|
|
main_window *widgets = yon_dictionary_get_data(windows->first->next,main_window*);
|
|
|
GtkTreeIter iter;
|
|
|
const char *string = gtk_entry_get_text(GTK_ENTRY(window->ManualInputEntry));
|
|
|
const char *type = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(window->TargetTypeCombo));
|
|
|
const char *target = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(window->TargetCombo));
|
|
|
char *soft = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->SoftRestrictionCheck)) ? yon_char_append(yon_char_from_long(gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->SoftRestrictionSpin))),get_size_mod(GTK_COMBO_BOX(window->SoftRestrictionCombo))) : NULL;
|
|
|
char *hard = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->HardRestrictionCheck)) ? yon_char_append(yon_char_from_long(gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->HardRestrictionSpin))),get_size_mod(GTK_COMBO_BOX(window->HardRestrictionCombo))) : NULL;
|
|
|
char *paging = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->PagingLimitCheck)) ? yon_char_append(yon_char_from_long(gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->PagingLimitSpin))),get_size_mod(GTK_COMBO_BOX(window->PagingLimitCombo))) : NULL;
|
|
|
char *cpu = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->CpuLimitCheck)) ? yon_char_from_long(gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->CpuLimitSpin))) : NULL;
|
|
|
char *read_limit = "";
|
|
|
char *read_devices = "";
|
|
|
dictionary *dict;
|
|
|
for_dictionaries(dict,window->devices){
|
|
|
if (dict->data&&yon_dictionary_get_data(dict,device_limits*)->read)
|
|
|
read_devices = yon_char_unite(read_devices,"",yon_char_divide_search(yon_char_new(dict->key)," ",-1)," ",yon_dictionary_get_data(dict,device_limits*)->read,"\n",NULL);
|
|
|
}
|
|
|
if (read_devices[strlen(read_devices)-1]=='\n') read_devices[strlen(read_devices)-1]='\0';
|
|
|
read_limit = yon_char_unite(read_limit,read_devices,NULL);
|
|
|
|
|
|
|
|
|
char *write_limit = "";
|
|
|
char *write_devices = "";
|
|
|
for_dictionaries(dict,window->devices){
|
|
|
if (dict->data&&yon_dictionary_get_data(dict,device_limits*)->write)
|
|
|
write_devices = yon_char_unite(write_devices,"",yon_char_divide_search(yon_char_new(dict->key)," ",-1)," ",yon_dictionary_get_data(dict,device_limits*)->write,"\n",NULL);
|
|
|
}
|
|
|
if (write_devices[strlen(write_devices)-1]=='\n') write_devices[strlen(write_devices)-1]='\0';
|
|
|
write_limit = yon_char_unite(write_limit,write_devices,NULL);
|
|
|
gtk_list_store_append(main_config.list,&iter);
|
|
|
gtk_list_store_set(main_config.list,&iter,0,type,1,target,2,soft,3,hard,4,paging,5,cpu,6,read_limit,7,write_limit,8,string,-1);
|
|
|
yon_config_register(CGROUP_QUOTA((char*)target),yon_char_new((char*)string));
|
|
|
on_close_subwindow(self);
|
|
|
yon_ubl_status_box_render(SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
|
}
|
|
|
|
|
|
int yon_get_size_request_from_letter(char size){
|
|
|
switch (size){
|
|
|
case 'K': return 0;
|
|
|
break;
|
|
|
case 'M': return 1;
|
|
|
break;
|
|
|
case 'G': return 2;
|
|
|
break;
|
|
|
case 'T': return 0;
|
|
|
break;
|
|
|
default: return -1;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void yon_load_proceed(char *command){
|
|
|
gtk_list_store_clear(main_config.list);
|
|
|
if (yon_config_load_register(command)){
|
|
|
config_str rtn = yon_config_get_all();
|
|
|
char *quota = NULL;
|
|
|
for (int i=0;rtn[i];i++){
|
|
|
quota=yon_char_new(rtn[i]);
|
|
|
char *name = yon_char_divide_search(quota,"=",-1);
|
|
|
if (quota[0]=='\"') yon_char_divide(quota,0);
|
|
|
if (quota[strlen(quota)-1]=='\"') quota[strlen(quota)-1]='\0';
|
|
|
yon_char_divide_search(name,"[",-1);
|
|
|
name = yon_char_divide_search(name,"]",-1);
|
|
|
name = yon_char_divide_search(name,"=",-1);
|
|
|
char *type = NULL;
|
|
|
if (strstr(name,".service")) type=STR_PROCESS;
|
|
|
else if (strstr(name,".slice")) type=STR_SLICE;
|
|
|
else type=STR_USER;
|
|
|
int size=0;
|
|
|
char *high = NULL;
|
|
|
char *max = NULL;
|
|
|
char *swap = NULL;
|
|
|
char *cpu = NULL;
|
|
|
char *read = "";
|
|
|
char *write = "";
|
|
|
config_str single_quota = yon_char_parse(quota,&size,",");
|
|
|
if (!single_quota) {single_quota = g_malloc0(sizeof(char*));single_quota[0]=quota;}
|
|
|
for (int j = 0; j < (size==0 ? 1 : size); j++){
|
|
|
if (strstr(single_quota[j],"MemoryHigh")){
|
|
|
high=yon_char_new(single_quota[j]);
|
|
|
yon_char_divide_search(high,"=",-1);
|
|
|
}
|
|
|
if (strstr(single_quota[j],"MemoryMax")){
|
|
|
max=yon_char_new(single_quota[j]);
|
|
|
yon_char_divide_search(max,"=",-1);
|
|
|
}
|
|
|
if (strstr(single_quota[j],"MemorySwapMax")){
|
|
|
swap=yon_char_new(single_quota[j]);
|
|
|
yon_char_divide_search(swap,"=",-1);
|
|
|
}
|
|
|
if (strstr(single_quota[j],"CPUQuota")){
|
|
|
cpu=yon_char_new(single_quota[j]);
|
|
|
yon_char_divide_search(cpu,"=",-1);
|
|
|
}
|
|
|
if (strstr(single_quota[j],"IOReadBandwidthMax")){
|
|
|
char *qta = yon_char_new(single_quota[j]);
|
|
|
yon_char_divide_search(qta,"=",-1);
|
|
|
read=yon_char_unite(strcmp(read,"")!=0 ? yon_char_append(read,"\n"):read,qta,NULL);
|
|
|
free(qta);
|
|
|
}
|
|
|
if (strstr(single_quota[j],"IOWriteBandwidthMax")){
|
|
|
char *qta = yon_char_new(single_quota[j]);
|
|
|
yon_char_divide_search(qta,"=",-1);
|
|
|
write=yon_char_unite(strcmp(write,"")!=0 ? yon_char_append(write,"\n"):write,qta,NULL);
|
|
|
free(qta);
|
|
|
}
|
|
|
}
|
|
|
GtkTreeIter iter;
|
|
|
gtk_list_store_append(main_config.list,&iter);
|
|
|
gtk_list_store_set(main_config.list,&iter,0,type,1,name,2,high,3,max,4,swap,5,cpu,6,read,7,write,8,quota,-1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
void on_config_load_global(){
|
|
|
yon_load_proceed(load_global_command);
|
|
|
yon_ubl_status_box_render(GLOBAL_LOAD_SUCCESS,BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
|
}
|
|
|
|
|
|
void on_config_load_local(){
|
|
|
yon_load_proceed(load_local_command);
|
|
|
yon_ubl_status_box_render(LOCAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
|
|
|
|
}
|
|
|
|
|
|
void yon_save_proceed(char *path, char *section){
|
|
|
yon_config_save_registered(path,section);
|
|
|
|
|
|
}
|
|
|
|
|
|
void on_config_save(){
|
|
|
yon_save_proceed(NULL,"security");
|
|
|
yon_ubl_status_box_render(GLOBAL_LOCAL_SAVE_SUCCESS,BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
|
}
|
|
|
|
|
|
void on_config_save_global(){
|
|
|
yon_save_proceed("global","security");
|
|
|
yon_ubl_status_box_render(GLOBAL_SAVE_SUCCESS,BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
|
|
|
|
}
|
|
|
|
|
|
void on_config_save_local(){
|
|
|
yon_save_proceed("system","security");
|
|
|
yon_ubl_status_box_render(LOCAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
|
|
|
|
}
|
|
|
|
|
|
void on_apply_filters(GtkWidget *self, dictionary *dict){
|
|
|
GList *columns = yon_dictionary_get_data(dict->first,GList*);
|
|
|
GList *checks = yon_dictionary_get_data(dict->first->next,GList*);
|
|
|
if (g_list_length(columns)==g_list_length(checks)){
|
|
|
for (int i=0;i<g_list_length(columns);i++){
|
|
|
if (gtk_toggle_button_get_active((GtkToggleButton*)g_list_nth_data(checks,i)))
|
|
|
gtk_tree_view_column_set_visible((GtkTreeViewColumn*)g_list_nth_data(columns,i),1);
|
|
|
else {
|
|
|
gtk_tree_view_column_set_visible((GtkTreeViewColumn*)g_list_nth_data(columns,i),0);
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
printf("Error! Unequal quantity of filters and tree columns!");
|
|
|
}
|
|
|
on_close_subwindow(self);
|
|
|
}
|
|
|
|
|
|
// void on_quota_manual_input(GtkWidget *self, quota_window *window){
|
|
|
// // g_signal_handlers_block_by_func(G_OBJECT(window));
|
|
|
// int size=0;
|
|
|
// char *string = yon_char_new((char*)gtk_entry_get_text(GTK_ENTRY(self)));
|
|
|
// config_str rtn = yon_char_parse(string,&size,",");
|
|
|
// if (rtn){
|
|
|
// for (int i=0; i<size; i++){
|
|
|
// char *value = yon_char_new(rtn[i]);
|
|
|
// yon_char_divide_search(value,"=",-1);
|
|
|
// int size = yon_get_size_request_from_letter(value[strlen(value)-1]);
|
|
|
// if (size!=-1||strstr(rtn[i],"CPUQuota=")){
|
|
|
// // value[strlen(value)-1]='\0';
|
|
|
// if (strstr(rtn[i],"MemoryHigh=")){
|
|
|
// gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->SoftRestrictionCheck),1);
|
|
|
// gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->SoftRestrictionSpin),strtol(value,NULL,10));
|
|
|
// gtk_combo_box_set_active(GTK_COMBO_BOX(window->SoftRestrictionCombo),size);
|
|
|
// } else if (strstr(rtn[i],"MemoryMax=")){
|
|
|
// gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->HardRestrictionCheck),1);
|
|
|
// gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->HardRestrictionSpin),strtol(value,NULL,10));
|
|
|
// gtk_combo_box_set_active(GTK_COMBO_BOX(window->HardRestrictionCombo),size);
|
|
|
|
|
|
// } else if (strstr(rtn[i],"MemorySwapMax=")){
|
|
|
// gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->PagingLimitCheck),1);
|
|
|
// gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->PagingLimitSpin),strtol(value,NULL,10));
|
|
|
// gtk_combo_box_set_active(GTK_COMBO_BOX(window->PagingLimitCombo),size);
|
|
|
|
|
|
// } else if (strstr(rtn[i],"CPUQuota=")){
|
|
|
// gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->CpuLimitCheck),1);
|
|
|
// gtk_spin_button_set_value(GTK_SPIN_BUTTON(window-> CpuLimitSpin),strtol(value,NULL,10));
|
|
|
|
|
|
// } else if (strstr(rtn[i],"IOReadBandwidthMax=")){
|
|
|
// char *name = yon_char_divide_search(value, " ",-1);
|
|
|
// dictionary *dict;
|
|
|
// for_dictionaries(dict,window->devices){
|
|
|
// if (strstr(dict->key,name)){
|
|
|
// if (!((device_limits*)dict->data)){
|
|
|
// dict->data = g_malloc0(sizeof(device_limits));
|
|
|
// ((device_limits*)dict->data)->write=NULL;
|
|
|
// ((device_limits*)dict->data)->read=NULL;
|
|
|
// }
|
|
|
// ((device_limits*)dict->data)->read = value;
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
// } else if (strstr(rtn[i],"IOWriteBandwidthMax=")){
|
|
|
// char *name = yon_char_divide_search(value, " ",-1);
|
|
|
// dictionary *dict;
|
|
|
// for_dictionaries(dict,window->devices){
|
|
|
// if (strstr(dict->key,name)){
|
|
|
// if (!((device_limits*)dict->data)){
|
|
|
// dict->data = g_malloc0(sizeof(device_limits));
|
|
|
// ((device_limits*)dict->data)->write=NULL;
|
|
|
// ((device_limits*)dict->data)->read=NULL;
|
|
|
// }
|
|
|
// ((device_limits*)dict->data)->write = value;
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
// } else return;
|
|
|
// }
|
|
|
// free(value);
|
|
|
// }
|
|
|
// } else {
|
|
|
// char *value = yon_char_new(string);
|
|
|
// yon_char_divide_search(value,"=",-1);
|
|
|
// int size = yon_get_size_request_from_letter(value[strlen(value)-1]);
|
|
|
// if (size!=-1||strstr(string,"CPUQuota=")){
|
|
|
// // value[strlen(value)-1]='\0';
|
|
|
// if (strstr(string,"MemoryHigh=")){
|
|
|
// gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->SoftRestrictionCheck),1);
|
|
|
// gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->SoftRestrictionSpin),strtol(value,NULL,10));
|
|
|
// gtk_combo_box_set_active(GTK_COMBO_BOX(window->SoftRestrictionCombo),size);
|
|
|
// } else if (strstr(string,"MemoryMax=")){
|
|
|
// gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->HardRestrictionCheck),1);
|
|
|
// gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->HardRestrictionSpin),strtol(value,NULL,10));
|
|
|
// gtk_combo_box_set_active(GTK_COMBO_BOX(window->HardRestrictionCombo),size);
|
|
|
|
|
|
// } else if (strstr(string,"MemorySwapMax=")){
|
|
|
// gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->PagingLimitCheck),1);
|
|
|
// gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->PagingLimitSpin),strtol(value,NULL,10));
|
|
|
// gtk_combo_box_set_active(GTK_COMBO_BOX(window->PagingLimitCombo),size);
|
|
|
|
|
|
// } else if (strstr(string,"CPUQuota=")){
|
|
|
// gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->CpuLimitCheck),1);
|
|
|
// gtk_spin_button_set_value(GTK_SPIN_BUTTON(window-> CpuLimitSpin),strtol(value,NULL,10));
|
|
|
|
|
|
// } else if (strstr(string,"IOReadBandwidthMax=")){
|
|
|
// char *name = yon_char_divide_search(value, " ",-1);
|
|
|
// dictionary *dict;
|
|
|
// for_dictionaries(dict,window->devices){
|
|
|
// if (strstr(dict->key,name)){
|
|
|
// if (!((device_limits*)dict->data)){
|
|
|
// dict->data = g_malloc0(sizeof(device_limits));
|
|
|
// ((device_limits*)dict->data)->write=NULL;
|
|
|
// ((device_limits*)dict->data)->read=NULL;
|
|
|
// }
|
|
|
// ((device_limits*)dict->data)->read = value;
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
// } else if (strstr(string,"IOWriteBandwidthMax=")){
|
|
|
// char *name = yon_char_divide_search(value, " ",-1);
|
|
|
// dictionary *dict;
|
|
|
// for_dictionaries(dict,window->devices){
|
|
|
// if (strstr(dict->key,name)){
|
|
|
// if (!((device_limits*)dict->data)){
|
|
|
// dict->data = g_malloc0(sizeof(device_limits));
|
|
|
// ((device_limits*)dict->data)->write=NULL;
|
|
|
// ((device_limits*)dict->data)->read=NULL;
|
|
|
// }
|
|
|
// ((device_limits*)dict->data)->write = value;
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
// } else return;
|
|
|
// }
|
|
|
// }
|
|
|
// g_signal_handlers_block_by_func(G_OBJECT(window->DeviceLimitCombo),G_CALLBACK(on_device_current_changed),window);
|
|
|
// gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitCombo),0);
|
|
|
// g_signal_handlers_unblock_by_func(G_OBJECT(window->DeviceLimitCombo),G_CALLBACK(on_device_current_changed),window);
|
|
|
// if (window->devices->data){
|
|
|
// if (((device_limits*)window->devices->data)->read&&strcmp(((device_limits*)window->devices->data)->read,"")!=0){
|
|
|
// char *rd = ((device_limits*)window->devices->data)->read;
|
|
|
// g_signal_handlers_block_by_func(G_OBJECT(window->DeviceLimitReadCheck),G_CALLBACK(on_quota_configuration_update),window);
|
|
|
// gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->DeviceLimitReadCheck),1);
|
|
|
// g_signal_handlers_unblock_by_func(G_OBJECT(window->DeviceLimitReadCheck),G_CALLBACK(on_quota_configuration_update),window);
|
|
|
// gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitReadCombo),yon_get_size_request_from_letter(rd[strlen(rd)-1]));
|
|
|
// rd[strlen(rd)-1]='\0';
|
|
|
// gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->DeviceLimitReadSpin),strtol(((device_limits*)window->devices->data)->read,NULL,10));
|
|
|
// }
|
|
|
// else ((device_limits*)window->devices->data)->read=NULL;
|
|
|
// if (((device_limits*)window->devices->data)->write&&strcmp(((device_limits*)window->devices->data)->write,"")!=0){
|
|
|
// gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->DeviceLimitWriteCheck),1);
|
|
|
// gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitWriteCombo),yon_get_size_request_from_letter(((device_limits*)window->devices->data)->write[strlen(((device_limits*)window->devices->data)->write)-1]));
|
|
|
// ((device_limits*)window->devices->data)->write[strlen(((device_limits*)window->devices->data)->write)-1]='\0';
|
|
|
// gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->DeviceLimitWriteSpin),strtol(((device_limits*)window->devices->data)->write,NULL,10));
|
|
|
// } else ((device_limits*)window->devices->data)->write=NULL;
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
// void on_quota_manual_input_focus (GtkWidget *self, GdkEventFocus *event, quota_window *window){
|
|
|
// on_quota_manual_input(self,window);
|
|
|
// }
|
|
|
|
|
|
void on_filters_opened(GtkWidget *self, main_window *widgets) {
|
|
|
GtkBuilder *builder = gtk_builder_new_from_resource(glade_filters_path);
|
|
|
filters_window *window = g_malloc0(sizeof(filters_window));
|
|
|
|
|
|
window->Window = yon_gtk_builder_get_widget(builder, "FiltersWindow");
|
|
|
window->QuotaTypeCheck = yon_gtk_builder_get_widget(builder, "QuotaTypeCheck");
|
|
|
window->QuotaTargetCheck = yon_gtk_builder_get_widget(builder, "QuotaTargetCheck");
|
|
|
window->SoftRamLimitCheck = yon_gtk_builder_get_widget(builder, "SoftRamLimitCheck");
|
|
|
window->HardRamLimitCheck = yon_gtk_builder_get_widget(builder, "HardRamLimitCheck");
|
|
|
window->PagingLimitCheck = yon_gtk_builder_get_widget(builder, "PagingLimitCheck");
|
|
|
window->CpuLimitCheck = yon_gtk_builder_get_widget(builder, "CpuLimitCheck");
|
|
|
window->ReadLimitCheck = yon_gtk_builder_get_widget(builder, "ReadLimitCheck");
|
|
|
window->WriteLimitCheck = yon_gtk_builder_get_widget(builder, "WriteLimitCheck");
|
|
|
|
|
|
window->CancelButton = yon_gtk_builder_get_widget(builder, "CancelButton");
|
|
|
window->AcceptButton = yon_gtk_builder_get_widget(builder, "AcceptButton");
|
|
|
|
|
|
GList *columns = gtk_tree_view_get_columns(GTK_TREE_VIEW(widgets->MainTree));
|
|
|
GList *checks = gtk_container_get_children(GTK_CONTAINER(gtk_widget_get_parent(window->QuotaTypeCheck)));
|
|
|
if (g_list_length(columns)==g_list_length(checks)){
|
|
|
for (int i=0;i<g_list_length(columns);i++){
|
|
|
if (gtk_tree_view_column_get_visible((GtkTreeViewColumn*)g_list_nth_data(columns,i)))
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON((GtkToggleButton*)g_list_nth_data(checks,i)),1);
|
|
|
}
|
|
|
} else {
|
|
|
printf("Error! Unequal quantity of filters and tree columns!");
|
|
|
}
|
|
|
|
|
|
dictionary *dict = NULL;
|
|
|
yon_dictionary_add_or_create_if_exists_with_data(dict,"columns",columns);
|
|
|
yon_dictionary_add_or_create_if_exists_with_data(dict,"checks",checks);
|
|
|
|
|
|
g_signal_connect(G_OBJECT(window->CancelButton),"clicked",G_CALLBACK(on_close_subwindow),NULL);
|
|
|
g_signal_connect(G_OBJECT(window->AcceptButton),"clicked",G_CALLBACK(on_apply_filters),dict);
|
|
|
|
|
|
gtk_window_set_title(GTK_WINDOW(window->Window),TITLE_LABEL);
|
|
|
gtk_widget_show(window->Window);
|
|
|
}
|
|
|
|
|
|
void on_add_open(GtkWidget *self, main_window *widgets){
|
|
|
GtkBuilder *builder = gtk_builder_new_from_resource(glade_quota_path);
|
|
|
quota_window *window = g_malloc0(sizeof(quota_window));
|
|
|
|
|
|
window->Window = yon_gtk_builder_get_widget(builder,"QuotasWindow");
|
|
|
|
|
|
window->TitleLabel = yon_gtk_builder_get_widget(builder,"TitleLabel");
|
|
|
window->BlockUiBox = yon_gtk_builder_get_widget(builder,"BlockUiBox");
|
|
|
window->TargetTypeCombo = yon_gtk_builder_get_widget(builder,"TargetTypeCombo");
|
|
|
window->AddQuotaTargetBox = yon_gtk_builder_get_widget(builder,"AddQuotaTargetBox");
|
|
|
window->EditQuotaTargetBox = yon_gtk_builder_get_widget(builder,"EditQuotaTargetBox");
|
|
|
window->TargetCombo = yon_gtk_builder_get_widget(builder,"TargetCombo");
|
|
|
window->TargetLabel = yon_gtk_builder_get_widget(builder,"TargetLabel");
|
|
|
|
|
|
window->SoftRestrictionCheck = yon_gtk_builder_get_widget(builder,"SoftRestrictionCheck");
|
|
|
window->SoftRestrictionSpin = yon_gtk_builder_get_widget(builder,"SoftRestrictionSpin");
|
|
|
window->SoftRestrictionCombo = yon_gtk_builder_get_widget(builder,"SoftRestrictionCombo");
|
|
|
|
|
|
window->HardRestrictionCheck = yon_gtk_builder_get_widget(builder,"HardRestrictionCheck");
|
|
|
window->HardRestrictionSpin = yon_gtk_builder_get_widget(builder,"HardRestrictionSpin");
|
|
|
window->HardRestrictionCombo = yon_gtk_builder_get_widget(builder,"HardRestrictionCombo");
|
|
|
|
|
|
window->PagingLimitCheck = yon_gtk_builder_get_widget(builder,"PagingLimitCheck");
|
|
|
window->PagingLimitSpin = yon_gtk_builder_get_widget(builder,"PagingLimitSpin");
|
|
|
window->PagingLimitCombo = yon_gtk_builder_get_widget(builder,"PagingLimitCombo");
|
|
|
|
|
|
window->CpuLimitCheck = yon_gtk_builder_get_widget(builder,"CpuLimitCheck");
|
|
|
window->CpuLimitSpin = yon_gtk_builder_get_widget(builder,"CpuLimitSpin");
|
|
|
|
|
|
window->DeviceLimitCombo = yon_gtk_builder_get_widget(builder,"DeviceLimitCombo");
|
|
|
|
|
|
window->DeviceLimitReadCheck = yon_gtk_builder_get_widget(builder,"DeviceLimitReadCheck");
|
|
|
window->DeviceLimitReadSpin = yon_gtk_builder_get_widget(builder,"DeviceLimitReadSpin");
|
|
|
window->DeviceLimitReadCombo = yon_gtk_builder_get_widget(builder,"DeviceLimitReadCombo");
|
|
|
|
|
|
window->DeviceLimitWriteCheck = yon_gtk_builder_get_widget(builder,"DeviceLimitWriteCheck");
|
|
|
window->DeviceLimitWriteSpin = yon_gtk_builder_get_widget(builder,"DeviceLimitWriteSpin");
|
|
|
window->DeviceLimitWriteCombo = yon_gtk_builder_get_widget(builder,"DeviceLimitWriteCombo");
|
|
|
window->ApplyChangesButton = yon_gtk_builder_get_widget(builder,"ApplyChangesButton");
|
|
|
window->ManualInputEntry = yon_gtk_builder_get_widget(builder,"ManualInputEntry");
|
|
|
|
|
|
window->CancelButton = yon_gtk_builder_get_widget(builder,"CancelButton");
|
|
|
window->SaveButton = yon_gtk_builder_get_widget(builder,"SaveButton");
|
|
|
|
|
|
window->devices = NULL;
|
|
|
|
|
|
gtk_window_set_title(GTK_WINDOW(window->Window),TITLE_LABEL);
|
|
|
|
|
|
struct sysinfo inf;
|
|
|
sysinfo(&inf);
|
|
|
main_config.avaliable_ram=inf.totalram;
|
|
|
main_config.avaliable_swap=inf.totalswap;
|
|
|
main_config.cores = sysconf(_SC_NPROCESSORS_ONLN);
|
|
|
dictionary *windows = NULL;
|
|
|
yon_dictionary_add_or_create_if_exists_with_data(windows,"window",window);
|
|
|
yon_dictionary_add_or_create_if_exists_with_data(windows,"widgets",widgets);
|
|
|
g_signal_connect(G_OBJECT(window->CancelButton),"clicked",G_CALLBACK(on_close_subwindow),NULL);
|
|
|
g_signal_connect(G_OBJECT(window->SaveButton),"clicked",G_CALLBACK(on_quotas_save),windows);
|
|
|
|
|
|
g_signal_connect(G_OBJECT(window->TargetTypeCombo),"changed",G_CALLBACK(on_quota_target_type_changed),window);
|
|
|
|
|
|
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->SoftRestrictionSpin)),main_config.avaliable_ram);
|
|
|
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->HardRestrictionSpin)),main_config.avaliable_ram);
|
|
|
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->PagingLimitSpin)),main_config.avaliable_swap);
|
|
|
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->CpuLimitSpin)),main_config.cores*100);
|
|
|
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->DeviceLimitReadSpin)),main_config.avaliable_ram);
|
|
|
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->DeviceLimitWriteSpin)),main_config.avaliable_ram);
|
|
|
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitCombo),"changed",G_CALLBACK(on_device_current_changed),window);
|
|
|
|
|
|
g_signal_connect(G_OBJECT(window->TargetCombo),"changed",G_CALLBACK(on_target_check_chosen),window);
|
|
|
g_signal_connect(G_OBJECT(window->SoftRestrictionSpin),"change-value",G_CALLBACK(on_check_maximum),window->SoftRestrictionCombo);
|
|
|
g_signal_connect(G_OBJECT(window->SoftRestrictionCombo),"changed",G_CALLBACK(on_check_maximum),window->SoftRestrictionSpin);
|
|
|
g_signal_connect(G_OBJECT(window->HardRestrictionSpin),"change-value",G_CALLBACK(on_check_maximum),window->HardRestrictionCombo);
|
|
|
g_signal_connect(G_OBJECT(window->HardRestrictionCombo),"changed",G_CALLBACK(on_check_maximum),window->HardRestrictionSpin);
|
|
|
g_signal_connect(G_OBJECT(window->PagingLimitSpin),"change-value",G_CALLBACK(on_check_maximum_cpu),window->PagingLimitCombo);
|
|
|
g_signal_connect(G_OBJECT(window->PagingLimitCombo),"changed",G_CALLBACK(on_check_maximum_cpu),window->PagingLimitSpin);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitReadSpin),"change-value",G_CALLBACK(on_check_maximum),window->DeviceLimitReadCombo);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitReadCombo),"changed",G_CALLBACK(on_check_maximum),window->DeviceLimitReadSpin);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitWriteSpin),"change-value",G_CALLBACK(on_check_maximum),window->DeviceLimitWriteCombo);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCombo),"changed",G_CALLBACK(on_check_maximum),window->DeviceLimitWriteSpin);
|
|
|
|
|
|
g_signal_connect(G_OBJECT(window->SoftRestrictionCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->SoftRestrictionCombo);
|
|
|
g_signal_connect(G_OBJECT(window->SoftRestrictionCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->SoftRestrictionSpin);
|
|
|
g_signal_connect(G_OBJECT(window->HardRestrictionCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->HardRestrictionCombo);
|
|
|
g_signal_connect(G_OBJECT(window->HardRestrictionCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->HardRestrictionSpin);
|
|
|
g_signal_connect(G_OBJECT(window->PagingLimitCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->PagingLimitCombo);
|
|
|
g_signal_connect(G_OBJECT(window->PagingLimitCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->PagingLimitSpin);
|
|
|
g_signal_connect(G_OBJECT(window->CpuLimitCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->CpuLimitSpin);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitReadCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->DeviceLimitReadCombo);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitReadCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->DeviceLimitReadSpin);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->DeviceLimitWriteCombo);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->DeviceLimitWriteSpin);
|
|
|
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitCombo),"changed",G_CALLBACK(yon_gtk_widget_set_sensitive_from_combo_box),window->DeviceLimitReadCheck);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitCombo),"changed",G_CALLBACK(yon_gtk_widget_set_sensitive_from_combo_box),window->DeviceLimitWriteCheck);
|
|
|
|
|
|
g_signal_connect(G_OBJECT(window->SoftRestrictionSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->SoftRestrictionCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->HardRestrictionSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->HardRestrictionCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->PagingLimitSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->PagingLimitCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->CpuLimitSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitReadSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitReadCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitWriteSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->SoftRestrictionCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->HardRestrictionCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->PagingLimitCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->CpuLimitCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitReadCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
|
|
|
// g_signal_connect(G_OBJECT(window->ManualInputEntry),"activate",G_CALLBACK(on_quota_manual_input),window);
|
|
|
// g_signal_connect(G_OBJECT(window->ManualInputEntry),"focus-out-event",G_CALLBACK(on_quota_manual_input_focus),window);
|
|
|
yon_get_devices(window);
|
|
|
dictionary *dict;
|
|
|
for_dictionaries(dict,window->devices){
|
|
|
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(window->DeviceLimitCombo),dict->key);
|
|
|
}
|
|
|
main_config.users = yon_ubl_get_all_users(&main_config.users_size);
|
|
|
main_config.processes = yon_ubl_get_all_processes(&main_config.processes_size);
|
|
|
main_config.slices = yon_ubl_get_all_slices(&main_config.slices_size);
|
|
|
for (int i=0; i<main_config.users_size;i++){
|
|
|
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(window->TargetCombo),main_config.users[i]);
|
|
|
}
|
|
|
gtk_widget_show(window->Window);
|
|
|
}
|
|
|
|
|
|
void on_information_chosen_changed(GtkWidget *self, main_window *widgets){
|
|
|
const char *chosen = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(self));
|
|
|
if (chosen){
|
|
|
char *command = yon_char_unite(get_information_command, (char*)chosen," --no-pager",NULL);
|
|
|
main_config.last_info = yon_char_new((char*)chosen);
|
|
|
yon_terminal_integrated_start(widgets->InformationTerminal, command, NULL, NULL);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void on_information(GtkWidget *self, main_window *widgets){
|
|
|
GtkTreeModel *model = GTK_TREE_MODEL(main_config.list);
|
|
|
GtkTreeIter iter;
|
|
|
if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->MainTree)),&model,&iter)){
|
|
|
char *name, *group;
|
|
|
gtk_tree_model_get(model,&iter,1,&name,0,&group,-1);
|
|
|
g_signal_handlers_block_by_func(G_OBJECT(widgets->TargetCombo),on_information_chosen_changed,widgets);
|
|
|
if (strcmp(group,STR_PROCESS)==0){
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->TargetTypeCombo),1);
|
|
|
} else if (strcmp(group,STR_SLICE)==0){
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->TargetTypeCombo),2);
|
|
|
} else {
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->TargetTypeCombo),0);
|
|
|
}
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->TargetCombo),yon_gtk_combo_box_text_find(widgets->TargetCombo,name));
|
|
|
g_signal_handlers_unblock_by_func(G_OBJECT(widgets->TargetCombo),on_information_chosen_changed,widgets);
|
|
|
char *command = yon_char_unite(get_information_command, (char*)name," --no-pager",NULL);
|
|
|
main_config.last_info = yon_char_new((char*)name);
|
|
|
yon_terminal_integrated_start(widgets->InformationTerminal, command, NULL, NULL);
|
|
|
gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->MainNotebook),3);
|
|
|
yon_ubl_status_box_render(SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
|
}
|
|
|
else yon_ubl_status_box_render(NOTHING_CHOSEN_LABEL,BACKGROUND_IMAGE_FAIL_TYPE);
|
|
|
}
|
|
|
|
|
|
void on_information_update(GtkWidget *self, main_window *widgets){
|
|
|
char *command = yon_char_unite(get_information_command, main_config.last_info," --no-pager",NULL);
|
|
|
yon_terminal_integrated_start(widgets->InformationTerminal, command, NULL, NULL);
|
|
|
}
|
|
|
|
|
|
void on_remove(GtkWidget *self, main_window *widgets){
|
|
|
GtkTreeModel *model = GTK_TREE_MODEL(main_config.list);
|
|
|
GtkTreeIter iter;
|
|
|
if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->MainTree)),&model,&iter)){
|
|
|
char *name;
|
|
|
gtk_tree_model_get(model,&iter,1,&name,-1);
|
|
|
yon_config_set(CGROUP_QUOTA(name),"");
|
|
|
gtk_list_store_remove(main_config.list,&iter);
|
|
|
yon_ubl_status_box_render(SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
|
}
|
|
|
else yon_ubl_status_box_render(NOTHING_CHOSEN_LABEL,BACKGROUND_IMAGE_FAIL_TYPE);
|
|
|
|
|
|
}
|
|
|
|
|
|
void on_quotas_edit(GtkWidget *self, dictionary *windows){
|
|
|
GtkTreeModel *model = GTK_TREE_MODEL(main_config.list);
|
|
|
quota_window *window = yon_dictionary_get_data(windows->first,quota_window*);
|
|
|
main_window *widgets = yon_dictionary_get_data(windows->first->next,main_window*);
|
|
|
GtkTreeIter iter;
|
|
|
if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->MainTree)),&model,&iter)){
|
|
|
const char *string = gtk_entry_get_text(GTK_ENTRY(window->ManualInputEntry));
|
|
|
const char *target = gtk_label_get_text(GTK_LABEL(window->TargetLabel));
|
|
|
char *soft = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->SoftRestrictionCheck)) ? yon_char_append(yon_char_from_long(gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->SoftRestrictionSpin))),get_size_mod(GTK_COMBO_BOX(window->SoftRestrictionCombo))) : NULL;
|
|
|
char *hard = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->HardRestrictionCheck)) ? yon_char_append(yon_char_from_long(gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->HardRestrictionSpin))),get_size_mod(GTK_COMBO_BOX(window->HardRestrictionCombo))) : NULL;
|
|
|
char *paging = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->PagingLimitCheck)) ? yon_char_append(yon_char_from_long(gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->PagingLimitSpin))),get_size_mod(GTK_COMBO_BOX(window->PagingLimitCombo))) : NULL;
|
|
|
char *cpu = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->CpuLimitCheck)) ? yon_char_from_long(gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->CpuLimitSpin))) : NULL;
|
|
|
char *read_limit = "";
|
|
|
char *read_devices = "";
|
|
|
dictionary *dict;
|
|
|
for_dictionaries(dict,window->devices){
|
|
|
if (dict->data&&yon_dictionary_get_data(dict,device_limits*)->read)
|
|
|
read_devices = yon_char_unite(read_devices,"",yon_char_divide_search(yon_char_new(dict->key)," ",-1)," ",yon_dictionary_get_data(dict,device_limits*)->read,"\n",NULL);
|
|
|
}
|
|
|
if (read_devices[strlen(read_devices)-1]=='\n') read_devices[strlen(read_devices)-1]='\0';
|
|
|
read_limit = yon_char_unite(read_limit,read_devices,NULL);
|
|
|
|
|
|
|
|
|
char *write_limit = "";
|
|
|
char *write_devices = "";
|
|
|
for_dictionaries(dict,window->devices){
|
|
|
if (dict->data&&yon_dictionary_get_data(dict,device_limits*)->write)
|
|
|
write_devices = yon_char_unite(write_devices,"",yon_char_divide_search(yon_char_new(dict->key)," ",-1)," ",yon_dictionary_get_data(dict,device_limits*)->write,"\n",NULL);
|
|
|
}
|
|
|
if (write_devices[strlen(write_devices)-1]=='\n') write_devices[strlen(write_devices)-1]='\0';
|
|
|
write_limit = yon_char_unite(write_limit,write_devices,NULL);
|
|
|
gtk_list_store_set(main_config.list,&iter,1,target,2,soft,3,hard,4,paging,5,cpu,6,read_limit,7,write_limit,8,string,-1);
|
|
|
yon_config_set(CGROUP_QUOTA(target),(void*)yon_char_new((char*)string));
|
|
|
on_close_subwindow(self);
|
|
|
yon_ubl_status_box_render(SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
|
}
|
|
|
else yon_ubl_status_box_render(NOTHING_CHOSEN_LABEL,BACKGROUND_IMAGE_FAIL_TYPE);
|
|
|
}
|
|
|
|
|
|
void on_edit_open(GtkWidget *self, main_window *widgets){
|
|
|
GtkTreeModel *model = GTK_TREE_MODEL(main_config.list);
|
|
|
GtkTreeIter iter;
|
|
|
if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->MainTree)),&model,&iter)){
|
|
|
char *type;
|
|
|
char *target;
|
|
|
char *soft;
|
|
|
char *hard;
|
|
|
char *swap;
|
|
|
char *cpu;
|
|
|
char *read;
|
|
|
char *write;
|
|
|
int soft_size=-1;
|
|
|
int hard_size=-1;
|
|
|
int swap_size=-1;
|
|
|
gtk_tree_model_get(model,&iter,0,&type,1,&target,2,&soft,3,&hard,4,&swap,5,&cpu,6,&read,7,&write,-1);
|
|
|
if (soft&&strcmp(soft,"")!=0){
|
|
|
soft_size = yon_get_size_request_from_letter(soft[strlen(soft)-1]);
|
|
|
soft[strlen(soft)-1]='\0';
|
|
|
}
|
|
|
if (hard&&strcmp(hard,"")!=0){
|
|
|
hard_size=yon_get_size_request_from_letter(hard[strlen(hard)-1]);
|
|
|
hard[strlen(hard)-1]='\0';
|
|
|
}
|
|
|
if (swap&&strcmp(swap,"")!=0){
|
|
|
swap_size=yon_get_size_request_from_letter(swap[strlen(swap)-1]);
|
|
|
swap[strlen(swap)-1]='\0';
|
|
|
}
|
|
|
|
|
|
GtkBuilder *builder = gtk_builder_new_from_resource(glade_quota_path);
|
|
|
quota_window *window = g_malloc0(sizeof(quota_window));
|
|
|
|
|
|
window->Window = yon_gtk_builder_get_widget(builder,"QuotasWindow");
|
|
|
|
|
|
window->TitleLabel = yon_gtk_builder_get_widget(builder,"TitleLabel");
|
|
|
window->BlockUiBox = yon_gtk_builder_get_widget(builder,"BlockUiBox");
|
|
|
window->TargetTypeCombo = yon_gtk_builder_get_widget(builder,"TargetTypeCombo");
|
|
|
window->AddQuotaTargetBox = yon_gtk_builder_get_widget(builder,"AddQuotaTargetBox");
|
|
|
window->EditQuotaTargetBox = yon_gtk_builder_get_widget(builder,"EditQuotaTargetBox");
|
|
|
window->TargetCombo = yon_gtk_builder_get_widget(builder,"TargetCombo");
|
|
|
window->TargetLabel = yon_gtk_builder_get_widget(builder,"TargetLabel");
|
|
|
|
|
|
window->SoftRestrictionCheck = yon_gtk_builder_get_widget(builder,"SoftRestrictionCheck");
|
|
|
window->SoftRestrictionSpin = yon_gtk_builder_get_widget(builder,"SoftRestrictionSpin");
|
|
|
window->SoftRestrictionCombo = yon_gtk_builder_get_widget(builder,"SoftRestrictionCombo");
|
|
|
|
|
|
window->HardRestrictionCheck = yon_gtk_builder_get_widget(builder,"HardRestrictionCheck");
|
|
|
window->HardRestrictionSpin = yon_gtk_builder_get_widget(builder,"HardRestrictionSpin");
|
|
|
window->HardRestrictionCombo = yon_gtk_builder_get_widget(builder,"HardRestrictionCombo");
|
|
|
|
|
|
window->PagingLimitCheck = yon_gtk_builder_get_widget(builder,"PagingLimitCheck");
|
|
|
window->PagingLimitSpin = yon_gtk_builder_get_widget(builder,"PagingLimitSpin");
|
|
|
window->PagingLimitCombo = yon_gtk_builder_get_widget(builder,"PagingLimitCombo");
|
|
|
|
|
|
window->CpuLimitCheck = yon_gtk_builder_get_widget(builder,"CpuLimitCheck");
|
|
|
window->CpuLimitSpin = yon_gtk_builder_get_widget(builder,"CpuLimitSpin");
|
|
|
|
|
|
window->DeviceLimitCombo = yon_gtk_builder_get_widget(builder,"DeviceLimitCombo");
|
|
|
|
|
|
window->DeviceLimitReadCheck = yon_gtk_builder_get_widget(builder,"DeviceLimitReadCheck");
|
|
|
window->DeviceLimitReadSpin = yon_gtk_builder_get_widget(builder,"DeviceLimitReadSpin");
|
|
|
window->DeviceLimitReadCombo = yon_gtk_builder_get_widget(builder,"DeviceLimitReadCombo");
|
|
|
|
|
|
window->DeviceLimitWriteCheck = yon_gtk_builder_get_widget(builder,"DeviceLimitWriteCheck");
|
|
|
window->DeviceLimitWriteSpin = yon_gtk_builder_get_widget(builder,"DeviceLimitWriteSpin");
|
|
|
window->DeviceLimitWriteCombo = yon_gtk_builder_get_widget(builder,"DeviceLimitWriteCombo");
|
|
|
window->ApplyChangesButton = yon_gtk_builder_get_widget(builder,"ApplyChangesButton");
|
|
|
window->ManualInputEntry = yon_gtk_builder_get_widget(builder,"ManualInputEntry");
|
|
|
|
|
|
window->CancelButton = yon_gtk_builder_get_widget(builder,"CancelButton");
|
|
|
window->SaveButton = yon_gtk_builder_get_widget(builder,"SaveButton");
|
|
|
|
|
|
window->devices = NULL;
|
|
|
|
|
|
gtk_window_set_title(GTK_WINDOW(window->Window),TITLE_LABEL);
|
|
|
|
|
|
gtk_widget_show(window->EditQuotaTargetBox);
|
|
|
gtk_widget_hide(window->AddQuotaTargetBox);
|
|
|
struct sysinfo inf;
|
|
|
sysinfo(&inf);
|
|
|
main_config.avaliable_ram=inf.totalram;
|
|
|
main_config.avaliable_swap=inf.totalswap;
|
|
|
main_config.cores = sysconf(_SC_NPROCESSORS_ONLN);
|
|
|
dictionary *windows = NULL;
|
|
|
yon_dictionary_add_or_create_if_exists_with_data(windows,"window",window);
|
|
|
yon_dictionary_add_or_create_if_exists_with_data(windows,"widgets",widgets);
|
|
|
g_signal_connect(G_OBJECT(window->CancelButton),"clicked",G_CALLBACK(on_close_subwindow),NULL);
|
|
|
g_signal_connect(G_OBJECT(window->SaveButton),"clicked",G_CALLBACK(on_quotas_edit),windows);
|
|
|
|
|
|
g_signal_connect(G_OBJECT(window->TargetTypeCombo),"changed",G_CALLBACK(on_quota_target_type_changed),window);
|
|
|
|
|
|
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->SoftRestrictionSpin)),main_config.avaliable_ram);
|
|
|
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->HardRestrictionSpin)),main_config.avaliable_ram);
|
|
|
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->PagingLimitSpin)),main_config.avaliable_swap);
|
|
|
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->CpuLimitSpin)),main_config.cores*100);
|
|
|
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->DeviceLimitReadSpin)),main_config.avaliable_ram);
|
|
|
gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->DeviceLimitWriteSpin)),main_config.avaliable_ram);
|
|
|
|
|
|
g_signal_connect(G_OBJECT(window->SoftRestrictionCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->SoftRestrictionCombo);
|
|
|
g_signal_connect(G_OBJECT(window->SoftRestrictionCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->SoftRestrictionSpin);
|
|
|
g_signal_connect(G_OBJECT(window->HardRestrictionCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->HardRestrictionCombo);
|
|
|
g_signal_connect(G_OBJECT(window->HardRestrictionCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->HardRestrictionSpin);
|
|
|
g_signal_connect(G_OBJECT(window->PagingLimitCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->PagingLimitCombo);
|
|
|
g_signal_connect(G_OBJECT(window->PagingLimitCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->PagingLimitSpin);
|
|
|
g_signal_connect(G_OBJECT(window->CpuLimitCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->CpuLimitSpin);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitReadCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->DeviceLimitReadCombo);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitReadCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->DeviceLimitReadSpin);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->DeviceLimitWriteCombo);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->DeviceLimitWriteSpin);
|
|
|
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitCombo),"changed",G_CALLBACK(yon_gtk_widget_set_sensitive_from_combo_box),window->DeviceLimitReadCheck);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitCombo),"changed",G_CALLBACK(yon_gtk_widget_set_sensitive_from_combo_box),window->DeviceLimitWriteCheck);
|
|
|
|
|
|
yon_get_devices(window);
|
|
|
dictionary *dict;
|
|
|
gtk_widget_set_sensitive(window->BlockUiBox,1);
|
|
|
gtk_label_set_text(GTK_LABEL(window->TargetLabel),target);
|
|
|
int read_size=0;
|
|
|
config_str read_parsed = yon_char_parse(read,&read_size,"\n");
|
|
|
int write_size=0;
|
|
|
config_str write_parsed = yon_char_parse(write,&write_size,"\n");
|
|
|
for_dictionaries(dict,window->devices){
|
|
|
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(window->DeviceLimitCombo),dict->key);
|
|
|
if (read_parsed)
|
|
|
for (int i=0; i<read_size;i++){
|
|
|
char *read_limit = yon_char_new(read_parsed[i]);
|
|
|
char *read_cur = yon_char_divide_search(read_limit," ",-1);
|
|
|
if (strstr(dict->key,read_cur)){
|
|
|
if(!dict->data){
|
|
|
dict->data = g_malloc0(sizeof(device_limits));
|
|
|
((device_limits*)dict->data)->write=NULL;
|
|
|
((device_limits*)dict->data)->read=NULL;
|
|
|
}
|
|
|
((device_limits*)dict->data)->read=read_limit;
|
|
|
}
|
|
|
}
|
|
|
else{
|
|
|
char *read_limit = yon_char_new(read);
|
|
|
char *read_cur = yon_char_divide_search(read_limit," ",-1);
|
|
|
if (strstr(dict->key,read_cur)){
|
|
|
if(!dict->data){
|
|
|
dict->data = g_malloc0(sizeof(device_limits));
|
|
|
((device_limits*)dict->data)->write=NULL;
|
|
|
((device_limits*)dict->data)->read=NULL;
|
|
|
}
|
|
|
((device_limits*)dict->data)->read=read_limit;
|
|
|
}
|
|
|
}
|
|
|
if (write_parsed)
|
|
|
for (int i=0; i<write_size;i++){
|
|
|
char *write_limit = yon_char_new(write_parsed[i]);
|
|
|
char *write_cur = yon_char_divide_search(write_limit," ",-1);
|
|
|
if (strstr(dict->key,write_cur)){
|
|
|
if(!dict->data){
|
|
|
dict->data = g_malloc0(sizeof(device_limits));
|
|
|
((device_limits*)dict->data)->write=NULL;
|
|
|
((device_limits*)dict->data)->read=NULL;
|
|
|
}
|
|
|
((device_limits*)dict->data)->write=write_limit;
|
|
|
}
|
|
|
}
|
|
|
else{
|
|
|
char *write_limit = yon_char_new(write);
|
|
|
char *write_cur = yon_char_divide_search(write_limit," ",-1);
|
|
|
if (strstr(dict->key,write_cur)){
|
|
|
if(!dict->data){
|
|
|
dict->data = g_malloc0(sizeof(device_limits));
|
|
|
((device_limits*)dict->data)->write=NULL;
|
|
|
((device_limits*)dict->data)->read=NULL;
|
|
|
}
|
|
|
((device_limits*)dict->data)->write=write_limit;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
window->devices=window->devices->first;
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitCombo),0);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitCombo),"changed",G_CALLBACK(on_device_current_changed),window);
|
|
|
if (((device_limits*)window->devices->data)->read&&strcmp(((device_limits*)window->devices->data)->read,"")!=0){
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->DeviceLimitReadCheck),1);
|
|
|
char *rd = ((device_limits*)window->devices->data)->read;
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitReadCombo),yon_get_size_request_from_letter(rd[strlen(rd)-1]));
|
|
|
rd[strlen(rd)-1]='\0';
|
|
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->DeviceLimitReadSpin),strtol(((device_limits*)window->devices->data)->read,NULL,10));
|
|
|
}
|
|
|
else ((device_limits*)window->devices->data)->read=NULL;
|
|
|
if (((device_limits*)window->devices->data)->write&&strcmp(((device_limits*)window->devices->data)->write,"")!=0){
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->DeviceLimitWriteCheck),1);
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitWriteCombo),yon_get_size_request_from_letter(((device_limits*)window->devices->data)->write[strlen(((device_limits*)window->devices->data)->write)-1]));
|
|
|
((device_limits*)window->devices->data)->write[strlen(((device_limits*)window->devices->data)->write)-1]='\0';
|
|
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->DeviceLimitWriteSpin),strtol(((device_limits*)window->devices->data)->write,NULL,10));
|
|
|
} else ((device_limits*)window->devices->data)->write=NULL;
|
|
|
if (soft&&strcmp(soft,"")!=0) {
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->SoftRestrictionCheck),1);
|
|
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->SoftRestrictionSpin),strtol(soft,NULL,10));
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(window->SoftRestrictionCombo),soft_size);
|
|
|
}
|
|
|
if (hard&&strcmp(hard,"")!=0) {
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->HardRestrictionCheck),1);
|
|
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->HardRestrictionSpin),strtol(hard,NULL,10));
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(window->HardRestrictionCombo),hard_size);
|
|
|
}
|
|
|
if (hard&&strcmp(hard,"")!=0) {
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->HardRestrictionCheck),1);
|
|
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->HardRestrictionSpin),strtol(hard,NULL,10));
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(window->HardRestrictionCombo),hard_size);
|
|
|
}
|
|
|
if (swap&&strcmp(swap,"")!=0) {
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->PagingLimitCheck),1);
|
|
|
gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->PagingLimitSpin),strtol(swap,NULL,10));
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(window->PagingLimitCombo),swap_size);
|
|
|
}
|
|
|
for (int i=0; i<main_config.users_size;i++){
|
|
|
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(window->TargetCombo),main_config.users[i]);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
g_signal_connect(G_OBJECT(window->TargetCombo),"changed",G_CALLBACK(on_target_check_chosen),window);
|
|
|
g_signal_connect(G_OBJECT(window->SoftRestrictionSpin),"change-value",G_CALLBACK(on_check_maximum),window->SoftRestrictionCombo);
|
|
|
g_signal_connect(G_OBJECT(window->SoftRestrictionCombo),"changed",G_CALLBACK(on_check_maximum),window->SoftRestrictionSpin);
|
|
|
g_signal_connect(G_OBJECT(window->HardRestrictionSpin),"change-value",G_CALLBACK(on_check_maximum),window->HardRestrictionCombo);
|
|
|
g_signal_connect(G_OBJECT(window->HardRestrictionCombo),"changed",G_CALLBACK(on_check_maximum),window->HardRestrictionSpin);
|
|
|
g_signal_connect(G_OBJECT(window->PagingLimitSpin),"change-value",G_CALLBACK(on_check_maximum_cpu),window->PagingLimitCombo);
|
|
|
g_signal_connect(G_OBJECT(window->PagingLimitCombo),"changed",G_CALLBACK(on_check_maximum_cpu),window->PagingLimitSpin);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitReadSpin),"change-value",G_CALLBACK(on_check_maximum),window->DeviceLimitReadCombo);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitReadCombo),"changed",G_CALLBACK(on_check_maximum),window->DeviceLimitReadSpin);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitWriteSpin),"change-value",G_CALLBACK(on_check_maximum),window->DeviceLimitWriteCombo);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCombo),"changed",G_CALLBACK(on_check_maximum),window->DeviceLimitWriteSpin);
|
|
|
|
|
|
g_signal_connect(G_OBJECT(window->SoftRestrictionSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->SoftRestrictionCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->HardRestrictionSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->HardRestrictionCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->PagingLimitSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->PagingLimitCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->CpuLimitSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitReadSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitReadCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitWriteSpin),"output",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCombo),"changed",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->SoftRestrictionCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->HardRestrictionCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->PagingLimitCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->CpuLimitCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitReadCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
g_signal_connect(G_OBJECT(window->DeviceLimitWriteCheck),"toggled",G_CALLBACK(on_quota_configuration_update),window);
|
|
|
gtk_widget_show(window->Window);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void on_dispatcher_update(GtkWidget *self,main_window *widgets){
|
|
|
int interval = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widgets->DispatcherUpdateSpin));
|
|
|
if (interval>0) {
|
|
|
char* str_second = yon_char_from_int(interval);
|
|
|
char *command = yon_char_unite(get_dispatcher_command," -d ",str_second,NULL);
|
|
|
if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->DispatcherUpdateCheck))) command = yon_char_append(command," -n 1");
|
|
|
yon_terminal_integrated_start(widgets->DispatcherTerminal, command, NULL, NULL);
|
|
|
free(str_second);
|
|
|
GValue *val = g_malloc0(sizeof(GValue));
|
|
|
g_object_get_property(G_OBJECT(widgets->DispatcherUpdateSpin),"has-focus",val);
|
|
|
g_value_set_boolean(val,0);
|
|
|
g_object_set_property(G_OBJECT(widgets->DispatcherUpdateSpin),"has-focus",val);
|
|
|
g_free(val);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void on_processes_update(GtkWidget *self,main_window *widgets){
|
|
|
int show_all = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->ShowAllCheck));
|
|
|
int show_core = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->ShowCoreCheck));
|
|
|
char *command = get_processes_tree_command;
|
|
|
if (show_all) yon_char_append(command, " -k");
|
|
|
if (show_core) yon_char_append(command, " -l");
|
|
|
yon_terminal_integrated_start(widgets->ProcessesTerminal, command, NULL, NULL);
|
|
|
}
|
|
|
|
|
|
void on_tab_changed(GtkWidget *self, GtkWidget *page, int page_num, main_window *widgets){
|
|
|
|
|
|
}
|
|
|
|
|
|
void on_info_target_type_switched(GtkWidget *self, main_window *widgets){
|
|
|
int active = gtk_combo_box_get_active(GTK_COMBO_BOX(self));
|
|
|
gtk_combo_box_text_remove_all(GTK_COMBO_BOX_TEXT(widgets->TargetCombo));
|
|
|
int size=0;
|
|
|
config_str str = NULL;
|
|
|
switch (active){
|
|
|
case 0:
|
|
|
str = main_config.users;
|
|
|
size = main_config.users_size;
|
|
|
break;
|
|
|
case 1:
|
|
|
str = main_config.processes;
|
|
|
size = main_config.processes_size;
|
|
|
break;
|
|
|
case 2:
|
|
|
str = main_config.slices;
|
|
|
size = main_config.slices_size;
|
|
|
break;
|
|
|
}
|
|
|
for (int i=0; i<size;i++){
|
|
|
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(widgets->TargetCombo),str[i]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// standard functions
|
|
|
|
|
|
void config_init(){
|
|
|
main_config.always_open_documentation=0;
|
|
|
main_config.win_height=0;
|
|
|
main_config.win_width=0;
|
|
|
main_config.win_pos_x=0;
|
|
|
main_config.win_pos_y=0;
|
|
|
main_config.socket_id=-1;
|
|
|
main_config.save_socket_id=-1;
|
|
|
main_config.load_socket_id=-1;
|
|
|
main_config.lock_help=0;
|
|
|
main_config.lock_help=0;
|
|
|
main_config.lock_load_global=0;
|
|
|
main_config.lock_save_global=0;
|
|
|
main_config.lock_save_local=0;
|
|
|
main_config.avaliable_ram=0;
|
|
|
}
|
|
|
|
|
|
main_window *setup_window(){
|
|
|
/* Widgets getting | Получение виджетов */
|
|
|
main_window *widgets = malloc(sizeof(main_window));
|
|
|
GtkBuilder *builder = gtk_builder_new_from_resource(glade_path);
|
|
|
widgets->Window = yon_gtk_builder_get_widget(builder,"MainWindow");
|
|
|
widgets->HatLabel = yon_gtk_builder_get_widget(builder,"headerTopic");
|
|
|
widgets->PlugBox = yon_gtk_builder_get_widget(builder,"plugBox");
|
|
|
|
|
|
widgets->HeadOverlay = yon_gtk_builder_get_widget(builder,"HeadOverlay");
|
|
|
widgets->HeadImage = yon_gtk_builder_get_widget(builder,"HeadBackgroundImage");
|
|
|
widgets->HeadBox = yon_gtk_builder_get_widget(builder,"HeaderBox");
|
|
|
widgets->HeadTitleLabel = yon_gtk_builder_get_widget(builder,"HeaderTitleLabel");
|
|
|
widgets->HeadInfoLabel = yon_gtk_builder_get_widget(builder,"HeaderInfoLabel");
|
|
|
|
|
|
widgets->StatusBox = yon_gtk_builder_get_widget(builder,"mainStatusBox");
|
|
|
widgets->StatusIcon = yon_gtk_builder_get_widget(builder,"mainStatusIcon");
|
|
|
widgets->StatusLabel = yon_gtk_builder_get_widget(builder,"mainStatusLabel");
|
|
|
|
|
|
widgets->SaveLabel = yon_gtk_builder_get_widget(builder,"headerSaveConfigLabel");
|
|
|
widgets->SaveMenuItem = yon_gtk_builder_get_widget(builder,"SaveGlobalLocalConfigurationMenuItem");
|
|
|
widgets->SaveGlobalMenuItem = yon_gtk_builder_get_widget(builder,"SaveGlobalConfigurationMenuItem");
|
|
|
widgets->SaveLocalMenuItem = yon_gtk_builder_get_widget(builder,"SaveLocalConfigurationMenuItem");
|
|
|
widgets->RightBox = yon_gtk_builder_get_widget(builder,"HeaderRightBox");
|
|
|
|
|
|
widgets->LoadLabel = yon_gtk_builder_get_widget(builder,"headerLoadConfigLabel");
|
|
|
widgets->LoadGlobalMenuItem = yon_gtk_builder_get_widget(builder,"LoadGlobalConfigurationMenuItem");
|
|
|
widgets->LoadLocalMenuItem = yon_gtk_builder_get_widget(builder,"LoadLocalConfigurationMenuItem");
|
|
|
widgets->LeftBox = yon_gtk_builder_get_widget(builder,"HeaderLeftBox");
|
|
|
|
|
|
widgets->FiltersButton = yon_gtk_builder_get_widget(builder,"FiltersButton");
|
|
|
widgets->InformationButton = yon_gtk_builder_get_widget(builder,"InformationButton");
|
|
|
widgets->RemoveButton = yon_gtk_builder_get_widget(builder,"RemoveButton");
|
|
|
widgets->EditButton = yon_gtk_builder_get_widget(builder,"EditButton");
|
|
|
widgets->AddButton = yon_gtk_builder_get_widget(builder,"AddButton");
|
|
|
|
|
|
widgets->MainTree = yon_gtk_builder_get_widget(builder,"QuotasTreeView");
|
|
|
widgets->MainNotebook = yon_gtk_builder_get_widget(builder,"MainNotebook");
|
|
|
|
|
|
widgets->DispatcherUpdateCheck = yon_gtk_builder_get_widget(builder,"DispatcherUpdateCheck");
|
|
|
widgets->DispatcherUpdateSpin = yon_gtk_builder_get_widget(builder,"DispatcherUpdateSpin");
|
|
|
widgets->DispatcherUpdateButton = yon_gtk_builder_get_widget(builder,"DispatcherUpdateButton");
|
|
|
widgets->DispatcherTerminal = yon_gtk_builder_get_widget(builder,"DispatcherTerminal");
|
|
|
|
|
|
widgets->ShowAllCheck = yon_gtk_builder_get_widget(builder,"ShowAllCheck");
|
|
|
widgets->ShowCoreCheck = yon_gtk_builder_get_widget(builder,"ShowCoreCheck");
|
|
|
widgets->ProcessesUpdateButton = yon_gtk_builder_get_widget(builder,"ProcessesUpdateButton");
|
|
|
widgets->ProcessesTerminal = yon_gtk_builder_get_widget(builder,"ProcessesTerminal");
|
|
|
|
|
|
widgets->TargetTypeCombo = yon_gtk_builder_get_widget(builder,"TargetTypeCombo");
|
|
|
widgets->TargetCombo = yon_gtk_builder_get_widget(builder,"TargetCombo");
|
|
|
widgets->InformationUpdateButton = yon_gtk_builder_get_widget(builder,"InformationUpdateButton");
|
|
|
widgets->InformationTerminal = yon_gtk_builder_get_widget(builder,"InformationTerminal");
|
|
|
|
|
|
main_config.list = GTK_LIST_STORE(gtk_builder_get_object(builder,"liststore"));
|
|
|
|
|
|
widgets->DocumentationMenuItem = yon_ubl_menu_item_documentation_new(DOCUMENTATION_LABEL);
|
|
|
widgets->AboutMenuItem = yon_ubl_menu_item_about_new(ABOUT_LABEL);
|
|
|
|
|
|
gtk_window_set_title(GTK_WINDOW(widgets->Window),TITLE_LABEL);
|
|
|
|
|
|
GtkWidget *menu = yon_gtk_builder_get_widget(builder,"menu2");
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(menu),widgets->DocumentationMenuItem);
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(menu),widgets->AboutMenuItem);
|
|
|
|
|
|
if (main_config.lock_load_global == 1){
|
|
|
gtk_widget_set_sensitive(widgets->LoadGlobalMenuItem,0);
|
|
|
}
|
|
|
if (main_config.lock_save_global == 1){
|
|
|
gtk_widget_set_sensitive(widgets->SaveGlobalMenuItem,0);
|
|
|
gtk_widget_set_sensitive(widgets->SaveMenuItem,0);
|
|
|
}
|
|
|
if (main_config.lock_save_local == 1){
|
|
|
gtk_widget_set_sensitive(widgets->SaveLocalMenuItem,0);
|
|
|
gtk_widget_set_sensitive(widgets->SaveMenuItem,0);
|
|
|
}
|
|
|
|
|
|
/* Widget registration for config monitoring | Регистрация виджетов для мониторинга конфига */
|
|
|
// yon_window_config_add_custom_parameter(widgets->HeadInfoLabel,"head-text","label",YON_TYPE_STRING);
|
|
|
|
|
|
/* Signal connection | Присоединение сигналов */
|
|
|
g_signal_connect(G_OBJECT(widgets->DocumentationMenuItem),"activate",G_CALLBACK(on_open_documentation_confirmation),WIKI_LINK);
|
|
|
g_signal_connect(G_OBJECT(widgets->AboutMenuItem),"activate",G_CALLBACK(on_about),NULL);
|
|
|
g_signal_connect(G_OBJECT(widgets->FiltersButton),"clicked",G_CALLBACK(on_filters_opened),widgets);
|
|
|
g_signal_connect(G_OBJECT(widgets->InformationButton),"clicked",G_CALLBACK(on_information),widgets);
|
|
|
g_signal_connect(G_OBJECT(widgets->RemoveButton),"clicked",G_CALLBACK(on_remove),widgets);
|
|
|
g_signal_connect(G_OBJECT(widgets->EditButton),"clicked",G_CALLBACK(on_edit_open),widgets);
|
|
|
g_signal_connect(G_OBJECT(widgets->AddButton),"clicked",G_CALLBACK(on_add_open),widgets);
|
|
|
g_signal_connect(G_OBJECT(widgets->MainNotebook),"switch-page",G_CALLBACK(on_tab_changed),widgets);
|
|
|
g_signal_connect(G_OBJECT(widgets->DispatcherUpdateCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),widgets->DispatcherUpdateSpin);
|
|
|
g_signal_connect(G_OBJECT(widgets->DispatcherUpdateCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button_inversed),widgets->DispatcherUpdateButton);
|
|
|
g_signal_connect(G_OBJECT(widgets->DispatcherUpdateCheck),"toggled",G_CALLBACK(on_dispatcher_update),widgets);
|
|
|
g_signal_connect(G_OBJECT(widgets->DispatcherUpdateSpin),"output",G_CALLBACK(on_dispatcher_update),widgets);
|
|
|
g_signal_connect(G_OBJECT(widgets->DispatcherUpdateButton),"clicked",G_CALLBACK(on_dispatcher_update),widgets);
|
|
|
g_signal_connect(G_OBJECT(widgets->ShowAllCheck),"toggled",G_CALLBACK(on_processes_update),widgets);
|
|
|
g_signal_connect(G_OBJECT(widgets->ShowCoreCheck),"toggled",G_CALLBACK(on_processes_update),widgets);
|
|
|
g_signal_connect(G_OBJECT(widgets->TargetTypeCombo),"changed",G_CALLBACK(on_info_target_type_switched),widgets);
|
|
|
g_signal_connect(G_OBJECT(widgets->TargetCombo),"changed",G_CALLBACK(on_information_chosen_changed),widgets);
|
|
|
g_signal_connect(G_OBJECT(widgets->ProcessesUpdateButton),"clicked",G_CALLBACK(on_processes_update),widgets);
|
|
|
g_signal_connect(G_OBJECT(widgets->InformationUpdateButton),"clicked",G_CALLBACK(on_information_update),widgets);
|
|
|
|
|
|
g_signal_connect(G_OBJECT(widgets->SaveMenuItem),"activate",G_CALLBACK(on_config_save),NULL);
|
|
|
g_signal_connect(G_OBJECT(widgets->SaveGlobalMenuItem),"activate",G_CALLBACK(on_config_save_global),NULL);
|
|
|
g_signal_connect(G_OBJECT(widgets->SaveLocalMenuItem),"activate",G_CALLBACK(on_config_save_local),NULL);
|
|
|
g_signal_connect(G_OBJECT(widgets->LoadGlobalMenuItem),"activate",G_CALLBACK(on_config_load_global),NULL);
|
|
|
g_signal_connect(G_OBJECT(widgets->LoadLocalMenuItem),"activate",G_CALLBACK(on_config_load_local),NULL);
|
|
|
on_dispatcher_update(NULL,widgets);
|
|
|
on_processes_update(NULL,widgets);
|
|
|
yon_window_config_add_listener(widgets->DispatcherUpdateCheck,"DispatcherAutoupdate","active",YON_TYPE_BOOLEAN);
|
|
|
yon_window_config_add_listener(widgets->ShowAllCheck,"ProcessShowAll","active",YON_TYPE_BOOLEAN);
|
|
|
yon_window_config_add_listener(widgets->ShowCoreCheck,"ProcessShowCore","active",YON_TYPE_BOOLEAN);
|
|
|
yon_window_config_add_listener(widgets->DispatcherUpdateSpin,"DispatcherUpdateDelay","value",YON_TYPE_DOUBLE);
|
|
|
GList *list = gtk_tree_view_get_columns(GTK_TREE_VIEW(widgets->MainTree));
|
|
|
for (int i=0;i<g_list_length(list);i++){
|
|
|
yon_window_config_add_listener((GtkWidget*)g_list_nth_data(list,i),yon_char_append("column",yon_char_from_int(i)),"fixed-width",YON_TYPE_INT);
|
|
|
}
|
|
|
main_config.users = yon_ubl_get_all_users(&main_config.users_size);
|
|
|
main_config.processes = yon_ubl_get_all_processes(&main_config.processes_size);
|
|
|
main_config.slices = yon_ubl_get_all_slices(&main_config.slices_size);
|
|
|
on_info_target_type_switched(widgets->TargetTypeCombo,widgets);
|
|
|
gtk_widget_show(widgets->Window);
|
|
|
return widgets;
|
|
|
}
|
|
|
|
|
|
int main(int argc, char *argv[]){
|
|
|
local=setlocale(LC_ALL, "");
|
|
|
textdomain (LocaleName);
|
|
|
config_init();
|
|
|
int option_index=0;
|
|
|
int show_help=0;
|
|
|
int debug_mode=0;
|
|
|
{
|
|
|
struct option long_options[] = {
|
|
|
{"help", 0, 0, 'h'},
|
|
|
{"version", 0, 0, 'V'},
|
|
|
{"lock-help", 0,0, 1},
|
|
|
{"lock-save", 0,0, 2},
|
|
|
{"lock-save-local", 0,0, 3},
|
|
|
{"lock-save-global", 0,0, 4},
|
|
|
{"lock-load-global", 0,0, 5},
|
|
|
{"socket-id", 1, 0, 's'},
|
|
|
{"socket-ext-id", 1,0, 'e'},
|
|
|
{"socket-trd-id", 1,0, 't'},
|
|
|
{"debug", 0,0, 'd'},
|
|
|
{ NULL, 0, NULL, 0 }
|
|
|
};
|
|
|
for (int i=0;i<argc;i++){
|
|
|
int argument=getopt_long(argc,argv,"hVvs:e:t:d",long_options,&option_index);
|
|
|
switch(argument){
|
|
|
case 'h':
|
|
|
show_help=1;
|
|
|
break;
|
|
|
case 'v':
|
|
|
case 'V':
|
|
|
printf("%s\n",VERSION_LABEL);
|
|
|
exit(0);
|
|
|
break;
|
|
|
case 's':
|
|
|
if(optarg)
|
|
|
main_config.socket_id=atoi(optarg);
|
|
|
break;
|
|
|
case 'e':
|
|
|
if(optarg)
|
|
|
main_config.save_socket_id=atoi(optarg);
|
|
|
break;
|
|
|
case 't':
|
|
|
if(optarg)
|
|
|
main_config.load_socket_id=atoi(optarg);
|
|
|
break;
|
|
|
case 1:
|
|
|
main_config.lock_help=1;
|
|
|
break;
|
|
|
case 2:
|
|
|
main_config.lock_save_local=1;
|
|
|
main_config.lock_save_global=1;
|
|
|
break;
|
|
|
case 3:
|
|
|
main_config.lock_save_local=1;
|
|
|
break;
|
|
|
case 4:
|
|
|
main_config.lock_save_global=1;
|
|
|
break;
|
|
|
case 5:
|
|
|
main_config.lock_load_global=1;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (show_help==1&&main_config.lock_help!=1){
|
|
|
printf("%s\n",HELP_LABEL);
|
|
|
exit(0);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (getuid()!=0){
|
|
|
main_config.lock_load_global=1;
|
|
|
main_config.lock_save_global=1;
|
|
|
main_config.lock_save_local=1;
|
|
|
}
|
|
|
gtk_init(&argc,&argv);
|
|
|
|
|
|
|
|
|
main_window *widgets = setup_window();
|
|
|
yon_ubl_header_setup_resource(widgets->HeadOverlay,widgets->HeadBox,widgets->HeadImage,banner_path);
|
|
|
|
|
|
yon_ubl_status_box_setup(widgets->StatusIcon,widgets->StatusBox,widgets->StatusLabel);
|
|
|
if (getuid()!=0)
|
|
|
yon_ubl_status_box_render(ROOT_WARNING_LABEL,BACKGROUND_IMAGE_FAIL_TYPE);
|
|
|
else
|
|
|
yon_ubl_status_box_render(LOCAL_SAVE_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
|
yon_ubl_setup_sockets(widgets->PlugBox,widgets->LeftBox,widgets->RightBox,main_config.socket_id,main_config.load_socket_id,main_config.save_socket_id);
|
|
|
yon_window_config_setup(GTK_WINDOW(widgets->Window));
|
|
|
yon_window_config_load(config_path);
|
|
|
on_config_load_local();
|
|
|
GtkCssProvider *css=gtk_css_provider_new();
|
|
|
gtk_css_provider_load_from_resource(css,CssPath);
|
|
|
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),
|
|
|
GTK_STYLE_PROVIDER(css),
|
|
|
-1);
|
|
|
gtk_main();
|
|
|
} |