Skip to content

Commit 57606fc

Browse files
committed
Project portability through resource re-linking.
1 parent 64a1947 commit 57606fc

Some content is hidden

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

70 files changed

+2533
-143
lines changed

AbstractFilter.h

+6
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@ class FilterUiInterface;
2828
class PageId;
2929
class ProjectReader;
3030
class ProjectWriter;
31+
class AbstractRelinker;
3132
class QString;
3233
class QDomDocument;
3334
class QDomElement;
3435

36+
/**
37+
* Filters represent processing stages, like "Deskew", "Margins" and "Output".
38+
*/
3539
class AbstractFilter : public RefCountable
3640
{
3741
public:
@@ -51,6 +55,8 @@ class AbstractFilter : public RefCountable
5155
return std::vector<PageOrderOption>();
5256
}
5357

58+
virtual void performRelinking(AbstractRelinker const& relinker) = 0;
59+
5460
virtual void preUpdateUI(FilterUiInterface* ui, PageId const& page_id) = 0;
5561

5662
virtual QDomElement saveSettings(

AbstractRelinker.h

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
Scan Tailor - Interactive post-processing tool for scanned pages.
3+
Copyright (C) Joseph Artsimovich <joseph.artsimovich@gmail.com>
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#ifndef ABSTRACT_RELINKER_H_
20+
#define ABSTRACT_RELINKER_H_
21+
22+
#include "RefCountable.h"
23+
24+
class RelinkablePath;
25+
class QString;
26+
27+
class AbstractRelinker : public RefCountable
28+
{
29+
public:
30+
virtual ~AbstractRelinker() {}
31+
32+
/**
33+
* Returns the path to be used instead of the given path.
34+
* The same path will be returned if no substitution is to be made.
35+
*/
36+
virtual QString substitutionPathFor(RelinkablePath const& orig_path) const = 0;
37+
};
38+
39+
#endif

BackgroundExecutor.cpp

-14
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,6 @@
2525
#include <new>
2626
#include <assert.h>
2727

28-
template<typename T>
29-
class BackgroundExecutor::PayloadEvent : public QEvent
30-
{
31-
public:
32-
PayloadEvent(T const& payload) : QEvent(User), m_payload(payload) {}
33-
34-
T const& payload() const { return m_payload; }
35-
36-
T& payload() { return m_payload; }
37-
private:
38-
T m_payload;
39-
};
40-
41-
4228
class BackgroundExecutor::Dispatcher : public QObject
4329
{
4430
public:

BackgroundExecutor.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Scan Tailor - Interactive post-processing tool for scanned pages.
3-
Copyright (C) 2007-2008 Joseph Artsimovich <joseph_a@mail.ru>
3+
Copyright (C) Joseph Artsimovich <joseph.artsimovich@gmail.com>
44
55
This program is free software: you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -22,6 +22,7 @@
2222
#include "NonCopyable.h"
2323
#include "IntrusivePtr.h"
2424
#include "AbstractCommand.h"
25+
#include "PayloadEvent.h"
2526
#include <memory>
2627

2728
class BackgroundExecutor
@@ -59,7 +60,6 @@ class BackgroundExecutor
5960
private:
6061
class Impl;
6162
class Dispatcher;
62-
template<typename T> class PayloadEvent;
6363
typedef PayloadEvent<TaskPtr> TaskEvent;
6464
typedef PayloadEvent<TaskResultPtr> ResultEvent;
6565

CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,13 @@ SET(
445445
NonOwningWidget.cpp NonOwningWidget.h
446446
Dpi.cpp Dpi.h Dpm.cpp Dpm.h
447447
SmartFilenameOrdering.cpp SmartFilenameOrdering.h
448+
AbstractRelinker.h
449+
RelinkablePath.cpp RelinkablePath.h
450+
RelinkablePathVisualization.cpp RelinkablePathVisualization.h
451+
RelinkingModel.cpp RelinkingModel.h
452+
RelinkingSortingModel.cpp RelinkingSortingModel.h
453+
RelinkingListView.cpp RelinkingListView.h
454+
RelinkingDialog.cpp RelinkingDialog.h
448455
ImageInfo.cpp ImageInfo.h
449456
ImageFileInfo.cpp ImageFileInfo.h
450457
ImageMetadata.cpp ImageMetadata.h
@@ -528,6 +535,7 @@ SET(
528535
ChangedStateItemDelegate.h
529536
PageOrderProvider.h
530537
PageOrderOption.h
538+
PayloadEvent.h
531539
filter_dc/AbstractFilterDataCollector.h
532540
filter_dc/ThumbnailCollector.h
533541
filter_dc/ContentBoxCollector.h

ErrorWidget.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Scan Tailor - Interactive post-processing tool for scanned pages.
3-
Copyright (C) 2007-2008 Joseph Artsimovich <joseph_a@mail.ru>
3+
Copyright (C) Joseph Artsimovich <joseph.artsimovich@gmail.com>
44
55
This program is free software: you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -17,13 +17,17 @@
1717
*/
1818

1919
#include "ErrorWidget.h"
20+
#include "ErrorWidget.h.moc"
2021
#include <QStyle>
2122
#include <QIcon>
2223

23-
ErrorWidget::ErrorWidget(QString const& text)
24+
ErrorWidget::ErrorWidget(QString const& text, Qt::TextFormat fmt)
2425
{
2526
setupUi(this);
27+
textLabel->setTextFormat(fmt);
2628
textLabel->setText(text);
2729
QIcon icon(QApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning));
2830
imageLabel->setPixmap(icon.pixmap(48, 48));
31+
32+
connect(textLabel, SIGNAL(linkActivated(QString const&)), SLOT(linkActivated(QString const&)));
2933
}

ErrorWidget.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Scan Tailor - Interactive post-processing tool for scanned pages.
3-
Copyright (C) 2007-2008 Joseph Artsimovich <joseph_a@mail.ru>
3+
Copyright (C) Joseph Artsimovich <joseph.artsimovich@gmail.com>
44
55
This program is free software: you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -21,13 +21,20 @@
2121

2222
#include "ui_ErrorWidget.h"
2323
#include <QWidget>
24+
#include <Qt>
2425

2526
class QString;
2627

2728
class ErrorWidget : public QWidget, private Ui::ErrorWidget
2829
{
30+
Q_OBJECT
2931
public:
30-
ErrorWidget(QString const& text);
32+
ErrorWidget(QString const& text, Qt::TextFormat fmt = Qt::AutoText);
33+
private slots:
34+
/**
35+
* \see QLabel::linkActivated()
36+
*/
37+
virtual void linkActivated(QString const& link) {}
3138
};
3239

3340
#endif

FileNameDisambiguator.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818

1919
#include "FileNameDisambiguator.h"
20+
#include "RelinkablePath.h"
21+
#include "AbstractRelinker.h"
2022
#include <QString>
2123
#include <QFileInfo>
2224
#include <QDomDocument>
@@ -46,6 +48,8 @@ class FileNameDisambiguator::Impl
4648
int getLabel(QString const& file_path) const;
4749

4850
int registerFile(QString const& file_path);
51+
52+
void performRelinking(AbstractRelinker const& relinker);
4953
private:
5054
class ItemsByFilePathTag;
5155
class ItemsByFileNameLabelTag;
@@ -139,6 +143,12 @@ FileNameDisambiguator::registerFile(QString const& file_path)
139143
return m_ptrImpl->registerFile(file_path);
140144
}
141145

146+
void
147+
FileNameDisambiguator::performRelinking(AbstractRelinker const& relinker)
148+
{
149+
m_ptrImpl->performRelinking(relinker);
150+
}
151+
142152

143153
/*==================== FileNameDisambiguator::Impl ====================*/
144154

@@ -250,6 +260,21 @@ FileNameDisambiguator::Impl::registerFile(QString const& file_path)
250260
return label;
251261
}
252262

263+
void
264+
FileNameDisambiguator::Impl::performRelinking(AbstractRelinker const& relinker)
265+
{
266+
QMutexLocker const locker(&m_mutex);
267+
Container new_items;
268+
269+
BOOST_FOREACH(Item const& item, m_unorderedItems) {
270+
RelinkablePath const old_path(item.filePath, RelinkablePath::File);
271+
Item new_item(relinker.substitutionPathFor(old_path), item.label);
272+
new_items.insert(new_item);
273+
}
274+
275+
m_items.swap(new_items);
276+
}
277+
253278

254279
/*============================ Impl::Item =============================*/
255280

FileNameDisambiguator.h

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <memory>
2626
#include <set>
2727

28+
class AbstractRelinker;
2829
class QString;
2930
class QDomElement;
3031
class QDomDocument;
@@ -79,6 +80,8 @@ class FileNameDisambiguator : public RefCountable
7980
int getLabel(QString const& file_path) const;
8081

8182
int registerFile(QString const& file_path);
83+
84+
void performRelinking(AbstractRelinker const& relinker);
8285
private:
8386
class Impl;
8487

FilterUiInterface.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Scan Tailor - Interactive post-processing tool for scanned pages.
3-
Copyright (C) 2007-2008 Joseph Artsimovich <joseph_a@mail.ru>
3+
Copyright (C) Joseph Artsimovich <joseph.artsimovich@gmail.com>
44
55
This program is free software: you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -20,6 +20,8 @@
2020
#define FILTERUIINTERFACE_H_
2121

2222
#include "PageId.h"
23+
#include "AbstractCommand.h"
24+
#include "IntrusivePtr.h"
2325

2426
class DebugImages;
2527
class FilterOptionsWidget;
@@ -45,6 +47,11 @@ class FilterUiInterface
4547
virtual void invalidateThumbnail(PageId const& page_id) = 0;
4648

4749
virtual void invalidateAllThumbnails() = 0;
50+
51+
/**
52+
* Returns a callable object that when called will open a relinking dialog.
53+
*/
54+
virtual IntrusivePtr<AbstractCommand0<void> > relinkingDialogRequester() = 0;
4855
};
4956

