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) { ...@@ -1002,6 +1002,11 @@ bool KdenliveDoc::saveSceneList(const QString &path, const QString &scene) {
QTextStream out(&file); QTextStream out(&file);
out << sceneList.toString(); 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(); file.close();
return true; return true;
} }
......
...@@ -1205,7 +1205,7 @@ void MainWindow::closeCurrentDocument() { ...@@ -1205,7 +1205,7 @@ void MainWindow::closeCurrentDocument() {
switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) { switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
case KMessageBox::Yes : case KMessageBox::Yes :
// save document here. If saving fails, return false; // save document here. If saving fails, return false;
saveFile(); if (saveFile() == false) return;
break; break;
case KMessageBox::Cancel : case KMessageBox::Cancel :
return; return;
...@@ -1571,7 +1571,7 @@ void MainWindow::slotDoRender(const QString &dest, const QString &render, const ...@@ -1571,7 +1571,7 @@ void MainWindow::slotDoRender(const QString &dest, const QString &render, const
// Generate script file // Generate script file
QFile file(scriptExport); QFile file(scriptExport);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { 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; return;
} }
...@@ -1580,6 +1580,11 @@ void MainWindow::slotDoRender(const QString &dest, const QString &render, const ...@@ -1580,6 +1580,11 @@ void MainWindow::slotDoRender(const QString &dest, const QString &render, const
out << "SOURCE=" << "\"" + scriptExport + ".westley\"" << "\n"; out << "SOURCE=" << "\"" + scriptExport + ".westley\"" << "\n";
out << "TARGET=" << "\"" + dest + "\"" << "\n"; out << "TARGET=" << "\"" + dest + "\"" << "\n";
out << renderer << " " << args.join(" ") << "\n" << "\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(); file.close();
QFile::setPermissions(scriptExport, file.permissions() | QFile::ExeUser); QFile::setPermissions(scriptExport, file.permissions() | QFile::ExeUser);
} }
......
...@@ -155,6 +155,9 @@ void ProfilesDialog::saveProfile(const QString path) { ...@@ -155,6 +155,9 @@ void ProfilesDialog::saveProfile(const QString path) {
} }
QTextStream out(&file); 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"; 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(); file.close();
} }
......
...@@ -854,7 +854,7 @@ const QString Render::sceneList() { ...@@ -854,7 +854,7 @@ const QString Render::sceneList() {
return playlist; return playlist;
} }
void Render::saveSceneList(QString path, QDomElement kdenliveData) { bool Render::saveSceneList(QString path, QDomElement kdenliveData) {
QFile file(path); QFile file(path);
QDomDocument doc; QDomDocument doc;
doc.setContent(sceneList(), false); doc.setContent(sceneList(), false);
...@@ -865,11 +865,16 @@ void Render::saveSceneList(QString path, QDomElement kdenliveData) { ...@@ -865,11 +865,16 @@ void Render::saveSceneList(QString path, QDomElement kdenliveData) {
} }
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
kWarning() << "////// ERROR writing to file: " << path; kWarning() << "////// ERROR writing to file: " << path;
return; return false;
} }
QTextStream out(&file); QTextStream out(&file);
out << doc.toString(); out << doc.toString();
if (file.error() != QFile::NoError) {
file.close();
return false;
}
file.close(); file.close();
return true;
} }
......
...@@ -93,7 +93,7 @@ Q_OBJECT public: ...@@ -93,7 +93,7 @@ Q_OBJECT public:
void setSceneList(QString playlist, int position = 0); void setSceneList(QString playlist, int position = 0);
void setProducer(Mlt::Producer *producer, int position); void setProducer(Mlt::Producer *producer, int position);
const QString sceneList(); 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 /** Wraps the VEML command of the same name. Tells the renderer to
play the current scene at the speed specified, relative to normal play the current scene at the speed specified, relative to normal
......
...@@ -318,6 +318,11 @@ void RenderWidget::slotSaveProfile() { ...@@ -318,6 +318,11 @@ void RenderWidget::slotSaveProfile() {
} }
QTextStream out(&file); QTextStream out(&file);
out << doc.toString(); out << doc.toString();
if (file.error() != QFile::NoError) {
KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
file.close();
return;
}
file.close(); file.close();
parseProfiles(newMetaGroupId, newGroupName, newProfileName); parseProfiles(newMetaGroupId, newGroupName, newProfileName);
} }
...@@ -410,18 +415,21 @@ void RenderWidget::slotEditProfile() { ...@@ -410,18 +415,21 @@ void RenderWidget::slotEditProfile() {
profiles.appendChild(profileElement); profiles.appendChild(profileElement);
//QCString save = doc.toString().utf8(); //QCString save = doc.toString().utf8();
delete d;
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile)); KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
delete d;
return; return;
} }
QTextStream out(&file); QTextStream out(&file);
out << doc.toString(); out << doc.toString();
if (file.error() != QFile::NoError) {
KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
file.close();
return;
}
file.close(); file.close();
parseProfiles(newMetaGroupId, newGroupName, newProfileName); parseProfiles(newMetaGroupId, newGroupName, newProfileName);
} } else delete d;
delete d;
} }
void RenderWidget::slotDeleteProfile(bool refresh) { void RenderWidget::slotDeleteProfile(bool refresh) {
...@@ -473,6 +481,11 @@ void RenderWidget::slotDeleteProfile(bool refresh) { ...@@ -473,6 +481,11 @@ void RenderWidget::slotDeleteProfile(bool refresh) {
} }
QTextStream out(&file); QTextStream out(&file);
out << doc.toString(); out << doc.toString();
if (file.error() != QFile::NoError) {
KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
file.close();
return;
}
file.close(); file.close();
if (refresh) { if (refresh) {
parseProfiles(metaGroupId, currentGroup); parseProfiles(metaGroupId, currentGroup);
......
...@@ -70,8 +70,8 @@ QDomDocument TitleDocument::xml(QGraphicsPolygonItem* startv, QGraphicsPolygonIt ...@@ -70,8 +70,8 @@ QDomDocument TitleDocument::xml(QGraphicsPolygonItem* startv, QGraphicsPolygonIt
case 8: case 8:
e.setAttribute("type", "QGraphicsTextItem"); e.setAttribute("type", "QGraphicsTextItem");
t = static_cast<QGraphicsTextItem *>(item); t = static_cast<QGraphicsTextItem *>(item);
// Don't save empty text nodes // Don't save empty text nodes
if (t->toPlainText().simplified().isEmpty()) continue; if (t->toPlainText().simplified().isEmpty()) continue;
//content.appendChild(doc.createTextNode(((QGraphicsTextItem*)item)->toHtml())); //content.appendChild(doc.createTextNode(((QGraphicsTextItem*)item)->toHtml()));
content.appendChild(doc.createTextNode(t->toPlainText())); content.appendChild(doc.createTextNode(t->toPlainText()));
font = t->font(); font = t->font();
...@@ -150,13 +150,19 @@ bool TitleDocument::saveDocument(const KUrl& url, QGraphicsPolygonItem* startv, ...@@ -150,13 +150,19 @@ bool TitleDocument::saveDocument(const KUrl& url, QGraphicsPolygonItem* startv,
QDomDocument doc = xml(startv, endv); QDomDocument doc = xml(startv, endv);
KTemporaryFile tmpfile; 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()); QFile xmlf(tmpfile.fileName());
xmlf.open(QIODevice::WriteOnly); xmlf.open(QIODevice::WriteOnly);
xmlf.write(doc.toString().toUtf8()); xmlf.write(doc.toString().toUtf8());
if (xmlf.error() != QFile::NoError) {
xmlf.close();
return false;
}
xmlf.close(); xmlf.close();
kDebug() << KIO::NetAccess::upload(tmpfile.fileName(), url, 0); return KIO::NetAccess::upload(tmpfile.fileName(), url, 0);
return true;
} }
int TitleDocument::loadDocument(const KUrl& url, QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv) { int TitleDocument::loadDocument(const KUrl& url, QGraphicsPolygonItem* startv, QGraphicsPolygonItem* endv) {
...@@ -190,18 +196,17 @@ int TitleDocument::loadFromXml(QDomDocument doc, QGraphicsPolygonItem* /*startv* ...@@ -190,18 +196,17 @@ int TitleDocument::loadFromXml(QDomDocument doc, QGraphicsPolygonItem* /*startv*
int zValue = items.item(i).attributes().namedItem("z-index").nodeValue().toInt(); int zValue = items.item(i).attributes().namedItem("z-index").nodeValue().toInt();
if (zValue > -1000) if (zValue > -1000)
if (items.item(i).attributes().namedItem("type").nodeValue() == "QGraphicsTextItem") { if (items.item(i).attributes().namedItem("type").nodeValue() == "QGraphicsTextItem") {
QDomNamedNodeMap txtProperties = items.item(i).namedItem("content").attributes(); QDomNamedNodeMap txtProperties = items.item(i).namedItem("content").attributes();
QFont font(txtProperties.namedItem("font").nodeValue()); QFont font(txtProperties.namedItem("font").nodeValue());
font.setBold(txtProperties.namedItem("font-bold").nodeValue().toInt()); font.setBold(txtProperties.namedItem("font-bold").nodeValue().toInt());
font.setItalic(txtProperties.namedItem("font-italic").nodeValue().toInt()); font.setItalic(txtProperties.namedItem("font-italic").nodeValue().toInt());
font.setUnderline(txtProperties.namedItem("font-underline").nodeValue().toInt()); font.setUnderline(txtProperties.namedItem("font-underline").nodeValue().toInt());
// Older Kdenlive version did not store pixel size but point size // Older Kdenlive version did not store pixel size but point size
if (txtProperties.namedItem("font-pixel-size").isNull()) { if (txtProperties.namedItem("font-pixel-size").isNull()) {
QFont f2; QFont f2;
f2.setPointSize(txtProperties.namedItem("font-size").nodeValue().toInt()); f2.setPointSize(txtProperties.namedItem("font-size").nodeValue().toInt());
font.setPixelSize(QFontInfo(f2).pixelSize()); 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())); QColor col(stringToColor(txtProperties.namedItem("font-color").nodeValue()));
QGraphicsTextItem *txt = scene->addText(items.item(i).namedItem("content").firstChild().nodeValue(), font); QGraphicsTextItem *txt = scene->addText(items.item(i).namedItem("content").firstChild().nodeValue(), font);
txt->setDefaultTextColor(col); txt->setDefaultTextColor(col);
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <KGlobalSettings> #include <KGlobalSettings>
#include <KFileDialog> #include <KFileDialog>
#include <KStandardDirs> #include <KStandardDirs>
#include <KMessageBox>
#include <QDomDocument> #include <QDomDocument>
#include <QGraphicsItem> #include <QGraphicsItem>
...@@ -666,7 +667,10 @@ void TitleWidget::loadTitle() { ...@@ -666,7 +667,10 @@ void TitleWidget::loadTitle() {
void TitleWidget::saveTitle(KUrl url) { void TitleWidget::saveTitle(KUrl url) {
if (url.isEmpty()) url = KFileDialog::getSaveUrl(KUrl(m_projectPath), "*.kdenlivetitle", this, i18n("Save Title")); 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() { 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