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

« back to all changes in this revision

Viewing changes to khotkeys/libkhotkeysprivate/actions/menuentry_action.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) 1999-2001 Lubos Lunak <l.lunak@kde.org>
 
3
   Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
 
4
 
 
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.
 
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 "actions.h"
 
21
#include "action_data/action_data.h"
 
22
 
 
23
#include <KDE/KConfigGroup>
 
24
#include <KDE/KDebug>
 
25
#include <KDE/KMessageBox>
 
26
#include <KDE/KUrl>
 
27
#include <KDE/KRun>
 
28
 
 
29
namespace KHotKeys {
 
30
 
 
31
MenuEntryActionVisitor::~MenuEntryActionVisitor()
 
32
    {}
 
33
 
 
34
 
 
35
MenuEntryAction::MenuEntryAction( ActionData* data_P, const QString& menuentry_P )
 
36
    : CommandUrlAction( data_P, menuentry_P )
 
37
    {
 
38
    }
 
39
 
 
40
 
 
41
void MenuEntryAction::accept(ActionVisitor& visitor)
 
42
    {
 
43
    if (MenuEntryActionVisitor *v = dynamic_cast<MenuEntryActionVisitor*>(&visitor))
 
44
        {
 
45
        v->visit(*this);
 
46
        }
 
47
    else
 
48
        {
 
49
        kDebug() << "Visitor error";
 
50
        }
 
51
    }
 
52
 
 
53
 
 
54
void MenuEntryAction::cfg_write( KConfigGroup& cfg_P ) const
 
55
    {
 
56
    base::cfg_write( cfg_P );
 
57
    cfg_P.writeEntry( "Type", "MENUENTRY" ); // overwrites value set in base::cfg_write()
 
58
    }
 
59
 
 
60
 
 
61
KService::Ptr MenuEntryAction::service() const
 
62
    {
 
63
    if (!_service)
 
64
        {
 
65
        const_cast<MenuEntryAction *>(this)->_service = KService::serviceByStorageId(command_url());
 
66
        }
 
67
    return _service;
 
68
    }
 
69
 
 
70
 
 
71
void MenuEntryAction::set_service( KService::Ptr service )
 
72
    {
 
73
    _service = service;
 
74
    if (service)
 
75
        {
 
76
        set_command_url(service->storageId());
 
77
        }
 
78
    else
 
79
        {
 
80
        set_command_url(QString());
 
81
        }
 
82
    }
 
83
 
 
84
 
 
85
void MenuEntryAction::execute()
 
86
    {
 
87
    if (!service())
 
88
        {
 
89
        KMessageBox::sorry(
 
90
                NULL,
 
91
                i18n("No service configured."),
 
92
                i18n("Input Action: %1", data->comment()));
 
93
        return;
 
94
        }
 
95
 
 
96
    if (!KRun::run( *service(), KUrl::List(), 0 ))
 
97
        {
 
98
        KMessageBox::sorry(
 
99
                NULL,
 
100
                i18n("Failed to start service '%1'.", service()->name()),
 
101
                i18n("Input Action: %1", data->comment()));
 
102
        return;
 
103
        }
 
104
    }
 
105
 
 
106
 
 
107
Action* MenuEntryAction::copy( ActionData* data_P ) const
 
108
    {
 
109
    return new MenuEntryAction( data_P, command_url());
 
110
    }
 
111
 
 
112
 
 
113
const QString MenuEntryAction::description() const
 
114
    {
 
115
    return i18n( "Menu entry: " ) + (service() ? service()->comment() : QString());
 
116
    }
 
117
 
 
118
 
 
119
} // namespace KHotKeys
 
120