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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
/****************************************************************************
KHotKeys
Copyright (C) 1999-2001 Lubos Lunak <l.lunak@kde.org>
Distributed under the terms of the GNU General Public License version 2.
****************************************************************************/
#define _KCMKHOTKEYS_CPP_
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "kcmkhotkeys.h"
#include <unistd.h>
#include <stdlib.h>
#include <tqlayout.h>
#include <tqsplitter.h>
#include <tdecmodule.h>
#include <kaboutdata.h>
#include <klocale.h>
#include <kapplication.h>
#include <kconfig.h>
#include <kapplication.h>
#include <dcopclient.h>
#include <kdebug.h>
#include <kmessagebox.h>
#include <kglobal.h>
#include <ksimpleconfig.h>
#include <kfiledialog.h>
#include <dcopref.h>
#include <klibloader.h>
#include <input.h>
#include <triggers.h>
#include <action_data.h>
#include "tab_widget.h"
#include "actions_listview_widget.h"
#include "main_buttons_widget.h"
#include "voicerecorder.h"
extern "C"
{
KDE_EXPORT TDECModule* create_khotkeys( TQWidget* parent_P, const char* name_P )
{
// sleep( 20 ); // CHECKME DEBUG
TDEGlobal::locale()->insertCatalogue("khotkeys");
KHotKeys::Module* ret = new KHotKeys::Module( parent_P, name_P );
ret->load(); // CHECKME
return ret;
}
}
namespace KHotKeys
{
Module::Module( TQWidget* parent_P, const char* )
: TDECModule( parent_P, "khotkeys" ), _actions_root( NULL ), _current_action_data( NULL ),
listview_is_changed( false ), deleting_action( false )
{
setButtons( Help | Cancel | Apply | Ok );
module = this;
init_global_data( false, TQT_TQOBJECT(this) ); // don't grab keys
init_arts();
TQVBoxLayout* vbox = new TQVBoxLayout( this );
vbox->setSpacing( 6 );
vbox->setMargin( 11 );
TQSplitter* splt = new TQSplitter( this );
actions_listview_widget = new Actions_listview_widget( splt );
tab_widget = new Tab_widget( splt );
vbox->addWidget( splt );
buttons_widget = new Main_buttons_widget( this );
vbox->addWidget( buttons_widget );
connect( actions_listview_widget, TQT_SIGNAL( current_action_changed()),
TQT_SLOT( listview_current_action_changed()));
connect( buttons_widget, TQT_SIGNAL( new_action_pressed()), TQT_SLOT( new_action()));
connect( buttons_widget, TQT_SIGNAL( new_action_group_pressed()), TQT_SLOT( new_action_group()));
connect( buttons_widget, TQT_SIGNAL( delete_action_pressed()), TQT_SLOT( delete_action()));
connect( buttons_widget, TQT_SIGNAL( global_settings_pressed()), TQT_SLOT( global_settings()));
// listview_current_action_changed(); // init
TDEAboutData* about = new TDEAboutData("kcmkhotkeys", I18N_NOOP("KHotKeys"), KHOTKEYS_VERSION,
0,
TDEAboutData::License_GPL,
I18N_NOOP("(c) 1999-2005 Lubos Lunak"), 0, 0);
about->addAuthor("Lubos Lunak", I18N_NOOP("Maintainer"), "l.lunak@kde.org");
setAboutData( about );
}
Module::~Module()
{
_current_action_data = NULL;
tab_widget->load_current_action(); // clear tab_widget
delete _actions_root;
module = NULL;
}
void Module::load()
{
actions_listview_widget->clear();
delete _actions_root;
settings.actions = NULL;
_current_action_data = NULL;
settings.read_settings( true );
_actions_root = settings.actions;
kdDebug( 1217 ) << "actions_root:" << _actions_root << endl;
actions_listview_widget->build_up();
tab_widget->load_current_action();
emit TDECModule::changed( false ); // HACK otherwise the module would be changed from the very beginning
}
void Module::save()
{
tab_widget->save_current_action_changes();
settings.actions = _actions_root;
settings.write_settings();
if( daemon_disabled())
{
TQByteArray data;
kapp->dcopClient()->send( "khotkeys*", "khotkeys", "quit()", data );
kdDebug( 1217 ) << "disabling khotkeys daemon" << endl;
}
else
{
if( !kapp->dcopClient()->isApplicationRegistered( "khotkeys" ))
{
kdDebug( 1217 ) << "launching new khotkeys daemon" << endl;
TDEApplication::tdeinitExec( "khotkeys" );
}
else
{
TQByteArray data;
kapp->dcopClient()->send( "khotkeys*", "khotkeys", "reread_configuration()", data );
kdDebug( 1217 ) << "telling khotkeys daemon to reread configuration" << endl;
}
}
emit TDECModule::changed( false );
}
TQString Module::quickHelp() const
{
return i18n( "" ); // TODO CHECKME
}
void Module::action_name_changed( const TQString& name_P )
{
current_action_data()->set_name( name_P );
actions_listview_widget->action_name_changed( name_P );
}
void Module::listview_current_action_changed()
{
// CHECKME tohle je trosku hack, aby se pri save zmenenych hodnot ve stare vybrane polozce
// zmenila data v te stare polozce a ne nove aktivni
listview_is_changed = true;
set_new_current_action( !deleting_action );
listview_is_changed = false;
}
void Module::set_new_current_action( bool save_old_P )
{
if( save_old_P )
tab_widget->save_current_action_changes();
_current_action_data = actions_listview_widget->current_action_data();
kdDebug( 1217 ) << "set_new_current_action : " << _current_action_data << endl;
tab_widget->load_current_action();
buttons_widget->enable_delete( current_action_data() != NULL );
}
// CHECKME volano jen z Tab_widget pro nastaveni zmenenych dat ( novy Action_data_base )
void Module::set_current_action_data( Action_data_base* data_P )
{
delete _current_action_data;
_current_action_data = data_P;
actions_listview_widget->set_action_data( data_P, listview_is_changed );
// tab_widget->load_current_action(); CHECKME asi neni treba
}
#if 0
}
#include <iostream>
#include <iomanip>
namespace KHotKeys {
void check_tree( Action_data_group* b, int lev_P = 0 )
{
using namespace std;
cerr << setw( lev_P ) << "" << b << ":Group:" << b->name().latin1() << ":" << b->parent() << endl;
for( Action_data_group::Iterator it = b->first_child();
it;
++it )
if( Action_data_group* g = dynamic_cast< Action_data_group* >( *it ))
check_tree( g, lev_P + 1 );
else
cerr << setw( lev_P + 1 ) << "" << (*it) << ":Action:" << (*it)->name().latin1() << ":" << (*it)->parent() << endl;
}
#endif
void Module::new_action()
{
tab_widget->save_current_action_changes();
// check_tree( actions_root());
Action_data_group* parent = current_action_data() != NULL
? dynamic_cast< Action_data_group* >( current_action_data()) : NULL;
if( parent == NULL )
{
if( current_action_data() != NULL )
parent = current_action_data()->parent();
else
parent = module->actions_root();
}
Action_data_base* item = new Generic_action_data( parent, i18n( "New Action" ), "",
new Trigger_list( "" ), new Condition_list( "", NULL ), new Action_list( "" ), true );
actions_listview_widget->new_action( item );
// check_tree( actions_root());
set_new_current_action( false );
}
// CHECKME spojit tyhle dve do jedne
void Module::new_action_group()
{
tab_widget->save_current_action_changes();
// check_tree( actions_root());
Action_data_group* parent = current_action_data() != NULL
? dynamic_cast< Action_data_group* >( current_action_data()) : NULL;
if( parent == NULL )
{
if( current_action_data() != NULL )
parent = current_action_data()->parent();
else
parent = module->actions_root();
}
Action_data_base* item = new Action_data_group( parent, i18n( "New Action Group" ), "",
new Condition_list( "", NULL ), Action_data_group::SYSTEM_NONE, true );
actions_listview_widget->new_action( item );
// check_tree( actions_root());
set_new_current_action( false );
}
void Module::delete_action()
{
delete _current_action_data;
_current_action_data = NULL;
deleting_action = true; // CHECKME zase tak trosku hack, jinak by se snazilo provest save
actions_listview_widget->delete_action(); // prave mazane polozky
deleting_action = false;
set_new_current_action( false );
}
void Module::global_settings()
{
actions_listview_widget->set_current_action( NULL );
set_new_current_action( true );
}
void Module::set_gestures_exclude( Windowdef_list* windows )
{
delete settings.gestures_exclude;
settings.gestures_exclude = windows;
}
void Module::import()
{
TQString file = KFileDialog::getOpenFileName( TQString::null, "*.khotkeys", topLevelWidget(),
i18n( "Select File with Actions to Be Imported" ));
if( file.isEmpty())
return;
KSimpleConfig cfg( file, true );
if( !settings.import( cfg, true ))
{
KMessageBox::error( topLevelWidget(),
i18n( "Import of the specified file failed. Most probably the file is not a valid "
"file with actions." ));
return;
}
actions_listview_widget->clear();
actions_listview_widget->build_up();
tab_widget->load_current_action();
emit TDECModule::changed( true );
}
void Module::changed()
{
emit TDECModule::changed( true );
}
void Module::init_arts()
{
#ifdef HAVE_ARTS
if( haveArts())
{
KLibrary* arts = KLibLoader::self()->library( "khotkeys_arts" );
if( arts == NULL )
kdDebug( 1217 ) << "Couldn't load khotkeys_arts:" << KLibLoader::self()->lastErrorMessage() << endl;
if( arts != NULL && VoiceRecorder::init( arts ))
; // ok
else
disableArts();
}
#endif
}
Module* module; // CHECKME
} // namespace KHotKeys
#include "kcmkhotkeys.moc"
|