• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • libkonq
 

libkonq

  • libkonq
konq_drag.cpp
1/* This file is part of the KDE projects
2 Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include "konq_drag.h"
21#include <kdebug.h>
22#include <kurldrag.h>
23
24KonqIconDrag::KonqIconDrag( TQWidget * dragSource, const char* name )
25 : TQIconDrag( dragSource, name ),
26 m_bCutSelection( false )
27{
28}
29
30const char* KonqIconDrag::format( int i ) const
31{
32 if ( i == 0 )
33 return "application/x-qiconlist";
34 else if ( i == 1 )
35 return "text/uri-list";
36 else if ( i == 2 )
37 return "application/x-tde-cutselection";
38 else if ( i == 3 )
39 return "text/plain";
40 else if ( i == 4 ) //These two are imporant because they may end up being format 0,
41 //which is what KonqDirPart::updatePasteAction() checks
42 return "text/plain;charset=ISO-8859-1";
43 else if ( i == 5 ) //..as well as potentially for interoperability
44 return "text/plain;charset=UTF-8";
45 // warning, don't add anything here without checking KonqIconDrag2
46
47 else return 0;
48}
49
50TQByteArray KonqIconDrag::encodedData( const char* mime ) const
51{
52 TQByteArray a;
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 )
59 s.append( "\r\n" );
60 a.resize( s.length() + 1 ); // trailing zero
61 memcpy( a.data(), s.data(), s.length() + 1 );
62 }
63 else if ( mimetype == "application/x-tde-cutselection" ) {
64 TQCString s ( m_bCutSelection ? "1" : "0" );
65 a.resize( s.length() + 1 ); // trailing zero
66 memcpy( a.data(), s.data(), s.length() + 1 );
67 }
68 else if ( mimetype == "text/plain" ) {
69 if (!urls.isEmpty())
70 {
71 TQStringList uris;
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 )
76 s.append( "\n" );
77 a.resize( s.length()); // no trailing zero in clipboard text
78 memcpy( a.data(), s.data(), s.length());
79 }
80 }
81 else if ( mimetype.lower() == "text/plain;charset=iso-8859-1")
82 {
83 if (!urls.isEmpty())
84 {
85 TQStringList uris;
86
87 for (TQStringList::ConstIterator it = urls.begin(); it != urls.end(); ++it)
88 uris.append(KURLDrag::stringToUrl((*it).latin1()).url(0, 4)); // 4 for latin1
89
90 TQCString s = uris.join( "\n" ).latin1();
91 if( uris.count() > 1 )
92 s.append( "\n" );
93 a.resize( s.length());
94 memcpy( a.data(), s.data(), s.length());
95 }
96 }
97 else if ( mimetype.lower() == "text/plain;charset=utf-8")
98 {
99 if (!urls.isEmpty())
100 {
101 TQStringList uris;
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 )
106 s.append( "\n" );
107 a.resize( s.length());
108 memcpy( a.data(), s.data(), s.length());
109 }
110 }
111 return a;
112}
113
114bool KonqIconDrag::canDecode( const TQMimeSource* e )
115{
116 return e->provides( "application/x-qiconlist" ) ||
117 e->provides( "text/uri-list" ) ||
118 e->provides( "application/x-tde-cutselection" );
119}
120
121void KonqIconDrag::append( const TQIconDragItem &item, const TQRect &pr,
122 const TQRect &tr, const TQString &url )
123{
124 TQIconDrag::append( item, pr, tr );
125 urls.append( url );
126}
127
128KonqIconDrag2::KonqIconDrag2( TQWidget * dragSource )
129 : KonqIconDrag( dragSource )
130{
131}
132
133void KonqIconDrag2::append( const TQIconDragItem &item, const TQRect &pr,
134 const TQRect &tr, const TQString& url, const KURL &mostLocalURL )
135{
136 TQString mostLocalURLStr = KURLDrag::urlToString(mostLocalURL);
137 m_kdeURLs.append( url );
138 KonqIconDrag::append( item, pr, tr, mostLocalURLStr );
139}
140
141const char* KonqIconDrag2::format( int i ) const
142{
143 if ( i == 6 )
144 return "application/x-tde-urilist";
145 return KonqIconDrag::format( i );
146}
147
148TQByteArray KonqIconDrag2::encodedData( const char* mime ) const
149{
150 TQCString mimetype( mime );
151 if ( mimetype == "application/x-tde-urilist" )
152 {
153 TQByteArray a;
154 int c=0;
155 for (TQStringList::ConstIterator it = m_kdeURLs.begin(); it != m_kdeURLs.end(); ++it) {
156 TQCString url = (*it).utf8();
157 int l = url.length();
158 a.resize(c+l+2);
159 memcpy(a.data()+c, url.data(), l);
160 memcpy(a.data()+c+l,"\r\n",2);
161 c += l+2;
162 }
163 a.resize(c+1);
164 a[c] = 0;
165 return a;
166 }
167 return KonqIconDrag::encodedData( mime );
168}
169
170//
171
172KonqDrag * KonqDrag::newDrag( const KURL::List & urls, bool cut, TQWidget * dragSource, const char* name )
173{
174 // See KURLDrag::newDrag
175 TQStrList uris;
176 KURL::List::ConstIterator uit = urls.begin();
177 KURL::List::ConstIterator uEnd = urls.end();
178 // Get each URL encoded in utf8 - and since we get it in escaped
179 // form on top of that, .latin1() is fine.
180 for ( ; uit != uEnd ; ++uit )
181 uris.append( KURLDrag::urlToString( *uit ).latin1() );
182 return new KonqDrag( uris, cut, dragSource, name );
183}
184
185// urls must be already checked to have hostname in file URLs
186KonqDrag::KonqDrag( const TQStrList & urls, bool cut, TQWidget * dragSource, const char* name )
187 : TQUriDrag( urls, dragSource, name ),
188 m_bCutSelection( cut ), m_urls( urls )
189{}
190
191// urls must be already checked to have hostname in file URLs
192KonqDrag::KonqDrag( const KURL::List & urls, const KURL::List& mostLocalUrls,
193 bool cut, TQWidget * dragSource )
194 : TQUriDrag( dragSource ),
195 m_bCutSelection( cut )
196{
197 TQStrList uris;
198 KURL::List::ConstIterator uit = urls.begin();
199 KURL::List::ConstIterator uEnd = urls.end();
200 // Get each URL encoded in utf8 - and since we get it in escaped
201 // form on top of that, .latin1() is fine.
202 for ( ; uit != uEnd ; ++uit )
203 uris.append( KURLDrag::urlToString( *uit ).latin1() );
204 setUris( uris ); // we give the KDE uris to TQUriDrag. TODO: do the opposite in KDE4 and add a m_mostLocalUris member.
205
206 uit = mostLocalUrls.begin();
207 uEnd = mostLocalUrls.end();
208 for ( ; uit != uEnd ; ++uit )
209 m_urls.append( KURLDrag::urlToString( *uit ).latin1() );
210 // we keep the most-local-uris in m_urls for exporting those as text/plain (for xmms)
211}
212
213const char* KonqDrag::format( int i ) const
214{
215 if ( i == 0 )
216 return "text/uri-list";
217 else if ( i == 1 )
218 return "application/x-tde-cutselection";
219 else if ( i == 2 )
220 return "text/plain";
221 else if ( i == 3 )
222 return "application/x-tde-urilist";
223 else return 0;
224}
225
226TQByteArray KonqDrag::encodedData( const char* mime ) const
227{
228 TQByteArray a;
229 TQCString mimetype( mime );
230 if ( mimetype == "text/uri-list" )
231 {
232 // Code taken from TQUriDrag::setUris
233 int c=0;
234 for (TQStrListIterator it(m_urls); *it; ++it) {
235 int l = tqstrlen(*it);
236 a.resize(c+l+2);
237 memcpy(a.data()+c,*it,l);
238 memcpy(a.data()+c+l,"\r\n",2);
239 c+=l+2;
240 }
241 a.resize(c+1);
242 a[c] = 0;
243 }
244 else if ( mimetype == "application/x-tde-urilist" )
245 {
246 return TQUriDrag::encodedData( "text/uri-list" );
247 }
248 else if ( mimetype == "application/x-tde-cutselection" )
249 {
250 TQCString s ( m_bCutSelection ? "1" : "0" );
251 a.resize( s.length() + 1 ); // trailing zero
252 memcpy( a.data(), s.data(), s.length() + 1 );
253 }
254 else if ( mimetype == "text/plain" )
255 {
256 TQStringList uris;
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 )
261 s.append( "\n" );
262 a.resize( s.length() + 1 ); // trailing zero
263 memcpy( a.data(), s.data(), s.length() + 1 );
264 }
265 return a;
266}
267
268//
269
270// Used for KonqIconDrag too
271
272bool KonqDrag::decodeIsCutSelection( const TQMimeSource *e )
273{
274 TQByteArray a = e->encodedData( "application/x-tde-cutselection" );
275 if ( a.isEmpty() )
276 return false;
277 else
278 {
279 kdDebug(1203) << "KonqDrag::decodeIsCutSelection : a=" << TQCString(a.data(), a.size() + 1) << endl;
280 return (a.at(0) == '1'); // true if 1
281 }
282}
283
284#include "konq_drag.moc"

libkonq

Skip menu "libkonq"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

libkonq

Skip menu "libkonq"
  • kate
  • libkonq
  • twin
  •   lib
Generated for libkonq by doxygen 1.9.4
This website is maintained by Timothy Pearson.