21 #include "kbookmarkdrag.h" 25 KBookmarkDrag * KBookmarkDrag::newDrag(
const TQValueList<KBookmark> & bookmarks, TQWidget * dragSource,
const char * name )
29 for ( TQValueListConstIterator<KBookmark> it = bookmarks.begin(); it != bookmarks.end(); ++it ) {
30 urls.append( (*it).url() );
35 KURL::List::ConstIterator uit = urls.begin();
36 KURL::List::ConstIterator uEnd = urls.end();
39 for ( ; uit != uEnd ; ++uit )
40 uris.append( KURLDrag::urlToString(*uit).latin1() );
42 return new KBookmarkDrag( bookmarks, uris, dragSource, name );
45 KBookmarkDrag * KBookmarkDrag::newDrag(
const KBookmark & bookmark, TQWidget * dragSource,
const char * name )
47 TQValueList<KBookmark> bookmarks;
48 bookmarks.append( KBookmark(bookmark) );
49 return newDrag(bookmarks, dragSource, name);
52 KBookmarkDrag::KBookmarkDrag(
const TQValueList<KBookmark> & bookmarks,
const TQStrList & urls,
53 TQWidget * dragSource,
const char * name )
54 : TQUriDrag( urls, dragSource, name ), m_bookmarks( bookmarks ), m_doc(
"xbel")
60 TQDomElement elem = m_doc.createElement(
"xbel");
61 m_doc.appendChild( elem );
62 for ( TQValueListConstIterator<KBookmark> it = bookmarks.begin(); it != bookmarks.end(); ++it ) {
63 elem.appendChild( (*it).internalElement().cloneNode(
true ) );
68 const char* KBookmarkDrag::format(
int i )
const 71 return "application/x-xbel";
73 return "text/uri-list";
79 TQByteArray KBookmarkDrag::encodedData(
const char* mime )
const 82 TQCString mimetype( mime );
83 if ( mimetype ==
"text/uri-list" )
84 return TQUriDrag::encodedData( mime );
85 else if ( mimetype ==
"application/x-xbel" )
87 a = m_doc.toCString();
90 else if ( mimetype ==
"text/plain" )
92 KURL::List m_lstDragURLs;
93 if ( KURLDrag::decode(
this, m_lstDragURLs ) )
96 KURL::List::ConstIterator uit = m_lstDragURLs.begin();
97 KURL::List::ConstIterator uEnd = m_lstDragURLs.end();
98 for ( ; uit != uEnd ; ++uit )
99 uris.append( (*uit).prettyURL() );
101 TQCString s = uris.join(
"\n" ).local8Bit();
102 a.resize( s.length() + 1 );
103 memcpy( a.data(), s.data(), s.length() + 1 );
109 bool KBookmarkDrag::canDecode(
const TQMimeSource * e )
111 return e->provides(
"text/uri-list") || e->provides(
"application/x-xbel") ||
112 e->provides(
"text/plain");
115 TQValueList<KBookmark> KBookmarkDrag::decode(
const TQMimeSource * e )
117 TQValueList<KBookmark> bookmarks;
118 if ( e->provides(
"application/x-xbel") )
120 TQByteArray s( e->encodedData(
"application/x-xbel") );
124 TQDomElement elem = doc.documentElement();
125 TQDomNodeList children = elem.childNodes();
126 for ( uint childno = 0; childno < children.count(); childno++)
128 bookmarks.append( KBookmark( children.item(childno).cloneNode(
true).toElement() ));
132 if ( e->provides(
"text/uri-list") )
134 KURL::List m_lstDragURLs;
136 if ( KURLDrag::decode( e, m_lstDragURLs ) )
138 KURL::List::ConstIterator uit = m_lstDragURLs.begin();
139 KURL::List::ConstIterator uEnd = m_lstDragURLs.end();
140 for ( ; uit != uEnd ; ++uit )
143 bookmarks.append( KBookmark::standaloneBookmark(
144 (*uit).prettyURL(), (*uit) ));
149 if( e->provides(
"text/plain") )
153 if(TQTextDrag::decode( e, s ))
156 TQStringList listDragURLs = TQStringList::split(TQChar(
'\n'), s);
157 TQStringList::ConstIterator it = listDragURLs.begin();
158 TQStringList::ConstIterator end = listDragURLs.end();
159 for( ; it!=end; ++it)
162 bookmarks.append( KBookmark::standaloneBookmark( KURL(*it).prettyURL(), KURL(*it)));
167 bookmarks.append( KBookmark() );