File indexing completed on 2024-05-19 16:01:24

0001 /* This file is part of the KDE project
0002    Copyright (C) 2010 KO GmbH <jos.van.den.oever@kogmbh.com>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 #include "kpresenterslideloader.h"
0020 #include <KoPADocument.h>
0021 #include <KoPAPageBase.h>
0022 #include <kpluginfactory.h>
0023 #include <QDebug>
0024 
0025 KPresenterSlideLoader::KPresenterSlideLoader(QObject* parent) :SlideLoader(parent) {
0026     m_doc = 0;
0027     version = 0;
0028 }
0029 
0030 KPresenterSlideLoader::~KPresenterSlideLoader() {
0031     close();
0032 }
0033 void KPresenterSlideLoader::close() {
0034     delete m_doc;
0035     m_doc = 0;
0036     version++;
0037     emit slidesChanged();
0038 }
0039 
0040 void
0041 KPresenterSlideLoader::open(const QString& path)
0042 {
0043     close();
0044 
0045     KPluginFactory *factory = KPluginLoader("calligrastagepart", cd).factory();
0046     if (!factory) {
0047         qDebug() << "could not load calligrastagepart";
0048         close();
0049         return;
0050     }
0051     KoPADocument* doc = factory->create<KoPADocument>();
0052     m_doc = doc;
0053     KUrl url;
0054     url.setPath(path);
0055     doc->setCheckAutoSaveFile(false);
0056     doc->setAutoErrorHandlingEnabled(true); // show error dialogs
0057     if (!doc->openUrl(url)) {
0058         qDebug() << "could not open " << path;
0059         close();
0060         return;
0061     }
0062     doc->setReadWrite(false);
0063     doc->setAutoSave(0);
0064     emit slidesChanged();
0065 }
0066 int
0067 KPresenterSlideLoader::numberOfSlides() {
0068     return (m_doc) ?m_doc->pageCount() :0;
0069 }
0070 QSize KPresenterSlideLoader::slideSize() {
0071     if (!m_doc) return QSize();
0072     KoPAPageBase* page = m_doc->pages().value(0);
0073     if (!page) return QSize();
0074     return page->size().toSize();
0075 }
0076 QPixmap KPresenterSlideLoader::loadSlide(int number, const QSize& maxsize) {
0077     if (!m_doc) return QPixmap();
0078     KoPAPageBase* page = m_doc->pages().value(number);
0079     if (!page) return QPixmap();
0080     return page->thumbnail(maxsize);
0081 }