[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-panel-devel
Subject: [PATCH] update desktop wallpaper outside plasma
From: sycao <sycao () redflag-linux ! com>
Date: 2008-11-20 19:45:50
Message-ID: 4925BE6E.4030006 () redflag-linux ! com
[Download RAW message or body]
Hi, does anyone has an requirement that be able to change wallpaper
outside plasma.
I need this function so I export dbus service for DefaultDesktop. then I
rewrite the
kdegraphics/kolourpaint->setWallpaper to use this interface. I also need
it in some
other projects.
best regards
Siyuan Cao
["plasma-desktop-background.patch" (text/plain)]
diff --exclude='*~' --exclude='*.orig' -Nur \
kdebase-workspace-4.1.2-orig/plasma/containments/desktop/CMakeLists.txt \
kdebase-workspace-4.1.2-new/plasma/containments/desktop/CMakeLists.txt
--- kdebase-workspace-4.1.2-orig/plasma/containments/desktop/CMakeLists.txt 2008-11-19 \
11:41:07.000000000 +0800
+++ kdebase-workspace-4.1.2-new/plasma/containments/desktop/CMakeLists.txt 2008-11-19 \
16:50:21.000000000 +0800 @@ -15,6 +15,7 @@
set(ksmserver_xml ${KDEBASE_WORKSPACE_SOURCE_DIR}/ksmserver/org.kde.KSMServerInterface.xml)
QT4_ADD_DBUS_INTERFACE(desktop_SRCS ${ksmserver_xml} ksmserver_interface)
+QT4_ADD_DBUS_ADAPTOR(desktop_SRCS org.kde.plasma.desktop.xml desktop.h \
DefaultDesktop) kde4_add_plugin(plasma_containment_desktop ${desktop_SRCS})
if(WIN32)
target_link_libraries(plasma_containment_desktop plasma ${KDE4_KNEWSTUFF2_LIBS} \
${KDE4_KIO_LIBS} ${KDE4_KFILE_LIBS} ${KDE4_THREADWEAVER_LIBRARY})
--- kdebase-workspace-4.1.2-orig/plasma/containments/desktop/desktop.cpp 2008-11-19 \
11:41:07.000000000 +0800
+++ kdebase-workspace-4.1.2-new/plasma/containments/desktop/desktop.cpp 2008-11-19 \
16:45:41.000000000 +0800 @@ -29,6 +29,7 @@
#include <QGraphicsView>
#include <QPainter>
#include <QTimeLine>
+#include <QDBusConnection>
#include <KAuthorized>
#include <KComboBox>
@@ -39,6 +40,7 @@
#include <KStandardDirs>
#include <KWindowSystem>
#include <KProcess>
+#include <KDirWatch>
#include "plasma/corona.h"
#include "plasma/appletbrowser.h"
@@ -47,6 +49,7 @@
#include "kworkspace/kworkspace.h"
#include "knewstuff2/engine.h"
+#include "desktopadaptor.h"
#include "krunner_interface.h"
#include "screensaver_interface.h"
#include "ksmserver_interface.h"
@@ -112,11 +115,54 @@
return QApplication::desktop()->screenGeometry(screen()).size();
}
+void DefaultDesktop::changeBackground(const QString& filename, int position)
+{
+ kDebug() << "called with " << filename;
+
+ // judge correct picture path
+ QSet<QString> suffixes;
+ suffixes << "png" << "jpeg" << "jpg" << "svg" << "svgz";
+
+ QFileInfo fi(filename);
+ bool validFile = fi.exists() && fi.isFile() && \
!suffixes.contains(fi.suffix().toLower()); + if ( validFile ) {
+ kDebug() << filename << " does not exists or invalid file type";
+ return;
+ }
+
+ if ( position < Background::Scale || position > Background::CenterTiled ) {
+ kDebug() << "invalid background position";
+ return;
+ }
+
+ KConfigGroup cg = config();
+ // change background
+ if ( m_backgroundMode == BackgroundDialog::kStaticBackground
+ || m_wallpaperPath != filename
+ || m_wallpaperPosition != position ) {
+ m_wallpaperPath = filename;
+ m_wallpaperPosition = position;
+ cg.writeEntry("wallpaper", m_wallpaperPath);
+ cg.writeEntry("wallpaperposition", m_wallpaperPosition );
+ updateBackground();
+ } else if ( m_backgroundMode == BackgroundDialog::kSlideshowBackground ) {
+ // TODO: maybe set wallpaper to specified, and restart slideshow
+ }
+}
+
void DefaultDesktop::constraintsEvent(Plasma::Constraints constraints)
{
if (constraints & Plasma::StartupCompletedConstraint) {
qsrand(QTime(0,0,0).msecsTo(QTime::currentTime()) + id());
- reloadConfig();
+ QString cfgName = KGlobal::dirs()->locateLocal("config", \
config().config()->name()); + if ( !cfgName.isEmpty() ) {
+ KDirWatch::self()->addFile( cfgName );
+ connect(KDirWatch::self(), SIGNAL(dirty(const QString&)),
+ this, SLOT(notifyConfigFileChange(const QString&)));
+ }
+ reloadConfig();
+ new DesktopAdaptor(this);
+ QDBusConnection::sessionBus().registerObject( "/Desktop", this );
}
if (constraints & Plasma::SizeConstraint) {
@@ -245,6 +291,13 @@
}
}
+void DefaultDesktop::notifyConfigFileChange(const QString& file)
+{
+ kDebug() << file << " changed, reload configuration";
+ config().config()->reparseConfiguration();
+ reloadConfig();
+}
+
void DefaultDesktop::updateBackground()
{
if (m_wallpaperPath.isEmpty() && m_backgroundMode != \
BackgroundDialog::kNoBackground) {
--- kdebase-workspace-4.1.2-orig/plasma/containments/desktop/desktop.h 2008-11-19 \
11:41:07.000000000 +0800
+++ kdebase-workspace-4.1.2-new/plasma/containments/desktop/desktop.h 2008-11-19 \
16:46:40.000000000 +0800 @@ -81,6 +81,10 @@
const QStyleOptionGraphicsItem *option,
const QRect& contentsRect);
+public Q_SLOTS:
+ // dbus interfaces
+ void changeBackground(const QString& filename, int position);
+
protected Q_SLOTS:
void runKonsole();
void runCommand();
@@ -95,7 +99,8 @@
void updateBackground(int, const QImage &img);
void addPanel();
-
+ void notifyConfigFileChange(const QString& file);
+
private:
void reloadConfig();
QSize resolution() const;
--- kdebase-workspace-4.1.2-orig/plasma/containments/desktop/org.kde.plasma.desktop.xml 1970-01-01 \
08:00:00.000000000 +0800
+++ kdebase-workspace-4.1.2-new/plasma/containments/desktop/org.kde.plasma.desktop.xml 2008-11-19 \
16:53:36.000000000 +0800 @@ -0,0 +1,10 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+ <interface name="org.kde.plasma.desktop">
+ <method name="changeBackground">
+ <arg name="filename" type="s" direction="in"/>
+ <arg name="position" type="i" direction="in"/>
+ </method>
+ </interface>
+</node>
["kdegraphics-kolourpaint-setwallpaper.patch" (text/plain)]
diff --exclude='*~' --exclude='*.orig' -Nur \
kdegraphics-4.1.2-orig/kolourpaint/mainWindow/kpMainWindow_File.cpp \
kdegraphics-4.1.2-new/kolourpaint/mainWindow/kpMainWindow_File.cpp
--- kdegraphics-4.1.2-orig/kolourpaint/mainWindow/kpMainWindow_File.cpp 2008-11-16 \
16:49:40.000000000 +0800
+++ kdegraphics-4.1.2-new/kolourpaint/mainWindow/kpMainWindow_File.cpp 2008-11-19 \
16:55:46.000000000 +0800 @@ -1424,15 +1424,15 @@
}
- QByteArray data;
- QDataStream dataStream (&data, QIODevice::WriteOnly);
+// QByteArray data;
+// QDataStream dataStream (&data, QIODevice::WriteOnly);
// write path
#if DEBUG_KP_MAIN_WINDOW
kDebug () << "kpMainWindow::setAsWallpaper() path="
<< d->document->url ().path () << endl;
#endif
- dataStream << QString (d->document->url ().path ());
+// dataStream << QString (d->document->url ().path ());
// write position:
//
@@ -1452,7 +1452,7 @@
// flexiblity. We don't want to slow down average users, who see way too
// many dialogs already and probably haven't even heard of "Centered Maxpect"...
//
- dataStream << int (centered ? 1 : 2);
+ // dataStream << int (centered ? 1 : 2);
// I'm going to all this trouble because the user might not have kdebase
@@ -1461,14 +1461,19 @@
// COMPAT
#ifdef Q_WS_X11
- int konq_screen_number = KApplication::desktop()->primaryScreen();
- QByteArray appname;
- if (konq_screen_number == 0)
- appname = "org.kde.kdesktop";
- else
- appname = "org.kde.kdesktop-screen-" + \
QByteArray::number(konq_screen_number);
- QDBusInterface kdesktop(appname, "/Background", "org.kde.kdesktop.Background");
- QDBusReply<void> retVal = kdesktop.call( "setWallpaper", QString \
(d->document->url ().path ()), int (centered ? 1 : 2) ); + QDBusInterface \
desktop("org.kde.plasma", "/Desktop", "org.kde.plasma.desktop"); + QDBusReply<void> \
retVal = desktop.call( "changeBackground", QString(d->document->url().path()), \
+ (centered? 1: 3) ); +
+ // int konq_screen_number = KApplication::desktop()->primaryScreen();
+ // QByteArray appname;
+ // if (konq_screen_number == 0)
+ // appname = "org.kde.kdesktop";
+ // else
+ // appname = "org.kde.kdesktop-screen-" + \
QByteArray::number(konq_screen_number); + // QDBusInterface kdesktop(appname, \
"/Background", "org.kde.kdesktop.Background"); + // QDBusReply<void> retVal = \
kdesktop.call( "setWallpaper", QString (d->document->url ().path ()), int (centered ? \
1 : + // 2) );
if (!retVal.isValid())
{
KMessageBox::sorry (this, i18n ("Could not change wallpaper."));
_______________________________________________
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