5057
#endif

ImageId.h

+4
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ class ImageId
3636
bool isNull() const { return m_filePath.isNull(); }
3737

3838
QString const& filePath() const { return m_filePath; }
39+
40+
void setFilePath(QString const& path) { m_filePath = path; }
3941

4042
int page() const { return m_page; }
4143

44+
void setPage(int page) { m_page = page; }
45+
4246
int zeroBasedPage() const { return m_page > 0 ? m_page - 1 : 0; }
4347

4448
bool isMultiPageFile() const { return m_page > 0; }

LoadFileTask.cpp

+35-9
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,19 @@
3131
#include "Dpm.h"
3232
#include "FilterData.h"
3333
#include "ImageLoader.h"
34-
#include "imageproc/BinaryThreshold.h"
3534
#include <QCoreApplication>
35+
#include <QFile>
36+
#include <QDir>
3637
#include <QImage>
3738
#include <QString>
39+
#include <QTextDocument> // for Qt::escape()
3840
#include <assert.h>
3941

4042
using namespace imageproc;
4143

4244
class LoadFileTask::ErrorResult : public FilterResult
4345
{
46+
Q_DECLARE_TR_FUNCTIONS(LoadFileTask)
4447
public:
4548
ErrorResult(QString const& file_path);
4649

@@ -51,6 +54,7 @@ class LoadFileTask::ErrorResult : public FilterResult
5154
}
5255
private:
5356
QString m_filePath;
57+
bool m_fileExists;
5458
};
5559

