aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-07-05 22:45:03 +0800
committerMatthew Barnes <mbarnes@redhat.com>2013-07-06 04:40:50 +0800
commitda9673c4213668d49700d2a39183a41ad0373f47 (patch)
tree98637dd792c85b5ca5dbc81c7bdfd382885aef71
parent25d2fab96e6c74c7c2b7ff6134b0bb54ed3ce384 (diff)
downloadgsoc2013-evolution-da9673c4213668d49700d2a39183a41ad0373f47.tar
gsoc2013-evolution-da9673c4213668d49700d2a39183a41ad0373f47.tar.gz
gsoc2013-evolution-da9673c4213668d49700d2a39183a41ad0373f47.tar.bz2
gsoc2013-evolution-da9673c4213668d49700d2a39183a41ad0373f47.tar.lz
gsoc2013-evolution-da9673c4213668d49700d2a39183a41ad0373f47.tar.xz
gsoc2013-evolution-da9673c4213668d49700d2a39183a41ad0373f47.tar.zst
gsoc2013-evolution-da9673c4213668d49700d2a39183a41ad0373f47.zip
GalViewCollection: Move public members into private section.
-rw-r--r--e-util/gal-view-collection.c210
-rw-r--r--e-util/gal-view-collection.h16
-rw-r--r--e-util/gal-view-instance-save-as-dialog.c35
3 files changed, 140 insertions, 121 deletions
diff --git a/e-util/gal-view-collection.c b/e-util/gal-view-collection.c
index 39027af742..7c7e997a34 100644
--- a/e-util/gal-view-collection.c
+++ b/e-util/gal-view-collection.c
@@ -33,7 +33,21 @@
((obj), GAL_TYPE_VIEW_COLLECTION, GalViewCollectionPrivate))
struct _GalViewCollectionPrivate {
- gint placeholder;
+ GalViewCollectionItem **view_data;
+ gint view_count;
+
+ GList *factory_list;
+
+ GalViewCollectionItem **removed_view_data;
+ gint removed_view_count;
+
+ gboolean loaded;
+ gboolean default_view_built_in;
+
+ gchar *system_directory;
+ gchar *user_directory;
+
+ gchar *default_view;
};
enum {
@@ -104,12 +118,12 @@ gal_view_check_string (GalViewCollection *collection,
if (!strcmp (string, "current_view"))
return FALSE;
- for (i = 0; i < collection->view_count; i++) {
- if (!strcmp (string, collection->view_data[i]->id))
+ for (i = 0; i < collection->priv->view_count; i++) {
+ if (!strcmp (string, collection->priv->view_data[i]->id))
return FALSE;
}
- for (i = 0; i < collection->removed_view_count; i++) {
- if (!strcmp (string, collection->removed_view_data[i]->id))
+ for (i = 0; i < collection->priv->removed_view_count; i++) {
+ if (!strcmp (string, collection->priv->removed_view_data[i]->id))
return FALSE;
}
return TRUE;
@@ -158,28 +172,28 @@ gal_view_collection_get_property (GObject *object,
static void
gal_view_collection_dispose (GObject *object)
{
- GalViewCollection *collection;
+ GalViewCollectionPrivate *priv;
gint ii;
- collection = GAL_VIEW_COLLECTION (object);
+ priv = GAL_VIEW_COLLECTION_GET_PRIVATE (object);
- for (ii = 0; ii < collection->view_count; ii++)
- gal_view_collection_item_free (collection->view_data[ii]);
- g_free (collection->view_data);
- collection->view_data = NULL;
- collection->view_count = 0;
+ for (ii = 0; ii < priv->view_count; ii++)
+ gal_view_collection_item_free (priv->view_data[ii]);
+ g_free (priv->view_data);
+ priv->view_data = NULL;
+ priv->view_count = 0;
g_list_foreach (
- collection->factory_list,
+ priv->factory_list,
(GFunc) g_object_unref, NULL);
- g_list_free (collection->factory_list);
- collection->factory_list = NULL;
+ g_list_free (priv->factory_list);
+ priv->factory_list = NULL;
- for (ii = 0; ii < collection->removed_view_count; ii++)
- gal_view_collection_item_free (collection->removed_view_data[ii]);
- g_free (collection->removed_view_data);
- collection->removed_view_data = NULL;
- collection->removed_view_count = 0;
+ for (ii = 0; ii < priv->removed_view_count; ii++)
+ gal_view_collection_item_free (priv->removed_view_data[ii]);
+ g_free (priv->removed_view_data);
+ priv->removed_view_data = NULL;
+ priv->removed_view_count = 0;
/* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (gal_view_collection_parent_class)->dispose (object);
@@ -188,13 +202,13 @@ gal_view_collection_dispose (GObject *object)
static void
gal_view_collection_finalize (GObject *object)
{
- GalViewCollection *collection;
+ GalViewCollectionPrivate *priv;
- collection = GAL_VIEW_COLLECTION (object);
+ priv = GAL_VIEW_COLLECTION_GET_PRIVATE (object);
- g_free (collection->system_dir);
- g_free (collection->local_dir);
- g_free (collection->default_view);
+ g_free (priv->system_directory);
+ g_free (priv->user_directory);
+ g_free (priv->default_view);
/* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (gal_view_collection_parent_class)->finalize (object);
@@ -249,7 +263,7 @@ gal_view_collection_init (GalViewCollection *collection)
{
collection->priv = GAL_VIEW_COLLECTION_GET_PRIVATE (collection);
- collection->default_view_built_in = TRUE;
+ collection->priv->default_view_built_in = TRUE;
}
/**
@@ -276,7 +290,7 @@ gal_view_collection_get_system_directory (GalViewCollection *collection)
{
g_return_val_if_fail (GAL_IS_VIEW_COLLECTION (collection), NULL);
- return collection->system_dir;
+ return collection->priv->system_directory;
}
/**
@@ -292,7 +306,7 @@ gal_view_collection_get_user_directory (GalViewCollection *collection)
{
g_return_val_if_fail (GAL_IS_VIEW_COLLECTION (collection), NULL);
- return collection->local_dir;
+ return collection->priv->user_directory;
}
/**
@@ -312,11 +326,11 @@ gal_view_collection_set_storage_directories (GalViewCollection *collection,
g_return_if_fail (system_dir != NULL);
g_return_if_fail (local_dir != NULL);
- g_free (collection->system_dir);
- g_free (collection->local_dir);
+ g_free (collection->priv->system_directory);
+ g_free (collection->priv->user_directory);
- collection->system_dir = g_strdup (system_dir);
- collection->local_dir = g_strdup (local_dir);
+ collection->priv->system_directory = g_strdup (system_dir);
+ collection->priv->user_directory = g_strdup (local_dir);
g_object_notify (G_OBJECT (collection), "system-directory");
g_object_notify (G_OBJECT (collection), "user-directory");
@@ -340,8 +354,9 @@ gal_view_collection_add_factory (GalViewCollection *collection,
g_return_if_fail (GAL_IS_VIEW_COLLECTION (collection));
g_return_if_fail (GAL_IS_VIEW_FACTORY (factory));
- g_object_ref (factory);
- collection->factory_list = g_list_prepend (collection->factory_list, factory);
+ collection->priv->factory_list = g_list_prepend (
+ collection->priv->factory_list,
+ g_object_ref (factory));
}
static void
@@ -368,7 +383,7 @@ gal_view_collection_real_load_view_from_file (GalViewCollection *collection,
GList *factories;
factory = NULL;
- for (factories = collection->factory_list; factories; factories = factories->next) {
+ for (factories = collection->priv->factory_list; factories; factories = factories->next) {
if (type && !strcmp (gal_view_factory_get_type_code (factories->data), type)) {
factory = factories->data;
break;
@@ -390,12 +405,14 @@ gal_view_collection_load_view_from_file (GalViewCollection *collection,
const gchar *type,
const gchar *filename)
{
- return gal_view_collection_real_load_view_from_file (collection, type, "", collection->local_dir, filename);
+ return gal_view_collection_real_load_view_from_file (
+ collection, type, "",
+ collection->priv->user_directory, filename);
}
static GalViewCollectionItem *
load_single_file (GalViewCollection *collection,
- gchar *dir,
+ const gchar *dir,
gboolean local,
xmlNode *node)
{
@@ -427,7 +444,7 @@ load_single_file (GalViewCollection *collection,
static void
load_single_dir (GalViewCollection *collection,
- gchar *dir,
+ const gchar *dir,
gboolean local)
{
xmlDoc *doc = NULL;
@@ -461,19 +478,19 @@ load_single_dir (GalViewCollection *collection,
continue;
id = e_xml_get_string_prop_by_name (child, (const guchar *)"id");
- for (i = 0; i < collection->view_count; i++) {
- if (!strcmp (id, collection->view_data[i]->id)) {
+ for (i = 0; i < collection->priv->view_count; i++) {
+ if (!strcmp (id, collection->priv->view_data[i]->id)) {
if (!local)
- collection->view_data[i]->built_in = TRUE;
+ collection->priv->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)) {
+ for (i = 0; i < collection->priv->removed_view_count; i++) {
+ if (!strcmp (id, collection->priv->removed_view_data[i]->id)) {
if (!local)
- collection->removed_view_data[i]->built_in = TRUE;
+ collection->priv->removed_view_data[i]->built_in = TRUE;
found = TRUE;
break;
}
@@ -483,13 +500,13 @@ load_single_dir (GalViewCollection *collection,
if (!found) {
GalViewCollectionItem *item = load_single_file (collection, dir, local, child);
if (item->filename && *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++;
+ collection->priv->view_data = g_renew (GalViewCollectionItem *, collection->priv->view_data, collection->priv->view_count + 1);
+ collection->priv->view_data[collection->priv->view_count] = item;
+ collection->priv->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++;
+ collection->priv->removed_view_data = g_renew (GalViewCollectionItem *, collection->priv->removed_view_data, collection->priv->removed_view_count + 1);
+ collection->priv->removed_view_data[collection->priv->removed_view_count] = item;
+ collection->priv->removed_view_count++;
}
}
g_free (id);
@@ -498,11 +515,11 @@ load_single_dir (GalViewCollection *collection,
default_view = e_xml_get_string_prop_by_name (root, (const guchar *)"default-view");
if (default_view) {
if (local)
- collection->default_view_built_in = FALSE;
+ collection->priv->default_view_built_in = FALSE;
else
- collection->default_view_built_in = TRUE;
- g_free (collection->default_view);
- collection->default_view = default_view;
+ collection->priv->default_view_built_in = TRUE;
+ g_free (collection->priv->default_view);
+ collection->priv->default_view = default_view;
}
g_free (filename);
@@ -520,19 +537,25 @@ load_single_dir (GalViewCollection *collection,
void
gal_view_collection_load (GalViewCollection *collection)
{
+ const gchar *user_directory;
+ const gchar *system_directory;
+
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);
+ g_return_if_fail (collection->priv->user_directory != NULL);
+ g_return_if_fail (collection->priv->system_directory != NULL);
+ g_return_if_fail (!collection->priv->loaded);
- if ((g_mkdir_with_parents (collection->local_dir, 0777) == -1) && (errno != EEXIST))
- g_warning ("Unable to create dir %s: %s", collection->local_dir, g_strerror (errno));
+ user_directory = gal_view_collection_get_user_directory (collection);
+ system_directory = gal_view_collection_get_system_directory (collection);
- load_single_dir (collection, collection->local_dir, TRUE);
- load_single_dir (collection, collection->system_dir, FALSE);
+ if ((g_mkdir_with_parents (user_directory, 0777) == -1) && (errno != EEXIST))
+ g_warning ("Unable to create dir %s: %s", user_directory, g_strerror (errno));
+
+ load_single_dir (collection, user_directory, TRUE);
+ load_single_dir (collection, system_directory, FALSE);
gal_view_collection_changed (collection);
- collection->loaded = TRUE;
+ collection->priv->loaded = TRUE;
}
/**
@@ -550,23 +573,26 @@ gal_view_collection_save (GalViewCollection *collection)
xmlDoc *doc;
xmlNode *root;
gchar *filename;
+ const gchar *user_directory;
g_return_if_fail (GAL_IS_VIEW_COLLECTION (collection));
- g_return_if_fail (collection->local_dir != NULL);
+
+ user_directory = gal_view_collection_get_user_directory (collection);
+ g_return_if_fail (user_directory != NULL);
doc = xmlNewDoc ((const guchar *)"1.0");
root = xmlNewNode (NULL, (const guchar *)"GalViewCollection");
xmlDocSetRootElement (doc, root);
- if (collection->default_view && !collection->default_view_built_in) {
- e_xml_set_string_prop_by_name (root, (const guchar *)"default-view", collection->default_view);
+ if (collection->priv->default_view && !collection->priv->default_view_built_in) {
+ e_xml_set_string_prop_by_name (root, (const guchar *)"default-view", collection->priv->default_view);
}
- for (i = 0; i < collection->view_count; i++) {
+ for (i = 0; i < collection->priv->view_count; i++) {
xmlNode *child;
GalViewCollectionItem *item;
- item = collection->view_data[i];
+ item = collection->priv->view_data[i];
if (item->ever_changed) {
child = xmlNewChild (root, NULL, (const guchar *)"GalView", NULL);
e_xml_set_string_prop_by_name (child, (const guchar *)"id", item->id);
@@ -575,24 +601,24 @@ gal_view_collection_save (GalViewCollection *collection)
e_xml_set_string_prop_by_name (child, (const guchar *)"type", item->type);
if (item->changed) {
- filename = g_build_filename (collection->local_dir, item->filename, NULL);
+ filename = g_build_filename (user_directory, item->filename, NULL);
gal_view_save (item->view, filename);
g_free (filename);
}
}
}
- for (i = 0; i < collection->removed_view_count; i++) {
+ for (i = 0; i < collection->priv->removed_view_count; i++) {
xmlNode *child;
GalViewCollectionItem *item;
- item = collection->removed_view_data[i];
+ item = collection->priv->removed_view_data[i];
child = xmlNewChild (root, NULL, (const guchar *)"GalView", NULL);
e_xml_set_string_prop_by_name (child, (const guchar *)"id", item->id);
e_xml_set_string_prop_by_name (child, (const guchar *)"title", item->title);
e_xml_set_string_prop_by_name (child, (const guchar *)"type", item->type);
}
- filename = g_build_filename (collection->local_dir, "galview.xml", NULL);
+ filename = g_build_filename (user_directory, "galview.xml", NULL);
if (e_xml_save_file (filename, doc) == -1)
g_warning ("Unable to save view to %s - %s", filename, g_strerror (errno));
xmlFreeDoc (doc);
@@ -612,7 +638,7 @@ gal_view_collection_get_count (GalViewCollection *collection)
{
g_return_val_if_fail (GAL_IS_VIEW_COLLECTION (collection), -1);
- return collection->view_count;
+ return collection->priv->view_count;
}
/**
@@ -627,10 +653,10 @@ gal_view_collection_get_view (GalViewCollection *collection,
gint n)
{
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 < collection->priv->view_count, NULL);
g_return_val_if_fail (n >= 0, NULL);
- return collection->view_data[n]->view;
+ return collection->priv->view_data[n]->view;
}
/**
@@ -645,10 +671,10 @@ gal_view_collection_get_view_item (GalViewCollection *collection,
gint n)
{
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 < collection->priv->view_count, NULL);
g_return_val_if_fail (n >= 0, NULL);
- return collection->view_data[n];
+ return collection->priv->view_data[n];
}
gint
@@ -660,8 +686,8 @@ gal_view_collection_get_view_index_by_id (GalViewCollection *collection,
g_return_val_if_fail (GAL_IS_VIEW_COLLECTION (collection), -1);
g_return_val_if_fail (view_id != NULL, -1);
- for (ii = 0; ii < collection->view_count; ii++) {
- if (!strcmp (collection->view_data[ii]->id, view_id))
+ for (ii = 0; ii < collection->priv->view_count; ii++) {
+ if (!strcmp (collection->priv->view_data[ii]->id, view_id))
return ii;
}
@@ -675,18 +701,18 @@ gal_view_collection_delete_view (GalViewCollection *collection,
GalViewCollectionItem *item;
g_return_if_fail (GAL_IS_VIEW_COLLECTION (collection));
- g_return_if_fail (i >= 0 && i < collection->view_count);
+ g_return_if_fail (i >= 0 && i < collection->priv->view_count);
- item = collection->view_data[i];
- memmove (collection->view_data + i, collection->view_data + i + 1, (collection->view_count - i - 1) * sizeof (GalViewCollectionItem *));
- collection->view_count--;
+ item = collection->priv->view_data[i];
+ memmove (collection->priv->view_data + i, collection->priv->view_data + i + 1, (collection->priv->view_count - i - 1) * sizeof (GalViewCollectionItem *));
+ collection->priv->view_count--;
if (item->built_in) {
g_free (item->filename);
item->filename = NULL;
- 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++;
+ collection->priv->removed_view_data = g_renew (GalViewCollectionItem *, collection->priv->removed_view_data, collection->priv->removed_view_count + 1);
+ collection->priv->removed_view_data[collection->priv->removed_view_count] = item;
+ collection->priv->removed_view_count++;
} else {
gal_view_collection_item_free (item);
}
@@ -699,7 +725,7 @@ gal_view_collection_loaded (GalViewCollection *collection)
{
g_return_val_if_fail (GAL_IS_VIEW_COLLECTION (collection), FALSE);
- return collection->loaded;
+ return collection->priv->loaded;
}
const gchar *
@@ -733,9 +759,9 @@ gal_view_collection_append_with_title (GalViewCollection *collection,
item->view, "changed",
G_CALLBACK (view_changed), item);
- collection->view_data = g_renew (GalViewCollectionItem *, collection->view_data, collection->view_count + 1);
- collection->view_data[collection->view_count] = item;
- collection->view_count++;
+ collection->priv->view_data = g_renew (GalViewCollectionItem *, collection->priv->view_data, collection->priv->view_count + 1);
+ collection->priv->view_data[collection->priv->view_count] = item;
+ collection->priv->view_count++;
gal_view_collection_changed (collection);
return item->id;
@@ -752,11 +778,11 @@ gal_view_collection_set_nth_view (GalViewCollection *collection,
g_return_val_if_fail (GAL_IS_VIEW_COLLECTION (collection), NULL);
g_return_val_if_fail (GAL_IS_VIEW (view), NULL);
g_return_val_if_fail (i >= 0, NULL);
- g_return_val_if_fail (i < collection->view_count, NULL);
+ g_return_val_if_fail (i < collection->priv->view_count, NULL);
view_class = GAL_VIEW_GET_CLASS (view);
- item = collection->view_data[i];
+ item = collection->priv->view_data[i];
gal_view_set_title (view, item->title);
g_object_ref (view);
@@ -785,6 +811,6 @@ gal_view_collection_get_default_view (GalViewCollection *collection)
{
g_return_val_if_fail (GAL_IS_VIEW_COLLECTION (collection), NULL);
- return collection->default_view;
+ return collection->priv->default_view;
}
diff --git a/e-util/gal-view-collection.h b/e-util/gal-view-collection.h
index 9926e8b810..5cc355410e 100644
--- a/e-util/gal-view-collection.h
+++ b/e-util/gal-view-collection.h
@@ -55,22 +55,6 @@ typedef struct _GalViewCollectionItem GalViewCollectionItem;
struct _GalViewCollection {
GObject parent;
GalViewCollectionPrivate *priv;
-
- GalViewCollectionItem **view_data;
- gint view_count;
-
- GList *factory_list;
-
- GalViewCollectionItem **removed_view_data;
- gint removed_view_count;
-
- gboolean loaded;
- gboolean default_view_built_in;
-
- gchar *system_dir;
- gchar *local_dir;
-
- gchar *default_view;
};
struct _GalViewCollectionClass {
diff --git a/e-util/gal-view-instance-save-as-dialog.c b/e-util/gal-view-instance-save-as-dialog.c
index 54210e39be..a384152d70 100644
--- a/e-util/gal-view-instance-save-as-dialog.c
+++ b/e-util/gal-view-instance-save-as-dialog.c
@@ -48,21 +48,23 @@ static void
gal_view_instance_save_as_dialog_set_instance (GalViewInstanceSaveAsDialog *dialog,
GalViewInstance *instance)
{
- gint i;
GtkListStore *store;
GtkCellRenderer *renderer;
+ gint ii, view_count;
+
dialog->instance = instance;
store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER);
- for (i = 0; i < instance->collection->view_count; i++) {
- GalViewCollectionItem *item = instance->collection->view_data[i];
+ view_count = gal_view_collection_get_count (instance->collection);
+
+ for (ii = 0; ii < view_count; ii++) {
+ GalViewCollectionItem *item;
GtkTreeIter iter;
gchar *title = NULL;
- /* hide built in views */
- /*if (item->built_in == 1)
- continue;*/
+ item = gal_view_collection_get_view_item (
+ instance->collection, ii);
title = e_str_without_underscores (item->title);
@@ -316,9 +318,13 @@ gal_view_instance_save_as_dialog_save (GalViewInstanceSaveAsDialog *dialog)
{
GalView *view = gal_view_instance_get_current_view (dialog->instance);
const gchar *title;
- gint n;
const gchar *id = NULL;
+ GalViewCollection *collection;
GalViewCollectionItem *item;
+ gint ii, view_count;
+
+ collection = dialog->instance->collection;
+ view_count = gal_view_collection_get_count (collection);
view = gal_view_clone (view);
switch (dialog->toggle) {
@@ -331,10 +337,13 @@ gal_view_instance_save_as_dialog_save (GalViewInstanceSaveAsDialog *dialog)
if (gtk_tree_selection_get_selected (selection, &dialog->model, &iter)) {
gtk_tree_model_get (dialog->model, &iter, COL_GALVIEW_DATA, &item, -1);
- for (n = 0; n < dialog->instance->collection->view_count; n++) {
- if (item == dialog->instance->collection->view_data[n]) {
- id = gal_view_collection_set_nth_view (dialog->instance->collection, n, view);
- gal_view_collection_save (dialog->instance->collection);
+ for (ii = 0; ii < view_count; ii++) {
+ GalViewCollectionItem *candidate;
+
+ candidate = gal_view_collection_get_view_item (collection, ii);
+ if (item == candidate) {
+ id = gal_view_collection_set_nth_view (collection, ii, view);
+ gal_view_collection_save (collection);
}
}
}
@@ -345,8 +354,8 @@ gal_view_instance_save_as_dialog_save (GalViewInstanceSaveAsDialog *dialog)
case GAL_VIEW_INSTANCE_SAVE_AS_DIALOG_TOGGLE_CREATE:
if (dialog->entry_create && GTK_IS_ENTRY (dialog->entry_create)) {
title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_create));
- id = gal_view_collection_append_with_title (dialog->instance->collection, title, view);
- gal_view_collection_save (dialog->instance->collection);
+ id = gal_view_collection_append_with_title (collection, title, view);
+ gal_view_collection_save (collection);
}
break;
}