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

« back to all changes in this revision

Viewing changes to khotkeys/kcm_hotkeys/simple_action_data_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
/*
 
2
   Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
 
3
 
 
4
   This library is free software; you can redistribute it and/or
 
5
   modify it under the terms of the GNU Library General Public
 
6
   License as published by the Free Software Foundation; either
 
7
   version 2 of the License, or (at your option) any later version.
 
8
 
 
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.
 
13
 
 
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.
 
18
*/
 
19
 
 
20
#include "simple_action_data_widget.h"
 
21
 
 
22
#include "actions/command_url_action_widget.h"
 
23
#include "actions/dbus_action_widget.h"
 
24
#include "actions/menuentry_action_widget.h"
 
25
#include "actions/keyboard_input_action_widget.h"
 
26
#include "triggers/shortcut_trigger_widget.h"
 
27
#include "triggers/window_trigger_widget.h"
 
28
#include "triggers/gesture_trigger_widget.h"
 
29
 
 
30
#include <KDE/KDebug>
 
31
 
 
32
 
 
33
SimpleActionDataWidget::SimpleActionDataWidget( QWidget *parent )
 
34
        : HotkeysWidgetBase( parent )
 
35
         ,currentTrigger(NULL)
 
36
         ,currentAction(NULL)
 
37
    {}
 
38
 
 
39
 
 
40
SimpleActionDataWidget::~SimpleActionDataWidget()
 
41
    {
 
42
    delete currentTrigger;
 
43
    delete currentAction;
 
44
    }
 
45
 
 
46
 
 
47
bool SimpleActionDataWidget::isChanged() const
 
48
    {
 
49
    return ( currentTrigger && currentTrigger->isChanged() )
 
50
        || ( currentAction && currentAction->isChanged() )
 
51
        || Base::isChanged();
 
52
    }
 
53
 
 
54
 
 
55
void SimpleActionDataWidget::doCopyFromObject()
 
56
    {
 
57
    Base::doCopyFromObject();
 
58
 
 
59
    if (currentTrigger)
 
60
        {
 
61
        currentTrigger->copyFromObject();
 
62
        }
 
63
 
 
64
    if (currentAction)
 
65
        {
 
66
        currentAction->copyFromObject();
 
67
        }
 
68
 
 
69
    }
 
70
 
 
71
 
 
72
void SimpleActionDataWidget::doCopyToObject()
 
73
    {
 
74
    Base::doCopyToObject();
 
75
 
 
76
    if (currentTrigger)
 
77
        {
 
78
        currentTrigger->copyToObject();
 
79
        }
 
80
 
 
81
    if (currentAction)
 
82
        {
 
83
        currentAction->copyToObject();
 
84
        }
 
85
    }
 
86
 
 
87
 
 
88
void SimpleActionDataWidget::setActionData( KHotKeys::SimpleActionData* pData )
 
89
    {
 
90
    _data = pData;
 
91
 
 
92
    // Now go and work on the trigger
 
93
    delete currentTrigger; currentTrigger = NULL;
 
94
 
 
95
    if ( KHotKeys::Trigger *trg = data()->trigger() )
 
96
        {
 
97
        switch ( trg->type() )
 
98
            {
 
99
            case KHotKeys::Trigger::ShortcutTriggerType:
 
100
                kDebug() << "1";
 
101
                currentTrigger = new ShortcutTriggerWidget( static_cast<KHotKeys::ShortcutTrigger*>(trg) );
 
102
                break;
 
103
 
 
104
            case KHotKeys::Trigger::WindowTriggerType:
 
105
                kDebug() << "2";
 
106
                currentTrigger = new WindowTriggerWidget( static_cast<KHotKeys::WindowTrigger*>(trg) );
 
107
                break;
 
108
 
 
109
            case KHotKeys::Trigger::GestureTriggerType:
 
110
                kDebug() << "3";
 
111
                currentTrigger = new GestureTriggerWidget( static_cast<KHotKeys::GestureTrigger*>(trg) );
 
112
                break;
 
113
 
 
114
            default:
 
115
                kDebug() << "Unknown trigger type";
 
116
            };
 
117
        }
 
118
 
 
119
    if (currentTrigger )
 
120
        {
 
121
        connect(
 
122
            currentTrigger, SIGNAL(changed(bool)),
 
123
            this, SLOT(slotChanged() ));
 
124
        extend(currentTrigger, i18n("Trigger"));
 
125
        }
 
126
 
 
127
    // Now go and work on the action
 
128
    delete currentAction; currentAction = NULL;
 
129
 
 
130
    if ( KHotKeys::Action *act = data()->action() )
 
131
        {
 
132
        switch ( act->type() )
 
133
            {
 
134
            case KHotKeys::Action::MenuEntryActionType:
 
135
                currentAction = new MenuentryActionWidget( static_cast<KHotKeys::MenuEntryAction*>(act) );
 
136
                break;
 
137
 
 
138
            case KHotKeys::Action::DBusActionType:
 
139
                currentAction = new DbusActionWidget( static_cast<KHotKeys::DBusAction*>(act) );
 
140
                break;
 
141
 
 
142
            case KHotKeys::Action::CommandUrlActionType:
 
143
                currentAction = new CommandUrlActionWidget( static_cast<KHotKeys::CommandUrlAction*>(act) );
 
144
                break;
 
145
 
 
146
            case KHotKeys::Action::KeyboardInputActionType:
 
147
                currentAction = new KeyboardInputActionWidget( static_cast<KHotKeys::KeyboardInputAction*>(act) );
 
148
                break;
 
149
 
 
150
            default:
 
151
                kDebug() << "Unknown action type";
 
152
            };
 
153
        }
 
154
 
 
155
    if (currentAction )
 
156
        {
 
157
        connect(
 
158
            currentAction, SIGNAL(changed(bool)),
 
159
            this, SLOT(slotChanged() ));
 
160
        extend(currentAction, i18n("Action"));
 
161
        }
 
162
 
 
163
    Base::copyFromObject();
 
164
    }
 
165
 
 
166
 
 
167
 
 
168
#include "moc_simple_action_data_widget.cpp"