[gnome-applets/wip/muktupavels/timer] timer: port to libgnome-panel



commit 24c0b92dd150b5c6b9ef58e04cdbb51ffb3da173
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Wed Mar 25 00:05:11 2020 +0200

    timer: port to libgnome-panel

 Makefile.am                                        |   5 +-
 configure.ac                                       |   7 +-
 gnome-applets/Makefile.am                          |  36 ++++++
 gnome-applets/ga-module.c                          |  79 ++++++++++++
 {timer/src => gnome-applets/timer}/Makefile.am     |  12 +-
 {timer/src => gnome-applets/timer}/timer-applet.c  | 142 +++++++++++----------
 gnome-applets/timer/timer-applet.h                 |  30 +++++
 po/POTFILES.in                                     |   4 +-
 po/POTFILES.skip                                   |   1 -
 timer/Makefile.am                                  |   5 -
 timer/data/Makefile.am                             |  26 ----
 ...rg.gnome.applets.TimerApplet.panel-applet.in.in |  15 ---
 12 files changed, 228 insertions(+), 134 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 667fef83a..cac5268a4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -25,7 +25,6 @@ always_built_SUBDIRS =  \
        multiload \
        netspeed \
        sticky-notes    \
-       timer \
        trash \
        window-buttons \
        window-picker \
@@ -34,6 +33,7 @@ always_built_SUBDIRS =  \
 
 SUBDIRS = \
        data \
+       gnome-applets \
        help \
        po                      \
        $(always_built_SUBDIRS) \
@@ -41,11 +41,11 @@ SUBDIRS = \
        $(accessx_status_SUBDIR)\
        $(cpufreq_SUBDIR) \
        $(tracker_search_bar_SUBDIR) \
-       $(timer_SUBDIR) \
        $(NULL)
 
 DIST_SUBDIRS = \
        data \
+       gnome-applets \
        help \
        po              \
        drivemount      \
@@ -67,7 +67,6 @@ DIST_SUBDIRS = \
        brightness      \
        tracker-search-bar \
        command         \
-       timer   \
        $(NULL)
 
 EXTRA_DIST = \
