File indexing completed on 2024-05-12 05:14:55
0001 /* 0002 * preferences.h - program preference settings 0003 * Program: kalarm 0004 * SPDX-FileCopyrightText: 2001-2024 David Jarvie <djarvie@kde.org> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include "kalarmconfig.h" 0012 #include "kalarmcalendar/kadatetime.h" 0013 0014 #include <QObject> 0015 #include <QDateTime> 0016 #include <QTimeZone> 0017 0018 namespace KAlarmCal { class Holidays; } 0019 class AkonadiPlugin; 0020 0021 0022 // Settings configured in the Preferences dialog 0023 class Preferences : public PreferencesBase 0024 { 0025 Q_OBJECT 0026 public: 0027 enum MailFrom { MAIL_FROM_KMAIL, MAIL_FROM_SYS_SETTINGS, MAIL_FROM_ADDR }; 0028 0029 static Preferences* self(); 0030 static void connect(const char* signal, const QObject* receiver, const char* member); 0031 template<class Signal, class Receiver, class Func, 0032 class = typename std::enable_if<!std::is_convertible<Signal, const char*>::value>::type, 0033 class = typename std::enable_if<!std::is_convertible<Func, const char*>::value>::type> 0034 static void connect(Signal signal, const Receiver* receiver, Func member) 0035 { 0036 QObject::connect(self(), signal, receiver, member); 0037 } 0038 0039 /** Return whether Akonadi plugin is available and should be used. 0040 * @see useAkonadiIfAvailable(). 0041 */ 0042 static bool useAkonadi(); 0043 0044 /** Return the Akonadi plugin. 0045 * @return the Akonadi plugin, or null if not available or not to be used. 0046 */ 0047 static AkonadiPlugin* akonadiPlugin(); 0048 0049 /** Set whether to use the Akonadi plugin if available. 0050 * @see setUseAkonadiIfAvailable(). 0051 */ 0052 static void setUseAkonadi(bool yes); 0053 0054 static int autoHideSystemTray(); 0055 static void setAutoHideSystemTray(int timeout); 0056 static bool autoStartChangedByUser() { return mAutoStartChangedByUser; } 0057 static void setAutoStartChangedByUser(bool c){ mAutoStartChangedByUser = c; } 0058 0059 // Access to settings 0060 static QString previousVersion() { return mPreviousVersion; } 0061 static Backend previousBackend() { return mPreviousBackend; } 0062 static void setAskAutoStart(bool yes); 0063 static bool noAutoStart() { return self()->base_NoAutoStart(); } 0064 static void setNoAutoStart(bool yes); 0065 static bool modalMessages(); 0066 static void setModalMessages(bool yes); 0067 static int messageButtonDelay(); 0068 static void setMessageButtonDelay(int seconds) { self()->setBase_MessageButtonDelay(seconds); } 0069 static KAlarmCal::KADateTime::Spec timeSpec(); 0070 static QTimeZone timeSpecAsZone(); 0071 static void setTimeSpec(const KAlarmCal::KADateTime::Spec&); 0072 static const KAlarmCal::Holidays& holidays(); 0073 static void setHolidayRegion(const QString& regionCode); 0074 static QTime startOfDay() { return self()->mBase_StartOfDay.time(); } 0075 static void setStartOfDay(const QTime&); 0076 static QTime workDayStart() { return self()->mBase_WorkDayStart.time(); } 0077 static QTime workDayEnd() { return self()->mBase_WorkDayEnd.time(); } 0078 static QBitArray workDays(); 0079 static void setWorkDayStart(const QTime& t) { self()->setBase_WorkDayStart(QDateTime(QDate(1900,1,1), t)); } 0080 static void setWorkDayEnd(const QTime& t) { self()->setBase_WorkDayEnd(QDateTime(QDate(1900,1,1), t)); } 0081 static void setWorkDays(const QBitArray&); 0082 static bool quitWarn() { return mUsingDefaults ? self()->base_QuitWarn() : notifying(QUIT_WARN); } 0083 static void setQuitWarn(bool yes) { setNotify(QUIT_WARN, yes); } 0084 static bool confirmAlarmDeletion() { return mUsingDefaults ? self()->base_ConfirmAlarmDeletion() : notifying(CONFIRM_ALARM_DELETION); } 0085 static void setConfirmAlarmDeletion(bool yes){ setNotify(CONFIRM_ALARM_DELETION, yes); } 0086 static MailClient emailClient(); 0087 static void setEmailClient(MailClient); 0088 static bool emailCopyToKMail(); 0089 static void setEmailCopyToKMail(bool yes); 0090 static bool emailQueuedNotify() { return mUsingDefaults ? self()->base_EmailQueuedNotify() : notifying(EMAIL_QUEUED_NOTIFY); } 0091 static void setEmailQueuedNotify(bool yes) { setNotify(EMAIL_QUEUED_NOTIFY, yes); } 0092 static MailFrom emailFrom(); 0093 static QString emailAddress(); 0094 static void setEmailAddress(MailFrom, const QString& address); 0095 static MailFrom emailBccFrom(); 0096 static QString emailBccAddress(); 0097 static void setEmailBccAddress(bool useSystemSettings, const QString& address); 0098 static bool emailBccUseSystemSettings(); 0099 static QString cmdXTermCommand(); 0100 0101 /** Set a non-standard command line to open a terminal window for running command 0102 * alarms in. 0103 */ 0104 static void setCmdXTermSpecialCommand(const QString& cmd); 0105 0106 /** Set a standard command line to open a terminal window for running command 0107 * alarms in. 0108 */ 0109 static void setCmdXTermCommand(int index); 0110 0111 /** Return the currently configured command line to open a terminal window for 0112 * running command alarms in, together with its index. 0113 * @return 0 if user-defined command line, 0114 * -1 if empty command line, 0115 * > 0 if a standard command line. 0116 */ 0117 static std::pair<int, QString> cmdXTermCommandIndex(); 0118 0119 /** Return the standard command line to open a terminal window for running 0120 * command alarms in, as represented by the index returned by cmdXTermCommandIndex(). 0121 * @param index Index to the command line. Must be > 0. 0122 * @return the command line, or empty if @p index does not refer to a program 0123 * which is available on this system. 0124 */ 0125 static QString cmdXTermStandardCommand(int index); 0126 0127 /** Return all standard command lines to open terminal windows for running command 0128 * alarms in. Only those command lines which invoke programs which exist on this 0129 * system will be returned. 0130 * @return command lines, indexed by their index number. 0131 */ 0132 static QHash<int, QString> cmdXTermStandardCommands(); 0133 0134 static SoundType defaultSoundType(); 0135 static void setDefaultSoundType(SoundType); 0136 static float defaultSoundVolume() { int vol = self()->mBase_DefaultSoundVolume; return (vol < 0) ? -1 : static_cast<float>(vol) / 100; } 0137 static void setDefaultSoundVolume(float v) { self()->setBase_DefaultSoundVolume(v < 0 ? -1 : static_cast<int>(v * 100)); } 0138 0139 // Config file entry names for notification messages 0140 static const QLatin1String QUIT_WARN; 0141 static const QLatin1String ASK_AUTO_START; 0142 static const QLatin1String CONFIRM_ALARM_DELETION; 0143 static const QLatin1String EMAIL_QUEUED_NOTIFY; 0144 0145 bool useDefaults(bool def) override { mUsingDefaults = def; return PreferencesBase::useDefaults(def); } 0146 0147 Q_SIGNALS: 0148 void timeZoneChanged(const KAlarmCal::KADateTime::Spec& newTz); 0149 void holidaysChanged(const KAlarmCal::Holidays& newHolidays); 0150 void startOfDayChanged(const QTime& newStartOfDay); 0151 void workTimeChanged(const QTime& startTime, const QTime& endTime, const QBitArray& workDays); 0152 0153 private Q_SLOTS: 0154 void timeZoneChange(const QString&); 0155 void holidaysChange(const QString& regionCode); 0156 void startDayChange(const QDateTime&); 0157 void workTimeChange(const QDateTime&, const QDateTime&, int days); 0158 0159 private: 0160 Preferences(); // only one instance allowed 0161 static void setNotify(const QString& messageID, bool notify); 0162 static bool notifying(const QString& messageID); 0163 0164 static Preferences* mInstance; 0165 static bool mUsingDefaults; 0166 static KAlarmCal::Holidays* mHolidays; 0167 static QString mPreviousVersion; // last KAlarm version which wrote the config file 0168 static Backend mPreviousBackend; // backend used by last used version of KAlarm 0169 0170 // All the following members are accessed by the Preferences dialog classes 0171 static int mMessageButtonDelay; // 0 = scatter; -1 = no delay, no scatter; >0 = delay, no scatter 0172 0173 // Change tracking 0174 static bool mAutoStartChangedByUser; // AutoStart has been changed by the user 0175 }; 0176 0177 // vim: et sw=4: