19 #include "kshortcutsdialog_p.h"
25 #include <QTextStream>
26 #include <QtXml/QDomDocument>
27 #include <QFileDialog>
38 #include "kshortcutschemeshelper_p.h"
41 :
QGroupBox(
i18n(
"Shortcut Schemes"), parent), m_dialog(parent)
45 const QStringList schemeFiles = KGlobal::dirs()->findAllResources(
"appdata",
"*shortcuts.rc");
48 foreach (
QString schemeFile, schemeFiles)
50 schemes << schemeFile.remove(QRegExp(
"^.*/"+KGlobal::mainComponent().componentName())).
51 remove(
"shortcuts.rc");
54 QString currentScheme =
group.readEntry(
"Current Scheme",
"Default");
56 QHBoxLayout *l =
new QHBoxLayout(
this);
60 l->addWidget(schemesLabel);
63 m_schemesList->setEditable(
false);
64 m_schemesList->addItems(schemes);
65 m_schemesList->setCurrentIndex(m_schemesList->findText(currentScheme));
66 schemesLabel->setBuddy(m_schemesList);
67 l->addWidget(m_schemesList);
70 l->addWidget(m_newScheme);
73 l->addWidget(m_deleteScheme);
76 l->addWidget(moreActions);
79 moreActionsMenu->addAction(
i18n(
"Save as Scheme Defaults"),
80 this, SLOT(saveAsDefaultsForScheme()));
81 moreActionsMenu->addAction(
i18n(
"Export Scheme..."),
82 this, SLOT(exportShortcutsScheme()));
84 moreActions->setMenu(moreActionsMenu);
88 connect(m_schemesList, SIGNAL(activated(
QString)),
89 this, SIGNAL(shortcutsSchemeChanged(
QString)));
90 connect(m_newScheme, SIGNAL(clicked()),
this, SLOT(newScheme()));
91 connect(m_deleteScheme, SIGNAL(clicked()),
this, SLOT(deleteScheme()));
95 void KShortcutSchemesEditor::newScheme()
99 i18n(
"Name for new scheme:"),
i18n(
"New Scheme"), &ok,
this);
103 if (m_schemesList->findText(newName) != -1)
109 const QString newSchemeFileName = KShortcutSchemesHelper::applicationShortcutSchemeFileName(newName);
111 QFile schemeFile(newSchemeFileName);
112 if (!schemeFile.open(QFile::WriteOnly | QFile::Truncate))
116 QDomElement docElem = doc.createElement(
"kpartgui");
117 doc.appendChild(docElem);
118 QDomElement elem = doc.createElement(
"ActionProperties");
119 docElem.appendChild(elem);
121 QTextStream out(&schemeFile);
122 out << doc.toString(4);
124 m_schemesList->addItem(newName);
125 m_schemesList->setCurrentIndex(m_schemesList->findText(newName));
126 updateDeleteButton();
127 emit shortcutsSchemeChanged(newName);
130 void KShortcutSchemesEditor::deleteScheme()
133 i18n(
"Do you really want to delete the scheme %1?\n\
134 Note that this will not remove any system wide shortcut schemes.", currentScheme())) ==
KMessageBox::No)
138 QFile::remove(KShortcutSchemesHelper::applicationShortcutSchemeFileName(currentScheme()));
146 QFile::remove(KShortcutSchemesHelper::shortcutSchemeFileName(client, currentScheme()));
149 m_schemesList->removeItem(m_schemesList->findText(currentScheme()));
150 updateDeleteButton();
151 emit shortcutsSchemeChanged(currentScheme());
154 QString KShortcutSchemesEditor::currentScheme()
156 return m_schemesList->currentText();
159 void KShortcutSchemesEditor::exportShortcutsScheme()
162 QString exportTo = QFileDialog::getExistingDirectory(
this,
i18n(
"Export to Location"),
163 QDir::currentPath());
164 if (exportTo.isEmpty())
167 QDir schemeRoot(exportTo);
169 if (!schemeRoot.exists(exportTo))
178 if (!client)
continue;
179 KShortcutSchemesHelper::exportActionCollection(collection,
180 currentScheme(), exportTo +
'/');
184 void KShortcutSchemesEditor::saveAsDefaultsForScheme()
187 KShortcutSchemesHelper::exportActionCollection(collection, currentScheme());
191 void KShortcutSchemesEditor::updateDeleteButton()
193 m_deleteScheme->setEnabled(m_schemesList->count()>=1);