kalarm

preferences.h

00001 /*
00002  *  preferences.h  -  program preference settings
00003  *  Program:  kalarm
00004  *  Copyright © 2001-2007 by David Jarvie <djarvie@kde.org>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #ifndef PREFERENCES_H
00022 #define PREFERENCES_H
00023 
00024 #include "kalarm.h"
00025 
00026 #include <tqobject.h>
00027 #include <tqcolor.h>
00028 #include <tqfont.h>
00029 #include <tqdatetime.h>
00030 #include <tqvaluelist.h>
00031 class TQWidget;
00032 
00033 #include "colourlist.h"
00034 #include "editdlg.h"
00035 #include "karecurrence.h"
00036 #include "recurrenceedit.h"
00037 #include "soundpicker.h"
00038 #include "timeperiod.h"
00039 
00040 
00041 // Settings configured in the Preferences dialog
00042 class Preferences : public TQObject
00043 {
00044         Q_OBJECT
00045   TQ_OBJECT
00046     public:
00047         enum MailClient { SENDMAIL, KMAIL };
00048         enum MailFrom   { MAIL_FROM_KMAIL, MAIL_FROM_CONTROL_CENTRE, MAIL_FROM_ADDR };
00049         enum CmdLogType { DISCARD_OUTPUT, LOG_TO_FILE, EXEC_IN_TERMINAL };
00050 
00051         static void              initialise();
00052         static void              save(bool syncToDisc = true);
00053         static void              syncToDisc();
00054         static void              updateStartOfDayCheck();
00055         static void              connect(const char* signal, const TQObject* receiver, const char* member);
00056 
00057         // Access to settings
00058         static const ColourList& messageColours()                 { return mMessageColours; }
00059         static TQColor            defaultBgColour()                { return mDefaultBgColour; }
00060         static TQColor            defaultFgColour()                { return default_defaultFgColour; }
00061         static const TQFont&      messageFont()                    { return mMessageFont; }
00062         static const TQTime&      startOfDay()                     { return mStartOfDay; }
00063         static bool              hasStartOfDayChanged()           { return mStartOfDayChanged; }
00064         static bool              runInSystemTray()                { return mRunInSystemTray; }
00065         static bool              disableAlarmsIfStopped()         { return mDisableAlarmsIfStopped; }
00066         static bool              quitWarn()                       { return notifying(QUIT_WARN); }
00067         static void              setQuitWarn(bool yes)            { setNotify(QUIT_WARN, yes); }
00068         static bool              autostartTrayIcon()              { return mAutostartTrayIcon; }
00069         static bool              confirmAlarmDeletion()           { return notifying(CONFIRM_ALARM_DELETION); }
00070         static void              setConfirmAlarmDeletion(bool yes){ setNotify(CONFIRM_ALARM_DELETION, yes); }
00071         static bool              modalMessages()                  { return mModalMessages; }
00072         static int               messageButtonDelay()             { return mMessageButtonDelay; }
00073         static int               tooltipAlarmCount()              { return mTooltipAlarmCount; }
00074         static bool              showTooltipAlarmTime()           { return mShowTooltipAlarmTime; }
00075         static bool              showTooltipTimeToAlarm()         { return mShowTooltipTimeToAlarm; }
00076         static const TQString&    tooltipTimeToPrefix()            { return mTooltipTimeToPrefix; }
00077         static int               daemonTrayCheckInterval()        { return mDaemonTrayCheckInterval; }
00078         static MailClient        emailClient()                    { return mEmailClient; }
00079         static bool              emailCopyToKMail()               { return mEmailCopyToKMail  &&  mEmailClient == SENDMAIL; }
00080         static bool              emailQueuedNotify()              { return notifying(EMAIL_QUEUED_NOTIFY); }
00081         static void              setEmailQueuedNotify(bool yes)   { setNotify(EMAIL_QUEUED_NOTIFY, yes); }
00082         static MailFrom          emailFrom()                      { return mEmailFrom; }
00083         static bool              emailBccUseControlCentre()       { return mEmailBccFrom == MAIL_FROM_CONTROL_CENTRE; }
00084         static TQString           emailAddress();
00085         static TQString           emailBccAddress();
00086         static TQString           cmdXTermCommand()                { return mCmdXTermCommand; }
00087         static TQColor            disabledColour()                 { return mDisabledColour; }
00088         static TQColor            expiredColour()                  { return mExpiredColour; }
00089         static int               expiredKeepDays()                { return mExpiredKeepDays; }
00090         static SoundPicker::Type defaultSoundType()               { return mDefaultSoundType; }
00091         static const TQString&    defaultSoundFile()               { return mDefaultSoundFile; }
00092         static float             defaultSoundVolume()             { return mDefaultSoundVolume; }
00093         static bool              defaultSoundRepeat()             { return mDefaultSoundRepeat; }
00094         static int               defaultLateCancel()              { return mDefaultLateCancel; }
00095         static bool              defaultAutoClose()               { return mDefaultAutoClose; }
00096         static bool              defaultConfirmAck()              { return mDefaultConfirmAck; }
00097         static bool              defaultCopyToKOrganizer()        { return mDefaultCopyToKOrganizer; }
00098         static bool              defaultCmdScript()               { return mDefaultCmdScript; }
00099         static EditAlarmDlg::CmdLogType  
00100                                  defaultCmdLogType()              { return mDefaultCmdLogType; }
00101         static TQString           defaultCmdLogFile()              { return mDefaultCmdLogFile; }
00102         static bool              defaultEmailBcc()                { return mDefaultEmailBcc; }
00103         static RecurrenceEdit::RepeatType
00104                                  defaultRecurPeriod()             { return mDefaultRecurPeriod; }
00105         static KARecurrence::Feb29Type
00106                                  defaultFeb29Type()               { return mDefaultFeb29Type; }
00107         static TimePeriod::Units defaultReminderUnits()           { return mDefaultReminderUnits; }
00108         static const TQString&    defaultPreAction()               { return mDefaultPreAction; }
00109         static const TQString&    defaultPostAction()              { return mDefaultPostAction; }
00110 
00111         // Config file entry names for notification messages
00112         static const TQString     QUIT_WARN;
00113         static const TQString     CONFIRM_ALARM_DELETION;
00114         static const TQString     EMAIL_QUEUED_NOTIFY;
00115 
00116         // Default values for settings
00117         static const ColourList                 default_messageColours;
00118         static const TQColor                     default_defaultBgColour;
00119         static const TQColor                     default_defaultFgColour;
00120         static const TQFont&                     default_messageFont()  { return mDefault_messageFont; };
00121         static const TQTime                      default_startOfDay;
00122         static const bool                       default_runInSystemTray;
00123         static const bool                       default_disableAlarmsIfStopped;
00124         static const bool                       default_quitWarn;
00125         static const bool                       default_autostartTrayIcon;
00126         static const bool                       default_confirmAlarmDeletion;
00127         static const bool                       default_modalMessages;
00128         static const int                        default_messageButtonDelay;
00129         static const int                        default_tooltipAlarmCount;
00130         static const bool                       default_showTooltipAlarmTime;
00131         static const bool                       default_showTooltipTimeToAlarm;
00132         static const TQString                    default_tooltipTimeToPrefix;
00133         static const int                        default_daemonTrayCheckInterval;
00134         static const MailClient                 default_emailClient;
00135         static const bool                       default_emailCopyToKMail;
00136         static MailFrom                         default_emailFrom();
00137         static const bool                       default_emailQueuedNotify;
00138         static const MailFrom                   default_emailBccFrom;
00139         static const TQString                    default_emailAddress;
00140         static const TQString                    default_emailBccAddress;
00141         static const TQColor                     default_disabledColour;
00142         static const TQColor                     default_expiredColour;
00143         static const int                        default_expiredKeepDays;
00144         static const TQString                    default_defaultSoundFile;
00145         static const float                      default_defaultSoundVolume;
00146         static const int                        default_defaultLateCancel;
00147         static const bool                       default_defaultAutoClose;
00148         static const bool                       default_defaultCopyToKOrganizer;
00149         static const SoundPicker::Type          default_defaultSoundType;
00150         static const bool                       default_defaultSoundRepeat;
00151         static const bool                       default_defaultConfirmAck;
00152         static const bool                       default_defaultCmdScript;
00153         static const EditAlarmDlg::CmdLogType   default_defaultCmdLogType;
00154         static const bool                       default_defaultEmailBcc;
00155         static const RecurrenceEdit::RepeatType default_defaultRecurPeriod;
00156         static const KARecurrence::Feb29Type    default_defaultFeb29Type;
00157         static const TimePeriod::Units          default_defaultReminderUnits;
00158         static const TQString                    default_defaultPreAction;
00159         static const TQString                    default_defaultPostAction;
00160 
00161     signals:
00162         void  preferencesChanged();
00163         void  startOfDayChanged(const TQTime& oldStartOfDay);
00164 
00165     private:
00166         Preferences()  { }     // only one instance allowed
00167         void  emitPreferencesChanged();
00168         void  emitStartOfDayChanged();
00169 
00170         static void                read();
00171         static void                convertOldPrefs();
00172         static int                 startOfDayCheck();
00173         static TQString            emailFrom(MailFrom, bool useAddress, bool bcc);
00174         static MailFrom            emailFrom(const TQString&);
00175         static void                setNotify(const TQString& messageID, bool notify);
00176         static bool                notifying(const TQString& messageID);
00177 
00178         static Preferences*        mInstance;
00179         static TQFont               mDefault_messageFont;
00180         static TQString             mEmailAddress;
00181         static TQString             mEmailBccAddress;
00182 
00183         // All the following members are accessed by the Preferences dialog classes
00184         friend class MiscPrefTab;
00185         friend class EditPrefTab;
00186         friend class ViewPrefTab;
00187         friend class FontColourPrefTab;
00188         friend class EmailPrefTab;
00189         static void                setEmailAddress(MailFrom, const TQString& address);
00190         static void                setEmailBccAddress(bool useControlCentre, const TQString& address);
00191         static ColourList          mMessageColours;
00192         static TQColor              mDefaultBgColour;
00193         static TQFont               mMessageFont;
00194         static TQTime               mStartOfDay;
00195         static bool                mRunInSystemTray;
00196         static bool                mDisableAlarmsIfStopped;
00197         static bool                mAutostartTrayIcon;
00198         static bool                mModalMessages;
00199         static int                 mMessageButtonDelay;  // 0 = scatter; -1 = no delay, no scatter; >0 = delay, no scatter
00200         static int                 mTooltipAlarmCount;
00201         static bool                mShowTooltipAlarmTime;
00202         static bool                mShowTooltipTimeToAlarm;
00203         static TQString             mTooltipTimeToPrefix;
00204         static int                 mDaemonTrayCheckInterval;
00205         static MailClient          mEmailClient;
00206         static MailFrom            mEmailFrom;
00207         static MailFrom            mEmailBccFrom;
00208         static bool                mEmailCopyToKMail;
00209         static TQString             mCmdXTermCommand;
00210         static TQColor              mDisabledColour;
00211         static TQColor              mExpiredColour;
00212         static int                 mExpiredKeepDays;     // 0 = don't keep, -1 = keep indefinitely
00213         // Default settings for Edit Alarm dialog
00214         static TQString             mDefaultSoundFile;
00215         static float               mDefaultSoundVolume;
00216         static int                 mDefaultLateCancel;
00217         static bool                mDefaultAutoClose;
00218         static bool                mDefaultCopyToKOrganizer;
00219         static SoundPicker::Type   mDefaultSoundType;
00220         static bool                mDefaultSoundRepeat;
00221         static bool                mDefaultConfirmAck;
00222         static bool                mDefaultEmailBcc;
00223         static bool                mDefaultCmdScript;
00224         static EditAlarmDlg::CmdLogType   mDefaultCmdLogType;
00225         static TQString                    mDefaultCmdLogFile;
00226         static RecurrenceEdit::RepeatType mDefaultRecurPeriod;
00227         static KARecurrence::Feb29Type    mDefaultFeb29Type;
00228         static TimePeriod::Units   mDefaultReminderUnits;
00229         static TQString             mDefaultPreAction;
00230         static TQString             mDefaultPostAction;
00231         // Change tracking
00232         static TQTime               mOldStartOfDay;       // previous start-of-day time
00233         static bool                mStartOfDayChanged;   // start-of-day check value doesn't tally with mStartOfDay
00234 };
00235 
00236 #endif // PREFERENCES_H