delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / runtime / kioslave / remote / kio_remote.cpp
blob116da48560547c0fc008377cc4d800a030154b79
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"
22 #include <stdlib.h>
24 #include <kdebug.h>
25 #include <klocale.h>
26 #include <kapplication.h>
27 #include <kcmdlineargs.h>
28 #include <kglobal.h>
30 #include <QFile>
32 extern "C" {
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);
39 // start the slave
40 RemoteProtocol slave( argv[1], argv[2], argv[3] );
41 slave.dispatchLoop();
42 return 0;
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 )
63 listRoot();
64 return;
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) );
75 redirection(target);
76 finished();
77 return;
80 error(KIO::ERR_MALFORMED_URL, url.prettyUrl());
83 void RemoteProtocol::listRoot()
85 KIO::UDSEntry entry;
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();
100 for(; it!=end; ++it)
102 listEntry(*it, false);
105 entry.clear();
106 listEntry(entry, true);
108 finished();
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
119 KIO::UDSEntry entry;
120 m_impl.createTopLevelEntry( entry );
121 statEntry( entry );
122 finished();
123 return;
126 if (m_impl.isWizardURL(url))
128 KIO::UDSEntry entry;
129 if (m_impl.createWizardEntry(entry))
131 statEntry(entry);
132 finished();
134 else
136 error(KIO::ERR_DOES_NOT_EXIST, url.prettyUrl());
138 return;
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 )
146 KIO::UDSEntry entry;
147 if (m_impl.statNetworkFolder(entry, root_dirname))
149 statEntry(entry);
150 finished();
151 return;
154 else
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 );
162 finished();
163 return;
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()))
177 finished();
178 return;
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;
191 if (!file.isEmpty())
193 KUrl desktop;
194 desktop.setPath(file);
196 redirection(desktop);
197 finished();
198 return;
201 error(KIO::ERR_MALFORMED_URL, url.prettyUrl());
204 void RemoteProtocol::rename(const KUrl &src, const KUrl &dest,
205 KIO::JobFlags flags)
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());
211 return;
214 if (m_impl.renameFolders(src.fileName(), dest.fileName(), flags & KIO::Overwrite))
216 finished();
217 return;
220 error(KIO::ERR_CANNOT_RENAME, src.prettyUrl());