~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy-backports

« back to all changes in this revision

Viewing changes to kmenuedit/kmenuedit.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-09-05 20:45:14 UTC
  • Revision ID: james.westby@ubuntu.com-20070905204514-632hhspl0nvrc84i
Tags: upstream-3.93.0
ImportĀ upstreamĀ versionĀ 3.93.0

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
 
 
21
#include <QSplitter>
 
22
 
 
23
#include <kaction.h>
 
24
#include <kactioncollection.h>
 
25
#include <kapplication.h>
 
26
#include <kconfig.h>
 
27
#include <kdebug.h>
 
28
#include <kedittoolbar.h>
 
29
#include <kglobal.h>
 
30
#include <kicon.h>
 
31
#include <klocale.h>
 
32
#include <kmessagebox.h>
 
33
#include <kservice.h>
 
34
#include <kstandardaction.h>
 
35
#include <kstandardshortcut.h>
 
36
#include <kxmlguifactory.h>
 
37
#include "treeview.h"
 
38
#include "basictab.h"
 
39
#include "kmenuedit.h"
 
40
#include "kmenuedit.moc"
 
41
 
 
42
KMenuEdit::KMenuEdit (bool controlCenter)
 
43
  : KXmlGuiWindow (0), m_tree(0), m_basicTab(0), m_splitter(0), m_controlCenter(controlCenter)
 
44
{
 
45
#if 0
 
46
    m_showHidden = config->readEntry("ShowHidden", QVariant(false)).toBool();
 
47
#else
 
48
    m_showHidden = false;
 
49
#endif
 
50
 
 
51
    // setup GUI
 
52
    setupActions();
 
53
    slotChangeView();
 
54
}
 
55
 
 
56
KMenuEdit::~KMenuEdit()
 
57
{
 
58
    KConfigGroup config(KGlobal::config(), "General");
 
59
    config.writeEntry("SplitterSizes", m_splitter->sizes());
 
60
 
 
61
    config.sync();
 
62
}
 
63
 
 
64
void KMenuEdit::setupActions()
 
