Changeset View
Changeset View
Standalone View
Standalone View
src/kioexec/main.cpp
Show All 15 Lines | 1 | /* This file is part of the KDE project | |||
---|---|---|---|---|---|
16 | You should have received a copy of the GNU General Public License | 16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program; see the file COPYING. If not, write to | 17 | along with this program; see the file COPYING. If not, write to | ||
18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
19 | Boston, MA 02110-1301, USA. | 19 | Boston, MA 02110-1301, USA. | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #include "main.h" | 22 | #include "main.h" | ||
23 | #include "kio_version.h" | 23 | #include "kio_version.h" | ||
24 | #include "kioexecdinterface.h" | ||||
24 | 25 | | |||
25 | #include <QtCore/QFile> | 26 | #include <QtCore/QFile> | ||
26 | #include <QtCore/QDir> | 27 | #include <QtCore/QDir> | ||
27 | #include <QtCore/Q_PID> | 28 | #include <QtCore/Q_PID> | ||
28 | 29 | | |||
29 | #include <job.h> | 30 | #include <job.h> | ||
30 | #include <copyjob.h> | 31 | #include <copyjob.h> | ||
31 | #include <desktopexecparser.h> | 32 | #include <desktopexecparser.h> | ||
Show All 21 Lines | |||||
53 | 54 | | |||
54 | static const char description[] = | 55 | static const char description[] = | ||
55 | I18N_NOOP("KIO Exec - Opens remote files, watches modifications, asks for upload"); | 56 | I18N_NOOP("KIO Exec - Opens remote files, watches modifications, asks for upload"); | ||
56 | 57 | | |||
57 | 58 | | |||
58 | KIOExec::KIOExec(const QStringList &args, bool tempFiles, const QString &suggestedFileName) | 59 | KIOExec::KIOExec(const QStringList &args, bool tempFiles, const QString &suggestedFileName) | ||
59 | : mExited(false) | 60 | : mExited(false) | ||
60 | , mTempFiles(tempFiles) | 61 | , mTempFiles(tempFiles) | ||
62 | , mUseDaemon(false) | ||||
61 | , mSuggestedFileName(suggestedFileName) | 63 | , mSuggestedFileName(suggestedFileName) | ||
62 | , expectedCounter(0) | 64 | , expectedCounter(0) | ||
63 | , command(args.first()) | 65 | , command(args.first()) | ||
64 | , jobCounter(0) | 66 | , jobCounter(0) | ||
65 | { | 67 | { | ||
66 | qDebug() << "command=" << command << "args=" << args; | 68 | qDebug() << "command=" << command << "args=" << args; | ||
67 | 69 | | |||
68 | for (int i = 1; i < args.count(); i++) { | 70 | for (int i = 1; i < args.count(); i++) { | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 99 | } else { | |||
111 | fileList.append(file); | 113 | fileList.append(file); | ||
112 | 114 | | |||
113 | expectedCounter++; | 115 | expectedCounter++; | ||
114 | const QUrl dest = QUrl::fromLocalFile(tmp); | 116 | const QUrl dest = QUrl::fromLocalFile(tmp); | ||
115 | qDebug() << "Copying" << url << " to" << dest; | 117 | qDebug() << "Copying" << url << " to" << dest; | ||
116 | KIO::Job *job = KIO::file_copy(url, dest); | 118 | KIO::Job *job = KIO::file_copy(url, dest); | ||
117 | jobList.append(job); | 119 | jobList.append(job); | ||
118 | 120 | | |||
121 | // Tell kioexecd to watch the file for changes. | ||||
122 | OrgKdeKIOExecdInterface kioexecd(QStringLiteral("org.kde.kioexecd"), QStringLiteral("/modules/kioexecd"), QDBusConnection::sessionBus()); | ||||
123 | kioexecd.watch(file.path, file.url.toString()); | ||||
dfaure: Using a qdbusxml2cpp-generated header would provide more compile-time checking. | |||||
124 | mUseDaemon = !kioexecd.lastError().isValid(); | ||||
125 | | ||||
119 | connect(job, &KJob::result, this, &KIOExec::slotResult); | 126 | connect(job, &KJob::result, this, &KIOExec::slotResult); | ||
120 | } | 127 | } | ||
121 | } | 128 | } | ||
122 | } | 129 | } | ||
123 | 130 | | |||
124 | if (mTempFiles) { | 131 | if (mTempFiles) { | ||
125 | slotRunApp(); | 132 | slotRunApp(); | ||
126 | return; | 133 | return; | ||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Line(s) | 212 | #endif | |||
213 | 220 | | |||
214 | qDebug() << "EXEC done"; | 221 | qDebug() << "EXEC done"; | ||
215 | 222 | | |||
216 | // Test whether one of the files changed | 223 | // Test whether one of the files changed | ||
217 | for (it = fileList.begin(); it != fileList.end(); ++it) { | 224 | for (it = fileList.begin(); it != fileList.end(); ++it) { | ||
218 | QString src = it->path; | 225 | QString src = it->path; | ||
219 | const QUrl dest = it->url; | 226 | const QUrl dest = it->url; | ||
220 | QFileInfo info(src); | 227 | QFileInfo info(src); | ||
228 | const bool uploadChanges = !mUseDaemon && !dest.isLocalFile(); | ||||
221 | if (info.exists() && (it->time != info.lastModified())) { | 229 | if (info.exists() && (it->time != info.lastModified())) { | ||
222 | if (mTempFiles) { | 230 | if (mTempFiles) { | ||
223 | if (KMessageBox::questionYesNo(nullptr, | 231 | if (KMessageBox::questionYesNo(nullptr, | ||
224 | i18n("The supposedly temporary file\n%1\nhas been modified.\nDo you still want to delete it?", dest.toDisplayString(QUrl::PreferLocalFile)), | 232 | i18n("The supposedly temporary file\n%1\nhas been modified.\nDo you still want to delete it?", dest.toDisplayString(QUrl::PreferLocalFile)), | ||
225 | i18n("File Changed"), KStandardGuiItem::del(), KGuiItem(i18n("Do Not Delete"))) != KMessageBox::Yes) | 233 | i18n("File Changed"), KStandardGuiItem::del(), KGuiItem(i18n("Do Not Delete"))) != KMessageBox::Yes) | ||
226 | continue; // don't delete the temp file | 234 | continue; // don't delete the temp file | ||
227 | } else if (!dest.isLocalFile()) { // no upload when it's already a local file | 235 | } else if (uploadChanges) { // no upload when it's already a local file or kioexecd already did it. | ||
228 | if (KMessageBox::questionYesNo(nullptr, | 236 | if (KMessageBox::questionYesNo(nullptr, | ||
229 | i18n("The file\n%1\nhas been modified.\nDo you want to upload the changes?" , dest.toDisplayString()), | 237 | i18n("The file\n%1\nhas been modified.\nDo you want to upload the changes?" , dest.toDisplayString()), | ||
230 | i18n("File Changed"), KGuiItem(i18n("Upload")), KGuiItem(i18n("Do Not Upload"))) == KMessageBox::Yes) { | 238 | i18n("File Changed"), KGuiItem(i18n("Upload")), KGuiItem(i18n("Do Not Upload"))) == KMessageBox::Yes) { | ||
231 | qDebug() << "src='" << src << "' dest='" << dest << "'"; | 239 | qDebug() << "src='" << src << "' dest='" << dest << "'"; | ||
232 | // Do it the synchronous way. | 240 | // Do it the synchronous way. | ||
233 | KIO::CopyJob* job = KIO::copy(QUrl::fromLocalFile(src), dest); | 241 | KIO::CopyJob* job = KIO::copy(QUrl::fromLocalFile(src), dest); | ||
234 | if (!job->exec()) { | 242 | if (!job->exec()) { | ||
235 | KMessageBox::error(nullptr, job->errorText()); | 243 | KMessageBox::error(nullptr, job->errorText()); | ||
236 | continue; // don't delete the temp file | 244 | continue; // don't delete the temp file | ||
237 | } | 245 | } | ||
238 | } | 246 | } | ||
239 | } | 247 | } | ||
240 | } | 248 | } | ||
241 | 249 | | |||
242 | if ((!dest.isLocalFile() || mTempFiles) && exit_code == 0) { | 250 | if ((uploadChanges || mTempFiles) && exit_code == 0) { // Wait for a reasonable time so that even if the application forks on startup (like OOo or amarok) | ||
243 | // Wait for a reasonable time so that even if the application forks on startup (like OOo or amarok) | | |||
244 | // it will have time to start up and read the file before it gets deleted. #130709. | 251 | // it will have time to start up and read the file before it gets deleted. #130709. | ||
245 | qDebug() << "sleeping..."; | 252 | qDebug() << "sleeping..."; | ||
246 | QThread::currentThread()->sleep(180); // 3 mn | 253 | QThread::currentThread()->sleep(180); // 3 mn | ||
247 | const QString parentDir = info.path(); | 254 | const QString parentDir = info.path(); | ||
248 | qDebug() << "about to delete" << parentDir << "containing" << info.fileName(); | 255 | qDebug() << "about to delete" << parentDir << "containing" << info.fileName(); | ||
249 | QFile(QFile::encodeName(src)).remove(); | 256 | QFile(QFile::encodeName(src)).remove(); | ||
250 | QDir().rmdir(parentDir); | 257 | QDir().rmdir(parentDir); | ||
251 | } | 258 | } | ||
▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines |
Using a qdbusxml2cpp-generated header would provide more compile-time checking.