summaryrefslogtreecommitdiffstats
path: root/kshutdown/miscutils.h
blob: db2eb4765ef8318c8d6862de528e88b244a1da3c (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
/*
	miscutils.h - Misc functions
	Copyright (C) 2004  Konrad Twardowski <[email protected]>

	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 __MISCUTILS_H__
#define __MISCUTILS_H__

#include <qdatetime.h>

#include <kprocess.h>

class KAction;
class KPushButton;

/** @short Misc functions. */
class MiscUtils
{
public:
	/**
	 * Closes the CD-ROM tray (if this option is enabled).
	 */
	static void closeCDTray();

	/**
	 * Displays a custom message.
	 * @param text A text to display
	 * @param testCommand A command to execute (used internally in settings dialog to test entered command)
	 */
	static void customMessage(const QString &text, const QString &testCommand = QString::null);

	/**
	 * Converts seconds to time string.
	 * @param secs A number of seconds to convert
	 * @param format A date/time format
	 * @return Converted seconds or ">24", if @p secs >= 86400
	 */
	static QString formatDateTime(const int secs, const QString &format = QString::null);

	/**
	 * Converts seconds to time string.
	 * @param dt A date/time to convert
	 * @return Converted seconds or ">24", if @p secs >= 86400
	 */
	static QString formatDateTime(const QDateTime &dt);

	inline static QString HTML(const QString &text) {
		return ("<qt>" + text + "</qt>");
	}

	inline static QString HTML(QString &text) {
		text.prepend("<qt>");
		text.append("</qt>");

		return text;
	}

	/**
	 * Returns @c true if function (@p key) is restricted (KDE Kiosk).
	 * The key value is read from the configuration file
	 * (usually /usr/share/config/kshutdownrc).
	 * See Handbook (F1) for details.
	 */
	static bool isRestricted(const QString &key);

	/**
	 * Visual and sound notifications.
	 * @param secs A number of seconds to action
	 */
	static void notifyUser(const int secs);

	static void passiveMessage(const QString &text, QWidget *parent = 0);

	static void plug(const KAction *action, KPushButton *pushButton);

	/**
	 * Executes a command.
	 * @param command A command to execute
	 * @return @c true if successfull; otherwise @c false
	 */
	static bool runCommand(const QString &command);

	/**
	 * Executes a shell command before the specified action.
	 * @param configEntry A configuration entry (e.g. <i>"Shut Down"</i>)
	 */
	static void runCommandBeforeAction(const QString &configEntry);

	/**
	 * Executes a shell command.
	 * @param command A shell command to execute
	 * @param mode A run mode (@c KProcess::DontCare by default)
	 * @param pause A timeout in seconds (no timeout by default)
	 * @return @c true if successfull; otherwise @c false
	 */
	static bool runShellCommand(const QString &command, const KProcess::RunMode mode = KProcess::DontCare, const int pause = -1);

	static void setAutostart(const bool yes);

	/**
	 * Sets "tool tip text" and "what's this text" of @p widget to @p value.
	 */
	static void setHint(QWidget *widget, const QString &value);

	/**
	 * Displays a "KRun" error message in a passive message.
	 * @param command A command that failed
	 */
	static void showRunErrorMessage(const QString &command);

	/**
	 * Displays an information if KShutDown is in the <b>Test Mode</b>.
	 * @param message A message to display
	 */
	static void showTestMessage(const QString &message);

private:
	static void notifyUser(const QString &name, const QString &text);
};

#endif // __MISCUTILS_H__