and the patch...
On Wed, Apr 16, 2008 at 07:37:27PM +0800, John Lee wrote:
> Hi,
>
> Since now we can turn on/off gps from neod (power button), and it's
> relatively harder to reach the edge of touch screen on neo, I would
> like to propose we remove the popup menu from every icon on panel.
> This will be consistent with the wifi and usb icons. What left now
> are gsm and bluetooth.
>
> Here is a patch to openmoko-panel, if nobody rejects I will commit it
> by the end of this week.
>
>
> Regards,
> John
>
Index: src/openmoko-panel-gps.c
===================================================================
--- src/openmoko-panel-gps.c (revision 4289)
+++ src/openmoko-panel-gps.c (working copy)
@@ -1,18 +1,13 @@
-/* openmoko-panel-gps.c
- *
- * Authored by Michael 'Mickey' Lauer <[EMAIL PROTECTED]>
- * Copyright (C) 2007 OpenMoko Inc.
- *
- * 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
- * the Free Software Foundation; version 2 of the license.
- *
- * 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 Lesser Public License for more details.
- *
- * Current Version: $Rev$ ($Date$) [$Author: mickey $]
+/*
+ * openmoko-panel-gps.c Authored by Michael 'Mickey' Lauer
+ * <[EMAIL PROTECTED]> Copyright (C) 2007 OpenMoko Inc. 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 the Free
+ * Software Foundation; version 2 of the license. 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 Lesser Public License
+ * for more details. Current Version: $Rev$ ($Date$) [$Author: mickey $]
*/
#include <libmokopanelui2/moko-panel-applet.h>
#include <gtk/gtkbox.h>
@@ -23,99 +18,70 @@
#include <stdio.h>
#define GPS_PWOERON_FILENAME "/sys/bus/platform/drivers/neo1973-pm-gps/neo1973-pm-gps.0/pwron"
+#define QUERY_FREQ 5
+
typedef struct {
- MokoPanelApplet* mokoapplet;
- int state;
+ MokoPanelApplet *mokoapplet;
+ guint timeout_id;
} GpsApplet;
-static void
-gps_applet_free (GpsApplet *applet)
+static gboolean gps_applet_is_power_on()
{
- g_slice_free (GpsApplet, applet);
-}
-
-static int
-gps_applet_power_get()
-{
char buf[64];
- FILE * f = fopen(GPS_PWOERON_FILENAME, "r");
+ FILE *f = fopen(GPS_PWOERON_FILENAME, "r");
int ret;
if (!f) {
- printf("Open file %s failed!!\n",GPS_PWOERON_FILENAME);
- return 0;
+ printf("Open file %s failed!!\n", GPS_PWOERON_FILENAME);
+ return 0;
}
- ret = fread(buf,sizeof(char),sizeof(buf)/sizeof(char),f);
+ ret = fread(buf, sizeof(char), sizeof(buf) / sizeof(char), f);
fclose(f);
- if (ret > 0 && buf[0]=='1') {
- return 1;
+ if (ret > 0 && buf[0] == '1') {
+ return 1;
}
return 0;
}
-static int
-gps_applet_power_set(int on)
+static void gps_applet_update_status(GpsApplet * applet)
{
- char buf[64];
- FILE * f = fopen(GPS_PWOERON_FILENAME, "w");
- int ret;
- if (!f) {
- printf("Open file %s failed!!\n",GPS_PWOERON_FILENAME);
- return 0;
+ if (gps_applet_is_power_on()) {
+ gtk_widget_show(GTK_WIDGET(applet->mokoapplet));
+ } else {
+ gtk_widget_hide(GTK_WIDGET(applet->mokoapplet));
}
- sprintf(buf,"%d",on ==0 ? 0 : 1);
- ret = fwrite(buf,sizeof(char),sizeof(buf)/sizeof(char),f);
- fclose(f);
- if (ret <= 0) {
- printf("Write date into device failed!!\n");
- return 0;
- }
- return on ==0 ? 0 : 1;
}
-static void
-mb_panel_update (GpsApplet *applet, int state)
+static void gps_applet_weak_notify_cb(gpointer data, GObject * dead_object)
{
- moko_panel_applet_set_icon( applet->mokoapplet, state == 1 ? PKGDATADIR "/GPS_On.png" : PKGDATADIR "/GPS_Off.png");
- applet->state = state;
- printf("GPS State is %d\n", applet->state);
+ GpsApplet *applet = (GpsApplet *) data;
+ g_source_remove(applet->timeout_id);
+ g_slice_free(GpsApplet, applet);
}
-static void
-gps_applet_power_on (GtkWidget* menu, GpsApplet* applet) {
- mb_panel_update(applet,gps_applet_power_set(1));
+static gboolean gps_applet_timeout_cb(gpointer data)
+{
+ gps_applet_update_status((GpsApplet *) data);
+ return TRUE;
}
-static void
-gps_applet_power_off (GtkWidget* menu, GpsApplet* applet) {
- mb_panel_update(applet,gps_applet_power_set(0));
-}
-
-G_MODULE_EXPORT GtkWidget*
-mb_panel_applet_create(const char* id, GtkOrientation orientation)
+G_MODULE_EXPORT GtkWidget *mb_panel_applet_create(const char *id,
+ GtkOrientation
+ orientation)
{
- MokoPanelApplet* mokoapplet = moko_panel_applet_new();
-
GpsApplet *applet;
- time_t t;
- struct tm *local_time;
+ MokoPanelApplet *mokoapplet =
+ MOKO_PANEL_APPLET(moko_panel_applet_new());
- applet = g_slice_new (GpsApplet);
+ applet = g_slice_new(GpsApplet);
applet->mokoapplet = mokoapplet;
- applet->state=-100;
- moko_panel_applet_set_icon(applet->mokoapplet,PKGDATADIR "/GPS_Off.png");
- mb_panel_update(applet, gps_applet_power_get());
- gtk_widget_show_all( GTK_WIDGET(mokoapplet) );
-
- GtkMenu* menu = GTK_MENU(gtk_menu_new());
- GtkWidget* item1 = gtk_menu_item_new_with_label("Power-Up GPS");
- GtkWidget* item2 = gtk_menu_item_new_with_label("Power-Off GPS");
- g_signal_connect(G_OBJECT(item1), "activate", G_CALLBACK(gps_applet_power_on), applet);
- g_signal_connect(G_OBJECT(item2), "activate", G_CALLBACK(gps_applet_power_off), applet);
- gtk_menu_shell_append(GTK_MENU_SHELL(menu), item1);
- gtk_menu_shell_append(GTK_MENU_SHELL(menu), item2);
- gtk_widget_show_all(GTK_WIDGET(menu));
- moko_panel_applet_set_popup( mokoapplet, GTK_WIDGET(menu), MOKO_PANEL_APPLET_CLICK_POPUP);
+ g_object_weak_ref((GObject *) applet->mokoapplet,
+ gps_applet_weak_notify_cb, applet);
+ moko_panel_applet_set_icon(applet->mokoapplet,
+ PKGDATADIR "/GPS_Off.png");
+ gtk_widget_show_all( mokoapplet );
+ applet->timeout_id =
+ g_timeout_add_seconds(QUERY_FREQ, gps_applet_timeout_cb, applet);
- return GTK_WIDGET(mokoapplet);
+ return applet->mokoapplet;
};