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