Author: abrander
Date: 2009-12-21 02:34:39 +0100 (Mon, 21 Dec 2009)
New Revision: 2828
Modified:
trunk/src/application.c
trunk/src/application.h
trunk/src/gtk-interface.c
trunk/src/rs-actions.c
trunk/src/rs-library.c
trunk/src/rs-library.h
trunk/src/rs-store.c
trunk/src/rs-store.h
Log:
GObject'ified RSLibrary and added rs_library_get_singleton().
Modified: trunk/src/application.c
===================================================================
--- trunk/src/application.c 2009-12-20 23:56:00 UTC (rev 2827)
+++ trunk/src/application.c 2009-12-21 01:34:39 UTC (rev 2828)
@@ -210,9 +210,6 @@
rs->queue = rs_batch_new_queue();
rs->current_setting = 0;
- /* Create library */
- rs->library = rs_library_new();
-
/* Build basic filter chain */
rs->filter_input = rs_filter_new("RSInputImage16", NULL);
rs->filter_demosaic = rs_filter_new("RSDemosaic", rs->filter_input);
@@ -532,8 +529,6 @@
rs_stock_init();
- rs_library_init(rs->library);
-
#if GTK_CHECK_VERSION(2,10,0)
gtk_link_button_set_uri_hook(runuri,NULL,NULL);
#endif
Modified: trunk/src/application.h
===================================================================
--- trunk/src/application.h 2009-12-20 23:56:00 UTC (rev 2827)
+++ trunk/src/application.h 2009-12-21 01:34:39 UTC (rev 2828)
@@ -53,11 +53,6 @@
gboolean dispose_has_run;
} RS_PHOTO;
-typedef struct
-{
- sqlite3 *db;
-} RS_LIBRARY;
-
typedef struct {
RS_PHOTO *photo;
RSSettings *settings_buffer;
@@ -66,7 +61,6 @@
RS_QUEUE *queue;
RS_CMS *cms;
RSStore *store;
- RS_LIBRARY *library;
/* These should be moved to a future RS_WINDOW */
GtkWidget *window;
Modified: trunk/src/gtk-interface.c
===================================================================
--- trunk/src/gtk-interface.c 2009-12-20 23:56:00 UTC (rev 2827)
+++ trunk/src/gtk-interface.c 2009-12-21 01:34:39 UTC (rev 2828)
@@ -912,7 +912,7 @@
if (g_file_test(abspath, G_FILE_TEST_IS_DIR))
{
rs_store_remove(rs->store, NULL, NULL);
- if (rs_store_load_directory(rs->store, abspath,
rs->library) >= 0)
+ if (rs_store_load_directory(rs->store, abspath) >= 0)
rs_conf_set_string(CONF_LWD, abspath);
}
else if (g_file_test(abspath, G_FILE_TEST_IS_REGULAR))
@@ -920,13 +920,13 @@
lwd = g_path_get_dirname(abspath);
filename = g_path_get_basename(abspath);
rs_store_remove(rs->store, NULL, NULL);
- if (rs_store_load_directory(rs->store, lwd,
rs->library) >= 0)
+ if (rs_store_load_directory(rs->store, lwd) >= 0)
rs_conf_set_string(CONF_LWD, lwd);
rs_store_set_selected_name(rs->store, abspath);
g_free(lwd);
}
else
- rs_store_load_directory(rs->store, NULL, rs->library);
+ rs_store_load_directory(rs->store, NULL);
g_free(abspath);
}
}
@@ -950,7 +950,7 @@
gui_status_push(_("Opening directory..."));
gui_set_busy(TRUE);
GTK_CATCHUP();
- if (rs_store_load_directory(rs->store, path, rs->library) >= 0)
+ if (rs_store_load_directory(rs->store, path) >= 0)
rs_conf_set_string(CONF_LWD, path);
rs_window_set_title(path);
GTK_CATCHUP();
@@ -1045,6 +1045,13 @@
gtk_box_pack_start (GTK_BOX (hbox), valuefield[B], FALSE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (statusbar), TRUE, TRUE,
0);
+ /* Build iconbox */
+ rs->iconbox = rs_store_new();
+ g_signal_connect((gpointer) rs->iconbox, "thumb-activated",
G_CALLBACK(icon_activated), rs);
+ g_signal_connect((gpointer) rs->iconbox, "group-activated",
G_CALLBACK(group_activated), rs);
+
+ rs->store = RS_STORE(rs->iconbox);
+
/* Build toolbox */
rs->tools = tools = rs_toolbox_new();
g_signal_connect(tools, "snapshot-changed",
G_CALLBACK(snapshot_changed), rs);
@@ -1066,7 +1073,7 @@
directory_expander = gui_box(_("Directory"), dir_selector_vbox,
"OPEN_DIRECTORY_EXPANDER", TRUE);
- library_vbox = rs_library_toolbox_new(rs);
+ library_vbox = rs_library_toolbox_new(rs_library_get_singleton(),
rs->store);
library_expander = gui_box(_("Tag search"), library_vbox,
"OPEN_LIBRARY_SEARCH_EXPANDER", TRUE);
gtk_box_pack_start (GTK_BOX(open_box), library_expander, FALSE, TRUE,
0);
@@ -1081,17 +1088,10 @@
infobox = gtk_label_new("");
rs_toolbox_add_widget(RS_TOOLBOX(rs->tools), infobox, NULL);
- /* Build iconbox */
- rs->iconbox = rs_store_new();
- g_signal_connect((gpointer) rs->iconbox, "thumb-activated",
G_CALLBACK(icon_activated), rs);
- g_signal_connect((gpointer) rs->iconbox, "group-activated",
G_CALLBACK(group_activated), rs);
-
/* Catch window state changes (un/fullscreen) */
g_signal_connect((gpointer) rs->window, "window-state-event",
G_CALLBACK(gui_fullscreen_iconbox_callback), rs->iconbox);
g_signal_connect((gpointer) rs->window, "window-state-event",
G_CALLBACK(gui_fullscreen_toolbox_callback), rs->toolbox);
- rs->store = RS_STORE(rs->iconbox);
-
/* Build menubar */
menubar = gui_make_menubar(rs);
@@ -1197,7 +1197,7 @@
GTK_CATCHUP();
gui_status_push(_("Opening directory..."));
- if (rs_store_load_directory(rs->store, lwd, rs->library))
+ if (rs_store_load_directory(rs->store, lwd))
{
gint last_priority_page = 0;
rs_conf_get_integer(CONF_LAST_PRIORITY_PAGE,
&last_priority_page);
Modified: trunk/src/rs-actions.c
===================================================================
--- trunk/src/rs-actions.c 2009-12-20 23:56:00 UTC (rev 2827)
+++ trunk/src/rs-actions.c 2009-12-21 01:34:39 UTC (rev 2828)
@@ -160,7 +160,7 @@
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER
(fc));
gtk_widget_destroy (fc);
rs_store_remove(rs->store, NULL, NULL);
- if (rs_store_load_directory(rs->store, filename, rs->library)
>= 0)
+ if (rs_store_load_directory(rs->store, filename) >= 0)
rs_conf_set_string(CONF_LWD, filename);
g_free (filename);
} else
@@ -247,7 +247,7 @@
ACTION(reload)
{
rs_store_remove(rs->store, NULL, NULL);
- rs_store_load_directory(rs->store, NULL, rs->library);
+ rs_store_load_directory(rs->store, NULL);
}
ACTION(delete_flagged)
@@ -614,6 +614,7 @@
static void tag_photo_input_changed(GtkEntry *entry, gpointer user_data)
{
+ RSLibrary *library = rs_library_get_singleton();
RS_BLOB *rs = user_data;
GList * selected = rs_store_get_selected_names(rs->store);
@@ -628,10 +629,10 @@
for(i = 0; i < g_list_length(tags); i++)
{
gchar *tag = (gchar *) g_list_nth_data(tags, i);
- rs_library_add_tag(rs->library, tag);
+ rs_library_add_tag(library, tag);
for(cur=0;cur<num_selected;cur++)
- rs_library_photo_add_tag(rs->library,
g_list_nth_data(selected, cur), tag, FALSE);
+ rs_library_photo_add_tag(library,
g_list_nth_data(selected, cur), tag, FALSE);
g_free(tag);
}
@@ -647,6 +648,7 @@
ACTION(tag_photo)
{
+ RSLibrary *library = rs_library_get_singleton();
GtkWidget *popup = gtk_window_new(GTK_WINDOW_TOPLEVEL);
GtkWidget *label = gtk_label_new("Tag:");
GtkWidget *input = gtk_entry_new();
@@ -657,7 +659,7 @@
gtk_container_add(GTK_CONTAINER(popup), box);
gtk_widget_show_all(popup);
- GList *tags = rs_library_find_tag(rs->library, "");
+ GList *tags = rs_library_find_tag(library, "");
GtkEntryCompletion *completion = gtk_entry_completion_new();
GtkListStore *store = gtk_list_store_new(1, G_TYPE_STRING);
GtkTreeIter iter;
Modified: trunk/src/rs-library.c
===================================================================
--- trunk/src/rs-library.c 2009-12-20 23:56:00 UTC (rev 2827)
+++ trunk/src/rs-library.c 2009-12-21 01:34:39 UTC (rev 2828)
@@ -35,7 +35,7 @@
* photo
* tag
*/
-
+/*
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
@@ -45,34 +45,105 @@
#include "rs-metadata.h"
#include "rs-library.h"
#include "application.h"
+*/
+
+#include "rs-library.h"
#include "rs-store.h"
+#include "gtk-interface.h"
#include "conf_interface.h"
-#include "gtk-interface.h"
+#include "config.h"
#include "gettext.h"
-void library_sqlite_error(sqlite3 *db, gint result);
-gint library_create_tables(sqlite3 *db);
-gint library_find_tag_id(RS_LIBRARY *library, gchar *tagname);
-gint library_find_photo_id(RS_LIBRARY *library, gchar *photo);
-void library_photo_add_tag(RS_LIBRARY *library, gint photo_id, gint tag_id,
gboolean autotag);
-gboolean library_is_photo_tagged(RS_LIBRARY *library, gint photo_id, gint
tag_id);
-void library_add_photo(RS_LIBRARY *library, gchar *filename);
-void library_add_tag(RS_LIBRARY *library, gchar *tagname);
-void library_delete_photo(RS_LIBRARY *library, gint photo_id);
-void library_delete_tag(RS_LIBRARY *library, gint tag_id);
-void library_photo_delete_tags(RS_LIBRARY *library, gint photo_id);
-void library_tag_delete_photos(RS_LIBRARY *library, gint tag_id);
-gboolean library_tag_is_used(RS_LIBRARY *library, gint tag_id);
+struct _RSLibrary {
+ GObject parent;
+ gboolean dispose_has_run;
-GtkWidget *tag_search_entry = NULL;
+ sqlite3 *db;
+};
-//GList* rs_library_search(GList *tags);
-//void rs_library_add_directory(gchar *directory, gboolean recursive);
+G_DEFINE_TYPE(RSLibrary, rs_library, G_TYPE_OBJECT)
+static void library_sqlite_error(sqlite3 *db, const gint result);
+static gint library_create_tables(sqlite3 *db);
+static gint library_find_tag_id(RSLibrary *library, const gchar *tagname);
+static gint library_find_photo_id(RSLibrary *library, const gchar *photo);
+static void library_photo_add_tag(RSLibrary *library, const gint photo_id,
const gint tag_id, const gboolean autotag);
+static gboolean library_is_photo_tagged(RSLibrary *library, const gint
photo_id, const gint tag_id);
+static void library_add_photo(RSLibrary *library, const gchar *filename);
+static void library_add_tag(RSLibrary *library, const gchar *tagname);
+static void library_delete_photo(RSLibrary *library, const gint photo_id);
+static void library_delete_tag(RSLibrary *library, const gint tag_id);
+static void library_photo_delete_tags(RSLibrary *library, const gint photo_id);
+static void library_tag_delete_photos(RSLibrary *library, const gint tag_id);
+static gboolean library_tag_is_used(RSLibrary *library, const gint tag_id);
-/* BEGIN PRIVATE FUNCTIONS */
+static GtkWidget *tag_search_entry = NULL;
-void
+static void
+rs_library_dispose(GObject *object)
+{
+ RSLibrary *library = RS_LIBRARY(object);
+
+ if (!library->dispose_has_run)
+ {
+ library->dispose_has_run = TRUE;
+
+ sqlite3_close(library->db);
+ }
+
+ G_OBJECT_CLASS(rs_library_parent_class)->dispose (object);
+}
+
+static void
+rs_library_finalize(GObject *object)
+{
+ G_OBJECT_CLASS(rs_library_parent_class)->finalize (object);
+}
+
+static void
+rs_library_class_init(RSLibraryClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+ sqlite3_config(SQLITE_CONFIG_SERIALIZED);
+ object_class->dispose = rs_library_dispose;
+ object_class->finalize = rs_library_finalize;
+}
+
+static void
+rs_library_init(RSLibrary *library)
+{
+ int rc;
+
+ gchar *database = g_strdup_printf("%s/.rawstudio/library.db",
g_get_home_dir());
+
+ /* If unable to create database we exit */
+ if(sqlite3_open(database, &(library->db)))
+ {
+ g_debug("sqlite3 debug: could not open database %s\n",
database);
+ sqlite3_close(library->db);
+ exit(1);
+ }
+ g_free(database);
+
+ rc = library_create_tables(library->db);
+ library_sqlite_error(library->db, rc);
+}
+
+RSLibrary *
+rs_library_get_singleton(void)
+{
+ static GStaticMutex singleton_lock = G_STATIC_MUTEX_INIT;
+ static RSLibrary *singleton = NULL;
+
+ g_static_mutex_lock(&singleton_lock);
+ singleton = g_object_new(RS_TYPE_LIBRARY, NULL);
+ g_static_mutex_unlock(&singleton_lock);
+
+ return singleton;
+}
+
+static void
library_sqlite_error(sqlite3 *db, gint result)
{
if (result != SQLITE_OK)
@@ -81,7 +152,7 @@
}
}
-gint
+static gint
library_create_tables(sqlite3 *db)
{
sqlite3_stmt *stmt;
@@ -105,9 +176,8 @@
return SQLITE_OK;
}
-
-gint
-library_find_tag_id(RS_LIBRARY *library, gchar *tagname)
+static gint
+library_find_tag_id(RSLibrary *library, const gchar *tagname)
{
sqlite3 *db = library->db;
sqlite3_stmt *stmt;
@@ -122,8 +192,8 @@
return tag_id;
}
-gint
-library_find_photo_id(RS_LIBRARY *library, gchar *photo)
+static gint
+library_find_photo_id(RSLibrary *library, const gchar *photo)
{
sqlite3 *db = library->db;
sqlite3_stmt *stmt;
@@ -139,8 +209,8 @@
return photo_id;
}
-void
-library_photo_add_tag(RS_LIBRARY *library, gint photo_id, gint tag_id,
gboolean autotag)
+static void
+library_photo_add_tag(RSLibrary *library, const gint photo_id, const gint
tag_id, const gboolean autotag)
{
sqlite3 *db = library->db;
gint rc;
@@ -160,8 +230,8 @@
sqlite3_finalize(stmt);
}
-gboolean
-library_is_photo_tagged(RS_LIBRARY *library, gint photo_id, gint tag_id)
+static gboolean
+library_is_photo_tagged(RSLibrary *library, gint photo_id, gint tag_id)
{
sqlite3 *db = library->db;
gint rc;
@@ -179,8 +249,8 @@
return FALSE;
}
-void
-library_add_photo(RS_LIBRARY *library, gchar *filename)
+static void
+library_add_photo(RSLibrary *library, const gchar *filename)
{
sqlite3 *db = library->db;
gint rc;
@@ -194,8 +264,8 @@
sqlite3_finalize(stmt);
}
-void
-library_add_tag(RS_LIBRARY *library, gchar *tagname)
+static void
+library_add_tag(RSLibrary *library, const gchar *tagname)
{
sqlite3 *db = library->db;
gint rc;
@@ -209,8 +279,8 @@
sqlite3_finalize(stmt);
}
-void
-library_delete_photo(RS_LIBRARY *library, gint photo_id)
+static void
+library_delete_photo(RSLibrary *library, gint photo_id)
{
sqlite3 *db = library->db;
sqlite3_stmt *stmt;
@@ -225,8 +295,8 @@
rc = sqlite3_finalize(stmt);
}
-void
-library_delete_tag(RS_LIBRARY *library, gint tag_id)
+static void
+library_delete_tag(RSLibrary *library, gint tag_id)
{
sqlite3 *db = library->db;
sqlite3_stmt *stmt;
@@ -241,8 +311,8 @@
rc = sqlite3_finalize(stmt);
}
-void
-library_photo_delete_tags(RS_LIBRARY *library, gint photo_id)
+static void
+library_photo_delete_tags(RSLibrary *library, gint photo_id)
{
sqlite3 *db = library->db;
sqlite3_stmt *stmt;
@@ -257,8 +327,8 @@
rc = sqlite3_finalize(stmt);
}
-void
-library_tag_delete_photos(RS_LIBRARY *library, gint tag_id)
+static void
+library_tag_delete_photos(RSLibrary *library, gint tag_id)
{
sqlite3 *db = library->db;
sqlite3_stmt *stmt;
@@ -273,8 +343,8 @@
rc = sqlite3_finalize(stmt);
}
-gboolean
-library_tag_is_used(RS_LIBRARY *library, gint tag_id)
+static gboolean
+library_tag_is_used(RSLibrary *library, gint tag_id)
{
sqlite3 *db = library->db;
gint rc;
@@ -291,46 +361,11 @@
return FALSE;
}
-/* END PRIVATE FUNCTIONS */
-
-
-/* BEGIN PUBLIC FUNCTIONS */
-
-RS_LIBRARY *
-rs_library_new()
-{
- return g_malloc(sizeof(RS_LIBRARY));
-}
-
void
-rs_library_init(RS_LIBRARY *library)
+rs_library_add_photo(RSLibrary *library, const gchar *filename)
{
- int rc;
+ g_assert(RS_IS_LIBRARY(library));
- gchar *database = g_strdup_printf("%s/.rawstudio/library.db",
g_get_home_dir());
-
- /* If unable to create database we exit */
- if(sqlite3_open(database, &(library->db)))
- {
- g_debug("sqlite3 debug: could not open database %s\n",
database);
- sqlite3_close(library->db);
- exit(1);
- }
- g_free(database);
-
- rc = library_create_tables(library->db);
- library_sqlite_error(library->db, rc);
-}
-
-void
-rs_library_destroy(RS_LIBRARY *library)
-{
- sqlite3_close(library->db);
-}
-
-void
-rs_library_add_photo(RS_LIBRARY *library, gchar *filename)
-{
if (library_find_photo_id(library, filename) == -1)
{
g_debug("Adding photo to library: %s",filename);
@@ -339,8 +374,10 @@
}
void
-rs_library_add_tag(RS_LIBRARY *library, gchar *tagname)
+rs_library_add_tag(RSLibrary *library, const gchar *tagname)
{
+ g_assert(RS_IS_LIBRARY(library));
+
if (library_find_tag_id(library, tagname) == -1)
{
g_debug("Adding tag to tags: %s",tagname);
@@ -350,8 +387,10 @@
}
void
-rs_library_photo_add_tag(RS_LIBRARY *library, gchar *filename, gchar *tagname,
gboolean autotag)
+rs_library_photo_add_tag(RSLibrary *library, const gchar *filename, const
gchar *tagname, const gboolean autotag)
{
+ g_assert(RS_IS_LIBRARY(library));
+
gint photo_id = 0, tag_id;
photo_id = library_find_photo_id(library, filename);
@@ -375,8 +414,10 @@
}
void
-rs_library_delete_photo(RS_LIBRARY *library, gchar *photo)
+rs_library_delete_photo(RSLibrary *library, const gchar *photo)
{
+ g_assert(RS_IS_LIBRARY(library));
+
gint photo_id = -1;
photo_id = library_find_photo_id(library, photo);
@@ -391,8 +432,10 @@
}
gboolean
-rs_library_delete_tag(RS_LIBRARY *library, gchar *tag, gboolean force)
+rs_library_delete_tag(RSLibrary *library, const gchar *tag, const gboolean
force)
{
+ g_assert(RS_IS_LIBRARY(library));
+
gint tag_id = -1;
tag_id = library_find_tag_id(library, tag);
@@ -419,8 +462,10 @@
}
GList *
-rs_library_search(RS_LIBRARY *library, GList *tags)
+rs_library_search(RSLibrary *library, GList *tags)
{
+ g_assert(RS_IS_LIBRARY(library));
+
sqlite3_stmt *stmt;
gint rc;
sqlite3 *db = library->db;
@@ -474,8 +519,10 @@
}
void
-rs_library_photo_default_tags(RS_LIBRARY *library, gchar *photo, RSMetadata
*metadata)
+rs_library_photo_default_tags(RSLibrary *library, const gchar *photo,
RSMetadata *metadata)
{
+ g_assert(RS_IS_LIBRARY(library));
+
GList *tags = NULL;
rs_library_add_photo(library, photo);
@@ -578,8 +625,10 @@
}
GList *
-rs_library_photo_tags(RS_LIBRARY *library, gchar *photo, gboolean autotag)
+rs_library_photo_tags(RSLibrary *library, const gchar *photo, const gboolean
autotag)
{
+ g_assert(RS_IS_LIBRARY(library));
+
sqlite3_stmt *stmt;
gint rc;
sqlite3 *db = library->db;
@@ -603,8 +652,10 @@
}
GList *
-rs_library_find_tag(RS_LIBRARY *library, gchar *tag)
+rs_library_find_tag(RSLibrary *library, const gchar *tag)
{
+ g_assert(RS_IS_LIBRARY(library));
+
sqlite3_stmt *stmt;
gint rc;
sqlite3 *db = library->db;
@@ -624,32 +675,30 @@
return tags;
}
+/* Carrier used for a few callbacks */
+typedef struct {
+ RSLibrary *library;
+ RSStore *store;
+} cb_carrier;
-void
-library_toolbox_search_changed(GtkEntry *entry, gpointer user_data);
-
-void
-list_photos(gpointer data, gpointer user_data) {
- g_debug("%s",(gchar *) data);
-}
-
-void
+static void
load_photos(gpointer data, gpointer user_data) {
- RS_BLOB *rs = user_data;
+ RSStore *store = user_data;
gchar *text = (gchar *) data;
- rs_store_load_file(rs->store, text);
+ /* FIXME: Change this to be signal based at some point */
+ rs_store_load_file(store, text);
g_free(text);
}
-void
+static void
search_changed(GtkEntry *entry, gpointer user_data)
{
- RS_BLOB *rs = user_data;
+ cb_carrier *carrier = user_data;
const gchar *text = gtk_entry_get_text(entry);
GList *tags = rs_split_string(text, " ");
- GList *photos = rs_library_search(rs->library, tags);
+ GList *photos = rs_library_search(carrier->library, tags);
/*
printf("photos: %d\n",g_list_length(photos));
g_list_foreach(photos, list_photos, NULL);
@@ -657,8 +706,8 @@
*/
/* FIXME: deselect all photos in store */
- rs_store_remove(rs->store, NULL, NULL);
- g_list_foreach(photos, load_photos, rs);
+ rs_store_remove(carrier->store, NULL, NULL);
+ g_list_foreach(photos, load_photos, carrier->store);
GString *window_title = g_string_new("");
g_string_printf(window_title, _("Tag search [%s]"), text);
@@ -673,14 +722,21 @@
}
GtkWidget *
-rs_library_toolbox_new(RS_BLOB *rs)
+rs_library_toolbox_new(RSLibrary *library, RSStore *store)
{
+ g_assert(RS_IS_LIBRARY(library));
+ g_assert(RS_IS_STORE(store));
+
+ cb_carrier *carrier = g_new(cb_carrier, 1);
GtkWidget *box = gtk_vbox_new(FALSE, 0);
tag_search_entry = gtk_entry_new();
+ carrier->library = library;
+ carrier->store = store;
g_signal_connect (tag_search_entry, "changed",
- G_CALLBACK (search_changed), rs);
+ G_CALLBACK (search_changed), carrier);
gtk_box_pack_start (GTK_BOX(box), tag_search_entry, FALSE, TRUE, 0);
+ /* FIXME: Make sure to free carrier at some point */
return box;
}
@@ -693,5 +749,3 @@
gtk_entry_set_text(GTK_ENTRY(tag_search_entry), str);
return TRUE;
}
-
-/* END PUBLIC FUNCTIONS */
Modified: trunk/src/rs-library.h
===================================================================
--- trunk/src/rs-library.h 2009-12-20 23:56:00 UTC (rev 2827)
+++ trunk/src/rs-library.h 2009-12-21 01:34:39 UTC (rev 2828)
@@ -20,29 +20,42 @@
#ifndef RS_LIBRARY_H
#define RS_LIBRARY_H
+#include <glib-object.h>
#include <glib.h>
#include <gtk/gtk.h>
+#include "application.h"
#include <rawstudio.h>
-#include "sqlite3.h"
-#include "application.h"
-RS_LIBRARY * rs_library_new();
-void rs_library_init(RS_LIBRARY *library);
-void rs_library_destroy(RS_LIBRARY *library);
-void rs_library_add_photo(RS_LIBRARY *library, gchar *filename);
-void rs_library_add_tag(RS_LIBRARY *library, gchar *tagname);
-void rs_library_photo_add_tag(RS_LIBRARY *library, gchar *filename, gchar
*tagname, gboolean autotag);
-void rs_library_delete_photo(RS_LIBRARY *library, gchar *photo);
-gboolean rs_library_delete_tag(RS_LIBRARY *library, gchar *tag, gboolean
force);
-GList * rs_library_search(RS_LIBRARY *library, GList *tags);
-void rs_library_photo_default_tags(RS_LIBRARY *library, gchar *photo,
RSMetadata *metadata);
-GList * rs_library_photo_tags(RS_LIBRARY *library, gchar *photo, gboolean
autotag);
-GList * rs_library_find_tag(RS_LIBRARY *library, gchar *tag);
-GtkWidget * rs_library_toolbox_new(RS_BLOB *rs);
+G_BEGIN_DECLS
+
+#define RS_TYPE_LIBRARY rs_library_get_type()
+#define RS_LIBRARY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RS_TYPE_LIBRARY,
RSLibrary))
+#define RS_LIBRARY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
RS_TYPE_LIBRARY, RSLibraryClass))
+#define RS_IS_LIBRARY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
RS_TYPE_LIBRARY))
+#define RS_IS_LIBRARY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
RS_TYPE_LIBRARY))
+#define RS_LIBRARY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
RS_TYPE_LIBRARY, RSLibraryClass))
+
+typedef struct _RSLibrary RSLibrary;
+
+typedef struct {
+ GObjectClass parent_class;
+} RSLibraryClass;
+
+GType rs_library_get_type(void);
+
+RSLibrary *rs_library_get_singleton(void);
+void rs_library_add_photo(RSLibrary *library, const gchar *filename);
+void rs_library_add_tag(RSLibrary *library, const gchar *tagname);
+void rs_library_photo_add_tag(RSLibrary *library, const gchar *filename, const
gchar *tagname, const gboolean autotag);
+void rs_library_delete_photo(RSLibrary *library, const gchar *photo);
+gboolean rs_library_delete_tag(RSLibrary *library, const gchar *tag, const
gboolean force);
+GList *rs_library_search(RSLibrary *library, GList *tags);
+void rs_library_photo_default_tags(RSLibrary *library, const gchar *photo,
RSMetadata *metadata);
+GList *rs_library_photo_tags(RSLibrary *library, const gchar *photo, const
gboolean autotag);
+GList *rs_library_find_tag(RSLibrary *library, const gchar *tag);
+GtkWidget *rs_library_toolbox_new(RSLibrary *library, RSStore *store);
gboolean rs_library_set_tag_search(gchar *str);
-//void rs_library_delete_tag(gchar *filename, gchar *tag);
-//void rs_library_find_tags(gchar *filename);
-//void rs_library_find_photos(gchar *tag);
+G_END_DECLS
#endif /* RS_LIBRARY_H */
Modified: trunk/src/rs-store.c
===================================================================
--- trunk/src/rs-store.c 2009-12-20 23:56:00 UTC (rev 2827)
+++ trunk/src/rs-store.c 2009-12-21 01:34:39 UTC (rev 2828)
@@ -516,12 +516,10 @@
-1);
GTimer *gt = g_timer_new();
- RS_LIBRARY *library =
g_malloc(sizeof(RS_LIBRARY *));
- rs_library_init(library);
+ RSLibrary *library = rs_library_get_singleton();
gboolean autotag;
rs_conf_get_boolean_with_default(CONF_LIBRARY_AUTOTAG, &autotag,
DEFAULT_CONF_LIBRARY_AUTOTAG);
GList *tags = rs_library_photo_tags(library,
filename, autotag);
- rs_library_destroy(library);
printf("time: %f\n",g_timer_elapsed(gt, NULL));
if (metadata) switch(type)
@@ -1076,7 +1074,7 @@
}
static gint
-load_directory(RSStore *store, const gchar *path, RS_LIBRARY *library, const
gboolean load_8bit, const gboolean load_recursive)
+load_directory(RSStore *store, const gchar *path, RSLibrary *library, const
gboolean load_8bit, const gboolean load_recursive)
{
const gchar *name;
gchar *fullname;
@@ -1176,8 +1174,9 @@
* @return The number of files loaded or -1
*/
gint
-rs_store_load_directory(RSStore *store, const gchar *path, RS_LIBRARY *library)
+rs_store_load_directory(RSStore *store, const gchar *path)
{
+ RSLibrary *library = rs_library_get_singleton();
static gboolean running = FALSE;
GStaticMutex lock = G_STATIC_MUTEX_INIT;
Modified: trunk/src/rs-store.h
===================================================================
--- trunk/src/rs-store.h 2009-12-20 23:56:00 UTC (rev 2827)
+++ trunk/src/rs-store.h 2009-12-21 01:34:39 UTC (rev 2828)
@@ -61,7 +61,7 @@
* @return The number of files loaded or -1
*/
extern gint
-rs_store_load_directory(RSStore *store, const gchar *path, RS_LIBRARY
*library);
+rs_store_load_directory(RSStore *store, const gchar *path);
/**
* Set priority and exported flags of a thumbnail
_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit