From 50c6004204360701cf6bdfff3bb1da48c77750bd Mon Sep 17 00:00:00 2001 From: kelson42 Date: Wed, 11 Sep 2013 20:38:57 +0200 Subject: [PATCH] + useless --- src/contentManager/ContentManagerWrapper.cpp | 215 ------------- src/contentManager/ContentManagerWrapper.h | 52 ---- src/contentManager/Makefile | 21 -- src/contentManager/contentCTester.c | 137 --------- src/contentManager/contentManager.cpp | 303 ------------------- src/contentManager/contentManager.h | 37 --- src/contentManager/contentManagerTester.cpp | 143 --------- 7 files changed, 908 deletions(-) delete mode 100644 src/contentManager/ContentManagerWrapper.cpp delete mode 100644 src/contentManager/ContentManagerWrapper.h delete mode 100644 src/contentManager/Makefile delete mode 100644 src/contentManager/contentCTester.c delete mode 100644 src/contentManager/contentManager.cpp delete mode 100644 src/contentManager/contentManager.h delete mode 100644 src/contentManager/contentManagerTester.cpp diff --git a/src/contentManager/ContentManagerWrapper.cpp b/src/contentManager/ContentManagerWrapper.cpp deleted file mode 100644 index b3399f6..0000000 --- a/src/contentManager/ContentManagerWrapper.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright 2011 Renaud Gaudin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -#include -#include -#include -#include "ContentManagerWrapper.h" -#include "contentManager.h" - -/* creates instance of ContentManager */ -HCONTCLASS ContentManager_Create( void ) { - ContentManager * contentManager = new ContentManager(0); - - // Return its pointer (opaque) - return (HCONTCLASS)contentManager; -} - -/* Delete instance of ZimAccessor */ -void ContentManager_Destroy( HCONTCLASS h ) { - assert(h != NULL); - - // Convert from handle to ContentManager pointer - ContentManager * contentManager = (ContentManager *)h; - - delete contentManager; -} - -int ContentManager_OpenLibraryFromFile( HCONTCLASS h, char* path, int readOnly) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - return contentManager->OpenLibraryFromFile( string(path), readOnly ); -} - -int ContentManager_OpenLibraryFromText( HCONTCLASS h, char* xml, int readOnly) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - string xml_str = string(xml); - return contentManager->OpenLibraryFromText( xml_str, readOnly ); -} - -int ContentManager_WriteLibrary( HCONTCLASS h) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - return contentManager->WriteLibrary(); -} - -int ContentManager_WriteLibraryToFile( HCONTCLASS h, char* path) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - string path_str = string(path); - return contentManager->WriteLibraryToFile( path_str ); -} - -int ContentManager_AddBookFromPath( HCONTCLASS h, char* path) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - string path_str = string(path); - return contentManager->AddBookFromPath( path_str ); -} - -int ContentManager_RemoveBookById( HCONTCLASS h, char* id) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - string id_str = string(id); - return contentManager->RemoveBookById( id_str ); -} - -int ContentManager_SetCurrentBookId( HCONTCLASS h, char* id) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - string id_str = string(id); - return contentManager->SetCurrentBookId( id_str ); -} - -const char* ContentManager_GetCurrentBookId( HCONTCLASS h ) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - string id_str = contentManager->GetCurrentBookId(); - return id_str.c_str(); -} - -CMBook ContentManager_GetBookById( HCONTCLASS h, char* id ) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - CMBook book; - string path, title, indexPath, indexType, description, articleCount, mediaCount, size, creator, date, language, favicon, url; - string id_str = string(id); - - contentManager->GetBookById(id_str, path, title, indexPath, indexType, description, articleCount, mediaCount, size, creator, date, language, favicon, url); - book.path = path.c_str(); - book.title = title.c_str(); - book.indexPath = indexPath.c_str(); - book.indexType = indexType.c_str(); - book.description = description.c_str(); - book.articleCount = articleCount.c_str(); - book.mediaCount = mediaCount.c_str(); - book.size = size.c_str(); - book.creator = creator.c_str(); - book.date = date.c_str(); - book.language = language.c_str(); - book.favicon = favicon.c_str(); - book.url = url.c_str(); - return book; -} - -int ContentManager_UpdateBookLastOpenDateById( HCONTCLASS h, char* id) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - string id_str = string(id); - return contentManager->UpdateBookLastOpenDateById( id_str ); -} - -unsigned int ContentManager_GetBookCount( HCONTCLASS h, int remote, int local) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - return contentManager->GetBookCount( remote, local ); -} - -const char* ContentManager_GetListNextBookId( HCONTCLASS h) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - return contentManager->GetListNextBookId(); -} - -int ContentManager_SetBookIndex( HCONTCLASS h, char* id, char* path, char* type) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - string id_str = string(id); - string path_str = string(path); - string type_str = string(type); - return contentManager->SetBookIndex( id_str, path_str, type_str ); -} - -int ContentManager_SetBookPath( HCONTCLASS h, char* id, char* path) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - string id_str = string(id); - string path_str = string(path); - return contentManager->SetBookPath( id_str, path_str ); -} - -const char* ContentManager_GetBooksLanguages( HCONTCLASS h ) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - string languages = contentManager->GetBooksLanguages(); - return languages.c_str(); -} - -const char* ContentManager_GetBooksPublishers( HCONTCLASS h ) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - string publishers = contentManager->GetBooksPublishers(); - return publishers.c_str(); -} - -int ContentManager_ListBooks( HCONTCLASS h, char* mode, char* sortBy, unsigned int maxSize, char* language, char* publisher, char* search ) { - assert(h != NULL); - - ContentManager * contentManager = (ContentManager *)h; - - string mode_str = string(mode); - string sort_str = string(sortBy); - string lang_str = string(language); - string pub_str = string(publisher); - string search_str = string(search); - return contentManager->ListBooks( mode_str, sort_str, maxSize, lang_str, pub_str, search_str ); -} diff --git a/src/contentManager/ContentManagerWrapper.h b/src/contentManager/ContentManagerWrapper.h deleted file mode 100644 index 93ca57b..0000000 --- a/src/contentManager/ContentManagerWrapper.h +++ /dev/null @@ -1,52 +0,0 @@ - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -typedef void * HCONTCLASS; - -typedef struct { - const char* path; - const char* title; - const char* indexPath; - const char* indexType; - const char* description; - const char* articleCount; - const char* mediaCount; - const char* size; - const char* creator; - const char* date; - const char* language; - const char* favicon; - const char* url; -} CMBook; - -HCONTCLASS ContentManager_Create( void ); - -void ContentManager_Destroy( HCONTCLASS h ); - -int ContentManager_OpenLibraryFromFile( HCONTCLASS h, char* path, int readOnly ); -int ContentManager_OpenLibraryFromText( HCONTCLASS h, char* xml, int readOnly ); -int ContentManager_WriteLibrary( HCONTCLASS h ); -int ContentManager_WriteLibraryToFile( HCONTCLASS h, char* path ); -int ContentManager_AddBookFromPath( HCONTCLASS h, char* path ); -int ContentManager_RemoveBookById( HCONTCLASS h, char* id ); -int ContentManager_SetCurrentBookId( HCONTCLASS h, char* id ); -const char* ContentManager_GetCurrentBookId( HCONTCLASS h ); -CMBook ContentManager_GetBookById( HCONTCLASS h, char* id ); -int ContentManager_UpdateBookLastOpenDateById( HCONTCLASS h, char* id ); -unsigned int ContentManager_GetBookCount(HCONTCLASS h, int remote, int local ); -const char* ContentManager_GetListNextBookId( HCONTCLASS h ); -int ContentManager_SetBookIndex( HCONTCLASS h, char* id, char* path, char* type ); -int ContentManager_SetBookPath( HCONTCLASS h, char* id, char* path ); -const char* ContentManager_GetBooksLanguages( HCONTCLASS h ); -const char* ContentManager_GetBooksPublishers( HCONTCLASS h ); -int ContentManager_ListBooks( HCONTCLASS h, char* mode, char* sortBy, unsigned int maxSize, char* language, char* publisher, char* search ); - -#ifdef __cplusplus -}; -#endif diff --git a/src/contentManager/Makefile b/src/contentManager/Makefile deleted file mode 100644 index 4f4d27c..0000000 --- a/src/contentManager/Makefile +++ /dev/null @@ -1,21 +0,0 @@ - -all: contentTester - -wrapperlib: - g++ -shared ContentManagerWrapper.cpp -o libContentCManager.so contentManager.cpp ../common/kiwix/library.cpp ../common/kiwix/manager.cpp ../common/kiwix/reader.cpp ../common/base64.cpp ../common/pathTools.cpp ../common/componentTools.cpp ../common/regexTools.cpp ../common/kiwix/library.h ../common/kiwix/manager.h ../common/kiwix/reader.h ../pugixml/pugixml.hpp ../common/base64.h ../common/pathTools.h ../common/componentTools.h ../common/regexTools.h -I . -I ../common/ -I ../pugixml/ -I ../zimlib/include/ -I /usr/include/ -L ../zimlib/src/.libs/ -lzim ../pugixml/.libs/libpugixml.a ../dependences/xz/src/liblzma/.libs/liblzma.a - -contentTester: - g++ contentManagerTester.cpp contentManager.cpp ../common/kiwix/library.cpp ../common/kiwix/manager.cpp ../common/kiwix/reader.cpp ../common/base64.cpp ../common/pathTools.cpp ../common/componentTools.cpp ../common/regexTools.cpp ../common/kiwix/library.h ../common/kiwix/manager.h ../common/kiwix/reader.h ../pugixml/pugixml.hpp ../common/base64.h ../common/pathTools.h ../common/componentTools.h ../common/regexTools.h -o contentTester -I ../common/ -I ../pugixml/ -I ../zimlib/include/ -I /usr/include/ -L ../zimlib/src/.libs/ -lzim ../pugixml/.libs/libpugixml.a ../dependences/xz/src/liblzma/.libs/liblzma.a - -contentCTester: wrapperlib - gcc -o contentCTester contentCTester.c -I . -L . -lContentCManager -ldl -lm -L/usr/lib -licui18n -licuuc -licudata -ldl -lm - -cleanc: - find . -name 'contentCTester' -delete - -cleancpp: - find . -name 'contentTester' -delete - -clean: cleanc cleancpp - find . -name 'libContentCManager.so' -delete - find . -name '*.o' -delete diff --git a/src/contentManager/contentCTester.c b/src/contentManager/contentCTester.c deleted file mode 100644 index b69bf11..0000000 --- a/src/contentManager/contentCTester.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright 2011 Renaud Gaudin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -#include -#include -#include "ContentManagerWrapper.h" - - -int main(int argc, char* argv[]) -{ - if (argc < 2) { - printf("Usage: %s zimPath\n", argv[0]); - printf("No ZIM file path provided.\n"); - exit(0); - } - char* zimPath = argv[1]; - printf("Content Manager C Tester.\nLoading %s...\n", zimPath); - - HCONTCLASS contM = NULL; - contM = ContentManager_Create(); - if (contM == NULL) { - printf("Error creating ContentManager class\n"); - exit(1); - } - - int readOnly = 1; - if (ContentManager_OpenLibraryFromFile( contM, zimPath, readOnly )) - printf("Successfully opened library from %s\n", zimPath); - else - printf("Unable to open library from %s\n", zimPath); - - char * xmltext = ""; - if (ContentManager_OpenLibraryFromText( contM, xmltext, readOnly )) - printf("Successfully opened library from text.\n"); - else - printf("Unable to open library from text.\n"); - - if (ContentManager_WriteLibrary( contM )) - printf("Successfully wrote library.\n"); - else - printf("Unable to write library\n"); - - char* libPath = "/tmp/totoc"; - if (ContentManager_WriteLibraryToFile( contM, libPath )) - printf("Successfully wrote library to %s\n", libPath); - else - printf("Unable to write library to %s\n", libPath); - - if (ContentManager_AddBookFromPath( contM, zimPath )) - printf("Successfully added book from %s\n", zimPath); - else - printf("Unable to add book from %s\n", zimPath); - - char* bookId = "57b0b7c3-25a5-431e-431e-dce1771ee052963f"; - if (ContentManager_SetCurrentBookId( contM, bookId )) - printf("Successfully set book %s\n", bookId); - else - printf("Unable to set book %s\n", bookId); - - const char* currBookId = ContentManager_GetCurrentBookId( contM ); - printf("Current Book: %s\n", currBookId); - - if (ContentManager_UpdateBookLastOpenDateById( contM, bookId )) - printf("Successfully updated last open date for book %s\n", bookId); - else - printf("Unable to update last open date for book %s\n", bookId); - - unsigned int bookCount = 0; - bookCount = ContentManager_GetBookCount( contM, 1, 1 ); - printf("Book count: %d\n", bookCount); - - char* indexPath = "/home/reg/wksw.index"; - char* indexType = "xapian"; - if (ContentManager_SetBookIndex( contM, bookId, indexPath, indexType )) - printf("Successfully added index for book %s\n", bookId); - else - printf("Unable to add index for book %s\n", bookId); - - if (ContentManager_SetBookPath( contM, bookId, zimPath )) - printf("Successfully set path for book %s\n", bookId); - else - printf("Unable to set path for book %s\n", bookId); - - const char* langs; - langs = ContentManager_GetBooksLanguages( contM ); - printf("Languages: %s\n", langs); - - const char* pubs; - langs = ContentManager_GetBooksPublishers( contM ); - printf("Publishers: %s\n", langs); - - char* mode = "lastOpen"; - char* lsortBy = "size"; - unsigned int lmaxSize = 0; - char* llanguage = ""; - char* lpublisher = ""; - char* lsearch = ""; - if (ContentManager_ListBooks( contM, mode, lsortBy, lmaxSize, llanguage, lpublisher, lsearch )) - printf("Successfully listed books\n"); - else - printf("Unable to list books\n"); - - const char* nextBookId; - nextBookId = ContentManager_GetListNextBookId( contM ); - printf("Next book id: %s\n", nextBookId); - - CMBook book = ContentManager_GetBookById( contM, bookId ); - printf("Book: %s\n\tarticles: %s\n\tlangs: %s\n", book.title, book.articleCount, book.language); - - if (ContentManager_RemoveBookById( contM, bookId )) - printf("Successfully removed book %s\n", bookId); - else - printf("Unable to remove book %s\n", bookId); - - ContentManager_WriteLibraryToFile( contM, libPath ); - - ContentManager_Destroy( contM ); - contM = NULL; - - return 0; -} diff --git a/src/contentManager/contentManager.cpp b/src/contentManager/contentManager.cpp deleted file mode 100644 index 7c45a41..0000000 --- a/src/contentManager/contentManager.cpp +++ /dev/null @@ -1,303 +0,0 @@ -/* - * Copyright 2011 Emmanuel Engelhart - * Copyright 2011 Renaud Gaudin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -#include -#include -#include -#include -#include -#include -#include "contentManager.h" - -ContentManager::ContentManager(int x) : manager() {} - -bool ContentManager::OpenLibraryFromFile(string path, bool readOnly) { - try { - return this->manager.readFile(path, readOnly); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - return true; -} - -bool ContentManager::OpenLibraryFromText(string &xml, bool readOnly) { - - bool returnValue = true; - const char *cXml; - cXml = xml.c_str(); - - try { - return this->manager.readXml(cXml, readOnly); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - - return false; -} - -bool ContentManager::WriteLibrary() { - - try { - return this->manager.writeFile(this->manager.writableLibraryPath); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - - return false; -} - -bool ContentManager::WriteLibraryToFile(string &path) { - - try { - return this->manager.writeFile(path.c_str()); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - - return false; -} - -bool ContentManager::AddBookFromPath(string &path) { - - try { - return this->manager.addBookFromPath(path.c_str(), path); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - - return false; -} - -bool ContentManager::RemoveBookById(string &id) { - - try { - return this->manager.removeBookById(id.c_str()); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - return false; -} - -bool ContentManager::SetCurrentBookId(string &id) { - - try { - return this->manager.setCurrentBookId(id.c_str()); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - - return false; - } - -string ContentManager::GetCurrentBookId() { - string none = ""; - try { - return this->manager.getCurrentBookId(); - } catch (exception &e) { - cerr << e.what() << endl; - return none; - } - - return none; -} - -bool ContentManager::GetBookById(string &id, - string &path, - string &title, - string &indexPath, - string &indexType, - string &description, - string &articleCount, - string &mediaCount, - string &size, - string &creator, - string &date, - string &language, - string &favicon, - string &url) { - - try { - kiwix::Book book; - - if (this->manager.getBookById(id.c_str(), book)) { - path = book.pathAbsolute.data(); - title = book.title.data(); - indexPath = book.indexPathAbsolute.data(); - articleCount = book.articleCount.data(); - mediaCount = book.mediaCount.data(); - size = book.size.data(); - creator = book.creator.data(); - date = book.date.data(); - language = book.language.data(); - url = book.url.data(); - - string faviconUrl = ""; - if (!book.faviconMimeType.empty()) { - faviconUrl = "url(data:" + book.faviconMimeType + ";base64," + book.favicon + ")"; - } - favicon = faviconUrl.data(); - - string indexTypeString = ""; - if (book.indexType == kiwix::XAPIAN) { - indexTypeString = "xapian"; - } else if (book.indexType == kiwix::CLUCENE) { - indexTypeString = "clucene"; - } - indexType = indexTypeString.data(); - - description = book.description.data(); - - return true; - } - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - return false; -} - -bool ContentManager::UpdateBookLastOpenDateById(string &id) { - try { - return this->manager.updateBookLastOpenDateById(id.c_str()); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - - return false; -} - -unsigned int ContentManager::GetBookCount(const bool localBooks, const bool remoteBooks) { - int count = 0; - - try { - return this->manager.getBookCount(localBooks, remoteBooks); - } catch (exception &e) { - cerr << e.what() << endl; - return count; - } - - return count; -} - -bool ContentManager::ListBooks(string &mode, string &sortBy, unsigned int maxSize, - string &language, string &publisher, string &search) { - try { - - // Set the mode enum - kiwix::supportedListMode listMode; - if (mode == "lastOpen") { - listMode = kiwix::LASTOPEN; - } else if ( mode == "remote") { - listMode = kiwix::REMOTE; - } else { - listMode = kiwix::LOCAL; - } - - // Set the sortBy enum - kiwix::supportedListSortBy listSortBy; - if (sortBy == "publisher") { - listSortBy = kiwix::PUBLISHER; - } else if ( sortBy == "date") { - listSortBy = kiwix::DATE; - } else if ( sortBy == "size") { - listSortBy = kiwix::SIZE; - } else { - listSortBy = kiwix::TITLE; - } - - return this->manager.listBooks(listMode, listSortBy, maxSize, language.c_str(), publisher.c_str(), search.c_str()); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - return false; -} - -const char* ContentManager::GetListNextBookId() { - - string id; - try { - if (!this->manager.bookIdList.empty()) { - id = *(this->manager.bookIdList.begin()); - this->manager.bookIdList.erase(this->manager.bookIdList.begin()); - } - } catch (exception &e) { - cerr << e.what() << endl; - } - return id.c_str(); -} - -bool ContentManager::SetBookIndex(string &id, string &path, string &indexType) { - try { - kiwix::supportedIndexType iType; - if (indexType == "clucene") { - iType = kiwix::CLUCENE; - } else { - iType = kiwix::XAPIAN; - } - - return this->manager.setBookIndex(id.c_str(), path.c_str(), iType); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - - return false; -} - -bool ContentManager::SetBookPath(string &id, string &path) { - try { - return this->manager.setBookPath(id.c_str(), path.c_str()); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - return false; -} - -string ContentManager::GetBooksLanguages() { - string languagesStr = ""; - - vector booksLanguages = this->manager.getBooksLanguages(); - vector::iterator itr; - for ( itr = booksLanguages.begin(); itr != booksLanguages.end(); ++itr ) { - languagesStr += *itr + ";"; - } - return languagesStr; -} - -string ContentManager::GetBooksPublishers() { - string publishersStr = ""; - - vector booksPublishers = this->manager.getBooksPublishers(); - vector::iterator itr; - for ( itr = booksPublishers.begin(); itr != booksPublishers.end(); ++itr ) { - publishersStr += *itr + ";"; - } - return publishersStr; -} diff --git a/src/contentManager/contentManager.h b/src/contentManager/contentManager.h deleted file mode 100644 index c6ba26c..0000000 --- a/src/contentManager/contentManager.h +++ /dev/null @@ -1,37 +0,0 @@ - -#include -#include -#include -#include -#include -#include - -class ContentManager -{ - public: - ContentManager(int); - bool OpenLibraryFromFile(string, bool); - bool OpenLibraryFromText(string&, bool); - bool WriteLibrary(); - bool WriteLibraryToFile(string&); - bool AddBookFromPath(string&); - bool RemoveBookById(string&); - bool SetCurrentBookId(string&); - string GetCurrentBookId(); - bool GetBookById(string&, string&, string&, - string&, string&, string&, - string&, string&, string&, - string&, string&, string&, - string&, string&); - bool UpdateBookLastOpenDateById(string&); - unsigned int GetBookCount(bool, bool); - const char* GetListNextBookId(); - bool SetBookIndex(string&, string&, string&); - bool SetBookPath(string&, string&); - string GetBooksLanguages(); - string GetBooksPublishers(); - bool ListBooks(string&, string&, unsigned int, string&, string&, string&); - protected: - kiwix::Manager manager; - -}; diff --git a/src/contentManager/contentManagerTester.cpp b/src/contentManager/contentManagerTester.cpp deleted file mode 100644 index d2a31fa..0000000 --- a/src/contentManager/contentManagerTester.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright 2011 Renaud Gaudin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -#include -#include -#include -#include -#include -#include "contentManager.h" - - -int main(int argc, char* argv[]) -{ - ContentManager cont_man(0); - ContentManager* cont = new ContentManager(0); - - if (argc < 2) { - cout << "Usage: " << argv[0] << " zimPath" << endl << endl; - cout << "No ZIM file path provided." << endl; - exit(0); - } - string zimPath = (string) argv[1]; - cout << "Kiwix Tester." << endl << "Loading " << zimPath << "..." << endl; - - if (cont->OpenLibraryFromFile(zimPath, true)) - cout << "Successfully opened ZIM file." << endl; - else - cout << "Unable to open ZIM file." << endl; - - string xmltext = ""; - if (cont->OpenLibraryFromText(xmltext, true)) - cout << "Successfully opened XML library." << endl; - else - cout << "Unable to open XML library." << endl; - - if (cont->WriteLibrary()) - cout << "Successfully wrote library." << endl; - else - cout << "Unable to write library." << endl; - - if (cont->AddBookFromPath(zimPath)) - cout << "Successfully added book " << zimPath << endl; - else - cout << "Unable to add book " << zimPath << endl; - - string lpath = "/tmp/toto"; - if (cont->WriteLibraryToFile(lpath)) - cout << "Successfully wrote library to " << lpath << endl; - else - cout << "Unable to write library to " << lpath << endl; - - string bookid = "57b0b7c3-25a5-431e-431e-dce1771ee052963f"; - /*if (cont->RemoveBookById(bookid)) - cout << "Successfully removed book " << bookid << endl; - else - cout << "Unable to remove book " << bookid << endl;*/ - - if (cont->SetCurrentBookId(bookid)) - cout << "Successfully set current book " << bookid << endl; - else - cout << "Unable to set current book " << bookid << endl; - - cout << "Current Book ID: " << cont->GetCurrentBookId() << endl; - - if (cont->UpdateBookLastOpenDateById(bookid)) - cout << "Successfully updated last open date for book " << bookid << endl; - else - cout << "Unable to update last open date for book " << bookid << endl; - - cout << "Total book count: " << cont->GetBookCount(true, true) << endl; - - string indexPath = "/home/reg/wksw.index"; - string indexMethod = "xapian"; - if (cont->SetBookIndex(bookid, indexPath, indexMethod)) - cout << "Successfully set index for book " << bookid << endl; - else - cout << "Unable to set index for book " << bookid << endl; - - if (cont->SetBookPath(bookid, zimPath)) - cout << "Successfully set path for book " << bookid << endl; - else - cout << "Unable to set path for book " << bookid << endl; - - cout << "Languages: " << cont->GetBooksLanguages() << endl; - - cout << "Publishers: " << cont->GetBooksPublishers() << endl; - - string id; - string path; - string title; - string rindexPath; - string indexType; - string description; - string articleCount; - string mediaCount; - string size; - string creator; - string date; - string language; - string favicon; - string url; - if (cont->GetBookById(bookid, path, title, rindexPath, indexType, description, articleCount, mediaCount, size, creator, date, language, favicon, url)) { - cout << "Successfully retrieved book " << bookid << endl; - cout << "\ttitle: " << title << endl; - cout << "\tURL: " << url << endl; - cout << "\tarticleCount: " << articleCount << endl; - } else - cout << "Unable to set path for book " << bookid << endl; - - string lmode = "lastOpen"; - string lsortBy = "size"; - unsigned int lmaxSize = 0; - string llanguage = ""; - string lpublisher = ""; - string lsearch = ""; - if (cont->ListBooks(lmode, lsortBy, lmaxSize, llanguage, lpublisher, lsearch)) { - cout << "Successfully listed books" << endl; - cout << "Next Book: " << cont->GetListNextBookId() << endl; - } else - cout << "Unable to list books " << endl; - - cont->WriteLibraryToFile(lpath); - - delete cont; - - return 0; -}