support wallpaper drops

svn path=/trunk/KDE/kdelibs/; revision=1019584
This commit is contained in:
Aaron J. Seigo 2009-09-03 23:22:48 +00:00
parent 9e165484bc
commit 860e54d92c
2 changed files with 54 additions and 10 deletions

View File

@ -1220,7 +1220,29 @@ void ContainmentPrivate::dropData(QPointF scenePos, QPoint screenPos, QGraphicsS
//kDebug() << "Local file.";
KMenu choices;
QHash<QAction *, QString> actionsToApplets;
if (!appletList.isEmpty()) {
choices.addTitle(i18n("Widgets"));
QMap<QString, KPluginInfo> sorted;
bool hasIconWidget = false;
foreach (const KPluginInfo &info, appletList) {
if (info.pluginName() == "icon") {
hasIconWidget = true;
}
sorted.insert(info.name(), info);
}
if (!hasIconWidget) {
const QString constraint = QString("[X-KDE-PluginInfo-Name] == 'icon'");
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
if (!offers.isEmpty()) {
KPluginInfo info(offers.at(0));
sorted.insert(info.name(), info);
}
}
foreach (const KPluginInfo &info, sorted) {
QAction *action;
if (!info.icon().isEmpty()) {
action = choices.addAction(KIcon(info.icon()), info.name());
@ -1230,11 +1252,17 @@ void ContainmentPrivate::dropData(QPointF scenePos, QPoint screenPos, QGraphicsS
actionsToApplets.insert(action, info.pluginName());
}
actionsToApplets.insert(choices.addAction(i18n("Icon")), "icon");
}
QHash<QAction *, QString> actionsToWallpapers;
if (!wallpaperList.isEmpty()) {
choices.addTitle(i18n("Set As Wallpaper"));
choices.addTitle(i18n("Wallpaper"));
QMap<QString, KPluginInfo> sorted;
foreach (const KPluginInfo &info, appletList) {
sorted.insert(info.name(), info);
}
foreach (const KPluginInfo &info, wallpaperList) {
QAction *action;
if (!info.icon().isEmpty()) {
@ -1253,6 +1281,13 @@ void ContainmentPrivate::dropData(QPointF scenePos, QPoint screenPos, QGraphicsS
if (plugin.isEmpty()) {
//set wallpapery stuff
plugin = actionsToWallpapers.value(choice);
if (!wallpaper || plugin != wallpaper->pluginName()) {
q->setWallpaper(plugin);
}
if (wallpaper) {
emit wallpaper->urlDropped(url);
}
} else {
q->addApplet(actionsToApplets[choice], args, geom);
}
@ -1297,7 +1332,7 @@ void ContainmentPrivate::dropData(QPointF scenePos, QPoint screenPos, QGraphicsS
pluginFormats.insert(plugin.pluginName(), format);
}
}
kDebug() << "Mimetype ..." << formats << seenPlugins.keys() << pluginFormats.values();
//kDebug() << "Mimetype ..." << formats << seenPlugins.keys() << pluginFormats.values();
QString selectedPlugin;

View File

@ -349,6 +349,14 @@ class PLASMA_EXPORT Wallpaper : public QObject
*/
void renderCompleted(const QImage &image);
/**
* Emitted when a URL matching X-Plasma-DropMimeTypes is dropped on the wallpaper
*
* @arg url the URL of the dropped file
* @since 4.4
*/
void urlDropped(const KUrl &url);
/**
* @internal
*/
@ -451,6 +459,7 @@ class PLASMA_EXPORT Wallpaper : public QObject
friend class WallpaperPackage;
friend class WallpaperPrivate;
friend class ContainmentPrivate;
WallpaperPrivate *const d;
};