From aee2a8abdb50314e3e32f7bc7385172b0729a1a1 Mon Sep 17 00:00:00 2001 From: rbuj Date: Wed, 27 May 2020 15:11:48 +0200 Subject: timerapplet: Add timerapplet-preferences.ui --- po/POTFILES.in | 1 + timerapplet/Makefile.am | 42 ++++- timerapplet/timerapplet-preferences.ui | 235 ++++++++++++++++++++++++ timerapplet/timerapplet-resources.gresource.xml | 6 + timerapplet/timerapplet.c | 98 +++------- 5 files changed, 307 insertions(+), 75 deletions(-) create mode 100644 timerapplet/timerapplet-preferences.ui create mode 100644 timerapplet/timerapplet-resources.gresource.xml diff --git a/po/POTFILES.in b/po/POTFILES.in index 0195c0f3..a5fe9f59 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -67,6 +67,7 @@ stickynotes/stickynotes_callbacks.c timerapplet/org.mate.applets.TimerApplet.mate-panel-applet.desktop.in.in timerapplet/org.mate.panel.applet.timer.gschema.xml.in timerapplet/timerapplet.c +timerapplet/timerapplet-preferences.ui trashapplet/org.mate.applets.TrashApplet.mate-panel-applet.desktop.in.in trashapplet/src/trashapplet.c trashapplet/src/trash-empty.c diff --git a/timerapplet/Makefile.am b/timerapplet/Makefile.am index 7a69c74a..520c9553 100644 --- a/timerapplet/Makefile.am +++ b/timerapplet/Makefile.am @@ -1,3 +1,5 @@ +NULL = + AM_CPPFLAGS = \ $(MATE_APPLETS4_CFLAGS) \ $(LIBNOTIFY_CFLAGS) \ @@ -7,10 +9,26 @@ AM_CPPFLAGS = \ APPLET_LOCATION = $(libexecdir)/timer-applet libexec_PROGRAMS = timer-applet -timer_applet_SOURCES = timerapplet.c -timer_applet_LDADD = $(MATE_APPLETS4_LIBS) $(LIBNOTIFY_LIBS) + +BUILT_SOURCES = timerapplet-resources.c timerapplet-resources.h +nodist_timer_applet_SOURCES = $(BUILT_SOURCES) +timer_applet_SOURCES = \ + timerapplet.c \ + $(NULL) + +timer_applet_LDADD = \ + $(MATE_APPLETS4_LIBS) \ + $(LIBNOTIFY_LIBS) \ + $(NULL) + timer_applet_CFLAGS = $(WARN_CFLAGS) +timerapplet-resources.c: timerapplet-resources.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/timerapplet-resources.gresource.xml) + $(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate --c-name timerapplet $< + +timerapplet-resources.h: timerapplet-resources.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/timerapplet-resources.gresource.xml) + $(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate --c-name timerapplet $< + appletsdir = $(datadir)/mate-panel/applets applets_in_files = org.mate.applets.TimerApplet.mate-panel-applet.desktop.in applets_DATA = $(applets_in_files:.mate-panel-applet.desktop.in=.mate-panel-applet) @@ -35,11 +53,21 @@ timer_gschema_in_files = org.mate.panel.applet.timer.gschema.xml.in gsettings_SCHEMAS = $(timer_gschema_in_files:.xml.in=.xml) @GSETTINGS_RULES@ -EXTRA_DIST = \ - $(applets_in_files).in \ - $(service_in_files) \ - $(timer_gschema_in_files) +EXTRA_DIST = \ + $(applets_in_files).in \ + $(service_in_files) \ + $(timer_gschema_in_files) \ + timerapplet-preferences.ui \ + timerapplet-resources.gresource.xml \ + $(NULL) -CLEANFILES = $(applets_DATA) $(applets_in_files) $(service_DATA) $(gsettings_SCHEMAS) *.gschema.valid +CLEANFILES = \ + $(BUILT_SOURCES) \ + $(applets_DATA) \ + $(applets_in_files) \ + $(service_DATA) \ + $(gsettings_SCHEMAS) \ + *.gschema.valid \ + $(NULL) -include $(top_srcdir)/git.mk diff --git a/timerapplet/timerapplet-preferences.ui b/timerapplet/timerapplet-preferences.ui new file mode 100644 index 00000000..04e13e7d --- /dev/null +++ b/timerapplet/timerapplet-preferences.ui @@ -0,0 +1,235 @@ + + + + + + 23 + 1 + 10 + + + True + False + window-close + + + 59 + 1 + 10 + + + 59 + 1 + 10 + + + False + 12 + Timer Applet Preferences + dialog + + + False + vertical + 2 + + + False + end + + + _Close + True + True + True + image1 + True + True + + + True + True + 0 + + + + + False + False + 0 + + + + + True + False + vertical + 6 + + + True + False + 6 + 12 + + + True + False + start + _Name: + True + name_entry + + + 0 + 0 + + + + + True + False + start + _Hours: + True + hours_spinbutton + + + 0 + 1 + + + + + True + False + start + _Minutes: + True + minutes_spinbutton + + + 0 + 2 + + + + + True + False + start + _Seconds: + True + seconds_spinbutton + + + 0 + 3 + + + + + True + True + True + + + 1 + 0 + + + + + True + True + True + hours_adjustment + + + + 1 + 1 + + + + + True + True + True + minutes_adjustment + + + + 1 + 2 + + + + + True + True + True + seconds_adjustment + + + + 1 + 3 + + + + + False + True + 0 + + + + + Show notification _popup + True + True + False + start + True + True + + + False + True + 1 + + + + + Show _dialog + True + True + False + start + True + True + + + False + True + 2 + + + + + False + True + 1 + + + + + + button1 + + + + + + diff --git a/timerapplet/timerapplet-resources.gresource.xml b/timerapplet/timerapplet-resources.gresource.xml new file mode 100644 index 00000000..71b7915a --- /dev/null +++ b/timerapplet/timerapplet-resources.gresource.xml @@ -0,0 +1,6 @@ + + + + timerapplet-preferences.ui + + diff --git a/timerapplet/timerapplet.c b/timerapplet/timerapplet.c index 3dd2abf5..bf862e33 100644 --- a/timerapplet/timerapplet.c +++ b/timerapplet/timerapplet.c @@ -45,6 +45,10 @@ #define SHOW_NOTIFICATION_KEY "show-notification" #define SHOW_DIALOG_KEY "show-dialog" +#define GET_WIDGET(x) (GTK_WIDGET (gtk_builder_get_object (builder, (x)))) +#define GET_DIALOG(x) (GTK_DIALOG (gtk_builder_get_object (builder, (x)))) +#define GET_SPIN_BUTTON(x) (GTK_SPIN_BUTTON (gtk_builder_get_object (builder, (x)))) + typedef struct { MatePanelApplet *applet; @@ -286,7 +290,7 @@ timer_spin_button_value_changed (GtkSpinButton *spinbutton, TimerApplet *applet) { gint duration = 0; - duration += gtk_spin_button_get_value (applet->hours) * 60 * 60; + duration += gtk_spin_button_get_value (applet->hours) * 3600; duration += gtk_spin_button_get_value (applet->minutes) * 60; duration += gtk_spin_button_get_value (applet->seconds); @@ -297,83 +301,41 @@ timer_spin_button_value_changed (GtkSpinButton *spinbutton, TimerApplet *applet) static void timer_preferences_callback (GtkAction *action, TimerApplet *applet) { + GtkBuilder *builder; GtkDialog *dialog; - GtkGrid *grid; - GtkWidget *widget; gint duration, hours, minutes, seconds; + builder = gtk_builder_new_from_resource ("/org/mate/mate-applets/timerapplet/timerapplet-preferences.ui"); + + dialog = GET_DIALOG ("preferences_dialog"); + applet->hours = GET_SPIN_BUTTON ("hours_spinbutton"); + applet->minutes = GET_SPIN_BUTTON ("minutes_spinbutton"); + applet->seconds = GET_SPIN_BUTTON ("seconds_spinbutton"); + duration = g_settings_get_int (applet->settings, DURATION_KEY); hours = duration / 60 / 60; minutes = duration / 60 % 60; seconds = duration % 60; - dialog = GTK_DIALOG (gtk_dialog_new_with_buttons(_("Timer Applet Preferences"), - NULL, - GTK_DIALOG_MODAL, - "gtk-close", - GTK_RESPONSE_CLOSE, - NULL)); - grid = GTK_GRID (gtk_grid_new ()); - gtk_grid_set_row_spacing (grid, 12); - gtk_grid_set_column_spacing (grid, 12); - - gtk_window_set_default_size (GTK_WINDOW (dialog), 350, 150); - gtk_container_set_border_width (GTK_CONTAINER (dialog), 10); - - widget = gtk_label_new (_("Name:")); - gtk_label_set_xalign (GTK_LABEL (widget), 1.0); - gtk_label_set_yalign (GTK_LABEL (widget), 0.5); - gtk_grid_attach (grid, widget, 1, 0, 1, 1); - - widget = gtk_entry_new (); - gtk_grid_attach (grid, widget, 2, 0, 1, 1); - g_settings_bind (applet->settings, NAME_KEY, widget, "text", G_SETTINGS_BIND_DEFAULT); - - widget = gtk_label_new (_("Hours:")); - gtk_label_set_xalign (GTK_LABEL (widget), 1.0); - gtk_label_set_yalign (GTK_LABEL (widget), 0.5); - gtk_grid_attach (grid, widget, 1, 1, 1, 1); - - widget = gtk_spin_button_new_with_range (0.0, 100.0, 1.0); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), hours); - gtk_grid_attach (grid, widget, 2, 1, 1, 1); - applet->hours = GTK_SPIN_BUTTON (widget); - g_signal_connect (widget, "value-changed", G_CALLBACK (timer_spin_button_value_changed), applet); - - widget = gtk_label_new (_("Minutes:")); - gtk_label_set_xalign (GTK_LABEL (widget), 1.0); - gtk_label_set_yalign (GTK_LABEL (widget), 0.5); - gtk_grid_attach (grid, widget, 1, 2, 1, 1); - - widget = gtk_spin_button_new_with_range (0.0, 59.0, 1.0); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), minutes); - gtk_grid_attach (grid, widget, 2, 2, 1, 1);; - applet->minutes = GTK_SPIN_BUTTON (widget); - g_signal_connect (widget, "value-changed", G_CALLBACK (timer_spin_button_value_changed), applet); - - widget = gtk_label_new (_("Seconds:")); - gtk_label_set_xalign (GTK_LABEL (widget), 1.0); - gtk_label_set_yalign (GTK_LABEL (widget), 0.5); - gtk_grid_attach (grid, widget, 1, 3, 1, 1); - - widget = gtk_spin_button_new_with_range (0.0, 59.0, 1.0); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), seconds); - gtk_grid_attach (grid, widget, 2, 3, 1, 1); - applet->seconds = GTK_SPIN_BUTTON (widget); - g_signal_connect (widget, "value-changed", G_CALLBACK (timer_spin_button_value_changed), applet); - - widget = gtk_check_button_new_with_label (_("Show notification popup")); - gtk_grid_attach (grid, widget, 2, 4, 1, 1); - g_settings_bind (applet->settings, SHOW_NOTIFICATION_KEY, widget, "active", G_SETTINGS_BIND_DEFAULT); - - widget = gtk_check_button_new_with_label (_("Show dialog")); - gtk_grid_attach (grid, widget, 2, 5, 1, 1); - g_settings_bind (applet->settings, SHOW_DIALOG_KEY, widget, "active", G_SETTINGS_BIND_DEFAULT); - - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (dialog)), GTK_WIDGET (grid), TRUE, TRUE, 0); - + gtk_spin_button_set_value (applet->hours, hours); + gtk_spin_button_set_value (applet->minutes, minutes); + gtk_spin_button_set_value (applet->seconds, seconds); + + g_settings_bind (applet->settings, NAME_KEY, GET_WIDGET ("name_entry"), "text", G_SETTINGS_BIND_DEFAULT); + g_settings_bind (applet->settings, SHOW_NOTIFICATION_KEY, GET_WIDGET ("show_notification_popup_check"), "active", G_SETTINGS_BIND_DEFAULT); + g_settings_bind (applet->settings, SHOW_DIALOG_KEY, GET_WIDGET ("show_dialog_check"), "active", G_SETTINGS_BIND_DEFAULT); + + /* signals */ + gtk_builder_add_callback_symbols (builder, + "on_hours_spinbutton_value_changed", G_CALLBACK (timer_spin_button_value_changed), + "on_minutes_spinbutton_value_changed", G_CALLBACK (timer_spin_button_value_changed), + "on_seconds_spinbutton_value_changed", G_CALLBACK (timer_spin_button_value_changed), + NULL); + gtk_builder_connect_signals (builder, applet); g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), dialog); + g_object_unref (builder); + gtk_widget_show_all (GTK_WIDGET (dialog)); } -- cgit v1.2.1