-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
- * callbacks.c
- * Copyright (C) Philip en Marijn 2008 <>
- *
- * preferences.c is free software copyrighted by Philip en Marijn.
- *
+ * Copyright (C) 2008, 2009, 2010, 2011 Philip Chimento and Marijn van Vliet.
+ * All rights reserved.
+ *
+ * Chimara is free software copyrighted by Philip Chimento and Marijn van Vliet.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
+ *
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name ``Philip en Marijn'' nor the name of any other
- * contributor may be used to endorse or promote products derived
+ * 3. Neither of the names Philip Chimento or Marijn van Vliet, nor the name of
+ * any other contributor may be used to endorse or promote products derived
* from this software without specific prior written permission.
- *
- * preferences.c IS PROVIDED BY Philip en Marijn ``AS IS'' AND ANY EXPRESS
- * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL Philip en Marijn OR ANY OTHER CONTRIBUTORS
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <stdlib.h>
#include <glib.h>
#include <glib-object.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <libchimara/chimara-glk.h>
#include <libchimara/chimara-if.h>
-#include <config.h>
#include "error.h"
#include "app.h"
#include "preferences.h"
+#include "util.h"
typedef struct _ChimaraPrefsPrivate {
int dummy;
#define CHIMARA_PREFS_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), CHIMARA_TYPE_PREFS, ChimaraPrefsPrivate))
#define CHIMARA_PREFS_USE_PRIVATE ChimaraPrefsPrivate *priv = CHIMARA_PREFS_PRIVATE(self)
-G_DEFINE_TYPE(ChimaraPrefs, chimara_prefs, GTK_TYPE_WINDOW);
+G_DEFINE_TYPE(ChimaraPrefs, chimara_prefs, GTK_TYPE_DIALOG);
static GtkTextTag *current_tag;
static GtkListStore *preferred_list;
static void
chimara_prefs_finalize(GObject *self)
{
- //CHIMARA_APP_USE_PRIVATE;
- //g_object_unref(priv->action_group);
-
/* Chain up */
G_OBJECT_CLASS(chimara_prefs_parent_class)->finalize(self);
}
{
/* Override methods of parent classes */
GObjectClass *object_class = G_OBJECT_CLASS(klass);
- //object_class->set_property = chimara_if_set_property;
- //object_class->get_property = chimara_if_get_property;
object_class->finalize = chimara_prefs_finalize;
-
- /* Signals */
-
- /* Properties */
/* Private data */
g_type_class_add_private(klass, sizeof(ChimaraPrefsPrivate));
}
-static GObject *
-load_object(GtkBuilder *builder, const gchar *name)
-{
- GObject *retval;
- if( (retval = gtk_builder_get_object(builder, name)) == NULL) {
- error_dialog(NULL, NULL, "Error while getting object '%s'", name);
- g_error("Error while getting object '%s'", name);
- }
- return retval;
-}
-
/* Internal functions to convert from human-readable names in the config file
to enums and back. Later: replace with plugin functions. */
static ChimaraIFFormat
static void
chimara_prefs_init(ChimaraPrefs *self)
{
- GError *error = NULL;
ChimaraApp *theapp = chimara_app_get();
+
+ /* Set parent properties */
+ g_object_set(self,
+ "title", _("Chimara Preferences"),
+ "window-position", GTK_WIN_POS_CENTER,
+ "type-hint", GDK_WINDOW_TYPE_HINT_DIALOG,
+ "border-width", 6,
+ NULL);
+ gtk_dialog_add_buttons(GTK_DIALOG(self),
+ GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
+ NULL);
/* Build user interface */
- GtkBuilder *builder = gtk_builder_new();
char *object_ids[] = {
- "prefswindow",
+ "prefs-notebook",
"available_interpreters",
"interpreters",
"style-list",
NULL
};
-
- if( !gtk_builder_add_objects_from_file(builder, PACKAGE_DATA_DIR "/chimara.ui", object_ids, &error) ) {
-#ifdef DEBUG
- g_error_free(error);
- error = NULL;
- if( !gtk_builder_add_objects_from_file(builder, PACKAGE_SRC_DIR "/chimara.ui", object_ids, &error) ) {
-#endif /* DEBUG */
- error_dialog(NULL, error, "Error while building interface: ");
- return;
-#ifdef DEBUG
- }
-#endif /* DEBUG */
- }
+ GtkBuilder *builder = new_builder_with_objects(object_ids);
+
+ GtkWidget *notebook = GTK_WIDGET( load_object(builder, "prefs-notebook") );
+ GtkWidget *content_area = gtk_dialog_get_content_area( GTK_DIALOG(self) );
+ gtk_container_add( GTK_CONTAINER(content_area), notebook );
/* Initialize the tree of style names */
GtkTreeStore *style_list = GTK_TREE_STORE( load_object(builder, "style-list") );
gtk_tree_store_set(style_list, &buffer, 0, "Text buffer", -1);
gtk_tree_store_set(style_list, &grid, 0, "Text grid", -1);
- //int i;
- //unsigned int num_tags;
- //const gchar **tag_names = chimara_glk_get_tag_names(glk, &num_tags);
- //for(i=0; i<num_tags; i++) {
- // gtk_tree_store_append(style_list, &buffer_child, &buffer);
- // gtk_tree_store_append(style_list, &grid_child, &grid);
- // gtk_tree_store_set(style_list, &buffer_child, 0, tag_names[i], -1);
- // gtk_tree_store_set(style_list, &grid_child, 0, tag_names[i], -1);
- //}
+ int i;
+ unsigned int num_tags;
+ const gchar **tag_names = chimara_glk_get_tag_names(&num_tags);
+ for(i=0; i<num_tags; i++) {
+ gtk_tree_store_append(style_list, &buffer_child, &buffer);
+ gtk_tree_store_append(style_list, &grid_child, &grid);
+ gtk_tree_store_set(style_list, &buffer_child, 0, tag_names[i], -1);
+ gtk_tree_store_set(style_list, &grid_child, 0, tag_names[i], -1);
+ }
/* Set selection mode to single select */
GtkTreeView *view = GTK_TREE_VIEW( load_object(builder, "style-treeview") );
gtk_file_chooser_set_filename(blorb_chooser, filename);
g_free(filename);
}
+
g_settings_get(theapp->prefs_settings, "css-file", "ms", &filename);
- //if(filename) {
- // if(!chimara_glk_set_css_from_file(glk, filename, NULL)) {
- // /* If the setting didn't point to a CSS file, fail silently and
- // null the setting */
- // g_settings_set(theapp->prefs_settings, "css-file", "ms", NULL);
- // } else {
- // gtk_file_chooser_set_filename(css_chooser, filename);
- // }
- // g_free(filename);
- //}
+ if(filename) {
+ gtk_file_chooser_set_filename(css_chooser, filename);
+ g_free(filename);
+ }
/* Populate the list of available interpreters */
GtkListStore *interp_list = GTK_LIST_STORE( load_object(builder, "available_interpreters") );
// 1, interpreter_to_display_string(chimara_if_get_preferred_interpreter(CHIMARA_IF(glk), count)),
// -1);
//}
+
+ gtk_builder_connect_signals(builder, self);
+ g_object_unref(builder);
+
+ /* Connect own signals */
+ g_signal_connect(self, "response", G_CALLBACK(gtk_widget_hide), NULL);
+ g_signal_connect(self, "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL);
}
/* PUBLIC FUNCTIONS */
// current_tag = chimara_glk_get_tag(glk, CHIMARA_GLK_TEXT_GRID, child_name);
}
-#if 0
void
on_toggle_left(GtkToggleButton *button, ChimaraGlk *glk) {
/* No nothing if the button is deactivated */
g_object_set(current_tag, "font-desc", font_description, NULL);
chimara_glk_update_style(glk);
}
-#endif
void
on_css_filechooser_file_set(GtkFileChooserButton *button, ChimaraGlk *glk)
{
- //GError *error = NULL;
- //ChimaraApp *theapp = chimara_app_get();
- //char *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(button) );
- //if(!chimara_glk_set_css_from_file(glk, filename, &error)) {
- // error_dialog(NULL, error, "There was a problem reading the CSS file: ");
- // g_settings_set(theapp->prefs_settings, "css-file", "ms", NULL);
- //} else {
- // g_settings_set(theapp->prefs_settings, "css-file", "ms", filename);
- //}
- //g_free(filename);
+ ChimaraApp *theapp = chimara_app_get();
+ char *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(button) );
+ g_settings_set(theapp->prefs_settings, "css-file", "ms", filename);
+ g_free(filename);
}
void