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



commit fea7025dcbdcd78431046ed403638935cb2ce555
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Thu Mar 26 02:23:17 2020 +0200

    trash: port to libgnome-panel

 Makefile.am                                        |   2 -
 configure.ac                                       |   5 +-
 gnome-applets/Makefile.am                          |   2 +
 gnome-applets/ga-module.c                          |  11 ++
 {trash/src => gnome-applets/trash}/Makefile.am     |   9 +-
 {trash/src => gnome-applets/trash}/trash-applet.c  | 136 +++++++--------------
 gnome-applets/trash/trash-applet.h                 |  30 +++++
 {trash/src => gnome-applets/trash}/trash-empty.c   |   0
 {trash/src => gnome-applets/trash}/trash-empty.h   |   0
 {trash/src => gnome-applets/trash}/trash-empty.ui  |   0
 gnome-applets/trash/trash-menu.xml                 |  24 ++++
 .../trash}/trash-resources.gresource.xml           |   0
 po/POTFILES.in                                     |   9 +-
 po/POTFILES.skip                                   |   1 -
 trash/Makefile.am                                  |   3 -
 trash/data/Makefile.am                             |  26 ----
 ...rg.gnome.applets.TrashApplet.panel-applet.in.in |  15 ---
 trash/src/trash-applet.h                           |  69 -----------
 trash/src/trash-menu.xml                           |  20 ---
 19 files changed, 122 insertions(+), 240 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index caf17f025..2b8a712d9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -25,7 +25,6 @@ always_built_SUBDIRS =  \
        multiload \
        netspeed \
        sticky-notes    \
-       trash \
        window-buttons \
        window-title \
        $(NULL)
@@ -57,7 +56,6 @@ DIST_SUBDIRS = \
        gweather        \
        accessx-status  \
        sticky-notes    \
-       trash   \
        cpufreq         \
        window-buttons  \
        window-title    \
