Import of a KCM for KWin scripts
This KCM has been implemented by Tamas Krutk in the scope of Google Code-In. It is a simple KCM just listing all available scripts and allowing to import/export them. This will be further extended alongside the planned scripting changes in 4.9.
This commit is contained in:
parent
2a7a4bb74d
commit
572cd64af5
10 changed files with 405 additions and 0 deletions
|
@ -7,6 +7,9 @@ add_subdirectory( kwincompositing )
|
|||
if(KWIN_BUILD_SCREENEDGES)
|
||||
add_subdirectory( kwinscreenedges )
|
||||
endif(KWIN_BUILD_SCREENEDGES)
|
||||
if(KWIN_BUILD_SCRIPTING)
|
||||
add_subdirectory( kwinscripts )
|
||||
endif(KWIN_BUILD_SCRIPTING)
|
||||
add_subdirectory( kwindesktop )
|
||||
|
||||
if( KWIN_BUILD_TABBOX )
|
||||
|
|
19
kcmkwin/kwinscripts/CMakeLists.txt
Normal file
19
kcmkwin/kwinscripts/CMakeLists.txt
Normal file
|
@ -0,0 +1,19 @@
|
|||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/version.h)
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
set(kcm_SRCS
|
||||
main.cpp
|
||||
module.cpp
|
||||
)
|
||||
|
||||
kde4_add_ui_files(kcm_SRCS module.ui)
|
||||
|
||||
kde4_add_plugin(kcm_kwin_scripts ${kcm_SRCS})
|
||||
|
||||
target_link_libraries(kcm_kwin_scripts
|
||||
${KDE4_KDEUI_LIBRARY}
|
||||
${KDE4_KIO_LIBS}
|
||||
)
|
||||
|
||||
install(TARGETS kcm_kwin_scripts DESTINATION ${PLUGIN_INSTALL_DIR})
|
||||
install(FILES kwinscripts.desktop DESTINATION ${SERVICES_INSTALL_DIR})
|
4
kcmkwin/kwinscripts/Messages.sh
Executable file
4
kcmkwin/kwinscripts/Messages.sh
Executable file
|
@ -0,0 +1,4 @@
|
|||
#!bin/sh
|
||||
$EXTRACTRC `find . -name \*.rc -o -name \*.ui -o -name \*.kcfg` >> rc.cpp
|
||||
$XGETTEXT `find . -name \*.cc -o -name \*.cpp -o -name \*.h` -o $podir/kcm-kwin-scripts.pot
|
||||
rm -f rc.cpp
|
17
kcmkwin/kwinscripts/kwinscripts.desktop
Normal file
17
kcmkwin/kwinscripts/kwinscripts.desktop
Normal file
|
@ -0,0 +1,17 @@
|
|||
[Desktop Entry]
|
||||
Exec=kcmshell4 kwin-scripts
|
||||
Icon=preferences-system-windows-actions
|
||||
Type=Service
|
||||
X-KDE-ServiceTypes=KCModule
|
||||
|
||||
X-KDE-Library=kcm_kwin_scripts
|
||||
X-KDE-PluginKeyword=kwin-scripts
|
||||
X-KDE-ParentApp=kcontrol
|
||||
|
||||
X-KDE-Keywords=kwin script
|
||||
X-KDE-System-Settings-Parent-Category=window-behaviour
|
||||
|
||||
Name=KWin Scripts
|
||||
Comment=Manage KWin scripts
|
||||
|
||||
Categories=KDE;X-KDE-settings-system;
|
26
kcmkwin/kwinscripts/main.cpp
Normal file
26
kcmkwin/kwinscripts/main.cpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright (c) 2011 Tamas Krutki <ktamasw@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <KDE/KGenericFactory>
|
||||
#include <KDE/KPluginFactory>
|
||||
|
||||
#include "module.h"
|
||||
|
||||
K_PLUGIN_FACTORY(KcmKWinScriptsFactory,
|
||||
registerPlugin<Module>("kwin-scripts");)
|
||||
K_EXPORT_PLUGIN(KcmKWinScriptsFactory("kwin-scripts"))
|
177
kcmkwin/kwinscripts/module.cpp
Normal file
177
kcmkwin/kwinscripts/module.cpp
Normal file
|
@ -0,0 +1,177 @@
|
|||
/*
|
||||
* Copyright (c) 2011 Tamas Krutki <ktamasw@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "module.h"
|
||||
#include "ui_module.h"
|
||||
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtGui/QPaintEngine>
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QFileInfo>
|
||||
|
||||
#include <KDE/KAboutData>
|
||||
#include <KDE/KPluginFactory>
|
||||
#include <KDE/KStandardDirs>
|
||||
#include <KDE/KMessageBox>
|
||||
#include <KDE/KFileDialog>
|
||||
#include <KDE/KMessageWidget>
|
||||
|
||||
#include "version.h"
|
||||
|
||||
K_PLUGIN_FACTORY_DECLARATION(KcmKWinScriptsFactory);
|
||||
|
||||
Module::Module(QWidget *parent, const QVariantList &args) :
|
||||
KCModule(KcmKWinScriptsFactory::componentData(), parent, args),
|
||||
ui(new Ui::Module)
|
||||
{
|
||||
KAboutData *about = new KAboutData("kwin-scripts", 0,
|
||||
ki18n("KWin Scripts"),
|
||||
global_s_versionStringFull,
|
||||
ki18n("Configure KWin scripts"),
|
||||
KAboutData::License_GPL_V2);
|
||||
|
||||
about->addAuthor(ki18n("Tamás Krutki"));
|
||||
setAboutData(about);
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(ui->listWidget, SIGNAL(itemSelectionChanged()), SLOT(updateButtons()));
|
||||
connect(ui->exportSelectedButton, SIGNAL(clicked()), SLOT(exportScript()));
|
||||
connect(ui->importScriptButton, SIGNAL(clicked()), SLOT(importScript()));
|
||||
connect(ui->removeScriptButton, SIGNAL(clicked()), SLOT(removeScript()));
|
||||
|
||||
// We have no help and defaults and apply buttons.
|
||||
setButtons(buttons() ^ KCModule::Help ^ KCModule::Default ^ KCModule::Apply);
|
||||
|
||||
ui->listWidget->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
|
||||
updateListViewContents();
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
Module::~Module()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void Module::updateButtons()
|
||||
{
|
||||
if (ui->listWidget->selectedItems().isEmpty()) {
|
||||
ui->exportSelectedButton->setEnabled(false);
|
||||
ui->removeScriptButton->setEnabled(false);
|
||||
} else {
|
||||
ui->exportSelectedButton->setEnabled(true);
|
||||
ui->removeScriptButton->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void Module::exportScript()
|
||||
{
|
||||
QString path = KFileDialog::getSaveFileName(KUrl(), "*.kwinscript *.kws *.kwinqs|KWin scripts (*.kwinscript, *.kws, *.kwinqs)");
|
||||
|
||||
if (!path.isNull()) {
|
||||
QFile f(componentData().dirs()->findResource("data", "kwin/scripts/" + ui->listWidget->currentItem()->text()));
|
||||
|
||||
QFileInfo pathInfo(path);
|
||||
QDir dir(pathInfo.absolutePath());
|
||||
|
||||
if (dir.exists(pathInfo.fileName())) {
|
||||
dir.remove(pathInfo.fileName());
|
||||
}
|
||||
|
||||
if (f.copy(path)) {
|
||||
KMessageWidget* msgWidget = new KMessageWidget;
|
||||
msgWidget->setText(ki18n("The selected script was exported successfully!").toString());
|
||||
msgWidget->setMessageType(KMessageWidget::Positive);
|
||||
ui->verticalLayout2->insertWidget(0, msgWidget);
|
||||
msgWidget->animatedShow();
|
||||
} else {
|
||||
KMessageWidget* msgWidget = new KMessageWidget;
|
||||
msgWidget->setText(ki18n("An error occurred, the selected script could not be exported!").toString());
|
||||
msgWidget->setMessageType(KMessageWidget::Error);
|
||||
ui->verticalLayout2->insertWidget(0, msgWidget);
|
||||
msgWidget->animatedShow();
|
||||
}
|
||||
}
|
||||
|
||||
updateListViewContents();
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
void Module::importScript()
|
||||
{
|
||||
QString path = KFileDialog::getOpenFileName(KUrl(), "*.kwinscript *.kws *.kwinqs|KWin scripts (*.kwinscript, *.kws, *.kwinqs)");
|
||||
|
||||
if (!path.isNull()) {
|
||||
QFileInfo pathInfo(path);
|
||||
QString fileName(pathInfo.fileName());
|
||||
|
||||
QFile f(path);
|
||||
if (!f.copy(componentData().dirs()->saveLocation("data", "kwin/scripts/") + fileName)) {
|
||||
KMessageWidget* msgWidget = new KMessageWidget;
|
||||
msgWidget->setText(ki18n("Cannot import selected script: maybe a script already exists with the same name or there is a permission problem.").toString());
|
||||
msgWidget->setMessageType(KMessageWidget::Error);
|
||||
ui->verticalLayout2->insertWidget(0, msgWidget);
|
||||
msgWidget->animatedShow();
|
||||
} else {
|
||||
f.setFileName(componentData().dirs()->saveLocation("data", "kwin/scripts/") + fileName);
|
||||
f.open(QIODevice::ReadWrite);
|
||||
f.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner |
|
||||
QFile::ReadGroup | QFile::ExeGroup |
|
||||
QFile::ReadUser | QFile::ExeUser | QFile::WriteUser |
|
||||
QFile::ReadOther | QFile::ExeOther);
|
||||
f.close();
|
||||
|
||||
KMessageWidget* msgWidget = new KMessageWidget;
|
||||
msgWidget->setText(ki18n("The selected script was imported successfully!").toString());
|
||||
msgWidget->setMessageType(KMessageWidget::Positive);
|
||||
ui->verticalLayout2->insertWidget(0, msgWidget);
|
||||
msgWidget->animatedShow();
|
||||
}
|
||||
}
|
||||
|
||||
updateListViewContents();
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
void Module::removeScript()
|
||||
{
|
||||
if (KMessageBox::questionYesNo(this, ki18n("Do you really want to delete the selected script?").toString(), ki18n("Remove KWin script").toString()) == KMessageBox::Yes) {
|
||||
QDir dir(QFileInfo(componentData().dirs()->findResource("data", "kwin/scripts/" + ui->listWidget->currentItem()->text())).absolutePath());
|
||||
dir.remove(ui->listWidget->currentItem()->text());
|
||||
updateListViewContents();
|
||||
updateButtons();
|
||||
}
|
||||
}
|
||||
|
||||
void Module::updateListViewContents()
|
||||
{
|
||||
ui->listWidget->clear();
|
||||
|
||||
QStringList dirList = componentData().dirs()->findDirs("data", "kwin/scripts");
|
||||
for (int i = 0; i < dirList.size(); i++) {
|
||||
QDir dir(dirList[i]);
|
||||
QStringList fileNameList = dir.entryList(QStringList() << "*.kws" << "*.kwinscript" << "*.kwinqs", QDir::Files, QDir::Name);
|
||||
|
||||
for (int j = 0; j < fileNameList.size(); j++) {
|
||||
ui->listWidget->addItem(fileNameList[j]);
|
||||
}
|
||||
}
|
||||
}
|
79
kcmkwin/kwinscripts/module.h
Normal file
79
kcmkwin/kwinscripts/module.h
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2011 Tamas Krutki <ktamasw@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef MODULE_H
|
||||
#define MODULE_H
|
||||
|
||||
#include <KDE/KCModule>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class Module;
|
||||
}
|
||||
|
||||
class Module : public KCModule
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param parent Parent widget of the module
|
||||
* @param args Arguments for the module
|
||||
*/
|
||||
Module(QWidget *parent, const QVariantList &args = QVariantList());
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~Module();
|
||||
|
||||
protected slots:
|
||||
/**
|
||||
* Called when the selection changes in the list view.
|
||||
* Disables/enables the remove and export buttons.
|
||||
*/
|
||||
void updateButtons();
|
||||
|
||||
/**
|
||||
* Called when the export script button is clicked.
|
||||
*/
|
||||
void exportScript();
|
||||
|
||||
/**
|
||||
* Called when the import script button is clicked.
|
||||
*/
|
||||
void importScript();
|
||||
|
||||
/**
|
||||
* Called when the remove script button is clicked.
|
||||
*/
|
||||
void removeScript();
|
||||
|
||||
private:
|
||||
/**
|
||||
* UI
|
||||
*/
|
||||
Ui::Module *ui;
|
||||
/**
|
||||
* Updates the contents of the list view.
|
||||
*/
|
||||
void updateListViewContents();
|
||||
};
|
||||
|
||||
#endif // MODULE_H
|
70
kcmkwin/kwinscripts/module.ui
Normal file
70
kcmkwin/kwinscripts/module.ui
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Module</class>
|
||||
<widget class="QWidget" name="Module">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>484</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>KWin script configuration</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout2">
|
||||
<item>
|
||||
<widget class="QListWidget" name="listWidget"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="importScriptButton">
|
||||
<property name="text">
|
||||
<string>Import KWin script</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="exportSelectedButton">
|
||||
<property name="text">
|
||||
<string>Export selected KWin script</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="removeScriptButton">
|
||||
<property name="text">
|
||||
<string>Remove selected KWin script</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
7
kcmkwin/kwinscripts/version.h.cmake
Normal file
7
kcmkwin/kwinscripts/version.h.cmake
Normal file
|
@ -0,0 +1,7 @@
|
|||
#ifndef VERSION_H
|
||||
#define VERSION_H
|
||||
|
||||
static const char global_s_versionString[] = "${VERSION_STRING}";
|
||||
static const char global_s_versionStringFull[] = "${VERSION_STRING_FULL}";
|
||||
|
||||
#endif // VERSION_H
|
|
@ -1151,6 +1151,9 @@ QStringList Workspace::configModules(bool controlCenter)
|
|||
#endif
|
||||
#ifdef KWIN_BUILD_SCREENEDGES
|
||||
<< "kwinscreenedges"
|
||||
#endif
|
||||
#ifdef KWIN_BUILD_SCRIPTING
|
||||
<< "kwinscripts"
|
||||
#endif
|
||||
;
|
||||
return args;
|
||||
|
|
Loading…
Reference in a new issue