21 #include <tqstrlist.h>
22 #include <tqdragobject.h>
26 #include <tdeversion.h>
27 #include <tdeglobal.h>
38 : TQUriDrag(dragSource, name), m_metaData(), d( 0 )
44 TQWidget* dragSource,
const char * name )
45 : TQUriDrag(dragSource, name), m_metaData(metaData), d( 0 )
57 KURL::List::ConstIterator uit = urls.begin();
58 KURL::List::ConstIterator uEnd = urls.end();
61 for ( ; uit != uEnd ; ++uit )
72 d =
new KURLDragPrivate;
73 d->m_exportAsText = exp;
78 return new KURLDrag( urls, TQMap<TQString, TQString>(), dragSource, name );
82 TQWidget* dragSource,
const char * name )
84 return new KURLDrag( urls, metaData, dragSource, name );
89 if ( e->provides(
"application/x-tde-urilist" ) ) {
90 TQByteArray payload = e->encodedData(
"application/x-tde-urilist" );
91 if ( payload.size() ) {
93 const char* d = payload.data();
94 while (c < payload.size() && d[c]) {
97 while (c < payload.size() && d[c] && d[c]!=
'\r'
100 TQCString s(d+f,c-f+1);
104 while (c < payload.size() && d[c] &&
105 (d[c]==
'\n' || d[c]==
'\r'))
108 return !uris.isEmpty();
113 TQUriDrag::decode( e, lst );
114 for (TQStrListIterator it(lst); *it; ++it)
124 return !uris.isEmpty();
131 TQByteArray ba = e->encodedData(
"application/x-tdeio-metadata" );
134 TQString s = ba.data();
135 TQStringList l = TQStringList::split(
"$@@$", s );
136 TQStringList::ConstIterator it = l.begin();
137 bool readingKey =
true;
139 for ( ; it != l.end(); ++it ) {
143 metaData.replace( key, *it );
144 readingKey = !readingKey;
146 Q_ASSERT( readingKey );
156 TQStringList::ConstIterator end(e.end());
157 for(TQStringList::ConstIterator it=e.begin(); it!=end; ++it)
167 return !uris.isEmpty();
176 return "text/uri-list";
178 return "application/x-tdeio-metadata";
179 if ( d && d->m_exportAsText ==
false )
184 return "text/plain;charset=ISO-8859-1";
186 return "text/plain;charset=UTF-8";
193 TQCString mimetype( mime );
194 if ( mimetype ==
"text/uri-list" )
195 return TQUriDrag::encodedData( mime );
196 else if ( mimetype ==
"text/plain" )
199 for (TQStrListIterator it(m_urls); *it; ++it)
202 TQCString s = uris.join(
"\n" ).local8Bit();
203 if( uris.count() > 1 )
205 a.resize( s.length());
206 memcpy( a.data(), s.data(), s.length());
208 else if ( mimetype.lower() ==
"text/plain;charset=iso-8859-1")
211 for (TQStrListIterator it(m_urls); *it; ++it)
212 for (TQStrListIterator it(m_urls); *it; ++it)
215 TQCString s = uris.join(
"\n" ).latin1();
216 if( uris.count() > 1 )
218 a.resize( s.length());
219 memcpy( a.data(), s.data(), s.length());
221 else if ( mimetype.lower() ==
"text/plain;charset=utf-8")
224 for (TQStrListIterator it(m_urls); *it; ++it)
227 TQCString s = uris.join(
"\n" ).utf8();
228 if( uris.count() > 1 )
230 a.resize( s.length());
231 memcpy( a.data(), s.data(), s.length());
233 else if ( mimetype ==
"application/x-tdeio-metadata" )
235 if ( !m_metaData.isEmpty() )
238 TQMap<TQString,TQString>::ConstIterator it;
239 for( it = m_metaData.begin(); it != m_metaData.end(); ++it )
246 a.resize( s.length() + 1 );
247 memcpy( a.data(), s.latin1(), a.size() );
255 if (strncmp(s.data(),
"file:", 5) == 0)
272 if( !s.startsWith(
"file://" ))
275 if ( gethostname( hostname, 255 ) == 0 )
277 hostname[256] =
'\0';
278 return TQString(
"file://" ) + hostname + s.mid( 5 );
288 return url.
url(0, 106);
293 TQWidget * dragSource,
const char* name ) :
294 TQUriDrag( urls, dragSource, name ), m_urls( urls ), m_metaData( metaData ), d( 0 ) {}
Represents and parses a URL.
KURLDrag(const KURL::List &urls, TQWidget *dragSource=0, const char *name=0)
Constructs an object to drag the list of URLs in urls.
static KURLDrag * newDrag(const KURL::List &urls, TQWidget *dragSource=0, const char *name=0) KDE_DEPRECATED
void setExportAsText(bool exp)
By default, KURLDrag also exports the URLs as plain text, for e.g.
TQString protocol() const
Returns the protocol for the URL.
bool isLocalFile() const
Tests if the file is local.
static bool decode(const TQMimeSource *e, KURL::List &urls)
Convenience method that decodes the contents of e into a list of KURLs.
virtual TQByteArray encodedData(const char *mime) const
static TQString urlToString(const KURL &url)
Converts a URL to a string representation suitable for dragging.
static KURL stringToUrl(const TQCString &s)
Converts a string used for dragging to a URL.
static TDELocale * locale()
Returns the global locale object.
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.
TQString path() const
Returns the current decoded path.
KURL::List is a TQValueList that contains KURLs with a few convenience methods.
This class is to be used instead of TQUriDrag when using KURL.
bool isValid() const
Tests if the URL is well formed.
TQString prettyURL(int _trailing=0) const
Returns the URL as string in human-friendly format.
virtual const char * format(int i) const