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