]> git.sesse.net Git - kdenlive/blobdiff - src/mainwindow.cpp
Use QPointer, delete on error path [krazy 23/37] by Mikko Rapeli
[kdenlive] / src / mainwindow.cpp
index 3bcb4b797030aabcca8018903a830176c59265b4..4529d9be437dd538a1e295647ef3b9bebb35d34a 100644 (file)
@@ -399,14 +399,15 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, const QString &
     KActionCategory *layoutActions = new KActionCategory(i18n("Layouts"), actionCollection());
     m_loadLayout = new KSelectAction(i18n("Load Layout"), actionCollection());
     for (int i = 1; i < 5; i++) {
-        KAction *load = new KAction(KIcon(), i18n("Layout %1").arg(i), this);
+        KAction *load = new KAction(KIcon(), i18n("Layout %1"i), this);
         load->setData("_" + QString::number(i));
        layoutActions->addAction("load_layout" + QString::number(i), load);
         m_loadLayout->addAction(load);
-        KAction *save = new KAction(KIcon(), i18n("Save As Layout %1").arg(i), this);
+        KAction *save = new KAction(KIcon(), i18n("Save As Layout %1"i), this);
         save->setData("_" + QString::number(i));
         layoutActions->addAction("save_layout" + QString::number(i), save);
     }
+    // Required to enable user to add the load layout action to toolbar
     layoutActions->addAction("load_layouts", m_loadLayout);
     connect(m_loadLayout, SIGNAL(triggered(QAction*)), this, SLOT(slotLoadLayout(QAction*)));
 
@@ -430,6 +431,9 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, const QString &
     m_effectList->reloadEffectList(m_effectsMenu, m_effectActions);
     m_effectsActionCollection->readSettings();
 
+       // Populate View menu with show / hide actions for dock widgets
+    KActionCategory *guiActions = new KActionCategory(i18n("Interface"), actionCollection());
+
     setupGUI();
 
     // Find QDockWidget tab bars and show / hide widget title bars on right click
