[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-panel-devel
Subject: [PATCH] BUG167947 pick a picture and set it as wallpaper in dolphin
From: <wppan () redflag-linux ! com>
Date: 2009-08-06 10:28:17
Message-ID: 4A7AB041.8030306 () redflag-linux ! com
[Download RAW message or body]
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
["kdelibs-set-wallpaper.patch" (text/x-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 <QApplication>
#include <QClipboard>
#include <QFile>
+#include <QFileInfo>
#include <QGraphicsSceneContextMenuEvent>
#include <QGraphicsView>
#include <QMimeData>
@@ -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<QAction *, QString> 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<QAction *, QString> 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"
_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic