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() {
|
Book::~Book() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Sort functions */
|
||||||
bool Book::sortByLastOpen(const kiwix::Book &a, const kiwix::Book &b) {
|
bool Book::sortByLastOpen(const kiwix::Book &a, const kiwix::Book &b) {
|
||||||
return atoi(a.last.c_str()) > atoi(b.last.c_str());
|
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 */
|
/* Constructor */
|
||||||
Library::Library():
|
Library::Library():
|
||||||
current(""),
|
current(""),
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#define KIWIX_LIBRARY_VERSION "20110515"
|
#define KIWIX_LIBRARY_VERSION "20110515"
|
||||||
|
@ -40,6 +41,10 @@ namespace kiwix {
|
||||||
~Book();
|
~Book();
|
||||||
|
|
||||||
static bool sortByLastOpen(const Book &a, const Book &b);
|
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 id;
|
||||||
string path;
|
string path;
|
||||||
|
|
|
@ -403,10 +403,21 @@ namespace kiwix {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::listBooks(const supportedListMode mode) {
|
bool Manager::listBooks(const supportedListMode mode, const supportedListSortBy sortBy) {
|
||||||
this->bookIdList.clear();
|
this->bookIdList.clear();
|
||||||
std::vector<kiwix::Book>::iterator itr;
|
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) {
|
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);
|
||||||
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||||
|
|
|
@ -39,6 +39,7 @@ using namespace std;
|
||||||
namespace kiwix {
|
namespace kiwix {
|
||||||
|
|
||||||
enum supportedListMode { LASTOPEN, REMOTE, LOCAL };
|
enum supportedListMode { LASTOPEN, REMOTE, LOCAL };
|
||||||
|
enum supportedListSortBy { TITLE, SIZE, DATE, PUBLISHER };
|
||||||
|
|
||||||
class Manager {
|
class Manager {
|
||||||
|
|
||||||
|
@ -61,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);
|
bool listBooks(const supportedListMode mode, const supportedListSortBy sortBy);
|
||||||
|
|
||||||
string writableLibraryPath;
|
string writableLibraryPath;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue