Commits

Iñigo Serna committed 5bf1d5e

irex: MyUtils: new secs2strftime(); irexplus: all get_data_XX() include times, new db.update_entry_metadata()

Comments (0)

Files changed (3)

irex/MyUtils.vapi

         return now;
     }
 
+    public string secs2strftime(long secs, string format) {
+        tm t;
+    	localtime_r(ref secs, out t);
+        return tm2strftime(ref t, format);
+    }
+
     public string timeval2strftime(TimeVal tv, string format) {
         var secs = tv.tv_sec;
-	tm t;
+        tm t;
     	localtime_r(ref secs, out t);
-	return tm2strftime(ref t, format);
+        return tm2strftime(ref t, format);
     }
 
     public string tm2strftime(ref tm timeptr, string format) {
+////////////////////////////////////////////////////////////////////////
+// irex: IREX DR ereaders basic bindings
+//
+// Copyright (C) 2009  Ross, from mobileread.com
+// Copyright (C) 2011  Iñigo Serna <inigoserna@gmail.com>
+// Released under GPL v3+
+//
+// Time-stamp: <2011-09-04 17:49:06 inigo>
+//////////////////////////////////////////////////////////////////////
+
+
 using liberipc;
 
 namespace irex {

irex/irexplus.vala

+////////////////////////////////////////////////////////////////////////
+// irexplus: IREX DR ereaders extended bindings and utils
+//
+// Copyright (C) 2011  Iñigo Serna <inigoserna@gmail.com>
+// Released under GPL v3+
+//
+// Time-stamp: <2011-09-05 11:07:48 inigo>
+//////////////////////////////////////////////////////////////////////
+
+
 using Sqlite;
 using Gdk;
 
         public string? title;
         public string? author;
         public string? tags;
+        public long added;
+        public long modified;
+        public long lastread;
 
         public uint8[]? png_s;
         public uint8[]? png_m;
 
         public DBEntry(int id=0, string path="", string filename="",
                        string? title=null, string? author=null, string? tags=null,
-                       uint8[]? png_s=null, uint8[]? png_m=null) {
+                       uint8[]? png_s=null, uint8[]? png_m=null,
+                       long added=0, long modified=0, long lastread=0) {
             this.id = id;
             this.path = path;
             this.filename = filename;
             this.tags = tags;
             this.png_s = png_s;
             this.png_m = png_m;
+            this.added = added;
+            this.modified = modified;
+            this.lastread = lastread;
         }
     }
 
         const string FSCOVERSDIR   = "System/.covers";
         const string COVERFILE_FMT = "/%s/%2.2x/%d.png";
         const string STMT_GET_FILE_IDS    = "SELECT file_id FROM file_metadata;";
-        const string STMT_GET_METADATA    = "SELECT file_id, title, author, tag FROM file_metadata WHERE filename=? AND directory_path=?";
+        const string STMT_GET_METADATA    = "SELECT file_id, title, author, tag, file_time_added, file_time_modified, file_time_lastread FROM file_metadata WHERE filename=? AND directory_path=?";
+        const string STMT_UPDATE_METADATA = "UPDATE file_metadata SET title=?, author=?, tag=? WHERE file_id=?";
         const string STMT_GET_THUMBS      = "SELECT thumb_data_small, thumb_data_medium FROM thumbnails WHERE file_id=?";
         const string STMT_GET_WITH_IMGS   = "SELECT m.file_id, m.directory_path, m.filename, t.thumb_data_small, t.thumb_data_medium FROM file_metadata AS m, thumbnails AS t WHERE m.file_id==t.file_id;";
         const string STMT_INSERT_IMGS     = "INSERT INTO thumbnails('file_id', 'thumb_data_small', 'thumb_data_medium') VALUES (?, ?, ?)";
         const string STMT_DELETE_IMGS     = "DELETE FROM thumbnails;";
         const string STMT_UPDATE_LASTREAD = "UPDATE file_metadata SET file_time_lastread=? WHERE file_id=?";
-        const string STMT_GET_LASTREAD    = "SELECT file_id, directory_path, filename, title, author FROM file_metadata WHERE is_directory=0 ORDER BY file_time_lastread DESC LIMIT ?;";
-        const string STMT_GET_LASTADDED   = "SELECT file_id, directory_path, filename, title, author FROM file_metadata WHERE (is_directory=0 AND file_type!='desktop' AND file_type!='directory') ORDER BY file_time_added DESC LIMIT ?;";
+        const string STMT_GET_LASTREAD    = "SELECT file_id, directory_path, filename, title, author, tag, file_time_added, file_time_modified, file_time_lastread FROM file_metadata WHERE is_directory=0 ORDER BY file_time_lastread DESC LIMIT ?;";
+        const string STMT_GET_LASTADDED   = "SELECT file_id, directory_path, filename, title, author, tag, file_time_added, file_time_modified, file_time_lastread FROM file_metadata WHERE (is_directory=0 AND file_type!='desktop' AND file_type!='directory') ORDER BY file_time_added DESC LIMIT ?;";
         const string STMT_DO_VACUUM       = "VACUUM;";
 
         ///// Variables
             } else if (rc == Sqlite.ROW) {
                 return new DBEntry(stmt.column_int(0), path, filename,
                                    stmt.column_text(1), stmt.column_text(2), stmt.column_text(3),
-                                   null, null);
+                                   null, null,
+                                   stmt.column_int(4), stmt.column_int(5), stmt.column_int(6));
             } else
                 throw new IrexPlusError.DB_ERROR("SQL (%d): %s", rc, db.errmsg());
         }
 
+        public void update_entry_metadata(int file_id, string title, string author, string tags) throws IrexPlusError {
+            GLib.Value v1 = title, v2 = author, v3 = tags, v4 = file_id;
+            _build_query(STMT_UPDATE_METADATA, v1, v2, v3, v4);
+            if ((rc=stmt.step()) != Sqlite.DONE)
+                throw new IrexPlusError.DB_ERROR("SQL (%d): %s", rc, db.errmsg());
+        }
 
         ///// Thumbs
         public void get_png_thumbs_from_db(int file_id, out uint8[] png_s,
                     case Sqlite.ROW:
                         list.append(new DBEntry(stmt.column_int(0),
                                                 stmt.column_text(1), stmt.column_text(2),
-                                                stmt.column_text(3), stmt.column_text(4)));
+                                                stmt.column_text(3), stmt.column_text(4), stmt.column_text(5),
+                                                null, null,
+                                                stmt.column_int(6), stmt.column_int(7), stmt.column_int(8)));
                         break;
                     default:
                         throw new IrexPlusError.DB_ERROR("SQL (%d): %s", rc, db.errmsg());
                     case Sqlite.ROW:
                         list.append(new DBEntry(stmt.column_int(0),
                                                 stmt.column_text(1), stmt.column_text(2),
-                                                stmt.column_text(3), stmt.column_text(4)));
+                                                stmt.column_text(3), stmt.column_text(4), stmt.column_text(5),
+                                                null, null,
+                                                stmt.column_int(6), stmt.column_int(7), stmt.column_int(8)));
                         break;
                     default:
                         throw new IrexPlusError.DB_ERROR("SQL (%d): %s", rc, db.errmsg());