Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / kmenuedit / kmenuedit.cpp
blob108f55d73d6360c6a8eccbc2dacc6e58f15c10c4
1 /*
2 * Copyright (C) 2000 Matthias Elter <elter@kde.org>
3 * Copyright (C) 2001-2002 Raffaele Sandrini <sandrini@kde.org>
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.
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.
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.
21 #include <QSplitter>
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"
42 KMenuEdit::KMenuEdit (bool controlCenter)
43 : KXmlGuiWindow (0), m_tree(0), m_basicTab(0), m_splitter(0), m_controlCenter(controlCenter)
45 #if 0
46 m_showHidden = config->readEntry("ShowHidden", QVariant(false)).toBool();
47 #else
48 m_showHidden = false;
49 #endif
51 // setup GUI
52 setupActions();
53 slotChangeView();
56 KMenuEdit::~KMenuEdit()
58 KConfigGroup config(KGlobal::config(), "General");
59 config.writeEntry("SplitterSizes", m_splitter->sizes());
61 config.sync();
64 void KMenuEdit::setupActions()
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)
75 QAction *action = actionCollection()->addAction("newsep");
76 action->setIcon(KIcon("menu_new_sep"));
77 action->setText(i18n("New S&eparator"));
80 m_actionDelete = 0;
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);
89 void KMenuEdit::setupView()
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);
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() ) );
105 connect(m_basicTab, SIGNAL(changed(MenuFolderInfo *)),
106 m_tree, SLOT(currentChanged(MenuFolderInfo *)));
108 connect(m_basicTab, SIGNAL(changed(MenuEntryInfo *)),
109 m_tree, SLOT(currentChanged(MenuEntryInfo *)));
111 connect(m_basicTab, SIGNAL(findServiceShortcut(const KShortcut&, KService::Ptr &)),
112 m_tree, SLOT(findServiceShortcut(const KShortcut&, KService::Ptr &)));
114 // restore splitter sizes
115 KSharedConfig::Ptr config = KGlobal::config();
116 KConfigGroup generalGroup(config, "General");
117 QList<int> sizes = generalGroup.readEntry("SplitterSizes",QList<int>());
119 if (sizes.isEmpty())
120 sizes << 1 << 3;
121 m_splitter->setSizes(sizes);
122 m_tree->setFocus();
124 setCentralWidget(m_splitter);
127 void KMenuEdit::slotChangeView()
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 );
141 delete m_actionDelete;
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));
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");
155 m_tree->setViewMode(m_showHidden);
158 void KMenuEdit::slotSave()
160 m_tree->save();
163 bool KMenuEdit::queryClose()
165 if (!m_tree->dirty()) return true;
168 int result;
169 if (m_controlCenter)
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() );
177 else
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() );
186 switch(result)
188 case KMessageBox::Yes:
189 return m_tree->save();
191 case KMessageBox::No:
192 return true;
194 default:
195 break;
197 return false;
200 void KMenuEdit::slotConfigureToolbars()
202 KEditToolBar dlg( factory() );
203 dlg.exec();