r1046 - in trunk/src/target/OM-2007/panel-plugins/openmoko-panel-battery: data src

mickey at sita.openmoko.org mickey at sita.openmoko.org
Tue Feb 20 01:10:29 CET 2007


Author: mickey
Date: 2007-02-20 01:10:28 +0100 (Tue, 20 Feb 2007)
New Revision: 1046

Modified:
   trunk/src/target/OM-2007/panel-plugins/openmoko-panel-battery/data/Makefile.am
   trunk/src/target/OM-2007/panel-plugins/openmoko-panel-battery/src/Makefile.am
   trunk/src/target/OM-2007/panel-plugins/openmoko-panel-battery/src/openmoko-panel-battery.c
Log:
openmoko-panel-battery: first version working w/ matchbox-panel-2


Modified: trunk/src/target/OM-2007/panel-plugins/openmoko-panel-battery/data/Makefile.am
===================================================================
--- trunk/src/target/OM-2007/panel-plugins/openmoko-panel-battery/data/Makefile.am	2007-02-19 23:36:47 UTC (rev 1045)
+++ trunk/src/target/OM-2007/panel-plugins/openmoko-panel-battery/data/Makefile.am	2007-02-20 00:10:28 UTC (rev 1046)
@@ -2,4 +2,5 @@
 # misc. data files
 #
 resourcedir = $(pkgdatadir)
-resource_DATA_DIST = Battery_01.png  Battery_02.png  Battery_03.png  Battery_04.png  Battery_05.png  Battery_Plug.png  Battery.png  Battery_Warning.png
+resource_DATA = Battery_00.png Battery_01.png  Battery_02.png   Battery_03.png \
+                Battery_04.png  Battery_05.png Battery_Plug.png Battery.png

Modified: trunk/src/target/OM-2007/panel-plugins/openmoko-panel-battery/src/Makefile.am
===================================================================
--- trunk/src/target/OM-2007/panel-plugins/openmoko-panel-battery/src/Makefile.am	2007-02-19 23:36:47 UTC (rev 1045)
+++ trunk/src/target/OM-2007/panel-plugins/openmoko-panel-battery/src/Makefile.am	2007-02-20 00:10:28 UTC (rev 1046)
@@ -5,7 +5,7 @@
 applet_LTLIBRARIES = libopenmoko-panel-battery.la
 
 libopenmoko_panel_battery_la_SOURCES = openmoko-panel-battery.c
-libopenmoko_panel_battery_la_LIBADD = @OPENMOKO_LIBS@
+libopenmoko_panel_battery_la_LIBADD = @OPENMOKO_LIBS@ -lapm
 
 MAINTAINERCLEANFILES = Makefile.in
 

Modified: trunk/src/target/OM-2007/panel-plugins/openmoko-panel-battery/src/openmoko-panel-battery.c
===================================================================
--- trunk/src/target/OM-2007/panel-plugins/openmoko-panel-battery/src/openmoko-panel-battery.c	2007-02-19 23:36:47 UTC (rev 1045)
+++ trunk/src/target/OM-2007/panel-plugins/openmoko-panel-battery/src/openmoko-panel-battery.c	2007-02-20 00:10:28 UTC (rev 1046)
@@ -3,11 +3,12 @@
  *  Authored by Michael 'Mickey' Lauer <mlauer at vanille-media.de>
  *  Copyright (C) 2007 OpenMoko Inc.
  *
- *  Based on Battery Applet for matchbox-panel-2 by Jorn Baayen <jorn at openedhand.com>
+ *  Based on Battery Applet for matchbox-panel-2 by
+ *  Jorn Baayen <jorn at openedhand.com>
  *  (C) 2006 OpenedHand Ltd.
  *
  *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU Lesser Public License as published by
+ *  it under the terms of the GNU Public License as published by
  *  the Free Software Foundation; version 2 of the license.
  *
  *  This program is distributed in the hope that it will be useful,
@@ -21,18 +22,28 @@
 #include <libmokoui/moko-panel-applet.h>
 
 #include <gtk/gtklabel.h>
+
+#include <apm.h>
 #include <time.h>
 
+#define JUICE_PIXMAPS 6
+
+#define DEBUG_THIS_FILE
+
 typedef struct {
-        GtkLabel *label;
-        guint timeout_id;
+    GdkPixbuf* enclosing;
+    GdkPixbuf* plug;
+    GdkPixbuf* juice[JUICE_PIXMAPS];
+    GdkPixbuf* indicator;
+    GtkImage *image;
+    guint timeout_id;
 } BatteryApplet;
 
 static void
 battery_applet_free (BatteryApplet *applet)
 {
-        g_source_remove (applet->timeout_id);
-        g_slice_free (BatteryApplet, applet);
+    g_source_remove (applet->timeout_id);
+    g_slice_free (BatteryApplet, applet);
 }
 
 /* Called every 5 minutes */
