Removed MooConfig in favor of MooKeyFile

master
Yevgen Muntyan 2006-08-23 20:31:30 -05:00
parent 1a3a09871c
commit 08806c6bc0
5 changed files with 0 additions and 2205 deletions

View File

@ -29,7 +29,6 @@ mooutils_include_headers = \
moobigpaned.h \
mooclosure.h \
moocombo.h \
mooconfig.h \
mooentry.h \
moofiltermgr.h \
mooglade.h \
@ -80,7 +79,6 @@ mooutils_sources = \
moocombo.c \
moocompat.c \
moocompat.h \
mooconfig.c \
moodialogs.c \
moodialogs.h \
mooentry.c \

File diff suppressed because it is too large Load Diff

View File

@ -1,134 +0,0 @@
/*
* mooconfig.h
*
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* 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 of the License, or
* (at your option) any later version.
*
* See COPYING file that comes with this distribution.
*/
#ifndef __MOO_CONFIG_H__
#define __MOO_CONFIG_H__
#include <gtk/gtktreemodel.h>
G_BEGIN_DECLS
#define MOO_CONFIG_ERROR (moo_config_error_quark ())
#define MOO_TYPE_CONFIG_ITEM (moo_config_item_get_type ())
#define MOO_TYPE_CONFIG (moo_config_get_type ())
#define MOO_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MOO_TYPE_CONFIG, MooConfig))
#define MOO_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOO_TYPE_CONFIG, MooConfigClass))
#define MOO_IS_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MOO_TYPE_CONFIG))
#define MOO_IS_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_CONFIG))
#define MOO_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_CONFIG, MooConfigClass))
typedef enum {
MOO_CONFIG_ERROR_PARSE,
MOO_CONFIG_ERROR_FILE
} MooConfigError;
typedef struct _MooConfig MooConfig;
typedef struct _MooConfigPrivate MooConfigPrivate;
typedef struct _MooConfigClass MooConfigClass;
typedef struct _MooConfigItem MooConfigItem;
struct _MooConfig {
GObject parent;
MooConfigPrivate *priv;
};
struct _MooConfigClass {
GObjectClass parent_class;
};
GType moo_config_get_type (void) G_GNUC_CONST;
GType moo_config_item_get_type (void) G_GNUC_CONST;
GQuark moo_config_error_quark (void) G_GNUC_CONST;
MooConfig *moo_config_new (void);
MooConfig *moo_config_new_from_file (const char *filename,
gboolean modified,
GError **error);
MooConfig *moo_config_new_from_buffer (const char *string,
int len,
gboolean modified,
GError **error);
void moo_config_free (MooConfig *config);
gboolean moo_config_parse_buffer (MooConfig *config,
const char *string,
int len,
gboolean modify,
GError **error);
gboolean moo_config_parse_file (MooConfig *config,
const char *filename,
gboolean modify,
GError **error);
char *moo_config_format (MooConfig *config);
gboolean moo_config_save (MooConfig *config,
const char *file,
GError **error);
gboolean moo_config_get_modified (MooConfig *config);
void moo_config_set_modified (MooConfig *config,
gboolean modified);
guint moo_config_n_items (MooConfig *config);
MooConfigItem *moo_config_nth_item (MooConfig *config,
guint n);
MooConfigItem *moo_config_new_item (MooConfig *config,
int index,
gboolean modify);
void moo_config_delete_item (MooConfig *config,
guint index,
gboolean modify);
void moo_config_move_item (MooConfig *config,
guint index,
guint new_index,
gboolean modify);
void moo_config_set_default_bool (MooConfig *config,
const char *key,
gboolean value);
const char *moo_config_item_get (MooConfigItem *item,
const char *key);
void moo_config_set (MooConfig *config,
MooConfigItem *item,
const char *key,
const char *value,
gboolean modify);
gboolean moo_config_get_bool (MooConfig *config,
MooConfigItem *item,
const char *key);
void moo_config_set_bool (MooConfig *config,
MooConfigItem *item,
const char *key,
gboolean value,
gboolean modify);
const char *moo_config_item_get_content (MooConfigItem *item);
void moo_config_set_item_content (MooConfig *config,
MooConfigItem *item,
const char *content,
gboolean modify);
void moo_config_get_item_iter (MooConfig *config,
MooConfigItem *item,
GtkTreeIter *iter);
G_END_DECLS
#endif /* __MOO_CONFIG_H__ */

