19 #include "kbookmarkdrag.h"
23 KBookmarkDrag * KBookmarkDrag::newDrag(
const TQValueList<KBookmark> & bookmarks, TQWidget * dragSource,
const char * name )
27 for ( TQValueListConstIterator<KBookmark> it = bookmarks.begin(); it != bookmarks.end(); ++it ) {
28 urls.append( (*it).url() );
33 KURL::List::ConstIterator uit = urls.begin();
34 KURL::List::ConstIterator uEnd = urls.end();
37 for ( ; uit != uEnd ; ++uit )
38 uris.append( KURLDrag::urlToString(*uit).latin1() );
40 return new KBookmarkDrag( bookmarks, uris, dragSource, name );
43 KBookmarkDrag * KBookmarkDrag::newDrag(
const KBookmark & bookmark, TQWidget * dragSource,
const char * name )
45 TQValueList<KBookmark> bookmarks;
46 bookmarks.append( KBookmark(bookmark) );
47 return newDrag(bookmarks, dragSource, name);
50 KBookmarkDrag::KBookmarkDrag(
const TQValueList<KBookmark> & bookmarks,
const TQStrList & urls,
51 TQWidget * dragSource,
const char * name )
52 : TQUriDrag( urls, dragSource, name ), m_bookmarks( bookmarks ), m_doc(
"xbel")
58 TQDomElement elem = m_doc.createElement(
"xbel");
59 m_doc.appendChild( elem );
60 for ( TQValueListConstIterator<KBookmark> it = bookmarks.begin(); it != bookmarks.end(); ++it ) {
61 elem.appendChild( (*it).internalElement().cloneNode(
true ) );
66 const char* KBookmarkDrag::format(
int i )
const
69 return "application/x-xbel";
71 return "text/uri-list";
77 TQByteArray KBookmarkDrag::encodedData(
const char* mime )
const
80 TQCString mimetype( mime );
81 if ( mimetype ==
"text/uri-list" )
82 return TQUriDrag::encodedData( mime );
83 else if ( mimetype ==
"application/x-xbel" )
85 a = m_doc.toCString();
88 else if ( mimetype ==
"text/plain" )
90 KURL::List m_lstDragURLs;
91 if ( KURLDrag::decode(
this, m_lstDragURLs ) )
94 KURL::List::ConstIterator uit = m_lstDragURLs.begin();
95 KURL::List::ConstIterator uEnd = m_lstDragURLs.end();
96 for ( ; uit != uEnd ; ++uit )
97 uris.append( (*uit).prettyURL() );
99 TQCString s = uris.join(
"\n" ).local8Bit();
100 a.resize( s.length() + 1 );
101 memcpy( a.data(), s.data(), s.length() + 1 );
107 bool KBookmarkDrag::canDecode(
const TQMimeSource * e )
109 return e->provides(
"text/uri-list") || e->provides(
"application/x-xbel") ||
110 e->provides(
"text/plain");
113 TQValueList<KBookmark> KBookmarkDrag::decode(
const TQMimeSource * e )
115 TQValueList<KBookmark> bookmarks;
116 if ( e->provides(
"application/x-xbel") )
118 TQByteArray s( e->encodedData(
"application/x-xbel") );
122 TQDomElement elem = doc.documentElement();
123 TQDomNodeList children = elem.childNodes();
124 for ( uint childno = 0; childno < children.count(); childno++)
126 bookmarks.append( KBookmark( children.item(childno).cloneNode(
true).toElement() ));
130 if ( e->provides(
"text/uri-list") )
132 KURL::List m_lstDragURLs;
134 if ( KURLDrag::decode( e, m_lstDragURLs ) )
136 KURL::List::ConstIterator uit = m_lstDragURLs.begin();
137 KURL::List::ConstIterator uEnd = m_lstDragURLs.end();
138 for ( ; uit != uEnd ; ++uit )
141 bookmarks.append( KBookmark::standaloneBookmark(
142 (*uit).prettyURL(), (*uit) ));
147 if( e->provides(
"text/plain") )
151 if(TQTextDrag::decode( e, s ))
154 TQStringList listDragURLs = TQStringList::split(TQChar(
'\n'), s);
155 TQStringList::ConstIterator it = listDragURLs.begin();
156 TQStringList::ConstIterator end = listDragURLs.end();
157 for( ; it!=end; ++it)
160 bookmarks.append( KBookmark::standaloneBookmark( KURL(*it).prettyURL(), KURL(*it)));
165 bookmarks.append( KBookmark() );