@@ -40,9 +51,50 @@
 timeout (BatteryApplet *applet)
 {
     g_debug( "update battery applet" );
-        // draw...
-        /* Keep going */
-        return TRUE;
+
+    apm_info info;
+    // How about g_new0 here?
+    memset (&info, 0, sizeof (apm_info));
+    apm_read (&info);
+
+    /* compose new pixmap and set label */
+
+    guint w = gdk_pixbuf_get_width( applet->indicator );
+    guint h = gdk_pixbuf_get_height( applet->indicator );
+
+    gdk_pixbuf_copy_area( applet->enclosing, 0, 0, w, h, applet->indicator, 0, 0 );
+
+    GdkPixbuf* icon;
+
+    //FIXME Can we actually find out, when the battery is full?
+
+    if ( info.battery_status == BATTERY_STATUS_ABSENT ||
+         info.battery_status == AC_LINE_STATUS_ON )
+    {
+         icon = applet->plug;
+    }
+    else
+    {
+        if (info.battery_percentage < 10)
+            icon = applet->juice[0];
+        else if (info.battery_percentage < 30)
+            icon = applet->juice[1];
+        else if (info.battery_percentage < 50)
+            icon = applet->juice[2];
+        else if (info.battery_percentage < 70)
+            icon = applet->juice[3];
+        else if (info.battery_percentage < 90)
+            icon = applet->juice[4];
+        else
+            icon = applet->juice[5];
+    }
+
+    //FIXME Check whether we actually need to update
+
+    gdk_pixbuf_composite( icon, applet->indicator, 0, 0, w, h, 0, 0, 1, 1, GDK_INTERP_NEAREST, 255 );
+    gtk_image_set_from_pixbuf( applet->image, applet->indicator );
+
+    return TRUE;
 }
 
 G_MODULE_EXPORT GtkWidget* mb_panel_applet_create(const char* id, GtkOrientation orientation)
@@ -55,16 +107,39 @@
 
     applet = g_slice_new (BatteryApplet);
 
-    applet->label = GTK_LABEL(gtk_label_new (NULL));
-    gtk_widget_set_name( applet->label, "MatchboxPanelBattery" );
-    g_object_weak_ref( G_OBJECT(applet->label), (GWeakNotify) battery_applet_free, applet );
+    applet->image = GTK_IMAGE(gtk_image_new());
+    gtk_widget_set_name( GTK_WIDGET(applet->image), "MatchboxPanelBattery" );
+    g_object_weak_ref( G_OBJECT(applet->image), (GWeakNotify) battery_applet_free, applet );
 
+    /* preload pixbufs */
+    guint i = 0;
+    applet->juice[i++] = gdk_pixbuf_new_from_file( PKGDATADIR "/Battery_00.png", NULL );
+    applet->juice[i++] = gdk_pixbuf_new_from_file( PKGDATADIR "/Battery_01.png", NULL );
+    applet->juice[i++] = gdk_pixbuf_new_from_file( PKGDATADIR "/Battery_02.png", NULL );
+    applet->juice[i++] = gdk_pixbuf_new_from_file( PKGDATADIR "/Battery_03.png", NULL );
+    applet->juice[i++] = gdk_pixbuf_new_from_file( PKGDATADIR "/Battery_04.png", NULL );
+    applet->juice[i++] = gdk_pixbuf_new_from_file( PKGDATADIR "/Battery_05.png", NULL );
+    applet->enclosing = gdk_pixbuf_new_from_file( PKGDATADIR "/Battery.png", NULL );
+    applet->plug = gdk_pixbuf_new_from_file( PKGDATADIR "/Battery_Plug.png", NULL );
+
+    applet->indicator = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8,
+                                      gdk_pixbuf_get_width( applet->enclosing ),
+                                      gdk_pixbuf_get_height( applet->enclosing ) );
+
+    gtk_widget_set_size_request( GTK_WIDGET(applet->image),
+                                 gdk_pixbuf_get_width( applet->indicator ),
+                                 gdk_pixbuf_get_height( applet->indicator ) );
+
     t = time( NULL );
     local_time = localtime(&t);
+#ifndef DEBUG_THIS_FILE
     applet->timeout_id = g_timeout_add( 60 * 1000 * 5, (GSourceFunc) timeout, applet);
     timeout(applet);
-
-    moko_panel_applet_set_widget( GTK_CONTAINER(mokoapplet), applet->label );
+    //FIXME Add source watching for charger insertion event on /dev/input/event1
+#else
+    applet->timeout_id = g_timeout_add( 1000, (GSourceFunc) timeout, applet);
+#endif
+    moko_panel_applet_set_widget( MOKO_PANEL_APPLET(mokoapplet), GTK_WIDGET(applet->image) );
     gtk_widget_show_all( GTK_WIDGET(mokoapplet) );
     return GTK_WIDGET(mokoapplet);
 };





More information about the commitlog mailing list