File indexing completed on 2024-05-05 16:08:26

0001 /* This file is part of the KDE libraries
0002 
0003    Copyright (c) 2007 Jos van den Oever <jos@vandenoever.info>
0004                  2010 Sebastian Trueg <trueg@kde.org>
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 (LGPL) 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 
0022 #include "kfilemetainfoitem.h"
0023 #include "kfilemetainfoitem_p.h"
0024 #include <config-kdelibs4support.h>
0025 
0026 #ifdef HAVE_NEPOMUK
0027 #include <config-nepomuk.h>
0028 #endif
0029 
0030 KFileMetaInfoItem::KFileMetaInfoItem() : d(new KFileMetaInfoItemPrivate())
0031 {
0032 }
0033 
0034 KFileMetaInfoItem::KFileMetaInfoItem(const KFileMetaInfoItem &item) : d(item.d)
0035 {
0036 }
0037 KFileMetaInfoItem::KFileMetaInfoItem(const QString &pp,
0038                                      const QVariant &v, KFileWritePlugin *w, bool e)
0039     : d(new KFileMetaInfoItemPrivate())
0040 {
0041 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
0042     d->pp = pp;
0043 #else
0044 #if ! KIO_NO_NEPOMUK
0045     d->pp = QUrl(pp);
0046 #endif
0047 #endif
0048     d->value = v;
0049     d->writer = w;
0050     d->embedded = e;
0051     d->modified = false;
0052 }
0053 KFileMetaInfoItem::~KFileMetaInfoItem()
0054 {
0055 }
0056 const KFileMetaInfoItem &
0057 KFileMetaInfoItem::operator=(const KFileMetaInfoItem &item)
0058 {
0059     d = item.d;
0060     return item;
0061 }
0062 const QString &
0063 KFileMetaInfoItem::name() const
0064 {
0065 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
0066     return d->pp.name();
0067 #else
0068 #if ! KIO_NO_NEPOMUK
0069     return d->pp.name();
0070 #else
0071     return QString::null;
0072 #endif
0073 #endif
0074 }
0075 const QVariant &
0076 KFileMetaInfoItem::value() const
0077 {
0078     return d->value;
0079 }
0080 bool
0081 KFileMetaInfoItem::setValue(const QVariant &value)
0082 {
0083     bool changed = d->value != value;
0084     d->value = value;
0085     d->modified |= changed;
0086     return changed;
0087 }
0088 bool
0089 KFileMetaInfoItem::addValue(const QVariant &value)
0090 {
0091     QVariant &v = d->value;
0092     if (v.type() == QVariant::List) {
0093         QVariantList vl = v.toList();
0094         vl.append(value);
0095         d->value = vl;
0096     }
0097     return false;
0098 }
0099 bool
0100 KFileMetaInfoItem::isModified() const
0101 {
0102     return d->modified;
0103 }
0104 bool
0105 KFileMetaInfoItem::isRemoved() const
0106 {
0107     return d->modified && d->value.isNull();
0108 }
0109 bool
0110 KFileMetaInfoItem::isValid() const
0111 {
0112     return true;
0113 }
0114 bool
0115 KFileMetaInfoItem::isSkipped() const
0116 {
0117     // ########## TODO implement (vandenoever)
0118     return false;
0119 }
0120 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
0121 const PredicateProperties &
0122 KFileMetaInfoItem::properties() const
0123 {
0124     return d->pp;
0125 }
0126 #endif
0127 bool
0128 KFileMetaInfoItem::isEditable() const
0129 {
0130     return d->writer != nullptr;
0131 }
0132 QString
0133 KFileMetaInfoItem::suffix() const
0134 {
0135     // ########## TODO implement (vandenoever)
0136     return QString();
0137 }
0138 
0139 QString
0140 KFileMetaInfoItem::prefix() const
0141 {
0142     // ########## TODO implement (vandenoever)
0143     return QString();
0144 }