summaryrefslogtreecommitdiffstats
path: root/kshutdown/mmainwindow.h
blob: 0b17dde5733b156fa95d3e0e5073bc7cc0c71e73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
	mmainwindow.h - The main window
	Copyright (C) 2003  Konrad Twardowski <kdtonline@poczta.onet.pl>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#ifndef __MMAINWINDOW_H__
#define __MMAINWINDOW_H__

#include "actions.h"
#include "kshutdowniface.h"

#include <tqdatetime.h>

#include <tdemainwindow.h>

class AppObserver;

class TQDateTimeEdit;
class TQLabel;

class TDEGlobalAccel;
class KPushButton;

#define ks_main MMainWindow::getInstance()

/** @short The main window. */
class MMainWindow: public TDEMainWindow, virtual public KShutdownIface
{
	TQ_OBJECT
public:
	/**
	 * Timeout options.
	 */
	enum DelayType {
		DelayType_Now = 0, /**< Immediate action (no delay). */
		DelayType_TimeFromNow = 1, /**< Time from now in HH:MM format. */
		DelayType_DateTime = 2, /**< Absolute date and time. */
		DelayType_OnAppExit = 3 /**< When desired application exit. */
	};

	/** Constructor. */
	MMainWindow();

	/** Destructor. */
	virtual ~MMainWindow();

	/** Sets current action to @p action. */
	void setAction(const Action::Type action);

	/** Sets delay type to @p value. */
	void setDelayType(const DelayType value);

	/** Sets editor time to @p time. */
	void setTime(const TQTime &time);

	/** Returns the main window widget. Accessed via the @c ks_main macro. */
	inline static MMainWindow *getInstance() { return _instance; }

	/** Sets editor date to @p date. */
	void setDate(const TQDate &date);

	/**
	 * Activates the selected action.
	 * @param confirmation @c false - no confirmation
	 */
	void start(const bool confirmation = true);

	// actions
	inline TDEAction *cancelAction() const { return _cancelAction; }
	inline TDEAction *checkSystemConfigurationAction() const { return _checkSystemConfigurationAction; }
	inline TDEAction *configureKShutDownAction() const { return _configureKShutDownAction; }
	inline TDEAction *lockScreenAction() const { return _lockScreenAction; }
	inline TDEAction *logoutAction() const { return _logoutAction; }
	inline TDEAction *rebootAction() const { return _rebootAction; }
	inline TDEAction *shutDownAction() const { return _shutDownAction; }
	inline TDEAction *statisticsAction() const { return _statisticsAction; }

	// DCOP:
	// general:
	virtual void cancel();
	virtual bool shutDown();
	virtual bool shutdown();
	virtual bool reboot();
	virtual bool lockScreen();
	virtual bool logout();
	// misc:
	virtual void configure();
	virtual TQString getStatusInfo();
	virtual void makeInvisible();
	virtual void makeVisible();
	virtual void setTestMode(bool yes);
private:
	bool _showMinimizeInfo;
	// actions
	TDEAction
		*_cancelAction,
		*_checkSystemConfigurationAction,
		*_configureKShutDownAction,
		*_lockScreenAction,
		*_logoutAction,
		*_rebootAction,
		*_shutDownAction,
		*_startAction,
		*_statisticsAction;
	TDEActionCollection *ac_shutDown;
	TDEGlobalAccel *_globalAccel;

	int _oldSec;
	AppObserver *_appObserver;
	TQDateTimeEdit *_dateTimeEdit;
	KPushButton *b_startStop;

	// points to the main window widget (this)
	static MMainWindow *_instance;
	TQComboBox
		*cb_actions,
		*cb_delayTypes;
	TQDateTime
		dt_end, // end date/time
		dt_start; // start date/time
	TQLabel *l_statusLine;
	TQTimer *_timer; // timeout timer
	DelayType _delayType;

	TQString getTimeInfo();

	void initMainMenu();

	void initActions();
	TQWidget *initWidgets();

	/**
	 * Sets window and system tray captions.
	 * @param remainingTime A remaining time
	 * @param selectedTime A selected time
	 */
	void setCaptions(const TQString &remainingTime = TQString::null, const TQString &selectedTime = TQString::null);

	void setWidgetsEnabled(const bool yes);

	/**
	 * Updates time infos (e.g. window captions).
	 * Displays time to the final shut down, and the selected action name.
	 */
	void updateTimeInfo(const int secs);
private slots:
	/**
	 * This signal is emitted when the application is about to quit, or when the
	 * user shuts down the entire desktop session.
	 */
	void slotAboutToQuit();

	/**
	 * Checks the time, and after timeout executes active action.
	 */
	void slotCheckTime();

	/**
	 * Called when a new item has been selected in the combo box.
	 * @param index A new item index
	 */
	void slotDelayTypeChange(int index);

	void slotConfigureGlobalShortcuts();
	void slotConfigureKShutDown();
	void slotConfigureNotifications();
	void slotConfigureShortcuts();

	void slotActionChange(int index);
	void slotCheckSystemConfig();
	void slotStats();

	/**
	 * Updates "Selected time:" info.
	 * @see calcSelectedTime
	 */
	void slotUpdateTimeInfo();
public slots:
	/** Cancels an active action. */
	void slotCancel();
	/** Activates the selected action. */
	void slotStart();
	/** Quits the application. */
	void slotQuit();
protected:
	/** Closes or minizes the main window. */
	virtual bool queryClose();
	/**
	 * Invoked at application exit.
	 * @return @c true
	 */
	virtual bool queryExit();
};

#endif // __MMAINWINDOW_H__