From 0f3c1e28883323aa677a02bf43c677ca9f91e891 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Mon, 10 Oct 2011 17:05:36 +0000 Subject: [PATCH] + filter by size --- src/common/kiwix/library.cpp | 2 +- src/common/kiwix/manager.cpp | 44 ++++++++++++++++++++---------------- src/common/kiwix/manager.h | 2 +- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/common/kiwix/library.cpp b/src/common/kiwix/library.cpp index 60bd28ebc..503c9e3cc 100644 --- a/src/common/kiwix/library.cpp +++ b/src/common/kiwix/library.cpp @@ -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) { diff --git a/src/common/kiwix/manager.cpp b/src/common/kiwix/manager.cpp index c6f1b6e49..a29615320 100644 --- a/src/common/kiwix/manager.cpp +++ b/src/common/kiwix/manager.cpp @@ -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::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; } diff --git a/src/common/kiwix/manager.h b/src/common/kiwix/manager.h index c98e0495c..2fb12bf0a 100644 --- a/src/common/kiwix/manager.h +++ b/src/common/kiwix/manager.h @@ -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;