21 #include <Qt3Support/Q3CString> 22 #include <Qt3Support/Q3StrIList> 23 #include <Qt3Support/Q3ColorDrag> 24 #include <QtGui/QFont> 31 class K3URLDragPrivate
38 :
Q3UriDrag(dragSource), m_metaData(), d( 0 )
46 :
Q3UriDrag(dragSource), m_metaData(metaData), d( 0 )
58 KUrl::List::ConstIterator uit = urls.begin();
59 KUrl::List::ConstIterator uEnd = urls.end();
62 for ( ; uit != uEnd ; ++uit )
64 m_urls.append(
urlToString(*uit).toLatin1().constData() );
73 d =
new K3URLDragPrivate;
74 d->m_exportAsText = exp;
98 if ( e->provides(
"application/x-kde4-urilist" ) ) {
99 QByteArray payload = e->encodedData(
"application/x-kde4-urilist" );
100 if ( payload.size() ) {
102 const char* d = payload.data();
103 while (c < payload.size() && d[c]) {
106 while (c < payload.size() && d[c] && d[c]!=
'\r' 109 Q3CString s(d+f,c-f+1);
113 while (c < payload.size() && d[c] &&
114 (d[c]==
'\n' || d[c]==
'\r'))
117 return !uris.isEmpty();
122 Q3UriDrag::decode( e, lst );
123 for (Q3StrListIterator it(lst); *it; ++it)
126 if ( !url.isValid() )
133 return !uris.isEmpty();
140 QByteArray ba = e->encodedData(
"application/x-kio-metadata" );
143 QString s = ba.data();
144 const QStringList l = s.split(
"$@@$", QString::SkipEmptyParts );
145 QStringList::ConstIterator it = l.begin();
146 bool readingKey =
true;
148 for ( ; it != l.end(); ++it ) {
153 readingKey = !readingKey;
155 Q_ASSERT( readingKey );
167 return "text/uri-list";
169 return "application/x-kio-metadata";
170 if ( d && d->m_exportAsText ==
false )
175 return "text/plain;charset=ISO-8859-1";
177 return "text/plain;charset=UTF-8";
186 return Q3UriDrag::encodedData( mime );
187 else if (
mimetype ==
"text/plain" )
190 for (Q3StrListIterator it(m_urls); *it; ++it)
193 QByteArray s = uris.join(
"\n" ).toLocal8Bit();
194 if( uris.count() > 1 )
196 a.resize( s.length());
197 memcpy( a.data(), s.data(), s.length());
199 else if (
mimetype.toLower() ==
"text/plain;charset=iso-8859-1")
202 for (Q3StrListIterator it(m_urls); *it; ++it)
205 QByteArray s = uris.join(
"\n" ).toLatin1();
206 if( uris.count() > 1 )
208 a.resize( s.length());
209 memcpy( a.data(), s.data(), s.length());
211 else if (
mimetype.toLower() ==
"text/plain;charset=utf-8")
214 for (Q3StrListIterator it(m_urls); *it; ++it)
217 QByteArray s = uris.join(
"\n" ).toUtf8();
218 if( uris.count() > 1 )
220 a.resize( s.length());
221 memcpy( a.data(), s.data(), s.length());
223 else if (
mimetype ==
"application/x-kio-metadata" )
225 if ( !m_metaData.isEmpty() )
229 for( it = m_metaData.begin(); it != m_metaData.end(); ++it )
236 a.resize( s.length() + 1 );
237 memcpy( a.data(), s.toLatin1().constData(), a.size() );
245 if (strncmp(s.data(),
"file:", 5) == 0)
262 if( !s.startsWith(
"file://" ))
265 if ( gethostname( hostname, 255 ) == 0 )
267 hostname[256] =
'\0';
268 return QString(
"file://" ) + hostname + s.mid( 5 );
284 Q3UriDrag( urls, dragSource ), m_urls( urls ), m_metaData( metaData ), d( 0 ) {}
static QString urlToString(const KUrl &url)
Converts a URL to a string representation suitable for dragging.
K3URLDrag(const KUrl::List &urls, QWidget *dragSource=0)
Constructs an object to drag the list of URLs in urls.
MimetypeJob * mimetype(const KUrl &url, JobFlags flags=DefaultFlags)
virtual QByteArray encodedData(const char *mime) const
static bool decode(const QMimeSource *e, KUrl::List &urls)
Convenience method that decodes the contents of e into a list of KUrls.
QString prettyUrl(AdjustPathOption trailing=LeaveTrailingSlash) const
virtual const char * format(int i) const
static KUrl stringToUrl(const QByteArray &s)
Converts a string used for dragging to a URL.
void setExportAsText(bool exp)
By default, K3URLDrag also exports the URLs as plain text, for e.g.
This class is to be used instead of Q3UriDrag when using KUrl.
static K3URLDrag * newDrag(const KUrl::List &urls, QWidget *dragSource=0)
QMap< QString, QString > & metaData()
Meta-data to associate with those URLs.
QString url(AdjustPathOption trailing=LeaveTrailingSlash) const
QString path(AdjustPathOption trailing=LeaveTrailingSlash) const