diff --git a/configure.ac b/configure.ac
index 22539dc35..849acce6a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -337,6 +337,7 @@ AC_CONFIG_FILES([
 
   gnome-applets/Makefile
   gnome-applets/timer/Makefile
+  gnome-applets/trash/Makefile
   gnome-applets/window-picker/Makefile
 
   help/Makefile
@@ -408,10 +409,6 @@ AC_CONFIG_FILES([
   tracker-search-bar/src/Makefile
   tracker-search-bar/data/Makefile
 
-  trash/Makefile
-  trash/src/Makefile
-  trash/data/Makefile
-
   window-buttons/Makefile
   window-buttons/themes/Makefile
 
diff --git a/gnome-applets/Makefile.am b/gnome-applets/Makefile.am
index de07c9752..da0f21187 100644
--- a/gnome-applets/Makefile.am
+++ b/gnome-applets/Makefile.am
@@ -2,6 +2,7 @@ NULL =
 
 SUBDIRS = \
        timer \
+       trash \
        window-picker \
        $(NULL)
 
@@ -26,6 +27,7 @@ org_gnome_gnome_applets_la_SOURCES = \
 
 org_gnome_gnome_applets_la_LIBADD = \
        $(top_builddir)/gnome-applets/timer/libtimer-applet.la \
+       $(top_builddir)/gnome-applets/trash/libtrash-applet.la \
        $(top_builddir)/gnome-applets/window-picker/libwindow-picker-applet.la \
        $(GNOME_PANEL_LIBS) \
        $(NULL)
diff --git a/gnome-applets/ga-module.c b/gnome-applets/ga-module.c
index 24f3172da..75e8567ef 100644
--- a/gnome-applets/ga-module.c
+++ b/gnome-applets/ga-module.c
@@ -22,6 +22,7 @@
 #include <libgnome-panel/gp-module.h>
 
 #include "timer/timer-applet.h"
+#include "trash/trash-applet.h"
 #include "window-picker/wp-applet.h"
 
 static GpAppletInfo *
@@ -40,6 +41,13 @@ ga_get_applet_info (const char *id)
       description = _("Start a timer and receive a notification when it is finished");
       icon_name = "gnome-panel-clock";
     }
+  else if (g_strcmp0 (id, "trash") == 0)
+    {
+      type_func = trash_applet_get_type;
+      name = _("Trash");
+      description = _("Go to Trash");
+      icon_name = "user-trash-full";
+    }
   else if (g_strcmp0 (id, "window-picker") == 0)
     {
       type_func = wp_applet_get_type;
@@ -66,6 +74,8 @@ ga_get_applet_id_from_iid (const char *iid)
   else if (g_strcmp0 (iid, "WindowPickerFactory::WindowPicker") == 0 ||
            g_strcmp0 (iid, "org.gnome.gnome-applets.window-picker::window-picker") == 0)
     return "window-picker";
+  else if (g_strcmp0 (iid, "TrashAppletFactory::TrashApplet") == 0)
+    return "trash";
 
   return NULL;
 }
@@ -84,6 +94,7 @@ gp_module_load (GpModule *module)
 
   gp_module_set_applet_ids (module,
                             "timer",
+                            "trash",
                             "window-picker",
                             NULL);
 
diff --git a/trash/src/Makefile.am b/gnome-applets/trash/Makefile.am
similarity index 87%
rename from trash/src/Makefile.am
rename to gnome-applets/trash/Makefile.am
index 9a41f5878..3e415ac3f 100644
--- a/trash/src/Makefile.am
+++ b/gnome-applets/trash/Makefile.am
@@ -1,10 +1,8 @@
 NULL =
 
-trash_libdir=${pkglibdir}
-trash_lib_LTLIBRARIES=libtrash-applet.la
+noinst_LTLIBRARIES = libtrash-applet.la
 
 libtrash_applet_la_CPPFLAGS = \
-       -DGNOMELOCALEDIR=\""$(localedir)"\" \
        -DG_LOG_DOMAIN=\"org.gnome.gnome-applets.trash\" \
        -DG_LOG_USE_STRUCTURED=1 \
        -I$(top_builddir) \
@@ -12,20 +10,19 @@ libtrash_applet_la_CPPFLAGS = \
        $(NULL)
 
 libtrash_applet_la_CFLAGS = \
-       $(GNOME_APPLETS_CFLAGS) \
+       $(GNOME_PANEL_CFLAGS) \
        $(GIO_CFLAGS) \
        $(WARN_CFLAGS) \
        $(AM_CFLAGS) \
        $(NULL)
 
 libtrash_applet_la_LDFLAGS = \
-       -module -avoid-version \
        $(WARN_LDFLAGS) \
        $(AM_LDFLAGS) \
        $(NULL)
 
 libtrash_applet_la_LIBADD = \
-       $(GNOME_APPLETS_LIBS) \
+       $(GNOME_PANEL_LIBS) \
        $(GIO_LIBS) \
        $(X_LIBS) \
        $(NULL)
diff --git a/trash/src/trash-applet.c b/gnome-applets/trash/trash-applet.c
similarity index 85%
rename from trash/src/trash-applet.c
rename to gnome-applets/trash/trash-applet.c
index 7778334d8..b45a52e21 100644
--- a/trash/src/trash-applet.c
+++ b/gnome-applets/trash/trash-applet.c
@@ -1,5 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8 -*-
- *
+/*
  * Copyright (c) 2004  Michiel Sikkes <michiel eyesopened nl>,
  *               2004  Emmanuele Bassi <ebassi gmail com>
  *               2008  Ryan Lortie <desrt desrt ca>
@@ -19,9 +18,8 @@
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
+#include "trash-applet.h"
 
 #include <string.h>
 
@@ -29,15 +27,12 @@
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
 #include <gio/gio.h>
-#include <panel-applet.h>
 
 #include "trash-empty.h"
 
-typedef PanelAppletClass TrashAppletClass;
-
-typedef struct
+struct _TrashApplet
 {
-  PanelApplet applet;
+  GpApplet parent;
 
   GFileMonitor *trash_monitor;
   GFile *trash;
@@ -45,13 +40,9 @@ typedef struct
   GtkImage *image;
   GIcon *icon;
   gint items;
-} TrashApplet;
+};
 
-GType trash_applet_get_type (void);
-G_DEFINE_TYPE (TrashApplet, trash_applet, PANEL_TYPE_APPLET);
-#define TRASH_TYPE_APPLET (trash_applet_get_type ())
-#define TRASH_APPLET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
-                           TRASH_TYPE_APPLET, TrashApplet))
+G_DEFINE_TYPE (TrashApplet, trash_applet, GP_TYPE_APPLET)
 
 static void trash_applet_do_empty    (GSimpleAction *action,
                                       GVariant      *parameter,
@@ -70,7 +61,8 @@ static const GActionEntry trash_applet_menu_actions [] = {
        { "open",  trash_applet_open_folder, NULL, NULL, NULL },
        { "empty", trash_applet_do_empty,    NULL, NULL, NULL },
        { "help",  trash_applet_show_help,   NULL, NULL, NULL },
-       { "about", trash_applet_show_about,   NULL, NULL, NULL }
+       { "about", trash_applet_show_about,   NULL, NULL, NULL },
+       { NULL }
 };
 
 static void
@@ -160,15 +152,13 @@ trash_applet_size_allocate (GtkWidget    *widget,
 {
   TrashApplet *applet = TRASH_APPLET (widget);
 
-  switch (panel_applet_get_orient (PANEL_APPLET (applet)))
+  switch (gp_applet_get_orientation (GP_APPLET (applet)))
   {
-    case PANEL_APPLET_ORIENT_LEFT:
-    case PANEL_APPLET_ORIENT_RIGHT:
+    case GTK_ORIENTATION_VERTICAL:
       trash_applet_set_icon_size (applet, allocation->width);
       break;
 
-    case PANEL_APPLET_ORIENT_UP:
-    case PANEL_APPLET_ORIENT_DOWN:
+    case GTK_ORIENTATION_HORIZONTAL:
       trash_applet_set_icon_size (applet, allocation->height);
       break;
   }
@@ -201,37 +191,6 @@ trash_applet_dispose (GObject *object)
   G_OBJECT_CLASS (trash_applet_parent_class)->dispose (object);
 }
 
-static void
-trash_applet_init (TrashApplet *applet)
-{
-  const GtkTargetEntry drop_types[] = { { "text/uri-list" } };
-
-  /* needed to clamp ourselves to the panel size */
-  panel_applet_set_flags (PANEL_APPLET (applet), PANEL_APPLET_EXPAND_MINOR);
-
-  /* setup the image */
-  applet->image = g_object_ref_sink (gtk_image_new ());
-  gtk_container_add (GTK_CONTAINER (applet),
-                     GTK_WIDGET (applet->image));
-  gtk_widget_show (GTK_WIDGET (applet->image));
-
-  /* setup the trash backend */
-  applet->trash = g_file_new_for_uri ("trash:/");
-  applet->trash_monitor = g_file_monitor_file (applet->trash, 0, NULL, NULL);
-  g_signal_connect_swapped (applet->trash_monitor, "changed",
-                            G_CALLBACK (trash_applet_monitor_changed),
-                            applet);
-
-  /* setup drag and drop */
-  gtk_drag_dest_set (GTK_WIDGET (applet), GTK_DEST_DEFAULT_ALL,
-                     drop_types, G_N_ELEMENTS (drop_types),
-                     GDK_ACTION_MOVE);
-
-  /* synthesise the first update */
-  applet->items = -1;
-  trash_applet_monitor_changed (applet);
-}
-
 static gboolean
 trash_applet_button_release (GtkWidget      *widget,
                              GdkEventButton *event)
@@ -579,12 +538,16 @@ trash_applet_drag_data_received (GtkWidget        *widget,
 }
 
 static void
-trash_applet_class_init (TrashAppletClass *class)
+trash_applet_class_init (TrashAppletClass *self_class)
 {
-  GObjectClass *gobject_class = G_OBJECT_CLASS (class);
-  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+  GObjectClass *object_class;
+  GtkWidgetClass *widget_class;
+
+  object_class = G_OBJECT_CLASS (self_class);
+  widget_class = GTK_WIDGET_CLASS (self_class);
+
+  object_class->dispose = trash_applet_dispose;
 
-  gobject_class->dispose = trash_applet_dispose;
   widget_class->size_allocate = trash_applet_size_allocate;
   widget_class->button_release_event = trash_applet_button_release;
   widget_class->key_press_event = trash_applet_key_press;
@@ -592,44 +555,39 @@ trash_applet_class_init (TrashAppletClass *class)
   widget_class->drag_data_received = trash_applet_drag_data_received;
 }
 
-static gboolean
-trash_applet_factory (PanelApplet *applet,
-                      const gchar *iid,
-                      gpointer     data)
+static void
+trash_applet_init (TrashApplet *self)
 {
-  gboolean retval = FALSE;
-
-  if (!strcmp (iid, "TrashApplet"))
-    {
-      GSimpleActionGroup *action_group;
-      const gchar *resource_name;
-
-      /* Set up the menu */
-      action_group = g_simple_action_group_new ();
-      g_action_map_add_action_entries (G_ACTION_MAP (action_group),
-                                       trash_applet_menu_actions,
-                                       G_N_ELEMENTS (trash_applet_menu_actions),
-                                       applet);
-
-      resource_name = "/org/gnome/gnome-applets/trash/trash-menu.xml";
+  const GtkTargetEntry drop_types[] = { { "text/uri-list" } };
+  const gchar *resource_name;
 
-      panel_applet_setup_menu_from_resource (applet, resource_name,
-                                             action_group, GETTEXT_PACKAGE);
+  /* needed to clamp ourselves to the panel size */
+  gp_applet_set_flags (GP_APPLET (self), GP_APPLET_FLAGS_EXPAND_MINOR);
 
-      gtk_widget_insert_action_group (GTK_WIDGET (applet), "trash",
-                                      G_ACTION_GROUP (action_group));
+  /* Set up the menu */
+  resource_name = "/org/gnome/gnome-applets/trash/trash-menu.xml";
+  gp_applet_setup_menu_from_resource (GP_APPLET (self),
+                                      resource_name,
+                                      trash_applet_menu_actions);
 
-      g_object_unref (action_group);
+  /* setup the image */
+  self->image = g_object_ref_sink (gtk_image_new ());
+  gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (self->image));
+  gtk_widget_show (GTK_WIDGET (self->image));
 
-      gtk_widget_show (GTK_WIDGET (applet));
+  /* setup the trash backend */
+  self->trash = g_file_new_for_uri ("trash:/");
+  self->trash_monitor = g_file_monitor_file (self->trash, 0, NULL, NULL);
+  g_signal_connect_swapped (self->trash_monitor, "changed",
+                            G_CALLBACK (trash_applet_monitor_changed),
+                            self);
 
-      retval = TRUE;
-  }
+  /* setup drag and drop */
+  gtk_drag_dest_set (GTK_WIDGET (self), GTK_DEST_DEFAULT_ALL,
+                     drop_types, G_N_ELEMENTS (drop_types),
+                     GDK_ACTION_MOVE);
 
-  return retval;
+  /* synthesise the first update */
+  self->items = -1;
+  trash_applet_monitor_changed (self);
 }
-
-PANEL_APPLET_IN_PROCESS_FACTORY ("TrashAppletFactory",
-                                 TRASH_TYPE_APPLET,
-                                 trash_applet_factory,
-                                 NULL)
diff --git a/gnome-applets/trash/trash-applet.h b/gnome-applets/trash/trash-applet.h
new file mode 100644
index 000000000..cec24768a
--- /dev/null
+++ b/gnome-applets/trash/trash-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 TRASH_APPLET_H
+#define TRASH_APPLET_H
+
+#include <libgnome-panel/gp-applet.h>
+
+G_BEGIN_DECLS
+
+#define TRASH_TYPE_APPLET (trash_applet_get_type ())
+G_DECLARE_FINAL_TYPE (TrashApplet, trash_applet, TRASH, APPLET, GpApplet)
+
+G_END_DECLS
+
+#endif
diff --git a/trash/src/trash-empty.c b/gnome-applets/trash/trash-empty.c
similarity index 100%
rename from trash/src/trash-empty.c
rename to gnome-applets/trash/trash-empty.c
diff --git a/trash/src/trash-empty.h b/gnome-applets/trash/trash-empty.h
similarity index 100%
rename from trash/src/trash-empty.h
rename to gnome-applets/trash/trash-empty.h
diff --git a/trash/src/trash-empty.ui b/gnome-applets/trash/trash-empty.ui
similarity index 100%
rename from trash/src/trash-empty.ui
rename to gnome-applets/trash/trash-empty.ui
diff --git a/gnome-applets/trash/trash-menu.xml b/gnome-applets/trash/trash-menu.xml
new file mode 100644
index 000000000..711fbf11e
--- /dev/null
+++ b/gnome-applets/trash/trash-menu.xml
@@ -0,0 +1,24 @@
+<interface>
+  <menu id="trash-menu">
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_Open Trash</attribute>
+        <attribute name="action">trash.open</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_Empty Trash</attribute>
+        <attribute name="action">trash.empty</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_Help</attribute>
+        <attribute name="action">trash.help</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_About</attribute>
+        <attribute name="action">trash.about</attribute>
+      </item>
+    </section>
+  </menu>
+</interface>
diff --git a/trash/src/trash-resources.gresource.xml b/gnome-applets/trash/trash-resources.gresource.xml
similarity index 100%
rename from trash/src/trash-resources.gresource.xml
rename to gnome-applets/trash/trash-resources.gresource.xml
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 49c5e4fac..c94d9b0a0 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -50,6 +50,10 @@ geyes/src/geyes.c
 geyes/src/themes.c
 gnome-applets/ga-module.c
 gnome-applets/timer/timer-applet.c
+gnome-applets/trash/trash-applet.c
+gnome-applets/trash/trash-empty.c
+[type: gettext/glade]gnome-applets/trash/trash-empty.ui
+[type: gettext/glade]gnome-applets/trash/trash-menu.xml
 gnome-applets/window-picker/task-item.c
 gnome-applets/window-picker/wp-about-dialog.c
 gnome-applets/window-picker/wp-applet.c
@@ -105,11 +109,6 @@ tracker-search-bar/src/tracker-applet.c
 tracker-search-bar/src/tracker-results-window.c
 [type: gettext/glade]tracker-search-bar/src/tracker-search-bar-menu.xml
 [type: gettext/glade]tracker-search-bar/src/tracker-search-bar.ui
-[type: gettext/ini]trash/data/org.gnome.applets.TrashApplet.panel-applet.in.in
-trash/src/trash-applet.c
-trash/src/trash-empty.c
-[type: gettext/glade]trash/src/trash-empty.ui
-[type: gettext/glade]trash/src/trash-menu.xml
 [type: gettext/ini]window-buttons/org.gnome.panel.WindowButtonsApplet.panel-applet.in.in
 window-buttons/windowbuttons.c
 [type: gettext/glade]window-buttons/windowbuttons.ui
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 3dc0eff09..a2176a6da 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -33,6 +33,5 @@ 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
 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
 window-title/org.gnome.panel.WindowTitleApplet.panel-applet.in


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