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



commit facc57938d8c4b25a497406bd17230da8c66b765
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Mar 29 22:23:35 2020 +0300

    battstat: port to libgnome-panel

 Makefile.am                                        |   2 -
 battstat/Makefile.am                               |  33 ---
 battstat/battstat-applet-menu.xml                  |  14 --
 ...gnome.applets.BattstatApplet.panel-applet.in.in |  15 --
 configure.ac                                       |   4 +-
 gnome-applets/Makefile.am                          |   4 +
 .../src => gnome-applets/battstat}/Makefile.am     |  16 +-
 gnome-applets/battstat/battstat-applet-menu.xml    |  18 ++
 .../battstat/battstat-applet.c                     | 270 +++++++++------------
 gnome-applets/battstat/battstat-applet.h           |  31 +++
 .../battstat/battstat-applet.ui                    |   0
 .../battstat}/battstat-upower.c                    |   0
 .../battstat}/battstat-upower.h                    |   0
 .../src => gnome-applets/battstat}/battstat.h      |  19 +-
 {battstat/src => gnome-applets/battstat}/pixmaps.h |   0
 .../src => gnome-applets/battstat}/properties.c    |  36 +--
 gnome-applets/ga-module.c                          |  15 +-
 po/POTFILES.in                                     |   9 +-
 po/POTFILES.skip                                   |   1 -
 19 files changed, 202 insertions(+), 285 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index c57098700..5ef012077 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -14,7 +14,6 @@ endif
 
 always_built_SUBDIRS =  \
        charpick        \
-       battstat \
        drivemount      \
        inhibit         \
        geyes           \
@@ -47,7 +46,6 @@ DIST_SUBDIRS = \
        charpick        \
        geyes           \
        mini-commander  \
-       battstat        \
        multiload       \
        netspeed        \
        accessx-status  \
