Commit 49c7d8bd authored by Aurélien Gâteau's avatar Aurélien Gâteau
Browse files

Started to port hierarchy of the Document class. Image loading is now

non-blocking, but not progressive yet.

svn path=/trunk/playground/graphics/gwenview/; revision=662689
parent 6357a0cb
set(gwenviewlib_SRCS
abstractdocumentimpl.cpp
archiveutils.cpp
document.cpp
documentfactory.cpp
documentloadedimpl.cpp
emptydocumentimpl.cpp
imagescaler.cpp
imageviewpart.cpp
loadingdocumentimpl.cpp
mimetypeutils.cpp
sorteddirmodel.cpp
thumbnailview.cpp
......
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau
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 2
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
// Self
#include "abstractdocumentimpl.moc"
// Qt
// KDE
// Local
#include "document.h"
namespace Gwenview {
struct AbstractDocumentImplPrivate {
Document* mDocument;
};
AbstractDocumentImpl::AbstractDocumentImpl(Document* document)
: d(new AbstractDocumentImplPrivate) {
d->mDocument = document;
}
AbstractDocumentImpl::~AbstractDocumentImpl() {
delete d;
}
Document* AbstractDocumentImpl::document() const {
return d->mDocument;
}
void AbstractDocumentImpl::switchToImpl(AbstractDocumentImpl* impl) {
d->mDocument->switchToImpl(impl);
}
void AbstractDocumentImpl::setDocumentImage(const QImage& image) {
d->mDocument->setImage(image);
}
} // namespace
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau
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 2
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef ABSTRACTDOCUMENTIMPL_H
#define ABSTRACTDOCUMENTIMPL_H
// Qt
#include <QObject>
// KDE
// Local
class QImage;
class QRect;
namespace Gwenview {
class Document;
class AbstractDocumentImplPrivate;
class AbstractDocumentImpl : public QObject {
Q_OBJECT
public:
AbstractDocumentImpl(Document*);
virtual ~AbstractDocumentImpl();
/**
* This method is called by Document::switchToImpl after it has connected
* signals to the object
*/
virtual void init() = 0;
virtual bool isLoaded() const = 0;
Q_SIGNALS:
void loaded();
protected:
Document* document() const;
void setDocumentImage(const QImage& image);
void switchToImpl(AbstractDocumentImpl* impl);
private:
AbstractDocumentImplPrivate* const d;
};
} // namespace
#endif /* ABSTRACTDOCUMENTIMPL_H */
......@@ -25,10 +25,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// KDE
#include <KUrl>
// Local
#include "emptydocumentimpl.h"
#include "loadingdocumentimpl.h"
namespace Gwenview {
struct DocumentPrivate {
AbstractDocumentImpl* mImpl;
KUrl mUrl;
QImage mImage;
};
......@@ -36,17 +42,19 @@ struct DocumentPrivate {
Document::Document()
: QObject()
, d(new DocumentPrivate) {
d->mImpl = new EmptyDocumentImpl(this);
}
Document::~Document() {
delete d->mImpl;
delete d;
}
void Document::load(const KUrl& url) {
d->mImage.load(url.path());
loaded();
d->mUrl = url;
switchToImpl(new LoadingDocumentImpl(this));
}
......@@ -55,7 +63,30 @@ QImage& Document::image() {
}
bool Document::isLoaded() const {
return true;
return d->mImpl->isLoaded();
}
void Document::switchToImpl(AbstractDocumentImpl* impl) {
// There should always be an implementation defined
Q_ASSERT(d->mImpl);
Q_ASSERT(impl);
delete d->mImpl;
d->mImpl=impl;
connect(d->mImpl, SIGNAL(loaded()),
this, SIGNAL(loaded()) );
d->mImpl->init();
}
void Document::setImage(const QImage& image) {
d->mImage = image;
}
KUrl Document::url() const {
return d->mUrl;
}
} // namespace
......@@ -30,13 +30,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <ksharedptr.h>
class QImage;
class QRect;
class KUrl;
namespace Gwenview {
class AbstractDocumentImpl;
class DocumentFactory;
class DocumentPrivate;
class GWENVIEWLIB_EXPORT Document : public QObject, public QSharedData {
Q_OBJECT
public:
......@@ -48,11 +51,18 @@ public:
QImage& image();
KUrl url() const;
Q_SIGNALS:
void loaded();
private:
friend class DocumentFactory;
friend class AbstractDocumentImpl;
void setImage(const QImage&);
void switchToImpl(AbstractDocumentImpl* impl);
Document();
DocumentPrivate * const d;
};
......
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau
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 2
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
// Self
#include "documentloadedimpl.h"
// Qt
// KDE
// Local
namespace Gwenview {
struct DocumentLoadedImplPrivate {
};
DocumentLoadedImpl::DocumentLoadedImpl(Document* document, const QImage& image)
: AbstractDocumentImpl(document)
, d(new DocumentLoadedImplPrivate) {
setDocumentImage(image);
}
DocumentLoadedImpl::~DocumentLoadedImpl() {
delete d;
}
void DocumentLoadedImpl::init() {
}
bool DocumentLoadedImpl::isLoaded() const {
return true;
}
} // namespace
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau
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 2
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef DOCUMENTLOADEDIMPL_H
#define DOCUMENTLOADEDIMPL_H
// Qt
// KDE
// Local
#include "abstractdocumentimpl.h"
namespace Gwenview {
class DocumentLoadedImplPrivate;
class DocumentLoadedImpl : public AbstractDocumentImpl {
public:
DocumentLoadedImpl(Document*, const QImage& image);
~DocumentLoadedImpl();
virtual void init();
virtual bool isLoaded() const;
private:
DocumentLoadedImplPrivate* const d;
};
} // namespace
#endif /* DOCUMENTLOADEDIMPL_H */
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau
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 2
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
// Self
#include "emptydocumentimpl.h"
// Qt
// KDE
// Local
namespace Gwenview {
EmptyDocumentImpl::EmptyDocumentImpl(Document* document)
: AbstractDocumentImpl(document)
{}
EmptyDocumentImpl::~EmptyDocumentImpl()
{}
void EmptyDocumentImpl::init() {
}
bool EmptyDocumentImpl::isLoaded() const {
return false;
}
} // namespace
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau
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 2
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef EMPTYDOCUMENTIMPL_H
#define EMPTYDOCUMENTIMPL_H
// Qt
// KDE
// Local
#include "abstractdocumentimpl.h"
namespace Gwenview {
class EmptyDocumentImpl : public AbstractDocumentImpl {
public:
EmptyDocumentImpl(Document*);
~EmptyDocumentImpl();
virtual void init();
virtual bool isLoaded() const;
};
} // namespace
#endif /* EMPTYDOCUMENTIMPL_H */
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau
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 2
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
// Self
#include "loadingdocumentimpl.moc"
// Qt
#include <QImage>
#include <QThread>
// KDE
#include <KUrl>
// Local
#include "document.h"
#include "documentloadedimpl.h"
namespace Gwenview {
class LoadingThread : public QThread {
public:
virtual void run() {
mImage.load(mUrl.path());
}
KUrl mUrl;
QImage mImage;
};
struct LoadingDocumentImplPrivate {
LoadingThread mThread;
};
LoadingDocumentImpl::LoadingDocumentImpl(Document* document)
: AbstractDocumentImpl(document)
, d(new LoadingDocumentImplPrivate) {
}
LoadingDocumentImpl::~LoadingDocumentImpl() {
if (d->mThread.isRunning()) {
d->mThread.terminate();
d->mThread.wait();
}
delete d;
}
void LoadingDocumentImpl::init() {
d->mThread.mUrl = document()->url();
connect(&d->mThread, SIGNAL(finished()), SLOT(slotImageLoaded()) );
d->mThread.start();
}
bool LoadingDocumentImpl::isLoaded() const {
return false;
}
void LoadingDocumentImpl::slotImageLoaded() {
Q_ASSERT(d->mThread.isFinished());
setDocumentImage(d->mThread.mImage);
loaded();
switchToImpl(new DocumentLoadedImpl(document(), d->mThread.mImage));
}
} // namespace
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
/*
Gwenview: an image viewer
Copyright 2007 Aurélien Gâteau
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 2
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
*/
#ifndef LOADINGDOCUMENTIMPL_H
#define LOADINGDOCUMENTIMPL_H
// Qt
// KDE
// Local
#include "abstractdocumentimpl.h"
namespace Gwenview {
class LoadingDocumentImplPrivate;
class LoadingDocumentImpl : public AbstractDocumentImpl {
Q_OBJECT
public:
LoadingDocumentImpl(Document*);
~LoadingDocumentImpl();
virtual void init();
virtual bool isLoaded() const;
private Q_SLOTS:
void slotImageLoaded();
private:
LoadingDocumentImplPrivate* const d;
};
} // namespace
#endif /* LOADINGDOCUMENTIMPL_H */
......@@ -61,12 +61,31 @@ GVPart::GVPart(QWidget* parentWidget, QObject* parent, const QStringList&)
bool GVPart::openFile() {
mDocument = DocumentFactory::instance()->load(localFilePath());
mView->setImage(mDocument->image());
return false;
}
bool GVPart::openUrl(const KUrl& url) {
if (!url.isValid()) {
return false;
}
setUrl(url);
mDocument = DocumentFactory::instance()->load(url);
connect(mDocument.data(), SIGNAL(loaded()), SLOT(setViewImageFromDocument()) );
if (mDocument->isLoaded()) {
setViewImageFromDocument();
}
return true;
}
void GVPart::setViewImageFromDocument() {
mView->setImage(mDocument->image());
emit setWindowCaption( url().prettyUrl() );
emit completed();
}
KAboutData* GVPart::createAboutData() {
KAboutData* aboutData = new KAboutData( "gvpart", I18N_NOOP("GVPart"),
"2.0", I18N_NOOP("Image Viewer"),
......
......@@ -41,11 +41,13 @@ public:
protected:
virtual bool openFile();