]> git.sesse.net Git - kdenlive/blobdiff - src/mainwindow.cpp
Try to fix audio mixing bug ( http://www.kdenlive.org:80/mantis/view.php?id=228 )
[kdenlive] / src / mainwindow.cpp
index 282a7ec16e8fba7b96253e75ab19965388416cf4..387906a16dbcd5d482a6d0b980d4bf95dfed0ecd 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);
@@ -279,9 +285,15 @@ MainWindow::MainWindow(const QString &MltPath, QWidget *parent)
 
     QMenu *transitionsMenu = new QMenu(i18n("Add Transition"), this);
     QStringList effects = transitions.effectNames();
-    foreach(const QString &name, effects) {
-        action = new QAction(name, this);
-        action->setData(name);
+
+    effectsList.clear();
+    for (int ix = 0; ix < transitions.count(); ix++) {
+        effectInfo = transitions.effectIdInfo(ix);
+        effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
+    }
+    foreach(QStringList value, effectsList) {
+        action = new QAction(value.at(0), this);
+        action->setData(value);
         transitionsMenu->addAction(action);
     }
     connect(transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
@@ -315,21 +327,23 @@ MainWindow::MainWindow(const QString &MltPath, QWidget *parent)
     m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
     slotConnectMonitors();
 
-    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();
 }
 
@@ -385,6 +399,7 @@ void MainWindow::slotReloadEffects() {
     m_effectList->reloadEffectList();
 }
 
+#ifndef NO_JOGSHUTTLE
 void MainWindow::activateShuttleDevice() {
     if (m_jogProcess) delete m_jogProcess;
     m_jogProcess = NULL;
@@ -430,6 +445,7 @@ void MainWindow::slotShuttleAction(int code) {
         break;
     }
 }
+#endif /* NO_JOGSHUTTLE */
 
 void MainWindow::configureNotifications() {
     KNotifyConfigWidget::configure(this);
@@ -656,6 +672,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);
@@ -776,39 +793,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)));
 
@@ -828,6 +837,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();
 }
 
@@ -846,17 +857,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() {
-    if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
+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();
@@ -870,6 +887,7 @@ void MainWindow::newFile() {
         connectDocumentInfo(doc);
         connectDocument(trackView, doc);
     } else m_timelineArea->setTabBarHidden(false);
+    m_closeAction->setEnabled(m_timelineArea->count() > 1);
 }
 
 void MainWindow::activateDocument() {
@@ -902,7 +920,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) {
@@ -913,7 +934,8 @@ void MainWindow::closeCurrentDocument() {
 }
 
 void MainWindow::saveFileAs(const QString &outputFileName) {
-    m_projectMonitor->saveSceneList(outputFileName, m_activeDocument->documentInfoXml());
+    QDomDocument currentSceneList = m_projectMonitor->sceneList();
+    m_activeDocument->saveSceneList(outputFileName, currentSceneList);
     m_activeDocument->setUrl(KUrl(outputFileName));
     if (m_activeDocument->m_autosave == NULL) {
         m_activeDocument->m_autosave = new KAutoSaveFile(KUrl(outputFileName), this);
@@ -926,7 +948,7 @@ void MainWindow::saveFileAs(const QString &outputFileName) {
 }
 
 void MainWindow::saveFileAs() {
-    QString outputFile = KFileDialog::getSaveFileName(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)");
+    QString outputFile = KFileDialog::getSaveFileName(KUrl(), "application/x-kdenlive");
     if (QFile::exists(outputFile)) {
         if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return;
     }
@@ -944,7 +966,7 @@ void MainWindow::saveFile() {
 }
 
 void MainWindow::openFile() {
-    KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)\n*.westley|MLT project files (*.westley)");
+    KUrl url = KFileDialog::getOpenUrl(KUrl(), "application/x-kdenlive");
     if (url.isEmpty()) return;
     m_fileOpenRecent->addUrl(url);
     openFile(url);
@@ -953,7 +975,7 @@ 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());
 }
 
@@ -1207,6 +1229,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;
@@ -1223,8 +1246,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)));
@@ -1273,8 +1296,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());
@@ -1349,7 +1372,9 @@ void MainWindow::updateConfiguration() {
     }
     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
+#ifndef NO_JOGSHUTTLE
     activateShuttleDevice();
+#endif /* NO_JOGSHUTTLE */
 
 }
 
@@ -1381,7 +1406,7 @@ void MainWindow::slotSwitchMarkersComments() {
 
 void MainWindow::slotSwitchSnap() {
     KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
-    m_buttonShowMarkers->setChecked(KdenliveSettings::snaptopoints());
+    m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
 }
 
 
@@ -1455,9 +1480,12 @@ void MainWindow::slotAddProjectClip(KUrl url) {
 
 void MainWindow::slotAddTransition(QAction *result) {
     if (!result) return;
-    QDomElement effect = transitions.getEffectByName(result->data().toString());
+    QStringList info = result->data().toStringList();
+    if (info.isEmpty()) return;
+    QDomElement transition = transitions.getEffectByTag(info.at(1), info.at(2));
+    //QDomElement effect = transitions.getEffectByName(result->data().toString());
     if (m_activeTimeline) {
-        m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(effect);
+        m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(transition);
     }
 }
 
@@ -1688,6 +1716,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) {