diff --git a/configure.ac b/configure.ac
index 3f7abaa41..3cd841cf5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -335,6 +335,9 @@ AC_CONFIG_FILES([
   data/icons/scalable/status/Makefile
   data/schemas/Makefile
 
+  gnome-applets/Makefile
+  gnome-applets/timer/Makefile
+
   help/Makefile
   help/accessx-status/Makefile
   help/battstat/Makefile
@@ -401,10 +404,6 @@ AC_CONFIG_FILES([
   sticky-notes/src/Makefile
   sticky-notes/pixmaps/Makefile
 
-  timer/Makefile
-  timer/data/Makefile
-  timer/src/Makefile
-
   tracker-search-bar/Makefile
   tracker-search-bar/src/Makefile
   tracker-search-bar/data/Makefile
diff --git a/gnome-applets/Makefile.am b/gnome-applets/Makefile.am
new file mode 100644
index 000000000..60c3aff42
--- /dev/null
+++ b/gnome-applets/Makefile.am
@@ -0,0 +1,36 @@
+NULL =
+
+SUBDIRS = \
+       timer \
+       $(NULL)
+
+gnome_applets_libdir = $(GNOME_PANEL_MODULES_DIR)
+gnome_applets_lib_LTLIBRARIES = org.gnome.gnome-applets.la
+
+org_gnome_gnome_applets_la_CPPFLAGS = \
+       -DG_LOG_DOMAIN=\""org.gnome.gnome-applets"\" \
+       -DG_LOG_USE_STRUCTURED=1 \
+       -DLOCALE_DIR=\"$(localedir)\" \
+       $(AM_CPPFLAGS) \
+       $(NULL)
+
+org_gnome_gnome_applets_la_CFLAGS = \
+       $(GNOME_PANEL_CFLAGS) \
+       $(AM_CFLAGS) \
+       $(NULL)
+
+org_gnome_gnome_applets_la_SOURCES = \
+       ga-module.c \
+       $(NULL)
+
+org_gnome_gnome_applets_la_LIBADD = \
+       $(top_builddir)/gnome-applets/timer/libtimer-applet.la \
+       $(GNOME_PANEL_LIBS) \
+       $(NULL)
+
+org_gnome_gnome_applets_la_LDFLAGS = \
+       -module -avoid-version \
+       $(AM_LDFLAGS) \
+       $(NULL)
+
+-include $(top_srcdir)/git.mk
diff --git a/gnome-applets/ga-module.c b/gnome-applets/ga-module.c
new file mode 100644
index 000000000..391c0baaf
--- /dev/null
+++ b/gnome-applets/ga-module.c
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2020 Alberts Muktupāvels
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <glib/gi18n-lib.h>
+#include <libgnome-panel/gp-module.h>
+
+#include "timer/timer-applet.h"
+
+static GpAppletInfo *
+ga_get_applet_info (const char *id)
+{
+  GpGetAppletTypeFunc type_func;
+  const char *name;
+  const char *description;
+  const char *icon_name;
+  GpAppletInfo *info;
+
+  if (g_strcmp0 (id, "timer") == 0)
+    {
+      type_func = timer_applet_get_type;
+      name = _("Timer");
+      description = _("Start a timer and receive a notification when it is finished");
+      icon_name = "gnome-panel-clock";
+    }
+  else
+    {
+      g_assert_not_reached ();
+      return NULL;
+    }
+
+  info = gp_applet_info_new (type_func, name, description, icon_name);
+
+  return info;
+}
+
+static const char *
+ga_get_applet_id_from_iid (const char *iid)
+{
+  if (g_strcmp0 (iid, "TimerAppletFactory::TimerApplet") == 0)
+    return "timer";
+
+  return NULL;
+}
+
+void
+gp_module_load (GpModule *module)
+{
+  bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
+  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+  gp_module_set_gettext_domain (module, GETTEXT_PACKAGE);
+
+  gp_module_set_abi_version (module, GP_MODULE_ABI_VERSION);
+
+  gp_module_set_id (module, "org.gnome.gnome-applets");
+  gp_module_set_version (module, PACKAGE_VERSION);
+
+  gp_module_set_applet_ids (module,
+                            "timer",
+                            NULL);
+
+  gp_module_set_get_applet_info (module, ga_get_applet_info);
+  gp_module_set_compatibility (module, ga_get_applet_id_from_iid);
+}
diff --git a/timer/src/Makefile.am b/gnome-applets/timer/Makefile.am
similarity index 69%
rename from timer/src/Makefile.am
rename to gnome-applets/timer/Makefile.am
index bc9d15d0b..35b39096d 100644
--- a/timer/src/Makefile.am
+++ b/gnome-applets/timer/Makefile.am
@@ -1,19 +1,15 @@
 NULL =
 
-timer_applet_libdir = $(pkglibdir)
-timer_applet_lib_LTLIBRARIES = libtimer-applet.la
+noinst_LTLIBRARIES = libtimer-applet.la
 
 libtimer_applet_la_CPPFLAGS = \
-       -I. \
-       -I$(srcdir) \
        -DG_LOG_DOMAIN=\"org.gnome.gnome-applets.timer\" \
        -DG_LOG_USE_STRUCTURED=1 \
-       -DGNOMELOCALEDIR=\""$(localedir)"\" \
        -DPKG_DATA_DIR=\""$(pkgdatadir)"\" \
        $(NULL)
 
 libtimer_applet_la_CFLAGS = \
-       $(GNOME_APPLETS_CFLAGS) \
+       $(GNOME_PANEL_CFLAGS) \
        $(LIBNOTIFY_CFLAGS) \
        $(WARN_CFLAGS) \
        $(AM_CFLAGS) \
@@ -21,16 +17,16 @@ libtimer_applet_la_CFLAGS = \
 
 libtimer_applet_la_SOURCES = \
        timer-applet.c \
+       timer-applet.h \
        $(NULL)
 
 libtimer_applet_la_LDFLAGS = \
-       -avoid-version \
        $(WARN_LDFLAGS) \
        $(AM_LDFLAGS) \
        $(NULL)
 
 libtimer_applet_la_LIBADD = \
-       $(GNOME_APPLETS_LIBS) \
+       $(GNOME_PANEL_LIBS) \
        $(LIBNOTIFY_LIBS) \
        $(NULL)
 
diff --git a/timer/src/timer-applet.c b/gnome-applets/timer/timer-applet.c
similarity index 83%
rename from timer/src/timer-applet.c
rename to gnome-applets/timer/timer-applet.c
index 82ee6ba0c..6520e711c 100644
--- a/timer/src/timer-applet.c
+++ b/gnome-applets/timer/timer-applet.c
@@ -1,5 +1,4 @@
-/* timerapplet.c:
- *
+/*
  * Copyright (C) 2014 Stefano Karapetsas
  *
  * This file is part of GNOME Applets.
@@ -22,18 +21,16 @@
  *      Stefano Karapetsas <stefano karapetsas com>
  */
 
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
+#include "config.h"
+#include "timer-applet.h"
 
 #include <glib.h>
-#include <glib/gi18n.h>
+#include <glib/gi18n-lib.h>
 #include <gio/gio.h>
 #include <gtk/gtk.h>
 
 #include <libnotify/notify.h>
-
-#include <panel-applet.h>
+#include <libgnome-panel/gp-utils.h>
 
 /* Applet constants */
 #define APPLET_ICON  "gnome-panel-clock"
@@ -46,13 +43,12 @@
 #define SHOW_NOTIFICATION_KEY   "show-notification"
 #define SHOW_DIALOG_KEY         "show-dialog"
 
-typedef struct
+struct _TimerApplet
 {
-    PanelApplet        *applet;
+    GpApplet            parent;
 
     GSettings          *settings;
 
-    GSimpleActionGroup *action_group;
     GtkLabel           *label;
     GtkImage           *image;
     GtkImage           *pause_image;
@@ -67,7 +63,9 @@ typedef struct
     gint                elapsed;
 
     guint               timeout_id;
-} TimerApplet;
+};
+
+G_DEFINE_TYPE (TimerApplet, timer_applet, GP_TYPE_APPLET)
 
 static void timer_start_callback (GSimpleAction *action, GVariant *parameter, gpointer data);
 static void timer_pause_callback (GSimpleAction *action, GVariant *parameter, gpointer data);
@@ -81,9 +79,12 @@ static const GActionEntry applet_menu_actions [] = {
     {"stop", timer_stop_callback, NULL, NULL, NULL},
     {"preferences", timer_preferences_callback, NULL, NULL, NULL},
     {"about", timer_about_callback, NULL, NULL, NULL},
+    {NULL}
 };
 
-static const char *ui = "<section>\
+static const char *ui = "<interface>\
+      <menu id=\"timer-menu\">\
+      <section>\
       <item>\
         <attribute name=\"label\" translatable=\"yes\">_Start timer</attribute>\
         <attribute name=\"action\">timer.start</attribute>\
@@ -104,23 +105,9 @@ static const char *ui = "<section>\
         <attribute name=\"label\" translatable=\"yes\">_About</attribute>\
         <attribute name=\"action\">timer.about</attribute>\
       </item>\
-    </section>";
-
-static void
-timer_applet_destroy (PanelApplet *applet_widget, TimerApplet *applet)
-{
-    g_assert (applet);
-
-    if (applet->timeout_id != 0)
-    {
-        g_source_remove(applet->timeout_id);
-        applet->timeout_id = 0;
-    }
-
-    g_object_unref (applet->settings);
-
-    notify_uninit ();
-}
+    </section>\
+    </menu>\
+    </interface>";
 
 /* timer management */
 static gboolean
@@ -212,10 +199,10 @@ timer_callback (TimerApplet *applet)
     }
 
     /* update actions sensitiveness */
-    g_simple_action_set_enabled (G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP 
(applet->action_group), "start")), !applet->active || applet->pause);
-    g_simple_action_set_enabled (G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP 
(applet->action_group), "pause")), applet->active && !applet->pause);
-    g_simple_action_set_enabled (G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP 
(applet->action_group), "stop")), applet->active);
-    g_simple_action_set_enabled (G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP 
(applet->action_group), "preferences")), !applet->active && !applet->pause);
+    g_simple_action_set_enabled (G_SIMPLE_ACTION (gp_applet_menu_lookup_action (GP_APPLET (applet), 
"start")), !applet->active || applet->pause);
+    g_simple_action_set_enabled (G_SIMPLE_ACTION (gp_applet_menu_lookup_action (GP_APPLET (applet), 
"pause")), applet->active && !applet->pause);
+    g_simple_action_set_enabled (G_SIMPLE_ACTION (gp_applet_menu_lookup_action (GP_APPLET (applet), 
"stop")), applet->active);
+    g_simple_action_set_enabled (G_SIMPLE_ACTION (gp_applet_menu_lookup_action (GP_APPLET (applet), 
"preferences")), !applet->active && !applet->pause);
 
     g_free (name);
 
