From 542568087bb391eadc9b596c38270fb66a767bf8 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Tue, 10 Jun 2025 06:16:23 +0000 Subject: [PATCH] Added manual input support --- source/ubl-settings-resourcequota.c | 136 +++++++++++++++++++--------- source/ubl-settings-resourcequota.h | 4 +- 2 files changed, 95 insertions(+), 45 deletions(-) diff --git a/source/ubl-settings-resourcequota.c b/source/ubl-settings-resourcequota.c index 7dbaa1c..3e883f1 100644 --- a/source/ubl-settings-resourcequota.c +++ b/source/ubl-settings-resourcequota.c @@ -291,6 +291,7 @@ void on_device_current_changed(GtkWidget *, quota_window *window){ g_signal_handlers_unblock_by_func(G_OBJECT(window->DeviceLimitReadSpin),G_CALLBACK(on_device_set),window); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->DeviceLimitReadCheck),1); switch (read[strlen(read)-1]){ + default: 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); @@ -316,6 +317,7 @@ void on_device_current_changed(GtkWidget *, quota_window *window){ g_signal_handlers_unblock_by_func(G_OBJECT(window->DeviceLimitWriteSpin),G_CALLBACK(on_device_set),window); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->DeviceLimitWriteCheck),1); switch (write[strlen(write)-1]){ + default: 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); @@ -856,6 +858,10 @@ void yon_widget_set_sensitive(GtkComboBox *toggle, GtkWidget *target){ } } +void on_manual_edit(GtkWidget *, quota_window *window){ + yon_quota_update(window); +} + quota_window *yon_quota_window_new(){ GtkBuilder *builder = gtk_builder_new_from_resource(glade_quota_path); quota_window *window = g_malloc0(sizeof(quota_window)); @@ -955,6 +961,7 @@ quota_window *yon_quota_window_new(){ 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->TargetTypeCombo),"changed",G_CALLBACK(on_quota_target_type_changed),window); + g_signal_connect(G_OBJECT(window->ManualInputEntry),"changed",G_CALLBACK(on_manual_edit),window); yon_get_devices(window); window->devices=window->devices->first; @@ -990,23 +997,7 @@ quota_window *yon_quota_window_new(){ return window; } -void on_edit_open(GtkWidget *, 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)) return; - quota_window *window = yon_quota_window_new(); - gtk_widget_set_sensitive(window->BlockUiBox,1); - char *target, *type; - gtk_tree_model_get(model,&iter,0,&type,1,&target,-1); - - gtk_label_set_text(GTK_LABEL(window->TypeLabel),type); - gtk_label_set_text(GTK_LABEL(window->TargetLabel),target); - gtk_window_set_title(GTK_WINDOW(window->Window),EDITING_LABEL); - gtk_label_set_text(GTK_LABEL(window->TitleLabel),EDITING_LABEL); - - gtk_widget_show(window->EditQuotaTargetBox); - gtk_widget_hide(window->AddQuotaTargetBox); - +void yon_quota_update(quota_window *window){ g_signal_handlers_block_by_func(G_OBJECT(window->SoftRestrictionSpin),G_CALLBACK(on_quota_configuration_update),window); g_signal_handlers_block_by_func(G_OBJECT(window->SoftRestrictionCombo),G_CALLBACK(on_quota_configuration_update),window); g_signal_handlers_block_by_func(G_OBJECT(window->HardRestrictionSpin),G_CALLBACK(on_quota_configuration_update),window); @@ -1032,60 +1023,91 @@ void on_edit_open(GtkWidget *, main_window *widgets){ g_signal_handlers_block_by_func(G_OBJECT(window->DeviceLimitWriteSpin),G_CALLBACK(on_device_set),window); g_signal_handlers_block_by_func(G_OBJECT(window->DeviceLimitWriteCombo),G_CALLBACK(on_device_set),window); - char *parameter = config(CGROUP_QUOTA(target)); + char *parameter = yon_char_new(gtk_entry_get_text(GTK_ENTRY(window->ManualInputEntry))); int size; - gtk_entry_set_text(GTK_ENTRY(window->ManualInputEntry),parameter); config_str parsed = yon_char_parse(parameter,&size,","); + long soft_restr=0; + long hard_restr=0; + long swap_restr=0; + int cpu=0; for (int i=0;i1){ + soft_restr = atol(parsed_parameter[1]); int size_mult = yon_get_size_get_from_letter(parsed_parameter[1][strlen(parsed_parameter[1])-1]); + if (size_mult==-1) size_mult=0; long hard_current_max = main_config.avaliable_ram; for (int i=0;iSoftRestrictionSpin)),hard_current_max); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->SoftRestrictionSpin),soft_restr); - gtk_combo_box_set_active(GTK_COMBO_BOX(window->SoftRestrictionCombo),size_mult); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->SoftRestrictionCheck),1); - } else if (!strcmp(parsed_parameter[0],"MemoryMax")){ + if (soft_restr) { + gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->SoftRestrictionSpin),soft_restr); + gtk_combo_box_set_active(GTK_COMBO_BOX(window->SoftRestrictionCombo),size_mult); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->SoftRestrictionCheck),1); + } else { + gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->SoftRestrictionSpin),0); + gtk_combo_box_set_active(GTK_COMBO_BOX(window->SoftRestrictionCombo),0); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->SoftRestrictionCheck),0); + + } + } else if (!strcmp(parsed_parameter[0],"MemoryMax")&&parsed_size>1){ - long hard_restr = atol(parsed_parameter[1]); + hard_restr = atol(parsed_parameter[1]); int size_mult = yon_get_size_get_from_letter(parsed_parameter[1][strlen(parsed_parameter[1])-1]); + if (size_mult==-1) size_mult=0; long hard_current_max = main_config.avaliable_ram; for (int i=0;iHardRestrictionSpin)),hard_current_max); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->HardRestrictionSpin),hard_restr); - gtk_combo_box_set_active(GTK_COMBO_BOX(window->HardRestrictionCombo),yon_get_size_get_from_letter(parsed_parameter[1][strlen(parsed_parameter[1])-1])); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->HardRestrictionCheck),1); - } else if (!strcmp(parsed_parameter[0],"MemorySwapMax")){ - long swap_restr = atol(parsed_parameter[1]); + if (hard_restr){ + gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->HardRestrictionSpin),hard_restr); + gtk_combo_box_set_active(GTK_COMBO_BOX(window->HardRestrictionCombo),size_mult); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->HardRestrictionCheck),1); + } else { + gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->HardRestrictionSpin),0); + gtk_combo_box_set_active(GTK_COMBO_BOX(window->HardRestrictionCombo),0); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->HardRestrictionCheck),0); + } + } else if (!strcmp(parsed_parameter[0],"MemorySwapMax")&&parsed_size>1){ + swap_restr = atol(parsed_parameter[1]); int size_mult = yon_get_size_get_from_letter(parsed_parameter[1][strlen(parsed_parameter[1])-1]); + if (size_mult==-1) size_mult=0; long hard_current_max = main_config.avaliable_swap; for (int i=0;iPagingLimitSpin)),hard_current_max); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->PagingLimitSpin),swap_restr); - gtk_combo_box_set_active(GTK_COMBO_BOX(window->PagingLimitCombo),yon_get_size_get_from_letter(parsed_parameter[1][strlen(parsed_parameter[1])-1])); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->PagingLimitCheck),1); + if (swap_restr){ + gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->PagingLimitSpin),swap_restr); + gtk_combo_box_set_active(GTK_COMBO_BOX(window->PagingLimitCombo),size_mult); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->PagingLimitCheck),1); + } else { + gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->PagingLimitSpin),0); + gtk_combo_box_set_active(GTK_COMBO_BOX(window->PagingLimitCombo),0); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->PagingLimitCheck),0); + + } - } else if (!strcmp(parsed_parameter[0],"CPUQuota")){ - int cpu = atoi(parsed_parameter[1]); + } else if (!strcmp(parsed_parameter[0],"CPUQuota")&&parsed_size>1){ + cpu = atoi(parsed_parameter[1]); gtk_adjustment_set_upper(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(window->CpuLimitSpin)),main_config.cores*100); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->CpuLimitSpin),cpu); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->CpuLimitCheck),1); - } else if (!strcmp(parsed_parameter[0],"IOReadBandwidthMax")){ + if (cpu){ + gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->CpuLimitSpin),cpu); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->CpuLimitCheck),1); + } else { + gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->CpuLimitSpin),0); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->CpuLimitCheck),0); + } + } else if (!strcmp(parsed_parameter[0],"IOReadBandwidthMax")&&parsed_size>1){ char *device = yon_char_divide_search(parsed_parameter[1]," ",-1); dictionary *dict = yon_dictionary_get(&window->devices,device); if (dict){ device_limits *limit = yon_dictionary_get_data(dict,device_limits*); limit->read = yon_char_new(parsed_parameter[1]); } - } else if (!strcmp(parsed_parameter[0],"IOWriteBandwidthMax")){ + } else if (!strcmp(parsed_parameter[0],"IOWriteBandwidthMax")&&parsed_size>1){ char *device = yon_char_divide_search(parsed_parameter[1]," ",-1); dictionary *dict = yon_dictionary_get(&window->devices,device); if (dict){ @@ -1096,16 +1118,16 @@ void on_edit_open(GtkWidget *, main_window *widgets){ } } + if (!soft_restr) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->SoftRestrictionCheck),0); + if (!hard_restr) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->HardRestrictionCheck),0); + if (!swap_restr) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->PagingLimitCheck),0); + if (!cpu) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->CpuLimitCheck),0); 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->SaveButton),"clicked",G_CALLBACK(on_quotas_edit),windows); g_signal_handlers_unblock_by_func(G_OBJECT(window->SoftRestrictionSpin),G_CALLBACK(on_quota_configuration_update),window); g_signal_handlers_unblock_by_func(G_OBJECT(window->SoftRestrictionCombo),G_CALLBACK(on_quota_configuration_update),window); @@ -1133,6 +1155,32 @@ void on_edit_open(GtkWidget *, main_window *widgets){ g_signal_handlers_unblock_by_func(G_OBJECT(window->DeviceLimitWriteCombo),G_CALLBACK(on_device_set),window); } +void on_edit_open(GtkWidget *, 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)) return; + quota_window *window = yon_quota_window_new(); + gtk_widget_set_sensitive(window->BlockUiBox,1); + char *target, *type; + gtk_tree_model_get(model,&iter,0,&type,1,&target,-1); + + gtk_label_set_text(GTK_LABEL(window->TypeLabel),type); + gtk_label_set_text(GTK_LABEL(window->TargetLabel),target); + gtk_window_set_title(GTK_WINDOW(window->Window),EDITING_LABEL); + gtk_label_set_text(GTK_LABEL(window->TitleLabel),EDITING_LABEL); + + gtk_widget_show(window->EditQuotaTargetBox); + gtk_widget_hide(window->AddQuotaTargetBox); + + char *parameter = config(CGROUP_QUOTA(target)); + gtk_entry_set_text(GTK_ENTRY(window->ManualInputEntry),parameter); + yon_quota_update(window); + 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->SaveButton),"clicked",G_CALLBACK(on_quotas_edit),windows); +} + gboolean on_dispatcher_update(GtkWidget *,main_window *widgets){ int interval = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widgets->DispatcherUpdateSpin)); if (interval>0) { diff --git a/source/ubl-settings-resourcequota.h b/source/ubl-settings-resourcequota.h index e8a6eac..9b6f8ad 100644 --- a/source/ubl-settings-resourcequota.h +++ b/source/ubl-settings-resourcequota.h @@ -225,4 +225,6 @@ 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); void on_device_set(GtkWidget *self, quota_window *window); -quota_window *yon_quota_window_new(); \ No newline at end of file +quota_window *yon_quota_window_new(); +void yon_quota_update(quota_window *window); +void on_manual_edit(GtkWidget *, quota_window *window); \ No newline at end of file