diff --git a/source/ubl-settings-resourcequota.c b/source/ubl-settings-resourcequota.c index cf996b7..266ae1f 100644 --- a/source/ubl-settings-resourcequota.c +++ b/source/ubl-settings-resourcequota.c @@ -53,9 +53,8 @@ void on_device_limits_update(GtkWidget *, quota_window *window){ } } -void on_quota_configuration_update(GtkWidget *self, quota_window *window){ +void on_quota_configuration_update(GtkWidget *, quota_window *window){ char *output_line = NULL; - on_device_limits_update(self,window); long sft = (long)gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->SoftRestrictionSpin)); long hrd = (long)gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->HardRestrictionSpin)); long pgl = (long)gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->PagingLimitSpin)); @@ -218,74 +217,111 @@ void yon_get_devices(quota_window *window){ for (int i=0; idevices,pa,NULL); + char *device_name = yon_char_new(pa); + char *id = yon_char_divide_search(device_name," ",-1); + free(device_name); + device_limits *limits = malloc(sizeof(device_limits)); + limits->device_name = yon_char_new(pa); + limits->read=NULL; + limits->write=NULL; + yon_dictionary_add_or_create_if_exists_with_data(window->devices,id,limits); } yon_char_parsed_free(devices_parsed,size); } -void on_device_current_changed(GtkWidget *, 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 { - long read_lim = gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->DeviceLimitReadSpin)); - long write_lim = gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->DeviceLimitWriteSpin)); - if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->DeviceLimitReadCheck))){ - if (read_lim) yon_dictionary_get_data(window->devices,device_limits*)->read=yon_char_append(yon_char_from_long(read_lim),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))){ - if (write_lim) yon_dictionary_get_data(window->devices,device_limits*)->write=yon_char_append(yon_char_from_long(write_lim),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; +void on_device_set(GtkWidget *self, quota_window *window){ + char *id = (char*)gtk_combo_box_get_active_id(GTK_COMBO_BOX(window->DeviceLimitCombo)); + if (!yon_char_is_empty(id)){ + dictionary *current = yon_dictionary_get(&window->devices,id); + if (current){ + device_limits *limits = yon_dictionary_get_data(current,device_limits*); + if (self == window->DeviceLimitReadCheck||self == window->DeviceLimitReadSpin||self == window->DeviceLimitReadCombo){ + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->DeviceLimitReadCheck))){ + long value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->DeviceLimitReadSpin)); + if (!value) { + yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); + yon_ubl_status_highlight_incorrect(window->DeviceLimitReadSpin); + return; + } + char *value_str = yon_char_from_long(value); + char *full_str = yon_char_unite(value_str,yon_size_get_mod(gtk_combo_box_get_active(GTK_COMBO_BOX(window->DeviceLimitReadCombo))),NULL); + if (!yon_char_is_empty(limits->read)) free(limits->read); + limits->read=full_str; + } else { + limits->read=NULL; + } + } else if (self == window->DeviceLimitWriteCheck||self == window->DeviceLimitWriteSpin||self == window->DeviceLimitWriteCombo){ + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->DeviceLimitWriteCheck))){ + long value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->DeviceLimitWriteSpin)); + if (!value) { + yon_ubl_status_box_spawn(GTK_CONTAINER(window->StatusBox),EMPTY_IMPORTANT_LABEL,5,BACKGROUND_IMAGE_FAIL_TYPE); + yon_ubl_status_highlight_incorrect(window->DeviceLimitWriteSpin); + return; + } + char *value_str = yon_char_from_long(value); + char *full_str = yon_char_unite(value_str,yon_size_get_mod(gtk_combo_box_get_active(GTK_COMBO_BOX(window->DeviceLimitWriteCombo))),NULL); + if (!yon_char_is_empty(limits->read)) free(limits->read); + limits->read=full_str; + } else { + limits->read=NULL; + } } - } 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; + } +} + +void on_device_current_changed(GtkWidget *, quota_window *window){ + char *chosen = (char*)gtk_combo_box_get_active_id(GTK_COMBO_BOX(window->DeviceLimitCombo)); + if (!yon_char_is_empty(chosen)){ + dictionary *current = yon_dictionary_get(&window->devices,chosen); + if (current){ + device_limits *limits = yon_dictionary_get_data(current,device_limits*); + char *read = limits->read; + char *write = limits->write; + if (!yon_char_is_empty(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 (!yon_char_is_empty(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); } - } 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); } + } else { + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->DeviceLimitReadCheck),0); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->DeviceLimitReadSpin),0); + gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitReadCombo),0); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->DeviceLimitWriteCheck),0); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->DeviceLimitWriteSpin),0); + gtk_combo_box_set_active(GTK_COMBO_BOX(window->DeviceLimitWriteCombo),0); } } @@ -314,7 +350,6 @@ void on_quotas_save(GtkWidget *self, dictionary *windows){ if (!yon_char_is_empty(read_devices)&&read_devices[strlen(read_devices)-1]=='\n') read_devices[strlen(read_devices)-1]='\0'; read_limit = yon_char_unite(read_limit?read_limit:"",read_devices,NULL); - char *write_limit = NULL; char *write_devices = NULL; for_dictionaries(dict,window->devices){ @@ -539,7 +574,7 @@ void on_quota_manual_input(GtkWidget *self, quota_window *window){ char *name = yon_char_divide_search(value, " ",-1); dictionary *dict; for_dictionaries(dict,window->devices){ - if (strstr(dict->key,name)){ + if (!strcmp(dict->key,name)){ if (!((device_limits*)dict->data)){ dict->data = g_malloc0(sizeof(device_limits)); ((device_limits*)dict->data)->write=NULL; @@ -553,7 +588,7 @@ void on_quota_manual_input(GtkWidget *self, quota_window *window){ char *name = yon_char_divide_search(value, " ",-1); dictionary *dict; for_dictionaries(dict,window->devices){ - if (strstr(dict->key,name)){ + if (!strcmp(dict->key,name)){ if (!((device_limits*)dict->data)){ dict->data = g_malloc0(sizeof(device_limits)); ((device_limits*)dict->data)->write=NULL; @@ -738,6 +773,12 @@ void on_add_open(GtkWidget *, main_window *widgets){ 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->DeviceLimitReadCheck),"toggled",G_CALLBACK(on_device_set),window); + g_signal_connect(G_OBJECT(window->DeviceLimitReadSpin),"value-changed",G_CALLBACK(on_device_set),window); + g_signal_connect(G_OBJECT(window->DeviceLimitReadCombo),"changed",G_CALLBACK(on_device_set),window); + g_signal_connect(G_OBJECT(window->DeviceLimitWriteCheck),"toggled",G_CALLBACK(on_device_set),window); + g_signal_connect(G_OBJECT(window->DeviceLimitWriteSpin),"value-changed",G_CALLBACK(on_device_set),window); + g_signal_connect(G_OBJECT(window->DeviceLimitWriteCombo),"changed",G_CALLBACK(on_device_set),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); @@ -789,7 +830,8 @@ void on_add_open(GtkWidget *, main_window *widgets){ 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); + char *temp = yon_char_new(yon_dictionary_get_data(dict,device_limits*)->device_name); + gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(window->DeviceLimitCombo),dict->key,temp); } main_config.users = yon_ubl_get_all_users(&main_config.users_size); main_config.processes = yon_config_load(get_processes_command,&main_config.processes_size); @@ -882,7 +924,7 @@ void on_quotas_edit(GtkWidget *self, dictionary *windows){ 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?read_devices:"","",yon_char_divide_search(yon_char_new(dict->key)," ",-1)," ",yon_dictionary_get_data(dict,device_limits*)->read,"\n",NULL); + read_devices = yon_char_unite(read_devices?read_devices:"","",dict->key," ",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_limit:"",read_devices,NULL); @@ -892,7 +934,7 @@ void on_quotas_edit(GtkWidget *self, dictionary *windows){ char *write_devices = NULL; for_dictionaries(dict,window->devices){ if (dict->data&&yon_dictionary_get_data(dict,device_limits*)->write) - write_devices = yon_char_unite(write_devices?write_devices:"","",yon_char_divide_search(yon_char_new(dict->key)," ",-1)," ",yon_dictionary_get_data(dict,device_limits*)->write,"\n",NULL); + write_devices = yon_char_unite(write_devices?write_devices:"","",dict->key," ",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_limit:"",write_devices,NULL); @@ -1040,18 +1082,19 @@ void on_edit_open(GtkWidget *, main_window *widgets){ yon_get_devices(window); dictionary *dict; gtk_widget_set_sensitive(window->BlockUiBox,1); - gtk_label_set_text(GTK_LABEL(window->TargetLabel),target); + gtk_label_set_markup(GTK_LABEL(window->TargetLabel),yon_char_unite(type," ",target,"",NULL)); 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); + char *temp = yon_char_new(yon_dictionary_get_data(dict,device_limits*)->device_name); + gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(window->DeviceLimitCombo),dict->key,temp); if (read_parsed) for (int i=0; ikey,read_cur)){ + if (strstr(temp,read_cur)){ if(!dict->data){ dict->data = g_malloc0(sizeof(device_limits)); ((device_limits*)dict->data)->write=NULL; @@ -1063,7 +1106,7 @@ void on_edit_open(GtkWidget *, main_window *widgets){ 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 (strstr(temp,read_cur)){ if(!dict->data){ dict->data = g_malloc0(sizeof(device_limits)); ((device_limits*)dict->data)->write=NULL; @@ -1076,7 +1119,7 @@ void on_edit_open(GtkWidget *, main_window *widgets){ for (int i=0; ikey,write_cur)){ + if (strstr(temp,write_cur)){ if(!dict->data){ dict->data = g_malloc0(sizeof(device_limits)); ((device_limits*)dict->data)->write=NULL; @@ -1088,7 +1131,7 @@ void on_edit_open(GtkWidget *, main_window *widgets){ 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 (strstr(temp,write_cur)){ if(!dict->data){ dict->data = g_malloc0(sizeof(device_limits)); ((device_limits*)dict->data)->write=NULL; @@ -1103,6 +1146,12 @@ void on_edit_open(GtkWidget *, main_window *widgets){ 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); + g_signal_connect(G_OBJECT(window->DeviceLimitReadCheck),"toggled",G_CALLBACK(on_device_set),window); + g_signal_connect(G_OBJECT(window->DeviceLimitReadSpin),"value-changed",G_CALLBACK(on_device_set),window); + g_signal_connect(G_OBJECT(window->DeviceLimitReadCombo),"changed",G_CALLBACK(on_device_set),window); + g_signal_connect(G_OBJECT(window->DeviceLimitWriteCheck),"toggled",G_CALLBACK(on_device_set),window); + g_signal_connect(G_OBJECT(window->DeviceLimitWriteSpin),"value-changed",G_CALLBACK(on_device_set),window); + g_signal_connect(G_OBJECT(window->DeviceLimitWriteCombo),"changed",G_CALLBACK(on_device_set),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; diff --git a/source/ubl-settings-resourcequota.h b/source/ubl-settings-resourcequota.h index 3f6daf2..b54cf4e 100644 --- a/source/ubl-settings-resourcequota.h +++ b/source/ubl-settings-resourcequota.h @@ -177,6 +177,7 @@ typedef struct { } filters_window; typedef struct { + char *device_name; char *read; char *write; } device_limits; @@ -221,4 +222,5 @@ void on_check_maximum(GtkWidget *self, GtkWidget *pair); void on_limit_manual_input(GtkWidget *self, double *new_value, quota_window *window); void on_quota_configuration_update(GtkWidget *self, quota_window *window); void on_device_limits_update(GtkWidget *, quota_window *window); -void yon_widget_set_sensitive(GtkComboBox *toggle, GtkWidget *target); \ No newline at end of file +void yon_widget_set_sensitive(GtkComboBox *toggle, GtkWidget *target); +void on_device_set(GtkWidget *self, quota_window *window); \ No newline at end of file diff --git a/source/ubl-strings.h b/source/ubl-strings.h index 0915a56..8f641a7 100644 --- a/source/ubl-strings.h +++ b/source/ubl-strings.h @@ -87,6 +87,8 @@ #define VIEW_PROPERTIES_LABEL _("View properties for") +#define EMPTY_IMPORTANT_LABEL _("Important field is empty") + #define REMOVE_TITLE_LABEL _("Remove quota") #define REMOVE_VALIDATION_LABEL(target) yon_char_unite(_("Are you sure you want to remove quota")," ",target,"?",NULL) #define ADDING_LABEL _("Add quota") diff --git a/ubl-settings-resourcequota-quota.glade b/ubl-settings-resourcequota-quota.glade index 302ac46..5b73aea 100644 --- a/ubl-settings-resourcequota-quota.glade +++ b/ubl-settings-resourcequota-quota.glade @@ -3,6 +3,57 @@ + + 1 + 1 + 1 + 1 + 10 + + + 1 + 1 + 1 + 1 + 10 + + + 1 + 1 + 1 + 1 + 10 + + + 1 + 1 + 1 + 1 + 10 + + + 1 + 1 + 1 + 1 + 10 + + + 1 + 1 + 1 + 10 + + + True + False + process-stop-symbolic + + + True + False + emblem-ok-symbolic + False start @@ -941,55 +992,4 @@ - - 1 - 1 - 1 - 1 - 10 - - - 1 - 1 - 1 - 1 - 10 - - - 1 - 1 - 1 - 1 - 10 - - - 1 - 1 - 1 - 1 - 10 - - - 1 - 1 - 1 - 1 - 10 - - - 1 - 1 - 1 - 10 - - - True - False - process-stop-symbolic - - - True - False - emblem-ok-symbolic -