~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to khotkeys/kcm_hotkeys/actions/dbus_action_widget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
 
2
 
 
3
   This library is free software; you can redistribute it and/or
 
4
   modify it under the terms of the GNU Library General Public
 
5
   License as published by the Free Software Foundation; either
 
6
   version 2 of the License, or (at your option) any later version.
 
7
 
 
8
   This library is distributed in the hope that it will be useful,
 
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
   Library General Public License for more details.
 
12
 
 
13
   You should have received a copy of the GNU Library General Public License
 
14
   along with this library; see the file COPYING.LIB.  If not, write to
 
15
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
16
   Boston, MA 02110-1301, USA.
 
17
*/
 
18
 
 
19
#include "dbus_action_widget.h"
 
20
 
 
21
#include <KDE/KMessageBox>
 
22
#include <KDE/KRun>
 
23
 
 
24
DbusActionWidget::DbusActionWidget(
 
25
    KHotKeys::DBusAction *action,
 
26
    QWidget *parent )
 
27
        : Base(action, parent)
 
28
    {
 
29
    ui.setupUi(this);
 
30
 
 
31
    connect(
 
32
        ui.application, SIGNAL(textChanged(QString)),
 
33
        _changedSignals, SLOT(map()) );
 
34
    _changedSignals->setMapping(ui.application, "application" );
 
35
    connect(
 
36
        ui.object, SIGNAL(textChanged(QString)),
 
37
        _changedSignals, SLOT(map()) );
 
38
    _changedSignals->setMapping(ui.object, "object" );
 
39
    connect(
 
40
        ui.function, SIGNAL(textChanged(QString)),
 
41
        _changedSignals, SLOT(map()) );
 
42
    _changedSignals->setMapping(ui.function, "function" );
 
43
    connect(
 
44
        ui.arguments, SIGNAL(textChanged(QString)),
 
45
        _changedSignals, SLOT(map()) );
 
46
    _changedSignals->setMapping(ui.arguments, "arguments" );
 
47
 
 
48
    connect(
 
49
        ui.launchButton, SIGNAL(clicked()),
 
50
        this, SLOT(launchDbusBrowser()) );
 
51
    connect(
 
52
        ui.execButton, SIGNAL(clicked()),
 
53
        this, SLOT(execCommand()) );
 
54
    }
 
55
 
 
56
 
 
57
DbusActionWidget::~DbusActionWidget()
 
58
    {
 
59
    }
 
60
 
 
61
 
 
62
KHotKeys::DBusAction *DbusActionWidget::action()
 
63
    {
 
64
    return static_cast<KHotKeys::DBusAction*>(_action);
 
65
    }
 
66
 
 
67
 
 
68
const KHotKeys::DBusAction *DbusActionWidget::action() const
 
69
    {
 
70
    return static_cast<const KHotKeys::DBusAction*>(_action);
 
71
    }
 
72
 
 
73
 
 
74
void DbusActionWidget::doCopyFromObject()
 
75
    {
 
76
    Q_ASSERT(action());
 
77
    ui.application->setText( action()->remote_application() );
 
78
    ui.object->setText( action()->remote_object() );
 
79
    ui.function->setText( action()->called_function() );
 
80
    ui.arguments->setText( action()->arguments() );
 
81
    }
 
82
 
 
83
 
 
84
void DbusActionWidget::doCopyToObject()
 
85
    {
 
86
    Q_ASSERT(action());
 
87
    action()->set_remote_application( ui.application->text() );
 
88
    action()->set_remote_object( ui.object->text() );
 
89
    action()->set_called_function( ui.function->text() );
 
90
    action()->set_arguments( ui.arguments->text() );
 
91
    }
 
92
 
 
93
 
 
94
void DbusActionWidget::execCommand() const
 
95
    {
 
96
    KHotKeys::DBusAction action(
 
97
        0,
 
98
        ui.application->text(),
 
99
        ui.object->text(),
 
100
        ui.function->text(),
 
101
        ui.arguments->text() );
 
102
 
 
103
    // TODO: Error handling
 
104
    action.execute();
 
105
    }
 
106
 
 
107
 
 
108
bool DbusActionWidget::isChanged() const
 
109
    {
 
110
    Q_ASSERT(action());
 
111
    return ui.application->text() != action()->remote_application()
 
112
        || ui.object->text()      != action()->remote_object()
 
113
        || ui.function->text()    != action()->called_function()
 
114
        || ui.arguments->text()   != action()->arguments();
 
115
    }
 
116
 
 
117
 
 
118
void DbusActionWidget::launchDbusBrowser() const
 
119
    {
 
120
    if( KRun::runCommand( "qdbusviewer", window()) == 0 )
 
121
        {
 
122
        KMessageBox::sorry( window(), i18n( "Failed to run qdbusviewer" ));
 
123
        }
 
124
    }
 
125
 
 
126
 
 
127
#include "moc_dbus_action_widget.cpp"