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

« back to all changes in this revision

Viewing changes to kmenuedit/kmenuedit.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) 2000 Matthias Elter <elter@kde.org>
 
3
 *   Copyright (C) 2001-2002 Raffaele Sandrini <sandrini@kde.org>
 
4
 *
 
5
 *   This program is free software; you can redistribute it and/or modify
 
6
 *   it under the terms of the GNU General Public License as published by
 
7
 *   the Free Software Foundation; either version 2 of the License, or
 
8
 *   (at your option) any later version.
 
9
 *
 
10
 *   This program is distributed in the hope that it will be useful,
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *   GNU General Public License for more details.
 
14
 *
 
15
 *   You should have received a copy of the GNU General Public License
 
16
 *   along with this program; if not, write to the Free Software
 
17
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
18
 *
 
19
 */
 
20
#include "kmenuedit.h"
 
21
 
 
22
#include <QSplitter>
 
23
 
 
24
#include <kaction.h>
 
25
#include <kactioncollection.h>
 
26
#include <kapplication.h>
 
27
#include <kconfig.h>
 
28
#include <kdebug.h>
 
29
#include <kedittoolbar.h>
 
30
#include <kglobal.h>
 
31
#include <kicon.h>
 
32
#include <klocale.h>
 
33
#include <kmessagebox.h>
 
34
#include <kservice.h>
 
35
#include <kstandardaction.h>
 
36
#include <kstandardshortcut.h>
 
37
#include <kxmlguifactory.h>
 
38
#include <sonnet/configdialog.h>
 
39
#include "treeview.h"
 
40
#include "basictab.h"
 
41
#include "preferencesdlg.h"
 
42
#include "kmenueditadaptor.h"
 
43
 
 
44
#include "kmenuedit.moc"
 
45
 
 
46
KMenuEdit::KMenuEdit ()
 
47
  : KXmlGuiWindow (0), m_tree(0), m_basicTab(0), m_splitter(0)
 
48
{
 
49
    ( void )new KmenueditAdaptor(this);
 
50
    QDBusConnection::sessionBus().registerObject("/KMenuEdit", this);
 
51
    KConfigGroup grp( KGlobal::config(), "General" );
 
52
    m_showHidden = grp.readEntry("ShowHidden", false);
 
53
 
 
54
    // setup GUI
 
55
    setupActions();
 
56
    slotChangeView();
 
57
}
 
58
 
 
59
KMenuEdit::~KMenuEdit()
 
60
{
 
61
    KConfigGroup config(KGlobal::config(), "General");
 
62
    config.writeEntry("SplitterSizes", m_splitter->sizes());
 
63
 
 
64
    config.sync();
 
65
}
 
66
 
 
67
void KMenuEdit::setupActions()
 
68
{
 
69
    KAction *action = actionCollection()->addAction("newsubmenu");
 
70
    action->setIcon(KIcon("menu_new"));
 
71
    action->setText(i18n("&New Submenu..."));
 
72
    action = actionCollection()->addAction("newitem");
 
73
    action->setIcon(KIcon("document-new")) ;
 
74
    action->setText(i18n("New &Item..."));
 
75
    action->setShortcuts(KStandardShortcut::openNew());
 
76
    action = actionCollection()->addAction("newsep");
 
77
    action->setIcon(KIcon("menu_new_sep"));
 
78
    action->setText(i18n("New S&eparator"));
 
79
 
 
80
    m_actionDelete = 0;
 
81
 
 
82
    actionCollection()->addAction(KStandardAction::Save, this, SLOT( slotSave() ));
 
83
    actionCollection()->addAction(KStandardAction::Quit, this, SLOT( close() ));
 
84
    actionCollection()->addAction(KStandardAction::Cut);
 
85
    actionCollection()->addAction(KStandardAction::Copy);
 
86
    actionCollection()->addAction(KStandardAction::Paste);
 
87
 
 
88
    action = new KAction( i18n("Restore to System Menu"), this );
 
89
    actionCollection()->addAction( "restore_system_menu", action );
 
90
    connect( action, SIGNAL(triggered(bool) ), SLOT(slotRestoreMenu()) );
 
91
    KStandardAction::preferences( this, SLOT( slotConfigure() ), actionCollection() );
 
92
}
 
93
 
 
94
void KMenuEdit::slotConfigure()
 
95
{
 
96
    PreferencesDialog dlg( this );
 
97
    if ( dlg.exec() )
 
98
    {
 
99
        KConfigGroup grp( KGlobal::config(), "General" );
 
100
        bool newShowHiddenValue = grp.readEntry("ShowHidden", false);
 
101
        if ( newShowHiddenValue != m_showHidden )
 
102
        {
 
103
            m_showHidden = newShowHiddenValue;
 
104
            m_tree->updateTreeView(m_showHidden);
 
105
            m_basicTab->updateHiddenEntry( m_showHidden );
 
106
        }
 
107
    }
 
108
}
 
