changeset 401:2fdf440ea66a

Fix some segfaults, etc.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 19 Oct 2012 16:28:06 +0300
parents f44a89a25c97
children 0f290af63fc1
files edgui.cpp edmain.cpp edmain.h edtimeline.cpp edtlobj.cpp edtlobj.h
diffstat 6 files changed, 75 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/edgui.cpp	Fri Oct 19 15:56:59 2012 +0300
+++ b/edgui.cpp	Fri Oct 19 16:28:06 2012 +0300
@@ -26,15 +26,14 @@
     else
         name = currTimeline->filename;
 
-    if (changed)
+    if (currTimeline && currTimeline->touched())
         name = "*" + name;
     
     setWindowTitle(name + " - " + QCoreApplication::applicationName());
 
     // Enable menu items based on states
-    menuActSave->setEnabled(currTimeline->changed || changed);
-    menuActSaveAs->setEnabled(currTimeline->changed || changed);
-
+    menuActSave->setEnabled(currTimeline != NULL&& currTimeline->touched());
+    menuActSaveAs->setEnabled(currTimeline != NULL);
     
     // Enable undo/redo items and set their texts based on history status
     int historyLevels = undoHistory.size();
@@ -43,7 +42,7 @@
     
     if (undoHistoryPos >= 0 && undoHistoryPos < historyLevels)
     {
-        itemText = " " + undoHistory.at(undoHistoryPos)->state;
+        itemText = " " + undoHistory.at(undoHistoryPos)->state();
         itemEnabled = true;
     }
     else
@@ -57,7 +56,7 @@
 
     if (undoHistoryPos > 0 && historyLevels > 0)
     {
-        itemText = " " + undoHistory.at(undoHistoryPos - 1)->state;
+        itemText = " " + undoHistory.at(undoHistoryPos - 1)->state();
         itemEnabled = true;
     }
     else
