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

List:       kde-core-devel
Subject:    multi-url KBookmarkDrag
From:       Alexander Kellett <kelletta () eidetica ! com>
Date:       2002-03-20 22:50:23
[Download RAW message or body]

The attached patch changes KBookmarkDrag to allow for multiple 
bookmark drags. The interface to me seems fairly logical, but very BIC. 

Therefore, if possible i'd like to either get this into 3.0 release (or at
least the most basic change of using a qptrlist but not changing the actual
implementation) or alternatively get an idea on how to make this change without
any need for BIC changes.

Tronical suggested using KBookmarkGroup wrapped by a KBookmark, and
passing that around. But, umm... i'm not sure i agree as my patch would
probably look cuter :)

cheers,
Alex

fyi, these changes are for my addition of multiple selection in 
keditbookmarks, which i'd really like to get into 3.1.

btw, yes, i know the patch isn't complete as of yet, just for show.

--
kelletta@eidetica.com           (lypanov)           http://lypanov.shacknet.nu

["multi-bookmarks.patch" (text/plain)]

Index: kbookmarkdrag.cc
===================================================================
RCS file: /home/kde/kdelibs/kio/bookmarks/kbookmarkdrag.cc,v
retrieving revision 1.9
diff -u -r1.9 kbookmarkdrag.cc
--- kbookmarkdrag.cc	2001/10/12 10:15:13	1.9
+++ kbookmarkdrag.cc	2002/03/19 02:22:05
@@ -20,6 +20,26 @@
 #include <kurldrag.h>
 #include <kdebug.h>
 
+KBookmarkDrag * KBookmarkDrag::newDrag( const QPtrList<KBookmark> & bookmarks, \
QWidget * dragSource, const char * name ) +{
+    KURL::List urls;
+
+    for ( QPtrListIterator<KBookmark> it(bookmarks); it.current() != 0; ++it ) {
+       KBookmark *bookmark = it.current();
+       urls.append( bookmark->url() );
+    }
+
+    // See KURLDrag::newDrag
+    QStrList uris;
+    KURL::List::ConstIterator uit = urls.begin();
+    KURL::List::ConstIterator uEnd = urls.end();
+    // Get each URL encoded in utf8 - and since we get it in escaped
+    // form on top of that, .latin1() is fine.
+    for ( ; uit != uEnd ; ++uit )
+        uris.append( (*uit).url(0, 106).latin1() ); // 106 is mib enum for utf8 \
codec +    return new KBookmarkDrag( bookmarks, uris, dragSource, name );
+}
+
 KBookmarkDrag * KBookmarkDrag::newDrag( const KBookmark & bookmark, QWidget * \
dragSource, const char * name )  {
     KURL::List urls;
@@ -33,12 +53,15 @@
     // form on top of that, .latin1() is fine.
     for ( ; uit != uEnd ; ++uit )
         uris.append( (*uit).url(0, 106).latin1() ); // 106 is mib enum for utf8 \
                codec
-    return new KBookmarkDrag( bookmark, uris, dragSource, name );
+
+    QPtrList<KBookmark> bookmarks;
+    bookmarks.append(&bookmark);
+    return new KBookmarkDrag( bookmarks, uris, dragSource, name );
 }
 
-KBookmarkDrag::KBookmarkDrag( const KBookmark & bookmark, const QStrList & urls,
+KBookmarkDrag::KBookmarkDrag( const QPtrList<KBookmark> & bookmarks, const QStrList \
& urls,  QWidget * dragSource, const char * name )
-    : QUriDrag( urls, dragSource, name ), m_bookmark( bookmark ), m_doc("xbel")
+    : QUriDrag( urls, dragSource, name ), m_bookmarks( bookmarks ), m_doc("xbel")
 {
     // We need to create the XML for this drag right now and not
     // in encodedData because when cutting a folder, the children
@@ -46,7 +69,10 @@
     // is requested.
     QDomElement elem = m_doc.createElement("xbel");
     m_doc.appendChild( elem );
-    elem.appendChild( m_bookmark.internalElement().cloneNode( true /* deep */ ) );
+    for ( QPtrListIterator<KBookmark> it(bookmarks); it.current() != 0; ++it ) {
+       KBookmark *bookmark = it.current();
+       elem.appendChild( bookmark->internalElement().cloneNode( true /* deep */ ) );
+    }
     kdDebug(1203) << "KBookmarkDrag::KBookmarkDrag " << m_doc.toString() << endl;
 }
 
@@ -97,8 +123,9 @@
            e->provides("text/plain");
 }
 
