new way for sending data

plasmoid has an externalData signal, and will be used like
Connections {
        target: plasmoid
        onExternalData: {
            if (mimetype === "text/plain") {
                noteText.text = data
            }
        }
    }

a notes example applet describes its use
This commit is contained in:
Marco Martin 2013-09-20 12:59:35 +02:00
parent 3656c416f2
commit b14c23bed0
8 changed files with 91 additions and 24 deletions

View File

@ -1,11 +1,12 @@
plasma_install_package(config org.kde.example.configuration)
plasma_install_package(localegallery org.kde.example.locale)
plasma_install_package(notes org.kde.example.notes)
plasma_install_package(widgetgallery org.kde.example.widgetgallery)
plasma_install_package(qmltasks org.kde.example.tasks)
plasma_install_package(windowthumbnails org.kde.example.windowthumbnails)
plasma_install_package(conditionalloader org.kde.example.conditionalloader)
plasma_install_package(testcomponents org.kde.example.testcomponents)
plasma_install_package(testshaders org.kde.example.testshaders)
plasma_install_package(helloworld org.kde.examples.helloworld)
plasma_install_package(compactrepresentation org.kde.examples.compactrepresentation)
plasma_install_package(helloworld org.kde.example.helloworld)
plasma_install_package(compactrepresentation org.kde.example.compactrepresentation)

View File

@ -1,2 +0,0 @@
[General]
text/plain=Test

View File

@ -23,4 +23,3 @@ X-KDE-PluginInfo-Name=org.kde.example.configuration
X-KDE-PluginInfo-Version=
X-KDE-PluginInfo-Website=
X-Plasma-MainScript=ui/main.qml
X-Plasma-DropMimeTypes=text/plain

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name=""/>
<group name="General">
<entry name="Text" type="String">
<label>Notes text</label>
<default>Hello!</default>
</entry>
</group>
</kcfg>

View File

@ -0,0 +1,45 @@
/*
* Copyright 2013 Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 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 Library 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.
*/
import QtQuick 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
PlasmaCore.SvgItem {
property int minimumWidth: 150
property int minimumHeight: 150
svg: PlasmaCore.Svg("widgets/notes")
elementId: "yellow-notes"
Connections {
target: plasmoid
onExternalData: {
if (mimetype === "text/plain") {
noteText.text = data
}
}
}
PlasmaComponents.TextArea {
id: noteText
anchors.fill: parent
text: plasmoid.configuration.Text
onTextChanged: plasmoid.configuration.Text = text
}
}

View File

@ -0,0 +1,19 @@
[Desktop Entry]
Comment=Example on how to manage Drop data
Encoding=UTF-8
Keywords=
Name=Example notes
Type=Service
Icon=knotes
X-KDE-ParentApp=
X-KDE-PluginInfo-Author=Marco Martin
X-KDE-PluginInfo-Category=Miscellaneous
X-KDE-PluginInfo-Email=mart@kde.org
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-Name=org.kde.example.notes
X-KDE-PluginInfo-Version=
X-KDE-PluginInfo-Website=
X-KDE-ServiceTypes=Plasma/Applet
X-Plasma-API=declarativeappletscript
X-Plasma-MainScript=ui/main.qml
X-Plasma-DropMimeTypes=text/plain

View File

@ -281,6 +281,13 @@ public:
qreal implicitHeight() const;
Q_SIGNALS:
/**
* somebody else, usually the containment sent some data to the applet
* @param mimetype the mime type of the data such as text/plain
* @param data either the actual data or an URL representing it
*/
void externalData(const QString &mimetype, const QVariant &data);
void releaseVisualFocus();
void configNeedsSaving();

View File

@ -220,25 +220,8 @@ void ContainmentInterface::setAppletArgs(Plasma::Applet *applet, const QString &
return;
}
KConfig argsConf(applet->package().filePath("config", "argsrc"));
foreach (const QString &group, argsConf.groupList()) {
KConfigGroup cg(&argsConf, group);
if (cg.hasKey(mimetype)) {
QString key = cg.readEntry(mimetype);
Plasma::ConfigLoader *config = applet->configScheme();
if (config) {
KConfigSkeletonItem *item = config->findItemByName(key);
if (item) {
item->setProperty(data);
config->blockSignals(true);
config->writeConfig();
config->blockSignals(false);
m_appletScriptEngine->configNeedsSaving();
}
}
}
}
AppletInterface *appletInterface = applet->property("graphicObject").value<AppletInterface *>();
emit appletInterface->externalData(mimetype, data);
}
void ContainmentInterface::processMimeData(QMimeData *mimeData, int x, int y)