aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Faure <[email protected]>2016-06-25 18:02:03 +0200
committerDavid Faure <[email protected]>2016-06-25 18:02:43 +0200
commitda13f112dccc71e7652bac6d974b8c6ad99c909c (patch)
tree686df04b3cb7a1d79902a65b52bbcc5499f2a851
parent27e52f13b6a0a62f8d295157d927d007dbd3eec4 (diff)
Fix loading of files: the whole point of KIO::storedGet() is to use data()..v16.08.2v16.08.1v16.08.0v16.07.90v16.07.80
+ fix unused var + fix *.turtle vs .*turtle Tested.
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/editor.cpp32
-rw-r--r--src/mainwindow.cpp2
3 files changed, 14 insertions, 21 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c08cddf..ddd842d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,6 +35,7 @@ find_package(KF5 5.15 REQUIRED
#Allows QString concatenation to use a single memory allocation per source line.
add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS)
+add_definitions(-DQT_NO_URL_CAST_FROM_STRING)
add_subdirectory (doc)
add_subdirectory (src)
diff --git a/src/editor.cpp b/src/editor.cpp
index c3f89f4..a5790cb 100644
--- a/src/editor.cpp
+++ b/src/editor.cpp
@@ -28,6 +28,7 @@
#include <QSaveFile>
#include <QTemporaryFile>
#include <QTextStream>
+#include <QBuffer>
#include <KFind>
#include <KLocalizedString>
@@ -125,7 +126,7 @@ void Editor::openExample(const QString& example, const QString& exampleName)
if (newFile()) {
setContent(example);
editor->document()->setModified(false);
- setCurrentUrl(exampleName);
+ setCurrentUrl(QUrl::fromLocalFile(exampleName));
}
}
@@ -160,34 +161,27 @@ bool Editor::openFile(const QUrl &_url)
url = QFileDialog::getOpenFileUrl(this,
i18n("Open"),
QUrl(),
- QString("%1 (.*turtle);;%2 (*)").arg(i18n("Turtle code files")).arg(i18n("All files"))
+ QString("%1 (*.turtle);;%2 (*)").arg(i18n("Turtle code files")).arg(i18n("All files"))
);
}
if (!url.isEmpty()) {
-// if (!KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, this)) {
-// KMessageBox::error(this, i18n("The given file could not be read, check if it exists and if it is readable for the current user."));
-// return false;
-// }
- QString fileString; // could be a tmp file or local file
- KIO::StoredTransferJob *job = KIO::storedGet(url);
+ KIO::StoredTransferJob *job = KIO::storedGet(url);
if (job->exec()) {
- QFile file(job->url().toLocalFile());
- if (!file.open(QFile::ReadOnly | QFile::Text)) {
- KMessageBox::error(this, i18n("Cannot read %1", fileString));
- return false;
+ QByteArray data = job->data();
+ QBuffer buffer(&data);
+ if (!buffer.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ return false; // can't happen
}
- QTextStream in(&file);
+ QTextStream in(&buffer);
// check for our magic identifier
QString s;
s = in.readLine();
if (s != KTURTLE_MAGIC_1_0) {
- KMessageBox::error(this, i18n("The file you try to open is not a valid KTurtle script, or is incompatible with this version of KTurtle.\nCannot open %1", fileString));
+ KMessageBox::error(this, i18n("The file you try to open is not a valid KTurtle script, or is incompatible with this version of KTurtle.\nCannot open %1", url.toDisplayString(QUrl::PreferLocalFile)));
return false;
}
- QString localizedScript;
- localizedScript = Translator::instance()->localizeScript(in.readAll());
+ QString localizedScript = Translator::instance()->localizeScript(in.readAll());
setContent(localizedScript);
- QFile::remove(fileString);
setCurrentUrl(url);
editor->document()->setModified(false);
emit fileOpened(url);
@@ -267,7 +261,7 @@ bool Editor::saveFileAs()
QUrl url = QFileDialog::getSaveFileUrl(this,
i18n("Save As"),
QUrl(),
- QString("%1 (.*turtle);;%2 (*)").arg(i18n("Turtle code files")).arg(i18n("All files"))
+ QString("%1 (*.turtle);;%2 (*)").arg(i18n("Turtle code files")).arg(i18n("All files"))
);
if (url.isEmpty()) return false;
KIO::StatJob *job = KIO::stat(url, KIO::StatJob::SourceSide, 0);
@@ -347,7 +341,7 @@ void Editor::findPrev()
void Editor::setCurrentUrl(const QUrl &url)
{
- m_currentUrl = QUrl(url);
+ m_currentUrl = url;
emit contentNameChanged(m_currentUrl.fileName());
}
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 358da62..e318eb8 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -741,8 +741,6 @@ void MainWindow::openDownloadedExample()
QAction* action = qobject_cast<QAction*>(sender());
QString exampleFilename = action->data().toString();
editor->openFile(QUrl::fromLocalFile(exampleFilename));
- QFileInfo fileInfo(exampleFilename);
- editor->setCurrentUrl(fileInfo.baseName());
}
void MainWindow::toggleOverwriteMode(bool b)