File indexing completed on 2025-03-09 03:57:07
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-08-08 0007 * Description : an option to provide date information to the parser 0008 * 0009 * SPDX-FileCopyrightText: 2009-2012 by Andi Clemens <andi dot clemens at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #ifndef DIGIKAM_DATE_OPTION_H 0016 #define DIGIKAM_DATE_OPTION_H 0017 0018 // Qt includes 0019 0020 #include <QDialog> 0021 #include <QObject> 0022 #include <QString> 0023 #include <QVariant> 0024 0025 // Local includes 0026 0027 #include "option.h" 0028 #include "ruledialog.h" 0029 0030 namespace Ui 0031 { 0032 class DateOptionDialogWidget; 0033 } 0034 0035 namespace Digikam 0036 { 0037 0038 class DateFormat 0039 { 0040 public: 0041 0042 enum Type 0043 { 0044 Standard = 0, 0045 ISO, 0046 FullText, 0047 UnixTimeStamp, 0048 Custom 0049 }; 0050 0051 public: 0052 0053 typedef QPair<QString, QVariant> DateFormatDescriptor; 0054 typedef QList<DateFormatDescriptor> DateFormatMap; 0055 0056 public: 0057 0058 explicit DateFormat(); 0059 ~DateFormat() {}; 0060 0061 Type type(const QString& identifier); 0062 0063 QString identifier(Type type); 0064 0065 QVariant format(Type type); 0066 QVariant format(const QString& identifier); 0067 0068 DateFormatMap& map() 0069 { 0070 return m_map; 0071 }; 0072 0073 private: 0074 0075 DateFormat(const DateFormat&) = delete; 0076 DateFormat& operator=(const DateFormat&) = delete; 0077 0078 private: 0079 0080 DateFormatMap m_map; 0081 }; 0082 0083 // -------------------------------------------------------- 0084 0085 class DateOptionDialog : public RuleDialog 0086 { 0087 Q_OBJECT 0088 0089 public: 0090 0091 enum DateSource 0092 { 0093 FromImage = 0, 0094 CurrentDateTime, 0095 FixedDateTime 0096 }; 0097 0098 public: 0099 0100 explicit DateOptionDialog(Rule* parent); 0101 ~DateOptionDialog() override; 0102 0103 Ui::DateOptionDialogWidget* const ui; 0104 0105 DateSource dateSource(); 0106 0107 private Q_SLOTS: 0108 0109 void slotDateSourceChanged(int); 0110 void slotDateFormatChanged(int); 0111 void slotCustomFormatChanged(const QString&); 0112 0113 private: 0114 0115 // Disable 0116 explicit DateOptionDialog(QWidget*) = delete; 0117 DateOptionDialog(const DateOptionDialog&); 0118 DateOptionDialog& operator=(const DateOptionDialog&); 0119 0120 QString formattedDateTime(const QDateTime& date); 0121 void updateExampleLabel(); 0122 }; 0123 0124 // -------------------------------------------------------- 0125 0126 class DateOption : public Option 0127 { 0128 Q_OBJECT 0129 0130 public: 0131 0132 explicit DateOption(); 0133 ~DateOption() override = default; 0134 0135 protected: 0136 0137 QString parseOperation(ParseSettings& settings, 0138 const QRegularExpressionMatch& match) override; 0139 0140 private Q_SLOTS: 0141 0142 void slotTokenTriggered(const QString& token) override; 0143 0144 private: 0145 0146 // Disable 0147 explicit DateOption(QObject*) = delete; 0148 DateOption(const DateOption&) = delete; 0149 DateOption& operator=(const DateOption&) = delete; 0150 }; 0151 0152 } // namespace Digikam 0153 0154 #endif // DIGIKAM_DATE_OPTION_H