r1170 - in trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm: . src
zhiyong_sun at sita.openmoko.org
zhiyong_sun at sita.openmoko.org
Thu Mar 1 08:54:49 CET 2007
Author: zhiyong_sun
Date: 2007-03-01 08:54:40 +0100 (Thu, 01 Mar 2007)
New Revision: 1170
Modified:
trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/configure.ac
trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/Makefile.am
trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/moko-gsm-conn.c
trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/moko-gsm-conn.h
trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/openmoko-panel-gsm.c
Log:
convert to matchbox-panel-2
Modified: trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/configure.ac
===================================================================
--- trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/configure.ac 2007-03-01 07:39:08 UTC (rev 1169)
+++ trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/configure.ac 2007-03-01 07:54:40 UTC (rev 1170)
@@ -11,17 +11,14 @@
AC_PROG_LIBTOOL
# base deps
-PKG_CHECK_MODULES(OPENMOKO, openmoko-libs >= 0.0.1,,
- AC_MSG_ERROR([*** Required OpenMoko Libraries >= 0.0.1 not installed ***]))
+PKG_CHECK_MODULES(OPENMOKO, openmoko-libs >= 0.0.2,,
+ AC_MSG_ERROR([*** Required OpenMoko Libraries >= 0.0.2 not installed ***]))
-PKG_CHECK_MODULES(LIBMB, libmb,,
- exit)
-
PKG_CHECK_MODULES(LIBGSMD, libgsmd,,
exit)
-LIBS="$LIBS $GTK_LIBS $LIBMB_LIBS $LIBGSMD_LIBS"
-CFLAGS="$CFLAGS $OPENMOKO_CFLAGS $LIBMB_CFALGS $LIBGSMD_CFLAGS"
+LIBS="$LIBS $GTK_LIBS $LIBGSMD_LIBS"
+CFLAGS="$CFLAGS $OPENMOKO_CFLAGS $LIBGSMD_CFLAGS"
# output stuff
AC_OUTPUT([
Modified: trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/Makefile.am
===================================================================
--- trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/Makefile.am 2007-03-01 07:39:08 UTC (rev 1169)
+++ trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/Makefile.am 2007-03-01 07:54:40 UTC (rev 1170)
@@ -1,10 +1,11 @@
-INCLUDES = -DPKGDATADIR=\"$(pkgdatadir)\" @OPENMOKO_CFLAGS@ -Wall -std=c99 -pedantic
+AM_CPPFLAGS=-DPKGDATADIR=\"$(pkgdatadir)\" -DGETTEXT_PACKAGE=\"matchbox-panel\"
+AM_CFLAGS = -Wall -std=c99 -pedantic @OPENMOKO_CFLAGS@
-bin_PROGRAMS = openmoko-panel-gsm
+appletdir = $(libdir)/matchbox-panel/
+applet_LTLIBRARIES = libopenmoko-panel-gsm.la
-openmoko_panel_gsm_SOURCES = openmoko-panel-gsm.c\
- moko-gsm-conn.c
+libopenmoko_panel_gsm_la_SOURCES = openmoko-panel-gsm.c moko-gsm-conn.c
+libopenmoko_panel_gsm_la_LIBADD = @OPENMOKO_LIBS@
+MAINTAINERCLEANFILES = Makefile.in
-openmoko_panel_gsm_LDADD = @OPENMOKO_LIBS@
-
Modified: trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/moko-gsm-conn.c
===================================================================
--- trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/moko-gsm-conn.c 2007-03-01 07:39:08 UTC (rev 1169)
+++ trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/moko-gsm-conn.c 2007-03-01 07:54:40 UTC (rev 1170)
@@ -147,12 +147,30 @@
moko_panel_gsm_quality(int *quality)
{
update_gsm_signal_qualite();
-
- if (updated){
- *quality = signal_value;
- updated = FALSE;
+
+
+
+ if (updated)
+ {
+ /*switch (signal_value) //needs debug board to test signal value range.
+ {
+ }
+ */
+
+
+ updated = FALSE;
return TRUE;
- }
+ }
else
+ {
+ printf ("This is a test resualt without libgsmd support\n");
+ static int test = 0;
+
+ *quality = test;
+
+ if ( ++test >= TOTAL_SIGNALS )
+ test = 0;
+
return FALSE;
+ }
}
Modified: trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/moko-gsm-conn.h
===================================================================
--- trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/moko-gsm-conn.h 2007-03-01 07:39:08 UTC (rev 1169)
+++ trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/moko-gsm-conn.h 2007-03-01 07:54:40 UTC (rev 1170)
@@ -3,6 +3,16 @@
#define STDIN_BUF_SIZE 1024
+enum{
+ GSM_SIGNAL_ERROR = 0,
+ GSM_SIGNAL_LEVEL_1,
+ GSM_SIGNAL_LEVEL_2,
+ GSM_SIGNAL_LEVEL_3,
+ GSM_SIGNAL_LEVEL_4,
+ GSM_SIGNAL_LEVEL_5,
+ TOTAL_SIGNALS
+};
+
int
moko_panel_gsm_quality(int *quality);
Modified: trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/openmoko-panel-gsm.c
===================================================================
--- trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/openmoko-panel-gsm.c 2007-03-01 07:39:08 UTC (rev 1169)
+++ trunk/src/target/OM-2007/panel-plugins/openmoko-panel-gsm/src/openmoko-panel-gsm.c 2007-03-01 07:54:40 UTC (rev 1170)
@@ -1,334 +1,105 @@
-#include <libmb/mb.h>
-#include <X11/Xlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <unistd.h>
+/* openmoko-panel-gsm.c
+ *
+ * Authored by Sun Zhiyong <sunzhiyong at fic-sh.com.cn>
+ * 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 <libmokoui/moko-panel-applet.h>
+#include <gtk/gtkimage.h>
+#include <time.h>
+
#include "moko-gsm-conn.h"
-#define DIR_LONG 256
-#define FONT_POPUP_DESC "Sans bold 28px"
-#define ADD_IMG "mbadd.png" //use for test
+typedef struct {
+ int gsm_quality;
+ GtkImage *image;
+ guint timeout_id;
+} GsmApplet;
-enum {
- conn_err=0,
- level_1,
- level_2,
- level_3,
- level_4,
- level_5,
- MAX_ID,
-};
-
-static MBPixbuf *pb;
-static MBPixbufImage *img_icon[MAX_ID];
-static MBPixbufImage *img_scaled[MAX_ID];
-static int cur_img = 0;
-static int last_img = -1;
-MBMenu* popupmenu;
-static Display *dpy;
-static int screen;
-static int times = 0;
-static int gsm_quality = 0;
-
-static void
-fork_exec(char *cmd)
-{
- switch (fork())
- {
- case 0:
- setpgid(0, 0); /* Stop us killing child */
- mb_exec(cmd);
- fprintf(stderr, "openmoko-panel-gsm: Failed to Launch '%s'\n", cmd);
- exit(1);
- case -1:
- fprintf(stderr, "openmoko-panel-gsm: Failed to Launch '%s'", cmd);
- break;
- }
-}
-
-void
-om_gsm_connect_dialog_cb(MBMenuItem *item)
-{
- fprintf(stdout, "open connect status dialog");
-}
-
static void
-om_gsm_disconnect_dialog_cb(MBMenuItem *item)
+gsm_applet_free (GsmApplet *applet)
{
- fprintf(stdout, "open disconnect status dialog");
-}
+ g_source_remove (applet->timeout_id);
-static void
-xevent_callback (MBTrayApp *app, XEvent *e)
-{
- mb_menu_handle_xevent (popupmenu, e);
+ g_slice_free (GsmApplet, applet);
}
-static void
-menu_get_popup_pos (MBTrayApp *app, int *x, int *y)
+static gboolean
+timeout_cb (GsmApplet *applet)
{
- int abs_x, abs_y, menu_h, menu_w;
- mb_tray_app_get_absolute_coords (app, &abs_x, &abs_y);
- mb_menu_get_root_menu_size(popupmenu, &menu_w, &menu_h);
- if (mb_tray_app_tray_is_vertical (app))
- {
- /* XXX need to figure out menu size before its mapped
- so we can figure out offset for east panel
- */
- *y = abs_y + mb_tray_app_height(app);
+ /* if (!moko_panel_gsm_quality (&gsm_quality)) //signal value not changed.
+ return TRUE;
+ */
+ moko_panel_gsm_quality (&(applet->gsm_quality));
+ g_debug ("moko gsm quality = %d", applet->gsm_quality);
- if (abs_x > (DisplayWidth(mb_tray_app_xdisplay(app), mb_tray_app_xscreen(app)) /2))
- *x = abs_x - menu_w - 2;
- else
- *x = abs_x + mb_tray_app_width(app) + 2;
- }
- else
- {
- *x = abs_x;
- if (abs_y > (DisplayHeight(mb_tray_app_xdisplay(app), mb_tray_app_xscreen(app)) /2))
- *y = abs_y - 2;
- else
- *y = abs_y + mb_tray_app_height(app) + menu_h;
- }
-}
+ switch (applet->gsm_quality)
+ {
+ case GSM_SIGNAL_ERROR :
+ gtk_image_set_from_file (applet->image, PKGDATADIR"/SignalStrength25g_00.png");
+ break;
-static void
-menu_init(MBTrayApp* app)
-{
- char* icon_path_ucon;
- char* icon_path_con;
- char* mb_theme;
+ case GSM_SIGNAL_LEVEL_1 :
+ gtk_image_set_from_file (applet->image, PKGDATADIR"/SignalStrength25g_01.png");
+ break;
-if (popupmenu == NULL)
- {
- popupmenu = mb_menu_new (mb_tray_app_xdisplay(app),
- mb_tray_app_xscreen(app));
- mb_menu_set_icon_size(popupmenu, 32);
- mb_menu_set_font (popupmenu, FONT_POPUP_DESC);
- mb_menu_set_trans(popupmenu, 0);
- }
- else mb_menu_free(popupmenu);
+ case GSM_SIGNAL_LEVEL_2 :
+ gtk_image_set_from_file (applet->image, PKGDATADIR"/SignalStrength25g_02.png");
+ break;
- //if ((mb_theme = mb_tray_app_get_theme_name (app) ) == NULL) exit(1);
- mb_theme = mb_tray_app_get_theme_name (app);
+ case GSM_SIGNAL_LEVEL_3 :
+ gtk_image_set_from_file (applet->image, PKGDATADIR"/SignalStrength25g_03.png");
+ break;
-
- icon_path_con = mb_dot_desktop_icon_get_full_path (mb_theme,
- 16, ADD_IMG );
+ case GSM_SIGNAL_LEVEL_4 :
+ gtk_image_set_from_file (applet->image, PKGDATADIR"/SignalStrength25g_04.png");
+ break;
- icon_path_ucon = mb_dot_desktop_icon_get_full_path (mb_theme,
- 16, ADD_IMG );
-
- mb_menu_add_item_to_menu(popupmenu, popupmenu->rootmenu, "Connect",
- icon_path_con, NULL ,
- om_gsm_connect_dialog_cb, (void *)app, MBMENU_NO_SORT);
+ case GSM_SIGNAL_LEVEL_5 :
+ gtk_image_set_from_file (applet->image, PKGDATADIR"/SignalStrength25g_05.png");
+ break;
- mb_menu_add_item_to_menu(popupmenu, popupmenu->rootmenu, "Disconnect",
- icon_path_ucon, NULL ,
- om_gsm_disconnect_dialog_cb, (void *)app, MBMENU_NO_SORT);
+ default :
+ gtk_image_set_from_file (applet->image, PKGDATADIR"/SignalStrength25g_00.png");
+ break;
+ }
- if (icon_path_con) free (icon_path_con);
- if (icon_path_ucon) free (icon_path_ucon);
- if (mb_theme) free (mb_theme);
+ /* Keep going */
+ return TRUE;
}
-static void
-paint_callback (MBTrayApp *app, Drawable drw )
+G_MODULE_EXPORT GtkWidget*
+mb_panel_applet_create(const char* id, GtkOrientation orientation)
{
- MBPixbufImage *img_backing = NULL;
+ MokoPanelApplet* mokoapplet = moko_panel_applet_new();
- cur_img = gsm_quality;
+ GsmApplet *applet;
+ time_t t;
+ struct tm *local_time;
- if (last_img == cur_img)
- return;
-
- img_backing = mb_tray_app_get_background (app, pb);
+ applet = g_slice_new (GsmApplet);
- mb_pixbuf_img_copy_composite(pb, img_backing,
- img_scaled[cur_img], 0, 0,
- mb_pixbuf_img_get_width(img_scaled[0]),
- mb_pixbuf_img_get_height(img_scaled[0]),
- mb_tray_app_tray_is_vertical(app) ?
- (mb_pixbuf_img_get_width(img_backing)-mb_pixbuf_img_get_width(img_scaled[0]))/2 : 0,
- mb_tray_app_tray_is_vertical(app) ? 0 :
- (mb_pixbuf_img_get_height(img_backing)-mb_pixbuf_img_get_height(img_scaled[0]))/2 );
+ applet->image = GTK_IMAGE(gtk_image_new_from_file (PKGDATADIR"/SignalStrength25g_00.png"));
+ gtk_widget_set_name( applet->image, "OpenMoko gsm applet" );
+ g_object_weak_ref( G_OBJECT(applet->image), (GWeakNotify) gsm_applet_free, applet );
- mb_pixbuf_img_render_to_drawable(pb, img_backing, drw, 0, 0);
+ t = time( NULL );
+ local_time = localtime(&t);
+ applet->timeout_id = g_timeout_add( 2000, (GSourceFunc) timeout_cb, applet);
- mb_pixbuf_img_free( pb, img_backing );
-
- last_img = cur_img;
-}
-
-static void
-resize_callback (MBTrayApp *app, int w, int h )
-{
- int i;
- int base_width = mb_pixbuf_img_get_width(img_icon[0]);
- int base_height = mb_pixbuf_img_get_height(img_icon[0]);
- int scale_width = base_width, scale_height = base_height;
- Bool want_resize = True;
-
- if (mb_tray_app_tray_is_vertical(app) && w < base_width)
- {
-
- scale_width = w;
- scale_height = ( base_height * w ) / base_width;
-
- want_resize = False;
- }
- else if (!mb_tray_app_tray_is_vertical(app) && h < base_height)
- {
- scale_height = h;
- scale_width = ( base_width * h ) / base_height;
- want_resize = False;
- }
-
- if (w < base_width && h < base_height
- && ( scale_height > h || scale_width > w))
- {
-
- /* Something is really wrong to get here */
- scale_height = h; scale_width = w;
- want_resize = False;
- }
-
- if (want_resize) /* we only request a resize is absolutely needed */
- {
- last_img = -1;
- mb_tray_app_request_size (app, scale_width, scale_height);
- }
-
- for (i=0; i<MAX_ID; i++)
- {
- if (img_scaled[i] != NULL)
- mb_pixbuf_img_free(pb, img_scaled[i]);
-
- img_scaled[i] = mb_pixbuf_img_scale(pb,
- img_icon[i],
- scale_width,
- scale_height);
- }
-}
-
-/**
-*@brief button callback function.
-*/
-static void
-button_callback (MBTrayApp *app, int x, int y, Bool is_released )
-{
- XEvent ev;
- int done = 0;
- struct timeval then, now;
- Time click_time = 800;
- int click_x,click_y;
- int counter = 10;
-
- fprintf(stdout, "openmoko-panel-gsm: %d times call function buttoncallback", ++times);
-
- if (!popupmenu) return; /* menu disabled */
-
- gettimeofday(&then, NULL);
-
- //check the click type: tap "done = 1 "; tap with hold "done = 2";
- while (!done && !is_released)
- {
- if (XCheckMaskEvent(dpy,ButtonReleaseMask, &ev))
- if (ev.type == ButtonRelease)
- {
- done = 1;
- }
-
- gettimeofday(&now, NULL);
-
- if ((now.tv_usec-then.tv_usec) > (click_time*50000))
- {
- done = 2;
- }
- }
-
-//function for "tap" action.
- if (done == 1)
- {
- mb_tray_app_tray_send_message(app, "Run openmoko-gsm application (openmoko-preference)", 6000);
- //fork_exec("openmoko-preference"); //launch openmoko-preference.
- return;
- }
-//function for "tap with hold" action.
- else if (done == 2 && !mb_menu_is_active(popupmenu))
- {
- mb_tray_app_tray_send_message(app, "Connect or reconnect gsm signal", 6000);
-
- // menu_get_popup_pos(app, &click_x, &click_y);
- //fprintf(stdout, "openmoko-panel-gsm: x = %d, y = %d\n", click_x, click_y);
- //mb_menu_activate(popupmenu, click_x, click_y);
- }
-}
-
-static void
-timeout_callback ( MBTrayApp *app )
-{
- if (moko_panel_gsm_quality(&gsm_quality))
- {
- printf ("quality = %d\n", gsm_quality);
- mb_tray_app_repaint (app);
- return;
- }
- else
- {
- printf ("signal quality have not changed \n");
- return;
- }
-}
-
-
-int
-main( int argc, char *argv[])
-{
- MBTrayApp *app = NULL;
- struct timeval tv;
- int i =0;
-
- app = mb_tray_app_new ( "gsm Monitor",
- resize_callback,
- paint_callback,
- &argc,
- &argv );
-
- dpy = mb_tray_app_xdisplay(app);
- screen = mb_tray_app_xscreen(app);
-
- pb = mb_pixbuf_new(mb_tray_app_xdisplay(app),
- mb_tray_app_xscreen(app));
-
- memset (&tv,0,sizeof(struct timeval));
- tv.tv_sec = 5;
- tv.tv_usec = 0;
-
- menu_init (app);
-
- img_icon[conn_err]= mb_pixbuf_img_new_from_file(pb, PKGDATADIR"/SignalStrength25g_00.png");
- img_icon[level_1]= mb_pixbuf_img_new_from_file(pb, PKGDATADIR"/SignalStrength25g_01.png");
- img_icon[level_2]= mb_pixbuf_img_new_from_file(pb, PKGDATADIR"/SignalStrength25g_02.png");
- img_icon[level_3]= mb_pixbuf_img_new_from_file(pb, PKGDATADIR"/SignalStrength25g_03.png");
- img_icon[level_4]= mb_pixbuf_img_new_from_file(pb, PKGDATADIR"/SignalStrength25g_04.png");
- img_icon[level_5]= mb_pixbuf_img_new_from_file(pb, PKGDATADIR"/SignalStrength25g_05.png");
-
- mb_tray_app_set_timeout_callback (app, timeout_callback, &tv);
-
- mb_tray_app_set_button_callback (app, button_callback );
-
- mb_tray_app_set_xevent_callback(app, xevent_callback);
-
- mb_tray_app_set_icon(app, pb, img_icon[level_3]);
-
- mb_tray_app_request_offset (app, 1);
-
- mb_tray_app_main (app);
-
- XCloseDisplay(dpy);
-
-}
+ moko_panel_applet_set_widget( GTK_CONTAINER(mokoapplet), applet->image );
+ gtk_widget_show_all( GTK_WIDGET(mokoapplet) );
+ return GTK_WIDGET(mokoapplet);
+};
More information about the commitlog
mailing list