monkey-bubble r246 - in trunk: . src/monkey src/ui



Author: herzi
Date: Sat Jan 12 22:02:57 2008
New Revision: 246
URL: http://svn.gnome.org/viewvc/monkey-bubble?rev=246&view=rev

Log:
2008-01-12  Sven Herzberg  <herzi gnome-de org>

	Merge the outstanding Maemo changes from Jouni Roivas.

	* src/monkey/board.c,
	* src/monkey/board.h,
	* src/monkey/monkey.c,
	* src/monkey/monkey.h,
	* src/monkey/playground.c,
	* src/monkey/playground.h,
	* src/ui/Makefile.am,
	* src/ui/game-1-player-manager.c,
	* src/ui/game-1-player.c,
	* src/ui/game-1-player.h,
	* src/ui/global.h,
	* src/ui/main.c,
	* src/ui/state.c,
	* src/ui/state.h,
	* src/ui/ui-main.c,
	* src/ui/ui-main.h,
	* src/ui/ui-network-client.c: implement the maemo ui


Added:
   trunk/src/ui/global.h
   trunk/src/ui/state.c
   trunk/src/ui/state.h
Modified:
   trunk/ChangeLog
   trunk/src/monkey/board.c
   trunk/src/monkey/board.h
   trunk/src/monkey/monkey.c
   trunk/src/monkey/monkey.h
   trunk/src/monkey/playground.c
   trunk/src/monkey/playground.h
   trunk/src/ui/Makefile.am
   trunk/src/ui/game-1-player-manager.c
   trunk/src/ui/game-1-player.c
   trunk/src/ui/game-1-player.h
   trunk/src/ui/main.c
   trunk/src/ui/ui-main.c
   trunk/src/ui/ui-main.h
   trunk/src/ui/ui-network-client.c

Modified: trunk/src/monkey/board.c
==============================================================================
--- trunk/src/monkey/board.c	(original)
+++ trunk/src/monkey/board.c	Sat Jan 12 22:02:57 2008
@@ -165,6 +165,61 @@
 	return b;
 }
 
+
+#ifdef MAEMO
+void
+board_save_to_file (Board * board, const char *filename)
+{
+        #define MUL 4 
+        GError *error = NULL;
+        GIOChannel *channel;
+        gint i, j, s=0;
+        gchar buffer[COLUMN_COUNT*3+2];
+        gsize written = 0;
+
+        if (PRIVATE(board)->bubble_array==NULL) return;
+
+        channel = g_io_channel_new_file (filename, "w+", &error);
+
+        if (channel == NULL) return;
+
+        for (i = 0; i < ROW_COUNT; i++)
+        {
+                for (j = 0; j < COLUMN_COUNT*MUL; j++)
+                        buffer[j] = ' ';
+
+                if (i%2==1) {
+                        s = 2; 
+                } else {
+                        s = 0;
+                }
+
+                for (j = 0; j < COLUMN_COUNT; j++)
+                {
+                        Bubble *b;
+                        Color c;
+
+                        if (s>0 && (j+1==COLUMN_COUNT)) break;
+
+                        b = PRIVATE(board)->bubble_array[i*COLUMN_COUNT+j];
+                        if (b!=NULL) {
+                                c = bubble_get_color(b);
+                                buffer[j*MUL+s] = '0'+(int)c;
+                        } else {
+                                buffer[j*MUL+s] = '-';
+                        }
+                }
+                buffer[COLUMN_COUNT*MUL]='\n';
+                buffer[COLUMN_COUNT*MUL+1]=0;
+
+                g_io_channel_write_chars(channel, (const gchar *)&buffer, -1, &written, &error);
+        }
+
+        g_io_channel_shutdown (channel, TRUE, &error);
+        g_io_channel_unref (channel);
+}
+#endif
+
 void
 board_load_from_file (Board * board, const char *filename, gint level)
 {

Modified: trunk/src/monkey/board.h
==============================================================================
--- trunk/src/monkey/board.h	(original)
+++ trunk/src/monkey/board.h	Sat Jan 12 22:02:57 2008
@@ -61,6 +61,9 @@
 
 Bubble **board_get_array (Board * board);
 void board_print (Board * board);
+#ifdef MAEMO
+void board_save_to_file (Board * board, const char *filename);
+#endif
 
 
 #define TYPE_BOARD            (board_get_type())

Modified: trunk/src/monkey/monkey.c
==============================================================================
--- trunk/src/monkey/monkey.c	(original)
+++ trunk/src/monkey/monkey.c	Sat Jan 12 22:02:57 2008
@@ -737,3 +737,9 @@
 	return monkey_type;
 }
 
