diff --git a/khotkeys/data/Makefile.am b/khotkeys/data/Makefile.am index eed4af5ba8..543f9309bb 100644 --- a/khotkeys/data/Makefile.am +++ b/khotkeys/data/Makefile.am @@ -1,7 +1,7 @@ -khotkeys_data_DATA = kde32b1.khotkeys konqueror_gestures_kde321.khotkeys +khotkeys_data_DATA = kde32b1.khotkeys konqueror_gestures_kde321.khotkeys printscreen.khotkeys khotkeys_datadir = $(kde_datadir)/khotkeys -khotkeys_update_DATA = khotkeys_32b1_update.upd konqueror_gestures_kde321_update.upd +khotkeys_update_DATA = khotkeys_32b1_update.upd konqueror_gestures_kde321_update.upd khotkeys_printscreen.upd khotkeys_updatedir = $(kde_datadir)/kconf_update EXTRA_DIST = $(khotkeys_data_DATA) $(khotkeys_update_DATA) diff --git a/khotkeys/data/khotkeys_printscreen.upd b/khotkeys/data/khotkeys_printscreen.upd new file mode 100644 index 0000000000..145a0c06a8 --- /dev/null +++ b/khotkeys/data/khotkeys_printscreen.upd @@ -0,0 +1,8 @@ +Id=printscreen +# the file is intentionally a dummy, as the binary will update khotkeysrc, +# the khotkeys_update will just remember it has been done +File=khotkeys_update +Group=Dummy +Options=overwrite +ScriptArguments=--id printscreen +Script=khotkeys_update diff --git a/khotkeys/data/printscreen.khotkeys b/khotkeys/data/printscreen.khotkeys new file mode 100644 index 0000000000..acb8d73676 --- /dev/null +++ b/khotkeys/data/printscreen.khotkeys @@ -0,0 +1,44 @@ +[Data] +DataCount=1 + +[Data_1] +Comment=This group contains actions that are set up by default.\n +DataCount=1 +Enabled=true +Name=Preset Actions +SystemGroup=0 +Type=ACTION_DATA_GROUP +AllowMerge=true + +[Data_1Conditions] +Comment= +ConditionsCount=0 + +[Data_1_1] +Comment=Launches KSnapShot when PrintScrn is pressed.\n +Enabled=true +Name=PrintScreen +Type=COMMAND_URL_SHORTCUT_ACTION_DATA + +[Data_1_1Actions] +ActionsCount=1 + +[Data_1_1Actions0] +CommandURL=ksnapshot +Type=COMMAND_URL + +[Data_1_1Conditions] +Comment= +ConditionsCount=0 + +[Data_1_1Triggers] +Comment=Simple_action +TriggersCount=1 + +[Data_1_1Triggers0] +Key=Print +Type=SHORTCUT + +[Main] +Version=2 +ImportId=printscreen diff --git a/khotkeys/shared/action_data.cpp b/khotkeys/shared/action_data.cpp index da3ff8ae71..8af72cb9da 100644 --- a/khotkeys/shared/action_data.cpp +++ b/khotkeys/shared/action_data.cpp @@ -1,403 +1,418 @@ /**************************************************************************** KHotKeys Copyright (C) 1999-2001 Lubos Lunak Distributed under the terms of the GNU General Public License version 2. ****************************************************************************/ #define _ACTION_DATA_CPP_ #ifdef HAVE_CONFIG_H #include #endif #include "action_data.h" #include #include "actions.h" namespace KHotKeys { // Action_data_base Action_data_base::Action_data_base( Action_data_group* parent_P, const QString& name_P, const QString& comment_P, Condition_list* conditions_P, bool enabled_P ) : _parent( parent_P ), _conditions( conditions_P ), _name( name_P ), _comment( comment_P ), _enabled( enabled_P ) { if( parent()) parent()->add_child( this ); if( _conditions != NULL ) _conditions->set_data( this ); } Action_data_base::Action_data_base( KConfig& cfg_P, Action_data_group* parent_P ) : _parent( parent_P ) { QString save_cfg_group = cfg_P.group(); _name = cfg_P.readEntry( "Name" ); _comment = cfg_P.readEntry( "Comment" ); _enabled = cfg_P.readEntry( "Enabled", QVariant(true )).toBool(); cfg_P.setGroup( save_cfg_group + "Conditions" ); _conditions = new Condition_list( cfg_P, this ); cfg_P.setGroup( save_cfg_group ); if( parent()) parent()->add_child( this ); } Action_data_base::~Action_data_base() { // kDebug( 1217 ) << "~Action_data_base() :" << this << endl; if( parent()) parent()->remove_child( this ); delete _conditions; } void Action_data_base::cfg_write( KConfig& cfg_P ) const { cfg_P.writeEntry( "Type", "ERROR" ); // derived classes should call with their type cfg_P.writeEntry( "Name", name()); cfg_P.writeEntry( "Comment", comment()); cfg_P.writeEntry( "Enabled", enabled( true )); QString save_cfg_group = cfg_P.group(); cfg_P.setGroup( save_cfg_group + "Conditions" ); assert( conditions() != NULL ); conditions()->cfg_write( cfg_P ); cfg_P.setGroup( save_cfg_group ); } Action_data_base* Action_data_base::create_cfg_read( KConfig& cfg_P, Action_data_group* parent_P ) { QString type = cfg_P.readEntry( "Type" ); if( type == "ACTION_DATA_GROUP" ) + { + if( cfg_P.readBoolEntry( "AllowMerge", false )) + { + for( Action_data_group::Iterator it = parent_P->first_child(); + it; + ++it ) + { + if( Action_data_group* existing = dynamic_cast< Action_data_group* >( *it )) + { + if( cfg_P.readEntry( "Name" ) == existing->name()) + return existing; + } + } + } return new Action_data_group( cfg_P, parent_P ); + } if( type == "GENERIC_ACTION_DATA" ) return new Generic_action_data( cfg_P, parent_P ); if( type == "COMMAND_URL_SHORTCUT_ACTION_DATA" ) return new Command_url_shortcut_action_data( cfg_P, parent_P ); if( type == "MENUENTRY_SHORTCUT_ACTION_DATA" ) return new Menuentry_shortcut_action_data( cfg_P, parent_P ); if( type == "DCOP_SHORTCUT_ACTION_DATA" ) return new Dcop_shortcut_action_data( cfg_P, parent_P ); if( type == "KEYBOARD_INPUT_SHORTCUT_ACTION_DATA" ) return new Keyboard_input_shortcut_action_data( cfg_P, parent_P ); if( type == "KEYBOARD_INPUT_GESTURE_ACTION_DATA" ) return new Keyboard_input_gesture_action_data( cfg_P, parent_P ); if( type == "ACTIVATE_WINDOW_SHORTCUT_ACTION_DATA" ) return new Activate_window_shortcut_action_data( cfg_P, parent_P ); kWarning( 1217 ) << "Unknown Action_data_base type read from cfg file\n"; return NULL; } bool Action_data_base::cfg_is_enabled( KConfig& cfg_P ) { return cfg_P.readEntry( "Enabled", QVariant(true )).toBool(); } void Action_data_base::reparent( Action_data_group* new_parent_P ) { if( parent()) parent()->remove_child( this ); _parent = new_parent_P; if( parent()) parent()->add_child( this ); } bool Action_data_base::enabled( bool ignore_group_P ) const { if( ignore_group_P ) return _enabled; else return _enabled && ( parent() == NULL || parent()->enabled( false )); } bool Action_data_base::conditions_match() const { return ( conditions() ? conditions()->match() : true ) && ( parent() ? parent()->conditions_match() : true ); } // Action_data_group Action_data_group::Action_data_group( KConfig& cfg_P, Action_data_group* parent_P ) : Action_data_base( cfg_P, parent_P ) { unsigned int system_group_tmp = cfg_P.readEntry( "SystemGroup", 0 ); if( system_group_tmp >= SYSTEM_MAX ) system_group_tmp = 0; _system_group = static_cast< system_group_t >( system_group_tmp ); } void Action_data_group::cfg_write( KConfig& cfg_P ) const { Action_data_base::cfg_write( cfg_P ); cfg_P.writeEntry( "SystemGroup", int(system_group())); cfg_P.writeEntry( "Type", "ACTION_DATA_GROUP" ); } void Action_data_group::update_triggers() { for( Action_data_group::Iterator it = first_child(); it; ++it ) ( *it )->update_triggers(); } // Action_data Action_data::Action_data( KConfig& cfg_P, Action_data_group* parent_P ) : Action_data_base( cfg_P, parent_P ) { QString save_cfg_group = cfg_P.group(); cfg_P.setGroup( save_cfg_group + "Triggers" ); _triggers = new Trigger_list( cfg_P, this ); cfg_P.setGroup( save_cfg_group + "Actions" ); _actions = new Action_list( cfg_P, this ); cfg_P.setGroup( save_cfg_group ); } Action_data::~Action_data() { // kDebug( 1217 ) << "~Action_data" << this << endl; delete _triggers; delete _actions; // CHECKME jeste remove z parenta ? } void Action_data::cfg_write( KConfig& cfg_P ) const { Action_data_base::cfg_write( cfg_P ); QString save_cfg_group = cfg_P.group(); cfg_P.setGroup( save_cfg_group + "Triggers" ); triggers()->cfg_write( cfg_P ); cfg_P.setGroup( save_cfg_group + "Actions" ); actions()->cfg_write( cfg_P ); cfg_P.setGroup( save_cfg_group ); } void Action_data::execute() { for( Action_list::Iterator it( *_actions ); it; ++it ) it.current()->execute(); // CHECKME nebo nejak zpozdeni ? } void Action_data::add_trigger( Trigger* trigger_P ) { _triggers->append( trigger_P ); } void Action_data::add_triggers( Trigger_list* triggers_P ) { for( Trigger_list::Iterator it = *triggers_P; it; ++it ) _triggers->append( *it ); triggers_P->setAutoDelete( false ); delete triggers_P; } void Action_data::set_triggers( Trigger_list* triggers_P ) { assert( _triggers == NULL ); _triggers = triggers_P; } void Action_data::add_action( Action* action_P, Action* after_P ) { int index = 0; for( Action_list::Iterator it = *_actions; it; ++it ) { ++index; if( *it == after_P ) break; } _actions->insert( index, action_P ); } void Action_data::add_actions( Action_list* actions_P, Action* after_P ) { int index = 0; for( Action_list::Iterator it = *_actions; it; ++it ) { ++index; if( *it == after_P ) break; } for( Action_list::Iterator it = *actions_P; it; ++it ) _actions->insert( index++, *it ); actions_P->setAutoDelete( false ); delete actions_P; } void Action_data::set_actions( Action_list* actions_P ) { assert( _actions == NULL ); _actions = actions_P; } void Action_data::update_triggers() { bool activate = conditions_match() && enabled( false ); kDebug( 1217 ) << "Update triggers: " << name() << ":" << activate << endl; for( Trigger_list::Iterator it = ( *triggers()); it; ++it ) ( *it )->activate( activate ); } // Generic_action_data void Generic_action_data::cfg_write( KConfig& cfg_P ) const { base::cfg_write( cfg_P ); cfg_P.writeEntry( "Type", "GENERIC_ACTION_DATA" ); } // Simple_action_data template< typename T, typename A > void Simple_action_data< T, A >::set_action( A* action_P ) { Action_list* tmp = new Action_list( "Simple_action_data" ); tmp->append( action_P ); set_actions( tmp ); } template< typename T, typename A > void Simple_action_data< T, A >::set_trigger( T* trigger_P ) { Trigger_list* tmp = new Trigger_list( "Simple_action" ); tmp->append( trigger_P ); set_triggers( tmp ); } template< typename T, typename A > const A* Simple_action_data< T, A >::action() const { if( actions() == NULL || actions()->count() == 0 ) // CHECKME tohle poradne zkontrolovat return NULL; return static_cast< A* >( const_cast< Action_list* >( actions())->first()); } template< typename T, typename A > const T* Simple_action_data< T, A >::trigger() const { if( triggers() == NULL || triggers()->count() == 0 ) // CHECKME tohle poradne zkontrolovat return NULL; return static_cast< T* >( const_cast< Trigger_list* >( triggers())->first()); } // Command_url_shortcut_action_data Command_url_shortcut_action_data::Command_url_shortcut_action_data( Action_data_group* parent_P, const QString& name_P, const QString& comment_P, const KShortcut& shortcut_P, const QString& command_url_P, bool enabled_P ) : Simple_action_data< Shortcut_trigger, Command_url_action >( parent_P, name_P, comment_P, enabled_P ) { set_action( new Command_url_action( this, command_url_P )); set_trigger( new Shortcut_trigger( this, shortcut_P )); } template<> void Simple_action_data< Shortcut_trigger, Command_url_action > ::cfg_write( KConfig& cfg_P ) const { base::cfg_write( cfg_P ); cfg_P.writeEntry( "Type", "COMMAND_URL_SHORTCUT_ACTION_DATA" ); } template class Simple_action_data< Shortcut_trigger, Command_url_action >; // Menuentry_shortcut_action_data Menuentry_shortcut_action_data::Menuentry_shortcut_action_data( Action_data_group* parent_P, const QString& name_P, const QString& comment_P, const KShortcut& shortcut_P, const QString& menuentry_P, bool enabled_P ) : Simple_action_data< Shortcut_trigger, Menuentry_action >( parent_P, name_P, comment_P, enabled_P ) { set_action( new Menuentry_action( this, menuentry_P )); set_trigger( new Shortcut_trigger( this, shortcut_P )); } template<> void Simple_action_data< Shortcut_trigger, Menuentry_action > ::cfg_write( KConfig& cfg_P ) const { base::cfg_write( cfg_P ); cfg_P.writeEntry( "Type", "MENUENTRY_SHORTCUT_ACTION_DATA" ); } template class Simple_action_data< Shortcut_trigger, Menuentry_action >; // Dcop_shortcut_action_data template<> void Simple_action_data< Shortcut_trigger, Dcop_action > ::cfg_write( KConfig& cfg_P ) const { base::cfg_write( cfg_P ); cfg_P.writeEntry( "Type", "DCOP_SHORTCUT_ACTION_DATA" ); } template class Simple_action_data< Shortcut_trigger, Dcop_action >; // Keyboard_input_shortcut_action_data template<> void Simple_action_data< Shortcut_trigger, Keyboard_input_action > ::cfg_write( KConfig& cfg_P ) const { base::cfg_write( cfg_P ); cfg_P.writeEntry( "Type", "KEYBOARD_INPUT_SHORTCUT_ACTION_DATA" ); } template class Simple_action_data< Shortcut_trigger, Keyboard_input_action >; // Activate_window_shortcut_action_data template<> void Simple_action_data< Shortcut_trigger, Activate_window_action > ::cfg_write( KConfig& cfg_P ) const { base::cfg_write( cfg_P ); cfg_P.writeEntry( "Type", "ACTIVATE_WINDOW_SHORTCUT_ACTION_DATA" ); } template class Simple_action_data< Shortcut_trigger, Activate_window_action >; // Keyboard_input_gesture_action_data void Keyboard_input_gesture_action_data::set_action( Keyboard_input_action* action_P ) { Action_list* tmp = new Action_list( "Keyboard_input_gesture_action_data" ); tmp->append( action_P ); set_actions( tmp ); } const Keyboard_input_action* Keyboard_input_gesture_action_data::action() const { if( actions() == NULL ) // CHECKME tohle poradne zkontrolovat return NULL; return static_cast< Keyboard_input_action* >( const_cast< Action_list* >( actions())->first()); } void Keyboard_input_gesture_action_data::cfg_write( KConfig& cfg_P ) const { base::cfg_write( cfg_P ); cfg_P.writeEntry( "Type", "KEYBOARD_INPUT_GESTURE_ACTION_DATA" ); } } // namespace KHotKeys diff --git a/khotkeys/update/update.cpp b/khotkeys/update/update.cpp index 341c64a48a..1d1cb792ac 100644 --- a/khotkeys/update/update.cpp +++ b/khotkeys/update/update.cpp @@ -1,60 +1,62 @@ /**************************************************************************** KHotKeys Copyright (C) 2003 Lubos Lunak Distributed under the terms of the GNU General Public License version 2. ****************************************************************************/ #define _UPDATE_CPP_ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include +#include #include using namespace KHotKeys; static const KCmdLineOptions options[] = { // no need for I18N_NOOP(), this is not supposed to be used directly { "id ", "Id of the script to add to khotkeysrc.", 0 }, KCmdLineLastOption }; int main( int argc, char* argv[] ) { KCmdLineArgs::init( argc, argv, "khotkeys_update", "KHotKeys Update", "KHotKeys update utility", "1.0" ); KCmdLineArgs::addCmdLineOptions( options ); - KApplication::disableAutoDcopRegistration(); KApplication app( true ); // X11 connection is necessary for KKey* stuff :-/ KCmdLineArgs* args = KCmdLineArgs::parsedArgs(); QByteArray id = args->getOption( "id" ); QString file = locate( "data", "khotkeys/" + id + ".khotkeys" ); if( file.isEmpty()) { kWarning() << "File " << id << " not found!" << endl; return 1; } init_global_data( false, &app ); Settings settings; settings.read_settings( true ); KConfig cfg( file, true ); if( !settings.import( cfg, false )) { kWarning() << "Import of " << id << " failed!" << endl; return 2; } settings.write_settings(); + QByteArray data; + kapp->dcopClient()->send( "khotkeys*", "khotkeys", "reread_configuration()", data ); return 0; }