show recent files; supposed works, but glitch exists
probably due to Qt bug.
open web;
Change-Id: Ib9df50de82d7af659a09978e9d0aa0a5c540a041
diff --git a/src/action-log.cc b/src/action-log.cc
index 9d96efc..740430f 100644
--- a/src/action-log.cc
+++ b/src/action-log.cc
@@ -727,6 +727,38 @@
return (limit == 1); // more data is available
}
+void
+ActionLog::LookupRecentFileActions(const boost::function<void (const string &, int, int)> &visitor, int limit)
+{
+ sqlite3_stmt *stmt;
+
+ sqlite3_prepare_v2 (m_db,
+ "SELECT AL.filename, AL.action"
+ " FROM ActionLog AL"
+ " JOIN "
+ " (SELECT filename, MAX(action_timestamp) AS action_timestamp "
+ " FROM ActionLog "
+ " GROUP BY filename ) AS GAL"
+ " ON AL.filename = GAL.filename AND AL.action_timestamp = GAL.action_timestamp "
+ " ORDER BY AL.action_timestamp DESC "
+ " LIMIT ?;",
+ -1, &stmt, 0);
+ _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_OK, sqlite3_errmsg (m_db));
+ sqlite3_bind_int(stmt, 1, limit);
+ int index = 0;
+ while (sqlite3_step(stmt) == SQLITE_ROW)
+ {
+ std::string filename(reinterpret_cast<const char *> (sqlite3_column_text (stmt, 0)), sqlite3_column_bytes (stmt, 0));
+ int action = sqlite3_column_int (stmt, 1);
+ visitor(filename, action, index);
+ index++;
+ }
+
+ _LOG_DEBUG_COND (sqlite3_errcode (m_db) != SQLITE_DONE, sqlite3_errmsg (m_db));
+
+ sqlite3_finalize (stmt);
+}
+
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
diff --git a/src/action-log.h b/src/action-log.h
index cef0a65..6345281 100644
--- a/src/action-log.h
+++ b/src/action-log.h
@@ -109,6 +109,9 @@
LookupActionsInFolderRecursively (const boost::function<void (const Ccnx::Name &name, sqlite3_int64 seq_no, const ActionItem &)> &visitor,
const std::string &folder, int offset=0, int limit=-1);
+ void
+ LookupRecentFileActions(const boost::function<void (const std::string &, int, int)> &visitor, int limit = 5);
+
//
inline FileStatePtr
GetFileState ();
diff --git a/src/dispatcher.h b/src/dispatcher.h
index 0455ff0..d3b6bc3 100644
--- a/src/dispatcher.h
+++ b/src/dispatcher.h
@@ -75,6 +75,9 @@
HashPtr
SyncRoot() { return m_core->root(); }
+ inline void
+ LookupRecentFileActions(const boost::function<void(const std::string &, int, int)> &visitor, int limit) { m_actionLog->LookupRecentFileActions(visitor, limit); }
+
private:
void
Did_LocalFile_AddOrModify_Execute (boost::filesystem::path relativeFilepath); // cannot be const & for Execute event!!! otherwise there will be segfault