]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
Fix typo loop, fix missing i18n strings
[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 #include <stdlib.h>
21
22 #include <QTextStream>
23 #include <QTimer>
24 #include <QAction>
25 #include <QtTest>
26 #include <QtCore>
27 #include <QKeyEvent>
28
29 #include <KApplication>
30 #include <KAction>
31 #include <KLocale>
32 #include <KGlobal>
33 #include <KActionCollection>
34 #include <KStandardAction>
35 #include <KFileDialog>
36 #include <KMessageBox>
37 #include <KDebug>
38 #include <KIO/NetAccess>
39 #include <KSaveFile>
40 #include <KRuler>
41 #include <KConfigDialog>
42 #include <KXMLGUIFactory>
43 #include <KStatusBar>
44 #include <kstandarddirs.h>
45 #include <KUrlRequesterDialog>
46 #include <KTemporaryFile>
47 #include <KActionMenu>
48 #include <KMenu>
49 #include <locale.h>
50 #include <ktogglefullscreenaction.h>
51 #include <KFileItem>
52 #include <KNotification>
53 #include <KNotifyConfigWidget>
54
55 #include <mlt++/Mlt.h>
56
57 #include "mainwindow.h"
58 #include "kdenlivesettings.h"
59 #include "kdenlivesettingsdialog.h"
60 #include "initeffects.h"
61 #include "profilesdialog.h"
62 #include "projectsettings.h"
63 #include "events.h"
64 #include "clipmanager.h"
65 #include "projectlist.h"
66 #include "monitor.h"
67 #include "recmonitor.h"
68 #include "monitormanager.h"
69 #include "kdenlivedoc.h"
70 #include "trackview.h"
71 #include "customtrackview.h"
72 #include "effectslistview.h"
73 #include "effectstackview.h"
74 #include "transitionsettings.h"
75 #include "renderwidget.h"
76 #include "renderer.h"
77 #include "jogshuttle.h"
78 #include "clipproperties.h"
79 #include "wizard.h"
80 #include "editclipcommand.h"
81 #include "titlewidget.h"
82
83 static const int ID_STATUS_MSG = 1;
84 static const int ID_EDITMODE_MSG = 2;
85 static const int ID_TIMELINE_MSG = 3;
86 static const int ID_TIMELINE_BUTTONS = 5;
87 static const int ID_TIMELINE_POS = 6;
88 static const int ID_TIMELINE_FORMAT = 7;
89
90 namespace Mlt {
91 class Producer;
92 };
93
94 EffectsList MainWindow::videoEffects;
95 EffectsList MainWindow::audioEffects;
96 EffectsList MainWindow::customEffects;
97 EffectsList MainWindow::transitions;
98
99 MainWindow::MainWindow(QWidget *parent)
100         : KXmlGuiWindow(parent),
101         m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL), m_jogProcess(NULL), m_findActivated(false), m_initialized(false) {
102     setlocale(LC_NUMERIC, "POSIX");
103     setFont(KGlobalSettings::toolBarFont());
104     parseProfiles();
105     m_commandStack = new QUndoGroup;
106     m_timelineArea = new KTabWidget(this);
107     m_timelineArea->setTabReorderingEnabled(true);
108     m_timelineArea->setTabBarHidden(true);
109
110     QToolButton *closeTabButton = new QToolButton;
111     connect(closeTabButton, SIGNAL(clicked()), this, SLOT(closeCurrentDocument()));
112     closeTabButton->setIcon(KIcon("tab-close"));
113     closeTabButton->adjustSize();
114     closeTabButton->setToolTip(i18n("Close the current tab"));
115     m_timelineArea->setCornerWidget(closeTabButton);
116     connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
117
118     connect(&m_findTimer, SIGNAL(timeout()), this, SLOT(findTimeout()));
119     m_findTimer.setSingleShot(true);
120
121     initEffects::parseEffectFiles();
122     //initEffects::parseCustomEffectsFile();
123
124     m_monitorManager = new MonitorManager();
125
126     projectListDock = new QDockWidget(i18n("Project Tree"), this);
127     projectListDock->setObjectName("project_tree");
128     m_projectList = new ProjectList(this);
129     projectListDock->setWidget(m_projectList);
130     addDockWidget(Qt::TopDockWidgetArea, projectListDock);
131
132     effectListDock = new QDockWidget(i18n("Effect List"), this);
133     effectListDock->setObjectName("effect_list");
134     m_effectList = new EffectsListView();
135
136     //m_effectList = new KListWidget(this);
137     effectListDock->setWidget(m_effectList);
138     addDockWidget(Qt::TopDockWidgetArea, effectListDock);
139
140     effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
141     effectStackDock->setObjectName("effect_stack");
142     effectStack = new EffectStackView(this);
143     effectStackDock->setWidget(effectStack);
144     addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
145
146     transitionConfigDock = new QDockWidget(i18n("Transition"), this);
147     transitionConfigDock->setObjectName("transition");
148     transitionConfig = new TransitionSettings(this);
149     transitionConfigDock->setWidget(transitionConfig);
150     addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
151
152     KdenliveSettings::setCurrent_profile(KdenliveSettings::default_profile());
153     m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
154                        actionCollection());
155     readOptions();
156
157     clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
158     clipMonitorDock->setObjectName("clip_monitor");
159     m_clipMonitor = new Monitor("clip", m_monitorManager, this);
160     clipMonitorDock->setWidget(m_clipMonitor);
161     addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
162     //m_clipMonitor->stop();
163
164     projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
165     projectMonitorDock->setObjectName("project_monitor");
166     m_projectMonitor = new Monitor("project", m_monitorManager, this);
167     projectMonitorDock->setWidget(m_projectMonitor);
168     addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
169
170     recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
171     recMonitorDock->setObjectName("record_monitor");
172     m_recMonitor = new RecMonitor("record", this);
173     recMonitorDock->setWidget(m_recMonitor);
174     addDockWidget(Qt::TopDockWidgetArea, recMonitorDock);
175
176     connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
177     connect(m_recMonitor, SIGNAL(showConfigDialog(int, int)), this, SLOT(slotPreferences(int, int)));
178
179     undoViewDock = new QDockWidget(i18n("Undo History"), this);
180     undoViewDock->setObjectName("undo_history");
181     m_undoView = new QUndoView(this);
182     m_undoView->setCleanIcon(KIcon("edit-clear"));
183     m_undoView->setEmptyLabel(i18n("Clean"));
184     undoViewDock->setWidget(m_undoView);
185     m_undoView->setGroup(m_commandStack);
186     addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
187
188     //overviewDock = new QDockWidget(i18n("Project Overview"), this);
189     //overviewDock->setObjectName("project_overview");
190     //m_overView = new CustomTrackView(NULL, NULL, this);
191     //overviewDock->setWidget(m_overView);
192     //addDockWidget(Qt::TopDockWidgetArea, overviewDock);
193
194     setupActions();
195     //tabifyDockWidget(projectListDock, effectListDock);
196     tabifyDockWidget(projectListDock, effectStackDock);
197     tabifyDockWidget(projectListDock, transitionConfigDock);
198     //tabifyDockWidget(projectListDock, undoViewDock);
199
200
201     tabifyDockWidget(clipMonitorDock, projectMonitorDock);
202     tabifyDockWidget(clipMonitorDock, recMonitorDock);
203     setCentralWidget(m_timelineArea);
204
205     setupGUI(Default, NULL /*"kdenliveui.rc"*/);
206     kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
207
208     // build effects menus
209     QAction *action;
210     QMenu *videoEffectsMenu = static_cast<QMenu*>(factory()->container("video_effects_menu", this));
211     QStringList effects = videoEffects.effectNames();
212     foreach(const QString &name, effects) {
213         action = new QAction(name, this);
214         action->setData(name);
215         videoEffectsMenu->addAction(action);
216     }
217     QMenu *audioEffectsMenu = static_cast<QMenu*>(factory()->container("audio_effects_menu", this));
218     effects = audioEffects.effectNames();
219     foreach(const QString &name, effects) {
220         action = new QAction(name, this);
221         action->setData(name);
222         audioEffectsMenu->addAction(action);
223     }
224     m_customEffectsMenu = static_cast<QMenu*>(factory()->container("custom_effects_menu", this));
225     effects = customEffects.effectNames();
226     if (effects.isEmpty()) m_customEffectsMenu->setEnabled(false);
227     else m_customEffectsMenu->setEnabled(true);
228
229     foreach(const QString &name, effects) {
230         action = new QAction(name, this);
231         action->setData(name);
232         m_customEffectsMenu->addAction(action);
233     }
234
235     QMenu *viewMenu = static_cast<QMenu*>(factory()->container("dockwindows", this));
236     const QList<QAction *> viewActions = createPopupMenu()->actions();
237     viewMenu->insertActions(NULL, viewActions);
238
239     connect(videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
240     connect(audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
241     connect(m_customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
242
243     m_timelineContextMenu = new QMenu(this);
244     m_timelineContextClipMenu = new QMenu(this);
245     m_timelineContextTransitionMenu = new QMenu(this);
246
247
248     QMenu *transitionsMenu = new QMenu(i18n("Add Transition"), this);
249     effects = transitions.effectNames();
250     foreach(const QString &name, effects) {
251         action = new QAction(name, this);
252         action->setData(name);
253         transitionsMenu->addAction(action);
254     }
255     connect(transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
256
257     m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));
258
259     m_timelineContextClipMenu->addAction(actionCollection()->action("delete_timeline_clip"));
260     m_timelineContextClipMenu->addAction(actionCollection()->action("change_clip_speed"));
261     m_timelineContextClipMenu->addAction(actionCollection()->action("cut_timeline_clip"));
262     m_timelineContextClipMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
263     m_timelineContextClipMenu->addAction(actionCollection()->action("paste_effects"));
264
265     QMenu *markersMenu = (QMenu*)(factory()->container("marker_menu", this));
266     m_timelineContextClipMenu->addMenu(markersMenu);
267     m_timelineContextClipMenu->addMenu(transitionsMenu);
268     m_timelineContextClipMenu->addMenu(videoEffectsMenu);
269     m_timelineContextClipMenu->addMenu(audioEffectsMenu);
270     //TODO: re-enable custom effects menu when it is implemented
271     m_timelineContextClipMenu->addMenu(m_customEffectsMenu);
272
273     m_timelineContextTransitionMenu->addAction(actionCollection()->action("delete_timeline_clip"));
274     m_timelineContextTransitionMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
275
276     connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
277     connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
278     //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
279     connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
280     connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
281     connect(m_effectList, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
282
283     m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
284     slotConnectMonitors();
285
286     setAutoSaveSettings();
287
288     if (KdenliveSettings::openlastproject()) {
289         openLastFile();
290     } else {
291         /*QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::allStaleFiles();
292         if (!staleFiles.isEmpty()) {
293             if (KMessageBox::questionYesNo(this, i18n("Auto-saved files exist. Do you want to recover them now?"), i18n("File Recovery"), KGuiItem(i18n("Recover")), KGuiItem(i18n("Don't recover"))) == KMessageBox::Yes) {
294          recoverFiles(staleFiles);
295             }
296             else newFile();
297         }
298         else*/
299         newFile();
300     }
301
302     activateShuttleDevice();
303     projectListDock->raise();
304 }
305
306 void MainWindow::queryQuit() {
307     kDebug() << "----- SAVING CONFUIG";
308     if (queryClose()) kapp->quit();
309 }
310
311 //virtual
312 bool MainWindow::queryClose() {
313     saveOptions();
314     if (m_activeDocument && m_activeDocument->isModified()) {
315         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
316         case KMessageBox::Yes :
317             // save document here. If saving fails, return false;
318             saveFile();
319             return true;
320         case KMessageBox::No :
321             return true;
322         default: // cancel
323             return false;
324         }
325     }
326     return true;
327 }
328
329 void MainWindow::saveProperties(KConfig*) {
330     // save properties here,used by session management
331     saveFile();
332 }
333
334
335 void MainWindow::readProperties(KConfig *config) {
336     // read properties here,used by session management
337     QString Lastproject = config->group("Recent Files").readPathEntry("File1", QString());
338     openFile(KUrl(Lastproject));
339 }
340
341 void MainWindow::slotReloadEffects() {
342     initEffects::parseCustomEffectsFile();
343     m_customEffectsMenu->clear();
344     const QStringList effects = customEffects.effectNames();
345     QAction *action;
346     if (effects.isEmpty()) m_customEffectsMenu->setEnabled(false);
347     else m_customEffectsMenu->setEnabled(true);
348
349     foreach(const QString &name, effects) {
350         action = new QAction(name, this);
351         action->setData(name);
352         m_customEffectsMenu->addAction(action);
353     }
354     m_effectList->reloadEffectList();
355 }
356
357 void MainWindow::activateShuttleDevice() {
358     if (m_jogProcess) delete m_jogProcess;
359     m_jogProcess = NULL;
360     if (KdenliveSettings::enableshuttle() == false) return;
361     m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
362     connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
363     connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
364     connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
365     connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
366     connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
367     connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
368 }
369
370 void MainWindow::slotShuttleButton(int code) {
371     switch (code) {
372     case 5:
373         slotShuttleAction(KdenliveSettings::shuttle1());
374         break;
375     case 6:
376         slotShuttleAction(KdenliveSettings::shuttle2());
377         break;
378     case 7:
379         slotShuttleAction(KdenliveSettings::shuttle3());
380         break;
381     case 8:
382         slotShuttleAction(KdenliveSettings::shuttle4());
383         break;
384     case 9:
385         slotShuttleAction(KdenliveSettings::shuttle5());
386         break;
387     }
388 }
389
390 void MainWindow::slotShuttleAction(int code) {
391     switch (code) {
392     case 0:
393         return;
394     case 1:
395         m_monitorManager->slotPlay();
396         break;
397     default:
398         m_monitorManager->slotPlay();
399         break;
400     }
401 }
402
403 void MainWindow::configureNotifications() {
404     KNotifyConfigWidget::configure(this);
405 }
406
407 void MainWindow::slotFullScreen() {
408     //KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
409 }
410
411 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
412     if (!m_activeDocument) return;
413     if (effect.isNull()) {
414         kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
415         return;
416     }
417     TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
418     currentTimeLine->projectView()->slotAddEffect(effect, pos, track);
419 }
420
421 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
422     if (clipMonitor) clipMonitorDock->raise();
423     else projectMonitorDock->raise();
424 }
425
426 void MainWindow::slotSetClipDuration(const QString &id, int duration) {
427     if (!m_activeDocument) return;
428     m_activeDocument->setProducerDuration(id, duration);
429 }
430
431 void MainWindow::slotConnectMonitors() {
432
433     m_projectList->setRenderer(m_clipMonitor->render);
434     connect(m_projectList, SIGNAL(receivedClipDuration(const QString &, int)), this, SLOT(slotSetClipDuration(const QString &, int)));
435     connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
436     connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, const QString &)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, const QString &)));
437     connect(m_clipMonitor->render, SIGNAL(replyGetImage(const QString &, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(const QString &, int, const QPixmap &, int, int)));
438     connect(m_clipMonitor->render, SIGNAL(replyGetFileProperties(const QString &, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(const QString &, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &)));
439
440     connect(m_clipMonitor->render, SIGNAL(removeInvalidClip(const QString &)), m_projectList, SLOT(slotRemoveInvalidClip(const QString &)));
441
442     connect(m_clipMonitor, SIGNAL(refreshClipThumbnail(const QString &)), m_projectList, SLOT(slotRefreshClipThumbnail(const QString &)));
443
444     connect(m_clipMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustClipMonitor()));
445     connect(m_projectMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustProjectMonitor()));
446
447     connect(m_clipMonitor, SIGNAL(saveZone(Render *, QPoint)), this, SLOT(slotSaveZone(Render *, QPoint)));
448     connect(m_projectMonitor, SIGNAL(saveZone(Render *, QPoint)), this, SLOT(slotSaveZone(Render *, QPoint)));
449 }
450
451 void MainWindow::slotAdjustClipMonitor() {
452     clipMonitorDock->updateGeometry();
453     clipMonitorDock->adjustSize();
454     m_clipMonitor->resetSize();
455 }
456
457 void MainWindow::slotAdjustProjectMonitor() {
458     projectMonitorDock->updateGeometry();
459     projectMonitorDock->adjustSize();
460     m_projectMonitor->resetSize();
461 }
462
463 void MainWindow::setupActions() {
464
465     KActionCollection* collection = actionCollection();
466     m_timecodeFormat = new KComboBox(this);
467     m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
468     m_timecodeFormat->addItem(i18n("Frames"));
469
470     statusProgressBar = new QProgressBar(this);
471     statusProgressBar->setMinimum(0);
472     statusProgressBar->setMaximum(100);
473     statusProgressBar->setMaximumWidth(150);
474     statusProgressBar->setVisible(false);
475
476     QWidget *w = new QWidget;
477
478     QHBoxLayout *layout = new QHBoxLayout;
479     w->setLayout(layout);
480     layout->setContentsMargins(5, 0, 5, 0);
481     QToolBar *toolbar = new QToolBar("statusToolBar", this);
482
483
484     m_toolGroup = new QActionGroup(this);
485
486     QString style1 = "QToolButton {background-color: rgba(230, 230, 230, 220); border-style: inset; border:1px solid #999999;border-radius: 3px;margin: 0px 3px;padding: 0px;} QToolButton:checked { background-color: rgba(224, 224, 0, 100); border-style: inset; border:1px solid #cc6666;border-radius: 3px;}";
487
488     m_buttonSelectTool = toolbar->addAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"));
489     m_buttonSelectTool->setCheckable(true);
490     m_buttonSelectTool->setChecked(true);
491
492     m_buttonRazorTool = toolbar->addAction(KIcon("edit-cut"), i18n("Razor tool"));
493     m_buttonRazorTool->setCheckable(true);
494     m_buttonRazorTool->setChecked(false);
495
496     m_toolGroup->addAction(m_buttonSelectTool);
497     m_toolGroup->addAction(m_buttonRazorTool);
498     m_toolGroup->setExclusive(true);
499     toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
500
501     QWidget * actionWidget;
502     actionWidget = toolbar->widgetForAction(m_buttonSelectTool);
503     actionWidget->setMaximumWidth(24);
504     actionWidget->setMinimumHeight(17);
505
506     actionWidget = toolbar->widgetForAction(m_buttonRazorTool);
507     actionWidget->setMaximumWidth(24);
508     actionWidget->setMinimumHeight(17);
509
510     toolbar->setStyleSheet(style1);
511     connect(m_toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
512
513     toolbar->addSeparator();
514     m_buttonFitZoom = toolbar->addAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"));
515     m_buttonFitZoom->setCheckable(false);
516     connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
517
518     actionWidget = toolbar->widgetForAction(m_buttonFitZoom);
519     actionWidget->setMaximumWidth(24);
520     actionWidget->setMinimumHeight(17);
521
522     m_zoomSlider = new QSlider(Qt::Horizontal, this);
523     m_zoomSlider->setMaximum(13);
524     m_zoomSlider->setPageStep(1);
525
526     m_zoomSlider->setMaximumWidth(150);
527     m_zoomSlider->setMinimumWidth(100);
528
529     const int contentHeight = QFontMetrics(w->font()).height() + 8;
530
531     QString style = "QSlider::groove:horizontal { background-color: rgba(230, 230, 230, 220);border: 1px solid #999999;height: 8px;border-radius: 3px;margin-top:3px }";
532     style.append("QSlider::handle:horizontal {  background-color: white; border: 1px solid #999999;width: 9px;margin: -2px 0;border-radius: 3px; }");
533
534     m_zoomSlider->setStyleSheet(style);
535
536     //m_zoomSlider->height() + 5;
537     statusBar()->setMinimumHeight(contentHeight);
538
539
540     toolbar->addWidget(m_zoomSlider);
541
542     m_buttonVideoThumbs = toolbar->addAction(KIcon("kdenlive-show-videothumb"), i18n("Show video thumbnails"));
543     m_buttonVideoThumbs->setCheckable(true);
544     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
545     connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
546
547     m_buttonAudioThumbs = toolbar->addAction(KIcon("kdenlive-show-audiothumb"), i18n("Show audio thumbnails"));
548     m_buttonAudioThumbs->setCheckable(true);
549     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
550     connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
551
552     m_buttonShowMarkers = toolbar->addAction(KIcon("kdenlive-show-markers"), i18n("Show markers comments"));
553     m_buttonShowMarkers->setCheckable(true);
554     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
555     connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
556
557     m_buttonSnap = toolbar->addAction(KIcon("kdenlive-snap"), i18n("Snap"));
558     m_buttonSnap->setCheckable(true);
559     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
560     connect(m_buttonSnap, SIGNAL(triggered()), this, SLOT(slotSwitchSnap()));
561     layout->addWidget(toolbar);
562
563
564     actionWidget = toolbar->widgetForAction(m_buttonVideoThumbs);
565     actionWidget->setMaximumWidth(24);
566     actionWidget->setMinimumHeight(17);
567
568     actionWidget = toolbar->widgetForAction(m_buttonAudioThumbs);
569     actionWidget->setMaximumWidth(24);
570     actionWidget->setMinimumHeight(17);
571
572     actionWidget = toolbar->widgetForAction(m_buttonShowMarkers);
573     actionWidget->setMaximumWidth(24);
574     actionWidget->setMinimumHeight(17);
575
576     actionWidget = toolbar->widgetForAction(m_buttonSnap);
577     actionWidget->setMaximumWidth(24);
578     actionWidget->setMinimumHeight(17);
579
580     m_messageLabel = new StatusBarMessageLabel(this);
581     m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
582
583     statusBar()->addWidget(m_messageLabel, 10);
584     statusBar()->addWidget(statusProgressBar, 0);
585     statusBar()->insertPermanentWidget(ID_TIMELINE_BUTTONS, w);
586     statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
587     statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
588     statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
589     m_messageLabel->hide();
590
591     collection->addAction("select_tool", m_buttonSelectTool);
592     collection->addAction("razor_tool", m_buttonRazorTool);
593
594     collection->addAction("show_video_thumbs", m_buttonVideoThumbs);
595     collection->addAction("show_audio_thumbs", m_buttonAudioThumbs);
596     collection->addAction("show_markers", m_buttonShowMarkers);
597     collection->addAction("snap", m_buttonSnap);
598     collection->addAction("zoom_fit", m_buttonFitZoom);
599
600     m_projectSearch = new KAction(KIcon("edit-find"), i18n("Find"), this);
601     collection->addAction("project_find", m_projectSearch);
602     connect(m_projectSearch, SIGNAL(triggered(bool)), this, SLOT(slotFind()));
603     m_projectSearch->setShortcut(Qt::Key_Slash);
604
605     m_projectSearchNext = new KAction(KIcon("go-down-search"), i18n("Find Next"), this);
606     collection->addAction("project_find_next", m_projectSearchNext);
607     connect(m_projectSearchNext, SIGNAL(triggered(bool)), this, SLOT(slotFindNext()));
608     m_projectSearchNext->setShortcut(Qt::Key_F3);
609     m_projectSearchNext->setEnabled(false);
610
611     KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Profiles"), this);
612     collection->addAction("manage_profiles", profilesAction);
613     connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
614
615     KAction* projectAction = new KAction(KIcon("configure"), i18n("Project Settings"), this);
616     collection->addAction("project_settings", projectAction);
617     connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
618
619     KAction* projectRender = new KAction(KIcon("media-record"), i18n("Render"), this);
620     collection->addAction("project_render", projectRender);
621     connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
622
623     KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
624     KShortcut playShortcut;
625     playShortcut.setPrimary(Qt::Key_Space);
626     playShortcut.setAlternate(Qt::Key_K);
627     monitorPlay->setShortcut(playShortcut);
628     collection->addAction("monitor_play", monitorPlay);
629     connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
630
631     KAction *markIn = collection->addAction("mark_in");
632     markIn->setText(i18n("Set In Point"));
633     markIn->setShortcut(Qt::Key_I);
634     connect(markIn, SIGNAL(triggered(bool)), this, SLOT(slotSetInPoint()));
635
636     KAction *markOut = collection->addAction("mark_out");
637     markOut->setText(i18n("Set Out Point"));
638     markOut->setShortcut(Qt::Key_O);
639     connect(markOut, SIGNAL(triggered(bool)), this, SLOT(slotSetOutPoint()));
640
641     KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
642     monitorSeekBackward->setShortcut(Qt::Key_J);
643     collection->addAction("monitor_seek_backward", monitorSeekBackward);
644     connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
645
646     KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
647     monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
648     collection->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
649     connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
650
651     KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
652     monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
653     collection->addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
654     connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
655
656     KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
657     monitorSeekForward->setShortcut(Qt::Key_L);
658     collection->addAction("monitor_seek_forward", monitorSeekForward);
659     connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
660
661     KAction* clipStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Clip Start"), this);
662     clipStart->setShortcut(Qt::Key_Home);
663     collection->addAction("seek_clip_start", clipStart);
664     connect(clipStart, SIGNAL(triggered(bool)), this, SLOT(slotClipStart()));
665
666     KAction* clipEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Clip End"), this);
667     clipEnd->setShortcut(Qt::Key_End);
668     collection->addAction("seek_clip_end", clipEnd);
669     connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
670
671     KAction* projectStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Project Start"), this);
672     projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
673     collection->addAction("seek_start", projectStart);
674     connect(projectStart, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotStart()));
675
676     KAction* projectEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Project End"), this);
677     projectEnd->setShortcut(Qt::CTRL + Qt::Key_End);
678     collection->addAction("seek_end", projectEnd);
679     connect(projectEnd, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotEnd()));
680
681     KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
682     monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
683     collection->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
684     connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
685
686     KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
687     monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
688     collection->addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
689     connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
690
691     KAction* deleteTimelineClip = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
692     deleteTimelineClip->setShortcut(Qt::Key_Delete);
693     collection->addAction("delete_timeline_clip", deleteTimelineClip);
694     connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
695
696     KAction* editTimelineClipSpeed = new KAction(KIcon("edit-delete"), i18n("Change Clip Speed"), this);
697     collection->addAction("change_clip_speed", editTimelineClipSpeed);
698     connect(editTimelineClipSpeed, SIGNAL(triggered(bool)), this, SLOT(slotChangeClipSpeed()));
699
700     KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
701     cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
702     collection->addAction("cut_timeline_clip", cutTimelineClip);
703     connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
704
705     KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker to Clip"), this);
706     collection->addAction("add_clip_marker", addClipMarker);
707     connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
708
709     KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker from Clip"), this);
710     collection->addAction("delete_clip_marker", deleteClipMarker);
711     connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
712
713     KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers from Clip"), this);
714     collection->addAction("delete_all_clip_markers", deleteAllClipMarkers);
715     connect(deleteAllClipMarkers, SIGNAL(triggered(bool)), this, SLOT(slotDeleteAllClipMarkers()));
716
717     KAction* editClipMarker = new KAction(KIcon("document-properties"), i18n("Edit Marker"), this);
718     collection->addAction("edit_clip_marker", editClipMarker);
719     connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker()));
720
721     KAction *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
722     collection->addAction("add_guide", addGuide);
723     connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
724
725     QAction *delGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
726     collection->addAction("delete_guide", delGuide);
727     connect(delGuide, SIGNAL(triggered()), this, SLOT(slotDeleteGuide()));
728
729     QAction *editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
730     collection->addAction("edit_guide", editGuide);
731     connect(editGuide, SIGNAL(triggered()), this, SLOT(slotEditGuide()));
732
733     QAction *delAllGuides = new KAction(KIcon("edit-delete"), i18n("Delete All Guides"), this);
734     collection->addAction("delete_all_guides", delAllGuides);
735     connect(delAllGuides, SIGNAL(triggered()), this, SLOT(slotDeleteAllGuides()));
736
737     QAction *pasteEffects = new KAction(KIcon("edit-paste"), i18n("Paste Effects"), this);
738     collection->addAction("paste_effects", pasteEffects);
739     connect(pasteEffects , SIGNAL(triggered()), this, SLOT(slotPasteEffects()));
740
741     KStandardAction::quit(this, SLOT(queryQuit()),
742                           collection);
743
744     KStandardAction::open(this, SLOT(openFile()),
745                           collection);
746
747     m_saveAction = KStandardAction::save(this, SLOT(saveFile()),
748                                          collection);
749
750     KStandardAction::saveAs(this, SLOT(saveFileAs()),
751                             collection);
752
753     KStandardAction::openNew(this, SLOT(newFile()),
754                              collection);
755
756     KStandardAction::preferences(this, SLOT(slotPreferences()),
757                                  collection);
758
759     KStandardAction::configureNotifications(this , SLOT(configureNotifications()) , collection);
760
761     KStandardAction::copy(this, SLOT(slotCopy()),
762                           collection);
763
764     KStandardAction::paste(this, SLOT(slotPaste()),
765                            collection);
766
767     KAction *undo = KStandardAction::undo(m_commandStack, SLOT(undo()),
768                                           collection);
769     undo->setEnabled(false);
770     connect(m_commandStack, SIGNAL(canUndoChanged(bool)), undo, SLOT(setEnabled(bool)));
771
772     KAction *redo = KStandardAction::redo(m_commandStack, SLOT(redo()),
773                                           collection);
774     redo->setEnabled(false);
775     connect(m_commandStack, SIGNAL(canRedoChanged(bool)), redo, SLOT(setEnabled(bool)));
776
777     KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, collection);
778
779     connect(collection, SIGNAL(actionHovered(QAction*)),
780             this, SLOT(slotDisplayActionMessage(QAction*)));
781     //connect(collection, SIGNAL( clearStatusText() ),
782     //statusBar(), SLOT( clear() ) );
783 }
784
785 void MainWindow::slotDisplayActionMessage(QAction *a) {
786     statusBar()->showMessage(a->data().toString(), 3000);
787 }
788
789 void MainWindow::saveOptions() {
790     KdenliveSettings::self()->writeConfig();
791     KSharedConfigPtr config = KGlobal::config();
792     m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
793     config->sync();
794 }
795
796 void MainWindow::readOptions() {
797     KSharedConfigPtr config = KGlobal::config();
798     m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
799     KConfigGroup initialGroup(config, "version");
800     if (!initialGroup.exists()) {
801         // this is our first run, show Wizard
802         Wizard *w = new Wizard(this);
803         if (w->exec() == QDialog::Accepted && w->isOk()) {
804             w->adjustSettings();
805             initialGroup.writeEntry("version", "0.7");
806             delete w;
807         } else {
808             ::exit(1);
809         }
810     }
811 }
812
813 void MainWindow::newFile() {
814     QString profileName;
815     KUrl projectFolder;
816     QPoint projectTracks(3, 2);
817     if (m_timelineArea->count() == 0) profileName = KdenliveSettings::default_profile();
818     else {
819         ProjectSettings *w = new ProjectSettings;
820         if (w->exec() != QDialog::Accepted) return;
821         profileName = w->selectedProfile();
822         projectFolder = w->selectedFolder();
823         projectTracks = w->tracks();
824         delete w;
825     }
826     KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, profileName, projectTracks,  this);
827     doc->m_autosave = new KAutoSaveFile(KUrl(), doc);
828     TrackView *trackView = new TrackView(doc, this);
829     m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
830     if (m_timelineArea->count() == 1) {
831         connectDocumentInfo(doc);
832         connectDocument(trackView, doc);
833     } else m_timelineArea->setTabBarHidden(false);
834 }
835
836 void MainWindow::activateDocument() {
837     if (m_timelineArea->currentWidget() == NULL) return;
838     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
839     KdenliveDoc *currentDoc = currentTab->document();
840     connectDocumentInfo(currentDoc);
841     connectDocument(currentTab, currentDoc);
842 }
843
844 void MainWindow::closeCurrentDocument() {
845     QWidget *w = m_timelineArea->currentWidget();
846     // closing current document
847     int ix = m_timelineArea->currentIndex() + 1;
848     if (ix == m_timelineArea->count()) ix = 0;
849     m_timelineArea->setCurrentIndex(ix);
850     TrackView *tabToClose = (TrackView *) w;
851     KdenliveDoc *docToClose = tabToClose->document();
852     if (docToClose && docToClose->isModified()) {
853         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
854         case KMessageBox::Yes :
855             // save document here. If saving fails, return false;
856             saveFile();
857             break;
858         case KMessageBox::Cancel :
859             return;
860         default:
861             break;
862         }
863     }
864     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
865     if (m_timelineArea->count() == 1) m_timelineArea->setTabBarHidden(true);
866     delete docToClose;
867     delete w;
868     if (m_timelineArea->count() == 0) m_activeDocument = NULL;
869 }
870
871 void MainWindow::saveFileAs(const QString &outputFileName) {
872     m_projectMonitor->saveSceneList(outputFileName, m_activeDocument->documentInfoXml());
873     m_activeDocument->setUrl(KUrl(outputFileName));
874     if (m_activeDocument->m_autosave == NULL) {
875         m_activeDocument->m_autosave = new KAutoSaveFile(KUrl(outputFileName), this);
876     } else m_activeDocument->m_autosave->setManagedFile(KUrl(outputFileName));
877     setCaption(m_activeDocument->description());
878     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
879     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
880     m_activeDocument->setModified(false);
881     m_fileOpenRecent->addUrl(KUrl(outputFileName));
882 }
883
884 void MainWindow::saveFileAs() {
885     QString outputFile = KFileDialog::getSaveFileName(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)");
886     if (QFile::exists(outputFile)) {
887         if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return;
888     }
889     saveFileAs(outputFile);
890 }
891
892 void MainWindow::saveFile() {
893     if (!m_activeDocument) return;
894     if (m_activeDocument->url().isEmpty()) {
895         saveFileAs();
896     } else {
897         saveFileAs(m_activeDocument->url().path());
898         m_activeDocument->m_autosave->resize(0);
899     }
900 }
901
902 void MainWindow::openFile() {
903     KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)\n*.westley|MLT project files (*.westley)");
904     if (url.isEmpty()) return;
905     m_fileOpenRecent->addUrl(url);
906     openFile(url);
907 }
908
909 void MainWindow::openLastFile() {
910     KSharedConfigPtr config = KGlobal::config();
911     KUrl::List urls = m_fileOpenRecent->urls();
912     if (urls.isEmpty()) newFile();
913     else openFile(urls.last());
914 }
915
916 void MainWindow::openFile(const KUrl &url) {
917     // Check for backup file
918     QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::staleFiles(url);
919     if (!staleFiles.isEmpty()) {
920         if (KMessageBox::questionYesNo(this,
921                                        i18n("Auto-saved files exist. Do you want to recover them now?"),
922                                        i18n("File Recovery"),
923                                        KGuiItem(i18n("Recover")), KGuiItem(i18n("Don't recover"))) == KMessageBox::Yes) {
924             recoverFiles(staleFiles);
925             return;
926         } else {
927             // remove the stale files
928             foreach(KAutoSaveFile *stale, staleFiles) {
929                 stale->open(QIODevice::ReadWrite);
930                 delete stale;
931             }
932         }
933     }
934     if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
935     doOpenFile(url, NULL);
936 }
937
938 void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale) {
939     KdenliveDoc *doc;
940     doc = new KdenliveDoc(url, KUrl(), m_commandStack, QString(), QPoint(3, 2), this);
941     if (stale == NULL) {
942         stale = new KAutoSaveFile(url, doc);
943         doc->m_autosave = stale;
944     } else {
945         doc->m_autosave = stale;
946         doc->setUrl(stale->managedFile());
947         doc->setModified(true);
948         stale->setParent(doc);
949     }
950     connectDocumentInfo(doc);
951     TrackView *trackView = new TrackView(doc, this);
952     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
953     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
954     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
955     slotGotProgressInfo(QString(), -1);
956     m_clipMonitor->refreshMonitor(true);
957 }
958
959 void MainWindow::recoverFiles(QList<KAutoSaveFile *> staleFiles) {
960     if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
961     foreach(KAutoSaveFile *stale, staleFiles) {
962         /*if (!stale->open(QIODevice::QIODevice::ReadOnly)) {
963                   // show an error message; we could not steal the lockfile
964                   // maybe another application got to the file before us?
965                   delete stale;
966                   continue;
967         }*/
968         kDebug() << "// OPENING RECOVERY: " << stale->fileName() << "\nMANAGED: " << stale->managedFile().path();
969         // the stalefiles also contain ".lock" files so we must ignore them... bug in KAutoSaveFile ?
970         if (!stale->fileName().endsWith(".lock")) doOpenFile(KUrl(stale->fileName()), stale);
971         else KIO::NetAccess::del(KUrl(stale->fileName()), this);
972     }
973 }
974
975
976 void MainWindow::parseProfiles() {
977     //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
978
979     //KdenliveSettings::setDefaulttmpfolder();
980     if (KdenliveSettings::mltpath().isEmpty()) {
981         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
982     }
983     if (KdenliveSettings::rendererpath().isEmpty()) {
984         QString inigoPath = QString(MLT_PREFIX) + QString("/bin/inigo");
985         if (!QFile::exists(inigoPath))
986             inigoPath = KStandardDirs::findExe("inigo");
987         else KdenliveSettings::setRendererpath(inigoPath);
988     }
989     QStringList profilesFilter;
990     profilesFilter << "*";
991     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
992
993     if (profilesList.isEmpty()) {
994         // Cannot find MLT path, try finding inigo
995         QString profilePath = KdenliveSettings::rendererpath();
996         if (!profilePath.isEmpty()) {
997             profilePath = profilePath.section('/', 0, -3);
998             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
999             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1000         }
1001
1002         if (profilesList.isEmpty()) {
1003             // Cannot find the MLT profiles, ask for location
1004             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
1005             getUrl->fileDialog()->setMode(KFile::Directory);
1006             if (getUrl->exec() == QDialog::Rejected) {
1007                 ::exit(0);
1008             }
1009             KUrl mltPath = getUrl->selectedUrl();
1010             delete getUrl;
1011             if (mltPath.isEmpty()) ::exit(0);
1012             KdenliveSettings::setMltpath(mltPath.path());
1013             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1014         }
1015     }
1016
1017     if (KdenliveSettings::rendererpath().isEmpty()) {
1018         // Cannot find the MLT inigo renderer, ask for location
1019         KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(QString(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
1020         if (getUrl->exec() == QDialog::Rejected) {
1021             ::exit(0);
1022         }
1023         KUrl rendererPath = getUrl->selectedUrl();
1024         delete getUrl;
1025         if (rendererPath.isEmpty()) ::exit(0);
1026         KdenliveSettings::setRendererpath(rendererPath.path());
1027     }
1028
1029     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
1030
1031     // Parse MLT profiles to build a list of available video formats
1032     if (profilesList.isEmpty()) parseProfiles();
1033 }
1034
1035
1036 void MainWindow::slotEditProfiles() {
1037     ProfilesDialog *w = new ProfilesDialog;
1038     w->exec();
1039     delete w;
1040 }
1041
1042 void MainWindow::slotEditProjectSettings() {
1043     ProjectSettings *w = new ProjectSettings;
1044     if (w->exec() == QDialog::Accepted) {
1045         QString profile = w->selectedProfile();
1046         m_activeDocument->setProfilePath(profile);
1047         KdenliveSettings::setCurrent_profile(profile);
1048         KdenliveSettings::setProject_fps(m_activeDocument->fps());
1049         setCaption(m_activeDocument->description(), m_activeDocument->isModified());
1050         m_monitorManager->resetProfiles(m_activeDocument->timecode());
1051         if (m_renderWidget) m_renderWidget->setDocumentStandard(m_activeDocument->getDocumentStandard());
1052         m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1053
1054         // We need to desactivate & reactivate monitors to get a refresh
1055         m_monitorManager->switchMonitors();
1056     }
1057     delete w;
1058 }
1059
1060 void MainWindow::slotRenderProject() {
1061     if (!m_renderWidget) {
1062         m_renderWidget = new RenderWidget(this);
1063         connect(m_renderWidget, SIGNAL(doRender(const QString&, const QString&, const QStringList &, const QStringList &, bool, bool, double, double)), this, SLOT(slotDoRender(const QString&, const QString&, const QStringList &, const QStringList &, bool, bool, double, double)));
1064         if (m_activeDocument) m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1065     }
1066     /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1067     if (currentTab) m_renderWidget->setTimeline(currentTab);
1068     m_renderWidget->setDocument(m_activeDocument);*/
1069     m_renderWidget->show();
1070 }
1071
1072 void MainWindow::slotDoRender(const QString &dest, const QString &render, const QStringList &overlay_args, const QStringList &avformat_args, bool zoneOnly, bool playAfter, double guideStart, double guideEnd) {
1073     if (dest.isEmpty()) return;
1074     int in;
1075     int out;
1076     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1077     if (currentTab && zoneOnly) {
1078         in = currentTab->inPoint();
1079         out = currentTab->outPoint();
1080     }
1081     KTemporaryFile temp;
1082     temp.setAutoRemove(false);
1083     temp.setSuffix(".westley");
1084     if (temp.open()) {
1085         m_projectMonitor->saveSceneList(temp.fileName());
1086         QStringList args;
1087         args << "-erase";
1088         if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
1089         else if (guideStart != -1) {
1090             args << "in=" + QString::number(GenTime(guideStart).frames(m_activeDocument->fps())) << "out=" + QString::number(GenTime(guideEnd).frames(m_activeDocument->fps()));
1091         }
1092         if (!overlay_args.isEmpty()) args << "preargs=" + overlay_args.join(" ");
1093         QString videoPlayer = "-";
1094         if (playAfter) {
1095             videoPlayer = KdenliveSettings::defaultplayerapp();
1096             if (videoPlayer.isEmpty()) KMessageBox::sorry(this, i18n("Cannot play video after rendering because the default video player application is not set.\nPlease define it in Kdenlive settings dialog."));
1097         }
1098         args << KdenliveSettings::rendererpath() << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
1099         QString renderer = QCoreApplication::applicationDirPath() + QString("/kdenlive_render");
1100         if (!QFile::exists(renderer)) renderer = "kdenlive_render";
1101         QProcess::startDetached(renderer, args);
1102
1103         KNotification::event("RenderStarted", i18n("Rendering <i>%1</i> started", dest), QPixmap(), this);
1104     }
1105 }
1106
1107 void MainWindow::slotUpdateMousePosition(int pos) {
1108     if (m_activeDocument)
1109         switch (m_timecodeFormat->currentIndex()) {
1110         case 0:
1111             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
1112             break;
1113         default:
1114             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
1115         }
1116 }
1117
1118 void MainWindow::slotUpdateDocumentState(bool modified) {
1119     setCaption(m_activeDocument->description(), modified);
1120     m_saveAction->setEnabled(modified);
1121     if (modified) {
1122         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
1123         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
1124     } else {
1125         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
1126         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
1127     }
1128 }
1129
1130 void MainWindow::connectDocumentInfo(KdenliveDoc *doc) {
1131     if (m_activeDocument) {
1132         if (m_activeDocument == doc) return;
1133         disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1134     }
1135     connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1136 }
1137
1138 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
1139     //m_projectMonitor->stop();
1140     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
1141     if (m_activeDocument) {
1142         if (m_activeDocument == doc) return;
1143         m_activeDocument->backupMltPlaylist();
1144         if (m_activeTimeline) {
1145             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
1146             disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), trackView, SLOT(slotSetZone(QPoint)));
1147             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
1148             disconnect(m_projectList, SIGNAL(projectModified()), m_activeDocument, SLOT(setModified()));
1149             disconnect(m_activeDocument, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1150             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
1151             disconnect(m_activeDocument, SIGNAL(addProjectFolder(const QString, const QString &, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, const QString &, bool, bool)));
1152             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1153             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1154             disconnect(m_activeDocument, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1155             disconnect(m_activeDocument, SIGNAL(deleteTimelineClip(const QString &)), m_activeTimeline, SLOT(slotDeleteClip(const QString &)));
1156             disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
1157             disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
1158             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
1159             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
1160             disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
1161             disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1162             disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1163
1164             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1165             disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1166             disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1167             disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1168             disconnect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1169             disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1170             disconnect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1171             disconnect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1172             disconnect(transitionConfig, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
1173             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1174             disconnect(trackView, SIGNAL(zoneMoved(int, int)), m_projectMonitor, SLOT(slotZoneMoved(int, int)));
1175             effectStack->clear();
1176         }
1177         m_activeDocument->setRenderer(NULL);
1178         disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1179         m_clipMonitor->stop();
1180     }
1181     KdenliveSettings::setCurrent_profile(doc->profilePath());
1182     KdenliveSettings::setProject_fps(doc->fps());
1183     m_monitorManager->resetProfiles(doc->timecode());
1184     m_projectList->setDocument(doc);
1185     transitionConfig->updateProjectFormat(doc->mltProfile());
1186     connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1187     connect(m_projectList, SIGNAL(projectModified()), doc, SLOT(setModified()));
1188     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1189     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
1190     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
1191     connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), trackView, SLOT(slotSetZone(QPoint)));
1192     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
1193     connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
1194     connect(doc, SIGNAL(addProjectFolder(const QString, const QString &, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, const QString &, bool, bool)));
1195     connect(doc, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1196     connect(doc, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1197     connect(doc, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1198
1199     connect(doc, SIGNAL(deleteTimelineClip(const QString &)), trackView, SLOT(slotDeleteClip(const QString &)));
1200     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1201     connect(doc, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1202
1203
1204     connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
1205     connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
1206     connect(trackView, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
1207     connect(trackView, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
1208     m_zoomSlider->setValue(doc->zoom());
1209     connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
1210     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
1211     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
1212     connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1213
1214     connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1215
1216
1217     connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1218     connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1219     connect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1220     connect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1221     connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1222     connect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1223     connect(transitionConfig, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
1224     connect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1225
1226     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1227     connect(trackView, SIGNAL(zoneMoved(int, int)), m_projectMonitor, SLOT(slotZoneMoved(int, int)));
1228
1229     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
1230     m_activeTimeline = trackView;
1231     if (m_renderWidget) m_renderWidget->setDocumentStandard(doc->getDocumentStandard());
1232     doc->setRenderer(m_projectMonitor->render);
1233     m_commandStack->setActiveStack(doc->commandStack());
1234     KdenliveSettings::setProject_display_ratio(doc->dar());
1235     m_projectList->updateAllClips();
1236     trackView->projectView()->updateAllThumbs();
1237
1238
1239     //m_overView->setScene(trackView->projectScene());
1240     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
1241     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
1242
1243     setCaption(doc->description(), doc->isModified());
1244     m_saveAction->setEnabled(doc->isModified());
1245     m_activeDocument = doc;
1246 }
1247
1248 void MainWindow::slotGuidesUpdated() {
1249     if (m_renderWidget) m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1250 }
1251
1252 void MainWindow::slotPreferences(int page, int option) {
1253     //An instance of your dialog could be already created and could be
1254     // cached, in which case you want to display the cached dialog
1255     // instead of creating another one
1256     if (KConfigDialog::showDialog("settings")) {
1257         if (page != -1) static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"))->showPage(page, option);
1258         return;
1259     }
1260
1261     // KConfigDialog didn't find an instance of this dialog, so lets
1262     // create it :
1263     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
1264     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
1265     connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(slotResetProfiles()));
1266     dialog->show();
1267     if (page != -1) dialog->showPage(page, option);
1268 }
1269
1270 void MainWindow::updateConfiguration() {
1271     //TODO: we should apply settings to all projects, not only the current one
1272     if (m_activeTimeline) {
1273         m_activeTimeline->refresh();
1274         m_activeTimeline->projectView()->checkAutoScroll();
1275         m_activeTimeline->projectView()->checkTrackHeight();
1276         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1277     }
1278     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1279     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1280     activateShuttleDevice();
1281
1282 }
1283
1284 void MainWindow::slotSwitchVideoThumbs() {
1285     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
1286     if (m_activeTimeline) {
1287         m_activeTimeline->refresh();
1288     }
1289     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1290 }
1291
1292 void MainWindow::slotSwitchAudioThumbs() {
1293     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
1294     if (m_activeTimeline) {
1295         m_activeTimeline->refresh();
1296         m_activeTimeline->projectView()->checkAutoScroll();
1297         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1298     }
1299     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1300 }
1301
1302 void MainWindow::slotSwitchMarkersComments() {
1303     KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
1304     if (m_activeTimeline) {
1305         m_activeTimeline->refresh();
1306     }
1307     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
1308 }
1309
1310 void MainWindow::slotSwitchSnap() {
1311     KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
1312     m_buttonShowMarkers->setChecked(KdenliveSettings::snaptopoints());
1313 }
1314
1315
1316 void MainWindow::slotDeleteTimelineClip() {
1317     if (m_activeTimeline) {
1318         m_activeTimeline->projectView()->deleteSelectedClips();
1319     }
1320 }
1321
1322 void MainWindow::slotChangeClipSpeed() {
1323     if (m_activeTimeline) {
1324         m_activeTimeline->projectView()->changeClipSpeed();
1325     }
1326 }
1327
1328 void MainWindow::slotAddClipMarker() {
1329     if (m_activeTimeline) {
1330         m_activeTimeline->projectView()->slotAddClipMarker();
1331     }
1332 }
1333
1334 void MainWindow::slotDeleteClipMarker() {
1335     if (m_activeTimeline) {
1336         m_activeTimeline->projectView()->slotDeleteClipMarker();
1337     }
1338 }
1339
1340 void MainWindow::slotDeleteAllClipMarkers() {
1341     if (m_activeTimeline) {
1342         m_activeTimeline->projectView()->slotDeleteAllClipMarkers();
1343     }
1344 }
1345
1346 void MainWindow::slotEditClipMarker() {
1347     if (m_activeTimeline) {
1348         m_activeTimeline->projectView()->slotEditClipMarker();
1349     }
1350 }
1351
1352 void MainWindow::slotAddGuide() {
1353     if (m_activeTimeline)
1354         m_activeTimeline->projectView()->slotAddGuide();
1355 }
1356
1357 void MainWindow::slotEditGuide() {
1358     if (m_activeTimeline)
1359         m_activeTimeline->projectView()->slotEditGuide();
1360 }
1361
1362 void MainWindow::slotDeleteGuide() {
1363     if (m_activeTimeline)
1364         m_activeTimeline->projectView()->slotDeleteGuide();
1365 }
1366
1367 void MainWindow::slotDeleteAllGuides() {
1368     if (m_activeTimeline)
1369         m_activeTimeline->projectView()->slotDeleteAllGuides();
1370 }
1371
1372 void MainWindow::slotCutTimelineClip() {
1373     if (m_activeTimeline) {
1374         m_activeTimeline->projectView()->cutSelectedClips();
1375     }
1376 }
1377
1378 void MainWindow::slotAddProjectClip(KUrl url) {
1379     if (m_activeDocument)
1380         m_activeDocument->slotAddClipFile(url, QString());
1381 }
1382
1383 void MainWindow::slotAddTransition(QAction *result) {
1384     if (!result) return;
1385     QDomElement effect = transitions.getEffectByName(result->data().toString());
1386     if (m_activeTimeline) {
1387         m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(effect);
1388     }
1389 }
1390
1391 void MainWindow::slotAddVideoEffect(QAction *result) {
1392     if (!result) return;
1393     QDomElement effect = videoEffects.getEffectByName(result->data().toString());
1394     slotAddEffect(effect);
1395 }
1396
1397 void MainWindow::slotAddAudioEffect(QAction *result) {
1398     if (!result) return;
1399     QDomElement effect = audioEffects.getEffectByName(result->data().toString());
1400     slotAddEffect(effect);
1401 }
1402
1403 void MainWindow::slotAddCustomEffect(QAction *result) {
1404     if (!result) return;
1405     if (result->data().toString().isEmpty()) return;
1406     QDomElement effect = customEffects.getEffectByName(result->data().toString());
1407     slotAddEffect(effect);
1408 }
1409
1410 void MainWindow::slotZoomIn() {
1411     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
1412 }
1413
1414 void MainWindow::slotZoomOut() {
1415     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
1416 }
1417
1418 void MainWindow::slotFitZoom() {
1419     if (m_activeTimeline) {
1420         m_zoomSlider->setValue(m_activeTimeline->fitZoom());
1421     }
1422 }
1423
1424 void MainWindow::slotGotProgressInfo(const QString &message, int progress) {
1425     statusProgressBar->setValue(progress);
1426     if (progress >= 0) {
1427         if (!message.isEmpty()) m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
1428         statusProgressBar->setVisible(true);
1429     } else {
1430         m_messageLabel->setMessage(QString(), DefaultMessage);
1431         statusProgressBar->setVisible(false);
1432     }
1433 }
1434
1435 void MainWindow::slotShowClipProperties(DocClipBase *clip) {
1436     if (clip->clipType() == TEXT) {
1437         QString titlepath = m_activeDocument->projectFolder().path() + "/titles/";
1438         QString path = clip->getProperty("resource");
1439         TitleWidget *dia_ui = new TitleWidget(KUrl(), titlepath, m_projectMonitor->render, this);
1440         QDomDocument doc;
1441         doc.setContent(clip->getProperty("xmldata"));
1442         dia_ui->setXml(doc);
1443         if (dia_ui->exec() == QDialog::Accepted) {
1444             QPixmap pix = dia_ui->renderedPixmap();
1445             pix.save(path);
1446             //slotAddClipFile(KUrl("/tmp/kdenlivetitle.png"), QString(), -1);
1447             //m_clipManager->slotEditTextClipFile(id, dia_ui->xml().toString());
1448             QMap <QString, QString> newprops;
1449             newprops.insert("xmldata", dia_ui->xml().toString());
1450             EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
1451             m_activeDocument->commandStack()->push(command);
1452             m_clipMonitor->refreshMonitor(true);
1453             m_activeDocument->setModified(true);
1454         }
1455         delete dia_ui;
1456
1457         //m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
1458         return;
1459     }
1460     ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
1461     connect(&dia, SIGNAL(addMarker(const QString &, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(const QString &, GenTime, QString)));
1462     if (dia.exec() == QDialog::Accepted) {
1463         EditClipCommand *command = new EditClipCommand(m_projectList, dia.clipId(), clip->properties(), dia.properties(), true);
1464         m_activeDocument->commandStack()->push(command);
1465
1466         //m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
1467         if (dia.needsTimelineRefresh()) {
1468             // update clip occurences in timeline
1469             m_activeTimeline->projectView()->slotUpdateClip(dia.clipId());
1470         }
1471     }
1472 }
1473
1474 void MainWindow::customEvent(QEvent* e) {
1475     if (e->type() == QEvent::User) {
1476         // The timeline playing position changed...
1477         kDebug() << "RECIEVED JOG EVEMNT!!!";
1478     }
1479 }
1480 void MainWindow::slotActivateEffectStackView() {
1481     effectStack->raiseWindow(effectStackDock);
1482 }
1483
1484 void MainWindow::slotActivateTransitionView() {
1485     transitionConfig->raiseWindow(transitionConfigDock);
1486 }
1487
1488 void MainWindow::slotSnapRewind() {
1489     if (m_projectMonitor->isActive()) {
1490         if (m_activeTimeline)
1491             m_activeTimeline->projectView()->slotSeekToPreviousSnap();
1492     }
1493 }
1494
1495 void MainWindow::slotSnapForward() {
1496     if (m_projectMonitor->isActive()) {
1497         if (m_activeTimeline)
1498             m_activeTimeline->projectView()->slotSeekToNextSnap();
1499     }
1500 }
1501
1502 void MainWindow::slotClipStart() {
1503     if (m_projectMonitor->isActive()) {
1504         if (m_activeTimeline)
1505             m_activeTimeline->projectView()->clipStart();
1506     }
1507 }
1508
1509 void MainWindow::slotClipEnd() {
1510     if (m_projectMonitor->isActive()) {
1511         if (m_activeTimeline)
1512             m_activeTimeline->projectView()->clipEnd();
1513     }
1514 }
1515
1516 void MainWindow::slotChangeTool(QAction * action) {
1517     if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
1518     else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
1519 }
1520
1521 void MainWindow::slotSetTool(PROJECTTOOL tool) {
1522     if (m_activeDocument && m_activeTimeline) {
1523         //m_activeDocument->setTool(tool);
1524         m_activeTimeline->projectView()->setTool(tool);
1525     }
1526 }
1527
1528 void MainWindow::slotCopy() {
1529     if (!m_activeDocument || !m_activeTimeline) return;
1530     m_activeTimeline->projectView()->copyClip();
1531 }
1532
1533 void MainWindow::slotPaste() {
1534     if (!m_activeDocument || !m_activeTimeline) return;
1535     m_activeTimeline->projectView()->pasteClip();
1536 }
1537
1538 void MainWindow::slotPasteEffects() {
1539     if (!m_activeDocument || !m_activeTimeline) return;
1540     m_activeTimeline->projectView()->pasteClipEffects();
1541 }
1542
1543 void MainWindow::slotFind() {
1544     if (!m_activeDocument || !m_activeTimeline) return;
1545     m_projectSearch->setEnabled(false);
1546     m_findActivated = true;
1547     m_findString = QString();
1548     m_activeTimeline->projectView()->initSearchStrings();
1549     statusBar()->showMessage(i18n("Starting -- find text as you type"));
1550     m_findTimer.start(5000);
1551     qApp->installEventFilter(this);
1552 }
1553
1554 void MainWindow::slotFindNext() {
1555     if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString)) {
1556         statusBar()->showMessage(i18n("Found : %1", m_findString));
1557     } else {
1558         statusBar()->showMessage(i18n("Reached end of project"));
1559     }
1560     m_findTimer.start(4000);
1561 }
1562
1563 void MainWindow::findAhead() {
1564     if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
1565         m_projectSearchNext->setEnabled(true);
1566         statusBar()->showMessage(i18n("Found : %1", m_findString));
1567     } else {
1568         m_projectSearchNext->setEnabled(false);
1569         statusBar()->showMessage(i18n("Not found : %1", m_findString));
1570     }
1571 }
1572
1573 void MainWindow::findTimeout() {
1574     m_projectSearchNext->setEnabled(false);
1575     m_findActivated = false;
1576     m_findString = QString();
1577     statusBar()->showMessage(i18n("Find stopped"), 3000);
1578     if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
1579     m_projectSearch->setEnabled(true);
1580     removeEventFilter(this);
1581 }
1582
1583 void MainWindow::keyPressEvent(QKeyEvent *ke) {
1584     if (m_findActivated) {
1585         if (ke->key() == Qt::Key_Backspace) {
1586             m_findString = m_findString.left(m_findString.length() - 1);
1587
1588             if (!m_findString.isEmpty()) {
1589                 findAhead();
1590             } else {
1591                 findTimeout();
1592             }
1593
1594             m_findTimer.start(4000);
1595             ke->accept();
1596             return;
1597         } else if (ke->key() == Qt::Key_Escape) {
1598             findTimeout();
1599             ke->accept();
1600             return;
1601         } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
1602             m_findString += ke->text();
1603
1604             findAhead();
1605
1606             m_findTimer.start(4000);
1607             ke->accept();
1608             return;
1609         }
1610     } else KXmlGuiWindow::keyPressEvent(ke);
1611 }
1612
1613 bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
1614     if (m_findActivated) {
1615         if (event->type() == QEvent::ShortcutOverride) {
1616             QKeyEvent* ke = (QKeyEvent*) event;
1617             if (ke->text().trimmed().isEmpty()) return false;
1618             ke->accept();
1619             return true;
1620         } else return false;
1621     } else {
1622         // pass the event on to the parent class
1623         return QMainWindow::eventFilter(obj, event);
1624     }
1625 }
1626
1627 void MainWindow::slotSaveZone(Render *render, QPoint zone) {
1628     KDialog *dialog = new KDialog(this);
1629     dialog->setCaption("Save clip zone");
1630     dialog->setButtons(KDialog::Ok | KDialog::Cancel);
1631
1632     QWidget *widget = new QWidget(dialog);
1633     dialog->setMainWidget(widget);
1634
1635     QVBoxLayout *vbox = new QVBoxLayout(widget);
1636     QLabel *label1 = new QLabel(i18n("Save clip zone as:"), this);
1637     QString path = m_activeDocument->projectFolder().path();
1638     path.append("/");
1639     path.append("untitled.westley");
1640     KUrlRequester *url = new KUrlRequester(KUrl(path), this);
1641     url->setFilter("video/mlt-playlist");
1642     QLabel *label2 = new QLabel(i18n("Description:"), this);
1643     KLineEdit *edit = new KLineEdit(this);
1644     vbox->addWidget(label1);
1645     vbox->addWidget(url);
1646     vbox->addWidget(label2);
1647     vbox->addWidget(edit);
1648     if (dialog->exec() == QDialog::Accepted) render->saveZone(url->url(), edit->text(), zone);
1649
1650 }
1651
1652 void MainWindow::slotSetInPoint() {
1653     if (m_clipMonitor->isActive()) {
1654         m_clipMonitor->slotSetZoneStart();
1655     } else m_activeTimeline->projectView()->setInPoint();
1656 }
1657
1658 void MainWindow::slotSetOutPoint() {
1659     if (m_clipMonitor->isActive()) {
1660         m_clipMonitor->slotSetZoneEnd();
1661     } else m_activeTimeline->projectView()->setOutPoint();
1662 }
1663
1664 #include "mainwindow.moc"