Skip to content

Commit

Permalink
Added ability to load external books
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLazarescu committed Feb 26, 2024
1 parent 95c8f64 commit 33a2319
Show file tree
Hide file tree
Showing 21 changed files with 525 additions and 82 deletions.
3 changes: 2 additions & 1 deletion librum.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
Type=Application
Name=Librum
GenericName=E-Book Reader
MimeType=application/pdf
Comment=A modern ebook reader and library manager
Comment[fr]=Un lecteur de livres et un gestionnaire de bibliothèque moderne
Comment[de]=Ein moderner E-Book-Reader und Bibliotheksmanager
Exec=librum
Exec=librum %f
Icon=librum
Terminal=false
Categories=Education;Viewer;Printing;Literature;Qt;
Expand Down
2 changes: 2 additions & 0 deletions src/adapters/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ add_library(adapters
controllers/ai_explanation_controller.hpp
controllers/folder_controller.hpp
controllers/folder_controller.cpp
controllers/external_book_controller.hpp
controllers/external_book_controller.cpp

gateways/user_storage_gateway.cpp
gateways/user_storage_gateway.hpp
Expand Down
11 changes: 8 additions & 3 deletions src/adapters/controllers/book_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
#include "fz_utils.hpp"
#include "highlight.hpp"
#include "i_book_service.hpp"
#include "library_book_getter.hpp"
#include "search_options.hpp"

using namespace application::core;
using application::utility::LibraryBookGetter;
using domain::entities::Bookmark;
using domain::entities::Highlight;

namespace adapters::controllers
{

BookController::BookController(application::IBookService* bookService) :
m_bookService(bookService)
BookController::BookController(application::IBookService* bookService,
application::ILibraryService* libraryService) :
m_bookService(bookService),
m_libraryService(libraryService)
{
connect(m_bookService, &application::IBookService::goToPosition, this,
&BookController::goToPosition);
Expand All @@ -36,7 +40,8 @@ BookController::BookController(application::IBookService* bookService) :

void BookController::setUp(QString uuid)
{
m_bookService->setUp(QUuid(uuid));
m_bookService->setUp(
std::make_unique<LibraryBookGetter>(m_libraryService, QUuid(uuid)));

m_bookmarksModel = std::make_unique<data_models::BookmarksModel>(
QUuid(uuid), m_bookService);
Expand Down
5 changes: 4 additions & 1 deletion src/adapters/controllers/book_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "bookmarks_model.hpp"
#include "i_book_controller.hpp"
#include "i_book_service.hpp"
#include "i_library_service.hpp"
#include "search_options.hpp"
#include "toc/filtered_toc_model.hpp"

Expand All @@ -17,7 +18,8 @@ class ADAPTERS_EXPORT BookController : public IBookController
Q_OBJECT

public:
BookController(application::IBookService* bookService);
BookController(application::IBookService* bookService,
application::ILibraryService* libraryService);

void setUp(QString uuid) override;
mupdf::FzDocument* getFzDocument() override;
Expand Down Expand Up @@ -69,6 +71,7 @@ class ADAPTERS_EXPORT BookController : public IBookController

private:
application::IBookService* m_bookService;
application::ILibraryService* m_libraryService;
application::core::utils::SearchOptions m_searchOptions;

std::unique_ptr<data_models::BookmarksModel> m_bookmarksModel;
Expand Down
225 changes: 225 additions & 0 deletions src/adapters/controllers/external_book_controller.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
#include "external_book_controller.hpp"
#include <QUuid>
#include <memory>
#include "bookmark.hpp"
#include "external_book_getter.hpp"
#include "fz_utils.hpp"
#include "highlight.hpp"
#include "i_book_service.hpp"
#include "search_options.hpp"

using namespace application::core;
using application::utility::ExternalBookGetter;
using domain::entities::Bookmark;
using domain::entities::Highlight;

namespace adapters::controllers
{

ExternalBookController::ExternalBookController(
application::IBookService* bookService) :
m_externalBookService(bookService)
{
connect(m_externalBookService, &application::IBookService::goToPosition,
this, &ExternalBookController::goToPosition);

connect(m_externalBookService, &application::IBookService::highlightText,
this,
[this](int pageNumber, mupdf::FzQuad quad)
{
auto rect = utils::fzQuadToQRectF(quad);
QPointF left(rect.left(), rect.center().y());
QPointF right(rect.right(), rect.center().y());

emit selectText(pageNumber, left, right);
});

connect(m_externalBookService,
&application::IBookService::noSearchHitsFound, this,
&IBookController::noSearchHitsFound);
}

void ExternalBookController::setUp(QString filePath)
{
m_externalBookService->setUp(
std::make_unique<ExternalBookGetter>(filePath));
}

mupdf::FzDocument* ExternalBookController::getFzDocument()
{
return m_externalBookService->getFzDocument();
}

void ExternalBookController::search(const QString& text)
{
m_externalBookService->search(text, m_searchOptions);
}

void ExternalBookController::clearSearch()
{
m_externalBookService->clearSearch();
}

void ExternalBookController::goToNextSearchHit()
{
m_externalBookService->goToNextSearchHit();
}

void ExternalBookController::goToPreviousSearchHit()
{
m_externalBookService->goToPreviousSearchHit();
}

const QList<Highlight>& ExternalBookController::getHighlights() const
{
}

void ExternalBookController::addHighlight(const Highlight& highlight)
{
Q_UNUSED(highlight);
}

void ExternalBookController::removeHighlight(const QUuid& uuid)
{
Q_UNUSED(uuid);
}

void ExternalBookController::changeHighlightColor(const QUuid& uuid,
const QColor& color)
{
Q_UNUSED(uuid);
Q_UNUSED(color);
}

const Highlight* ExternalBookController::getHighlightAtPoint(
const QPointF& point, int page) const
{
Q_UNUSED(point);
Q_UNUSED(page);

return nullptr;
}

const QList<Bookmark>& ExternalBookController::getBookmark() const
{
}

QString ExternalBookController::addBookmark(const QString& name, int pageNumber,
float yOffset)
{
Q_UNUSED(name);
Q_UNUSED(pageNumber);
Q_UNUSED(yOffset);
}

void ExternalBookController::renameBookmark(const QString& uuid,
const QString& newName)
{
Q_UNUSED(uuid);
Q_UNUSED(newName);
}

void ExternalBookController::removeBookmark(const QString& uuid)
{
Q_UNUSED(uuid);
}

void ExternalBookController::goToBookmark(const QString& uuid)
{
Q_UNUSED(uuid);
}

void ExternalBookController::followLink(const char* uri)
{
return m_externalBookService->followLink(uri);
}

QString ExternalBookController::getFilePath() const
{
return m_externalBookService->getFilePath();
}

int ExternalBookController::getPageCount() const
{
return m_externalBookService->getPageCount();
}

void ExternalBookController::setCurrentPage(int newCurrentPage)
{
m_externalBookService->setCurrentPage(newCurrentPage);
m_searchOptions.currentPage = m_externalBookService->getCurrentPage();

emit currentPageChanged(newCurrentPage);
}

int ExternalBookController::getCurrentPage() const
{
return m_externalBookService->getCurrentPage();
}

float ExternalBookController::getZoom() const
{
return m_externalBookService->getZoom();
}

void ExternalBookController::setZoom(float newZoom)
{
m_externalBookService->setZoom(newZoom);
emit zoomChanged(newZoom);
}

bool ExternalBookController::getSearchWholeWords() const
{
return m_searchOptions.wholeWords;
}

void ExternalBookController::setSearchWholeWords(bool newSearchWholeWords)
{
m_searchOptions.wholeWords = newSearchWholeWords;
emit searchWholeWordsChanged();
}

bool ExternalBookController::getSearchCaseSensitive() const
{
return m_searchOptions.caseSensitive;
}

void ExternalBookController::setSearchCaseSensitive(bool newCaseSensitive)
{
m_searchOptions.caseSensitive = newCaseSensitive;
emit searchCaseSensitiveChanged();
}

bool ExternalBookController::getSearchFromStart() const
{
return m_searchOptions.fromStart;
}

void ExternalBookController::setSearchFromStart(bool newSearchFromStart)
{
m_searchOptions.fromStart = newSearchFromStart;
emit searchFromStartChanged();
}

QString ExternalBookController::getColorTheme()
{
return m_externalBookService->getColorTheme();
}

void ExternalBookController::setColorTheme(const QString& colorTheme)
{
m_externalBookService->setColorTheme(colorTheme);
emit colorThemeChanged(colorTheme);
}

FilteredTOCModel* ExternalBookController::getTableOfContents()
{
return m_externalBookService->getTableOfContents();
}

data_models::BookmarksProxyModel* ExternalBookController::getBookmarksModel()
{
return nullptr;
}

} // namespace adapters::controllers
81 changes: 81 additions & 0 deletions src/adapters/controllers/external_book_controller.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#pragma once
#include <QObject>
#include <QRectF>
#include <QString>
#include "adapters_export.hpp"
#include "bookmarks_model.hpp"
#include "i_book_controller.hpp"
#include "i_book_service.hpp"
#include "search_options.hpp"
#include "toc/filtered_toc_model.hpp"

namespace adapters::controllers
{

/***
* This class implements the IBookController interface to provide access to a
* book that is not managed by the application, a so called 'external book'.
*
* This usecase occurs when e.g. using 'Open with Librum' from a file manager.
*/
class ADAPTERS_EXPORT ExternalBookController : public IBookController
{
Q_OBJECT

public:
ExternalBookController(application::IBookService* externalBookService);

void setUp(QString filePath) override;
mupdf::FzDocument* getFzDocument() override;

void search(const QString& text) override;
void clearSearch() override;
void goToNextSearchHit() override;
void goToPreviousSearchHit() override;

const QList<domain::entities::Highlight>& getHighlights() const override;
void addHighlight(const domain::entities::Highlight& highlight) override;
void removeHighlight(const QUuid& uuid) override;
void changeHighlightColor(const QUuid& uuid, const QColor& color) override;
const domain::entities::Highlight* getHighlightAtPoint(
const QPointF& point, int page) const override;

const QList<domain::entities::Bookmark>& getBookmark() const override;
QString addBookmark(const QString& name, int pageNumber,
float yOffset) override;
void renameBookmark(const QString& uuid, const QString& newName) override;
void removeBookmark(const QString& uuid) override;
void goToBookmark(const QString& uuid) override;

void followLink(const char* uri) override;

QString getFilePath() const override;
int getPageCount() const override;

void setCurrentPage(int newCurrentPage) override;
int getCurrentPage() const override;

float getZoom() const override;
void setZoom(float newZoom) override;

bool getSearchWholeWords() const override;
void setSearchWholeWords(bool newSearchWholeWords) override;

bool getSearchCaseSensitive() const override;
void setSearchCaseSensitive(bool newCaseSensitive) override;

bool getSearchFromStart() const override;
void setSearchFromStart(bool newSearchFromStart) override;

QString getColorTheme() override;
void setColorTheme(const QString& colorTheme) override;

application::core::FilteredTOCModel* getTableOfContents() override;
data_models::BookmarksProxyModel* getBookmarksModel() override;

private:
application::IBookService* m_externalBookService;
application::core::utils::SearchOptions m_searchOptions;
};

} // namespace adapters::controllers
2 changes: 1 addition & 1 deletion src/adapters/interfaces/controllers/i_book_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ADAPTERS_EXPORT IBookController : public QObject
public:
virtual ~IBookController() noexcept = default;

Q_INVOKABLE virtual void setUp(QString uuid) = 0;
Q_INVOKABLE virtual void setUp(QString filePath) = 0;
virtual mupdf::FzDocument* getFzDocument() = 0;

Q_INVOKABLE virtual void search(const QString& text) = 0;
Expand Down
Loading

0 comments on commit 33a2319

Please sign in to comment.