Author: abrander
Date: 2010-01-27 17:50:02 +0100 (Wed, 27 Jan 2010)
New Revision: 3095

Modified:
   branches/rawstudio-ng-color/librawstudio/rs-profile-factory.c
   branches/rawstudio-ng-color/librawstudio/rs-profile-factory.h
   branches/rawstudio-ng-color/librawstudio/rs-profile-selector.c
   branches/rawstudio-ng-color/librawstudio/rs-profile-selector.h
Log:
Enabled RSProfileFactory and RSProfileSelector to share their stores and models.

Modified: branches/rawstudio-ng-color/librawstudio/rs-profile-factory.c
===================================================================
--- branches/rawstudio-ng-color/librawstudio/rs-profile-factory.c       
2010-01-27 15:43:09 UTC (rev 3094)
+++ branches/rawstudio-ng-color/librawstudio/rs-profile-factory.c       
2010-01-27 16:50:02 UTC (rev 3095)
@@ -126,6 +126,34 @@
        return matches;
 }
 
+static gboolean
+visible_func(GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
+{
+       gboolean visible = FALSE;
+
+       gchar *model_needle = (gchar *) data;
+       gchar *model_haystack;
+
+       gtk_tree_model_get(model, iter, FACTORY_MODEL_COLUMN_MODEL, 
&model_haystack, -1);
+
+       if (g_strcmp0(model_needle, model_haystack) == 0)
+           visible = TRUE;
+
+       return visible;
+}
+
+GtkTreeModelFilter *
+rs_dcp_factory_get_compatible_as_model(RSProfileFactory *factory, const gchar 
*make, const gchar *model)
+{
+       g_assert(RS_IS_PROFILE_FACTORY(factory));
+
+       GtkTreeModelFilter *filter = 
GTK_TREE_MODEL_FILTER(gtk_tree_model_filter_new(GTK_TREE_MODEL(factory->profiles),
 NULL));
+
+       gtk_tree_model_filter_set_visible_func(filter, visible_func, 
g_strdup(model), g_free);
+
+       return filter;
+}
+
 RSDcpFile *
 rs_profile_factory_find_from_id(RSProfileFactory *factory, const gchar *id)
 {

Modified: branches/rawstudio-ng-color/librawstudio/rs-profile-factory.h
===================================================================
--- branches/rawstudio-ng-color/librawstudio/rs-profile-factory.h       
2010-01-27 15:43:09 UTC (rev 3094)
+++ branches/rawstudio-ng-color/librawstudio/rs-profile-factory.h       
2010-01-27 16:50:02 UTC (rev 3095)
@@ -33,6 +33,8 @@
 
 GList *rs_profile_factory_get_compatible(RSProfileFactory *factory, const 
gchar *make, const gchar *model);
 
+GtkTreeModelFilter *rs_dcp_factory_get_compatible_as_model(RSProfileFactory 
*factory, const gchar *make, const gchar *model);
+
 RSDcpFile *rs_profile_factory_find_from_id(RSProfileFactory *factory, const 
gchar *path);
 
 G_END_DECLS

Modified: branches/rawstudio-ng-color/librawstudio/rs-profile-selector.c
===================================================================
--- branches/rawstudio-ng-color/librawstudio/rs-profile-selector.c      
2010-01-27 15:43:09 UTC (rev 3094)
+++ branches/rawstudio-ng-color/librawstudio/rs-profile-selector.c      
2010-01-27 16:50:02 UTC (rev 3095)
@@ -1,5 +1,6 @@
 #include "rs-profile-selector.h"
 #include "rs-icc-profile.h"
+#include "rs-profile-factory-model.h"
 
 G_DEFINE_TYPE(RSProfileSelector, rs_profile_selector, GTK_TYPE_COMBO_BOX)
 
@@ -17,6 +18,12 @@
        NUM_COLUMNS
 };
 
+/* We use these for sorting */
+enum {
+       SELECTOR_TYPE_DCP,
+       SELECTOR_TYPE_ICC
+};
+
 static void
 rs_profile_selector_dispose(GObject *object)
 {
@@ -59,23 +66,27 @@
 static void
 changed(GtkComboBox *combo, gpointer data)
 {
-       GtkTreeIter iter;
-       GType type;
+       GtkTreeIter iter, child_iter;
+       gint type;
        gpointer profile;
-       GtkTreeModel *model;
+       GtkTreeModel *model, *child_model;
 
        if (gtk_combo_box_get_active_iter(combo, &iter))
        {
                model = gtk_combo_box_get_model(combo);
 
-               gtk_tree_model_get(model, &iter,
+               /* Find the original iter before sorting */
+               
gtk_tree_model_sort_convert_iter_to_child_iter(GTK_TREE_MODEL_SORT(model), 
&child_iter, &iter);
+               child_model = 
gtk_tree_model_sort_get_model(GTK_TREE_MODEL_SORT(model));
+
+               gtk_tree_model_get(child_model, &child_iter,
                        COLUMN_POINTER, &profile,
                        COLUMN_TYPE, &type,
                        -1);
 
-               if (type == RS_TYPE_DCP_FILE)
+               if (type == SELECTOR_TYPE_DCP)
                        g_signal_emit(RS_PROFILE_SELECTOR(combo), 
signals[DCP_SELECTED_SIGNAL], 0, profile);
-               else if (type == RS_TYPE_ICC_PROFILE)
+               else if (type == SELECTOR_TYPE_ICC)
                        g_signal_emit(RS_PROFILE_SELECTOR(combo), 
signals[ICC_SELECTED_SIGNAL], 0, profile);
        }
 }
@@ -85,12 +96,8 @@
 {
        GtkComboBox *combo = GTK_COMBO_BOX(selector);
 
-       selector->store = gtk_list_store_new(NUM_COLUMNS, G_TYPE_STRING, 
G_TYPE_POINTER, G_TYPE_GTYPE);
-
        g_signal_connect(combo, "changed", G_CALLBACK(changed), NULL);
 
-       gtk_combo_box_set_model(combo, GTK_TREE_MODEL(selector->store));
-
        GtkCellRenderer *cell = gtk_cell_renderer_text_new();
        gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE );
        gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
@@ -113,7 +120,7 @@
 
        g_assert(RS_IS_PROFILE_SELECTOR(selector));
 
-       model = GTK_TREE_MODEL(selector->store);
+       model = gtk_combo_box_get_model(GTK_COMBO_BOX(selector));
 
        if (gtk_tree_model_get_iter_first(model, &iter))
                do {
@@ -128,41 +135,106 @@
                } while (gtk_tree_model_iter_next(model, &iter));
 }
 
-void
-rs_profile_selector_set_dcp_profile(RSProfileSelector *selector, RSDcpFile 
*dcp)
+static void
+modify_func(GtkTreeModel *filter, GtkTreeIter *iter, GValue *value, gint 
column, gpointer data)
 {
-       GtkTreeIter iter;
+       GtkTreeModel *model; 
+       GtkTreeIter child_iter;
 
-       g_assert(RS_IS_PROFILE_SELECTOR(selector));
-       g_assert(RS_IS_DCP_FILE(dcp));
+       gpointer profile;
 
-       gtk_list_store_append(selector->store, &iter);
-       gtk_list_store_set(selector->store, &iter,
-               COLUMN_NAME, rs_dcp_file_get_name(dcp),
-               COLUMN_POINTER, dcp,
-               COLUMN_TYPE, RS_TYPE_DCP_FILE,
-               -1);
+       g_object_get(filter, "child-model", &model, NULL);
+       
gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(filter), 
&child_iter, iter);
+       gtk_tree_model_get(model, &child_iter, FACTORY_MODEL_COLUMN_PROFILE, 
&profile, -1 );
+
+       if (RS_IS_DCP_FILE(profile))
+       {
+               switch (column)
+               {
+                       case COLUMN_POINTER:
+                               g_value_set_pointer(value, profile);
+                               break;
+                       case COLUMN_NAME:
+                               g_value_set_string(value, 
rs_dcp_file_get_name(profile));
+                               break;
+                       case COLUMN_TYPE:
+                               g_value_set_int(value, SELECTOR_TYPE_DCP);
+                               break;
+               }
+       }
+       else if (RS_IS_ICC_PROFILE(profile))
+       {
+               switch (column)
+               {
+                       case COLUMN_POINTER:
+                               g_value_set_pointer(value, profile);
+                               break;
+                       case COLUMN_NAME:
+                               g_value_set_string(value, "ICC FIXME");
+                               break;
+                       case COLUMN_TYPE:
+                               g_value_set_int(value, SELECTOR_TYPE_ICC);
+                               break;
+               }
+       }
 }
 
-void
-rs_profile_selector_set_profiles(RSProfileSelector *selector, GList *profiles)
+static gint
+sort_func(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer 
user_data)
 {
-       GList *node;
-       g_assert(RS_IS_PROFILE_SELECTOR(selector));
+       gint a_type, b_type;
+       gchar *a_name, *b_name;
 
-       gtk_list_store_clear(selector->store);
 
-       for (node=g_list_first(profiles) ; node!=NULL ; node = 
g_list_next(node))
-       {
-               if (RS_IS_DCP_FILE(node->data))
-                       rs_profile_selector_set_dcp_profile(selector, 
node->data);
-               /* FIXME: Add support for ICC profiles */
-       }
+       /* You never know */
+       if (a == b) return 0;
+       if (!a) return 1;
+       if (!b) return -1;
+
+       gtk_tree_model_get(model, a,
+               COLUMN_TYPE, &a_type,
+               -1);
+       gtk_tree_model_get(model, b,
+               COLUMN_TYPE, &b_type,
+               -1);
+
+       if (a_type < b_type)
+               return -1;
+       else if (a_type > b_type)
+               return 1;
+
+       /* If we get here, both a and b have same type, sort by name */
+
+       gtk_tree_model_get(model, a,
+               COLUMN_NAME, &a_name,
+               -1);
+
+       gtk_tree_model_get(model, b,
+               COLUMN_NAME, &b_name,
+               -1);
+
+       gint ret = g_strcmp0(a_name, b_name);
+
+       g_free(a_name);
+       g_free(b_name);
+
+       return ret;
 }
 
 void
-rs_profile_selector_set_profiles_steal(RSProfileSelector *selector, GList 
*profiles)
+rs_profile_selector_set_model_filter(RSProfileSelector *selector, 
GtkTreeModelFilter *filter)
 {
-       rs_profile_selector_set_profiles(selector, profiles);
+       g_assert(RS_IS_PROFILE_SELECTOR(selector));
+       g_assert(GTK_IS_TREE_MODEL_FILTER(filter));
 
+       /* We set up a modify function, to write correct names for the combobox 
*/
+       GType types[NUM_COLUMNS] = {G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_INT};
+       gtk_tree_model_filter_set_modify_func(filter, NUM_COLUMNS, types, 
modify_func, NULL, NULL);
+
+       /* ort the damn thing, we do it this late to avoid sorting the complete 
list */
+       GtkTreeSortable *sortable = 
GTK_TREE_SORTABLE(gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(filter)));
+       gtk_tree_sortable_set_default_sort_func(sortable, sort_func, NULL, 
NULL);
+       gtk_tree_sortable_set_sort_column_id(sortable, 
GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
+
+       gtk_combo_box_set_model(GTK_COMBO_BOX(selector), 
GTK_TREE_MODEL(sortable));
 }

Modified: branches/rawstudio-ng-color/librawstudio/rs-profile-selector.h
===================================================================
--- branches/rawstudio-ng-color/librawstudio/rs-profile-selector.h      
2010-01-27 15:43:09 UTC (rev 3094)
+++ branches/rawstudio-ng-color/librawstudio/rs-profile-selector.h      
2010-01-27 16:50:02 UTC (rev 3095)
@@ -16,8 +16,6 @@
 
 typedef struct {
        GtkComboBox parent;
-
-       GtkListStore *store;
 } RSProfileSelector;
 
 typedef struct {


_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit

Reply via email to