@@ -526,11 +530,7 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, const QString &
 
     connect(m, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
     connect(m_effectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
-    connect(m_transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
-
-    QMenu *viewMenu = static_cast<QMenu*>(factory()->container("dockwindows", this));
-    const QList<QAction *> viewActions = createPopupMenu()->actions();
-    viewMenu->insertActions(NULL, viewActions);
+    connect(m_transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));    
 
     m_timelineContextMenu = new QMenu(this);
     m_timelineContextClipMenu = new QMenu(this);
@@ -604,6 +604,33 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, const QString &
     actionCollection()->addAssociatedWidget(m_clipMonitor->container());
     actionCollection()->addAssociatedWidget(m_projectMonitor->container());
 
+    QMap <QString, KAction *> viewActions;
+    KAction *showTimeline = new KAction(i18n("Timeline"), this);
+    showTimeline->setCheckable(true);
+    showTimeline->setChecked(true);
+    connect(showTimeline, SIGNAL(triggered(bool)), this, SLOT(slotShowTimeline(bool)));
+    viewActions.insert(showTimeline->text(), showTimeline);
+    
+    QList <QDockWidget *> docks = findChildren<QDockWidget *>();
+    for (int i = 0; i < docks.count(); i++) {
+        QDockWidget* dock = docks.at(i);
+       KAction* dockInformations = new KAction(this);
+       dockInformations->setText(dock->windowTitle());
+       dockInformations->setCheckable(true);
+       dockInformations->setChecked(!dock->isHidden());
+       connect(dockInformations,SIGNAL(toggled(bool)), dock, SLOT(setVisible(bool)));
+       viewActions.insert(dockInformations->text(), dockInformations);
+    }
+
+
+    KMenu *viewMenu = static_cast<KMenu*>(factory()->container("dockwindows", this));
+    //const QList<QAction *> viewActions = createPopupMenu()->actions();
+    QMap<QString, KAction *>::const_iterator i = viewActions.constBegin();
+    while (i != viewActions.constEnd()) {
+       viewMenu->addAction(guiActions->addAction(i.key(), i.value()));
+       ++i;
+    }
+    
     // Populate encoding profiles
     KConfig conf("encodingprofiles.rc", KConfig::FullConfig, "appdata");
     if (KdenliveSettings::proxyparams().isEmpty() || KdenliveSettings::proxyextension().isEmpty()) {
@@ -698,7 +725,7 @@ bool MainWindow::queryClose()
         if (m_activeDocument->url().fileName().isEmpty())
             message = i18n("Save changes to document?");
         else
-            message = i18n("The project <b>\"%1\"</b> has been changed.\nDo you want to save your changes?").arg(m_activeDocument->url().fileName());
+            message = i18n("The project <b>\"%1\"</b> has been changed.\nDo you want to save your changes?"m_activeDocument->url().fileName());
         switch (KMessageBox::warningYesNoCancel(this, message)) {
         case KMessageBox::Yes :
             // save document here. If saving fails, return false;
@@ -1558,12 +1585,6 @@ void MainWindow::setupActions()
     pasteEffects->setData("paste_effects");
     connect(pasteEffects , SIGNAL(triggered()), this, SLOT(slotPasteEffects()));
 
-    QAction *showTimeline = new KAction(i18n("Show Timeline"), this);
-    collection.addAction("show_timeline", showTimeline);
-    showTimeline->setCheckable(true);
-    showTimeline->setChecked(true);
-    connect(showTimeline, SIGNAL(triggered(bool)), this, SLOT(slotShowTimeline(bool)));
-
     QAction *showTitleBar = new KAction(i18n("Show Title Bars"), this);
     collection.addAction("show_titlebars", showTitleBar);
     showTitleBar->setCheckable(true);
@@ -1578,7 +1599,7 @@ void MainWindow::setupActions()
     KStandardAction::saveAs(this,                 SLOT(saveFileAs()),             collection);
     KStandardAction::openNew(this,                SLOT(newFile()),                collection);
     // TODO: make the following connection to slotEditKeys work
-    KStandardAction::keyBindings(this,            SLOT(slotEditKeys()),           collection);
+    //KStandardAction::keyBindings(this,            SLOT(slotEditKeys()),           collection);
     KStandardAction::preferences(this,            SLOT(slotPreferences()),        collection);
     KStandardAction::configureNotifications(this, SLOT(configureNotifications()), collection);
     KStandardAction::copy(this,                   SLOT(slotCopy()),               collection);
@@ -1736,7 +1757,7 @@ void MainWindow::loadLayouts()
                 }
                 for (int j = 0; j < saveActions.count(); j++) {
                     if (saveActions.at(j)->data().toString().endsWith("_" + QString::number(i))) {
-                        saveActions[j]->setText(i18n("Save as %1").arg(layoutName));
+                        saveActions[j]->setText(i18n("Save as %1"layoutName));
                         saveActions[j]->setData(key);
                         break;
                     }
@@ -1809,12 +1830,13 @@ void MainWindow::readOptions()
 
     if (!initialGroup.exists() || upgrade) {
         // this is our first run, show Wizard
-        Wizard *w = new Wizard(upgrade, this);
+        QPointer<Wizard> w = new Wizard(upgrade, this);
         if (w->exec() == QDialog::Accepted && w->isOk()) {
             w->adjustSettings();
             initialGroup.writeEntry("version", version);
             delete w;
         } else {
+            delete w;
             ::exit(1);
         }
     }
@@ -1826,7 +1848,7 @@ void MainWindow::readOptions()
 
 void MainWindow::slotRunWizard()
 {
-    Wizard *w = new Wizard(false, this);
+    QPointer<Wizard> w = new Wizard(false, this);
     if (w->exec() == QDialog::Accepted && w->isOk()) {
         w->adjustSettings();
     }
@@ -1848,12 +1870,16 @@ void MainWindow::newFile(bool showProjectSettings, bool force)
             if (!closeCurrentDocument())
                 return;
     } else {
-        ProjectSettings *w = new ProjectSettings(NULL, QMap <QString, QString> (), QStringList(), projectTracks.x(), projectTracks.y(), KdenliveSettings::defaultprojectfolder(), false, true, this);
-        if (w->exec() != QDialog::Accepted)
+        QPointer<ProjectSettings> w = new ProjectSettings(NULL, QMap <QString, QString> (), QStringList(), projectTracks.x(), projectTracks.y(), KdenliveSettings::defaultprojectfolder(), false, true, this);
+        if (w->exec() != QDialog::Accepted) {
+            delete w;
             return;
+        }
         if (!KdenliveSettings::activatetabs())
-            if (!closeCurrentDocument())
+            if (!closeCurrentDocument()) {
+                delete w;
                 return;
+            }
         if (KdenliveSettings::videothumbnails() != w->enableVideoThumbs())
             slotSwitchVideoThumbs();
         if (KdenliveSettings::audiothumbnails() != w->enableAudioThumbs())
@@ -1919,7 +1945,7 @@ bool MainWindow::closeCurrentDocument(bool saveChanges)
         if (m_activeDocument->url().fileName().isEmpty())
             message = i18n("Save changes to document?");
         else
-            message = i18n("The project <b>\"%1\"</b> has been changed.\nDo you want to save your changes?").arg(m_activeDocument->url().fileName());
+            message = i18n("The project <b>\"%1\"</b> has been changed.\nDo you want to save your changes?"m_activeDocument->url().fileName());
         switch (KMessageBox::warningYesNoCancel(this, message)) {
         case KMessageBox::Yes :
             // save document here. If saving fails, return false;
@@ -2036,7 +2062,7 @@ void MainWindow::openFile(const KUrl &url)
     if (mime.data()->is("application/x-compressed-tar")) {
         // Opening a compressed project file, we need to process it
         kDebug()<<"Opening archive, processing";
-        ArchiveWidget *ar = new ArchiveWidget(url);
+        QPointer<ArchiveWidget> ar = new ArchiveWidget(url);
         if (ar->exec() == QDialog::Accepted) openFile(KUrl(ar->extractedProjectFile()));
         delete ar;
         return;
@@ -2194,8 +2220,9 @@ void MainWindow::parseProfiles(const QString &mltPath)
 
     if (KdenliveSettings::rendererpath().isEmpty()) {
         // Cannot find the MLT melt renderer, ask for location
-        KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(QString(), i18n("Cannot find the melt program required for rendering (part of MLT)"), this);
+        QPointer<KUrlRequesterDialog> getUrl = new KUrlRequesterDialog(QString(), i18n("Cannot find the melt program required for rendering (part of MLT)"), this);
         if (getUrl->exec() == QDialog::Rejected) {
+            delete getUrl;
             ::exit(0);
         }
         KUrl rendererPath = getUrl->selectedUrl();
@@ -2217,9 +2244,10 @@ void MainWindow::parseProfiles(const QString &mltPath)
         }
         if (profilesList.isEmpty()) {
             // Cannot find the MLT profiles, ask for location
-            KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your MLT profiles, please give the path"), this);
+            QPointer<KUrlRequesterDialog> getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your MLT profiles, please give the path"), this);
             getUrl->fileDialog()->setMode(KFile::Directory);
             if (getUrl->exec() == QDialog::Rejected) {
+                delete getUrl;
                 ::exit(0);
             }
             KUrl mltPath = getUrl->selectedUrl();
@@ -3108,7 +3136,7 @@ void MainWindow::slotAddVideoEffect(QAction *result)
     else
             effect = customEffects.getEffectByTag(info.at(0), info.at(1));
     if (!effect.isNull()) slotAddEffect(effect);
-    else m_messageLabel->setMessage(i18n("Cannot find effect %1 / %2").arg(info.at(0)).arg(info.at(1)), ErrorMessage);
+    else m_messageLabel->setMessage(i18n("Cannot find effect %1 / %2", info.at(0), info.at(1)), ErrorMessage);
 }
 
 
@@ -4108,12 +4136,12 @@ void MainWindow::slotPrepareRendering(bool scriptExport, bool zoneOnly, const QS
     // Do save scenelist
     QFile file(playlistPath);
     if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
-        m_messageLabel->setMessage(i18n("Cannot write to file %1").arg(playlistPath), ErrorMessage);
+        m_messageLabel->setMessage(i18n("Cannot write to file %1"playlistPath), ErrorMessage);
         return;
     }
     file.write(playlistContent.toUtf8());
     if (file.error() != QFile::NoError) {
-        m_messageLabel->setMessage(i18n("Cannot write to file %1").arg(playlistPath), ErrorMessage);
+        m_messageLabel->setMessage(i18n("Cannot write to file %1"playlistPath), ErrorMessage);
         file.close();
         return;
     }