--- a/gplate/variables/Makefile.am Fri Jul 18 02:12:56 2008 -0500
+++ b/gplate/variables/Makefile.am Fri Jul 18 02:13:15 2008 -0500
@@ -8,6 +8,7 @@
gplatevariablesinc_HEADERS=\
gplate-dictionary-variable.h \
+ gplate-directory-variable.h \ @@ -15,6 +16,7 @@
libgplate_variables_la_SOURCES=\
gplate-dictionary-variable.c \
+ gplate-directory-variable.h \ --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplate/variables/gplate-directory-variable.c Fri Jul 18 02:13:15 2008 -0500
@@ -0,0 +1,267 @@
+ * Copyright (C) 2007-2008 Gary Kramlich <grim@reaperworld.com> + * 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) + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +#endif /* HAVE_CONFIG_H */ +#include <gplate/gplate-collection.h> +#include <gplate/variables/gplate-directory-variable.h> +#define GPLATE_DIRECTORY_VARIABLE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GPLATE_TYPE_DIRECTORY_VARIABLE, GPlateDirectoryVariablePrivate)) +/****************************************************************************** + *****************************************************************************/ +/****************************************************************************** + *****************************************************************************/ +} GPlateDirectoryVariablePrivate; +/****************************************************************************** + *****************************************************************************/ +static GObjectClass *parent_class = NULL; +/****************************************************************************** + *****************************************************************************/ +gplate_directory_variable_set_path(GPlateDirectoryVariable *directory_variable, + GPlateDirectoryVariablePrivate *priv = NULL; + g_return_if_fail(GPLATE_IS_DIRECTORY_VARIABLE(directory_variable)); + g_return_if_fail(path); + priv = GPLATE_DIRECTORY_VARIABLE_GET_PRIVATE(directory_variable); + priv->path = g_strdup(path); + gplate_directory_variable_refresh(directory_variable); +gplate_directory_variable_real_refresh(GPlateDirectoryVariable *directory_variable) { + GPlateDirectoryVariablePrivate *priv = NULL; + GPlateCollection *collection = NULL; + const gchar *entry = NULL; + g_return_if_fail(GPLATE_IS_DIRECTORY_VARIABLE(directory_variable)); + priv = GPLATE_DIRECTORY_VARIABLE_GET_PRIVATE(directory_variable); + collection = GPLATE_COLLECTION(directory_variable); + /* open the directory */ + dir = g_dir_open(priv->path, 0, NULL); + /* clear out the old junk, this might not be necessary, but then we'd need + * to manually track which files were removed, and i'm not doing that right + gplate_collection_remove_all(GPLATE_COLLECTION(directory_variable)); + /* now add all our files */ + while((entry = g_dir_read_name(dir)) != NULL) { + GPlateVariable *variable = NULL; + gchar *filename = NULL; + filename = g_build_filename(priv->path, entry, NULL); + variable = gplate_file_variable_new(entry, filename); + if(GPLATE_IS_VARIABLE(variable)) + gplate_collection_add_variable(collection, variable); + /* close that shit back up, NOW! */ +/****************************************************************************** + *****************************************************************************/ +gplate_directory_variable_get_property(GObject *obj, guint param_id, GValue *value, + GPlateDirectoryVariable *var = GPLATE_DIRECTORY_VARIABLE(obj); + g_value_set_string(value, gplate_directory_variable_get_path(var)); + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); +gplate_directory_variable_set_property(GObject *obj, guint param_id, + const GValue *value, GParamSpec *pspec) + GPlateDirectoryVariable *var = GPLATE_DIRECTORY_VARIABLE(obj); + gplate_directory_variable_set_path(var, g_value_get_string(value)); + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); +gplate_directory_variable_finalize(GObject *obj) { + GPlateDirectoryVariablePrivate *priv = NULL; + priv = GPLATE_DIRECTORY_VARIABLE_GET_PRIVATE(obj); + G_OBJECT_CLASS(parent_class)->finalize(obj); +gplate_directory_variable_class_init(GPlateVariableClass *klass) { + GPlateDirectoryVariableClass *fvar_class = GPLATE_DIRECTORY_VARIABLE_CLASS(klass); + GObjectClass *obj_class = G_OBJECT_CLASS(klass); + GParamSpec *pspec = NULL; + g_type_class_add_private(klass, sizeof(GPlateDirectoryVariablePrivate)); + parent_class = g_type_class_peek_parent(klass); + obj_class->get_property = gplate_directory_variable_get_property; + obj_class->set_property = gplate_directory_variable_set_property; + obj_class->finalize = gplate_directory_variable_finalize; + klass->get_value = NULL; + fvar_class->refresh = gplate_directory_variable_real_refresh; + pspec = g_param_spec_string("path", "path", + "The path for this variable.", + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property(obj_class, PROP_PATH, pspec); +/****************************************************************************** + *****************************************************************************/ +gplate_directory_variable_get_gtype(void) { + static const GTypeInfo info = { + sizeof(GPlateDirectoryVariableClass), + (GClassInitFunc)gplate_directory_variable_class_init, + sizeof(GPlateDirectoryVariable), + type = g_type_register_static(GPLATE_TYPE_DICTIONARY_VARIABLE, + "GPlateDirectoryVariable", + * gplate_directory_variable_new: + * @name: The name of the directory to create. + * @path: The name of the directory. + * Creates a new #GPlateDirectoryVariable named @name. + * Return Value: The new #GPlateDirectoryVariable. +gplate_directory_variable_new(const gchar *name, const gchar *path) { + return g_object_new(GPLATE_TYPE_DIRECTORY_VARIABLE, + * gplate_directory_variable_get_path: + * @directory_variable: The #GPlateDirectoryVariable. + * Gets the path of @directory_variable. + * Return Value: The path of @directory_variable. +gplate_directory_variable_get_path(const GPlateDirectoryVariable *directory_variable) { + GPlateDirectoryVariablePrivate *priv = NULL; + g_return_val_if_fail(GPLATE_IS_DIRECTORY_VARIABLE(directory_variable), NULL); + priv = GPLATE_DIRECTORY_VARIABLE_GET_PRIVATE(directory_variable); + * gplate_directory_variable_refresh: + * @directory_variable: The #GPlateDirectoryVariable. + * Refreshes all of the attributes store in @directory_variable. +gplate_directory_variable_refresh(GPlateDirectoryVariable *directory_variable) { + GPlateDirectoryVariableClass *klass = NULL; + g_return_if_fail(GPLATE_IS_DIRECTORY_VARIABLE(directory_variable)); + klass = GPLATE_DIRECTORY_VARIABLE_GET_CLASS(directory_variable); + if(klass && klass->refresh) + klass->refresh(directory_variable); --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplate/variables/gplate-directory-variable.h Fri Jul 18 02:13:15 2008 -0500
@@ -0,0 +1,66 @@
+ * Copyright (C) 2007-2008 Gary Kramlich <grim@reaperworld.com> + * 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) + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +#ifndef GPLATE_DIRECTORY_VARIABLE_H +#define GPLATE_DIRECTORY_VARIABLE_H +#include <gplate/variables/gplate-dictionary-variable.h> +#define GPLATE_TYPE_DIRECTORY_VARIABLE (gplate_directory_variable_get_gtype()) +#define GPLATE_DIRECTORY_VARIABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GPLATE_TYPE_DIRECTORY_VARIABLE, GPlateDirectoryVariable)) +#define GPLATE_DIRECTORY_VARIABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GPLATE_TYPE_DIRECTORY_VARIABLE, GPlateDirectoryVariableClass)) +#define GPLATE_IS_DIRECTORY_VARIABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GPLATE_TYPE_DIRECTORY_VARIABLE)) +#define GPLATE_IS_DIRECTORY_VARIABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GPLATE_TYPE_DIRECTORY_VARIABLE)) +#define GPLATE_DIRECTORY_VARIABLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GPLATE_TYPE_DIRECTORY_VARIABLE, GPlateDirectoryVariableClass)) +typedef struct _GPlateDirectoryVariable GPlateDirectoryVariable; +typedef struct _GPlateDirectoryVariableClass GPlateDirectoryVariableClass; +struct _GPlateDirectoryVariable { + GPlateDictionaryVariable gparent; + void (*_gplate_reserved1)(void); + void (*_gplate_reserved2)(void); + void (*_gplate_reserved3)(void); + void (*_gplate_reserved4)(void); +struct _GPlateDirectoryVariableClass { + GPlateDictionaryVariableClass parent; + void (*refresh)(GPlateDirectoryVariable *directory_variable); + void (*_gplate_reserved1)(void); + void (*_gplate_reserved2)(void); + void (*_gplate_reserved3)(void); + void (*_gplate_reserved4)(void); +GType gplate_directory_variable_get_gtype(void); +GPlateVariable *gplate_directory_variable_new(const gchar *name, const gchar *path); +const gchar *gplate_directory_variable_get_path(const GPlateDirectoryVariable *directory_variable); +void gplate_directory_variable_refresh(GPlateDirectoryVariable *directory_variable); +#endif /* GPLATE_DIRECTORY_VARIABLE_H */