Make sure there is no write error when saving a file:

http://www.kdenlive.org/mantis/view.php?id=717

svn path=/trunk/kdenlive/; revision=3191
parent bd7d1eef
......@@ -1002,6 +1002,11 @@ bool KdenliveDoc::saveSceneList(const QString &path, const QString &scene) {
QTextStream out(&file);
out << sceneList.toString();
if (file.error() != QFile::NoError) {
KMessageBox::error(kapp->activeWindow(), i18n("Cannot write to file %1", path));
file.close();
return false;
}
file.close();
return true;
}
......
......@@ -1205,7 +1205,7 @@ void MainWindow::closeCurrentDocument() {
switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
case KMessageBox::Yes :
// save document here. If saving fails, return false;
saveFile();
if (saveFile() == false) return;
break;
case KMessageBox::Cancel :
return;
......@@ -1571,7 +1571,7 @@ void MainWindow::slotDoRender(const QString &dest, const QString &render, const
// Generate script file
QFile file(scriptExport);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
m_messageLabel->setMessage(i18n("Cannot write to file %1", scriptExport), ErrorMessage);
KMessageBox::error(this, i18n("Cannot write to file %1", scriptExport));
return;
}
......@@ -1580,6 +1580,11 @@ void MainWindow::slotDoRender(const QString &dest, const QString &render, const
out << "SOURCE=" << "\"" + scriptExport + ".westley\"" << "\n";
out << "TARGET=" << "\"" + dest + "\"" << "\n";
out << renderer << " " << args.join(" ") << "\n" << "\n";
if (file.error() != QFile::NoError) {
KMessageBox::error(this, i18n("Cannot write to file %1", scriptExport));
file.close();
return;
}
file.close();
QFile::setPermissions(scriptExport, file.permissions() | QFile::ExeUser);
}
......
......@@ -155,6 +155,9 @@ void ProfilesDialog::saveProfile(const QString path) {
}
QTextStream out(&file);
out << "description=" << m_view.description->text() << "\n" << "frame_rate_num=" << m_view.frame_num->value() << "\n" << "frame_rate_den=" << m_view.frame_den->value() << "\n" << "width=" << m_view.size_w->value() << "\n" << "height=" << m_view.size_h->value() << "\n" << "progressive=" << m_view.progressive->isChecked() << "\n" << "sample_aspect_num=" << m_view.aspect_num->value() << "\n" << "sample_aspect_den=" << m_view.aspect_den->value() << "\n" << "display_aspect_num=" << m_view.display_num->value() << "\n" << "display_aspect_den=" << m_view.display_den->value() << "\n";
if (file.error() != QFile::NoError) {
KMessageBox::error(this, i18n("Cannot write to file %1", path));
}
file.close();
}
......
......@@ -854,7 +854,7 @@ const QString Render::sceneList() {
return playlist;
}
void Render::saveSceneList(QString path, QDomElement kdenliveData) {
bool Render::saveSceneList(QString path, QDomElement kdenliveData) {
QFile file(path);
QDomDocument doc;
doc.setContent(sceneList(), false);
......@@ -865,11 +865,16 @@ void Render::saveSceneList(QString path, QDomElement kdenliveData) {
}
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
kWarning() << "////// ERROR writing to file: " << path;
return;
return false;
}
QTextStream out(&file);
out << doc.toString();
if (file.error() != QFile::NoError) {
file.close();
return false;
}
file.close();
return true;
}
......
......@@ -93,7 +93,7 @@ Q_OBJECT public:
void setSceneList(QString playlist, int position = 0);
void setProducer(Mlt::Producer *producer, int position);
const QString sceneList();
void saveSceneList(QString path, QDomElement kdenliveData = QDomElement());
bool saveSceneList(QString path, QDomElement kdenliveData = QDomElement());
/** Wraps the VEML command of the same name. Tells the renderer to
play the current scene at the speed specified, relative to normal
......
......@@ -318,6 +318,11 @@ void RenderWidget::slotSaveProfile() {
}
QTextStream out(&file);
out << doc.toString();
if (file.error() != QFile::NoError) {
KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
file.close();
return;
}
file.close();
parseProfiles(newMetaGroupId, newGroupName, newProfileName);
}
......@@ -410,18 +415,21 @@ void RenderWidget::slotEditProfile() {
profiles.appendChild(profileElement);
//QCString save = doc.toString().utf8();
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
delete d;
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
return;
}
QTextStream out(&file);
out << doc.toString();
if (file.error() != QFile::NoError) {
KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
file.close();
parseProfiles(newMetaGroupId, newGroupName, newProfileName);
return;
}
delete d;
file.close();
parseProfiles(newMetaGroupId, newGroupName, newProfileName);
} else delete d;
}
void RenderWidget::slotDeleteProfile(bool refresh) {
......@@ -473,6 +481,11 @@ void RenderWidget::slotDeleteProfile(bool refresh) {
}
QTextStream out(&file);
out << doc.toString();
if (file.error() != QFile::NoError) {
KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
file.close();
return;
}
file.close();
if (refresh) {
parseProfiles(metaGroupId, currentGroup);
......
......@@ -150,13 +150,19 @@ bool TitleDocument::saveDocument(const KUrl& url, QGraphicsPolygonItem* startv,
QDomDocument doc = xml(startv, endv);
KTemporaryFile tmpfile;
if (!tmpfile.open()) kWarning() << "///// CANNOT CREATE TMP FILE in: " << tmpfile.fileName();
if (!tmpfile.open()) {
kWarning() << "///// CANNOT CREATE TMP FILE in: " << tmpfile.fileName();
return false;
}
QFile xmlf(tmpfile.fileName());
xmlf.open(QIODevice::WriteOnly);
xmlf.write(doc.toString().toUtf8());
if (xmlf.error() != QFile::NoError) {
xmlf.close();
return false;
}
xmlf.close();
kDebug() << KIO::NetAccess::upload(tmpfile.fileName(), url, 0);
return true;
return KIO::NetAccess::upload(tmpfile.fileName(), url, 0);
}
int TitleDocument::loadDocument(const KUrl& url, QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv) {
......@@ -200,8 +206,7 @@ int TitleDocument::loadFromXml(QDomDocument doc, QGraphicsPolygonItem* /*startv*
QFont f2;
f2.setPointSize(txtProperties.namedItem("font-size").nodeValue().toInt());
font.setPixelSize(QFontInfo(f2).pixelSize());
}
else font.setPixelSize(txtProperties.namedItem("font-pixel-size").nodeValue().toInt());
} else font.setPixelSize(txtProperties.namedItem("font-pixel-size").nodeValue().toInt());
QColor col(stringToColor(txtProperties.namedItem("font-color").nodeValue()));
QGraphicsTextItem *txt = scene->addText(items.item(i).namedItem("content").firstChild().nodeValue(), font);
txt->setDefaultTextColor(col);
......
......@@ -22,6 +22,7 @@
#include <KGlobalSettings>
#include <KFileDialog>
#include <KStandardDirs>
#include <KMessageBox>
#include <QDomDocument>
#include <QGraphicsItem>
......@@ -666,7 +667,10 @@ void TitleWidget::loadTitle() {
void TitleWidget::saveTitle(KUrl url) {
if (url.isEmpty()) url = KFileDialog::getSaveUrl(KUrl(m_projectPath), "*.kdenlivetitle", this, i18n("Save Title"));
if (!url.isEmpty()) m_titledocument.saveDocument(url, startViewport, endViewport);
if (!url.isEmpty()) {
if (m_titledocument.saveDocument(url, startViewport, endViewport) == false)
KMessageBox::error(this, i18n("Cannot write to file %1", url.path()));
}
}
QDomDocument TitleWidget::xml() {
......
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