This is a multi-part message in MIME format. --------------090502000201040405030803 Content-Type: text/plain; charset=GB2312 Content-Transfer-Encoding: 8bit Hi, all In KDE 3 , it was possible to set a wallpaper by dragging a picture from konqueror. And I implement this feature in Plasma::Containment. Note: When you use this function, the plugin of wallpaper will be set as image, and the mode will be set as SingleImage. I think this is what most people want to do. Regards -- ÅËÎÀƽ(Peter Pan) Red Flag Software Co., Ltd --------------090502000201040405030803 Content-Type: text/x-patch; name="kdelibs-set-wallpaper.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="kdelibs-set-wallpaper.patch" Index: containment.h =================================================================== --- containment.h (revision 1007852) +++ containment.h (working copy) @@ -540,6 +540,12 @@ */ const QGraphicsItem *toolBoxItem() const; + /** + * set the url as wallpaper + * set the wallpaper plugin as image, and set the mode as SingleImage + */ + void setAsWallpaper(const KUrl &url); + private: Q_PRIVATE_SLOT(d, void appletDestroyed(Plasma::Applet*)) Q_PRIVATE_SLOT(d, void containmentAppletAnimationComplete(QGraphicsItem *item, Index: containment.cpp =================================================================== --- containment.cpp (revision 1007852) +++ containment.cpp (working copy) @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -1117,7 +1118,22 @@ //TODO: collect the mimetypes of available script engines and offer // to create widgets out of the matching URLs, if any const KUrl::List urls = KUrl::List::fromMimeData(mimeData); + foreach (const KUrl &url, urls) { + QMenu choices; + QHash actionsToPlugins; + + if (urls.count() == 1) { + QFileInfo fileInfo(urls[0].pathOrUrl()); + QString suffix = fileInfo.suffix(); + if (suffix == "png" || suffix == "jpg" || suffix == "jpeg" || suffix == "xcf" + || suffix == "svg" || suffix == "svgz") + { + QIcon icon = KIcon("configure"); + actionsToPlugins.insert(choices.addAction(icon, i18n("Set as Wallpaper")), "setAsWallpaper"); + } + } + KMimeType::Ptr mime = KMimeType::findByUrl(url); QString mimeName = mime->name(); QRectF geom(pos, QSize()); @@ -1129,8 +1145,6 @@ if (!appletList.isEmpty()) { //TODO: should we show a dialog here to choose which plasmoid load if //!appletList.isEmpty() - QMenu choices; - QHash actionsToPlugins; foreach (const KPluginInfo &info, appletList) { QAction *action; if (!info.icon().isEmpty()) { @@ -1143,15 +1157,20 @@ } actionsToPlugins.insert(choices.addAction(i18n("Icon")), "icon"); - QAction *choice = choices.exec(screenPos); - if (choice) { - q->addApplet(actionsToPlugins[choice], args, geom); - } } else if (url.protocol() != "data") { // We don't try to do anything with data: URIs // no special applet associated with this mimetype, let's - q->addApplet("icon", args, geom); + actionsToPlugins.insert(choices.addAction(i18n("Icon")), "icon"); } + + QAction *choice = choices.exec(screenPos); + if (choice) { + if (actionsToPlugins[choice] == "setAsWallpaper") { + q->setAsWallpaper(url); + return; + } + q->addApplet(actionsToPlugins[choice], args, geom); + } } if (dropEvent) { @@ -2043,6 +2062,38 @@ } } +void Containment::setAsWallpaper(const KUrl &url) +{ + QString pluginName = "image"; + QString mode = "SingleImage"; + + KConfigGroup cfg = config(); + + if (d->drawWallpaper) { + if (d->wallpaper) { + if (d->wallpaper->pluginName() != pluginName) { + delete d->wallpaper; + d->wallpaper = 0; + } + } + + if (!d->wallpaper) { + d->wallpaper = Plasma::Wallpaper::load(pluginName); + } + + if (d->wallpaper) { + cfg.writeEntry("wallpaperplugin", pluginName); + cfg.writeEntry("wallpaperpluginmode", mode); + KConfigGroup wallpaperConfig = KConfigGroup(&cfg, "Wallpaper"); + wallpaperConfig = KConfigGroup(&wallpaperConfig, pluginName); + wallpaperConfig.writeEntry("wallpaper", url.pathOrUrl()); + } + } + + emit configNeedsSaving(); + setWallpaper(pluginName, mode); +} + } // Plasma namespace #include "containment.moc" --------------090502000201040405030803 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Plasma-devel mailing list Plasma-devel@kde.org https://mail.kde.org/mailman/listinfo/plasma-devel --------------090502000201040405030803--