Krazy/EBN: fix i18n warnings
[kphotoalbum.git] / ImageManager / VideoManager.cpp
blob5a159ea7dce9df42df61b19a79e694c05ab9405f
1 /* Copyright (C) 2003-2006 Jesper K. Pedersen <blackie@kde.org>
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public
5 License as published by the Free Software Foundation; either
6 version 2 of the License, or (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; see the file COPYING. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
18 #include "VideoManager.h"
19 #include "ImageManager/ImageClient.h"
20 #include <kurl.h>
21 #include "ImageRequest.h"
22 #include "Utilities/Util.h"
23 #include <kio/previewjob.h>
24 #include <Settings/SettingsData.h>
25 #include <qimage.h>
26 #include <QPixmap>
27 #include <kiconloader.h>
29 ImageManager::VideoManager::VideoManager()
30 :_currentRequest(0)
34 ImageManager::VideoManager& ImageManager::VideoManager::instance()
36 static VideoManager manager;
37 return manager;
40 void ImageManager::VideoManager::request( ImageRequest* request )
42 _pending.addRequest( request );
44 if ( _currentRequest == 0 )
45 requestLoadNext();
48 void ImageManager::VideoManager::load( ImageRequest* request )
50 _currentRequest = request;
51 KUrl::List list;
52 list.append( request->fileName() );
53 KIO::PreviewJob* job=KIO::filePreview(list, request->width() );
54 job->setIgnoreMaximumSize( true );
56 connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)),
57 this, SLOT(slotGotPreview(const KFileItem&, const QPixmap&)) );
58 connect(job, SIGNAL(failed(const KFileItem&)),
59 this, SLOT(previewFailed()) );
62 void ImageManager::VideoManager::slotGotPreview(const KFileItem&, const QPixmap& pixmap )
64 if ( _pending.isRequestStillValid(_currentRequest) ) {
65 _currentRequest->setLoadedOK( true );
66 QImage img = pixmap.toImage();
67 _currentRequest->client()->pixmapLoaded( _currentRequest->fileName(), pixmap.size(), QSize(-1,-1), 0, img, !pixmap.isNull());
70 requestLoadNext();
73 void ImageManager::VideoManager::previewFailed()
75 if ( _pending.isRequestStillValid(_currentRequest) ) {
76 QPixmap pix = KIconLoader::global()->loadIcon( QString::fromLatin1("video"), KIconLoader::Desktop,
77 Settings::SettingsData::instance()->thumbSize() );
78 _currentRequest->setLoadedOK( false );
79 _currentRequest->client()->pixmapLoaded( _currentRequest->fileName(), pix.size(), pix.size(), 0, pix.toImage(), true);
82 requestLoadNext();
85 void ImageManager::VideoManager::requestLoadNext()
87 if ( _currentRequest )
88 _pending.removeRequest( _currentRequest );
89 _currentRequest = _pending.popNext();
90 if ( _currentRequest )
91 load( _currentRequest );
94 void ImageManager::VideoManager::stop( ImageClient* client, StopAction action )
96 _pending.cancelRequests( client, action );
100 bool ImageManager::VideoManager::hasVideoThumbnailSupport() const
102 KUrl::List list;
103 list.append(Utilities::locateDataFile(QString::fromLatin1("demo/movie.avi")));
104 KIO::PreviewJob* job=KIO::filePreview(list, 64 );
105 job->setIgnoreMaximumSize( true );
107 connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)),
108 this, SLOT(testGotPreview(const KFileItem&, const QPixmap&)) );
109 connect(job, SIGNAL(failed(const KFileItem&)),
110 this, SLOT(testPreviewFailed()) );
112 _eventLoop.exec();
113 return _hasVideoSupport;
116 void ImageManager::VideoManager::testGotPreview(const KFileItem&, const QPixmap& pixmap )
118 _hasVideoSupport = !pixmap.isNull();
119 _eventLoop.exit();
122 void ImageManager::VideoManager::testPreviewFailed()
124 _hasVideoSupport = false;
125 _eventLoop.exit();
128 #include "VideoManager.moc"