mirror of https://github.com/kiwix/libkiwix.git
+ filter by size
This commit is contained in:
parent
d11f027fbe
commit
0f3c1e2888
|
@ -55,7 +55,7 @@ namespace kiwix {
|
|||
}
|
||||
|
||||
bool Book::sortByDate(const kiwix::Book &a, const kiwix::Book &b) {
|
||||
return atoi(a.date.c_str()) < atoi(b.date.c_str());
|
||||
return strcmp(a.date.c_str(), b.date.c_str()) < 0;
|
||||
}
|
||||
|
||||
bool Book::sortBySize(const kiwix::Book &a, const kiwix::Book &b) {
|
||||
|
|
|
@ -403,7 +403,7 @@ namespace kiwix {
|
|||
return result;
|
||||
}
|
||||
|
||||
bool Manager::listBooks(const supportedListMode mode, const supportedListSortBy sortBy) {
|
||||
bool Manager::listBooks(const supportedListMode mode, const supportedListSortBy sortBy, const unsigned int maxSize) {
|
||||
this->bookIdList.clear();
|
||||
std::vector<kiwix::Book>::iterator itr;
|
||||
|
||||
|
@ -417,27 +417,31 @@ namespace kiwix {
|
|||
} else if (sortBy == PUBLISHER) {
|
||||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByPublisher);
|
||||
}
|
||||
|
||||
if (mode == LASTOPEN) {
|
||||
|
||||
/* Special sort for LASTOPEN */
|
||||
if (mode == LASTOPEN)
|
||||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByLastOpen);
|
||||
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||
if (!itr->last.empty())
|
||||
this->bookIdList.push_back(itr->id);
|
||||
}
|
||||
} else if (mode == REMOTE) {
|
||||
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||
if (itr->path.empty() && !itr->url.empty()) {
|
||||
this->bookIdList.push_back(itr->id);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||
if (!itr->path.empty()) {
|
||||
this->bookIdList.push_back(itr->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Generate the list of book id */
|
||||
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||
bool ok = true;
|
||||
|
||||
if (mode == LOCAL && itr->path.empty())
|
||||
ok = false;
|
||||
|
||||
if (mode == REMOTE && (!itr->path.empty() || itr->url.empty()))
|
||||
ok = false;
|
||||
|
||||
if (mode == LASTOPEN && itr->last.empty())
|
||||
ok = false;
|
||||
|
||||
if (atoi(itr->size.c_str()) > maxSize * 1024 * 1024)
|
||||
ok = false;
|
||||
|
||||
if (ok == true)
|
||||
this->bookIdList.push_back(itr->id);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ namespace kiwix {
|
|||
unsigned int getBookCount(const bool localBooks, const bool remoteBooks);
|
||||
bool updateBookLastOpenDateById(const string id);
|
||||
void removeBookPaths();
|
||||
bool listBooks(const supportedListMode mode, const supportedListSortBy sortBy);
|
||||
bool listBooks(const supportedListMode mode, const supportedListSortBy sortBy, const unsigned int maxSize);
|
||||
|
||||
string writableLibraryPath;
|
||||
|
||||
|
|
Loading…
Reference in New Issue