Changeset View
Changeset View
Standalone View
Standalone View
kioslave/remote/kio_remote.cpp
- This file was added.
1 | /* This file is part of the KDE project | ||||
---|---|---|---|---|---|
2 | Copyright (c) 2004 Kevin Ottens <ervin ipsquad net> | ||||
3 | | ||||
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. | ||||
8 | | ||||
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. | ||||
13 | | ||||
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. | ||||
18 | */ | ||||
19 | | ||||
20 | #include "kio_remote.h" | ||||
21 | #include "debug.h" | ||||
22 | #include <stdlib.h> | ||||
23 | | ||||
24 | #include <QCoreApplication> | ||||
25 | | ||||
26 | extern "C" { | ||||
27 | int Q_DECL_EXPORT kdemain( int argc, char **argv ) | ||||
28 | { | ||||
29 | // necessary to use other kio slaves | ||||
30 | QCoreApplication app(argc, argv); | ||||
31 | app.setApplicationName("kio_remote"); | ||||
32 | | ||||
33 | // start the slave | ||||
34 | RemoteProtocol slave( argv[1], argv[2], argv[3] ); | ||||
35 | slave.dispatchLoop(); | ||||
36 | return 0; | ||||
37 | } | ||||
38 | } | ||||
39 | | ||||
40 | | ||||
41 | RemoteProtocol::RemoteProtocol(const QByteArray &protocol, | ||||
42 | const QByteArray &pool, const QByteArray &app) | ||||
43 | : SlaveBase(protocol, pool, app) | ||||
44 | { | ||||
45 | } | ||||
46 | | ||||
47 | RemoteProtocol::~RemoteProtocol() | ||||
48 | { | ||||
49 | } | ||||
50 | | ||||
51 | void RemoteProtocol::listDir(const QUrl &url) | ||||
52 | { | ||||
53 | qCDebug(KIOREMOTE_LOG) << "RemoteProtocol::listDir: " << url; | ||||
54 | | ||||
55 | if ( url.path().length() <= 1 ) | ||||
56 | { | ||||
57 | listRoot(); | ||||
58 | return; | ||||
59 | } | ||||
60 | | ||||
61 | int second_slash_idx = url.path().indexOf( '/', 1 ); | ||||
62 | const QString root_dirname = url.path().mid( 1, second_slash_idx-1 ); | ||||
63 | | ||||
64 | QUrl target = m_impl.findBaseURL( root_dirname ); | ||||
65 | qCDebug(KIOREMOTE_LOG) << "possible redirection target : " << target; | ||||
66 | if( target.isValid() ) | ||||
67 | { | ||||
68 | if ( second_slash_idx < 0 ) { | ||||
69 | second_slash_idx = url.path().size(); | ||||
70 | } | ||||
71 | target = target.adjusted(QUrl::StripTrailingSlash); | ||||
72 | target.setPath(target.path() + '/' + ( url.path().remove(0, second_slash_idx) )); | ||||
73 | qCDebug(KIOREMOTE_LOG) << "complete redirection target : " << target; | ||||
74 | redirection(target); | ||||
75 | finished(); | ||||
76 | return; | ||||
77 | } | ||||
78 | | ||||
79 | error(KIO::ERR_MALFORMED_URL, url.toDisplayString()); | ||||
80 | } | ||||
81 | | ||||
82 | void RemoteProtocol::listRoot() | ||||
83 | { | ||||
84 | KIO::UDSEntry entry; | ||||
85 | | ||||
86 | KIO::UDSEntryList remote_entries; | ||||
87 | m_impl.listRoot(remote_entries); | ||||
88 | | ||||
89 | totalSize(remote_entries.count()+2); | ||||
90 | | ||||
91 | m_impl.createTopLevelEntry(entry); | ||||
92 | listEntry(entry); | ||||
93 | | ||||
94 | if(m_impl.createWizardEntry(entry)) | ||||
95 | listEntry(entry); | ||||
96 | | ||||
97 | KIO::UDSEntryList::ConstIterator it = remote_entries.constBegin(); | ||||
98 | const KIO::UDSEntryList::ConstIterator end = remote_entries.constEnd(); | ||||
99 | for(; it!=end; ++it) | ||||
100 | { | ||||
101 | listEntry(*it); | ||||
102 | } | ||||
103 | | ||||
104 | entry.clear(); | ||||
105 | finished(); | ||||
106 | } | ||||
107 | | ||||
108 | void RemoteProtocol::stat(const QUrl &url) | ||||
109 | { | ||||
110 | qCDebug(KIOREMOTE_LOG) << "RemoteProtocol::stat: " << url; | ||||
111 | | ||||
112 | QString path = url.path(); | ||||
113 | if ( path.isEmpty() || path == QLatin1String("/") ) | ||||
114 | { | ||||
115 | // The root is "virtual" - it's not a single physical directory | ||||
116 | KIO::UDSEntry entry; | ||||
117 | m_impl.createTopLevelEntry( entry ); | ||||
118 | statEntry( entry ); | ||||
119 | finished(); | ||||
120 | return; | ||||
121 | } | ||||
122 | | ||||
123 | if (m_impl.isWizardURL(url)) | ||||
124 | { | ||||
125 | KIO::UDSEntry entry; | ||||
126 | if (m_impl.createWizardEntry(entry)) | ||||
127 | { | ||||
128 | statEntry(entry); | ||||
129 | finished(); | ||||
130 | } | ||||
131 | else | ||||
132 | { | ||||
133 | error(KIO::ERR_DOES_NOT_EXIST, url.toDisplayString()); | ||||
134 | } | ||||
135 | return; | ||||
136 | } | ||||
137 | | ||||
138 | int second_slash_idx = url.path().indexOf( '/', 1 ); | ||||
139 | const QString root_dirname = url.path().mid( 1, second_slash_idx-1 ); | ||||
140 | | ||||
141 | if ( second_slash_idx==-1 || ( (int)url.path().length() )==second_slash_idx+1 ) | ||||
142 | { | ||||
143 | KIO::UDSEntry entry; | ||||
144 | if (m_impl.statNetworkFolder(entry, root_dirname)) | ||||
145 | { | ||||
146 | statEntry(entry); | ||||
147 | finished(); | ||||
148 | return; | ||||
149 | } | ||||
150 | } | ||||
151 | else | ||||
152 | { | ||||
153 | QUrl target = m_impl.findBaseURL( root_dirname ); | ||||
154 | qCDebug(KIOREMOTE_LOG) << "possible redirection target : " << target; | ||||
155 | if ( target.isValid() ) | ||||
156 | { | ||||
157 | if ( second_slash_idx < 0 ) { | ||||
158 | second_slash_idx = url.path().size(); | ||||
159 | } | ||||
160 | qCDebug(KIOREMOTE_LOG) << "complete redirection target : " << target; | ||||
161 | target = target.adjusted(QUrl::StripTrailingSlash); | ||||
162 | target.setPath(target.path() + '/' + ( url.path().remove( 0, second_slash_idx ) )); | ||||
163 | redirection( target ); | ||||
164 | finished(); | ||||
165 | return; | ||||
166 | } | ||||
167 | } | ||||
168 | | ||||
169 | error(KIO::ERR_MALFORMED_URL, url.toDisplayString()); | ||||
170 | } | ||||
171 | | ||||
172 | void RemoteProtocol::del(const QUrl &url, bool /*isFile*/) | ||||
173 | { | ||||
174 | qCDebug(KIOREMOTE_LOG) << "RemoteProtocol::del: " << url; | ||||
175 | | ||||
176 | if (!m_impl.isWizardURL(url) | ||||
177 | && m_impl.deleteNetworkFolder(url.fileName())) | ||||
178 | { | ||||
179 | finished(); | ||||
180 | return; | ||||
181 | } | ||||
182 | | ||||
183 | error(KIO::ERR_CANNOT_DELETE, url.toDisplayString()); | ||||
184 | } | ||||
185 | | ||||
186 | void RemoteProtocol::get(const QUrl &url) | ||||
187 | { | ||||
188 | qCDebug(KIOREMOTE_LOG) << "RemoteProtocol::get: " << url; | ||||
189 | | ||||
190 | const QString file = m_impl.findDesktopFile( url.fileName() ); | ||||
191 | qCDebug(KIOREMOTE_LOG) << "desktop file : " << file; | ||||
192 | | ||||
193 | if (!file.isEmpty()) | ||||
194 | { | ||||
195 | QUrl desktop; | ||||
196 | desktop.setPath(file); | ||||
197 | | ||||
198 | redirection(desktop); | ||||
199 | finished(); | ||||
200 | return; | ||||
201 | } | ||||
202 | | ||||
203 | error(KIO::ERR_MALFORMED_URL, url.toDisplayString()); | ||||
204 | } | ||||
205 | | ||||
206 | void RemoteProtocol::rename(const QUrl &src, const QUrl &dest, | ||||
207 | KIO::JobFlags flags) | ||||
208 | { | ||||
209 | if (src.scheme()!=QLatin1String("remote") || dest.scheme()!=QLatin1String("remote") | ||||
210 | || m_impl.isWizardURL(src) || m_impl.isWizardURL(dest)) | ||||
211 | { | ||||
212 | error(KIO::ERR_UNSUPPORTED_ACTION, src.toDisplayString()); | ||||
213 | return; | ||||
214 | } | ||||
215 | | ||||
216 | if (m_impl.renameFolders(src.fileName(), dest.fileName(), flags & KIO::Overwrite)) | ||||
217 | { | ||||
218 | finished(); | ||||
219 | return; | ||||
220 | } | ||||
221 | | ||||
222 | error(KIO::ERR_CANNOT_RENAME, src.toDisplayString()); | ||||
223 | } | ||||
224 | | ||||
225 | void RemoteProtocol::symlink(const QString &target, const QUrl &dest, KIO::JobFlags flags) | ||||
226 | { | ||||
227 | if (m_impl.changeFolderTarget(dest.fileName(), target, flags & KIO::Overwrite)) | ||||
228 | { | ||||
229 | finished(); | ||||
230 | return; | ||||
231 | } | ||||
232 | | ||||
233 | error(KIO::ERR_CANNOT_SYMLINK, dest.toDisplayString()); | ||||
234 | } |