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