diff --git a/krusader/Dialogs/krdialogs.cpp b/krusader/Dialogs/krdialogs.cpp index 394b05f2..1ba4ba68 100644 --- a/krusader/Dialogs/krdialogs.cpp +++ b/krusader/Dialogs/krdialogs.cpp @@ -1,240 +1,264 @@ /***************************************************************************** * Copyright (C) 2000 Shie Erlich * * Copyright (C) 2000 Rafi Yanai * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This package is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #include "krdialogs.h" // QtCore #include // QtGui #include #include // QtWidgets #include #include #include #include #include #include #include #include #include #include #include #include #include "../krglobal.h" #include "../VFS/vfs.h" #include "../defaults.h" +#include "../JobMan/jobman.h" QUrl KChooseDir::getFile(const QString &text, const QUrl& url, const QUrl& cwd) { return get(text, url, cwd, KFile::File); } QUrl KChooseDir::getDir(const QString &text, const QUrl& url, const QUrl& cwd) { return get(text, url, cwd, KFile::Directory); } QUrl KChooseDir::get(const QString &text, const QUrl &url, const QUrl &cwd, KFile::Modes mode) { QScopedPointer dlg(new KUrlRequesterDialog(vfs::ensureTrailingSlash(url), text, krMainWindow)); dlg->urlRequester()->setStartDir(cwd); dlg->urlRequester()->setMode(mode); dlg->exec(); QUrl u = dlg->selectedUrl(); // empty if cancelled if (u.scheme() == "zip" || u.scheme() == "krarc" || u.scheme() == "tar" || u.scheme() == "iso") { if (QDir(u.path()).exists()) { u.setScheme("file"); } } return u; } KChooseDir::ChooseResult KChooseDir::getCopyDir(const QString &text, const QUrl &url, const QUrl &cwd, bool preserveAttrs, const QUrl &baseURL) { QScopedPointer dlg(new KUrlRequesterDlgForCopy( vfs::ensureTrailingSlash(url), text, preserveAttrs, krMainWindow, true, baseURL)); if (!preserveAttrs) dlg->hidePreserveAttrs(); dlg->urlRequester()->setStartDir(cwd); dlg->urlRequester()->setMode(KFile::Directory); dlg->exec(); QUrl u = dlg->selectedURL(); if (u.scheme() == "zip" || u.scheme() == "krarc" || u.scheme() == "tar" || u.scheme() == "iso") { if (QDir(u.path()).exists()) { u.setScheme("file"); } } ChooseResult result; result.url = u; - result.queue = dlg->enqueue(); + result.reverseQueueMode = dlg->isReverseQueueMode(); + result.startPaused = dlg->isStartPaused(); result.preserveAttrs = dlg->preserveAttrs(); result.baseURL = dlg->copyDirStructure() ? dlg->baseURL() : QUrl(); return result; } KUrlRequesterDlgForCopy::KUrlRequesterDlgForCopy(const QUrl &urlName, const QString &_text, bool /*presAttrs*/, QWidget *parent, bool modal, QUrl baseURL) : QDialog(parent), baseUrlCombo(0), copyDirStructureCB(0) { setWindowModality(modal ? Qt::WindowModal : Qt::NonModal); QVBoxLayout *mainLayout = new QVBoxLayout; setLayout(mainLayout); mainLayout->addWidget(new QLabel(_text)); urlRequester_ = new KUrlRequester(urlName, this); urlRequester_->setMinimumWidth(urlRequester_->sizeHint().width() * 3); mainLayout->addWidget(urlRequester_); // preserveAttrsCB = new QCheckBox(i18n("Preserve attributes (only for local targets)"), widget); // preserveAttrsCB->setChecked(presAttrs); // topLayout->addWidget(preserveAttrsCB); if (!baseURL.isEmpty()) { QFrame *line = new QFrame(this); line->setFrameStyle(QFrame::HLine | QFrame::Sunken); mainLayout->addWidget(line); copyDirStructureCB = new QCheckBox(i18n("Keep virtual folder structure"), this); connect(copyDirStructureCB, SIGNAL(toggled(bool)), this, SLOT(slotDirStructCBChanged())); copyDirStructureCB->setChecked(false); mainLayout->addWidget(copyDirStructureCB); QWidget *hboxWidget = new QWidget(this); QHBoxLayout * hbox = new QHBoxLayout(hboxWidget); QLabel * lbl = new QLabel(i18n("Base URL:"), hboxWidget); hbox->addWidget(lbl); baseUrlCombo = new QComboBox(hboxWidget); baseUrlCombo->setMinimumWidth(baseUrlCombo->sizeHint().width() * 3); baseUrlCombo->setEnabled(copyDirStructureCB->isChecked()); hbox->addWidget(baseUrlCombo); QUrl temp = baseURL, tempOld; do { QString baseURLText = temp.toDisplayString(QUrl::PreferLocalFile); baseUrlCombo->addItem(baseURLText); tempOld = temp; temp = KIO::upUrl(temp); } while (!tempOld.matches(temp, QUrl::StripTrailingSlash)); baseUrlCombo->setCurrentIndex(0); mainLayout->addWidget(hboxWidget); } QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); mainLayout->addWidget(buttonBox); okButton = buttonBox->button(QDialogButtonBox::Ok); okButton->setDefault(true); okButton->setShortcut(Qt::CTRL | Qt::Key_Return); - queueBox = new QCheckBox(i18n("Start &Paused"), this); - buttonBox->addButton(queueBox, QDialogButtonBox::ActionRole); + pauseBox = new QCheckBox(i18n("Start &Paused"), this); + buttonBox->addButton(pauseBox, QDialogButtonBox::ActionRole); + QPushButton *reverseQueueModeButton = new QPushButton(krJobMan->isQueueModeEnabled() ? i18n("F2 Run Immediately") : i18n("F2 Queue"), this); + reverseQueueModeButton->setToolTip(krJobMan->isQueueModeEnabled() ? i18n("Immediately start job even if there are running jobs in queue.") : i18n("Enqueue the job if queue is not empty. Otherwise start the job immediately.")); + buttonBox->addButton(reverseQueueModeButton, QDialogButtonBox::ActionRole); connect(buttonBox, SIGNAL(accepted()), SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), SLOT(reject())); + connect(reverseQueueModeButton, SIGNAL(clicked()), SLOT(slotReverseQueueMode())); connect(urlRequester_, SIGNAL(textChanged(QString)), SLOT(slotTextChanged(QString))); urlRequester_->setFocus(); bool state = !urlName.isEmpty(); okButton->setEnabled(state); } +void KUrlRequesterDlgForCopy::keyPressEvent(QKeyEvent *e) +{ + switch (e->key()) { + case Qt::Key_F2: + slotReverseQueueMode(); + return; + default: + QDialog::keyPressEvent(e); + } +} + +void KUrlRequesterDlgForCopy::slotReverseQueueMode() +{ + reverseQueueMode = true; + accept(); +} + + bool KUrlRequesterDlgForCopy::preserveAttrs() { // return preserveAttrsCB->isChecked(); return true; } bool KUrlRequesterDlgForCopy::copyDirStructure() { if (copyDirStructureCB == 0) return false; return copyDirStructureCB->isChecked(); } void KUrlRequesterDlgForCopy::slotTextChanged(const QString & text) { bool state = !text.trimmed().isEmpty(); okButton->setEnabled(state); } void KUrlRequesterDlgForCopy::slotDirStructCBChanged() { baseUrlCombo->setEnabled(copyDirStructureCB->isChecked()); } QUrl KUrlRequesterDlgForCopy::selectedURL() const { if (result() == QDialog::Accepted) { QUrl url = urlRequester_->url(); if (url.isValid()) KRecentDocument::add(url); return url; } else return QUrl(); } KUrlRequester * KUrlRequesterDlgForCopy::urlRequester() { return urlRequester_; } QUrl KUrlRequesterDlgForCopy::baseURL() const { if (baseUrlCombo == 0) return QUrl(); return QUrl::fromUserInput(baseUrlCombo->currentText(), QString(), QUrl::AssumeLocalFile); } KRGetDate::KRGetDate(QDate date, QWidget *parent) : QDialog(parent, Qt::MSWindowsFixedSizeDialogHint) { setWindowModality(Qt::WindowModal); dateWidget = new KDatePicker(this); dateWidget->setDate(date); dateWidget->resize(dateWidget->sizeHint()); setMinimumSize(dateWidget->sizeHint()); setMaximumSize(dateWidget->sizeHint()); resize(minimumSize()); connect(dateWidget, SIGNAL(dateSelected(QDate)), this, SLOT(setDate(QDate))); connect(dateWidget, SIGNAL(dateEntered(QDate)), this, SLOT(setDate(QDate))); // keep the original date - incase ESC is pressed originalDate = date; } QDate KRGetDate::getDate() { if (exec() == QDialog::Rejected) chosenDate = QDate(); hide(); return chosenDate; } void KRGetDate::setDate(QDate date) { chosenDate = date; accept(); } diff --git a/krusader/Dialogs/krdialogs.h b/krusader/Dialogs/krdialogs.h index 9f24ba64..ac6f0bce 100644 --- a/krusader/Dialogs/krdialogs.h +++ b/krusader/Dialogs/krdialogs.h @@ -1,124 +1,132 @@ /***************************************************************************** * Copyright (C) 2000 Shie Erlich * * Copyright (C) 2000 Rafi Yanai * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This package is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #ifndef KRDIALOGS_H #define KRDIALOGS_H // QtCore #include #include // QtWidgets #include #include #include #include #include #include #include // QtGui #include #include #include #include #include /** \class KChooseDir * Used for asking the user for a folder. * example: * \code * QUrl u = KChooseDir::getDir("target folder", "/suggested/path", ACTIVE_PANEL->virtualPath()); * if (u.isEmpty()) { * // user canceled (either by pressing cancel, or esc * } else { * // do you thing here: you've got a safe url to use * } * \endcode */ class KChooseDir { public: struct ChooseResult { QUrl url; - bool queue; + bool reverseQueueMode; + bool startPaused; bool preserveAttrs; // NOTE: field never read QUrl baseURL; // NOTE: field never read }; /** * \param text - description of the info requested from the user * \param url - a suggested url to appear in the box as a default choice * \param cwd - a path which is the current working directory (usually ACTIVE_PANEL->virtualPath()). * this is used for completion of partial urls */ static QUrl getFile(const QString &text, const QUrl &url, const QUrl &cwd); static QUrl getDir(const QString &text, const QUrl &url, const QUrl &cwd); static ChooseResult getCopyDir(const QString &text, const QUrl &url, const QUrl &cwd, bool preserveAttrs = false, const QUrl &baseURL = QUrl()); private: static QUrl get(const QString &text, const QUrl &url, const QUrl &cwd, KFile::Modes mode); }; class KUrlRequesterDlgForCopy : public QDialog { Q_OBJECT public: KUrlRequesterDlgForCopy(const QUrl& url, const QString& text, bool presAttrs, QWidget *parent, bool modal = true, QUrl baseURL = QUrl()); QUrl selectedURL() const; QUrl baseURL() const; bool preserveAttrs(); - bool enqueue() { return queueBox->isChecked(); } + bool isReverseQueueMode() { return reverseQueueMode; }; + bool isStartPaused() { return pauseBox->isChecked(); }; bool copyDirStructure(); void hidePreserveAttrs() { // preserveAttrsCB->hide(); } KUrlRequester *urlRequester(); +protected: + virtual void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE; + + private slots: + void slotReverseQueueMode(); void slotTextChanged(const QString &); void slotDirStructCBChanged(); private: KUrlRequester *urlRequester_; QComboBox *baseUrlCombo; // QCheckBox *preserveAttrsCB; QCheckBox *copyDirStructureCB; - QCheckBox *queueBox; + QCheckBox *pauseBox; QPushButton *okButton; + bool reverseQueueMode = false; }; class KRGetDate : public QDialog { Q_OBJECT public: KRGetDate(QDate date = QDate::currentDate(), QWidget *parent = 0); QDate getDate(); private slots: void setDate(QDate); private: KDatePicker *dateWidget; QDate chosenDate, originalDate; }; #endif diff --git a/krusader/JobMan/jobman.cpp b/krusader/JobMan/jobman.cpp index dda41f0c..03651f39 100644 --- a/krusader/JobMan/jobman.cpp +++ b/krusader/JobMan/jobman.cpp @@ -1,408 +1,410 @@ /***************************************************************************** * Copyright (C) 2016 Krusader Krew * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This package is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #include "jobman.h" // QtCore #include // QtWidgets #include #include #include #include #include #include #include #include #include #include "krjob.h" #include "../krglobal.h" /** The menu action entry for a job in the popup menu.*/ class JobMenuAction : public QWidgetAction { Q_OBJECT public: JobMenuAction(KrJob *krJob, QObject *parent) : QWidgetAction(parent), _krJob(krJob) { QWidget *container = new QWidget(); QGridLayout *layout = new QGridLayout(container); _description = new QLabel(krJob->description()); _progressBar = new QProgressBar(); layout->addWidget(_description, 0, 0, 1, 3); layout->addWidget(_progressBar, 1, 0); _pauseResumeButton = new QPushButton(); updatePauseResumeButton(); connect(_pauseResumeButton, &QPushButton::clicked, this, &JobMenuAction::slotPauseResumeButtonClicked); layout->addWidget(_pauseResumeButton, 1, 1); _cancelButton = new QPushButton(); _cancelButton->setIcon(QIcon::fromTheme("remove")); _cancelButton->setToolTip(i18n("Cancel Job")); connect(_cancelButton, &QPushButton::clicked, this, &JobMenuAction::slotCancelButtonClicked); layout->addWidget(_cancelButton, 1, 2); setDefaultWidget(container); connect(krJob, &KrJob::started, this, [=](KJob *job) { connect(job, &KJob::description, this, &JobMenuAction::slotDescription); connect(job, SIGNAL(percent(KJob *, unsigned long)), this, SLOT(slotPercent(KJob *, unsigned long))); connect(job, &KJob::suspended, this, &JobMenuAction::updatePauseResumeButton); connect(job, &KJob::resumed, this, &JobMenuAction::updatePauseResumeButton); connect(job, &KJob::result, this, &JobMenuAction::slotResult); connect(job, &KJob::warning, this, [](KJob *, const QString &plain, const QString &) { krOut << "unexpected job warning: " << plain; }); updatePauseResumeButton(); }); connect(krJob, &KrJob::terminated, this, &JobMenuAction::slotTerminated); } protected slots: void slotDescription(KJob *, const QString &description, const QPair &field1, const QPair &field2) { const QPair textField = !field2.first.isEmpty() ? field2 : field1; QString text = description; if (!textField.first.isEmpty()) { text += QString(" - %1: %2").arg(textField.first, textField.second); } _description->setText(text); if (!field2.first.isEmpty() && !field1.first.isEmpty()) { // NOTE: tooltips for QAction items in menu are not shown _progressBar->setToolTip(QString("%1: %2").arg(field1.first, field1.second)); } } void slotPercent(KJob *, unsigned long percent) { _progressBar->setValue(percent); } void updatePauseResumeButton() { _pauseResumeButton->setIcon(QIcon::fromTheme( _krJob->isRunning() ? "media-playback-pause" : _krJob->isManuallyPaused() ? "media-playback-start" : "chronometer-start")); _pauseResumeButton->setToolTip(_krJob->isRunning() ? i18n("Pause Job") : _krJob->isManuallyPaused() ? i18n("Resume Job") : i18n("Start Job")); } void slotResult(KJob *job) { // NOTE: _job may already set to 0 now if(!job->error()) { // percent signal is not reliable, set manually _progressBar->setValue(100); } } void slotTerminated() { _pauseResumeButton->setEnabled(false); _cancelButton->setIcon(QIcon::fromTheme("edit-clear")); _cancelButton->setToolTip(i18n("Clear")); _krJob = 0; } void slotPauseResumeButtonClicked() { if (!_krJob) return; if (_krJob->isRunning()) _krJob->pause(); else _krJob->start(); } void slotCancelButtonClicked() { if (_krJob) { _krJob->cancel(); } else { deleteLater(); } } private: KrJob *_krJob; QLabel *_description; QProgressBar *_progressBar; QPushButton *_pauseResumeButton; QPushButton *_cancelButton; }; #include "jobman.moc" // required for class definitions with Q_OBJECT macro in implementation files const QString JobMan::sDefaultToolTip = i18n("No jobs"); JobMan::JobMan(QObject *parent) : QObject(parent), _messageBox(0) { // job control action _controlAction = new KToolBarPopupAction(QIcon::fromTheme("media-playback-pause"), i18n("Play/Pause &Job"), this); _controlAction->setEnabled(false); connect(_controlAction, &QAction::triggered, this, &JobMan::slotControlActionTriggered); QMenu *menu = new QMenu(krMainWindow); menu->setMinimumWidth(300); // make scrollable if menu is too long menu->setStyleSheet("QMenu { menu-scrollable: 1; }"); _controlAction->setMenu(menu); // progress bar action _progressBar = new QProgressBar(); _progressBar->setToolTip(sDefaultToolTip); _progressBar->setEnabled(false); // listen to clicks on progress bar _progressBar->installEventFilter(this); QWidgetAction *progressAction = new QWidgetAction(krMainWindow); progressAction->setText(i18n("Job Progress Bar")); progressAction->setDefaultWidget(_progressBar); _progressAction = progressAction; // job queue mode action KConfigGroup cfg(krConfig, "JobManager"); _queueMode = cfg.readEntry("Queue Mode", false); _modeAction = new QAction(QIcon::fromTheme("media-playlist-repeat"), i18n("Job Queue Mode"), krMainWindow); _modeAction->setToolTip(i18n("Run only one job in parallel")); _modeAction->setCheckable(true); _modeAction->setChecked(_queueMode); connect(_modeAction, &QAction::toggled, [=](bool checked) mutable { _queueMode = checked; cfg.writeEntry("Queue Mode", _queueMode); }); // undo action KIO::FileUndoManager *undoManager = KIO::FileUndoManager::self(); undoManager->uiInterface()->setParentWidget(krMainWindow); _undoAction = new QAction(QIcon::fromTheme("edit-undo"), i18n("Undo Last Job"), krMainWindow); _undoAction->setEnabled(false); connect(_undoAction, &QAction::triggered, undoManager, &KIO::FileUndoManager::undo); connect(undoManager, static_cast(&KIO::FileUndoManager::undoAvailable), _undoAction, &QAction::setEnabled); connect(undoManager, &KIO::FileUndoManager::undoTextChanged, this, &JobMan::slotUndoTextChange); } bool JobMan::waitForJobs(bool waitForUserInput) { if (_jobs.isEmpty() && !waitForUserInput) return true; // attempt to get all job threads does not work //QList threads = krMainWindow->findChildren(); _autoCloseMessageBox = !waitForUserInput; _messageBox = new QMessageBox(krMainWindow); _messageBox->setWindowTitle(i18n("Warning")); _messageBox->setIconPixmap(QIcon::fromTheme("dialog-warning") .pixmap(QMessageBox::standardIcon(QMessageBox::Information).size())); _messageBox->setText(i18n("Are you sure you want to quit?")); _messageBox->addButton(QMessageBox::Abort); _messageBox->addButton(QMessageBox::Cancel); _messageBox->setDefaultButton(QMessageBox::Cancel); for (KrJob *job: _jobs) connect(job, &KrJob::terminated, this, &JobMan::slotUpdateMessageBox); slotUpdateMessageBox(); int result = _messageBox->exec(); // blocking _messageBox->deleteLater(); _messageBox = 0; // accepted -> cancel all jobs if (result == QMessageBox::Abort) { for (KrJob *job: _jobs) { job->cancel(); } return true; } // else: return false; } -void JobMan::manageJob(KrJob *job, bool enqueue) +void JobMan::manageJob(KrJob *job, bool reverseQueueMode, bool startPaused) { JobMenuAction *menuAction = new JobMenuAction(job, _controlAction); connect(menuAction, &QObject::destroyed, this, &JobMan::slotUpdateControlAction); _controlAction->menu()->addAction(menuAction); slotUpdateControlAction(); connect(job, &KrJob::started, this, &JobMan::slotKJobStarted); connect(job, &KrJob::terminated, this, &JobMan::slotTerminated); - if (!enqueue && !(_queueMode && jobsAreRunning())) { + bool isQueueMode = _queueMode != reverseQueueMode; + + if (!startPaused && (!jobsAreRunning() || !isQueueMode)) { job->start(); } _jobs.append(job); updateUI(); } // #### protected slots void JobMan::slotKJobStarted(KJob *job) { // KJob has two percent() functions connect(job, SIGNAL(percent(KJob *, unsigned long)), this, SLOT(slotPercent(KJob *, unsigned long))); connect(job, &KJob::description, this, &JobMan::slotDescription); connect(job, &KJob::suspended, this, &JobMan::updateUI); connect(job, &KJob::resumed, this, &JobMan::updateUI); } void JobMan::slotControlActionTriggered() { if (_jobs.isEmpty()) { _controlAction->menu()->clear(); _controlAction->setEnabled(false); return; } const bool anyRunning = jobsAreRunning(); if (!anyRunning && _queueMode) { _jobs.first()->start(); } else { for (KrJob *job : _jobs) { if (anyRunning) job->pause(); else job->start(); } } } void JobMan::slotPercent(KJob *, unsigned long) { updateUI(); } void JobMan::slotDescription(KJob*,const QString &description, const QPair &field1, const QPair &field2) { // TODO cache all descriptions if (_jobs.length() > 1) return; _progressBar->setToolTip( QString("%1\n%2: %3\n%4: %5") .arg(description, field1.first, field1.second, field2.first, field2.second)); } void JobMan::slotTerminated(KrJob *krJob) { _jobs.removeAll(krJob); if (!_jobs.isEmpty() && !jobsAreRunning()) { foreach (KrJob *job, _jobs) { if (!job->isManuallyPaused()) { // start next job job->start(); break; } } } updateUI(); } void JobMan::slotUpdateControlAction() { _controlAction->setEnabled(!_controlAction->menu()->isEmpty()); } void JobMan::slotUndoTextChange(const QString &text) { _undoAction->setToolTip(KIO::FileUndoManager::self()->undoAvailable() ? text : i18n("Undo Last Job")); } void JobMan::slotUpdateMessageBox() { if (!_messageBox) return; if (_jobs.isEmpty() && _autoCloseMessageBox) { _messageBox->done(QMessageBox::Abort); return; } if (_jobs.isEmpty()) { _messageBox->setInformativeText(""); _messageBox->setButtonText(QMessageBox::Abort, "Quit"); return; } _messageBox->setInformativeText(i18np("There is one job operation left.", "There are %1 job operations left.", _jobs.length())); _messageBox->setButtonText(QMessageBox::Abort, "Abort Jobs and Quit"); } // #### private void JobMan::updateUI() { int totalPercent = 0; for (KrJob *job: _jobs) { totalPercent += job->percent(); } const bool hasJobs = !_jobs.isEmpty(); _progressBar->setEnabled(hasJobs); if (hasJobs) { _progressBar->setValue(totalPercent / _jobs.length()); } else { _progressBar->reset(); } if (!hasJobs) _progressBar->setToolTip(i18n("No Jobs")); if (_jobs.length() > 1) _progressBar->setToolTip(i18np("%1 Job", "%1 Jobs", _jobs.length())); const bool running = jobsAreRunning(); _controlAction->setIcon(QIcon::fromTheme( !hasJobs ? "edit-clear" : running ? "media-playback-pause" : "media-playback-start")); _controlAction->setToolTip(!hasJobs ? i18n("Clear Job List") : running ? i18n("Pause All Jobs") : i18n("Resume Job List")); } bool JobMan::jobsAreRunning() { for (KrJob *job: _jobs) if (job->isRunning()) return true; return false; } diff --git a/krusader/JobMan/jobman.h b/krusader/JobMan/jobman.h index 580a7e77..2ce66f25 100644 --- a/krusader/JobMan/jobman.h +++ b/krusader/JobMan/jobman.h @@ -1,117 +1,126 @@ /***************************************************************************** * Copyright (C) 2010 Jan Lepper * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This package is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #ifndef JOBMAN_H #define JOBMAN_H // QtCore #include // QtWidgets #include #include #include #include #include class KrJob; /** * @brief The job manager provides a progress dialog and control over (KIO) file operation jobs. * * Job manager does not have a window (or dialog). All functions are provided via toolbar actions. * Icon, text and tooltip are already set, shortcuts are missing. * * If Job manager queue mode is activated only the first job is started. If more jobs are incoming * via manageJob() they are not started. If the running job finishes the next job in line is * started. * * Note that the desktop system (e.g. KDE Plasma Shell) may also has control over the jobs. * * Reference: plasma-workspace/kuiserver/progresslistdelegate.h * * If a job still exists Krusader does not exit on quit() until the job is finished. If the job is * paused this takes forever. Call waitForJobs() before exit to prevent this. * * About undoing jobs: If jobs are recorded (all KrJobs are, some in VFS) we can undo them with * FileUndoManager (which is a singleton) here. * It would be great if each job in the job list could be undone invividually but FileUndoManager * is currently (KF5.27) only able to undo the last recorded job. */ class JobMan : public QObject { Q_OBJECT public: explicit JobMan(QObject *parent = 0); /** Toolbar action icon for pausing/starting all jobs with drop down menu showing all jobs.*/ QAction *controlAction() const { return _controlAction; } /** Toolbar action progress bar showing the average job progress percentage of all jobs.*/ QAction *progressAction() const { return _progressAction; } /** Toolbar action combo box for changing the .*/ QAction *modeAction() const { return _modeAction; } QAction *undoAction() const { return _undoAction; } /** Wait for all jobs to terminate (blocking!). * * Returns true immediately if there are no jobs and user input is not required. Otherwise a * modal UI dialog is shown and the user can abort all jobs or cancel the dialog. * * @param waitForUserInput if true dialog is only closed after user interaction (button click) * @return true if no jobs are running (anymore) and user wants to quit. Else false */ bool waitForJobs(bool waitForUserInput); + /* Curent info about _queueMode state */ + bool isQueueModeEnabled() { return _queueMode; }; + public slots: /** Display, monitor and give user ability to control a job. - * If enqueued the job is not started. Otherwise this depends on the job manager mode. + * + * If reverseQueueMode is false, job is queued or run in parallel accordingly + * to job manager mode. When reverseQueueMode is true, opposite manager mode is chosen. + * + * When startPaused is true, job is never started immediately. Instead, it is waiting + * to be manually unpaused. Or in case of enabled queueMode it is started automatically + * when other jobs are finished. */ - void manageJob(KrJob *krJob, bool enqueue = false); + void manageJob(KrJob *krJob, bool reverseQueueMode = false, bool startPaused = false); protected slots: void slotKJobStarted(KJob *krJob); void slotControlActionTriggered(); void slotPercent(KJob *, unsigned long); void slotDescription(KJob*,const QString &description, const QPair &field1, const QPair &field2); void slotTerminated(KrJob *krJob); void slotUpdateControlAction(); void slotUndoTextChange(const QString &text); void slotUpdateMessageBox(); private: void updateUI(); bool jobsAreRunning(); QList _jobs; // all jobs not terminated (finished or canceled) yet bool _queueMode; KToolBarPopupAction *_controlAction; QProgressBar *_progressBar; QAction *_progressAction; QAction *_modeAction; QAction *_undoAction; QMessageBox *_messageBox; bool _autoCloseMessageBox; static const QString sDefaultToolTip; }; #endif // JOBMAN_H diff --git a/krusader/JobMan/krjob.cpp b/krusader/JobMan/krjob.cpp index 03022681..14e33b0d 100644 --- a/krusader/JobMan/krjob.cpp +++ b/krusader/JobMan/krjob.cpp @@ -1,126 +1,128 @@ /***************************************************************************** * Copyright (C) 2016 Krusader Krew * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This package is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #include "krjob.h" #include #include #include KrJob *KrJob::createCopyJob(KIO::CopyJob::CopyMode mode, const QList &src, - const QUrl &destination, KIO::JobFlags flags) + const QUrl &destination, KIO::JobFlags flags, bool startManually) { Type type; QString description; switch (mode) { case KIO::CopyJob::Copy: type = Copy; description = i18n("Copy to %1", destination.toDisplayString()); break; case KIO::CopyJob::Move: type = Move; description = i18n("Move to %1", destination.toDisplayString()); break; case KIO::CopyJob::Link: description = i18n("Link to %1", destination.toDisplayString()); type = Link; break; } - return new KrJob(type, src, destination, flags, description); + return new KrJob(type, src, destination, flags, description, startManually); } KrJob *KrJob::createDeleteJob(const QList &urls, bool moveToTrash) { const Type type = moveToTrash ? Trash : Delete; const bool oneFile = urls.length() == 1; const QString description = moveToTrash ? (oneFile ? i18n("Move %1 to trash", urls.first().toDisplayString()) : i18np("Move %1 file to trash", "Move %1 files to trash", urls.length())) : (oneFile ? i18n("Delete %1", urls.first().toDisplayString()) : i18np("Delete %1 file", "Delete %1 files", urls.length())); return new KrJob(type, urls, QUrl(), KIO::DefaultFlags, description); } KrJob::KrJob(Type type, const QList &urls, const QUrl &dest, KIO::JobFlags flags, - const QString &description) - : _type(type), _urls(urls), _dest(dest), _flags(flags), _description(description), _job(0) + const QString &description, bool startManually) + : _type(type), _urls(urls), _dest(dest), _flags(flags), _description(description), _initiallyPaused(startManually), _job(0) { } void KrJob::start() { if (_job) { // job was already started _job->resume(); return; } + _initiallyPaused = false; + switch (_type) { case Copy: { KIO::CopyJob *job = KIO::copy(_urls, _dest, _flags); KIO::FileUndoManager::self()->recordCopyJob(job); _job = job; break; } case Move: { KIO::CopyJob *job = KIO::move(_urls, _dest, _flags); KIO::FileUndoManager::self()->recordCopyJob(job); _job = job; break; } case Link: { KIO::CopyJob *job = KIO::link(_urls, _dest, _flags); KIO::FileUndoManager::self()->recordCopyJob(job); _job = job; break; } case Trash: { _job = KIO::trash(_urls); KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Trash, _urls, QUrl("trash:/"), _job); break; } case Delete: _job = KIO::del(_urls); } connect(_job, &KIO::Job::finished, [=]() { emit terminated(this); deleteLater(); }); emit started(_job); } void KrJob::cancel() { if (_job) _job->kill(); else { emit terminated(this); deleteLater(); } } void KrJob::pause() { if (_job) _job->suspend(); } diff --git a/krusader/JobMan/krjob.h b/krusader/JobMan/krjob.h index 7b28b79b..85460e86 100644 --- a/krusader/JobMan/krjob.h +++ b/krusader/JobMan/krjob.h @@ -1,86 +1,87 @@ /***************************************************************************** * Copyright (C) 2016 Krusader Krew * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This package is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #ifndef KRJOB_H #define KRJOB_H #include #include /** Wrapper for KIO::Job cause it has limitations. * * KIO::Jobs cannot be started in pause mode (and pausing direct after creation is buggy). Instead * a KrJob can be created which creates the KIO::Job on first start() call. * * Started jobs are recorded by KIO/FileUndoManager. * * KrJob is deleted after KIO::Job was deleted (which is after finished() call). Do not use * KIO::Job::finished() but KrJob::terminated() to be prepared for job deletion. */ class KrJob : public QObject { Q_OBJECT public: /** Type of this job. Add other types if needed.*/ enum Type { Copy, Move, Link, Trash, Delete }; /** Create a new copy, move, or link job. */ static KrJob *createCopyJob(KIO::CopyJob::CopyMode mode, const QList &src, - const QUrl &destination, KIO::JobFlags flags); + const QUrl &destination, KIO::JobFlags flags, bool startManually); /** Create a new trash or delete job. */ static KrJob *createDeleteJob(const QList &urls, bool moveToTrash); /** Start or resume this job. If job was started started() is emitted. */ void start(); /** Cancel this job and mark for deletion. terminated() will be emitted.*/ void cancel(); /** Suspend job (if started). */ void pause(); /** Return true if job was started and is not suspended(). */ bool isRunning() const { return _job && !_job->isSuspended(); } /** Return true if job was started and then paused by user. */ - bool isManuallyPaused() const { return _job && _job->isSuspended(); } + bool isManuallyPaused() const { return _initiallyPaused || (_job && _job->isSuspended()); } /** Return percent progress of job. */ int percent() const { return _job ? _job->percent() : 0; } /** Return (initial) job description. * The KIO::Job emits a more detailed description after start. */ QString description() const { return _description; } signals: /** Emitted if job was started. Parameter is the KIO::Job that was created. */ void started(KIO::Job *job); /** Emitted if job is finished or was canceled. Job will be deleted afterwards. */ void terminated(KrJob *krJob); private: KrJob(Type type, const QList &urls, const QUrl &dest, KIO::JobFlags flags, - const QString &description); + const QString &description, bool startManually = false); const Type _type; const QList _urls; const QUrl _dest; const KIO::JobFlags _flags; const QString _description; + bool _initiallyPaused; KIO::Job *_job; }; #endif // KRJOB_H diff --git a/krusader/Panel/panelfunc.cpp b/krusader/Panel/panelfunc.cpp index 8df2bada..4b38cb7f 100644 --- a/krusader/Panel/panelfunc.cpp +++ b/krusader/Panel/panelfunc.cpp @@ -1,1203 +1,1216 @@ /*************************************************************************** panelfunc.cpp ------------------- copyright : (C) 2000 by Shie Erlich & Rafi Yanai e-mail : krusader@users.sourceforge.net web site : http://krusader.sourceforge.net --------------------------------------------------------------------------- Description *************************************************************************** A db dD d8888b. db db .d8888. .d8b. d8888b. d88888b d8888b. 88 ,8P' 88 `8D 88 88 88' YP d8' `8b 88 `8D 88' 88 `8D 88,8P 88oobY' 88 88 `8bo. 88ooo88 88 88 88ooooo 88oobY' 88`8b 88`8b 88 88 `Y8b. 88~~~88 88 88 88~~~~~ 88`8b 88 `88. 88 `88. 88b d88 db 8D 88 88 88 .8D 88. 88 `88. YP YD 88 YD ~Y8888P' `8888Y' YP YP Y8888D' Y88888P 88 YD S o u r c e F i l e *************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "panelfunc.h" // QtCore #include #include #include #include #include #include // QtGui #include #include // QtWidgets #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "dirhistoryqueue.h" #include "krcalcspacedialog.h" #include "listpanel.h" #include "krerrordisplay.h" #include "listpanelactions.h" #include "../krglobal.h" #include "../krslots.h" #include "../kractions.h" #include "../defaults.h" #include "../abstractpanelmanager.h" #include "../krservices.h" #include "../Archive/krarchandler.h" #include "../Archive/packjob.h" #include "../VFS/vfile.h" #include "../VFS/virt_vfs.h" #include "../VFS/krpermhandler.h" #include "../VFS/krvfshandler.h" #include "../Dialogs/packgui.h" #include "../Dialogs/krdialogs.h" #include "../Dialogs/krpleasewait.h" #include "../Dialogs/krspwidgets.h" #include "../Dialogs/checksumdlg.h" #include "../KViewer/krviewer.h" #include "../GUI/syncbrowsebutton.h" #include "../MountMan/kmountman.h" +#include "../JobMan/jobman.h" QPointer ListPanelFunc::copyToClipboardOrigin; ListPanelFunc::ListPanelFunc(ListPanel *parent) : QObject(parent), panel(parent), vfsP(0), urlManuallyEntered(false), _refreshing(false), _ignoreVFSErrors(false) { history = new DirHistoryQueue(panel); delayTimer.setSingleShot(true); connect(&delayTimer, SIGNAL(timeout()), this, SLOT(doRefresh())); } ListPanelFunc::~ListPanelFunc() { if (vfsP) { vfsP->deleteLater(); } delete history; } void ListPanelFunc::navigatorUrlChanged(const QUrl &url) { if (_refreshing) return; if (!ListPanel::isNavigatorEditModeSet()) { panel->urlNavigator->setUrlEditable(false); } openUrl(KrServices::escapeFileUrl(url), QString(), true); } bool ListPanelFunc::isSyncing(const QUrl &url) { if(otherFunc()->otherFunc() == this && panel->otherPanel()->gui->syncBrowseButton->state() == SYNCBROWSE_CD && !otherFunc()->syncURL.isEmpty() && otherFunc()->syncURL == url) return true; return false; } void ListPanelFunc::openFileNameInternal(const QString &name, bool theFileCanBeExecutedOrOpenedWithOtherSoftware) { if (name == "..") { dirUp(); return ; } vfile *vf = files()->getVfile(name); if (vf == 0) return ; QUrl url = files()->getUrl(name); if (vf->vfile_isDir()) { panel->view->setNameToMakeCurrent(QString()); openUrl(url); return; } QString mime = vf->vfile_getMime(); QUrl arcPath = browsableArchivePath(name); if (!arcPath.isEmpty()) { bool theArchiveMustBeBrowsedAsADirectory = (KConfigGroup(krConfig, "Archives").readEntry("ArchivesAsDirectories", _ArchivesAsDirectories) && KRarcHandler::arcSupported(mime)) || !theFileCanBeExecutedOrOpenedWithOtherSoftware; if (theArchiveMustBeBrowsedAsADirectory) { openUrl(arcPath); return; } } if (theFileCanBeExecutedOrOpenedWithOtherSoftware) { if (KRun::isExecutableFile(url, mime)) { runCommand(KShell::quoteArg(url.path())); return; } KService::Ptr service = KMimeTypeTrader::self()->preferredService(mime); if(service) { runService(*service, QList() << url); return; } displayOpenWithDialog(QList() << url); } } #if 0 //FIXME: see if this is still needed void ListPanelFunc::popErronousUrl() { QUrl current = urlStack.last(); while (urlStack.count() != 0) { QUrl url = urlStack.takeLast(); if (!current.equals(url)) { immediateOpenUrl(url, true); return; } } immediateOpenUrl(QUrl::fromLocalFile(ROOT_DIR), true); } #endif QUrl ListPanelFunc::cleanPath(const QUrl &urlIn) { QUrl url = urlIn; url.setPath(QDir::cleanPath(url.path())); if (!url.isValid() || url.isRelative()) { if (url.url() == "~") url = QUrl::fromLocalFile(QDir::homePath()); else if (!url.url().startsWith('/')) { // possible relative URL - translate to full URL url = files()->currentDirectory(); url.setPath(url.path() + '/' + urlIn.path()); } } url.setPath(QDir::cleanPath(url.path())); return url; } void ListPanelFunc::openUrl(const QUrl &url, const QString& nameToMakeCurrent, bool manuallyEntered) { if (panel->syncBrowseButton->state() == SYNCBROWSE_CD) { //do sync-browse stuff.... if(syncURL.isEmpty()) syncURL = panel->otherPanel()->virtualPath(); QString relative = QDir(panel->virtualPath().path() + '/').relativeFilePath(url.path()); syncURL.setPath(QDir::cleanPath(syncURL.path() + '/' + relative)); panel->otherPanel()->gui->setLocked(false); otherFunc()->openUrlInternal(syncURL, nameToMakeCurrent, false, false, false); } openUrlInternal(url, nameToMakeCurrent, false, false, manuallyEntered); } void ListPanelFunc::immediateOpenUrl(const QUrl &url, bool disableLock) { openUrlInternal(url, QString(), true, disableLock, false); } void ListPanelFunc::openUrlInternal(const QUrl &url, const QString& nameToMakeCurrent, bool immediately, bool disableLock, bool manuallyEntered) { QUrl cleanUrl = cleanPath(url); if (!disableLock && panel->isLocked() && !files()->currentDirectory().matches(cleanUrl, QUrl::StripTrailingSlash)) { panel->_manager->newTab(url); urlManuallyEntered = false; return; } urlManuallyEntered = manuallyEntered; history->add(cleanUrl, nameToMakeCurrent); if(immediately) doRefresh(); else refresh(); } void ListPanelFunc::refresh() { panel->inlineRefreshCancel(); delayTimer.start(0); // to avoid qApp->processEvents() deadlock situaltion } void ListPanelFunc::doRefresh() { _refreshing = true; delayTimer.stop(); QUrl url = history->currentUrl(); if(!url.isValid()) { //FIXME go back in history here ? panel->slotStartUpdate(true); // refresh the panel urlManuallyEntered = false; return ; } panel->inlineRefreshCancel(); // if we are not refreshing to current URL bool isEqualUrl = files()->currentDirectory().matches(url, QUrl::StripTrailingSlash); if (!isEqualUrl) { panel->setCursor(Qt::WaitCursor); panel->view->clearSavedSelection(); } if(panel->vfsError) panel->vfsError->hide(); bool refreshFailed = false; while (true) { QUrl url = history->currentUrl(); isEqualUrl = files()->currentDirectory().matches(url, QUrl::StripTrailingSlash); // may get a new vfs for this url vfs* vfs = KrVfsHandler::instance().getVfs(url, files()); vfs->setParentWindow(krMainWindow); connect(vfs, &vfs::aboutToOpenDir, &krMtMan, &KMountMan::autoMount, Qt::DirectConnection); if (vfs != vfsP) { panel->view->setFiles(0); // disconnect older signals disconnect(vfsP, 0, panel, 0); vfsP->deleteLater(); vfsP = vfs; // v != 0 so this is safe } else { if (vfsP->isRefreshing()) { delayTimer.start(100); /* if vfs is busy try refreshing later */ return; } } // (re)connect vfs signals disconnect(files(), 0, panel, 0); connect(files(), SIGNAL(refreshDone(bool)), panel, SLOT(slotStartUpdate(bool))); connect(files(), SIGNAL(refreshJobStarted(KIO::Job*)), panel, SLOT(slotJobStarted(KIO::Job*))); connect(files(), SIGNAL(error(QString)), panel, SLOT(slotVfsError(QString))); panel->view->setFiles(files()); if(!history->currentItem().isEmpty() && isEqualUrl) { // if the url we're refreshing into is the current one, then the // partial refresh will not generate the needed signals to actually allow the // view to use nameToMakeCurrent. do it here instead (patch by Thomas Jarosch) panel->view->setCurrentItem(history->currentItem()); panel->view->makeItemVisible(panel->view->getCurrentKrViewItem()); } panel->view->setNameToMakeCurrent(history->currentItem()); int savedHistoryState = history->state(); // NOTE: this is blocking. Returns false on error or interruption (cancel requested or panel // was deleted) const bool refreshed = vfsP->refresh(url); if (refreshed) { // update the history and address bar, as the actual url might differ from the one requested history->setCurrentUrl(vfsP->currentDirectory()); panel->urlNavigator->setLocationUrl(vfsP->currentDirectory()); break; // we have a valid refreshed URL now } if (!panel || !panel->view) // this panel was deleted while refreshing return; refreshFailed = true; panel->view->setNameToMakeCurrent(QString()); if(history->state() != savedHistoryState) // don't go back if the history was touched break; if(!history->goBack()) { // put the root dir to the beginning of history, if it's not there yet if (!url.matches(QUrl::fromLocalFile(ROOT_DIR), QUrl::StripTrailingSlash)) history->pushBackRoot(); else break; } _ignoreVFSErrors = true; } _ignoreVFSErrors = false; panel->view->setNameToMakeCurrent(QString()); panel->setCursor(Qt::ArrowCursor); // on local file system change the working directory if (files()->isLocal()) QDir::setCurrent(KrServices::urlToLocalPath(files()->currentDirectory())); // see if the open url operation failed, and if so, // put the attempted url in the navigator bar and let the user change it if (refreshFailed) { if(isSyncing(url)) panel->otherPanel()->gui->syncBrowseButton->setChecked(false); else if(urlManuallyEntered) { panel->urlNavigator->setLocationUrl(url); if(panel == ACTIVE_PANEL) panel->editLocation(); } } if(otherFunc()->otherFunc() == this) // not true if our tab is not active otherFunc()->syncURL = QUrl(); urlManuallyEntered = false; refreshActions(); _refreshing = false; } void ListPanelFunc::redirectLink() { if (!files()->isLocal()) { KMessageBox::sorry(krMainWindow, i18n("You can edit links only on local file systems")); return ; } vfile *vf = files()->getVfile(panel->getCurrentName()); if (!vf) return ; QString file = vf->vfile_getUrl().path(); QString currentLink = vf->vfile_getSymDest(); if (currentLink.isEmpty()) { KMessageBox::sorry(krMainWindow, i18n("The current file is not a link, so it cannot be redirected.")); return ; } // ask the user for a new destination bool ok = false; QString newLink = QInputDialog::getText(krMainWindow, i18n("Link Redirection"), i18n("Please enter the new link destination:"), QLineEdit::Normal, currentLink, &ok); // if the user canceled - quit if (!ok || newLink == currentLink) return ; // delete the current link if (unlink(file.toLocal8Bit()) == -1) { KMessageBox::sorry(krMainWindow, i18n("Cannot remove old link: %1", file)); return ; } // try to create a new symlink if (symlink(newLink.toLocal8Bit(), file.toLocal8Bit()) == -1) { KMessageBox:: /* --=={ Patch by Heiner }==-- */sorry(krMainWindow, i18n("Failed to create a new link: %1", file)); return ; } } void ListPanelFunc::krlink(bool sym) { if (!files()->isLocal()) { KMessageBox::sorry(krMainWindow, i18n("You can create links only on local file systems")); return; } QString name = panel->getCurrentName(); // ask the new link name.. bool ok = false; QString linkName = QInputDialog::getText(krMainWindow, i18n("New Link"), i18n("Create a new link to: %1", name), QLineEdit::Normal, name, &ok); // if the user canceled - quit if (!ok || linkName == name) return; // if the name is already taken - quit if (files()->getVfile(linkName) != 0) { KMessageBox::sorry(krMainWindow, i18n("A folder or a file with this name already exists.")); return; } // make link name and target absolute path if (linkName.left(1) != "/") linkName = files()->currentDirectory().path() + '/' + linkName; name = files()->getUrl(name).path(); if (sym) { if (symlink(name.toLocal8Bit(), linkName.toLocal8Bit()) == -1) KMessageBox::sorry(krMainWindow, i18n("Failed to create a new symlink '%1' to: '%2'", linkName, name)); } else { if (link(name.toLocal8Bit(), linkName.toLocal8Bit()) == -1) KMessageBox::sorry(krMainWindow, i18n("Failed to create a new link '%1' to '%2'", linkName, name)); } } void ListPanelFunc::view() { QString fileName = panel->getCurrentName(); if (fileName.isNull()) return ; // if we're trying to view a directory, just exit vfile * vf = files()->getVfile(fileName); if (!vf || vf->vfile_isDir()) return ; if (!vf->vfile_isReadable()) { KMessageBox::sorry(0, i18n("No permissions to view this file.")); return ; } // call KViewer. KrViewer::view(files()->getUrl(fileName)); // nothing more to it! } void ListPanelFunc::viewDlg() { // ask the user for a url to view QUrl dest = KChooseDir::getFile(i18n("Enter a URL to view:"), panel->virtualPath(), panel->virtualPath()); if (dest.isEmpty()) return ; // the user canceled KrViewer::view(dest); // view the file } void ListPanelFunc::terminal() { SLOTS->runTerminal(panel->realPath()); } void ListPanelFunc::edit() { KFileItem tmp; if (fileToCreate.isEmpty()) { QString name = panel->getCurrentName(); if (name.isNull()) return; fileToCreate = files()->getUrl(name); } tmp = KFileItem(fileToCreate); if (tmp.isDir()) { KMessageBox::sorry(krMainWindow, i18n("You cannot edit a folder")); fileToCreate = QUrl(); return ; } if (!tmp.isReadable()) { KMessageBox::sorry(0, i18n("No permissions to edit this file.")); fileToCreate = QUrl(); return; } KrViewer::edit(fileToCreate); fileToCreate = QUrl(); } void ListPanelFunc::editNew() { if(!fileToCreate.isEmpty()) return; // ask the user for the filename to edit fileToCreate = KChooseDir::getFile(i18n("Enter the filename to edit:"), panel->virtualPath(), panel->virtualPath()); if(fileToCreate.isEmpty()) return ; // the user canceled // if the file exists, edit it instead of creating a new one QFile f(fileToCreate.toLocalFile()); if(f.exists()) { edit(); } else { QTemporaryFile *tempFile = new QTemporaryFile; tempFile->open(); KIO::CopyJob *job = KIO::copy(QUrl::fromLocalFile(tempFile->fileName()), fileToCreate); job->setUiDelegate(0); job->setDefaultPermissions(true); connect(job, SIGNAL(result(KJob*)), SLOT(slotFileCreated(KJob*))); connect(job, SIGNAL(result(KJob*)), tempFile, SLOT(deleteLater())); } } void ListPanelFunc::slotFileCreated(KJob *job) { if(!job->error() || job->error() == KIO::ERR_FILE_ALREADY_EXIST) { KrViewer::edit(fileToCreate); if(KIO::upUrl(fileToCreate).matches(panel->virtualPath(), QUrl::StripTrailingSlash)) refresh(); else if(KIO::upUrl(fileToCreate).matches(panel->otherPanel()->virtualPath(), QUrl::StripTrailingSlash)) otherFunc()->refresh(); } else KMessageBox::sorry(krMainWindow, job->errorString()); fileToCreate = QUrl(); } -void ListPanelFunc::copyFiles(bool enqueue, bool move) +void ListPanelFunc::moveFilesByQueue() +{ + moveFiles(!krJobMan->isQueueModeEnabled()); +} + +void ListPanelFunc::copyFilesByQueue() +{ + copyFiles(!krJobMan->isQueueModeEnabled()); +} + +void ListPanelFunc::copyFiles(bool reverseQueueMode, bool move) { QStringList fileNames; panel->getSelectedNames(&fileNames); if (fileNames.isEmpty()) return ; // safety QUrl destination = panel->otherPanel()->virtualPath(); + bool startPaused = false; KConfigGroup group(krConfig, "Advanced"); bool showDialog = move ? group.readEntry("Confirm Move", _ConfirmMove) : group.readEntry("Confirm Copy", _ConfirmCopy); if (showDialog) { QString operationText; if (move) { operationText = fileNames.count() == 1 ? i18n("Move %1 to:", fileNames.first()) : i18np("Move %1 file to:", "Move %1 files to:", fileNames.count()); } else { operationText = fileNames.count() == 1 ? i18n("Copy %1 to:", fileNames.first()) : i18np("Copy %1 file to:", "Copy %1 files to:", fileNames.count()); } // ask the user for the copy/move dest KChooseDir::ChooseResult result = KChooseDir::getCopyDir(operationText, destination, panel->virtualPath()); destination = result.url; if (destination.isEmpty()) return ; // the user canceled - enqueue = result.queue; + reverseQueueMode = result.reverseQueueMode; + startPaused = result.startPaused; } const QList fileUrls = files()->getUrls(fileNames); if (move) { // after the delete return the cursor to the first unmarked file above the current item panel->prepareToDelete(); } // make sure the user does not overwrite multiple files by mistake if (fileNames.count() > 1) { destination = vfs::ensureTrailingSlash(destination); } KIO::CopyJob::CopyMode mode = move ? KIO::CopyJob::Move : KIO::CopyJob::Copy; - KrVfsHandler::instance().startCopyFiles(fileUrls, destination, mode, true, enqueue); + KrVfsHandler::instance().startCopyFiles(fileUrls, destination, mode, true, reverseQueueMode, startPaused); if(KConfigGroup(krConfig, "Look&Feel").readEntry("UnselectBeforeOperation", _UnselectBeforeOperation)) { panel->view->saveSelection(); panel->view->unselectAll(); } } // called from SLOTS to begin the renaming process void ListPanelFunc::rename() { panel->view->renameCurrentItem(); } // called by signal itemRenamed() from the view to complete the renaming process void ListPanelFunc::rename(const QString &oldname, const QString &newname) { if (oldname == newname) return ; // do nothing // set current after rename panel->view->setNameToMakeCurrent(newname); // as always - the vfs do the job files()->rename(oldname, newname); } void ListPanelFunc::mkdir() { // ask the new dir name.. // suggested name is the complete name for the directories // while filenames are suggested without their extension QString suggestedName = panel->getCurrentName(); if (!suggestedName.isEmpty() && !files()->getVfile(suggestedName)->vfile_isDir()) suggestedName = QFileInfo(suggestedName).completeBaseName(); QString dirName = QInputDialog::getText(krMainWindow, i18n("New folder"), i18n("Folder's name:"), QLineEdit::Normal, suggestedName); // if the user canceled - quit if (dirName.isEmpty()) return ; QStringList dirTree = dirName.split('/'); for (QStringList::Iterator it = dirTree.begin(); it != dirTree.end(); ++it) { if (*it == ".") continue; if (*it == "..") { immediateOpenUrl(QUrl::fromUserInput(*it, QString(), QUrl::AssumeLocalFile)); continue; } // check if the name is already taken if (files()->getVfile(*it)) { // if it is the last dir to be created - quit if (*it == dirTree.last()) { KMessageBox::sorry(krMainWindow, i18n("A folder or a file with this name already exists.")); return ; } // else go into this dir else { immediateOpenUrl(QUrl::fromUserInput(*it, QString(), QUrl::AssumeLocalFile)); continue; } } panel->view->setNameToMakeCurrent(*it); // as always - the vfs does the job files()->mkDir(*it); if (dirTree.count() > 1) immediateOpenUrl(QUrl::fromUserInput(*it, QString(), QUrl::AssumeLocalFile)); } // for } // TODO it is not possible to move virtual local files to trash void ListPanelFunc::deleteFiles(bool reallyDelete) { // first get the selected file names list QStringList fileNames; panel->getSelectedNames(&fileNames); if (fileNames.isEmpty()) return ; KConfigGroup gg(krConfig, "General"); bool trash = gg.readEntry("Move To Trash", _MoveToTrash); // now ask the user if he want to delete: KConfigGroup group(krConfig, "Advanced"); if (group.readEntry("Confirm Delete", _ConfirmDelete)) { QString s, b; if (!reallyDelete && trash && files()->isLocal()) { s = i18np("Do you really want to move this item to the trash?", "Do you really want to move these %1 items to the trash?", fileNames.count()); b = i18n("&Trash"); } else if (files()->type() == vfs::VFS_VIRT && files()->isRoot()) { s = i18np( "Do you really want to delete this virtual item (physical files stay untouched)?", "Do you really want to delete these %1 virtual items (physical files stay " "untouched)?", fileNames.count()); b = i18n("&Delete"); } else if (files()->type() == vfs::VFS_VIRT) { s = i18np("Do you really want to delete this item physically (not just " "removing it from the virtual items)?", "Do you really want to delete these %1 items physically (not just " "removing them from the virtual items)?", fileNames.count()); b = i18n("&Delete"); } else { s = i18np("Do you really want to delete this item?", "Do you really want to delete these %1 items?", fileNames.count()); b = i18n("&Delete"); } // show message // note: i'm using continue and not yes/no because the yes/no has cancel as default button if (KMessageBox::warningContinueCancelList(krMainWindow, s, fileNames, i18n("Warning"), KGuiItem(b)) != KMessageBox::Continue) return ; } // we want to warn the user about non empty dir // and files he don't have permission to delete bool emptyDirVerify = group.readEntry("Confirm Unempty Dir", _ConfirmUnemptyDir); emptyDirVerify = (emptyDirVerify && files()->isLocal()); QDir dir; for (QStringList::Iterator name = fileNames.begin(); name != fileNames.end();) { vfile * vf = files()->getVfile(*name); // verify non-empty dirs delete... (only for local vfs) if (vf && emptyDirVerify && vf->vfile_isDir() && !vf->vfile_isSymLink()) { dir.setPath(panel->virtualPath().path() + '/' + (*name)); if (dir.entryList(QDir::TypeMask | QDir::System | QDir::Hidden).count() > 2) { switch (KMessageBox::warningYesNoCancel(krMainWindow, i18n("

Folder %1 is not empty.

Skip this one or delete all?

", *name), QString(), KGuiItem(i18n("&Skip")), KGuiItem(i18n("&Delete All")))) { case KMessageBox::No : emptyDirVerify = false; break; case KMessageBox::Yes : name = fileNames.erase(name); continue; default : return ; } } } ++name; } if (fileNames.count() == 0) return ; // nothing to delete // after the delete return the cursor to the first unmarked // file above the current item; panel->prepareToDelete(); // let the vfs do the job... files()->deleteFiles(fileNames, reallyDelete); } void ListPanelFunc::goInside(const QString& name) { openFileNameInternal(name, false); } void ListPanelFunc::runCommand(QString cmd) { krOut << "Run command: " << cmd; QString workdir = panel->virtualPath().isLocalFile() ? panel->virtualPath().path() : QDir::homePath(); if(!KRun::runCommand(cmd, krMainWindow, workdir)) KMessageBox::error(0, i18n("Could not start %1", cmd)); } void ListPanelFunc::runService(const KService &service, QList urls) { krOut << "Run service: " << service.name(); KIO::DesktopExecParser parser(service, urls); QStringList args = parser.resultingArguments(); if (!args.isEmpty()) runCommand(KShell::joinArgs(args)); else KMessageBox::error(0, i18n("%1 cannot open %2", service.name(), KrServices::toStringList(urls).join(", "))); } void ListPanelFunc::displayOpenWithDialog(QList urls) { KRun::displayOpenWithDialog(urls, krMainWindow); } QUrl ListPanelFunc::browsableArchivePath(const QString &filename) { vfile *vf = files()->getVfile(filename); QUrl url = files()->getUrl(filename); QString mime = vf->vfile_getMime(); if(url.isLocalFile()) { QString protocol = KrServices::registeredProtocol(mime); if(!protocol.isEmpty()) { url.setScheme(protocol); return url; } } return QUrl(); } // this is done when you double click on a file void ListPanelFunc::execute(const QString& name) { openFileNameInternal(name, true); } void ListPanelFunc::pack() { QStringList fileNames; panel->getSelectedNames(&fileNames); if (fileNames.isEmpty()) return ; // safety if (fileNames.count() == 0) return ; // nothing to pack // choose the default name QString defaultName = panel->virtualPath().fileName(); if (defaultName.isEmpty()) defaultName = "pack"; if (fileNames.count() == 1) defaultName = fileNames.first(); // ask the user for archive name and packer new PackGUI(defaultName, panel->otherPanel()->virtualPath().toDisplayString(QUrl::PreferLocalFile | QUrl::StripTrailingSlash), fileNames.count(), fileNames.first()); if (PackGUI::type.isEmpty()) { return ; // the user canceled } // check for partial URLs if (!PackGUI::destination.contains(":/") && !PackGUI::destination.startsWith('/')) { PackGUI::destination = panel->virtualPath().toDisplayString() + '/' + PackGUI::destination; } QString destDir = PackGUI::destination; if (!destDir.endsWith('/')) destDir += '/'; bool packToOtherPanel = (destDir == vfs::ensureTrailingSlash(panel->otherPanel()->virtualPath()).toDisplayString(QUrl::PreferLocalFile)); QUrl destURL = QUrl::fromUserInput(destDir + PackGUI::filename + '.' + PackGUI::type, QString(), QUrl::AssumeLocalFile); if (destURL.isLocalFile() && QFile::exists(destURL.path())) { QString msg = i18n("

The archive %1.%2 already exists. Do you want to overwrite it?

All data in the previous archive will be lost.

", PackGUI::filename, PackGUI::type); if (PackGUI::type == "zip") { msg = i18n("

The archive %1.%2 already exists. Do you want to overwrite it?

Zip will replace identically named entries in the zip archive or add entries for new names.

", PackGUI::filename, PackGUI::type); } if (KMessageBox::warningContinueCancel(krMainWindow, msg, QString(), KGuiItem(i18n("&Overwrite"))) == KMessageBox::Cancel) return ; // stop operation } else if (destURL.scheme() == QStringLiteral("virt")) { KMessageBox::error(krMainWindow, i18n("Cannot pack files onto a virtual destination.")); return; } PackJob * job = PackJob::createPacker(files()->currentDirectory(), destURL, fileNames, PackGUI::type, PackGUI::extraProps); job->setUiDelegate(new KIO::JobUiDelegate()); KIO::getJobTracker()->registerJob(job); job->ui()->setAutoErrorHandlingEnabled(true); if (packToOtherPanel) connect(job, SIGNAL(result(KJob*)), panel->otherPanel()->func, SLOT(refresh())); } void ListPanelFunc::testArchive() { QStringList fileNames; panel->getSelectedNames(&fileNames); if (fileNames.isEmpty()) return ; // safety TestArchiveJob * job = TestArchiveJob::testArchives(files()->currentDirectory(), fileNames); job->setUiDelegate(new KIO::JobUiDelegate()); KIO::getJobTracker()->registerJob(job); job->ui()->setAutoErrorHandlingEnabled(true); } void ListPanelFunc::unpack() { QStringList fileNames; panel->getSelectedNames(&fileNames); if (fileNames.isEmpty()) return ; // safety QString s; if (fileNames.count() == 1) s = i18n("Unpack %1 to:", fileNames[0]); else s = i18np("Unpack %1 file to:", "Unpack %1 files to:", fileNames.count()); // ask the user for the copy dest QUrl dest = KChooseDir::getDir(s, panel->otherPanel()->virtualPath(), panel->virtualPath()); if (dest.isEmpty()) return ; // the user canceled bool packToOtherPanel = (dest.matches(panel->otherPanel()->virtualPath(), QUrl::StripTrailingSlash)); UnpackJob * job = UnpackJob::createUnpacker(files()->currentDirectory(), dest, fileNames); job->setUiDelegate(new KIO::JobUiDelegate()); KIO::getJobTracker()->registerJob(job); job->ui()->setAutoErrorHandlingEnabled(true); if (packToOtherPanel) connect(job, SIGNAL(result(KJob*)), panel->otherPanel()->func, SLOT(refresh())); } // a small ugly function, used to prevent duplication of EVERY line of // code (maybe except 3) from createChecksum and matchChecksum static void checksum_wrapper(ListPanel *panel, QStringList& args, bool &folders) { KrViewItemList items; panel->view->getSelectedKrViewItems(&items); if (items.isEmpty()) return ; // nothing to do // determine if we need recursive mode (md5deep) folders = false; for (KrViewItemList::Iterator it = items.begin(); it != items.end(); ++it) { if (panel->func->getVFile(*it)->vfile_isDir()) { folders = true; args << (*it)->name(); } else args << (*it)->name(); } } void ListPanelFunc::createChecksum() { QStringList args; bool folders; checksum_wrapper(panel, args, folders); CreateChecksumDlg dlg(args, folders, panel->realPath()); } void ListPanelFunc::matchChecksum() { QStringList args; bool folders; checksum_wrapper(panel, args, folders); QList checksumFiles = files()->searchVfiles(KRQuery(MatchChecksumDlg::checksumTypesFilter)); MatchChecksumDlg dlg(args, folders, panel->realPath(), (checksumFiles.size() == 1 ? checksumFiles[0]->vfile_getUrl().toDisplayString(QUrl::PreferLocalFile) : QString())); } void ListPanelFunc::calcSpace(KrViewItem *item) { QStringList items; if (item) { items << item->name(); } else { panel->view->getSelectedItems(&items); if (items.isEmpty()) { panel->view->selectAllIncludingDirs(); panel->view->getSelectedItems(&items); if (items.isEmpty()) return ; // nothing to do } } QPointer calc = new KrCalcSpaceDialog(krMainWindow, panel, items, item != 0); calc->exec(); panel->slotUpdateTotals(); delete calc; } void ListPanelFunc::FTPDisconnect() { // you can disconnect only if connected! if (files()->isRemote()) { panel->_actions->actFTPDisconnect->setEnabled(false); panel->view->setNameToMakeCurrent(QString()); openUrl(QUrl::fromLocalFile(panel->realPath())); // open the last local URL } } void ListPanelFunc::newFTPconnection() { QUrl url = KRSpWidgets::newFTP(); // if the user canceled - quit if (url.isEmpty()) return ; panel->_actions->actFTPDisconnect->setEnabled(true); openUrl(url); } void ListPanelFunc::properties() { QStringList names; panel->getSelectedNames(&names); if (names.isEmpty()) return ; // no names... KFileItemList fi; for (int i = 0 ; i < names.count() ; ++i) { vfile* vf = files()->getVfile(names[i]); if (!vf) continue; QUrl url = files()->getUrl(names[i]); fi.push_back(KFileItem(vf->vfile_getEntry(), url)); } if (fi.isEmpty()) return ; // Show the properties dialog KPropertiesDialog *dlg = new KPropertiesDialog(fi, krMainWindow); connect(dlg, SIGNAL(applied()), SLOT(refresh())); dlg->show(); } void ListPanelFunc::refreshActions() { panel->updateButtons(); if(ACTIVE_PANEL != panel) return; QString protocol = files()->currentDirectory().scheme(); krRemoteEncoding->setEnabled(protocol == "ftp" || protocol == "sftp" || protocol == "fish" || protocol == "krarc"); //krMultiRename->setEnabled( vfsType == vfs::VFS_NORMAL ); // batch rename //krProperties ->setEnabled( vfsType == vfs::VFS_NORMAL || vfsType == vfs::VFS_FTP ); // file properties /* krUnpack->setEnabled(true); // unpack archive krTest->setEnabled(true); // test archive krSelect->setEnabled(true); // select a group by filter krSelectAll->setEnabled(true); // select all files krUnselect->setEnabled(true); // unselect by filter krUnselectAll->setEnabled( true); // remove all selections krInvert->setEnabled(true); // invert the selection krFTPConnect->setEnabled(true); // connect to an ftp krFTPNew->setEnabled(true); // create a new connection krAllFiles->setEnabled(true); // show all files in list krCustomFiles->setEnabled(true); // show a custom set of files krRoot->setEnabled(true); // go all the way up krExecFiles->setEnabled(true); // show only executables */ panel->_actions->setViewActions[panel->panelType]->setChecked(true); panel->_actions->actFTPDisconnect->setEnabled(files()->isRemote()); // allow disconnecting a network session panel->_actions->actCreateChecksum->setEnabled(files()->isLocal()); panel->_actions->actDirUp->setEnabled(!files()->isRoot()); panel->_actions->actRoot->setEnabled(!panel->virtualPath().matches(QUrl::fromLocalFile(ROOT_DIR), QUrl::StripTrailingSlash)); panel->_actions->actHome->setEnabled(!atHome()); panel->_actions->actHistoryBackward->setEnabled(history->canGoBack()); panel->_actions->actHistoryForward->setEnabled(history->canGoForward()); panel->view->op()->emitRefreshActions(); } vfs* ListPanelFunc::files() { if (!vfsP) vfsP = KrVfsHandler::instance().getVfs(QUrl::fromLocalFile("/")); return vfsP; } void ListPanelFunc::clipboardChanged(QClipboard::Mode mode) { if (mode == QClipboard::Clipboard && this == copyToClipboardOrigin) { disconnect(QApplication::clipboard(), 0, this, 0); copyToClipboardOrigin = 0; } } void ListPanelFunc::copyToClipboard(bool move) { QStringList fileNames; panel->getSelectedNames(&fileNames); if (fileNames.isEmpty()) return ; // safety QList fileUrls = files()->getUrls(fileNames); QMimeData *mimeData = new QMimeData; mimeData->setData("application/x-kde-cutselection", move ? "1" : "0"); mimeData->setUrls(fileUrls); if (copyToClipboardOrigin) disconnect(QApplication::clipboard(), 0, copyToClipboardOrigin, 0); copyToClipboardOrigin = this; QApplication::clipboard()->setMimeData(mimeData, QClipboard::Clipboard); connect(QApplication::clipboard(), SIGNAL(changed(QClipboard::Mode)), this, SLOT(clipboardChanged(QClipboard::Mode))); } void ListPanelFunc::pasteFromClipboard() { QClipboard * cb = QApplication::clipboard(); ListPanelFunc *origin = 0; if (copyToClipboardOrigin) { disconnect(QApplication::clipboard(), 0, copyToClipboardOrigin, 0); origin = copyToClipboardOrigin; copyToClipboardOrigin = 0; } bool move = false; const QMimeData *data = cb->mimeData(); if (data->hasFormat("application/x-kde-cutselection")) { QByteArray a = data->data("application/x-kde-cutselection"); if (!a.isEmpty()) move = (a.at(0) == '1'); // true if 1 } QList urls = data->urls(); if (urls.isEmpty()) return ; if(origin && KConfigGroup(krConfig, "Look&Feel").readEntry("UnselectBeforeOperation", _UnselectBeforeOperation)) { origin->panel->view->saveSelection(); for(KrViewItem *item = origin->panel->view->getFirst(); item != 0; item = origin->panel->view->getNext(item)) { if (urls.contains(item->getVfile()->vfile_getUrl())) item->setSelected(false); } } files()->addFiles(urls, move ? KIO::CopyJob::Move : KIO::CopyJob::Copy); } ListPanelFunc* ListPanelFunc::otherFunc() { return panel->otherPanel()->func; } void ListPanelFunc::historyGotoPos(int pos) { if(history->gotoPos(pos)) refresh(); } void ListPanelFunc::historyBackward() { if(history->goBack()) refresh(); } void ListPanelFunc::historyForward() { if(history->goForward()) refresh(); } void ListPanelFunc::dirUp() { openUrl(KIO::upUrl(files()->currentDirectory()), files()->currentDirectory().fileName()); } void ListPanelFunc::home() { openUrl(QUrl::fromLocalFile(QDir::homePath())); } void ListPanelFunc::root() { openUrl(QUrl::fromLocalFile(ROOT_DIR)); } void ListPanelFunc::cdToOtherPanel() { openUrl(panel->otherPanel()->virtualPath()); } void ListPanelFunc::syncOtherPanel() { otherFunc()->openUrl(panel->virtualPath()); } bool ListPanelFunc::atHome() { return QUrl::fromLocalFile(QDir::homePath()).matches(panel->virtualPath(), QUrl::StripTrailingSlash); } diff --git a/krusader/Panel/panelfunc.h b/krusader/Panel/panelfunc.h index 6f17c511..092224dd 100644 --- a/krusader/Panel/panelfunc.h +++ b/krusader/Panel/panelfunc.h @@ -1,160 +1,160 @@ /*************************************************************************** panelfunc.h ------------------- begin : Thu May 4 2000 copyright : (C) 2000 by Shie Erlich & Rafi Yanai e-mail : krusader@users.sourceforge.net web site : http://krusader.sourceforge.net --------------------------------------------------------------------------- Description *************************************************************************** A db dD d8888b. db db .d8888. .d8b. d8888b. d88888b d8888b. 88 ,8P' 88 `8D 88 88 88' YP d8' `8b 88 `8D 88' 88 `8D 88,8P 88oobY' 88 88 `8bo. 88ooo88 88 88 88ooooo 88oobY' 88`8b 88`8b 88 88 `Y8b. 88~~~88 88 88 88~~~~~ 88`8b 88 `88. 88 `88. 88b d88 db 8D 88 88 88 .8D 88. 88 `88. YP YD 88 YD ~Y8888P' `8888Y' YP YP Y8888D' Y88888P 88 YD H e a d e r F i l e *************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef PANELFUNC_H #define PANELFUNC_H #include "krviewitem.h" #include "../VFS/vfs.h" // QtCore #include #include // QtGui #include #include class DirHistoryQueue; class ListPanel; class ListPanelFunc : public QObject { friend class ListPanel; Q_OBJECT public slots: void execute(const QString&); void goInside(const QString&); void navigatorUrlChanged(const QUrl &url); void openUrl(const QUrl &path, const QString& nameToMakeCurrent = QString(), bool manuallyEntered = false); // void popErronousUrl(); void immediateOpenUrl(const QUrl &url, bool disableLock = false); void rename(const QString &oldname, const QString &newname); // actions void historyBackward(); void historyForward(); void dirUp(); void refresh(); void home(); void root(); void cdToOtherPanel(); void FTPDisconnect(); void newFTPconnection(); void terminal(); void view(); void viewDlg(); void edit(); void editNew(); // create a new textfile and edit it - void moveFilesByQueue() { moveFiles(true); } - void copyFilesByQueue() { copyFiles(true); } - void moveFiles(bool enqueue = false) { copyFiles(enqueue, true); } - void copyFiles(bool enqueue = false, bool move = false); + void moveFilesByQueue(); // start in queue regardless of _queueMode state + void copyFilesByQueue(); // start in queue regardless of _queueMode state + void moveFiles(bool reverseQueueMode = false) { copyFiles(reverseQueueMode, true); } + void copyFiles(bool reverseQueueMode = false, bool move = false); /*! * asks the user the new directory name */ void mkdir(); void deleteFiles(bool reallyDelete = false); void rename(); void krlink(bool sym = true); void createChecksum(); void matchChecksum(); void pack(); void unpack(); void testArchive(); // Calculate the occupied space of an item or the currently selected item and show it in a dialog void calcSpace(KrViewItem *item = 0); void properties(); void cut() { copyToClipboard(true); } void copyToClipboard(bool move = false); void pasteFromClipboard(); void syncOtherPanel(); public: ListPanelFunc(ListPanel *parent); ~ListPanelFunc(); vfs* files(); // return a pointer to the vfs inline vfile* getVFile(KrViewItem *item) { return files()->getVfile(item->name()); } inline vfile* getVFile(const QString& name) { return files()->getVfile(name); } void refreshActions(); void redirectLink(); void runService(const KService &service, QList urls); void displayOpenWithDialog(QList urls); QUrl browsableArchivePath(const QString &); ListPanelFunc* otherFunc(); bool atHome(); bool ignoreVFSErrors() { return _ignoreVFSErrors; } protected slots: // Load the current url from history and refresh vfs and panel to it. If this fails, try the // next url in history until success (last try is root) void doRefresh(); void slotFileCreated(KJob *job); // a file has been created by editNewFile() void historyGotoPos(int pos); void clipboardChanged(QClipboard::Mode mode); protected: QUrl cleanPath(const QUrl &url); bool isSyncing(const QUrl &url); void openFileNameInternal(const QString &name, bool theFileCanBeExecutedOrOpenedWithOtherSoftware); void openUrlInternal(const QUrl &url, const QString& makeCurrent, bool immediately, bool disableLock, bool manuallyEntered); void runCommand(QString cmd); ListPanel* panel; // our ListPanel DirHistoryQueue* history; vfs* vfsP; // pointer to vfs. QTimer delayTimer; QUrl syncURL; QUrl fileToCreate; // file that's to be created by editNewFile() bool urlManuallyEntered; static QPointer copyToClipboardOrigin; private: bool _refreshing; // ignore url changes while refreshing bool _ignoreVFSErrors; // ignore (repeated) errors emitted by vfs; }; #endif diff --git a/krusader/VFS/default_vfs.cpp b/krusader/VFS/default_vfs.cpp index ea46692e..d21eaf3b 100644 --- a/krusader/VFS/default_vfs.cpp +++ b/krusader/VFS/default_vfs.cpp @@ -1,379 +1,381 @@ /*************************************************************************** default_vfs.cpp ------------------- copyright : (C) 2000 by Rafi Yanai e-mail : krusader@users.sourceforge.net web site : http://krusader.sourceforge.net --------------------------------------------------------------------------- *************************************************************************** A db dD d8888b. db db .d8888. .d8b. d8888b. d88888b d8888b. 88 ,8P' 88 `8D 88 88 88' YP d8' `8b 88 `8D 88' 88 `8D 88,8P 88oobY' 88 88 `8bo. 88ooo88 88 88 88ooooo 88oobY' 88`8b 88`8b 88 88 `Y8b. 88~~~88 88 88 88~~~~~ 88`8b 88 `88. 88 `88. 88b d88 db 8D 88 88 88 .8D 88. 88 `88. YP YD 88 YD ~Y8888P' `8888Y' YP YP Y8888D' Y88888P 88 YD S o u r c e F i l e *************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "default_vfs.h" // QtCore #include #include #include #include #include #include #include #include #include #include #include #include "../defaults.h" #include "../krglobal.h" #include "../krservices.h" #include "../JobMan/jobman.h" #include "../JobMan/krjob.h" default_vfs::default_vfs(): vfs(), _watcher() { _type = VFS_DEFAULT; } void default_vfs::copyFiles(const QList &urls, const QUrl &destination, - KIO::CopyJob::CopyMode mode, bool showProgressInfo, bool enqueue) + KIO::CopyJob::CopyMode mode, bool showProgressInfo, bool reverseQueueMode, bool startPaused) { // resolve relative path before resolving symlinks const QUrl dest = resolveRelativePath(destination); KIO::JobFlags flags = showProgressInfo ? KIO::DefaultFlags : KIO::HideProgressInfo; - KrJob *krJob = KrJob::createCopyJob(mode, urls, destination, flags); + // allow job to be started only manually when startPaused=true AND queueMode=false + bool queueMode = krJobMan->isQueueModeEnabled() != reverseQueueMode; + KrJob *krJob = KrJob::createCopyJob(mode, urls, destination, flags, startPaused && !queueMode); connect(krJob, &KrJob::started, [=](KIO::Job *job) { connectJob(job, dest); }); if (mode == KIO::CopyJob::Move) { // notify source about removed files connect(krJob, &KrJob::started, [=](KIO::Job *job) { connectSourceVFS(job, urls); }); } - krJobMan->manageJob(krJob, enqueue); + krJobMan->manageJob(krJob, reverseQueueMode, startPaused); } void default_vfs::dropFiles(const QUrl &destination, QDropEvent *event) { // resolve relative path before resolving symlinks const QUrl dest = resolveRelativePath(destination); KIO::DropJob *job = KIO::drop(event, dest); // NOTE: DropJob does not provide information about the actual user choice // (move/copy/link/abort). We have to assume the worst (move) connectJob(job, dest); connectSourceVFS(job, KUrlMimeData::urlsFromMimeData(event->mimeData())); // NOTE: DrobJobs are internally recorded //recordJobUndo(job, type, dst, src); } void default_vfs::connectSourceVFS(KJob *job, const QList urls) { if (!urls.isEmpty()) { // NOTE: we assume that all files were in the same directory and only emit one signal for // the directory of the first file URL // their current directory was deleted const QUrl url = urls.first().adjusted(QUrl::RemoveFilename); connect(job, &KIO::Job::result, [=]() { emit filesystemChanged(url); }); } } void default_vfs::addFiles(const QList &fileUrls, KIO::CopyJob::CopyMode mode, QString dir) { QUrl destination(_currentDirectory); if (!dir.isEmpty()) { destination.setPath(QDir::cleanPath(destination.path() + '/' + dir)); const QString scheme = destination.scheme(); if (scheme == "tar" || scheme == "zip" || scheme == "krarc") { if (QDir(cleanUrl(destination).path()).exists()) // if we get out from the archive change the protocol destination.setScheme("file"); } } copyFiles(fileUrls, destination, mode); } void default_vfs::deleteFiles(const QStringList &fileNames, bool forceDeletion) { // get absolute URLs for file names const QList fileUrls = getUrls(fileNames); // delete or move to trash? const KConfigGroup group(krConfig, "General"); const bool moveToTrash = !forceDeletion && isLocal() && group.readEntry("Move To Trash", _MoveToTrash); KrJob *krJob = KrJob::createDeleteJob(fileUrls, moveToTrash); connect(krJob, &KrJob::started, [=](KIO::Job *job) { connectJob(job, currentDirectory()); }); krJobMan->manageJob(krJob); } void default_vfs::mkDir(const QString &name) { KIO::SimpleJob* job = KIO::mkdir(getUrl(name)); connectJob(job, currentDirectory()); } void default_vfs::rename(const QString &oldName, const QString &newName) { const QUrl oldUrl = getUrl(oldName); const QUrl newUrl = getUrl(newName); KIO::Job *job = KIO::moveAs(oldUrl, newUrl, KIO::HideProgressInfo); connectJob(job, currentDirectory()); KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, {oldUrl}, newUrl, job); } void default_vfs::connectJob(KJob *job, const QUrl &destination) { // (additional) direct refresh if on local fs because watcher is too slow connect(job, &KIO::Job::result, this, [=](KJob* job) { slotJobResult(job, isLocal()); }); connect(job, &KIO::Job::result, [=]() { emit filesystemChanged(destination); }); } QUrl default_vfs::getUrl(const QString& name) { // NOTE: on non-local fs file URL does not have to be path + name! vfile *vf = getVfile(name); if (vf) return vf->vfile_getUrl(); QUrl absoluteUrl(_currentDirectory); absoluteUrl.setPath(absoluteUrl.path() + "/" + name); return absoluteUrl; } // ==== protected ==== bool default_vfs::refreshInternal(const QUrl &directory, bool showHidden) { if (!KProtocolManager::supportsListing(directory)) { emit error(i18n("Protocol not supported by Krusader:\n%1", directory.url())); return false; } delete _watcher; // stop watching the old dir if (directory.isLocalFile()) { // we could read local directories with KIO but using Qt is a lot faster! return refreshLocal(directory); } _currentDirectory = cleanUrl(directory); // start the listing job KIO::ListJob *job = KIO::listDir(_currentDirectory, KIO::HideProgressInfo, showHidden); connect(job, &KIO::ListJob::entries, this, &default_vfs::slotAddFiles); connect(job, &KIO::ListJob::redirection, this, &default_vfs::slotRedirection); connect(job, &KIO::ListJob::permanentRedirection, this, &default_vfs::slotRedirection); connect(job, &KIO::Job::result, this, &default_vfs::slotListResult); // ensure connection credentials are asked only once if(!parentWindow.isNull()) { KIO::JobUiDelegate *ui = static_cast(job->uiDelegate()); ui->setWindow(parentWindow); } emit refreshJobStarted(job); _listError = false; // ugly: we have to wait here until the list job is finished QEventLoop eventLoop; connect(job, &KJob::finished, &eventLoop, &QEventLoop::quit); eventLoop.exec(); // blocking until quit() return !_listError; } bool default_vfs::ignoreRefresh() { return !_watcher.isNull(); } // ==== protected slots ==== void default_vfs::slotListResult(KJob *job) { if (job && job->error()) { // we failed to refresh _listError = true; emit error(job->errorString()); // display error message (in panel) } } void default_vfs::slotAddFiles(KIO::Job *, const KIO::UDSEntryList& entries) { for (const KIO::UDSEntry entry : entries) { vfile *vfile = vfs::createVFileFromKIO(entry, _currentDirectory); if (vfile) { addVfile(vfile); } } } void default_vfs::slotRedirection(KIO::Job *job, const QUrl &url) { krOut << "default_vfs; redirection to " << url; // some protocols (zip, tar) send redirect to local URL without scheme const QUrl newUrl = preferLocalUrl(url); if (newUrl.scheme() != _currentDirectory.scheme()) { // abort and start over again, // some protocols (iso, zip, tar) do this on transition to local fs job->kill(); _isRefreshing = false; refresh(newUrl); return; } _currentDirectory = cleanUrl(newUrl); } void default_vfs::slotWatcherDirty(const QString& path) { if (path == realPath()) { // this happens // 1. if a directory was created/deleted/renamed inside this directory. No deleted // 2. during and after a file operation (create/delete/rename/touch) inside this directory // KDirWatcher doesn't reveal the name of changed directories and we have to refresh. // (QFileSystemWatcher in Qt5.7 can't help here either) refresh(); return; } const QString name = QUrl::fromLocalFile(path).fileName(); vfile *vf = getVfile(name); if (!vf) { krOut << "dirty watcher file not found (unexpected): " << path; return; } // we have an updated file.. vfile *newVf = createLocalVFile(name); *vf = *newVf; delete newVf; emit updatedVfile(vf); } void default_vfs::slotWatcherDeleted(const QString& path) { if (path != realPath()) { // ignore deletion of files here, a 'dirty' signal will be send anyway return; } // the current directory was deleted, try a refresh, which will fail. An error message will // be emitted and the empty (non-existing) directory remains. refresh(); } bool default_vfs::refreshLocal(const QUrl &directory) { const QString path = KrServices::urlToLocalPath(directory); #ifdef Q_WS_WIN if (!path.contains("/")) { // change C: to C:/ path = path + QString("/"); } #endif // check if the new directory exists if (!QDir(path).exists()) { emit error(i18n("The folder %1 does not exist.", path)); return false; } // mount if needed emit aboutToOpenDir(path); // set the current directory... _currentDirectory = directory; _currentDirectory.setPath(QDir::cleanPath(_currentDirectory.path())); // Note: we are using low-level Qt functions here. // It's around twice as fast as using the QDir class. QT_DIR* dir = QT_OPENDIR(path.toLocal8Bit()); if (!dir) { emit error(i18n("Cannot open the folder %1.", path)); return false; } // change directory to the new directory const QString savedDir = QDir::currentPath(); if (!QDir::setCurrent(path)) { emit error(i18nc("%1=folder path", "Access to %1 denied", path)); QT_CLOSEDIR(dir); return false; } QT_DIRENT* dirEnt; QString name; const bool showHidden = showHiddenFiles(); while ((dirEnt = QT_READDIR(dir)) != NULL) { name = QString::fromLocal8Bit(dirEnt->d_name); // show hidden files? if (!showHidden && name.left(1) == ".") continue ; // we don't need the "." and ".." entries if (name == "." || name == "..") continue; vfile* temp = createLocalVFile(name); addVfile(temp); } // clean up QT_CLOSEDIR(dir); QDir::setCurrent(savedDir); // start watching the new dir for file changes _watcher = new KDirWatch(this); // if the current dir is a link path the watcher needs to watch the real path - and signal // parameters will be the real path _watcher->addDir(realPath(), KDirWatch::WatchFiles); connect(_watcher.data(), &KDirWatch::dirty, this, &default_vfs::slotWatcherDirty); // NOTE: not connecting 'created' signal. A 'dirty' is send after that anyway //connect(_watcher, SIGNAL(created(const QString&)), this, SLOT(slotWatcherCreated(const QString&))); connect(_watcher.data(), &KDirWatch::deleted, this, &default_vfs::slotWatcherDeleted); _watcher->startScan(false); return true; } vfile *default_vfs::createLocalVFile(const QString &name) { return vfs::createLocalVFile(name, _currentDirectory.path()); } QString default_vfs::default_vfs::realPath() { return QDir(_currentDirectory.toLocalFile()).canonicalPath(); } QUrl default_vfs::resolveRelativePath(const QUrl &url) { // if e.g. "/tmp/bin" is a link to "/bin", // resolve "/tmp/bin/.." to "/tmp" and not "/" return url.adjusted(QUrl::NormalizePathSegments); } diff --git a/krusader/VFS/default_vfs.h b/krusader/VFS/default_vfs.h index fbcf5e7d..764d22fd 100644 --- a/krusader/VFS/default_vfs.h +++ b/krusader/VFS/default_vfs.h @@ -1,104 +1,104 @@ /*************************************************************************** default_vfs.h ------------------- begin : Thu May 4 2000 copyright : (C) 2000 by Shie Erlich & Rafi Yanai e-mail : krusader@users.sourceforge.net web site : http://krusader.sourceforge.net *************************************************************************** A db dD d8888b. db db .d8888. .d8b. d8888b. d88888b d8888b. 88 ,8P' 88 `8D 88 88 88' YP d8' `8b 88 `8D 88' 88 `8D 88,8P 88oobY' 88 88 `8bo. 88ooo88 88 88 88ooooo 88oobY' 88`8b 88`8b 88 88 `Y8b. 88~~~88 88 88 88~~~~~ 88`8b 88 `88. 88 `88. 88b d88 db 8D 88 88 88 .8D 88. 88 `88. YP YD 88 YD ~Y8888P' `8888Y' YP YP Y8888D' Y88888P 88 YD H e a d e r F i l e *************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef DEFAULT_VFS_H #define DEFAULT_VFS_H #include "vfs.h" #include #include /** * @brief Default filesystem implementation supporting all KIO protocols * * This vfs implementation allows file operations and listing for all supported KIO protocols (local * and remote/network). * * Refreshing local directories is optimized for performance. * * NOTE: For detecting local file changes a filesystem watcher is used. It cannot be used for * refreshing the view after own file operations are performed because the detection is to slow * (~500ms delay between operation finished and watcher emits signals). * */ class default_vfs : public vfs { Q_OBJECT public: default_vfs(); ~default_vfs() {} virtual void copyFiles(const QList &urls, const QUrl &destination, KIO::CopyJob::CopyMode mode = KIO::CopyJob::Copy, - bool showProgressInfo = true, bool enqueue = false) Q_DECL_OVERRIDE; + bool showProgressInfo = true, bool reverseQueueMode = false, bool startPaused = false) Q_DECL_OVERRIDE; virtual void dropFiles(const QUrl &destination, QDropEvent *event) Q_DECL_OVERRIDE; virtual void addFiles(const QList &fileUrls, KIO::CopyJob::CopyMode mode, QString dir = "") Q_DECL_OVERRIDE; virtual void deleteFiles(const QStringList &fileNames, bool forceDeletion = false) Q_DECL_OVERRIDE; virtual void mkDir(const QString &name) Q_DECL_OVERRIDE; virtual void rename(const QString &fileName, const QString &newName) Q_DECL_OVERRIDE; /// Return URL for file name - even if file does not exist. virtual QUrl getUrl(const QString &name) Q_DECL_OVERRIDE; protected: virtual bool refreshInternal(const QUrl &origin, bool showHidden) Q_DECL_OVERRIDE; virtual bool ignoreRefresh() Q_DECL_OVERRIDE; protected slots: /// Handle result after dir listing job is finished void slotListResult(KJob *job); /// Fill directory file list with new files from the dir lister void slotAddFiles(KIO::Job *job, const KIO::UDSEntryList &entries); /// URL redirection signal from dir lister void slotRedirection(KIO::Job *job, const QUrl &url); // React to filesystem changes nofified by watcher // NOTE: the path parameter can be the directory itself or files in this directory void slotWatcherDirty(const QString &path); void slotWatcherDeleted(const QString &path); private: void connectSourceVFS(KJob *job, const QList urls); void connectJob(KJob *job, const QUrl &destination); bool refreshLocal(const QUrl &directory); // NOTE: this is very fast vfile *createLocalVFile(const QString &name); /// Returns the current path with symbolic links resolved QString realPath(); static QUrl resolveRelativePath(const QUrl &url); QPointer _watcher; // dir watcher used to detect changes in the current dir bool _listError; // for async operation, return list job result }; #endif diff --git a/krusader/VFS/krvfshandler.cpp b/krusader/VFS/krvfshandler.cpp index 065f8eb7..1c035b16 100644 --- a/krusader/VFS/krvfshandler.cpp +++ b/krusader/VFS/krvfshandler.cpp @@ -1,168 +1,168 @@ /***************************************************************************** * Copyright (C) 2003 Shie Erlich * * Copyright (C) 2003 Rafi Yanai * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This package is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #include "krvfshandler.h" #ifdef HAVE_POSIX_ACL #include #ifdef HAVE_NON_POSIX_ACL_EXTENSIONS #include #endif #endif // QtCore #include #include "default_vfs.h" #include "virt_vfs.h" #include "../krservices.h" vfs* KrVfsHandler::getVfs(const QUrl &url, vfs* oldVfs) { if (oldVfs && oldVfs->type() == getVfsType(url)) { return oldVfs; } vfs *newVfs = createVfs(url); QPointer vfsPointer(newVfs); _vfs_list.append(vfsPointer); connect(newVfs, &vfs::filesystemChanged, this, &KrVfsHandler::refreshVfs); return newVfs; } void KrVfsHandler::startCopyFiles(const QList &urls, const QUrl &destination, - KIO::CopyJob::CopyMode mode, bool showProgressInfo, bool enqueue) + KIO::CopyJob::CopyMode mode, bool showProgressInfo, bool reverseQueueMode, bool startPaused) { vfs *vfs = getVfs(destination); // implementation depends on filesystem of destination - vfs->copyFiles(urls, destination, mode, showProgressInfo, enqueue); + vfs->copyFiles(urls, destination, mode, showProgressInfo, reverseQueueMode, startPaused); } void KrVfsHandler::refreshVfs(const QUrl &directory) { QMutableListIterator> it(_vfs_list); while (it.hasNext()) { if (it.next().isNull()) { it.remove(); } } // refresh all vfs currently showing this directory for(QPointer vfsPointer: _vfs_list) { // always refresh virtual vfs showing a virtual directory; it can contain files from various // places, we don't know if they were (re)moved, refreshing is also fast enough vfs *vfs = vfsPointer.data(); const QUrl vfsDir = vfs->currentDirectory(); if (vfsDir == vfs::cleanUrl(directory) || (vfsDir.scheme() == "virt" && !vfs->isRoot())) { vfs->mayRefresh(); } } } // ==== static ==== KrVfsHandler &KrVfsHandler::instance() { static KrVfsHandler instance; return instance; } vfs::VFS_TYPE KrVfsHandler::getVfsType(const QUrl &url) { return url.scheme() == QStringLiteral("virt") ? vfs::VFS_VIRT : vfs::VFS_DEFAULT; } vfs* KrVfsHandler::createVfs(const QUrl &url) { vfs::VFS_TYPE newType = getVfsType(url); switch (newType) { case (vfs::VFS_VIRT): return new virt_vfs(); default: return new default_vfs(); } } void KrVfsHandler::getACL(vfile *file, QString &acl, QString &defAcl) { Q_UNUSED(file); acl.clear(); defAcl.clear(); #ifdef HAVE_POSIX_ACL QString fileName = vfs::cleanUrl(file->vfile_getUrl()).path(); #ifdef HAVE_NON_POSIX_ACL_EXTENSIONS if (acl_extended_file(fileName)) { #endif acl = getACL(fileName, ACL_TYPE_ACCESS); if (file->vfile_isDir()) defAcl = getACL(fileName, ACL_TYPE_DEFAULT); #ifdef HAVE_NON_POSIX_ACL_EXTENSIONS } #endif #endif } QString KrVfsHandler::getACL(const QString & path, int type) { Q_UNUSED(path); Q_UNUSED(type); #ifdef HAVE_POSIX_ACL acl_t acl = 0; // do we have an acl for the file, and/or a default acl for the dir, if it is one? if ((acl = acl_get_file(path.toLocal8Bit(), type)) != 0) { bool aclExtended = false; #ifdef HAVE_NON_POSIX_ACL_EXTENSIONS aclExtended = acl_equiv_mode(acl, 0); #else acl_entry_t entry; int ret = acl_get_entry(acl, ACL_FIRST_ENTRY, &entry); while (ret == 1) { acl_tag_t currentTag; acl_get_tag_type(entry, ¤tTag); if (currentTag != ACL_USER_OBJ && currentTag != ACL_GROUP_OBJ && currentTag != ACL_OTHER) { aclExtended = true; break; } ret = acl_get_entry(acl, ACL_NEXT_ENTRY, &entry); } #endif if (!aclExtended) { acl_free(acl); acl = 0; } } if (acl == 0) return QString(); char *aclString = acl_to_text(acl, 0); QString ret = QString::fromLatin1(aclString); acl_free((void*)aclString); acl_free(acl); return ret; #else return QString(); #endif } diff --git a/krusader/VFS/krvfshandler.h b/krusader/VFS/krvfshandler.h index adae9b8c..5c20fa2d 100644 --- a/krusader/VFS/krvfshandler.h +++ b/krusader/VFS/krvfshandler.h @@ -1,74 +1,74 @@ /***************************************************************************** * Copyright (C) 2003 Shie Erlich * * Copyright (C) 2003 Rafi Yanai * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This package is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #ifndef KRVFSHANDLER_H #define KRVFSHANDLER_H // QtCore #include #include #include #include "vfs.h" /** * @brief Provider for virtual file systems. * * This is a singleton. */ class KrVfsHandler : public QObject { Q_OBJECT public: /** * Get a VFS implementation for the filesystem target specified by URL. oldVfs is returned if * the filesystem did not change. * * The VFS instances returned by this method are already connected with this handler and will * notify each other about filesystem changes. */ vfs *getVfs(const QUrl &url, vfs *oldVfs = 0); /** * Start a copy job for copying, moving or linking files to a destination directory. * May be implemented async depending on destination filesystem. */ void startCopyFiles(const QList &urls, const QUrl &destination, KIO::CopyJob::CopyMode mode = KIO::CopyJob::Copy, - bool showProgressInfo = true, bool enqueue = false); + bool showProgressInfo = true, bool reverseQueueMode = false, bool startPaused = false); static KrVfsHandler &instance(); static vfs::VFS_TYPE getVfsType(const QUrl &url); /** Get ACL permissions for a file */ static void getACL(vfile *file, QString &acl, QString &defAcl); protected slots: void refreshVfs(const QUrl &directory); private: KrVfsHandler() {} QList> _vfs_list; static vfs *createVfs(const QUrl &url); static QString getACL(const QString & path, int type); }; #endif diff --git a/krusader/VFS/vfs.h b/krusader/VFS/vfs.h index e6dc763b..f231d0b5 100644 --- a/krusader/VFS/vfs.h +++ b/krusader/VFS/vfs.h @@ -1,232 +1,232 @@ /*************************************************************************** vfs.h ------------------- begin : Thu May 4 2000 copyright : (C) 2000 by Shie Erlich & Rafi Yanai e-mail : krusader@users.sourceforge.net web site : http://krusader.sourceforge.net *************************************************************************** A db dD d8888b. db db .d8888. .d8b. d8888b. d88888b d8888b. 88 ,8P' 88 `8D 88 88 88' YP d8' `8b 88 `8D 88' 88 `8D 88,8P 88oobY' 88 88 `8bo. 88ooo88 88 88 88ooooo 88oobY' 88`8b 88`8b 88 88 `Y8b. 88~~~88 88 88 88~~~~~ 88`8b 88 `88. 88 `88. 88b d88 db 8D 88 88 88 .8D 88. 88 `88. YP YD 88 YD ~Y8888P' `8888Y' YP YP Y8888D' Y88888P 88 YD H e a d e r F i l e *************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef VFS_H #define VFS_H #include "vfilecontainer.h" // QtCore #include #include #include #include #include // QtGui #include // QtWidgets #include #include #include "vfile.h" #include "krquery.h" /** * An abstract virtual filesystem. Use the implementations of this class for all file operations. * * It represents a directory and gives access to its files. All common file operations * are supported. Methods with absolute URL as argument can be used independently from the current * directory. Otherwise - if the methods argument is a file name - the operation is performed inside * the current directory. * * Notification signals are emitted if the directory content may have been changed. */ class vfs : public VfileContainer { Q_OBJECT public: typedef QHash vfileDict; enum VFS_TYPE { /// Virtual filesystem. Krusaders custom virt:/ protocol VFS_VIRT, /// Filesystem supporting all KIO protocols (file:/, ftp:/, smb:/, etc.) VFS_DEFAULT }; vfs(); virtual ~vfs(); // VfileContainer implementation virtual inline QList vfiles() { return _vfiles.values(); } virtual inline unsigned long numVfiles() { return _vfiles.count(); } virtual inline bool isRoot() { const QString path = _currentDirectory.path(); return path.isEmpty() || path == "/"; } /// Copy (copy, move or link) files in this VFS. /// Destination is absolute URL. May implemented async. virtual void copyFiles(const QList &urls, const QUrl &destination, KIO::CopyJob::CopyMode mode = KIO::CopyJob::Copy, - bool showProgressInfo = true, bool enqueue = false) = 0; + bool showProgressInfo = true, bool reverseQueueMode = false, bool startPaused = false) = 0; /// Handle file dropping in this VFS. Destination is absolute URL. May implemented async. virtual void dropFiles(const QUrl &destination, QDropEvent *event) = 0; /// Copy (copy, move or link) files to the current VFS directory or to "dir", the /// directory name relative to the current dir. May implemented async. virtual void addFiles(const QList &fileUrls, KIO::CopyJob::CopyMode mode, QString dir = "") = 0; /// Delete or move a file in the current directory to trash. May implemented async. virtual void deleteFiles(const QStringList &fileNames, bool reallyDelete = false) = 0; /// Create a new directory in the current directory. May implemented async. virtual void mkDir(const QString &name) = 0; /// Rename file/directory in the current directory. May implemented async. virtual void rename(const QString &fileName, const QString &newName) = 0; /// Return an absolute URL for a single file/directory name in the current directory - with no /// trailing slash. virtual QUrl getUrl(const QString &name) = 0; /// Return a list of URLs for multiple files/directories in the current directory. virtual QList getUrls(const QStringList &names); /// Returns the current directory path of this VFS. inline QUrl currentDirectory() { return _currentDirectory; } /// Return the vfile for a file name in the current directory. Or 0 if not found. inline vfile *getVfile(const QString &name) { return (_vfiles)[name]; } /// Return a list of vfiles for a search query. Or an empty list if nothing was found. QList searchVfiles(const KRQuery &filter); /// The total size of all files in the current directory (only valid after refresh). // TODO unused KIO::filesize_t vfs_totalSize(); /// Return the VFS type. inline VFS_TYPE type() { return _type; } /// Return true if the current directory is local (without recognizing mount points). inline bool isLocal() { return _currentDirectory.isLocalFile(); } /// Return true if the current directory is a remote (network) location. inline bool isRemote() { const QString sc = _currentDirectory.scheme(); return (sc == "fish" || sc == "ftp" || sc == "sftp" || sc == "nfs" || sc == "smb" || sc == "webdav"); } /// Returns true if this VFS is currently refreshing the current directory. inline bool isRefreshing() { return _isRefreshing; } /// Return a displayable string containing special filesystem meta information. Or an empty /// string by default. virtual QString metaInformation() { return QString(); } /// Calculate the amount of space occupied by a file or directory in the current directory /// (recursive). virtual void calcSpace(const QString &name, KIO::filesize_t *totalSize, unsigned long *totalFiles, unsigned long *totalDirs, bool *stop); /// Return the input URL with a trailing slash if absent. static QUrl ensureTrailingSlash(const QUrl &url); /// Return the input URL without trailing slash. static QUrl cleanUrl(const QUrl &url) { return url.adjusted(QUrl::StripTrailingSlash); } /// Add 'file' scheme to non-empty URL without scheme static QUrl preferLocalUrl(const QUrl &url); // set the parent window to be used for dialogs void setParentWindow(QWidget *widget) { parentWindow = widget; } public slots: /// Re-read the current directory files or change to another directory. Blocking. /// Returns true if directory was read. Returns false if failed or refresh job was killed. // optional TODO: add an async version of this bool refresh(const QUrl &directory = QUrl()); /// Notify this VFS that the current directory content may have changed. void mayRefresh(); signals: /// Emitted when this VFS is currently refreshing the VFS directory. void refreshJobStarted(KIO::Job *job); /// Emitted when an error occured in this VFS. /// The error can be caused by refresh or any filesystem operation void error(const QString &msg); /// Emitted when the content of a directory was changed by this VFS. void filesystemChanged(const QUrl &directory); /// Emitted before a directory path is opened for reading. Used for automounting. void aboutToOpenDir(const QString &path); protected: /// Fill the vfs dictionary with vfiles, must be implemented for each VFS. virtual bool refreshInternal(const QUrl &origin, bool showHidden) = 0; /// Returns true if this VFS implementation does not need to be notified about changes in the /// current directory. virtual bool ignoreRefresh() { return false; } /// Returns true if showing hidden files is set in config. bool showHiddenFiles(); /// Add a new vfile to the internal dictionary (while refreshing). inline void addVfile(vfile *vf) { _vfiles.insert(vf->vfile_getName(), vf); } /// Calculate the size of a file or directory (recursive). void calcSpace(const QUrl &url, KIO::filesize_t *totalSize, unsigned long *totalFiles, unsigned long *totalDirs, bool *stop); /// Calculate the size of a local file or directory (recursive). void calcSpaceLocal(const QString &path, KIO::filesize_t *totalSize, unsigned long *totalFiles, unsigned long *totalDirs, bool *stop); /// Calculate the size of any KIO file or directory. void calcSpaceKIO(const QUrl &url, KIO::filesize_t *totalSize, unsigned long *totalFiles, unsigned long *totalDirs, bool *stop); /// Return a vfile for a local file inside a directory static vfile *createLocalVFile(const QString &name, const QString &directory, bool virt = false); /// Return a vfile for a KIO result. Returns 0 if entry is not needed static vfile *createVFileFromKIO(const KIO::UDSEntry &_calcEntry, const QUrl &directory, bool virt = false); VFS_TYPE _type; // the vfs type. QUrl _currentDirectory; // the path or file the VFS originates from. bool _isRefreshing; // true if vfs is busy with refreshing QPointer parentWindow; protected slots: /// Handle result after job (except when refreshing!) finished void slotJobResult(KJob *job, bool refresh); private slots: /// Handle result of KIO::DirectorySizeJob when calculating URL size void slotCalcKdsResult(KJob *job); /// Handle result of KIO::StatJob when calculating URL size void slotCalcStatResult(KJob *job); private: /// Delete and clear vfiles. void clear(vfileDict &vfiles); vfileDict _vfiles; // The list of files in the current dictionary // used in the calcSpace function bool *_calcKdsBusy; bool _calcStatBusy; KIO::UDSEntry _calcEntry; KIO::filesize_t *_calcKdsTotalSize; unsigned long *_calcKdsTotalFiles; unsigned long *_calcKdsTotalDirs; }; #endif diff --git a/krusader/VFS/virt_vfs.cpp b/krusader/VFS/virt_vfs.cpp index ed7a725d..683e7a6b 100644 --- a/krusader/VFS/virt_vfs.cpp +++ b/krusader/VFS/virt_vfs.cpp @@ -1,370 +1,370 @@ /***************************************************************************** * Copyright (C) 2003 Shie Erlich * * Copyright (C) 2003 Rafi Yanai * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This package is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #include "virt_vfs.h" // QtCore #include #include #include #include #include #include #include #include #include #include #include #include "../defaults.h" #include "../krglobal.h" #include "../krservices.h" #include "krpermhandler.h" #define VIRT_VFS_DB "virt_vfs.db" QHash *> virt_vfs::_virtVfsDict; QHash virt_vfs::_metaInfoDict; virt_vfs::virt_vfs() : vfs() { if (_virtVfsDict.isEmpty()) { restore(); } _type = VFS_VIRT; } virt_vfs::~virt_vfs() {} void virt_vfs::copyFiles(const QList &urls, const QUrl &destination, KIO::CopyJob::CopyMode /*mode*/, bool /*showProgressInfo*/, - bool /*enqueue*/) + bool /*reverseQueueMode*/, bool /*startPaused*/) { const QString dir = QDir(destination.path()).absolutePath().remove('/'); if (dir.isEmpty()) { emit error(i18n("You cannot copy files directly to the 'virt:/' folder.\n" "You can create a sub folder and copy your files into it.")); return; } if (!_virtVfsDict.contains(dir)) { mkDirInternal(dir); } QList *urlList = _virtVfsDict[dir]; for (const QUrl &fileUrl : urls) { if (!urlList->contains(fileUrl)) { urlList->push_back(fileUrl); } } emit filesystemChanged(QUrl("virt:///" + dir)); // may call refresh() } void virt_vfs::dropFiles(const QUrl &destination, QDropEvent *event) { const QList &urls = KUrlMimeData::urlsFromMimeData(event->mimeData()); // dropping on virtual vfs (sic!) is always copy operation copyFiles(urls, destination); } void virt_vfs::addFiles(const QList &fileUrls, KIO::CopyJob::CopyMode /*mode*/, QString dir) { QUrl destination(_currentDirectory); if (!dir.isEmpty()) { destination.setPath(QDir::cleanPath(destination.path() + '/' + dir)); } copyFiles(fileUrls, destination); } void virt_vfs::deleteFiles(const QStringList &fileNames, bool reallyDelete) { if (currentDir() == "/") { // remove virtual directory for (const QString &filename : fileNames) { _virtVfsDict["/"]->removeAll(QUrl(QStringLiteral("virt:/") + filename)); delete _virtVfsDict[filename]; _virtVfsDict.remove(filename); _metaInfoDict.remove(filename); } emit filesystemChanged(currentDirectory()); // will call refresh() return; } // names -> urls QList filesUrls = getUrls(fileNames); // delete or move to trash? KIO::Job *job; KConfigGroup group(krConfig, "General"); if (!reallyDelete && group.readEntry("Move To Trash", _MoveToTrash)) { job = KIO::trash(filesUrls); } else { job = KIO::del(filesUrls); } connect(job, &KIO::Job::result, this, [=](KJob* job) { slotJobResult(job, false); }); // refresh will remove the deleted files from the vfs dict... connect(job, &KIO::Job::result, [=]() { emit filesystemChanged(currentDirectory()); }); } void virt_vfs::vfs_removeFiles(QStringList *fileNames) { if (currentDir() == "/") return; // removing the URLs from the collection for (int i = 0; i < fileNames->count(); ++i) { if (_virtVfsDict.find(currentDir()) != _virtVfsDict.end()) { QList *urlList = _virtVfsDict[currentDir()]; urlList->removeAll(getUrl((*fileNames)[i])); } } emit filesystemChanged(currentDirectory()); // will call refresh() } QUrl virt_vfs::getUrl(const QString &name) { vfile *vf = getVfile(name); if (!vf) { return QUrl(); // not found } return vf->vfile_getUrl(); } void virt_vfs::mkDir(const QString &name) { if (currentDir() != "/") { emit error(i18n("Creating new folders is allowed only in the 'virt:/' folder.")); return; } mkDirInternal(name); emit filesystemChanged(currentDirectory()); // will call refresh() } void virt_vfs::rename(const QString &fileName, const QString &newName) { vfile *vf = getVfile(fileName); if (!vf) return; // not found if (currentDir() == "/") { // rename virtual directory _virtVfsDict["/"]->append(QUrl(QStringLiteral("virt:/") + newName)); _virtVfsDict["/"]->removeAll(QUrl(QStringLiteral("virt:/") + fileName)); _virtVfsDict.insert(newName, _virtVfsDict.take(fileName)); refresh(); return; } // newName can be a (local) path or a full url QUrl dest(newName); if (dest.scheme().isEmpty()) dest.setScheme("file"); // add the new url to the list // the list is refreshed, only existing files remain - // so we don't have to worry if the job was successful _virtVfsDict[currentDir()]->append(dest); KIO::Job *job = KIO::moveAs(vf->vfile_getUrl(), dest, KIO::HideProgressInfo); connect(job, &KIO::Job::result, this, [=](KJob* job) { slotJobResult(job, false); }); connect(job, &KIO::Job::result, [=]() { emit filesystemChanged(currentDirectory()); }); } void virt_vfs::calcSpace(const QString &name, KIO::filesize_t *totalSize, unsigned long *totalFiles, unsigned long *totalDirs, bool *stop) { if (currentDir() == "/") { if (!_virtVfsDict.contains(name)) { return; // virtual folder not found } const QList *urlList = _virtVfsDict[name]; if (urlList) { for (int i = 0; (i != urlList->size()) && !(*stop); i++) { vfs::calcSpace((*urlList)[i], totalSize, totalFiles, totalDirs, stop); } } return; } vfs::calcSpace(name, totalSize, totalFiles, totalDirs, stop); } void virt_vfs::setMetaInformation(QString info) { _metaInfo = info; _metaInfoDict[currentDir()] = _metaInfo; refresh(); } // ==== protected ==== bool virt_vfs::refreshInternal(const QUrl &directory, bool /*showHidden*/) { _currentDirectory = cleanUrl(directory); _currentDirectory.setHost(""); // remove invalid subdirectories _currentDirectory.setPath("/" + _currentDirectory.path().remove('/')); if (!_virtVfsDict.contains(currentDir())) { // NOTE: silently creating non-existing directories here. The search and locate tools expect // this. (And user can enter some directory and it will be created). mkDirInternal(currentDir()); save(); // infinite loop possible //emit filesystemChanged(currentDirectory()); return true; } QList *urlList = _virtVfsDict[currentDir()]; _metaInfo = _metaInfoDict[currentDir()]; QMutableListIterator it(*urlList); while (it.hasNext()) { const QUrl url = it.next(); vfile *vf = createVFile(url); if (!vf) { // remove URL from the list for a file that no longer exists it.remove(); } else { addVfile(vf); } } save(); return true; } // ==== private ==== void virt_vfs::mkDirInternal(const QString &name) { // clean path, consistent with currentDir() QString dirName = name; dirName = dirName.remove('/'); if (dirName.isEmpty()) dirName = "/"; _virtVfsDict.insert(dirName, new QList()); _virtVfsDict["/"]->append(QUrl(QStringLiteral("virt:/") + dirName)); } void virt_vfs::save() { KConfig *db = &virt_vfs::getVirtDB(); db->deleteGroup("virt_db"); KConfigGroup group(db, "virt_db"); QHashIterator *> it(_virtVfsDict); while (it.hasNext()) { it.next(); QList *urlList = it.value(); QList::iterator url; QStringList entry; for (url = urlList->begin(); url != urlList->end(); ++url) { entry.append((*url).toDisplayString()); } // KDE 4.0 workaround: 'Item_' prefix is added as KConfig fails on 1 char names (such as /) group.writeEntry("Item_" + it.key(), entry); group.writeEntry("MetaInfo_" + it.key(), _metaInfoDict[it.key()]); } db->sync(); } void virt_vfs::restore() { KConfig *db = &virt_vfs::getVirtDB(); const KConfigGroup dbGrp(db, "virt_db"); const QMap map = db->entryMap("virt_db"); QMapIterator it(map); while (it.hasNext()) { it.next(); // KDE 4.0 workaround: check and remove 'Item_' prefix if (!it.key().startsWith(QLatin1String("Item_"))) continue; const QString key = it.key().mid(5); const QList urlList = KrServices::toUrlList(dbGrp.readEntry(it.key(), QStringList())); _virtVfsDict.insert(key, new QList(urlList)); _metaInfoDict.insert(key, dbGrp.readEntry("MetaInfo_" + key, QString())); } if (!_virtVfsDict["/"]) { // insert root element if missing for some reason _virtVfsDict.insert("/", new QList()); } } vfile *virt_vfs::createVFile(const QUrl &url) { if (url.scheme() == "virt") { // return a virtual directory in root QString path = url.path().mid(1); if (path.isEmpty()) path = '/'; return new vfile(path, 0, "drwxr-xr-x", time(0), false, false, getuid(), getgid(), "inode/directory", "", 0, -1, url); } const QUrl directory = url.adjusted(QUrl::RemoveFilename); if (url.isLocalFile()) { QFileInfo file(url.path()); return file.exists() ? vfs::createLocalVFile(url.fileName(), directory.path(), true) : 0; } KIO::StatJob *statJob = KIO::stat(url, KIO::HideProgressInfo); connect(statJob, &KIO::Job::result, this, &virt_vfs::slotStatResult); // ugly: we have to wait here until the stat job is finished QEventLoop eventLoop; connect(statJob, &KJob::finished, &eventLoop, &QEventLoop::quit); eventLoop.exec(); // blocking until quit() if (_fileEntry.count() == 0) { return 0; // stat job failed } if (!_fileEntry.contains(KIO::UDSEntry::UDS_MODIFICATION_TIME)) { // TODO this also happens for FTP directories return 0; // file not found } return vfs::createVFileFromKIO(_fileEntry, directory, true); } KConfig &virt_vfs::getVirtDB() { //virt_vfs_db = new KConfig("data",VIRT_VFS_DB,KConfig::NoGlobals); static KConfig db(VIRT_VFS_DB, KConfig::CascadeConfig, QStandardPaths::AppDataLocation); return db; } void virt_vfs::slotStatResult(KJob *job) { _fileEntry = job->error() ? KIO::UDSEntry() : static_cast(job)->statResult(); } diff --git a/krusader/VFS/virt_vfs.h b/krusader/VFS/virt_vfs.h index 7c399668..dd8c4c42 100644 --- a/krusader/VFS/virt_vfs.h +++ b/krusader/VFS/virt_vfs.h @@ -1,108 +1,108 @@ /***************************************************************************** * Copyright (C) 2003 Shie Erlich * * Copyright (C) 2003 Rafi Yanai * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This package is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #ifndef VIRT_VFS_H #define VIRT_VFS_H // QtCore #include #include "vfs.h" /** * Custom virtual filesystem implementation: It holds arbitrary lists of files which are only * virtual references to real files. The filename of a virtual file is the full path of the real * file. * * Only two filesystem levels are supported: On root level only directories can be created; these * virtual root directories can contain a set of virtual files and directories. Entering a directory * on the sublevel is out of scope and the real directory will be opened. * * The filesystem content is saved in a separate config file and preserved between application runs. * * Used at least by bookmarks, locate, search and synchronizer dialog. */ class virt_vfs : public vfs { Q_OBJECT public: virt_vfs(); ~virt_vfs(); /// Create virtual files in this VFS. Copy mode and showProgressInfo are ignored. void copyFiles(const QList &urls, const QUrl &destination, KIO::CopyJob::CopyMode mode = KIO::CopyJob::Copy, - bool showProgressInfo = true, bool enqueue = false) Q_DECL_OVERRIDE; + bool showProgressInfo = true, bool reverseQueueMode = false, bool startPaused = false) Q_DECL_OVERRIDE; /// Handle file dropping in this VFS: Always creates virtual files. void dropFiles(const QUrl &destination, QDropEvent *event) Q_DECL_OVERRIDE; /// Add virtual files to the current directory. void addFiles(const QList &fileUrls, KIO::CopyJob::CopyMode mode = KIO::CopyJob::Copy, QString dir = "") Q_DECL_OVERRIDE; /// Delete files from the current directory (real files, not virtual). void deleteFiles(const QStringList &fileNames, bool reallyDelete = true) Q_DECL_OVERRIDE; /// Remove files from the collection (only virtual, not the real file). void vfs_removeFiles(QStringList *fileNames); /// Create a virtual directory. Only possible in the root directory. void mkDir(const QString &name) Q_DECL_OVERRIDE; /// Rename a (real) file in the current directory. void rename(const QString &fileName, const QString &newName) Q_DECL_OVERRIDE; void calcSpace(const QString &name, KIO::filesize_t *totalSize, unsigned long *totalFiles, unsigned long *totalDirs, bool *stop) Q_DECL_OVERRIDE; /// Returns the URL of the real file or an empty URL if file with name does not exist. QUrl getUrl(const QString& name) Q_DECL_OVERRIDE; virtual QString metaInformation() Q_DECL_OVERRIDE { return _metaInfo; } void setMetaInformation(QString info); protected: bool refreshInternal(const QUrl &origin, bool showHidden) Q_DECL_OVERRIDE; private: /// Return current dir: "/" or pure directory name inline QString currentDir() { const QString path = _currentDirectory.path().mid(1); // remove slash return path.isEmpty() ? "/" : path; } void mkDirInternal(const QString& name); /// Save the dictionary to file void save(); /// Restore the dictionary from file void restore(); /// Create local or KIO vfile. Returns 0 if file does not exist vfile *createVFile(const QUrl &url); /// Return the configuration file storing the urls of virtual files KConfig &getVirtDB(); private slots: void slotStatResult(KJob *job); private: static QHash *> _virtVfsDict; // map virtual directories to containing files static QHash _metaInfoDict; // map virtual directories to meta infos QString _metaInfo; // displayable string with information about the current virtual directory KIO::UDSEntry _fileEntry; // for async call, save stat job result here }; #endif