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