~ubuntu-branches/ubuntu/trusty/gwenview/trusty

« back to all changes in this revision

Viewing changes to app/documentinfoprovider.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Rohan Garg
  • Date: 2011-07-20 13:46:34 UTC
  • Revision ID: james.westby@ubuntu.com-20110720134634-92930fdjeed4gdc9
Tags: upstream-4.6.90+repack
Import upstream version 4.6.90+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
 
2
/*
 
3
Gwenview: an image viewer
 
4
Copyright 2010 Aurélien Gâteau <agateau@kde.org>
 
5
 
 
6
This program is free software; you can redistribute it and/or
 
7
modify it under the terms of the GNU General Public License
 
8
as published by the Free Software Foundation; either version 2
 
9
of the License, or (at your option) any later version.
 
10
 
 
11
This program is distributed in the hope that it will be useful,
 
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
GNU General Public License for more details.
 
15
 
 
16
You should have received a copy of the GNU General Public License
 
17
along with this program; if not, write to the Free Software
 
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
 
19
 
 
20
*/
 
21
// Self
 
22
#include "documentinfoprovider.moc"
 
23
 
 
24
// Qt
 
25
#include <QPixmap>
 
26
 
 
27
// KDE
 
28
 
 
29
// Local
 
30
#include <lib/document/documentfactory.h>
 
31
#include <lib/semanticinfo/sorteddirmodel.h>
 
32
 
 
33
namespace Gwenview {
 
34
 
 
35
 
 
36
struct DocumentInfoProviderPrivate {
 
37
        SortedDirModel* mDirModel;
 
38
};
 
39
 
 
40
 
 
41
DocumentInfoProvider::DocumentInfoProvider(SortedDirModel* model)
 
42
: AbstractDocumentInfoProvider(model)
 
43
, d(new DocumentInfoProviderPrivate) {
 
44
        d->mDirModel = model;
 
45
        connect(DocumentFactory::instance(), SIGNAL(documentBusyStateChanged(const KUrl&, bool)),
 
46
                SLOT(emitBusyStateChanged(const KUrl&, bool)) );
 
47
 
 
48
        connect(DocumentFactory::instance(), SIGNAL(documentChanged(const KUrl&)),
 
49
                SLOT(emitDocumentChanged(const KUrl&)) );
 
50
}
 
51
 
 
52
 
 
53
DocumentInfoProvider::~DocumentInfoProvider() {
 
54
        delete d;
 
55
}
 
56
 
 
57
 
 
58
void DocumentInfoProvider::thumbnailForDocument(const KUrl& url, ThumbnailGroup::Enum group, QPixmap* outPix, QSize* outFullSize) const {
 
59
        Q_ASSERT(outPix);
 
60
        Q_ASSERT(outFullSize);
 
61
        *outPix = QPixmap();
 
62
        *outFullSize = QSize();
 
63
        DocumentFactory* factory = DocumentFactory::instance();
 
64
        const int pixelSize = ThumbnailGroup::pixelSize(group);
 
65
 
 
66
        if (!factory->hasUrl(url)) {
 
67
                return;
 
68
        }
 
69
 
 
70
        Document::Ptr doc = factory->load(url);
 
71
        if (doc->loadingState() != Document::Loaded) {
 
72
                return;
 
73
        }
 
74
 
 
75
        QImage image = doc->image();
 
76
        if (image.width() > pixelSize || image.height() > pixelSize) {
 
77
                image = image.scaled(pixelSize, pixelSize, Qt::KeepAspectRatio);
 
78
        }
 
79
        *outPix = QPixmap::fromImage(image);
 
80
        *outFullSize = doc->size();
 
81
}
 
82
 
 
83
 
 
84
bool DocumentInfoProvider::isModified(const KUrl& url) {
 
85
        DocumentFactory* factory = DocumentFactory::instance();
 
86
 
 
87
        if (factory->hasUrl(url)) {
 
88
                Document::Ptr doc = factory->load(url);
 
89
                return doc->loadingState() == Document::Loaded && doc->isModified();
 
90
        } else {
 
91
                return false;
 
92
        }
 
93
}
 
94
 
 
95
 
 
96
bool DocumentInfoProvider::isBusy(const KUrl& url) {
 
97
        DocumentFactory* factory = DocumentFactory::instance();
 
98
 
 
99
        if (factory->hasUrl(url)) {
 
100
                Document::Ptr doc = factory->load(url);
 
101
                return doc->isBusy();
 
102
        } else {
 
103
                return false;
 
104
        }
 
105
}
 
106
 
 
107
 
 
108
void DocumentInfoProvider::emitBusyStateChanged(const KUrl& url, bool busy) {
 
109
        QModelIndex index = d->mDirModel->indexForUrl(url);
 
110
        if (!index.isValid()) {
 
111
                return;
 
112
        }
 
113
        busyStateChanged(index, busy);
 
114
}
 
115
 
 
116
 
 
117
void DocumentInfoProvider::emitDocumentChanged(const KUrl& url) {
 
118
        QModelIndex index = d->mDirModel->indexForUrl(url);
 
119
        if (!index.isValid()) {
 
120
                return;
 
121
        }
 
122
        documentChanged(index);
 
123
}
 
124
 
 
125
 
 
126
} // namespace