From 8b5559af2b8fdb896b397526e131d112ae6ff3c6 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Tue, 11 Oct 2011 18:47:08 +0000 Subject: [PATCH] + code to populate the language filter combobox in the content manager --- src/common/kiwix/library.cpp | 4 ++++ src/common/kiwix/library.h | 1 + src/common/kiwix/manager.cpp | 16 ++++++++++++++++ src/common/kiwix/manager.h | 4 +++- 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/common/kiwix/library.cpp b/src/common/kiwix/library.cpp index 503c9e3cc..4741b5add 100644 --- a/src/common/kiwix/library.cpp +++ b/src/common/kiwix/library.cpp @@ -66,6 +66,10 @@ namespace kiwix { return strcmp(a.creator.c_str(), b.creator.c_str()) < 0; } + bool Book::sortByLanguage(const kiwix::Book &a, const kiwix::Book &b) { + return strcmp(a.language.c_str(), b.language.c_str()) < 0; + } + /* Constructor */ Library::Library(): current(""), diff --git a/src/common/kiwix/library.h b/src/common/kiwix/library.h index 147b85710..ac85eb90c 100644 --- a/src/common/kiwix/library.h +++ b/src/common/kiwix/library.h @@ -45,6 +45,7 @@ namespace kiwix { static bool sortBySize(const Book &a, const Book &b); static bool sortByDate(const Book &a, const Book &b); static bool sortByPublisher(const Book &a, const Book &b); + static bool sortByLanguage(const Book &a, const Book &b); string id; string path; diff --git a/src/common/kiwix/manager.cpp b/src/common/kiwix/manager.cpp index a29615320..788f1a13a 100644 --- a/src/common/kiwix/manager.cpp +++ b/src/common/kiwix/manager.cpp @@ -329,6 +329,22 @@ namespace kiwix { return false; } + vector Manager::getBooksLanguages() { + std::vector booksLanguages; + std::vector::iterator itr; + std::map booksLanguagesMap; + + std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByLanguage); + for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) { + if (booksLanguagesMap.find(itr->language) == booksLanguagesMap.end()) { + booksLanguagesMap[itr->language] = true; + booksLanguages.push_back(itr->language); + } + } + + return booksLanguages; + } + kiwix::Library Manager::cloneLibrary() { return this->library; } diff --git a/src/common/kiwix/manager.h b/src/common/kiwix/manager.h index 2fb12bf0a..5f02d553c 100644 --- a/src/common/kiwix/manager.h +++ b/src/common/kiwix/manager.h @@ -20,6 +20,7 @@ #ifndef KIWIX_MANAGER_H #define KIWIX_MANAGER_H +#include #include #include #include @@ -63,10 +64,11 @@ namespace kiwix { bool updateBookLastOpenDateById(const string id); void removeBookPaths(); bool listBooks(const supportedListMode mode, const supportedListSortBy sortBy, const unsigned int maxSize); + vector getBooksLanguages(); string writableLibraryPath; - vector bookIdList; + vector bookIdList; protected: kiwix::Library library;