support for setting a wallpaper trough drag and drop

This commit is contained in:
Marco Martin 2013-09-10 17:57:51 +02:00
parent d101966f91
commit 33dae6b18c
7 changed files with 143 additions and 20 deletions

View File

@ -43,5 +43,6 @@ target_link_libraries(plasma_appletscript_declarative
install(TARGETS plasma_appletscript_declarative DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES data/plasma-scriptengine-applet-declarative.desktop DESTINATION ${SERVICES_INSTALL_DIR})
install(FILES data/plasma-wallpaper.desktop DESTINATION ${SERVICES_INSTALL_DIR})

View File

@ -0,0 +1,89 @@
[Desktop Entry]
Type=ServiceType
X-KDE-ServiceType=Plasma/Wallpaper
Comment=Plasma wallpaper
Comment[ar]=خلفية شاشة بلازما
Comment[as]=Plasma wallpaper
Comment[ast]=Fondu d'escritoriu de Plasma
Comment[be@latin]=Špalery Plasma
Comment[bg]=Тапет за Plasma
Comment[bn]=
Comment[bn_IN]=Plasma -
Comment[bs]=Plazma tapet
Comment[ca]=Fons d'escriptori del Plasma
Comment[ca@valencia]=Fons d'escriptori del Plasma
Comment[cs]=Tapeta Plasma
Comment[da]=Plasma-baggrundsbillede
Comment[de]=Plasma-Hintergrundbild
Comment[el]=Ταπετσαρία plasma
Comment[en_GB]=Plasma wallpaper
Comment[es]=Fondo de escritorio para Plasma
Comment[et]=Plasma taustapilt
Comment[eu]=Plasma horma papera
Comment[fi]=Plasma-taustakuva
Comment[fr]=Fond d'écran Plasma
Comment[fy]=Plasma eftergrûnôfbylding
Comment[ga]=Cúlbhrat Plasma
Comment[gl]=Fondo de escritorio do Plasma
Comment[gu]=
Comment[he]=תמונת רקע של Plasma
Comment[hi]=
Comment[hne]=
Comment[hr]=Plasmina pozadinska slika
Comment[hsb]=Tapeta za Plasma
Comment[hu]=Plasma háttérkép
Comment[hy]=Պլազմա պաստառ
Comment[ia]=Tapete de papiro de Plasma
Comment[id]=Gambar belakang Plasma
Comment[is]=Plasma veggfóður
Comment[it]=Sfondo Plasma
Comment[ja]=Plasma
Comment[kk]=Plasma тұсқағазы
Comment[km]=
Comment[kn]= ಿ ಿ ( )
Comment[ko]=Plasma
Comment[ku]=Wêne-rûerdê Plasma
Comment[lt]=Plasma apmušalas
Comment[lv]=Plasma ekrāntapete
Comment[mai]=
Comment[ml]= ി
Comment[mr]=
Comment[nb]=Plasma tapet
Comment[nds]=Plasma-Achtergrundbild
Comment[nl]=Plasma-bureaubladachtergrond
Comment[nn]=Plasmabakgrunn
Comment[pa]=
Comment[pl]=Tapeta Plazmy
Comment[pt]=Papel de parede do Plasma
Comment[pt_BR]=Papel de parede do Plasma
Comment[ro]=Fundal Plasma
Comment[ru]=Обои Plasma
Comment[se]=Plasma-duogášgovva
Comment[si]=Plasma
Comment[sk]=Tapeta Plasma
Comment[sl]=Slika ozadja za Plasmo
Comment[sq]=Tapetat plazma
Comment[sr]=Плазма тапет
Comment[sr@ijekavian]=Плазма тапет
Comment[sr@ijekavianlatin]=Plasma tapet
Comment[sr@latin]=Plasma tapet
Comment[sv]=Plasma skrivbordsunderlägg
Comment[ta]=ி ிிி
Comment[tg]=Тасвири заминаи Plasma
Comment[th]=
Comment[tr]=Plasma duvar kağıdı
Comment[tt]=Плазма обое
Comment[ug]=Plasma تام قەغىزى
Comment[uk]=Тло стільниці Плазми
Comment[vi]=Hình nn Plasma
Comment[wa]=Tapisreye di Plasma
Comment[x-test]=xxPlasma wallpaperxx
Comment[zh_CN]=Plasma
Comment[zh_TW]=Plasma
[PropertyDef::X-Plasma-FormFactors]
Type=QStringList
[PropertyDef::X-Plasma-DropMimeTypes]
Type=QStringList

View File

@ -402,13 +402,14 @@ void ContainmentInterface::mimeTypeRetrieved(KIO::Job *job, const QString &mimet
appletList << Plasma::PluginLoader::self()->listAppletInfoForMimeType(mimetype);
KPluginInfo::List wallpaperList;
//TODO: how restore wallpaper dnd?
/*if (drawWallpaper) {
if (wallpaper && wallpaper->supportsMimetype(mimetype)) {
wallpaperList << wallpaper->d->wallpaperDescription;
if (drawWallpaper()) {
if (m_wallpaperInterface && m_wallpaperInterface->supportsMimetype(mimetype)) {
wallpaperList << m_wallpaperInterface->package().metadata();
} else {
wallpaperList = Wallpaper::listWallpaperInfoForMimetype(mimetype);
wallpaperList = WallpaperInterface::listWallpaperInfoForMimetype(mimetype);
}
}*/
}
if (!appletList.isEmpty() || !wallpaperList.isEmpty()) {
choices->clear();
@ -426,7 +427,7 @@ void ContainmentInterface::mimeTypeRetrieved(KIO::Job *job, const QString &mimet
actionsToApplets.insert(action, info.pluginName());
qDebug() << info.pluginName();
}
actionsToApplets.insert(choices->addAction(i18n("Icon")), "icon");
actionsToApplets.insert(choices->addAction(i18n("Icon")), "org.kde.icon");
QHash<QAction *, QString> actionsToWallpapers;
if (!wallpaperList.isEmpty()) {
@ -462,17 +463,9 @@ void ContainmentInterface::mimeTypeRetrieved(KIO::Job *job, const QString &mimet
if (plugin.isEmpty()) {
//set wallpapery stuff
plugin = actionsToWallpapers.value(choice);
//TODO: wallpapers
/*
if (!wallpaper || plugin != wallpaper->pluginName()) {
qDebug() << "Wallpaper dropped:" << tjob->url();
q->setWallpaper(plugin);
if (m_wallpaperInterface && tjob->url().isValid()) {
m_wallpaperInterface->setUrl(tjob->url());
}
if (wallpaper) {
qDebug() << "Wallpaper dropped:" << tjob->url();
wallpaper->setUrls(KUrl::List() << tjob->url());
}*/
} else {
addApplet(actionsToApplets[choice], args, posi);
}
@ -482,7 +475,7 @@ void ContainmentInterface::mimeTypeRetrieved(KIO::Job *job, const QString &mimet
}
} else {
// we can at least create an icon as a link to the URL
addApplet("icon", args, posi);
addApplet("org.kde.icon", args, posi);
}
}

View File

@ -24,6 +24,8 @@
#include <kdeclarative/qmlobject.h>
#include <KActionCollection>
#include <KServiceTypeTrader>
#include <KDesktopFile>
#include <QDebug>
#include <QQmlExpression>
@ -55,6 +57,17 @@ WallpaperInterface::WallpaperInterface(ContainmentInterface *parent)
WallpaperInterface::~WallpaperInterface()
{}
KPluginInfo::List WallpaperInterface::listWallpaperInfoForMimetype(const QString &mimetype, const QString &formFactor)
{
QString constraint = QString("'%1' in [X-Plasma-DropMimeTypes]").arg(mimetype);
if (!formFactor.isEmpty()) {
constraint.append("[X-Plasma-FormFactors] ~~ '").append(formFactor).append("'");
}
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Wallpaper", constraint);
qDebug() << offers.count() << constraint;
return KPluginInfo::fromServices(offers);
}
Plasma::Package WallpaperInterface::package() const
{
@ -100,7 +113,7 @@ void WallpaperInterface::syncWallpaperPackage()
}
m_actions->clear();
m_pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/QmlWallpaper");
m_pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Wallpaper");
m_pkg.setPath(m_wallpaperPlugin);
m_configLoader->deleteLater();
@ -145,6 +158,20 @@ QList<QAction*> WallpaperInterface::contextualActions() const
return m_actions->actions();
}
bool WallpaperInterface::supportsMimetype(const QString &mimetype) const
{
//FIXME: a less brutal way? packages should have valid KService :/
KDesktopFile desktop(m_pkg.path() + "/" + "metadata.desktop");
return desktop.desktopGroup().readEntry<QStringList>("X-Plasma-DropMimeTypes", QStringList()).contains(mimetype);
}
void WallpaperInterface::setUrl(const QUrl &url)
{
if (m_qmlObject->rootObject()) {
QMetaObject::invokeMethod(m_qmlObject->rootObject(), QString("setUrl").toLatin1(), Qt::DirectConnection, Q_ARG(QVariant, QVariant::fromValue(url)));
}
}
void WallpaperInterface::setAction(const QString &name, const QString &text, const QString &icon, const QString &shortcut)
{
QAction *action = m_actions->action(name);

View File

@ -46,6 +46,15 @@ public:
WallpaperInterface(ContainmentInterface *parent = 0);
~WallpaperInterface();
/**
* Returns a list of all known wallpapers that can accept the given mimetype
* @param mimetype the mimetype to search for
* @param formFactor the format of the wallpaper being search for (e.g. desktop)
* @return list of wallpapers
*/
static KPluginInfo::List listWallpaperInfoForMimetype(const QString &mimetype,
const QString &formFactor = QString());
Plasma::Package package() const;
ConfigPropertyMap *configuration() const;
@ -54,6 +63,10 @@ public:
QList<QAction*> contextualActions() const;
bool supportsMimetype(const QString &mimetype) const;
void setUrl(const QUrl &urls);
Q_INVOKABLE void setAction(const QString &name, const QString &text,
const QString &icon = QString(), const QString &shortcut = QString());

View File

@ -52,7 +52,7 @@ ContainmentConfigView::ContainmentConfigView(Plasma::Containment *cont, QWindow
engine()->rootContext()->setContextProperty("configDialog", this);
setCurrentWallpaper(cont->containment()->wallpaper());
Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/QmlWallpaper");
Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Wallpaper");
pkg.setPath(m_containment->wallpaper());
QFile file(pkg.filePath("config", "main.xml"));
KConfigGroup cfg = m_containment->config();

View File

@ -38,7 +38,7 @@ Plasma::Package ShellPluginLoader::internalLoadPackage(const QString &packageFor
if (packageFormat.endsWith("/LookAndFeel")) {
Plasma::PackageStructure *structure = new LookAndFeelPackage();
return Plasma::Package(structure);
} else if (packageFormat.endsWith("/QmlWallpaper")) {
} else if (packageFormat.endsWith("/Wallpaper")) {
Plasma::PackageStructure *structure = new QmlWallpaperPackage();
return Plasma::Package(structure);
} else {