pagevideos: Prevent renaming video if file name prefix is already used
authorWuzzy <Wuzzy2@mail.ru>
Mon, 06 May 2019 01:25:50 +0200
changeset 14893 b5a9dd36c7ea
parent 14892 a414d37278df
child 14894 9b292184d793
pagevideos: Prevent renaming video if file name prefix is already used This prevents some issues and weirdnesses with losing the video thumbnail, etc.
QTfrontend/ui/page/pagevideos.cpp
--- a/QTfrontend/ui/page/pagevideos.cpp	Mon May 06 00:43:27 2019 +0200
+++ b/QTfrontend/ui/page/pagevideos.cpp	Mon May 06 01:25:50 2019 +0200
@@ -292,6 +292,7 @@
         VideoItem * item = nameItem(row);
         item->seen = true;
         item->desc = "";
+        setName(item, item->name);
         updateSize(row);
     }
 
@@ -426,8 +427,16 @@
         }
     }
     else
+        newPrefix = newName;
+    for (int i = 0; i < filesTable->rowCount(); i++)
     {
-        newPrefix = newName;
+        // don't allow rename if duplicate prefix
+        VideoItem * iterateItem = nameItem(i);
+        if ((i != row) && (newPrefix == iterateItem->prefix))
+        {
+            setName(item, oldName);
+            return;
+        }
     }
 #ifdef Q_OS_WIN
     // there is a bug in qt, QDir::rename() doesn't fail on such names but damages files
@@ -460,6 +469,15 @@
     item->setText(newName);
     nameChangedFromCode = false;
     item->name = newName;
+    // try to extract prefix
+    if (item->ready())
+        item->prefix = item->name;
+    else
+        item->prefix = item->pRecorder->name;
+    // remove extension
+    int pt = item->prefix.lastIndexOf('.');
+    if (pt != -1)
+        item->prefix.truncate(pt);
 }
 
 int PageVideos::appendRow(const QString & name)
@@ -546,7 +564,7 @@
         desc += item->desc + '\n';
     }
 
-    if (item->prefix.isEmpty())
+    if (item->prefix.isNull() || item->prefix.isEmpty())
     {
         // try to extract prefix from file name instead
         if (item->ready())