1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) Philip en Marijn 2008 <>
6 * iliad.c is free software copyrighted by Philip en Marijn.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name ``Philip en Marijn'' nor the name of any other
17 * contributor may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * main.c IS PROVIDED BY Philip en Marijn ``AS IS'' AND ANY EXPRESS
21 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Philip en Marijn OR ANY OTHER CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/types.h>
40 #include <glib/gi18n.h>
44 #include <libchimara/chimara-glk.h>
45 #include <libchimara/chimara-if.h>
48 #include <liberdm/erdm.h>
49 #include <liberipc/eripcviewer.h>
50 #include <liberipc/eripctoolbar.h>
51 #include <liberipc/eripcbusyd.h>
52 /*#include "xepdmgrclient.h"*/
55 /* Global pointers to widgets */
56 GtkWidget *window = NULL;
57 GtkWidget *glk = NULL;
60 /* sEpd *epd = NULL;*/
62 static erClientChannel_t erbusyChannel;
63 static erClientChannel_t ertoolbarChannel;
66 on_started(ChimaraGlk *glk)
68 g_printerr("Started!\n");
72 on_stopped(ChimaraGlk *glk)
74 g_printerr("Stopped!\n");
80 chimara_glk_feed_line_input( CHIMARA_GLK(glk), "restore" );
86 chimara_glk_feed_line_input( CHIMARA_GLK(glk), "save" );
90 update_screen(gpointer data)
92 printf("Update screen from idle handler\n");
93 dmDisplay(dmCmdPriorNormal, dmQFull);
99 on_iliad_screen_update(ChimaraGlk *glk, gboolean typing)
101 printf("Update screen\n");
102 g_idle_add_full(G_PRIORITY_DEFAULT_IDLE+100, update_screen, NULL, NULL);
109 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
110 glk = chimara_if_new();
111 //chimara_if_set_preferred_interpreter( CHIMARA_IF(glk), CHIMARA_IF_FORMAT_Z8, CHIMARA_IF_INTERPRETER_NITFOL);
113 gtk_widget_set_size_request(window, 800, 800);
117 "ignore-errors", TRUE,
118 "style-sheet", "style.css",
121 g_signal_connect(glk, "started", G_CALLBACK(on_started), NULL);
122 g_signal_connect(glk, "stopped", G_CALLBACK(on_stopped), NULL);
123 g_signal_connect(glk, "iliad-screen-update", G_CALLBACK(on_iliad_screen_update), NULL);
125 GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
126 GtkWidget *toolbar = gtk_toolbar_new();
128 GtkToolItem *restore_button = gtk_tool_button_new_from_stock(GTK_STOCK_OPEN);
129 g_signal_connect(restore_button, "clicked", G_CALLBACK(on_restore), NULL);
130 gtk_toolbar_insert( GTK_TOOLBAR(toolbar), restore_button, 0 );
132 GtkToolItem *save_button = gtk_tool_button_new_from_stock(GTK_STOCK_SAVE);
133 g_signal_connect(save_button, "clicked", G_CALLBACK(on_save), NULL);
134 gtk_toolbar_insert( GTK_TOOLBAR(toolbar), save_button, 0 );
136 GtkToolItem *quit_button = gtk_tool_button_new_from_stock(GTK_STOCK_QUIT);
137 g_signal_connect(quit_button, "clicked", G_CALLBACK(gtk_main_quit), NULL);
138 gtk_toolbar_insert( GTK_TOOLBAR(toolbar), quit_button, 0 );
140 GtkWidget *spacer = gtk_vbox_new(FALSE, 0);
141 gtk_widget_set_size_request(spacer, -1, 250);
143 gtk_box_pack_start( GTK_BOX(vbox), toolbar, FALSE, FALSE, 0 );
144 gtk_box_pack_start( GTK_BOX(vbox), glk, TRUE, TRUE, 0 );
145 gtk_box_pack_end( GTK_BOX(vbox), spacer, FALSE, FALSE, 0 );
147 gtk_container_add( GTK_CONTAINER(window), vbox );
153 erIpcStartClient(ER_TOOLBAR_CHANNEL, &ertoolbarChannel);
154 tbSelectIconSet(ertoolbarChannel, ER_PDF_VIEWER_UA_ID);
155 tbClearIconSet(ertoolbarChannel, ER_PDF_VIEWER_UA_ID);
158 tbAppendPlatformIcon( ertoolbarChannel, ER_PDF_VIEWER_UA_ID, iconID_trashcan, -1);
159 tbSetStatePlatformIcon(ertoolbarChannel, ER_PDF_VIEWER_UA_ID, iconID_trashcan, iconState_grey );
161 // Enable then pop up keyboard
162 tbAppendPlatformIcon( ertoolbarChannel, ER_PDF_VIEWER_UA_ID, iconID_keyboard, -1);
163 tbSetStatePlatformIcon(ertoolbarChannel, ER_PDF_VIEWER_UA_ID, iconID_keyboard, iconState_selected);
167 iliad_clear_toolbar()
170 tbSetStatePlatformIcon(ertoolbarChannel, ER_PDF_VIEWER_UA_ID, iconID_trashcan, iconState_normal );
172 // Disable the keyboard
173 tbSetStatePlatformIcon(ertoolbarChannel, ER_PDF_VIEWER_UA_ID, iconID_keyboard, iconState_normal);
177 main(int argc, char *argv[])
179 GError *error = NULL;
182 bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
183 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
184 textdomain(GETTEXT_PACKAGE);
187 /* Setup connection to display manager deamon */
189 if( (epd = EpdInit(NULL)) == NULL ) {
190 g_critical("Could not connect to xepdmgr server\n");
193 EpdRefreshAuto(epd, 0);
196 if( !g_thread_supported() )
199 gtk_init(&argc, &argv);
202 gtk_widget_show_all(window);
205 g_printerr("Must provide a game file\n");
209 if( !chimara_if_run_game(CHIMARA_IF(glk), argv[1], &error) ) {
210 g_printerr("Error starting Glk library: %s\n", error->message);
213 //chimara_glk_run( CHIMARA_GLK(glk), ".libs/multiwin.so", argc, argv, NULL);
215 iliad_init_toolbar();
221 chimara_glk_stop(CHIMARA_GLK(glk));
222 chimara_glk_wait(CHIMARA_GLK(glk));
224 iliad_clear_toolbar();