@@ -121,7 +120,7 @@
 {
     bool okToCreate = true;
 
-    if (changed)
+    if (currTimeline != NULL && currTimeline->touched())
     {
         okToCreate = false;
         switch (showDocumentModifiedDialog())
@@ -132,7 +131,7 @@
             
             case QMessageBox::Save:
                 actionFileSave();
-                if (!changed)
+                if (!currTimeline->touched())
                 {
                     QMessageBox::information(this, 
                         "Document saved",
@@ -156,7 +155,7 @@
 {
     bool okToOpen = true;
 
-    if (changed)
+    if (currTimeline != NULL && currTimeline->touched())
     {
         okToOpen = false;
 
@@ -168,7 +167,7 @@
             
             case QMessageBox::Save:
                 actionFileSave();
-                if (!changed)
+                if (!currTimeline->touched())
                 {
                     QMessageBox::information(this, 
                         "Document saved",
@@ -241,7 +240,7 @@
 {
     bool okToClose = true;
 
-    if (changed)
+    if (currTimeline && currTimeline->touched())
     {
         okToClose = false;
         switch (showDocumentModifiedDialog())
@@ -252,7 +251,7 @@
             
             case QMessageBox::Save:
                 actionFileSave();
-                if (!changed)
+                if (!currTimeline->touched())
                     okToClose = true;
                 break;
             
--- a/edmain.cpp	Fri Oct 19 15:56:59 2012 +0300
+++ b/edmain.cpp	Fri Oct 19 16:28:06 2012 +0300
@@ -100,7 +100,6 @@
     setWindowTitle(QCoreApplication::applicationName());
 
     memset(&engine, 0, sizeof(engine));
-    changed = FALSE;
     initSDL = FALSE;
     currTimeline = NULL;
 
@@ -207,17 +206,9 @@
 
     // Setup GUI elements
     createMainGUI();
-    createNewFile();
-    DMTimelineTrack *tr = NULL;
-    dmTimelineAddTrack(currTimeline->tl, &tr, "Penis");
-    dmTimelineAddTrack(currTimeline->tl, &tr, "Cyrbe");
-    dmTimelineAddTrack(currTimeline->tl, &tr, "Pasci");
-    dmTimelineAddTrack(currTimeline->tl, &tr, "Lol");
-
+//    createNewFile();
     timelineView->setTimeline(currTimeline);
-
     settingsRestore();
-
     initEffectsAndResources();
     statusMsg("Application started.");
 }
@@ -377,7 +368,6 @@
 
     update();
     historyReset();
-    changed = false;
     updateMenuStates();
 }
 
@@ -402,7 +392,6 @@
 
         update();
         historyReset();
-        changed = false;
         updateMenuStates();
     }
 }
@@ -445,7 +434,9 @@
 //
 void DemoEditor::historyReset()
 {
-    changed = false;
+    if (currTimeline != NULL)
+        currTimeline->scrub();
+
     undoHistoryPos = -1;
     undoHistoryMax = DOC_UNDO_MAX;
     undoHistory.clear();
@@ -454,7 +445,10 @@
 
 void DemoEditor::historyPush(QString description)
 {
-    if (!undoHistory.isEmpty() && undoHistory.last()->state == "-")
+    if (currTimeline == NULL)
+        return;
+
+    if (!undoHistory.isEmpty() && undoHistory.last()->state() == "-")
     {
         delete undoHistory.takeLast();
     }
@@ -465,19 +459,22 @@
     }
     
     TimelineObject *copy = new TimelineObject(currTimeline);
-    copy->state = description;
+    copy->setState(description);
     undoHistory.append(copy);
 }
 
 
 void DemoEditor::historyTop()
 {
+    if (currTimeline == NULL)
+        return;
+
     TimelineObject *copy = new TimelineObject(currTimeline);
-    copy->state = "-";
+    copy->setState("-");
     undoHistory.append(copy);
 
     undoHistoryPos = undoHistory.size() - 1;
-    changed = true;
+    currTimeline->touch();
     updateMenuStates();
     update();
 }
@@ -499,7 +496,7 @@
         undoHistoryPos++;
         delete currTimeline;
         currTimeline = new TimelineObject(undoHistory.at(undoHistoryPos));
-        changed = true;
+        currTimeline->touch();
         
         updateMenuStates();
         update();
@@ -514,7 +511,7 @@
         undoHistoryPos--;
         delete currTimeline;
         currTimeline = new TimelineObject(undoHistory.at(undoHistoryPos));
-        changed = true;
+        currTimeline->touch();
         
         updateMenuStates();
         update();
--- a/edmain.h	Fri Oct 19 15:56:59 2012 +0300
+++ b/edmain.h	Fri Oct 19 16:28:06 2012 +0300
@@ -107,7 +107,7 @@
     void saveToFile(QString filename);
 
 
-    bool changed, initSDL;
+    bool initSDL;
     float currViewScale;
     int currViewOffset;
     int currFrameTime;
--- a/edtimeline.cpp	Fri Oct 19 15:56:59 2012 +0300
+++ b/edtimeline.cpp	Fri Oct 19 16:28:06 2012 +0300
@@ -230,7 +230,7 @@
 {
     if (tl != NULL)
     {
-        tl->changed++;
+        tl->touch();
         emit timelineChanged();
     }
 }
--- a/edtlobj.cpp	Fri Oct 19 15:56:59 2012 +0300
+++ b/edtlobj.cpp	Fri Oct 19 16:28:06 2012 +0300
@@ -9,13 +9,13 @@
 TimelineObject::TimelineObject()
 {
     dmTimelineNew(&tl, "Demo");
-    changed = 0;
+    scrub();
 }
 
 
 TimelineObject::TimelineObject(TimelineObject *obj)
 {
-    changed = 0;
+    scrub();
     filename = obj->filename;
     dmCopyTimeline(obj->tl, &tl);
 }
@@ -36,7 +36,8 @@
 
     dmFreeTimeline(tl);
     int err = dmLoadTimeline(res, &tl);
-    changed = 0;
+
+    scrub();
 
     dmf_close(res);
     filename = mfilename;
@@ -52,8 +53,38 @@
         return DMERR_FOPEN;
 
     int err = dmSaveTimeline(res, tl);
-    changed = 0;
+    scrub();
 
     dmf_close(res);
     return err;
 }
+
+
+void TimelineObject::touch()
+{
+    ntouches++;
+}
+
+
+void TimelineObject::scrub()
+{
+    ntouches = 0;
+}
+
+
+bool TimelineObject::touched()
+{
+    return ntouches;
+}
+
+
+void TimelineObject::setState(const QString &mstate)
+{
+    cstate = mstate;
+}
+
+
+QString TimelineObject::state() const
+{
+    return cstate;
+}
--- a/edtlobj.h	Fri Oct 19 15:56:59 2012 +0300
+++ b/edtlobj.h	Fri Oct 19 16:28:06 2012 +0300
@@ -10,10 +10,12 @@
 
 class TimelineObject
 {
+private:
+    QString cstate;
+    int ntouches;
+
 public:
-    QString state;
     QString filename;
-    int changed;
     DMTimeline *tl;
 
     TimelineObject();
@@ -22,6 +24,13 @@
 
     int load(QString filename);
     int save(QString filename);
+    
+    void scrub();
+    void touch();
+    bool touched();
+
+    void setState(const QString &mstate);
+    QString state() const;
 };