+#ifdef MAEMO
+void monkey_save(Monkey *monkey, const gchar * filename)
+{
+       playground_save(PRIVATE(monkey)->playground, filename);
+}
+#endif

Modified: trunk/src/monkey/monkey.h
==============================================================================
--- trunk/src/monkey/monkey.h	(original)
+++ trunk/src/monkey/monkey.h	Sat Jan 12 22:02:57 2008
@@ -105,6 +105,9 @@
 
 
 gboolean monkey_is_empty(Monkey * monkey);
+#ifdef MAEMO
+void monkey_save(Monkey *monkey, const gchar * filename);
+#endif
 G_END_DECLS
 
 

Modified: trunk/src/monkey/playground.c
==============================================================================
--- trunk/src/monkey/playground.c	(original)
+++ trunk/src/monkey/playground.c	Sat Jan 12 22:02:57 2008
@@ -307,3 +307,10 @@
 	return playground_type;
 }
 
+#ifdef MAEMO
+void 
+playground_save(Playground * self, const gchar * level_filename)
+{
+       board_save_to_file(PRIVATE(self)->board, level_filename);
+}
+#endif

Modified: trunk/src/monkey/playground.h
==============================================================================
--- trunk/src/monkey/playground.h	(original)
+++ trunk/src/monkey/playground.h	Sat Jan 12 22:02:57 2008
@@ -52,6 +52,9 @@
 
 void playground_shoot_bubble(Playground *pl,Bubble * b);
 
+#ifdef MAEMO
+void playground_save(Playground * self, const gchar * level_filename);
+#endif
 
 #define TYPE_PLAYGROUND            (playground_get_type())
 

Modified: trunk/src/ui/Makefile.am
==============================================================================
--- trunk/src/ui/Makefile.am	(original)
+++ trunk/src/ui/Makefile.am	Sat Jan 12 22:02:57 2008
@@ -35,6 +35,7 @@
 	ui-network-client.c ui-network-client.h \
 	ui-network-server.c ui-network-server.h \
 	ui-main.c ui-main.h \
+	state.c state.h global.h \
 	$(NULL)
 
 

Modified: trunk/src/ui/game-1-player-manager.c
==============================================================================
--- trunk/src/ui/game-1-player-manager.c	(original)
+++ trunk/src/ui/game-1-player-manager.c	Sat Jan 12 22:02:57 2008
@@ -17,13 +17,18 @@
  * Boston, MA 02111-1307, USA.
  */
 #include <gtk/gtk.h>
+#ifdef GNOME
 #include <libgnome/gnome-score.h>
+#endif
 #include "game-1-player-manager.h"
 #include "game-1-player.h"
 #include "game.h"
 #include "game-manager.h"
 #include "ui-main.h"
 
+#ifdef MAEMO
+#include "global.h"
+#endif
 #define PRIVATE(game_1_player_manager) (game_1_player_manager->private )
 
 static GObjectClass* parent_class = NULL;
@@ -132,6 +137,10 @@
 	PRIVATE(manager)->current_level = 0;
   }
 
+#ifdef MAEMO
+  state.level = PRIVATE(manager)->current_level;
+#endif
+
   game_1_player_manager_start_level(manager);
   return FALSE;
 }
