From kde-core-devel Thu Mar 21 02:46:51 2002 From: Alexander Kellett Date: Thu, 21 Mar 2002 02:46:51 +0000 To: kde-core-devel Subject: Re: multi-url KBookmarkDrag X-MARC-Message: https://marc.info/?l=kde-core-devel&m=101667889809824 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--KsGdsel6WgEHnImy" --KsGdsel6WgEHnImy Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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, 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 --KsGdsel6WgEHnImy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="bookmarks.patch" ? 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 #include -KBookmarkDrag * KBookmarkDrag::newDrag( const KBookmark & bookmark, QWidget * dragSource, const char * name ) +KBookmarkDrag * KBookmarkDrag::newDrag( const QValueList & bookmarks, QWidget * dragSource, const char * name ) { KURL::List urls; - urls.append( bookmark.url() ); + + for ( QValueListConstIterator 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 bookmarks; + bookmarks.append( KBookmark(bookmark) ); + return newDrag(bookmarks, dragSource, name); +} + +KBookmarkDrag::KBookmarkDrag( const QValueList & 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 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 KBookmarkDrag::decode( const QMimeSource * e ) { + QValueList 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 & 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 & 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 decode( const QMimeSource * e ); protected: - KBookmark m_bookmark; + QValueList m_bookmarks; QDomDocument m_doc; class KBookmarkDragPrivate; KBookmarkDragPrivate * d; --KsGdsel6WgEHnImy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="keditbookmarks.patch" ? 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 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 ); } } --KsGdsel6WgEHnImy--