-KBookmark KBookmarkDrag::decode( const QMimeSource * e )
+QPtrList<KBookmark> * KBookmarkDrag::decode( const QMimeSource * e )
 {
+    QPtrList<KBookmark> * bks = new QPtrList<KBookmark>();
     if ( e->provides("application/x-xbel") )
     {
         QCString s( e->encodedData("application/x-xbel") );
@@ -107,19 +134,25 @@
         doc.setContent( s );
         QDomElement elem = doc.documentElement();
         QDomNodeList children = elem.childNodes();
-        Q_ASSERT(children.count()==1);
-        return KBookmark( children.item(0).toElement() );
+        for ( uint childno = 0; childno < children.count(); childno++) 
+        {
+           bks->append( new KBookmark( children.item(childno).toElement() ));
+        }
+        return bks;
     }
     if ( e->provides("text/uri-list") )
     {
         KURL::List m_lstDragURLs;
         if ( KURLDrag::decode( e, m_lstDragURLs ) )
         {
+            // FIXME iterate through them!!!
             if ( m_lstDragURLs.count() > 1 )
                 kdWarning() << "Only first URL inserted, known limitation" << endl;
             //kdDebug(1203) << "KBookmarkDrag::decode url=" << \
                m_lstDragURLs.first().url() << endl;
-            return KBookmark::standaloneBookmark( m_lstDragURLs.first().fileName(), \
m_lstDragURLs.first() ); +            bks->append( new KBookmark( \
KBookmark::standaloneBookmark( m_lstDragURLs.first().fileName(), \
m_lstDragURLs.first() ) )); +            return bks;
         }
     }
-    return KBookmark(QDomElement());
+    bks->append(new KBookmark(QDomElement()));
+    return bks;
 }
Index: kbookmarkdrag.h
===================================================================
RCS file: /home/kde/kdelibs/kio/bookmarks/kbookmarkdrag.h,v
retrieving revision 1.3
diff -u -r1.3 kbookmarkdrag.h
--- kbookmarkdrag.h	2001/02/19 00:57:32	1.3
+++ kbookmarkdrag.h	2002/03/19 02:22:05
@@ -26,11 +26,14 @@
 class KBookmarkDrag : public QUriDrag
 {
 public:
+    static KBookmarkDrag * newDrag( const QPtrList<KBookmark> & bookmarks,
+                                    QWidget * dragSource = 0,
+                                    const char * name = 0 );
     static KBookmarkDrag * newDrag( const KBookmark & bookmark,
                                     QWidget * dragSource = 0,
                                     const char * name = 0 );
 protected:
-    KBookmarkDrag( const KBookmark & bookmark,
+    KBookmarkDrag( const QPtrList<KBookmark> & bookmarks,
                    const QStrList & urls,
                    QWidget * dragSource,
                    const char * name );
@@ -41,10 +44,10 @@
     virtual QByteArray encodedData( const char* mime ) const;
 
     static bool canDecode( const QMimeSource * e );
-    static KBookmark decode( const QMimeSource * e );
+    static QPtrList<KBookmark> * decode( const QMimeSource * e );
 
 protected:
-    KBookmark m_bookmark;
+    QPtrList<KBookmark> m_bookmarks;
     QDomDocument m_doc;
     class KBookmarkDragPrivate;
     KBookmarkDragPrivate * d;



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

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