#include "db.h"
#include "ctb_log.h"
Go to the source code of this file.
Functions | |
erMetadb | get_database () |
int | open_global_database (const gchar *directory) |
void | close_database () |
int | db_query_create (int column1,...) |
static const gchar * | get_sort_order_name (int sort_order, gboolean show_filenames) |
int | db_query_execute (int sort_order, gboolean sort_asc, metadata_table **values, const gchar *tag_filter) |
int | db_query_execute_recent (metadata_table **values, int limit) |
int | db_query_execute_search_filter (int sort_order, gboolean sort_asc, metadata_table **values, const gchar *search_filter) |
int | db_query_execute_path_filter (int sort_order, gboolean sort_asc, metadata_table **values, const gchar *path_filter, gboolean show_filenames) |
int | db_query_get_metadata (const gchar *filename, const gchar *dirpath, metadata_table **values) |
int | db_query_update_lastread (const GString *filename, const GString *directory, int value) |
Variables | |
static const char * | MDB_COLUMN_NAMES [] |
static const int | SORT_COLUMN_NAME_IDX [N_CTB_SORT_ORDER] |
static const int | MAX_WAIT_DATABASE = 30 |
static erMetadb | g_metadb = NULL |
metadata_table * | g_query_names = NULL |
gboolean | g_query_in_progress = FALSE |
void close_database | ( | ) |
Definition at line 98 of file ctb/src/db.c.
References ermetadb_close(), and g_metadb.
Referenced by do_example_db_actions(), filemodel_chdir(), filemodel_quit(), and open_global_database().
00099 { 00100 if (g_metadb) 00101 { 00102 ermetadb_close(g_metadb); 00103 g_metadb = NULL; 00104 } 00105 }
int db_query_create | ( | int | column1, | |
... | ||||
) |
Definition at line 108 of file ctb/src/db.c.
References ER_FAIL, ER_OK, g_query_in_progress, MDB_COLUMN_NAMES, metadata_table_add_column(), metadata_table_free, metadata_table_new(), and WARNPRINTF.
Referenced by create_query().
00109 { 00110 va_list ap; 00111 int col; 00112 00113 if (g_query_in_progress) 00114 { 00115 WARNPRINTF("trying to start a new query mid-query"); 00116 if (g_query_names) 00117 metadata_table_free(g_query_names); 00118 } 00119 00120 g_query_in_progress = TRUE; 00121 g_query_names = metadata_table_new(); 00122 if (!g_query_names) 00123 return ER_FAIL; 00124 00125 va_start(ap, column1); 00126 for (col = column1; col!=-1; col = va_arg(ap, int)) 00127 { 00128 int rc = metadata_table_add_column(g_query_names, MDB_COLUMN_NAMES[col]); 00129 if (rc!=ER_OK) 00130 { 00131 va_end(ap); 00132 return rc; 00133 } 00134 } 00135 va_end(ap); 00136 return ER_OK; 00137 }
int db_query_execute | ( | int | sort_order, | |
gboolean | sort_asc, | |||
metadata_table ** | values, | |||
const gchar * | tag_filter | |||
) |
Definition at line 148 of file ctb/src/db.c.
References ermetadb_global_select_files(), g_metadb, g_query_in_progress, get_sort_order_name(), and metadata_table_free.
Referenced by load_dir_from_metadb().
00152 { 00153 int rc = ermetadb_global_select_files( g_metadb, 00154 get_sort_order_name(sort_order, FALSE), 00155 sort_asc, 00156 g_query_names, 00157 values, 00158 tag_filter ); 00159 metadata_table_free(g_query_names); 00160 g_query_in_progress = FALSE; 00161 return rc; 00162 }
int db_query_execute_path_filter | ( | int | sort_order, | |
gboolean | sort_asc, | |||
metadata_table ** | values, | |||
const gchar * | path_filter, | |||
gboolean | show_filenames | |||
) |
Definition at line 195 of file ctb/src/db.c.
References ermetadb_global_select_subdir(), g_metadb, g_query_in_progress, get_sort_order_name(), and metadata_table_free.
Referenced by load_dir_from_metadb().
00200 { 00201 int rc = ermetadb_global_select_subdir( g_metadb, 00202 get_sort_order_name(sort_order, show_filenames), 00203 sort_asc, 00204 g_query_names, 00205 values, 00206 path_filter); 00207 metadata_table_free(g_query_names); 00208 g_query_in_progress = FALSE; 00209 return rc; 00210 }
int db_query_execute_recent | ( | metadata_table ** | values, | |
int | limit | |||
) |
Definition at line 165 of file ctb/src/db.c.
References CTB_SORT_BY_DATE_ADDED, ermetadb_global_select_recent(), g_metadb, g_query_in_progress, get_sort_order_name(), and metadata_table_free.
Referenced by load_dir_from_metadb().
00166 { 00167 int rc = ermetadb_global_select_recent( g_metadb, 00168 get_sort_order_name(CTB_SORT_BY_DATE_ADDED, FALSE), 00169 limit, 00170 g_query_names, 00171 values); 00172 metadata_table_free(g_query_names); 00173 g_query_in_progress = FALSE; 00174 return rc; 00175 }
int db_query_execute_search_filter | ( | int | sort_order, | |
gboolean | sort_asc, | |||
metadata_table ** | values, | |||
const gchar * | search_filter | |||
) |
Definition at line 178 of file ctb/src/db.c.
References ermetadb_global_select_search(), g_metadb, g_query_in_progress, get_sort_order_name(), and metadata_table_free.
Referenced by load_dir_from_metadb().
00182 { 00183 int rc = ermetadb_global_select_search( g_metadb, 00184 get_sort_order_name(sort_order, FALSE), 00185 sort_asc, 00186 g_query_names, 00187 values, 00188 search_filter); 00189 metadata_table_free(g_query_names); 00190 g_query_in_progress = FALSE; 00191 return rc; 00192 }
int db_query_get_metadata | ( | const gchar * | filename, | |
const gchar * | dirpath, | |||
metadata_table ** | values | |||
) |
Definition at line 213 of file ctb/src/db.c.
References ermetadb_global_get_file(), g_metadb, g_query_in_progress, and metadata_table_free.
00216 { 00217 int rc = ermetadb_global_get_file( g_metadb, 00218 dirpath, 00219 filename, 00220 g_query_names, 00221 values); 00222 metadata_table_free(g_query_names); 00223 g_query_in_progress = FALSE; 00224 return rc; 00225 }
int db_query_update_lastread | ( | const GString * | filename, | |
const GString * | directory, | |||
int | value | |||
) |
Definition at line 228 of file ctb/src/db.c.
References COL_FILETIME_LASTREAD, ER_OK, ermetadb_global_change_file(), g_metadb, MDB_COLUMN_NAMES, metadata_table_add_column(), metadata_table_free, metadata_table_new(), and metadata_table_set_int64().
00229 { 00230 metadata_table *query = metadata_table_new(); 00231 00232 int rc = metadata_table_add_column(query, MDB_COLUMN_NAMES[COL_FILETIME_LASTREAD]); 00233 if (rc == ER_OK) rc = metadata_table_set_int64(query, 0, value); 00234 if (rc == ER_OK) rc = ermetadb_global_change_file(g_metadb, 00235 directory->str, 00236 filename->str, 00237 query); 00238 metadata_table_free(query); 00239 return rc; 00240 }
erMetadb get_database | ( | ) |
Definition at line 75 of file ctb/src/db.c.
References g_metadb.
Referenced by filemodel_get_database().
00076 { 00077 return g_metadb; 00078 }
static const gchar* get_sort_order_name | ( | int | sort_order, | |
gboolean | show_filenames | |||
) | [static] |
Definition at line 140 of file ctb/src/db.c.
References COL_FILENAME, CTB_SORT_BY_NAME, MDB_COLUMN_NAMES, and SORT_COLUMN_NAME_IDX.
Referenced by db_query_execute(), db_query_execute_path_filter(), db_query_execute_recent(), and db_query_execute_search_filter().
00141 { 00142 int sort_column = SORT_COLUMN_NAME_IDX[sort_order]; 00143 if (show_filenames && sort_order == CTB_SORT_BY_NAME) sort_column = COL_FILENAME; 00144 return MDB_COLUMN_NAMES[sort_column]; 00145 }
int open_global_database | ( | const gchar * | directory | ) |
Definition at line 81 of file ctb/src/db.c.
References close_database(), ER_FAIL, ER_OK, ermetadb_get_dir(), ermetadb_global_open(), ERRORPRINTF, and g_metadb.
Referenced by filemodel_chdir().
00082 { 00083 if (g_metadb && strcmp(directory, ermetadb_get_dir(g_metadb)) == 0 ) 00084 { 00085 return ER_OK; 00086 } 00087 00088 close_database(); 00089 g_metadb = ermetadb_global_open(directory, FALSE); 00090 if (!g_metadb) { 00091 ERRORPRINTF("error opening global database in at [%s]", directory); 00092 return ER_FAIL; 00093 } 00094 return ER_OK; 00095 }
Definition at line 70 of file ctb/src/db.c.
Referenced by close_database(), db_query_execute(), db_query_execute_path_filter(), db_query_execute_recent(), db_query_execute_search_filter(), db_query_get_metadata(), db_query_update_lastread(), get_database(), and open_global_database().
gboolean g_query_in_progress = FALSE |
Definition at line 72 of file ctb/src/db.c.
Referenced by db_query_create(), db_query_execute(), db_query_execute_path_filter(), db_query_execute_recent(), db_query_execute_search_filter(), and db_query_get_metadata().
metadata_table* g_query_names = NULL |
Definition at line 71 of file ctb/src/db.c.
const int MAX_WAIT_DATABASE = 30 [static] |
Definition at line 68 of file ctb/src/db.c.
const char* MDB_COLUMN_NAMES[] [static] |
{ [COL_FILENAME] = "filename" , [COL_DIRECTORY_PATH] = "directory_path" , [COL_SORT_PRIORITY] = "sort_priority" , [COL_IS_DIRECTORY] = "is_directory" , [COL_FILETYPE] = "file_type" , [COL_FILESIZE] = "file_size" , [COL_FILETIME_MODIFIED] = "file_time_modified" , [COL_FILETIME_LASTREAD] = "file_time_lastread" , [COL_FILETIME_ADDED] = "file_time_added" , [COL_TITLE] = "title" , [COL_AUTHOR] = "author" , [COL_THUMB_MINI] = "thumb_data_mini" , [COL_THUMB_SMALL] = "thumb_data_small" , [COL_THUMB_MEDIUM] = "thumb_data_medium" , [COL_THUMB_LARGE] = "thumb_data_large" , [N_METADATA_COLUMNS] = NULL }
Copyright (C) 2008 iRex Technologies B.V. All rights reserved.
Definition at line 32 of file ctb/src/db.c.
Referenced by db_query_create(), db_query_update_lastread(), and get_sort_order_name().
const int SORT_COLUMN_NAME_IDX[N_CTB_SORT_ORDER] [static] |
{ [CTB_SORT_BY_NAME] = COL_TITLE, [CTB_SORT_BY_TYPE] = COL_FILETYPE, [CTB_SORT_BY_SIZE] = COL_FILESIZE, [CTB_SORT_BY_DATE_ADDED] = COL_FILETIME_ADDED, [CTB_SORT_BY_DATE_READ] = COL_FILETIME_LASTREAD, [CTB_SORT_BY_AUTHOR] = COL_AUTHOR, }
Definition at line 56 of file ctb/src/db.c.
Referenced by get_sort_order_name().