]> git.sesse.net Git - kdenlive/blobdiff - src/mainwindow.cpp
Fix issue 254: starting up with project supplied on CLI should not result in 'Untitle...
[kdenlive] / src / mainwindow.cpp
index 2231b2cc759c68d5694486bdcc25b133ecbb6cd8..d214cd2f10d6b4dc6a78a148286519ad8c0526fc 100644 (file)
@@ -74,7 +74,9 @@
 #include "transitionsettings.h"
 #include "renderwidget.h"
 #include "renderer.h"
+#ifndef NO_JOGSHUTTLE
 #include "jogshuttle.h"
+#endif /* NO_JOGSHUTTLE */
 #include "clipproperties.h"
 #include "wizard.h"
 #include "editclipcommand.h"
@@ -96,9 +98,13 @@ EffectsList MainWindow::audioEffects;
 EffectsList MainWindow::customEffects;
 EffectsList MainWindow::transitions;
 
-MainWindow::MainWindow(const QString &MltPath, QWidget *parent)
+MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, QWidget *parent)
         : KXmlGuiWindow(parent),
-        m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL), m_jogProcess(NULL), m_findActivated(false), m_initialized(false) {
+        m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL),
+#ifndef NO_JOGSHUTTLE
+        m_jogProcess(NULL),
+#endif /* NO_JOGSHUTTLE */
+        m_findActivated(false), m_initialized(false) {
     setlocale(LC_NUMERIC, "POSIX");
     setFont(KGlobalSettings::toolBarFont());
     parseProfiles(MltPath);
@@ -202,8 +208,11 @@ MainWindow::MainWindow(const QString &MltPath, QWidget *parent)
     tabifyDockWidget(clipMonitorDock, recMonitorDock);
     setCentralWidget(m_timelineArea);
 
-    setupGUI(Default, NULL /*"kdenliveui.rc"*/);
-    kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
+    setupGUI();
+    //kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
+
+    m_projectMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)));
+    m_clipMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)));
 
     // build effects menus
     QAction *action;
@@ -312,23 +321,23 @@ MainWindow::MainWindow(const QString &MltPath, QWidget *parent)
     m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
     slotConnectMonitors();
 
-    setAutoSaveSettings();
-
-    if (KdenliveSettings::openlastproject()) {
-        openLastFile();
+    // Open or create a file.  Command line argument passed in Url has
+    // precedence, then "openlastproject", then just a plain empty file.
+    // If opening Url fails, openlastproject will _not_ be used.
+    if (!Url.isEmpty()) {
+        openFile(Url);
     } else {
-        /*QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::allStaleFiles();
-        if (!staleFiles.isEmpty()) {
-            if (KMessageBox::questionYesNo(this, i18n("Auto-saved files exist. Do you want to recover them now?"), i18n("File Recovery"), KGuiItem(i18n("Recover")), KGuiItem(i18n("Don't recover"))) == KMessageBox::Yes) {
-         recoverFiles(staleFiles);
-            }
-            else newFile();
+        if (KdenliveSettings::openlastproject()) {
+            openLastFile();
         }
-        else*/
-        newFile();
+    }
+    if (m_timelineArea->count() == 0) {
+        newFile(false);
     }
 
+#ifndef NO_JOGSHUTTLE
     activateShuttleDevice();
+#endif /* NO_JOGSHUTTLE */
     projectListDock->raise();
 }
 
@@ -384,6 +393,7 @@ void MainWindow::slotReloadEffects() {
     m_effectList->reloadEffectList();
 }
 
+#ifndef NO_JOGSHUTTLE
 void MainWindow::activateShuttleDevice() {
     if (m_jogProcess) delete m_jogProcess;
     m_jogProcess = NULL;
@@ -429,6 +439,7 @@ void MainWindow::slotShuttleAction(int code) {
         break;
     }
 }
+#endif /* NO_JOGSHUTTLE */
 
 void MainWindow::configureNotifications() {
     KNotifyConfigWidget::configure(this);
@@ -445,7 +456,7 @@ void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
         return;
     }
     TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
-    currentTimeLine->projectView()->slotAddEffect(effect, pos, track);
+    currentTimeLine->projectView()->slotAddEffect(effect.cloneNode().toElement(), pos, track);
 }
 
 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
