mirror of https://github.com/procxx/kepka.git
Remove CancelledFileLoader hack.
This commit is contained in:
parent
274fed3cb0
commit
46d8d9f97a
|
@ -437,9 +437,6 @@ public slots:
|
|||
|
||||
};
|
||||
|
||||
static FileLoader * const CancelledFileLoader = SharedMemoryLocation<FileLoader, 0>();
|
||||
static mtpFileLoader * const CancelledMtpFileLoader = static_cast<mtpFileLoader*>(CancelledFileLoader);
|
||||
static webFileLoader * const CancelledWebFileLoader = static_cast<webFileLoader*>(CancelledFileLoader);
|
||||
static WebLoadManager * const FinishedWebLoadManager = SharedMemoryLocation<WebLoadManager, 0>();
|
||||
|
||||
void stopWebLoadManager();
|
||||
|
|
|
@ -271,13 +271,14 @@ QByteArray LocalFileSource::bytesForCache() {
|
|||
}
|
||||
|
||||
QImage RemoteSource::takeLoaded() {
|
||||
if (!loaderValid() || !_loader->finished()) {
|
||||
if (!_loader || !_loader->finished()) {
|
||||
return QImage();
|
||||
}
|
||||
|
||||
auto data = _loader->imageData(shrinkBox());
|
||||
if (data.isNull()) {
|
||||
destroyLoader(CancelledFileLoader);
|
||||
_cancelled = true;
|
||||
destroyLoader();
|
||||
return QImage();
|
||||
}
|
||||
|
||||
|
@ -288,34 +289,33 @@ QImage RemoteSource::takeLoaded() {
|
|||
return data;
|
||||
}
|
||||
|
||||
bool RemoteSource::loaderValid() const {
|
||||
return _loader && !cancelled();
|
||||
}
|
||||
void RemoteSource::destroyLoader() {
|
||||
if (!_loader) {
|
||||
return;
|
||||
}
|
||||
|
||||
void RemoteSource::destroyLoader(FileLoader *newValue) {
|
||||
Expects(loaderValid());
|
||||
|
||||
const auto loader = std::exchange(_loader, newValue);
|
||||
const auto loader = base::take(_loader);
|
||||
if (cancelled()) {
|
||||
loader->cancel();
|
||||
}
|
||||
loader->stop();
|
||||
delete loader;
|
||||
}
|
||||
|
||||
void RemoteSource::loadLocal() {
|
||||
if (loaderValid()) {
|
||||
return;
|
||||
if (_loader) {
|
||||
return;
|
||||
}
|
||||
|
||||
_loader = createLoader(Data::FileOrigin(), LoadFromLocalOnly, true);
|
||||
if (_loader) _loader->start();
|
||||
if (_loader) {
|
||||
_loader->start();
|
||||
}
|
||||
}
|
||||
|
||||
void RemoteSource::setImageBytes(const QByteArray &bytes) {
|
||||
if (bytes.isEmpty()) {
|
||||
return;
|
||||
} else if (loaderValid()) {
|
||||
} else if (_loader) {
|
||||
unload();
|
||||
}
|
||||
_loader = createLoader({}, LoadFromLocalOnly, true);
|
||||
|
@ -334,7 +334,7 @@ void RemoteSource::setImageBytes(const QByteArray &bytes) {
|
|||
}
|
||||
|
||||
bool RemoteSource::loading() {
|
||||
return loaderValid();
|
||||
return (_loader != nullptr);
|
||||
}
|
||||
|
||||
void RemoteSource::automaticLoad(
|
||||
|
@ -358,60 +358,55 @@ void RemoteSource::automaticLoad(
|
|||
loadFromCloud ? LoadFromCloudOrLocal : LoadFromLocalOnly,
|
||||
true);
|
||||
}
|
||||
if (loaderValid()) {
|
||||
if (_loader) {
|
||||
_loader->start();
|
||||
}
|
||||
}
|
||||
|
||||
void RemoteSource::automaticLoadSettingsChanged() {
|
||||
if (_loader == CancelledFileLoader) {
|
||||
_loader = nullptr;
|
||||
}
|
||||
_cancelled = false;
|
||||
}
|
||||
|
||||
void RemoteSource::load(Data::FileOrigin origin) {
|
||||
if (!_loader) {
|
||||
_loader = createLoader(origin, LoadFromCloudOrLocal, false);
|
||||
}
|
||||
if (loaderValid()) {
|
||||
if (_loader) {
|
||||
_loader->start();
|
||||
}
|
||||
}
|
||||
|
||||
bool RemoteSource::cancelled() const {
|
||||
return (_loader == CancelledFileLoader);
|
||||
return _cancelled;
|
||||
}
|
||||
|
||||
void RemoteSource::loadEvenCancelled(Data::FileOrigin origin) {
|
||||
if (cancelled()) {
|
||||
_loader = nullptr;
|
||||
}
|
||||
_cancelled = false;
|
||||
return load(origin);
|
||||
}
|
||||
|
||||
bool RemoteSource::displayLoading() {
|
||||
return loaderValid()
|
||||
&& (!_loader->loadingLocal() || !_loader->autoLoading());
|
||||
return _loader && (!_loader->loadingLocal() || !_loader->autoLoading());
|
||||
}
|
||||
|
||||
void RemoteSource::cancel() {
|
||||
if (!loaderValid()) return;
|
||||
|
||||
destroyLoader(CancelledFileLoader);
|
||||
if (!_loader) {
|
||||
return;
|
||||
}
|
||||
_cancelled = true;
|
||||
destroyLoader();
|
||||
}
|
||||
|
||||
void RemoteSource::unload() {
|
||||
if (loaderValid()) {
|
||||
delete base::take(_loader);
|
||||
}
|
||||
base::take(_loader);
|
||||
}
|
||||
|
||||
float64 RemoteSource::progress() {
|
||||
return loaderValid() ? _loader->currentProgress() : 0.;
|
||||
return _loader ? _loader->currentProgress() : 0.;
|
||||
}
|
||||
|
||||
int RemoteSource::loadOffset() {
|
||||
return loaderValid() ? _loader->currentOffset() : 0;
|
||||
return _loader ? _loader->currentOffset() : 0;
|
||||
}
|
||||
|
||||
RemoteSource::~RemoteSource() {
|
||||
|
@ -484,12 +479,12 @@ QSize StorageSource::shrinkBox() const {
|
|||
return QSize();
|
||||
}
|
||||
|
||||
FileLoader *StorageSource::createLoader(
|
||||
std::unique_ptr<FileLoader> StorageSource::createLoader(
|
||||
Data::FileOrigin origin,
|
||||
LoadFromCloudSetting fromCloud,
|
||||
bool autoLoading) {
|
||||
return _location.valid()
|
||||
? new mtpFileLoader(
|
||||
? std::make_unique<mtpFileLoader>(
|
||||
_location.file(),
|
||||
origin,
|
||||
UnknownFileLocation,
|
||||
|
@ -554,18 +549,18 @@ QSize WebCachedSource::shrinkBox() const {
|
|||
return _box;
|
||||
}
|
||||
|
||||
FileLoader *WebCachedSource::createLoader(
|
||||
std::unique_ptr<FileLoader> WebCachedSource::createLoader(
|
||||
Data::FileOrigin origin,
|
||||
LoadFromCloudSetting fromCloud,
|
||||
bool autoLoading) {
|
||||
return _location.isNull()
|
||||
? nullptr
|
||||
: new mtpFileLoader(
|
||||
return !_location.isNull()
|
||||
? std::make_unique<mtpFileLoader>(
|
||||
_location,
|
||||
_size,
|
||||
fromCloud,
|
||||
autoLoading,
|
||||
Data::kImageCacheTag);
|
||||
Data::kImageCacheTag)
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
GeoPointSource::GeoPointSource(const GeoPointLocation &location)
|
||||
|
@ -604,11 +599,11 @@ QSize GeoPointSource::shrinkBox() const {
|
|||
return QSize();
|
||||
}
|
||||
|
||||
FileLoader *GeoPointSource::createLoader(
|
||||
std::unique_ptr<FileLoader> GeoPointSource::createLoader(
|
||||
Data::FileOrigin origin,
|
||||
LoadFromCloudSetting fromCloud,
|
||||
bool autoLoading) {
|
||||
return new mtpFileLoader(
|
||||
return std::make_unique<mtpFileLoader>(
|
||||
_location,
|
||||
_size,
|
||||
fromCloud,
|
||||
|
@ -740,11 +735,11 @@ QSize WebUrlSource::shrinkBox() const {
|
|||
return _box;
|
||||
}
|
||||
|
||||
FileLoader *WebUrlSource::createLoader(
|
||||
std::unique_ptr<FileLoader> WebUrlSource::createLoader(
|
||||
Data::FileOrigin origin,
|
||||
LoadFromCloudSetting fromCloud,
|
||||
bool autoLoading) {
|
||||
return new webFileLoader(
|
||||
return std::make_unique<webFileLoader>(
|
||||
_url,
|
||||
QString(),
|
||||
fromCloud,
|
||||
|
|
|
@ -142,7 +142,7 @@ protected:
|
|||
// If after loading the image we need to shrink it to fit into a
|
||||
// specific size, you can return this size here.
|
||||
virtual QSize shrinkBox() const = 0;
|
||||
virtual FileLoader *createLoader(
|
||||
virtual std::unique_ptr<FileLoader> createLoader(
|
||||
Data::FileOrigin origin,
|
||||
LoadFromCloudSetting fromCloud,
|
||||
bool autoLoading) = 0;
|
||||
|
@ -150,11 +150,11 @@ protected:
|
|||
void loadLocal();
|
||||
|
||||
private:
|
||||
bool loaderValid() const;
|
||||
bool cancelled() const;
|
||||
void destroyLoader(FileLoader *newValue = nullptr);
|
||||
void destroyLoader();
|
||||
|
||||
FileLoader *_loader = nullptr;
|
||||
std::unique_ptr<FileLoader> _loader;
|
||||
bool _cancelled = false;
|
||||
|
||||
};
|
||||
|
||||
|
@ -176,7 +176,7 @@ public:
|
|||
|
||||
protected:
|
||||
QSize shrinkBox() const override;
|
||||
FileLoader *createLoader(
|
||||
std::unique_ptr<FileLoader> createLoader(
|
||||
Data::FileOrigin origin,
|
||||
LoadFromCloudSetting fromCloud,
|
||||
bool autoLoading) override;
|
||||
|
@ -204,7 +204,7 @@ public:
|
|||
|
||||
protected:
|
||||
QSize shrinkBox() const override;
|
||||
FileLoader *createLoader(
|
||||
std::unique_ptr<FileLoader> createLoader(
|
||||
Data::FileOrigin origin,
|
||||
LoadFromCloudSetting fromCloud,
|
||||
bool autoLoading) override;
|
||||
|
@ -230,7 +230,7 @@ public:
|
|||
|
||||
protected:
|
||||
QSize shrinkBox() const override;
|
||||
FileLoader *createLoader(
|
||||
std::unique_ptr<FileLoader> createLoader(
|
||||
Data::FileOrigin origin,
|
||||
LoadFromCloudSetting fromCloud,
|
||||
bool autoLoading) override;
|
||||
|
@ -289,7 +289,7 @@ public:
|
|||
|
||||
protected:
|
||||
QSize shrinkBox() const override;
|
||||
FileLoader *createLoader(
|
||||
std::unique_ptr<FileLoader> createLoader(
|
||||
Data::FileOrigin origin,
|
||||
LoadFromCloudSetting fromCloud,
|
||||
bool autoLoading) override;
|
||||
|
|
Loading…
Reference in New Issue