From 1c122108686f4989bce461f952b0e96521b14b34 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Sat, 27 Apr 2024 10:24:47 +0600 Subject: [PATCH] Added tooltip --- Makefile | 1 + ...settings-services.arrow-round-symbolic.svg | 1 + source/ubl-settings-services.c | 90 ++++++ source/ubl-settings-services.h | 11 + source/ubl-strings.h | 7 +- ubl-settings-services.glade | 258 +++++++++++++++++- ubl-settings-services.pot | 26 +- ubl-settings-services_ru.po | 26 +- 8 files changed, 415 insertions(+), 5 deletions(-) create mode 100644 icons/com.ublinux.ubl-settings-services.arrow-round-symbolic.svg diff --git a/Makefile b/Makefile index 17148b3..5dcd1b2 100644 --- a/Makefile +++ b/Makefile @@ -143,6 +143,7 @@ install: check uninstall @install -Dm644 -t "${DESTDIR}/usr/share/icons/hicolor/scalable/actions/" "icons/com.ublinux.${PKGNAME}.source-symbolic.svg" @install -Dm644 -t "${DESTDIR}/usr/share/icons/hicolor/scalable/actions/" "icons/com.ublinux.${PKGNAME}.save-symbolic.svg" @install -Dm644 -t "${DESTDIR}/usr/share/icons/hicolor/scalable/actions/" "icons/com.ublinux.${PKGNAME}.update-symbolic.svg" + @install -Dm644 -t "${DESTDIR}/usr/share/icons/hicolor/scalable/actions/" "icons/com.ublinux.${PKGNAME}.arrow-round-symbolic.svg" @install -Dm644 -t "${DESTDIR}/usr/share/polkit-1/actions/" "${CMAKE_BUILD_DIR}/com.ublinux.${PKGNAME}${PKGIDENT}.policy" @if [ -z ${DESTDIR} ]; then \ [ -d "${DESTDIR}/usr/share/icons/hicolor/" ] && gtk-update-icon-cache -fiq "${DESTDIR}/usr/share/icons/hicolor/" &>/dev/null || true; \ diff --git a/icons/com.ublinux.ubl-settings-services.arrow-round-symbolic.svg b/icons/com.ublinux.ubl-settings-services.arrow-round-symbolic.svg new file mode 100644 index 0000000..694731a --- /dev/null +++ b/icons/com.ublinux.ubl-settings-services.arrow-round-symbolic.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/source/ubl-settings-services.c b/source/ubl-settings-services.c index 336900b..001c6ac 100644 --- a/source/ubl-settings-services.c +++ b/source/ubl-settings-services.c @@ -1455,6 +1455,85 @@ void on_tree_selection_changed(GtkWidget *self, main_window *widgets){ } } +gboolean on_tooltip_show(GtkWidget* self, gint x, gint y, gboolean keyboard_mode, GtkTooltip* tooltip, main_window *widgets) { + if (self || x || y || keyboard_mode) {}; + + gtk_tooltip_set_custom(tooltip,widgets->TooltipBox); + GtkWidget *tree = NULL; + GtkTreeModel *model = NULL; + if (gtk_notebook_get_current_page(GTK_NOTEBOOK(widgets->MainNotebook)) == 0) { + tree = widgets->SystemUnitsTree; + model = gtk_tree_view_get_model(GTK_TREE_VIEW(widgets->SystemUnitsTree)); + } else { + tree = widgets->UserUnitsTree; + model = gtk_tree_view_get_model(GTK_TREE_VIEW(widgets->UserUnitsTree)); + } + + gint tree_x, tree_y; + gtk_tree_view_convert_widget_to_bin_window_coords(GTK_TREE_VIEW(tree), x, y, &tree_x, &tree_y); + + GtkTreePath *path; + if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tree), tree_x, tree_y, &path, NULL, NULL, NULL)) { + GtkTreeIter iter; + if (gtk_tree_model_get_iter(model, &iter, path)) { + gchar *name, *description, *state; + gint64 activa, deactiva; + int size; + gtk_tree_model_get(model, &iter, 5, &name, 6, &description, 11, &state, -1); + config_str target = yon_config_load(get_activate_deactivate_times(name), &size); + free(yon_char_divide_search(target[0], "=", -1)); + yon_char_remove_last_symbol(target[0], '\n'); + free(yon_char_divide_search(target[1], "=", -1)); + yon_char_remove_last_symbol(target[1], '\n'); + free(yon_char_divide_search(target[2], "=", -1)); + yon_char_remove_last_symbol(target[2], '\n'); + activa = g_ascii_strtoll(target[1], NULL, 10); + deactiva = g_ascii_strtoll(target[1], NULL, 10); + + gtk_label_set_text(GTK_LABEL(widgets->NameLabel), name); + gtk_label_set_text(GTK_LABEL(widgets->DescriptionLabel), description); + gtk_label_set_text(GTK_LABEL(widgets->StatusQueryLabel), state); + gtk_label_set_text(GTK_LABEL(widgets->UnitLabel), target[0]); + + free(name); + free(description); + free(state); + free(target[1]); + free(target[2]); + + gchar *formatted_activa = NULL; + gchar *formatted_deactiva = NULL; + if (activa) { + GDateTime *datetime = g_date_time_new_from_unix_local(activa); + formatted_activa = g_date_time_format(datetime, "%d:%M:%Y %T"); + g_date_time_unref(datetime); + } else { + formatted_activa = g_strdup(NULL_LABEL); + } + if (deactiva) { + GDateTime *datetime = g_date_time_new_from_unix_local(deactiva); + formatted_deactiva = g_date_time_format(datetime, "%d:%M:%Y %T"); + g_date_time_unref(datetime); + } else { + formatted_deactiva = g_strdup(NULL_LABEL); + } + + gtk_label_set_text(GTK_LABEL(widgets->ActivateLabel), formatted_activa); + gtk_label_set_text(GTK_LABEL(widgets->DeactivateLabel), formatted_deactiva); + + g_free(formatted_activa); + g_free(formatted_deactiva); + + // Освобождение памяти пути + gtk_tree_path_free(path); + return TRUE; + } + gtk_tree_path_free(path); + } + return FALSE; +} + + /**yon_main_window_complete(main_window *widgets) * [EN] * @@ -1478,6 +1557,14 @@ void yon_main_window_complete(main_window *widgets){ widgets->SystemUnitsTree=yon_gtk_builder_get_widget(builder,"SystemUnitsTree"); widgets->MainNotebook=yon_gtk_builder_get_widget(builder,"MainNotebook"); + widgets->TooltipBox=yon_gtk_builder_get_widget(builder,"TooltipBox"); + widgets->NameLabel=yon_gtk_builder_get_widget(builder,"NameLabel"); + widgets->DescriptionLabel=yon_gtk_builder_get_widget(builder,"DescriptionLabel"); + widgets->UnitLabel=yon_gtk_builder_get_widget(builder,"UnitLabel"); + widgets->StatusQueryLabel=yon_gtk_builder_get_widget(builder,"StatusQueryLabel"); + widgets->ActivateLabel=yon_gtk_builder_get_widget(builder,"ActivateLabel"); + widgets->DeactivateLabel=yon_gtk_builder_get_widget(builder,"DeactivateLabel"); + widgets->SystemServicesStatusMenuItem=yon_gtk_builder_get_widget(builder,"SystemServicesStatusMenuItem"); widgets->InstalledUnitsStatusMenuItem=yon_gtk_builder_get_widget(builder,"InstalledUnitsStatusMenuItem"); widgets->UnitsStatusListMenuItem=yon_gtk_builder_get_widget(builder,"UnitsStatusListMenuItem"); @@ -1583,6 +1670,9 @@ void yon_main_window_complete(main_window *widgets){ GList *list = gtk_tree_view_get_columns(GTK_TREE_VIEW(widgets->SystemUnitsTree)); yon_gtk_tree_view_minimal_fixed_size_set_full(GTK_TREE_VIEW(widgets->SystemUnitsTree)); + g_signal_connect(G_OBJECT(widgets->UserUnitsTree),"query-tooltip",G_CALLBACK(on_tooltip_show),widgets); + g_signal_connect(G_OBJECT(widgets->SystemUnitsTree),"query-tooltip",G_CALLBACK(on_tooltip_show),widgets); + g_signal_connect(G_OBJECT(widgets->SystemPrevButton),"clicked",G_CALLBACK(on_system_update_hz_clicked),widgets); g_signal_connect(G_OBJECT(widgets->SystemUpdateButton),"clicked",G_CALLBACK(on_interface_update),widgets); g_signal_connect(G_OBJECT(widgets->SystemServiceUpdateButton),"clicked",G_CALLBACK(on_system_update_clicked),widgets); diff --git a/source/ubl-settings-services.h b/source/ubl-settings-services.h index 45e190d..3c51d16 100644 --- a/source/ubl-settings-services.h +++ b/source/ubl-settings-services.h @@ -75,6 +75,7 @@ #define list_of_sockets_command "systemctl list-sockets --all --no-pager| sed -e 's/ */;/g'" #define list_of_timers_command "systemctl list-timers --all --no-pager| sed -e 's/ */;/g'" #define list_of_session_command "while IFS=\" \" read -r GET_SESSION GET_UID GET_USER GET_SEAT GET_TTY; do echo -e \"${GET_SESSION} $(loginctl session-status ${GET_SESSION} --no-page | sed -Enr \"s/^\\s*State: (.*)$/\1/p\") ${GET_UID} ${GET_USER} ${GET_SEAT} ${GET_TTY}\"; done < <(loginctl list-sessions --no-legend)" +#define get_activate_deactivate_times(target) yon_char_append("systemctl show -p ActiveEnterTimestampMonotonic -p InactiveEnterTimestampMonotonic -p Names ",target) #define config_get_command(target) yon_char_append("cat ",target) @@ -212,6 +213,14 @@ typedef struct { GtkWidget *UserSocketsStatusListMenuItem; GtkWidget *UserTimersStatusListMenuItem; + GtkWidget *TooltipBox; + GtkWidget *NameLabel; + GtkWidget *DescriptionLabel; + GtkWidget *UnitLabel; + GtkWidget *StatusQueryLabel; + GtkWidget *ActivateLabel; + GtkWidget *DeactivateLabel; + GtkTreeModelFilter *SystemFilter; GtkTreeModelFilter *UserFilter; @@ -269,6 +278,8 @@ typedef struct { char *target; } log_window; +gboolean on_tooltip_show(GtkWidget* self, gint x, gint y, gboolean keyboard_mode, GtkTooltip* tooltip, main_window *widgets); + void on_config_local_load(GtkWidget *self,main_window *widgets); void on_config_global_load(GtkWidget *self,main_window *widgets); diff --git a/source/ubl-strings.h b/source/ubl-strings.h index 974fddd..67bde3e 100644 --- a/source/ubl-strings.h +++ b/source/ubl-strings.h @@ -149,5 +149,10 @@ #define SERVICE_RELOAD_SUCCESS_LABEL _("Service has been successfully restarted") #define SAVE_LABEL _("Save") +#define NULL_LABEL _("Null") +#define UNIT_FILE_LABEL _("Unit file:") +#define UNIT_STATE_LABEL _("Unit file state:") +#define ACTIVATED_LABEL _("Activated:") +#define DEACTIVATED_LABEL _("Deactivated:") -#define service_tooltip_template() yon_char_unite("",target,"\n",_("Description:"),description,"\n",_("Unit file:"),unit,"\n",_("Status:"),status,"\n",) \ No newline at end of file +#define service_tooltip_template(target,description,unit,status,activated,deactivated) yon_char_unite("",target,"\n",_("Description:"),description,"\n",_("Unit file:"),unit,"\n",_("Status:"),status,"\n",_("Activated:"),activated,"\n",_("Deactivated:"),deactivated,NULL) \ No newline at end of file diff --git a/ubl-settings-services.glade b/ubl-settings-services.glade index 40e4cca..71fa92c 100644 --- a/ubl-settings-services.glade +++ b/ubl-settings-services.glade @@ -53,6 +53,8 @@ + + @@ -74,6 +76,254 @@ + + True + False + vertical + 5 + + + True + False + 5 + + + True + False + Service: + + + False + True + 0 + + + + + True + False + Service: + True + 0 + + + False + True + 1 + + + + + False + True + 0 + + + + + True + False + + + + False + True + 1 + + + + + True + False + 5 + + + True + False + Description: + + + False + True + 0 + + + + + True + False + Description: + True + 0 + + + False + True + 1 + + + + + False + True + 2 + + + + + True + False + 5 + + + True + False + Unit file: + + + False + True + 0 + + + + + True + False + Unit file: + True + 0 + + + False + True + 1 + + + + + False + True + 3 + + + + + True + False + 5 + + + True + False + Unit file state: + + + False + True + 0 + + + + + True + False + Unit file state: + True + 0 + + + False + True + 1 + + + + + False + True + 4 + + + + + True + False + 5 + + + True + False + Activated: + + + False + True + 0 + + + + + True + False + Activated: + True + 0 + + + False + True + 1 + + + + + False + True + 5 + + + + + True + False + 5 + + + True + False + Deactivated: + + + False + True + 0 + + + + + True + False + Deactivated: + True + 0 + + + False + True + 1 + + + + + False + True + 6 + + + @@ -100,6 +350,8 @@ + + @@ -168,12 +420,12 @@ True False - com.ublinux.ubl-settings-services.update-symbolic + com.ublinux.ubl-settings-services.arrow-round-symbolic True False - com.ublinux.ubl-settings-services.update-symbolic + com.ublinux.ubl-settings-services.arrow-round-symbolic True @@ -675,6 +927,7 @@ SystemList 5 both + 12 @@ -1275,6 +1528,7 @@ UserList 5 both + 12 diff --git a/ubl-settings-services.pot b/ubl-settings-services.pot index 89da742..75c07a8 100644 --- a/ubl-settings-services.pot +++ b/ubl-settings-services.pot @@ -137,7 +137,7 @@ msgstr "" msgid "Service:" msgstr "" -#: source/ubl-strings.h:37 +#: source/ubl-strings.h:37 source/ubl-strings.h:158 msgid "Description:" msgstr "" @@ -489,3 +489,27 @@ msgstr "" #: source/ubl-strings.h:151 msgid "Save" msgstr "" + +#: source/ubl-strings.h:152 +msgid "Null" +msgstr "" + +#: source/ubl-strings.h:153 source/ubl-strings.h:158 +msgid "Unit file:" +msgstr "" + +#: source/ubl-strings.h:154 +msgid "Unit file state:" +msgstr "" + +#: source/ubl-strings.h:155 source/ubl-strings.h:158 +msgid "Activated:" +msgstr "" + +#: source/ubl-strings.h:156 source/ubl-strings.h:158 +msgid "Deactivated:" +msgstr "" + +#: source/ubl-strings.h:158 +msgid "Status:" +msgstr "" diff --git a/ubl-settings-services_ru.po b/ubl-settings-services_ru.po index ee90d38..227a5e7 100644 --- a/ubl-settings-services_ru.po +++ b/ubl-settings-services_ru.po @@ -137,7 +137,7 @@ msgstr "Открыть лог сервиса" msgid "Service:" msgstr "Сервис:" -#: source/ubl-strings.h:37 +#: source/ubl-strings.h:37 source/ubl-strings.h:158 msgid "Description:" msgstr "Описание:" @@ -491,3 +491,27 @@ msgstr "Сервис был успешно перезапущен" #: source/ubl-strings.h:151 msgid "Save" msgstr "Сохранить" + +#: source/ubl-strings.h:152 +msgid "Null" +msgstr "Нет данных" + +#: source/ubl-strings.h:153 source/ubl-strings.h:158 +msgid "Unit file:" +msgstr "Юнит-файл:" + +#: source/ubl-strings.h:154 +msgid "Unit file state:" +msgstr "Статус юнит-файла:" + +#: source/ubl-strings.h:155 source/ubl-strings.h:158 +msgid "Activated:" +msgstr "Активирован:" + +#: source/ubl-strings.h:156 source/ubl-strings.h:158 +msgid "Deactivated:" +msgstr "Деактивирован:" + +#: source/ubl-strings.h:158 +msgid "Status:" +msgstr "Статус:"