mirror of https://github.com/kiwix/libkiwix.git
+ content manager sortBy
This commit is contained in:
parent
8f43bcc954
commit
d11f027fbe
|
@ -45,10 +45,27 @@ namespace kiwix {
|
|||
Book::~Book() {
|
||||
}
|
||||
|
||||
/* Sort functions */
|
||||
bool Book::sortByLastOpen(const kiwix::Book &a, const kiwix::Book &b) {
|
||||
return atoi(a.last.c_str()) > atoi(b.last.c_str());
|
||||
}
|
||||
|
||||
bool Book::sortByTitle(const kiwix::Book &a, const kiwix::Book &b) {
|
||||
return strcmp(a.title.c_str(), b.title.c_str()) < 0;
|
||||
}
|
||||
|
||||
bool Book::sortByDate(const kiwix::Book &a, const kiwix::Book &b) {
|
||||
return atoi(a.date.c_str()) < atoi(b.date.c_str());
|
||||
}
|
||||
|
||||
bool Book::sortBySize(const kiwix::Book &a, const kiwix::Book &b) {
|
||||
return atoi(a.size.c_str()) < atoi(b.size.c_str());
|
||||
}
|
||||
|
||||
bool Book::sortByPublisher(const kiwix::Book &a, const kiwix::Book &b) {
|
||||
return strcmp(a.creator.c_str(), b.creator.c_str()) < 0;
|
||||
}
|
||||
|
||||
/* Constructor */
|
||||
Library::Library():
|
||||
current(""),
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
|
||||
#define KIWIX_LIBRARY_VERSION "20110515"
|
||||
|
@ -40,6 +41,10 @@ namespace kiwix {
|
|||
~Book();
|
||||
|
||||
static bool sortByLastOpen(const Book &a, const Book &b);
|
||||
static bool sortByTitle(const Book &a, const Book &b);
|
||||
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);
|
||||
|
||||
string id;
|
||||
string path;
|
||||
|
|
|
@ -403,10 +403,21 @@ namespace kiwix {
|
|||
return result;
|
||||
}
|
||||
|
||||
bool Manager::listBooks(const supportedListMode mode) {
|
||||
bool Manager::listBooks(const supportedListMode mode, const supportedListSortBy sortBy) {
|
||||
this->bookIdList.clear();
|
||||
std::vector<kiwix::Book>::iterator itr;
|
||||
|
||||
/* Sort */
|
||||
if (sortBy == TITLE) {
|
||||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByTitle);
|
||||
} else if (sortBy == SIZE) {
|
||||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortBySize);
|
||||
} else if (sortBy == DATE) {
|
||||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByDate);
|
||||
} else if (sortBy == PUBLISHER) {
|
||||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByPublisher);
|
||||
}
|
||||
|
||||
if (mode == LASTOPEN) {
|
||||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByLastOpen);
|
||||
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||
|
|
|
@ -39,6 +39,7 @@ using namespace std;
|
|||
namespace kiwix {
|
||||
|
||||
enum supportedListMode { LASTOPEN, REMOTE, LOCAL };
|
||||
enum supportedListSortBy { TITLE, SIZE, DATE, PUBLISHER };
|
||||
|
||||
class Manager {
|
||||
|
||||
|
@ -61,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);
|
||||
bool listBooks(const supportedListMode mode, const supportedListSortBy sortBy);
|
||||
|
||||
string writableLibraryPath;
|
||||
|
||||
|
|
Loading…
Reference in New Issue