]> git.sesse.net Git - kdenlive/blobdiff - src/projectlist.cpp
Fix Coverity #980695
[kdenlive] / src / projectlist.cpp
index 6564238a1704c3470e7c0443a5f9e1ff62294d10..ca4ba8c1755424a61a0af2a33198247815e053bf 100644 (file)
@@ -219,22 +219,24 @@ QStringList InvalidDialog::getIds() const
 
 
 ProjectList::ProjectList(QWidget *parent) :
-    QWidget(parent),
-    m_render(NULL),
-    m_fps(-1),
-    m_commandStack(NULL),
-    m_openAction(NULL),
-    m_reloadAction(NULL),
-    m_extractAudioAction(NULL),
-    m_transcodeAction(NULL),
-    m_clipsActionsMenu(NULL),
-    m_doc(NULL),
-    m_refreshed(false),
-    m_allClipsProcessed(false),
-    m_thumbnailQueue(),
-    m_abortAllJobs(false),
-    m_closing(false),
-    m_invalidClipDialog(NULL)
+    QWidget(parent)
+    , m_render(NULL)
+    , m_fps(-1)
+    , m_menu(NULL)
+    , m_commandStack(NULL)
+    , m_openAction(NULL)
+    , m_reloadAction(NULL)
+    , m_extractAudioAction(NULL)
+    , m_transcodeAction(NULL)
+    , m_clipsActionsMenu(NULL)
+    , m_doc(NULL)
+    , m_refreshed(false)
+    , m_allClipsProcessed(false)
+    , m_thumbnailQueue()
+    , m_proxyAction(NULL)
+    , m_abortAllJobs(false)
+    , m_closing(false)
+    , m_invalidClipDialog(NULL)
 {
     qRegisterMetaType<stringMap> ("stringMap");
     QVBoxLayout *layout = new QVBoxLayout;
@@ -353,7 +355,7 @@ ProjectList::~ProjectList()
     m_jobThreads.clearFutures();
     if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
     m_jobList.clear();
-    delete m_menu;
+    if (m_menu) delete m_menu;
     m_listView->blockSignals(true);
     m_listView->clear();
     delete m_listViewDelegate;
@@ -404,6 +406,10 @@ void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
 
 void ProjectList::setupGeneratorMenu(const QHash<QString,QMenu*>& menus)
 {
+    if (!m_menu) {
+       kDebug()<<"Warning, menu was not created, something is wrong";
+       return;
+    }
     if (!menus.contains("addMenu") && ! menus.value("addMenu") )
         return;
     QMenu *menu = m_addButton->menu();
@@ -434,8 +440,8 @@ void ProjectList::setupGeneratorMenu(const QHash<QString,QMenu*>& menus)
                m_clipsActionsMenu = stabilizeMenu;
 
        }
-    m_menu->addAction(m_reloadAction);
-    m_menu->addAction(m_proxyAction);
+    if (m_reloadAction) m_menu->addAction(m_reloadAction);
+    if (m_proxyAction) m_menu->addAction(m_proxyAction);
        if (menus.contains("inTimelineMenu") && menus.value("inTimelineMenu")){
                QMenu* inTimelineMenu=menus.value("inTimelineMenu");
                m_menu->addMenu(inTimelineMenu);
@@ -892,6 +898,7 @@ void ProjectList::slotClipSelected()
 
 void ProjectList::adjustProxyActions(ProjectItem *clip) const
 {
+    if (!m_proxyAction) return;
     if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == SLIDESHOW || clip->clipType() == AUDIO) {
         m_proxyAction->setEnabled(false);
         return;
@@ -1071,6 +1078,10 @@ void ProjectList::slotCheckScrolling()
 
 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
 {
+    if (!m_menu) {
+       kDebug()<<"Warning, menu was not created, something is wrong";
+       return;
+    }
     bool enable = item ? true : false;
     m_editButton->defaultAction()->setEnabled(enable);
     m_deleteButton->defaultAction()->setEnabled(enable);
@@ -1184,10 +1195,10 @@ void ProjectList::updateButtons() const
         else m_editButton->defaultAction()->setEnabled(false);
     }
     m_openAction->setEnabled(false);
-    m_reloadAction->setEnabled(false);
+    if (m_reloadAction) m_reloadAction->setEnabled(false);
     m_transcodeAction->setEnabled(false);
     m_clipsActionsMenu->setEnabled(false);
-    m_proxyAction->setEnabled(false);
+    if (m_proxyAction) m_proxyAction->setEnabled(false);
 }
 
 void ProjectList::selectItemById(const QString &clipId)
@@ -2198,30 +2209,56 @@ void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
 
 void ProjectList::extractMetadata(DocClipBase *clip)
 {
+    CLIPTYPE t = clip->clipType();
+    if (t != AV && t != VIDEO) {
+       // Currently, we only use exiftool on video files
+       return;
+    }
     QMap <QString, QString> props = clip->properties();
     if (KdenliveSettings::use_exiftool() && !props.contains("exiftool")) {
-       QString codecid = props.value("videocodecid").simplified();
-       if (codecid == "h264") {
+       QMap <QString, QString> meta;
+       QString url = clip->fileURL().path();
+       //Check for Canon THM file
+       url = url.section('.', 0, -2) + ".THM";
+       if (QFile::exists(url)) {
+           // Read the exif metadata embeded in the THM file
            QProcess p;
            QStringList args;
-           args << "-g" << "-args" << clip->fileURL().encodedPathAndQuery();
+           args << "-g" << "-args" << url;
            p.start("exiftool", args);
            p.waitForFinished();
            QString res = p.readAllStandardOutput();
            QStringList list = res.split("\n");
-           QMap <QString, QString> meta;
            foreach(QString tagline, list) {
-               if (!tagline.startsWith("-H264")) continue;
-               QString tag = tagline.section(':', 1);
+               if (tagline.startsWith("-File") || tagline.startsWith("-ExifTool")) continue;
+               QString tag = tagline.section(':', 1).simplified();
                if (tag.startsWith("ImageWidth") || tag.startsWith("ImageHeight")) continue;
-               meta.insert(tag.section('=', 0, 0), tag.section('=', 1));
+               if (!tag.section('=', 0, 0).isEmpty() && !tag.section('=', 1).simplified().isEmpty())
+                   meta.insert(tag.section('=', 0, 0), tag.section('=', 1).simplified());
            }
-           clip->setProperty("exiftool", "1");
-           if (!meta.isEmpty()) {
-               clip->setMetadata(meta, "ExifTool");
-               //checkCamcorderFilters(clip, meta);
+       } else {
+           QString codecid = props.value("videocodecid").simplified();
+           if (codecid == "h264") {
+               QProcess p;
+               QStringList args;
+               args << "-g" << "-args" << clip->fileURL().encodedPathAndQuery();
+               p.start("exiftool", args);
+               p.waitForFinished();
+               QString res = p.readAllStandardOutput();
+               QStringList list = res.split("\n");
+               foreach(QString tagline, list) {
+                   if (!tagline.startsWith("-H264")) continue;
+                   QString tag = tagline.section(':', 1);
+                   if (tag.startsWith("ImageWidth") || tag.startsWith("ImageHeight")) continue;
+                   meta.insert(tag.section('=', 0, 0), tag.section('=', 1));
+               }
            }
        }
+       clip->setProperty("exiftool", "1");
+       if (!meta.isEmpty()) {
+           clip->setMetadata(meta, "ExifTool");
+           //checkCamcorderFilters(clip, meta);
+       }
     }
     if (KdenliveSettings::use_magicLantern() && !props.contains("magiclantern")) {
        QMap <QString, QString> meta;
@@ -2238,24 +2275,6 @@ void ProjectList::extractMetadata(DocClipBase *clip)
                }
            }
        }
-       url = url.section('.', 0, -2) + ".THM";
-       if (QFile::exists(url) && KdenliveSettings::use_exiftool()) {
-           // Read the exif metadata embeded in the THM file
-           QProcess p;
-           QStringList args;
-           args << "-g" << "-args" << url;
-           p.start("exiftool", args);
-           p.waitForFinished();
-           QString res = p.readAllStandardOutput();
-           QStringList list = res.split("\n");
-           foreach(QString tagline, list) {
-               if (tagline.startsWith("-File") || tagline.startsWith("-ExifTool")) continue;
-               QString tag = tagline.section(':', 1).simplified();
-               if (tag.startsWith("ImageWidth") || tag.startsWith("ImageHeight")) continue;
-               if (!tag.section('=', 0, 0).isEmpty() && !tag.section('=', 1).simplified().isEmpty())
-                   meta.insert(tag.section('=', 0, 0), tag.section('=', 1).simplified());
-           }
-       }
        
        if (!meta.isEmpty())
            clip->setMetadata(meta, "Magic Lantern");