aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/menus/gal-view-collection.c
diff options
context:
space:
mode:
authorChristopher James Lahey <clahey@ximian.com>2002-02-01 05:47:00 +0800
committerChris Lahey <clahey@src.gnome.org>2002-02-01 05:47:00 +0800
commit3263cd26212cfeaa820882499ffad95f67937b40 (patch)
tree51fea90edc348d4f114a9ea07caca3ad1b02bc72 /widgets/menus/gal-view-collection.c
parenta3bd2634b10cbeaa0dd82cdb37c9007476977050 (diff)
downloadgsoc2013-evolution-3263cd26212cfeaa820882499ffad95f67937b40.tar
gsoc2013-evolution-3263cd26212cfeaa820882499ffad95f67937b40.tar.gz
gsoc2013-evolution-3263cd26212cfeaa820882499ffad95f67937b40.tar.bz2
gsoc2013-evolution-3263cd26212cfeaa820882499ffad95f67937b40.tar.lz
gsoc2013-evolution-3263cd26212cfeaa820882499ffad95f67937b40.tar.xz
gsoc2013-evolution-3263cd26212cfeaa820882499ffad95f67937b40.tar.zst
gsoc2013-evolution-3263cd26212cfeaa820882499ffad95f67937b40.zip
Added gal-view-instance.c and gal-view-instance.h.
2002-01-31 Christopher James Lahey <clahey@ximian.com> * Makefile.am: Added gal-view-instance.c and gal-view-instance.h. * gal-view-collection.c, gal-view-collection.h (gal_view_collection_load_view_from_file): Factored out this function so that it can be used outside of gal-view-collection.c. (gal_view_collection_get_view_index_by_id, gal_view_collection_get_view_id_by_index, gal_view_collection_loaded): Added these functions. * gal-view-instance.c, gal-view-instance.h: New class representing a single folder of a particular type of folder. svn path=/trunk/; revision=15544
Diffstat (limited to 'widgets/menus/gal-view-collection.c')
-rw-r--r--widgets/menus/gal-view-collection.c178
1 files changed, 117 insertions, 61 deletions
diff --git a/widgets/menus/gal-view-collection.c b/widgets/menus/gal-view-collection.c
index fe555ee5bd..89cd4deab7 100644
--- a/widgets/menus/gal-view-collection.c
+++ b/widgets/menus/gal-view-collection.c
@@ -88,6 +88,61 @@ gal_view_collection_item_free (GalViewCollectionItem *item)
g_free(item);
}
+static char *
+gal_view_generate_string (GalViewCollection *collection,
+ GalView *view,
+ int which)
+{
+ char *ret_val;
+ char *pointer;
+
+ if (which == 1)
+ ret_val = g_strdup(gal_view_get_title(view));
+ else
+ ret_val = g_strdup_printf("%s_%d", gal_view_get_title(view), which);
+ for (pointer = ret_val; *pointer; pointer++) {
+ if (!isalnum((guint) *pointer)) {
+ *pointer = '_';
+ }
+ }
+ return ret_val;
+}
+
+static gint
+gal_view_check_string (GalViewCollection *collection,
+ char *string)
+{
+ int i;
+
+ if (!strcmp (string, "current_view"))
+ return FALSE;
+
+ for (i = 0; i < collection->view_count; i++) {
+ if (!strcmp(string, collection->view_data[i]->id))
+ return FALSE;
+ }
+ for (i = 0; i < collection->removed_view_count; i++) {
+ if (!strcmp(string, collection->removed_view_data[i]->id))
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static char *
+gal_view_generate_id (GalViewCollection *collection,
+ GalView *view)
+{
+ int i;
+ for (i = 1; TRUE; i++) {
+ char *try;
+
+ try = gal_view_generate_string(collection, view, i);
+ if (gal_view_check_string(collection, try))
+ return try;
+ g_free(try);
+ }
+}
+
static void
gal_view_collection_destroy (GtkObject *object)
{
@@ -154,6 +209,8 @@ gal_view_collection_init (GalViewCollection *collection)
collection->system_dir = NULL;
collection->local_dir = NULL;
+
+ collection->loaded = FALSE;
}
/**
@@ -255,6 +312,40 @@ view_changed (GalView *view,
gal_view_collection_changed(item->collection);
}
+/* Use factory list to load a GalView file. */
+static GalView *
+gal_view_collection_real_load_view_from_file (GalViewCollection *collection, const char *type, const char *title, const char *dir, const char *filename)
+{
+ GalViewFactory *factory;
+ GList *factories;
+
+ factory = NULL;
+ for (factories = collection->factory_list; factories; factories = factories->next) {
+ if (type && !strcmp(gal_view_factory_get_type_code(factories->data), type)) {
+ factory = factories->data;
+ break;
+ }
+ }
+ if (factory) {
+ char *fullpath;
+ GalView *view;
+
+ fullpath = g_concat_dir_and_file(dir, filename);
+ view = gal_view_factory_new_view (factory, title);
+ gal_view_set_title (view, title);
+ gal_view_load(view, fullpath);
+ g_free(fullpath);
+ return view;
+ }
+ return NULL;
+}
+
+GalView *
+gal_view_collection_load_view_from_file (GalViewCollection *collection, const char *type, const char *filename)
+{
+ return gal_view_collection_real_load_view_from_file (collection, type, "", collection->local_dir, filename);
+}
+
static GalViewCollectionItem *
load_single_file (GalViewCollection *collection,
gchar *dir,
@@ -273,28 +364,11 @@ load_single_file (GalViewCollection *collection,
item->collection = collection;
if (item->filename) {
- GalViewFactory *factory;
- GList *factories;
-
- factory = NULL;
- for (factories = collection->factory_list; factories; factories = factories->next) {
- if (item->type && !strcmp(gal_view_factory_get_type_code(factories->data), item->type)) {
- factory = factories->data;
- break;
- }
- }
- if (factory) {
- char *filename;
-
- filename = g_concat_dir_and_file(dir, item->filename);
- item->view = gal_view_factory_new_view (factory, item->title);
- gal_view_load(item->view, filename);
- gal_view_set_title (item->view, item->title);
+ item->view = gal_view_collection_real_load_view_from_file (collection, item->type, item->title, dir, item->filename);
+ if (item->view) {
gtk_signal_connect(GTK_OBJECT(item->view), "changed",
GTK_SIGNAL_FUNC(view_changed), item);
- g_free(filename);
}
-
}
return item;
}
@@ -373,9 +447,13 @@ gal_view_collection_load (GalViewCollection *collection)
g_return_if_fail (GAL_IS_VIEW_COLLECTION (collection));
g_return_if_fail (collection->local_dir != NULL);
g_return_if_fail (collection->system_dir != NULL);
+ g_return_if_fail (!collection->loaded);
load_single_dir(collection, collection->local_dir, TRUE);
load_single_dir(collection, collection->system_dir, FALSE);
+ gal_view_collection_changed(collection);
+
+ collection->loaded = TRUE;
}
/**
@@ -403,6 +481,7 @@ gal_view_collection_save (GalViewCollection *collection)
doc = xmlNewDoc("1.0");
root = xmlNewNode(NULL, "GalViewCollection");
xmlDocSetRootElement(doc, root);
+
for (i = 0; i < collection->view_count; i++) {
xmlNode *child;
GalViewCollectionItem *item;
@@ -494,58 +573,29 @@ gal_view_collection_get_view_item (GalViewCollection *collection,
return collection->view_data[n];
}
-static char *
-gal_view_generate_string (GalViewCollection *collection,
- GalView *view,
- int which)
-{
- char *ret_val;
- char *pointer;
-
- if (which == 1)
- ret_val = g_strdup(gal_view_get_title(view));
- else
- ret_val = g_strdup_printf("%s_%d", gal_view_get_title(view), which);
- for (pointer = ret_val; *pointer; pointer++) {
- if (!isalnum((guint) *pointer)) {
- *pointer = '_';
- }
- }
- return ret_val;
-}
-
-static gint
-gal_view_check_string (GalViewCollection *collection,
- char *string)
+int
+gal_view_collection_get_view_index_by_id (GalViewCollection *collection, const char *view_id)
{
int i;
-
for (i = 0; i < collection->view_count; i++) {
- if (!strcmp(string, collection->view_data[i]->id))
- return FALSE;
+ if (!strcmp (collection->view_data[i]->id, view_id))
+ return i;
}
- for (i = 0; i < collection->removed_view_count; i++) {
- if (!strcmp(string, collection->removed_view_data[i]->id))
- return FALSE;
- }
- return TRUE;
+ return -1;
}
-static char *
-gal_view_generate_id (GalViewCollection *collection,
- GalView *view)
+char *
+gal_view_collection_get_view_id_by_index (GalViewCollection *collection, int n)
{
- int i;
- for (i = 1; TRUE; i++) {
- char *try;
+ g_return_val_if_fail (collection != NULL, NULL);
+ g_return_val_if_fail (GAL_IS_VIEW_COLLECTION (collection), NULL);
+ g_return_val_if_fail(n < collection->view_count, NULL);
+ g_return_val_if_fail(n >= 0, NULL);
- try = gal_view_generate_string(collection, view, i);
- if (gal_view_check_string(collection, try))
- return try;
- g_free(try);
- }
+ return g_strdup (collection->view_data[n]->id);
}
+
void
gal_view_collection_append (GalViewCollection *collection,
GalView *view)
@@ -638,3 +688,9 @@ gal_view_collection_copy_view (GalViewCollection *collection,
gal_view_collection_changed(collection);
}
+
+gboolean
+gal_view_collection_loaded (GalViewCollection *collection)
+{
+ return collection->loaded;
+}