You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
285 lines
9.3 KiB
285 lines
9.3 KiB
15 years ago
|
/* This file is part of the KDE projects
|
||
|
Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
|
||
|
|
||
|
This program is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This program is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with this program; see the file COPYING. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "konq_drag.h"
|
||
|
#include <kdebug.h>
|
||
|
#include <kurldrag.h>
|
||
|
|
||
14 years ago
|
KonqIconDrag::KonqIconDrag( TQWidget * dragSource, const char* name )
|
||
|
: TQIconDrag( dragSource, name ),
|
||
15 years ago
|
m_bCutSelection( false )
|
||
|
{
|
||
|
}
|
||
|
|
||
|
const char* KonqIconDrag::format( int i ) const
|
||
|
{
|
||
|
if ( i == 0 )
|
||
|
return "application/x-qiconlist";
|
||
|
else if ( i == 1 )
|
||
|
return "text/uri-list";
|
||
|
else if ( i == 2 )
|
||
11 years ago
|
return "application/x-tde-cutselection";
|
||
15 years ago
|
else if ( i == 3 )
|
||
|
return "text/plain";
|
||
|
else if ( i == 4 ) //These two are imporant because they may end up being format 0,
|
||
|
//which is what KonqDirPart::updatePasteAction() checks
|
||
|
return "text/plain;charset=ISO-8859-1";
|
||
|
else if ( i == 5 ) //..as well as potentially for interoperability
|
||
|
return "text/plain;charset=UTF-8";
|
||
|
// warning, don't add anything here without checking KonqIconDrag2
|
||
|
|
||
|
else return 0;
|
||
|
}
|
||
|
|
||
13 years ago
|
TQByteArray KonqIconDrag::encodedData( const char* mime ) const
|
||
15 years ago
|
{
|
||
14 years ago
|
TQByteArray a;
|
||
|
TQCString mimetype( mime );
|
||
15 years ago
|
if ( mimetype == "application/x-qiconlist" )
|
||
13 years ago
|
a = TQIconDrag::encodedData( mime );
|
||
15 years ago
|
else if ( mimetype == "text/uri-list" ) {
|
||
14 years ago
|
TQCString s = urls.join( "\r\n" ).latin1();
|
||
15 years ago
|
if( urls.count() > 0 )
|
||
|
s.append( "\r\n" );
|
||
|
a.resize( s.length() + 1 ); // trailing zero
|
||
|
memcpy( a.data(), s.data(), s.length() + 1 );
|
||
|
}
|
||
11 years ago
|
else if ( mimetype == "application/x-tde-cutselection" ) {
|
||
14 years ago
|
TQCString s ( m_bCutSelection ? "1" : "0" );
|
||
15 years ago
|
a.resize( s.length() + 1 ); // trailing zero
|
||
|
memcpy( a.data(), s.data(), s.length() + 1 );
|
||
|
}
|
||
|
else if ( mimetype == "text/plain" ) {
|
||
|
if (!urls.isEmpty())
|
||
|
{
|
||
14 years ago
|
TQStringList uris;
|
||
|
for (TQStringList::ConstIterator it = urls.begin(); it != urls.end(); ++it)
|
||
15 years ago
|
uris.append(KURLDrag::stringToUrl((*it).latin1()).prettyURL());
|
||
14 years ago
|
TQCString s = uris.join( "\n" ).local8Bit();
|
||
15 years ago
|
if( uris.count() > 1 )
|
||
|
s.append( "\n" );
|
||
|
a.resize( s.length()); // no trailing zero in clipboard text
|
||
|
memcpy( a.data(), s.data(), s.length());
|
||
|
}
|
||
|
}
|
||
|
else if ( mimetype.lower() == "text/plain;charset=iso-8859-1")
|
||
|
{
|
||
|
if (!urls.isEmpty())
|
||
|
{
|
||
14 years ago
|
TQStringList uris;
|
||
15 years ago
|
|
||
14 years ago
|
for (TQStringList::ConstIterator it = urls.begin(); it != urls.end(); ++it)
|
||
15 years ago
|
uris.append(KURLDrag::stringToUrl((*it).latin1()).url(0, 4)); // 4 for latin1
|
||
|
|
||
14 years ago
|
TQCString s = uris.join( "\n" ).latin1();
|
||
15 years ago
|
if( uris.count() > 1 )
|
||
|
s.append( "\n" );
|
||
|
a.resize( s.length());
|
||
|
memcpy( a.data(), s.data(), s.length());
|
||
|
}
|
||
|
}
|
||
|
else if ( mimetype.lower() == "text/plain;charset=utf-8")
|
||
|
{
|
||
|
if (!urls.isEmpty())
|
||
|
{
|
||
14 years ago
|
TQStringList uris;
|
||
|
for (TQStringList::ConstIterator it = urls.begin(); it != urls.end(); ++it)
|
||
15 years ago
|
uris.append(KURLDrag::stringToUrl((*it).latin1()).prettyURL());
|
||
14 years ago
|
TQCString s = uris.join( "\n" ).utf8();
|
||
15 years ago
|
if( uris.count() > 1 )
|
||
|
s.append( "\n" );
|
||
|
a.resize( s.length());
|
||
|
memcpy( a.data(), s.data(), s.length());
|
||
|
}
|
||
|
}
|
||
|
return a;
|
||
|
}
|
||
|
|
||
14 years ago
|
bool KonqIconDrag::canDecode( const TQMimeSource* e )
|
||
15 years ago
|
{
|
||
|
return e->provides( "application/x-qiconlist" ) ||
|
||
|
e->provides( "text/uri-list" ) ||
|
||
11 years ago
|
e->provides( "application/x-tde-cutselection" );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
void KonqIconDrag::append( const TQIconDragItem &item, const TQRect &pr,
|
||
|
const TQRect &tr, const TQString &url )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQIconDrag::append( item, pr, tr );
|
||
15 years ago
|
urls.append( url );
|
||
|
}
|
||
|
|
||
14 years ago
|
KonqIconDrag2::KonqIconDrag2( TQWidget * dragSource )
|
||
15 years ago
|
: KonqIconDrag( dragSource )
|
||
|
{
|
||
|
}
|
||
|
|
||
14 years ago
|
void KonqIconDrag2::append( const TQIconDragItem &item, const TQRect &pr,
|
||
|
const TQRect &tr, const TQString& url, const KURL &mostLocalURL )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQString mostLocalURLStr = KURLDrag::urlToString(mostLocalURL);
|
||
15 years ago
|
m_kdeURLs.append( url );
|
||
|
KonqIconDrag::append( item, pr, tr, mostLocalURLStr );
|
||
|
}
|
||
|
|
||
|
const char* KonqIconDrag2::format( int i ) const
|
||
|
{
|
||
|
if ( i == 6 )
|
||
11 years ago
|
return "application/x-tde-urilist";
|
||
15 years ago
|
return KonqIconDrag::format( i );
|
||
|
}
|
||
|
|
||
13 years ago
|
TQByteArray KonqIconDrag2::encodedData( const char* mime ) const
|
||
15 years ago
|
{
|
||
14 years ago
|
TQCString mimetype( mime );
|
||
11 years ago
|
if ( mimetype == "application/x-tde-urilist" )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQByteArray a;
|
||
15 years ago
|
int c=0;
|
||
14 years ago
|
for (TQStringList::ConstIterator it = m_kdeURLs.begin(); it != m_kdeURLs.end(); ++it) {
|
||
|
TQCString url = (*it).utf8();
|
||
15 years ago
|
int l = url.length();
|
||
|
a.resize(c+l+2);
|
||
|
memcpy(a.data()+c, url.data(), l);
|
||
|
memcpy(a.data()+c+l,"\r\n",2);
|
||
|
c += l+2;
|
||
|
}
|
||
|
a.resize(c+1);
|
||
|
a[c] = 0;
|
||
|
return a;
|
||
|
}
|
||
13 years ago
|
return KonqIconDrag::encodedData( mime );
|
||
15 years ago
|
}
|
||
|
|
||
|
//
|
||
|
|
||
14 years ago
|
KonqDrag * KonqDrag::newDrag( const KURL::List & urls, bool cut, TQWidget * dragSource, const char* name )
|
||
15 years ago
|
{
|
||
|
// See KURLDrag::newDrag
|
||
14 years ago
|
TQStrList uris;
|
||
15 years ago
|
KURL::List::ConstIterator uit = urls.begin();
|
||
|
KURL::List::ConstIterator uEnd = urls.end();
|
||
|
// Get each URL encoded in utf8 - and since we get it in escaped
|
||
|
// form on top of that, .latin1() is fine.
|
||
|
for ( ; uit != uEnd ; ++uit )
|
||
|
uris.append( KURLDrag::urlToString( *uit ).latin1() );
|
||
|
return new KonqDrag( uris, cut, dragSource, name );
|
||
|
}
|
||
|
|
||
|
// urls must be already checked to have hostname in file URLs
|
||
14 years ago
|
KonqDrag::KonqDrag( const TQStrList & urls, bool cut, TQWidget * dragSource, const char* name )
|
||
|
: TQUriDrag( urls, dragSource, name ),
|
||
15 years ago
|
m_bCutSelection( cut ), m_urls( urls )
|
||
|
{}
|
||
|
|
||
|
// urls must be already checked to have hostname in file URLs
|
||
|
KonqDrag::KonqDrag( const KURL::List & urls, const KURL::List& mostLocalUrls,
|
||
14 years ago
|
bool cut, TQWidget * dragSource )
|
||
|
: TQUriDrag( dragSource ),
|
||
15 years ago
|
m_bCutSelection( cut )
|
||
|
{
|
||
14 years ago
|
TQStrList uris;
|
||
15 years ago
|
KURL::List::ConstIterator uit = urls.begin();
|
||
|
KURL::List::ConstIterator uEnd = urls.end();
|
||
|
// Get each URL encoded in utf8 - and since we get it in escaped
|
||
|
// form on top of that, .latin1() is fine.
|
||
|
for ( ; uit != uEnd ; ++uit )
|
||
|
uris.append( KURLDrag::urlToString( *uit ).latin1() );
|
||
14 years ago
|
setUris( uris ); // we give the KDE uris to TQUriDrag. TODO: do the opposite in KDE4 and add a m_mostLocalUris member.
|
||
15 years ago
|
|
||
|
uit = mostLocalUrls.begin();
|
||
|
uEnd = mostLocalUrls.end();
|
||
|
for ( ; uit != uEnd ; ++uit )
|
||
|
m_urls.append( KURLDrag::urlToString( *uit ).latin1() );
|
||
|
// we keep the most-local-uris in m_urls for exporting those as text/plain (for xmms)
|
||
|
}
|
||
|
|
||
|
const char* KonqDrag::format( int i ) const
|
||
|
{
|
||
|
if ( i == 0 )
|
||
|
return "text/uri-list";
|
||
|
else if ( i == 1 )
|
||
11 years ago
|
return "application/x-tde-cutselection";
|
||
15 years ago
|
else if ( i == 2 )
|
||
|
return "text/plain";
|
||
|
else if ( i == 3 )
|
||
11 years ago
|
return "application/x-tde-urilist";
|
||
15 years ago
|
else return 0;
|
||
|
}
|
||
|
|
||
13 years ago
|
TQByteArray KonqDrag::encodedData( const char* mime ) const
|
||
15 years ago
|
{
|
||
14 years ago
|
TQByteArray a;
|
||
|
TQCString mimetype( mime );
|
||
15 years ago
|
if ( mimetype == "text/uri-list" )
|
||
|
{
|
||
14 years ago
|
// Code taken from TQUriDrag::setUris
|
||
15 years ago
|
int c=0;
|
||
14 years ago
|
for (TQStrListIterator it(m_urls); *it; ++it) {
|
||
14 years ago
|
int l = tqstrlen(*it);
|
||
15 years ago
|
a.resize(c+l+2);
|
||
|
memcpy(a.data()+c,*it,l);
|
||
|
memcpy(a.data()+c+l,"\r\n",2);
|
||
|
c+=l+2;
|
||
|
}
|
||
|
a.resize(c+1);
|
||
|
a[c] = 0;
|
||
|
}
|
||
11 years ago
|
else if ( mimetype == "application/x-tde-urilist" )
|
||
15 years ago
|
{
|
||
13 years ago
|
return TQUriDrag::encodedData( "text/uri-list" );
|
||
15 years ago
|
}
|
||
11 years ago
|
else if ( mimetype == "application/x-tde-cutselection" )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQCString s ( m_bCutSelection ? "1" : "0" );
|
||
15 years ago
|
a.resize( s.length() + 1 ); // trailing zero
|
||
|
memcpy( a.data(), s.data(), s.length() + 1 );
|
||
|
}
|
||
|
else if ( mimetype == "text/plain" )
|
||
|
{
|
||
14 years ago
|
TQStringList uris;
|
||
|
for (TQStrListIterator it(m_urls); *it; ++it)
|
||
15 years ago
|
uris.append(KURLDrag::stringToUrl(*it).prettyURL());
|
||
14 years ago
|
TQCString s = uris.join( "\n" ).local8Bit();
|
||
15 years ago
|
if( uris.count() > 1 )
|
||
|
s.append( "\n" );
|
||
|
a.resize( s.length() + 1 ); // trailing zero
|
||
|
memcpy( a.data(), s.data(), s.length() + 1 );
|
||
|
}
|
||
|
return a;
|
||
|
}
|
||
|
|
||
|
//
|
||
|
|
||
|
// Used for KonqIconDrag too
|
||
|
|
||
14 years ago
|
bool KonqDrag::decodeIsCutSelection( const TQMimeSource *e )
|
||
15 years ago
|
{
|
||
11 years ago
|
TQByteArray a = e->encodedData( "application/x-tde-cutselection" );
|
||
15 years ago
|
if ( a.isEmpty() )
|
||
|
return false;
|
||
|
else
|
||
|
{
|
||
14 years ago
|
kdDebug(1203) << "KonqDrag::decodeIsCutSelection : a=" << TQCString(a.data(), a.size() + 1) << endl;
|
||
13 years ago
|
return (a.at(0) == '1'); // true if 1
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
#include "konq_drag.moc"
|