[niepce] workspace: perform keyword count
- From: Hubert Figuière <hub src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [niepce] workspace: perform keyword count
- Date: Tue, 28 Nov 2017 01:24:25 +0000 (UTC)
commit 5290aaaa3b5218a9b995308c7d5f57822fe4b516
Author: Hubert Figuière <hub figuiere net>
Date: Fri Nov 17 18:13:50 2017 -0500
workspace: perform keyword count
- FolderCount renamed to Count
- engine_library_notification_get_folder_count() rename to engine_library_notification_get_count()
src/engine/db/library.rs | 13 +++++++++++++
src/engine/library/commands.rs | 15 +++++++++++----
src/engine/library/notification.rs | 24 ++++++++++++++++--------
src/libraryclient/clientimpl.rs | 9 +++++++++
src/libraryclient/clientinterface.rs | 1 +
src/libraryclient/libraryclient.rs | 11 ++++++++++-
src/niepce/ui/workspacecontroller.cpp | 28 +++++++++++++++++++++-------
7 files changed, 81 insertions(+), 20 deletions(-)
---
diff --git a/src/engine/db/library.rs b/src/engine/db/library.rs
index 852502f..df3a825 100644
--- a/src/engine/db/library.rs
+++ b/src/engine/db/library.rs
@@ -342,6 +342,19 @@ impl Library {
Some(keywords)
}
+ pub fn count_keyword(&self, id: LibraryId) -> i64 {
+ if let Some(ref conn) = self.dbconn {
+ if let Ok(mut stmt) = conn.prepare("SELECT COUNT(keyword_id) FROM keywording \
+ WHERE keyword_id=:1;") {
+ let mut rows = stmt.query(&[&id]).unwrap();
+ if let Some(Ok(row)) = rows.next() {
+ return row.get(0);
+ }
+ }
+ }
+ -1
+ }
+
pub fn add_fs_file(&self, file: &str) -> LibraryId {
if let Some(ref conn) = self.dbconn {
if let Ok(c) = conn.execute(
diff --git a/src/engine/library/commands.rs b/src/engine/library/commands.rs
index 4e6201e..f3f7675 100644
--- a/src/engine/library/commands.rs
+++ b/src/engine/library/commands.rs
@@ -33,8 +33,8 @@ use engine::db::libfolder::LibFolder;
use super::notification::Notification as LibNotification;
use super::notification::{
Content,
+ Count,
FileMove,
- FolderCount,
MetadataChange,
};
use root::eng::NiepceProperties as Np;
@@ -174,7 +174,7 @@ pub fn cmd_set_metadata(lib: &Library, id: LibraryId, meta: Np,
pub fn cmd_count_folder(lib: &Library, folder_id: LibraryId) -> bool {
let count = lib.count_folder(folder_id);
lib.notify(Box::new(LibNotification::FolderCounted(
- FolderCount{folder: folder_id, count: count})));
+ Count{id: folder_id, count: count})));
true
}
@@ -196,6 +196,13 @@ pub fn cmd_query_keyword_content(lib: &Library, keyword_id: LibraryId) -> bool {
false
}
+pub fn cmd_count_keyword(lib: &Library, id: LibraryId) -> bool {
+ let count = lib.count_keyword(id);
+ lib.notify(Box::new(LibNotification::KeywordCounted(
+ Count{id: id, count: count})));
+ true
+}
+
pub fn cmd_write_metadata(lib: &Library, file_id: LibraryId) -> bool {
lib.write_metadata(file_id)
}
@@ -207,9 +214,9 @@ pub fn cmd_move_file_to_folder(lib: &Library, file_id: LibraryId, from: LibraryI
lib.notify(Box::new(LibNotification::FileMoved(
FileMove{file: file_id, from: from, to: to})));
lib.notify(Box::new(LibNotification::FolderCountChanged(
- FolderCount{folder: from, count: -1})));
+ Count{id: from, count: -1})));
lib.notify(Box::new(LibNotification::FolderCountChanged(
- FolderCount{folder: to, count: 1})));
+ Count{id: to, count: 1})));
return true;
}
false
diff --git a/src/engine/library/notification.rs b/src/engine/library/notification.rs
index bd71666..58d8caf 100644
--- a/src/engine/library/notification.rs
+++ b/src/engine/library/notification.rs
@@ -40,14 +40,16 @@ pub enum NotificationType {
ADDED_LABEL,
FOLDER_CONTENT_QUERIED,
FOLDER_DELETED,
+ FOLDER_COUNTED,
+ FOLDER_COUNT_CHANGE,
KEYWORD_CONTENT_QUERIED,
+ KEYWORD_COUNTED,
+ KEYWORD_COUNT_CHANGE,
METADATA_QUERIED,
METADATA_CHANGED,
LABEL_CHANGED,
LABEL_DELETED,
XMP_NEEDS_UPDATE,
- FOLDER_COUNTED,
- FOLDER_COUNT_CHANGE ,
FILE_MOVED,
}
@@ -59,8 +61,8 @@ pub struct FileMove {
}
#[repr(C)]
-pub struct FolderCount {
- pub folder: LibraryId,
+pub struct Count {
+ pub id: LibraryId,
pub count: i64,
}
@@ -92,10 +94,12 @@ pub enum Notification {
AddedLabel(Label),
FileMoved(FileMove),
FolderContentQueried(Content),
- FolderCounted(FolderCount),
- FolderCountChanged(FolderCount),
+ FolderCounted(Count),
+ FolderCountChanged(Count),
FolderDeleted(LibraryId),
KeywordContentQueried(Content),
+ KeywordCounted(Count),
+ KeywordCountChanged(Count),
LabelChanged(Label),
LabelDeleted(LibraryId),
LibCreated,
@@ -151,6 +155,8 @@ pub extern "C" fn engine_library_notification_type(n: *const Notification) -> No
Some(&Notification::FolderDeleted(_)) => NotificationType::FOLDER_DELETED,
Some(&Notification::KeywordContentQueried(_)) =>
NotificationType::KEYWORD_CONTENT_QUERIED,
+ Some(&Notification::KeywordCounted(_)) => NotificationType::KEYWORD_COUNTED,
+ Some(&Notification::KeywordCountChanged(_)) => NotificationType::KEYWORD_COUNT_CHANGE,
Some(&Notification::LabelChanged(_)) => NotificationType::LABEL_CHANGED,
Some(&Notification::LabelDeleted(_)) => NotificationType::LABEL_DELETED,
Some(&Notification::LibCreated) => NotificationType::NEW_LIBRARY_CREATED,
@@ -199,10 +205,12 @@ pub extern "C" fn engine_library_notification_get_libmetadata(n: *const Notifica
}
#[no_mangle]
-pub extern "C" fn engine_library_notification_get_folder_count(n: *const Notification) -> *const FolderCount
{
+pub extern "C" fn engine_library_notification_get_count(n: *const Notification) -> *const Count {
match unsafe { n.as_ref() } {
Some(&Notification::FolderCountChanged(ref c)) |
- Some(&Notification::FolderCounted(ref c)) =>
+ Some(&Notification::FolderCounted(ref c)) |
+ Some(&Notification::KeywordCountChanged(ref c)) |
+ Some(&Notification::KeywordCounted(ref c)) =>
c,
_ => unreachable!()
}
diff --git a/src/libraryclient/clientimpl.rs b/src/libraryclient/clientimpl.rs
index 27a6b16..2fc7eb1 100644
--- a/src/libraryclient/clientimpl.rs
+++ b/src/libraryclient/clientimpl.rs
@@ -117,23 +117,32 @@ impl ClientInterface for ClientImpl {
commands::cmd_list_all_keywords(&lib)
});
}
+
fn query_keyword_content(&mut self, keyword_id: LibraryId) {
self.schedule_op(move |lib| {
commands::cmd_query_keyword_content(&lib, keyword_id)
});
}
+ fn count_keyword(&mut self, id: LibraryId) {
+ self.schedule_op(move |lib| {
+ commands::cmd_count_keyword(&lib, id)
+ });
+ }
+
/// get all the folder
fn get_all_folders(&mut self) {
self.schedule_op(move |lib| {
commands::cmd_list_all_folders(&lib)
});
}
+
fn query_folder_content(&mut self, folder_id: LibraryId) {
self.schedule_op(move |lib| {
commands::cmd_query_folder_content(&lib, folder_id)
});
}
+
fn count_folder(&mut self, folder_id: LibraryId) {
self.schedule_op(move |lib| {
commands::cmd_count_folder(&lib, folder_id)
diff --git a/src/libraryclient/clientinterface.rs b/src/libraryclient/clientinterface.rs
index 4206b8c..16b8f0e 100644
--- a/src/libraryclient/clientinterface.rs
+++ b/src/libraryclient/clientinterface.rs
@@ -28,6 +28,7 @@ pub trait ClientInterface {
/// get all the keywords
fn get_all_keywords(&mut self);
fn query_keyword_content(&mut self, id: LibraryId);
+ fn count_keyword(&mut self, id: LibraryId);
/// get all the folder
fn get_all_folders(&mut self);
diff --git a/src/libraryclient/libraryclient.rs b/src/libraryclient/libraryclient.rs
index ae470f1..369593c 100644
--- a/src/libraryclient/libraryclient.rs
+++ b/src/libraryclient/libraryclient.rs
@@ -82,6 +82,9 @@ impl ClientInterface for LibraryClient {
fn query_keyword_content(&mut self, id: LibraryId) {
self.pimpl.query_keyword_content(id);
}
+ fn count_keyword(&mut self, id: LibraryId) {
+ self.pimpl.count_keyword(id);
+ }
/// get all the folder
fn get_all_folders(&mut self) {
@@ -225,7 +228,7 @@ pub extern "C" fn libraryclient_delete_folder(client: &mut LibraryClientWrapper,
#[no_mangle]
pub extern "C" fn libraryclient_count_folder(client: &mut LibraryClientWrapper,
folder_id: LibraryId) {
- client.unwrap_mut().count_folder(folder_id)
+ client.unwrap_mut().count_folder(folder_id);
}
#[no_mangle]
@@ -235,6 +238,12 @@ pub extern "C" fn libraryclient_query_keyword_content(client: &mut LibraryClient
}
#[no_mangle]
+pub extern "C" fn libraryclient_count_keyword(client: &mut LibraryClientWrapper,
+ id: LibraryId) {
+ client.unwrap_mut().count_keyword(id);
+}
+
+#[no_mangle]
pub extern "C" fn libraryclient_request_metadata(client: &mut LibraryClientWrapper,
file_id: LibraryId) {
client.unwrap_mut().request_metadata(file_id);
diff --git a/src/niepce/ui/workspacecontroller.cpp b/src/niepce/ui/workspacecontroller.cpp
index 5fe484e..e73adae 100644
--- a/src/niepce/ui/workspacecontroller.cpp
+++ b/src/niepce/ui/workspacecontroller.cpp
@@ -180,10 +180,10 @@ void WorkspaceController::on_lib_notification(const eng::LibNotification &ln)
}
case eng::NotificationType::FOLDER_COUNTED:
{
- auto count = engine_library_notification_get_folder_count(&ln);
- DBG_OUT("count for folder %Ld is %d", (long long)count->folder, count->count);
+ auto count = engine_library_notification_get_count(&ln);
+ DBG_OUT("count for folder %Ld is %d", (long long)count->id, count->count);
std::map<eng::library_id_t, Gtk::TreeIter>::const_iterator iter
- = m_folderidmap.find(count->folder);
+ = m_folderidmap.find(count->id);
if(iter != m_folderidmap.cend()) {
Gtk::TreeRow row = *(iter->second);
row[m_librarycolumns.m_count_n] = count->count;
@@ -192,12 +192,26 @@ void WorkspaceController::on_lib_notification(const eng::LibNotification &ln)
break;
}
+ case eng::NotificationType::KEYWORD_COUNTED:
+ {
+ auto count = engine_library_notification_get_count(&ln);
+ DBG_OUT("count for folder %Ld is %d", (long long)count->id, count->count);
+ std::map<eng::library_id_t, Gtk::TreeIter>::const_iterator iter
+ = m_keywordsidmap.find(count->id);
+ if(iter != m_keywordsidmap.cend()) {
+ Gtk::TreeRow row = *(iter->second);
+ row[m_librarycolumns.m_count_n] = count->count;
+ row[m_librarycolumns.m_count] = std::to_string(count->count);
+ }
+
+ break;
+ }
case eng::NotificationType::FOLDER_COUNT_CHANGE:
{
- auto count = engine_library_notification_get_folder_count(&ln);
- DBG_OUT("count change for folder %Ld is %d", (long long)count->folder, count->count);
+ auto count = engine_library_notification_get_count(&ln);
+ DBG_OUT("count change for folder %Ld is %d", (long long)count->id, count->count);
std::map<eng::library_id_t, Gtk::TreeIter>::const_iterator iter
- = m_folderidmap.find(count->folder);
+ = m_folderidmap.find(count->id);
if(iter != m_folderidmap.cend()) {
Gtk::TreeRow row = *(iter->second);
int new_count = row[m_librarycolumns.m_count_n] + count->count;
@@ -302,7 +316,7 @@ void WorkspaceController::add_keyword_item(const eng::Keyword* k)
m_icons[ICON_KEYWORD], keyword,
engine_db_keyword_id(k), KEYWORD_ITEM);
ffi::rust_cstring_delete(keyword);
-// getLibraryClient()->countKeyword(f->id());
+ ffi::libraryclient_count_keyword(getLibraryClient()->client(), engine_db_keyword_id(k));
m_keywordsidmap[engine_db_keyword_id(k)] = iter;
if(was_empty) {
expand_from_cfg("workspace_keywords_expanded", m_keywordsNode);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]