2 Copyright (C) 1999-2001 Lubos Lunak <l.lunak@kde.org>
3 Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
22 #include <KDE/KConfigGroup>
24 #include <KDE/KProcess>
28 DBusAction::DBusAction( KConfigGroup
& cfg_P
, ActionData
* data_P
)
29 : Action( cfg_P
, data_P
)
31 _application
= cfg_P
.readEntry( "RemoteApp" );
32 _object
= cfg_P
.readEntry( "RemoteObj" );
33 _function
= cfg_P
.readEntry( "Call" );
34 _arguments
= cfg_P
.readEntry( "Arguments" );
38 DBusAction::DBusAction( ActionData
* data_P
, const QString
& app_P
, const QString
& obj_P
,
39 const QString
& call_P
, const QString
& args_P
)
40 : Action( data_P
), _application( app_P
), _object( obj_P
), _function( call_P
), _arguments( args_P
)
45 const QString
DBusAction::remote_application() const
51 const QString
DBusAction::remote_object() const
57 const QString
DBusAction::called_function() const
63 const QString
DBusAction::arguments() const
69 void DBusAction::cfg_write( KConfigGroup
& cfg_P
) const
71 base::cfg_write( cfg_P
);
72 cfg_P
.writeEntry( "Type", "DBUS" ); // overwrites value set in base::cfg_write()
73 cfg_P
.writeEntry( "RemoteApp", _application
);
74 cfg_P
.writeEntry( "RemoteObj", _object
);
75 cfg_P
.writeEntry( "Call", _function
);
76 cfg_P
.writeEntry( "Arguments", _arguments
);
80 void DBusAction::execute()
82 if( _application
.isEmpty() || _object
.isEmpty() || _function
.isEmpty())
84 QStringList args_list
;
85 QString args_str
= _arguments
;
86 while( !args_str
.isEmpty())
89 while( args_str
[ pos
] == ' ' )
91 if( args_str
[ pos
] == '\"' || args_str
[ pos
] == '\'' )
94 QChar sep
= args_str
[ pos
];
98 pos
< args_str
.length();
101 if( args_str
[ pos
] == '\\' )
106 if( !skip
&& args_str
[ pos
] == sep
)
109 val
+= args_str
[ pos
];
111 if( pos
>= args_str
.length())
114 args_str
= args_str
.mid( pos
);
115 args_list
.append( val
);
121 args_str
= args_str
.mid( pos
);
122 int nxt_pos
= args_str
.indexOf( ' ' );
123 args_list
.append( args_str
.left( nxt_pos
)); // should be ok if nxt_pos is -1
124 args_str
= nxt_pos
>= 0 ? args_str
.mid( nxt_pos
) : "";
127 kDebug() << "D-Bus call:" << _application
<< ":" << _object
<< ":" << _function
<< ":" << args_list
;
129 proc
<< "qdbus" << _application
<< _object
<< _function
<< args_list
;
130 proc
.startDetached();
134 const QString
DBusAction::description() const
136 return i18n( "D-Bus: " ) + remote_application() + "::" + remote_object() + "::"
141 Action
* DBusAction::copy( ActionData
* data_P
) const
143 return new DBusAction( data_P
, remote_application(), remote_object(),
144 called_function(), arguments());
147 void DBusAction::set_arguments( const QString
&arguments
)
149 _arguments
= arguments
;
153 void DBusAction::set_called_function( const QString
&function
)
155 _function
= function
;
159 void DBusAction::set_remote_application( const QString
&application
)
161 _application
= application
;
165 void DBusAction::set_remote_object( const QString
&object
)
171 } // namespace KHotKeys