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



commit 27b096ee83f3518e8136ca3f64d77a6f6fc6b06a
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Fri Mar 27 23:38:24 2020 +0200

    command: port to libgnome-panel

 Makefile.am                                        |   2 -
 command/Makefile.am                                |  25 -----
 ....gnome.applets.CommandApplet.panel-applet.in.in |  15 ---
 configure.ac                                       |   4 +-
 gnome-applets/Makefile.am                          |   2 +
 {command/src => gnome-applets/command}/Makefile.am |  12 +--
 .../command/command-applet.c                       | 109 +++++++++++----------
 gnome-applets/command/command-applet.h             |  30 ++++++
 .../src => gnome-applets/command}/ga-command.c     |   0
 .../src => gnome-applets/command}/ga-command.h     |   0
 gnome-applets/ga-module.c                          |  11 +++
 po/POTFILES.in                                     |   3 +-
 po/POTFILES.skip                                   |   1 -
 13 files changed, 105 insertions(+), 109 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 0ccba26ee..c57098700 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -15,7 +15,6 @@ endif
 always_built_SUBDIRS =  \
        charpick        \
        battstat \
-       command         \
        drivemount      \
        inhibit         \
        geyes           \
@@ -58,7 +57,6 @@ DIST_SUBDIRS = \
        window-title    \
        inhibit         \
        tracker-search-bar \
-       command         \
        $(NULL)
 
 EXTRA_DIST = \
