kalarm

messagewin.h

Go to the documentation of this file.
00001 /*
00002  *  messagewin.h  -  displays an alarm message
00003  *  Program:  kalarm
00004  *  Copyright © 2001-2007 by David Jarvie <software@astrojar.org.uk>
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 MESSAGEWIN_H
00022 #define MESSAGEWIN_H
00023 
00026 #include <tqmap.h>
00027 
00028 #include "mainwindowbase.h"
00029 #include "alarmevent.h"
00030 
00031 class TQPushButton;
00032 class KPushButton;
00033 class TQLabel;
00034 class TQTimer;
00035 class KWinModule;
00036 class AlarmTimeWidget;
00037 class DeferAlarmDlg;
00038 class KArtsDispatcher;
00039 namespace KDE { class PlayObject; }
00040 
00044 class MessageWin : public MainWindowBase
00045 {
00046         Q_OBJECT
00047     public:
00048         MessageWin();     // for session management restoration only
00049         MessageWin(const KAEvent&, const KAAlarm&, bool reschedule_event = true, bool allowDefer = true);
00050         MessageWin(const KAEvent&, const DateTime& alarmDateTime, const TQStringList& errmsgs);
00051         ~MessageWin();
00052         void                repeat(const KAAlarm&);
00053         void                setRecreating()        { mRecreating = true; }
00054         const DateTime&     dateTime()             { return mDateTime; }
00055         KAAlarm::Type       alarmType() const      { return mAlarmType; }
00056         bool                hasDefer() const       { return !!mDeferButton; }
00057         bool                isValid() const        { return !mInvalid; }
00058         virtual void        show();
00059         virtual TQSize       sizeHint() const;
00060         static int          instanceCount()        { return mWindowList.count(); }
00061         static MessageWin*  findEvent(const TQString& eventID);
00062 
00063     protected:
00064         virtual void        showEvent(TQShowEvent*);
00065         virtual void        moveEvent(TQMoveEvent*);
00066         virtual void        resizeEvent(TQResizeEvent*);
00067         virtual void        closeEvent(TQCloseEvent*);
00068         virtual void        saveProperties(KConfig*);
00069         virtual void        readProperties(KConfig*);
00070 
00071     private slots:
00072         void                slotEdit();
00073         void                slotDefer();
00074         void                checkDeferralLimit();
00075         void                displayMainWindow();
00076         void                slotShowKMailMessage();
00077         void                slotSpeak();
00078         void                slotPlayAudio();
00079         void                checkAudioPlay();
00080         void                stopPlay();
00081         void                slotFade();
00082         void                enableButtons();
00083         void                setRemainingTextDay();
00084         void                setRemainingTextMinute();
00085         void                setMaxSize();
00086 
00087     private:
00088         void                initView();
00089 #ifndef WITHOUT_ARTS
00090         void                initAudio(bool firstTime);
00091         int                 getKMixVolume();
00092         void                setKMixVolume(int percent);
00093 #endif
00094         void                displayComplete();
00095         void                playAudio();
00096         void                setDeferralLimit(const KAEvent&);
00097         bool                haveErrorMessage(unsigned msg) const;
00098         void                clearErrorMessage(unsigned msg) const;
00099 
00100         static TQValueList<MessageWin*> mWindowList;  // list of existing message windows
00101         static TQMap<TQString, unsigned> mErrorMessages;  // error messages currently displayed, by event ID
00102         // Properties needed by readProperties()
00103         TQString             mMessage;
00104         TQFont               mFont;
00105         TQColor              mBgColour, mFgColour;
00106         DateTime            mDateTime;        // date/time displayed in the message window
00107         TQDateTime           mCloseTime;       // time at which window should be auto-closed
00108         TQString             mEventID;
00109         TQString             mAudioFile;
00110         float               mVolume;
00111         float               mFadeVolume;
00112         int                 mFadeSeconds;
00113         int                 mDefaultDeferMinutes;
00114         KAAlarm::Type       mAlarmType;
00115         KAEvent::Action     mAction;
00116         unsigned long       mKMailSerialNumber; // if email text, message's KMail serial number, else 0
00117         TQStringList         mErrorMsgs;
00118         int                 mRestoreHeight;
00119         bool                mAudioRepeat;
00120         bool                mConfirmAck;
00121         bool                mShowEdit;        // display the Edit button
00122         bool                mNoDefer;         // don't display a Defer option
00123         bool                mInvalid;         // restored window is invalid
00124         // Sound file playing
00125         KArtsDispatcher*    mArtsDispatcher;
00126         KDE::PlayObject*    mPlayObject;
00127         TQCString            mKMixName;        // DCOP name for KMix
00128         TQString             mKMixError;       // error message starting KMix
00129         TQTimer*             mPlayTimer;       // timer for repeating the sound file
00130         TQTimer*             mFadeTimer;       // timer for fading the sound volume
00131         float               mOldVolume;       // volume before volume was set for sound file
00132         TQString             mLocalAudioFile;  // local copy of audio file
00133         TQTime               mAudioFileStart;  // time when audio file loading first started, or when play first started
00134         int                 mAudioFileLoadSecs;  // how many seconds it took to load audio file
00135         bool                mPlayedOnce;      // the sound file has started playing at least once
00136         bool                mPlayed;          // the PlayObject->play() has been called
00137         // Miscellaneous
00138         KAEvent             mEvent;           // the whole event, for updating the calendar file
00139         TQLabel*             mRemainingText;   // the remaining time (for a reminder window)
00140         KPushButton*        mOkButton;
00141         TQPushButton*        mEditButton;
00142         TQPushButton*        mDeferButton;
00143         TQPushButton*        mSilenceButton;
00144         TQPushButton*        mKAlarmButton;
00145         TQPushButton*        mKMailButton;
00146         DeferAlarmDlg*      mDeferDlg;
00147         TQDateTime           mDeferLimit;      // last time to which the message can currently be deferred
00148         mutable KWinModule* mWinModule;
00149         int                 mFlags;
00150         int                 mLateCancel;
00151         int                 mButtonDelay;     // delay (ms) after window is shown before buttons are enabled
00152         bool                mErrorWindow;     // the window is simply an error message
00153         bool                mNoPostAction;    // don't execute any post-alarm action
00154         bool                mRecreating;      // window is about to be deleted and immediately recreated
00155         bool                mBeep;
00156         bool                mSpeak;           // the message should be spoken via kttsd
00157         bool                mRescheduleEvent; // true to delete event after message has been displayed
00158         bool                mShown;           // true once the window has been displayed
00159         bool                mPositioning;     // true when the window is being positioned initially
00160         bool                mNoCloseConfirm;  // the Defer or Edit button is closing the dialog
00161         bool                mUsingKMix;       // master volume is being set using kmix
00162         bool                mDisableDeferral; // true if past deferral limit, so don't enable Defer button
00163 };
00164 
00165 #endif // MESSAGEWIN_H