changeset 2:7172a0db97af

Use GtkBuilder for all widgets
author Guido Berhoerster <guido+pui@berhoerster.name>
date Wed, 13 Jun 2018 20:06:00 +0200
parents 2f04ec9e0506
children 2fa34d6272c6
files Makefile po/POTFILES.in pui-about-dialog.ui pui-application.c pui-menu.ui pui.gresource.xml
diffstat 6 files changed, 96 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Fri Jun 08 08:38:42 2018 +0200
+++ b/Makefile	Wed Jun 13 20:06:00 2018 +0200
@@ -103,7 +103,8 @@
 		pui-backend.o \
 		pui-get-updates.o \
 		pui-settings.o \
-		pui-types.o
+		pui-types.o \
+		pui-resources.o
 
 $(PACKAGE)-prefs_OBJS = package-update-indicator-prefs.o \
 		pui-prefs-application.o \
--- a/po/POTFILES.in	Fri Jun 08 08:38:42 2018 +0200
+++ b/po/POTFILES.in	Wed Jun 13 20:06:00 2018 +0200
@@ -3,9 +3,11 @@
 org.guido-berhoerster.code.package-update-indicator.preferences.desktop.in
 package-update-indicator-prefs.c
 package-update-indicator.c
+pui-about-dialog.ui
 pui-application.c
 pui-backend.c
 pui-get-updates.c
+pui-menu.ui
 pui-prefs-application.c
 pui-prefs-window.ui
 pui-settings.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pui-about-dialog.ui	Wed Jun 13 20:06:00 2018 +0200
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.20.0 -->
+<interface>
+  <requires lib="gtk+" version="3.20"/>
+  <object class="GtkAboutDialog" id="about-dialog">
+    <property name="can_focus">False</property>
+    <property name="title" translatable="yes">About Package Update Indicator</property>
+    <property name="icon_name">system-software-update</property>
+    <property name="type_hint">dialog</property>
+    <property name="program_name">Package Update Indicator</property>
+    <property name="copyright" translatable="yes">Copyright © 2018 Guido Berhörster</property>
+    <property name="comments" translatable="yes">Notify about available software updates</property>
+    <property name="website">http://code.guido-berhoerster.org/projects/package-update-indicator/</property>
+    <property name="authors">Guido Berhörster</property>
+    <property name="translator_credits" translatable="yes" comments="Place your name here.">Translator</property>
+    <property name="logo_icon_name">system-software-update</property>
+    <property name="wrap_license">True</property>
+    <property name="license_type">mit-x11</property>
+    <child internal-child="vbox">
+      <object class="GtkBox">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox">
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
--- a/pui-application.c	Fri Jun 08 08:38:42 2018 +0200
+++ b/pui-application.c	Wed Jun 13 20:06:00 2018 +0200
@@ -111,27 +111,18 @@
     gpointer user_data)
 {
 	PuiApplication	*self = user_data;
-	const gchar	*translators;
+	GtkBuilder	*builder;
 
 	if (self->about_dialog == NULL) {
-		translators = _("Translators");
-		if (strcmp(translators, "Translators") == 0) {
-			translators = NULL;
-		}
+		/* get dialog from builder */
+		builder = gtk_builder_new_from_resource("/org"
+		    "/guido-berhoerster/code/package-update-indicator"
+		    "/pui-about-dialog.ui");
 
-		self->about_dialog = gtk_about_dialog_new();
-		g_object_set(G_OBJECT(self->about_dialog),
-		    "authors", (gchar *[]){ "Guido Berhoerster", NULL },
-		    "comments", _("Notify about available software updates"),
-		    "copyright", "Copyright \xc2\xa9 2018 Guido Berhoerster",
-		    "license-type", GTK_LICENSE_MIT_X11,
-		    "logo-icon-name", "system-software-update",
-		    "translator-credits", translators,
-		    "version", VERSION,
-		    "website", "https://code.guido-berhoerster.org/projects/"
-		    "package-update-indicator/",
-		    "wrap-license", TRUE,
-		    NULL);
+		self->about_dialog = GTK_WIDGET(gtk_builder_get_object(builder,
+		    "about-dialog"));
+
+		g_object_unref(builder);
 	}
 
 	gtk_dialog_run(GTK_DIALOG(self->about_dialog));
@@ -405,8 +396,8 @@
 {
 	PuiApplication	*self = PUI_APPLICATION(application);
 	gsize		i;
+	GtkBuilder	*builder;
 	GtkWidget	*menu;
-	GtkWidget	*menu_item;
 
 	G_APPLICATION_CLASS(pui_application_parent_class)->startup(application);
 
@@ -433,22 +424,11 @@
 	    "system-software-update",
 	    APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
 
-	/* build menu */
-	menu = gtk_menu_new();
-	gtk_widget_insert_action_group(GTK_WIDGET(menu), "app",
-	    G_ACTION_GROUP(self));
-
-	menu_item = gtk_menu_item_new_with_label(_("Install "
-	    "Updates\342\200\246"));
-	gtk_actionable_set_action_name(GTK_ACTIONABLE(menu_item),
-	    "app.install-updates");
-	gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
-
-	menu_item = gtk_menu_item_new_with_label(_("About\342\200\246"));
-	gtk_actionable_set_action_name(GTK_ACTIONABLE(menu_item),
-	    "app.about");
-	gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
-
+	/* get menu from builder and add it to the indicator */
+	builder = gtk_builder_new_from_resource("/org/guido-berhoerster/code/"
+	    "package-update-indicator/pui-menu.ui");
+	menu = GTK_WIDGET(gtk_builder_get_object(builder, "menu"));
+	gtk_widget_insert_action_group(menu, "app", G_ACTION_GROUP(self));
 	gtk_widget_show_all(menu);
 	app_indicator_set_menu(self->indicator, GTK_MENU(menu));
 
@@ -456,6 +436,8 @@
 
 	/* keep GApplication running */
 	g_application_hold(application);
+
+	g_object_unref(builder);
 }
 
 static void
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pui-menu.ui	Wed Jun 13 20:06:00 2018 +0200
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.20.0 -->
+<interface>
+  <requires lib="gtk+" version="3.20"/>
+  <object class="GtkMenu" id="menu">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <child>
+      <object class="GtkMenuItem">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="action_name">app.install-updates</property>
+        <property name="label" translatable="yes">_Install updates</property>
+        <property name="use_underline">True</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkMenuItem">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="action_name">app.about</property>
+        <property name="label" translatable="yes">_About…</property>
+        <property name="use_underline">True</property>
+      </object>
+    </child>
+  </object>
+</interface>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pui.gresource.xml	Wed Jun 13 20:06:00 2018 +0200
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/guido-berhoerster/code/package-update-indicator">
+    <file compressed="true">pui-menu.ui</file>
+    <file compressed="true">pui-about-dialog.ui</file>
+  </gresource>
+</gresources>