diff --git a/configure.ac b/configure.ac
index 6a5582b80..7307af18d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -344,6 +344,7 @@ AC_CONFIG_FILES([
   data/schemas/Makefile
 
   gnome-applets/Makefile
+  gnome-applets/battstat/Makefile
   gnome-applets/brightness/Makefile
   gnome-applets/command/Makefile
   gnome-applets/gweather/Makefile
@@ -371,9 +372,6 @@ AC_CONFIG_FILES([
   accessx-status/pixmaps/Makefile
   accessx-status/src/Makefile
 
-  battstat/Makefile
-  battstat/src/Makefile
-
   charpick/Makefile
   charpick/src/Makefile
 
diff --git a/gnome-applets/Makefile.am b/gnome-applets/Makefile.am
index ab76214e5..c5a0d4d17 100644
--- a/gnome-applets/Makefile.am
+++ b/gnome-applets/Makefile.am
@@ -1,6 +1,7 @@
 NULL =
 
 SUBDIRS = \
+       battstat \
        brightness \
        command \
        gweather \
@@ -31,6 +32,7 @@ org_gnome_gnome_applets_la_SOURCES = \
        $(NULL)
 
 org_gnome_gnome_applets_la_LIBADD = \
+       $(top_builddir)/gnome-applets/battstat/libbattery-status-applet.la \
        $(top_builddir)/gnome-applets/brightness/libbrightness-applet.la \
        $(top_builddir)/gnome-applets/command/libcommand-applet.la \
        $(top_builddir)/gnome-applets/gweather/libgweather-applet.la \
@@ -50,6 +52,8 @@ icon_files = \
        $(NULL)
 
 ui_files = \
+       battstat/battstat-applet.ui \
+       battstat/battstat-applet-menu.xml \
        brightness/brightness-applet-menu.xml \
        command/command-applet-menu.xml \
        gweather/gweather-applet-menu.xml \
diff --git a/battstat/src/Makefile.am b/gnome-applets/battstat/Makefile.am
similarity index 63%
rename from battstat/src/Makefile.am
rename to gnome-applets/battstat/Makefile.am
index 131929fd9..90077558d 100644
--- a/battstat/src/Makefile.am
+++ b/gnome-applets/battstat/Makefile.am
@@ -1,20 +1,14 @@
 NULL =
 
-uidir = $(pkgdatadir)/ui
-
-battery_status_applet_libdir = $(pkglibdir)
-battery_status_applet_lib_LTLIBRARIES = libbattery-status-applet.la
+noinst_LTLIBRARIES = libbattery-status-applet.la
 
 libbattery_status_applet_la_CPPFLAGS = \
-       -DBATTSTAT_MENU_UI_DIR=\""$(uidir)"\" \
-       -DGNOMELOCALEDIR=\""$(localedir)"\" \
-       -DGTK_BUILDERDIR=\""$(pkgdatadir)/builder"\" \
        -DG_LOG_DOMAIN=\"org.gnome.gnome-applets.battery-status\" \
        -DG_LOG_USE_STRUCTURED=1 \
        $(NULL)
 
 libbattery_status_applet_la_CFLAGS = \
-       $(GNOME_APPLETS_CFLAGS) \
+       $(GNOME_PANEL_CFLAGS) \
        $(LIBNOTIFY_CFLAGS) \
        $(UPOWER_CFLAGS) \
        $(WARN_CFLAGS) \
@@ -25,19 +19,19 @@ libbattery_status_applet_la_SOURCES = \
        battstat.h \
        pixmaps.h \
        properties.c \
-       battstat_applet.c \
+       battstat-applet.c \
+       battstat-applet.h \
        battstat-upower.c \
        battstat-upower.h \
        $(NULL)
 
 libbattery_status_applet_la_LDFLAGS = \
-       -avoid-version \
        $(WARN_LDFLAGS) \
        $(AM_LDFLAGS) \
        $(NULL)
 
 libbattery_status_applet_la_LIBADD = \
-       $(GNOME_APPLETS_LIBS) \
+       $(GNOME_PANEL_LIBS) \
        $(LIBNOTIFY_LIBS) \
        $(UPOWER_LIBS) \
        $(LIBM) \
diff --git a/gnome-applets/battstat/battstat-applet-menu.xml b/gnome-applets/battstat/battstat-applet-menu.xml
new file mode 100644
index 000000000..322d85eca
--- /dev/null
+++ b/gnome-applets/battstat/battstat-applet-menu.xml
@@ -0,0 +1,18 @@
+<interface>
+  <menu id="battstat-menu">
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_Preferences</attribute>
+        <attribute name="action">battstat.preferences</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_Help</attribute>
+        <attribute name="action">battstat.help</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_About</attribute>
+        <attribute name="action">battstat.about</attribute>
+      </item>
+    </section>
+  </menu>
+</interface>
diff --git a/battstat/src/battstat_applet.c b/gnome-applets/battstat/battstat-applet.c
similarity index 88%
rename from battstat/src/battstat_applet.c
rename to gnome-applets/battstat/battstat-applet.c
index 38aa64bab..10116efbd 100644
--- a/battstat/src/battstat_applet.c
+++ b/gnome-applets/battstat/battstat-applet.c
@@ -1,4 +1,4 @@
-/* battstat        A GNOME battery meter for laptops. 
+/*
  * Copyright (C) 2000 by Jörgen Pehrson <jp spektr eu org>
  * Copyright (C) 2002 Free Software Foundation
  *
@@ -14,13 +14,10 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- $Id$
  */
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "config.h"
+#include "battstat-applet.h"
 
 #include <stdio.h>
 
@@ -34,18 +31,17 @@
 #include <time.h>
 #include <unistd.h>
 
+#include <glib/gi18n-lib.h>
 #include <gtk/gtk.h>
 
-#include <panel-applet.h>
-
+#include <libgnome-panel/gp-utils.h>
 #include <libnotify/notify.h>
 
 #include "battstat.h"
+#include "battstat-upower.h"
 #include "pixmaps.h"
 
-#ifndef gettext_noop
-#define gettext_noop(String) (String)
-#endif
+G_DEFINE_TYPE (BattstatApplet, battstat_applet, GP_TYPE_APPLET)
 
 static gboolean check_for_updates (gpointer data);
 static void about_cb( GSimpleAction *, GVariant *, gpointer );
@@ -54,7 +50,8 @@ static void help_cb( GSimpleAction *, GVariant *, gpointer );
 static const GActionEntry battstat_menu_actions [] = {
        { "preferences", prop_cb,  NULL, NULL, NULL },
        { "help",        help_cb,  NULL, NULL, NULL },
-       { "about",       about_cb, NULL, NULL, NULL }
+       { "about",       about_cb, NULL, NULL, NULL },
+       { NULL }
 };
 
 #define AC_POWER_STRING _("System is running on AC power")
@@ -654,7 +651,7 @@ update_tooltip( ProgressData *battstat, BatteryStatus *info )
                                  _("Battery status unknown"));
   }
 
-  gtk_widget_set_tooltip_text (battstat->applet, tiptext);
+  gtk_widget_set_tooltip_text (GTK_WIDGET (battstat), tiptext);
   g_free (tiptext);
 }
 
@@ -946,12 +943,8 @@ check_for_updates( gpointer data )
 {
   ProgressData *battstat = data;
   BatteryStatus info;
-  const char *err;
 
-  if (DEBUG) g_print("check_for_updates()\n");
-
-  if( (err = battstat_upower_get_battery_info( &info )) )
-    battstat_error_dialog( battstat->applet, err );
+  battstat_upower_get_battery_info (&info);
 
   if (!event_driven)
   {
@@ -1014,7 +1007,7 @@ check_for_updates( gpointer data )
     /* Inform that battery now fully charged */
     if(battstat->fullbattnot)
     {
-      battery_full_dialog (battstat->applet);
+      battery_full_dialog (GTK_WIDGET (battstat));
  
       if (battstat->beep)
         gdk_beep();
@@ -1070,36 +1063,6 @@ check_for_updates( gpointer data )
   return TRUE;
 }
 
-/* Gets called when the user removes the applet from the panel.  Clean up
-   all instance-specific data and call the global teardown function to
-   decrease our applet count (and possibly perform global cleanup)
- */
-static void
-destroy_applet( GtkWidget *widget, ProgressData *battstat )
-{
-  if (DEBUG) g_print("destroy_applet()\n");
-
-  if (battstat->prop_win)
-    gtk_widget_destroy (GTK_WIDGET (battstat->prop_win));
-
-  if( battstat->battery_low_dialog )
-    battery_low_dialog_destroy( battstat );
-
-  if (battstat->timeout_id)
-    g_source_remove (battstat->timeout_id);
-
-  if (battstat->settings)
-    g_object_unref (battstat->settings);
-
-  g_object_unref( G_OBJECT(battstat->status) );
-  g_object_unref( G_OBJECT(battstat->percent) );
-  g_object_unref( G_OBJECT(battstat->battery) );
-
-  g_free( battstat );
-
-  static_global_teardown (battstat);
-}
-
 /* Common function invoked by the 'Help' context menu item and the 'Help'
  * button in the preferences dialog.
  */
@@ -1114,7 +1077,7 @@ battstat_show_help( ProgressData *battstat, const char *section )
   else
     uri = g_strdup ("help:battstat");
 
-  gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (battstat->applet)),
+  gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (battstat)),
                 uri,
                 gtk_get_current_event_time (),
                 &error);
