]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
34ff83f0ffaaacd8964d8c01641b45a60c6ffd85
[kdenlive] / src / mainwindow.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20
21
22 #include <QTextStream>
23 #include <QTimer>
24 #include <QAction>
25 #include <QtTest>
26 #include <QtCore>
27
28 #include <KApplication>
29 #include <KAction>
30 #include <KLocale>
31 #include <KGlobal>
32 #include <KActionCollection>
33 #include <KStandardAction>
34 #include <KFileDialog>
35 #include <KMessageBox>
36 #include <KDebug>
37 #include <KIO/NetAccess>
38 #include <KSaveFile>
39 #include <KRuler>
40 #include <KConfigDialog>
41 #include <KXMLGUIFactory>
42 #include <KStatusBar>
43 #include <kstandarddirs.h>
44 #include <KUrlRequesterDialog>
45 #include <KTemporaryFile>
46 #include <KActionMenu>
47 #include <KMenu>
48 #include <locale.h>
49 #include <ktogglefullscreenaction.h>
50
51 #include <mlt++/Mlt.h>
52
53 #include "mainwindow.h"
54 #include "kdenlivesettings.h"
55 #include "kdenlivesettingsdialog.h"
56 #include "initeffects.h"
57 #include "profilesdialog.h"
58 #include "projectsettings.h"
59 #include "events.h"
60 #include "renderjob.h"
61 #include "clipmanager.h"
62 #include "projectlist.h"
63 #include "monitor.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"
73 #include "renderer.h"
74 #include "jogshuttle.h"
75 #include "clipproperties.h"
76
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
83
84 EffectsList MainWindow::videoEffects;
85 EffectsList MainWindow::audioEffects;
86 EffectsList MainWindow::customEffects;
87 EffectsList MainWindow::transitions;
88
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");
93     parseProfiles();
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);
99
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()));
107
108     initEffects::parseEffectFiles();
109     m_monitorManager = new MonitorManager();
110
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);
116
117     effectListDock = new QDockWidget(i18n("Effect List"), this);
118     effectListDock->setObjectName("effect_list");
119     m_effectList = new EffectsListView();
120
121     //m_effectList = new KListWidget(this);
122     effectListDock->setWidget(m_effectList);
123     addDockWidget(Qt::TopDockWidgetArea, effectListDock);
124
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);
130
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);
136
137
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();
144
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);
150
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);
156
157     connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
158
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);
167
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);
173
174     setupActions();
175     tabifyDockWidget(projectListDock, effectListDock);
176     tabifyDockWidget(projectListDock, effectStackDock);
177     tabifyDockWidget(projectListDock, transitionConfigDock);
178     tabifyDockWidget(projectListDock, undoViewDock);
179     projectListDock->raise();
180
181     tabifyDockWidget(clipMonitorDock, projectMonitorDock);
182     setCentralWidget(m_timelineArea);
183
184     setupGUI(Default, NULL /*"kdenliveui.rc"*/);
185     kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
186
187     // build effects menus
188     QAction *action;
189     QMenu *videoEffectsMenu = (QMenu*)(factory()->container("video_effects_menu", this));
190     QStringList effects = videoEffects.effectNames();
191     foreach(QString name, effects) {
192         action = new QAction(name, this);
193         action->setData(name);
194         videoEffectsMenu->addAction(action);
195     }
196     QMenu *audioEffectsMenu = (QMenu*)(factory()->container("audio_effects_menu", this));
197     effects = audioEffects.effectNames();
198     foreach(QString name, effects) {
199         action = new QAction(name, this);
200         action->setData(name);
201         audioEffectsMenu->addAction(action);
202     }
203     QMenu *customEffectsMenu = (QMenu*)(factory()->container("custom_effects_menu", this));
204     effects = customEffects.effectNames();
205     foreach(QString name, effects) {
206         action = new QAction(name, this);
207         action->setData(name);
208         customEffectsMenu->addAction(action);
209     }
210
211     connect(videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
212     connect(audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
213     connect(customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
214
215     m_timelineContextMenu = new QMenu(this);
216     m_timelineContextClipMenu = new QMenu(this);
217     m_timelineContextTransitionMenu = new QMenu(this);
218
219     action = actionCollection()->action("delete_timeline_clip");
220     m_timelineContextClipMenu->addAction(action);
221     m_timelineContextClipMenu->addMenu(videoEffectsMenu);
222     m_timelineContextClipMenu->addMenu(audioEffectsMenu);
223     m_timelineContextClipMenu->addMenu(customEffectsMenu);
224
225     connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
226     connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
227     //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
228     connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
229     connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
230     m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
231     slotConnectMonitors();
232
233     setAutoSaveSettings();
234     newFile();
235
236     activateShuttleDevice();
237 }
238
239 void MainWindow::queryQuit() {
240     kDebug() << "----- SAVING CONFUIG";
241     if (queryClose()) kapp->quit();
242 }
243
244 //virtual
245 bool MainWindow::queryClose() {
246     saveOptions();
247     if (m_activeDocument && m_activeDocument->isModified()) {
248         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
249         case KMessageBox::Yes :
250             // save document here. If saving fails, return false;
251             return true;
252         case KMessageBox::No :
253             return true;
254         default: // cancel
255             return false;
256         }
257     }
258     return true;
259 }
260
261 void MainWindow::activateShuttleDevice() {
262     if (m_jogProcess) delete m_jogProcess;
263     m_jogProcess = NULL;
264     if (KdenliveSettings::enableshuttle() == false) return;
265     m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
266     connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
267     connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
268     connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
269     connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
270     connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
271     connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
272 }
273
274 void MainWindow::slotShuttleButton(int code) {
275     switch (code) {
276     case 5:
277         slotShuttleAction(KdenliveSettings::shuttle1());
278         break;
279     case 6:
280         slotShuttleAction(KdenliveSettings::shuttle2());
281         break;
282     case 7:
283         slotShuttleAction(KdenliveSettings::shuttle3());
284         break;
285     case 8:
286         slotShuttleAction(KdenliveSettings::shuttle4());
287         break;
288     case 9:
289         slotShuttleAction(KdenliveSettings::shuttle5());
290         break;
291     }
292 }
293
294 void MainWindow::slotShuttleAction(int code) {
295     switch (code) {
296     case 0:
297         return;
298     case 1:
299         m_monitorManager->slotPlay();
300         break;
301     default:
302         m_monitorManager->slotPlay();
303         break;
304     }
305 }
306
307 void MainWindow::slotFullScreen() {
308     //KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
309 }
310
311 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
312     if (!m_activeDocument) return;
313     if (effect.isNull()) {
314         kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
315         return;
316     }
317     TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
318     currentTimeLine->projectView()->slotAddEffect(effect, pos, track);
319 }
320
321 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
322     if (clipMonitor) clipMonitorDock->raise();
323     else projectMonitorDock->raise();
324 }
325
326 void MainWindow::slotSetClipDuration(int id, int duration) {
327     if (!m_activeDocument) return;
328     m_activeDocument->setProducerDuration(id, duration);
329 }
330
331 void MainWindow::slotConnectMonitors() {
332
333     m_projectList->setRenderer(m_clipMonitor->render);
334     connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
335     connect(m_projectList, SIGNAL(receivedClipDuration(int, int)), this, SLOT(slotSetClipDuration(int, int)));
336     connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
337     connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
338     connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int)));
339     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 > &)));
340 }
341
342 void MainWindow::setupActions() {
343
344     m_timecodeFormat = new KComboBox(this);
345     m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
346     m_timecodeFormat->addItem(i18n("Frames"));
347
348     statusProgressBar = new QProgressBar(this);
349     statusProgressBar->setMinimum(0);
350     statusProgressBar->setMaximum(100);
351     statusProgressBar->setMaximumWidth(150);
352     statusProgressBar->setVisible(false);
353     statusLabel = new QLabel(this);
354
355     QWidget *w = new QWidget;
356
357     QHBoxLayout *layout = new QHBoxLayout;
358     w->setLayout(layout);
359     layout->setContentsMargins(5, 0, 5, 0);
360     QToolBar *toolbar = new QToolBar("statusToolBar", this);
361     w->setMinimumHeight(34);
362
363     m_toolGroup = new QActionGroup(this);
364
365     m_buttonSelectTool = toolbar->addAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"));
366     m_buttonSelectTool->setCheckable(true);
367     m_buttonSelectTool->setChecked(true);
368
369     m_buttonRazorTool = toolbar->addAction(KIcon("edit-cut"), i18n("Razor tool"));
370     m_buttonRazorTool->setCheckable(true);
371     m_buttonRazorTool->setChecked(false);
372
373     m_toolGroup->addAction(m_buttonSelectTool);
374     m_toolGroup->addAction(m_buttonRazorTool);
375     m_toolGroup->setExclusive(true);
376     connect(m_toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
377
378     toolbar->addSeparator();
379     m_buttonFitZoom = toolbar->addAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"));
380     m_buttonFitZoom->setCheckable(false);
381     connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
382
383     m_zoomSlider = new QSlider(Qt::Horizontal, this);
384     m_zoomSlider->setMaximum(13);
385     m_zoomSlider->setMaximumHeight(34);
386     m_zoomSlider->setMaximumWidth(150);
387     m_zoomSlider->setMinimumWidth(100);
388     toolbar->addWidget(m_zoomSlider);
389
390     m_buttonVideoThumbs = toolbar->addAction(KIcon("video-mpeg"), i18n("Show videoo thumbnails"));
391     m_buttonVideoThumbs->setCheckable(true);
392     m_buttonVideoThumbs->setChecked(KdenliveSettings::audiothumbnails());
393     connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
394
395     m_buttonAudioThumbs = toolbar->addAction(KIcon("audio-mpeg"), i18n("Show audio thumbnails"));
396     m_buttonAudioThumbs->setCheckable(true);
397     m_buttonAudioThumbs->setChecked(KdenliveSettings::videothumbnails());
398     connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
399     layout->addWidget(toolbar);
400
401     statusBar()->insertPermanentWidget(0, statusProgressBar, 1);
402     statusBar()->insertPermanentWidget(1, statusLabel, 1);
403     statusBar()->insertPermanentWidget(ID_TIMELINE_BUTTONS, w);
404     statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
405     statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
406     statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
407
408     actionCollection()->addAction("select_tool", m_buttonSelectTool);
409     actionCollection()->addAction("razor_tool", m_buttonRazorTool);
410
411     KAction* clearAction = new KAction(KIcon("document-new"), i18n("Clear"), this);
412     clearAction->setShortcut(Qt::CTRL + Qt::Key_W);
413     actionCollection()->addAction("clear", clearAction);
414     /*connect(clearAction, SIGNAL(triggered(bool)),
415             textArea, SLOT(clear()));*/
416
417     KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Profiles"), this);
418     actionCollection()->addAction("manage_profiles", profilesAction);
419     connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
420
421     KAction* projectAction = new KAction(KIcon("document-new"), i18n("Project Settings"), this);
422     actionCollection()->addAction("project_settings", projectAction);
423     connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
424
425     KAction* projectRender = new KAction(KIcon("document-new"), i18n("Render Project"), this);
426     actionCollection()->addAction("project_render", projectRender);
427     connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
428
429     KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
430     monitorPlay->setShortcut(Qt::Key_Space);
431     actionCollection()->addAction("monitor_play", monitorPlay);
432     connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
433
434     KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
435     monitorSeekBackward->setShortcut(Qt::Key_J);
436     actionCollection()->addAction("monitor_seek_backward", monitorSeekBackward);
437     connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
438
439     KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
440     monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
441     actionCollection()->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
442     connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
443
444     KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
445     monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
446     actionCollection()->addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
447     connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
448
449     KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
450     monitorSeekForward->setShortcut(Qt::Key_L);
451     actionCollection()->addAction("monitor_seek_forward", monitorSeekForward);
452     connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
453
454     KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
455     monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
456     actionCollection()->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
457     connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
458
459     KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
460     monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
461     actionCollection()->addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
462     connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
463
464     KAction* deleteTimelineClip = new KAction(KIcon("edit-delete"), i18n("Delete Clip"), this);
465     deleteTimelineClip->setShortcut(Qt::Key_Delete);
466     actionCollection()->addAction("delete_timeline_clip", deleteTimelineClip);
467     connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
468
469     KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
470     cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
471     actionCollection()->addAction("cut_timeline_clip", cutTimelineClip);
472     connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
473
474     KStandardAction::quit(this, SLOT(queryQuit()),
475                           actionCollection());
476
477     KStandardAction::open(this, SLOT(openFile()),
478                           actionCollection());
479
480     m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
481                        actionCollection());
482
483     KStandardAction::save(this, SLOT(saveFile()),
484                           actionCollection());
485
486     KStandardAction::saveAs(this, SLOT(saveFileAs()),
487                             actionCollection());
488
489     KStandardAction::openNew(this, SLOT(newFile()),
490                              actionCollection());
491
492     KStandardAction::preferences(this, SLOT(slotPreferences()),
493                                  actionCollection());
494
495     KStandardAction::undo(this, SLOT(undo()),
496                           actionCollection());
497
498     KStandardAction::redo(this, SLOT(redo()),
499                           actionCollection());
500
501     KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, actionCollection());
502
503     connect(actionCollection(), SIGNAL(actionHovered(QAction*)),
504             this, SLOT(slotDisplayActionMessage(QAction*)));
505     //connect(actionCollection(), SIGNAL( clearStatusText() ),
506     //statusBar(), SLOT( clear() ) );
507
508     readOptions();
509 }
510
511 void MainWindow::undo() {
512     m_commandStack->undo();
513 }
514
515 void MainWindow::redo() {
516     m_commandStack->redo();
517 }
518
519 void MainWindow::slotDisplayActionMessage(QAction *a) {
520     statusBar()->showMessage(a->data().toString(), 3000);
521 }
522
523 void MainWindow::saveOptions() {
524     KdenliveSettings::self()->writeConfig();
525     KSharedConfigPtr config = KGlobal::config();
526     m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
527     config->sync();
528 }
529
530 void MainWindow::readOptions() {
531     KSharedConfigPtr config = KGlobal::config();
532     m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
533 }
534
535 void MainWindow::newFile() {
536     QString profileName;
537     KUrl projectFolder;
538     if (m_timelineArea->count() == 0) profileName = KdenliveSettings::default_profile();
539     else {
540         ProjectSettings *w = new ProjectSettings;
541         if (w->exec() != QDialog::Accepted) return;
542         profileName = w->selectedProfile();
543         projectFolder = w->selectedFolder();
544         delete w;
545     }
546     MltVideoProfile prof = ProfilesDialog::getVideoProfile(profileName);
547     if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
548     KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, prof, m_commandStack);
549     TrackView *trackView = new TrackView(doc, this);
550     m_timelineArea->addTab(trackView, KIcon("kdenlive"), i18n("Untitled") + " / " + prof.description);
551     if (m_timelineArea->count() == 1)
552         connectDocument(trackView, doc);
553     else m_timelineArea->setTabBarHidden(false);
554 }
555
556 void MainWindow::activateDocument() {
557     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
558     KdenliveDoc *currentDoc = currentTab->document();
559     connectDocument(currentTab, currentDoc);
560 }
561
562 void MainWindow::slotRemoveTab() {
563     QWidget *w = m_timelineArea->currentWidget();
564     // closing current document
565     int ix = m_timelineArea->currentIndex() + 1;
566     if (ix == m_timelineArea->count()) ix = 0;
567     m_timelineArea->setCurrentIndex(ix);
568     TrackView *tabToClose = (TrackView *) w;
569     KdenliveDoc *docToClose = tabToClose->document();
570     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
571     if (m_timelineArea->count() == 1) m_timelineArea->setTabBarHidden(true);
572     delete docToClose;
573     delete w;
574 }
575
576 void MainWindow::saveFileAs(const QString &outputFileName) {
577     m_projectMonitor->saveSceneList(outputFileName, m_activeDocument->documentInfoXml());
578     m_activeDocument->setUrl(KUrl(outputFileName));
579     setCaption(m_activeDocument->description());
580     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
581     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
582     m_activeDocument->setModified(false);
583 }
584
585 void MainWindow::saveFileAs() {
586     QString outputFile = KFileDialog::getSaveFileName();
587     if (QFile::exists(outputFile)) {
588         if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return;
589     }
590     saveFileAs(outputFile);
591 }
592
593 void MainWindow::saveFile() {
594     if (!m_activeDocument) return;
595     if (m_activeDocument->url().isEmpty()) {
596         saveFileAs();
597     } else {
598         saveFileAs(m_activeDocument->url().path());
599     }
600 }
601
602 void MainWindow::openFile() { //changed
603     KUrl url = KFileDialog::getOpenUrl(KUrl(), "application/vnd.kde.kdenlive;*.kdenlive");
604     if (url.isEmpty()) return;
605     m_fileOpenRecent->addUrl(url);
606     openFile(url);
607 }
608
609 void MainWindow::openFile(const KUrl &url) { //new
610     //TODO: get video profile from url before opening it
611     MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
612     if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
613     KdenliveDoc *doc = new KdenliveDoc(url, KUrl(), prof, m_commandStack);
614     TrackView *trackView = new TrackView(doc, this);
615     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
616     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
617     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
618     //connectDocument(trackView, doc);
619 }
620
621
622 void MainWindow::parseProfiles() {
623     //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
624
625     //KdenliveSettings::setDefaulttmpfolder();
626     if (KdenliveSettings::mltpath().isEmpty()) {
627         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
628     }
629     if (KdenliveSettings::rendererpath().isEmpty()) {
630         KdenliveSettings::setRendererpath(KStandardDirs::findExe("inigo"));
631     }
632     QStringList profilesFilter;
633     profilesFilter << "*";
634     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
635
636     if (profilesList.isEmpty()) {
637         // Cannot find MLT path, try finding inigo
638         QString profilePath = KdenliveSettings::rendererpath();
639         if (!profilePath.isEmpty()) {
640             profilePath = profilePath.section('/', 0, -3);
641             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
642             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
643         }
644
645         if (profilesList.isEmpty()) {
646             // Cannot find the MLT profiles, ask for location
647             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
648             getUrl->fileDialog()->setMode(KFile::Directory);
649             getUrl->exec();
650             KUrl mltPath = getUrl->selectedUrl();
651             delete getUrl;
652             if (mltPath.isEmpty()) exit(1);
653             KdenliveSettings::setMltpath(mltPath.path());
654             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
655         }
656     }
657
658     if (KdenliveSettings::rendererpath().isEmpty()) {
659         // Cannot find the MLT inigo renderer, ask for location
660         KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
661         getUrl->exec();
662         KUrl rendererPath = getUrl->selectedUrl();
663         delete getUrl;
664         if (rendererPath.isEmpty()) exit(1);
665         KdenliveSettings::setRendererpath(rendererPath.path());
666     }
667
668     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
669
670     // Parse MLT profiles to build a list of available video formats
671     if (profilesList.isEmpty()) parseProfiles();
672 }
673
674
675 void MainWindow::slotEditProfiles() {
676     ProfilesDialog *w = new ProfilesDialog;
677     w->exec();
678     delete w;
679 }
680
681 void MainWindow::slotEditProjectSettings() {
682     ProjectSettings *w = new ProjectSettings;
683     if (w->exec() == QDialog::Accepted) {
684         QString profile = w->selectedProfile();
685         m_activeDocument->setProfilePath(profile);
686         m_monitorManager->resetProfiles(profile);
687         setCaption(m_activeDocument->description());
688         KdenliveSettings::setCurrent_profile(m_activeDocument->profilePath());
689         if (m_renderWidget) m_renderWidget->setDocumentStandard(m_activeDocument->getDocumentStandard());
690         m_monitorManager->setTimecode(m_activeDocument->timecode());
691         m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
692
693         // We need to desactivate & reactivate monitors to get a refresh
694         m_monitorManager->switchMonitors();
695     }
696     delete w;
697 }
698
699 void MainWindow::slotRenderProject() {
700     if (!m_renderWidget) {
701         m_renderWidget = new RenderWidget(this);
702         connect(m_renderWidget, SIGNAL(doRender(const QString&, const QString&, const QStringList &, bool, bool)), this, SLOT(slotDoRender(const QString&, const QString&, const QStringList &, bool, bool)));
703     }
704     /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
705     if (currentTab) m_renderWidget->setTimeline(currentTab);
706     m_renderWidget->setDocument(m_activeDocument);*/
707     m_renderWidget->show();
708 }
709
710 void MainWindow::slotDoRender(const QString &dest, const QString &render, const QStringList &avformat_args, bool zoneOnly, bool playAfter) {
711     if (dest.isEmpty()) return;
712     int in;
713     int out;
714     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
715     if (currentTab && zoneOnly) {
716         in = currentTab->inPoint();
717         out = currentTab->outPoint();
718     }
719     KTemporaryFile temp;
720     temp.setAutoRemove(false);
721     temp.setSuffix(".westley");
722     if (temp.open()) {
723         m_projectMonitor->saveSceneList(temp.fileName());
724         QStringList args;
725         args << "-erase";
726         if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
727         QString videoPlayer = "-";
728         if (playAfter) videoPlayer = "kmplayer";
729         args << "inigo" << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
730         QProcess::startDetached("kdenlive_render", args);
731     }
732 }
733
734 void MainWindow::slotUpdateMousePosition(int pos) {
735     if (m_activeDocument)
736         switch (m_timecodeFormat->currentIndex()) {
737         case 0:
738             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
739             break;
740         default:
741             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
742         }
743 }
744
745 void MainWindow::slotUpdateDocumentState(bool modified) {
746     setCaption(m_activeDocument->description(), modified);
747     if (modified) {
748         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
749         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
750     } else {
751         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
752         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
753     }
754 }
755
756 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
757     //m_projectMonitor->stop();
758     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
759     if (m_activeDocument) {
760         if (m_activeDocument == doc) return;
761         m_activeDocument->backupMltPlaylist();
762         if (m_activeTimeline) {
763             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
764             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
765             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
766             disconnect(m_activeDocument, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
767             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
768             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
769             disconnect(m_activeDocument, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
770             disconnect(m_activeDocument, SIGNAL(deletTimelineClip(int)), m_activeTimeline, SLOT(slotDeleteClip(int)));
771             disconnect(m_activeDocument, SIGNAL(thumbsProgress(KUrl, int)), this, SLOT(slotGotProgressInfo(KUrl, int)));
772             disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
773             disconnect(trackView, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
774             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
775             disconnect(trackView, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
776             disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
777             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
778             disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
779             disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
780             disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool)));
781             disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
782             disconnect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
783             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
784         }
785         m_activeDocument->setRenderer(NULL);
786         disconnect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
787         m_clipMonitor->stop();
788     }
789     m_monitorManager->resetProfiles(doc->profilePath());
790     m_projectList->setDocument(doc);
791     connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
792     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
793     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
794     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
795     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
796     connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
797     connect(doc, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
798     connect(doc, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
799     connect(doc, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
800     connect(doc, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
801
802     connect(doc, SIGNAL(deletTimelineClip(int)), trackView, SLOT(slotDeleteClip(int)));
803     connect(doc, SIGNAL(thumbsProgress(KUrl, int)), this, SLOT(slotGotProgressInfo(KUrl, int)));
804     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
805
806
807
808     connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
809     connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
810     connect(trackView, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
811     connect(trackView, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
812     m_zoomSlider->setValue(trackView->currentZoom());
813     connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
814     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
815     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
816     connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
817     connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
818     connect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool)));
819     connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
820     connect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
821     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
822     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
823     m_activeTimeline = trackView;
824     KdenliveSettings::setCurrent_profile(doc->profilePath());
825     if (m_renderWidget) m_renderWidget->setDocumentStandard(doc->getDocumentStandard());
826     m_monitorManager->setTimecode(doc->timecode());
827     doc->setRenderer(m_projectMonitor->render);
828     m_commandStack->setActiveStack(doc->commandStack());
829     if (m_commandStack->isClean()) kDebug() << "////////////  UNDO STACK IS CLEAN";
830     else  kDebug() << "////////////  UNDO STACK IS NOT CLEAN*******************";
831
832     m_overView->setScene(trackView->projectScene());
833     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
834     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
835
836     setCaption(doc->description());
837     m_activeDocument = doc;
838 }
839
840 void MainWindow::slotPreferences() {
841     //An instance of your dialog could be already created and could be
842     // cached, in which case you want to display the cached dialog
843     // instead of creating another one
844     if (KConfigDialog::showDialog("settings"))
845         return;
846
847     // KConfigDialog didn't find an instance of this dialog, so lets
848     // create it :
849     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
850     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
851     dialog->show();
852 }
853
854 void MainWindow::updateConfiguration() {
855     //TODO: we should apply settings to all projects, not only the current one
856     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
857     if (currentTab) {
858         currentTab->refresh();
859         currentTab->projectView()->checkAutoScroll();
860         currentTab->projectView()->checkTrackHeight();
861         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
862     }
863     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
864     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
865     activateShuttleDevice();
866
867 }
868
869 void MainWindow::slotSwitchVideoThumbs() {
870     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
871     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
872     if (currentTab) {
873         currentTab->refresh();
874     }
875     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
876 }
877
878 void MainWindow::slotSwitchAudioThumbs() {
879     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
880     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
881     if (currentTab) {
882         currentTab->refresh();
883         currentTab->projectView()->checkAutoScroll();
884         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
885     }
886     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
887 }
888
889 void MainWindow::slotDeleteTimelineClip() {
890     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
891     if (currentTab) {
892         currentTab->projectView()->deleteSelectedClips();
893     }
894 }
895
896 void MainWindow::slotCutTimelineClip() {
897     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
898     if (currentTab) {
899         currentTab->projectView()->cutSelectedClips();
900     }
901 }
902
903 void MainWindow::slotAddProjectClip(KUrl url) {
904     if (m_activeDocument)
905         m_activeDocument->slotAddClipFile(url, QString());
906 }
907
908 void MainWindow::slotAddVideoEffect(QAction *result) {
909     if (!result) return;
910     QDomElement effect = videoEffects.getEffectByName(result->data().toString());
911     slotAddEffect(effect);
912 }
913
914 void MainWindow::slotAddAudioEffect(QAction *result) {
915     if (!result) return;
916     QDomElement effect = audioEffects.getEffectByName(result->data().toString());
917     slotAddEffect(effect);
918 }
919
920 void MainWindow::slotAddCustomEffect(QAction *result) {
921     if (!result) return;
922     QDomElement effect = customEffects.getEffectByName(result->data().toString());
923     slotAddEffect(effect);
924 }
925
926 void MainWindow::slotZoomIn() {
927     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
928 }
929
930 void MainWindow::slotZoomOut() {
931     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
932 }
933
934 void MainWindow::slotFitZoom() {
935     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
936     if (currentTab) {
937         m_zoomSlider->setValue(currentTab->fitZoom());
938     }
939 }
940
941 void MainWindow::slotGotProgressInfo(KUrl url, int progress) {
942     statusProgressBar->setValue(progress);
943     if (progress > 0) {
944         statusLabel->setText(tr("Creating Audio Thumbs"));
945         statusProgressBar->setVisible(true);
946     } else {
947         statusLabel->setText("");
948         statusProgressBar->setVisible(false);
949     }
950 }
951
952 void MainWindow::slotShowClipProperties(DocClipBase *clip) {
953     if (clip->clipType() == TEXT) {
954         m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
955         return;
956     }
957     ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
958     if (dia.exec() == QDialog::Accepted) {
959         m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
960     }
961 }
962
963 void MainWindow::customEvent(QEvent* e) {
964     if (e->type() == QEvent::User) {
965         // The timeline playing position changed...
966         kDebug() << "RECIEVED JOG EVEMNT!!!";
967     }
968 }
969 void MainWindow::slotActivateEffectStackView() {
970     effectStack->raiseWindow(effectStackDock);
971 }
972
973 void MainWindow::slotActivateTransitionView() {
974     transitionConfig->raiseWindow(transitionConfigDock);
975 }
976
977 void MainWindow::slotSnapRewind() {
978     if (m_monitorManager->projectMonitorFocused()) {
979         TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
980         currentTab->projectView()->slotSeekToPreviousSnap();
981     }
982 }
983
984 void MainWindow::slotSnapForward() {
985     if (m_monitorManager->projectMonitorFocused()) {
986         TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
987         currentTab->projectView()->slotSeekToNextSnap();
988     }
989 }
990
991 void MainWindow::slotChangeTool(QAction * action) {
992     if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
993     else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
994 }
995
996 void MainWindow::slotSetTool(PROJECTTOOL tool) {
997     if (m_activeDocument) {
998         //m_activeDocument->setTool(tool);
999         TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1000         currentTab->projectView()->setTool(tool);
1001     }
1002 }
1003
1004 #include "mainwindow.moc"