@@ -185,6 +194,9 @@
 
   if( game_get_state( game ) == GAME_FINISHED ) {
     PRIVATE(manager)->current_score = game_1_player_get_score( GAME_1_PLAYER(game));
+#ifdef MAEMO
+    state.score = PRIVATE(manager)->current_score;
+#endif
     if( game_1_player_is_lost( GAME_1_PLAYER(game) )) {
       ui_main_set_game(ui_main,NULL);	 
       g_timeout_add(2000,
@@ -231,8 +243,22 @@
 	 
   manager = GAME_1_PLAYER_MANAGER(g);
 
+#ifdef GNOME
   PRIVATE(manager)->current_level = 0;
   PRIVATE(manager)->current_score = 0;
+#endif
+#ifdef MAEMO
+  if (state.game == 1 && state.level > 0 ) {
+    PRIVATE(manager)->current_level = state.level;
+    PRIVATE(manager)->current_score = state.score;
+  } else {
+    state.level = 0;
+    PRIVATE(manager)->current_level = 0;
+    PRIVATE(manager)->current_score = 0;
+  }
+  state.game = 1;
+#endif
+
   game_1_player_manager_start_level(manager);
 
 }
@@ -248,7 +274,9 @@
   g_signal_handlers_disconnect_matched(  G_OBJECT( PRIVATE(manager)->current_game ),
                                          G_SIGNAL_MATCH_DATA,0,0,NULL,NULL,manager);
 
+#ifdef GNOME
   gnome_score_log(0.0 + game_1_player_get_score(PRIVATE(manager)->current_game), NULL, TRUE);
+#endif
 
   g_object_unref( PRIVATE(manager)->current_game);
 

Modified: trunk/src/ui/game-1-player.c
==============================================================================
--- trunk/src/ui/game-1-player.c	(original)
+++ trunk/src/ui/game-1-player.c	Sat Jan 12 22:02:57 2008
@@ -17,6 +17,10 @@
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif /* HAVE_CONFIG_H */
+
 #include <stdlib.h>
 #include <gtk/gtk.h>
 #include <gconf/gconf-client.h>
@@ -29,6 +33,10 @@
 #include "game-sound.h"
 #define FRAME_DELAY 10
 
+#ifdef MAEMO
+#include "global.h"
+#endif
+
 #define PRIVATE(game_1_player) (game_1_player->private)
 
 
@@ -95,6 +103,13 @@
 static void time_init(Game1Player * game);
 
 
+#ifdef MAEMO
+void game_1_player_save(Game1Player *game)
+{
+        //monkey_save(PRIVATE(game)->monkey, MONKEY_TEMP); //TODO: enable saving
+}
+#endif
+
 static void game_1_player_instance_init(Game1Player * game) {
         game->private =g_new0 (Game1PlayerPrivate, 1);		
 }
@@ -213,9 +228,23 @@
 
 
         monkey_canvas_clear(canvas);
+#ifdef GNOME
         PRIVATE(game)->monkey = 
                 monkey_new_level_from_file(DATADIR"/monkey-bubble/levels",
                                            level);
+#endif
+
+#ifdef MAEMO
+	if (state.loadmap==1) {
+          PRIVATE(game)->monkey =
+                monkey_new_level_from_file(MONKEY_TEMP, 0);
+          state.loadmap = 0;
+        } else {
+          PRIVATE(game)->monkey =
+                monkey_new_level_from_file(DATADIR"/monkey-bubble/levels",
+                                           level);
+        }
+#endif
         PRIVATE(game)->display = 
                 monkey_view_new(canvas, 
                                 PRIVATE(game)->monkey,0,0,DATADIR"/monkey-bubble/gfx/layout_1_player.svg",TRUE,TRUE);

Modified: trunk/src/ui/game-1-player.h
==============================================================================
--- trunk/src/ui/game-1-player.h	(original)
+++ trunk/src/ui/game-1-player.h	Sat Jan 12 22:02:57 2008
@@ -55,6 +55,10 @@
 gint game_1_player_get_score(Game1Player * g);
 gboolean game_1_player_is_lost(Game1Player * g);
 
+#ifdef MAEMO
+void game_1_player_save(Game1Player *game);
+#endif
+
 G_END_DECLS
 
 

Added: trunk/src/ui/global.h
==============================================================================
--- (empty file)
+++ trunk/src/ui/global.h	Sat Jan 12 22:02:57 2008
@@ -0,0 +1,29 @@
+#ifdef MAEMO
+
+#ifndef GLOBAL_H
+#define GLOBAL_H
+
+#include <libosso.h>
+
+#include "game-1-player.h"
+
+#define MONKEY_TEMP "/tmp/monkey_level_state"
+
+struct GlobalData {
+    osso_context_t *osso;
+    Game1Player *game;
+};
+
+struct StateData {
+    int game;
+    int level;
+    int score;
+    int loadmap;
+};
+
+extern struct StateData state;
+extern struct GlobalData global;
+
+#endif
+
+#endif

Modified: trunk/src/ui/main.c
==============================================================================
--- trunk/src/ui/main.c	(original)
+++ trunk/src/ui/main.c	Sat Jan 12 22:02:57 2008
@@ -15,14 +15,58 @@
 #include <gtk/gtk.h>
 #include <gst/gst.h>
 #include <glib/gi18n.h>
-#include <glib/gthread.h>
+#ifdef GNOME
 #include <libgnome/gnome-score.h>
 #include <libgnomeui/gnome-ui-init.h>
+#endif
+#include <glib/gthread.h>
 
 #include <math.h>
 #include <stdio.h>
 #include <string.h>
 
+#ifdef MAEMO
+#include <libosso.h>
+
+#include "state.h"
+#include "global.h"
+
+#include "game-1-player.h"
+
+#define APPNAME "monkey_bubble"
+#define APPVERSION "0.0.1"
+
+
+struct GlobalData global;
+
+static void _top_cb(const char *args, gpointer data)
+{
+}
+
+static void _hw_cb(osso_hw_state_t * state, gpointer data)
+{
+       if(state->shutdown_ind)
+       {
+               state_save();
+               gtk_main_quit();
+       }
+}
+
+osso_context_t *osso_init(void)
+{
+    osso_context_t *osso =
+        osso_initialize(APPNAME, APPVERSION, TRUE, NULL);
+
+    if (OSSO_OK != osso_application_set_top_cb(osso, _top_cb, NULL))
+        return NULL;
+
+    if (OSSO_OK != osso_hw_set_event_cb(osso, NULL, _hw_cb, NULL))
+        return NULL;
+
+    return osso;
+}
+#endif
+
 int main(int  argc, char **argv)
 {
   UiMain * ui_main;
@@ -30,6 +74,12 @@
   SoundManager * manager;
   GError* error = NULL;
   GOptionContext * context;
+
+#ifdef MAEMO
+  setlocale(LC_ALL, "");
+  bind_textdomain_codeset(PACKAGE, "UTF-8");
+#endif
+
 #ifdef ENABLE_NLS
   bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
   textdomain (PACKAGE);
@@ -48,16 +98,29 @@
   }
   g_option_context_free (context);
 
+#ifdef GNOME
   if(gnome_score_init(PACKAGE)) {
 	g_message("You'll have to play without highscore support");
   }
+#endif
+  
+#ifdef MAEMO
+  global.osso = osso_init();
+  if (!global.osso) {
+       perror("osso_init");
+       exit(1);
+  }
+  global.game = NULL;
+#endif
 
+#ifdef GNOME
   /* to get help working */
   gnome_program_init (PACKAGE, VERSION,
 		      LIBGNOMEUI_MODULE,
 		      argc, argv,
 		      GNOME_PROGRAM_STANDARD_PROPERTIES,
 		      NULL);
+#endif
 
   gtk_window_set_default_icon_name ("monkey-bubble");
 
@@ -73,6 +136,12 @@
 
   gtk_widget_show_all (window);
 
+#ifdef MAEMO
+  if (state.game == 1) {
+       continue_game();
+  }
+#endif
+
   gtk_main ();
 
 

Added: trunk/src/ui/state.c
==============================================================================
--- (empty file)
+++ trunk/src/ui/state.c	Sat Jan 12 22:02:57 2008
@@ -0,0 +1,51 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif /* HAVE_CONFIG_H */
+
+#ifdef MAEMO
+#include <libosso.h>
+
+#include "state.h"
+#include "global.h"
+
+struct StateData state;
+
+gboolean state_load(void)
+{
+    osso_state_t osso_state;
+    osso_return_t ret;
+
+    osso_state.state_size = sizeof(struct StateData);
+    osso_state.state_data = &state;
+
+    ret = osso_state_read(global.osso, &osso_state);
+    if (ret != OSSO_OK)
+        return FALSE;
+    return TRUE;
+}
+
+gboolean state_save(void)
+{
+    osso_state_t osso_state;
+    osso_return_t ret;
+
+    osso_state.state_size = sizeof(struct StateData);
+    osso_state.state_data = &state;
+
+    ret = osso_state_write(global.osso, &osso_state);
+
+    if (ret != OSSO_OK)
+        return FALSE;
+    return TRUE;
+}
+
+void state_clear(void)
+{
+    state.game = 0;
+    state.level = 0;
+    state.score = 0;
+    state.loadmap = 0;
+
+    state_save();
+}
+#endif

Added: trunk/src/ui/state.h
==============================================================================
--- (empty file)
+++ trunk/src/ui/state.h	Sat Jan 12 22:02:57 2008
@@ -0,0 +1,17 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif /* HAVE_CONFIG_H */
+
+#ifdef MAEMO
+#ifndef STATE_H
+#define STATE_H
+
+#include <glib.h>
+
+gboolean state_load(void);
+gboolean state_save(void);
+void state_clear(void);
+
+#endif
+
+#endif

Modified: trunk/src/ui/ui-main.c
==============================================================================
--- trunk/src/ui/ui-main.c	(original)
+++ trunk/src/ui/ui-main.c	Sat Jan 12 22:02:57 2008
@@ -34,11 +34,13 @@
 #include "keyboard-properties.h"
 #include "sound-manager.h"
 
+#ifdef GNOME
 #include <libgnomeui/libgnomeui.h>
 #include <libgnomeui/gnome-about.h>
 #include <libgnome/gnome-score.h>
 #include <libgnome/gnome-sound.h>
 #include <libgnome/gnome-help.h>
+#endif
 #include <gdk/gdkkeysyms.h>
 #include <glade/glade.h>
 #include <glib/gi18n.h>
@@ -46,6 +48,13 @@
 #include <string.h>
 #include <stdlib.h>
 
+#ifdef MAEMO
+#include <hildon/hildon-program.h>
+#include "global.h"
+#include "state.h"
+#include <conic.h>
+#endif
+
 #include "ui-network-client.h"
 #include "ui-network-server.h"
 #include "simple-server.h"
@@ -59,34 +68,43 @@
 static void new_1_player_game(gpointer    callback_data,
                               guint       callback_action,
                               GtkWidget  *widget);
+#ifdef GNOME
 static void new_2_player_game(gpointer    callback_data,
                               guint       callback_action,
                               GtkWidget  *widget);
+#endif
 
 static void new_network_game(gpointer    callback_data,
                              guint       callback_action,
                              GtkWidget  *widget);
 
+#ifdef GNOME
 static void new_network_server(gpointer    callback_data,
                                guint       callback_action,
                                GtkWidget  *widget);
+#endif
 
+#ifdef GNOME
 static void show_high_scores(gpointer callback_data,
 			     guint    callback_action,
 			     GtkWidget* widget);
+#endif
 
 static void pause_game(gpointer    callback_data,
                        guint       callback_action,
                        GtkWidget  *widget);
+#ifdef GNOME
 static void stop_game(gpointer    callback_data,
                       guint       callback_action,
                       GtkWidget  *widget);
+#endif
 
 
 static void quit_program(gpointer    callback_data,
                          guint       callback_action,
                          GtkWidget  *widget);
 			      
+#ifdef GNOME
 static void about(gpointer    callback_data,
                   guint       callback_action,
                   GtkWidget  *widget);
@@ -101,7 +119,9 @@
 static void show_preferences_dialog(gpointer    callback_data,
                                     guint       callback_action,
                                     GtkWidget  *widget);
+#endif
 
+static void ui_main_new_1_player_game(UiMain * ui_main);
 
 struct UiMainPrivate {
         GtkAccelGroup * accel_group;
@@ -116,6 +136,9 @@
         gboolean fullscreen;
         SoundManager * sm;
         GladeXML * glade_xml;
+#ifdef MAEMO
+	ConIcConnection *ic;
+#endif
 };
 
 static void ui_main_class_init(UiMainClass* klass);
@@ -125,9 +148,36 @@
 
 static void ui_main_draw_main(UiMain * ui_main);
 
+static UiMain* ui_main_new(void);
 
 
-static UiMain* ui_main_new(void);
+#ifdef MAEMO
+static void ui_main_topmost_cb(GObject *self, GParamSpec *property_param, gpointer null)
+{
+       HildonProgram *program = HILDON_PROGRAM(self);
+
+       if (program == NULL) return;
+
+       if (hildon_program_get_is_topmost(program)) {
+               hildon_program_set_can_hibernate(program, FALSE);
+       } else {
+               if (state.game == 1 && global.game!=NULL) {
+                       //game_1_player_save(global.game); //TODO: enable saving
+                       state.loadmap=1;
+               }
+               state_save();
+               hildon_program_set_can_hibernate(program, TRUE);
+       }
+}
+
+void continue_game(void) {
+        UiMain * ui_main;
+        ui_main = ui_main_get_instance();
+
+        ui_main_new_1_player_game(ui_main);
+}
+
+#endif
 
 GType ui_main_get_type(void) {
         static GType ui_main_type = 0;
@@ -169,10 +219,17 @@
 
 
 static UiMain* ui_main_new(void) {
+#ifdef MAEMO
+	HildonProgram * program;
+	GtkWidget * container;
+	GtkWidget * main_menu; 
+#endif
         UiMain * ui_main;
         GtkWidget * vbox;
         GtkWidget * item;
+#ifdef GNOME
         KeyboardProperties * kp;
+#endif
 
         ui_main = UI_MAIN(g_object_new(UI_TYPE_MAIN, NULL));
     
@@ -215,7 +272,33 @@
                           GTK_WIDGET(PRIVATE(ui_main)->canvas), 
                           TRUE,
                           TRUE, 0);
+
+#ifdef MAEMO
+	/* Setting menu */
+	main_menu = gtk_menu_new();
+
+	item = gtk_menu_item_new_with_label(_("New game"));
+	g_signal_connect_swapped( item,"activate",GTK_SIGNAL_FUNC(new_1_player_game),ui_main);
+	gtk_menu_append(main_menu, item);
+
+	item = gtk_menu_item_new_with_label(_("Join network game"));
+	g_signal_connect_swapped( item,"activate",GTK_SIGNAL_FUNC(new_network_game),ui_main);
+	gtk_menu_append(main_menu, item);
+
+	item = gtk_menu_item_new_with_label(_("Pause"));
+	g_signal_connect_swapped( item,"activate",GTK_SIGNAL_FUNC(pause_game),ui_main);
+	gtk_menu_append(main_menu, item);
+
+	item = gtk_menu_item_new_with_label(_("Quit"));
+	g_signal_connect_swapped( item,"activate",GTK_SIGNAL_FUNC(quit_program),ui_main);
+	gtk_menu_append(main_menu, item);
+
+	hildon_window_set_menu(HILDON_WINDOW(PRIVATE(ui_main)->window), GTK_MENU(main_menu));
+
+	gtk_widget_show_all(GTK_WIDGET(main_menu));
+#endif
      
+#ifdef GNOME
         PRIVATE(ui_main)->menu = glade_xml_get_widget(PRIVATE(ui_main)->glade_xml,"main_menubar");
         g_object_ref(PRIVATE(ui_main)->menu);
         kp = keyboard_properties_get_instance();
@@ -272,6 +355,7 @@
         g_signal_connect_swapped( G_OBJECT( PRIVATE(ui_main)->window),"delete-event",GTK_SIGNAL_FUNC(quit_program),NULL);
 
         item = glade_xml_get_widget(PRIVATE(ui_main)->glade_xml,"help_contents");
+
         g_signal_connect_swapped(item, "activate", 
                                  GTK_SIGNAL_FUNC(show_help_content), ui_main);
 
@@ -280,6 +364,7 @@
                                   "activate",
                                   G_CALLBACK (about),
                                   ui_main);
+#endif
 
         PRIVATE(ui_main)->game = NULL;
 
@@ -366,6 +451,7 @@
         ui_main_set_game_manager(ui_main,manager);
 }
 
+#ifdef GNOME
 static void ui_main_new_2_player_game(UiMain * ui_main) {
 
         GameManager * manager;
@@ -379,6 +465,7 @@
 
         ui_main_set_game_manager(ui_main,manager);
 }
+#endif
 
 
 void ui_main_set_game_manager(UiMain * ui_main,GameManager * manager) {
@@ -429,11 +516,16 @@
         UiMain * ui_main;
         ui_main = ui_main_get_instance();
 
+#ifdef MAEMO
+	state_clear();
+#endif
+
         ui_main_new_1_player_game(ui_main);
 
 }
 
 
+#ifdef GNOME
 static void new_2_player_game(gpointer    callback_data,
                               guint       callback_action,
                               GtkWidget  *widget){
@@ -447,6 +539,7 @@
 
 
 }
+#endif
 
 static void quit_program(gpointer    callback_data,
                          guint       callback_action,
@@ -487,6 +580,7 @@
         ui_main_draw_main(ui_main);
 }
 
+#ifdef GNOME
 static void stop_game(gpointer    callback_data,
                       guint       callback_action,
                       GtkWidget  *widget) {
@@ -498,6 +592,7 @@
 Block * ui_main_get_main_image(UiMain *ui_main) {
         return(PRIVATE(ui_main)->main_image);
 }
+#endif
 
 void ui_main_set_game(UiMain *ui_main, Game *game) {
 
@@ -554,16 +649,40 @@
   
 }
 
+#ifdef MAEMO
+static void network_connected(ConIcConnection *cnx, ConIcConnectionEvent *event, gpointer user_data)
+{
+        UiNetworkClient  * ngl;
+
+	switch (con_ic_connection_event_get_status(event)) {
+		case CON_IC_STATUS_CONNECTED:
+		  ngl = ui_network_client_new();
+		  break;
+		default:
+		  break;
+	}
+}
+#endif
 
 static void new_network_game(gpointer    callback_data,
                              guint       callback_action,
                              GtkWidget  *widget) {
-        UiNetworkClient  * ngl;
+#ifdef MAEMO
+	UiMain * uimain = UI_MAIN(callback_data);
+	PRIVATE(uimain)->ic = con_ic_connection_new();
+	g_signal_connect(PRIVATE(uimain)->ic, "connection-event", (GCallback)network_connected, NULL);
+	con_ic_connection_connect(PRIVATE(uimain)->ic, CON_IC_CONNECT_FLAG_NONE);
+#endif
 
+
+#ifdef GNOME
+        UiNetworkClient  * ngl;
         ngl = ui_network_client_new();
+#endif
 }
 
 
+#ifdef GNOME
 static void new_network_server(gpointer    callback_data,
                                guint       callback_action,
                                GtkWidget  *widget) {
@@ -605,7 +724,9 @@
 	gnome_scores_set_logo_pixmap(GNOME_SCORES(dialog), DATADIR "/monkey-bubble/gfx/monkey.png");
 	gtk_widget_show(dialog);
 }
+#endif
 
+#ifdef GNOME
 static void show_preferences_dialog(gpointer    callback_data,
                                     guint       callback_action,
                                     GtkWidget  *widget) {
@@ -620,7 +741,9 @@
   
         keyboard_properties_show( keyboard_properties_get_instance(),GTK_WINDOW(PRIVATE(ui_main)->window));
 }
+#endif
 
+#ifdef GNOME
 static void about (gpointer    callback_data,
                    guint       callback_action,
                    GtkWidget  *widget) {
@@ -652,7 +775,9 @@
 
         g_object_unref( logo);
 }
+#endif
 
+#ifdef GNOME
 static void show_help_content(gpointer    callback_data,
                               guint       callback_action,
                               GtkWidget  *widget) {
@@ -669,7 +794,9 @@
                 g_error_free (err);
         }
 }
+#endif
 
+#ifdef GNOME
 static void show_error_dialog (GtkWindow *transient_parent,
                                const char *message_format, ...) {
         char *message;
@@ -696,3 +823,4 @@
     
         gtk_widget_show_all (dialog);
 }
+#endif

Modified: trunk/src/ui/ui-main.h
==============================================================================
--- trunk/src/ui/ui-main.h	(original)
+++ trunk/src/ui/ui-main.h	Sat Jan 12 22:02:57 2008
@@ -57,4 +57,8 @@
 void ui_main_set_game_manager(UiMain * ui_main,GameManager * manager);
 
 void ui_main_enabled_games_item(UiMain * ui_main ,gboolean enabled);
+
+#ifdef MAEMO
+void continue_game(void);
+#endif
 #endif /* __UI_MAIN_H__ */

Modified: trunk/src/ui/ui-network-client.c
==============================================================================
--- trunk/src/ui/ui-network-client.c	(original)
+++ trunk/src/ui/ui-network-client.c	Sat Jan 12 22:02:57 2008
@@ -102,7 +102,33 @@
                               xmlDoc * message,
                               gpointer * p);
 
