1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
22 #include <QTextStream>
28 #include <KApplication>
32 #include <KActionCollection>
33 #include <KStandardAction>
34 #include <KFileDialog>
35 #include <KMessageBox>
37 #include <KIO/NetAccess>
40 #include <KConfigDialog>
41 #include <KXMLGUIFactory>
43 #include <kstandarddirs.h>
44 #include <KUrlRequesterDialog>
45 #include <KTemporaryFile>
46 #include <KActionMenu>
48 #include <ktogglefullscreenaction.h>
50 #include <mlt++/Mlt.h>
52 #include "mainwindow.h"
53 #include "kdenlivesettings.h"
54 #include "kdenlivesettingsdialog.h"
55 #include "initeffects.h"
56 #include "profilesdialog.h"
57 #include "projectsettings.h"
59 #include "renderjob.h"
60 #include "clipmanager.h"
61 #include "projectlist.h"
63 #include "recmonitor.h"
64 #include "monitormanager.h"
65 #include "kdenlivedoc.h"
66 #include "trackview.h"
67 #include "customtrackview.h"
68 #include "effectslistview.h"
69 #include "effectstackview.h"
70 #include "transitionsettings.h"
71 #include "renderwidget.h"
72 #include "jogshuttle.h"
74 #define ID_STATUS_MSG 1
75 #define ID_EDITMODE_MSG 2
76 #define ID_TIMELINE_MSG 3
77 #define ID_TIMELINE_BUTTONS 5
78 #define ID_TIMELINE_POS 6
79 #define ID_TIMELINE_FORMAT 7
81 MainWindow::MainWindow(QWidget *parent)
82 : KXmlGuiWindow(parent),
83 m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL), m_jogProcess(NULL) {
86 m_commandStack = new QUndoGroup;
87 m_timelineArea = new KTabWidget(this);
88 m_timelineArea->setTabReorderingEnabled(true);
89 m_timelineArea->setTabBarHidden(true);
91 QToolButton *closeTabButton = new QToolButton;
92 connect(closeTabButton, SIGNAL(clicked()), this, SLOT(slotRemoveTab()));
93 closeTabButton->setIcon(KIcon("tab-close"));
94 closeTabButton->adjustSize();
95 closeTabButton->setToolTip(i18n("Close the current tab"));
96 m_timelineArea->setCornerWidget(closeTabButton);
97 connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
99 initEffects::parseEffectFiles(&m_audioEffects, &m_videoEffects, &m_transitions);
100 m_monitorManager = new MonitorManager();
102 projectListDock = new QDockWidget(i18n("Project Tree"), this);
103 projectListDock->setObjectName("project_tree");
104 m_projectList = new ProjectList(this);
105 projectListDock->setWidget(m_projectList);
106 addDockWidget(Qt::TopDockWidgetArea, projectListDock);
108 effectListDock = new QDockWidget(i18n("Effect List"), this);
109 effectListDock->setObjectName("effect_list");
110 m_effectList = new EffectsListView(&m_audioEffects, &m_videoEffects, &m_customEffects);
112 //m_effectList = new KListWidget(this);
113 effectListDock->setWidget(m_effectList);
114 addDockWidget(Qt::TopDockWidgetArea, effectListDock);
116 effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
117 effectStackDock->setObjectName("effect_stack");
118 effectStack = new EffectStackView(&m_audioEffects, &m_videoEffects, &m_customEffects, this);
119 effectStackDock->setWidget(effectStack);
120 addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
122 transitionConfigDock = new QDockWidget(i18n("Transition"), this);
123 transitionConfigDock->setObjectName("transition");
124 transitionConfig = new TransitionSettings(&m_transitions, this);
125 transitionConfigDock->setWidget(transitionConfig);
126 addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
129 clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
130 clipMonitorDock->setObjectName("clip_monitor");
131 m_clipMonitor = new Monitor("clip", m_monitorManager, this);
132 clipMonitorDock->setWidget(m_clipMonitor);
133 addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
134 //m_clipMonitor->stop();
136 projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
137 projectMonitorDock->setObjectName("project_monitor");
138 m_projectMonitor = new Monitor("project", m_monitorManager, this);
139 projectMonitorDock->setWidget(m_projectMonitor);
140 addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
142 recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
143 recMonitorDock->setObjectName("record_monitor");
144 m_recMonitor = new RecMonitor("record", this);
145 recMonitorDock->setWidget(m_recMonitor);
146 addDockWidget(Qt::TopDockWidgetArea, recMonitorDock);
148 connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
150 undoViewDock = new QDockWidget(i18n("Undo History"), this);
151 undoViewDock->setObjectName("undo_history");
152 m_undoView = new QUndoView(this);
153 m_undoView->setCleanIcon(KIcon("edit-clear"));
154 m_undoView->setEmptyLabel(i18n("Clean"));
155 undoViewDock->setWidget(m_undoView);
156 m_undoView->setGroup(m_commandStack);
157 addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
159 overviewDock = new QDockWidget(i18n("Project Overview"), this);
160 overviewDock->setObjectName("project_overview");
161 m_overView = new CustomTrackView(NULL, NULL, this);
162 overviewDock->setWidget(m_overView);
163 addDockWidget(Qt::TopDockWidgetArea, overviewDock);
166 tabifyDockWidget(projectListDock, effectListDock);
167 tabifyDockWidget(projectListDock, effectStackDock);
168 tabifyDockWidget(projectListDock, transitionConfigDock);
169 tabifyDockWidget(projectListDock, undoViewDock);
170 projectListDock->raise();
172 tabifyDockWidget(clipMonitorDock, projectMonitorDock);
173 setCentralWidget(m_timelineArea);
175 m_timecodeFormat = new KComboBox(this);
176 m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
177 m_timecodeFormat->addItem(i18n("Frames"));
179 statusProgressBar = new QProgressBar(this);
180 statusProgressBar->setMinimum(0);
181 statusProgressBar->setMaximum(100);
182 statusProgressBar->setMaximumWidth(150);
183 statusProgressBar->setVisible(false);
184 statusLabel = new QLabel(this);
186 QWidget *w = new QWidget;
187 timeline_buttons_ui.setupUi(w);
188 timeline_buttons_ui.buttonVideo->setDown(KdenliveSettings::videothumbnails());
189 timeline_buttons_ui.buttonAudio->setDown(KdenliveSettings::audiothumbnails());
190 connect(timeline_buttons_ui.buttonVideo, SIGNAL(clicked()), this, SLOT(slotSwitchVideoThumbs()));
191 connect(timeline_buttons_ui.buttonAudio, SIGNAL(clicked()), this, SLOT(slotSwitchAudioThumbs()));
192 connect(timeline_buttons_ui.buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotFitZoom()));
194 statusBar()->insertPermanentWidget(0, statusProgressBar, 1);
195 statusBar()->insertPermanentWidget(1, statusLabel, 1);
196 statusBar()->insertPermanentWidget(ID_TIMELINE_BUTTONS, w);
197 statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
198 statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
199 statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
201 timeline_buttons_ui.buttonVideo->setIcon(KIcon("video-mpeg"));
202 timeline_buttons_ui.buttonVideo->setToolTip(i18n("Show video thumbnails"));
203 timeline_buttons_ui.buttonAudio->setIcon(KIcon("audio-mpeg"));
204 timeline_buttons_ui.buttonAudio->setToolTip(i18n("Show audio thumbnails"));
205 timeline_buttons_ui.buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
206 timeline_buttons_ui.buttonFitZoom->setToolTip(i18n("Fit zoom to project"));
208 setupGUI(Default, NULL /*"kdenliveui.rc"*/);
209 kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
211 // build effects menus
213 QMenu *videoEffectsMenu = (QMenu*)(factory()->container("video_effects_menu", this));
214 QStringList effects = m_videoEffects.effectNames();
215 foreach(QString name, effects) {
216 action = new QAction(name, this);
217 action->setData(name);
218 videoEffectsMenu->addAction(action);
220 QMenu *audioEffectsMenu = (QMenu*)(factory()->container("audio_effects_menu", this));
221 effects = m_audioEffects.effectNames();
222 foreach(QString name, effects) {
223 action = new QAction(name, this);
224 action->setData(name);
225 audioEffectsMenu->addAction(action);
227 QMenu *customEffectsMenu = (QMenu*)(factory()->container("custom_effects_menu", this));
228 effects = m_customEffects.effectNames();
229 foreach(QString name, effects) {
230 action = new QAction(name, this);
231 action->setData(name);
232 customEffectsMenu->addAction(action);
235 connect(videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
236 connect(audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
237 connect(customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
239 m_timelineContextMenu = new QMenu(this);
240 m_timelineContextClipMenu = new QMenu(this);
241 m_timelineContextTransitionMenu = new QMenu(this);
243 action = actionCollection()->action("delete_timeline_clip");
244 m_timelineContextClipMenu->addAction(action);
245 m_timelineContextClipMenu->addMenu(videoEffectsMenu);
246 m_timelineContextClipMenu->addMenu(audioEffectsMenu);
247 m_timelineContextClipMenu->addMenu(customEffectsMenu);
249 connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
250 connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
251 //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
252 connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
253 connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
254 m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
255 slotConnectMonitors();
257 setAutoSaveSettings();
260 activateShuttleDevice();
264 bool MainWindow::queryClose() {
266 switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
267 case KMessageBox::Yes :
268 // save document here. If saving fails, return false;
270 case KMessageBox::No :
277 void MainWindow::activateShuttleDevice() {
278 if (m_jogProcess) delete m_jogProcess;
280 if (KdenliveSettings::enableshuttle() == false) return;
281 m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
282 connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
283 connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
284 connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
285 connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
286 connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
287 connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
290 void MainWindow::slotShuttleButton(int code) {
293 slotShuttleAction(KdenliveSettings::shuttle1());
296 slotShuttleAction(KdenliveSettings::shuttle2());
299 slotShuttleAction(KdenliveSettings::shuttle3());
302 slotShuttleAction(KdenliveSettings::shuttle4());
305 slotShuttleAction(KdenliveSettings::shuttle5());
310 void MainWindow::slotShuttleAction(int code) {
315 m_monitorManager->slotPlay();
318 m_monitorManager->slotPlay();
323 void MainWindow::slotFullScreen() {
324 //KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
327 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
328 if (!m_activeDocument) return;
329 if (effect.isNull()) {
330 kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
333 TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
334 currentTimeLine->projectView()->slotAddEffect(effect, pos, track);
337 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
338 if (clipMonitor) clipMonitorDock->raise();
339 else projectMonitorDock->raise();
342 void MainWindow::slotSetClipDuration(int id, int duration) {
343 if (!m_activeDocument) return;
344 m_activeDocument->setProducerDuration(id, duration);
347 void MainWindow::slotConnectMonitors() {
349 m_projectList->setRenderer(m_clipMonitor->render);
350 connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
351 connect(m_projectList, SIGNAL(receivedClipDuration(int, int)), this, SLOT(slotSetClipDuration(int, int)));
352 connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
353 connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int)));
354 connect(m_clipMonitor->render, SIGNAL(replyGetFileProperties(int, const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(int, const QMap < QString, QString > &, const QMap < QString, QString > &)));
357 void MainWindow::setupActions() {
358 KAction* clearAction = new KAction(this);
359 clearAction->setText(i18n("Clear"));
360 clearAction->setIcon(KIcon("document-new"));
361 clearAction->setShortcut(Qt::CTRL + Qt::Key_W);
362 actionCollection()->addAction("clear", clearAction);
363 /*connect(clearAction, SIGNAL(triggered(bool)),
364 textArea, SLOT(clear()));*/
366 KAction* profilesAction = new KAction(this);
367 profilesAction->setText(i18n("Manage Profiles"));
368 profilesAction->setIcon(KIcon("document-new"));
369 actionCollection()->addAction("manage_profiles", profilesAction);
370 connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
372 KAction* projectAction = new KAction(this);
373 projectAction->setText(i18n("Project Settings"));
374 projectAction->setIcon(KIcon("document-new"));
375 actionCollection()->addAction("project_settings", projectAction);
376 connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
378 KAction* projectRender = new KAction(this);
379 projectRender->setText(i18n("Render Project"));
380 projectRender->setIcon(KIcon("document-new"));
381 actionCollection()->addAction("project_render", projectRender);
382 connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
384 KAction* monitorPlay = new KAction(this);
385 monitorPlay->setText(i18n("Play"));
386 monitorPlay->setIcon(KIcon("media-playback-start"));
387 monitorPlay->setShortcut(Qt::Key_Space);
388 actionCollection()->addAction("monitor_play", monitorPlay);
389 connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
391 KAction* monitorSeekBackward = new KAction(this);
392 monitorSeekBackward->setText(i18n("Rewind"));
393 monitorSeekBackward->setIcon(KIcon("media-seek-backward"));
394 monitorSeekBackward->setShortcut(Qt::Key_J);
395 actionCollection()->addAction("monitor_seek_backward", monitorSeekBackward);
396 connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
398 KAction* monitorSeekBackwardOneFrame = new KAction(this);
399 monitorSeekBackwardOneFrame->setText(i18n("Rewind 1 Frame"));
400 monitorSeekBackwardOneFrame->setIcon(KIcon("media-skip-backward"));
401 monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
402 actionCollection()->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
403 connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
405 KAction* monitorSeekForward = new KAction(this);
406 monitorSeekForward->setText(i18n("Forward"));
407 monitorSeekForward->setIcon(KIcon("media-seek-forward"));
408 monitorSeekForward->setShortcut(Qt::Key_L);
409 actionCollection()->addAction("monitor_seek_forward", monitorSeekForward);
410 connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
412 KAction* monitorSeekForwardOneFrame = new KAction(this);
413 monitorSeekForwardOneFrame->setText(i18n("Forward 1 Frame"));
414 monitorSeekForwardOneFrame->setIcon(KIcon("media-skip-forward"));
415 monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
416 actionCollection()->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
417 connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
419 KAction* deleteTimelineClip = new KAction(this);
420 deleteTimelineClip->setText(i18n("Delete Clip"));
421 deleteTimelineClip->setShortcut(Qt::Key_Delete);
422 deleteTimelineClip->setIcon(KIcon("edit-delete"));
423 actionCollection()->addAction("delete_timeline_clip", deleteTimelineClip);
424 connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
426 KStandardAction::quit(kapp, SLOT(quit()),
429 KStandardAction::open(this, SLOT(openFile()),
432 m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
435 KStandardAction::save(this, SLOT(saveFile()),
438 KStandardAction::saveAs(this, SLOT(saveFileAs()),
441 KStandardAction::openNew(this, SLOT(newFile()),
444 KStandardAction::preferences(this, SLOT(slotPreferences()),
447 KStandardAction::undo(this, SLOT(undo()),
450 KStandardAction::redo(this, SLOT(redo()),
453 KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, actionCollection());
455 connect(actionCollection(), SIGNAL(actionHovered(QAction*)),
456 this, SLOT(slotDisplayActionMessage(QAction*)));
457 //connect(actionCollection(), SIGNAL( clearStatusText() ),
458 //statusBar(), SLOT( clear() ) );
463 void MainWindow::undo() {
464 m_commandStack->undo();
467 void MainWindow::redo() {
468 m_commandStack->redo();
471 void MainWindow::slotDisplayActionMessage(QAction *a) {
472 statusBar()->showMessage(a->data().toString(), 3000);
475 void MainWindow::saveOptions() {
476 KSharedConfigPtr config = KGlobal::config();
477 m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
481 void MainWindow::readOptions() {
482 KSharedConfigPtr config = KGlobal::config();
483 m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
486 void MainWindow::newFile() {
488 if (m_timelineArea->count() == 0) profileName = KdenliveSettings::default_profile();
490 ProjectSettings *w = new ProjectSettings;
492 profileName = w->selectedProfile();
495 MltVideoProfile prof = ProfilesDialog::getVideoProfile(profileName);
496 if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
497 KdenliveDoc *doc = new KdenliveDoc(KUrl(), prof, m_commandStack);
498 TrackView *trackView = new TrackView(doc, this);
499 m_timelineArea->addTab(trackView, KIcon("kdenlive"), i18n("Untitled") + " / " + prof.description);
500 if (m_timelineArea->count() == 1)
501 connectDocument(trackView, doc);
502 else m_timelineArea->setTabBarHidden(false);
505 void MainWindow::activateDocument() {
506 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
507 KdenliveDoc *currentDoc = currentTab->document();
508 connectDocument(currentTab, currentDoc);
511 void MainWindow::slotRemoveTab() {
512 QWidget *w = m_timelineArea->currentWidget();
513 // closing current document
514 int ix = m_timelineArea->currentIndex() + 1;
515 if (ix == m_timelineArea->count()) ix = 0;
516 m_timelineArea->setCurrentIndex(ix);
517 TrackView *tabToClose = (TrackView *) w;
518 KdenliveDoc *docToClose = tabToClose->document();
519 m_timelineArea->removeTab(m_timelineArea->indexOf(w));
520 if (m_timelineArea->count() == 1) m_timelineArea->setTabBarHidden(true);
525 void MainWindow::saveFileAs(const QString &outputFileName) {
526 m_projectMonitor->saveSceneList(outputFileName, m_activeDocument->documentInfoXml());
527 m_activeDocument->setUrl(KUrl(outputFileName));
528 setCaption(m_activeDocument->description());
529 m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
530 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
531 m_activeDocument->setModified(false);
534 void MainWindow::saveFileAs() {
535 QString outputFile = KFileDialog::getSaveFileName();
536 if (QFile::exists(outputFile)) {
537 if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return;
539 saveFileAs(outputFile);
542 void MainWindow::saveFile() {
543 if (!m_activeDocument) return;
544 if (m_activeDocument->url().isEmpty()) {
547 saveFileAs(m_activeDocument->url().path());
551 void MainWindow::openFile() { //changed
552 KUrl url = KFileDialog::getOpenUrl(KUrl(), "application/vnd.kde.kdenlive;*.kdenlive");
553 if (url.isEmpty()) return;
554 m_fileOpenRecent->addUrl(url);
558 void MainWindow::openFile(const KUrl &url) { //new
559 //TODO: get video profile from url before opening it
560 MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
561 if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
562 KdenliveDoc *doc = new KdenliveDoc(url, prof, m_commandStack);
563 TrackView *trackView = new TrackView(doc, this);
564 m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
565 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
566 if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
567 //connectDocument(trackView, doc);
571 void MainWindow::parseProfiles() {
572 //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
573 if (KdenliveSettings::mltpath().isEmpty()) {
574 KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
576 if (KdenliveSettings::rendererpath().isEmpty()) {
577 KdenliveSettings::setRendererpath(KStandardDirs::findExe("inigo"));
579 QStringList profilesFilter;
580 profilesFilter << "*";
581 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
583 if (profilesList.isEmpty()) {
584 // Cannot find MLT path, try finding inigo
585 QString profilePath = KdenliveSettings::rendererpath();
586 if (!profilePath.isEmpty()) {
587 profilePath = profilePath.section('/', 0, -3);
588 KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
589 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
592 if (profilesList.isEmpty()) {
593 // Cannot find the MLT profiles, ask for location
594 KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
595 getUrl->fileDialog()->setMode(KFile::Directory);
597 KUrl mltPath = getUrl->selectedUrl();
599 if (mltPath.isEmpty()) exit(1);
600 KdenliveSettings::setMltpath(mltPath.path());
601 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
605 if (KdenliveSettings::rendererpath().isEmpty()) {
606 // Cannot find the MLT inigo renderer, ask for location
607 KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
609 KUrl rendererPath = getUrl->selectedUrl();
611 if (rendererPath.isEmpty()) exit(1);
612 KdenliveSettings::setRendererpath(rendererPath.path());
615 kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
617 // Parse MLT profiles to build a list of available video formats
618 if (profilesList.isEmpty()) parseProfiles();
622 void MainWindow::slotEditProfiles() {
623 ProfilesDialog *w = new ProfilesDialog;
628 void MainWindow::slotEditProjectSettings() {
629 ProjectSettings *w = new ProjectSettings;
630 if (w->exec() == QDialog::Accepted) {
631 QString profile = w->selectedProfile();
632 m_activeDocument->setProfilePath(profile);
633 m_monitorManager->resetProfiles(profile);
634 setCaption(m_activeDocument->description());
635 KdenliveSettings::setCurrent_profile(m_activeDocument->profilePath());
636 if (m_renderWidget) m_renderWidget->setDocumentStandard(m_activeDocument->getDocumentStandard());
637 m_monitorManager->setTimecode(m_activeDocument->timecode());
638 m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
640 // We need to desactivate & reactivate monitors to get a refresh
641 m_monitorManager->switchMonitors();
646 void MainWindow::slotRenderProject() {
647 if (!m_renderWidget) {
648 m_renderWidget = new RenderWidget(this);
649 connect(m_renderWidget, SIGNAL(doRender(const QString&, const QString&, const QStringList &, bool, bool)), this, SLOT(slotDoRender(const QString&, const QString&, const QStringList &, bool, bool)));
651 /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
652 if (currentTab) m_renderWidget->setTimeline(currentTab);
653 m_renderWidget->setDocument(m_activeDocument);*/
654 m_renderWidget->show();
657 void MainWindow::slotDoRender(const QString &dest, const QString &render, const QStringList &avformat_args, bool zoneOnly, bool playAfter) {
658 if (dest.isEmpty()) return;
661 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
662 if (currentTab && zoneOnly) {
663 in = currentTab->inPoint();
664 out = currentTab->outPoint();
667 temp.setAutoRemove(false);
668 temp.setSuffix(".westley");
670 m_projectMonitor->saveSceneList(temp.fileName());
673 if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
674 QString videoPlayer = "-";
675 if (playAfter) videoPlayer = "kmplayer";
676 args << "inigo" << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
677 QProcess::startDetached("kdenlive_render", args);
681 void MainWindow::slotUpdateMousePosition(int pos) {
682 if (m_activeDocument)
683 switch (m_timecodeFormat->currentIndex()) {
685 statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
688 statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
692 void MainWindow::slotUpdateDocumentState(bool modified) {
693 setCaption(m_activeDocument->description(), modified);
695 m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
696 m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
698 m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
699 m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
703 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
704 //m_projectMonitor->stop();
705 kDebug() << "/////////////////// CONNECTING DOC TO PROJECT VIEW ////////////////";
706 if (m_activeDocument) {
707 if (m_activeDocument == doc) return;
708 m_activeDocument->backupMltPlaylist();
709 if (m_activeTimeline) {
710 disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
711 disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
712 disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
713 disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
714 disconnect(m_activeDocument, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
715 disconnect(m_activeDocument, SIGNAL(deletTimelineClip(int)), m_activeTimeline, SLOT(slotDeleteClip(int)));
716 disconnect(m_activeDocument, SIGNAL(thumbsProgress(KUrl, int)), this, SLOT(slotGotProgressInfo(KUrl, int)));
717 disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
718 disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
719 disconnect(timeline_buttons_ui.zoom_slider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
720 disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
721 disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
722 disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
723 disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool)));
724 disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
725 disconnect(transitionConfig, SIGNAL(transitionUpdated(QDomElement, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(QDomElement, QDomElement)));
726 disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
728 m_activeDocument->setRenderer(NULL);
729 disconnect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
730 m_clipMonitor->stop();
732 m_monitorManager->resetProfiles(doc->profilePath());
733 m_projectList->setDocument(doc);
734 connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
735 connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
736 connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
737 connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
738 connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
739 connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
740 connect(doc, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
741 connect(doc, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
742 connect(doc, SIGNAL(deletTimelineClip(int)), trackView, SLOT(slotDeleteClip(int)));
743 connect(doc, SIGNAL(thumbsProgress(KUrl, int)), this, SLOT(slotGotProgressInfo(KUrl, int)));
744 connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
746 connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
747 connect(trackView, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
748 timeline_buttons_ui.zoom_slider->setValue(trackView->currentZoom());
749 connect(timeline_buttons_ui.zoom_slider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
750 connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
751 connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
752 connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
753 connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
754 connect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool)));
755 connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
756 connect(transitionConfig, SIGNAL(transitionUpdated(QDomElement, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(QDomElement, QDomElement)));
757 connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
758 trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
759 m_activeTimeline = trackView;
760 KdenliveSettings::setCurrent_profile(doc->profilePath());
761 if (m_renderWidget) m_renderWidget->setDocumentStandard(doc->getDocumentStandard());
762 m_monitorManager->setTimecode(doc->timecode());
763 doc->setRenderer(m_projectMonitor->render);
764 m_commandStack->setActiveStack(doc->commandStack());
765 if (m_commandStack->isClean()) kDebug() << "//////////// UNDO STACK IS CLEAN";
766 else kDebug() << "//////////// UNDO STACK IS NOT CLEAN*******************";
768 m_overView->setScene(trackView->projectScene());
769 //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
770 //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
772 setCaption(doc->description());
773 m_activeDocument = doc;
776 void MainWindow::slotPreferences() {
777 //An instance of your dialog could be already created and could be
778 // cached, in which case you want to display the cached dialog
779 // instead of creating another one
780 if (KConfigDialog::showDialog("settings"))
783 // KConfigDialog didn't find an instance of this dialog, so lets
785 KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
786 connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
790 void MainWindow::updateConfiguration() {
791 //TODO: we should apply settings to all projects, not only the current one
792 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
794 currentTab->refresh();
795 currentTab->projectView()->checkAutoScroll();
796 currentTab->projectView()->checkTrackHeight();
797 if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
799 timeline_buttons_ui.buttonAudio->setDown(KdenliveSettings::audiothumbnails());
800 timeline_buttons_ui.buttonVideo->setDown(KdenliveSettings::videothumbnails());
801 activateShuttleDevice();
805 void MainWindow::slotSwitchVideoThumbs() {
806 KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
807 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
809 currentTab->refresh();
811 timeline_buttons_ui.buttonVideo->setDown(KdenliveSettings::videothumbnails());
814 void MainWindow::slotSwitchAudioThumbs() {
815 KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
816 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
818 currentTab->refresh();
819 currentTab->projectView()->checkAutoScroll();
820 if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
822 timeline_buttons_ui.buttonAudio->setDown(KdenliveSettings::audiothumbnails());
825 void MainWindow::slotDeleteTimelineClip() {
826 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
828 currentTab->projectView()->deleteSelectedClips();
832 void MainWindow::slotAddProjectClip(KUrl url) {
833 if (m_activeDocument)
834 m_activeDocument->slotAddClipFile(url, QString());
837 void MainWindow::slotAddVideoEffect(QAction *result) {
839 QDomElement effect = m_videoEffects.getEffectByName(result->data().toString());
840 slotAddEffect(effect);
843 void MainWindow::slotAddAudioEffect(QAction *result) {
845 QDomElement effect = m_audioEffects.getEffectByName(result->data().toString());
846 slotAddEffect(effect);
849 void MainWindow::slotAddCustomEffect(QAction *result) {
851 QDomElement effect = m_customEffects.getEffectByName(result->data().toString());
852 slotAddEffect(effect);
855 void MainWindow::slotZoomIn() {
856 timeline_buttons_ui.zoom_slider->setValue(timeline_buttons_ui.zoom_slider->value() - 1);
859 void MainWindow::slotZoomOut() {
860 timeline_buttons_ui.zoom_slider->setValue(timeline_buttons_ui.zoom_slider->value() + 1);
863 void MainWindow::slotFitZoom() {
864 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
866 timeline_buttons_ui.zoom_slider->setValue(currentTab->fitZoom());
870 void MainWindow::slotGotProgressInfo(KUrl url, int progress) {
871 statusProgressBar->setValue(progress);
873 statusLabel->setText(tr("Creating Audio Thumbs"));
874 statusProgressBar->setVisible(true);
876 statusLabel->setText("");
877 statusProgressBar->setVisible(false);
881 void MainWindow::customEvent(QEvent* e) {
882 if (e->type() == QEvent::User) {
883 // The timeline playing position changed...
884 kDebug() << "RECIEVED JOG EVEMNT!!!";
889 #include "mainwindow.moc"