2015-02-12 12:16:25 -03:00
|
|
|
// Aseprite
|
|
|
|
// Copyright (C) 2001-2015 David Capello
|
|
|
|
//
|
2016-08-26 17:02:58 -03:00
|
|
|
// This program is distributed under the terms of
|
|
|
|
// the End-User License Agreement for Aseprite.
|
2013-08-05 21:20:19 -03:00
|
|
|
|
|
|
|
#ifndef APP_THUMBNAIL_GENERATOR_H_INCLUDED
|
|
|
|
#define APP_THUMBNAIL_GENERATOR_H_INCLUDED
|
2014-03-29 19:40:17 -03:00
|
|
|
#pragma once
|
2013-08-05 21:20:19 -03:00
|
|
|
|
|
|
|
#include "base/mutex.h"
|
|
|
|
#include "base/unique_ptr.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace base {
|
|
|
|
class thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace app {
|
|
|
|
class IFileItem;
|
|
|
|
|
|
|
|
class ThumbnailGenerator {
|
|
|
|
public:
|
|
|
|
enum WorkerStatus { WithoutWorker, WorkingOnThumbnail, ThumbnailIsDone };
|
|
|
|
|
|
|
|
static ThumbnailGenerator* instance();
|
|
|
|
|
|
|
|
// Generate a thumbnail for the given file-item. It must be called
|
|
|
|
// from the GUI thread.
|
|
|
|
void addWorkerToGenerateThumbnail(IFileItem* fileitem);
|
|
|
|
|
|
|
|
// Returns the status of the worker that is generating the thumbnail
|
|
|
|
// for the given file.
|
|
|
|
WorkerStatus getWorkerStatus(IFileItem* fileitem, double& progress);
|
|
|
|
|
|
|
|
// Checks the status of workers. If there are workers that already
|
|
|
|
// done its job, we've to destroy them. This function must be called
|
|
|
|
// from the GUI thread (because a thread is joint to it).
|
|
|
|
// Returns true if there are workers generating thumbnails.
|
|
|
|
bool checkWorkers();
|
|
|
|
|
|
|
|
// Stops all workers generating thumbnails. This is an non-blocking
|
|
|
|
// operation. The cancelation of all workers is done in a background
|
|
|
|
// thread.
|
|
|
|
void stopAllWorkers();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void stopAllWorkersBackground();
|
|
|
|
|
|
|
|
class Worker;
|
|
|
|
typedef std::vector<Worker*> WorkerList;
|
|
|
|
|
|
|
|
WorkerList m_workers;
|
|
|
|
base::mutex m_workersAccess;
|
|
|
|
base::UniquePtr<base::thread> m_stopThread;
|
|
|
|
};
|
|
|
|
} // namespace app
|
|
|
|
|
|
|
|
#endif
|