65
{
 
66
    QAction *action = actionCollection()->addAction("newsubmenu");
 
67
    action->setIcon(KIcon("menu_new"));
 
68
    action->setText(i18n("&New Submenu..."));
 
69
    action = actionCollection()->addAction("newitem");
 
70
    action->setIcon(KIcon("document-new")) ;
 
71
    action->setText(i18n("New &Item..."));
 
72
    action->setShortcuts(KStandardShortcut::openNew());
 
73
    if (!m_controlCenter)
 
74
    {
 
75
       QAction *action = actionCollection()->addAction("newsep");
 
76
       action->setIcon(KIcon("menu_new_sep"));
 
77
       action->setText(i18n("New S&eparator"));
 
78
    }
 
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
 
 
89
void KMenuEdit::setupView()
 
90
{
 
91
    m_splitter = new QSplitter;
 
92
    m_splitter->setOrientation(Qt::Horizontal);
 
93
    m_tree = new TreeView(m_controlCenter, actionCollection());
 
94
    m_splitter->addWidget(m_tree);
 
95
    m_basicTab = new BasicTab;
 
96
    m_splitter->addWidget(m_basicTab);
 
97
 
 
98
    connect(m_tree, SIGNAL(entrySelected(MenuFolderInfo *)),
 
99
            m_basicTab, SLOT(setFolderInfo(MenuFolderInfo *)));
 
100
    connect(m_tree, SIGNAL(entrySelected(MenuEntryInfo *)),
 
101
            m_basicTab, SLOT(setEntryInfo(MenuEntryInfo *)));
 
102
    connect(m_tree, SIGNAL(disableAction()),
 
103
            m_basicTab, SLOT(slotDisableAction() ) );
 
104
 
 
105
    connect(m_basicTab, SIGNAL(changed(MenuFolderInfo *)),
 
106
            m_tree, SLOT(currentChanged(MenuFolderInfo *)));
 
107
 
 
108
    connect(m_basicTab, SIGNAL(changed(MenuEntryInfo *)),
 
109
            m_tree, SLOT(currentChanged(MenuEntryInfo *)));
 
110
 
 
111
    connect(m_basicTab, SIGNAL(findServiceShortcut(const KShortcut&, KService::Ptr &)),
 
112
            m_tree, SLOT(findServiceShortcut(const KShortcut&, KService::Ptr &)));
 
113
 
 
114
    // restore splitter sizes
 
115
    KSharedConfig::Ptr config = KGlobal::config();
 
116
    KConfigGroup generalGroup(config, "General");
 
117
    QList<int> sizes = generalGroup.readEntry("SplitterSizes",QList<int>());
 
118
 
 
119
    if (sizes.isEmpty())
 
120
        sizes << 1 << 3;
 
121
    m_splitter->setSizes(sizes);
 
122
    m_tree->setFocus();
 
123
 
 
124
    setCentralWidget(m_splitter);
 
125
}
 
126
 
 
127
void KMenuEdit::slotChangeView()
 
128
{
 
129
#if 0
 
130
    m_showHidden = m_actionShowHidden->isChecked();
 
131
#else
 
132
    m_showHidden = false;
 
133
#endif
 
134
#ifdef __GNUC__
 
135
#warning "kde4: comment setUpdatesEnabled otherwise we can't see layout"
 
136
#endif
 
137
    // disabling the updates prevents unnecessary redraws
 
138
    //setUpdatesEnabled( false );
 
139
    guiFactory()->removeClient( this );
 
140
 
 
141
    delete m_actionDelete;
 
142
 
 
143
    m_actionDelete = actionCollection()->addAction("delete");
 
144
    m_actionDelete->setIcon(KIcon("edit-delete"));
 
145
    m_actionDelete->setText(i18n("&Delete"));
 
146
    m_actionDelete->setShortcut(QKeySequence(Qt::Key_Delete));
 
147
 
 
148
    if (!m_splitter)
 
149
       setupView();
 
150
    if (m_controlCenter)
 
151
       setupGUI(KXmlGuiWindow::ToolBar|Keys|Save|Create, "kcontroleditui.rc");
 
152
    else
 
153
       setupGUI(KXmlGuiWindow::ToolBar|Keys|Save|Create, "kmenueditui.rc");
 
154
 
 
155
    m_tree->setViewMode(m_showHidden);
 
156
}
 
157
 
 
158
void KMenuEdit::slotSave()
 
159
{
 
160
    m_tree->save();
 
161
}
 
162
 
 
163
bool KMenuEdit::queryClose()
 
164
{
 
165
    if (!m_tree->dirty()) return true;
 
166
 
 
167
 
 
168
    int result;
 
169
    if (m_controlCenter)
 
170
    {
 
171
       result = KMessageBox::warningYesNoCancel(this,
 
172
                    i18n("You have made changes to the Control Center.\n"
 
173
                         "Do you want to save the changes or discard them?"),
 
174
                    i18n("Save Control Center Changes?"),
 
175
                    KStandardGuiItem::save(), KStandardGuiItem::discard() );
 
176
    }
 
177
    else
 
178
    {
 
179
       result = KMessageBox::warningYesNoCancel(this,
 
180
                    i18n("You have made changes to the menu.\n"
 
181
                         "Do you want to save the changes or discard them?"),
 
182
                    i18n("Save Menu Changes?"),
 
183
                    KStandardGuiItem::save(), KStandardGuiItem::discard() );
 
184
    }
 
185
 
 
186
    switch(result)
 
187
    {
 
188
      case KMessageBox::Yes:
 
189
         return m_tree->save();
 
190
 
 
191
      case KMessageBox::No:
 
192
         return true;
 
193
 
 
194
      default:
 
195
         break;
 
196
    }
 
197
    return false;
 
198
}
 
199
 
 
200
void KMenuEdit::slotConfigureToolbars()
 
201
{
 
202
    KEditToolBar dlg( factory() );
 
203
    dlg.exec();
 
204
}