@@ -394,19 +381,10 @@ timer_settings_changed (GSettings *settings, gchar *key, TimerApplet *applet)
     timer_callback (applet);
 }
 
-static gboolean
-timer_applet_fill (PanelApplet* applet_widget)
+static void
+timer_applet_fill (TimerApplet *applet)
 {
-    TimerApplet *applet;
-
-    if (!notify_is_initted ())
-        notify_init ("timer-applet");
-
-    panel_applet_set_flags (applet_widget, PANEL_APPLET_EXPAND_MINOR);
-
-    applet = g_malloc0(sizeof(TimerApplet));
-    applet->applet = applet_widget;
-    applet->settings = panel_applet_settings_new (applet_widget,TIMER_SCHEMA);
+    applet->settings = gp_applet_settings_new (GP_APPLET (applet), TIMER_SCHEMA);
     applet->timeout_id = 0;
     applet->active = FALSE;
     applet->pause = FALSE;
@@ -416,7 +394,7 @@ timer_applet_fill (PanelApplet* applet_widget)
     applet->pause_image = GTK_IMAGE (gtk_image_new_from_icon_name ("media-playback-pause", 
GTK_ICON_SIZE_BUTTON));
     applet->label = GTK_LABEL (gtk_label_new (""));
 
-    panel_applet_add_text_class (applet_widget, GTK_WIDGET (applet->label));
+    gp_add_text_color_class (GTK_WIDGET (applet->label));
 
     /* we add the Gtk label into the applet */
     gtk_box_pack_start (applet->box,
@@ -429,21 +407,14 @@ timer_applet_fill (PanelApplet* applet_widget)
                         GTK_WIDGET (applet->label),
                         TRUE, TRUE, 3);
 
-    gtk_container_add (GTK_CONTAINER (applet_widget),
+    gtk_container_add (GTK_CONTAINER (applet),
                        GTK_WIDGET (applet->box));
 
-    gtk_widget_show_all (GTK_WIDGET (applet->applet));
+    gtk_widget_show_all (GTK_WIDGET (applet));
     gtk_widget_hide (GTK_WIDGET (applet->pause_image));
 
-    g_signal_connect(G_OBJECT (applet->applet), "destroy",
-                     G_CALLBACK (timer_applet_destroy),
-                     applet);
-
     /* set up context menu */
-    applet->action_group = g_simple_action_group_new ();
-    g_action_map_add_action_entries (G_ACTION_MAP (applet->action_group), applet_menu_actions, 
G_N_ELEMENTS(applet_menu_actions), applet);
-    panel_applet_setup_menu (applet->applet, ui, applet->action_group, GETTEXT_PACKAGE);
-    gtk_widget_insert_action_group (GTK_WIDGET (applet->applet), "timer", G_ACTION_GROUP 
(applet->action_group));
+    gp_applet_setup_menu (GP_APPLET (applet), ui, applet_menu_actions);
 
     /* execute callback to set actions sensitiveness */
     timer_callback (applet);
@@ -451,24 +422,55 @@ timer_applet_fill (PanelApplet* applet_widget)
     /* GSettings callback */
     g_signal_connect (G_OBJECT (applet->settings), "changed",
                       G_CALLBACK (timer_settings_changed), applet);
+}
 
-    return TRUE;
+static void
+timer_applet_constructed (GObject *object)
+{
+  G_OBJECT_CLASS (timer_applet_parent_class)->constructed (object);
+  timer_applet_fill (TIMER_APPLET (object));
 }
 
-/* this function, called by gnome-panel, will create the applet */
-static gboolean
-timer_factory (PanelApplet* applet, const char* iid, gpointer data)
+static void
+timer_applet_finalize (GObject *object)
 {
-    gboolean retval = FALSE;
+  TimerApplet *self;
 
-    if (!g_strcmp0 (iid, "TimerApplet"))
-        retval = timer_applet_fill (applet);
+  self = TIMER_APPLET (object);
 
-    return retval;
+  if (self->timeout_id != 0)
+    {
+      g_source_remove (self->timeout_id);
+      self->timeout_id = 0;
+    }
+
+  g_object_unref (self->settings);
+
+  notify_uninit ();
+
+  G_OBJECT_CLASS (timer_applet_parent_class)->finalize (object);
 }
 
-/* needed by gnome-panel applet library */
-PANEL_APPLET_IN_PROCESS_FACTORY("TimerAppletFactory",
-                                PANEL_TYPE_APPLET,
-                                timer_factory,
-                                NULL)
+static void
+timer_applet_class_init (TimerAppletClass *self_class)
+{
+  GObjectClass *object_class;
+
+  object_class = G_OBJECT_CLASS (self_class);
+
+  object_class->constructed = timer_applet_constructed;
+  object_class->finalize = timer_applet_finalize;
+}
+
+static void
+timer_applet_init (TimerApplet *self)
+{
+  GpApplet *applet;
+
+  applet = GP_APPLET (self);
+
+  if (!notify_is_initted ())
+    notify_init ("timer-applet");
+
+  gp_applet_set_flags (applet, GP_APPLET_FLAGS_EXPAND_MINOR);
+}
diff --git a/gnome-applets/timer/timer-applet.h b/gnome-applets/timer/timer-applet.h
new file mode 100644
index 000000000..17ceed0ef
--- /dev/null
+++ b/gnome-applets/timer/timer-applet.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2020 Alberts Muktupāvels
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TIMER_APPLET_H
+#define TIMER_APPLET_H
+
+#include <libgnome-panel/gp-applet.h>
+
+G_BEGIN_DECLS
+
+#define TIMER_TYPE_APPLET (timer_applet_get_type ())
+G_DECLARE_FINAL_TYPE (TimerApplet, timer_applet, TIMER, APPLET, GpApplet)
+
+G_END_DECLS
+
+#endif
diff --git a/po/POTFILES.in b/po/POTFILES.in
index b6417cffe..e5183c171 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -49,6 +49,8 @@ drivemount/src/drivemount.c
 [type: gettext/ini]geyes/org.gnome.applets.GeyesApplet.panel-applet.in.in
 geyes/src/geyes.c
 geyes/src/themes.c
+gnome-applets/ga-module.c
+gnome-applets/timer/timer-applet.c
 [type: gettext/glade]gweather/gweather-applet-menu.xml
 [type: gettext/ini]gweather/org.gnome.applets.GWeatherApplet.panel-applet.in.in
 gweather/src/gweather-applet.c
@@ -93,8 +95,6 @@ sticky-notes/src/stickynotes_callbacks.c
 [type: gettext/glade]sticky-notes/src/sticky-notes-note.ui
 [type: gettext/glade]sticky-notes/src/sticky-notes-preferences.ui
 [type: gettext/glade]sticky-notes/src/sticky-notes-properties.ui
-[type: gettext/ini]timer/data/org.gnome.applets.TimerApplet.panel-applet.in.in
-timer/src/timer-applet.c
 [type: gettext/ini]tracker-search-bar/data/org.gnome.panel.SearchBar.panel-applet.in.in
 tracker-search-bar/src/tracker-applet.c
 tracker-search-bar/src/tracker-results-window.c
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 0f2a8e625..3dc0eff09 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -32,7 +32,6 @@ mini-commander/src/org.gnome.applets.MiniCommanderApplet.panel-applet.in
 multiload/org.gnome.applets.MultiLoadApplet.panel-applet.in
 netspeed/data/org.gnome.panel.Netspeed.panel-applet.in
 sticky-notes/data/org.gnome.applets.StickyNotesApplet.panel-applet.in
-timer/data/org.gnome.applets.TimerApplet.panel-applet.in
 tracker-search-bar/data/org.gnome.panel.SearchBar.panel-applet.in
 trash/data/org.gnome.applets.TrashApplet.panel-applet.in
 window-buttons/org.gnome.panel.WindowButtonsApplet.panel-applet.in


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]