22#include <tqdragobject.h>
37 : TQUriDrag(dragSource, name), m_metaData(), d( 0 )
43 TQWidget* dragSource,
const char * name )
44 : TQUriDrag(dragSource, name), m_metaData(metaData), d( 0 )
56 KURL::List::ConstIterator uit = urls.begin();
57 KURL::List::ConstIterator uEnd = urls.end();
60 for ( ; uit != uEnd ; ++uit )
71 d =
new KURLDragPrivate;
72 d->m_exportAsText = exp;
77 return new KURLDrag( urls, TQMap<TQString, TQString>(), dragSource, name );
81 TQWidget* dragSource,
const char * name )
88 if ( e->provides(
"application/x-tde-urilist" ) ) {
89 TQByteArray payload = e->encodedData(
"application/x-tde-urilist" );
90 if ( payload.size() ) {
92 const char* d = payload.data();
93 while (c < payload.size() && d[c]) {
96 while (c < payload.size() && d[c] && d[c]!=
'\r'
99 TQCString s(d+f,c-f+1);
103 while (c < payload.size() && d[c] &&
104 (d[c]==
'\n' || d[c]==
'\r'))
107 return !uris.isEmpty();
112 TQUriDrag::decode( e, lst );
113 for (TQStrListIterator it(lst); *it; ++it)
123 return !uris.isEmpty();
130 TQByteArray ba = e->encodedData(
"application/x-tdeio-metadata" );
133 TQString s = ba.data();
134 TQStringList l = TQStringList::split(
"$@@$", s );
135 TQStringList::ConstIterator it = l.begin();
136 bool readingKey =
true;
138 for ( ; it != l.end(); ++it ) {
143 readingKey = !readingKey;
145 Q_ASSERT( readingKey );
155 TQStringList::ConstIterator end(e.end());
156 for(TQStringList::ConstIterator it=e.begin(); it!=end; ++it)
166 return !uris.isEmpty();
175 return "text/uri-list";
177 return "application/x-tdeio-metadata";
178 if ( d && d->m_exportAsText ==
false )
183 return "text/plain;charset=ISO-8859-1";
185 return "text/plain;charset=UTF-8";
192 TQCString mimetype( mime );
193 if ( mimetype ==
"text/uri-list" )
194 return TQUriDrag::encodedData( mime );
195 else if ( mimetype ==
"text/plain" )
198 for (TQStrListIterator it(m_urls); *it; ++it)
201 TQCString s = uris.join(
"\n" ).local8Bit();
202 if( uris.count() > 1 )
204 a.resize( s.length());
205 memcpy( a.data(), s.data(), s.length());
207 else if ( mimetype.lower() ==
"text/plain;charset=iso-8859-1")
210 for (TQStrListIterator it(m_urls); *it; ++it)
211 for (TQStrListIterator it(m_urls); *it; ++it)
214 TQCString s = uris.join(
"\n" ).latin1();
215 if( uris.count() > 1 )
217 a.resize( s.length());
218 memcpy( a.data(), s.data(), s.length());
220 else if ( mimetype.lower() ==
"text/plain;charset=utf-8")
223 for (TQStrListIterator it(m_urls); *it; ++it)
226 TQCString s = uris.join(
"\n" ).utf8();
227 if( uris.count() > 1 )
229 a.resize( s.length());
230 memcpy( a.data(), s.data(), s.length());
232 else if ( mimetype ==
"application/x-tdeio-metadata" )
234 if ( !m_metaData.isEmpty() )
237 TQMap<TQString,TQString>::ConstIterator it;
238 for( it = m_metaData.begin(); it != m_metaData.end(); ++it )
245 a.resize( s.length() + 1 );
246 memcpy( a.data(), s.latin1(), a.size() );
254 if (strncmp(s.data(),
"file:", 5) == 0)
271 if( !s.startsWith(
"file://" ))
274 if ( gethostname( hostname, 255 ) == 0 )
276 hostname[256] =
'\0';
277 return TQString(
"file://" ) + hostname + s.mid( 5 );
287 return url.
url(0, 106);
292 TQWidget * dragSource,
const char* name ) :
293TQUriDrag( urls, dragSource, name ), m_urls( urls ), m_metaData( metaData ), d( 0 ) {}
This class is to be used instead of TQUriDrag when using KURL.
static KURL stringToUrl(const TQCString &s)
Converts a string used for dragging to a URL.
void setExportAsText(bool exp)
By default, KURLDrag also exports the URLs as plain text, for e.g.
virtual TQByteArray encodedData(const char *mime) const
static KURLDrag * newDrag(const KURL::List &urls, TQWidget *dragSource=0, const char *name=0) TDE_DEPRECATED
virtual const char * format(int i) const
KURLDrag(const KURL::List &urls, TQWidget *dragSource=0, const char *name=0)
Constructs an object to drag the list of URLs in urls.
TQMap< TQString, TQString > & metaData()
Meta-data to associate with those URLs.
static TQString urlToString(const KURL &url)
Converts a URL to a string representation suitable for dragging.
static bool decode(const TQMimeSource *e, KURL::List &urls)
Convenience method that decodes the contents of e into a list of KURLs.
KURL::List is a TQValueList that contains KURLs with a few convenience methods.
Represents and parses a URL.
TQString path() const
Returns the current decoded path.
TQString protocol() const
Returns the protocol for the URL.
TQString url(int _trailing=0, int encoding_hint=0) const
Returns the URL as string, with all escape sequences intact, encoded in a given charset.
bool isLocalFile() const
Tests if the file is local.
TQString prettyURL(int _trailing=0) const
Returns the URL as string in human-friendly format.
bool isValid() const
Tests if the URL is well formed.
static TDELocale * locale()
Returns the global locale object.