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

« back to all changes in this revision

Viewing changes to khotkeys/kcm_hotkeys/actions/menuentry_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
/*
 
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 "menuentry_action_widget.h"
 
21
 
 
22
#include <KDE/KDebug>
 
23
#include <KDE/KOpenWithDialog>
 
24
 
 
25
 
 
26
 
 
27
MenuentryActionWidget::MenuentryActionWidget( KHotKeys::MenuEntryAction *action, QWidget *parent )
 
28
        : ActionWidgetBase(action, parent )
 
29
          ,storage_id()
 
30
    {
 
31
    ui.setupUi(this);
 
32
 
 
33
    connect(
 
34
        ui.applicationButton, SIGNAL(clicked()),
 
35
        this, SLOT(selectApplicationClicked()) );
 
36
 
 
37
    connect(
 
38
        ui.application, SIGNAL(textChanged(QString)),
 
39
        _changedSignals, SLOT(map()) );
 
40
    _changedSignals->setMapping(ui.application, "application" );
 
41
    }
 
42
 
 
43
 
 
44
MenuentryActionWidget::~MenuentryActionWidget()
 
45
    {}
 
46
 
 
47
 
 
48
KHotKeys::MenuEntryAction *MenuentryActionWidget::action()
 
49
    {
 
50
    Q_ASSERT(dynamic_cast<KHotKeys::MenuEntryAction*>(_action));
 
51
    return static_cast<KHotKeys::MenuEntryAction*>(_action);
 
52
    }
 
53
 
 
54
 
 
55
const KHotKeys::MenuEntryAction *MenuentryActionWidget::action() const
 
56
    {
 
57
    Q_ASSERT(dynamic_cast<KHotKeys::MenuEntryAction*>(_action));
 
58
    return static_cast<const KHotKeys::MenuEntryAction*>(_action);
 
59
    }
 
60
 
 
61
 
 
62
void MenuentryActionWidget::doCopyFromObject()
 
63
    {
 
64
    Q_ASSERT(action());
 
65
    KService::Ptr service = action()->service();
 
66
 
 
67
    if (service)
 
68
        {
 
69
        ui.application->setText( service->name() );
 
70
        storage_id = service->storageId();
 
71
        }
 
72
    else
 
73
        {
 
74
        ui.application->setText(QString());
 
75
        storage_id = QString();
 
76
        }
 
77
    }
 
78
 
 
79
 
 
80
void MenuentryActionWidget::doCopyToObject()
 
81
    {
 
82
    Q_ASSERT(action());
 
83
    action()->set_service( KService::serviceByStorageId(storage_id));
 
84
    }
 
85
 
 
86
 
 
87
bool MenuentryActionWidget::isChanged() const
 
88
    {
 
89
    Q_ASSERT(action());
 
90
 
 
91
    bool changed;
 
92
 
 
93
    // There could be no service set, so be careful!
 
94
    if (action()->service())
 
95
        {
 
96
        changed = ui.application->text() != action()->service()->name();
 
97
        }
 
98
    else
 
99
        {
 
100
        // No service set. If the string is not empty something changed.
 
101
        changed = ! ui.application->text().isEmpty();
 
102
        }
 
103
 
 
104
    return changed;
 
105
    }
 
106
 
 
107
 
 
108
void MenuentryActionWidget::selectApplicationClicked()
 
109
    {
 
110
    KOpenWithDialog dlg;
 
111
    dlg.exec();
 
112
 
 
113
    KService::Ptr service = dlg.service();
 
114
 
 
115
    if (service)
 
116
        {
 
117
        ui.application->setText( service->name() );
 
118
        storage_id = service->storageId();
 
119
        }
 
120
    }
 
121
 
 
122
 
 
123
#include "moc_menuentry_action_widget.cpp"