File indexing completed on 2024-05-05 04:33:14

0001 /*
0002     SPDX-FileCopyrightText: 2004-2018 Gilles Caulier <caulier dot gilles at gmail dot com>
0003     SPDX-FileCopyrightText: 2004-2005 Renchi Raju <renchi dot raju at gmail dot com>
0004     SPDX-FileCopyrightText: 2004-2005 Jesper K. Pedersen <blackie at kde dot org>
0005     SPDX-FileCopyrightText: 2004-2005 Aurelien Gateau <aurelien dot gateau at free dot fr>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 // Local includes
0011 
0012 #include "imagecollection.h"
0013 #include "imagecollectionshared.h"
0014 #include "libkipi_debug.h"
0015 
0016 // Macros
0017 
0018 #define PrintWarningMessage()                                           \
0019         qCWarning(LIBKIPI_LOG) << "Image collection is invalid - this might be the case if you asked for an album, " \
0020                                << "and not album existed. You should check using .isValid() first. "                 \
0021                                << "Note: Plugins should never create an instance of ImageCollection, only the "      \
0022                                << "host application should do that."
0023 
0024 namespace KIPI
0025 {
0026 
0027 ImageCollection::ImageCollection(ImageCollectionShared* const data)
0028     : d(data)
0029 {
0030 }
0031 
0032 ImageCollection::ImageCollection(const ImageCollection& rhs)
0033 {
0034     if ( rhs.d )
0035     {
0036         d = rhs.d;
0037         d->addRef();
0038     }
0039     else
0040     {
0041         d = nullptr;
0042     }
0043 }
0044 
0045 ImageCollection::ImageCollection()
0046 {
0047     d = nullptr;
0048 }
0049 
0050 ImageCollection::~ImageCollection()
0051 {
0052     if ( d )
0053         d->removeRef();
0054 }
0055 
0056 ImageCollection& ImageCollection::operator=(const ImageCollection& rhs)
0057 {
0058     if ( rhs.d == d )
0059         return *this;
0060 
0061     if ( d )
0062         d->removeRef();
0063 
0064     if ( !rhs.d )
0065     {
0066         PrintWarningMessage();
0067         d = nullptr;
0068     }
0069     else
0070     {
0071         d = rhs.d;
0072         d->addRef();
0073     }
0074     return *this;
0075 }
0076 
0077 bool ImageCollection::operator==(const ImageCollection& ic) const
0078 {
0079     if (!d || !(ic.d))
0080     {
0081         PrintWarningMessage();
0082         return false;
0083     }
0084     return *d == *(ic.d);
0085 }
0086 
0087 QString ImageCollection::comment() const
0088 {
0089     if ( d )
0090     {
0091         return d->comment();
0092     }
0093     else
0094     {
0095         PrintWarningMessage();
0096         return QString();
0097     }
0098 }
0099 
0100 QString ImageCollection::name() const
0101 {
0102     if ( d )
0103     {
0104         return d->name();
0105     }
0106     else
0107     {
0108         PrintWarningMessage();
0109         return QString();
0110     }
0111 }
0112 
0113 QString ImageCollection::category() const
0114 {
0115     if ( d )
0116     {
0117         return d->category();
0118     }
0119     else
0120     {
0121         PrintWarningMessage();
0122         return QString();
0123     }
0124 }
0125 
0126 QDate ImageCollection::date() const
0127 {
0128     if ( d )
0129     {
0130         return d->date();
0131     }
0132     else
0133     {
0134         PrintWarningMessage();
0135         return QDate();
0136     }
0137 }
0138 
0139 QList<QUrl> ImageCollection::images() const
0140 {
0141     if ( d )
0142     {
0143         return d->images();
0144     }
0145     else
0146     {
0147         PrintWarningMessage();
0148         return QList<QUrl>();
0149     }
0150 }
0151 
0152 QUrl ImageCollection::url() const
0153 {
0154     if ( d )
0155     {
0156         return d->url();
0157     }
0158     else
0159     {
0160         PrintWarningMessage();
0161         return QUrl();
0162     }
0163 }
0164 
0165 QUrl ImageCollection::uploadUrl() const
0166 {
0167     if ( d )
0168     {
0169         return d->uploadUrl();
0170     }
0171     else
0172     {
0173         PrintWarningMessage();
0174         return QUrl();
0175     }
0176 }
0177 
0178 QUrl ImageCollection::uploadRootUrl() const
0179 {
0180     if ( d )
0181     {
0182         return d->uploadRootUrl();
0183     }
0184     else
0185     {
0186         PrintWarningMessage();
0187         return QUrl();
0188     }
0189 }
0190 
0191 QString ImageCollection::uploadRootName() const
0192 {
0193     if ( d )
0194     {
0195         return d->uploadRootName();
0196     }
0197     else
0198     {
0199         PrintWarningMessage();
0200         return QString();
0201     }
0202 }
0203 
0204 bool ImageCollection::isDirectory() const
0205 {
0206     if ( d )
0207     {
0208         return d->isDirectory();
0209     }
0210     else
0211     {
0212         PrintWarningMessage();
0213         return false;
0214     }
0215 }
0216 
0217 bool ImageCollection::isValid() const
0218 {
0219     return (d != nullptr);
0220 }
0221 
0222 } // namespace KIPI