[gnome-applets/wip/muktupavels/drivemount: 1/3] drivemount: port to libgnome-panel



commit dc95f2e3780ae515264dc81c5ea1d56038cb0207
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Mon Mar 30 20:07:57 2020 +0300

    drivemount: port to libgnome-panel

 Makefile.am                                        |   2 -
 configure.ac                                       |   4 +-
 drivemount/Makefile.am                             |  29 ---
 drivemount/drivemount-applet-menu.xml              |  10 --
 ...ome.applets.DriveMountApplet.panel-applet.in.in |  15 --
 drivemount/src/drivemount.c                        | 197 ---------------------
 gnome-applets/Makefile.am                          |   3 +
 .../src => gnome-applets/drivemount}/Makefile.am   |  17 +-
 .../drivemount}/drive-button.c                     |   0
 .../drivemount}/drive-button.h                     |   0
 .../src => gnome-applets/drivemount}/drive-list.c  |   0
 .../src => gnome-applets/drivemount}/drive-list.h  |   0
 .../drivemount/drivemount-applet-menu.xml          |  14 ++
 gnome-applets/drivemount/drivemount-applet.c       | 189 ++++++++++++++++++++
 gnome-applets/drivemount/drivemount-applet.h       |  31 ++++
 gnome-applets/ga-module.c                          |  11 ++
 po/POTFILES.in                                     |   7 +-
 po/POTFILES.skip                                   |   1 -
 18 files changed, 257 insertions(+), 273 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 879f6c2bf..3d5cdd0ba 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,7 +5,6 @@ tracker_search_bar_SUBDIR = tracker-search-bar
 endif
 
 always_built_SUBDIRS =  \
-       drivemount      \
        geyes           \
        mini-commander \
        multiload \
@@ -28,7 +27,6 @@ DIST_SUBDIRS = \
        gnome-applets \
        help \
        po              \
-       drivemount      \
        geyes           \
        mini-commander  \
        multiload       \
