Game of Fifteen Applet
- From: Thomas Canty <tommy optushome com au>
- To: desktop-devel-list gnome org
- Subject: Game of Fifteen Applet
- Date: Tue, 11 Dec 2001 19:42:05 +0100
Hello,
here is a patch which gets the Fifteen Applet working under Gnome 2,
is it okay to commit?
thanks,
Thomas
Index: Makefile.am
===================================================================
RCS file: /cvs/gnome/gnome-applets/fifteen/Makefile.am,v
retrieving revision 1.12
diff -u -r1.12 Makefile.am
--- Makefile.am 2001/09/19 16:36:43 1.12
+++ Makefile.am 2001/12/11 10:15:18
@@ -3,27 +3,26 @@
INCLUDES = -I. -I$(srcdir) \
-I$(top_srcdir)/intl -I$(top_builddir)/intl \
-DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
- -I$(includedir)
+ $(GNOME_LIBS2_CFLAGS)
+ $(LIBGNOMECANVAS_APPLETS_CFLAGS)
-bin_PROGRAMS = fifteen_applet
+bin_PROGRAMS = fifteen_applet2
-fifteen_applet_SOURCES = fifteen.c
+fifteen_applet2_SOURCES = fifteen.c
-fifteen_applet_LDADD = \
- $(GNOME_APPLETS_LIBS) $(INTLLIBS)
+fifteen_applet2_LDADD = \
+ $(GNOME_LIBS2_LIBS) \
+ $(INTLLIBS) \
+ $(LIBGNOMECANVAS_APPLETS_LIBS)
-sysdir = $(datadir)/applets/Amusements
-sys_predata = fifteen_applet.desktop.in
-sys_DATA = $(sys_predata:.desktop.in=.desktop)
- XML_I18N_MERGE_DESKTOP_RULE@
-
pixmapdir = $(datadir)/pixmaps
pixmap_DATA = gnome-fifteen.png
-gnorbadir = $(sysconfdir)/CORBA/servers
-gnorba_DATA = fifteen_applet.gnorba
+serverdir = $(libdir)/bonobo/servers
+server_in_files = GNOME_FifteenApplet_Factory.server.in
+server_DATA = $(server_in_files:.server.in=.server)
+ INTLTOOL_SERVER_RULE@
EXTRA_DIST = \
$(pixmap_DATA) \
- $(gnorba_DATA) $(sys_DATA) $(sys_predata)
-
+ GNOME_FifteenApplet_Factory.server.in
Index: fifteen.c
===================================================================
RCS file: /cvs/gnome/gnome-applets/fifteen/fifteen.c,v
retrieving revision 1.25
diff -u -r1.25 fifteen.c
--- fifteen.c 2001/07/11 20:55:51 1.25
+++ fifteen.c 2001/12/11 10:15:18
@@ -8,8 +8,14 @@
*/
#include <config.h>
-#include <applet-widget.h>
+
+#include <panel-applet.h>
+
+#include <gtk/gtkframe.h>
+#include <gtk/gtkmessagedialog.h>
+#include <gtk/gtkdialog.h>
#include <libgnomeui/gnome-window-icon.h>
+#include <libgnomecanvas/libgnomecanvas.h>
#include <assert.h>
/* the piece size is for 48 and will be scaled to the proper size */
@@ -44,9 +50,13 @@
return;
buf = g_strdup_printf("%s : %u", _("You win!\nMoves"), moves);
- dlg = gnome_ok_dialog(buf);
- gtk_window_set_modal(GTK_WINDOW(dlg),TRUE);
- gnome_dialog_run (GNOME_DIALOG (dlg));
+ dlg = gtk_message_dialog_new (NULL,
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_OK,
+ buf);
+
+ gtk_dialog_run (GTK_DIALOG(dlg));
g_free(buf);
moves = 0;
scrambled = FALSE;
@@ -182,8 +192,8 @@
board = g_new (GnomeCanvasItem *, 16);
gtk_object_set_user_data (GTK_OBJECT (*canvas), board);
- gtk_signal_connect (GTK_OBJECT (*canvas), "destroy",
- (GtkSignalFunc) free_stuff,
+ g_signal_connect (G_OBJECT (*canvas), "destroy",
+ G_CALLBACK (free_stuff),
board);
for (i = 0; i < 15; i++) {
@@ -222,8 +232,8 @@
gtk_object_set_data (GTK_OBJECT (board[i]), "piece_num", GINT_TO_POINTER (i));
gtk_object_set_data (GTK_OBJECT (board[i]), "piece_pos", GINT_TO_POINTER (i));
gtk_object_set_data (GTK_OBJECT (board[i]), "text", text);
- gtk_signal_connect (GTK_OBJECT (board[i]), "event",
- (GtkSignalFunc) piece_event,
+ g_signal_connect (G_OBJECT (board[i]), "event",
+ G_CALLBACK (piece_event),
NULL);
}
@@ -235,7 +245,9 @@
}
static void
-scramble (AppletWidget *applet, gpointer data)
+scramble (BonoboUIComponent *uic,
+ gpointer data,
+ const char *verbname)
{
GnomeCanvas *canvas;
GnomeCanvasItem **board;
@@ -290,7 +302,9 @@
}
static void
-about (AppletWidget *applet, gpointer data)
+display_about_dialog (BonoboUIComponent *uic,
+ gpointer data,
+ const char *verbname)
{
static const char *authors[] = { "Federico Mena", NULL };
static GtkWidget *about_box = NULL;
@@ -304,20 +318,22 @@
about_box = gnome_about_new (_("Fifteen sliding pieces"),
VERSION,
_("Copyright (C) The Free Software Foundation"),
- authors,
_("Sam Lloyd's all-time favorite game, "
"now for your delight in the Gnome Panel. "
"Guaranteed to be a productivity buster."),
+ authors,
+ NULL, /* documenters */
+ NULL, /* translator_credits */
NULL);
- gtk_signal_connect( GTK_OBJECT(about_box), "destroy",
- GTK_SIGNAL_FUNC(gtk_widget_destroyed), &about_box );
+ g_signal_connect( G_OBJECT(about_box), "destroy",
+ G_CALLBACK(gtk_widget_destroyed), &about_box );
gtk_widget_show(about_box);
return;
}
static void
-change_pixel_size(GtkWidget *w, int size, gpointer data)
+applet_change_pixel_size(GtkWidget *w, int size, gpointer data)
{
GnomeCanvas *canvas = data;
double scale_factor = size/48.0;
@@ -332,65 +348,70 @@
}
static void
-help_cb (AppletWidget *applet, gpointer data)
+display_help (BonoboUIComponent *uic,
+ gpointer data,
+ const char *verbname)
{
- GnomeHelpMenuEntry help_entry = { "fifteen_applet", "index.html"};
- gnome_help_display(NULL, &help_entry);
+ gnome_help_display("index.html", "fifteen_applet", NULL);
}
+
+static const BonoboUIVerb fifteen_menu_verbs [] = {
+ BONOBO_UI_UNSAFE_VERB ("FifteenScramble", scramble),
+ BONOBO_UI_UNSAFE_VERB ("FifteenHelp", display_help),
+ BONOBO_UI_UNSAFE_VERB ("FifteenAbout", display_about_dialog),
+ BONOBO_UI_VERB_END
+};
+
+static const char fifteen_menu_xml [] =
+ "<popup name=\"button3\">\n"
+ " <menuitem name=\"Fifteen Scramble Item\" verb=\"FifteenScramble\" _label=\"Scramble\"/>\n"
+ " <menuitem name=\"Fifteen Help Item\" verb=\"FifteenHelp\" _label=\"Help\"\n"
+ " pixtype=\"stock\" pixname=\"gtk-help\"/>\n"
+ " <menuitem name=\"Fifteen About Item\" verb=\"FifteenAbout\" _label=\"About ...\"\n"
+ " pixtype=\"stock\" pixname=\"gnome-stock-about\"/>\n"
+ "</popup>\n";
-int
-main (int argc, char **argv)
+static BonoboObject *
+fifteen_applet_new ()
{
GtkWidget *applet;
GtkWidget *fifteen;
GtkWidget *canvas = NULL;
- int size;
+ int size;
- bindtextdomain (PACKAGE, GNOMELOCALEDIR);
- textdomain (PACKAGE);
+ size = 48;
+ fifteen = create_fifteen (size, &canvas);
- applet_widget_init ("fifteen_applet", VERSION, argc,
- argv, NULL, 0, NULL);
- gnome_window_icon_set_default_from_file (GNOME_ICONDIR"/gnome-fifteen.png");
+ applet = panel_applet_new (fifteen);
- applet = applet_widget_new ("fifteen_applet");
- if (!applet)
- g_error (_("Can't create fifteen applet!"));
+ panel_applet_setup_menu (PANEL_APPLET(applet), fifteen_menu_xml, fifteen_menu_verbs, fifteen);
- size = applet_widget_get_panel_pixel_size(APPLET_WIDGET(applet));
- fifteen = create_fifteen (size, &canvas);
- applet_widget_add (APPLET_WIDGET (applet), fifteen);
- gtk_widget_show (fifteen);
+ g_signal_connect (G_OBJECT (applet),
+ "change_size",
+ G_CALLBACK (applet_change_pixel_size),
+ canvas);
- /* here it is ok to connect here, this is because we have already
- * gotten the size before, and thus don't care about the initial
- * signal */
- gtk_signal_connect(GTK_OBJECT(applet),"change_pixel_size",
- GTK_SIGNAL_FUNC(change_pixel_size),
- canvas);
-
-
- gtk_widget_show (applet);
-
- applet_widget_register_callback (APPLET_WIDGET (applet),
- "scramble",
- _("Scramble pieces"),
- scramble,
- fifteen);
-
- applet_widget_register_stock_callback (APPLET_WIDGET (applet),
- "help",
- GNOME_STOCK_PIXMAP_HELP,
- _("Help"), help_cb, NULL);
-
- applet_widget_register_stock_callback (APPLET_WIDGET (applet),
- "about",
- GNOME_STOCK_MENU_ABOUT,
- _("About..."),
- about,
- NULL);
+ gtk_widget_show_all (applet);
- applet_widget_gtk_main ();
+ return BONOBO_OBJECT (panel_applet_get_control(PANEL_APPLET(applet)));
+}
- return 0;
+static BonoboObject *
+fifteen_factory (BonoboGenericFactory *this,
+ const gchar *iid,
+ gpointer data)
+{
+ BonoboObject *applet = NULL;
+
+ if (!strcmp (iid, "OAFIID:GNOME_FifteenApplet"))
+ applet = fifteen_applet_new ();
+
+ return applet;
}
+
+PANEL_APPLET_BONOBO_FACTORY ("OAFIID:GNOME_FifteenApplet_Factory",
+ "Game of Fifteen",
+ "0",
+ fifteen_factory,
+ NULL)
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]