]> git.sesse.net Git - kdenlive/commitdiff
Make sure there is no write error when saving a file:
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 30 Mar 2009 22:44:17 +0000 (22:44 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 30 Mar 2009 22:44:17 +0000 (22:44 +0000)
http://www.kdenlive.org/mantis/view.php?id=717

svn path=/trunk/kdenlive/; revision=3191

src/kdenlivedoc.cpp
src/mainwindow.cpp
src/profilesdialog.cpp
src/renderer.cpp
src/renderer.h
src/renderwidget.cpp
src/titledocument.cpp
src/titlewidget.cpp

index e3640e4d7b10d431c885e541396d5b9e5cd4b80c..382d92236d14cb131282b435b35258269547fe6c 100644 (file)
@@ -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;
 }
index 6e5640d25ba8fed0bd36dcca439f0a2c887cec7d..879ac05fb30301c10fead6cf097a3adb5e0c04bf 100644 (file)
@@ -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);
         }
index 97a822e93665f6c618abf23c9eaaf004554ab329..fe39f86b5cfe47aedb24e41f505de1336ef44288 100644 (file)
@@ -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();
 }
 
index 096f25986af1b09b934bc8b3ca5ebc35e2f1715c..7fdd9e4a9ac2c92dc92d401090e240a5a77f386b 100644 (file)
@@ -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;
 }
 
 
index cc1b3ec73530c464d04da6f7458935c864287a56..eda891903b6570d318b56ea54e88a438c4e2e8e5 100644 (file)
@@ -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
index b16c0e34b8b61db3eaea9ccd3f67401b9220aa30..84af5b95ee8cacf00870d14aab7c988d4cd4beda 100644 (file)
@@ -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();
-
+        delete d;
         if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
-            KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
-            delete d;
+            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();
+            return;
+        }
         file.close();
         parseProfiles(newMetaGroupId, newGroupName, newProfileName);
-    }
-    delete d;
+    } 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);
index 1f02b7e3df95c53bf4322d13109644f8dbbbb1c9..3a841510acf8b1146453a0b67b2521b1feb48620 100644 (file)
@@ -70,8 +70,8 @@ QDomDocument TitleDocument::xml(QGraphicsPolygonItem* startv, QGraphicsPolygonIt
         case 8:
             e.setAttribute("type", "QGraphicsTextItem");
             t = static_cast<QGraphicsTextItem *>(item);
-           // Don't save empty text nodes
-           if (t->toPlainText().simplified().isEmpty()) continue;
+            // Don't save empty text nodes
+            if (t->toPlainText().simplified().isEmpty()) continue;
             //content.appendChild(doc.createTextNode(((QGraphicsTextItem*)item)->toHtml()));
             content.appendChild(doc.createTextNode(t->toPlainText()));
             font = t->font();
@@ -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) {
@@ -190,18 +196,17 @@ int TitleDocument::loadFromXml(QDomDocument doc, QGraphicsPolygonItem* /*startv*
             int zValue = items.item(i).attributes().namedItem("z-index").nodeValue().toInt();
             if (zValue > -1000)
                 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());
                     font.setBold(txtProperties.namedItem("font-bold").nodeValue().toInt());
                     font.setItalic(txtProperties.namedItem("font-italic").nodeValue().toInt());
                     font.setUnderline(txtProperties.namedItem("font-underline").nodeValue().toInt());
-                   // Older Kdenlive version did not store pixel size but point size
-                   if (txtProperties.namedItem("font-pixel-size").isNull()) {
-                       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());
+                    // Older Kdenlive version did not store pixel size but point size
+                    if (txtProperties.namedItem("font-pixel-size").isNull()) {
+                        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());
                     QColor col(stringToColor(txtProperties.namedItem("font-color").nodeValue()));
                     QGraphicsTextItem *txt = scene->addText(items.item(i).namedItem("content").firstChild().nodeValue(), font);
                     txt->setDefaultTextColor(col);
index 1505adb8a0eebda079236c7c09bd226d9d2d9311..5f876ea87c0f1e3b6515c557a53a975cf425f5d1 100644 (file)
@@ -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() {