Permalink
Browse files

Project portability through resource re-linking.

  • Loading branch information...
1 parent 64a1947 commit 57606fc2a808e50b08009ef85f49f1afa6e88d8b @Tulon Tulon committed Dec 28, 2011
Showing with 2,533 additions and 143 deletions.
  1. +6 −0 AbstractFilter.h
  2. +39 −0 AbstractRelinker.h
  3. +0 −14 BackgroundExecutor.cpp
  4. +2 −2 BackgroundExecutor.h
  5. +8 −0 CMakeLists.txt
  6. +6 −2 ErrorWidget.cpp
  7. +9 −2 ErrorWidget.h
  8. +25 −0 FileNameDisambiguator.cpp
  9. +3 −0 FileNameDisambiguator.h
  10. +8 −1 FilterUiInterface.h
  11. +4 −0 ImageId.h
  12. +35 −9 LoadFileTask.cpp
  13. +71 −9 MainWindow.cpp
  14. +8 −0 MainWindow.h
  15. +9 −0 OutputFileNameGenerator.cpp
  16. +3 −0 OutputFileNameGenerator.h
  17. +2 −0 PageId.h
  18. +37 −0 PayloadEvent.h
  19. +36 −0 ProjectPages.cpp
  20. +11 −0 ProjectPages.h
  21. +66 −0 RelinkablePath.cpp
  22. +55 −0 RelinkablePath.h
  23. +313 −0 RelinkablePathVisualization.cpp
  24. +56 −0 RelinkablePathVisualization.h
  25. +151 −0 RelinkingDialog.cpp
  26. +67 −0 RelinkingDialog.h
  27. +169 −0 RelinkingListView.cpp
  28. +47 −0 RelinkingListView.h
  29. +491 −0 RelinkingModel.cpp
  30. +130 −0 RelinkingModel.h
  31. +66 −0 RelinkingSortingModel.cpp
  32. +32 −0 RelinkingSortingModel.h
  33. +8 −0 StageSequence.cpp
  34. +4 −1 StageSequence.h
  35. +31 −1 ThumbnailPixmapCache.cpp
  36. +3 −1 ThumbnailPixmapCache.h
  37. +8 −3 Utils.cpp
  38. +4 −3 Utils.h
  39. +8 −0 filters/deskew/Filter.cpp
  40. +4 −2 filters/deskew/Filter.h
  41. +19 −1 filters/deskew/Settings.cpp
  42. +5 −1 filters/deskew/Settings.h
  43. +6 −0 filters/fix_orientation/Filter.cpp
  44. +3 −1 filters/fix_orientation/Filter.h
  45. +19 −1 filters/fix_orientation/Settings.cpp
  46. +5 −1 filters/fix_orientation/Settings.h
  47. +6 −0 filters/output/Filter.cpp
  48. +2 −0 filters/output/Filter.h
  49. +46 −0 filters/output/Settings.cpp
  50. +4 −0 filters/output/Settings.h
  51. +6 −0 filters/page_layout/Filter.cpp
  52. +3 −1 filters/page_layout/Filter.h
  53. +26 −0 filters/page_layout/Settings.cpp
  54. +3 −0 filters/page_layout/Settings.h
  55. +6 −0 filters/page_split/Filter.cpp
  56. +2 −0 filters/page_split/Filter.h
  57. +18 −0 filters/page_split/Settings.cpp
  58. +4 −0 filters/page_split/Settings.h
  59. +6 −0 filters/select_content/Filter.cpp
  60. +2 −0 filters/select_content/Filter.h
  61. +20 −1 filters/select_content/Settings.cpp
  62. +5 −1 filters/select_content/Settings.h
  63. +16 −1 resources/icons/COPYING
  64. BIN resources/icons/file-16.png
  65. BIN resources/icons/folder-16.png
  66. BIN resources/icons/undo-22.png
  67. +55 −52 resources/resources.qrc
  68. +36 −29 ui/ErrorWidget.ui
  69. +9 −3 ui/MainWindow.ui
  70. +166 −0 ui/RelinkingDialog.ui
