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) {
|
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) {
|
bool Book::sortBySize(const kiwix::Book &a, const kiwix::Book &b) {
|
||||||
|
|
|
@ -403,7 +403,7 @@ namespace kiwix {
|
||||||
return result;
|
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();
|
this->bookIdList.clear();
|
||||||
std::vector<kiwix::Book>::iterator itr;
|
std::vector<kiwix::Book>::iterator itr;
|
||||||
|
|
||||||
|
@ -418,25 +418,29 @@ namespace kiwix {
|
||||||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByPublisher);
|
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);
|
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByLastOpen);
|
||||||
|
|
||||||
|
/* Generate the list of book id */
|
||||||
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||||
if (!itr->last.empty())
|
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);
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ namespace kiwix {
|
||||||
unsigned int getBookCount(const bool localBooks, const bool remoteBooks);
|
unsigned int getBookCount(const bool localBooks, const bool remoteBooks);
|
||||||
bool updateBookLastOpenDateById(const string id);
|
bool updateBookLastOpenDateById(const string id);
|
||||||
void removeBookPaths();
|
void removeBookPaths();
|
||||||
bool listBooks(const supportedListMode mode, const supportedListSortBy sortBy);
|
bool listBooks(const supportedListMode mode, const supportedListSortBy sortBy, const unsigned int maxSize);
|
||||||
|
|
||||||
string writableLibraryPath;
|
string writableLibraryPath;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue