metadata.c File Reference

#include "config.h"
#include <glib.h>
#include <stdlib.h>
#include "log.h"
#include "metadata.h"
Include dependency graph for metadata.c:

Go to the source code of this file.

Defines

#define DEFAULT_H_POSITION   0.0
#define DEFAULT_V_POSITION   0.0
#define DEFAULT_ZOOM_LEVEL   1.0
#define DEFAULT_FULL_SCREEN   FALSE

Functions

static const metadata_cellget_column_data (const metadata_table *table, const char *column_name)
static gint get_double (const metadata_table *table, const char *column_name, gdouble *value)
static gint get_integer (const metadata_table *table, const char *column_name, gint *value)
static gint get_boolean (const metadata_table *table, const char *column_name, gboolean *value)
static gint set_double (const metadata_table *table, const char *column_name, gdouble value)
static gint set_boolean (const metadata_table *table, const char *column_name, gboolean value)
static void meta_file_close (void)
void meta_initialize (void)
void meta_finalize (void)
void meta_file_open (const gchar *filepath)
gdouble meta_get_h_position (void)
gdouble meta_get_v_position (void)
gfloat meta_get_zoom_level (void)
gboolean meta_get_full_screen (void)
void meta_set_h_position (gdouble position)
void meta_set_v_position (gdouble position)
void meta_set_zoom_level (gfloat factor)
void meta_set_full_screen (gboolean is_full_screen)

Variables

static const gchar * META_H_POSITION = "erbrowser_h_position"
static const gchar * META_V_POSITION = "erbrowser_v_position"
static const gchar * META_ZOOM_LEVEL = "erbrowser_zoom_level"
static const gchar * META_FULL_SCREEN = "erbrowser_full_screem"
static gchar * g_path = NULL
static gchar * g_filename = NULL
static gboolean g_should_save = FALSE
static gdouble g_h_position = DEFAULT_H_POSITION
static gdouble g_v_position = DEFAULT_V_POSITION
static gdouble g_zoom_level = DEFAULT_ZOOM_LEVEL
static gboolean g_full_screen = DEFAULT_FULL_SCREEN

Define Documentation

#define DEFAULT_FULL_SCREEN   FALSE

Definition at line 51 of file metadata.c.

Referenced by meta_file_open().

#define DEFAULT_H_POSITION   0.0

Copyright (C) 2009 iRex Technologies B.V. All rights reserved.

Definition at line 48 of file metadata.c.

Referenced by meta_file_open().

#define DEFAULT_V_POSITION   0.0

Definition at line 49 of file metadata.c.

Referenced by meta_file_open().

#define DEFAULT_ZOOM_LEVEL   1.0

Definition at line 50 of file metadata.c.

Referenced by meta_file_open().


Function Documentation

static gint get_boolean ( const metadata_table table,
const char *  column_name,
gboolean *  value 
) [static]

Definition at line 112 of file metadata.c.

References ER_INVALID_DATA, ER_OK, and get_integer().

Referenced by meta_file_open().

00113 {
00114     gint int_value;
00115     gint ret = get_integer(table, column_name, &int_value);
00116     if (ret == ER_OK)
00117     {
00118         *value = int_value ? TRUE : FALSE;
00119     }
00120     
00121     return ER_INVALID_DATA;
00122 }

Here is the call graph for this function:

Here is the caller graph for this function:

static const metadata_cell* get_column_data ( const metadata_table table,
const char *  column_name 
) [static]

Definition at line 82 of file metadata.c.

References metadata_table_find_column(), and metadata_table_get_cell().

Referenced by get_double(), and get_integer().

00083 {
00084     return metadata_table_get_cell(table, metadata_table_find_column(table, column_name));
00085 }

Here is the call graph for this function:

Here is the caller graph for this function:

static gint get_double ( const metadata_table table,
const char *  column_name,
gdouble *  value 
) [static]

Definition at line 88 of file metadata.c.

References ER_INVALID_DATA, ER_OK, get_column_data(), METADATA_DOUBLE, metadata_cell::type, metadata_cell::v_double, and metadata_cell::value.