+#ifdef MAEMO
+static gboolean close_signal(gpointer    callback_data,
+                             guint       callback_action,
+                             GtkWidget  *widget) {
+
+    UiNetworkClient * self;
+    self = UI_NETWORK_CLIENT(callback_data);
+
+    quit_signal(callback_data, callback_action, widget);
+    gtk_widget_hide_all(PRIVATE(self)->window);
+    return FALSE;
+}
+
+void connected_set_sensitive(UiNetworkClient * ngl, gboolean sensitive) {
+    set_sensitive( glade_xml_get_widget( PRIVATE(ngl)->glade_xml
+        ,"scrolledwindow2"), sensitive);
+    set_sensitive( glade_xml_get_widget( PRIVATE(ngl)->glade_xml
+        ,"quit_button"), sensitive);
+    set_sensitive( glade_xml_get_widget( PRIVATE(ngl)->glade_xml
+        ,"ready_button"), sensitive);
+}
+#endif
+
 UiNetworkClient *ui_network_client_new() {
+#ifdef MAEMO
+	GtkWidget * container;
+#endif
         UiNetworkClient * ngl;
         GtkWidget * item;
 
@@ -152,9 +178,14 @@
         
         PRIVATE(ngl)->connection_label = GTK_LABEL(glade_xml_get_widget( PRIVATE(ngl)->glade_xml, "connection_state_label"));
         
+#ifdef GNOME
        gtk_widget_set_sensitive( glade_xml_get_widget( PRIVATE(ngl)->glade_xml
                                                        , "connected_game_hbox"),
                                  FALSE);
+#endif
+#ifdef MAEMO
+	connected_set_sensitive(ngl, FALSE);
+#endif
 
 
        item = glade_xml_get_widget( PRIVATE(ngl)->glade_xml,"players_treeview");
@@ -184,6 +215,10 @@
 
         
         PRIVATE(ngl)->players_list = list;
+
+#ifdef MAEMO
+	gtk_widget_show_all(GTK_WIDGET(PRIVATE(ngl)->window));
+#endif
         
         return ngl;
         
@@ -244,7 +279,6 @@
         set_status_message(self,  g_strdup_printf("Connecting %s ...",
                                                  PRIVATE(self)->server_name));
 
-
         set_sensitive( glade_xml_get_widget( PRIVATE(self)->glade_xml
                                              , "connect_hbox"),FALSE);        
         if( connect_server(self) ) {
@@ -256,7 +290,6 @@
 
                 set_sensitive( glade_xml_get_widget( PRIVATE(self)->glade_xml
                                                      , "connect_hbox"),TRUE);        
-
         }
 
 }
