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.
235 lines
5.4 KiB
235 lines
5.4 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (c) 2004 Kevin Ottens <ervin ipsquad net>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library 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
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
#include <kdebug.h>
|
||
|
#include <klocale.h>
|
||
|
#include <kapplication.h>
|
||
|
#include <dcopclient.h>
|
||
|
#include <kcmdlineargs.h>
|
||
|
#include <kglobal.h>
|
||
|
|
||
|
|
||
12 years ago
|
#include "tdeio_remote.h"
|
||
15 years ago
|
|
||
|
static const KCmdLineOptions options[] =
|
||
|
{
|
||
|
{ "+protocol", I18N_NOOP( "Protocol name" ), 0 },
|
||
|
{ "+pool", I18N_NOOP( "Socket name" ), 0 },
|
||
|
{ "+app", I18N_NOOP( "Socket name" ), 0 },
|
||
|
KCmdLineLastOption
|
||
|
};
|
||
|
|
||
|
extern "C" {
|
||
|
int KDE_EXPORT kdemain( int argc, char **argv )
|
||
|
{
|
||
12 years ago
|
// TDEApplication is necessary to use other ioslaves
|
||
15 years ago
|
putenv(strdup("SESSION_MANAGER="));
|
||
12 years ago
|
TDECmdLineArgs::init(argc, argv, "tdeio_remote", 0, 0, 0, 0);
|
||
12 years ago
|
TDECmdLineArgs::addCmdLineOptions( options );
|
||
12 years ago
|
TDEApplication app( false, false );
|
||
15 years ago
|
// We want to be anonymous even if we use DCOP
|
||
|
app.dcopClient()->attach();
|
||
|
|
||
12 years ago
|
TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
|
||
15 years ago
|
RemoteProtocol slave( args->arg(0), args->arg(1), args->arg(2) );
|
||
|
slave.dispatchLoop();
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
RemoteProtocol::RemoteProtocol(const TQCString &protocol,
|
||
|
const TQCString &pool, const TQCString &app)
|
||
15 years ago
|
: SlaveBase(protocol, pool, app)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
RemoteProtocol::~RemoteProtocol()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void RemoteProtocol::listDir(const KURL &url)
|
||
|
{
|
||
|
kdDebug(1220) << "RemoteProtocol::listDir: " << url << endl;
|
||
|
|
||
|
if ( url.path().length() <= 1 )
|
||
|
{
|
||
|
listRoot();
|
||
|
return;
|
||
|
}
|
||
|
|
||
13 years ago
|
int second_slash_idx = url.path().find( '/', 1 );
|
||
14 years ago
|
TQString root_dirname = url.path().mid( 1, second_slash_idx-1 );
|
||
15 years ago
|
|
||
|
KURL target = m_impl.findBaseURL( root_dirname );
|
||
|
kdDebug(1220) << "possible redirection target : " << target << endl;
|
||
|
if( target.isValid() )
|
||
|
{
|
||
|
target.addPath( url.path().remove(0, second_slash_idx) );
|
||
|
redirection(target);
|
||
|
finished();
|
||
|
return;
|
||
|
}
|
||
|
|
||
12 years ago
|
error(TDEIO::ERR_MALFORMED_URL, url.prettyURL());
|
||
15 years ago
|
}
|
||
|
|
||
|
void RemoteProtocol::listRoot()
|
||
|
{
|
||
12 years ago
|
TDEIO::UDSEntry entry;
|
||
15 years ago
|
|
||
12 years ago
|
TDEIO::UDSEntryList remote_entries;
|
||
15 years ago
|
m_impl.listRoot(remote_entries);
|
||
|
|
||
|
totalSize(remote_entries.count()+2);
|
||
|
|
||
|
m_impl.createTopLevelEntry(entry);
|
||
|
listEntry(entry, false);
|
||
|
|
||
|
m_impl.createWizardEntry(entry);
|
||
|
listEntry(entry, false);
|
||
|
|
||
12 years ago
|
TDEIO::UDSEntryListIterator it = remote_entries.begin();
|
||
|
TDEIO::UDSEntryListIterator end = remote_entries.end();
|
||
15 years ago
|
|
||
|
for(; it!=end; ++it)
|
||
|
{
|
||
|
listEntry(*it, false);
|
||
|
}
|
||
|
|
||
|
entry.clear();
|
||
|
listEntry(entry, true);
|
||
|
|
||
|
finished();
|
||
|
}
|
||
|
|
||
|
void RemoteProtocol::stat(const KURL &url)
|
||
|
{
|
||
|
kdDebug(1220) << "RemoteProtocol::stat: " << url << endl;
|
||
|
|
||
14 years ago
|
TQString path = url.path();
|
||
15 years ago
|
if ( path.isEmpty() || path == "/" )
|
||
|
{
|
||
|
// The root is "virtual" - it's not a single physical directory
|
||
12 years ago
|
TDEIO::UDSEntry entry;
|
||
15 years ago
|
m_impl.createTopLevelEntry( entry );
|
||
|
statEntry( entry );
|
||
|
finished();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (m_impl.isWizardURL(url))
|
||
|
{
|
||
12 years ago
|
TDEIO::UDSEntry entry;
|
||
15 years ago
|
if (m_impl.createWizardEntry(entry))
|
||
|
{
|
||
|
statEntry(entry);
|
||
|
finished();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
12 years ago
|
error(TDEIO::ERR_DOES_NOT_EXIST, url.prettyURL());
|
||
15 years ago
|
}
|
||
|
return;
|
||
|
}
|
||
|
|
||
13 years ago
|
int second_slash_idx = url.path().find( '/', 1 );
|
||
14 years ago
|
TQString root_dirname = url.path().mid( 1, second_slash_idx-1 );
|
||
15 years ago
|
|
||
|
if ( second_slash_idx==-1 || ( (int)url.path().length() )==second_slash_idx+1 )
|
||
|
{
|
||
12 years ago
|
TDEIO::UDSEntry entry;
|
||
15 years ago
|
if (m_impl.statNetworkFolder(entry, root_dirname))
|
||
|
{
|
||
|
statEntry(entry);
|
||
|
finished();
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
KURL target = m_impl.findBaseURL( root_dirname );
|
||
|
kdDebug( 1220 ) << "possible redirection target : " << target << endl;
|
||
|
if ( target.isValid() )
|
||
|
{
|
||
|
target.addPath( url.path().remove( 0, second_slash_idx ) );
|
||
|
redirection( target );
|
||
|
finished();
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
error(TDEIO::ERR_MALFORMED_URL, url.prettyURL());
|
||
15 years ago
|
}
|
||
|
|
||
|
void RemoteProtocol::del(const KURL &url, bool /*isFile*/)
|
||
|
{
|
||
|
kdDebug(1220) << "RemoteProtocol::del: " << url << endl;
|
||
|
|
||
|
if (!m_impl.isWizardURL(url)
|
||
|
&& m_impl.deleteNetworkFolder(url.fileName()))
|
||
|
{
|
||
|
finished();
|
||
|
return;
|
||
|
}
|
||
|
|
||
12 years ago
|
error(TDEIO::ERR_CANNOT_DELETE, url.prettyURL());
|
||
15 years ago
|
}
|
||
|
|
||
|
void RemoteProtocol::get(const KURL &url)
|
||
|
{
|
||
|
kdDebug(1220) << "RemoteProtocol::get: " << url << endl;
|
||
|
|
||
14 years ago
|
TQString file = m_impl.findDesktopFile( url.fileName() );
|
||
15 years ago
|
kdDebug(1220) << "desktop file : " << file << endl;
|
||
|
|
||
|
if (!file.isEmpty())
|
||
|
{
|
||
|
KURL desktop;
|
||
|
desktop.setPath(file);
|
||
|
|
||
|
redirection(desktop);
|
||
|
finished();
|
||
|
return;
|
||
|
}
|
||
|
|
||
12 years ago
|
error(TDEIO::ERR_MALFORMED_URL, url.prettyURL());
|
||
15 years ago
|
}
|
||
|
|
||
|
void RemoteProtocol::rename(const KURL &src, const KURL &dest,
|
||
|
bool overwrite)
|
||
|
{
|
||
|
if (src.protocol()!="remote" || dest.protocol()!="remote"
|
||
|
|| m_impl.isWizardURL(src) || m_impl.isWizardURL(dest))
|
||
|
{
|
||
12 years ago
|
error(TDEIO::ERR_UNSUPPORTED_ACTION, src.prettyURL());
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
if (m_impl.renameFolders(src.fileName(), dest.fileName(), overwrite))
|
||
|
{
|
||
|
finished();
|
||
|
return;
|
||
|
}
|
||
|
|
||
12 years ago
|
error(TDEIO::ERR_CANNOT_RENAME, src.prettyURL());
|
||
15 years ago
|
}
|