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>
49 #include <ktogglefullscreenaction.h>
51 #include <mlt++/Mlt.h>
53 #include "mainwindow.h"
54 #include "kdenlivesettings.h"
55 #include "kdenlivesettingsdialog.h"
56 #include "initeffects.h"
57 #include "profilesdialog.h"
58 #include "projectsettings.h"
60 #include "renderjob.h"
61 #include "clipmanager.h"
62 #include "projectlist.h"
64 #include "recmonitor.h"
65 #include "monitormanager.h"
66 #include "kdenlivedoc.h"
67 #include "trackview.h"
68 #include "customtrackview.h"
69 #include "effectslistview.h"
70 #include "effectstackview.h"
71 #include "transitionsettings.h"
72 #include "renderwidget.h"
74 #include "jogshuttle.h"
75 #include "clipproperties.h"
77 #define ID_STATUS_MSG 1
78 #define ID_EDITMODE_MSG 2
79 #define ID_TIMELINE_MSG 3
80 #define ID_TIMELINE_BUTTONS 5
81 #define ID_TIMELINE_POS 6
82 #define ID_TIMELINE_FORMAT 7
84 EffectsList MainWindow::videoEffects;
85 EffectsList MainWindow::audioEffects;
86 EffectsList MainWindow::customEffects;
87 EffectsList MainWindow::transitions;
89 MainWindow::MainWindow(QWidget *parent)
90 : KXmlGuiWindow(parent),
91 m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL), m_jogProcess(NULL) {
92 setlocale(LC_NUMERIC, "POSIX");
94 setFont(KGlobalSettings::toolBarFont());
95 m_commandStack = new QUndoGroup;
96 m_timelineArea = new KTabWidget(this);
97 m_timelineArea->setTabReorderingEnabled(true);
98 m_timelineArea->setTabBarHidden(true);
100 QToolButton *closeTabButton = new QToolButton;
101 connect(closeTabButton, SIGNAL(clicked()), this, SLOT(slotRemoveTab()));
102 closeTabButton->setIcon(KIcon("tab-close"));
103 closeTabButton->adjustSize();
104 closeTabButton->setToolTip(i18n("Close the current tab"));
105 m_timelineArea->setCornerWidget(closeTabButton);
106 connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
108 initEffects::parseEffectFiles();
109 m_monitorManager = new MonitorManager();
111 projectListDock = new QDockWidget(i18n("Project Tree"), this);
112 projectListDock->setObjectName("project_tree");
113 m_projectList = new ProjectList(this);
114 projectListDock->setWidget(m_projectList);
115 addDockWidget(Qt::TopDockWidgetArea, projectListDock);
117 effectListDock = new QDockWidget(i18n("Effect List"), this);
118 effectListDock->setObjectName("effect_list");
119 m_effectList = new EffectsListView();
121 //m_effectList = new KListWidget(this);
122 effectListDock->setWidget(m_effectList);
123 addDockWidget(Qt::TopDockWidgetArea, effectListDock);
125 effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
126 effectStackDock->setObjectName("effect_stack");
127 effectStack = new EffectStackView(this);
128 effectStackDock->setWidget(effectStack);
129 addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
131 transitionConfigDock = new QDockWidget(i18n("Transition"), this);
132 transitionConfigDock->setObjectName("transition");
133 transitionConfig = new TransitionSettings(this);
134 transitionConfigDock->setWidget(transitionConfig);
135 addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
138 clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
139 clipMonitorDock->setObjectName("clip_monitor");
140 m_clipMonitor = new Monitor("clip", m_monitorManager, this);
141 clipMonitorDock->setWidget(m_clipMonitor);
142 addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
143 //m_clipMonitor->stop();
145 projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
146 projectMonitorDock->setObjectName("project_monitor");
147 m_projectMonitor = new Monitor("project", m_monitorManager, this);
148 projectMonitorDock->setWidget(m_projectMonitor);
149 addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
151 recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
152 recMonitorDock->setObjectName("record_monitor");
153 m_recMonitor = new RecMonitor("record", this);
154 recMonitorDock->setWidget(m_recMonitor);
155 addDockWidget(Qt::TopDockWidgetArea, recMonitorDock);
157 connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
159 undoViewDock = new QDockWidget(i18n("Undo History"), this);
160 undoViewDock->setObjectName("undo_history");
161 m_undoView = new QUndoView(this);
162 m_undoView->setCleanIcon(KIcon("edit-clear"));
163 m_undoView->setEmptyLabel(i18n("Clean"));
164 undoViewDock->setWidget(m_undoView);
165 m_undoView->setGroup(m_commandStack);
166 addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
168 overviewDock = new QDockWidget(i18n("Project Overview"), this);
169 overviewDock->setObjectName("project_overview");
170 m_overView = new CustomTrackView(NULL, NULL, this);
171 overviewDock->setWidget(m_overView);
172 addDockWidget(Qt::TopDockWidgetArea, overviewDock);
175 tabifyDockWidget(projectListDock, effectListDock);
176 tabifyDockWidget(projectListDock, effectStackDock);
177 tabifyDockWidget(projectListDock, transitionConfigDock);
178 tabifyDockWidget(projectListDock, undoViewDock);
179 projectListDock->raise();
181 tabifyDockWidget(clipMonitorDock, projectMonitorDock);
182 setCentralWidget(m_timelineArea);
184 m_timecodeFormat = new KComboBox(this);
185 m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
186 m_timecodeFormat->addItem(i18n("Frames"));
188 statusProgressBar = new QProgressBar(this);
189 statusProgressBar->setMinimum(0);
190 statusProgressBar->setMaximum(100);
191 statusProgressBar->setMaximumWidth(150);
192 statusProgressBar->setVisible(false);
193 statusLabel = new QLabel(this);
195 QWidget *w = new QWidget;
196 timeline_buttons_ui.setupUi(w);
197 timeline_buttons_ui.buttonVideo->setDown(KdenliveSettings::videothumbnails());
198 timeline_buttons_ui.buttonAudio->setDown(KdenliveSettings::audiothumbnails());
199 connect(timeline_buttons_ui.buttonVideo, SIGNAL(clicked()), this, SLOT(slotSwitchVideoThumbs()));
200 connect(timeline_buttons_ui.buttonAudio, SIGNAL(clicked()), this, SLOT(slotSwitchAudioThumbs()));
201 connect(timeline_buttons_ui.buttonFitZoom, SIGNAL(clicked()), this, SLOT(slotFitZoom()));
203 statusBar()->insertPermanentWidget(0, statusProgressBar, 1);
204 statusBar()->insertPermanentWidget(1, statusLabel, 1);
205 statusBar()->insertPermanentWidget(ID_TIMELINE_BUTTONS, w);
206 statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
207 statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
208 statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
210 timeline_buttons_ui.buttonVideo->setIcon(KIcon("video-mpeg"));
211 timeline_buttons_ui.buttonVideo->setToolTip(i18n("Show video thumbnails"));
212 timeline_buttons_ui.buttonAudio->setIcon(KIcon("audio-mpeg"));
213 timeline_buttons_ui.buttonAudio->setToolTip(i18n("Show audio thumbnails"));
214 timeline_buttons_ui.buttonFitZoom->setIcon(KIcon("zoom-fit-best"));
215 timeline_buttons_ui.buttonFitZoom->setToolTip(i18n("Fit zoom to project"));
217 setupGUI(Default, NULL /*"kdenliveui.rc"*/);
218 kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
220 // build effects menus
222 QMenu *videoEffectsMenu = (QMenu*)(factory()->container("video_effects_menu", this));
223 QStringList effects = videoEffects.effectNames();
224 foreach(QString name, effects) {
225 action = new QAction(name, this);
226 action->setData(name);
227 videoEffectsMenu->addAction(action);
229 QMenu *audioEffectsMenu = (QMenu*)(factory()->container("audio_effects_menu", this));
230 effects = audioEffects.effectNames();
231 foreach(QString name, effects) {
232 action = new QAction(name, this);
233 action->setData(name);
234 audioEffectsMenu->addAction(action);
236 QMenu *customEffectsMenu = (QMenu*)(factory()->container("custom_effects_menu", this));
237 effects = customEffects.effectNames();
238 foreach(QString name, effects) {
239 action = new QAction(name, this);
240 action->setData(name);
241 customEffectsMenu->addAction(action);
244 connect(videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
245 connect(audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
246 connect(customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
248 m_timelineContextMenu = new QMenu(this);
249 m_timelineContextClipMenu = new QMenu(this);
250 m_timelineContextTransitionMenu = new QMenu(this);
252 action = actionCollection()->action("delete_timeline_clip");
253 m_timelineContextClipMenu->addAction(action);
254 m_timelineContextClipMenu->addMenu(videoEffectsMenu);
255 m_timelineContextClipMenu->addMenu(audioEffectsMenu);
256 m_timelineContextClipMenu->addMenu(customEffectsMenu);
258 connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
259 connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
260 //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
261 connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
262 connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
263 m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
264 slotConnectMonitors();
266 setAutoSaveSettings();
269 activateShuttleDevice();
272 void MainWindow::queryQuit() {
273 kDebug() << "----- SAVING CONFUIG";
274 if (queryClose()) kapp->quit();
278 bool MainWindow::queryClose() {
280 if (m_activeDocument && m_activeDocument->isModified()) {
281 switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
282 case KMessageBox::Yes :
283 // save document here. If saving fails, return false;
285 case KMessageBox::No :
294 void MainWindow::activateShuttleDevice() {
295 if (m_jogProcess) delete m_jogProcess;
297 if (KdenliveSettings::enableshuttle() == false) return;
298 m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
299 connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
300 connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
301 connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
302 connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
303 connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
304 connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
307 void MainWindow::slotShuttleButton(int code) {
310 slotShuttleAction(KdenliveSettings::shuttle1());
313 slotShuttleAction(KdenliveSettings::shuttle2());
316 slotShuttleAction(KdenliveSettings::shuttle3());
319 slotShuttleAction(KdenliveSettings::shuttle4());
322 slotShuttleAction(KdenliveSettings::shuttle5());
327 void MainWindow::slotShuttleAction(int code) {
332 m_monitorManager->slotPlay();
335 m_monitorManager->slotPlay();
340 void MainWindow::slotFullScreen() {
341 //KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
344 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
345 if (!m_activeDocument) return;
346 if (effect.isNull()) {
347 kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
350 TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
351 currentTimeLine->projectView()->slotAddEffect(effect, pos, track);
354 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
355 if (clipMonitor) clipMonitorDock->raise();
356 else projectMonitorDock->raise();
359 void MainWindow::slotSetClipDuration(int id, int duration) {
360 if (!m_activeDocument) return;
361 m_activeDocument->setProducerDuration(id, duration);
364 void MainWindow::slotConnectMonitors() {
366 m_projectList->setRenderer(m_clipMonitor->render);
367 connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
368 connect(m_projectList, SIGNAL(receivedClipDuration(int, int)), this, SLOT(slotSetClipDuration(int, int)));
369 connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
370 connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
371 connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int)));
372 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 > &)));
375 void MainWindow::setupActions() {
376 KAction* clearAction = new KAction(this);
377 clearAction->setText(i18n("Clear"));
378 clearAction->setIcon(KIcon("document-new"));
379 clearAction->setShortcut(Qt::CTRL + Qt::Key_W);
380 actionCollection()->addAction("clear", clearAction);
381 /*connect(clearAction, SIGNAL(triggered(bool)),
382 textArea, SLOT(clear()));*/
384 KAction* profilesAction = new KAction(this);
385 profilesAction->setText(i18n("Manage Profiles"));
386 profilesAction->setIcon(KIcon("document-new"));
387 actionCollection()->addAction("manage_profiles", profilesAction);
388 connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
390 KAction* projectAction = new KAction(this);
391 projectAction->setText(i18n("Project Settings"));
392 projectAction->setIcon(KIcon("document-new"));
393 actionCollection()->addAction("project_settings", projectAction);
394 connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
396 KAction* projectRender = new KAction(this);
397 projectRender->setText(i18n("Render Project"));
398 projectRender->setIcon(KIcon("document-new"));
399 actionCollection()->addAction("project_render", projectRender);
400 connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
402 KAction* monitorPlay = new KAction(this);
403 monitorPlay->setText(i18n("Play"));
404 monitorPlay->setIcon(KIcon("media-playback-start"));
405 monitorPlay->setShortcut(Qt::Key_Space);
406 actionCollection()->addAction("monitor_play", monitorPlay);
407 connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
409 KAction* monitorSeekBackward = new KAction(this);
410 monitorSeekBackward->setText(i18n("Rewind"));
411 monitorSeekBackward->setIcon(KIcon("media-seek-backward"));
412 monitorSeekBackward->setShortcut(Qt::Key_J);
413 actionCollection()->addAction("monitor_seek_backward", monitorSeekBackward);
414 connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
416 KAction* monitorSeekBackwardOneFrame = new KAction(this);
417 monitorSeekBackwardOneFrame->setText(i18n("Rewind 1 Frame"));
418 monitorSeekBackwardOneFrame->setIcon(KIcon("media-skip-backward"));
419 monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
420 actionCollection()->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
421 connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
423 KAction* monitorSeekForward = new KAction(this);
424 monitorSeekForward->setText(i18n("Forward"));
425 monitorSeekForward->setIcon(KIcon("media-seek-forward"));
426 monitorSeekForward->setShortcut(Qt::Key_L);
427 actionCollection()->addAction("monitor_seek_forward", monitorSeekForward);
428 connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
430 KAction* monitorSeekForwardOneFrame = new KAction(this);
431 monitorSeekForwardOneFrame->setText(i18n("Forward 1 Frame"));
432 monitorSeekForwardOneFrame->setIcon(KIcon("media-skip-forward"));
433 monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
434 actionCollection()->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
435 connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
437 KAction* deleteTimelineClip = new KAction(this);
438 deleteTimelineClip->setText(i18n("Delete Clip"));
439 deleteTimelineClip->setShortcut(Qt::Key_Delete);
440 deleteTimelineClip->setIcon(KIcon("edit-delete"));
441 actionCollection()->addAction("delete_timeline_clip", deleteTimelineClip);
442 connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
444 KStandardAction::quit(this, SLOT(queryQuit()),
447 KStandardAction::open(this, SLOT(openFile()),
450 m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
453 KStandardAction::save(this, SLOT(saveFile()),
456 KStandardAction::saveAs(this, SLOT(saveFileAs()),
459 KStandardAction::openNew(this, SLOT(newFile()),
462 KStandardAction::preferences(this, SLOT(slotPreferences()),
465 KStandardAction::undo(this, SLOT(undo()),
468 KStandardAction::redo(this, SLOT(redo()),
471 KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, actionCollection());
473 connect(actionCollection(), SIGNAL(actionHovered(QAction*)),
474 this, SLOT(slotDisplayActionMessage(QAction*)));
475 //connect(actionCollection(), SIGNAL( clearStatusText() ),
476 //statusBar(), SLOT( clear() ) );
481 void MainWindow::undo() {
482 m_commandStack->undo();
485 void MainWindow::redo() {
486 m_commandStack->redo();
489 void MainWindow::slotDisplayActionMessage(QAction *a) {
490 statusBar()->showMessage(a->data().toString(), 3000);
493 void MainWindow::saveOptions() {
494 KdenliveSettings::self()->writeConfig();
495 KSharedConfigPtr config = KGlobal::config();
496 m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
500 void MainWindow::readOptions() {
501 KSharedConfigPtr config = KGlobal::config();
502 m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
505 void MainWindow::newFile() {
507 if (m_timelineArea->count() == 0) profileName = KdenliveSettings::default_profile();
509 ProjectSettings *w = new ProjectSettings;
511 profileName = w->selectedProfile();
514 MltVideoProfile prof = ProfilesDialog::getVideoProfile(profileName);
515 if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
516 KdenliveDoc *doc = new KdenliveDoc(KUrl(), prof, m_commandStack);
517 TrackView *trackView = new TrackView(doc, this);
518 m_timelineArea->addTab(trackView, KIcon("kdenlive"), i18n("Untitled") + " / " + prof.description);
519 if (m_timelineArea->count() == 1)
520 connectDocument(trackView, doc);
521 else m_timelineArea->setTabBarHidden(false);
524 void MainWindow::activateDocument() {
525 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
526 KdenliveDoc *currentDoc = currentTab->document();
527 connectDocument(currentTab, currentDoc);
530 void MainWindow::slotRemoveTab() {
531 QWidget *w = m_timelineArea->currentWidget();
532 // closing current document
533 int ix = m_timelineArea->currentIndex() + 1;
534 if (ix == m_timelineArea->count()) ix = 0;
535 m_timelineArea->setCurrentIndex(ix);
536 TrackView *tabToClose = (TrackView *) w;
537 KdenliveDoc *docToClose = tabToClose->document();
538 m_timelineArea->removeTab(m_timelineArea->indexOf(w));
539 if (m_timelineArea->count() == 1) m_timelineArea->setTabBarHidden(true);
544 void MainWindow::saveFileAs(const QString &outputFileName) {
545 m_projectMonitor->saveSceneList(outputFileName, m_activeDocument->documentInfoXml());
546 m_activeDocument->setUrl(KUrl(outputFileName));
547 setCaption(m_activeDocument->description());
548 m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
549 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
550 m_activeDocument->setModified(false);
553 void MainWindow::saveFileAs() {
554 QString outputFile = KFileDialog::getSaveFileName();
555 if (QFile::exists(outputFile)) {
556 if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return;
558 saveFileAs(outputFile);
561 void MainWindow::saveFile() {
562 if (!m_activeDocument) return;
563 if (m_activeDocument->url().isEmpty()) {
566 saveFileAs(m_activeDocument->url().path());
570 void MainWindow::openFile() { //changed
571 KUrl url = KFileDialog::getOpenUrl(KUrl(), "application/vnd.kde.kdenlive;*.kdenlive");
572 if (url.isEmpty()) return;
573 m_fileOpenRecent->addUrl(url);
577 void MainWindow::openFile(const KUrl &url) { //new
578 //TODO: get video profile from url before opening it
579 MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
580 if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
581 KdenliveDoc *doc = new KdenliveDoc(url, prof, m_commandStack);
582 TrackView *trackView = new TrackView(doc, this);
583 m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
584 m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
585 if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
586 //connectDocument(trackView, doc);
590 void MainWindow::parseProfiles() {
591 //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
592 if (KdenliveSettings::mltpath().isEmpty()) {
593 KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
595 if (KdenliveSettings::rendererpath().isEmpty()) {
596 KdenliveSettings::setRendererpath(KStandardDirs::findExe("inigo"));
598 QStringList profilesFilter;
599 profilesFilter << "*";
600 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
602 if (profilesList.isEmpty()) {
603 // Cannot find MLT path, try finding inigo
604 QString profilePath = KdenliveSettings::rendererpath();
605 if (!profilePath.isEmpty()) {
606 profilePath = profilePath.section('/', 0, -3);
607 KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
608 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
611 if (profilesList.isEmpty()) {
612 // Cannot find the MLT profiles, ask for location
613 KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
614 getUrl->fileDialog()->setMode(KFile::Directory);
616 KUrl mltPath = getUrl->selectedUrl();
618 if (mltPath.isEmpty()) exit(1);
619 KdenliveSettings::setMltpath(mltPath.path());
620 QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
624 if (KdenliveSettings::rendererpath().isEmpty()) {
625 // Cannot find the MLT inigo renderer, ask for location
626 KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
628 KUrl rendererPath = getUrl->selectedUrl();
630 if (rendererPath.isEmpty()) exit(1);
631 KdenliveSettings::setRendererpath(rendererPath.path());
634 kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
636 // Parse MLT profiles to build a list of available video formats
637 if (profilesList.isEmpty()) parseProfiles();
641 void MainWindow::slotEditProfiles() {
642 ProfilesDialog *w = new ProfilesDialog;
647 void MainWindow::slotEditProjectSettings() {
648 ProjectSettings *w = new ProjectSettings;
649 if (w->exec() == QDialog::Accepted) {
650 QString profile = w->selectedProfile();
651 m_activeDocument->setProfilePath(profile);
652 m_monitorManager->resetProfiles(profile);
653 setCaption(m_activeDocument->description());
654 KdenliveSettings::setCurrent_profile(m_activeDocument->profilePath());
655 if (m_renderWidget) m_renderWidget->setDocumentStandard(m_activeDocument->getDocumentStandard());
656 m_monitorManager->setTimecode(m_activeDocument->timecode());
657 m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
659 // We need to desactivate & reactivate monitors to get a refresh
660 m_monitorManager->switchMonitors();
665 void MainWindow::slotRenderProject() {
666 if (!m_renderWidget) {
667 m_renderWidget = new RenderWidget(this);
668 connect(m_renderWidget, SIGNAL(doRender(const QString&, const QString&, const QStringList &, bool, bool)), this, SLOT(slotDoRender(const QString&, const QString&, const QStringList &, bool, bool)));
670 /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
671 if (currentTab) m_renderWidget->setTimeline(currentTab);
672 m_renderWidget->setDocument(m_activeDocument);*/
673 m_renderWidget->show();
676 void MainWindow::slotDoRender(const QString &dest, const QString &render, const QStringList &avformat_args, bool zoneOnly, bool playAfter) {
677 if (dest.isEmpty()) return;
680 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
681 if (currentTab && zoneOnly) {
682 in = currentTab->inPoint();
683 out = currentTab->outPoint();
686 temp.setAutoRemove(false);
687 temp.setSuffix(".westley");
689 m_projectMonitor->saveSceneList(temp.fileName());
692 if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
693 QString videoPlayer = "-";
694 if (playAfter) videoPlayer = "kmplayer";
695 args << "inigo" << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
696 QProcess::startDetached("kdenlive_render", args);
700 void MainWindow::slotUpdateMousePosition(int pos) {
701 if (m_activeDocument)
702 switch (m_timecodeFormat->currentIndex()) {
704 statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
707 statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
711 void MainWindow::slotUpdateDocumentState(bool modified) {
712 setCaption(m_activeDocument->description(), modified);
714 m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
715 m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
717 m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
718 m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
722 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
723 //m_projectMonitor->stop();
724 kDebug() << "/////////////////// CONNECTING DOC TO PROJECT VIEW ////////////////";
725 if (m_activeDocument) {
726 if (m_activeDocument == doc) return;
727 m_activeDocument->backupMltPlaylist();
728 if (m_activeTimeline) {
729 disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
730 disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
731 disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
732 disconnect(m_activeDocument, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
733 disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
734 disconnect(m_activeDocument, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
735 disconnect(m_activeDocument, SIGNAL(deletTimelineClip(int)), m_activeTimeline, SLOT(slotDeleteClip(int)));
736 disconnect(m_activeDocument, SIGNAL(thumbsProgress(KUrl, int)), this, SLOT(slotGotProgressInfo(KUrl, int)));
737 disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
738 disconnect(trackView, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
739 disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
740 disconnect(trackView, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
741 disconnect(timeline_buttons_ui.zoom_slider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
742 disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
743 disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
744 disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
745 disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool)));
746 disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
747 disconnect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
748 disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
750 m_activeDocument->setRenderer(NULL);
751 disconnect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
752 m_clipMonitor->stop();
754 m_monitorManager->resetProfiles(doc->profilePath());
755 m_projectList->setDocument(doc);
756 connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
757 connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
758 connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
759 connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
760 connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
761 connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
762 connect(doc, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
763 connect(doc, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
764 connect(doc, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
765 connect(doc, SIGNAL(deletTimelineClip(int)), trackView, SLOT(slotDeleteClip(int)));
766 connect(doc, SIGNAL(thumbsProgress(KUrl, int)), this, SLOT(slotGotProgressInfo(KUrl, int)));
767 connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
769 connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
770 connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
771 connect(trackView, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
772 connect(trackView, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
773 timeline_buttons_ui.zoom_slider->setValue(trackView->currentZoom());
774 connect(timeline_buttons_ui.zoom_slider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
775 connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
776 connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
777 connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
778 connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
779 connect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool)));
780 connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
781 connect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
782 connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
783 trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
784 m_activeTimeline = trackView;
785 KdenliveSettings::setCurrent_profile(doc->profilePath());
786 if (m_renderWidget) m_renderWidget->setDocumentStandard(doc->getDocumentStandard());
787 m_monitorManager->setTimecode(doc->timecode());
788 doc->setRenderer(m_projectMonitor->render);
789 m_commandStack->setActiveStack(doc->commandStack());
790 if (m_commandStack->isClean()) kDebug() << "//////////// UNDO STACK IS CLEAN";
791 else kDebug() << "//////////// UNDO STACK IS NOT CLEAN*******************";
793 m_overView->setScene(trackView->projectScene());
794 //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
795 //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
797 setCaption(doc->description());
798 m_activeDocument = doc;
801 void MainWindow::slotPreferences() {
802 //An instance of your dialog could be already created and could be
803 // cached, in which case you want to display the cached dialog
804 // instead of creating another one
805 if (KConfigDialog::showDialog("settings"))
808 // KConfigDialog didn't find an instance of this dialog, so lets
810 KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
811 connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
815 void MainWindow::updateConfiguration() {
816 //TODO: we should apply settings to all projects, not only the current one
817 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
819 currentTab->refresh();
820 currentTab->projectView()->checkAutoScroll();
821 currentTab->projectView()->checkTrackHeight();
822 if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
824 timeline_buttons_ui.buttonAudio->setDown(KdenliveSettings::audiothumbnails());
825 timeline_buttons_ui.buttonVideo->setDown(KdenliveSettings::videothumbnails());
826 activateShuttleDevice();
830 void MainWindow::slotSwitchVideoThumbs() {
831 KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
832 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
834 currentTab->refresh();
836 timeline_buttons_ui.buttonVideo->setDown(KdenliveSettings::videothumbnails());
839 void MainWindow::slotSwitchAudioThumbs() {
840 KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
841 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
843 currentTab->refresh();
844 currentTab->projectView()->checkAutoScroll();
845 if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
847 timeline_buttons_ui.buttonAudio->setDown(KdenliveSettings::audiothumbnails());
850 void MainWindow::slotDeleteTimelineClip() {
851 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
853 currentTab->projectView()->deleteSelectedClips();
857 void MainWindow::slotAddProjectClip(KUrl url) {
858 if (m_activeDocument)
859 m_activeDocument->slotAddClipFile(url, QString());
862 void MainWindow::slotAddVideoEffect(QAction *result) {
864 QDomElement effect = videoEffects.getEffectByName(result->data().toString());
865 slotAddEffect(effect);
868 void MainWindow::slotAddAudioEffect(QAction *result) {
870 QDomElement effect = audioEffects.getEffectByName(result->data().toString());
871 slotAddEffect(effect);
874 void MainWindow::slotAddCustomEffect(QAction *result) {
876 QDomElement effect = customEffects.getEffectByName(result->data().toString());
877 slotAddEffect(effect);
880 void MainWindow::slotZoomIn() {
881 timeline_buttons_ui.zoom_slider->setValue(timeline_buttons_ui.zoom_slider->value() - 1);
884 void MainWindow::slotZoomOut() {
885 timeline_buttons_ui.zoom_slider->setValue(timeline_buttons_ui.zoom_slider->value() + 1);
888 void MainWindow::slotFitZoom() {
889 TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
891 timeline_buttons_ui.zoom_slider->setValue(currentTab->fitZoom());
895 void MainWindow::slotGotProgressInfo(KUrl url, int progress) {
896 statusProgressBar->setValue(progress);
898 statusLabel->setText(tr("Creating Audio Thumbs"));
899 statusProgressBar->setVisible(true);
901 statusLabel->setText("");
902 statusProgressBar->setVisible(false);
906 void MainWindow::slotShowClipProperties(DocClipBase *clip) {
907 ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
908 if (dia.exec() == QDialog::Accepted) {
909 m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
913 void MainWindow::customEvent(QEvent* e) {
914 if (e->type() == QEvent::User) {
915 // The timeline playing position changed...
916 kDebug() << "RECIEVED JOG EVEMNT!!!";
919 void MainWindow::slotActivateEffectStackView() {
920 effectStack->raiseWindow(effectStackDock);
923 void MainWindow::slotActivateTransitionView() {
924 transitionConfig->raiseWindow(transitionConfigDock);
926 #include "mainwindow.moc"