diff options
author | Christopher James Lahey <clahey@helixcode.com> | 2001-01-21 14:00:04 +0800 |
---|---|---|
committer | Chris Lahey <clahey@src.gnome.org> | 2001-01-21 14:00:04 +0800 |
commit | 9348acc44109d5fc54a70393131c1c5f30d181df (patch) | |
tree | 76d069c1c7082cd512b01ba38e61a3600ed2fae1 | |
parent | ac6ce9637e4abaa35ede7aecf4ca1126dc57809c (diff) | |
download | gsoc2013-evolution-9348acc44109d5fc54a70393131c1c5f30d181df.tar gsoc2013-evolution-9348acc44109d5fc54a70393131c1c5f30d181df.tar.gz gsoc2013-evolution-9348acc44109d5fc54a70393131c1c5f30d181df.tar.bz2 gsoc2013-evolution-9348acc44109d5fc54a70393131c1c5f30d181df.tar.lz gsoc2013-evolution-9348acc44109d5fc54a70393131c1c5f30d181df.tar.xz gsoc2013-evolution-9348acc44109d5fc54a70393131c1c5f30d181df.tar.zst gsoc2013-evolution-9348acc44109d5fc54a70393131c1c5f30d181df.zip |
Use the new gal_view_set_title function.
2001-01-21 Christopher James Lahey <clahey@helixcode.com>
* gal-define-views-model.c (gdvm_set_value_at): Use the new
gal_view_set_title function.
* gal-view-collection.c, gal-view-collection.h: Implemented this.
Added gal_view_collection_save and gal_view_collection_load.
* gal-view-etable.c: Implemented save, load, and set_title methods
for this class.
* gal-view-factory.c: Implemented gal_view_factory_get_type_code.
* gal-view.c, gal-view.h: Replaced gal_view_save_to_node with
gal_view_save. Replaced gal_view_load_from_node with
gal_view_load. Added gal_view_set_title.
svn path=/trunk/; revision=7676
-rw-r--r-- | widgets/menus/gal-define-views-model.c | 4 | ||||
-rw-r--r-- | widgets/menus/gal-view-collection.c | 206 | ||||
-rw-r--r-- | widgets/menus/gal-view-collection.h | 20 | ||||
-rw-r--r-- | widgets/menus/gal-view-etable.c | 35 | ||||
-rw-r--r-- | widgets/menus/gal-view-factory.c | 22 | ||||
-rw-r--r-- | widgets/menus/gal-view.c | 44 | ||||
-rw-r--r-- | widgets/menus/gal-view.h | 36 |
7 files changed, 311 insertions, 56 deletions
diff --git a/widgets/menus/gal-define-views-model.c b/widgets/menus/gal-define-views-model.c index 4f988c09bb..ca365d662b 100644 --- a/widgets/menus/gal-define-views-model.c +++ b/widgets/menus/gal-define-views-model.c @@ -79,9 +79,7 @@ gdvm_set_value_at (ETableModel *etc, int col, int row, const void *val) if (views->editable) { if (col != 0 || row < 0 || row > views->data_count) return; - gtk_object_set(GTK_OBJECT(views->data[row]), - "name", val, - NULL); + gal_view_set_title(views->data[row], val); e_table_model_cell_changed(etc, col, row); } } diff --git a/widgets/menus/gal-view-collection.c b/widgets/menus/gal-view-collection.c index 30652f064f..1ac4215f93 100644 --- a/widgets/menus/gal-view-collection.c +++ b/widgets/menus/gal-view-collection.c @@ -10,12 +10,25 @@ #include <config.h> #include <gtk/gtksignal.h> #include <gal/util/e-util.h> +#include <gal/util/e-xml-utils.h> +#include <gnome-xml/parser.h> #include "gal-view-collection.h" #define GVC_CLASS(e) ((GalViewCollectionClass *)((GtkObject *)e)->klass) #define PARENT_TYPE gtk_object_get_type () +struct _GalViewCollectionItem { + GalView *view; + char *id; + gboolean changed; + gboolean ever_changed; + gboolean built_in; + char *filename; + char *title; + char *type; +}; + static GtkObjectClass *gal_view_collection_parent_class; enum { @@ -44,13 +57,34 @@ gal_view_collection_display_view (GalViewCollection *collection, } static void +gal_view_collection_item_free (GalViewCollectionItem *item) +{ + g_free(item->id); + if (item->view) + gtk_object_unref(GTK_OBJECT(item->view)); + g_free(item); +} + +static void gal_view_collection_destroy (GtkObject *object) { GalViewCollection *collection = GAL_VIEW_COLLECTION(object); + int i; - e_free_object_list(collection->view_list); + for (i = 0; i < collection->view_count; i++) { + gal_view_collection_item_free (collection->view_data[i]); + } + g_free(collection->view_data); e_free_object_list(collection->factory_list); + for (i = 0; i < collection->removed_view_count; i++) { + gal_view_collection_item_free (collection->removed_view_data[i]); + } + g_free(collection->removed_view_data); + + g_free(collection->system_dir); + g_free(collection->local_dir); + if (gal_view_collection_parent_class->destroy) (*gal_view_collection_parent_class->destroy)(object); } @@ -79,8 +113,15 @@ gal_view_collection_class_init (GtkObjectClass *object_class) static void gal_view_collection_init (GalViewCollection *collection) { - collection->view_list = NULL; - collection->factory_list = NULL; + collection->view_data = NULL; + collection->view_count = 0; + collection->factory_list = NULL; + + collection->removed_view_data = NULL; + collection->removed_view_count = 0; + + collection->system_dir = NULL; + collection->local_dir = NULL; } /** @@ -133,9 +174,14 @@ gal_view_collection_new (void) */ void gal_view_collection_set_storage_directories (GalViewCollection *collection, - char *system_dir, - char *local_dir) + const char *system_dir, + const char *local_dir) { + g_free(collection->system_dir); + g_free(collection->local_dir); + + collection->system_dir = g_strdup(system_dir); + collection->local_dir = g_strdup(local_dir); } /** @@ -154,3 +200,153 @@ gal_view_collection_add_factory (GalViewCollection *collection, gtk_object_ref(GTK_OBJECT(factory)); collection->factory_list = g_list_prepend(collection->factory_list, factory); } + +static GalViewCollectionItem * +load_single_file (GalViewCollection *collection, + gchar *dir, + gboolean local, + xmlNode *node) +{ + GalViewCollectionItem *item; + item = g_new(GalViewCollectionItem, 1); + item->ever_changed = local; + item->changed = FALSE; + item->built_in = !local; + item->id = e_xml_get_string_prop_by_name(node, "id"); + item->title = e_xml_get_string_prop_by_name(node, "title"); + item->filename = e_xml_get_string_prop_by_name(node, "filename"); + item->type = e_xml_get_string_prop_by_name(node, "type"); + if (item->filename) { + GalViewFactory *factory; + char *temp; + GList *factories; + + temp = g_concat_dir_and_file(dir, item->filename); + g_free(item->filename); + item->filename = temp; + + factory = NULL; + for (factories = collection->factory_list; factories; factories = factories->next) { + if (!strcmp(gal_view_factory_get_type_code(factories->data), item->type)) { + factory = factories->data; + break; + } + } + if (factory) { + item->view = gal_view_factory_new_view (factory, item->filename); + gal_view_load(item->view, item->filename); + } + } + return item; +} + +static void +load_single_dir (GalViewCollection *collection, + char *dir, + gboolean local) +{ + xmlDoc *doc; + xmlNode *root; + xmlNode *child; + char *filename = g_concat_dir_and_file(dir, "galview.xml"); + + doc = xmlParseFile(filename); + root = xmlDocGetRootElement(doc); + for (child = root->xmlChildrenNode; child; child = child->next) { + gchar *id = e_xml_get_string_prop_by_name(child, "id"); + gboolean found = FALSE; + int i; + + for (i = 0; i < collection->view_count; i++) { + if (!strcmp(id, collection->view_data[i]->id)) + if (!local) + collection->view_data[i]->built_in = TRUE; + found = TRUE; + break; + } + if (!found) { + for (i = 0; i < collection->removed_view_count; i++) { + if (!strcmp(id, collection->removed_view_data[i]->id)) + if (!local) + collection->removed_view_data[i]->built_in = TRUE; + found = TRUE; + break; + } + } + + if (!found) { + GalViewCollectionItem *item = load_single_file (collection, dir, local, child); + if (item->filename) { + collection->view_data = g_renew(GalViewCollectionItem *, collection->view_data, collection->view_count + 1); + collection->view_data[collection->view_count] = item; + collection->view_count ++; + } else { + collection->removed_view_data = g_renew(GalViewCollectionItem *, collection->removed_view_data, collection->removed_view_count + 1); + collection->removed_view_data[collection->removed_view_count] = item; + collection->removed_view_count ++; + } + } + g_free(id); + } + + g_free(filename); +} + +/** + * gal_view_collection_load + * @collection: The view collection to load information for + * + * Loads the data from the system and user directories specified in + * set storage directories. This is primarily for internal use by + * other parts of gal_view. + */ +void +gal_view_collection_load (GalViewCollection *collection) +{ + load_single_dir(collection, collection->local_dir, TRUE); + load_single_dir(collection, collection->system_dir, FALSE); +} + +/** + * gal_view_collection_save + * @collection: The view collection to save information for + * + * Saves the data to the user directory specified in set storage + * directories. This is primarily for internal use by other parts of + * gal_view. + */ +void +gal_view_collection_save (GalViewCollection *collection) +{ + int i; + xmlDoc *doc; + xmlNode *root; + char *filename; + + doc = xmlNewDoc("1.0"); + root = xmlNewNode(NULL, "GalViewCollection"); + xmlDocSetRootElement(doc, root); + for (i = 0; i < collection->view_count; i++) { + xmlNode *child; + GalViewCollectionItem *item; + + item = collection->view_data[i]; + if (item->ever_changed) { + child = xmlNewChild(root, NULL, "GalView", NULL); + e_xml_set_string_prop_by_name(child, "id", item->id); + e_xml_set_string_prop_by_name(child, "title", item->title); + e_xml_set_string_prop_by_name(child, "filename", item->filename); + e_xml_set_string_prop_by_name(child, "type", item->type); + + if (item->changed) { + filename = g_concat_dir_and_file(collection->local_dir, item->filename); + gal_view_save(item->view, filename); + g_free(filename); + } + } + } + filename = g_concat_dir_and_file(collection->local_dir, "galview.xml"); + xmlSaveFile(filename, doc); + xmlFreeDoc(doc); + g_free(filename); +} diff --git a/widgets/menus/gal-view-collection.h b/widgets/menus/gal-view-collection.h index 40272da186..0de5f9ff71 100644 --- a/widgets/menus/gal-view-collection.h +++ b/widgets/menus/gal-view-collection.h @@ -11,11 +11,20 @@ #define GAL_IS_VIEW_COLLECTION(o) (GTK_CHECK_TYPE ((o), GAL_VIEW_COLLECTION_TYPE)) #define GAL_IS_VIEW_COLLECTION_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), GAL_VIEW_COLLECTION_TYPE)) +typedef struct _GalViewCollectionItem GalViewCollectionItem; + typedef struct { GtkObject base; - GList *view_list; + GalViewCollectionItem **view_data; + int view_count; GList *factory_list; + + GalViewCollectionItem **removed_view_data; + int removed_view_count; + + char *system_dir; + char *local_dir; } GalViewCollection; typedef struct { @@ -34,8 +43,8 @@ GalViewCollection *gal_view_collection_new (void); /* Set up the view collection */ void gal_view_collection_set_storage_directories (GalViewCollection *collection, - char *system_dir, - char *local_dir); + const char *system_dir, + const char *local_dir); void gal_view_collection_add_factory (GalViewCollection *collection, GalViewFactory *factory); @@ -43,4 +52,9 @@ void gal_view_collection_add_factory (GalViewCollecti void gal_view_collection_display_view (GalViewCollection *collection, GalView *view); +/* Call set_storage_directories and add factories for anything that + * might be found there before doing either of these. */ +void gal_view_collection_load (GalViewCollection *collection); +void gal_view_collection_save (GalViewCollection *collection); + #endif /* _GAL_VIEW_COLLECTION_H_ */ diff --git a/widgets/menus/gal-view-etable.c b/widgets/menus/gal-view-etable.c index b748f66952..c25f3a62a8 100644 --- a/widgets/menus/gal-view-etable.c +++ b/widgets/menus/gal-view-etable.c @@ -25,17 +25,17 @@ gal_view_etable_edit (GalView *view) } static void -gal_view_etable_load_from_node (GalView *view, - xmlNode *node) +gal_view_etable_load (GalView *view, + const char *filename) { - + e_table_state_load_from_file(GAL_VIEW_ETABLE(view)->state, filename); } static void -gal_view_etable_save_to_node (GalView *view, - xmlNode *parent) +gal_view_etable_save (GalView *view, + const char *filename) { - + e_table_state_save_to_file(GAL_VIEW_ETABLE(view)->state, filename); } static const char * @@ -44,6 +44,14 @@ gal_view_etable_get_title (GalView *view) return GAL_VIEW_ETABLE(view)->title; } +static void +gal_view_etable_set_title (GalView *view, + const char *title) +{ + g_free(GAL_VIEW_ETABLE(view)->title); + GAL_VIEW_ETABLE(view)->title = g_strdup(title); +} + static GalView * gal_view_etable_clone (GalView *view) { @@ -77,14 +85,15 @@ gal_view_etable_class_init (GtkObjectClass *object_class) { GalViewClass *gal_view_class = GAL_VIEW_CLASS(object_class); gal_view_etable_parent_class = gtk_type_class (PARENT_TYPE); - - gal_view_class->edit = gal_view_etable_edit ; - gal_view_class->load_from_node = gal_view_etable_load_from_node; - gal_view_class->save_to_node = gal_view_etable_save_to_node ; - gal_view_class->get_title = gal_view_etable_get_title ; - gal_view_class->clone = gal_view_etable_clone ; - object_class->destroy = gal_view_etable_destroy ; + gal_view_class->edit = gal_view_etable_edit ; + gal_view_class->load = gal_view_etable_load ; + gal_view_class->save = gal_view_etable_save ; + gal_view_class->get_title = gal_view_etable_get_title; + gal_view_class->set_title = gal_view_etable_set_title; + gal_view_class->clone = gal_view_etable_clone ; + + object_class->destroy = gal_view_etable_destroy ; } static void diff --git a/widgets/menus/gal-view-factory.c b/widgets/menus/gal-view-factory.c index 32eb7ad016..569dc59b92 100644 --- a/widgets/menus/gal-view-factory.c +++ b/widgets/menus/gal-view-factory.c @@ -49,8 +49,8 @@ GalView * gal_view_factory_new_view (GalViewFactory *factory, const char *name) { - g_return_val_if_fail (factory != NULL, 0); - g_return_val_if_fail (GAL_IS_VIEW_FACTORY (factory), 0); + g_return_val_if_fail (factory != NULL, NULL); + g_return_val_if_fail (GAL_IS_VIEW_FACTORY (factory), NULL); if (GVF_CLASS (factory)->new_view) return GVF_CLASS (factory)->new_view (factory, name); @@ -58,6 +58,24 @@ gal_view_factory_new_view (GalViewFactory *factory, return NULL; } +/** + * gal_view_factory_get_type_code: + * @factory: The factory to use + * + * Returns: The type code + */ +const char * +gal_view_factory_get_type_code (GalViewFactory *factory) +{ + g_return_val_if_fail (factory != NULL, NULL); + g_return_val_if_fail (GAL_IS_VIEW_FACTORY (factory), NULL); + + if (GVF_CLASS (factory)->get_type_code) + return GVF_CLASS (factory)->get_type_code (factory); + else + return NULL; +} + static void gal_view_factory_class_init (GtkObjectClass *object_class) { diff --git a/widgets/menus/gal-view.c b/widgets/menus/gal-view.c index a9a57b5443..484e1d5116 100644 --- a/widgets/menus/gal-view.c +++ b/widgets/menus/gal-view.c @@ -36,35 +36,35 @@ gal_view_edit (GalView *view) } /** - * gal_view_load_from_node + * gal_view_load * @view: The view to load to - * @node: The xml data to load + * @filename: The file to load from */ void -gal_view_load_from_node (GalView *view, - xmlNode *node) +gal_view_load (GalView *view, + const char *filename) { g_return_if_fail (view != NULL); g_return_if_fail (GAL_IS_VIEW (view)); - if (GV_CLASS (view)->load_from_node) - GV_CLASS (view)->load_from_node (view, node); + if (GV_CLASS (view)->load) + GV_CLASS (view)->load (view, filename); } /** - * gal_view_save_to_node + * gal_view_save * @view: The view to save - * @parent: Save the data as a child of this node + * @filename: The file to save to */ void -gal_view_save_to_node (GalView *view, - xmlNode *parent) +gal_view_save (GalView *view, + const char *filename) { g_return_if_fail (view != NULL); g_return_if_fail (GAL_IS_VIEW (view)); - if (GV_CLASS (view)->save_to_node) - GV_CLASS (view)->save_to_node (view, parent); + if (GV_CLASS (view)->save) + GV_CLASS (view)->save (view, filename); } /** @@ -86,6 +86,22 @@ gal_view_get_title (GalView *view) } /** + * gal_view_set_title + * @view: The view to set. + * @title: The new title value. + */ +void +gal_view_set_title (GalView *view, + const char *title) +{ + g_return_if_fail (view != NULL); + g_return_if_fail (GAL_IS_VIEW (view)); + + if (GV_CLASS (view)->set_title) + GV_CLASS (view)->set_title (view, title); +} + +/** * gal_view_clone * @view: The view to clone. * @@ -110,8 +126,8 @@ gal_view_class_init (GtkObjectClass *object_class) gal_view_parent_class = gtk_type_class (PARENT_TYPE); klass->edit = NULL; - klass->load_from_node = NULL; - klass->save_to_node = NULL; + klass->load = NULL; + klass->save = NULL; klass->get_title = NULL; klass->clone = NULL; } diff --git a/widgets/menus/gal-view.h b/widgets/menus/gal-view.h index 7860f08da7..70a410bd61 100644 --- a/widgets/menus/gal-view.h +++ b/widgets/menus/gal-view.h @@ -21,32 +21,36 @@ typedef struct { /* * Virtual methods */ - void (*edit) (GalView *view); - void (*load_from_node) (GalView *view, - xmlNode *node); - void (*save_to_node) (GalView *view, - xmlNode *parent); - const char *(*get_title) (GalView *view); - GalView *(*clone) (GalView *view); + void (*edit) (GalView *view); + void (*load) (GalView *view, + const char *filename); + void (*save) (GalView *view, + const char *filename); + const char *(*get_title) (GalView *view); + void (*set_title) (GalView *view, + const char *title); + GalView *(*clone) (GalView *view); } GalViewClass; /* Standard functions */ -GtkType gal_view_get_type (void); +GtkType gal_view_get_type (void); /* Open an editor dialog for this view. */ -void gal_view_edit (GalView *view); +void gal_view_edit (GalView *view); /* xml load and save functions */ -void gal_view_load_from_node (GalView *view, - xmlNode *node); -void gal_view_save_to_node (GalView *view, - xmlNode *parent); +void gal_view_load (GalView *view, + const char *filename); +void gal_view_save (GalView *view, + const char *filename); -/* Query functions */ -const char *gal_view_get_title (GalView *view); +/* Title functions */ +const char *gal_view_get_title (GalView *view); +void gal_view_set_title (GalView *view, + const char *title); /* Cloning the view */ -GalView *gal_view_clone (GalView *view); +GalView *gal_view_clone (GalView *view); #endif /* _GAL_VIEW_H_ */ |