1 /****************************************************************************
5 Copyright (C) 1999-2001 Lubos Lunak <l.lunak@kde.org>
7 Distributed under the terms of the GNU General Public License version 2.
9 ****************************************************************************/
11 #define _ACTION_LIST_WIDGET_CPP_
15 #include "action_list_widget.h"
19 #include <QPushButton>
20 #include <Qt3Support/Q3Header>
26 #include <khlistview.h>
28 #include "command_url_widget.h"
29 #include "menuentry_widget.h"
30 #include "dbus_widget.h"
31 #include "keyboard_input_widget.h"
32 #include "activate_window_widget.h"
33 #include "kcmkhotkeys.h"
40 Action_list_widget::Action_list_widget( QWidget
* parent_P
, const char* name_P
)
41 : Action_list_widget_ui( parent_P
), selected_item( NULL
)
43 setObjectName(name_P
);
44 QMenu
* popup
= new QMenu
; // CHECKME looks like setting parent doesn't work
45 QAction
*action
= popup
->addAction( i18n( "Command/URL..." ) );
46 action
->setData( TYPE_COMMAND_URL_ACTION
);
47 action
= popup
->addAction( i18n( "K-Menu Entry..." ) );
48 action
->setData( TYPE_MENUENTRY_ACTION
);
49 action
= popup
->addAction( i18n( "D-Bus Call..." ) );
50 action
->setData( TYPE_DBUS_ACTION
);
51 action
= popup
->addAction( i18n( "Keyboard Input..." ) );
52 action
->setData( TYPE_KEYBOARD_INPUT_ACTION
);
53 action
= popup
->addAction( i18n( "Activate Window..." ) );
54 action
->setData( TYPE_ACTIVATE_WINDOW_ACTION
);
55 connect( popup
, SIGNAL( triggered( QAction
* )), SLOT( new_selected( QAction
* )));
56 new_button
->setMenu( popup
);
57 actions_listview
->header()->hide();
58 actions_listview
->addColumn( "" );
59 actions_listview
->setSorting( -1 );
60 actions_listview
->setForceSelect( true );
61 copy_button
->setEnabled( false );
62 modify_button
->setEnabled( false );
63 delete_button
->setEnabled( false );
65 connect( actions_listview
, SIGNAL( doubleClicked ( Q3ListViewItem
*, const QPoint
&, int ) ),
66 this, SLOT( modify_pressed() ) );
67 connect( copy_button
,SIGNAL(clicked()),this,SLOT(copy_pressed()));
68 connect(modify_button
,SIGNAL(clicked()),this,SLOT(modify_pressed()));
69 connect(delete_button
,SIGNAL(clicked()),this,SLOT(delete_pressed()));
70 connect(actions_listview
,SIGNAL(current_changed(Q3ListViewItem
*)),this,SLOT(current_changed(Q3ListViewItem
*)));
72 // KHotKeys::Module::changed()
73 connect( new_button
, SIGNAL( clicked()),
74 module
, SLOT( changed()));
75 connect( copy_button
, SIGNAL( clicked()),
76 module
, SLOT( changed()));
77 connect( modify_button
, SIGNAL( clicked()),
78 module
, SLOT( changed()));
79 connect( delete_button
, SIGNAL( clicked()),
80 module
, SLOT( changed()));
81 connect( comment_lineedit
, SIGNAL( textChanged( const QString
& )),
82 module
, SLOT( changed()));
85 Action_list_widget::~Action_list_widget()
87 delete new_button
->menu();
90 void Action_list_widget::clear_data()
92 comment_lineedit
->clear();
93 actions_listview
->clear();
96 void Action_list_widget::set_data( const Action_list
* data_P
)
103 comment_lineedit
->setText( data_P
->comment());
104 Action_list_item
* after
= NULL
;
105 actions_listview
->clear();
106 for( Action_list::Iterator
it( *data_P
);
109 after
= create_listview_item( *it
, actions_listview
, NULL
, after
, true );
112 Action_list
* Action_list_widget::get_data( Action_data
* data_P
) const
114 // CHECKME TODO hmm, tady to bude chtit asi i children :(
115 Action_list
* list
= new Action_list( comment_lineedit
->text());
116 for( Q3ListViewItem
* pos
= actions_listview
->firstChild();
118 pos
= pos
->nextSibling())
119 list
->append( static_cast< Action_list_item
* >( pos
)->action()->copy( data_P
));
123 void Action_list_widget::new_selected( QAction
*action
)
125 Action_dialog
* dlg
= NULL
;
127 int type_P
= action
->data().toInt();
130 case TYPE_COMMAND_URL_ACTION
: // Command_url_action_dialog
131 dlg
= new Command_url_action_dialog( NULL
);
133 case TYPE_MENUENTRY_ACTION
: // Menuentry_action_dialog
134 dlg
= new Menuentry_action_dialog( NULL
);
136 case TYPE_DBUS_ACTION
: // Dbus_action_dialog
137 dlg
= new Dbus_action_dialog( NULL
);
139 case TYPE_KEYBOARD_INPUT_ACTION
: // Keyboard_input_action_dialog
140 dlg
= new Keyboard_input_action_dialog( NULL
);
142 case TYPE_ACTIVATE_WINDOW_ACTION
: // Activate_window_action_dialog
143 dlg
= new Activate_window_action_dialog( NULL
);
150 Action
* action
= dlg
->edit_action();
152 actions_listview
->setSelected( create_listview_item( action
, actions_listview
,
153 NULL
, selected_item
, false ), true );
154 // CHECKME tady pak jeste spravne vnoreni, kdyz bude skupina
159 void Action_list_widget::copy_pressed()
161 actions_listview
->setSelected( create_listview_item( selected_item
->action(),
162 selected_item
->parent() ? NULL
: actions_listview
, selected_item
->parent(),
163 selected_item
, true ), true );
166 void Action_list_widget::delete_pressed()
168 delete selected_item
; // CHECKME snad vyvola signaly pro enable()
171 void Action_list_widget::modify_pressed()
173 edit_listview_item( selected_item
);
176 void Action_list_widget::current_changed( Q3ListViewItem
* item_P
)
178 // if( item_P == selected_item )
180 selected_item
= static_cast< Action_list_item
* >( item_P
);
181 // actions_listview->setSelected( item_P, true );
182 copy_button
->setEnabled( item_P
!= NULL
);
183 modify_button
->setEnabled( item_P
!= NULL
);
184 delete_button
->setEnabled( item_P
!= NULL
);
187 Action_list_item
* Action_list_widget::create_listview_item( Action
* action_P
,
188 Q3ListView
* parent1_P
, Q3ListViewItem
* parent2_P
, Q3ListViewItem
* after_P
, bool copy_P
)
190 Action
* new_win
= copy_P
? action_P
->copy( NULL
) : action_P
;
191 // CHECKME uz by nemelo byt treba
192 /* if( after_P == NULL )
194 if( parent1_P == NULL )
195 return new Action_list_item( parent2_P, new_win );
197 return new Action_list_item( parent1_P, new_win );
201 if( parent1_P
== NULL
)
202 return new Action_list_item( parent2_P
, after_P
, new_win
);
204 return new Action_list_item( parent1_P
, after_P
, new_win
);
208 void Action_list_widget::edit_listview_item( Action_list_item
* item_P
)
210 Action_dialog
* dlg
= NULL
;
211 if( Command_url_action
* action
= dynamic_cast< Command_url_action
* >( item_P
->action()))
212 dlg
= new Command_url_action_dialog( action
);
213 else if( Menuentry_action
* action
= dynamic_cast< Menuentry_action
* >( item_P
->action()))
214 dlg
= new Menuentry_action_dialog( action
);
215 else if( Dbus_action
* action
= dynamic_cast< Dbus_action
* >( item_P
->action()))
216 dlg
= new Dbus_action_dialog( action
);
217 else if( Keyboard_input_action
* action
218 = dynamic_cast< Keyboard_input_action
* >( item_P
->action()))
219 dlg
= new Keyboard_input_action_dialog( action
);
220 else if( Activate_window_action
* action
221 = dynamic_cast< Activate_window_action
* >( item_P
->action()))
222 dlg
= new Activate_window_action_dialog( action
);
223 else // CHECKME TODO pridat dalsi
225 Action
* new_action
= dlg
->edit_action();
226 if( new_action
!= NULL
)
228 item_P
->set_action( new_action
);
229 item_P
->widthChanged( 0 );
230 actions_listview
->repaintItem( item_P
);
237 QString
Action_list_item::text( int column_P
) const
239 return column_P
== 0 ? action()->description() : QString();
242 Action_list_item::~Action_list_item()
247 // Command_url_action_dialog
249 Command_url_action_dialog::Command_url_action_dialog( Command_url_action
* action_P
)
250 : KDialog( 0 ), action( NULL
) // CHECKME caption
253 setButtons( Ok
| Cancel
);
254 widget
= new Command_url_widget( this );
255 widget
->set_data( action_P
);
256 setMainWidget( widget
);
259 Action
* Command_url_action_dialog::edit_action()
265 void Command_url_action_dialog::accept()
268 action
= widget
->get_data( NULL
); // CHECKME NULL ?
271 // Menuentry_action_dialog
273 Menuentry_action_dialog::Menuentry_action_dialog( Menuentry_action
* action_P
)
274 : KDialog( 0 ), action( NULL
) // CHECKME caption
277 setButtons( Ok
| Cancel
);
278 widget
= new Menuentry_widget( this );
279 widget
->set_data( action_P
);
280 setMainWidget( widget
);
283 Action
* Menuentry_action_dialog::edit_action()
289 void Menuentry_action_dialog::accept()
292 action
= widget
->get_data( NULL
); // CHECKME NULL ?
295 // Dbus_action_dialog
297 Dbus_action_dialog::Dbus_action_dialog( Dbus_action
* action_P
)
298 : KDialog( 0 ), action( NULL
) // CHECKME caption
301 setButtons( Ok
| Cancel
);
302 widget
= new Dbus_widget( this );
303 widget
->set_data( action_P
);
304 setMainWidget( widget
);
307 Action
* Dbus_action_dialog::edit_action()
313 void Dbus_action_dialog::accept()
316 action
= widget
->get_data( NULL
); // CHECKME NULL ?
319 // Keyboard_input_action_dialog
321 Keyboard_input_action_dialog::Keyboard_input_action_dialog( Keyboard_input_action
* action_P
)
322 : KDialog( 0 ), action( NULL
) // CHECKME caption
325 setButtons( Ok
| Cancel
);
326 widget
= new Keyboard_input_widget( this );
327 widget
->set_data( action_P
);
328 setMainWidget( widget
);
331 Action
* Keyboard_input_action_dialog::edit_action()
337 void Keyboard_input_action_dialog::accept()
340 action
= widget
->get_data( NULL
); // CHECKME NULL ?
343 // Activate_window_action_dialog
345 Activate_window_action_dialog::Activate_window_action_dialog( Activate_window_action
* action_P
)
346 : KDialog( 0 ), action( NULL
) // CHECKME caption
349 setButtons( Ok
| Cancel
);
350 widget
= new Activate_window_widget( this );
351 widget
->set_data( action_P
? action_P
->window() : NULL
);
352 setMainWidget( widget
);
355 Action
* Activate_window_action_dialog::edit_action()
361 void Activate_window_action_dialog::accept()
364 action
= new Activate_window_action( NULL
, widget
->get_data()); // CHECKME NULL ?
367 } // namespace KHotKeys
369 #include "action_list_widget.moc"