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