File indexing completed on 2024-05-12 16:36:49

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2007 Thomas Zander <zander@kde.org>
0003  * Copyright (C) 2007 Jan Hambrecht <jaham@gmx.net>
0004  * Copyright (C) 2008 C. Boemann <cbo@boemann.dk>
0005  *
0006  * This library is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Library General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Library General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Library General Public License
0017  * along with this library; see the file COPYING.LIB.  If not, write to
0018  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019  * Boston, MA 02110-1301, USA.
0020  */
0021 #ifndef KPRSOUNDDATA_H
0022 #define KPRSOUNDDATA_H
0023 
0024 #include "stage_export.h"
0025 
0026 #include <QString>
0027 
0028 class KPrSoundCollection;
0029 class QIODevice;
0030 
0031 /**
0032  * Class meant to hold sound data so it can be shared between shapes.
0033  * In Stage shapes can have click actions attached to them. One such action is playing sound.
0034  * The binary data for those sounds are saved in this class.
0035  */
0036 
0037 /* 
0038  * TODO needs a file for playing, store it as a tmp file
0039  */
0040 class STAGE_EXPORT KPrSoundData {
0041 public:
0042     /**
0043      * The storage location
0044      */
0045     enum StorageLocation {
0046         SaveRelativeUrl,        ///< in the odf use a relative (to document) xlink:href, if possible
0047         SaveAbsoluteUrl,        ///< in the odf use a fully specified xlink:href
0048         SaveInStore            ///< Save the sound data in the ODF store
0049     };
0050 
0051     /**
0052      * constructor
0053      * @param collection the sound collection which will do the loading of the sound data for us.
0054      * @param href the url of the sound in the store.
0055      */
0056     explicit KPrSoundData(KPrSoundCollection *collection, const QString &href = QString());
0057 
0058     /**
0059      * copy constructor using ref-counting.
0060      * @param soundData the other one.
0061      */
0062     KPrSoundData(const KPrSoundData &soundData);
0063     /// destructor
0064     ~KPrSoundData();
0065 
0066     /**
0067      * Tags this sound to be saved and returns the href for reference in the xml.
0068      * @return returns the url-like location this sound will be saved to.
0069      */
0070     QString tagForSaving();
0071 
0072     /// returns the url-like location
0073     QString storeHref() const;
0074 
0075     /// returns the url-like location of the tmp file
0076     QString nameOfTempFile() const;
0077 
0078     /// returns the title of the sound (for now its the basename part of the filename
0079     QString title() const;
0080 
0081     /**
0082      * Load the sound data from the param device.
0083      * Note that it will copy the data to a temp-file and postpone loading it until the phonon plays it.
0084      * @para device the device that is used to get the data from.
0085      * @return returns true if load was successful.
0086      */
0087     bool loadFromFile(QIODevice *device);
0088 
0089     /**
0090      * Save the sound data to the param device.
0091      * The full file is saved.
0092      * @para device the device that is used to get the data from.
0093      * @return returns true if load was successful.
0094      */
0095     bool saveToFile(QIODevice *device);
0096 
0097     /**
0098      * Return whether this sound have been tagged for saving.
0099      * @return returns true if this sound should be saved.
0100      */
0101     bool isTaggedForSaving();
0102 
0103 
0104     bool operator==(const KPrSoundData &other) const;
0105 
0106     /**
0107      * Get the collection used
0108      */
0109     KPrSoundCollection * soundCollection();
0110 
0111 private:
0112     class Private;
0113     Private * const d;
0114 };
0115 
0116 #endif
0117