[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdebase/kdesktop
From:       Pascal Létourneau <pletourn () globetrotter ! net>
Date:       2005-07-26 19:03:52
Message-ID: 1122404632.494969.25212.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 438985 by pletourn:

Allow setting the wallpaper via DnD, even when icons on desktop are \
disabled

FEATURE:63852


 M  +46 -3     desktop.cc  
 M  +3 -0      desktop.h  


--- trunk/KDE/kdebase/kdesktop/desktop.cc #438984:438985
@@ -31,6 +31,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <kcolordrag.h>
+#include <kurldrag.h>
 
 #include <qdir.h>
 #include <qevent.h>
@@ -70,6 +71,7 @@
 KRootWidget::KRootWidget() : QObject()
 {
      kapp->desktop()->installEventFilter(this);
+     kapp->desktop()->setAcceptDrops( true );
 }
 
 bool KRootWidget::eventFilter ( QObject *, QEvent * e )
@@ -86,6 +88,43 @@
        emit wheelRolled(we->delta());
        return true;
      }
+     else if ( e->type() == QEvent::DragEnter )
+     {
+       QDragEnterEvent* de = static_cast<QDragEnterEvent *>( e );
+       bool b = !KGlobal::config()->isImmutable();
+       b &= !KGlobal::dirs()->isRestrictedResource( "wallpaper" );
+
+       bool imageURL = false;
+       if ( KURLDrag::canDecode( de ) )
+       {
+         KURL::List list;
+         KURLDrag::decode( de, list );
+         KURL url = list.first();
+         KMimeType::Ptr mime = KMimeType::findByURL( url );
+         if ( !KImageIO::type( url.path() ).isEmpty() ||
+              KImageIO::isSupported( mime->name(), KImageIO::Reading ) || \
mime->is( "image/svg+xml" ) ) +           imageURL = true;
+       }
+
+       b &= KColorDrag::canDecode( de ) || QImageDrag::canDecode( de ) || \
imageURL; +       de->accept( b );
+       return true;
+     }
+     else if ( e->type() == QEvent::Drop )
+     {
+       QDropEvent* de = static_cast<QDropEvent*>( e );
+       if ( KColorDrag::canDecode( de ) ) 
+         emit colorDropEvent( de );
+       else if ( QImageDrag::canDecode( de ) )
+         emit imageDropEvent( de );
+       else if ( KURLDrag::canDecode( de ) ) {
+	 KURL::List list;
+         KURLDrag::decode( de, list );
+         KURL url = list.first();
+         emit newWallpaper( url );
+       }
+       return true;
+     }
      return false; // Don't filter.
 }
 
@@ -194,7 +233,10 @@
 
      m_pRootWidget = new KRootWidget;
      connect(m_pRootWidget, SIGNAL(wheelRolled(int)), this, \
                SLOT(slotSwitchDesktops(int)));
-
+     connect(m_pRootWidget, SIGNAL(colorDropEvent(QDropEvent*)), this, \
SLOT(handleColorDropEvent(QDropEvent*)) ); +     connect(m_pRootWidget, \
SIGNAL(imageDropEvent(QDropEvent*)), this, \
SLOT(handleImageDropEvent(QDropEvent*)) ); +     connect(m_pRootWidget, \
SIGNAL(newWallpaper(const KURL&)), this, SLOT(slotNewWallpaper(const \
KURL&)) ); +     
      // Geert Jansen: backgroundmanager belongs here
      // TODO tell KBackgroundManager if we change widget()
      bgMgr = new KBackgroundManager( m_pIconView, m_pKwinmodule );
@@ -710,8 +752,9 @@
 void KDesktop::handleImageDropEvent(QDropEvent * e)
 {
     KPopupMenu popup;
-    popup.insertItem(SmallIconSet("filesave"),i18n("&Save to Desktop..."), \
                1);
-    if (m_pIconView && m_pIconView->maySetWallpaper())
+    if ( m_pIconView )
+       popup.insertItem(SmallIconSet("filesave"),i18n("&Save to \
Desktop..."), 1); +    if ( ( m_pIconView && m_pIconView->maySetWallpaper() \
                ) || m_pRootWidget )
        popup.insertItem(SmallIconSet("background"),i18n("Set as \
&Wallpaper"), 2);  popup.insertSeparator();
     popup.insertItem(SmallIconSet("cancel"), i18n("&Cancel"));
--- trunk/KDE/kdebase/kdesktop/desktop.h #438984:438985
@@ -48,6 +48,9 @@
    bool eventFilter( QObject *, QEvent * e );
 signals:
    void wheelRolled( int delta );
+   void colorDropEvent( QDropEvent* e );
+   void imageDropEvent( QDropEvent* e );
+   void newWallpaper( const KURL& url );
 };
 
 /**


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic