View Single Post
Old 03-20-2010, 12:12 AM   #13
stsu
Member
stsu began at the beginning.
 
Posts: 13
Karma: 24
Join Date: Jan 2010
Device: irex dr1000s
You may find metadata utilities in the headers of libermetadb ermetadb.h, metadata_table.h and usage examples in ctb/src/filemodel.c

The code might be something like this, which is copied from filemodel.c and modified.
Code:
// create metadata database if not exists
static int create_metadatabase (const gchar *directory, 
				const gchar *filename, 
				const gchar *fullpath,
				const gchar *title, 
				const gchar *author)
{
  int ret = ER_OK;    // return code
  int rc;
  GString *dir = g_string_new(directory);
  GString *file = g_string_new(filename);

  struct stat statbuf;
                
  erMetadb *g_metadb = NULL; 
  metadata_table *values = NULL;
                
  // set title and an author              
  values = metadata_table_new();
  metadata_table_add_column(values,"title");
  metadata_table_add_column(values,"author");

  metadata_table_set_text(values,0,title);
  metadata_table_set_text(values,1,author);
                
  g_metadb = ermetadb_new();
  if (g_metadb == NULL)
    {
      ret = ER_FAIL;
    }
                
  // open database in specified directory
  if (ret == ER_OK)
    {
      rc = ermetadb_open_database_readonly(g_metadb, dir);
      switch(rc)
	{
	case ER_NOT_FOUND:
	  // database not present: create a new database and open it
	  rc = ermetadb_create_database(dir);
	  if(rc == ER_OK)
	    {
	      rc = ermetadb_open_database(g_metadb, dir);
	    }
	  if(rc == ER_OK)
	    {
	      rc = stat(fullpath, &statbuf);
	      if(rc != 0)
		rc = ER_FAIL;
	      else
		rc = ER_OK;
	    }
	  if(rc == ER_OK && S_ISREG(statbuf.st_mode) )
	    {
	      (void) ermetadb_add_document( g_metadb,
					    file    , 
   					    statbuf.st_size         ,   
					    statbuf.st_mtime         );
	      ermetadb_set_file_metadata( g_metadb, file, values);
	      rc =ermetadb_close_database(g_metadb);
	    }
	  ret = rc;
	  break;
	case ER_OK:
	  ret =ermetadb_close_database(g_metadb);
	  break;                                          
	}
    }
                
  // clean up
  ermetadb_free(g_metadb);
  metadata_table_free(values);
  g_string_free(dir, TRUE);
  g_string_free(file, TRUE);
                
  return ret;
}
stsu is offline   Reply With Quote