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