Add configure UI to Frotz plugin
authorPhilip Chimento <philip.chimento@gmail.com>
Fri, 12 Oct 2012 12:18:30 +0000 (14:18 +0200)
committerPhilip Chimento <philip.chimento@gmail.com>
Fri, 12 Oct 2012 12:18:30 +0000 (14:18 +0200)
GObject bindings do not work, for some reason!

interpreters/Makefile.am
interpreters/chimara-frotz-plugin.c
interpreters/chimara-frotz-plugin.glade [new file with mode: 0644]

index 53a2cf44c60d47e2bceb6a49a7f9aaeaad4a1515..3882c6bffc264d28c580fe4f83e3c25ae155e4f2 100644 (file)
@@ -33,6 +33,8 @@ libfrotz_la_SOURCES = frotz/buffer.c frotz/err.c frotz/fastmem.c frotz/files.c \
 libfrotz_la_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/libchimara
 libfrotz_la_CFLAGS = -Wno-pointer-sign $(PLUGIN_CFLAGS) $(AM_CFLAGS)
 libfrotz_la_LDFLAGS = -module $(PLUGIN_LIBS) $(PLUGIN_LIBTOOL_FLAGS)
+frotzdatadir = $(plugindir)/frotz
+dist_frotzdata_DATA = chimara-frotz-plugin.glade
 
 # Git
 
index 705b12c38a63bca3e3cac78637f81734f3dacbb2..c390d3b062b19130500e98b486caaa354b6de119 100644 (file)
@@ -16,7 +16,6 @@ typedef struct _ChimaraFrotzPluginPrivate {
 #define CHIMARA_FROTZ_PLUGIN_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), CHIMARA_TYPE_FROTZ_PLUGIN, ChimaraFrotzPluginPrivate))
 #define CHIMARA_FROTZ_PLUGIN_USE_PRIVATE ChimaraFrotzPluginPrivate *priv = CHIMARA_FROTZ_PLUGIN_PRIVATE(self)
 
-
 static void chimara_frotz_plugin_configurable_init(PeasGtkConfigurableInterface *);
 static GtkWidget *chimara_frotz_plugin_create_configure_widget(PeasGtkConfigurable *);
 
@@ -320,8 +319,101 @@ chimara_frotz_plugin_configurable_init(PeasGtkConfigurableInterface *iface)
        iface->create_configure_widget = chimara_frotz_plugin_create_configure_widget;
 }
 
+/* Helper function to transform flags value to boolean; @data contains the
+GINT_TO_POINTER()'ed but position (0=LSB). */
+static gboolean
+debug_message_flags_transform_to(GBinding *binding, const GValue *source, GValue *target, gpointer data)
+{
+       int bit_shift = GPOINTER_TO_INT(data);
+       unsigned flags = g_value_get_uint(source);
+       g_value_set_boolean(target, flags & (1 << bit_shift));
+       return TRUE; /* success */
+}
+
+/* Reverse of debug_message_flags_transform_to(). */
+static gboolean
+debug_message_flags_transform_from(GBinding *binding, const GValue *source, GValue *target, gpointer data)
+{
+       int bit_shift = GPOINTER_TO_INT(data);
+       unsigned flags = g_value_get_uint(target);
+       int new_value = g_value_get_boolean(source)? 1 : 0;
+       g_value_set_uint(target, flags & (new_value << bit_shift));
+       return TRUE; /* success */
+}
+
 static GtkWidget *
 chimara_frotz_plugin_create_configure_widget(PeasGtkConfigurable *self)
 {
-       return gtk_label_new("Configure Widget");
+       GError *error = NULL;
+       const char *datadir = peas_plugin_info_get_data_dir(peas_engine_get_plugin_info(peas_engine_get_default(), "frotz"));
+       char *glade_file = g_build_filename(datadir, "chimara-frotz-plugin.glade", NULL);
+       GtkBuilder *builder = gtk_builder_new();
+       if(!gtk_builder_add_from_file(builder, glade_file, &error)) {
+               g_free(glade_file);
+               g_critical("Error building Frotz configuration dialog: %s\n", error->message);
+               return NULL;
+       }
+       g_free(glade_file);
+       GObject *retval = gtk_builder_get_object(builder, "frotz-configure-widget");
+
+       /* Bind GUI widget properties to this plugin's configuration properties */
+       g_object_bind_property_full(self, "debug-messages",
+               gtk_builder_get_object(builder, "attribute-setting-button"), "active",
+               G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL,
+               debug_message_flags_transform_to,
+               debug_message_flags_transform_from,
+               GINT_TO_POINTER(0), NULL);
+       g_object_bind_property_full(self, "debug-messages",
+               gtk_builder_get_object(builder, "attribute-testing-button"), "active",
+               G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL,
+               debug_message_flags_transform_to,
+               debug_message_flags_transform_from,
+               GINT_TO_POINTER(1), NULL);
+       g_object_bind_property_full(self, "debug-messages",
+               gtk_builder_get_object(builder, "object-movement-button"), "active",
+               G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL,
+               debug_message_flags_transform_to,
+               debug_message_flags_transform_from,
+               GINT_TO_POINTER(2), NULL);
+       g_object_bind_property_full(self, "debug-messages",
+               gtk_builder_get_object(builder, "object-location-button"), "active",
+               G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL,
+               debug_message_flags_transform_to,
+               debug_message_flags_transform_from,
+               GINT_TO_POINTER(3), NULL);
+       g_object_bind_property(self, "ignore-errors",
+               gtk_builder_get_object(builder, "ignore-errors-button"), "active",
+               G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+       g_object_bind_property(self, "piracy-mode",
+               gtk_builder_get_object(builder, "piracy-button"), "active",
+               G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+       g_object_bind_property(self, "quetzal-save-format",
+               gtk_builder_get_object(builder, "quetzal-button"), "active",
+               G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+       g_object_bind_property(self, "tandy-bit",
+               gtk_builder_get_object(builder, "tandy-button"), "active",
+               G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+       g_object_bind_property(self, "expand-abbreviations",
+               gtk_builder_get_object(builder, "expand-abbreviations-button"), "active",
+               G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+       g_object_bind_property(self, "random-seed",
+               gtk_builder_get_object(builder, "random-seed-adjustment"), "value",
+               G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+       g_object_bind_property(self, "random-seed-set",
+               gtk_builder_get_object(builder, "random-seed-set-button"), "active",
+               G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+       g_object_bind_property(self, "random-seed-set",
+               gtk_builder_get_object(builder, "random-seed-button"), "sensitive",
+               G_BINDING_SYNC_CREATE);
+       g_object_bind_property(self, "transcript-columns",
+               gtk_builder_get_object(builder, "columns-adjustment"), "value",
+               G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+       g_object_bind_property(self, "undo-slots",
+               gtk_builder_get_object(builder, "undo-adjustment"), "value",
+               G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+
+       /* Make sure the widget is returned with only one reference */
+       g_object_ref_sink(G_OBJECT(retval));
+       g_object_unref(builder);
+       return GTK_WIDGET(retval);
 }
diff --git a/interpreters/chimara-frotz-plugin.glade b/interpreters/chimara-frotz-plugin.glade
new file mode 100644 (file)
index 0000000..57baaa9
--- /dev/null
@@ -0,0 +1,155 @@
+<interface>
+  <object class="GtkNotebook" id="frotz-configure-widget">
+    <child>
+      <object class="GtkGrid" id="options-page">
+        <property name="orientation">GTK_ORIENTATION_VERTICAL</property>
+        <child>
+          <object class="GtkCheckButton" id="expand-abbreviations-button">
+            <property name="label" translatable="yes">Expand G, X, and Z</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkCheckButton" id="piracy-button">
+            <property name="label" translatable="yes">Pretend the story file is pirated</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkCheckButton" id="tandy-button">
+            <property name="label" translatable="yes">Pretend the interpreter is the edition sold by Tandy</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkCheckButton" id="quetzal-button">
+            <property name="label" translatable="yes">Use the Quetzal saved-game format</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkGrid" id="transcript-columns-box">
+            <child>
+              <object class="GtkLabel" id="transcript-columns-label">
+                <property name="label" translatable="yes">Use</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkSpinButton" id="transcript-columns-button">
+                <property name="adjustment">columns-adjustment</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkLabel" id="transcript-columns-label2">
+                <property name="label" translatable="yes">columns when saving transcripts</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkGrid" id="undo-box">
+            <child>
+              <object class="GtkLabel" id="undo-label1">
+                <property name="label" translatable="yes">Reserve</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkSpinButton" id="undo-button">
+                <property name="adjustment">undo-adjustment</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkLabel" id="undo-label2">
+                <property name="label" translatable="yes">slots for multiple undo</property>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+    <child type="tab">
+      <object class="GtkLabel" id="options-tab-label">
+        <property name="label" translatable="yes">Options</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkGrid" id="debug-box">
+        <property name="orientation">GTK_ORIENTATION_VERTICAL</property>
+        <child>
+          <object class="GtkCheckButton" id="ignore-errors-button">
+            <property name="label" translatable="yes">Ignore fatal errors</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkCheckButton" id="random-seed-set-button">
+            <property name="label" translatable="yes">Set random seed manually</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkGrid" id="random-seed-box">
+            <child>
+              <object class="GtkLabel" id="random-seed-label">
+                <property name="label" translatable="yes">to</property>
+                <property name="margin-left">12</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkSpinButton" id="random-seed-button">
+                <property name="adjustment">random-seed-adjustment</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel" id="debug-messages-label">
+            <property name="label">Print debug messages on:</property>
+            <property name="halign">GTK_ALIGN_START</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkCheckButton" id="attribute-setting-button">
+            <property name="label">attribute setting</property>
+            <property name="margin-left">12</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkCheckButton" id="attribute-testing-button">
+            <property name="label">attribute testing</property>
+            <property name="margin-left">12</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkCheckButton" id="object-movement-button">
+            <property name="label">object movement</property>
+            <property name="margin-left">12</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkCheckButton" id="object-location-button">
+            <property name="label">object location</property>
+            <property name="margin-left">12</property>
+          </object>
+        </child>
+      </object>
+    </child>
+    <child type="tab">
+      <object class="GtkLabel" id="debug-tab-label">
+        <property name="label" translatable="yes">Debugging</property>
+      </object>
+    </child>
+  </object>
+  <object class="GtkAdjustment" id="columns-adjustment">
+    <property name="lower">0</property>
+    <property name="value">80</property>
+    <property name="upper">200</property>
+    <property name="step-increment">1</property>
+  </object>
+  <object class="GtkAdjustment" id="undo-adjustment">
+    <property name="lower">1</property>
+    <property name="value">1</property>
+    <property name="upper">32767</property>
+    <property name="step-increment">1</property>
+  </object>
+  <object class="GtkAdjustment" id="random-seed-adjustment">
+    <property name="lower">0</property>
+    <property name="value">0</property>
+    <property name="upper">32767</property>
+    <property name="step-increment">1</property>
+  </object>
+</interface>
\ No newline at end of file