summaryrefslogtreecommitdiffstats
path: root/tdecore/kshortcutlist.h
blob: 99e83766bcb08e0755aa4b8bf9638b61dd0b4578 (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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/*  This file is part of the KDE libraries
    Copyright (C) 2002 Ellis Whitehead <ellis@kde.org>

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

    This library 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
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#ifndef __KSHORTCUTLIST_H
#define __KSHORTCUTLIST_H

#include <tqglobal.h>	// For uint
#include <tqstring.h>
#include "tdelibs_export.h"

class TQVariant;
class TDEConfigBase;
class TDEInstance;
class KKeySequence;
class TDEShortcut;

/**********************************************************************
* This is a wrapper class which allows a function to use one interface
* to TDEActionCollection, TDEAccelActions, and TDEActionPtrList.
**********************************************************************/

/**
 * TDEShortcutList is an abstract base class for
 * TDEAccelShortcutList and TDEStdAccel::ShortcutList. It gives
 * you an unified interface for accessing the accelerator lists
 * of TDEAccel (using TDEAccelShortcutList),
 * TDEGlobalAccel (using TDEAccelShortcutList), and
 * TDEStdAccel (using TDEStdAccel::ShortcutList).
 *
 * @short Base class for accessing accelerator lists
 */
class TDECORE_EXPORT TDEShortcutList
{
 public:
        /**
	 * Default constructor.
	 */
	TDEShortcutList();
	virtual ~TDEShortcutList();

	/**
	 * Returns the number of entries.
	 * @return the number of entries
	 */
	virtual uint count() const = 0;

	/**
	 * Returns the name of the shortcut with the given @p index.
	 * @param index the index of the shortcut (must be < count())
	 * @return the name of the shortcut
	 */
	virtual TQString name( uint index ) const = 0;

	/**
	 * Returns the (i18n'd) label of the shortcut with the given @p index.
	 * @param index the index of the shortcut (must be < count())
	 * @return the label (i18n'd) of the shortcut
	 */
	virtual TQString label( uint index ) const = 0;

	/**
	 * Returns the (i18n'd) What's This text of the shortcut with the given @p index.
	 * @param index the index of the shortcut (must be < count())
	 * @return the What's This text (i18n'd) of the shortcut
	 */
	virtual TQString whatsThis( uint index ) const = 0;

	// TODO KDE4: add virtual TQString toolTip( uint index ) const = 0
	// Will then be used by the listview in kkeydialog

	/**
	 * Returns the shortcut with the given @p index.
	 * @param index the index of the shortcut (must be < count())
	 * @return the shortcut
	 * @see shortcutDefault()
	 */
	virtual const TDEShortcut& shortcut( uint index ) const = 0;

	/**
	 * Returns default shortcut with the given @p index.
	 * @param index the index of the shortcut (must be < count())
	 * @return the default shortcut
	 * @see shortcut()
	 */
	virtual const TDEShortcut& shortcutDefault( uint index ) const = 0;

	/**
	 * Checks whether the shortcut with the given @p index is configurable.
	 * @param index the index of the shortcut (must be < count())
	 * @return true if configurable, false otherwise
	 */
	virtual bool isConfigurable( uint index ) const = 0;

	/**
	 * Sets the shortcut of the given entry
	 * @param index the index of the shortcut (must be < count())
	 * @param shortcut the shortcut
	 */
	virtual bool setShortcut( uint index, const TDEShortcut &shortcut ) = 0;

	/**
	 * Checks whether the shortcut with the given @p index is saved in the
	 * global configuration.
	 * @param index the index of the shortcut (must be < count())
	 * @return true if global, false otherwise
	 */
	virtual bool isGlobal( uint index ) const;

	/**
	 * Returns the index of the shortcut with he given name.
	 * @param sName the name of the shortcut to search
	 * @return the index of the shortcut, of -1 if not found
	 */
	virtual int index( const TQString& sName ) const;

	/**
	 * Returns the index of the shortcut with he given key sequence.
	 * @param keySeq the key sequence to search for
	 * @return the index of the shortcut, of -1 if not found
	 */
	virtual int index( const KKeySequence& keySeq ) const;

	/**
	 * The TDEInstance.
	 * @return the TDEInstance of the list, can be 0 if not available
	 */
	virtual const TDEInstance* instance() const;

	// These are here in order to handle expansion.
	enum Other { };
	/** \internal */
	virtual TQVariant getOther( Other, uint index ) const = 0;
	/** \internal */
	virtual bool setOther( Other, uint index, TQVariant ) = 0;

	/**
	 * Save the shortcut list.
	 * @return true if successful, false otherwise
	 */
	virtual bool save() const = 0;

	/**
	 * Loads the shortcuts from the given configuration file.
	 *
	 * @param sConfigGroup the group in the configuration file
	 * @param pConfig the configuration file to load from
	 * @return true if successful, false otherwise
	 */
	virtual bool readSettings( const TQString& sConfigGroup = TQString::null, TDEConfigBase* pConfig = 0 );

	/**
	 * Writes the shortcuts to the given configuration file.
	 *
	 * @param sConfigGroup the group in the configuration file
	 * @param pConfig the configuration file to save to
	 * @param bWriteAll true to write all actions
	 * @param bGlobal true to write to the global configuration file
	 * @return true if successful, false otherwise
	 */
	virtual bool writeSettings( const TQString& sConfigGroup = TQString::null, TDEConfigBase* pConfig = 0,
			bool bWriteAll = false, bool bGlobal = false ) const;

 protected:
	/// used to extend the interface with virtuals without breaking binary compatibility
        virtual void virtual_hook( int id, void* data );
 private:
	class TDEShortcutListPrivate* d;
};

//---------------------------------------------------------------------
// TDEAccelShortcutList
//---------------------------------------------------------------------

class TDEAccel;
class TDEAccelActions;
class TDEGlobalAccel;

/**
 * TDEShortcutList implementation to access TDEAccel and
 * TDEGlobalAccel lists.
 */
class TDECORE_EXPORT TDEAccelShortcutList : public TDEShortcutList
{
 public:
        /**
	 * Creates a new TDEShortcutList that accesses the given TDEAccel.
	 * @param accel the accelerators to access
	 */
	TDEAccelShortcutList( TDEAccel* accel );

        /**
	 * Creates a new TDEShortcutList that accesses the given
	 * TDEGlobalAccel.
	 * @param accel the accelerators to access
	 */
	TDEAccelShortcutList( TDEGlobalAccel* accel );

        /**
	 * @internal
	 * Creates a new TDEShortcutList that accesses the given
	 * TDEAccelActions collection.
	 * @param actions the actions to access
	 * @param bGlobal true to save the actions in the global
	 *        configuration file
	 */
	TDEAccelShortcutList( TDEAccelActions &actions, bool bGlobal );
	virtual ~TDEAccelShortcutList();

	virtual uint count() const;
	virtual TQString name( uint index ) const;
	virtual TQString label( uint index ) const;
	virtual TQString whatsThis( uint index ) const;
	virtual const TDEShortcut& shortcut( uint index ) const;
	virtual const TDEShortcut& shortcutDefault( uint index ) const;
	virtual bool isConfigurable( uint index ) const;
	virtual bool setShortcut( uint index , const TDEShortcut& shortcut );
	virtual bool isGlobal( uint index ) const;

	/** \internal */
	virtual TQVariant getOther( Other, uint index ) const;
	/** \internal */
	virtual bool setOther( Other, uint index, TQVariant );

	virtual bool save() const;

 protected:
	/** Actions (collection) for this shortcut list. Set by constructor. */
	TDEAccelActions& m_actions;
	/** Is this shortcut list global? Access through isGlobal() */
	bool m_bGlobal;

 protected:
	virtual void virtual_hook( int id, void* data );
 private:
	class TDEAccelShortcutListPrivate* d;
};

namespace TDEStdAccel {
//---------------------------------------------------------------------
// ShortcutList
//---------------------------------------------------------------------

/**
 * TDEShortcutList implementation that accesses TDEStdAccel
 * actions.
 */
class TDECORE_EXPORT ShortcutList : public TDEShortcutList
{
 public:
        /**
	 * Creates a new ShortcutList.
	 */
	ShortcutList();
	virtual ~ShortcutList();

	virtual uint count() const;
	virtual TQString name( uint index ) const;
	virtual TQString label( uint index ) const;
	virtual TQString whatsThis( uint index ) const;
	virtual const TDEShortcut& shortcut( uint index ) const;
	virtual const TDEShortcut& shortcutDefault( uint index ) const;
	virtual bool isConfigurable( uint index ) const;
	virtual bool setShortcut( uint index , const TDEShortcut& shortcut );

	/** \internal */
	virtual TQVariant getOther( Other, uint index ) const;
	/** \internal */
	virtual bool setOther( Other, uint index, TQVariant );

	virtual bool save() const;

 protected:
	virtual void virtual_hook( int id, void* data );
 private:
	class ShortcutListPrivate* d;
};
}

#endif // __KSHORTCUTLIST_H