Permalink
Browse files

big fix: no more background tasks

with background tasks it was falling.
tasks are running directly.
  • Loading branch information...
1 parent f2bdfe1 commit 4ccf93858d2e170d9a6f6c3ecc8d31b2e53e284c @pejuko pejuko committed Feb 8, 2011
Showing with 51 additions and 95 deletions.
  1. +1 −0 .gitignore
  2. +19 −1 CommandLine.cpp
  3. +3 −0 CommandLine.h
  4. +22 −75 ConsoleBatch.cpp
  5. +2 −16 ConsoleBatch.h
  6. +1 −1 filters/fix_orientation/Task.cpp
  7. +3 −2 main.cpp
View
@@ -3,3 +3,4 @@ CMakeFiles
*.qm
*.h.moc
build/
+*~
View
@@ -6,13 +6,16 @@
#include "Dpi.h"
#include "ImageId.h"
+#include "version.h"
#include "CommandLine.h"
+#include "ProjectPages.h"
#include "ImageFileInfo.h"
#include "ImageMetadata.h"
QMap<QString, QString> CommandLine::s_options;
QString CommandLine::s_project_file = "";
+std::vector<QFileInfo> CommandLine::s_files;
std::vector<ImageFileInfo> CommandLine::s_images;
QString CommandLine::s_output_directory = ".";
@@ -35,12 +38,14 @@ CommandLine::parse_cli(QStringList const& argv)
{
QRegExp rx("^--([^=]+)=(.*)$");
QRegExp rx_switch("^--([^=]+)$");
- QRegExp rx_short("^-(.)$");
+ QRegExp rx_short("^-(.*)$");
QRegExp rx_project(".*\\.ScanTailor$", Qt::CaseInsensitive);
QMap<QString, QString> shortMap;
shortMap["h"] = "help";
shortMap["help"] = "help";
+ shortMap["v"] = "verbose";
+ shortMap["l"] = "layout";
shortMap["ld"] = "layout-direction";
// skip first argument (scantailor)
@@ -64,6 +69,7 @@ CommandLine::parse_cli(QStringList const& argv)
} else {
// image and output directory
QFileInfo file(argv[i]);
+ CommandLine::s_files.push_back(file);
if (i==(argv.size()-1)) {
// output directory
if (file.isDir()) {
@@ -101,6 +107,7 @@ CommandLine::printHelp()
{
std::cout << "\n";
std::cout << "Scan Tailor is a post-processing tool for scanned pages." << "\n";
+ std::cout << "Version: " << VERSION << "\n";
std::cout << "\n";
std::cout << "ScanTailor usage: " << "\n";
std::cout << "\t1) scantailor [options]" << "\n";
@@ -116,6 +123,8 @@ CommandLine::printHelp()
std::cout << "\n";
std::cout << "Options:" << "\n";
std::cout << "\t--help, -h" << "\n";
+ std::cout << "\t--verbose, -v" << "\n";
+ std::cout << "\t--layout=, -l=<1|2>\t\t-- default: 1" << "\n";
std::cout << "\t--layout-direction=, -ld=<lr|rl>\t-- default: lr" << "\n";
std::cout << "\t--dpi=<number>\t\t\t\t-- sets x and y dpi. default: 300" << "\n";
std::cout << "\t\t--dpi-x=<number>" << "\n";
@@ -124,6 +133,15 @@ CommandLine::printHelp()
}
+ProjectPages::LayoutType
+CommandLine::layout()
+{
+ ProjectPages::LayoutType lt = ProjectPages::ONE_PAGE_LAYOUT;
+ if (CommandLine::s_options["layout"] == "2")
+ lt = ProjectPages::TWO_PAGE_LAYOUT;
+ return lt;
+}
+
Qt::LayoutDirection
CommandLine::layoutDirection()
{
View
@@ -26,6 +26,7 @@
#include <QStringList>
#include "Dpi.h"
+#include "ProjectPages.h"
#include "ImageFileInfo.h"
// CommandLine is a singleton simulation; if you create anywhere object CommandLine
@@ -34,6 +35,7 @@ class CommandLine
{
static QMap<QString, QString> s_options;
static QString s_project_file;
+ static std::vector<QFileInfo> s_files;
static std::vector<ImageFileInfo> s_images;
static QString s_output_directory;
@@ -55,6 +57,7 @@ class CommandLine
QString const operator[](QString const& key) const { return CommandLine::s_options.value(key); };
bool help() { return (CommandLine::s_options["help"] == "true"); };
+ ProjectPages::LayoutType layout();
Qt::LayoutDirection layoutDirection();
void dpi(int &xdpi, int &ydpi) { CommandLine::getDpi(xdpi, ydpi); };
View
@@ -61,21 +61,20 @@
#include "filters/output/CacheDrivenTask.h"
#include "ConsoleBatch.h"
-#include "ConsoleBatch.h.moc"
+//#include "ConsoleBatch.h.moc"
+#include "CommandLine.h"
ConsoleBatch::ConsoleBatch(MainWindow* main_w)
-: batch(true), debug(true), main_wnd(main_w),
- m_ptrWorkerThread(new WorkerThread()),
- m_ptrBatchQueue(new ProcessingTaskQueue(ProcessingTaskQueue::SEQUENTIAL_ORDER)),
+: batch(true), debug(true), main_wnd(main_w),
disambiguator(new FileNameDisambiguator)
+{};
+
+
+ConsoleBatch::~ConsoleBatch()
{
- connect(
- m_ptrWorkerThread.get(),
- SIGNAL(taskResult(BackgroundTaskPtr const&, FilterResultPtr const&)),
- this, SLOT(filterResult(BackgroundTaskPtr const&, FilterResultPtr const&))
- );
-};
+ delete(disambiguator);
+}
BackgroundTaskPtr
@@ -138,7 +137,7 @@ ConsoleBatch::createCompositeTask(
return BackgroundTaskPtr(
new LoadFileTask(
- batch ? BackgroundTask::BATCH : BackgroundTask::INTERACTIVE,
+ BackgroundTask::BATCH,
page, m_ptrThumbnailCache, m_ptrPages, fix_orientation_task
)
);
@@ -149,77 +148,25 @@ ConsoleBatch::createCompositeTask(
void
ConsoleBatch::process(std::vector<ImageFileInfo> const& images, QString const& output_dir, Qt::LayoutDirection const layout)
{
- IntrusivePtr<ProjectPages> pages(new ProjectPages(images, ProjectPages::AUTO_PAGES, layout));
- StageSequence* stages = new StageSequence(pages, PageSelectionAccessor(main_wnd));
+ IntrusivePtr<ProjectPages> pages(new ProjectPages(images, ProjectPages::AUTO_PAGES, layout));
+ StageSequence* stages = new StageSequence(pages, PageSelectionAccessor(main_wnd));
IntrusivePtr<ThumbnailPixmapCache> thumbnail_cache = IntrusivePtr<ThumbnailPixmapCache>(new ThumbnailPixmapCache(output_dir+"/cache/thumbs", QSize(200,200), 40, 5));
- OutputFileNameGenerator out_filename_gen(disambiguator, output_dir, pages->layoutDirection());
+ OutputFileNameGenerator out_filename_gen(disambiguator, output_dir, pages->layoutDirection());
- // Create batch queue
+ CommandLine cli;
+ pages->setLayoutTypeForAllPages(cli.layout());
+
+ // simulate clicking on batch processing button one by one
PageSequence page_sequence = pages->toPageSequence(IMAGE_VIEW);
for (int j=0; j<stages->count(); j++) {
+ if (cli["verbose"] == "true")
+ std::cout << "Filter: " << j << "\n";
for (unsigned i=0; i<page_sequence.numPages(); i++) {
PageInfo page = page_sequence.pageAt(i);
+ if (cli["verbose"] == "true")
+ std::cout << "\tProcessing: " << page.imageId().filePath().toAscii().constData() << "\n";
BackgroundTaskPtr bgTask = createCompositeTask(stages, thumbnail_cache, out_filename_gen, page, pages, j);
- m_ptrBatchQueue->addProcessingTask(page, bgTask);
+ (*bgTask)();
}
}
-
- // Start processing the first image
- BackgroundTaskPtr const task(m_ptrBatchQueue->takeForProcessing());
- m_ptrWorkerThread->performTask(task);
-}
-
-
-// remove finished task from queue and schedule new one
-void
-ConsoleBatch::filterResult(BackgroundTaskPtr const& task, FilterResultPtr const& result)
-{
- m_ptrBatchQueue->processingFinished(task);
-
-#ifdef DEBUG_CLI
- PageInfo const page(m_ptrBatchQueue->selectedPage());
- if (!page.isNull()) {
- std::cout << "Finished: " << page.imageId().filePath().toAscii().constData() << "\n";
- }
-#endif
-
- if (isBatchProcessingInProgress()) {
- // if all images were processed, shutdown
- if (m_ptrBatchQueue->allProcessed()) {
- stopBatchProcessing();
- return;
- }
-
- // schedule new one
- BackgroundTaskPtr const task(m_ptrBatchQueue->takeForProcessing());
- if (task) {
- m_ptrWorkerThread->performTask(task);
- }
- }
-}
-
-
-bool
-ConsoleBatch::isBatchProcessingInProgress() const
-{
- return m_ptrBatchQueue.get() != 0;
-}
-
-
-// shutdown
-void
-ConsoleBatch::stopBatchProcessing()
-{
- if (!isBatchProcessingInProgress()) {
- return;
- }
-
-#ifdef DEBUG_CLI
- std::cout << "Stopping..." << "\n";
-#endif
-
- m_ptrBatchQueue->cancelAndClear();
- m_ptrBatchQueue.reset();
-
- main_wnd->close();
}
View
@@ -37,32 +37,23 @@
#include "OutputFileNameGenerator.h"
-class ConsoleBatch :
- public QObject
+class ConsoleBatch
{
- DECLARE_NON_COPYABLE(ConsoleBatch)
- Q_OBJECT
-
public:
ConsoleBatch(MainWindow* main_w);
- //virtual ~ConsoleBatch();
+ virtual ~ConsoleBatch();
void process(
//std::vector<ImageInfo> const& images,
std::vector<ImageFileInfo> const& images,
QString const& output_dir,
Qt::LayoutDirection const layout);
- bool isBatchProcessingInProgress() const;
- void stopBatchProcessing();
-
private:
bool batch;
bool debug;
MainWindow *main_wnd;
- std::auto_ptr<WorkerThread> m_ptrWorkerThread;
- std::auto_ptr<ProcessingTaskQueue> m_ptrBatchQueue;
IntrusivePtr<FileNameDisambiguator> disambiguator;
BackgroundTaskPtr createCompositeTask(
@@ -72,11 +63,6 @@ class ConsoleBatch :
PageInfo const& page,
IntrusivePtr<ProjectPages> const m_ptrPages,
int const last_filter_idx);
-
-private slots:
- void filterResult(
- BackgroundTaskPtr const& task,
- FilterResultPtr const& result);
};
#endif
@@ -27,6 +27,7 @@
#include "ImageView.h"
#include "FilterUiInterface.h"
#include <QImage>
+#include <iostream>
namespace fix_orientation
{
@@ -115,7 +116,6 @@ void
Task::UiUpdater::updateUI(FilterUiInterface* ui)
{
// This function is executed from the GUI thread.
-
OptionsWidget* const opt_widget = m_ptrFilter->optionsWidget();
opt_widget->postUpdateUI(m_xform.preRotation());
ui->setOptionsWidget(opt_widget, ui->KEEP_OWNERSHIP);
View
@@ -197,7 +197,8 @@ int main(int argc, char** argv)
main_wnd->hide();
ConsoleBatch cbatch(main_wnd);
cbatch.process(cli.images(), cli.outputDirectory(), cli.layoutDirection());
+ main_wnd->close();
+ } else {
+ return app.exec();
}
-
- return app.exec();
}

0 comments on commit 4ccf938

Please sign in to comment.