Author: abrander
Date: 2009-12-31 02:38:03 +0100 (Thu, 31 Dec 2009)
New Revision: 2938
Added:
branches/rawstudio-ng-color/librawstudio/rs-dcp-factory.c
branches/rawstudio-ng-color/librawstudio/rs-dcp-factory.h
Modified:
branches/rawstudio-ng-color/librawstudio/rawstudio.h
Log:
Added RSDcpFactory.
Modified: branches/rawstudio-ng-color/librawstudio/rawstudio.h
===================================================================
--- branches/rawstudio-ng-color/librawstudio/rawstudio.h 2009-12-31
01:28:52 UTC (rev 2937)
+++ branches/rawstudio-ng-color/librawstudio/rawstudio.h 2009-12-31
01:38:03 UTC (rev 2938)
@@ -64,6 +64,7 @@
#include "rs-tiff.h"
#include "rs-huesat-map.h"
#include "rs-dcp-file.h"
+#include "rs-dcp-factory.h"
#include "x86-cpu.h"
Added: branches/rawstudio-ng-color/librawstudio/rs-dcp-factory.c
===================================================================
--- branches/rawstudio-ng-color/librawstudio/rs-dcp-factory.c
(rev 0)
+++ branches/rawstudio-ng-color/librawstudio/rs-dcp-factory.c 2009-12-31
01:38:03 UTC (rev 2938)
@@ -0,0 +1,117 @@
+#include "rs-dcp-file.h"
+#include "rs-dcp-factory.h"
+#include "config.h"
+
+#define DCP_FACTORY_DEFAULT_SEARCH_PATH PACKAGE_DATA_DIR "/" PACKAGE
"/profiles/"
+
+struct _RSDcpFactory {
+ GObject parent;
+
+ GList *profiles;
+};
+
+G_DEFINE_TYPE(RSDcpFactory, rs_dcp_factory, G_TYPE_OBJECT)
+
+static void
+rs_dcp_factory_class_init(RSDcpFactoryClass *klass)
+{
+}
+
+static void
+rs_dcp_factory_init(RSDcpFactory *factory)
+{
+ factory->profiles = NULL;
+}
+
+static void
+load_profiles(RSDcpFactory *factory, const gchar *path)
+{
+ const gchar *basename;
+ gchar *filename;
+ GDir *dir = g_dir_open(path, 0, NULL);
+
+ while((dir != NULL) && (basename = g_dir_read_name(dir)))
+ {
+ if (basename[0] == '.')
+ continue;
+
+ filename = g_build_filename(path, basename, NULL);
+
+ if (g_file_test(filename, G_FILE_TEST_IS_DIR))
+ load_profiles(factory, filename);
+
+ else if (g_file_test(filename, G_FILE_TEST_IS_REGULAR)
+ && (g_str_has_suffix(basename, ".dcp") ||
g_str_has_suffix(basename, ".DCP")))
+ {
+ RSDcpFile *dcp = rs_dcp_file_new_from_file(filename);
+ const gchar *model = rs_dcp_file_get_model(dcp);
+ if (model)
+ {
+ factory->profiles =
g_list_prepend(factory->profiles, dcp);
+ }
+ }
+
+ g_free(filename);
+ }
+
+}
+
+RSDcpFactory *
+rs_dcp_factory_new(const gchar *search_path)
+{
+ RSDcpFactory *factory = g_object_new(RS_TYPE_DCP_FACTORY, NULL);
+
+ load_profiles(factory, search_path);
+
+ return factory;
+}
+
+RSDcpFactory *
+rs_dcp_factory_new_default(void)
+{
+ static RSDcpFactory *factory = NULL;
+ GStaticMutex lock = G_STATIC_MUTEX_INIT;
+
+ g_static_mutex_lock(&lock);
+ if (!factory)
+ {
+ factory = rs_dcp_factory_new(DCP_FACTORY_DEFAULT_SEARCH_PATH);
+ }
+ g_static_mutex_unlock(&lock);
+
+ return factory;
+}
+
+GList *
+rs_dcp_factory_get_compatible(RSDcpFactory *factory, const gchar *make, const
gchar *model)
+{
+ GList *matches = NULL;
+ GList *node;
+
+ for (node = g_list_first(factory->profiles) ; node != NULL ; node =
g_list_next(node))
+ {
+ RSDcpFile *dcp = RS_DCP_FILE(node->data);
+
+ if (g_str_equal(model, rs_dcp_file_get_model(dcp)))
+ matches = g_list_prepend(matches, dcp);
+ }
+
+ return matches;
+}
+
+RSDcpFile *
+rs_dcp_factory_find_from_path(RSDcpFactory *factory, const gchar *path)
+{
+ RSDcpFile *ret = NULL;
+ GList *node;
+
+ for (node = g_list_first(factory->profiles) ; node != NULL ; node =
g_list_next(node))
+ {
+ RSDcpFile *dcp = RS_DCP_FILE(node->data);
+
+ if (g_str_equal(path, rs_tiff_get_filename(RS_TIFF(dcp))))
+ ret = dcp;
+ }
+
+ return ret;
+}
Added: branches/rawstudio-ng-color/librawstudio/rs-dcp-factory.h
===================================================================
--- branches/rawstudio-ng-color/librawstudio/rs-dcp-factory.h
(rev 0)
+++ branches/rawstudio-ng-color/librawstudio/rs-dcp-factory.h 2009-12-31
01:38:03 UTC (rev 2938)
@@ -0,0 +1,39 @@
+#ifndef RS_DCP_FACTORY_H
+#define RS_DCP_FACTORY_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define RS_TYPE_DCP_FACTORY rs_dcp_factory_get_type()
+#define RS_DCP_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
RS_TYPE_DCP_FACTORY, RSDcpFactory))
+#define RS_DCP_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
RS_TYPE_DCP_FACTORY, RSDcpFactoryClass))
+#define RS_IS_DCP_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
RS_TYPE_DCP_FACTORY))
+#define RS_IS_DCP_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
RS_TYPE_DCP_FACTORY))
+#define RS_DCP_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
RS_TYPE_DCP_FACTORY, RSDcpFactoryClass))
+
+enum {
+ RS_DCP_FACTORY_STORE_MODEL,
+ RS_DCP_FACTORY_STORE_DCP,
+ RS_DCP_FACTORY_NUM_FIELDS
+};
+
+typedef struct _RSDcpFactory RSDcpFactory;
+
+typedef struct {
+ GObjectClass parent_class;
+} RSDcpFactoryClass;
+
+GType rs_dcp_factory_get_type(void);
+
+RSDcpFactory *rs_dcp_factory_new(const gchar *search_path);
+
+RSDcpFactory *rs_dcp_factory_new_default(void);
+
+GList *rs_dcp_factory_get_compatible(RSDcpFactory *factory, const gchar *make,
const gchar *model);
+
+RSDcpFile *rs_dcp_factory_find_from_path(RSDcpFactory *factory, const gchar
*path);
+
+G_END_DECLS
+
+#endif /* RS_DCP_FACTORY_H */
_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit