mirror of https://github.com/kiwix/libkiwix.git
+ code to populate the language filter combobox in the content manager
This commit is contained in:
parent
0f3c1e2888
commit
8b5559af2b
|
@ -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(""),
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -329,6 +329,22 @@ namespace kiwix {
|
|||
return false;
|
||||
}
|
||||
|
||||
vector<string> Manager::getBooksLanguages() {
|
||||
std::vector<string> booksLanguages;
|
||||
std::vector<kiwix::Book>::iterator itr;
|
||||
std::map<string, bool> 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;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#ifndef KIWIX_MANAGER_H
|
||||
#define KIWIX_MANAGER_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <time.h>
|
||||
|
@ -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<string> getBooksLanguages();
|
||||
|
||||
string writableLibraryPath;
|
||||
|
||||
vector <std::string> bookIdList;
|
||||
vector<std::string> bookIdList;
|
||||
|
||||
protected:
|
||||
kiwix::Library library;
|
||||
|
|
Loading…
Reference in New Issue