@@ -1127,7 +1090,7 @@ battstat_show_help( ProgressData *battstat, const char *section )
 
     message = g_strdup_printf( _("There was an error displaying help: %s"),
                                error->message );
-    battstat_error_dialog( battstat->applet, message );
+    battstat_error_dialog (GTK_WIDGET (battstat), message);
     g_error_free( error );
     g_free( message );
   }
@@ -1197,49 +1160,39 @@ about_cb (GSimpleAction *action,
 static void
 setup_text_orientation( ProgressData *battstat )
 {
-  if( battstat->orienttype == PANEL_APPLET_ORIENT_RIGHT )
+  GtkPositionType position;
+
+  position = gp_applet_get_position (GP_APPLET (battstat));
+
+  if (position == GTK_POS_LEFT)
     gtk_label_set_angle( GTK_LABEL( battstat->percent ), 90 );
-  else if( battstat->orienttype == PANEL_APPLET_ORIENT_LEFT )
+  else if (position == GTK_POS_RIGHT)
     gtk_label_set_angle( GTK_LABEL( battstat->percent ), 270 );
   else
     gtk_label_set_angle( GTK_LABEL( battstat->percent ), 0 );
 }
 
-
-/* This signal is delivered by the panel when the orientation of the applet
-   has changed.  This is either because the applet has just been created,
-   has just been moved to a new panel or the panel that the applet was on
-   has changed orientation.
-*/
 static void
-change_orient (PanelApplet       *applet,
-              PanelAppletOrient  orient,
-              ProgressData      *battstat)
+placement_changed_cb (GpApplet        *applet,
+                      GtkOrientation   orientation,
+                      GtkPositionType  position,
+                      BattstatApplet  *self)
 {
-  if (DEBUG) g_print("change_orient()\n");
-
-  /* Ignore the update if we already know. */
-  if( orient != battstat->orienttype )
-  {
-    battstat->orienttype = orient;
-
-    /* The applet changing orientation very likely involves the layout
-       being changed to better fit the new shape of the panel.
-    */
-    setup_text_orientation( battstat );
-    reconfigure_layout( battstat );
-  }
+  /* The applet changing orientation very likely involves the layout
+   * being changed to better fit the new shape of the panel.
+   */
+  setup_text_orientation (self);
+  reconfigure_layout (self);
 }
 
 /* This is delivered when our size has changed.  This happens when the applet
    is just created or if the size of the panel has changed.
 */
 static void
-size_allocate( PanelApplet *applet, GtkAllocation *allocation,
-               ProgressData *battstat)
+size_allocate (GtkWidget     *widget,
+               GtkAllocation *allocation,
+               ProgressData  *battstat)
 {
-  if (DEBUG) g_print("applet_change_pixel_size()\n");
-
   /* Ignore the update if we already know. */
   if( battstat->width == allocation->width &&
       battstat->height == allocation->height )
@@ -1257,10 +1210,6 @@ size_allocate( PanelApplet *applet, GtkAllocation *allocation,
 static void
 load_preferences(ProgressData *battstat)
 {
-  PanelApplet *applet = PANEL_APPLET (battstat->applet);
-
-  if (DEBUG) g_print("load_preferences()\n");
-  
   battstat->red_val = g_settings_get_int (battstat->settings, KEY_RED_VALUE);
   battstat->red_val = CLAMP (battstat->red_val, 0, 100);
   battstat->red_value_is_time = g_settings_get_boolean (battstat->settings, KEY_RED_VALUE_IS_TIME);
@@ -1348,10 +1297,9 @@ reconfigure_layout( ProgressData *battstat )
   int needwidth;
 
   /* Decide if we are doing to do 'square' mode. */
-  switch( battstat->orienttype )
+  switch (gp_applet_get_orientation (GP_APPLET (battstat)))
   {
-    case PANEL_APPLET_ORIENT_UP:
-    case PANEL_APPLET_ORIENT_DOWN:
+    case GTK_ORIENTATION_HORIZONTAL:
       up_down_order = TRUE;
 
       /* Need to be at least 46px tall to do square mode on a horiz. panel */
@@ -1359,8 +1307,7 @@ reconfigure_layout( ProgressData *battstat )
         do_square = TRUE;
       break;
 
-    case PANEL_APPLET_ORIENT_LEFT:
-    case PANEL_APPLET_ORIENT_RIGHT:
+    case GTK_ORIENTATION_VERTICAL:
       /* We need 64px to fix the text beside anything. */
       if( battstat->showtext )
         needwidth = 64;
@@ -1450,7 +1397,7 @@ reconfigure_layout( ProgressData *battstat )
     table_layout_attach( GTK_TABLE(battstat->table),
                          c.text, battstat->percent );
 
-    gtk_widget_show_all( battstat->applet );
+    gtk_widget_show_all (GTK_WIDGET (battstat));
   }
 
   /* If we are showing the battery meter and we weren't showing it before or
@@ -1478,15 +1425,13 @@ reconfigure_layout( ProgressData *battstat )
 static gint
 create_layout(ProgressData *battstat)
 {
-  if (DEBUG) g_print("create_layout()\n");
-
   /* Allocate the four widgets that we need. */
   battstat->table = gtk_table_new( 3, 3, FALSE );
   battstat->percent = gtk_label_new( "" );
   battstat->status = gtk_image_new();
   battstat->battery = gtk_image_new();
 
-  panel_applet_add_text_class (PANEL_APPLET (battstat->applet), battstat->percent);
+  gp_add_text_color_class (battstat->percent);
 
   /* When you first get a pointer to a newly created GtkWidget it has one
      'floating' reference.  When you first add this widget to a container
@@ -1496,12 +1441,9 @@ create_layout(ProgressData *battstat)
      reference to each widget.  This adds a real reference to each widget
      and "sinks" the floating reference.
   */
-  g_object_ref( battstat->status );
-  g_object_ref( battstat->percent );
-  g_object_ref( battstat->battery );
-  g_object_ref_sink( G_OBJECT( battstat->status ) );
-  g_object_ref_sink( G_OBJECT( battstat->percent ) );
-  g_object_ref_sink( G_OBJECT( battstat->battery ) );
+  g_object_ref_sink (battstat->status);
+  g_object_ref_sink (battstat->percent);
+  g_object_ref_sink (battstat->battery);
 
   /* Let reconfigure_layout know that the table is currently empty. */
   battstat->layout.status = LAYOUT_NONE;
@@ -1509,21 +1451,17 @@ create_layout(ProgressData *battstat)
   battstat->layout.battery = LAYOUT_NONE;
 
   /* Put the table directly inside the applet and show everything. */
-  gtk_container_add (GTK_CONTAINER (battstat->applet), battstat->table);
-  gtk_widget_show_all (battstat->applet);
+  gtk_container_add (GTK_CONTAINER (battstat), battstat->table);
+  gtk_widget_show_all (GTK_WIDGET (battstat));
 
   /* Attach all sorts of signals to the applet. */
-  g_signal_connect(G_OBJECT(battstat->applet),
-                   "destroy",
-                   G_CALLBACK(destroy_applet),
-                   battstat);
-
-  g_signal_connect (battstat->applet,
-                   "change_orient",
-                   G_CALLBACK(change_orient),
-                   battstat);
 
-  g_signal_connect (battstat->applet,
+  g_signal_connect (battstat,
+                    "placement-changed",
+                    G_CALLBACK(placement_changed_cb),
+                    battstat);
+
+  g_signal_connect (battstat,
                    "size_allocate",
                    G_CALLBACK (size_allocate),
                    battstat);
@@ -1531,33 +1469,24 @@ create_layout(ProgressData *battstat)
   return FALSE;
 }
 
-/* Called by the factory to fill in the fields for the applet.
- */
-static gboolean
-battstat_applet_fill (PanelApplet *applet)
+static void
+battstat_applet_fill (BattstatApplet *self)
 {
   ProgressData *battstat;
   AtkObject *atk_widget;
-  GSimpleActionGroup *action_group;
   GAction *action;
-  gchar *ui_path;
+  const char *menu_resource;
   const char *err;
 
-  if (DEBUG) g_print("main()\n");
-
-  panel_applet_set_flags (applet, PANEL_APPLET_EXPAND_MINOR);
-  
-  battstat = g_new0 (ProgressData, 1);
+  battstat = (ProgressData *) self;
 
   /* Some starting values... */
-  battstat->applet = GTK_WIDGET (applet);
-  battstat->settings = panel_applet_settings_new (applet, BATTSTAT_GSCHEMA);
+  battstat->settings = gp_applet_settings_new (GP_APPLET (self), BATTSTAT_GSCHEMA);
   battstat->refresh_label = TRUE;
   battstat->last_batt_life = 1000;
   battstat->last_acline_status = 1000;
   battstat->last_pixmap_index = 1000;
   battstat->last_charging = 1000;
-  battstat->orienttype = panel_applet_get_orient (applet);
   battstat->horizont = TRUE;
   battstat->battery_low_dialog = NULL;
   battstat->battery_low_label = NULL;
@@ -1572,54 +1501,77 @@ battstat_applet_fill (PanelApplet *applet)
   create_layout (battstat);
   setup_text_orientation( battstat );
 
-  action_group = g_simple_action_group_new ();
-  g_action_map_add_action_entries (G_ACTION_MAP (action_group),
-                               battstat_menu_actions,
-                               G_N_ELEMENTS (battstat_menu_actions),
-                               battstat);
-  ui_path = g_build_filename (BATTSTAT_MENU_UI_DIR, "battstat-applet-menu.xml", NULL);
-  panel_applet_setup_menu_from_file (PANEL_APPLET (battstat->applet),
-                                    ui_path, action_group,
-                                    GETTEXT_PACKAGE);
-  g_free (ui_path);
-
-  gtk_widget_insert_action_group (GTK_WIDGET (applet), "battstat",
-                                     G_ACTION_GROUP (action_group));
-
-  action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "preferences");
-  g_object_bind_property (applet, "locked-down", action, "enabled",
-                          G_BINDING_DEFAULT|G_BINDING_INVERT_BOOLEAN|G_BINDING_SYNC_CREATE);
+  menu_resource = GRESOURCE_PREFIX "/ui/battstat-applet-menu.xml";
+  gp_applet_setup_menu_from_resource (GP_APPLET (self),
+                                      menu_resource,
+                                      battstat_menu_actions);
 
-  g_object_unref (action_group);
+  action = gp_applet_menu_lookup_action (GP_APPLET (self), "preferences");
+  g_object_bind_property (self, "locked-down", action, "enabled",
+                          G_BINDING_DEFAULT|G_BINDING_INVERT_BOOLEAN|G_BINDING_SYNC_CREATE);
 
-  atk_widget = gtk_widget_get_accessible (battstat->applet);
+  atk_widget = gtk_widget_get_accessible (GTK_WIDGET (self));
   if (GTK_IS_ACCESSIBLE (atk_widget)) {
          atk_object_set_name (atk_widget, _("Battery Charge Monitor"));
          atk_object_set_description(atk_widget, _("Monitor a laptop's remaining power"));
   }
 
   if ((err = static_global_initialisation (battstat)))
-    battstat_error_dialog (GTK_WIDGET (applet), err);
+    battstat_error_dialog (GTK_WIDGET (self), err);
+}
 
-  return TRUE;
+static void
+battstat_applet_constructed (GObject *object)
+{
+  G_OBJECT_CLASS (battstat_applet_parent_class)->constructed (object);
+  battstat_applet_fill (BATTSTAT_APPLET (object));
 }
 
-/* Boilerplate... */
-static gboolean
-battstat_applet_factory (PanelApplet *applet,
-                        const gchar          *iid,
-                        gpointer              data)
+static void
+battstat_applet_dispose (GObject *object)
 {
-  gboolean retval = FALSE;
+  BattstatApplet *self;
 
-  if (!strcmp (iid, "BattstatApplet"))
-    retval = battstat_applet_fill (applet);
-  
-  return retval;
+  self = BATTSTAT_APPLET (object);
+
+  g_clear_pointer (&self->prop_win, gtk_widget_destroy);
+
+  if (self->battery_low_dialog != NULL)
+    {
+      battery_low_dialog_destroy (self);
+      self->battery_low_dialog = NULL;
+    }
+
+  if (self->timeout_id != 0)
+    {
+      g_source_remove (self->timeout_id);
+      self->timeout_id = 0;
+    }
+
+  g_clear_object (&self->settings);
+
+  g_clear_object (&self->status);
+  g_clear_object (&self->percent);
+  g_clear_object (&self->battery);
+
+  static_global_teardown (self);
+
+  G_OBJECT_CLASS (battstat_applet_parent_class)->dispose (object);
 }
 
+static void
+battstat_applet_class_init (BattstatAppletClass *self_class)
+{
+  GObjectClass *object_class;
+
+  object_class = G_OBJECT_CLASS (self_class);
+
+  object_class->constructed = battstat_applet_constructed;
+  object_class->dispose = battstat_applet_dispose;
+}
 
-PANEL_APPLET_IN_PROCESS_FACTORY ("BattstatAppletFactory",
-                                 PANEL_TYPE_APPLET,
-                                 battstat_applet_factory,
-                                 NULL)
+static void
+battstat_applet_init (BattstatApplet *self)
+{
+  gp_applet_set_flags (GP_APPLET (self), GP_APPLET_FLAGS_EXPAND_MINOR);
+}
diff --git a/gnome-applets/battstat/battstat-applet.h b/gnome-applets/battstat/battstat-applet.h
new file mode 100644
index 000000000..2a4768b8c
--- /dev/null
+++ b/gnome-applets/battstat/battstat-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 BATTSTAT_APPLET_H
+#define BATTSTAT_APPLET_H
+
+#include <libgnome-panel/gp-applet.h>
+
+G_BEGIN_DECLS
+
+#define BATTSTAT_TYPE_APPLET (battstat_applet_get_type ())
+G_DECLARE_FINAL_TYPE (BattstatApplet, battstat_applet,
+                      BATTSTAT, APPLET, GpApplet)
+
+G_END_DECLS
+
+#endif
diff --git a/battstat/battstat_applet.ui b/gnome-applets/battstat/battstat-applet.ui
similarity index 100%
rename from battstat/battstat_applet.ui
rename to gnome-applets/battstat/battstat-applet.ui
diff --git a/battstat/src/battstat-upower.c b/gnome-applets/battstat/battstat-upower.c
similarity index 100%
rename from battstat/src/battstat-upower.c
rename to gnome-applets/battstat/battstat-upower.c
diff --git a/battstat/src/battstat-upower.h b/gnome-applets/battstat/battstat-upower.h
similarity index 100%
rename from battstat/src/battstat-upower.h
rename to gnome-applets/battstat/battstat-upower.h
diff --git a/battstat/src/battstat.h b/gnome-applets/battstat/battstat.h
similarity index 93%
rename from battstat/src/battstat.h
rename to gnome-applets/battstat/battstat.h
index bc13b7931..0ccf427e5 100644
--- a/battstat/src/battstat.h
+++ b/gnome-applets/battstat/battstat.h
@@ -20,13 +20,7 @@
 #ifndef _battstat_h_
 #define _battstat_h_
 
-#include <glib.h>
-#include <glib/gi18n.h>
-#include <gtk/gtk.h>
-
-#include <panel-applet.h>
-
-#define DEBUG 0
+#include "battstat-applet.h"
 
 #define PROGLEN 33.0
 
@@ -92,8 +86,10 @@ typedef struct
   LayoutLocation battery;
 } LayoutConfiguration;
 
-typedef struct _ProgressData {
-  GtkWidget *applet;
+typedef struct _BattstatApplet
+{
+  GpApplet parent;
+
   GSettings *settings;
 
   /* these are used by properties.c */
@@ -131,7 +127,7 @@ typedef struct _ProgressData {
   GtkWidget *percent;
 
   /* dialog boxes that might be displayed */
-  GtkDialog *prop_win;
+  GtkWidget *prop_win;
   GtkWidget *battery_low_dialog;
 
   /* text label inside the low battery dialog */
@@ -143,9 +139,6 @@ typedef struct _ProgressData {
   /* should the battery meter be drawn horizontally? */
   gboolean horizont;
 
-  /* on a vertical or horizontal panel? (up/down/left/right) */
-  PanelAppletOrient orienttype;
-
   /* the current layout of the visual elements inside the table */
   LayoutConfiguration layout;
 
diff --git a/battstat/src/pixmaps.h b/gnome-applets/battstat/pixmaps.h
similarity index 100%
rename from battstat/src/pixmaps.h
rename to gnome-applets/battstat/pixmaps.h
diff --git a/battstat/src/properties.c b/gnome-applets/battstat/properties.c
similarity index 93%
rename from battstat/src/properties.c
rename to gnome-applets/battstat/properties.c
index 417a8379f..8a2bf58a4 100644
--- a/battstat/src/properties.c
+++ b/gnome-applets/battstat/properties.c
@@ -1,5 +1,4 @@
-/* -*- Mode: C; tab-width: 2; indent-tabs-mode: t; c-basic-offset: 2 -*- */
-/* battstat        A GNOME battery meter for laptops. 
+/*
  * Copyright (C) 2000 by Jörgen Pehrson <jp spektr eu org>
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -14,13 +13,9 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- $Id$
  */
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "config.h"
 
 #include <stdio.h>
 
@@ -39,16 +34,11 @@
 #include <time.h>
 #include <unistd.h>
 
+#include <glib/gi18n-lib.h>
 #include <gtk/gtk.h>
 
-#include <panel-applet.h>
-
 #include "battstat.h"
 
-#ifndef gettext_noop
-#define gettext_noop(String) (String)
-#endif
-
 #define NEVER_SENSITIVE                "never_sensitive"
 
 /* set sensitive and setup NEVER_SENSITIVE appropriately */
@@ -109,7 +99,6 @@ static void
 radio_traditional_toggled (GtkToggleButton *button, gpointer data)
 {
   ProgressData   *battstat = data;
-  PanelApplet *applet = PANEL_APPLET (battstat->applet);
   gboolean toggled;
   
   toggled = gtk_toggle_button_get_active (button);
@@ -129,7 +118,6 @@ static void
 radio_ubuntu_toggled (GtkToggleButton *button, gpointer data)
 {
   ProgressData   *battstat = data;
-  PanelApplet *applet = PANEL_APPLET (battstat->applet);
   gboolean toggled;
   
   toggled = gtk_toggle_button_get_active (button);
@@ -149,8 +137,7 @@ static void
 show_text_toggled (GtkToggleButton *button, gpointer data)
 {
   ProgressData   *battstat = data;
-  PanelApplet *applet = PANEL_APPLET (battstat->applet);
-  
+
   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (battstat->radio_text_2))
    && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (battstat->check_text)))
          battstat->showtext = APPLET_SHOW_PERCENT;
@@ -178,8 +165,7 @@ static void
 lowbatt_toggled (GtkToggleButton *button, gpointer data)
 {
   ProgressData   *battstat = data;
-  PanelApplet *applet = PANEL_APPLET (battstat->applet);
-  
+
   battstat->lowbattnotification = gtk_toggle_button_get_active (button);
   g_settings_set_boolean (battstat->settings, KEY_LOW_BATTERY_NOTIFICATION, battstat->lowbattnotification);  
 
@@ -190,8 +176,7 @@ static void
 full_toggled (GtkToggleButton *button, gpointer data)
 {
   ProgressData   *battstat = data;
-  PanelApplet *applet = PANEL_APPLET (battstat->applet);
-  
+
   battstat->fullbattnot = gtk_toggle_button_get_active (button);
   g_settings_set_boolean (battstat->settings, KEY_FULL_BATTERY_NOTIFICATION, battstat->fullbattnot);  
 }
@@ -221,22 +206,19 @@ prop_cb (GSimpleAction *action,
 
   battstat = (ProgressData *) user_data;
 
-  if (DEBUG) g_print("prop_cb()\n");
-
    if (battstat->prop_win) { 
      gtk_window_set_screen (GTK_WINDOW (battstat->prop_win),
-                           gtk_widget_get_screen (battstat->applet));
+                           gtk_widget_get_screen (GTK_WIDGET (battstat)));
      gtk_window_present (GTK_WINDOW (battstat->prop_win));
      return;
    } 
 
-  builder = gtk_builder_new ();
-  gtk_builder_add_from_file (builder, GTK_BUILDERDIR"/battstat_applet.ui", NULL);
+  builder = gtk_builder_new_from_resource (GRESOURCE_PREFIX "/ui/battstat-applet.ui");
 
   battstat->prop_win = GTK_DIALOG (gtk_builder_get_object (builder, 
                                   "battstat_properties"));
   gtk_window_set_screen (GTK_WINDOW (battstat->prop_win),
-                        gtk_widget_get_screen (battstat->applet));
+                        gtk_widget_get_screen (GTK_WIDGET (battstat)));
 
   g_signal_connect (G_OBJECT (battstat->prop_win), "delete_event",
                  G_CALLBACK (gtk_true), NULL);
diff --git a/gnome-applets/ga-module.c b/gnome-applets/ga-module.c
index fd07323fd..792d2166c 100644
--- a/gnome-applets/ga-module.c
+++ b/gnome-applets/ga-module.c
@@ -21,6 +21,7 @@
 #include <glib/gi18n-lib.h>
 #include <libgnome-panel/gp-module.h>
 
+#include "battstat/battstat-applet.h"
 #include "brightness/brightness-applet.h"
 #include "command/command-applet.h"
 #include "gweather/gweather-applet.h"
@@ -37,7 +38,14 @@ ga_get_applet_info (const char *id)
   const char *icon_name;
   GpAppletInfo *info;
 
-  if (g_strcmp0 (id, "brightness") == 0)
+  if (g_strcmp0 (id, "battstat") == 0)
+    {
+      type_func = battstat_applet_get_type;
+      name = _("Battery Charge Monitor");
+      description = _("Monitor a laptop's remaining power");
+      icon_name = "battery";
+    }
+  else if (g_strcmp0 (id, "brightness") == 0)
     {
       type_func = gpm_brightness_applet_get_type;
       name = _("Brightness Applet");
@@ -93,7 +101,9 @@ ga_get_applet_info (const char *id)
 static const char *
 ga_get_applet_id_from_iid (const char *iid)
 {
-  if (g_strcmp0 (iid, "BrightnessAppletFactory::BrightnessApplet") == 0)
+  if (g_strcmp0 (iid, "BattstatAppletFactory::BattstatApplet") == 0)
+    return "battstat";
+  else if (g_strcmp0 (iid, "BrightnessAppletFactory::BrightnessApplet") == 0)
     return "brightness";
   else if (g_strcmp0 (iid, "CommandAppletFactory::CommandApplet") == 0)
     return "command";
@@ -123,6 +133,7 @@ gp_module_load (GpModule *module)
   gp_module_set_version (module, PACKAGE_VERSION);
 
   gp_module_set_applet_ids (module,
+                            "battstat",
                             "brightness",
                             "command",
                             "gweather",
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 813fe7cc4..2533d763c 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -5,11 +5,6 @@
 [type: gettext/glade]accessx-status/accessx-status-applet-menu.xml
 [type: gettext/ini]accessx-status/org.gnome.applets.AccessxStatusApplet.panel-applet.in.in
 accessx-status/src/applet.c
-[type: gettext/glade]battstat/battstat-applet-menu.xml
-[type: gettext/glade]battstat/battstat_applet.ui
-[type: gettext/ini]battstat/org.gnome.applets.BattstatApplet.panel-applet.in.in
-battstat/src/battstat_applet.c
-battstat/src/properties.c
 [type: gettext/glade]charpick/charpick-applet-menu.xml
 [type: gettext/ini]charpick/org.gnome.applets.CharpickerApplet.panel-applet.in.in
 charpick/src/charpick.c
@@ -43,6 +38,10 @@ drivemount/src/drivemount.c
 [type: gettext/ini]geyes/org.gnome.applets.GeyesApplet.panel-applet.in.in
 geyes/src/geyes.c
 geyes/src/themes.c
+[type: gettext/glade]gnome-applets/battstat/battstat-applet-menu.xml
+[type: gettext/glade]gnome-applets/battstat/battstat-applet.ui
+gnome-applets/battstat/battstat-applet.c
+gnome-applets/battstat/properties.c
 [type: gettext/glade]gnome-applets/brightness/brightness-applet-menu.xml
 gnome-applets/brightness/brightness-applet.c
 [type: gettext/glade]gnome-applets/command/command-applet-menu.xml
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 9a80baf6f..6295b8e2d 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -4,7 +4,6 @@
 # upper-case before lower-case).
 #
 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
 cpufreq/org.gnome.applets.CPUFreqApplet.panel-applet.in
 data/schemas/org.gnome.gnome-applets.battstat.gschema.xml.in


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