diff --git a/krita/image/metadata/kis_meta_data_entry.cc b/krita/image/metadata/kis_meta_data_entry.cc index cdc8ce543e7..288c27960aa 100644 --- a/krita/image/metadata/kis_meta_data_entry.cc +++ b/krita/image/metadata/kis_meta_data_entry.cc @@ -1,149 +1,149 @@ /* * Copyright (c) 2007 Cyrille Berger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kis_meta_data_entry.h" #include #include #include "kis_meta_data_value.h" #include "kis_meta_data_schema.h" using namespace KisMetaData; struct Entry::Private { QString name; const Schema* schema; Value value; bool valid; }; Entry::Entry() : d(new Private) { d->name = ""; d->schema = 0; d->valid = false; } Entry::Entry(const Schema* schema, QString name, const Value& value) : d(new Private) { Q_ASSERT(!name.isEmpty()); if (!isValidName(name)) { errKrita << "Invalid metadata name:" << name; d->name = QString("INVALID: %s").arg(name); } else { d->name = name; } d->schema = schema; d->value = value; d->valid = true; } Entry::Entry(const Entry& e) : d(new Private()) { d->valid = false; *this = e; } Entry::~Entry() { delete d; } QString Entry::name() const { return d->name; } const Schema* Entry::schema() const { Q_ASSERT(d->schema); return d->schema; } void Entry::setSchema(const KisMetaData::Schema* schema) { d->schema = schema; } QString Entry::qualifiedName() const { return d->schema->generateQualifiedName(d->name); } const Value& Entry::value() const { return d->value; } Value& Entry::value() { return d->value; } bool Entry::isValid() const { return d->valid; } bool Entry::isValidName(const QString& _name) { if (_name.length() < 1) { dbgImage << "Too small"; return false; } if (!_name[0].isLetter()) { dbgImage << _name << " doesn't start by a letter"; return false; } for (int i = 1; i < _name.length(); ++i) { QChar c = _name[i]; if (!c.isLetterOrNumber()) { dbgImage << _name << " " << i << "th character isn't a letter or a digit"; return false; } } return true; } -bool Entry::operator==(const Entry& e) +bool Entry::operator==(const Entry& e) const { return qualifiedName() == e.qualifiedName(); } Entry& Entry::operator=(const Entry & e) { if (e.isValid()) { Q_ASSERT(!isValid() || *this == e); d->name = e.d->name; d->schema = e.d->schema; d->value = e.d->value; d->valid = true; } return *this; } QDebug operator<<(QDebug debug, const Entry &c) { debug.nospace() << "Name: " << c.name() << " Qualified name: " << c.qualifiedName() << " Value: " << c.value(); return debug.space(); } diff --git a/krita/image/metadata/kis_meta_data_entry.h b/krita/image/metadata/kis_meta_data_entry.h index 94852811efb..704e03819f6 100644 --- a/krita/image/metadata/kis_meta_data_entry.h +++ b/krita/image/metadata/kis_meta_data_entry.h @@ -1,96 +1,96 @@ /* * Copyright (c) 2007 Cyrille Berger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _KIS_META_DATA_ENTRY_H_ #define _KIS_META_DATA_ENTRY_H_ #include class QString; namespace KisMetaData { class Value; class Store; class Schema; /** * Represent a metadata entry, a name and a value (\ref KisMetaData::Value). */ class KRITAIMAGE_EXPORT Entry { struct Private; friend class Store; public: /** * Create an invalid entry */ Entry(); /** * Create a new entry. * @param name * @param namespacePrefix * @param value */ Entry(const KisMetaData::Schema* schema, QString name, const KisMetaData::Value& value); Entry(const Entry&); ~Entry(); /** * @return the name of this entry */ QString name() const; /** * @return the namespace of this entry */ const KisMetaData::Schema* schema() const; /** * @return the qualified name of this entry, which is the concatenation of the * namespace and of the name */ QString qualifiedName() const; /** * @return the value of this entry */ const KisMetaData::Value& value() const; /** * @return the value of this entry */ KisMetaData::Value& value(); /** * @return true if this entry is valid */ bool isValid() const; /** * @return true if the name in argument is valid entry name. */ static bool isValidName(const QString& _name); /** * Affect the content of entry to this entry if entry is valid */ Entry& operator=(const Entry& entry); - bool operator==(const Entry&); + bool operator==(const Entry&) const; private: void setSchema(const KisMetaData::Schema* schema); private: Private* const d; }; } KRITAIMAGE_EXPORT QDebug operator<<(QDebug debug, const KisMetaData::Entry &c); #endif diff --git a/libs/odf/KoElementReference.cpp b/libs/odf/KoElementReference.cpp index 6672a9ed9c7..be8026b7217 100644 --- a/libs/odf/KoElementReference.cpp +++ b/libs/odf/KoElementReference.cpp @@ -1,114 +1,114 @@ /* * Copyright (c) 2011 Boudewijn Rempt * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KoElementReference.h" #include "KoXmlReader.h" #include "KoXmlWriter.h" #include KoElementReference::KoElementReference() : d(new KoElementReferenceData()) { d->xmlid = "id-" + d->xmlid; } KoElementReference::KoElementReference(const QString &prefix) : d(new KoElementReferenceData) { d->xmlid = prefix + "-" + d->xmlid; } KoElementReference::KoElementReference(const QString &prefix, int counter) : d(new KoElementReferenceData) { d->xmlid = QString("%1-%2").arg(prefix).arg(counter); } KoElementReference::KoElementReference(const KoElementReference &other) : d(other.d) { } KoElementReference &KoElementReference::operator=(const KoElementReference &rhs) { if (this == &rhs) return *this; d = rhs.d; return *this; } -bool KoElementReference::operator==(const KoElementReference &other) +bool KoElementReference::operator==(const KoElementReference &other) const { return d->xmlid == other.d->xmlid; } -bool KoElementReference::operator!=(const KoElementReference &other) +bool KoElementReference::operator!=(const KoElementReference &other) const { return !(*this == other); } bool KoElementReference::isValid() const { return (!d->xmlid.isEmpty()); } void KoElementReference::saveOdf(KoXmlWriter *writer, SaveOption saveOptions) const { if (d->xmlid.isEmpty()) return; writer->addAttribute("xml:id", d->xmlid); if (saveOptions & DrawId) { writer->addAttribute("draw:id", d->xmlid); } if (saveOptions & TextId) { writer->addAttribute("text:id", d->xmlid); } } QString KoElementReference::toString() const { return d->xmlid; } KoElementReference KoElementReference::loadOdf(const KoXmlElement &element) { QString xmlid; if (element.hasAttributeNS(KoXmlNS::xml, "id")) { xmlid = element.attributeNS(KoXmlNS::xml, "id"); } else if (element.hasAttributeNS(KoXmlNS::draw, "id")) { xmlid = element.attributeNS(KoXmlNS::draw, "id"); } else if (element.hasAttributeNS(KoXmlNS::text, "id")) { xmlid = element.attributeNS(KoXmlNS::text, "id"); } d->xmlid = xmlid; return *this; } void KoElementReference::invalidate() { d->xmlid.clear(); } diff --git a/libs/odf/KoElementReference.h b/libs/odf/KoElementReference.h index 3b3b1f652f4..ed356f002dc 100644 --- a/libs/odf/KoElementReference.h +++ b/libs/odf/KoElementReference.h @@ -1,132 +1,132 @@ /* * Copyright (c) 2011-2012 Boudewijn Rempt * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KOELEMENTREFERENCE_H #define KOELEMENTREFERENCE_H #include #include #include #include #include #include #include #include #include "koodf_export.h" class KoElementReferenceData : public QSharedData { public: KoElementReferenceData() { xmlid = QUuid::createUuid().toString(); xmlid.remove('{'); xmlid.remove('}'); } KoElementReferenceData(const KoElementReferenceData &other) : QSharedData(other) , xmlid(other.xmlid) { } ~KoElementReferenceData() {} QString xmlid; }; /** * KoElementReference is used to store unique identifiers for elements in an odf document. * Element references are saved as xml:id and optionally for compatibility also as draw:id * and text:id. * * You can use element references wherever you would have used a QString to refer to the id * of an object. * * Element references are implicitly shared, so you can and should pass them along by value. */ class KOODF_EXPORT KoElementReference { public: enum GenerationOption { UUID = 0, Counter = 1 }; enum SaveOption { XmlId = 0x0, DrawId = 0x1, TextId = 0x2 }; Q_DECLARE_FLAGS(SaveOptions, SaveOption) KoElementReference(); explicit KoElementReference(const QString &prefix); KoElementReference(const QString &prefix, int counter); KoElementReference(const KoElementReference &other); KoElementReference &operator=(const KoElementReference &rhs); - bool operator==(const KoElementReference &other); - bool operator!=(const KoElementReference &other); + bool operator==(const KoElementReference &other) const; + bool operator!=(const KoElementReference &other) const; /** * @return true if the xmlid is valid, i.e., not null */ bool isValid() const; /** * @brief loadOdf creates a new KoElementReference from the given element. If the element * does not have an xml:id, draw:id or text:id attribute, and invalid element reference * is returned. * @param element the element that may contain xml:id, text:id or draw:id. xml:id has * priority. * @return a new element reference */ KoElementReference loadOdf(const KoXmlElement &element); /** * @brief saveOdf saves this element reference into the currently open element in the xml writer. * @param writer the writer we save to * @param saveOptions determines which attributes we save. We always save the xml:id. */ void saveOdf(KoXmlWriter *writer, SaveOption saveOption = XmlId) const; /** * @brief toString creates a QString from the element reference * @return a string that represents the element. Can be used in maps etc. */ QString toString() const; /** * Invalidate the reference */ void invalidate(); private: QSharedDataPointer d; }; Q_DECLARE_OPERATORS_FOR_FLAGS(KoElementReference::SaveOptions) #endif // KOELEMENTREFERENCE_H diff --git a/stage/part/KPrSoundData.cpp b/stage/part/KPrSoundData.cpp index 00c322108e8..524ed127722 100644 --- a/stage/part/KPrSoundData.cpp +++ b/stage/part/KPrSoundData.cpp @@ -1,188 +1,191 @@ /* This file is part of the KDE project * Copyright (C) 2007 Thomas Zander * Copyright (C) 2007 Jan Hambrecht * Copyright (C) 2008 C. Boemann * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KPrSoundData.h" #include "KPrSoundCollection.h" #include #include #include #include #include // make it a QSharedData class KPrSoundData::Private { public: Private(KPrSoundCollection *c) : refCount(0) , collection(c) , tempFile(0) , taggedForSaving(false) { } ~Private() { delete tempFile; } QString tempFileName; QString title; int refCount; QString storeHref; KPrSoundCollection *collection; KTemporaryFile *tempFile; bool taggedForSaving; }; KPrSoundData::KPrSoundData(KPrSoundCollection *collection, QString href) : d(new Private(collection)) { Q_ASSERT(collection); collection->addSound(this); d->storeHref = href; //TODO make sure the title is not duplicated d->title = href.section('/', -1); // TODO only works on linux like filenames Q_ASSERT(d->refCount == 1); } KPrSoundData::KPrSoundData(const KPrSoundData &soundData) : d(soundData.d) { d->refCount++; } KPrSoundData::~KPrSoundData() { if(--d->refCount == 0) { d->collection->removeSound(this); delete d; } } +bool KPrSoundData::operator==(const KPrSoundData &other) const { + return other.d == d; +} QString KPrSoundData::tagForSaving() { d->taggedForSaving=true; d->storeHref = QString("Sounds/%1").arg(d->title); return d->storeHref; } QString KPrSoundData::storeHref() const { return d->storeHref; } QString KPrSoundData::nameOfTempFile() const { return d->tempFileName; } QString KPrSoundData::title() const { return d->title; } bool KPrSoundData::saveToFile(QIODevice *device) { if(! d->tempFile->open()) return false; char * data = new char[32 * 1024]; while(true) { bool failed = false; qint64 bytes = d->tempFile->read(data, 32*1024); if(bytes == 0) break; else if(bytes == -1) { kWarning() << "Failed to read data from the tmpfile"; failed = true; } while(! failed && bytes > 0) { qint64 written = device->write(data, bytes); if(written < 0) {// error! kWarning() << "Failed to copy the sound from the temp file"; failed = true; } bytes -= written; } if(failed) { // read or write failed; so lets cleanly abort. delete[] data; return false; } } delete[] data; return true; } bool KPrSoundData::isTaggedForSaving() { return d->taggedForSaving; } bool KPrSoundData::loadFromFile(QIODevice *device) { struct Finally { Finally(QIODevice *d) : device (d), bytes(0) {} ~Finally() { delete device; delete[] bytes; } QIODevice *device; char *bytes; }; Finally finally(device); // remove prev data delete d->tempFile; d->tempFile = 0; d->tempFile = new KTemporaryFile(); if(! d->tempFile->open()) return false; char * data = new char[32 * 1024]; finally.bytes = data; while(true) { bool failed = false; qint64 bytes = device->read(data, 32*1024); if(bytes == 0) break; else if(bytes == -1) { kWarning() << "Failed to read sound data"; failed = true; } while(! failed && bytes > 0) { qint64 written = d->tempFile->write(data, bytes); if(written < 0) {// error! kWarning() << "Failed to copy the sound to temp"; failed = true; } bytes -= written; } if(failed) { // read or write failed; so lets cleanly abort. delete d->tempFile; d->tempFile = 0; return false; } } d->tempFileName = d->tempFile->fileName(); d->tempFile->close(); return true; } KPrSoundCollection * KPrSoundData::soundCollection() { return d->collection; } diff --git a/stage/part/KPrSoundData.h b/stage/part/KPrSoundData.h index 16e954e7570..4cc9016af5d 100644 --- a/stage/part/KPrSoundData.h +++ b/stage/part/KPrSoundData.h @@ -1,118 +1,116 @@ /* This file is part of the KDE project * Copyright (C) 2007 Thomas Zander * Copyright (C) 2007 Jan Hambrecht * Copyright (C) 2008 C. Boemann * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPRSOUNDDATA_H #define KPRSOUNDDATA_H #include #include "stage_export.h" class KPrSoundCollection; class QIODevice; /** * Class meant to hold sound data so it can be shared between shapes. * In KPresenter shapes can have click actions attached to them. One such action is playing sound. * The binary data for those sounds are saved in this class. */ /* * TODO needs a file for playing, store it as a tmp file */ class STAGE_EXPORT KPrSoundData { public: /** * The storage location */ enum StorageLocation { SaveRelativeUrl, ///< in the odf use a relative (to document) xlink:href, if possible SaveAbsoluteUrl, ///< in the odf use a fully specified xlink:href SaveInStore ///< Save the sound data in the ODF store }; /** * constructor * @param collection the sound collection which will do the loading of the sound data for us. * @param href the url of the sound in the store. */ explicit KPrSoundData(KPrSoundCollection *collection, QString href=""); /** * copy constructor using ref-counting. * @param soundData the other one. */ KPrSoundData(const KPrSoundData &soundData); /// destructor ~KPrSoundData(); /** * Tags this sound to be saved and returns the href for reference in the xml. * @return returns the url-like location this sound will be saved to. */ QString tagForSaving(); /// returns the url-like location QString storeHref() const; /// returns the url-like location of the tmp file QString nameOfTempFile() const; /// returns the title of the sound (for now its the basename part of the filename QString title() const; /** * Load the sound data from the param device. * Note that it will copy the data to a temp-file and postpone loading it until the phonon plays it. * @para device the device that is used to get the data from. * @return returns true if load was successful. */ bool loadFromFile(QIODevice *device); /** * Save the sound data to the param device. * The full file is saved. * @para device the device that is used to get the data from. * @return returns true if load was successful. */ bool saveToFile(QIODevice *device); /** * Return whether this sound have been tagged for saving. * @return returns true if this sound should be saved. */ bool isTaggedForSaving(); - bool operator==(const KPrSoundData &other) { - return other.d == d; - } + bool operator==(const KPrSoundData &other) const; /** * Get the collection used */ KPrSoundCollection * soundCollection(); private: class Private; Private * const d; }; #endif