5660

@@ -125,19 +129,41 @@ LoadFileTask::overrideDpi(QImage& image) const
125129
/*======================= LoadFileTask::ErrorResult ======================*/
126130

127131
LoadFileTask::ErrorResult::ErrorResult(QString const& file_path)
128-
: m_filePath(file_path)
132+
: m_filePath(QDir::toNativeSeparators(file_path))
133+
, m_fileExists(QFile::exists(file_path))
129134
{
130135
}
131136

132137
void
133138
LoadFileTask::ErrorResult::updateUI(FilterUiInterface* ui)
134139
{
135-
QString const err_msg(
136-
QCoreApplication::translate(
137-
"LoadFileTask",
138-
"The following file could not be loaded:\n%1"
139-
).arg(m_filePath)
140-
);
141-
ui->setImageWidget(new ErrorWidget(err_msg), ui->TRANSFER_OWNERSHIP);
140+
class ErrWidget : public ErrorWidget
141+
{
142+
public:
143+
ErrWidget(IntrusivePtr<AbstractCommand0<void> > const& relinking_dialog_requester,
144+
QString const& text, Qt::TextFormat fmt = Qt::AutoText)
145+
: ErrorWidget(text, fmt), m_ptrRelinkingDialogRequester(relinking_dialog_requester) {}
146+
private:
147+
virtual void linkActivated(QString const&) {
148+
(*m_ptrRelinkingDialogRequester)();
149+
}
150+
151+
IntrusivePtr<AbstractCommand0<void> > m_ptrRelinkingDialogRequester;
152+
};
153+
154+
QString err_msg;
155+
Qt::TextFormat fmt = Qt::AutoText;
156+
if (m_fileExists) {
157+
err_msg = tr("The following file could not be loaded:\n%1").arg(m_filePath);
158+
fmt = Qt::PlainText;
159+
} else {
160+
err_msg = tr(
161+
"The following file doesn't exist:<br>%1<br>"
162+
"<br>"
163+
"Use the <a href=\"#relink\">Relinking Tool</a> to locate it."
164+
).arg(Qt::escape(m_filePath));
165+
fmt = Qt::RichText;
166+
}
167+
ui->setImageWidget(new ErrWidget(ui->relinkingDialogRequester(), err_msg, fmt), ui->TRANSFER_OWNERSHIP);
142168
ui->setOptionsWidget(new FilterOptionsWidget, ui->TRANSFER_OWNERSHIP);
143169
}

0 commit comments

Comments
 (0)