diff --git a/configure.ac b/configure.ac
index 1f206cd7d..5bd42ec45 100644
--- a/configure.ac
+++ b/configure.ac
@@ -346,6 +346,7 @@ AC_CONFIG_FILES([
   gnome-applets/command/Makefile
   gnome-applets/cpufreq/Makefile
   gnome-applets/cpufreq/cpufreq-selector/Makefile
+  gnome-applets/drivemount/Makefile
   gnome-applets/gweather/Makefile
   gnome-applets/inhibit/Makefile
   gnome-applets/netspeed/Makefile
@@ -369,9 +370,6 @@ AC_CONFIG_FILES([
 
   po/Makefile.in
 
-  drivemount/Makefile
-  drivemount/src/Makefile
-
   geyes/Makefile
   geyes/src/Makefile
   geyes/themes/Makefile
diff --git a/gnome-applets/Makefile.am b/gnome-applets/Makefile.am
index a63b74f21..d2e0ca52f 100644
--- a/gnome-applets/Makefile.am
+++ b/gnome-applets/Makefile.am
@@ -7,6 +7,7 @@ SUBDIRS = \
        charpick \
        command \
        cpufreq \
+       drivemount \
        gweather \
        inhibit \
        netspeed \
@@ -42,6 +43,7 @@ org_gnome_gnome_applets_la_LIBADD = \
        $(top_builddir)/gnome-applets/brightness/libbrightness-applet.la \
        $(top_builddir)/gnome-applets/charpick/libcharacter-picker-applet.la \
        $(top_builddir)/gnome-applets/command/libcommand-applet.la \
+       $(top_builddir)/gnome-applets/drivemount/libdrive-mount-applet.la \
        $(top_builddir)/gnome-applets/gweather/libgweather-applet.la \
        $(top_builddir)/gnome-applets/inhibit/libinhibit-applet.la \
        $(top_builddir)/gnome-applets/netspeed/libnet-speed-applet.la \
@@ -122,6 +124,7 @@ ui_files = \
        brightness/brightness-applet-menu.xml \
        charpick/charpick-applet-menu.xml \
        command/command-applet-menu.xml \
+       drivemount/drivemount-applet-menu.xml \
        gweather/gweather-applet-menu.xml \
        inhibit/inhibit-applet-menu.xml \
        netspeed/netspeed-menu.xml \
diff --git a/drivemount/src/Makefile.am b/gnome-applets/drivemount/Makefile.am
similarity index 62%
rename from drivemount/src/Makefile.am
rename to gnome-applets/drivemount/Makefile.am
index af089edae..dd37480ba 100644
--- a/drivemount/src/Makefile.am
+++ b/gnome-applets/drivemount/Makefile.am
@@ -1,28 +1,22 @@
 NULL =
 
-uidir = $(pkgdatadir)/ui
-
-drivemount_applet_libdir = $(pkglibdir)
-drivemount_applet_lib_LTLIBRARIES = libdrive-mount-applet.la
+noinst_LTLIBRARIES = libdrive-mount-applet.la
 
 libdrive_mount_applet_la_CPPFLAGS = \
-       -I. \
-       -I$(srcdir) \
-       -DDRIVEMOUNT_MENU_UI_DIR=\""$(uidir)"\" \
-       -DGNOMELOCALEDIR=\""$(localedir)"\" \
        -DG_LOG_DOMAIN=\"org.gnome.gnome-applets.drive-mount\" \
        -DG_LOG_USE_STRUCTURED=1 \
        $(NULL)
 
 libdrive_mount_applet_la_CFLAGS = \
-       $(GNOME_APPLETS_CFLAGS) \
+       $(GNOME_PANEL_CFLAGS) \
        $(GIO_UNIX_CFLAGS) \
        $(WARN_CFLAGS) \
        $(AM_CFLAGS) \
        $(NULL)
 
 libdrive_mount_applet_la_SOURCES = \
-       drivemount.c \
+       drivemount-applet.c \
+       drivemount-applet.h \
        drive-list.c \
        drive-list.h \
        drive-button.c \
@@ -30,13 +24,12 @@ libdrive_mount_applet_la_SOURCES = \
        $(NULL)
 
 libdrive_mount_applet_la_LDFLAGS = \
-       -avoid-version \
        $(WARN_LDFLAGS) \
        $(AM_LDFLAGS) \
        $(NULL)
 
 libdrive_mount_applet_la_LIBADD = \
-       $(GNOME_APPLETS_LIBS) \
+       $(GNOME_PAENL_LIBS) \
        $(GIO_UNIX_LIBS) \
        $(NULL)
 
diff --git a/drivemount/src/drive-button.c b/gnome-applets/drivemount/drive-button.c
similarity index 100%
rename from drivemount/src/drive-button.c
rename to gnome-applets/drivemount/drive-button.c
diff --git a/drivemount/src/drive-button.h b/gnome-applets/drivemount/drive-button.h
similarity index 100%
rename from drivemount/src/drive-button.h
rename to gnome-applets/drivemount/drive-button.h
diff --git a/drivemount/src/drive-list.c b/gnome-applets/drivemount/drive-list.c
similarity index 100%
rename from drivemount/src/drive-list.c
rename to gnome-applets/drivemount/drive-list.c
diff --git a/drivemount/src/drive-list.h b/gnome-applets/drivemount/drive-list.h
similarity index 100%
rename from drivemount/src/drive-list.h
rename to gnome-applets/drivemount/drive-list.h
diff --git a/gnome-applets/drivemount/drivemount-applet-menu.xml 
b/gnome-applets/drivemount/drivemount-applet-menu.xml
new file mode 100644
index 000000000..eb7962e0b
--- /dev/null
+++ b/gnome-applets/drivemount/drivemount-applet-menu.xml
@@ -0,0 +1,14 @@
+<interface>
+  <menu id="drivemount-menu">
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_Help</attribute>
+        <attribute name="action">drivemount.help</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_About</attribute>
+        <attribute name="action">drivemount.about</attribute>
+      </item>
+    </section>
+  </menu>
+</interface>
diff --git a/gnome-applets/drivemount/drivemount-applet.c b/gnome-applets/drivemount/drivemount-applet.c
new file mode 100644
index 000000000..6266ce943
--- /dev/null
+++ b/gnome-applets/drivemount/drivemount-applet.c
@@ -0,0 +1,189 @@
+/*
+ * Copyright (c) 2004 Canonical Ltd
+ *
+ * This library 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/>.
+ *
+ * Author:
+ *   James Henstridge <jamesh canonical com>
+ */
+
+#include "config.h"
+#include "drivemount-applet.h"
+
+#include <string.h>
+
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+
+#include "drive-list.h"
+
+struct _DrivemountApplet
+{
+  GpApplet   parent;
+
+  GtkWidget *drive_list;
+};
+
+G_DEFINE_TYPE (DrivemountApplet, drivemount_applet, GP_TYPE_APPLET)
+
+static void
+placement_changed_cb (GpApplet         *applet,
+                      GtkOrientation    orientation,
+                      GtkPositionType   position,
+                      DrivemountApplet *self)
+{
+  drive_list_set_orientation (DRIVE_LIST (self->drive_list), orientation);
+}
+
+static void
+size_allocate_cb (GtkWidget        *widget,
+                  GtkAllocation    *allocation,
+                  DrivemountApplet *self)
+{
+    int size;
+
+    switch (gp_applet_get_orientation (GP_APPLET (self))) {
+    case GTK_ORIENTATION_VERTICAL:
+       size = allocation->width;
+       break;
+    case GTK_ORIENTATION_HORIZONTAL:
+    default:
+       size = allocation->height;
+       break;
+    }
+
+    drive_list_set_panel_size (DRIVE_LIST (self->drive_list), size);
+}
+
+static void
+display_about_dialog (GSimpleAction *action,
+                      GVariant      *parameter,
+                      gpointer       user_data)
+{
+    const gchar *authors[] = {
+       "James Henstridge <jamesh canonical com>",
+       NULL
+    };
+    const gchar *documenters[] = {
+       "Dan Mueth <muet alumni uchicago edu>",
+       "John Fleck <jfleck inkstain net>",
+       NULL
+    };
+
+    gtk_show_about_dialog (NULL,
+       "version",     VERSION,
+       "copyright",   "Copyright \xC2\xA9 2004 Canonical Ltd",
+       "comments",    _("Applet for mounting and unmounting block volumes."),
+       "authors",     authors,
+       "documenters", documenters,
+       "translator-credits", _("translator-credits"),
+       "logo_icon_name",     "media-floppy",
+       NULL);
+}
+
+static void
+display_help (GSimpleAction *action,
+              GVariant      *parameter,
+              gpointer       user_data)
+{
+    DrivemountApplet *self = (DrivemountApplet *) user_data;
+    GdkScreen *screen;
+    GError *error = NULL;
+
+    screen = gtk_widget_get_screen (GTK_WIDGET (self));
+
+    gtk_show_uri (screen,
+               "help:drivemount",
+               gtk_get_current_event_time (),
+               &error);
+
+    if (error) {
+       GtkWidget *dialog;
+
+       dialog = gtk_message_dialog_new (NULL,
+                                        GTK_DIALOG_MODAL,
+                                        GTK_MESSAGE_ERROR,
+                                        GTK_BUTTONS_OK,
+                                        _("There was an error displaying help: %s"),
+                                        error->message);
+       g_signal_connect (dialog, "response",
+                         G_CALLBACK (gtk_widget_destroy), NULL);
+       gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+       gtk_window_set_screen (GTK_WINDOW (dialog), screen);
+       gtk_widget_show (dialog);
+       g_error_free (error);
+    }
+}
+
+static const GActionEntry applet_menu_actions [] = {
+       { "help",  display_help,         NULL, NULL, NULL },
+       { "about", display_about_dialog, NULL, NULL, NULL },
+       { NULL }
+};
+
+static void
+drivemount_applet_setup (DrivemountApplet *self)
+{
+  const char *menu_resource;
+  AtkObject *ao;
+
+  self->drive_list = drive_list_new ();
+  gtk_container_add (GTK_CONTAINER (self), self->drive_list);
+
+  g_signal_connect (self,
+                    "placement-changed",
+                    G_CALLBACK (placement_changed_cb),
+                    self);
+
+  g_signal_connect (self,
+                    "size-allocate",
+                    G_CALLBACK (size_allocate_cb),
+                    self);
+
+  drive_list_set_orientation (DRIVE_LIST (self->drive_list),
+                              gp_applet_get_orientation (GP_APPLET (self)));
+
+  menu_resource = GRESOURCE_PREFIX "/ui/drivemount-applet-menu.xml";
+  gp_applet_setup_menu_from_resource (GP_APPLET (self),
+                                      menu_resource,
+                                      applet_menu_actions);
+
+  ao = gtk_widget_get_accessible (GTK_WIDGET (self));
+  atk_object_set_name (ao, _("Disk Mounter"));
+
+  gtk_widget_show_all (GTK_WIDGET (self));
+}
+
+static void
+drivemount_applet_constructed (GObject *object)
+{
+  G_OBJECT_CLASS (drivemount_applet_parent_class)->constructed (object);
+  drivemount_applet_setup (DRIVEMOUNT_APPLET (object));
+}
+
+static void
+drivemount_applet_class_init (DrivemountAppletClass *self_class)
+{
+  GObjectClass *object_class;
+
+  object_class = G_OBJECT_CLASS (self_class);
+
+  object_class->constructed = drivemount_applet_constructed;
+}
+
+static void
+drivemount_applet_init (DrivemountApplet *self)
+{
+  gp_applet_set_flags (GP_APPLET (self), GP_APPLET_FLAGS_EXPAND_MINOR);
+}
diff --git a/gnome-applets/drivemount/drivemount-applet.h b/gnome-applets/drivemount/drivemount-applet.h
new file mode 100644
index 000000000..567d9456f
--- /dev/null
+++ b/gnome-applets/drivemount/drivemount-applet.h
@@ -0,0 +1,31 @@
+/*
+ * 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 DRIVEMOUNT_APPLET_H
+#define DRIVEMOUNT_APPLET_H
+
+#include <libgnome-panel/gp-applet.h>
+
+G_BEGIN_DECLS
+
+#define DRIVEMOUNT_TYPE_APPLET (drivemount_applet_get_type ())
+G_DECLARE_FINAL_TYPE (DrivemountApplet, drivemount_applet,
+                      DRIVEMOUNT, APPLET, GpApplet)
+
+G_END_DECLS
+
+#endif
diff --git a/gnome-applets/ga-module.c b/gnome-applets/ga-module.c
index b58c6da54..29da2769b 100644
--- a/gnome-applets/ga-module.c
+++ b/gnome-applets/ga-module.c
@@ -29,6 +29,7 @@
 #ifdef BUILD_CPUFREQ_APPLET
 #include "cpufreq/cpufreq-applet.h"
 #endif
+#include "drivemount/drivemount-applet.h"
 #include "gweather/gweather-applet.h"
 #include "inhibit/inhibit-applet.h"
 #include "netspeed/netspeed-applet.h"
@@ -89,6 +90,13 @@ ga_get_applet_info (const char *id)
       icon_name = "gnome-cpu-frequency-applet";
     }
 #endif
+  else if (g_strcmp0 (id, "drivemount") == 0)
+    {
+      type_func = drivemount_applet_get_type;
+      name = _("Disk Mounter");
+      description = _("Mount local disks and devices");
+      icon_name = "media-floppy";
+    }
   else if (g_strcmp0 (id, "gweather") == 0)
     {
       type_func = gweather_applet_get_type;
@@ -159,6 +167,8 @@ ga_get_applet_id_from_iid (const char *iid)
   else if (g_strcmp0 (iid, "CPUFreqAppletFactory::CPUFreqApplet") == 0)
     return "cpufreq";
 #endif
+  else if (g_strcmp0 (iid, "DriveMountAppletFactory::DriveMountApplet") == 0)
+    return "drivemount";
   else if (g_strcmp0 (iid, "GWeatherAppletFactory::GWeatherApplet") == 0)
     return "gweather";
   else if (g_strcmp0 (iid, "InhibitAppletFactory::InhibitApplet") == 0)
@@ -197,6 +207,7 @@ gp_module_load (GpModule *module)
 #ifdef BUILD_CPUFREQ_APPLET
                             "cpufreq",
 #endif
+                            "drivemount",
                             "gweather",
                             "inhibit",
                             "netspeed",
diff --git a/po/POTFILES.in b/po/POTFILES.in
index ed382c3a8..0ea4e054e 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -16,10 +16,6 @@ data/schemas/org.gnome.gnome-applets.timer.gschema.xml.in.in
 data/schemas/org.gnome.gnome-applets.window-buttons.gschema.xml.in.in
 data/schemas/org.gnome.gnome-applets.window-picker-applet.gschema.xml.in.in
 data/schemas/org.gnome.gnome-applets.window-title.gschema.xml.in.in
-[type: gettext/glade]drivemount/drivemount-applet-menu.xml
-[type: gettext/ini]drivemount/org.gnome.applets.DriveMountApplet.panel-applet.in.in
-drivemount/src/drive-button.c
-drivemount/src/drivemount.c
 [type: gettext/glade]geyes/geyes-applet-menu.xml
 [type: gettext/ini]geyes/org.gnome.applets.GeyesApplet.panel-applet.in.in
 geyes/src/geyes.c
@@ -43,6 +39,9 @@ gnome-applets/cpufreq/cpufreq-applet.c
 gnome-applets/cpufreq/cpufreq-popup.c
 gnome-applets/cpufreq/cpufreq-prefs.c
 gnome-applets/cpufreq/cpufreq-selector/org.gnome.cpufreqselector.policy.in
+[type: gettext/glade]gnome-applets/drivemount/drivemount-applet-menu.xml
+gnome-applets/drivemount/drive-button.c
+gnome-applets/drivemount/drivemount-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 fba41b4cd..a25cc0825 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -17,7 +17,6 @@ data/schemas/org.gnome.gnome-applets.timer.gschema.xml.in
 data/schemas/org.gnome.gnome-applets.window-buttons.gschema.xml.in
 data/schemas/org.gnome.gnome-applets.window-picker-applet.gschema.xml.in
 data/schemas/org.gnome.gnome-applets.window-title.gschema.xml.in
-drivemount/org.gnome.applets.DriveMountApplet.panel-applet.in
 geyes/org.gnome.applets.GeyesApplet.panel-applet.in
 mini-commander/src/org.gnome.applets.MiniCommanderApplet.panel-applet.in
 multiload/org.gnome.applets.MultiLoadApplet.panel-applet.in


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