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