@@ -287,8 +320,13 @@
         PRIVATE(self)->manager_proxy = NULL;
                 
         update_players_list(self);
+#ifdef GNOME
         set_sensitive( glade_xml_get_widget( PRIVATE(self)->glade_xml
                                              , "connected_game_hbox"),FALSE);
+#endif
+#ifdef MAEMO
+	connected_set_sensitive(self, FALSE);
+#endif
         
         set_sensitive( glade_xml_get_widget( PRIVATE(self)->glade_xml
                                              , "connect_hbox"),TRUE);
@@ -363,8 +401,13 @@
         set_sensitive( glade_xml_get_widget( PRIVATE(self)->glade_xml
                                              , "connect_hbox"),TRUE); 
 
+#ifdef GNOME
         set_sensitive( glade_xml_get_widget( PRIVATE(self)->glade_xml
                                              , "connected_game_hbox"),FALSE); 
+#endif
+#ifdef MAEMO
+	connected_set_sensitive(self, FALSE);
+#endif
 
         
         return FALSE;
@@ -654,8 +697,13 @@
                 
                 sscanf((gchar*)root->children->content,"%d",&game_id);
                 g_print("game id : %d\n",game_id);                
+#ifdef GNOME
                 set_sensitive( glade_xml_get_widget( PRIVATE(self)->glade_xml
                                                      ,"connected_game_hbox"),TRUE); 
+#endif
+#ifdef MAEMO
+	connected_set_sensitive(self, TRUE);
+#endif
 
                 sscanf((gchar*)root->children->content,"%d",&game_id);
              



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