summaryrefslogtreecommitdiffstats
path: root/kopete/libkopete/kopeteaway.h
blob: 90d074693d09a0a2e0861ae553176ae5ffba61e5 (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
210
211
212
213
214
215
216
217
218
/*
    kopeteaway.h  -  Kopete Away

    Copyright (c) 2002 by Hendrik vom Lehn <[email protected]>
    Copyright (c) 2003 Olivier Goffart     <ogoffart @ kde.org>

    Kopete (c) 2002-2003 by the Kopete developers  <[email protected]>

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

#ifndef KOPETEAWAY_HI
#define KOPETEAWAY_HI

#include <tqstring.h>
#include <tqobject.h>
#include <tqvaluelist.h>

#include "kopeteawaydialog.h"
#include "kopete_export.h"

class TQStringList;

struct KopeteAwayPrivate;

class KopeteGlobalAwayDialog;
class KopeteAwayDialog;

namespace Kopete
{

/**
 * @class Kopete::Away kopeteaway.h
 *
 * Kopete::Away is a singleton class that manages away messages
 * for Kopete. It stores a global away message, as well as
 * a list of user defined away messages.
 * This class is used by KopeteAwayDialog, which gets it's
 * list of user-defined away messages from this.  Protocol
 * plugins' individual away dialogs should also get away
 * messages from this object.
 *
 * It also handle global Idle Time, and all auto away stuff
 *
 * @author Hendrik vom Lehn <[email protected]>
 * @author Chris TenHarmsel <[email protected]>
 * @author Olivier Goffart <ogoffart @ kde.org>

 */
class KOPETE_EXPORT Away : public TQObject
{
Q_OBJECT
  TQ_OBJECT

friend class ::KopeteAwayDialog;

public:

	/**
	 * @brief Method to get the single instance of Kopete::Away
	 * @return Kopete::Away instance pointer
	 */
	static Away *getInstance();

	/**
	 * @brief Gets the current global away message
	 * @return The global away message
	 */
	static TQString message();

	/**
	 * @brief Gets the current global auto away message
	 * @return The global auto away message
	 */
	static TQString autoAwayMessage();

	/**
	 * This method sets the global away message,
	 * it does not set you away, just sets the message.
	 * @brief Sets the global away message
	 * @param message The message you want to set
	 */
	void setGlobalAwayMessage(const TQString &message);

	/**
	 * This method sets the global auto away message,
	 * it does not set you away, just sets the message.
	 * @brief Sets the global auto away message
	 * @param message The message you want to set
	 */
	void setAutoAwayMessage(const TQString &message);

	/**
	 * @brief Sets global away for all protocols
	 */
	static void setGlobalAway(bool status);

	/**
	 * @brief Indicates global away status
	 * @return Bool indicating global away status
	 */
	static bool globalAway();

	/**
	 * @brief Function to get the titles of user defined away messages
	 * @return List of away message titles
	 *
	 * This function can be used to retrieve a TQStringList of the away message titles,
	 * these titles can be passed to getMessage(TQString title) to retrieve the
	 * corresponding message.
	 */
	TQStringList getMessages();

	/**
	 * @brief Function to get an away message
	 * @return The away message corresponding to the title
	 * @param messageNumber Number of the away message to retrieve
	 *
	 * This function retrieves the away message that corresponds to the ringbuffer index
	 * passed in.
	 */
	 TQString getMessage( uint messageNumber );

	 /**
	  * @brief Adds an away message to the ringbuffer
	  * @param message The away message
	  *
	  * This function will add an away message to the ringbuffer of user defined
	  * away messages.
	  */
	 void addMessage(const TQString &message);

	/**
	 * time in seconds the user has been idle
	 */
	long int idleTime();

private:
	Away();
	~Away();

	/**
	 * @brief Saves the away messages to disk
	 *
	 * This function will save the current list of away messages to the disk
	 * using KConfig. It is called automatically.
	 */
	void save();

	/**
	 * @brief Check for activity using X11 methods
	 * @return true if activity was detected, otherwise false
	 *
	 * Attempt to detect activity using a variety of X11 methods.
	 */
	bool isActivity();

	//Away( const Away &rhs );
	//Away &operator=( const Away &rhs );
	static Away *instance;
	KopeteAwayPrivate *d;

private slots:
	void slotTimerTimeout();
	void load();

public slots:
	/**
	 * @brief Mark the user active
	 *
	 * Plugins can mark the user active if they discover activity by another way than the mouse or the keyboard
	 * (example, the motion auto away plugin)
	 * this will reset the @ref idleTime to 0, and set all protocols to available (online) if the state was
	 * set automatically to away because of idleness, and if they was previously online
	 */
	void setActive();

	/**
	 * Use this method if you want to go in the autoaway mode.
	 * This will go autoaway even if the idle time is not yet reached. (and even if the user
	 * did not selected to go autoaway automaticaly)
	 * But that will go unaway again when activity will be detected
	 */
	void setAutoAway();

signals:
	/**
	 * @brief Activity was detected
	 *
	 * this signal is emit when activity has been discover after being autoAway.
	 */
	void activity();

	/**
	 * @brief Default messages were changed
	 */
	void messagesChanged();
};

}

#endif
/*
 * Local variables:
 * c-indentation-style: k&r
 * c-basic-offset: 8
 * indent-tabs-mode: t
 * End:
 */
// vim: set noet ts=4 sts=4 sw=4: