kdeplasma-addons: drop paste applet

have not used it, ever..

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-04-16 05:20:53 +03:00
parent fb09ddeb67
commit 4c494a6c43
26 changed files with 0 additions and 2178 deletions

View file

@ -11,4 +11,3 @@ add_subdirectory(spellcheck)
add_subdirectory(timer)
add_subdirectory(eyes)
add_subdirectory(unitconverter)
add_subdirectory(paste)

View file

@ -1,24 +0,0 @@
project(plasma-paste)
set(paste_SRCS
paste.cpp
sendkeys.cpp
list.cpp
configdata.cpp
snippetconfig.cpp
autopasteconfig.cpp
appkey.cpp
pastemacroexpander.cpp
addmacro.cpp
list.ui
snippetconfig.ui
autopasteconfig.ui
appkey.ui
)
kde4_add_plugin(plasma_applet_paste ${paste_SRCS})
target_link_libraries(plasma_applet_paste
${X11_X11_LIB} KDE4::kdeui KDE4::kio KDE4::plasma)
install(TARGETS plasma_applet_paste DESTINATION ${KDE4_PLUGIN_INSTALL_DIR})
install(FILES plasma-applet-paste.desktop DESTINATION ${KDE4_SERVICES_INSTALL_DIR})

View file

@ -1,4 +0,0 @@
#!/bin/sh
$EXTRACTRC *.ui >> rc.cpp
$XGETTEXT *.cpp *.h -o $podir/plasma_applet_paste.pot
rm -f rc.cpp

View file

@ -1,135 +0,0 @@
/*
* Copyright 2008 Petri Damsten <damu@iki.fi>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#include "addmacro.h"
#include <fixx11h.h>
#include <QVBoxLayout>
#include <KComboBox>
#include <QLabel>
#include <QCheckBox>
#include <KLineEdit>
#include <QSpinBox>
#include <KUrlRequester>
#include <KLocale>
AddMacro::AddMacro(QWidget* parent)
: KDialog(parent), m_params(0)
{
setCaption(i18n("Add Macro"));
setButtons(KDialog::Ok | KDialog::Cancel);
m_widget = new QWidget(this);
setMainWidget(m_widget);
m_layout = new QVBoxLayout(m_widget);
m_layout->setMargin(0);
m_layout->setSpacing(spacingHint());
m_macrosComboBox = new KComboBox(m_widget);
const QMap<QString, QVariantList>& macros = PasteMacroExpander::instance().macros();
foreach (const QString& macro, macros.keys()) {
m_macrosComboBox->addItem(macros[macro][0].toString(), macro);
}
connect(m_macrosComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(currentIndexChanged(int)));
m_layout->addWidget(m_macrosComboBox);
currentIndexChanged(0);
}
AddMacro::~AddMacro()
{
}
void AddMacro::currentIndexChanged(int index)
{
delete m_params;
m_params = new QWidget(m_widget);
m_layout->addWidget(m_params);
QVBoxLayout* layout = new QVBoxLayout(m_params);
const QMap<QString, QVariantList>& macros = PasteMacroExpander::instance().macros();
const QVariantList& params = macros[m_macrosComboBox->itemData(index).toString()];
QWidget* w = 0;
for (int i = 1; i < params.count(); ++i) {
MacroParam param = params[i].value<MacroParam>();
switch (param.type) {
case MacroParam::Int:
{
QHBoxLayout* l = new QHBoxLayout(m_params);
l->addWidget(new QLabel(param.name + ':', m_params));
l->addWidget(w = new QSpinBox(m_params));
layout->addItem(l);
break;
}
case MacroParam::String:
layout->addWidget(new QLabel(param.name + ':', m_params));
layout->addWidget(w = new KLineEdit(m_params));
break;
case MacroParam::Url:
layout->addWidget(new QLabel(param.name + ':'));
layout->addWidget(w = new KUrlRequester(m_params));
break;
case MacroParam::Boolean:
layout->addWidget(w = new QCheckBox(param.name, m_params));
break;
}
w->setObjectName(param.name);
}
layout->addStretch(1.0);
}
QString AddMacro::macro()
{
int index = m_macrosComboBox->currentIndex();
const QMap<QString, QVariantList>& macros = PasteMacroExpander::instance().macros();
QString macro = m_macrosComboBox->itemData(index).toString();
const QVariantList& params = macros[m_macrosComboBox->itemData(index).toString()];
QStringList values;
for (int i = 1; i < params.count(); ++i) {
MacroParam param = params[i].value<MacroParam>();
switch (param.type) {
case MacroParam::Int:
{
QSpinBox* w = m_params->findChildren<QSpinBox*>(param.name)[0];
values.append(QString::number(w->value()));
break;
}
case MacroParam::String:
{
KLineEdit* w = m_params->findChildren<KLineEdit*>(param.name)[0];
values.append(w->text());
break;
}
case MacroParam::Url:
{
KUrlRequester* w = m_params->findChildren<KUrlRequester*>(param.name)[0];
values.append(w->url().prettyUrl());
break;
}
case MacroParam::Boolean:
{
QCheckBox* w = m_params->findChildren<QCheckBox*>(param.name)[0];
values.append((w->checkState() == Qt::Unchecked) ? "false" : "true");
break;
}
}
}
return QString("%{%1(%2)}").arg(macro).arg(values.join(", "));
}
#include "moc_addmacro.cpp"

View file

@ -1,46 +0,0 @@
/*
* Copyright 2008 Petri Damsten <damu@iki.fi>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef ADDMACRO_H
#define ADDMACRO_H
#include <pastemacroexpander.h>
#include <KDialog>
class KComboBox;
#include <QVBoxLayout>
class AddMacro : public KDialog
{
Q_OBJECT
public:
AddMacro(QWidget* parent);
~AddMacro();
QString macro();
protected slots:
void currentIndexChanged(int index);
private:
KComboBox* m_macrosComboBox;
QVBoxLayout* m_layout;
QWidget* m_widget;
QWidget* m_params;
};
#endif

View file

@ -1,64 +0,0 @@
/*
* Copyright 2008 Petri Damsten <damu@iki.fi>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#include "appkey.h"
#include <KWindowSystem>
#include <KLocale>
AppKey::AppKey(QWidget *parent)
: KDialog(parent)
{
setupUi(mainWidget());
setButtons(KDialog::Ok | KDialog::Cancel);
pasteButton->setClearButtonShown(false);
connect(appButton, SIGNAL(clicked()), this, SLOT(appClicked()));
connect(pasteButton, SIGNAL(keySequenceChanged(QKeySequence)),
this, SLOT(enableWidgets()));
enableWidgets();
}
AppKey::~AppKey()
{
}
void AppKey::appClicked()
{
appButton->setText(i18nc("Button to select an application by clicking on its window",
"Click application"));
appButton->setIcon(KIcon());
connect(KWindowSystem::self(), SIGNAL(activeWindowChanged(WId)),
this, SLOT(activeWindowChanged(WId)));
}
void AppKey::enableWidgets()
{
enableButtonOk(!appButton->text().isEmpty() && !pasteButton->keySequence().isEmpty());
}
void AppKey::activeWindowChanged(WId id)
{
KWindowInfo info = KWindowSystem::windowInfo(id, 0, NET::WM2WindowClass);
appButton->setText(info.windowClassClass());
appButton->setIcon(KIcon(info.windowClassClass().toLower()));
app = info.windowClassClass();
appButton->setChecked(false);
disconnect(KWindowSystem::self(), SIGNAL(activeWindowChanged(WId)),
this, SLOT(activeWindowChanged(WId)));
enableWidgets();
}
#include "moc_appkey.cpp"

View file

@ -1,39 +0,0 @@
/*
* Copyright 2008 Petri Damsten <damu@iki.fi>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef APPKEY_HEADER
#define APPKEY_HEADER
#include "ui_appkey.h"
#include <KDialog>
class AppKey : public KDialog, public Ui::AppKey
{
Q_OBJECT
public:
AppKey(QWidget *parent = 0);
virtual ~AppKey();
QString app;
protected slots:
void appClicked();
void activeWindowChanged(WId id);
void enableWidgets();
};
#endif // APPKEY_HEADER

View file

@ -1,78 +0,0 @@
<ui version="4.0" >
<class>AppKey</class>
<widget class="QWidget" name="AppKey" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>216</width>
<height>80</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout" >
<item>
<layout class="QGridLayout" name="gridLayout" >
<item row="0" column="0" >
<widget class="QLabel" name="appLabel" >
<property name="text" >
<string>&amp;Application:</string>
</property>
<property name="buddy" >
<cstring>appButton</cstring>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="KPushButton" name="appButton" >
<property name="checkable" >
<bool>true</bool>
</property>
<property name="checked" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="pasteLabel" >
<property name="text" >
<string>&amp;Paste key:</string>
</property>
<property name="buddy" >
<cstring>pasteButton</cstring>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="KKeySequenceWidget" name="pasteButton" />
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer" >
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>20</width>
<height>6</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KKeySequenceWidget</class>
<extends>QWidget</extends>
<header>kkeysequencewidget.h</header>
</customwidget>
<customwidget>
<class>KPushButton</class>
<extends>QPushButton</extends>
<header>kpushbutton.h</header>
</customwidget>
</customwidgets>
<connections/>
</ui>

View file

@ -1,123 +0,0 @@
/*
* Copyright 2008 Petri Damsten <damu@iki.fi>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#include "autopasteconfig.h"
#include "appkey.h"
#include "configdata.h"
#include <KDebug>
#include <KLocale>
#include <QCheckBox>
#include <QPointer>
AutoPasteConfig::AutoPasteConfig(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
addButton->setIcon(KIcon("list-add"));
removeButton->setIcon(KIcon("list-remove"));
editButton->setIcon(KIcon("list-edit"));
pasteKeyButton->setClearButtonShown(false);
appsTreeView->setModel(&m_appModel);
m_appModel.setHorizontalHeaderLabels(QStringList() << i18n("Application") << i18n("Paste Key"));
connect(addButton, SIGNAL(clicked()), this, SLOT(addClicked()));
connect(removeButton, SIGNAL(clicked()), this, SLOT(removeClicked()));
connect(editButton, SIGNAL(clicked()), this, SLOT(editClicked()));
connect(autoPasteCheckBox, SIGNAL(clicked()), this, SLOT(enableWidgets()));
connect(appsTreeView->selectionModel(),
SIGNAL(currentChanged(QModelIndex,QModelIndex)),
this, SLOT(enableWidgets()));
enableWidgets();
}
AutoPasteConfig::~AutoPasteConfig()
{
}
void AutoPasteConfig::setData(const ConfigData &data)
{
pasteKeyButton->setKeySequence(data.pasteKey);
autoPasteCheckBox->setChecked(data.autoPaste);
foreach (const QString &key, data.specialApps.keys()) {
QStandardItem *appItem = new QStandardItem(KIcon(key.toLower()), key);
QStandardItem *keyItem = new QStandardItem(data.specialApps[key].toString());
m_appModel.appendRow(QList<QStandardItem*>() << appItem << keyItem);
}
enableWidgets();
}
void AutoPasteConfig::getData(ConfigData *data)
{
data->pasteKey = pasteKeyButton->keySequence();
data->autoPaste = autoPasteCheckBox->isChecked();
data->specialApps.clear();
for (int i = 0; i < m_appModel.rowCount(); ++i) {
QStandardItem *appItem = m_appModel.item(i, 0);
QStandardItem *keyItem = m_appModel.item(i, 1);
data->specialApps[appItem->text()] = QKeySequence::fromString(keyItem->text());
}
}
void AutoPasteConfig::addClicked()
{
QPointer<AppKey> dlg = new AppKey(this);
if (dlg->exec() == QDialog::Accepted) {
QStandardItem *appItem = new QStandardItem(KIcon(dlg->app.toLower()), dlg->app);
QStandardItem *keyItem = new QStandardItem(dlg->pasteButton->keySequence().toString());
m_appModel.appendRow(QList<QStandardItem*>() << appItem << keyItem);
enableWidgets();
}
delete dlg;
}
void AutoPasteConfig::removeClicked()
{
m_appModel.takeRow(appsTreeView->selectionModel()->currentIndex().row());
enableWidgets();
}
void AutoPasteConfig::editClicked()
{
QPointer<AppKey> dlg = new AppKey(this);
int row = appsTreeView->selectionModel()->currentIndex().row();
QStandardItem *appItem = m_appModel.item(row, 0);
QStandardItem *keyItem = m_appModel.item(row, 1);
dlg->appButton->setText(appItem->text());
dlg->appButton->setIcon(KIcon(appItem->text().toLower()));
dlg->pasteButton->setKeySequence(QKeySequence::fromString(keyItem->text()));
if (dlg->exec() == QDialog::Accepted) {
appItem->setText(dlg->app);
appItem->setIcon(KIcon(dlg->app.toLower()));
keyItem->setText(dlg->pasteButton->keySequence().toString());
}
delete dlg;
}
void AutoPasteConfig::enableWidgets()
{
addButton->setEnabled(autoPasteCheckBox->isChecked());
removeButton->setEnabled(autoPasteCheckBox->isChecked() &&
appsTreeView->selectionModel()->currentIndex().isValid());
editButton->setEnabled(autoPasteCheckBox->isChecked() &&
appsTreeView->selectionModel()->currentIndex().isValid());
pasteKeyButton->setEnabled(autoPasteCheckBox->isChecked());
appsTreeView->setEnabled(autoPasteCheckBox->isChecked());
}
#include "moc_autopasteconfig.cpp"

View file

@ -1,49 +0,0 @@
/*
* Copyright 2008 Petri Damsten <damu@iki.fi>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef AUTOPASTECONFIG_HEADER
#define AUTOPASTECONFIG_HEADER
#include <QStandardItemModel>
#include <QWidget>
#include "ui_autopasteconfig.h"
class ConfigData;
class AutoPasteConfig : public QWidget, public Ui::AutoPasteConfig
{
Q_OBJECT
public:
AutoPasteConfig(QWidget *parent = 0);
virtual ~AutoPasteConfig();
void getData(ConfigData *data);
public slots:
void setData(const ConfigData &data);
protected slots:
void addClicked();
void removeClicked();
void editClicked();
void enableWidgets();
private:
QStandardItemModel m_appModel;
};
#endif // AUTOPASTECONFIG_HEADER

View file

@ -1,98 +0,0 @@
<ui version="4.0" >
<class>AutoPasteConfig</class>
<widget class="QWidget" name="AutoPasteConfig" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout" >
<item>
<layout class="QHBoxLayout" name="horizontalLayout" >
<item>
<widget class="QCheckBox" name="autoPasteCheckBox" >
<property name="text" >
<string>Paste text automatically with:</string>
</property>
</widget>
</item>
<item>
<widget class="KKeySequenceWidget" name="pasteKeyButton" />
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="appsLabel" >
<property name="text" >
<string>Use &amp;special keys for these apps:</string>
</property>
<property name="buddy" >
<cstring>appsTreeView</cstring>
</property>
</widget>
</item>
<item>
<widget class="QTreeView" name="appsTreeView" >
<property name="rootIsDecorated" >
<bool>false</bool>
</property>
<property name="uniformRowHeights" >
<bool>true</bool>
</property>
<property name="itemsExpandable" >
<bool>false</bool>
</property>
<property name="sortingEnabled" >
<bool>true</bool>
</property>
<property name="expandsOnDoubleClick" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" >
<item>
<widget class="QPushButton" name="addButton" >
<property name="text" >
<string>&amp;Add...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton" >
<property name="text" >
<string>&amp;Edit...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeButton" >
<property name="text" >
<string>&amp;Remove</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KKeySequenceWidget</class>
<extends>QWidget</extends>
<header>kkeysequencewidget.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>autoPasteCheckBox</tabstop>
<tabstop>appsTreeView</tabstop>
<tabstop>addButton</tabstop>
<tabstop>editButton</tabstop>
<tabstop>removeButton</tabstop>
</tabstops>
<connections/>
</ui>

View file

@ -1,153 +0,0 @@
/*
* Copyright 2008 Petri Damsten <damu@iki.fi>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#include "configdata.h"
#include <KLocale>
#include <KStandardDirs>
#include <KSaveFile>
#include <KDebug>
#include <KDirWatch>
#include <QtXml/qdom.h>
#include <QFile>
#include <QTextStream>
ConfigData::ConfigData()
{
xmlFile = KStandardDirs::locateLocal("data", "plasma_applet_paste/snippets.xml");
KDirWatch::self()->addFile(xmlFile);
connect(KDirWatch::self(), SIGNAL(dirty(QString)), this, SLOT(readEntries()));
}
ConfigData::~ConfigData()
{
}
ConfigData &ConfigData::operator=(const KConfigGroup &rhs)
{
KConfigGroup::operator=(rhs);
readEntries();
return *this;
}
#define CHECK(TYPE, VAR, READFUNC) { \
TYPE tmp = READFUNC; \
if (VAR != tmp) { \
VAR = tmp; \
change = true; \
} }
void ConfigData::readEntries()
{
AppMap defApps;
defApps["Konsole"] = QKeySequence::fromString("Ctrl+Shift+V");
QString defPaste = QKeySequence(QKeySequence::Paste).toString();
bool change = false;
CHECK(SnippetMap, snippets, readFromXmlFile());
CHECK(bool, autoPaste, readEntry("auto_paste", true));
CHECK(QKeySequence, pasteKey, QKeySequence::fromString(readEntry("paste_key", defPaste)));
CHECK(AppMap, specialApps, readKeySequenceMapEntry("special_apps", defApps));
if (change) {
emit changed(*this);
}
}
void ConfigData::writeEntries()
{
writeToXmlFile(snippets);
KConfigGroup::writeEntry("auto_paste", autoPaste);
KConfigGroup::writeEntry("paste_key", pasteKey.toString());
writeEntry("special_apps", specialApps);
}
void ConfigData::writeToXmlFile(SnippetMap value)
{
// Make XML
QDomDocument doc("text_snippets");
QDomElement root = doc.createElement("snippets");
doc.appendChild(doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""));
foreach (const QString &key, value.keys()) {
QDomElement snippet = doc.createElement("snippet");
snippet.setAttribute("name", key);
snippet.setAttribute("icon", value[key][Icon]);
QDomText txt = doc.createTextNode(value[key][Text]);
snippet.appendChild(txt);
root.appendChild(snippet);
}
doc.appendChild(root);
// Save to file
KSaveFile file(xmlFile);
if (file.open()) {
QTextStream stream(&file);
doc.save(stream, 2);
stream.flush();
}
file.finalize();
}
SnippetMap ConfigData::readFromXmlFile()
{
// Read file
SnippetMap result;
QDomDocument doc("text_snippets");
QFile file(xmlFile);
if (file.open(QIODevice::ReadOnly)) {
if (doc.setContent(&file)) {
// Parse xml
QDomElement node = doc.documentElement().firstChildElement();
while (!node.isNull()) {
if (node.tagName() == "snippet") {
result[node.attribute("name")] = QStringList() <<
node.attribute("icon") << node.firstChild().toText().data();
}
node = node.nextSiblingElement();
}
return result;
}
file.close();
}
result[i18n("Random Password")] = QStringList() << "object-unlocked" << "%{password(8)}";
result[i18n("Current Date")] = QStringList() << "office-calendar" << "%{date()}";
return result;
}
void ConfigData::writeEntry(const char *pKey, AppMap value)
{
QByteArray ba;
QDataStream ds(&ba, QIODevice::WriteOnly);
ds << value;
KConfigGroup::writeEntry(pKey, ba);
}
AppMap ConfigData::readKeySequenceMapEntry(const char *pKey, AppMap defaultValue)
{
AppMap result;
QByteArray ba = readEntry(pKey, QByteArray());
if (ba.isEmpty()) {
return defaultValue;
}
QDataStream ds(&ba, QIODevice::ReadOnly);
ds >> result;
return result;
}
#include "moc_configdata.cpp"

View file

@ -1,59 +0,0 @@
/*
* Copyright 2008 Petri Damsten <damu@iki.fi>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef CONFIGDATA_HEADER
#define CONFIGDATA_HEADER
#include <KConfigGroup>
#include <QKeySequence>
typedef QMap<QString, QStringList> SnippetMap;
typedef QMap<QString, QKeySequence> AppMap;
class ConfigData : public QObject, public KConfigGroup
{
Q_OBJECT
public:
enum DataIndex {Icon = 0, Text};
ConfigData();
virtual ~ConfigData();
ConfigData &operator=(const KConfigGroup &rhs);
void writeEntries();
void writeEntry(const char *pKey, AppMap value);
QMap<QString, QKeySequence> readKeySequenceMapEntry(const char *pKey,
AppMap defaultValue = AppMap());
void writeToXmlFile(SnippetMap value);
SnippetMap readFromXmlFile();
public slots:
void readEntries();
signals:
void changed(const ConfigData&);
public:
SnippetMap snippets;
bool autoPaste;
QKeySequence pasteKey;
AppMap specialApps;
QString xmlFile;
};
#endif // CONFIGDATA_HEADER

View file

@ -1,147 +0,0 @@
/*
* Copyright 2008 Petri Damsten <damu@iki.fi>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#include "list.h"
#include "sendkeys.h"
#include "configdata.h"
#include "pastemacroexpander.h"
#include <QTimer>
#include <QStandardItemModel>
#include <QApplication>
#include <QClipboard>
#include <KWindowSystem>
#include <KDebug>
#include <KGlobalSettings>
#include <KIconLoader>
#include <KIcon>
#include <Plasma/Delegate>
#include <Plasma/Theme>
ListForm::ListForm(QWidget *parent)
: QWidget(parent), m_hide(false), cfg(0)
{
setupUi(this);
setAttribute(Qt::WA_NoSystemBackground);
icon->setPixmap(KIcon("edit-paste").pixmap(KIconLoader::SizeSmall,
KIconLoader::SizeSmall));
Plasma::Delegate *delegate = new Plasma::Delegate;
delegate->setRoleMapping(Plasma::Delegate::SubTitleRole, SubTitleRole);
delegate->setRoleMapping(Plasma::Delegate::SubTitleMandatoryRole, SubTitleMandatoryRole);
treeView->setItemDelegate(delegate);
m_listModel = new QStandardItemModel(this);
treeView->setModel(m_listModel);
treeView->setFocusPolicy(Qt::NoFocus);
if (KGlobalSettings::singleClick()) {
connect(treeView, SIGNAL(clicked(QModelIndex)),
this, SLOT(clicked(QModelIndex)));
} else {
connect(treeView, SIGNAL(doubleClicked(QModelIndex)),
this, SLOT(clicked(QModelIndex)));
}
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(themeChanged()));
themeChanged();
}
ListForm::~ListForm()
{
}
void ListForm::setData(const ConfigData &data)
{
m_listModel->clear();
foreach (const QString &txt, data.snippets.keys()) {
QStandardItem *item = new QStandardItem();
QString tmp = data.snippets[txt][ConfigData::Text];
item->setData(txt, Qt::DisplayRole);
item->setData(false, SubTitleMandatoryRole);
item->setData(tmp.replace('\n', ' '), SubTitleRole);
item->setData(data.snippets[txt][ConfigData::Text], DataRole);
item->setData(KIcon(data.snippets[txt][ConfigData::Icon]), Qt::DecorationRole);
m_listModel->insertRow(0, item);
}
if (data.autoPaste) {
label->setText(i18n("Text &snippets (Click to paste text):"));
} else {
label->setText(i18n("Text &snippets (Click to copy text to clipboard):"));
}
cfg = &data;
}
void ListForm::clicked(const QModelIndex &index)
{
QList<WId> windows = KWindowSystem::stackingOrder();
KWindowInfo info;
static const QStringList classes =
QStringList() << "Plasma" << "Plasma-desktop" << "Plasmoidviewer";
// Don't paste to plasma windows
for (int i = windows.count() - 1; i >= 0; --i) {
info = KWindowSystem::windowInfo(windows[i], 0, NET::WM2WindowClass);
//kDebug() << info.windowClassClass();
if (classes.contains(info.windowClassClass())) {
if (i > 0) {
continue;
}
return;
}
break;
}
QString txt = m_listModel->data(index, DataRole).toString();
PasteMacroExpander::instance().expandMacros(txt);
//kDebug() << txt;
QApplication::clipboard()->setText(txt);
emit textCopied();
if (m_hide) {
hide();
}
if (cfg->autoPaste) {
// Macro expander might change windows focus so activate windows after that
KWindowSystem::activateWindow(info.win());
if (cfg->specialApps.contains(info.windowClassClass())) {
m_pasteKey = cfg->specialApps[info.windowClassClass()];
} else {
m_pasteKey = cfg->pasteKey;
}
QTimer::singleShot(200, this, SLOT(paste()));
}
treeView->selectionModel()->clear();
}
void ListForm::paste()
{
SendKeys::send(m_pasteKey);
}
void ListForm::themeChanged()
{
label->setStyleSheet(QString("QLabel{color:%1;}")
.arg(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor).name()));
setStyleSheet(QString(".ListForm{background-color:%1;}")
.arg(Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor).name()));
}
void ListForm::setHideAfterClick(bool hide)
{
m_hide = hide;
}
#include "moc_list.cpp"

View file

@ -1,61 +0,0 @@
/*
* Copyright 2008 Petri Damsten <damu@iki.fi>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef LIST_HEADER
#define LIST_HEADER
#include <Plasma/Dialog>
#include "ui_list.h"
#include <QStandardItemModel>
class ConfigData;
#include <QWidget>
class ListForm : public QWidget, public Ui::ListForm
{
Q_OBJECT
public:
enum SpecificRoles {
DataRole = Qt::UserRole + 1,
SubTitleRole,
SubTitleMandatoryRole
};
ListForm(QWidget *parent = 0);
virtual ~ListForm();
void setHideAfterClick(bool hide);
public slots:
void setData(const ConfigData &data);
protected slots:
void clicked(const QModelIndex &index);
void paste();
void themeChanged();
signals:
void textCopied();
private:
QStandardItemModel *m_listModel;
bool m_hide;
QKeySequence m_pasteKey;
const ConfigData *cfg;
};
#endif

View file

@ -1,56 +0,0 @@
<ui version="4.0" >
<class>ListForm</class>
<widget class="QWidget" name="ListForm" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout" >
<property name="margin" >
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" >
<item>
<widget class="QLabel" name="icon" >
<property name="text" >
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text" >
<string/>
</property>
<property name="buddy" >
<cstring>treeView</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTreeView" name="treeView" >
<property name="rootIsDecorated" >
<bool>false</bool>
</property>
<property name="headerHidden" >
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<connections/>
</ui>

View file

@ -1,126 +0,0 @@
/*
* Copyright 2008 Petri Damsten <damu@iki.fi>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#include "paste.h"
#include "list.h"
#include "snippetconfig.h"
#include "autopasteconfig.h"
#include <QGraphicsLinearLayout>
#include <QGraphicsProxyWidget>
#include <QTimer>
#include <KIcon>
#include <KIconLoader>
#include <KColorScheme>
#include <KConfigDialog>
#include <Plasma/IconWidget>
#include <Plasma/Containment>
#include <Plasma/Theme>
Paste::Paste(QObject *parent, const QVariantList &args)
: Plasma::PopupApplet(parent, args), m_list(0), m_snippetConfig(0)
{
setHasConfigurationInterface(true);
setAspectRatioMode(Plasma::IgnoreAspectRatio);
resize(200, 300);
setPopupIcon("edit-paste");
}
Paste::~Paste()
{
m_list->deleteLater();
m_list = 0;
}
void Paste::init()
{
cfg = globalConfig();
m_list = new ListForm;
connect(&cfg, SIGNAL(changed(ConfigData)), m_list, SLOT(setData(ConfigData)));
connect(m_list, SIGNAL(textCopied()), this, SLOT(showOk()));
m_list->setData(cfg);
}
void Paste::createConfigurationInterface(KConfigDialog *parent)
{
m_snippetConfig = new SnippetConfig;
connect(&cfg, SIGNAL(changed(ConfigData)),
m_snippetConfig, SLOT(setData(ConfigData)));
m_snippetConfig->setData(cfg);
m_autoPasteConfig = new AutoPasteConfig;
connect(&cfg, SIGNAL(changed(ConfigData)),
m_autoPasteConfig, SLOT(setData(ConfigData)));
m_autoPasteConfig->setData(cfg);
parent->addPage(m_snippetConfig, i18n("Texts"), "accessories-text-editor");
parent->addPage(m_autoPasteConfig, i18n("Automatic Paste"), "edit-paste");
connect(parent, SIGNAL(applyClicked()), this, SLOT(configAccepted()));
connect(parent, SIGNAL(okClicked()), this, SLOT(configAccepted()));
connect(m_snippetConfig->textEdit, SIGNAL(textChanged()), parent, SLOT(settingsModified()));
connect(m_snippetConfig->nameEdit, SIGNAL(textChanged(QString)), parent, SLOT(settingsModified()));
connect(m_snippetConfig->list, SIGNAL(itemSelectionChanged()), parent, SLOT(settingsModified()));
connect(m_snippetConfig->addMacroButton, SIGNAL(toggled(bool)), parent, SLOT(settingsModified()));
connect(m_snippetConfig->addButton, SIGNAL(toggled(bool)), parent, SLOT(settingsModified()));
connect(m_snippetConfig->removeButton, SIGNAL(toggled(bool)), parent, SLOT(settingsModified()));
connect(m_autoPasteConfig->autoPasteCheckBox, SIGNAL(toggled(bool)), parent, SLOT(settingsModified()));
connect(m_autoPasteConfig->addButton, SIGNAL(clicked()), parent, SLOT(settingsModified()));
connect(m_autoPasteConfig->editButton, SIGNAL(clicked()), parent, SLOT(settingsModified()));
connect(m_autoPasteConfig->removeButton, SIGNAL(clicked(bool)), parent, SLOT(settingsModified()));
connect(m_autoPasteConfig->pasteKeyButton, SIGNAL(keySequenceChanged(QKeySequence)), parent, SLOT(settingsModified()));
connect(m_autoPasteConfig->appsTreeView->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
parent, SLOT(settingsModified()));
}
void Paste::configAccepted()
{
m_snippetConfig->getData(&cfg);
m_autoPasteConfig->getData(&cfg);
m_list->setData(cfg);
cfg.writeEntries();
emit configNeedsSaving();
}
void Paste::configChanged()
{
cfg.readEntries();
}
void Paste::showOk()
{
// Show ok icon like in DeviceNotifier
setPopupIcon("dialog-ok");
m_list->icon->setPixmap(KIcon("dialog-ok").pixmap(KIconLoader::SizeSmall,
KIconLoader::SizeSmall));
QTimer::singleShot(2000, this, SLOT(resetIcon()));
}
void Paste::resetIcon()
{
setPopupIcon("edit-paste");
m_list->icon->setPixmap(KIcon("edit-paste").pixmap(KIconLoader::SizeSmall,
KIconLoader::SizeSmall));
}
QWidget *Paste::widget()
{
return m_list;
}
#include "moc_paste.cpp"

View file

@ -1,57 +0,0 @@
/*
* Copyright 2008 Petri Damsten <damu@iki.fi>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef PASTE_HEADER
#define PASTE_HEADER
#include <configdata.h>
#include <Plasma/PopupApplet>
class ListForm;
class SnippetConfig;
class AutoPasteConfig;
namespace Plasma {
class Icon;
}
class Paste : public Plasma::PopupApplet
{
Q_OBJECT
public:
Paste(QObject *parent, const QVariantList &args);
~Paste();
virtual void init();
virtual void createConfigurationInterface(KConfigDialog *parent);
virtual QWidget *widget();
public slots:
void showOk();
void configAccepted();
void resetIcon();
void configChanged();
private:
ListForm *m_list;
SnippetConfig *m_snippetConfig;
AutoPasteConfig *m_autoPasteConfig;
ConfigData cfg;
};
K_EXPORT_PLASMA_APPLET(paste, Paste)
#endif

View file

@ -1,185 +0,0 @@
/*
* Copyright 2008 Petri Damsten <damu@iki.fi>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#include "pastemacroexpander.h"
#include <QTextCodec>
#include <QFile>
#include <QProcess>
#include <QtCore/qdatetime.h>
#include <KIO/NetAccess>
#include <KDebug>
#include <KLocale>
#include <KMessageBox>
#include <KRandom>
class PasteMacroExpanderSingleton
{
public:
PasteMacroExpander instance;
};
K_GLOBAL_STATIC(PasteMacroExpanderSingleton, g_pasteMacroExpander)
PasteMacroExpander& PasteMacroExpander::instance()
{
return g_pasteMacroExpander->instance;
}
PasteMacroExpander::PasteMacroExpander(QWidget *parent) : QObject(parent)
{
m_macros["exec"] = QVariantList()
<< i18n("Execute Command And Get Output")
<< QVariant::fromValue(MacroParam(i18n("Command"), MacroParam::Url));
m_macros["date"] = QVariantList()
<< i18n("Current Date");
m_macros["time"] = QVariantList()
<< i18n("Current Time");
m_macros["file"] = QVariantList()
<< i18n("Insert File Contents")
<< QVariant::fromValue(MacroParam(i18n("File"), MacroParam::Url));
m_macros["password"] = QVariantList()
<< i18n("Random Password")
<< QVariant::fromValue(MacroParam(i18n("Character count"), MacroParam::Int))
<< QVariant::fromValue(MacroParam(i18n("Lowercase letters"), MacroParam::Boolean))
<< QVariant::fromValue(MacroParam(i18n("Uppercase letters"), MacroParam::Boolean))
<< QVariant::fromValue(MacroParam(i18n("Numbers"), MacroParam::Boolean))
<< QVariant::fromValue(MacroParam(i18n("Symbols"), MacroParam::Boolean));
}
QMap<QString, QVariantList> PasteMacroExpander::macros()
{
return m_macros;
}
bool PasteMacroExpander::expandMacro(const QString &str, QStringList &ret)
{
QString func;
QString args;
QString result;
int n;
if ((n = str.indexOf('(')) > 0) {
func = str.left(n).trimmed();
int m = str.lastIndexOf(')');
args = str.mid(n + 1, m - n - 1);
} else {
func = str.trimmed();
}
//kDebug() << str << func << args;
if (m_macros.keys().contains(func)) {
QMetaObject::invokeMethod(this, func.toAscii(), Qt::DirectConnection,
Q_RETURN_ARG(QString, result),
Q_ARG(QString, args));
ret += result;
return true;
}
return false;
}
QString PasteMacroExpander::date(const QString& args)
{
Q_UNUSED(args)
return QDate::currentDate().toString();
}
QString PasteMacroExpander::time(const QString& args)
{
Q_UNUSED(args)
return QTime::currentTime().toString();
}
QString PasteMacroExpander::exec(const QString& args)
{
QProcess process;
process.start(args, QProcess::ReadOnly);
process.waitForFinished();
QByteArray ba = process.readAll();
return QTextCodec::codecForLocale()->toUnicode(ba);
}
QString PasteMacroExpander::file(const QString& args)
{
QString tmpFile;
QString txt;
QWidget *p = qobject_cast<QWidget*>(parent());
if (KIO::NetAccess::download(args, tmpFile, p)) {
QFile file(tmpFile);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
txt = QTextCodec::codecForLocale()->toUnicode(file.readAll());
} else {
KMessageBox::error(p, i18n("Could not open file: %1",tmpFile));
}
KIO::NetAccess::removeTempFile(tmpFile);
} else {
KMessageBox::error(p, KIO::NetAccess::lastErrorString());
}
return txt;
}
QString PasteMacroExpander::password(const QString& args)
{
QStringList a = args.split(',', QString::SkipEmptyParts);
static QStringList characterSets = QStringList()
<< "abcdefghijklmnopqrstuvwxyz"
<< "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
<< "0123456789"
<< "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
int charCount = 8;
QString chars;
QString result;
if (a.count() > 0) {
charCount = qMax(a[0].trimmed().toInt(), 8);
}
if (a.count() > 1) {
chars += (a[1].trimmed() == "true") ? characterSets[0] : "";
}
if (a.count() > 2) {
chars += (a[2].trimmed() == "true") ? characterSets[1] : "";
}
if (a.count() > 3) {
chars += (a[3].trimmed() == "true") ? characterSets[2] : "";
}
if (a.count() > 4) {
chars += (a[4].trimmed() == "true") ? characterSets[3] : "";
}
// no character set arguments
if (chars.isEmpty()) {
chars = characterSets[0];
chars += characterSets[1];
chars += characterSets[2];
}
const int setSize = chars.count();
for (int i = 0; i < charCount; ++i) {
result += chars[KRandom::randomMax(setSize)];
}
//kDebug() << result;
return result;
}
#include "moc_pastemacroexpander.cpp"

View file

@ -1,68 +0,0 @@
/*
* Copyright 2008 Petri Damsten <damu@iki.fi>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef PASTEMACROEXPANDER_HEADER
#define PASTEMACROEXPANDER_HEADER
#include <KWordMacroExpander>
#include <QStringList>
#include <QtCore/qvariant.h>
#include <QHash>
class MacroParam
{
public:
enum ParamType {
String = 0,
Int,
Boolean,
Url
};
explicit MacroParam(const QString& n = QString(), ParamType t = String) : name(n), type(t) {};
QString name;
ParamType type;
};
Q_DECLARE_METATYPE(MacroParam)
class PasteMacroExpander : public QObject, public KWordMacroExpander
{
Q_OBJECT
public:
static PasteMacroExpander& instance();
QMap<QString, QVariantList> macros();
protected:
PasteMacroExpander(QWidget* parent = 0);
friend class PasteMacroExpanderSingleton;
virtual bool expandMacro(const QString &str, QStringList &ret);
protected slots:
QString exec(const QString& args);
QString date(const QString& args);
QString time(const QString& args);
QString file(const QString& args);
QString password(const QString& args);
private:
QMap<QString, QVariantList> m_macros;
};
#endif // PASTEMACROEXPANDER_HEADER

View file

@ -1,130 +0,0 @@
[Desktop Entry]
Encoding=UTF-8
Name=Paste
Name[ar]=ألصق
Name[ast]=Apegar
Name[bs]=Umetni
Name[ca]=Enganxa
Name[ca@valencia]=Apega
Name[cs]=Vložit
Name[da]=Indsæt
Name[de]=Einfügen
Name[el]=Επικόλληση
Name[en_GB]=Paste
Name[eo]=Glui
Name[es]=Pegar
Name[et]=Asetamine
Name[eu]=Itsatsi
Name[fi]=Liitä
Name[fr]=Coller
Name[ga]=Greamaigh
Name[gl]=Pegar
Name[he]=הדבק
Name[hr]=Zalijepi
Name[hu]=Beillesztés
Name[is]=Líma
Name[it]=Incolla
Name[ja]=Paste
Name[kk]=Енгізу
Name[km]=
Name[ko]=
Name[ku]=Pê Ve Bike
Name[lt]=Padėti
Name[lv]=Ielīmēt
Name[mr]=ि
Name[nb]=Lim inn
Name[nds]=Infögen
Name[nl]=Plakken
Name[nn]=Tekstbitar
Name[pa]=
Name[pl]=Wklej
Name[pt]=Colar
Name[pt_BR]=Colar
Name[ro]=Lipește
Name[ru]=Вставка текста
Name[sk]=Vložiť
Name[sl]=Prilepi
Name[sq]=Ngjit
Name[sr]=налепљивање
Name[sr@ijekavian]=наљепљивање
Name[sr@ijekavianlatin]=naljepljivanje
Name[sr@latin]=nalepljivanje
Name[sv]=Klistra in
Name[th]=
Name[tr]=Yapıştır
Name[ug]=چاپلا
Name[uk]=Вставка
Name[wa]=Aclaper
Name[x-test]=xxPastexx
Name[zh_CN]=
Name[zh_TW]=
Comment=Paste text snippets
Comment[ar]=ألصق قطع من النص
Comment[ast]=Apegar fragmentos de testu
Comment[bs]=Umeće dijelove teksta
Comment[ca]=Enganxa retalls de text
Comment[ca@valencia]=Apega retalls de text
Comment[cs]=Vložit textové úryvky
Comment[da]=Indsætter tekststbidder.
Comment[de]=Textbaustein einfügen
Comment[el]=Επικόλληση δειγμάτων κειμένου
Comment[en_GB]=Paste text snippets
Comment[es]=Pegar fragmentos de texto
Comment[et]=Tekstijuppide asetamine
Comment[eu]=Itsatsi testu zatiak
Comment[fi]=Liitä tekstipalasia
Comment[fr]=Colle des fragments de texte
Comment[ga]=Greamaigh blúirí téacs
Comment[gl]=Pega retallos de texto
Comment[he]=מעתיק קטעי טקסט שונים
Comment[hr]=Zalijepi tekstualne svaštice
Comment[hu]=Szövegdarabok beillesztése
Comment[is]=Líma textabrot
Comment[it]=Incolla frammenti di testo
Comment[ja]=
Comment[kk]=Мәтін үзінділерін енгізу
Comment[km]= snippets
Comment[ko]=
Comment[ku]=Parî yên nivîsê pêve bike
Comment[lt]=Padėti teksto gabalėlius
Comment[lv]=Ielīmēt teksta fragmentus
Comment[mr]= ि ि
Comment[nb]=Lim inn tekstbiter
Comment[nds]=Textsnippels infögen
Comment[nl]=Tekstfragmenten plakken
Comment[nn]=Lim inn tekstbitar
Comment[pa]= ਿ
Comment[pl]=Wklejanie fragmentów tekstu
Comment[pt]=Colar excertos de texto
Comment[pt_BR]=Cola trechos de texto
Comment[ro]=Lipește frînturi de text
Comment[ru]=Вставка маленьких текстовых шаблонов
Comment[sk]=Vloženie textových úryvkov
Comment[sl]=Prilepite besedilne izrezke
Comment[sr]=Налепљујте исечке текста
Comment[sr@ijekavian]=Наљепљујте исјечке текста
Comment[sr@ijekavianlatin]=Naljepljujte isječke teksta
Comment[sr@latin]=Nalepljujte isečke teksta
Comment[sv]=Klistra in textsnuttar
Comment[th]=
Comment[tr]=Metin parçacıklarını yapıştırın
Comment[ug]=تېكىست پۇرۇچلىرىنى چاپلايدۇ
Comment[uk]=Вставка уривків тексту
Comment[wa]=Aclaper des bokets d' tecse
Comment[x-test]=xxPaste text snippetsxx
Comment[zh_CN]=
Comment[zh_TW]=
Type=Service
Icon=edit-paste
ServiceTypes=Plasma/Applet
X-KDE-Library=plasma_applet_paste
X-KDE-PluginInfo-Author=Petri Damstén
X-KDE-PluginInfo-Email=damu@iki.fi
X-KDE-PluginInfo-Name=paste
X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-Website=
X-KDE-PluginInfo-Category=Utilities
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true

View file

@ -1,78 +0,0 @@
/*
* Copyright 2008 Petri Damsten <damu@iki.fi>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#include "sendkeys.h"
#include <KGlobal>
#include <KDebug>
#include <QMap>
#include <QKeySequence>
#include <QX11Info>
#include <X11/Xlib.h>
#include <X11/keysym.h>
void SendKeys::send(const QKeySequence &ks)
{
for (uint i = 0; i < ks.count(); ++i) {
SendKeys::send(ks[i]);
}
}
void SendKeys::send(uint k)
{
Display *dsp = QX11Info::display();
uint keycode = k & 0x01FFFFFF;
XKeyEvent event;
Window currentFocus;
int focusState;
if (keycode < Qt::Key_Space || keycode > Qt::Key_ydiaeresis) {
return;
}
keycode = XKeysymToKeycode(dsp, keycode);
event.display = dsp;
XGetInputFocus(dsp, &currentFocus, &focusState);
event.window = currentFocus;
event.root = DefaultRootWindow(dsp);
event.subwindow = None;
event.time = CurrentTime;
event.x = 0;
event.y = 0;
event.x_root = 0;
event.y_root = 0;
event.same_screen = true;
event.type = KeyPress;
event.keycode = keycode;
event.state = 0;
if (k & Qt::ALT) {
event.state |= Mod1Mask;
}
if (k & Qt::CTRL) {
event.state |= ControlMask;
}
if (k & Qt::META) {
event.state |= Mod1Mask;
}
if (k & Qt::SHIFT) {
event.state |= ShiftMask;
}
XSendEvent(dsp, InputFocus, false, KeyPressMask, (XEvent *)&event);
event.type = KeyRelease;
event.time = CurrentTime;
XSendEvent(dsp, InputFocus, false, KeyReleaseMask, (XEvent *)&event);
}

View file

@ -1,30 +0,0 @@
/*
* Copyright 2008 Petri Damsten <damu@iki.fi>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SENDKEYS_HEADER
#define SENDKEYS_HEADER
#include <QKeySequence>
class SendKeys
{
public:
static void send(const QKeySequence &ks);
static void send(uint k);
};
#endif

View file

@ -1,167 +0,0 @@
/*
* Copyright 2008 Petri Damsten <damu@iki.fi>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#include "snippetconfig.h"
#include "configdata.h"
#include "addmacro.h"
#include <KDebug>
SnippetConfig::SnippetConfig(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
addButton->setIcon(KIcon("list-add"));
removeButton->setIcon(KIcon("list-remove"));
addMacroButton->setIcon(KIcon("system-run"));
connect(addButton, SIGNAL(clicked()), this, SLOT(addClicked()));
connect(removeButton, SIGNAL(clicked()), this, SLOT(removeClicked()));
connect(addMacroButton, SIGNAL(clicked()), this, SLOT(addMacroClicked()));
connect(list, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
this, SLOT(currentItemChanged(QListWidgetItem*,QListWidgetItem*)));
connect(list, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
this, SLOT(enableWidgets()));
connect(nameEdit, SIGNAL(textChanged(QString)),
this, SLOT(nameChanged(QString)));
connect(textEdit, SIGNAL(textChanged()), this, SLOT(textChanged()));
connect(iconButton, SIGNAL(iconChanged(QString)),
this, SLOT(iconChanged(QString)));
enableWidgets();
}
SnippetConfig::~SnippetConfig()
{
}
void SnippetConfig::setData(const ConfigData &data)
{
list->clear();
foreach (const QString &txt, data.snippets.keys()) {
if (!txt.isEmpty() || !data.snippets[txt].isEmpty()) {
QListWidgetItem *item = new QListWidgetItem(txt, list);
item->setData(TextRole, data.snippets[txt][ConfigData::Text]);
item->setData(IconNameRole, data.snippets[txt][ConfigData::Icon]);
item->setData(Qt::DecorationRole, KIcon(data.snippets[txt][ConfigData::Icon]));
}
}
}
void SnippetConfig::getData(ConfigData *data)
{
QListWidgetItem *current = list->currentItem();
if (current) {
current->setData(Qt::UserRole, textEdit->toPlainText());
}
data->snippets.clear();
for (int i = 0; i < list->count(); ++i) {
QListWidgetItem *item = list->item(i);
if (!item->text().isEmpty() || !item->data(TextRole).toString().isEmpty()) {
data->snippets[item->text()] = QStringList() <<
item->data(IconNameRole).toString() << item->data(TextRole).toString();
}
}
}
void SnippetConfig::addClicked()
{
newItem();
nameEdit->setFocus();
nameEdit->selectAll();
}
void SnippetConfig::addMacroClicked()
{
QPointer<AddMacro> dlg = new AddMacro(this);
if (dlg->exec() == QDialog::Accepted) {
textEdit->insertPlainText(dlg->macro());
}
delete dlg;
}
void SnippetConfig::removeClicked()
{
delete list->currentItem();
}
void SnippetConfig::currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
{
if (previous) {
previous->setData(TextRole, textEdit->toPlainText());
previous->setData(IconNameRole, iconButton->icon());
}
if (current) {
nameEdit->setText(current->text());
textEdit->setPlainText(current->data(TextRole).toString());
iconButton->setIcon(current->data(IconNameRole).toString());
} else {
nameEdit->blockSignals(true);
textEdit->blockSignals(true);
nameEdit->setText("");
textEdit->setPlainText("");
iconButton->setIcon("");
nameEdit->blockSignals(false);
textEdit->blockSignals(false);
}
}
void SnippetConfig::nameChanged(const QString& name)
{
QListWidgetItem *current = list->currentItem();
if (!current) {
current = newItem(QString(), name);
}
current->setText(name);
}
void SnippetConfig::textChanged()
{
QListWidgetItem *current = list->currentItem();
if (!current) {
newItem(textEdit->toPlainText());
}
}
void SnippetConfig::enableWidgets()
{
removeButton->setEnabled(list->selectionModel()->currentIndex().isValid());
iconButton->setEnabled(list->selectionModel()->currentIndex().isValid());
}
void SnippetConfig::iconChanged(const QString &icon)
{
QListWidgetItem *current = list->currentItem();
if (current) {
current->setData(IconNameRole, icon);
current->setData(Qt::DecorationRole, KIcon(icon));
}
}
QListWidgetItem *SnippetConfig::newItem(const QString& text, const QString& name)
{
QListWidgetItem *item = new QListWidgetItem(name, list);
item->setData(TextRole, text);
item->setData(IconNameRole, "edit-paste");
item->setData(Qt::DecorationRole, KIcon("edit-paste"));
list->setCurrentItem(item);
QTextCursor tc = textEdit->textCursor();
tc.setPosition(text.size());
textEdit->setTextCursor(tc);
return item;
}
#include "moc_snippetconfig.cpp"

View file

@ -1,56 +0,0 @@
/*
* Copyright 2008 Petri Damsten <damu@iki.fi>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef SNIPPETCONFIG_HEADER
#define SNIPPETCONFIG_HEADER
#include <QWidget>
#include <KLocale>
#include "ui_snippetconfig.h"
#include <QListWidgetItem>
class ConfigData;
class SnippetConfig : public QWidget, public Ui::SnippetConfig
{
Q_OBJECT
enum SnippetRoles { TextRole = Qt::UserRole, IconNameRole };
public:
SnippetConfig(QWidget *parent = 0);
virtual ~SnippetConfig();
void getData(ConfigData *data);
public slots:
void setData(const ConfigData &data);
protected slots:
void addClicked();
void removeClicked();
void addMacroClicked();
void currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
void nameChanged(const QString& name);
void textChanged();
void enableWidgets();
void iconChanged(const QString &icon);
protected:
QListWidgetItem *newItem(const QString& text = QString(),
const QString& name = i18n("Untitled"));
};
#endif // SNIPPETCONFIG_HEADER

View file

@ -1,144 +0,0 @@
<ui version="4.0" >
<author>Petri Damstén</author>
<class>SnippetConfig</class>
<widget class="QWidget" name="SnippetConfig" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>562</width>
<height>433</height>
</rect>
</property>
<property name="windowTitle" >
<string>Configure Paste Snippets</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3" >
<item>
<layout class="QVBoxLayout" name="verticalLayout_2" >
<item>
<widget class="QLabel" name="textsLabel" >
<property name="text" >
<string>&amp;Texts:</string>
</property>
<property name="buddy" >
<cstring>list</cstring>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="list" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Expanding" hsizetype="Preferred" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3" >
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" >
<item>
<layout class="QVBoxLayout" name="verticalLayout" >
<item>
<widget class="QLabel" name="nameLabel" >
<property name="text" >
<string>&amp;Name:</string>
</property>
<property name="buddy" >
<cstring>nameEdit</cstring>
</property>
</widget>
</item>
<item>
<widget class="KLineEdit" name="nameEdit" />
</item>
</layout>
</item>
<item>
<widget class="KIconButton" name="iconButton" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="textLabel" >
<property name="text" >
<string>Text to be &amp;pasted:</string>
</property>
<property name="buddy" >
<cstring>textEdit</cstring>
</property>
</widget>
</item>
<item>
<widget class="KTextEdit" name="textEdit" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="lineWrapMode" >
<enum>KTextEdit::NoWrap</enum>
</property>
<property name="acceptRichText" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="addMacroButton" >
<property name="text" >
<string>&amp;Add Macro...</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" >
<item>
<widget class="QPushButton" name="addButton" >
<property name="text" >
<string>&amp;Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeButton" >
<property name="text" >
<string>&amp;Remove</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KIconButton</class>
<extends>QPushButton</extends>
<header>kicondialog.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>list</tabstop>
<tabstop>nameEdit</tabstop>
<tabstop>iconButton</tabstop>
<tabstop>addButton</tabstop>
<tabstop>removeButton</tabstop>
</tabstops>
<connections/>
</ui>