Commit 20c09f3c authored by Elvis Angelaccio's avatar Elvis Angelaccio

Don't add invalid URLs to the recent files

Part::openFile() used to return false if the URL of the part was not a
valid archive. This is no longer the case as nowadays we run an async
LoadJob. So MainWindow cannot use the return value of openFile() to
choose whether to add the URL to the recent files. Instead, we connect
to the part's completed() signal which is emitted only if the LoadJob
ends without errors.
parent 2529d2f4
......@@ -164,6 +164,7 @@ bool MainWindow::loadPart()
// #365200: this will disable m_recentFilesAction, while openUrl() will enable it.
// So updateActions() needs to be called after openUrl() returns.
connect(m_part, SIGNAL(busy()), this, SLOT(updateActions()), Qt::QueuedConnection);
connect(m_part, static_cast<void (KParts::ReadOnlyPart::*)()>(&KParts::ReadOnlyPart::completed), this, &MainWindow::addPartUrl);
return true;
}
......@@ -219,15 +220,12 @@ void MainWindow::openArchive()
void MainWindow::openUrl(const QUrl& url)
{
if (!url.isEmpty()) {
m_part->setArguments(m_openArgs);
if (m_part->openUrl(url)) {
m_recentFilesAction->addUrl(url);
} else {
m_recentFilesAction->removeUrl(url);
}
if (url.isEmpty()) {
return;
}
m_part->setArguments(m_openArgs);
m_part->openUrl(url);
}
void MainWindow::setShowExtractDialog(bool option)
......@@ -286,6 +284,11 @@ void MainWindow::writeSettings()
iface->config()->save();
}
void MainWindow::addPartUrl()
{
m_recentFilesAction->addUrl(m_part->url());
}
void MainWindow::newArchive()
{
qCDebug(ARK) << "Creating new archive";
......
......@@ -58,6 +58,7 @@ private slots:
void quit();
void showSettings();
void writeSettings();
void addPartUrl();
private:
void setupActions();
......
......@@ -776,11 +776,12 @@ bool Part::openFile()
if (creatingNewArchive) {
createArchive();
} else {
loadArchive();
return true;
}
return true;
loadArchive();
// Loading is async, we don't know yet whether we got a valid archive.
return false;
}
bool Part::saveFile()
......@@ -891,6 +892,8 @@ void Part::slotLoadingFinished(KJob *job)
emit setWindowCaption(QString());
}
} else {
emit completed();
}
m_view->sortByColumn(0, Qt::AscendingOrder);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment