refractoring to use osso-game-startup
authorReto Zingg <g.d0b3rm4n@gmail.com>
Sun, 27 Dec 2009 14:11:40 +0000 (16:11 +0200)
committerReto Zingg <g.d0b3rm4n@gmail.com>
Sun, 27 Dec 2009 14:11:40 +0000 (16:11 +0200)
21 files changed:
.gitignore
Makefile
data/com.nokia.mancala.service
data/com.nokia.mancala_startup.service [new file with mode: 0644]
data/mancala.conf [new file with mode: 0644]
data/mancala.desktop
data/mancala.game [new file with mode: 0644]
data/mancala.html [new file with mode: 0644]
data/mancala.sh [new file with mode: 0755]
debian/changelog
debian/control
debian/copyright
src/Makefile
src/callbacks.c [new file with mode: 0644]
src/callbacks.h [new file with mode: 0644]
src/launcher/Makefile [new file with mode: 0644]
src/launcher/mancala-launcher.c [new file with mode: 0644]
src/main.c
src/play.c
src/plugin/Makefile [new file with mode: 0644]
src/plugin/mancala-ui-plugin.c [new file with mode: 0644]

index 341e353..3a1f3cf 100644 (file)
@@ -34,6 +34,9 @@ src/.libs
 *.dsc
 src/build-stamp
 src/mancala
+src/launcher/mancala-launcher
+src/plugin/mancala-ui-plugin.o
+src/plugin/mancala-ui-plugin.so
 build-stamp
 debian/docs
 debian/maemo-mancala/
index e825012..61290a4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -8,9 +8,16 @@ install:
        mkdir -p $(DESTDIR)/usr/share/applications/hildon
        mkdir -p $(DESTDIR)/usr/share/icons/hicolor/40x40/apps
        mkdir -p $(DESTDIR)/usr/share/dbus-1/services
+       mkdir -p $(DESTDIR)/home/opt/mancala/data/
+       mkdir -p $(DESTDIR)/home/opt/mancala/bin/
        cp data/mancala.desktop $(DESTDIR)/usr/share/applications/hildon
        cp data/mancala.png $(DESTDIR)/usr/share/icons/hicolor/40x40/apps/mancala.png
        cp data/com.nokia.mancala.service $(DESTDIR)/usr/share/dbus-1/services/
+       cp data/com.nokia.mancala_startup.service $(DESTDIR)/usr/share/dbus-1/services/
+       cp data/mancala.conf $(DESTDIR)/home/opt/mancala/data/
+       cp data/mancala.game $(DESTDIR)/home/opt/mancala/data/
+       cp data/mancala.html $(DESTDIR)/home/opt/mancala/data/
+       cp data/mancala.sh $(DESTDIR)/home/opt/mancala/bin/
 
 clean:
        rm -f build-stamp config.guess config.sub
@@ -27,4 +34,3 @@ maemo-bin: clean
        dpkg-buildpackage -rfakeroot -b -us -uc
 
 .PHONY: clobber clean install subsystem maemo-source maemo-bin
-
index de77262..01bfde4 100644 (file)
@@ -1,3 +1,3 @@
 [D-BUS Service]
 Name=com.nokia.mancala
-Exec=/home/opt/mancala/bin/mancala
+Exec=/home/opt/mancala/bin/mancala-launcher
diff --git a/data/com.nokia.mancala_startup.service b/data/com.nokia.mancala_startup.service
new file mode 100644 (file)
index 0000000..4b2298b
--- /dev/null
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=com.nokia.mancala_startup
+Exec=/home/opt/mancala/bin/mancala.sh
diff --git a/data/mancala.conf b/data/mancala.conf
new file mode 100644 (file)
index 0000000..a9b89ff
--- /dev/null
@@ -0,0 +1,20 @@
+[Startup Entry]
+# the name of the application
+Name=mancala
+# the current version of the application
+Version=0.2
+# the title that is used, if not specified by the GettextPackage
+Title=Mancala
+# the GettextPackage to be used to locate the title string
+GettextPackage=mancala
+# if the TitleId is defined, it searches for it inside the gettext package
+# TitleId=example_title
+# if the game has a plug-in
+PluginPath=/home/opt/mancala/plugin/mancala-ui-plugin.so
+# the games-startup screen image
+Image=/home/opt/mancala/data/mancala.png
+# the D-BUS service, path and interface names
+ServiceName=com.nokia.mancala
+PathName=/com/nokia/mancala
+InterfaceName=com.nokia.mancala
+
index 4697e22..8ce24f8 100644 (file)
@@ -1,16 +1,12 @@
 [Desktop Entry]
 Encoding=UTF-8
-Version=0.1
+Version=0.2
 Name=Mancala
 Comment=Mancala game for Maemo devices
-Exec=/home/opt/mancala/bin/mancala
+Exec=/home/opt/mancala/bin/mancala.sh
 Icon=mancala
-Terminal=false
 Type=Application
 Categories=Games
 X-HildonDesk-ShowInToolbar=true
-X-Osso-Type=application/x-executable
 X-Window-Icon=mancala
-X-Osso-Service=com.nokia.mancala
-
-
+X-Osso-Service=com.nokia.mancala_startup
\ No newline at end of file
diff --git a/data/mancala.game b/data/mancala.game
new file mode 100644 (file)
index 0000000..88bc54e
--- /dev/null
@@ -0,0 +1,7 @@
+mancala
+/home/opt/mancala/bin/mancala
+com.nokia.mancala
+/com/nokia/mancala
+com.nokia.mancala
+0.2
+
diff --git a/data/mancala.html b/data/mancala.html
new file mode 100644 (file)
index 0000000..f9cb653
--- /dev/null
@@ -0,0 +1,32 @@
+<!--
+*
+* This file is part of Mancala
+*
+* Copyright (c) 2009 Reto Zingg
+* Text from cmancala game:
+* http://sourceforge.net/projects/cmancala/files/mancala-text/mancala-0.2.1/mancala-0.2.1.tar.gz/download
+*
+* This software is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public License
+* as published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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 General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA
+-->
+<html>
+<head></head>
+<body>
+<h1>Welcome to Mancala, the ancient African game of skill!</h1>
+<p><big>Mancala is a very simple, easy-to-learn game. Each player begins with a horizontal row of holes or pits filled with a certain number of stones. At either end of the board are the players' home pits, which are used to keep score. In this case, the human player has the left home pit and the upper row holes. A move is made by clicking into the hole you wish to move from. The stones are then picked up and distributed, one to each hole, moving toward your home pit is reached, and then moving through your opponent's row, bypassing his/her home, and moving back towards in a circle (counterclockwise), until all the stones have been distributed.</big></p>
+<p><big>If the last stone is placed in your home, you receive an extra turn. If the last stone lands in an empty hole on your side, you 'capture' the stones in the opposite hole on your opponent's side, moving them to your home.</big></p>
+<p><big>The game ends when one player cannot play (ie. there are no stones on his/her side of the board.  The player who has the most stones on his/her *side* wins.</big></p>
+</body>
+</html>
diff --git a/data/mancala.sh b/data/mancala.sh
new file mode 100755 (executable)
index 0000000..f9819f8
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/sh
+#
+#
+#  This file is part of Mancala
+#
+#  Copyright (C) 2009 Reto Zingg
+#
+#  Some of the code is based on the examples on:
+#  http://wiki.maemo.org/Documentation/Maemo_5_Developer_Guide
+#
+#  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, 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, a copy of which may be found in
+#  the file COPYING provided in the main directory of this release.
+#
+
+/usr/bin/osso_games_startup /home/opt/mancala/data/mancala.conf
+
index 8d326ff..528f5b3 100644 (file)
@@ -1,3 +1,15 @@
+mancala (0.2.0-2) unstable; urgency=low
+
+  * with plugin
+
+ -- Reto Zingg <g.d0b3rm4n@gmail.com>  Fri, 25 Dec 2009 18:01:34 +0200
+
+mancala (0.2.0-1) unstable; urgency=low
+
+  * refractoring
+
+ -- Reto Zingg <g.d0b3rm4n@gmail.com>  Fri, 25 Dec 2009 13:40:07 +0200
+
 mancala (0.1.10-2) unstable; urgency=low
 
   * updated control file 
index 7eb681a..b1b10f9 100644 (file)
@@ -9,7 +9,7 @@ Homepage: http://mancala.garage.maemo.org/
 Package: mancala
 Architecture: any
 Section: user/games
-Depends: ${shlibs:Depends}, ${misc:Depends}
+Depends: ${shlibs:Depends}, ${misc:Depends}, osso-games-startup, hildon-games-wrapper0
 Description: Mancala, the ancient African game of skill!
  Maemo version of mancala from http://cmancala.sourceforge.net/
  Please file bugs here for this maemo version:
index 3fc31f6..891b4b1 100644 (file)
@@ -36,3 +36,7 @@ instruction code copyright (c) 2001 by URW++ GmbH. All Rights
 Reserved. Luxi is a registered trademark of Bigelow & Holmes Inc.
 
 see COPYRIGHT.BH file.
+
+parts from Crazyparking:
+http://repository.maemo.org/extras-testing/pool/fremantle/free/source/c/crazyparking/crazyparking_0.2.7-2.tar.gz
+License: GNU General Public License Version 2
index 5e40a78..ea07efa 100644 (file)
@@ -17,15 +17,20 @@ CC = gcc
 DBG = gdb
 STD = _GNU_SOURCE
 CFLAGS = `sdl-config --cflags` -I/usr/local/include/SDL `pkg-config hildon-1 --cflags` -I/usr/include/dbus-1.0/ -I/usr/lib/dbus-1.0/include/
-LFLAGS = `sdl-config --static-libs ` -lSDL_image -lSDL_ttf -lSDL_mixer `pkg-config hildon-1 --libs` `pkg-config --libs  libosso`
+LFLAGS = `sdl-config --static-libs ` -lSDL_image -lSDL_ttf -lSDL_mixer `pkg-config hildon-1 --libs` `pkg-config --libs  libosso` -lhgw
 
-MAIN_OBJ = main.o graphics.o mancala.o sounds.o play.o
+# MAIN_OBJ = main.o graphics.o mancala.o sounds.o play.o
+MAIN_OBJ = graphics.o mancala.o sounds.o play.o callbacks.o
 TEST_OBJ = ai-test.o mancala.o
 
 NORMAL = ai.o
 RECURSE = ai-init.o ai-recurse.o
 ULTIMATE = ai-init.o ai-ultimate.o
 
+subsystem:
+       $(MAKE) -C launcher
+       $(MAKE) -C plugin 
+
 #'$<' is filename of input, '$@' is filename of output
 .c.o:
        $(CC) -c -g$(DBG) -Wall $(CFLAGS) -D$(STD) $<
@@ -33,6 +38,8 @@ ULTIMATE = ai-init.o ai-ultimate.o
        $(CC) -c -g$(DBG) -Wall $(CFLAGS) -D$(STD) $<
 
 all:           $(MAIN_OBJ) $(NORMAL)
+       $(MAKE) -C launcher all
+       $(MAKE) -C plugin all
        $(CC) $(MAIN_OBJ) $(NORMAL) $(LFLAGS) -o mancala
 
 recurse:       $(MAIN_OBJ) $(RECURSE)
@@ -57,6 +64,8 @@ install:      all
        cp ../data/*.png $(DESTDIR)/home/opt/mancala/data/
        cp ../data/*.wav $(DESTDIR)/home/opt/mancala/data/
        cp ../data/*.ttf $(DESTDIR)/home/opt/mancala/data/
+       $(MAKE) -C launcher install
+       $(MAKE) -C plugin install
 
 
 uninstall:
@@ -65,9 +74,13 @@ uninstall:
 
 clean:
        rm -f *.o *.core *.swp *~ *.log
+       $(MAKE) -C launcher clean
+       $(MAKE) -C plugin clean
 
 clobber:       clean
        rm -f mancala ai-test
+       $(MAKE) -C launcher clobber
+       $(MAKE) -C plugin clobber
 
 distclean:     clobber
        @echo "No configuration files to distclean yet."
diff --git a/src/callbacks.c b/src/callbacks.c
new file mode 100644 (file)
index 0000000..0b0e6cf
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+* This file is part of Mancala
+*
+* Originally from Crazyparking:
+*
+* Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia
+* http://www.indt.org/maemo
+*
+* adapted:
+* Copyright (c) 2009 Reto Zingg
+*
+* This software is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public License
+* as published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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 General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA
+*
+*/
+#include <stdio.h>
+#include <hgw/hgw.h>
+#include "callbacks.h"
+
+
+// Pause the game
+int exit_callback(int errcode) {
+    printf("exit_callback called...\n");
+       return 0;
+}
+
+// Quit game
+int quit_callback(int errcode) {
+    printf("quit_callback called...\n");
+       hgw_context_compat_destroy_quit(hgw_context);
+       return 0;
+}
+
+int flush_callback(int errcode) {
+    printf("quit_callback called...\n");
+       return 0;
+}
diff --git a/src/callbacks.h b/src/callbacks.h
new file mode 100644 (file)
index 0000000..baa1383
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+* This file is part of Mancala
+*
+* Originally from Crazyparking:
+* Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia
+* http://www.indt.org/maemo
+*
+* This software is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public License
+* as published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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 General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA
+*
+*/ 
+extern HgwContext *hgw_context;
+
+int exit_callback(int errcode/*, AppData *app_data*/);
+int quit_callback(int errcode/*, AppData *app_data*/);
+int flush_callback(int errcode);
diff --git a/src/launcher/Makefile b/src/launcher/Makefile
new file mode 100644 (file)
index 0000000..16cc005
--- /dev/null
@@ -0,0 +1,23 @@
+# GNU Makefile -- Makefile
+# 2009 Reto Zingg
+
+
+CC = gcc
+
+
+all:
+       $(CC) mancala-launcher.c -o mancala-launcher
+
+install:       all
+       mkdir -p $(DESTDIR)/home/opt/mancala/bin/
+       cp ./mancala-launcher $(DESTDIR)/home/opt/mancala/bin/mancala-launcher
+
+uninstall:
+       rm -rf $(DESTDIR)/home/opt/mancala/mancala-launcher
+
+clean:
+       rm -f *.o *.core *.swp *~ *.log
+
+clobber:       clean
+       rm -f mancala-launcher
+
diff --git a/src/launcher/mancala-launcher.c b/src/launcher/mancala-launcher.c
new file mode 100644 (file)
index 0000000..20462e2
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+* This file is part of Mancala
+*
+* Idea from Crazyparking
+*
+* Copyright (c) 2009 Reto Zingg
+*
+* This software is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public License
+* as published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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 General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA
+*/
+
+#include <stdio.h>
+#include <unistd.h>
+
+char *wrapper_args[] = {"/usr/games/wrapper/wrapper",
+                        "/home/opt/mancala/data/mancala.game",
+                        NULL};
+
+int main(int argc, char *argv[])
+{
+    
+    if (execv ("/usr/games/wrapper/wrapper", wrapper_args) == -1) {
+        printf("Launching mancala wrapper failed\n");
+    }
+
+    return 0;
+}
index 2214dcd..d587d33 100644 (file)
@@ -1,4 +1,7 @@
 /*
+*
+*  This file is part of Mancala
+*
 *  Copyright (C) 2009 Reto Zingg
 *
 *  Some of the code is based on the examples on:
 *
 */
 
+/*********************************************************************
+**
+** NOT used at the moment...
+**
+*********************************************************************/
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -190,3 +199,4 @@ int main (int argc, char **argv) {
         return 0;
 }
 
+
index c833d56..79948ee 100644 (file)
 */
 
 #include <hildon/hildon.h>
+#include <hgw/hgw.h>
+#include <unistd.h>
 
 #include "SDL_mixer.h"
 #include "SDL.h"
 #include "SDL_image.h"
 #include "SDL_ttf.h"
+#include "SDL_getenv.h"
 
 #include "graphics.h"
 #include "mancala.h"
 #include "sounds.h"
 #include "play.h"
 
+#include "callbacks.h"
+
 // the surfaces
 SDL_Surface *screen, *board, *title_text, *tile, *stone[STONE_MAX+1], *exit_text;
 // the fonts
 TTF_Font *title_font, *home_font, *board_font;
 // The sound effects that will be used
 Mix_Chunk *pick = NULL;
+// the hildon-game-wrapper context
+HgwContext *hgw_context = NULL;
+
+// for debugging, example:
+
+// rmz_debug(g_strdup_printf("play step 2: SDL_AUDIODRIVER: %s",
+//                            my_sdl_audiodrv)
+//                          );
 
+// void rmz_debug (char *msg){
+//     FILE *pFile;
+//     
+//     pFile = fopen ("/home/rzingg/mancala.debug", "a");
+//     if (pFile) {
+//         fprintf (pFile, "rmz_debug: %s \n", msg);
+//         fclose (pFile);
+//     }
+// }
 
 void sdl_clean_up(){
         
@@ -65,6 +87,11 @@ void sdl_clean_up(){
 }
 
 int play() {
+
+        // Scratchbox needs different SDL_AudiDriver env
+        #if __i386__
+        putenv("SDL_AUDIODRIVER=alsa") ;
+        #endif /* __i386__ */
         
         SDL_Rect board_rect, title_rect, exit_rect;
         SDL_Color font_color;
@@ -87,34 +114,33 @@ int play() {
         /* initialize our libraries */
         //if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO) < 0) {
        if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
-               fprintf(stderr, "Unable to initialize SDL: %s\n", 
+               printf("Unable to initialize SDL: %s\n", 
                         SDL_GetError());
                         sdl_clean_up();
                         return 1;
        }
        
        if (TTF_Init() < 0) {
-               fprintf(stderr, "Unable to initialize SDL_ttf: %s\n", 
+               printf("Unable to initialize SDL_ttf: %s\n", 
                         SDL_GetError());
                         sdl_clean_up();
                         return 1;
        }
        
        //Initialize SDL_mixer 
-       
        if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 ) 
+       // if( Mix_OpenAudio(22050, (Uint16)AUDIO_U8, 2, 256 ) == -1 )
        {
-               fprintf(stderr, "Unable to initialize Mix_OpenAudio: %s\n",
+               printf("Unable to initialize Mix_OpenAudio: %s\n",
                         SDL_GetError());
                         sdl_clean_up();
                         return 1;
        }
        
-       
        /* Load our images... PNGs now, maybe XPMs later */
        sprintf(tile_path, "%s/tile.png", RES_PATH);
        if ((tile = LoadRes(tile_path)) == NULL) {
-               fprintf(stderr, "Unable to load resource: %s\n", 
+               printf("Unable to load resource: %s\n", 
                         SDL_GetError());
                         sdl_clean_up();
                         return 1;
@@ -122,9 +148,9 @@ int play() {
        
        for (i=0; i<=STONE_MAX; i++) {
                if (sprintf(stone_path, "%s/stone%02d.png", RES_PATH, i) == 0)
-                       fprintf(stderr, "Problems assembling path.\n");
+                       printf("Problems assembling path.\n");
                if (!(stone[i] = LoadRes(stone_path))) {
-                       fprintf(stderr, "Unable to load resource: %s\n",
+                       printf("Unable to load resource: %s\n",
                                 SDL_GetError());
                                 sdl_clean_up();
                                 return 1;
@@ -133,25 +159,25 @@ int play() {
        
        /* Load our font(s) */
        if (sprintf(title_path, "%s/luxisr.ttf", FONT_PATH) == 0)
-               fprintf(stderr, "Problems assembling path.\n");
+               printf("Problems assembling path.\n");
        if (!(title_font = TTF_OpenFont(title_path, TITLE_SIZE))) {
-               fprintf(stderr, "Could not load font: %s\n", TTF_GetError());
+               printf("Could not load font: %s\n", TTF_GetError());
                sdl_clean_up();
                return 1;
        }
        
        if (sprintf(board_path, "%s/luxisr.ttf", FONT_PATH) == 0)
-               fprintf(stderr, "Problems assembling path.\n");
+               printf("Problems assembling path.\n");
        if (!(board_font = TTF_OpenFont(board_path, BOARD_SIZE))) {
-               fprintf(stderr, "Could not load font: %s\n", TTF_GetError());
+               printf("Could not load font: %s\n", TTF_GetError());
                sdl_clean_up();
                return 1;
        }
        
        if (sprintf(home_path, "%s/luxisr.ttf", FONT_PATH) == 0)
-               fprintf(stderr, "Problems assembling path.\n");
+               printf("Problems assembling path.\n");
        if (!(home_font = TTF_OpenFont(home_path, HOME_SIZE))) {
-               fprintf(stderr, "Could not load font: %s\n", TTF_GetError());
+               printf("Could not load font: %s\n", TTF_GetError());
                sdl_clean_up();
                return 1;
        }
@@ -159,7 +185,7 @@ int play() {
        /* Load sound effects */ 
        sprintf(pick_path, "%s/pick.wav", RES_PATH); 
        if ((pick = Mix_LoadWAV(pick_path)) == NULL) { 
-               fprintf(stderr, "Unable to load sound: %s\n", 
+               printf("Unable to load sound: %s\n", 
                         SDL_GetError());
                         sdl_clean_up();
                         return 1; 
@@ -187,27 +213,25 @@ int play() {
        /* set window properties and create it */
        SDL_WM_SetCaption("Mancala", "Mancala");
        if (sprintf(icon_path, "%s/icon.png", RES_PATH) == 0)
-               fprintf(stderr, "Problems assembling icon path.\n");
+               printf("Problems assembling icon path.\n");
        SDL_WM_SetIcon(LoadRes(icon_path), NULL);
        if ((screen = SDL_SetVideoMode(tile->w*8, (tile->h*2) + Y_OFFSET, 16, SDL_FULLSCREEN))
                == NULL) {
-               fprintf(stderr, "Unable to set %dx%d video: %s", tile->w*8,
+               printf("Unable to set %dx%d video: %s", tile->w*8,
                         tile->h*2, SDL_GetError());
                         sdl_clean_up();
                         return 1;
        }
-       
+       SDL_ShowCursor(SDL_DISABLE);
        
        /* define the font color fot the exit text */
        font_color_exit.r = 255;
        font_color_exit.r = 255;
        font_color_exit.r = 255;
        
-       
-       
        if (!(exit_text = TTF_RenderText_Blended(home_font, "EXIT", 
              font_color_exit))) {
-                     fprintf(stderr, "SDL_ttf: %s\n", TTF_GetError());
+                     printf("SDL_ttf: %s\n", TTF_GetError());
                      return 1;
         }
        
@@ -237,10 +261,10 @@ int play() {
                while (SDL_PollEvent(&event)) {
                        /* BAIL OUT! BAIL OUT! */
                        if (event.type == SDL_KEYDOWN){
-                               fprintf(stderr, "event SDL_KEYDOWN found....\n");
+                               printf("event SDL_KEYDOWN found....\n");
                                if ( event.key.keysym.sym == SDLK_q )
                                {
-                                       fprintf(stderr, "event SDLK_q found....\n");
+                                       printf("event SDLK_q found....\n");
                                        SDL_Event quit_event;
                                        quit_event.type = SDL_QUIT;
                                        SDL_PushEvent(&quit_event);
@@ -250,7 +274,7 @@ int play() {
                        if (event.type == SDL_MOUSEBUTTONDOWN) {
                                if ((event.button.button = 1) &&
                                    (event.button.y < Y_OFFSET)) {
-                                       fprintf(stderr, "clicked out side the board in exit area...\n");
+                                       printf("clicked out side the board in exit area...\n");
                                        SDL_Event quit_event;
                                        quit_event.type = SDL_QUIT;
                                        SDL_PushEvent(&quit_event);
@@ -258,7 +282,7 @@ int play() {
                        }
                        
                        if (event.type == SDL_QUIT) {
-                               fprintf(stderr, "event SDL_QUIT found....\n");
+                               printf("event SDL_QUIT found....\n");
                                sdl_clean_up();
                                return 0;
                        }
@@ -276,7 +300,7 @@ int play() {
 
                                                         // pitch 0 and 7 are the homebases which you can't play
                                                         if ( pitch == 0 || pitch == 7 ){
-                                                                 fprintf(stderr, "clicked out side the board...\n");
+                                                                 printf("clicked out side the board...\n");
                                                         }
                                                         else{
                                                                 current_move = pitch;
@@ -341,12 +365,12 @@ int play() {
                                if (aiBoard[0] > humanBoard[0]) {
                                        if (!(title_text = TTF_RenderText_Blended(title_font, 
                                                "Computer Wins!", font_color)))
-                                               fprintf(stderr, "TTF: %s\n", TTF_GetError());
+                                               printf("TTF: %s\n", TTF_GetError());
                                }
                                else {
                                        if (!(title_text = TTF_RenderText_Blended(title_font, 
                                                "Human Wins!", font_color))) 
-                                               fprintf(stderr, "TTF: %s\n", TTF_GetError());
+                                               printf("TTF: %s\n", TTF_GetError());
                                }
                                redraw_board = 1;
                                break;
@@ -361,7 +385,7 @@ int play() {
                                           home_font, tile, stone, active, 
                                           highlight);
                                           if (!board) {
-                                                  fprintf(stderr, "Could not draw the board.\n");
+                                                  printf("Could not draw the board.\n");
                                           }
                                           else {
                                                   // board_rect = SurfaceToRect(board);
@@ -383,12 +407,43 @@ int play() {
                                           redraw_board = 0;
                }
                
+               hgw_msg_compat_receive(hgw_context, 0);
+               
        }
        
        SDL_Delay(DELAY_AI);
        
+       
        sdl_clean_up();
        return 0;
        
 }
 
+
+int main(int argc, char **argv) {
+
+    hgw_context = hgw_context_compat_init(argc, argv);
+    if (!hgw_context) {
+        printf("Cannot init hildon-games-startup!\n");
+        return 0;
+    }
+
+    hgw_compat_set_cb_exit(hgw_context, exit_callback);
+    hgw_compat_set_cb_quit(hgw_context, quit_callback);
+    hgw_compat_set_cb_flush(hgw_context, flush_callback);    
+    if(!hgw_context_compat_check(hgw_context)) return 0;
+
+    /* hildon-games-wrapper part */
+    hgw_msg_compat_receive(hgw_context, 0);
+    usleep(100);
+
+    // Main game
+    play();
+
+    // hgw_context_compat_destroy_deinit(hgw_context);
+    // hgw_context_compat_destroy_quit(hgw_context);
+    hgw_context_destroy(hgw_context);
+
+    return 0;
+}
+
diff --git a/src/plugin/Makefile b/src/plugin/Makefile
new file mode 100644 (file)
index 0000000..c55993b
--- /dev/null
@@ -0,0 +1,34 @@
+# GNU Makefile -- Makefile
+# 2009 Reto Zingg
+
+CC = gcc
+DBG = gdb
+STD = _GNU_SOURCE
+CFLAGS = `pkg-config hildon-1 --cflags` -I/usr/include/dbus-1.0/ -I/usr/lib/dbus-1.0/include/
+LFLAGS =  -shared `pkg-config hildon-1 --libs`
+
+MAIN_OBJ = mancala-ui-plugin.o
+
+
+
+#'$<' is filename of input, '$@' is filename of output
+.c.o:
+       $(CC) -c -g$(DBG) -Wall $(CFLAGS) -D$(STD) $<
+.h.o:
+       $(CC) -c -g$(DBG) -Wall $(CFLAGS) -D$(STD) $<
+
+all:   $(MAIN_OBJ)
+       $(CC) $(LFLAGS) $(MAIN_OBJ) -o mancala-ui-plugin.so
+
+install:       all
+       mkdir -p $(DESTDIR)/home/opt/mancala/plugin/
+       cp mancala-ui-plugin.so $(DESTDIR)/home/opt/mancala/plugin/
+
+clean:
+       rm -f *.o *.core *.swp *~ *.log
+
+clobber:       clean
+       rm -f mancala-ui-plugin.so
+
+
+
diff --git a/src/plugin/mancala-ui-plugin.c b/src/plugin/mancala-ui-plugin.c
new file mode 100644 (file)
index 0000000..9fb5cf7
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+* This file is part of Mancala
+*
+* Originally from Crazyparking:
+* Copyright (C) 2005 INdT - Instituto Nokia de Tecnologia
+* http://www.indt.org/maemo
+*
+* adapted:
+* Copyright (c) 2009 Reto Zingg
+*
+* Some of the code is based on the examples on:
+* http://wiki.maemo.org/Documentation/Maemo_5_Developer_Guide
+*
+* This software is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public License
+* as published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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 General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA
+*
+*/ 
+
+
+#include <stdio.h>
+#include <hildon/hildon.h>
+#include <gtk/gtk.h>
+#include <startup_plugin.h>
+#include <startup_app.h>
+#include <dbus/dbus-glib.h>
+
+
+static GtkWidget *load_plugin               (void);
+static void       unload_plugin             (void);
+static void       write_config              (void);
+
+static GameStartupInfo gs;
+
+static StartupPluginInfo plugin_info = {
+  load_plugin,
+  unload_plugin,
+  write_config,
+  NULL
+};
+
+
+
+
+STARTUP_INIT_PLUGIN(plugin_info, gs, FALSE, FALSE)
+
+// the following does not work proper until osso_game_startup is
+// implemented as stackable window...
+
+// static void destroy_help_subwindow (void)
+// {
+//     StartupApp *app = gs.ui->app;
+//     osso_application_top(app->osso, app->path, NULL);
+// }
+// 
+// static void show_help_subwindow (void)
+// {
+//     GtkWidget *win;
+//     GtkWidget *textbox;
+//     GtkTextBuffer *textbox_buffer;
+//     gchar *textbox_text;
+//     PangoFontDescription *font_desc;
+//     GtkWidget *pannable_text;
+//     
+//     /* Create the subwindow (a stackable window) */
+//     win = hildon_stackable_window_new();
+//     gtk_window_set_title ( GTK_WINDOW (win), "Help");
+// 
+//     /* Create and pack labels */     
+//     textbox_text = g_strdup_printf("Welcome to Mancala, the ancient African game of skill!\n\nMancala is a very simple, easy-to-learn game. Each player begins with a horizontal row of holes or pits filled with a certain number of stones. At either end of the board are the players' home pits, which are used to keep score. In this case, the human player has the left home pit and the upper row holes. A move is made by clicking into the hole you wish to move from. The stones are then picked up and distributed, one to each hole, moving toward your home pit is reached, and then moving through your opponent's row, bypassing his/her home, and moving back towards in a circle (counterclockwise), until all the stones have been distributed.\n\nIf the last stone is placed in your home, you receive an extra turn. If the last stone lands in an empty hole on your side, you 'capture' the stones in the opposite hole on your opponent's side, moving them to your home.\n\nThe game ends when one player cannot play (ie. there are no stones on his/her side of the board.  The player who has the most stones on his/her *side* wins.");
+//     
+//     textbox = hildon_text_view_new();
+//     gtk_text_view_set_editable(GTK_TEXT_VIEW(textbox), FALSE);
+//     // gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(textbox), FALSE);
+//     gtk_text_view_set_indent(GTK_TEXT_VIEW(textbox), 10);
+//     gtk_text_view_set_left_margin(GTK_TEXT_VIEW(textbox), 10);
+//     gtk_text_view_set_right_margin(GTK_TEXT_VIEW(textbox), 10);
+//     gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW(textbox), 3);
+//     gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(textbox), 2);
+//     gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textbox), GTK_WRAP_WORD);
+//     // gtk_widget_set_sensitive(textbox, FALSE);
+//     font_desc = pango_font_description_from_string ("vera 18");
+//     gtk_widget_modify_font(textbox, font_desc);
+//     pango_font_description_free (font_desc);
+//     
+//     textbox_buffer = hildon_text_view_get_buffer (HILDON_TEXT_VIEW (textbox));
+//     
+//     gtk_text_buffer_set_text(textbox_buffer, textbox_text, -1);
+//     
+//     
+//     pannable_text = hildon_pannable_area_new();
+//     hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA(pannable_text), textbox);
+//     
+//     gtk_container_add (GTK_CONTAINER (win), pannable_text);
+//     
+//     g_signal_connect (win, "destroy",    destroy_help_subwindow, NULL);
+//     
+// 
+//     /* This call show the window and also add the window to the stack */
+//     gtk_widget_show_all (win);
+// }
+
+
+static void show_help_browser (void)
+{
+    char *uri = "file:///home/opt/mancala/data/mancala.html";
+    DBusGConnection *connection;
+    GError *error = NULL;
+    DBusGProxy *proxy;
+    
+    connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+    
+    if (connection == NULL){
+        printf("Dbus connection failed: %s\n",error->message);
+        g_error_free (error);
+        return;
+    }
+    
+    proxy = dbus_g_proxy_new_for_name (connection,
+                                       "com.nokia.osso_browser",
+                                       "/com/nokia/osso_browser/request",
+                                       "com.nokia.osso_browser");
+
+    error = NULL;
+
+    if (!dbus_g_proxy_call (proxy, "load_url", &error, G_TYPE_STRING, uri, G_TYPE_INVALID, G_TYPE_INVALID)){
+        printf("Load_URL failed: %s\n",error->message);
+        g_error_free (error);
+    }
+
+}
+
+
+static GtkWidget *load_plugin (void)
+{
+    GtkWidget *button;
+    button =  gtk_button_new_with_label ("Instuctions");
+    
+    g_signal_connect (button, "clicked", G_CALLBACK (show_help_browser), NULL);
+    
+    return GTK_WIDGET(button);
+    
+}
+
+static void
+unload_plugin (void)
+{
+
+}
+
+static void
+write_config (void)
+{
+  
+}
+
+