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

List:       kde-core-devel
Subject:    Re: multi-url KBookmarkDrag
From:       Alexander Kellett <kelletta () eidetica ! com>
Date:       2002-03-21 2:46:51
[Download RAW message or body]

On Thu, Mar 21, 2002 at 12:23:21AM +0100, Alexander Kellett wrote:
> On Thu, Mar 21, 2002 at 12:15:20AM +0100, David Faure wrote:
> > Summary: I strongly suggest QValueList<KBookmark>, and committing
> > before 3.0.
> 
> Okay, shall do. I'll post the patch for approval first of course, 

Okay. Here it is. Tested, works here, but i'd like someone to read over it as
i've never used qvaluelist before :)

Haven't had time to test rest of kde* modules but I assume nothing other than
keditbookmarks depends on KBookmarkDrag::decode().

It also adds a default ctor to KBookmark as discussed with dfaure on irc, and
this version lacks the code dup the last one had :)

mvg,
Alex

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

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

? bookmarks.patch
Index: kbookmark.h
===================================================================
RCS file: /home/kde/kdelibs/kio/bookmarks/kbookmark.h,v
retrieving revision 1.43
diff -u -r1.43 kbookmark.h
--- kbookmark.h	2002/03/04 13:40:28	1.43
+++ kbookmark.h	2002/03/21 02:22:13
@@ -29,6 +29,7 @@
 {
     friend class KBookmarkGroup;
 public:
+    KBookmark( ) {}
     KBookmark( QDomElement elem ) : element(elem) {}
 
     static KBookmark standaloneBookmark( const QString & text, const KURL & url, \
                const QString & icon = QString::null );
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/21 02:22:13
@@ -20,10 +20,13 @@
 #include <kurldrag.h>
 #include <kdebug.h>
 
-KBookmarkDrag * KBookmarkDrag::newDrag( const KBookmark & bookmark, QWidget * \
dragSource, const char * name ) +KBookmarkDrag * KBookmarkDrag::newDrag( const \
QValueList<KBookmark> & bookmarks, QWidget * dragSource, const char * name )  {
     KURL::List urls;
-    urls.append( bookmark.url() );
+
+    for ( QValueListConstIterator<KBookmark> it = bookmarks.begin(); it != \
bookmarks.end(); ++it ) { +       urls.append( (*it).url() );
+    }
 
     // See KURLDrag::newDrag
     QStrList uris;
@@ -33,12 +36,20 @@
     // 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 );
+
+    return new KBookmarkDrag( bookmarks, uris, dragSource, name );
 }
 
-KBookmarkDrag::KBookmarkDrag( const KBookmark & bookmark, const QStrList & urls,
+KBookmarkDrag * KBookmarkDrag::newDrag( const KBookmark & bookmark, QWidget * \
dragSource, const char * name ) +{
+    QValueList<KBookmark> bookmarks;
+    bookmarks.append( KBookmark(bookmark) );
+    return newDrag(bookmarks, dragSource, name);
+}
+
+KBookmarkDrag::KBookmarkDrag( const QValueList<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 +57,9 @@
     // is requested.
     QDomElement elem = m_doc.createElement("xbel");
     m_doc.appendChild( elem );
-    elem.appendChild( m_bookmark.internalElement().cloneNode( true /* deep */ ) );
+    for ( QValueListConstIterator<KBookmark> it = bookmarks.begin(); it != \
bookmarks.end(); ++it ) { +       elem.appendChild( \
(*it).internalElement().cloneNode( true /* deep */ ) ); +    }
     kdDebug(1203) << "KBookmarkDrag::KBookmarkDrag " << m_doc.toString() << endl;
 }
 
@@ -97,8 +110,9 @@
            e->provides("text/plain");
 }
 
-KBookmark KBookmarkDrag::decode( const QMimeSource * e )
+QValueList<KBookmark> KBookmarkDrag::decode( const QMimeSource * e )
 {
+    QValueList<KBookmark> bookmarks;
     if ( e->provides("application/x-xbel") )
     {
         QCString s( e->encodedData("application/x-xbel") );
@@ -107,19 +121,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++) 
+        {
+           bookmarks.append( KBookmark( children.item(childno).toElement() ));
+        }
+        return bookmarks;
     }
     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() ); +            bookmarks.append( \
KBookmark::standaloneBookmark( m_lstDragURLs.first().fileName(), \
m_lstDragURLs.first() )); +            return bookmarks;
         }
     }
-    return KBookmark(QDomElement());
+    bookmarks.append( KBookmark() );
+    return bookmarks;
 }
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/21 02:22:13
@@ -26,11 +26,14 @@
 class KBookmarkDrag : public QUriDrag
 {
 public:
+    static KBookmarkDrag * newDrag( const QValueList<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 QValueList<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 QValueList<KBookmark> decode( const QMimeSource * e );
 
 protected:
-    KBookmark m_bookmark;
+    QValueList<KBookmark> m_bookmarks;
     QDomDocument m_doc;
     class KBookmarkDragPrivate;
     KBookmarkDragPrivate * d;


["keditbookmarks.patch" (text/plain)]

? multi.patch
? keditbookmarks.patch
Index: toplevel.cpp
===================================================================
RCS file: /home/kde/kdebase/konqueror/keditbookmarks/toplevel.cpp,v
retrieving revision 1.73
diff -u -r1.73 toplevel.cpp
--- toplevel.cpp	2002/03/08 09:53:59	1.73
+++ toplevel.cpp	2002/03/21 02:22:02
@@ -809,9 +809,11 @@
 {
     if ( KBookmarkDrag::canDecode( data ) )
     {
-        KBookmark bk = KBookmarkDrag::decode( data );
-        kdDebug() << "KEBTopLevel::slotPaste url=" << bk.url().prettyURL() << endl;
-        CreateCommand * cmd = new CreateCommand( cmdName, insertionAddress, bk );
+        QValueList<KBookmark> bks = KBookmarkDrag::decode( data );
+        if (bks.size() > 1)
+           kdWarning() << "Sadly, pasteData is currently limited to only one url." << endl;
+        kdDebug() << "KEBTopLevel::slotPaste url=" << bks.first().url().prettyURL() << endl;
+        CreateCommand * cmd = new CreateCommand( cmdName, insertionAddress, bks.first() );
         m_commandHistory.addCommand( cmd );
     }
 }


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

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