From 5aaccf0489826e0beadce046057bc99fb525279d Mon Sep 17 00:00:00 2001 From: Riccardo Iaconelli Date: Tue, 31 Jul 2007 10:52:05 +0000 Subject: [PATCH] The applets now can associate with (one or more) certain mimetypes, and be called when that mime is dragged onto the desktop. Very rudimental for the moment, we should pass the name of the file to the applet. Added some copyrights I missed in the past. Aaron: your turn now to discover the 'Mimetypes' key problem. CCMAIL: aseigo@kde.org svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=694676 --- applet.cpp | 9 +++++++++ applet.h | 9 +++++++++ corona.cpp | 12 +++++++++++- package.cpp | 1 + package.h | 1 + widgets/icon.cpp | 3 ++- widgets/icon.h | 3 ++- 7 files changed, 35 insertions(+), 3 deletions(-) diff --git a/applet.cpp b/applet.cpp index a297c98e3..66f4a3551 100644 --- a/applet.cpp +++ b/applet.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2005 by Aaron Seigo + * Copyright (C) 2007 by Riccardo Iaconelli * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License version 2 as @@ -758,6 +759,14 @@ KPluginInfo::List Applet::knownApplets(const QString &category, return KPluginInfo::fromServices(offers); } +KPluginInfo::List Applet::knownAppletsForMimetype(QString mimetype) +{ + QString constraint = QString("'%1' in [X-Plasma-Mimetypes]").arg(mimetype); + kDebug() << constraint << endl; + KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint); + return KPluginInfo::fromServices(offers); +} + QStringList Applet::knownCategories(const QString &parentApp) { QString constraint = "exist [X-KDE-PluginInfo-Category]"; diff --git a/applet.h b/applet.h index 2d3af1b6b..2195c786c 100644 --- a/applet.h +++ b/applet.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2006-2007 by Aaron Seigo + * Copyright (C) 2007 by Riccardo Iaconelli * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License version 2 as @@ -237,6 +238,14 @@ class PLASMA_EXPORT Applet : public QObject, public Widget static KPluginInfo::List knownApplets(const QString &category = QString(), const QString &parentApp = QString()); + /** + * Returns a list of all known applets associated with a certain mimetype in a hash keyed by a unique + * identifier for each applet + * + * @return list of applets + **/ + static KPluginInfo::List knownAppletsForMimetype(QString mimetype); + /** * Returns a list of all the categories used by * installed applets. diff --git a/corona.cpp b/corona.cpp index 16a058a4c..e69c55c78 100644 --- a/corona.cpp +++ b/corona.cpp @@ -1,6 +1,7 @@ /* * Copyright (C) 2007 Matt Broadstone * Copyright (C) 2007 Aaron Seigo + * Copyright (C) 2007 Riccardo Iaconelli * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License version 2 as @@ -252,11 +253,20 @@ void Corona::dropEvent(QGraphicsSceneDragDropEvent *event) } else if (KUrl::List::canDecode(event->mimeData())) { KUrl::List urls = KUrl::List::fromMimeData(event->mimeData()); foreach (const KUrl& url, urls) { + KMimeType::Ptr mime = KMimeType::findByUrl(url); + QString mimeName = mime->name(); +// kDebug() << mimeName << endl; + KPluginInfo::List appletList = Applet::knownAppletsForMimetype(mimeName); + + + //FIXME: we should probably show a dialog here to choose which plasmoid load. + addApplet(appletList.first().pluginName()); + QStringList args; args << url.url(); Applet* button = addApplet("url", args); if (button) { - //button->setSize(128,128); +// button->setSize(128,128); button->setPos(event->scenePos() - QPoint(button->boundingRect().width()/2, button->boundingRect().height()/2)); } diff --git a/package.cpp b/package.cpp index bedd7beb9..1ec658b4c 100644 --- a/package.cpp +++ b/package.cpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2007 by Aaron Seigo * +* Copyright (C) 2007 by Riccardo Iaconelli * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * diff --git a/package.h b/package.h index 4467a3b6c..3b1ccb8b0 100644 --- a/package.h +++ b/package.h @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2007 by Aaron Seigo * +* Copyright (C) 2007 by Riccardo Iaconelli * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * diff --git a/widgets/icon.cpp b/widgets/icon.cpp index 40343a4f9..f4b0e6929 100644 --- a/widgets/icon.cpp +++ b/widgets/icon.cpp @@ -1,5 +1,6 @@ /* - * Copyright (C) 2007 by Aaron Seigo aseigo@kde.org + * Copyright (C) 2007 by Aaron Seigo + * Copyright (C) 2007 by Riccardo Iaconelli * Copyright (C) 2007 by Matt Broadstone * * This program is free software; you can redistribute it and/or modify diff --git a/widgets/icon.h b/widgets/icon.h index 7dd459a61..76ba7f4d8 100644 --- a/widgets/icon.h +++ b/widgets/icon.h @@ -1,5 +1,6 @@ /* -* Copyright (C) 2007 by Siraj Razick siraj@kde.org +* Copyright (C) 2007 by Siraj Razick +* Copyright (C) 2007 by Riccardo Iaconelli * Copyright (C) 2007 by Matt Broadstone * * This program is free software; you can redistribute it and/or modify