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