View File

@ -749,604 +749,3 @@ _moo_tree_helper_update_widgets (MooTreeHelper *helper)
moo_tree_helper_real_update_widgets (MOO_TREE_HELPER (helper), NULL, NULL);
}
}
/****************************************************************************/
/* MooConfigHelper
*/
#define MOO_TYPE_CONFIG_HELPER (_moo_config_helper_get_type ())
#define MOO_CONFIG_HELPER(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MOO_TYPE_CONFIG_HELPER, MooConfigHelper))
#define MOO_CONFIG_HELPER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOO_TYPE_CONFIG_HELPER, MooConfigHelperClass))
#define MOO_IS_CONFIG_HELPER(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MOO_TYPE_CONFIG_HELPER))
#define MOO_IS_CONFIG_HELPER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_CONFIG_HELPER))
#define MOO_CONFIG_HELPER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_CONFIG_HELPER, MooConfigHelperClass))
enum {
NEW_ITEM,
SET_FROM_ITEM,
SET_FROM_WIDGETS,
CONFIG_NUM_SIGNALS
};
static guint config_signals[CONFIG_NUM_SIGNALS];
typedef void (*MooConfigItemToWidget) (MooConfig *config,
MooConfigItem *item,
GtkWidget *widget,
gpointer data);
typedef void (*MooConfigWidgetToItem) (GtkWidget *widget,
MooConfig *config,
MooConfigItem *item,
gpointer data);
typedef struct {
char *key;
gboolean update_live;
gulong handler;
MooConfigItemToWidget item_to_widget;
MooConfigWidgetToItem widget_to_item;
gpointer data;
} WidgetInfo;
struct _MooConfigHelper {
MooTreeHelper parent;
GSList *widgets;
};
GType _moo_config_helper_get_type (void) G_GNUC_CONST;
G_DEFINE_TYPE (MooConfigHelper, _moo_config_helper, MOO_TYPE_TREE_HELPER)
static WidgetInfo *
get_info (gpointer widget)
{
return g_object_get_data (G_OBJECT (widget), "moo-config-helper-widget-info");
}
static void
moo_config_helper_destroy (GtkObject *object)
{
MooConfigHelper *helper = MOO_CONFIG_HELPER (object);
if (helper->widgets)
{
GSList *l;
for (l = helper->widgets; l != NULL; l = l->next)
{
GtkWidget *widget = l->data;
WidgetInfo *info = get_info (widget);
if (info->handler)
g_signal_handler_disconnect (widget, info->handler);
g_object_set_data (G_OBJECT (widget), "moo-config-helper-widget-info", NULL);
}
g_slist_free (helper->widgets);
helper->widgets = NULL;
}
GTK_OBJECT_CLASS(_moo_config_helper_parent_class)->destroy (object);
}
static gboolean
moo_config_helper_new_row (MooTreeHelper *tree_helper,
GtkTreeModel *model,
GtkTreePath *path)
{
int index;
MooConfigItem *item;
MooConfigHelper *helper = MOO_CONFIG_HELPER (tree_helper);
g_return_val_if_fail (path != NULL, FALSE);
g_return_val_if_fail (gtk_tree_path_get_depth (path) == 1, FALSE);
index = gtk_tree_path_get_indices(path)[0];
item = moo_config_new_item (MOO_CONFIG (model), index, TRUE);
g_return_val_if_fail (item != NULL, FALSE);
g_signal_emit (helper, config_signals[NEW_ITEM], 0, model, item);
return TRUE;
}
static gboolean
moo_config_helper_delete_row (G_GNUC_UNUSED MooTreeHelper *tree_helper,
GtkTreeModel *model,
GtkTreePath *path)
{
int index;
g_return_val_if_fail (path != NULL, FALSE);
g_return_val_if_fail (gtk_tree_path_get_depth (path) == 1, FALSE);
index = gtk_tree_path_get_indices(path)[0];
moo_config_delete_item (MOO_CONFIG (model), index, TRUE);
return TRUE;
}
static gboolean
moo_config_helper_move_row (G_GNUC_UNUSED MooTreeHelper *helper,
GtkTreeModel *model,
GtkTreePath *old_path,
GtkTreePath *new_path)
{
g_return_val_if_fail (old_path && new_path, FALSE);
g_return_val_if_fail (gtk_tree_path_get_depth (old_path) == 1, FALSE);
g_return_val_if_fail (gtk_tree_path_get_depth (new_path) == 1, FALSE);
moo_config_move_item (MOO_CONFIG (model),
gtk_tree_path_get_indices(old_path)[0],
gtk_tree_path_get_indices(new_path)[0],
TRUE);
return TRUE;
}
static void
moo_config_helper_update_widgets_real (MooTreeHelper *tree_helper,
GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter)
{
GSList *l;
MooConfigItem *item = NULL;
MooConfigHelper *helper = MOO_CONFIG_HELPER (tree_helper);
g_return_if_fail (MOO_IS_CONFIG (model));
if (path)
{
gtk_tree_model_get (model, iter, 0, &item, -1);
g_return_if_fail (item != NULL);
}
for (l = helper->widgets; l != NULL; l = l->next)
{
GtkWidget *widget;
WidgetInfo *info;
widget = l->data;
info = get_info (widget);
if (info->handler)
g_signal_handler_block (widget, info->handler);
gtk_widget_set_sensitive (widget, item != NULL);
if (item)
{
info->item_to_widget (MOO_CONFIG (model), item, widget, info->data);
}
else
{
if (GTK_IS_TOGGLE_BUTTON (widget))
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
else if (GTK_IS_ENTRY (widget))
gtk_entry_set_text (GTK_ENTRY (widget), "");
else
gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget)),
"", -1);
}
if (info->handler)
g_signal_handler_unblock (widget, info->handler);
}
}
static void
moo_config_helper_update_model_real (MooTreeHelper *tree_helper,
GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter)
{
GSList *l;
MooConfigItem *item = NULL;
MooConfigHelper *helper = MOO_CONFIG_HELPER (tree_helper);
g_return_if_fail (MOO_IS_CONFIG (model));
g_return_if_fail (path != NULL);
gtk_tree_model_get (model, iter, 0, &item, -1);
if (!item)
return;
for (l = helper->widgets; l != NULL; l = l->next)
{
GtkWidget *widget;
WidgetInfo *info;
widget = l->data;
info = get_info (widget);
info->widget_to_item (widget, MOO_CONFIG (model), item, info->data);
}
}
static void
_moo_config_helper_class_init (MooConfigHelperClass *klass)
{
MooTreeHelperClass *tree_class = MOO_TREE_HELPER_CLASS (klass);
GTK_OBJECT_CLASS(klass)->destroy = moo_config_helper_destroy;
tree_class->new_row = moo_config_helper_new_row;
tree_class->delete_row = moo_config_helper_delete_row;
tree_class->move_row = moo_config_helper_move_row;
tree_class->update_widgets = moo_config_helper_update_widgets_real;
tree_class->update_model = moo_config_helper_update_model_real;
config_signals[NEW_ITEM] =
g_signal_new ("new-item",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (MooConfigHelperClass, new_item),
NULL, NULL,
_moo_marshal_VOID__OBJECT_POINTER,
G_TYPE_NONE, 2,
MOO_TYPE_CONFIG,
MOO_TYPE_CONFIG_ITEM);
config_signals[SET_FROM_ITEM] =
g_signal_new ("set-from-item",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (MooConfigHelperClass, set_from_item),
NULL, NULL,
_moo_marshal_VOID__OBJECT_POINTER,
G_TYPE_NONE, 2,
MOO_TYPE_CONFIG,
MOO_TYPE_CONFIG_ITEM);
config_signals[SET_FROM_WIDGETS] =
g_signal_new ("set-from-widgets",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (MooConfigHelperClass, set_from_widgets),
NULL, NULL,
_moo_marshal_VOID__OBJECT_POINTER,
G_TYPE_NONE, 2,
MOO_TYPE_CONFIG,
MOO_TYPE_CONFIG_ITEM);
}
static void
_moo_config_helper_init (MooConfigHelper *helper)
{
helper->widgets = NULL;
}
MooConfigHelper *
_moo_config_helper_new (GtkWidget *tree_view,
GtkWidget *new_btn,
GtkWidget *delete_btn,
GtkWidget *up_btn,
GtkWidget *down_btn)
{
MooConfigHelper *helper;
g_return_val_if_fail (GTK_IS_TREE_VIEW (tree_view), NULL);
helper = g_object_new (MOO_TYPE_CONFIG_HELPER, NULL);
gtk_object_sink (g_object_ref (helper));
_moo_tree_helper_connect (MOO_TREE_HELPER (helper), tree_view,
new_btn, delete_btn, up_btn, down_btn);
return helper;
}
static void
button_toggled (MooTreeHelper *helper,
GtkToggleButton *button)
{
GtkTreeModel *model;
GtkTreeIter iter;
MooConfigItem *item = NULL;
WidgetInfo *info;
GtkTreeSelection *selection;
selection = gtk_tree_view_get_selection (helper->widget);
if (!gtk_tree_selection_get_selected (selection, &model, &iter))
return;
info = get_info (button);
g_return_if_fail (info != NULL);
gtk_tree_model_get (model, &iter, 0, &item, -1);
g_return_if_fail (item != NULL);
moo_config_set_bool (MOO_CONFIG (model), item, info->key,
gtk_toggle_button_get_active (button), TRUE);
}
static void
entry_changed (MooTreeHelper *helper,
GtkEntry *entry)
{
GtkTreeModel *model;
GtkTreeIter iter;
const char *text;
MooConfigItem *item = NULL;
WidgetInfo *info;
GtkTreeSelection *selection;
selection = gtk_tree_view_get_selection (helper->widget);
if (!gtk_tree_selection_get_selected (selection, &model, &iter))
return;
info = get_info (entry);
g_return_if_fail (info != NULL);
text = gtk_entry_get_text (entry);
gtk_tree_model_get (model, &iter, 0, &item, -1);
g_return_if_fail (item != NULL);
if (info->key)
moo_config_set (MOO_CONFIG (model), item,
info->key, text, TRUE);
else
moo_config_set_item_content (MOO_CONFIG (model), item,
text, TRUE);
}
static void
toggle_button_to_item (GtkToggleButton *button,
MooConfig *config,
MooConfigItem *item)
{
gboolean value;
WidgetInfo *info = get_info (button);
g_return_if_fail (info != NULL);
value = gtk_toggle_button_get_active (button);
moo_config_set_bool (config, item, info->key, value, TRUE);
}
static void
entry_to_item (GtkEntry *entry,
MooConfig *config,
MooConfigItem *item)
{
const char *text;
WidgetInfo *info = get_info (entry);
g_return_if_fail (info != NULL);
text = gtk_entry_get_text (entry);
if (info->key)
moo_config_set (config, item, info->key, text, TRUE);
else
moo_config_set_item_content (config, item, text, TRUE);
}
static void
text_view_to_item (GtkTextView *view,
MooConfig *config,
MooConfigItem *item)
{
char *text;
GtkTextBuffer *buffer;
GtkTextIter start, end;
WidgetInfo *info = get_info (view);
g_return_if_fail (info != NULL);
buffer = gtk_text_view_get_buffer (view);
gtk_text_buffer_get_bounds (buffer, &start, &end);
text = gtk_text_buffer_get_slice (buffer, &start, &end, TRUE);
if (!text[0])
{
g_free (text);
text = NULL;
}
if (info->key)
moo_config_set (config, item, info->key, text, TRUE);
else
moo_config_set_item_content (config, item, text, TRUE);
g_free (text);
}
static MooConfigWidgetToItem
get_widget_to_item_func (GtkWidget *widget)
{
if (GTK_IS_TOGGLE_BUTTON (widget))
return (MooConfigWidgetToItem) toggle_button_to_item;
else if (GTK_IS_ENTRY (widget))
return (MooConfigWidgetToItem) entry_to_item;
else if (GTK_IS_TEXT_VIEW (widget))
return (MooConfigWidgetToItem) text_view_to_item;
else
return NULL;
}
static void
item_to_toggle_button (MooConfig *config,
MooConfigItem *item,
GtkToggleButton *button)
{
gboolean value;
WidgetInfo *info = get_info (button);
g_return_if_fail (info != NULL);
value = moo_config_get_bool (config, item, info->key);
gtk_toggle_button_set_active (button, value);
}
static void
item_to_entry (G_GNUC_UNUSED MooConfig *config,
MooConfigItem *item,
GtkEntry *entry)
{
const char *text;
WidgetInfo *info = get_info (entry);
g_return_if_fail (info != NULL);
if (info->key)
text = moo_config_item_get (item, info->key);
else
text = moo_config_item_get_content (item);
gtk_entry_set_text (entry, text ? text : "");
}
static void
item_to_text_view (G_GNUC_UNUSED MooConfig *config,
MooConfigItem *item,
GtkTextView *view)
{
const char *text;
GtkTextBuffer *buffer;
WidgetInfo *info = get_info (view);
g_return_if_fail (info != NULL);
if (info->key)
text = moo_config_item_get (item, info->key);
else
text = moo_config_item_get_content (item);
buffer = gtk_text_view_get_buffer (view);
gtk_text_buffer_set_text (buffer, text ? text : "", -1);
}
static MooConfigItemToWidget
get_item_to_widget_func (GtkWidget *widget)
{
if (GTK_IS_TOGGLE_BUTTON (widget))
return (MooConfigItemToWidget) item_to_toggle_button;
else if (GTK_IS_ENTRY (widget))
return (MooConfigItemToWidget) item_to_entry;
else if (GTK_IS_TEXT_VIEW (widget))
return (MooConfigItemToWidget) item_to_text_view;
else
return NULL;
}
static WidgetInfo *
widget_info_new (const char *key,
gboolean update_live)
{
WidgetInfo *info = g_new0 (WidgetInfo, 1);
info->key = g_strdup (key);
info->update_live = update_live;
return info;
}
static void
widget_info_free (WidgetInfo *info)
{
if (info)
{
g_free (info->key);
g_free (info);
}
}
static void
moo_config_helper_add_widget_full (MooConfigHelper *helper,
GtkWidget *widget,
const char *key,
MooConfigWidgetToItem widget_to_item_func,
MooConfigItemToWidget item_to_widget_func,
gpointer data,
gboolean update_live)
{
WidgetInfo *info;
g_return_if_fail (!update_live || key != NULL);
g_return_if_fail (GTK_IS_TOGGLE_BUTTON (widget) ||
GTK_IS_ENTRY (widget) || GTK_IS_TEXT_VIEW (widget));
if (!widget_to_item_func)
{
widget_to_item_func = get_widget_to_item_func (widget);
g_return_if_fail (widget_to_item_func != NULL);
}
if (!item_to_widget_func)
{
item_to_widget_func = get_item_to_widget_func (widget);
g_return_if_fail (item_to_widget_func != NULL);
}
info = widget_info_new (key, update_live);
info->widget_to_item = widget_to_item_func;
info->item_to_widget = item_to_widget_func;
info->data = data;
helper->widgets = g_slist_prepend (helper->widgets, widget);
g_object_set_data_full (G_OBJECT (widget), "moo-config-helper-widget-info", info,
(GDestroyNotify) widget_info_free);
if (update_live)
{
if (GTK_IS_TOGGLE_BUTTON (widget))
info->handler =
g_signal_connect_swapped (widget, "toggled",
G_CALLBACK (button_toggled),
helper);
else if (GTK_IS_ENTRY (widget))
info->handler =
g_signal_connect_swapped (widget, "changed",
G_CALLBACK (entry_changed),
helper);
}
}
void
_moo_config_helper_add_widget (MooConfigHelper *helper,
GtkWidget *widget,
const char *key,
gboolean update_live)
{
g_return_if_fail (MOO_IS_CONFIG_HELPER (helper));
g_return_if_fail (GTK_IS_WIDGET (widget));
moo_config_helper_add_widget_full (helper, widget, key,
NULL, NULL, NULL,
update_live);
}
void
_moo_config_helper_update_model (MooConfigHelper *helper,
GtkTreeModel *model,
GtkTreePath *path)
{
g_return_if_fail (MOO_IS_CONFIG_HELPER (helper));
_moo_tree_helper_update_model (MOO_TREE_HELPER (helper), model, path);
}

