Changeset View
Changeset View
Standalone View
Standalone View
kioclient/kioclient.cpp
Show All 12 Lines | 1 | /* This file is part of the KDE project | |||
---|---|---|---|---|---|
13 | You should have received a copy of the GNU Library General Public License | 13 | You should have received a copy of the GNU Library General Public License | ||
14 | along with this library; see the file COPYING.LIB. If not, write to | 14 | along with this library; see the file COPYING.LIB. If not, write to | ||
15 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 15 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
16 | Boston, MA 02110-1301, USA. | 16 | Boston, MA 02110-1301, USA. | ||
17 | */ | 17 | */ | ||
18 | 18 | | |||
19 | #include "kioclient.h" | 19 | #include "kioclient.h" | ||
20 | #include "kio_version.h" | 20 | #include "kio_version.h" | ||
21 | #include "urlinfo.h" | ||||
21 | 22 | | |||
22 | #include <KIO/CopyJob> | 23 | #include <KIO/CopyJob> | ||
23 | #include <KIO/DeleteJob> | 24 | #include <KIO/DeleteJob> | ||
24 | #include <kio/listjob.h> | 25 | #include <kio/listjob.h> | ||
25 | #include <kio/transferjob.h> | 26 | #include <kio/transferjob.h> | ||
26 | #ifndef KIOCORE_ONLY | 27 | #ifndef KIOCORE_ONLY | ||
27 | #include <KIO/JobUiDelegate> | 28 | #include <KIO/JobUiDelegate> | ||
28 | #include <KPropertiesDialog> | 29 | #include <KPropertiesDialog> | ||
29 | #include <KService> | 30 | #include <KService> | ||
30 | #include <KRun> | 31 | #include <KRun> | ||
31 | #include <KMimeTypeTrader> | 32 | #include <KMimeTypeTrader> | ||
32 | #endif | 33 | #endif | ||
33 | #include <KAboutData> | 34 | #include <KAboutData> | ||
34 | #include <KLocalizedString> | 35 | #include <KLocalizedString> | ||
35 | 36 | | |||
36 | #include <QDBusConnection> | 37 | #include <QDBusConnection> | ||
37 | #include <QCommandLineParser> | 38 | #include <QCommandLineParser> | ||
38 | #include <QFileDialog> | 39 | #include <QFileDialog> | ||
39 | #include <QDebug> | 40 | #include <QDebug> | ||
41 | #include <QUrlQuery> | ||||
40 | #include <iostream> | 42 | #include <iostream> | ||
41 | 43 | | |||
42 | bool ClientApp::m_ok = true; | 44 | bool ClientApp::m_ok = true; | ||
43 | static bool s_interactive = false; | 45 | static bool s_interactive = false; | ||
44 | static KIO::JobFlags s_jobFlags = KIO::DefaultFlags; | 46 | static KIO::JobFlags s_jobFlags = KIO::DefaultFlags; | ||
45 | 47 | | |||
46 | static QUrl makeURL(const QString &urlArg) | 48 | static QUrl makeURL(const QString &urlArg) | ||
47 | { | 49 | { | ||
▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Line(s) | 186 | { | |||
190 | if (max && (count > max)) | 192 | if (max && (count > max)) | ||
191 | { | 193 | { | ||
192 | fputs( i18nc("@info:shell", "%1: Syntax error, too many arguments\n", qAppName()).toLocal8Bit().constData(), stderr ); | 194 | fputs( i18nc("@info:shell", "%1: Syntax error, too many arguments\n", qAppName()).toLocal8Bit().constData(), stderr ); | ||
193 | ::exit(1); | 195 | ::exit(1); | ||
194 | } | 196 | } | ||
195 | } | 197 | } | ||
196 | 198 | | |||
197 | #ifndef KIOCORE_ONLY | 199 | #ifndef KIOCORE_ONLY | ||
198 | bool ClientApp::kde_open(const QUrl& url, const QString& mimeType, bool allowExec) | 200 | bool ClientApp::kde_open(const QString& url, const QString& mimeType, bool allowExec) | ||
199 | { | 201 | { | ||
202 | UrlInfo info(url); | ||||
203 | | ||||
204 | if(!info.atStart()) { | ||||
205 | QUrlQuery q; | ||||
206 | q.addQueryItem(QStringLiteral("line"), QString::number(info.line)); | ||||
207 | q.addQueryItem(QStringLiteral("column"), QString::number(info.column)); | ||||
208 | info.url.setQuery(q); | ||||
209 | } | ||||
210 | | ||||
200 | if ( mimeType.isEmpty() ) { | 211 | if ( mimeType.isEmpty() ) { | ||
201 | KRun * run = new KRun( url, nullptr ); | 212 | KRun * run = new KRun( info.url, nullptr ); | ||
202 | run->setRunExecutables(allowExec); | 213 | run->setRunExecutables(allowExec); | ||
203 | 214 | | |||
204 | #if KIO_VERSION >= QT_VERSION_CHECK(5,55,0) | 215 | #if KIO_VERSION >= QT_VERSION_CHECK(5,55,0) | ||
205 | run->setFollowRedirections(false); | 216 | run->setFollowRedirections(false); | ||
206 | #endif | 217 | #endif | ||
207 | QObject::connect( run, SIGNAL( finished() ), this, SLOT( delayedQuit() )); | 218 | QObject::connect( run, SIGNAL( finished() ), this, SLOT( delayedQuit() )); | ||
208 | QObject::connect( run, SIGNAL( error() ), this, SLOT( delayedQuit() )); | 219 | QObject::connect( run, SIGNAL( error() ), this, SLOT( delayedQuit() )); | ||
209 | qApp->exec(); | 220 | qApp->exec(); | ||
210 | return !krun_has_error; | 221 | return !krun_has_error; | ||
211 | } else { | 222 | } else { | ||
212 | return KRun::runUrl(url, mimeType, nullptr, KRun::RunFlags(KRun::RunExecutables)); | 223 | return KRun::runUrl(info.url, mimeType, nullptr, KRun::RunFlags(KRun::RunExecutables)); | ||
213 | } | 224 | } | ||
214 | } | 225 | } | ||
215 | #endif | 226 | #endif | ||
216 | 227 | | |||
217 | bool ClientApp::doCopy( const QStringList& urls ) | 228 | bool ClientApp::doCopy( const QStringList& urls ) | ||
218 | { | 229 | { | ||
219 | QList<QUrl> srcLst(makeUrls(urls)); | 230 | QList<QUrl> srcLst(makeUrls(urls)); | ||
220 | QUrl dest = srcLst.takeLast(); | 231 | QUrl dest = srcLst.takeLast(); | ||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Line(s) | 294 | { | |||
294 | } | 305 | } | ||
295 | #if !defined(KIOCLIENT_AS_KDEOPEN) | 306 | #if !defined(KIOCLIENT_AS_KDEOPEN) | ||
296 | if (parser.isSet(QStringLiteral("overwrite"))) { | 307 | if (parser.isSet(QStringLiteral("overwrite"))) { | ||
297 | s_jobFlags |= KIO::Overwrite; | 308 | s_jobFlags |= KIO::Overwrite; | ||
298 | } | 309 | } | ||
299 | #endif | 310 | #endif | ||
300 | 311 | | |||
301 | #ifdef KIOCLIENT_AS_KDEOPEN | 312 | #ifdef KIOCLIENT_AS_KDEOPEN | ||
302 | return kde_open(makeURL(parser.positionalArguments().at(0)), QString(), false); | 313 | return kde_open(parser.positionalArguments().at(0), QString(), false); | ||
303 | #elif defined(KIOCLIENT_AS_KDECP5) | 314 | #elif defined(KIOCLIENT_AS_KDECP5) | ||
304 | checkArgumentCount(argc, 2, 0); | 315 | checkArgumentCount(argc, 2, 0); | ||
305 | return doCopy(parser.positionalArguments()); | 316 | return doCopy(parser.positionalArguments()); | ||
306 | #elif defined(KIOCLIENT_AS_KDEMV5) | 317 | #elif defined(KIOCLIENT_AS_KDEMV5) | ||
307 | checkArgumentCount(argc, 2, 0); | 318 | checkArgumentCount(argc, 2, 0); | ||
308 | return doMove(parser.positionalArguments()); | 319 | return doMove(parser.positionalArguments()); | ||
309 | #else | 320 | #else | ||
310 | // Normal kioclient mode | 321 | // Normal kioclient mode | ||
Show All 25 Lines | 338 | { | |||
336 | connect(job, SIGNAL( result( KJob * ) ), this, SLOT( slotResult( KJob * ) ) ); | 347 | connect(job, SIGNAL( result( KJob * ) ), this, SLOT( slotResult( KJob * ) ) ); | ||
337 | qApp->exec(); | 348 | qApp->exec(); | ||
338 | return m_ok; | 349 | return m_ok; | ||
339 | } | 350 | } | ||
340 | #ifndef KIOCORE_ONLY | 351 | #ifndef KIOCORE_ONLY | ||
341 | else if ( command ==QLatin1String( "exec") ) | 352 | else if ( command ==QLatin1String( "exec") ) | ||
342 | { | 353 | { | ||
343 | checkArgumentCount(argc, 2, 3); | 354 | checkArgumentCount(argc, 2, 3); | ||
344 | return kde_open( makeURL(parser.positionalArguments()[1]), | 355 | return kde_open( parser.positionalArguments()[1], | ||
345 | argc == 3 ? parser.positionalArguments().last() : QString(), | 356 | argc == 3 ? parser.positionalArguments().last() : QString(), | ||
346 | true ); | 357 | true ); | ||
347 | } | 358 | } | ||
348 | #endif | 359 | #endif | ||
349 | else if ( command == QLatin1String("download") ) | 360 | else if ( command == QLatin1String("download") ) | ||
350 | { | 361 | { | ||
351 | checkArgumentCount(argc, 0, 0); | 362 | checkArgumentCount(argc, 0, 0); | ||
352 | QStringList args = parser.positionalArguments(); | 363 | QStringList args = parser.positionalArguments(); | ||
▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines |