Skip to content

Commit

Permalink
Merge branch 'dev/develop' into feat/booksSelection
Browse files Browse the repository at this point in the history
DavidLazarescu authored Dec 16, 2023

Verified

This commit was signed with the committer’s verified signature.
2 parents 96c806f + 2904e1d commit b31b596
Showing 40 changed files with 2,688 additions and 343 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ jobs:
echo "TEMPORARY WORKAROUND FOR GITHUB RUNNER BUG #8659\n\nRemoving GCC 13 as it breaks Clang14"
sudo rm -f /etc/apt/sources.list.d/ubuntu-toolchain-r-ubuntu-test-jammy.list
sudo apt-get update
sudo apt-get install -y --allow-downgrades libc6=2.35-0ubuntu3.4 libc6-dev=2.35-0ubuntu3.4 libstdc++6=12.3.0-1ubuntu1~22.04 libgcc-s1=12.3.0-1ubuntu1~22.04
sudo apt-get install -y --allow-downgrades libc6=2.35-0ubuntu3.5 libc6-dev=2.35-0ubuntu3.5 libstdc++6=12.3.0-1ubuntu1~22.04 libgcc-s1=12.3.0-1ubuntu1~22.04
- name: Install Qt
uses: jurplel/install-qt-action@v3
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -38,7 +38,28 @@ If you want to build Librum from source, follow the instructions [here](#build-g

# Translations

Do you want to translate Librum into your language? If so, then feel free to reach out to us at [email protected] and we can work on making that happen together!
Librum is currently available in:
- English
- German
- Russian
- Mandarin

If you want to translate Librum to another language, follow the steps below:
- Download the file at: https://github.com/Librum-Reader/Librum/blob/main/src/presentation/translations/librum_en.ts
- Rename the file to contain your language's suffix, e.g. "librum_ru.ts" for Russian or "librum_de.ts" for German
- Download the translation software (Qt Linguist) either for Windows from https://github.com/thurask/Qt-Linguist or using the Qt Installer at https://www.qt.io/download-open-source
- Now start Qt Linguist, open the downloaded file, set the target language to the language you want to translate to and start translating.
(For a quick guide on Qt Linguist, check out: https://youtu.be/xNIz78IPBu0?t=347)

Once you are done, create a pull request or an issue with your new translation file!<br>
If you run into any problems, need guidance or have questions, feel free to reach out to us at: [email protected]

<br>

Notes:
- Make sure that your translations are approximately the same length as the original text
- Make sure that you keep to the punctuation and capitalisation
- Make sure that your translations make sense in the context they are in

<br>

11 changes: 11 additions & 0 deletions scripts/update_translations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# Get the directory of the script
SCRIPT_DIR=$(dirname "$0")

# Find translation files using find command
TRANSLATION_FILES=$(find "$SCRIPT_DIR/../src/presentation/translations" -name "librum_*.ts")

# Use lupdate with the list of translation files
lupdate "$SCRIPT_DIR/../src/presentation" -ts $TRANSLATION_FILES

4 changes: 3 additions & 1 deletion src/adapters/controllers/app_info_controller.cpp
Original file line number Diff line number Diff line change
@@ -145,7 +145,9 @@ bool AppInfoController::switchToLanguage(const QString& language)
return false;
}

if(!QGuiApplication::installTranslator(&m_translator))
// The english translation is empty since it is the default language. Thus
// it causes an error when trying to switch to english. Ignore it.
if(!QGuiApplication::installTranslator(&m_translator) && language != "en")
{
qWarning() << "Failed installing translator for language: " << language;
return false;
11 changes: 11 additions & 0 deletions src/adapters/controllers/book_controller.cpp
Original file line number Diff line number Diff line change
@@ -227,6 +227,17 @@ void BookController::setSearchFromStart(bool newSearchFromStart)
emit searchFromStartChanged();
}

QString BookController::getColorTheme()
{
return m_bookService->getColorTheme();
}

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

FilteredTOCModel* BookController::getTableOfContents()
{
return m_bookService->getTableOfContents();
3 changes: 3 additions & 0 deletions src/adapters/controllers/book_controller.hpp
Original file line number Diff line number Diff line change
@@ -61,6 +61,9 @@ class ADAPTERS_EXPORT BookController : public IBookController
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;

91 changes: 49 additions & 42 deletions src/adapters/controllers/library_controller.cpp
Original file line number Diff line number Diff line change
@@ -18,28 +18,30 @@ using namespace dtos;

LibraryController::LibraryController(
application::ILibraryService* bookService) :
m_bookService(bookService),
m_libraryModel(m_bookService->getBooks())
m_libraryService(bookService),
m_libraryModel(m_libraryService->getBooks())
{
// book insertion
connect(m_bookService, &application::ILibraryService::bookInsertionStarted,
connect(m_libraryService,
&application::ILibraryService::bookInsertionStarted,
&m_libraryModel, &data_models::LibraryModel::startInsertingRow);

connect(m_bookService, &application::ILibraryService::bookInsertionEnded,
connect(m_libraryService, &application::ILibraryService::bookInsertionEnded,
&m_libraryModel, &data_models::LibraryModel::endInsertingRow);

connect(m_bookService, &application::ILibraryService::bookInsertionEnded,
connect(m_libraryService, &application::ILibraryService::bookInsertionEnded,
this, &LibraryController::bookCountChanged);

// Library syncing
connect(m_bookService, &application::ILibraryService::syncingLibraryStarted,
connect(m_libraryService,
&application::ILibraryService::syncingLibraryStarted,
[this]()
{
m_currentlySyncing = true;
emit isSyncingChanged();
});

connect(m_bookService,
connect(m_libraryService,
&application::ILibraryService::syncingLibraryFinished,
[this]()
{
@@ -49,46 +51,49 @@ LibraryController::LibraryController(


// book deletion
connect(m_bookService, &application::ILibraryService::bookDeletionStarted,
&m_libraryModel, &data_models::LibraryModel::startDeletingBook);
connect(m_libraryService,
&application::ILibraryService::bookDeletionStarted, &m_libraryModel,
&data_models::LibraryModel::startDeletingBook);

connect(m_bookService, &application::ILibraryService::bookDeletionEnded,
connect(m_libraryService, &application::ILibraryService::bookDeletionEnded,
&m_libraryModel, &data_models::LibraryModel::endDeletingBook);

connect(m_bookService, &application::ILibraryService::bookDeletionEnded,
connect(m_libraryService, &application::ILibraryService::bookDeletionEnded,
this, &LibraryController::bookCountChanged);


// book clearing
connect(m_bookService, &application::ILibraryService::bookClearingStarted,
&m_libraryModel, &data_models::LibraryModel::startBookClearing);
connect(m_libraryService,
&application::ILibraryService::bookClearingStarted, &m_libraryModel,
&data_models::LibraryModel::startBookClearing);

connect(m_bookService, &application::ILibraryService::bookClearingEnded,
connect(m_libraryService, &application::ILibraryService::bookClearingEnded,
&m_libraryModel, &data_models::LibraryModel::endBookClearing);

connect(m_bookService, &application::ILibraryService::bookClearingEnded,
connect(m_libraryService, &application::ILibraryService::bookClearingEnded,
this, &LibraryController::bookCountChanged);

// Storage limit exceeded
connect(m_bookService, &application::ILibraryService::storageLimitExceeded,
this, &LibraryController::storageLimitExceeded);
connect(m_libraryService,
&application::ILibraryService::storageLimitExceeded, this,
&LibraryController::storageLimitExceeded);

// tags changed
connect(m_bookService, &application::ILibraryService::tagsChanged,
connect(m_libraryService, &application::ILibraryService::tagsChanged,
&m_libraryModel, &data_models::LibraryModel::refreshTags);

// data changed
connect(m_bookService, &application::ILibraryService::dataChanged,
connect(m_libraryService, &application::ILibraryService::dataChanged,
&m_libraryModel, &data_models::LibraryModel::refreshBook);

// download book media progress changed
connect(m_bookService,
connect(m_libraryService,
&application::ILibraryService::downloadingBookMediaProgressChanged,
&m_libraryModel,
&data_models::LibraryModel::downloadingBookMediaProgressChanged);

// downloaded Project Gutenberg books
connect(m_bookService,
connect(m_libraryService,
&application::ILibraryService::downloadedProjectGutenbergIdsReady,
this, &LibraryController::downloadedProjectGutenbergIdsReady);

@@ -97,18 +102,20 @@ LibraryController::LibraryController(

void LibraryController::syncWithServer()
{
m_bookService->downloadBooks();
m_libraryService->downloadBooks();
}

int LibraryController::addBook(const QString& path, int projectGutenbergId)
int LibraryController::addBook(const QString& path, bool allowDuplicates,
int projectGutenbergId)
{
auto localPath = QUrl(path).toLocalFile();
QFileInfo fileInfo(localPath);
if(!fileInfo.isFile())
return 0;

QApplication::setOverrideCursor(Qt::WaitCursor);
auto result = m_bookService->addBook(localPath, projectGutenbergId);
auto result = m_libraryService->addBook(localPath, allowDuplicates,
projectGutenbergId);
QApplication::restoreOverrideCursor();

emit addingBookFinished(
@@ -120,32 +127,32 @@ int LibraryController::addBook(const QString& path, int projectGutenbergId)

int LibraryController::deleteBook(const QString& uuid)
{
auto result = m_bookService->deleteBook(QUuid(uuid));
auto result = m_libraryService->deleteBook(QUuid(uuid));
return static_cast<int>(result);
}

int LibraryController::deleteAllBooks()
{
auto result = m_bookService->deleteAllBooks();
auto result = m_libraryService->deleteAllBooks();
return static_cast<int>(result);
}

int LibraryController::uninstallBook(const QString& uuid)
{
auto result = m_bookService->uninstallBook(QUuid(uuid));
auto result = m_libraryService->uninstallBook(QUuid(uuid));
return static_cast<int>(result);
}

int LibraryController::downloadBookMedia(const QString& uuid)
{
auto result = m_bookService->downloadBookMedia(QUuid(uuid));
auto result = m_libraryService->downloadBookMedia(QUuid(uuid));
return static_cast<int>(result);
}

int LibraryController::updateBook(const QString& uuid,
const QVariant& operations)
{
auto bookToUpdate = m_bookService->getBook(QUuid(uuid));
auto bookToUpdate = m_libraryService->getBook(QUuid(uuid));
if(!bookToUpdate)
return static_cast<int>(BookOperationStatus::BookDoesNotExist);

@@ -207,14 +214,14 @@ int LibraryController::updateBook(const QString& uuid,
}
}

auto result = m_bookService->updateBook(updatedBook);
auto result = m_libraryService->updateBook(updatedBook);
return static_cast<int>(result);
}

int LibraryController::changeBookCover(const QString& uuid, const QString& path)
{
auto result =
m_bookService->changeBookCover(QUuid(uuid), QUrl(path).toLocalFile());
auto result = m_libraryService->changeBookCover(QUuid(uuid),
QUrl(path).toLocalFile());
return static_cast<int>(result);
}

@@ -230,7 +237,7 @@ int LibraryController::addTag(const QString& bookUuid, const QString& tagName,
}

Tag tag(tagName, tagUuid);
auto result = m_bookService->addTagToBook(QUuid(bookUuid), tag);
auto result = m_libraryService->addTagToBook(QUuid(bookUuid), tag);

return static_cast<int>(result);
}
@@ -240,39 +247,39 @@ void LibraryController::removeAllTagsWithUuid(const QString& tagUuid)
if(QUuid(tagUuid).isNull())
return;

auto& books = m_bookService->getBooks();
auto& books = m_libraryService->getBooks();
for(const auto& book : books)
{
if(listContainsTag(book.getTags(), QUuid(tagUuid)))
{
m_bookService->removeTagFromBook(book.getUuid(), QUuid(tagUuid));
m_libraryService->removeTagFromBook(book.getUuid(), QUuid(tagUuid));
}
}
}

void LibraryController::renameTags(const QString& oldName,
const QString& newName)
{
auto& books = m_bookService->getBooks();
auto& books = m_libraryService->getBooks();
for(const auto& book : books)
{
auto tagUuid = getTagUuidByName(book, oldName);
if(!tagUuid.isNull())
m_bookService->renameTagOfBook(book.getUuid(), tagUuid, newName);
m_libraryService->renameTagOfBook(book.getUuid(), tagUuid, newName);
}
}

int LibraryController::removeTag(const QString& bookUuid,
const QString& tagUuid)
{
auto result =
m_bookService->removeTagFromBook(QUuid(bookUuid), QUuid(tagUuid));
m_libraryService->removeTagFromBook(QUuid(bookUuid), QUuid(tagUuid));
return static_cast<int>(result);
}

dtos::BookDto LibraryController::getBook(const QString& uuid)
{
const auto& books = m_bookService->getBooks();
const auto& books = m_libraryService->getBooks();
auto book = std::ranges::find_if(books,
[&uuid](const Book& b)
{
@@ -284,7 +291,7 @@ dtos::BookDto LibraryController::getBook(const QString& uuid)

int LibraryController::getBookCount() const
{
return m_bookService->getBookCount();
return m_libraryService->getBookCount();
}

bool LibraryController::isSyncing() const
@@ -300,14 +307,14 @@ data_models::LibraryProxyModel* LibraryController::getLibraryModel()
int LibraryController::saveBookToFile(const QString& uuid, const QUrl& path)
{
auto result =
m_bookService->saveBookToFile(QUuid(uuid), path.toLocalFile());
m_libraryService->saveBookToFile(QUuid(uuid), path.toLocalFile());

return static_cast<int>(result);
}

void LibraryController::refreshLastOpenedFlag(const QString& uuid)
{
m_bookService->refreshLastOpenedDateOfBook(QUuid(uuid));
m_libraryService->refreshLastOpenedDateOfBook(QUuid(uuid));
}

dtos::BookDto LibraryController::getDtoFromBook(
5 changes: 3 additions & 2 deletions src/adapters/controllers/library_controller.hpp
Original file line number Diff line number Diff line change
@@ -18,7 +18,8 @@ class ADAPTERS_EXPORT LibraryController : public ILibraryController
public:
LibraryController(application::ILibraryService* bookService);

int addBook(const QString& path, int projectGutenbergId = 0) override;
int addBook(const QString& path, bool allowDuplicates = false,
int projectGutenbergId = 0) override;
int deleteBook(const QString& uuid) override;
int deleteAllBooks() override;
int uninstallBook(const QString& uuid) override;
@@ -51,7 +52,7 @@ public slots:
dtos::BookDto& bookDto);
bool listContainsTag(const QList<domain::entities::Tag>& tags, QUuid uuid);

application::ILibraryService* m_bookService;
application::ILibraryService* m_libraryService;
data_models::LibraryModel m_libraryModel;
data_models::LibraryProxyModel m_libraryProxyModel;
bool m_currentlySyncing = false;
6 changes: 6 additions & 0 deletions src/adapters/interfaces/controllers/i_book_controller.hpp
Original file line number Diff line number Diff line change
@@ -34,6 +34,8 @@ class ADAPTERS_EXPORT IBookController : public QObject
setSearchCaseSensitive NOTIFY searchCaseSensitiveChanged)
Q_PROPERTY(bool searchFromStart READ getSearchFromStart WRITE
setSearchFromStart NOTIFY searchFromStartChanged)
Q_PROPERTY(QString colorTheme READ getColorTheme WRITE setColorTheme NOTIFY
colorThemeChanged)

public:
virtual ~IBookController() noexcept = default;
@@ -82,6 +84,9 @@ class ADAPTERS_EXPORT IBookController : public QObject
virtual bool getSearchFromStart() const = 0;
virtual void setSearchFromStart(bool newSearchFromStart) = 0;

virtual QString getColorTheme() = 0;
virtual void setColorTheme(const QString& colorTheme) = 0;

virtual application::core::FilteredTOCModel* getTableOfContents() = 0;
virtual adapters::data_models::BookmarksProxyModel* getBookmarksModel() = 0;

@@ -100,6 +105,7 @@ class ADAPTERS_EXPORT IBookController : public QObject
void searchCaseSensitiveChanged();
void searchFromStartChanged();
void bookmarksModelChanged();
void colorThemeChanged(const QString& colorTheme);
};

} // namespace adapters
Loading

0 comments on commit b31b596

Please sign in to comment.