View
@@ -28,10 +28,14 @@ class FilterUiInterface;
class PageId;
class ProjectReader;
class ProjectWriter;
+class AbstractRelinker;
class QString;
class QDomDocument;
class QDomElement;
+/**
+ * Filters represent processing stages, like "Deskew", "Margins" and "Output".
+ */
class AbstractFilter : public RefCountable
{
public:
@@ -51,6 +55,8 @@ class AbstractFilter : public RefCountable
return std::vector<PageOrderOption>();
}
+ virtual void performRelinking(AbstractRelinker const& relinker) = 0;
+
virtual void preUpdateUI(FilterUiInterface* ui, PageId const& page_id) = 0;
virtual QDomElement saveSettings(
View
@@ -0,0 +1,39 @@
+/*
+ Scan Tailor - Interactive post-processing tool for scanned pages.
+ Copyright (C) Joseph Artsimovich <joseph.artsimovich@gmail.com>
+
+ 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
+ (at your option) 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, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef ABSTRACT_RELINKER_H_
+#define ABSTRACT_RELINKER_H_
+
+#include "RefCountable.h"
+
+class RelinkablePath;
+class QString;
+
+class AbstractRelinker : public RefCountable
+{
+public:
+ virtual ~AbstractRelinker() {}
+
+ /**
+ * Returns the path to be used instead of the given path.
+ * The same path will be returned if no substitution is to be made.
+ */
+ virtual QString substitutionPathFor(RelinkablePath const& orig_path) const = 0;
+};
+
+#endif
@@ -25,20 +25,6 @@
#include <new>
#include <assert.h>
-template<typename T>
-class BackgroundExecutor::PayloadEvent : public QEvent
-{
-public:
- PayloadEvent(T const& payload) : QEvent(User), m_payload(payload) {}
-
- T const& payload() const { return m_payload; }
-
- T& payload() { return m_payload; }
-private:
- T m_payload;
-};
-
-
class BackgroundExecutor::Dispatcher : public QObject
{
public:
@@ -1,6 +1,6 @@
/*
Scan Tailor - Interactive post-processing tool for scanned pages.
- Copyright (C) 2007-2008 Joseph Artsimovich <joseph_a@mail.ru>
+ Copyright (C) Joseph Artsimovich <joseph.artsimovich@gmail.com>
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
@@ -22,6 +22,7 @@
#include "NonCopyable.h"
#include "IntrusivePtr.h"
#include "AbstractCommand.h"
+#include "PayloadEvent.h"
#include <memory>
class BackgroundExecutor
@@ -59,7 +60,6 @@ class BackgroundExecutor
private:
class Impl;
class Dispatcher;
- template<typename T> class PayloadEvent;
typedef PayloadEvent<TaskPtr> TaskEvent;
typedef PayloadEvent<TaskResultPtr> ResultEvent;
View
@@ -445,6 +445,13 @@ SET(
NonOwningWidget.cpp NonOwningWidget.h
Dpi.cpp Dpi.h Dpm.cpp Dpm.h
SmartFilenameOrdering.cpp SmartFilenameOrdering.h
+ AbstractRelinker.h
+ RelinkablePath.cpp RelinkablePath.h
+ RelinkablePathVisualization.cpp RelinkablePathVisualization.h
+ RelinkingModel.cpp RelinkingModel.h
+ RelinkingSortingModel.cpp RelinkingSortingModel.h
+ RelinkingListView.cpp RelinkingListView.h
+ RelinkingDialog.cpp RelinkingDialog.h
ImageInfo.cpp ImageInfo.h
ImageFileInfo.cpp ImageFileInfo.h
ImageMetadata.cpp ImageMetadata.h
@@ -528,6 +535,7 @@ SET(
ChangedStateItemDelegate.h
PageOrderProvider.h
PageOrderOption.h
+ PayloadEvent.h
filter_dc/AbstractFilterDataCollector.h
filter_dc/ThumbnailCollector.h
filter_dc/ContentBoxCollector.h
View
@@ -1,6 +1,6 @@
/*
Scan Tailor - Interactive post-processing tool for scanned pages.
- Copyright (C) 2007-2008 Joseph Artsimovich <joseph_a@mail.ru>
+ Copyright (C) Joseph Artsimovich <joseph.artsimovich@gmail.com>
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
@@ -17,13 +17,17 @@
*/
#include "ErrorWidget.h"
+#include "ErrorWidget.h.moc"
#include <QStyle>
#include <QIcon>
-ErrorWidget::ErrorWidget(QString const& text)
+ErrorWidget::ErrorWidget(QString const& text, Qt::TextFormat fmt)
{
setupUi(this);
+ textLabel->setTextFormat(fmt);
textLabel->setText(text);
QIcon icon(QApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning));
imageLabel->setPixmap(icon.pixmap(48, 48));
+
+ connect(textLabel, SIGNAL(linkActivated(QString const&)), SLOT(linkActivated(QString const&)));
}
View
@@ -1,6 +1,6 @@
/*
Scan Tailor - Interactive post-processing tool for scanned pages.
- Copyright (C) 2007-2008 Joseph Artsimovich <joseph_a@mail.ru>
+ Copyright (C) Joseph Artsimovich <joseph.artsimovich@gmail.com>
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
@@ -21,13 +21,20 @@
#include "ui_ErrorWidget.h"
#include <QWidget>
+#include <Qt>
class QString;
class ErrorWidget : public QWidget, private Ui::ErrorWidget
{
+ Q_OBJECT
public:
- ErrorWidget(QString const& text);
+ ErrorWidget(QString const& text, Qt::TextFormat fmt = Qt::AutoText);
+private slots:
+ /**
+ * \see QLabel::linkActivated()
+ */
+ virtual void linkActivated(QString const& link) {}
};
#endif
@@ -17,6 +17,8 @@
*/
#include "FileNameDisambiguator.h"
+#include "RelinkablePath.h"
+#include "AbstractRelinker.h"
#include <QString>
#include <QFileInfo>
#include <QDomDocument>
@@ -46,6 +48,8 @@ class FileNameDisambiguator::Impl
int getLabel(QString const& file_path) const;
int registerFile(QString const& file_path);
+
+ void performRelinking(AbstractRelinker const& relinker);
private:
class ItemsByFilePathTag;
class ItemsByFileNameLabelTag;
@@ -139,6 +143,12 @@ FileNameDisambiguator::registerFile(QString const& file_path)
return m_ptrImpl->registerFile(file_path);
}
+void
+FileNameDisambiguator::performRelinking(AbstractRelinker const& relinker)
+{
+ m_ptrImpl->performRelinking(relinker);
+}
+
/*==================== FileNameDisambiguator::Impl ====================*/
@@ -250,6 +260,21 @@ FileNameDisambiguator::Impl::registerFile(QString const& file_path)
return label;
}
+void
+FileNameDisambiguator::Impl::performRelinking(AbstractRelinker const& relinker)
+{
+ QMutexLocker const locker(&m_mutex);
+ Container new_items;
+
+ BOOST_FOREACH(Item const& item, m_unorderedItems) {
+ RelinkablePath const old_path(item.filePath, RelinkablePath::File);
+ Item new_item(relinker.substitutionPathFor(old_path), item.label);
+ new_items.insert(new_item);
+ }
+
+ m_items.swap(new_items);
+}
+
/*============================ Impl::Item =============================*/
@@ -25,6 +25,7 @@
#include <memory>
#include <set>
+class AbstractRelinker;
class QString;
class QDomElement;
class QDomDocument;
@@ -79,6 +80,8 @@ class FileNameDisambiguator : public RefCountable
int getLabel(QString const& file_path) const;
int registerFile(QString const& file_path);
+
+ void performRelinking(AbstractRelinker const& relinker);
private:
class Impl;
View
@@ -1,6 +1,6 @@
/*
Scan Tailor - Interactive post-processing tool for scanned pages.
- Copyright (C) 2007-2008 Joseph Artsimovich <joseph_a@mail.ru>
+ Copyright (C) Joseph Artsimovich <joseph.artsimovich@gmail.com>
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
@@ -20,6 +20,8 @@
#define FILTERUIINTERFACE_H_
#include "PageId.h"
+#include "AbstractCommand.h"
+#include "IntrusivePtr.h"
class DebugImages;
class FilterOptionsWidget;
@@ -45,6 +47,11 @@ class FilterUiInterface
virtual void invalidateThumbnail(PageId const& page_id) = 0;
virtual void invalidateAllThumbnails() = 0;
+
+ /**
+ * Returns a callable object that when called will open a relinking dialog.
+ */
+ virtual IntrusivePtr<AbstractCommand0<void> > relinkingDialogRequester() = 0;
};
#endif
View
@@ -36,9 +36,13 @@ class ImageId
bool isNull() const { return m_filePath.isNull(); }
QString const& filePath() const { return m_filePath; }
+
+ void setFilePath(QString const& path) { m_filePath = path; }
int page() const { return m_page; }
+ void setPage(int page) { m_page = page; }
+
int zeroBasedPage() const { return m_page > 0 ? m_page - 1 : 0; }
bool isMultiPageFile() const { return m_page > 0; }
View
@@ -31,16 +31,19 @@
#include "Dpm.h"
#include "FilterData.h"
#include "ImageLoader.h"
-#include "imageproc/BinaryThreshold.h"
#include <QCoreApplication>
+#include <QFile>
+#include <QDir>
#include <QImage>
#include <QString>
+#include <QTextDocument> // for Qt::escape()
#include <assert.h>
using namespace imageproc;
class LoadFileTask::ErrorResult : public FilterResult
{
+ Q_DECLARE_TR_FUNCTIONS(LoadFileTask)
public:
ErrorResult(QString const& file_path);
@@ -51,6 +54,7 @@ class LoadFileTask::ErrorResult : public FilterResult
}
private:
QString m_filePath;
+ bool m_fileExists;
};
@@ -125,19 +129,41 @@ LoadFileTask::overrideDpi(QImage& image) const
/*======================= LoadFileTask::ErrorResult ======================*/
LoadFileTask::ErrorResult::ErrorResult(QString const& file_path)
-: m_filePath(file_path)
+: m_filePath(QDir::toNativeSeparators(file_path))
+, m_fileExists(QFile::exists(file_path))
{
}
void
LoadFileTask::ErrorResult::updateUI(FilterUiInterface* ui)
{
- QString const err_msg(
- QCoreApplication::translate(
- "LoadFileTask",
- "The following file could not be loaded:\n%1"
- ).arg(m_filePath)
- );
- ui->setImageWidget(new ErrorWidget(err_msg), ui->TRANSFER_OWNERSHIP);
+ class ErrWidget : public ErrorWidget
+ {
+ public:
+ ErrWidget(IntrusivePtr<AbstractCommand0<void> > const& relinking_dialog_requester,
+ QString const& text, Qt::TextFormat fmt = Qt::AutoText)
+ : ErrorWidget(text, fmt), m_ptrRelinkingDialogRequester(relinking_dialog_requester) {}
+ private:
+ virtual void linkActivated(QString const&) {
+ (*m_ptrRelinkingDialogRequester)();
+ }
+
+ IntrusivePtr<AbstractCommand0<void> > m_ptrRelinkingDialogRequester;
+ };
+
+ QString err_msg;
+ Qt::TextFormat fmt = Qt::AutoText;
+ if (m_fileExists) {
+ err_msg = tr("The following file could not be loaded:\n%1").arg(m_filePath);
+ fmt = Qt::PlainText;
+ } else {
+ err_msg = tr(
+ "The following file doesn't exist:<br>%1<br>"
+ "<br>"
+ "Use the <a href=\"#relink\">Relinking Tool</a> to locate it."
+ ).arg(Qt::escape(m_filePath));
+ fmt = Qt::RichText;
+ }
+ ui->setImageWidget(new ErrWidget(ui->relinkingDialogRequester(), err_msg, fmt), ui->TRANSFER_OWNERSHIP);
ui->setOptionsWidget(new FilterOptionsWidget, ui->TRANSFER_OWNERSHIP);
}
Oops, something went wrong.

0 comments on commit 57606fc

Please sign in to comment.