]> git.sesse.net Git - kdenlive/blobdiff - src/mainwindow.cpp
some work on settings dialog (mlt path) and start of profiles management dialog
[kdenlive] / src / mainwindow.cpp
index c0aff81386d50ece1e120373c579814733fe3c4d..4449df7f08395471e1197ce4e6061d209fd4f27b 100644 (file)
@@ -22,6 +22,8 @@
 #include <QTextStream>
 #include <QTimer>
 #include <QAction>
+#include <QtTest>
+#include <QtCore>
 
 #include <KApplication>
 #include <KAction>
 #include <KRuler>
 #include <KConfigDialog>
 #include <KXMLGUIFactory>
+#include <KStatusBar>
+#include <kstandarddirs.h>
+#include <KUrlRequesterDialog>
 
 #include <mlt++/Mlt.h>
 
 #include "mainwindow.h"
 #include "kdenlivesettings.h"
 #include "ui_configmisc_ui.h"
+#include "ui_configenv_ui.h"
+#include "initeffects.h"
+#include "ui_profiledialog_ui.h"
+
+#define ID_STATUS_MSG 1
+#define ID_EDITMODE_MSG 2
+#define ID_TIMELINE_MSG 3
+#define ID_TIMELINE_POS 4
+#define ID_TIMELINE_FORMAT 5
  
 MainWindow::MainWindow(QWidget *parent)
     : KXmlGuiWindow(parent),
       fileName(QString()), m_activeDocument(NULL), m_commandStack(NULL)
 {
+  parseProfiles();
   m_timelineArea = new KTabWidget(this);
   m_timelineArea->setHoverCloseButton(true);
   m_timelineArea->setTabReorderingEnabled(true);
   connect(m_timelineArea, SIGNAL(currentChanged (int)), this, SLOT(activateDocument()));
 
+  initEffects::parseEffectFiles( &m_audioEffects, &m_videoEffects );
   m_monitorManager = new MonitorManager();
 
   projectListDock = new QDockWidget(i18n("Project Tree"), this);
@@ -62,13 +78,15 @@ MainWindow::MainWindow(QWidget *parent)
 
   effectListDock = new QDockWidget(i18n("Effect List"), this);
   effectListDock->setObjectName("effect_list");
-  effectList = new KListWidget(this);
-  effectListDock->setWidget(effectList);
+  m_effectList = new EffectsListView(&m_audioEffects, &m_videoEffects, &m_customEffects);
+
+  //m_effectList = new KListWidget(this);
+  effectListDock->setWidget(m_effectList);
   addDockWidget(Qt::TopDockWidgetArea, effectListDock);
   
   effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
   effectStackDock->setObjectName("effect_stack");
-  effectStack = new KListWidget(this);
+  effectStack = new EffectStackView(this);
   effectStackDock->setWidget(effectStack);
   addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
   
@@ -78,14 +96,14 @@ MainWindow::MainWindow(QWidget *parent)
   transitionConfigDock->setWidget(transitionConfig);
   addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
 
-  Mlt::Factory::init(NULL);
 
   clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
   clipMonitorDock->setObjectName("clip_monitor");
   m_clipMonitor = new Monitor("clip", m_monitorManager, this);
   clipMonitorDock->setWidget(m_clipMonitor);
   addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
-  
+  //m_clipMonitor->stop();
+
   projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
   projectMonitorDock->setObjectName("project_monitor");
   m_projectMonitor = new Monitor("project", m_monitorManager, this);
@@ -114,14 +132,22 @@ MainWindow::MainWindow(QWidget *parent)
 
   tabifyDockWidget (clipMonitorDock, projectMonitorDock);
   setCentralWidget(m_timelineArea);
+
+  m_timecodeFormat = new KComboBox(this);
+  m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
+  m_timecodeFormat->addItem(i18n("Frames"));
+  statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
+  statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat); 
+
   setupGUI(Default, "kdenliveui.rc");
 
   connect(projectMonitorDock, SIGNAL(visibilityChanged (bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
   connect(clipMonitorDock, SIGNAL(visibilityChanged (bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
   connect(m_monitorManager, SIGNAL(connectMonitors ()), this, SLOT(slotConnectMonitors()));
   connect(m_monitorManager, SIGNAL(raiseClipMonitor (bool)), this, SLOT(slotRaiseMonitor(bool)));
+  connect(m_effectList, SIGNAL(addEffect(int, const QString&)), this, SLOT(slotAddEffect(int, const QString &)));
   m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
-
+       
   setAutoSaveSettings();
   newFile();
 }
@@ -141,6 +167,20 @@ bool MainWindow::queryClose()
   }
 }
 
+void MainWindow::slotAddEffect(int effectType, const QString &effectName)
+{
+  if (!m_activeDocument) return;
+  QMap <QString, QString> filter;
+  if (effectType == 0)
+    filter = m_videoEffects.effect(effectName);
+  else if (effectType == 1)
+    filter = m_audioEffects.effect(effectName);
+  else 
+    filter = m_customEffects.effect(effectName);
+  TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
+  currentTimeLine->projectView()->slotAddEffect(filter);
+}
+
 void MainWindow::slotRaiseMonitor(bool clipMonitor)
 {
   if (clipMonitor) clipMonitorDock->raise();
@@ -179,6 +219,12 @@ void MainWindow::setupActions()
   actionCollection()->addAction("clear", clearAction);
   /*connect(clearAction, SIGNAL(triggered(bool)),
           textArea, SLOT(clear()));*/
+
+  KAction* profilesAction = new KAction(this);
+  profilesAction->setText(i18n("Manage Profiles"));
+  profilesAction->setIcon(KIcon("document-new"));
+  actionCollection()->addAction("manage_profiles", profilesAction);
+  connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
  
   KStandardAction::quit(kapp, SLOT(quit()),
                         actionCollection());
@@ -198,6 +244,9 @@ void MainWindow::setupActions()
   KStandardAction::openNew(this, SLOT(newFile()),
                         actionCollection());
 
+  KStandardAction::preferences(this, SLOT(slotPreferences()),
+                        actionCollection());
+
   /*KStandardAction::undo(this, SLOT(undo()),
                         actionCollection());
 
@@ -287,14 +336,114 @@ void MainWindow::openFile(const KUrl &url) //new
   //connectDocument(trackView, doc);
 }
 
+
+void MainWindow::parseProfiles()
+{
+       //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
+       if (KdenliveSettings::mltpath().isEmpty()) {
+           KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
+       }
+       if (KdenliveSettings::rendererpath().isEmpty())
+       {
+           KdenliveSettings::setRendererpath(KStandardDirs::findExe("inigo"));
+       }
+       QStringList profilesFilter;
+       profilesFilter<<"*";
+       QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
+
+       if (profilesList.isEmpty()) {
+           // Cannot find MLT path, try finding inigo
+           QString profilePath = KdenliveSettings::rendererpath();
+           if (!profilePath.isEmpty()) {
+               profilePath = profilePath.section('/', 0, -3);
+               KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
+               QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
+           }
+
+           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);
+               getUrl->fileDialog()->setMode(KFile::Directory);
+               getUrl->exec();
+               KUrl mltPath = getUrl->selectedUrl ();
+               delete getUrl;
+               if (mltPath.isEmpty()) exit(1);
+               KdenliveSettings::setMltpath(mltPath.path());
+               QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
+           }
+       }
+
+       if (KdenliveSettings::rendererpath().isEmpty()) {
+               // Cannot find the MLT inigo renderer, ask for location
+               KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
+               getUrl->exec();
+               KUrl rendererPath = getUrl->selectedUrl();
+               delete getUrl;
+               if (rendererPath.isEmpty()) exit(1);
+               KdenliveSettings::setRendererpath(rendererPath.path());
+       }
+
+       kDebug()<<"RESULTING MLT PATH: "<<KdenliveSettings::mltpath();
+
+       // Parse MLT profiles to build a list of available video formats
+       if (profilesList.isEmpty()) parseProfiles();
+/*
+       uint i = 0;
+       for (; i < profilesList.count(); i++) { 
+           KConfig confFile(profilePath + *profilesList.at(i), true);
+           QString name = confFile.readEntry("description");
+           int width = confFile.readNumEntry("width");
+           int height = confFile.readNumEntry("height");
+           int aspect_num = confFile.readNumEntry("sample_aspect_num");
+           int aspect_den = confFile.readNumEntry("sample_aspect_den");
+           int display_num = confFile.readNumEntry("display_aspect_num");
+           int display_den = confFile.readNumEntry("display_aspect_den");
+           int fps_num = confFile.readNumEntry("frame_rate_num");
+           int fps_den = confFile.readNumEntry("frame_rate_den");
+           int progressive = confFile.readNumEntry("progressive");
+           if (!name.isEmpty()) m_projectTemplates[name] = formatTemplate(width, height, fps_num, fps_den, aspect_num, aspect_den, display_num, display_den, progressive, *profilesList.at(i));
+       }*/
+    }
+
+
+void MainWindow::slotEditProfiles()
+{
+  QDialog *w = new QDialog;
+  Ui::ProfilesDialog_UI profilesDialog;
+  profilesDialog.setupUi(w);
+  w->exec();
+}
+
+
+void MainWindow::slotUpdateMousePosition(int pos)
+{
+  if (m_activeDocument)
+    switch(m_timecodeFormat->currentIndex()) {
+      case 0:
+       statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
+       break;
+    default:
+      statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
+    }
+}
+
 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) //changed
 {
   //m_projectMonitor->stop();
+  kDebug()<<"///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
   if (m_activeDocument) {
     if (m_activeDocument == doc) return;
     m_activeDocument->setProducers(m_projectList->producersList());
     m_activeDocument->setRenderer(NULL);
   }
+  connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
+  connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
+  connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
+  connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
+  connect(doc, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
+  connect(doc, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
+  connect(doc, SIGNAL(deletTimelineClip(int)), trackView, SLOT(slotDeleteClip(int)));
+       connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
   m_projectList->setDocument(doc);
   m_monitorManager->setTimecode(doc->timecode());
   doc->setRenderer(m_projectMonitor->render);
@@ -323,7 +472,6 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) //chang
   m_activeDocument = doc;
 }
 
-
 void MainWindow::slotPreferences()
 {
   //An instance of your dialog could be already created and could be
@@ -340,9 +488,17 @@ void MainWindow::slotPreferences()
   QWidget *page1 = new QWidget;
   Ui::ConfigMisc_UI* confWdg = new Ui::ConfigMisc_UI( );
   confWdg->setupUi(page1);
-
   dialog->addPage( page1, i18n("Misc"), "misc" );
 
+  QWidget *page2 = new QWidget;
+  Ui::ConfigEnv_UI* confWdg2 = new Ui::ConfigEnv_UI( );
+  confWdg2->setupUi(page2);
+  confWdg2->kcfg_mltpath->setMode(KFile::Directory);
+
+  //WARNING: the 2 lines below should not be necessary, but does not work without it...
+  confWdg2->kcfg_mltpath->setPath(KdenliveSettings::mltpath());
+  confWdg2->kcfg_rendererpath->setPath(KdenliveSettings::rendererpath());
+  dialog->addPage( page2, i18n("Environnment"), "env" );
   //User edited the configuration - update your local copies of the
   //configuration data
   connect( dialog, SIGNAL(settingsChanged()), this, SLOT(updateConfiguration()) );