1 /* This file is part of the KDE project
2 Copyright (c) 2004 Kevin Ottens <ervin ipsquad net>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library 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.
9 This library 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 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #include "kio_remote.h"
26 #include <kapplication.h>
27 #include <kcmdlineargs.h>
33 int KDE_EXPORT
kdemain( int argc
, char **argv
)
35 // necessary to use other kio slaves
36 KComponentData
componentData("kio_remote" );
37 QCoreApplication
app(argc
, argv
);
40 RemoteProtocol
slave( argv
[1], argv
[2], argv
[3] );
47 RemoteProtocol::RemoteProtocol(const QByteArray
&protocol
,
48 const QByteArray
&pool
, const QByteArray
&app
)
49 : SlaveBase(protocol
, pool
, app
)
53 RemoteProtocol::~RemoteProtocol()
57 void RemoteProtocol::listDir(const KUrl
&url
)
59 kDebug(1220) << "RemoteProtocol::listDir: " << url
;
61 if ( url
.path().length() <= 1 )
67 int second_slash_idx
= url
.path().indexOf( '/', 1 );
68 QString root_dirname
= url
.path().mid( 1, second_slash_idx
-1 );
70 KUrl target
= m_impl
.findBaseURL( root_dirname
);
71 kDebug(1220) << "possible redirection target : " << target
;
72 if( target
.isValid() )
74 target
.addPath( url
.path().remove(0, second_slash_idx
) );
80 error(KIO::ERR_MALFORMED_URL
, url
.prettyUrl());
83 void RemoteProtocol::listRoot()
87 KIO::UDSEntryList remote_entries
;
88 m_impl
.listRoot(remote_entries
);
90 totalSize(remote_entries
.count()+2);
92 m_impl
.createTopLevelEntry(entry
);
93 listEntry(entry
, false);
95 m_impl
.createWizardEntry(entry
);
96 listEntry(entry
, false);
98 KIO::UDSEntryList::ConstIterator it
= remote_entries
.constBegin();
99 const KIO::UDSEntryList::ConstIterator end
= remote_entries
.constEnd();
102 listEntry(*it
, false);
106 listEntry(entry
, true);
111 void RemoteProtocol::stat(const KUrl
&url
)
113 kDebug(1220) << "RemoteProtocol::stat: " << url
;
115 QString path
= url
.path();
116 if ( path
.isEmpty() || path
== "/" )
118 // The root is "virtual" - it's not a single physical directory
120 m_impl
.createTopLevelEntry( entry
);
126 if (m_impl
.isWizardURL(url
))
129 if (m_impl
.createWizardEntry(entry
))
136 error(KIO::ERR_DOES_NOT_EXIST
, url
.prettyUrl());
141 int second_slash_idx
= url
.path().indexOf( '/', 1 );
142 QString root_dirname
= url
.path().mid( 1, second_slash_idx
-1 );
144 if ( second_slash_idx
==-1 || ( (int)url
.path().length() )==second_slash_idx
+1 )
147 if (m_impl
.statNetworkFolder(entry
, root_dirname
))
156 KUrl target
= m_impl
.findBaseURL( root_dirname
);
157 kDebug( 1220 ) << "possible redirection target : " << target
;
158 if ( target
.isValid() )
160 target
.addPath( url
.path().remove( 0, second_slash_idx
) );
161 redirection( target
);
167 error(KIO::ERR_MALFORMED_URL
, url
.prettyUrl());
170 void RemoteProtocol::del(const KUrl
&url
, bool /*isFile*/)
172 kDebug(1220) << "RemoteProtocol::del: " << url
;
174 if (!m_impl
.isWizardURL(url
)
175 && m_impl
.deleteNetworkFolder(url
.fileName()))
181 error(KIO::ERR_CANNOT_DELETE
, url
.prettyUrl());
184 void RemoteProtocol::get(const KUrl
&url
)
186 kDebug(1220) << "RemoteProtocol::get: " << url
;
188 QString file
= m_impl
.findDesktopFile( url
.fileName() );
189 kDebug(1220) << "desktop file : " << file
;
194 desktop
.setPath(file
);
196 redirection(desktop
);
201 error(KIO::ERR_MALFORMED_URL
, url
.prettyUrl());
204 void RemoteProtocol::rename(const KUrl
&src
, const KUrl
&dest
,
207 if (src
.protocol()!="remote" || dest
.protocol()!="remote"
208 || m_impl
.isWizardURL(src
) || m_impl
.isWizardURL(dest
))
210 error(KIO::ERR_UNSUPPORTED_ACTION
, src
.prettyUrl());
214 if (m_impl
.renameFolders(src
.fileName(), dest
.fileName(), flags
& KIO::Overwrite
))
220 error(KIO::ERR_CANNOT_RENAME
, src
.prettyUrl());