20 #include "konq_drag.h"
24 KonqIconDrag::KonqIconDrag( TQWidget * dragSource,
const char* name )
25 : TQIconDrag( dragSource, name ),
26 m_bCutSelection( false )
30 const char* KonqIconDrag::format(
int i )
const
33 return "application/x-qiconlist";
35 return "text/uri-list";
37 return "application/x-tde-cutselection";
42 return "text/plain;charset=ISO-8859-1";
44 return "text/plain;charset=UTF-8";
50 TQByteArray KonqIconDrag::encodedData(
const char* mime )
const
53 TQCString mimetype( mime );
54 if ( mimetype ==
"application/x-qiconlist" )
55 a = TQIconDrag::encodedData( mime );
56 else if ( mimetype ==
"text/uri-list" ) {
57 TQCString s = urls.join(
"\r\n" ).latin1();
58 if( urls.count() > 0 )
60 a.resize( s.length() + 1 );
61 memcpy( a.data(), s.data(), s.length() + 1 );
63 else if ( mimetype ==
"application/x-tde-cutselection" ) {
64 TQCString s ( m_bCutSelection ?
"1" :
"0" );
65 a.resize( s.length() + 1 );
66 memcpy( a.data(), s.data(), s.length() + 1 );
68 else if ( mimetype ==
"text/plain" ) {
72 for (TQStringList::ConstIterator it = urls.begin(); it != urls.end(); ++it)
73 uris.append(KURLDrag::stringToUrl((*it).latin1()).prettyURL());
74 TQCString s = uris.join(
"\n" ).local8Bit();
75 if( uris.count() > 1 )
77 a.resize( s.length());
78 memcpy( a.data(), s.data(), s.length());
81 else if ( mimetype.lower() ==
"text/plain;charset=iso-8859-1")
87 for (TQStringList::ConstIterator it = urls.begin(); it != urls.end(); ++it)
88 uris.append(KURLDrag::stringToUrl((*it).latin1()).url(0, 4));
90 TQCString s = uris.join(
"\n" ).latin1();
91 if( uris.count() > 1 )
93 a.resize( s.length());
94 memcpy( a.data(), s.data(), s.length());
97 else if ( mimetype.lower() ==
"text/plain;charset=utf-8")
102 for (TQStringList::ConstIterator it = urls.begin(); it != urls.end(); ++it)
103 uris.append(KURLDrag::stringToUrl((*it).latin1()).prettyURL());
104 TQCString s = uris.join(
"\n" ).utf8();
105 if( uris.count() > 1 )
107 a.resize( s.length());
108 memcpy( a.data(), s.data(), s.length());
114 bool KonqIconDrag::canDecode(
const TQMimeSource* e )
116 return e->provides(
"application/x-qiconlist" ) ||
117 e->provides(
"text/uri-list" ) ||
118 e->provides(
"application/x-tde-cutselection" );
121 void KonqIconDrag::append(
const TQIconDragItem &item,
const TQRect &pr,
122 const TQRect &tr,
const TQString &url )
124 TQIconDrag::append( item, pr, tr );
128 KonqIconDrag2::KonqIconDrag2( TQWidget * dragSource )
129 : KonqIconDrag( dragSource )
133 void KonqIconDrag2::append(
const TQIconDragItem &item,
const TQRect &pr,
134 const TQRect &tr,
const TQString& url,
const KURL &mostLocalURL )
136 TQString mostLocalURLStr = KURLDrag::urlToString(mostLocalURL);
137 m_kdeURLs.append( url );
138 KonqIconDrag::append( item, pr, tr, mostLocalURLStr );
141 const char* KonqIconDrag2::format(
int i )
const
144 return "application/x-tde-urilist";
145 return KonqIconDrag::format( i );
148 TQByteArray KonqIconDrag2::encodedData(
const char* mime )
const
150 TQCString mimetype( mime );
151 if ( mimetype ==
"application/x-tde-urilist" )
155 for (TQStringList::ConstIterator it = m_kdeURLs.begin(); it != m_kdeURLs.end(); ++it) {
156 TQCString url = (*it).utf8();
157 int l = url.length();
159 memcpy(a.data()+c, url.data(), l);
160 memcpy(a.data()+c+l,
"\r\n",2);
167 return KonqIconDrag::encodedData( mime );
172 KonqDrag * KonqDrag::newDrag(
const KURL::List & urls,
bool cut, TQWidget * dragSource,
const char* name )
176 KURL::List::ConstIterator uit = urls.begin();
177 KURL::List::ConstIterator uEnd = urls.end();
180 for ( ; uit != uEnd ; ++uit )
181 uris.append( KURLDrag::urlToString( *uit ).latin1() );
182 return new KonqDrag( uris, cut, dragSource, name );
186 KonqDrag::KonqDrag(
const TQStrList & urls,
bool cut, TQWidget * dragSource,
const char* name )
187 : TQUriDrag( urls, dragSource, name ),
188 m_bCutSelection( cut ), m_urls( urls )
192 KonqDrag::KonqDrag(
const KURL::List & urls,
const KURL::List& mostLocalUrls,
193 bool cut, TQWidget * dragSource )
194 : TQUriDrag( dragSource ),
195 m_bCutSelection( cut )
198 KURL::List::ConstIterator uit = urls.begin();
199 KURL::List::ConstIterator uEnd = urls.end();
202 for ( ; uit != uEnd ; ++uit )
203 uris.append( KURLDrag::urlToString( *uit ).latin1() );
206 uit = mostLocalUrls.begin();
207 uEnd = mostLocalUrls.end();
208 for ( ; uit != uEnd ; ++uit )
209 m_urls.append( KURLDrag::urlToString( *uit ).latin1() );
213 const char* KonqDrag::format(
int i )
const
216 return "text/uri-list";
218 return "application/x-tde-cutselection";
222 return "application/x-tde-urilist";
226 TQByteArray KonqDrag::encodedData(
const char* mime )
const
229 TQCString mimetype( mime );
230 if ( mimetype ==
"text/uri-list" )
234 for (TQStrListIterator it(m_urls); *it; ++it) {
235 int l = tqstrlen(*it);
237 memcpy(a.data()+c,*it,l);
238 memcpy(a.data()+c+l,
"\r\n",2);
244 else if ( mimetype ==
"application/x-tde-urilist" )
246 return TQUriDrag::encodedData(
"text/uri-list" );
248 else if ( mimetype ==
"application/x-tde-cutselection" )
250 TQCString s ( m_bCutSelection ?
"1" :
"0" );
251 a.resize( s.length() + 1 );
252 memcpy( a.data(), s.data(), s.length() + 1 );
254 else if ( mimetype ==
"text/plain" )
257 for (TQStrListIterator it(m_urls); *it; ++it)
258 uris.append(KURLDrag::stringToUrl(*it).prettyURL());
259 TQCString s = uris.join(
"\n" ).local8Bit();
260 if( uris.count() > 1 )
262 a.resize( s.length() + 1 );
263 memcpy( a.data(), s.data(), s.length() + 1 );
272 bool KonqDrag::decodeIsCutSelection(
const TQMimeSource *e )
274 TQByteArray a = e->encodedData(
"application/x-tde-cutselection" );
279 kdDebug(1203) <<
"KonqDrag::decodeIsCutSelection : a=" << TQCString(a.data(), a.size() + 1) << endl;
280 return (a.at(0) ==
'1');
284 #include "konq_drag.moc"