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

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 #ifndef OOTHREAD_H
0020 #define OOTHREAD_H
0021 
0022 #include <QThread>
0023 #include <QAtomicInt>
0024 #include <QMutex>
0025 #include <QWaitCondition>
0026 #include <QPair>
0027 
0028 class OoThread : public QThread {
0029 Q_OBJECT
0030 private:
0031     QAtomicInt running;
0032     QMutex mutex;
0033     QWaitCondition moreWork;
0034     class Conversion {
0035     public:
0036         QString from;
0037         QString to;
0038         int width;
0039         operator bool() {
0040             return !from.isEmpty();
0041         }
0042     };
0043     Conversion currentToOdp;
0044     Conversion currentToPng;
0045     Conversion nextToOdp;
0046     Conversion nextToPng;
0047     class OOConnection;
0048     OOConnection* oo;
0049 
0050     void convertToOdp(const Conversion& c);
0051     void convertToPng(const Conversion& c);
0052 protected:
0053     void run();
0054 public:
0055     explicit OoThread(QObject* o);
0056     ~OoThread();
0057 
0058     void stop();
0059 
0060     /**
0061      * Read ppt file at path and convert it to an odp file.
0062      * The path where the new file will occur is returned.
0063      **/
0064     QString toOdp(const QString& path);
0065     /**
0066      * Read file at path and convert it to png files in a new temporary
0067      * directory. The path of the directory where the files will occur is
0068      * returned.
0069      **/
0070     QString toPng(const QString& path, int pngwidth);
0071     /**
0072      * Return true of the job for which the given output is given, is still
0073      * waiting or busy.
0074      **/
0075     bool waitingOrBusy(const QString& path);
0076 Q_SIGNALS:
0077     void toOdpDone(const QString& odppath);
0078     void toPngDone(const QString& odppath);
0079 };
0080 
0081 #endif