Referenced by meta_file_open().

00089 {
00090     const metadata_cell *cell = get_column_data(table, column_name);
00091     if (cell && (cell->type == METADATA_DOUBLE))
00092     {
00093         *value  = cell->value.v_double;
00094         return ER_OK;
00095     }
00096     return ER_INVALID_DATA;
00097 }

Here is the call graph for this function:

Here is the caller graph for this function:

static gint get_integer ( const metadata_table table,
const char *  column_name,
gint *  value 
) [static]

Definition at line 100 of file metadata.c.

References ER_INVALID_DATA, ER_OK, get_column_data(), METADATA_INT64, metadata_cell::type, metadata_cell::v_int64, and metadata_cell::value.

Referenced by get_boolean().

00101 {
00102     const metadata_cell *cell = get_column_data(table, column_name);
00103     if (cell && (cell->type == METADATA_INT64))
00104     {
00105         *value  = cell->value.v_int64;
00106         return ER_OK;
00107     }
00108     return ER_INVALID_DATA;
00109 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void meta_file_close ( void   )  [static]

Definition at line 137 of file metadata.c.

References ER_OK, ermetadb_close(), ermetadb_local_open(), ermetadb_local_set_application_data(), ERRORPRINTF, g_filename, g_full_screen, g_h_position, g_path, g_should_save, g_v_position, g_zoom_level, LOGPRINTF, META_FULL_SCREEN, META_H_POSITION, META_V_POSITION, META_ZOOM_LEVEL, metadata_table_add_column(), metadata_table_free, metadata_table_new(), set_boolean(), and set_double().

Referenced by meta_file_open(), and meta_finalize().

00138 {
00139     LOGPRINTF("entry");
00140 
00141     if (!g_should_save || !g_path || !g_filename) goto out;
00142     
00143     // open database
00144     erMetadb db = ermetadb_local_open(g_path, TRUE);
00145     if (db == NULL) {
00146         ERRORPRINTF("Error storing data for %s", g_filename);
00147         goto out;
00148     }
00149 
00150     // copy values to table
00151     metadata_table *values_table = metadata_table_new();
00152     metadata_table_add_column(values_table, META_H_POSITION);
00153     metadata_table_add_column(values_table, META_V_POSITION);
00154     metadata_table_add_column(values_table, META_ZOOM_LEVEL);
00155     metadata_table_add_column(values_table, META_FULL_SCREEN);
00156 
00157     set_double (values_table, META_H_POSITION,  g_h_position);
00158     set_double (values_table, META_V_POSITION,  g_v_position);
00159     set_double (values_table, META_ZOOM_LEVEL,  g_zoom_level);
00160     set_boolean(values_table, META_FULL_SCREEN, g_full_screen);
00161     
00162     // update database
00163     int ret = ermetadb_local_set_application_data(db, g_filename, values_table);
00164     if (ret != ER_OK)
00165     {
00166         ERRORPRINTF("Error storing application data for %s, error %d", g_filename, ret);
00167     }
00168 
00169     metadata_table_free(values_table);
00170     ermetadb_close(db);
00171 out:
00172     g_free(g_path);
00173     g_path = NULL;
00174     g_free(g_filename);
00175     g_filename = NULL;
00176 }

Here is the call graph for this function:

Here is the caller graph for this function:

void meta_file_open ( const gchar *  filepath  ) 

Definition at line 196 of file metadata.c.

References DEFAULT_FULL_SCREEN, DEFAULT_H_POSITION, DEFAULT_V_POSITION, DEFAULT_ZOOM_LEVEL, ER_OK, ermetadb_close(), ermetadb_local_get_application_data(), ermetadb_local_open(), g_filename, g_full_screen, g_h_position, g_path, g_should_save, g_v_position, g_zoom_level, get_boolean(), get_double(), LOGPRINTF, meta_file_close(), META_FULL_SCREEN, META_H_POSITION, META_V_POSITION, META_ZOOM_LEVEL, metadata_table_add_column(), metadata_table_free, and metadata_table_new().

Referenced by view_open_uri().

00197 {
00198     LOGPRINTF("entry file='%s'", filepath);
00199     
00200     // close if already open
00201     if (g_path || g_filename)
00202     {
00203         meta_file_close();
00204     }
00205 
00206     g_path = g_path_get_dirname(filepath);
00207     g_filename = g_path_get_basename(filepath);
00208 
00209     // initialize to default values
00210     g_should_save = FALSE; 
00211     g_h_position  = DEFAULT_H_POSITION;
00212     g_v_position  = DEFAULT_V_POSITION;
00213     g_zoom_level  = DEFAULT_ZOOM_LEVEL;
00214     g_full_screen = DEFAULT_FULL_SCREEN;
00215 
00216     // try to open database
00217     erMetadb db = ermetadb_local_open(g_path, FALSE);
00218     if (db == NULL) {   // db doesn't exist, ok
00219         LOGPRINTF("No (valid) metadata found for %s", filepath);
00220         return;
00221     }
00222 
00223     // read values from db
00224     metadata_table *names_table = metadata_table_new();
00225     metadata_table_add_column(names_table, META_H_POSITION);
00226     metadata_table_add_column(names_table, META_V_POSITION);
00227     metadata_table_add_column(names_table, META_ZOOM_LEVEL);
00228     metadata_table_add_column(names_table, META_FULL_SCREEN);
00229 
00230     metadata_table *results_table = NULL;
00231     int ret = ermetadb_local_get_application_data(db,
00232                                                   g_filename,
00233                                                   names_table,
00234                                                   &results_table);
00235     if (ret == ER_OK && results_table) {
00236         // assign to static variables
00237         get_double (results_table, META_H_POSITION,  &g_h_position);
00238         get_double (results_table, META_V_POSITION,  &g_v_position);
00239         get_double (results_table, META_ZOOM_LEVEL,  &g_zoom_level);
00240         get_boolean(results_table, META_FULL_SCREEN, &g_full_screen);
00241     } else {
00242         LOGPRINTF("No (valid) application data found for %s, error %d", filepath, ret);
00243     }
00244 
00245     metadata_table_free(names_table);
00246     metadata_table_free(results_table);
00247     ermetadb_close(db);
00248 }

Here is the call graph for this function:

Here is the caller graph for this function:

void meta_finalize ( void   ) 

Definition at line 185 of file metadata.c.

References g_filename, g_path, LOGPRINTF, and meta_file_close().

Referenced by destroy_cb().

00186 {
00187     LOGPRINTF("entry");
00188 
00189     if (g_path || g_filename)
00190     {
00191         meta_file_close();
00192     }
00193 }

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean meta_get_full_screen ( void   ) 

Definition at line 269 of file metadata.c.

References g_full_screen.

Referenced by view_open_uri().

00270 {
00271     return g_full_screen;
00272 }

Here is the caller graph for this function:

gdouble meta_get_h_position ( void   ) 

Definition at line 251 of file metadata.c.

References g_h_position.

00252 {
00253     return g_h_position;
00254 }

gdouble meta_get_v_position ( void   ) 

Definition at line 257 of file metadata.c.

References g_v_position.

00258 {
00259     return g_v_position;
00260 }

gfloat meta_get_zoom_level ( void   ) 

Definition at line 263 of file metadata.c.

References g_zoom_level.

Referenced by view_open_uri().

00264 {
00265     return (gfloat) g_zoom_level;
00266 }

Here is the caller graph for this function:

void meta_initialize ( void   ) 

File Name : metadata.h

Description: File metadata functions Copyright (C) 2009 iRex Technologies B.V. All rights reserved.

Definition at line 179 of file metadata.c.

References LOGPRINTF.

Referenced by view_create().

00180 {
00181     LOGPRINTF("entry");
00182 }

Here is the caller graph for this function:

void meta_set_full_screen ( gboolean  is_full_screen  ) 

Definition at line 314 of file metadata.c.

References g_full_screen, g_should_save, and LOGPRINTF.

Referenced by view_full_screen().

00315 {
00316     LOGPRINTF("entry");
00317     
00318     if (is_full_screen != g_full_screen)
00319     {
00320         LOGPRINTF("saved full screen: %d", is_full_screen);
00321         g_full_screen = is_full_screen;
00322         g_should_save = TRUE;
00323     }
00324 }

Here is the caller graph for this function:

void meta_set_h_position ( gdouble  position  ) 

Definition at line 275 of file metadata.c.

References g_h_position, g_should_save, and LOGPRINTF.

Referenced by hadjustment_changed_cb().

00276 {
00277     LOGPRINTF("entry");
00278     
00279     if (position != g_h_position)
00280     {
00281         LOGPRINTF("saved h position: %f", position);
00282         g_h_position  = position;
00283         g_should_save = TRUE;
00284     }
00285 }

Here is the caller graph for this function:

void meta_set_v_position ( gdouble  position  ) 

Definition at line 288 of file metadata.c.

References g_should_save, g_v_position, and LOGPRINTF.

Referenced by vadjustment_changed_cb().

00289 {
00290     LOGPRINTF("entry");
00291     
00292     if (position != g_v_position)
00293     {
00294         LOGPRINTF("saved v position: %f", position);
00295         g_v_position  = position;
00296         g_should_save = TRUE;
00297     }
00298 }

Here is the caller graph for this function:

void meta_set_zoom_level ( gfloat  factor  ) 

Definition at line 301 of file metadata.c.

References g_should_save, g_zoom_level, and LOGPRINTF.

Referenced by view_set_zoom_level(), view_zoom_in(), and view_zoom_out().

00302 {
00303     LOGPRINTF("entry");
00304     
00305     if (factor != g_zoom_level)
00306     {
00307         LOGPRINTF("saved zoom: %f", factor);
00308         g_zoom_level = factor;
00309         g_should_save = TRUE;
00310     }
00311 }

Here is the caller graph for this function:

static gint set_boolean ( const metadata_table table,
const char *  column_name,
gboolean  value 
) [static]

Definition at line 131 of file metadata.c.

References metadata_table_find_column(), and metadata_table_set_int64().

Referenced by meta_file_close().

00132 {
00133     return metadata_table_set_int64((metadata_table *) table, metadata_table_find_column(table, column_name), value ? 1 : 0 );
00134 }

Here is the call graph for this function:

Here is the caller graph for this function:

static gint set_double ( const metadata_table table,
const char *  column_name,
gdouble  value 
) [static]

Definition at line 125 of file metadata.c.

References metadata_table_find_column(), and metadata_table_set_double().

Referenced by meta_file_close().

00126 {
00127     return metadata_table_set_double((metadata_table *) table, metadata_table_find_column(table, column_name), value);
00128 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

gchar* g_filename = NULL [static]

Definition at line 69 of file metadata.c.

Referenced by meta_file_close(), meta_file_open(), and meta_finalize().

gboolean g_full_screen = DEFAULT_FULL_SCREEN [static]
gdouble g_h_position = DEFAULT_H_POSITION [static]
gchar* g_path = NULL [static]

Definition at line 68 of file metadata.c.

Referenced by meta_file_close(), meta_file_open(), and meta_finalize().

gboolean g_should_save = FALSE [static]
gdouble g_v_position = DEFAULT_V_POSITION [static]
gdouble g_zoom_level = DEFAULT_ZOOM_LEVEL [static]
const gchar* META_FULL_SCREEN = "erbrowser_full_screem" [static]

Definition at line 61 of file metadata.c.

Referenced by meta_file_close(), and meta_file_open().

const gchar* META_H_POSITION = "erbrowser_h_position" [static]

Definition at line 58 of file metadata.c.

Referenced by meta_file_close(), and meta_file_open().

const gchar* META_V_POSITION = "erbrowser_v_position" [static]

Definition at line 59 of file metadata.c.

Referenced by meta_file_close(), and meta_file_open().

const gchar* META_ZOOM_LEVEL = "erbrowser_zoom_level" [static]

Definition at line 60 of file metadata.c.

Referenced by meta_file_close(), and meta_file_open().

Generated by  doxygen 1.6.2-20100208