mirror of https://github.com/kiwix/libkiwix.git
+ last imp. in the new content manager
This commit is contained in:
parent
ca1713d609
commit
e05dd65111
|
@ -43,6 +43,10 @@ namespace kiwix {
|
||||||
Book::~Book() {
|
Book::~Book() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Book::sortByLastOpen(const kiwix::Book &a, const kiwix::Book &b) {
|
||||||
|
return atoi(a.last.c_str()) > atoi(b.last.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
/* Constructor */
|
/* Constructor */
|
||||||
Library::Library():
|
Library::Library():
|
||||||
current(""),
|
current(""),
|
||||||
|
|
|
@ -20,11 +20,13 @@
|
||||||
#ifndef KIWIX_LIBRARY_H
|
#ifndef KIWIX_LIBRARY_H
|
||||||
#define KIWIX_LIBRARY_H
|
#define KIWIX_LIBRARY_H
|
||||||
|
|
||||||
#define KIWIX_LIBRARY_VERSION "20110503"
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#define KIWIX_LIBRARY_VERSION "20110503"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace kiwix {
|
namespace kiwix {
|
||||||
|
@ -37,6 +39,8 @@ namespace kiwix {
|
||||||
Book();
|
Book();
|
||||||
~Book();
|
~Book();
|
||||||
|
|
||||||
|
static bool sortByLastOpen(const Book &a, const Book &b);
|
||||||
|
|
||||||
string id;
|
string id;
|
||||||
string path;
|
string path;
|
||||||
string last;
|
string last;
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace kiwix {
|
||||||
book.readOnly = readOnly;
|
book.readOnly = readOnly;
|
||||||
book.id = bookNode.attribute("id").value();
|
book.id = bookNode.attribute("id").value();
|
||||||
book.path = bookNode.attribute("path").value();
|
book.path = bookNode.attribute("path").value();
|
||||||
book.last = bookNode.attribute("last").value();
|
book.last = bookNode.attribute("last").value() != "undefined" ? bookNode.attribute("last").value() : "";
|
||||||
book.indexPath = bookNode.attribute("indexPath").value();
|
book.indexPath = bookNode.attribute("indexPath").value();
|
||||||
book.indexType = bookNode.attribute("indexType").value() == "xapian" ? XAPIAN : CLUCENE;
|
book.indexType = bookNode.attribute("indexType").value() == "xapian" ? XAPIAN : CLUCENE;
|
||||||
book.title = bookNode.attribute("title").value();
|
book.title = bookNode.attribute("title").value();
|
||||||
|
@ -99,8 +99,9 @@ namespace kiwix {
|
||||||
bookNode.append_attribute("id") = itr->id.c_str();
|
bookNode.append_attribute("id") = itr->id.c_str();
|
||||||
bookNode.append_attribute("path") = itr->path.c_str();
|
bookNode.append_attribute("path") = itr->path.c_str();
|
||||||
|
|
||||||
if (itr->last != "")
|
if (itr->last != "" && itr->last != "undefined") {
|
||||||
bookNode.append_attribute("last") = itr->last.c_str();
|
bookNode.append_attribute("last") = itr->last.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
if (itr->indexPath != "") {
|
if (itr->indexPath != "") {
|
||||||
bookNode.append_attribute("indexPath") = itr->indexPath.c_str();
|
bookNode.append_attribute("indexPath") = itr->indexPath.c_str();
|
||||||
|
@ -219,4 +220,43 @@ namespace kiwix {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Manager::updateBookLastOpenDateById(const string id) {
|
||||||
|
std::vector<kiwix::Book>::iterator itr;
|
||||||
|
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||||
|
if ( itr->id == id) {
|
||||||
|
char unixdate[12];
|
||||||
|
sprintf (unixdate, "%d", (int)time(NULL));
|
||||||
|
itr->last = unixdate;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Manager::listBooks(const supportedListMode mode) {
|
||||||
|
this->bookIdList.clear();
|
||||||
|
std::vector<kiwix::Book>::iterator itr;
|
||||||
|
|
||||||
|
if (mode == LASTOPEN) {
|
||||||
|
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByLastOpen);
|
||||||
|
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||||
|
this->bookIdList.push_back(itr->id);
|
||||||
|
}
|
||||||
|
} else if (mode == REMOTE) {
|
||||||
|
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||||
|
if (itr->path == "")
|
||||||
|
this->bookIdList.push_back(itr->id);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||||
|
if (itr->path != "")
|
||||||
|
this->bookIdList.push_back(itr->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,12 +24,15 @@
|
||||||
#include <kiwix/reader.h>
|
#include <kiwix/reader.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "time.h"
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace kiwix {
|
namespace kiwix {
|
||||||
|
|
||||||
|
enum supportedListMode { LASTOPEN, REMOTE, LOCAL };
|
||||||
|
|
||||||
class Manager {
|
class Manager {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -45,13 +48,17 @@ namespace kiwix {
|
||||||
bool addBookFromPath(const string path, const string url = "");
|
bool addBookFromPath(const string path, const string url = "");
|
||||||
Library cloneLibrary();
|
Library cloneLibrary();
|
||||||
bool getBookById(const string id, Book &book);
|
bool getBookById(const string id, Book &book);
|
||||||
|
bool updateBookLastOpenDateById(const string id);
|
||||||
|
bool listBooks(const supportedListMode);
|
||||||
|
|
||||||
string writableLibraryPath;
|
string writableLibraryPath;
|
||||||
|
|
||||||
|
vector <std::string> bookIdList;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
kiwix::Library library;
|
kiwix::Library library;
|
||||||
|
|
||||||
bool readBookFromPath(const string path, kiwix::Book &book);
|
bool readBookFromPath(const string path, Book &book);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue