Skip to content

Commit d1433e0

Browse files
committed
Version 1.09
2 parents 8084fad + c69bc14 commit d1433e0

File tree

725 files changed

+27732
-15266
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

725 files changed

+27732
-15266
lines changed

AbstractFilter.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ class QDomElement;
3838
*/
3939
class AbstractFilter : public ref_countable {
4040
public:
41-
virtual ~AbstractFilter() {
42-
}
41+
~AbstractFilter() override = default;
4342

4443
virtual QString getName() const = 0;
4544

@@ -59,16 +58,19 @@ class AbstractFilter : public ref_countable {
5958
return std::vector<PageOrderOption>();
6059
}
6160

62-
virtual void performRelinking(AbstractRelinker const& relinker) = 0;
61+
virtual void performRelinking(const AbstractRelinker& relinker) = 0;
6362

64-
virtual void preUpdateUI(FilterUiInterface* ui, PageId const& page_id) = 0;
63+
virtual void preUpdateUI(FilterUiInterface* ui, const PageId& page_id) = 0;
6564

6665
virtual void updateStatistics() {
6766
}
6867

69-
virtual QDomElement saveSettings(ProjectWriter const& writer, QDomDocument& doc) const = 0;
68+
virtual QDomElement saveSettings(const ProjectWriter& writer, QDomDocument& doc) const = 0;
69+
70+
virtual void loadSettings(const ProjectReader& reader, const QDomElement& filters_el) = 0;
7071

71-
virtual void loadSettings(ProjectReader const& reader, QDomElement const& filters_el) = 0;
72+
virtual void loadDefaultSettings(const PageId& page_id) {
73+
};
7274
};
7375

7476

AbstractRelinker.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@ class QString;
2626

2727
class AbstractRelinker : public ref_countable {
2828
public:
29-
virtual ~AbstractRelinker() {
30-
}
29+
~AbstractRelinker() override = default;
3130

3231
/**
3332
* Returns the path to be used instead of the given path.
3433
* The same path will be returned if no substitution is to be made.
3534
*/
36-
virtual QString substitutionPathFor(RelinkablePath const& orig_path) const = 0;
35+
virtual QString substitutionPathFor(const RelinkablePath& orig_path) const = 0;
3736
};
3837

3938

Application.cpp

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@
3434
#include <QtCore/QDir>
3535

3636
Application::Application(int& argc, char** argv)
37-
: QApplication(argc, argv) {
37+
: QApplication(argc, argv),
38+
m_currentLocale("en") {
39+
initTranslations();
3840
}
3941

4042
bool Application::notify(QObject* receiver, QEvent* e) {
4143
try {
4244
return QApplication::notify(receiver, e);
43-
} catch (std::bad_alloc const&) {
45+
} catch (const std::bad_alloc&) {
4446
OutOfMemoryHandler::instance().handleOutOfMemorySituation();
4547

4648
return false;
@@ -52,35 +54,52 @@ void Application::installLanguage(const QString& locale) {
5254
return;
5355
}
5456

55-
QString const translation("scantailor_" + locale);
56-
QStringList const translation_dirs(
57-
QString::fromUtf8(TRANSLATION_DIRS).split(QChar(':'), QString::SkipEmptyParts)
58-
);
59-
bool loaded = false;
60-
for (QString const& path : translation_dirs) {
61-
QString absolute_path;
62-
if (QDir::isAbsolutePath(path)) {
63-
absolute_path = path;
64-
} else {
65-
absolute_path = this->applicationDirPath();
66-
absolute_path += QChar('/');
67-
absolute_path += path;
68-
}
69-
absolute_path += QChar('/');
70-
absolute_path += translation;
57+
if (m_translationsMap.find(locale) != m_translationsMap.end()) {
58+
bool loaded = m_translator.load(m_translationsMap[locale]);
7159

72-
loaded = m_translator.load(absolute_path);
73-
if (loaded) {
74-
break;
75-
}
76-
}
77-
78-
this->removeTranslator(&m_translator);
79-
this->installTranslator(&m_translator);
60+
this->removeTranslator(&m_translator);
61+
this->installTranslator(&m_translator);
8062

81-
m_currentLocale = (loaded) ? locale : "en";
63+
m_currentLocale = (loaded) ? locale : "en";
64+
} else {
65+
this->removeTranslator(&m_translator);
66+
67+
m_currentLocale = "en";
68+
}
8269
}
8370

8471
const QString& Application::getCurrentLocale() const {
8572
return m_currentLocale;
86-
}
73+
}
74+
75+
std::list<QString> Application::getLanguagesList() const {
76+
std::list<QString> list{ "en" };
77+
std::transform(m_translationsMap.begin(), m_translationsMap.end(),
78+
std::back_inserter(list),
79+
[](const std::pair<QString, QString>& val) {
80+
return val.first;
81+
});
82+
83+
return list;
84+
}
85+
86+
void Application::initTranslations() {
87+
const QStringList translation_dirs(
88+
QString::fromUtf8(TRANSLATION_DIRS).split(QChar(':'), QString::SkipEmptyParts)
89+
);
90+
91+
const QStringList language_file_filter("scantailor_*.qm");
92+
for (const QString& path : translation_dirs) {
93+
QDir dir(path);
94+
if (dir.exists()) {
95+
QStringList translationFileNames = QDir(path).entryList(language_file_filter);
96+
for (const QString& fileName : translationFileNames) {
97+
QString locale(fileName);
98+
locale.truncate(locale.lastIndexOf('.'));
99+
locale.remove(0, locale.indexOf('_') + 1);
100+
101+
m_translationsMap[locale] = dir.absoluteFilePath(fileName);
102+
}
103+
}
104+
}
105+
}

Application.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,21 @@ Q_OBJECT
3232
public:
3333
Application(int& argc, char** argv);
3434

35-
virtual bool notify(QObject* receiver, QEvent* e);
35+
bool notify(QObject* receiver, QEvent* e) override;
3636

3737
const QString& getCurrentLocale() const;
3838

3939
void installLanguage(const QString& locale);
4040

41+
std::list<QString> getLanguagesList() const;
42+
4143
private:
44+
void initTranslations();
45+
46+
4247
QTranslator m_translator;
4348
QString m_currentLocale;
49+
std::map<QString, QString> m_translationsMap;
4450
};
4551

4652

AtomicFileOverwriter.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,16 @@
2121
#include <QFile>
2222
#include <QTemporaryFile>
2323

24-
AtomicFileOverwriter::AtomicFileOverwriter() {
25-
}
24+
AtomicFileOverwriter::AtomicFileOverwriter() = default;
2625

2726
AtomicFileOverwriter::~AtomicFileOverwriter() {
2827
abort();
2928
}
3029

31-
QIODevice* AtomicFileOverwriter::startWriting(QString const& file_path) {
30+
QIODevice* AtomicFileOverwriter::startWriting(const QString& file_path) {
3231
abort();
3332

34-
m_ptrTempFile.reset(new QTemporaryFile(file_path));
33+
m_ptrTempFile = std::make_unique<QTemporaryFile>(file_path);
3534
m_ptrTempFile->setAutoRemove(false);
3635
if (!m_ptrTempFile->open()) {
3736
m_ptrTempFile.reset();
@@ -41,12 +40,12 @@ QIODevice* AtomicFileOverwriter::startWriting(QString const& file_path) {
4140
}
4241

4342
bool AtomicFileOverwriter::commit() {
44-
if (!m_ptrTempFile.get()) {
43+
if (!m_ptrTempFile) {
4544
return false;
4645
}
4746

48-
QString const temp_file_path(m_ptrTempFile->fileName());
49-
QString const target_path(m_ptrTempFile->fileTemplate());
47+
const QString temp_file_path(m_ptrTempFile->fileName());
48+
const QString target_path(m_ptrTempFile->fileTemplate());
5049

5150
// Yes, we have to destroy this object here, because:
5251
// 1. Under Windows, open files can't be renamed or deleted.
@@ -63,11 +62,11 @@ bool AtomicFileOverwriter::commit() {
6362
}
6463

6564
void AtomicFileOverwriter::abort() {
66-
if (!m_ptrTempFile.get()) {
65+
if (!m_ptrTempFile) {
6766
return;
6867
}
6968

70-
QString const temp_file_path(m_ptrTempFile->fileName());
69+
const QString temp_file_path(m_ptrTempFile->fileName());
7170
m_ptrTempFile.reset(); // See comments in commit()
7271
QFile::remove(temp_file_path);
7372
}

AtomicFileOverwriter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ DECLARE_NON_COPYABLE(AtomicFileOverwriter)
5454
* If a file is already being written, it calles abort() and then
5555
* proceeds as usual.
5656
*/
57-
QIODevice* startWriting(QString const& file_path);
57+
QIODevice* startWriting(const QString& file_path);
5858

5959
/**
6060
* \brief Replaces the target file with the temporary one.

BackgroundExecutor.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
#include "OutOfMemoryHandler.h"
2121
#include <QCoreApplication>
2222
#include <QThread>
23-
#include <assert.h>
23+
#include <cassert>
2424

2525
class BackgroundExecutor::Dispatcher : public QObject {
2626
public:
27-
Dispatcher(Impl& owner);
27+
explicit Dispatcher(Impl& owner);
2828

2929
protected:
30-
virtual void customEvent(QEvent* event);
30+
void customEvent(QEvent* event) override;
3131

3232
private:
3333
Impl& m_rOwner;
@@ -36,16 +36,16 @@ class BackgroundExecutor::Dispatcher : public QObject {
3636

3737
class BackgroundExecutor::Impl : public QThread {
3838
public:
39-
Impl(BackgroundExecutor& owner);
39+
explicit Impl(BackgroundExecutor& owner);
4040

41-
~Impl();
41+
~Impl() override;
4242

43-
void enqueueTask(TaskPtr const& task);
43+
void enqueueTask(const TaskPtr& task);
4444

4545
protected:
46-
virtual void run();
46+
void run() override;
4747

48-
virtual void customEvent(QEvent* event);
48+
void customEvent(QEvent* event) override;
4949

5050
private:
5151
BackgroundExecutor& m_rOwner;
@@ -60,15 +60,14 @@ BackgroundExecutor::BackgroundExecutor()
6060
: m_ptrImpl(new Impl(*this)) {
6161
}
6262

63-
BackgroundExecutor::~BackgroundExecutor() {
64-
}
63+
BackgroundExecutor::~BackgroundExecutor() = default;
6564

6665
void BackgroundExecutor::shutdown() {
6766
m_ptrImpl.reset();
6867
}
6968

70-
void BackgroundExecutor::enqueueTask(TaskPtr const& task) {
71-
if (m_ptrImpl.get()) {
69+
void BackgroundExecutor::enqueueTask(const TaskPtr& task) {
70+
if (m_ptrImpl) {
7271
m_ptrImpl->enqueueTask(task);
7372
}
7473
}
@@ -81,19 +80,19 @@ BackgroundExecutor::Dispatcher::Dispatcher(Impl& owner)
8180

8281
void BackgroundExecutor::Dispatcher::customEvent(QEvent* event) {
8382
try {
84-
TaskEvent* evt = dynamic_cast<TaskEvent*>(event);
83+
auto* evt = dynamic_cast<TaskEvent*>(event);
8584
assert(evt);
8685

87-
TaskPtr const& task = evt->payload();
86+
const TaskPtr& task = evt->payload();
8887
assert(task);
8988

90-
TaskResultPtr const result((*task)());
89+
const TaskResultPtr result((*task)());
9190
if (result) {
9291
QCoreApplication::postEvent(
9392
&m_rOwner, new ResultEvent(result)
9493
);
9594
}
96-
} catch (std::bad_alloc const&) {
95+
} catch (const std::bad_alloc&) {
9796
OutOfMemoryHandler::instance().handleOutOfMemorySituation();
9897
}
9998
}
@@ -112,7 +111,7 @@ BackgroundExecutor::Impl::~Impl() {
112111
wait();
113112
}
114113

115-
void BackgroundExecutor::Impl::enqueueTask(TaskPtr const& task) {
114+
void BackgroundExecutor::Impl::enqueueTask(const TaskPtr& task) {
116115
QCoreApplication::postEvent(&m_dispatcher, new TaskEvent(task));
117116
if (!m_threadStarted) {
118117
start();
@@ -125,10 +124,10 @@ void BackgroundExecutor::Impl::run() {
125124
}
126125

127126
void BackgroundExecutor::Impl::customEvent(QEvent* event) {
128-
ResultEvent* evt = dynamic_cast<ResultEvent*>(event);
127+
auto* evt = dynamic_cast<ResultEvent*>(event);
129128
assert(evt);
130129

131-
TaskResultPtr const& result = evt->payload();
130+
const TaskResultPtr& result = evt->payload();
132131
assert(result);
133132

134133
(*result)();

BackgroundExecutor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ DECLARE_NON_COPYABLE(BackgroundExecutor)
5656
* to be executed in the thread where this BackgroundExecutor
5757
* object was constructed.
5858
*/
59-
void enqueueTask(TaskPtr const& task);
59+
void enqueueTask(const TaskPtr& task);
6060

6161
private:
6262
class Impl;

BackgroundTask.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include "BackgroundTask.h"
2020

21-
char const* BackgroundTask::CancelledException::what() const throw() {
21+
const char* BackgroundTask::CancelledException::what() const throw() {
2222
return "BackgroundTask cancelled";
2323
}
2424

BackgroundTask.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,34 @@ class BackgroundTask : public AbstractCommand0<FilterResultPtr>, public TaskStat
3535

3636
class CancelledException : public std::exception {
3737
public:
38-
virtual char const* what() const throw();
38+
const char* what() const throw() override;
3939
};
4040

4141

42-
BackgroundTask(Type type)
42+
explicit BackgroundTask(Type type)
4343
: m_type(type) {
4444
}
4545

4646
Type type() const {
4747
return m_type;
4848
}
4949

50-
virtual void cancel() {
50+
void cancel() override {
5151
m_cancelFlag.store(1);
5252
}
5353

54-
virtual bool isCancelled() const {
54+
bool isCancelled() const override {
5555
return m_cancelFlag.load() != 0;
5656
}
5757

5858
/**
5959
* \brief If cancelled, throws CancelledException.
6060
*/
61-
virtual void throwIfCancelled() const;
61+
void throwIfCancelled() const override;
6262

6363
private:
6464
QAtomicInt m_cancelFlag;
65-
Type const m_type;
65+
const Type m_type;
6666
};
6767

6868

0 commit comments

Comments
 (0)