View File

@ -14,7 +14,6 @@
#ifndef __MOO_UTILS_TREE_VIEW_H__
#define __MOO_UTILS_TREE_VIEW_H__
#include <mooutils/mooconfig.h>
#include <gtk/gtk.h>
G_BEGIN_DECLS
@ -28,9 +27,7 @@ G_BEGIN_DECLS
#define MOO_TREE_HELPER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_TREE_HELPER, MooTreeHelperClass))
typedef struct _MooTreeHelper MooTreeHelper;
typedef struct _MooConfigHelper MooConfigHelper;
typedef struct _MooTreeHelperClass MooTreeHelperClass;
typedef struct _MooConfigHelperClass MooConfigHelperClass;
struct _MooTreeHelper {
GtkObject parent;
@ -68,20 +65,6 @@ struct _MooTreeHelperClass {
GtkTreeIter *iter);
};
struct _MooConfigHelperClass {
MooTreeHelperClass parent_class;
void (*new_item) (MooConfigHelper *helper,
MooConfig *config,
MooConfigItem *item);
void (*set_from_item) (MooConfigHelper *helper,
MooConfig *config,
MooConfigItem *item);
void (*set_from_widgets) (MooConfigHelper *helper,
MooConfig *config,
MooConfigItem *item);
};
GType _moo_tree_helper_get_type (void) G_GNUC_CONST;
@ -101,21 +84,6 @@ void _moo_tree_helper_update_model (MooTreeHelper *helper,
GtkTreePath *path);
void _moo_tree_helper_update_widgets (MooTreeHelper *helper);
MooConfigHelper *_moo_config_helper_new (GtkWidget *tree_view,
GtkWidget *new_btn,
GtkWidget *delete_btn,
GtkWidget *up_btn,
GtkWidget *down_btn);
void _moo_config_helper_add_widget (MooConfigHelper *helper,
GtkWidget *widget,
const char *key,
gboolean update_live);
void _moo_config_helper_update_model (MooConfigHelper *helper,
GtkTreeModel *model,
GtkTreePath *path);
void _moo_tree_view_select_first (GtkTreeView *tree_view);
void _moo_combo_box_select_first (GtkComboBox *combo);