File indexing completed on 2025-01-19 03:53:36

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2008-05-12
0007  * Description : Access to copy-right info of an item in the database
0008  *
0009  * SPDX-FileCopyrightText: 2008-2013 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0010  * SPDX-FileCopyrightText: 2009-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #ifndef DIGIKAM_ITEM_COPY_RIGHT_H
0017 #define DIGIKAM_ITEM_COPY_RIGHT_H
0018 
0019 // Qt includes
0020 
0021 #include <QString>
0022 #include <QStringList>
0023 #include <QList>
0024 
0025 // Local includes
0026 
0027 #include "metaengine.h"
0028 #include "metadatainfo.h"
0029 #include "digikam_export.h"
0030 
0031 namespace Digikam
0032 {
0033 
0034 class CopyrightInfo;
0035 class ItemCopyrightCache;
0036 class Template;
0037 
0038 class DIGIKAM_DATABASE_EXPORT ItemCopyright
0039 {
0040 public:
0041 
0042     enum ReplaceMode
0043     {
0044         ReplaceAllEntries,         ///< Remove entries for all languages and add one new entry
0045         ReplaceLanguageEntry,      ///< Only replace the entry with the given language
0046         AddEntryToExisting         ///< No constraints on adding the entry
0047     };
0048 
0049 public:
0050 
0051     explicit ItemCopyright(qlonglong imageid);
0052 
0053     /**
0054      * Create a null ItemCopyright object
0055      */
0056     ItemCopyright();
0057 
0058     ItemCopyright(const ItemCopyright& other);
0059     ~ItemCopyright();
0060 
0061     ItemCopyright& operator=(const ItemCopyright& other);
0062 
0063     /**
0064      * Returns the author/creator/byline.
0065      * This is Photoshop Author.
0066      * This is IPTC By-line.
0067      * This is DC creator.
0068      * This is dc:creator in XMP.
0069      * Contains preferably the name of the person who created the content of this news object, a
0070      * photographer for photos, a graphic artist for graphics, or a writer for textual news. If it is not
0071      * appropriate to add the name of a person the name of a company or organization could be
0072      * applied as well.
0073      * Aligning with IIM notions IPTC Core intents to have only one creator for this news object
0074      * despite the underlying XMP property dc:creator allows for more than one item to be
0075      * included. If there are more than one item in this array the first one should be considered as
0076      * the IPTC Core Creator value.
0077      */
0078     QStringList creator() const;
0079 
0080     QStringList author() const
0081     {
0082         return creator();
0083     }
0084 
0085     QStringList byLine() const
0086     {
0087         return creator();
0088     }
0089 
0090     /**
0091      * Sets the creator.
0092      * If you want to specify only one creator, set the replace mode to ReplaceAllEntries.
0093      * If you want to add it to a list of existing entries, pass AddEntryToExisting.
0094      * You shall not use ReplaceLanguageEntry for this method, creators have no language associated.
0095      */
0096     void setCreator(const QString& creator, ReplaceMode mode = ReplaceAllEntries);
0097 
0098     void setAuthor(const QString& author, ReplaceMode mode = ReplaceAllEntries)
0099     {
0100         setCreator(author, mode);
0101     }
0102 
0103     void setByLine(const QString& byline, ReplaceMode mode = ReplaceAllEntries)
0104     {
0105         setCreator(byline, mode);
0106     }
0107 
0108     void removeCreators();
0109 
0110     /**
0111      * Returns the credit/provider.
0112      * This is Photoshop Credit.
0113      * This is IPTC Credit.
0114      * This is photoshop:Credit in XMP
0115      * Identifies the provider of the news object, who is not necessarily the owner/creator.
0116      */
0117     QString provider() const;
0118 
0119     QString credit() const
0120     {
0121         return provider();
0122     }
0123 
0124     void setProvider(const QString& provider);
0125 
0126     void setCredit(const QString& credit)
0127     {
0128         setProvider(credit);
0129     }
0130 
0131     void removeProvider();
0132 
0133     /**
0134      * Returns the copyright notice.
0135      * This is Photoshop Copyright Notice.
0136      * This is IPTC Copyright Notice.
0137      * This is DC Rights.
0138      * This is dc:rights in XMP.
0139      * Contains any necessary copyright notice for claiming the intellectual property for this news
0140      * object and should identify the current owner of the copyright for the news object. Other
0141      * entities like the creator of the news object may be added. Notes on usage rights should be
0142      * provided in Rights usage terms.
0143      * Note on language matching:
0144      * You can specify a language code.
0145      * If the requested language is not available, the entry with default
0146      * language code is returned.
0147      * If a default-language entry is not available, the first entry is returned.
0148      * If you pass a null string as languageCode, the local language is returned.
0149      */
0150     QString copyrightNotice(const QString& languageCode = QString());
0151 
0152     QString rights(const QString& languageCode = QString())
0153     {
0154         return copyrightNotice(languageCode);
0155     }
0156 
0157     MetaEngine::AltLangMap allCopyrightNotices();
0158 
0159     /**
0160      * Sets the copyright notice. If you supply a null QString as language code,
0161      * this is regarded as an entry for the default language (&ldquo;x-default&rdquo;).
0162      * The ReplaceMode determines how existing entries are handled.
0163      */
0164     void setCopyrightNotice(const QString& notice,
0165                             const QString& languageCode = QString(),
0166                             ReplaceMode mode = ReplaceLanguageEntry);
0167 
0168     void setRights(const QString& notice,
0169                    const QString& languageCode = QString(),
0170                    ReplaceMode mode = ReplaceLanguageEntry)
0171     {
0172         setCopyrightNotice(notice, languageCode, mode);
0173     }
0174 
0175     void removeCopyrightNotices();
0176 
0177     /**
0178      * Returns the right usage terms.
0179      * This has no equivalent in Photoshop, IPTC, or DC.
0180      * This is xmpRights:UsageTerms in XMP.
0181      * Language matching is done as with copyrightNotice().
0182      * Free text instructions on how this news object can be legally used.
0183      */
0184     QString rightsUsageTerms(const QString& languageCode = QString());
0185     MetaEngine::AltLangMap allRightsUsageTerms();
0186 
0187     void setRightsUsageTerms(const QString& term,
0188                              const QString& languageCode = QString(),
0189                              ReplaceMode mode = ReplaceLanguageEntry);
0190 
0191     void removeRightsUsageTerms();
0192 
0193     /**
0194      * Returns the source.
0195      * This is Photoshop Source.
0196      * This is IPTC Source.
0197      * This is photoshop::Source in XMP.
0198      * Identifies the original owner of the copyright for the intellectual content of the news object.
0199      * This could be an agency, a member of an agency or an individual. Source could be
0200      * different from Creator and from the entities in the CopyrightNotice.
0201      * As the original owner can not change the content of this property should never be changed
0202      * or deleted after the information is entered following the news object's initial creation.
0203      */
0204     QString source();
0205     void setSource(const QString& source);
0206 
0207     void removeSource();
0208 
0209     /**
0210      * Returns the creator's job title.
0211      * This is Photoshop AuthorsPosition.
0212      * This is IPTC By-line Title.
0213      * This is photoshop:AuthorsPosition in XMP.
0214      * Contains the job title of the person who created the content of this news object. As this is
0215      * sort of a qualifier the Creator element has to be filled in as mandatory prerequisite for
0216      * using Creator's Jobtitle.
0217      */
0218     QString creatorJobTitle() const;
0219 
0220     QString authorsPosition() const
0221     {
0222         return creatorJobTitle();
0223     }
0224 
0225     QString byLineTitle()     const
0226     {
0227         return creatorJobTitle();
0228     }
0229 
0230     void setCreatorJobTitle(const QString& title);
0231 
0232     void setAuthorsPosition(const QString& position)
0233     {
0234         setCreatorJobTitle(position);
0235     }
0236 
0237     void setByLineTitle(const QString& title)
0238     {
0239         setCreatorJobTitle(title);
0240     }
0241 
0242     void removeCreatorJobTitle();
0243 
0244     /**
0245      * Returns the instructions.
0246      * This is Photoshop Instructions.
0247      * This is IPTC Special Instruction.
0248      * This is photoshop:Instructions in XMP.
0249      * Any of a number of instructions from the provider or creator to the receiver of the news
0250      * object which might include any of the following: embargoes (NewsMagazines OUT) and
0251      * other restrictions not covered by the Rights Usage Terms field; information regarding the
0252      * original means of capture (scanning notes, colorspace info) or other specific text
0253      * information that the user may need for accurate reproduction; additional permissions or
0254      * credits required when publishing.
0255      */
0256     QString instructions();
0257     void setInstructions(const QString& instructions);
0258     void removeInstructions();
0259 
0260     /**
0261      * Returns the creator's contact info.
0262      * This is Iptc4xmpCore:CreatorContactInfo in XMP.
0263      * The creator's contact information provides all necessary information to get in contact with
0264      * the creator of this news object and comprises a set of sub-properties for proper addressing.
0265      */
0266     IptcCoreContactInfo contactInfo();
0267     void setContactInfo(const IptcCoreContactInfo& info);
0268     void removeContactInfo();
0269 
0270     /**
0271      * Fills the information fields in template concerning copyright info
0272      * (note there are other fields in the a Template. There will not be touched)
0273      */
0274     void fillTemplate(Template& t);
0275 
0276     /**
0277      * Sets all database copyright fields from the template.
0278      *  This does not clear any fields before.
0279      */
0280     void setFromTemplate(const Template& t);
0281 
0282     /**
0283      * Calls all remove...() methods in this class
0284      */
0285     void removeAll();
0286 
0287     /**
0288      * Removes all entries and replaces them with the entries from source.
0289      */
0290     void replaceFrom(const ItemCopyright& source);
0291 
0292 protected:
0293 
0294     CopyrightInfo copyrightInfo(const QString& property)                                  const;
0295     QList<CopyrightInfo> copyrightInfos(const QString& property)                          const;
0296     QString readSimpleProperty(const QString& property)                                   const;
0297     int     languageMatch(const QList<CopyrightInfo>& infos, const QString& languageCode) const;
0298 
0299     void    setSimpleProperty(const QString& property, const QString& value);
0300     QString readLanguageProperty(const QString& property, const QString& languageCode);
0301     MetaEngine::AltLangMap readLanguageProperties(const QString& property);
0302 
0303     void    setLanguageProperty(const QString& property,
0304                                 const QString& value,
0305                                 const QString& languageCode,
0306                                 ReplaceMode mode);
0307 
0308     void    removeProperties(const QString& property);
0309     void    removeLanguageProperty(const QString& property, const QString& languageCode);
0310 
0311 protected:
0312 
0313     friend class ItemCopyrightCache;
0314 
0315     qlonglong           m_id;
0316     ItemCopyrightCache* m_cache;
0317 };
0318 
0319 } // namespace Digikam
0320 
0321 #endif // DIGIKAM_ITEM_COPY_RIGHT_H