@@ -515,11 +526,13 @@ void MainWindow::setupActions() {
 
     QString style1 = "QToolButton {background-color: rgba(230, 230, 230, 220); border-style: inset; border:1px solid #999999;border-radius: 3px;margin: 0px 3px;padding: 0px;} QToolButton:checked { background-color: rgba(224, 224, 0, 100); border-style: inset; border:1px solid #cc6666;border-radius: 3px;}";
 
-    m_buttonSelectTool = toolbar->addAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"));
+    m_buttonSelectTool = new KAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"), this);
+    toolbar->addAction(m_buttonSelectTool);
     m_buttonSelectTool->setCheckable(true);
     m_buttonSelectTool->setChecked(true);
 
-    m_buttonRazorTool = toolbar->addAction(KIcon("edit-cut"), i18n("Razor tool"));
+    m_buttonRazorTool = new KAction(KIcon("edit-cut"), i18n("Razor tool"), this);
+    toolbar->addAction(m_buttonRazorTool);
     m_buttonRazorTool->setCheckable(true);
     m_buttonRazorTool->setChecked(false);
 
@@ -541,7 +554,8 @@ void MainWindow::setupActions() {
     connect(m_toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
 
     toolbar->addSeparator();
-    m_buttonFitZoom = toolbar->addAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"));
+    m_buttonFitZoom = new KAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"), this);
+    toolbar->addAction(m_buttonFitZoom);
     m_buttonFitZoom->setCheckable(false);
     connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
 
@@ -569,22 +583,26 @@ void MainWindow::setupActions() {
 
     toolbar->addWidget(m_zoomSlider);
 
-    m_buttonVideoThumbs = toolbar->addAction(KIcon("kdenlive-show-videothumb"), i18n("Show video thumbnails"));
+    m_buttonVideoThumbs = new KAction(KIcon("kdenlive-show-videothumb"), i18n("Show video thumbnails"), this);
+    toolbar->addAction(m_buttonVideoThumbs);
     m_buttonVideoThumbs->setCheckable(true);
     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
     connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
 
-    m_buttonAudioThumbs = toolbar->addAction(KIcon("kdenlive-show-audiothumb"), i18n("Show audio thumbnails"));
+    m_buttonAudioThumbs = new KAction(KIcon("kdenlive-show-audiothumb"), i18n("Show audio thumbnails"), this);
+    toolbar->addAction(m_buttonAudioThumbs);
     m_buttonAudioThumbs->setCheckable(true);
     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
     connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
 
-    m_buttonShowMarkers = toolbar->addAction(KIcon("kdenlive-show-markers"), i18n("Show markers comments"));
+    m_buttonShowMarkers = new KAction(KIcon("kdenlive-show-markers"), i18n("Show markers comments"), this);
+    toolbar->addAction(m_buttonShowMarkers);
     m_buttonShowMarkers->setCheckable(true);
     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
     connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
 
-    m_buttonSnap = toolbar->addAction(KIcon("kdenlive-snap"), i18n("Snap"));
+    m_buttonSnap = new KAction(KIcon("kdenlive-snap"), i18n("Snap"), this);
+    toolbar->addAction(m_buttonSnap);
     m_buttonSnap->setCheckable(true);
     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
     connect(m_buttonSnap, SIGNAL(triggered()), this, SLOT(slotSwitchSnap()));
@@ -648,6 +666,7 @@ void MainWindow::setupActions() {
 
     KAction* projectRender = new KAction(KIcon("media-record"), i18n("Render"), this);
     collection->addAction("project_render", projectRender);
+    projectRender->setShortcut(Qt::CTRL + Qt::Key_Return);
     connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
 
     KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
@@ -698,12 +717,12 @@ void MainWindow::setupActions() {
     collection->addAction("seek_clip_end", clipEnd);
     connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
 
-    KAction* projectStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Project Start"), this);
+    KAction* projectStart = new KAction(KIcon("go-first"), i18n("Go to Project Start"), this);
     projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
     collection->addAction("seek_start", projectStart);
     connect(projectStart, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotStart()));
 
-    KAction* projectEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Project End"), this);
+    KAction* projectEnd = new KAction(KIcon("go-last"), i18n("Go to Project End"), this);
     projectEnd->setShortcut(Qt::CTRL + Qt::Key_End);
     collection->addAction("seek_end", projectEnd);
     connect(projectEnd, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotEnd()));
@@ -732,15 +751,15 @@ void MainWindow::setupActions() {
     collection->addAction("cut_timeline_clip", cutTimelineClip);
     connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
 
-    KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker to Clip"), this);
+    KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker"), this);
     collection->addAction("add_clip_marker", addClipMarker);
     connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
 
-    KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker from Clip"), this);
+    KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker"), this);
     collection->addAction("delete_clip_marker", deleteClipMarker);
     connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
 
-    KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers from Clip"), this);
+    KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers"), this);
     collection->addAction("delete_all_clip_markers", deleteAllClipMarkers);
     connect(deleteAllClipMarkers, SIGNAL(triggered(bool)), this, SLOT(slotDeleteAllClipMarkers()));
 
@@ -768,39 +787,31 @@ void MainWindow::setupActions() {
     collection->addAction("paste_effects", pasteEffects);
     connect(pasteEffects , SIGNAL(triggered()), this, SLOT(slotPasteEffects()));
 
-    KStandardAction::quit(this, SLOT(queryQuit()),
-                          collection);
+    m_closeAction = KStandardAction::close(this, SLOT(closeCurrentDocument()), collection);
 
-    KStandardAction::open(this, SLOT(openFile()),
-                          collection);
+    KStandardAction::quit(this, SLOT(queryQuit()), collection);
 
-    m_saveAction = KStandardAction::save(this, SLOT(saveFile()),
-                                         collection);
+    KStandardAction::open(this, SLOT(openFile()), collection);
 
-    KStandardAction::saveAs(this, SLOT(saveFileAs()),
-                            collection);
+    m_saveAction = KStandardAction::save(this, SLOT(saveFile()), collection);
 
-    KStandardAction::openNew(this, SLOT(newFile()),
-                             collection);
+    KStandardAction::saveAs(this, SLOT(saveFileAs()), collection);
 
-    KStandardAction::preferences(this, SLOT(slotPreferences()),
-                                 collection);
+    KStandardAction::openNew(this, SLOT(newFile()), collection);
 
-    KStandardAction::configureNotifications(this , SLOT(configureNotifications()) , collection);
+    KStandardAction::preferences(this, SLOT(slotPreferences()), collection);
 
-    KStandardAction::copy(this, SLOT(slotCopy()),
-                          collection);
+    KStandardAction::configureNotifications(this , SLOT(configureNotifications()), collection);
 
-    KStandardAction::paste(this, SLOT(slotPaste()),
-                           collection);
+    KStandardAction::copy(this, SLOT(slotCopy()), collection);
 
-    KAction *undo = KStandardAction::undo(m_commandStack, SLOT(undo()),
-                                          collection);
+    KStandardAction::paste(this, SLOT(slotPaste()), collection);
+
+    KAction *undo = KStandardAction::undo(m_commandStack, SLOT(undo()), collection);
     undo->setEnabled(false);
     connect(m_commandStack, SIGNAL(canUndoChanged(bool)), undo, SLOT(setEnabled(bool)));
 
-    KAction *redo = KStandardAction::redo(m_commandStack, SLOT(redo()),
-                                          collection);
+    KAction *redo = KStandardAction::redo(m_commandStack, SLOT(redo()), collection);
     redo->setEnabled(false);
     connect(m_commandStack, SIGNAL(canRedoChanged(bool)), redo, SLOT(setEnabled(bool)));
 
@@ -820,6 +831,8 @@ void MainWindow::saveOptions() {
     KdenliveSettings::self()->writeConfig();
     KSharedConfigPtr config = KGlobal::config();
     m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
+    KConfigGroup treecolumns(config, "Project Tree");
+    treecolumns.writeEntry("columns", m_projectList->headerInfo());
     config->sync();
 }
 
@@ -838,16 +851,23 @@ void MainWindow::readOptions() {
             ::exit(1);
         }
     }
+    KConfigGroup treecolumns(config, "Project Tree");
+    const QByteArray state = treecolumns.readEntry("columns", QByteArray());
+    if (!state.isEmpty())
+        m_projectList->setHeaderInfo(state);
 }
 
-void MainWindow::newFile() {
+void MainWindow::newFile(bool showProjectSettings) {
     QString profileName;
     KUrl projectFolder;
     QPoint projectTracks(3, 2);
-    if (m_timelineArea->count() == 0) profileName = KdenliveSettings::default_profile();
-    else {
+    if (!showProjectSettings && m_timelineArea->count() == 0) {
+        if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
+        profileName = KdenliveSettings::default_profile();
+    } else {
         ProjectSettings *w = new ProjectSettings;
         if (w->exec() != QDialog::Accepted) return;
+        if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
         profileName = w->selectedProfile();
         projectFolder = w->selectedFolder();
         projectTracks = w->tracks();
@@ -861,6 +881,7 @@ void MainWindow::newFile() {
         connectDocumentInfo(doc);
         connectDocument(trackView, doc);
     } else m_timelineArea->setTabBarHidden(false);
+    m_closeAction->setEnabled(m_timelineArea->count() > 1);
 }
 
 void MainWindow::activateDocument() {
@@ -873,6 +894,7 @@ void MainWindow::activateDocument() {
 
 void MainWindow::closeCurrentDocument() {
     QWidget *w = m_timelineArea->currentWidget();
+    if (!w) return;
     // closing current document
     int ix = m_timelineArea->currentIndex() + 1;
     if (ix == m_timelineArea->count()) ix = 0;
@@ -892,7 +914,10 @@ void MainWindow::closeCurrentDocument() {
         }
     }
     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
-    if (m_timelineArea->count() == 1) m_timelineArea->setTabBarHidden(true);
+    if (m_timelineArea->count() == 1) {
+        m_timelineArea->setTabBarHidden(true);
+        m_closeAction->setEnabled(false);
+    }
     delete docToClose;
     delete w;
     if (m_timelineArea->count() == 0) {
@@ -943,11 +968,28 @@ void MainWindow::openFile() {
 void MainWindow::openLastFile() {
     KSharedConfigPtr config = KGlobal::config();
     KUrl::List urls = m_fileOpenRecent->urls();
-    if (urls.isEmpty()) newFile();
+    if (urls.isEmpty()) newFile(false);
     else openFile(urls.last());
 }
 
 void MainWindow::openFile(const KUrl &url) {
+    // Check if the document is already opened
+    const int ct = m_timelineArea->count();
+    bool isOpened = false;
+    int i;
+    for (i = 0; i < ct; i++) {
+        TrackView *tab = (TrackView *) m_timelineArea->widget(i);
+        KdenliveDoc *doc = tab->document();
+        if (doc->url() == url) {
+            isOpened = true;
+            break;
+        }
+    }
+    if (isOpened) {
+        m_timelineArea->setCurrentIndex(i);
+        return;
+    }
+
     // Check for backup file
     QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::staleFiles(url);
     if (!staleFiles.isEmpty()) {
@@ -1180,6 +1222,7 @@ void MainWindow::connectDocumentInfo(KdenliveDoc *doc) {
 
 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
     //m_projectMonitor->stop();
+    m_closeAction->setEnabled(m_timelineArea->count() > 1);
     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
     if (m_activeDocument) {
         if (m_activeDocument == doc) return;
@@ -1196,8 +1239,8 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //cha
             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
             disconnect(m_activeDocument, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
             disconnect(m_activeDocument, SIGNAL(deleteTimelineClip(const QString &)), m_activeTimeline, SLOT(slotDeleteClip(const QString &)));
-            disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
-            disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
+            disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
+            disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
             disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
@@ -1246,8 +1289,8 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //cha
     connect(doc, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
 
 
-    connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
-    connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
+    connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
+    connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
     connect(trackView, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
     connect(trackView, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
     m_zoomSlider->setValue(doc->zoom());
@@ -1279,7 +1322,7 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //cha
     m_commandStack->setActiveStack(doc->commandStack());
     KdenliveSettings::setProject_display_ratio(doc->dar());
     m_projectList->updateAllClips();
-    doc->clipManager()->checkAudioThumbs();
+    //doc->clipManager()->checkAudioThumbs();
 
     //m_overView->setScene(trackView->projectScene());
     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
@@ -1322,7 +1365,9 @@ void MainWindow::updateConfiguration() {
     }
     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
+#ifndef NO_JOGSHUTTLE
     activateShuttleDevice();
+#endif /* NO_JOGSHUTTLE */
 
 }
 
@@ -1354,7 +1399,7 @@ void MainWindow::slotSwitchMarkersComments() {
 
 void MainWindow::slotSwitchSnap() {
     KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
-    m_buttonShowMarkers->setChecked(KdenliveSettings::snaptopoints());
+    m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
 }
 
 
@@ -1661,6 +1706,17 @@ void MainWindow::keyPressEvent(QKeyEvent *ke) {
     } else KXmlGuiWindow::keyPressEvent(ke);
 }
 
+
+/** Gets called when the window gets hidden */
+void MainWindow::hideEvent(QHideEvent *event) {
+    // kDebug() << "I was hidden";
+    // issue http://www.kdenlive.org/mantis/view.php?id=231
+    if (this->isMinimized()) {
+        // kDebug() << "I am minimized";
+        if (m_monitorManager) m_monitorManager->stopActiveMonitor();
+    }
+}
+
 bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
     if (m_findActivated) {
         if (event->type() == QEvent::ShortcutOverride) {