109
 
 
110
void KMenuEdit::setupView()
 
111
{
 
112
    m_splitter = new QSplitter;
 
113
    m_splitter->setOrientation(Qt::Horizontal);
 
114
    m_tree = new TreeView(actionCollection());
 
115
    m_splitter->addWidget(m_tree);
 
116
    m_basicTab = new BasicTab;
 
117
    m_splitter->addWidget(m_basicTab);
 
118
 
 
119
    connect(m_tree, SIGNAL(entrySelected(MenuFolderInfo *)),
 
120
            m_basicTab, SLOT(setFolderInfo(MenuFolderInfo *)));
 
121
    connect(m_tree, SIGNAL(entrySelected(MenuEntryInfo *)),
 
122
            m_basicTab, SLOT(setEntryInfo(MenuEntryInfo *)));
 
123
    connect(m_tree, SIGNAL(disableAction()),
 
124
            m_basicTab, SLOT(slotDisableAction() ) );
 
125
 
 
126
    connect(m_basicTab, SIGNAL(changed(MenuFolderInfo *)),
 
127
            m_tree, SLOT(currentChanged(MenuFolderInfo *)));
 
128
 
 
129
    connect(m_basicTab, SIGNAL(changed(MenuEntryInfo *)),
 
130
            m_tree, SLOT(currentChanged(MenuEntryInfo *)));
 
131
 
 
132
    connect(m_basicTab, SIGNAL(findServiceShortcut(const KShortcut&, KService::Ptr &)),
 
133
            m_tree, SLOT(findServiceShortcut(const KShortcut&, KService::Ptr &)));
 
134
 
 
135
    // restore splitter sizes
 
136
    KSharedConfig::Ptr config = KGlobal::config();
 
137
    KConfigGroup generalGroup(config, "General");
 
138
    QList<int> sizes = generalGroup.readEntry("SplitterSizes",QList<int>());
 
139
 
 
140
    if (sizes.isEmpty())
 
141
        sizes << 1 << 3;
 
142
    m_splitter->setSizes(sizes);
 
143
    m_tree->setFocus();
 
144
 
 
145
    setCentralWidget(m_splitter);
 
146
}
 
147
 
 
148
void KMenuEdit::slotChangeView()
 
149
{
 
150
 
 
151
#ifdef __GNUC__
 
152
#warning "kde4: comment setUpdatesEnabled otherwise we can't see layout"
 
153
#endif
 
154
    // disabling the updates prevents unnecessary redraws
 
155
    //setUpdatesEnabled( false );
 
156
    guiFactory()->removeClient( this );
 
157
 
 
158
    delete m_actionDelete;
 
159
 
 
160
    m_actionDelete = actionCollection()->addAction("delete");
 
161
    m_actionDelete->setIcon(KIcon("edit-delete"));
 
162
    m_actionDelete->setText(i18n("&Delete"));
 
163
    m_actionDelete->setShortcut(QKeySequence(Qt::Key_Delete));
 
164
 
 
165
    if (!m_splitter)
 
166
       setupView();
 
167
    setupGUI(KXmlGuiWindow::ToolBar|Keys|Save|Create, "kmenueditui.rc");
 
168
 
 
169
    m_tree->setViewMode(m_showHidden);
 
170
    m_basicTab->updateHiddenEntry( m_showHidden );
 
171
}
 
172
 
 
173
void KMenuEdit::slotSave()
 
174
{
 
175
    m_tree->save();
 
176
 
 
177
}
 
178
 
 
179
bool KMenuEdit::queryClose()
 
180
{
 
181
    if (!m_tree->dirty()) return true;
 
182
 
 
183
 
 
184
    int result;
 
185
    result = KMessageBox::warningYesNoCancel(this,
 
186
                                             i18n("You have made changes to the menu.\n"
 
187
                         "Do you want to save the changes or discard them?"),
 
188
                                             i18n("Save Menu Changes?"),
 
189
                                             KStandardGuiItem::save(), KStandardGuiItem::discard() );
 
190
 
 
191
    switch(result)
 
192
    {
 
193
      case KMessageBox::Yes:
 
194
         return m_tree->save();
 
195
 
 
196
      case KMessageBox::No:
 
197
         return true;
 
198
 
 
199
      default:
 
200
         break;
 
201
    }
 
202
    return false;
 
203
}
 
204
 
 
205
void KMenuEdit::slotConfigureToolbars()
 
206
{
 
207
    KEditToolBar dlg( factory() );
 
208
    dlg.exec();
 
209
}
 
210
 
 
211
void KMenuEdit::slotRestoreMenu()
 
212
{
 
213
    m_tree->restoreMenuSystem();
 
214
}
 
215
 
 
216
void KMenuEdit::restoreSystemMenu()
 
217
{
 
218
    m_tree->restoreMenuSystem();
 
219
}