diff --git a/configure.ac b/configure.ac
index cd9d93d3c..492b40033 100644
--- a/configure.ac
+++ b/configure.ac
@@ -337,6 +337,7 @@ AC_CONFIG_FILES([
 
   gnome-applets/Makefile
   gnome-applets/brightness/Makefile
+  gnome-applets/command/Makefile
   gnome-applets/gweather/Makefile
   gnome-applets/timer/Makefile
   gnome-applets/trash/Makefile
@@ -368,9 +369,6 @@ AC_CONFIG_FILES([
   charpick/Makefile
   charpick/src/Makefile
 
-  command/Makefile
-  command/src/Makefile
-
   cpufreq/Makefile
   cpufreq/pixmaps/Makefile
   cpufreq/src/cpufreq-selector/Makefile
diff --git a/gnome-applets/Makefile.am b/gnome-applets/Makefile.am
index 9ce3dcbfe..6ee4125fe 100644
--- a/gnome-applets/Makefile.am
+++ b/gnome-applets/Makefile.am
@@ -2,6 +2,7 @@ NULL =
 
 SUBDIRS = \
        brightness \
+       command \
        gweather \
        timer \
        trash \
@@ -30,6 +31,7 @@ org_gnome_gnome_applets_la_SOURCES = \
 
 org_gnome_gnome_applets_la_LIBADD = \
        $(top_builddir)/gnome-applets/brightness/libbrightness-applet.la \
+       $(top_builddir)/gnome-applets/command/libcommand-applet.la \
        $(top_builddir)/gnome-applets/gweather/libgweather-applet.la \
        $(top_builddir)/gnome-applets/timer/libtimer-applet.la \
        $(top_builddir)/gnome-applets/trash/libtrash-applet.la \
diff --git a/command/src/Makefile.am b/gnome-applets/command/Makefile.am
similarity index 70%
rename from command/src/Makefile.am
rename to gnome-applets/command/Makefile.am
index 023e1cecc..f743d15bf 100644
--- a/command/src/Makefile.am
+++ b/gnome-applets/command/Makefile.am
@@ -1,37 +1,35 @@
 NULL =
 
-command_applet_libdir = $(pkglibdir)
-command_applet_lib_LTLIBRARIES = libcommand-applet.la
+noinst_LTLIBRARIES = libcommand-applet.la
 
 libcommand_applet_la_CPPFLAGS = \
        -I. \
        -I$(srcdir) \
-       -DGNOMELOCALEDIR=\""$(localedir)"\" \
        -DPKG_DATA_DIR=\""$(pkgdatadir)"\" \
        -DG_LOG_DOMAIN=\"org.gnome.gnome-applets.command\" \
        -DG_LOG_USE_STRUCTURED=1 \
        $(NULL)
 
 libcommand_applet_la_CFLAGS = \
-       $(GNOME_APPLETS_CFLAGS) \
+       $(GNOME_PANEL_CFLAGS) \
        $(WARN_CFLAGS) \
        $(AM_CFLAGS) \
        $(NULL)
 
 libcommand_applet_la_SOURCES = \
-       command.c \
+       command-applet.c \
+       command-applet.h \
        ga-command.c \
        ga-command.h \
        $(NULL)
 
 libcommand_applet_la_LDFLAGS = \
-       -avoid-version \
        $(WARN_LDFLAGS) \
        $(AM_LDFLAGS) \
        $(NULL)
 
 libcommand_applet_la_LIBADD = \
-       $(GNOME_APPLETS_LIBS) \
+       $(GNOME_PANEL_LIBS) \
        $(NULL)
 
 -include $(top_srcdir)/git.mk
diff --git a/command/src/command.c b/gnome-applets/command/command-applet.c
similarity index 84%
rename from command/src/command.c
rename to gnome-applets/command/command-applet.c
index 50fcd54f3..07faa12bd 100644
--- a/command/src/command.c
+++ b/gnome-applets/command/command-applet.c
@@ -1,5 +1,4 @@
-/* command.c:
- *
+/*
  * Copyright (C) 2013-2014 Stefano Karapetsas
  *
  * This file is part of GNOME Applets.
@@ -23,14 +22,15 @@
  */
 
 #include "config.h"
-#include "ga-command.h"
+#include "command-applet.h"
 
 #include <glib.h>
-#include <glib/gi18n.h>
+#include <glib/gi18n-lib.h>
 #include <gio/gio.h>
 #include <gtk/gtk.h>
+#include <libgnome-panel/gp-utils.h>
 
-#include <panel-applet.h>
+#include "ga-command.h"
 
 /* Applet constants */
 #define APPLET_ICON    "utilities-terminal"
@@ -48,9 +48,9 @@
 #define GK_COMMAND_OUTPUT  "Output"
 #define GK_COMMAND_ICON    "Icon"
 
-typedef struct
+struct _CommandApplet
 {
-  PanelApplet *applet;
+  GpApplet     parent;
 
   GSettings   *settings;
 
@@ -61,7 +61,9 @@ typedef struct
   guint        width;
 
   GaCommand   *command;
-} CommandApplet;
+};
+
+G_DEFINE_TYPE (CommandApplet, command_applet, GP_TYPE_APPLET)
 
 static void command_about_callback (GSimpleAction *action, GVariant *parameter, gpointer data);
 static void command_settings_callback (GSimpleAction *action, GVariant *parameter, gpointer data);
@@ -69,9 +71,12 @@ static void command_settings_callback (GSimpleAction *action, GVariant *paramete
 static const GActionEntry applet_menu_actions [] = {
     {"preferences", command_settings_callback, NULL, NULL, NULL},
     {"about", command_about_callback, NULL, NULL, NULL},
+    {NULL}
 };
 
-static const char *ui = "<section>\
+static const char *ui = "<interface>\
+    <menu id=\"command-menu\">\
+    <section>\
       <item>\
         <attribute name=\"label\" translatable=\"yes\">_Preferences</attribute>\
         <attribute name=\"action\">command.preferences</attribute>\
@@ -80,17 +85,9 @@ static const char *ui = "<section>\
         <attribute name=\"label\" translatable=\"yes\">_About</attribute>\
         <attribute name=\"action\">command.about</attribute>\
       </item>\
-    </section>";
-
-static void
-command_applet_destroy (PanelApplet *applet_widget, CommandApplet *command_applet)
-{
-    g_assert (command_applet);
-
-    g_clear_object (&command_applet->command);
-
-    g_object_unref (command_applet->settings);
-}
+    </section>\
+    </menu>\
+    </interface>";
 
 /* Show the about dialog */
 static void
@@ -328,17 +325,11 @@ settings_interval_changed (GSettings     *settings,
                            g_settings_get_uint (self->settings, INTERVAL_KEY));
 }
 
-static gboolean
-command_applet_fill (PanelApplet* applet)
+static void
+command_applet_fill (CommandApplet *command_applet)
 {
-    CommandApplet *command_applet;
-    GSimpleActionGroup *action_group;
-
-    panel_applet_set_flags (applet, PANEL_APPLET_EXPAND_MINOR);
-
-    command_applet = g_malloc0(sizeof(CommandApplet));
-    command_applet->applet = applet;
-    command_applet->settings = panel_applet_settings_new (applet, COMMAND_SCHEMA);
+    command_applet->settings = gp_applet_settings_new (GP_APPLET (command_applet),
+                                                       COMMAND_SCHEMA);
 
     command_applet->width = g_settings_get_uint (command_applet->settings, WIDTH_KEY);
 
@@ -354,16 +345,12 @@ command_applet_fill (PanelApplet* applet)
                         GTK_WIDGET (command_applet->label),
                         TRUE, TRUE, 0);
 
-    panel_applet_add_text_class (command_applet->applet, GTK_WIDGET (command_applet->label));
+    gp_add_text_color_class (GTK_WIDGET (command_applet->label));
 
-    gtk_container_add (GTK_CONTAINER (applet),
+    gtk_container_add (GTK_CONTAINER (command_applet),
                        GTK_WIDGET (command_applet->box));
 
-    gtk_widget_show_all (GTK_WIDGET (command_applet->applet));
-
-    g_signal_connect(G_OBJECT (command_applet->applet), "destroy",
-                     G_CALLBACK (command_applet_destroy),
-                     command_applet);
+    gtk_widget_show_all (GTK_WIDGET (command_applet));
 
     /* GSettings signals */
     g_signal_connect(command_applet->settings,
@@ -385,31 +372,45 @@ command_applet_fill (PanelApplet* applet)
                      G_SETTINGS_BIND_DEFAULT);
 
     /* set up context menu */
-    action_group = g_simple_action_group_new ();
-    g_action_map_add_action_entries (G_ACTION_MAP (action_group), applet_menu_actions, 
G_N_ELEMENTS(applet_menu_actions), command_applet);
-    panel_applet_setup_menu (applet, ui, action_group, GETTEXT_PACKAGE);
-    gtk_widget_insert_action_group (GTK_WIDGET (applet), "command", G_ACTION_GROUP (action_group));
+    gp_applet_setup_menu (GP_APPLET (command_applet), ui, applet_menu_actions);
 
     /* first command execution */
     create_command (command_applet);
+}
+
+static void
+command_applet_constructed (GObject *object)
+{
+  G_OBJECT_CLASS (command_applet_parent_class)->constructed (object);
+  command_applet_fill (COMMAND_APPLET (object));
+}
+
+static void
+command_applet_dispose (GObject *object)
+{
+  CommandApplet *self;
+
+  self = COMMAND_APPLET (object);
+
+  g_clear_object (&self->settings);
+  g_clear_object (&self->command);
 
-    return TRUE;
+  G_OBJECT_CLASS (command_applet_parent_class)->dispose (object);
 }
 
-/* this function, called by gnome-panel, will create the applet */
-static gboolean
-command_factory (PanelApplet* applet, const char* iid, gpointer data)
+static void
+command_applet_class_init (CommandAppletClass *self_class)
 {
-    gboolean retval = FALSE;
+  GObjectClass *object_class;
 
-    if (!g_strcmp0 (iid, "CommandApplet"))
-        retval = command_applet_fill (applet);
+  object_class = G_OBJECT_CLASS (self_class);
 
-    return retval;
+  object_class->constructed = command_applet_constructed;
+  object_class->dispose = command_applet_dispose;
 }
 
-/* needed by gnome-panel applet library */
-PANEL_APPLET_IN_PROCESS_FACTORY("CommandAppletFactory",
-                                PANEL_TYPE_APPLET,
-                                command_factory,
-                                NULL)
+static void
+command_applet_init (CommandApplet *self)
+{
+  gp_applet_set_flags (GP_APPLET (self), GP_APPLET_FLAGS_EXPAND_MINOR);
+}
diff --git a/gnome-applets/command/command-applet.h b/gnome-applets/command/command-applet.h
new file mode 100644
index 000000000..4e83ba110
--- /dev/null
+++ b/gnome-applets/command/command-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 COMMAND_APPLET_H
+#define COMMAND_APPLET_H
+
+#include <libgnome-panel/gp-applet.h>
+
+G_BEGIN_DECLS
+
+#define COMMAND_TYPE_APPLET (command_applet_get_type ())
+G_DECLARE_FINAL_TYPE (CommandApplet, command_applet, COMMAND, APPLET, GpApplet)
+
+G_END_DECLS
+
+#endif
diff --git a/command/src/ga-command.c b/gnome-applets/command/ga-command.c
similarity index 100%
rename from command/src/ga-command.c
rename to gnome-applets/command/ga-command.c
diff --git a/command/src/ga-command.h b/gnome-applets/command/ga-command.h
similarity index 100%
rename from command/src/ga-command.h
rename to gnome-applets/command/ga-command.h
diff --git a/gnome-applets/ga-module.c b/gnome-applets/ga-module.c
index a7e0c4fa8..fd07323fd 100644
--- a/gnome-applets/ga-module.c
+++ b/gnome-applets/ga-module.c
@@ -22,6 +22,7 @@
 #include <libgnome-panel/gp-module.h>
 
 #include "brightness/brightness-applet.h"
+#include "command/command-applet.h"
 #include "gweather/gweather-applet.h"
 #include "timer/timer-applet.h"
 #include "trash/trash-applet.h"
@@ -43,6 +44,13 @@ ga_get_applet_info (const char *id)
       description = _("Adjusts Laptop panel brightness");
       icon_name = "gnome-brightness-applet";
     }
+  else if (g_strcmp0 (id, "command") == 0)
+    {
+      type_func = command_applet_get_type;
+      name = _("Command");
+      description = _("Shows the output of a command");
+      icon_name = "utilities-terminal";
+    }
   else if (g_strcmp0 (id, "gweather") == 0)
     {
       type_func = gweather_applet_get_type;
@@ -87,6 +95,8 @@ ga_get_applet_id_from_iid (const char *iid)
 {
   if (g_strcmp0 (iid, "BrightnessAppletFactory::BrightnessApplet") == 0)
     return "brightness";
+  else if (g_strcmp0 (iid, "CommandAppletFactory::CommandApplet") == 0)
+    return "command";
   else if (g_strcmp0 (iid, "GWeatherAppletFactory::GWeatherApplet") == 0)
     return "gweather";
   else if (g_strcmp0 (iid, "TimerAppletFactory::TimerApplet") == 0)
@@ -114,6 +124,7 @@ gp_module_load (GpModule *module)
 
   gp_module_set_applet_ids (module,
                             "brightness",
+                            "command",
                             "gweather",
                             "timer",
                             "trash",
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5e0da0673..77fa176a4 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -14,8 +14,6 @@ battstat/src/properties.c
 [type: gettext/ini]charpick/org.gnome.applets.CharpickerApplet.panel-applet.in.in
 charpick/src/charpick.c
 charpick/src/properties.c
-[type: gettext/ini]command/org.gnome.applets.CommandApplet.panel-applet.in.in
-command/src/command.c
 [type: gettext/glade]cpufreq/cpufreq-applet-menu.xml
 [type: gettext/glade]cpufreq/cpufreq-preferences.ui
 [type: gettext/ini]cpufreq/org.gnome.applets.CPUFreqApplet.panel-applet.in.in
@@ -47,6 +45,7 @@ geyes/src/geyes.c
 geyes/src/themes.c
 [type: gettext/glade]gnome-applets/brightness/brightness-applet-menu.xml
 gnome-applets/brightness/brightness-applet.c
+gnome-applets/command/command-applet.c
 gnome-applets/ga-module.c
 [type: gettext/glade]gnome-applets/gweather/gweather-applet-menu.xml
 gnome-applets/gweather/gweather-applet.c
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 9f78db162..9a80baf6f 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -6,7 +6,6 @@
 accessx-status/org.gnome.applets.AccessxStatusApplet.panel-applet.in
 battstat/org.gnome.applets.BattstatApplet.panel-applet.in
 charpick/org.gnome.applets.CharpickerApplet.panel-applet.in
-command/org.gnome.applets.CommandApplet.panel-applet.in
 cpufreq/org.gnome.applets.CPUFreqApplet.panel-applet.in
 data/schemas/org.gnome.gnome-applets.battstat.gschema.xml.in
 data/schemas/org.gnome.gnome-applets.charpick.gschema.xml.in


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