Changeset View
Changeset View
Standalone View
Standalone View
kioclient/kioclient.cpp
Show All 11 Lines | 1 | /* This file is part of the KDE project | |||
---|---|---|---|---|---|
12 | 12 | | |||
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 "urlinfo.h" | ||||
20 | 21 | | |||
21 | #include <KIO/CopyJob> | 22 | #include <KIO/CopyJob> | ||
22 | #include <KIO/DeleteJob> | 23 | #include <KIO/DeleteJob> | ||
23 | #include <kio/listjob.h> | 24 | #include <kio/listjob.h> | ||
24 | #include <kio/transferjob.h> | 25 | #include <kio/transferjob.h> | ||
25 | #ifndef KIOCORE_ONLY | 26 | #ifndef KIOCORE_ONLY | ||
26 | #include <KIO/JobUiDelegate> | 27 | #include <KIO/JobUiDelegate> | ||
27 | #include <KPropertiesDialog> | 28 | #include <KPropertiesDialog> | ||
28 | #include <KService> | 29 | #include <KService> | ||
29 | #include <KRun> | 30 | #include <KRun> | ||
30 | #include <KMimeTypeTrader> | 31 | #include <KMimeTypeTrader> | ||
31 | #endif | 32 | #endif | ||
32 | #include <KAboutData> | 33 | #include <KAboutData> | ||
33 | #include <KLocalizedString> | 34 | #include <KLocalizedString> | ||
34 | 35 | | |||
35 | #include <QDBusConnection> | 36 | #include <QDBusConnection> | ||
36 | #include <QCommandLineParser> | 37 | #include <QCommandLineParser> | ||
37 | #include <QFileDialog> | 38 | #include <QFileDialog> | ||
38 | #include <QDebug> | 39 | #include <QDebug> | ||
40 | #include <QUrlQuery> | ||||
39 | #include <iostream> | 41 | #include <iostream> | ||
40 | 42 | | |||
41 | bool ClientApp::m_ok = true; | 43 | bool ClientApp::m_ok = true; | ||
42 | static bool s_interactive = false; | 44 | static bool s_interactive = false; | ||
43 | static KIO::JobFlags s_jobFlags = KIO::DefaultFlags; | 45 | static KIO::JobFlags s_jobFlags = KIO::DefaultFlags; | ||
44 | 46 | | |||
45 | static QUrl makeURL(const QString &urlArg) | 47 | static QUrl makeURL(const QString &urlArg) | ||
46 | { | 48 | { | ||
▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Line(s) | 185 | { | |||
189 | if (max && (count > max)) | 191 | if (max && (count > max)) | ||
190 | { | 192 | { | ||
191 | fputs( i18nc("@info:shell", "%1: Syntax error, too many arguments\n", qAppName()).toLocal8Bit().constData(), stderr ); | 193 | fputs( i18nc("@info:shell", "%1: Syntax error, too many arguments\n", qAppName()).toLocal8Bit().constData(), stderr ); | ||
192 | ::exit(1); | 194 | ::exit(1); | ||
193 | } | 195 | } | ||
194 | } | 196 | } | ||
195 | 197 | | |||
196 | #ifndef KIOCORE_ONLY | 198 | #ifndef KIOCORE_ONLY | ||
197 | bool ClientApp::kde_open(const QUrl& url, const QString& mimeType, bool allowExec) | 199 | bool ClientApp::kde_open(const QString& url, const QString& mimeType, bool allowExec) | ||
198 | { | 200 | { | ||
201 | UrlInfo info(url); | ||||
202 | | ||||
203 | if(!info.atStart()) { | ||||
204 | QUrlQuery q; | ||||
205 | q.addQueryItem(QStringLiteral("line"), QString::number(info.line)); | ||||
206 | q.addQueryItem(QStringLiteral("column"), QString::number(info.column)); | ||||
207 | info.url.setQuery(q); | ||||
208 | } | ||||
209 | | ||||
199 | if ( mimeType.isEmpty() ) { | 210 | if ( mimeType.isEmpty() ) { | ||
200 | KRun * run = new KRun( url, nullptr ); | 211 | KRun * run = new KRun( info.url, nullptr ); | ||
201 | run->setRunExecutables(allowExec); | 212 | run->setRunExecutables(allowExec); | ||
202 | QObject::connect( run, SIGNAL( finished() ), this, SLOT( delayedQuit() )); | 213 | QObject::connect( run, SIGNAL( finished() ), this, SLOT( delayedQuit() )); | ||
203 | QObject::connect( run, SIGNAL( error() ), this, SLOT( delayedQuit() )); | 214 | QObject::connect( run, SIGNAL( error() ), this, SLOT( delayedQuit() )); | ||
204 | qApp->exec(); | 215 | qApp->exec(); | ||
205 | return !krun_has_error; | 216 | return !krun_has_error; | ||
206 | } else { | 217 | } else { | ||
207 | return KRun::runUrl(url, mimeType, nullptr, KRun::RunFlags(KRun::RunExecutables)); | 218 | return KRun::runUrl(info.url, mimeType, nullptr, KRun::RunFlags(KRun::RunExecutables)); | ||
208 | } | 219 | } | ||
209 | } | 220 | } | ||
210 | #endif | 221 | #endif | ||
211 | 222 | | |||
212 | bool ClientApp::doCopy( const QStringList& urls ) | 223 | bool ClientApp::doCopy( const QStringList& urls ) | ||
213 | { | 224 | { | ||
214 | QList<QUrl> srcLst(makeUrls(urls)); | 225 | QList<QUrl> srcLst(makeUrls(urls)); | ||
215 | QUrl dest = srcLst.takeLast(); | 226 | QUrl dest = srcLst.takeLast(); | ||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Line(s) | 289 | { | |||
289 | } | 300 | } | ||
290 | #if !defined(KIOCLIENT_AS_KDEOPEN) | 301 | #if !defined(KIOCLIENT_AS_KDEOPEN) | ||
291 | if (parser.isSet(QStringLiteral("overwrite"))) { | 302 | if (parser.isSet(QStringLiteral("overwrite"))) { | ||
292 | s_jobFlags |= KIO::Overwrite; | 303 | s_jobFlags |= KIO::Overwrite; | ||
293 | } | 304 | } | ||
294 | #endif | 305 | #endif | ||
295 | 306 | | |||
296 | #ifdef KIOCLIENT_AS_KDEOPEN | 307 | #ifdef KIOCLIENT_AS_KDEOPEN | ||
297 | return kde_open(makeURL(parser.positionalArguments().at(0)), QString(), false); | 308 | return kde_open(parser.positionalArguments().at(0), QString(), false); | ||
298 | #elif defined(KIOCLIENT_AS_KDECP5) | 309 | #elif defined(KIOCLIENT_AS_KDECP5) | ||
299 | checkArgumentCount(argc, 2, 0); | 310 | checkArgumentCount(argc, 2, 0); | ||
300 | return doCopy(parser.positionalArguments()); | 311 | return doCopy(parser.positionalArguments()); | ||
301 | #elif defined(KIOCLIENT_AS_KDEMV5) | 312 | #elif defined(KIOCLIENT_AS_KDEMV5) | ||
302 | checkArgumentCount(argc, 2, 0); | 313 | checkArgumentCount(argc, 2, 0); | ||
303 | return doMove(parser.positionalArguments()); | 314 | return doMove(parser.positionalArguments()); | ||
304 | #else | 315 | #else | ||
305 | // Normal kioclient mode | 316 | // Normal kioclient mode | ||
Show All 25 Lines | 333 | { | |||
331 | connect(job, SIGNAL( result( KJob * ) ), this, SLOT( slotResult( KJob * ) ) ); | 342 | connect(job, SIGNAL( result( KJob * ) ), this, SLOT( slotResult( KJob * ) ) ); | ||
332 | qApp->exec(); | 343 | qApp->exec(); | ||
333 | return m_ok; | 344 | return m_ok; | ||
334 | } | 345 | } | ||
335 | #ifndef KIOCORE_ONLY | 346 | #ifndef KIOCORE_ONLY | ||
336 | else if ( command ==QLatin1String( "exec") ) | 347 | else if ( command ==QLatin1String( "exec") ) | ||
337 | { | 348 | { | ||
338 | checkArgumentCount(argc, 2, 3); | 349 | checkArgumentCount(argc, 2, 3); | ||
339 | return kde_open( makeURL(parser.positionalArguments()[1]), | 350 | return kde_open( parser.positionalArguments()[1], | ||
340 | argc == 3 ? parser.positionalArguments().last() : QString(), | 351 | argc == 3 ? parser.positionalArguments().last() : QString(), | ||
341 | true ); | 352 | true ); | ||
342 | } | 353 | } | ||
343 | #endif | 354 | #endif | ||
344 | else if ( command == QLatin1String("download") ) | 355 | else if ( command == QLatin1String("download") ) | ||
345 | { | 356 | { | ||
346 | checkArgumentCount(argc, 0, 0); | 357 | checkArgumentCount(argc, 0, 0); | ||
347 | QStringList args = parser.positionalArguments(); | 358 | QStringList args = parser.positionalArguments(); | ||
▲ Show 20 Lines • Show All 93 Lines • Show Last 20 Lines |