File indexing completed on 2024-05-12 16:35:05

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2007, 2009 Thomas Zander <zander@kde.org>
0003  * Copyright (C) 2007 Jan Hambrecht <jaham@gmx.net>
0004  * Copyright (C) 2008 Thorsten Zachmann <zachmann@kde.org>
0005  * Copyright (C) 2012 Gopalakrishna Bhat A <gopalakbhat@gmail.com>
0006  *
0007  * This library is free software; you can redistribute it and/or
0008  * modify it under the terms of the GNU Library General Public
0009  * License as published by the Free Software Foundation; either
0010  * version 2 of the License, or (at your option) any later version.
0011  *
0012  * This library is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  * Library General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Library General Public License
0018  * along with this library; see the file COPYING.LIB.  If not, write to
0019  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020  * Boston, MA 02110-1301, USA.
0021  */
0022 #ifndef VIDEODATA_H
0023 #define VIDEODATA_H
0024 
0025 #include <KoShapeUserData.h>
0026 
0027 class QIODevice;
0028 class QUrl;
0029 class VideoCollection;
0030 class VideoDataPrivate;
0031 class KoStore;
0032 
0033 /**
0034  * This class is meant to represent the video data so it can be shared between video shapes.
0035  * This class inherits from KoShapeUserData which means you can set it on any KoShape using
0036  * KoShape::setUserData() and get it using KoShape::userData().  The videoshape plugin
0037  * uses this class to show its video data.
0038  */
0039 class VideoData : public KoShapeUserData
0040 {
0041     Q_OBJECT
0042 public:
0043     /// Various error codes representing what has gone wrong
0044     enum ErrorCode {
0045         Success,
0046         OpenFailed,
0047         StorageFailed, ///< This is set if the video data has to be stored on disk in a temporary file, but we failed to do so
0048         LoadFailed
0049     };
0050 
0051     /// default constructor, creates an invalid imageData object
0052     VideoData();
0053 
0054     /**
0055      * copy constructor
0056      * @param videoData the other one.
0057      */
0058     VideoData(const VideoData &videoData);
0059     
0060     /// destructor
0061     virtual ~VideoData();
0062 
0063     void setExternalVideo(const QUrl &location, bool saveInternal, VideoCollection *collection = 0);
0064     void setVideo(const QString &location, KoStore *store, VideoCollection *collection = 0);
0065     //void setVideo(const QUrl &location);
0066 
0067     /**
0068      * Save the video data to the param device.
0069      * The full file is saved.
0070      * @param device the device that is used to get the data from.
0071      * @return returns true if load was successful.
0072      */
0073     bool saveData(QIODevice &device);
0074 
0075     QString tagForSaving(int &counter);
0076 
0077     VideoData &operator=(const VideoData &other);
0078 
0079     inline bool operator!=(const VideoData &other) const { return !operator==(other); }
0080     bool operator==(const VideoData &other) const;
0081 
0082     /// returns if this is a valid imageData with actual video data present on it.
0083     bool isValid() const;
0084 
0085     QUrl playableUrl() const;
0086 
0087     QString saveName() const;
0088 
0089     void setSaveName(const QString &saveName);
0090 
0091     VideoCollection *collection();
0092     void setCollection(VideoCollection *collection);
0093 
0094     qint64 key();
0095 
0096     enum DataStoreState {
0097         StateEmpty,     ///< No video data, possible an external video
0098         StateSpooled, ///< Video data is spooled
0099     };
0100 protected:
0101     friend class VideoCollection;
0102 
0103     /// take the data from \a device and store it in the temporaryFile
0104     void copyToTemporary(QIODevice &device);
0105 
0106     void clear();
0107 
0108     static qint64 generateKey(const QByteArray &bytes);
0109 
0110 private:
0111     VideoDataPrivate *d;
0112 };
0113 
0114 #endif