]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
Correctly use thumbs settings from new project dialog:
[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
21 #include "mainwindow.h"
22 #include "mainwindowadaptor.h"
23 #include "kdenlivesettings.h"
24 #include "kdenlivesettingsdialog.h"
25 #include "initeffects.h"
26 #include "profilesdialog.h"
27 #include "projectsettings.h"
28 #include "events.h"
29 #include "clipmanager.h"
30 #include "projectlist.h"
31 #include "monitor.h"
32 #include "recmonitor.h"
33 #include "monitormanager.h"
34 #include "kdenlivedoc.h"
35 #include "trackview.h"
36 #include "customtrackview.h"
37 #include "effectslistview.h"
38 #include "effectstackview.h"
39 #include "transitionsettings.h"
40 #include "renderwidget.h"
41 #include "renderer.h"
42 #ifndef NO_JOGSHUTTLE
43 #include "jogshuttle.h"
44 #endif /* NO_JOGSHUTTLE */
45 #include "clipproperties.h"
46 #include "wizard.h"
47 #include "editclipcommand.h"
48 #include "titlewidget.h"
49 #include "markerdialog.h"
50 #include "clipitem.h"
51 #include "interfaces.h"
52 #include "kdenlive-config.h"
53
54 #include <KApplication>
55 #include <KAction>
56 #include <KLocale>
57 #include <KGlobal>
58 #include <KActionCollection>
59 #include <KStandardAction>
60 #include <KFileDialog>
61 #include <KMessageBox>
62 #include <KDebug>
63 #include <KIO/NetAccess>
64 #include <KSaveFile>
65 #include <KRuler>
66 #include <KConfigDialog>
67 #include <KXMLGUIFactory>
68 #include <KStatusBar>
69 #include <kstandarddirs.h>
70 #include <KUrlRequesterDialog>
71 #include <KTemporaryFile>
72 #include <KActionMenu>
73 #include <KMenu>
74 #include <locale.h>
75 #include <ktogglefullscreenaction.h>
76 #include <KFileItem>
77 #include <KNotification>
78 #include <KNotifyConfigWidget>
79 #include <knewstuff2/engine.h>
80 #include <knewstuff2/ui/knewstuffaction.h>
81
82 #include <QTextStream>
83 #include <QTimer>
84 #include <QAction>
85 #include <QKeyEvent>
86
87 #include <stdlib.h>
88
89 static const char version[] = VERSION;
90
91 static const int ID_STATUS_MSG = 1;
92 static const int ID_EDITMODE_MSG = 2;
93 static const int ID_TIMELINE_MSG = 3;
94 static const int ID_TIMELINE_BUTTONS = 5;
95 static const int ID_TIMELINE_POS = 6;
96 static const int ID_TIMELINE_FORMAT = 7;
97
98 namespace Mlt {
99 class Producer;
100 };
101
102 EffectsList MainWindow::videoEffects;
103 EffectsList MainWindow::audioEffects;
104 EffectsList MainWindow::customEffects;
105 EffectsList MainWindow::transitions;
106
107 MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, QWidget *parent)
108         : KXmlGuiWindow(parent),
109         m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL),
110 #ifndef NO_JOGSHUTTLE
111         m_jogProcess(NULL),
112 #endif /* NO_JOGSHUTTLE */
113         m_findActivated(false), m_initialized(false) {
114
115     // Create DBus interface
116     new MainWindowAdaptor(this);
117     QDBusConnection dbus = QDBusConnection::sessionBus();
118     dbus.registerObject("/MainWindow", this);
119
120     setlocale(LC_NUMERIC, "POSIX");
121     setFont(KGlobalSettings::toolBarFont());
122     parseProfiles(MltPath);
123     m_commandStack = new QUndoGroup;
124     m_timelineArea = new KTabWidget(this);
125     m_timelineArea->setTabReorderingEnabled(true);
126     m_timelineArea->setTabBarHidden(true);
127
128     QToolButton *closeTabButton = new QToolButton;
129     connect(closeTabButton, SIGNAL(clicked()), this, SLOT(closeCurrentDocument()));
130     closeTabButton->setIcon(KIcon("tab-close"));
131     closeTabButton->adjustSize();
132     closeTabButton->setToolTip(i18n("Close the current tab"));
133     m_timelineArea->setCornerWidget(closeTabButton);
134     connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
135
136     connect(&m_findTimer, SIGNAL(timeout()), this, SLOT(findTimeout()));
137     m_findTimer.setSingleShot(true);
138
139     initEffects::parseEffectFiles();
140     //initEffects::parseCustomEffectsFile();
141
142     m_monitorManager = new MonitorManager();
143
144     projectListDock = new QDockWidget(i18n("Project Tree"), this);
145     projectListDock->setObjectName("project_tree");
146     m_projectList = new ProjectList(this);
147     projectListDock->setWidget(m_projectList);
148     addDockWidget(Qt::TopDockWidgetArea, projectListDock);
149
150     effectListDock = new QDockWidget(i18n("Effect List"), this);
151     effectListDock->setObjectName("effect_list");
152     m_effectList = new EffectsListView();
153
154     //m_effectList = new KListWidget(this);
155     effectListDock->setWidget(m_effectList);
156     addDockWidget(Qt::TopDockWidgetArea, effectListDock);
157
158     effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
159     effectStackDock->setObjectName("effect_stack");
160     effectStack = new EffectStackView(this);
161     effectStackDock->setWidget(effectStack);
162     addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
163
164     transitionConfigDock = new QDockWidget(i18n("Transition"), this);
165     transitionConfigDock->setObjectName("transition");
166     transitionConfig = new TransitionSettings(this);
167     transitionConfigDock->setWidget(transitionConfig);
168     addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
169
170     KdenliveSettings::setCurrent_profile(KdenliveSettings::default_profile());
171     m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
172                        actionCollection());
173     readOptions();
174
175     clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
176     clipMonitorDock->setObjectName("clip_monitor");
177     m_clipMonitor = new Monitor("clip", m_monitorManager, this);
178     clipMonitorDock->setWidget(m_clipMonitor);
179     addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
180     //m_clipMonitor->stop();
181
182     projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
183     projectMonitorDock->setObjectName("project_monitor");
184     m_projectMonitor = new Monitor("project", m_monitorManager, this);
185     projectMonitorDock->setWidget(m_projectMonitor);
186     addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
187
188     recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
189     recMonitorDock->setObjectName("record_monitor");
190     m_recMonitor = new RecMonitor("record", this);
191     recMonitorDock->setWidget(m_recMonitor);
192     addDockWidget(Qt::TopDockWidgetArea, recMonitorDock);
193
194     connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
195     connect(m_recMonitor, SIGNAL(showConfigDialog(int, int)), this, SLOT(slotPreferences(int, int)));
196
197     undoViewDock = new QDockWidget(i18n("Undo History"), this);
198     undoViewDock->setObjectName("undo_history");
199     m_undoView = new QUndoView(this);
200     m_undoView->setCleanIcon(KIcon("edit-clear"));
201     m_undoView->setEmptyLabel(i18n("Clean"));
202     undoViewDock->setWidget(m_undoView);
203     m_undoView->setGroup(m_commandStack);
204     addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
205
206     //overviewDock = new QDockWidget(i18n("Project Overview"), this);
207     //overviewDock->setObjectName("project_overview");
208     //m_overView = new CustomTrackView(NULL, NULL, this);
209     //overviewDock->setWidget(m_overView);
210     //addDockWidget(Qt::TopDockWidgetArea, overviewDock);
211
212     setupActions();
213     //tabifyDockWidget(projectListDock, effectListDock);
214     tabifyDockWidget(projectListDock, effectStackDock);
215     tabifyDockWidget(projectListDock, transitionConfigDock);
216     //tabifyDockWidget(projectListDock, undoViewDock);
217
218
219     tabifyDockWidget(clipMonitorDock, projectMonitorDock);
220     tabifyDockWidget(clipMonitorDock, recMonitorDock);
221     setCentralWidget(m_timelineArea);
222
223
224     setupGUI();
225     /*ScriptingPart* sp = new ScriptingPart(this, QStringList());
226     guiFactory()->addClient(sp);*/
227
228     loadPlugins();
229     //kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
230
231     m_projectMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)), m_playZone, m_loopZone);
232     m_clipMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)), m_playZone, m_loopZone, static_cast<QMenu*>(factory()->container("marker_menu", this)));
233     m_projectList->setupGeneratorMenu(static_cast<QMenu*>(factory()->container("generators", this)));
234
235     // build effects menus
236     QAction *action;
237     QMenu *videoEffectsMenu = static_cast<QMenu*>(factory()->container("video_effects_menu", this));
238
239     QStringList effectInfo;
240     QMap<QString, QStringList> effectsList;
241     for (int ix = 0; ix < videoEffects.count(); ix++) {
242         effectInfo = videoEffects.effectIdInfo(ix);
243         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
244     }
245
246     foreach(const QStringList &value, effectsList) {
247         action = new QAction(value.at(0), this);
248         action->setData(value);
249         videoEffectsMenu->addAction(action);
250     }
251
252     QMenu *audioEffectsMenu = static_cast<QMenu*>(factory()->container("audio_effects_menu", this));
253
254
255     effectsList.clear();
256     for (int ix = 0; ix < audioEffects.count(); ix++) {
257         effectInfo = audioEffects.effectIdInfo(ix);
258         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
259     }
260
261     foreach(const QStringList &value, effectsList) {
262         action = new QAction(value.at(0), this);
263         action->setData(value);
264         audioEffectsMenu->addAction(action);
265     }
266
267     m_customEffectsMenu = static_cast<QMenu*>(factory()->container("custom_effects_menu", this));
268
269     if (customEffects.isEmpty()) m_customEffectsMenu->setEnabled(false);
270     else m_customEffectsMenu->setEnabled(true);
271
272     effectsList.clear();
273     for (int ix = 0; ix < customEffects.count(); ix++) {
274         effectInfo = customEffects.effectIdInfo(ix);
275         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
276     }
277
278     foreach(const QStringList &value, effectsList) {
279         action = new QAction(value.at(0), this);
280         action->setData(value);
281         m_customEffectsMenu->addAction(action);
282     }
283
284     QMenu *newEffect = new QMenu(this);
285     newEffect->addMenu(videoEffectsMenu);
286     newEffect->addMenu(audioEffectsMenu);
287     newEffect->addMenu(m_customEffectsMenu);
288     effectStack->setMenu(newEffect);
289
290
291     QMenu *viewMenu = static_cast<QMenu*>(factory()->container("dockwindows", this));
292     const QList<QAction *> viewActions = createPopupMenu()->actions();
293     viewMenu->insertActions(NULL, viewActions);
294
295     connect(videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
296     connect(audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
297     connect(m_customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
298
299     m_timelineContextMenu = new QMenu(this);
300     m_timelineContextClipMenu = new QMenu(this);
301     m_timelineContextTransitionMenu = new QMenu(this);
302
303
304     QMenu *transitionsMenu = new QMenu(i18n("Add Transition"), this);
305     QStringList effects = transitions.effectNames();
306
307     effectsList.clear();
308     for (int ix = 0; ix < transitions.count(); ix++) {
309         effectInfo = transitions.effectIdInfo(ix);
310         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
311     }
312     foreach(const QStringList &value, effectsList) {
313         action = new QAction(value.at(0), this);
314         action->setData(value);
315         transitionsMenu->addAction(action);
316     }
317     connect(transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
318
319     m_timelineContextMenu->addAction(actionCollection()->action("insert_space"));
320     m_timelineContextMenu->addAction(actionCollection()->action("delete_space"));
321     m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));
322
323     m_timelineContextClipMenu->addAction(actionCollection()->action("delete_timeline_clip"));
324     m_timelineContextClipMenu->addAction(actionCollection()->action("change_clip_speed"));
325     m_timelineContextClipMenu->addAction(actionCollection()->action("group_clip"));
326     m_timelineContextClipMenu->addAction(actionCollection()->action("ungroup_clip"));
327     m_timelineContextClipMenu->addAction(actionCollection()->action("cut_timeline_clip"));
328     m_timelineContextClipMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
329     m_timelineContextClipMenu->addAction(actionCollection()->action("paste_effects"));
330     m_timelineContextClipMenu->addAction(actionCollection()->action("split_audio"));
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(const 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(const 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 Project 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 Render Profiles..."), this, SLOT(slotGetNewRenderStuff()), actionCollection(), "get_new_profiles");
782
783     KNS::standardAction(i18n("Download New Project Profiles..."), this, SLOT(slotGetNewMltProfileStuff()), actionCollection(), "get_new_mlt_profiles");
784
785     KAction* wizAction = new KAction(KIcon("configure"), i18n("Run Config Wizard"), this);
786     collection->addAction("run_wizard", wizAction);
787     connect(wizAction, SIGNAL(triggered(bool)), this, SLOT(slotRunWizard()));
788
789     KAction* projectAction = new KAction(KIcon("configure"), i18n("Project Settings"), this);
790     collection->addAction("project_settings", projectAction);
791     connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
792
793     KAction* projectRender = new KAction(KIcon("media-record"), i18n("Render"), this);
794     collection->addAction("project_render", projectRender);
795     projectRender->setShortcut(Qt::CTRL + Qt::Key_Return);
796     connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
797
798     KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
799     KShortcut playShortcut;
800     playShortcut.setPrimary(Qt::Key_Space);
801     playShortcut.setAlternate(Qt::Key_K);
802     monitorPlay->setShortcut(playShortcut);
803     collection->addAction("monitor_play", monitorPlay);
804     connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
805
806     m_playZone = new KAction(KIcon("media-playback-start"), i18n("Play Zone"), this);
807     m_playZone->setShortcut(Qt::CTRL + Qt::Key_Space);
808     collection->addAction("monitor_play_zone", m_playZone);
809     connect(m_playZone, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlayZone()));
810
811     m_loopZone = new KAction(KIcon("media-playback-start"), i18n("Loop Zone"), this);
812     m_loopZone->setShortcut(Qt::ALT + Qt::Key_Space);
813     collection->addAction("monitor_loop_zone", m_loopZone);
814     connect(m_loopZone, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotLoopZone()));
815
816     KAction *dvdWizard =  new KAction(KIcon("media-optical"), i18n("Dvd Wizard"), this);
817     collection->addAction("dvd_wizard", dvdWizard);
818     connect(dvdWizard, SIGNAL(triggered(bool)), this, SLOT(slotDvdWizard()));
819
820     KAction *markIn = collection->addAction("mark_in");
821     markIn->setText(i18n("Set In Point"));
822     markIn->setShortcut(Qt::Key_I);
823     connect(markIn, SIGNAL(triggered(bool)), this, SLOT(slotSetInPoint()));
824
825     KAction *markOut = collection->addAction("mark_out");
826     markOut->setText(i18n("Set Out Point"));
827     markOut->setShortcut(Qt::Key_O);
828     connect(markOut, SIGNAL(triggered(bool)), this, SLOT(slotSetOutPoint()));
829
830     KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
831     monitorSeekBackward->setShortcut(Qt::Key_J);
832     collection->addAction("monitor_seek_backward", monitorSeekBackward);
833     connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
834
835     KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
836     monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
837     collection->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
838     connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
839
840     KAction* monitorSeekBackwardOneSecond = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Second"), this);
841     monitorSeekBackwardOneSecond->setShortcut(Qt::SHIFT + Qt::Key_Left);
842     collection->addAction("monitor_seek_backward-one-second", monitorSeekBackwardOneSecond);
843     connect(monitorSeekBackwardOneSecond, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneSecond()));
844
845     KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
846     monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
847     collection->addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
848     connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
849
850     KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
851     monitorSeekForward->setShortcut(Qt::Key_L);
852     collection->addAction("monitor_seek_forward", monitorSeekForward);
853     connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
854
855     KAction* clipStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Clip Start"), this);
856     clipStart->setShortcut(Qt::Key_Home);
857     collection->addAction("seek_clip_start", clipStart);
858     connect(clipStart, SIGNAL(triggered(bool)), this, SLOT(slotClipStart()));
859
860     KAction* clipEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Clip End"), this);
861     clipEnd->setShortcut(Qt::Key_End);
862     collection->addAction("seek_clip_end", clipEnd);
863     connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
864
865     KAction* projectStart = new KAction(KIcon("go-first"), i18n("Go to Project Start"), this);
866     projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
867     collection->addAction("seek_start", projectStart);
868     connect(projectStart, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotStart()));
869
870     KAction* projectEnd = new KAction(KIcon("go-last"), i18n("Go to Project End"), this);
871     projectEnd->setShortcut(Qt::CTRL + Qt::Key_End);
872     collection->addAction("seek_end", projectEnd);
873     connect(projectEnd, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotEnd()));
874
875     KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
876     monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
877     collection->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
878     connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
879
880     KAction* monitorSeekForwardOneSecond = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Second"), this);
881     monitorSeekForwardOneSecond->setShortcut(Qt::SHIFT + Qt::Key_Right);
882     collection->addAction("monitor_seek_forward-one-second", monitorSeekForwardOneSecond);
883     connect(monitorSeekForwardOneSecond, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneSecond()));
884
885     KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
886     monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
887     collection->addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
888     connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
889
890     KAction* deleteTimelineClip = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
891     deleteTimelineClip->setShortcut(Qt::Key_Delete);
892     collection->addAction("delete_timeline_clip", deleteTimelineClip);
893     connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
894
895     KAction* editTimelineClipSpeed = new KAction(i18n("Change Clip Speed"), this);
896     collection->addAction("change_clip_speed", editTimelineClipSpeed);
897     editTimelineClipSpeed->setData("change_speed");
898     connect(editTimelineClipSpeed, SIGNAL(triggered(bool)), this, SLOT(slotChangeClipSpeed()));
899
900     KAction *stickTransition = collection->addAction("auto_transition");
901     stickTransition->setData(QString("auto"));
902     stickTransition->setCheckable(true);
903     stickTransition->setEnabled(false);
904     stickTransition->setText(i18n("Automatic Transition"));
905     connect(stickTransition, SIGNAL(triggered(bool)), this, SLOT(slotAutoTransition()));
906
907     KAction* groupClip = new KAction(KIcon("object-group"), i18n("Group Clips"), this);
908     collection->addAction("group_clip", groupClip);
909     connect(groupClip, SIGNAL(triggered(bool)), this, SLOT(slotGroupClips()));
910
911     KAction* ungroupClip = new KAction(KIcon("object-ungroup"), i18n("Ungroup Clips"), this);
912     collection->addAction("ungroup_clip", ungroupClip);
913     ungroupClip->setData("ungroup_clip");
914     connect(ungroupClip, SIGNAL(triggered(bool)), this, SLOT(slotUnGroupClips()));
915
916     KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
917     cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
918     collection->addAction("cut_timeline_clip", cutTimelineClip);
919     connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
920
921     KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker"), this);
922     collection->addAction("add_clip_marker", addClipMarker);
923     connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
924
925     KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker"), this);
926     collection->addAction("delete_clip_marker", deleteClipMarker);
927     connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
928
929     KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers"), this);
930     collection->addAction("delete_all_clip_markers", deleteAllClipMarkers);
931     connect(deleteAllClipMarkers, SIGNAL(triggered(bool)), this, SLOT(slotDeleteAllClipMarkers()));
932
933     KAction* editClipMarker = new KAction(KIcon("document-properties"), i18n("Edit Marker"), this);
934     collection->addAction("edit_clip_marker", editClipMarker);
935     connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker()));
936
937     KAction* splitAudio = new KAction(KIcon("document-new"), i18n("Split Audio"), this);
938     collection->addAction("split_audio", splitAudio);
939     connect(splitAudio, SIGNAL(triggered(bool)), this, SLOT(slotSplitAudio()));
940
941     KAction* audioOnly = new KAction(KIcon("document-new"), i18n("Audio Only"), this);
942     collection->addAction("clip_audio_only", audioOnly);
943     connect(audioOnly, SIGNAL(triggered(bool)), this, SLOT(slotAudioOnly()));
944
945     KAction* videoOnly = new KAction(KIcon("document-new"), i18n("Video Only"), this);
946     collection->addAction("clip_video_only", videoOnly);
947     connect(videoOnly, SIGNAL(triggered(bool)), this, SLOT(slotVideoOnly()));
948
949     KAction *insertSpace = new KAction(KIcon(), i18n("Insert Space"), this);
950     collection->addAction("insert_space", insertSpace);
951     connect(insertSpace, SIGNAL(triggered()), this, SLOT(slotInsertSpace()));
952
953     KAction *removeSpace = new KAction(KIcon(), i18n("Remove Space"), this);
954     collection->addAction("delete_space", removeSpace);
955     connect(removeSpace, SIGNAL(triggered()), this, SLOT(slotRemoveSpace()));
956
957     KAction *insertTrack = new KAction(KIcon(), i18n("Insert Track"), this);
958     collection->addAction("insert_track", insertTrack);
959     connect(insertTrack, SIGNAL(triggered()), this, SLOT(slotInsertTrack()));
960
961     KAction *deleteTrack = new KAction(KIcon(), i18n("Delete Track"), this);
962     collection->addAction("delete_track", deleteTrack);
963     connect(deleteTrack, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
964
965     KAction *changeTrack = new KAction(KIcon(), i18n("Change Track"), this);
966     collection->addAction("change_track", changeTrack);
967     connect(changeTrack, SIGNAL(triggered()), this, SLOT(slotChangeTrack()));
968
969     KAction *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
970     collection->addAction("add_guide", addGuide);
971     connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
972
973     QAction *delGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
974     collection->addAction("delete_guide", delGuide);
975     connect(delGuide, SIGNAL(triggered()), this, SLOT(slotDeleteGuide()));
976
977     QAction *editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
978     collection->addAction("edit_guide", editGuide);
979     connect(editGuide, SIGNAL(triggered()), this, SLOT(slotEditGuide()));
980
981     QAction *delAllGuides = new KAction(KIcon("edit-delete"), i18n("Delete All Guides"), this);
982     collection->addAction("delete_all_guides", delAllGuides);
983     connect(delAllGuides, SIGNAL(triggered()), this, SLOT(slotDeleteAllGuides()));
984
985     QAction *pasteEffects = new KAction(KIcon("edit-paste"), i18n("Paste Effects"), this);
986     collection->addAction("paste_effects", pasteEffects);
987     pasteEffects->setData("paste_effects");
988     connect(pasteEffects , SIGNAL(triggered()), this, SLOT(slotPasteEffects()));
989
990     m_closeAction = KStandardAction::close(this, SLOT(closeCurrentDocument()), collection);
991
992     KStandardAction::quit(this, SLOT(queryQuit()), collection);
993
994     KStandardAction::open(this, SLOT(openFile()), collection);
995
996     m_saveAction = KStandardAction::save(this, SLOT(saveFile()), collection);
997
998     KStandardAction::saveAs(this, SLOT(saveFileAs()), collection);
999
1000     KStandardAction::openNew(this, SLOT(newFile()), collection);
1001
1002     KStandardAction::preferences(this, SLOT(slotPreferences()), collection);
1003
1004     KStandardAction::configureNotifications(this , SLOT(configureNotifications()), collection);
1005
1006     KStandardAction::copy(this, SLOT(slotCopy()), collection);
1007
1008     KStandardAction::paste(this, SLOT(slotPaste()), collection);
1009
1010     KAction *undo = KStandardAction::undo(m_commandStack, SLOT(undo()), collection);
1011     undo->setEnabled(false);
1012     connect(m_commandStack, SIGNAL(canUndoChanged(bool)), undo, SLOT(setEnabled(bool)));
1013
1014     KAction *redo = KStandardAction::redo(m_commandStack, SLOT(redo()), collection);
1015     redo->setEnabled(false);
1016     connect(m_commandStack, SIGNAL(canRedoChanged(bool)), redo, SLOT(setEnabled(bool)));
1017
1018     KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, collection);
1019
1020     connect(collection, SIGNAL(actionHovered(QAction*)),
1021             this, SLOT(slotDisplayActionMessage(QAction*)));
1022
1023
1024     QAction *addClip = new KAction(KIcon("kdenlive-add-clip"), i18n("Add Clip"), this);
1025     collection->addAction("add_clip", addClip);
1026     connect(addClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddClip()));
1027
1028     QAction *addColorClip = new KAction(KIcon("kdenlive-add-color-clip"), i18n("Add Color Clip"), this);
1029     collection->addAction("add_color_clip", addColorClip);
1030     connect(addColorClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddColorClip()));
1031
1032     QAction *addSlideClip = new KAction(KIcon("kdenlive-add-slide-clip"), i18n("Add Slideshow Clip"), this);
1033     collection->addAction("add_slide_clip", addSlideClip);
1034     connect(addSlideClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddSlideshowClip()));
1035
1036     QAction *addTitleClip = new KAction(KIcon("kdenlive-add-text-clip"), i18n("Add Title Clip"), this);
1037     collection->addAction("add_text_clip", addTitleClip);
1038     connect(addTitleClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddTitleClip()));
1039
1040     QAction *addFolderButton = new KAction(KIcon("folder-new"), i18n("Create Folder"), this);
1041     collection->addAction("add_folder", addFolderButton);
1042     connect(addFolderButton , SIGNAL(triggered()), m_projectList, SLOT(slotAddFolder()));
1043
1044     QAction *clipProperties = new KAction(KIcon("document-edit"), i18n("Clip Properties"), this);
1045     collection->addAction("clip_properties", clipProperties);
1046     clipProperties->setData("clip_properties");
1047     connect(clipProperties , SIGNAL(triggered()), m_projectList, SLOT(slotEditClip()));
1048     clipProperties->setEnabled(false);
1049
1050     QAction *openClip = new KAction(KIcon("document-open"), i18n("Edit Clip"), this);
1051     collection->addAction("edit_clip", openClip);
1052     openClip->setData("edit_clip");
1053     connect(openClip , SIGNAL(triggered()), m_projectList, SLOT(slotOpenClip()));
1054     openClip->setEnabled(false);
1055
1056     QAction *deleteClip = new KAction(KIcon("edit-delete"), i18n("Delete Clip"), this);
1057     collection->addAction("delete_clip", deleteClip);
1058     deleteClip->setData("delete_clip");
1059     connect(deleteClip , SIGNAL(triggered()), m_projectList, SLOT(slotRemoveClip()));
1060     deleteClip->setEnabled(false);
1061
1062     QAction *reloadClip = new KAction(KIcon("view-refresh"), i18n("Reload Clip"), this);
1063     collection->addAction("reload_clip", reloadClip);
1064     reloadClip->setData("reload_clip");
1065     connect(reloadClip , SIGNAL(triggered()), m_projectList, SLOT(slotReloadClip()));
1066     reloadClip->setEnabled(false);
1067
1068     QMenu *addClips = new QMenu();
1069     addClips->addAction(addClip);
1070     addClips->addAction(addColorClip);
1071     addClips->addAction(addSlideClip);
1072     addClips->addAction(addTitleClip);
1073     addClips->addAction(addFolderButton);
1074
1075     addClips->addAction(reloadClip);
1076     addClips->addAction(clipProperties);
1077     addClips->addAction(openClip);
1078     addClips->addAction(deleteClip);
1079     m_projectList->setupMenu(addClips, addClip);
1080
1081     //connect(collection, SIGNAL( clearStatusText() ),
1082     //statusBar(), SLOT( clear() ) );
1083 }
1084
1085 void MainWindow::slotDisplayActionMessage(QAction *a) {
1086     statusBar()->showMessage(a->data().toString(), 3000);
1087 }
1088
1089 void MainWindow::saveOptions() {
1090     KdenliveSettings::self()->writeConfig();
1091     KSharedConfigPtr config = KGlobal::config();
1092     m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
1093     KConfigGroup treecolumns(config, "Project Tree");
1094     treecolumns.writeEntry("columns", m_projectList->headerInfo());
1095     config->sync();
1096 }
1097
1098 void MainWindow::readOptions() {
1099     KSharedConfigPtr config = KGlobal::config();
1100     m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
1101     KConfigGroup initialGroup(config, "version");
1102     bool upgrade = false;
1103     if (initialGroup.exists()) {
1104         if (initialGroup.readEntry("version", QString()).section(' ', 0, 0) != QString(version).section(' ', 0, 0))
1105             upgrade = true;
1106
1107         if (initialGroup.readEntry("version") == "0.7") {
1108             //Add new settings from 0.7.1
1109             if (KdenliveSettings::defaultprojectfolder().isEmpty()) {
1110                 QString path = QDir::homePath() + "/kdenlive";
1111                 if (KStandardDirs::makeDir(path)  == false) kDebug() << "/// ERROR CREATING PROJECT FOLDER: " << path;
1112                 KdenliveSettings::setDefaultprojectfolder(path);
1113             }
1114         }
1115
1116     }
1117
1118     if (!initialGroup.exists() || upgrade) {
1119         // this is our first run, show Wizard
1120         Wizard *w = new Wizard(upgrade, this);
1121         if (w->exec() == QDialog::Accepted && w->isOk()) {
1122             w->adjustSettings();
1123             initialGroup.writeEntry("version", version);
1124             delete w;
1125         } else {
1126             ::exit(1);
1127         }
1128     }
1129     KConfigGroup treecolumns(config, "Project Tree");
1130     const QByteArray state = treecolumns.readEntry("columns", QByteArray());
1131     if (!state.isEmpty())
1132         m_projectList->setHeaderInfo(state);
1133 }
1134
1135 void MainWindow::slotRunWizard() {
1136     Wizard *w = new Wizard(this);
1137     if (w->exec() == QDialog::Accepted && w->isOk()) {
1138         w->adjustSettings();
1139     }
1140     delete w;
1141 }
1142
1143 void MainWindow::newFile(bool showProjectSettings) {
1144     QString profileName;
1145     KUrl projectFolder;
1146     QPoint projectTracks(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks());
1147     if (!showProjectSettings && m_timelineArea->count() == 0) {
1148         if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1149         profileName = KdenliveSettings::default_profile();
1150     } else {
1151         ProjectSettings *w = new ProjectSettings(projectTracks.x(), projectTracks.y(), KdenliveSettings::defaultprojectfolder(), false, this);
1152         if (w->exec() != QDialog::Accepted) return;
1153         if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1154         KdenliveSettings::setVideothumbnails(w->enableVideoThumbs());
1155         m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1156         KdenliveSettings::setAudiothumbnails(w->enableAudioThumbs());
1157         m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1158         profileName = w->selectedProfile();
1159         projectFolder = w->selectedFolder();
1160         projectTracks = w->tracks();
1161         delete w;
1162     }
1163     KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, profileName, projectTracks, m_projectMonitor->render, this);
1164     doc->m_autosave = new KAutoSaveFile(KUrl(), doc);
1165     TrackView *trackView = new TrackView(doc, this);
1166     m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
1167     if (m_timelineArea->count() == 1) {
1168         connectDocumentInfo(doc);
1169         connectDocument(trackView, doc);
1170     } else m_timelineArea->setTabBarHidden(false);
1171     m_closeAction->setEnabled(m_timelineArea->count() > 1);
1172 }
1173
1174 void MainWindow::activateDocument() {
1175     if (m_timelineArea->currentWidget() == NULL) return;
1176     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1177     KdenliveDoc *currentDoc = currentTab->document();
1178     connectDocumentInfo(currentDoc);
1179     connectDocument(currentTab, currentDoc);
1180 }
1181
1182 void MainWindow::closeCurrentDocument() {
1183     QWidget *w = m_timelineArea->currentWidget();
1184     if (!w) return;
1185     // closing current document
1186     int ix = m_timelineArea->currentIndex() + 1;
1187     if (ix == m_timelineArea->count()) ix = 0;
1188     m_timelineArea->setCurrentIndex(ix);
1189     TrackView *tabToClose = (TrackView *) w;
1190     KdenliveDoc *docToClose = tabToClose->document();
1191     if (docToClose && docToClose->isModified()) {
1192         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
1193         case KMessageBox::Yes :
1194             // save document here. If saving fails, return false;
1195             saveFile();
1196             break;
1197         case KMessageBox::Cancel :
1198             return;
1199         default:
1200             break;
1201         }
1202     }
1203     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
1204     if (m_timelineArea->count() == 1) {
1205         m_timelineArea->setTabBarHidden(true);
1206         m_closeAction->setEnabled(false);
1207     }
1208     delete docToClose;
1209     delete w;
1210     if (m_timelineArea->count() == 0) {
1211         m_activeDocument = NULL;
1212         effectStack->clear();
1213         transitionConfig->slotTransitionItemSelected(NULL, false);
1214     }
1215 }
1216
1217 bool MainWindow::saveFileAs(const QString &outputFileName) {
1218     QString currentSceneList;
1219     if (KdenliveSettings::dropbframes()) {
1220         KdenliveSettings::setDropbframes(false);
1221         m_activeDocument->clipManager()->updatePreviewSettings();
1222         currentSceneList = m_projectMonitor->sceneList();
1223         KdenliveSettings::setDropbframes(true);
1224         m_activeDocument->clipManager()->updatePreviewSettings();
1225     } else currentSceneList = m_projectMonitor->sceneList();
1226
1227     if (m_activeDocument->saveSceneList(outputFileName, currentSceneList) == false)
1228         return false;
1229
1230     // Save timeline thumbnails
1231     m_activeTimeline->projectView()->saveThumbnails();
1232     m_activeDocument->setUrl(KUrl(outputFileName));
1233     if (m_activeDocument->m_autosave == NULL) {
1234         m_activeDocument->m_autosave = new KAutoSaveFile(KUrl(outputFileName), this);
1235     } else m_activeDocument->m_autosave->setManagedFile(KUrl(outputFileName));
1236     setCaption(m_activeDocument->description());
1237     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1238     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
1239     m_activeDocument->setModified(false);
1240     m_fileOpenRecent->addUrl(KUrl(outputFileName));
1241     return true;
1242 }
1243
1244 bool MainWindow::saveFileAs() {
1245     // Check that the Kdenlive mime type is correctly installed
1246     QString mimetype = "application/x-kdenlive";
1247     KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
1248     if (!mime) mimetype = "*.kdenlive";
1249
1250     QString outputFile = KFileDialog::getSaveFileName(KUrl(), mimetype);
1251     if (outputFile.isEmpty()) return false;
1252     if (QFile::exists(outputFile)) {
1253         if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return false;
1254     }
1255     return saveFileAs(outputFile);
1256 }
1257
1258 bool MainWindow::saveFile() {
1259     if (!m_activeDocument) return true;
1260     if (m_activeDocument->url().isEmpty()) {
1261         return saveFileAs();
1262     } else {
1263         bool result = saveFileAs(m_activeDocument->url().path());
1264         m_activeDocument->m_autosave->resize(0);
1265         return result;
1266     }
1267 }
1268
1269 void MainWindow::openFile() {
1270     // Check that the Kdenlive mime type is correctly installed
1271     QString mimetype = "application/x-kdenlive";
1272     KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
1273     if (!mime) mimetype = "*.kdenlive";
1274
1275     KUrl url = KFileDialog::getOpenUrl(KUrl("kfiledialog:///projectfolder"), mimetype);
1276     if (url.isEmpty()) return;
1277     m_fileOpenRecent->addUrl(url);
1278     openFile(url);
1279 }
1280
1281 void MainWindow::openLastFile() {
1282     KSharedConfigPtr config = KGlobal::config();
1283     KUrl::List urls = m_fileOpenRecent->urls();
1284     //WARNING: this is buggy, we get a random url, not the last one. Bug in KRecentFileAction ?
1285     if (urls.isEmpty()) newFile(false);
1286     else openFile(urls.last());
1287 }
1288
1289 void MainWindow::openFile(const KUrl &url) {
1290     // Check if the document is already opened
1291     const int ct = m_timelineArea->count();
1292     bool isOpened = false;
1293     int i;
1294     for (i = 0; i < ct; i++) {
1295         TrackView *tab = (TrackView *) m_timelineArea->widget(i);
1296         KdenliveDoc *doc = tab->document();
1297         if (doc->url() == url) {
1298             isOpened = true;
1299             break;
1300         }
1301     }
1302     if (isOpened) {
1303         m_timelineArea->setCurrentIndex(i);
1304         return;
1305     }
1306
1307     // Check for backup file
1308     QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::staleFiles(url);
1309     if (!staleFiles.isEmpty()) {
1310         if (KMessageBox::questionYesNo(this,
1311                                        i18n("Auto-saved files exist. Do you want to recover them now?"),
1312                                        i18n("File Recovery"),
1313                                        KGuiItem(i18n("Recover")), KGuiItem(i18n("Don't recover"))) == KMessageBox::Yes) {
1314             recoverFiles(staleFiles);
1315             return;
1316         } else {
1317             // remove the stale files
1318             foreach(KAutoSaveFile *stale, staleFiles) {
1319                 stale->open(QIODevice::ReadWrite);
1320                 delete stale;
1321             }
1322         }
1323     }
1324     if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1325     doOpenFile(url, NULL);
1326 }
1327
1328 void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale) {
1329     KdenliveDoc *doc = new KdenliveDoc(url, KUrl(), m_commandStack, QString(), QPoint(3, 2), m_projectMonitor->render, this);
1330     if (stale == NULL) {
1331         stale = new KAutoSaveFile(url, doc);
1332         doc->m_autosave = stale;
1333     } else {
1334         doc->m_autosave = stale;
1335         doc->setUrl(stale->managedFile());
1336         doc->setModified(true);
1337         stale->setParent(doc);
1338     }
1339     connectDocumentInfo(doc);
1340     TrackView *trackView = new TrackView(doc, this);
1341     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
1342     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
1343     trackView->setDuration(trackView->duration());
1344     trackView->projectView()->initCursorPos(m_projectMonitor->render->seekPosition().frames(doc->fps()));
1345
1346     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
1347     slotGotProgressInfo(QString(), -1);
1348     m_clipMonitor->refreshMonitor(true);
1349     m_projectMonitor->adjustRulerSize(trackView->duration());
1350     m_projectMonitor->slotZoneMoved(trackView->inPoint(), trackView->outPoint());
1351 }
1352
1353 void MainWindow::recoverFiles(QList<KAutoSaveFile *> staleFiles) {
1354     if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1355     foreach(KAutoSaveFile *stale, staleFiles) {
1356         /*if (!stale->open(QIODevice::QIODevice::ReadOnly)) {
1357                   // show an error message; we could not steal the lockfile
1358                   // maybe another application got to the file before us?
1359                   delete stale;
1360                   continue;
1361         }*/
1362         kDebug() << "// OPENING RECOVERY: " << stale->fileName() << "\nMANAGED: " << stale->managedFile().path();
1363         // the stalefiles also contain ".lock" files so we must ignore them... bug in KAutoSaveFile ?
1364         if (!stale->fileName().endsWith(".lock")) doOpenFile(KUrl(stale->fileName()), stale);
1365         else KIO::NetAccess::del(KUrl(stale->fileName()), this);
1366     }
1367 }
1368
1369
1370 void MainWindow::parseProfiles(const QString &mltPath) {
1371     //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
1372
1373     //KdenliveSettings::setDefaulttmpfolder();
1374     if (!mltPath.isEmpty()) {
1375         KdenliveSettings::setMltpath(mltPath + "/share/mlt/profiles/");
1376         KdenliveSettings::setRendererpath(mltPath + "/bin/inigo");
1377     }
1378
1379     if (KdenliveSettings::mltpath().isEmpty()) {
1380         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
1381     }
1382     if (KdenliveSettings::rendererpath().isEmpty()) {
1383         QString inigoPath = QString(MLT_PREFIX) + QString("/bin/inigo");
1384         if (!QFile::exists(inigoPath))
1385             inigoPath = KStandardDirs::findExe("inigo");
1386         else KdenliveSettings::setRendererpath(inigoPath);
1387     }
1388     QStringList profilesFilter;
1389     profilesFilter << "*";
1390     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1391
1392     if (profilesList.isEmpty()) {
1393         // Cannot find MLT path, try finding inigo
1394         QString profilePath = KdenliveSettings::rendererpath();
1395         if (!profilePath.isEmpty()) {
1396             profilePath = profilePath.section('/', 0, -3);
1397             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
1398             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1399         }
1400
1401         if (profilesList.isEmpty()) {
1402             // Cannot find the MLT profiles, ask for location
1403             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
1404             getUrl->fileDialog()->setMode(KFile::Directory);
1405             if (getUrl->exec() == QDialog::Rejected) {
1406                 ::exit(0);
1407             }
1408             KUrl mltPath = getUrl->selectedUrl();
1409             delete getUrl;
1410             if (mltPath.isEmpty()) ::exit(0);
1411             KdenliveSettings::setMltpath(mltPath.path());
1412             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1413         }
1414     }
1415
1416     if (KdenliveSettings::rendererpath().isEmpty()) {
1417         // Cannot find the MLT inigo renderer, ask for location
1418         KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(QString(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
1419         if (getUrl->exec() == QDialog::Rejected) {
1420             ::exit(0);
1421         }
1422         KUrl rendererPath = getUrl->selectedUrl();
1423         delete getUrl;
1424         if (rendererPath.isEmpty()) ::exit(0);
1425         KdenliveSettings::setRendererpath(rendererPath.path());
1426     }
1427
1428     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
1429
1430     // Parse MLT profiles to build a list of available video formats
1431     if (profilesList.isEmpty()) parseProfiles();
1432 }
1433
1434
1435 void MainWindow::slotEditProfiles() {
1436     ProfilesDialog *w = new ProfilesDialog;
1437     if (w->exec() == QDialog::Accepted) {
1438         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
1439         if (d) d->checkProfile();
1440     }
1441     delete w;
1442 }
1443
1444 void MainWindow::slotEditProjectSettings() {
1445     QPoint p = m_activeDocument->getTracksCount();
1446     ProjectSettings *w = new ProjectSettings(p.x(), p.y(), m_activeDocument->projectFolder().path(), true, this);
1447
1448     if (w->exec() == QDialog::Accepted) {
1449         QString profile = w->selectedProfile();
1450         m_activeDocument->setProjectFolder(w->selectedFolder());
1451         if (m_renderWidget) m_renderWidget->setDocumentPath(w->selectedFolder().path());
1452         if (m_activeDocument->profilePath() != profile) {
1453             // Profile was changed
1454             m_activeDocument->setProfilePath(profile);
1455             KdenliveSettings::setCurrent_profile(profile);
1456             KdenliveSettings::setProject_fps(m_activeDocument->fps());
1457             setCaption(m_activeDocument->description(), m_activeDocument->isModified());
1458             m_monitorManager->resetProfiles(m_activeDocument->timecode());
1459             if (m_renderWidget) m_renderWidget->setProfile(m_activeDocument->mltProfile());
1460             m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1461             m_activeDocument->clipManager()->resetProducersList(m_projectMonitor->render->producersList());
1462
1463             // We need to desactivate & reactivate monitors to get a refresh
1464             m_monitorManager->switchMonitors();
1465         }
1466     }
1467     delete w;
1468 }
1469
1470 void MainWindow::slotRenderProject() {
1471     if (!m_renderWidget) {
1472         QString projectfolder = m_activeDocument ? m_activeDocument->projectFolder().path() : KdenliveSettings::defaultprojectfolder();
1473         m_renderWidget = new RenderWidget(projectfolder, this);
1474         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 &)));
1475         connect(m_renderWidget, SIGNAL(abortProcess(const QString &)), this, SIGNAL(abortRenderJob(const QString &)));
1476         connect(m_renderWidget, SIGNAL(openDvdWizard(const QString &, const QString &)), this, SLOT(slotDvdWizard(const QString &, const QString &)));
1477         if (m_activeDocument) {
1478             m_renderWidget->setProfile(m_activeDocument->mltProfile());
1479             m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1480         }
1481     }
1482     /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1483     if (currentTab) m_renderWidget->setTimeline(currentTab);
1484     m_renderWidget->setDocument(m_activeDocument);*/
1485     m_renderWidget->show();
1486 }
1487
1488 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) {
1489     kDebug() << "// SCRIPT EXPORT: " << scriptExport;
1490     if (dest.isEmpty()) return;
1491     int in = 0;
1492     int out = 0;
1493     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1494     if (currentTab && zoneOnly) {
1495         in = currentTab->inPoint();
1496         out = currentTab->outPoint();
1497     }
1498     KTemporaryFile temp;
1499     temp.setAutoRemove(false);
1500     temp.setSuffix(".westley");
1501     if (!scriptExport.isEmpty() || temp.open()) {
1502         if (KdenliveSettings::dropbframes()) {
1503             KdenliveSettings::setDropbframes(false);
1504             m_activeDocument->clipManager()->updatePreviewSettings();
1505             if (!scriptExport.isEmpty()) m_projectMonitor->saveSceneList(scriptExport + ".westley");
1506             else m_projectMonitor->saveSceneList(temp.fileName());
1507             KdenliveSettings::setDropbframes(true);
1508             m_activeDocument->clipManager()->updatePreviewSettings();
1509         } else {
1510             if (!scriptExport.isEmpty()) m_projectMonitor->saveSceneList(scriptExport + ".westley");
1511             else m_projectMonitor->saveSceneList(temp.fileName());
1512         }
1513
1514         QStringList args;
1515         if (scriptExport.isEmpty()) args << "-erase";
1516         if (KdenliveSettings::usekuiserver()) args << "-kuiserver";
1517         if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
1518         else if (guideStart != -1) {
1519             args << "in=" + QString::number(GenTime(guideStart).frames(m_activeDocument->fps())) << "out=" + QString::number(GenTime(guideEnd).frames(m_activeDocument->fps()));
1520         }
1521         if (!overlay_args.isEmpty()) args << "preargs=" + overlay_args.join(" ");
1522         QString videoPlayer = "-";
1523         if (playAfter) {
1524             videoPlayer = KdenliveSettings::defaultplayerapp();
1525             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."));
1526         }
1527         if (!QFile::exists(KdenliveSettings::rendererpath())) {
1528             KMessageBox::sorry(this, i18n("Cannot find the inigo program required for rendering (part of Mlt)"));
1529             setRenderingProgress(dest, -3);
1530             return;
1531         }
1532         args << KdenliveSettings::rendererpath() << m_activeDocument->profilePath() << render << videoPlayer;
1533
1534         for (int i = 0; i < avformat_args.count(); i++) {
1535             if (avformat_args.at(i).startsWith("profile=")) {
1536                 if (avformat_args.at(i).section('=', 1) != m_activeDocument->profilePath()) resizeProfile = true;
1537                 break;
1538             }
1539         }
1540
1541         if (resizeProfile) {
1542             // The rendering profile is different from project profile, so use MLT's special producer_consumer
1543             if (scriptExport.isEmpty()) args << "consumer:" + temp.fileName();
1544             else args << "consumer:$SOURCE";
1545         } else {
1546             if (scriptExport.isEmpty()) args << temp.fileName();
1547             else args << "$SOURCE";
1548         }
1549         if (scriptExport.isEmpty()) args << dest;
1550         else args << "$TARGET";
1551         args << avformat_args;
1552         QString renderer = QCoreApplication::applicationDirPath() + QString("/kdenlive_render");
1553         if (!QFile::exists(renderer)) renderer = "kdenlive_render";
1554         if (scriptExport.isEmpty()) {
1555             QProcess::startDetached(renderer, args);
1556             KNotification::event("RenderStarted", i18n("Rendering <i>%1</i> started", dest), QPixmap(), this);
1557         } else {
1558             // Generate script file
1559             QFile file(scriptExport);
1560             if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1561                 m_messageLabel->setMessage(i18n("Cannot write to file %1", scriptExport), ErrorMessage);
1562                 return;
1563             }
1564
1565             QTextStream out(&file);
1566             out << "#! /bin/sh" << "\n" << "\n";
1567             out << "SOURCE=" << "\"" + scriptExport + ".westley\"" << "\n";
1568             out << "TARGET=" << "\"" + dest + "\"" << "\n";
1569             out << renderer << " " << args.join(" ") << "\n" << "\n";
1570             file.close();
1571             QFile::setPermissions(scriptExport, file.permissions() | QFile::ExeUser);
1572         }
1573     }
1574 }
1575
1576 void MainWindow::setRenderingProgress(const QString &url, int progress) {
1577     if (m_renderWidget) m_renderWidget->setRenderJob(url, progress);
1578 }
1579
1580 void MainWindow::setRenderingFinished(const QString &url, int status, const QString &error) {
1581     if (m_renderWidget) m_renderWidget->setRenderStatus(url, status, error);
1582 }
1583
1584 void MainWindow::slotUpdateMousePosition(int pos) {
1585     if (m_activeDocument)
1586         switch (m_timecodeFormat->currentIndex()) {
1587         case 0:
1588             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
1589             break;
1590         default:
1591             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
1592         }
1593 }
1594
1595 void MainWindow::slotUpdateDocumentState(bool modified) {
1596     if (!m_activeDocument) return;
1597     setCaption(m_activeDocument->description(), modified);
1598     m_saveAction->setEnabled(modified);
1599     if (modified) {
1600         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
1601         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
1602     } else {
1603         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
1604         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
1605     }
1606 }
1607
1608 void MainWindow::connectDocumentInfo(KdenliveDoc *doc) {
1609     if (m_activeDocument) {
1610         if (m_activeDocument == doc) return;
1611         disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1612     }
1613     connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1614 }
1615
1616 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
1617     //m_projectMonitor->stop();
1618     m_closeAction->setEnabled(m_timelineArea->count() > 1);
1619     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
1620     if (m_activeDocument) {
1621         if (m_activeDocument == doc) return;
1622         if (m_activeTimeline) {
1623             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
1624             disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeTimeline, SLOT(slotSetZone(QPoint)));
1625             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
1626             disconnect(m_projectList, SIGNAL(projectModified()), m_activeDocument, SLOT(setModified()));
1627
1628
1629             disconnect(m_activeDocument, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1630             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
1631             disconnect(m_activeDocument, SIGNAL(resetProjectList()), m_projectList, SLOT(slotResetProjectList()));
1632             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1633             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1634             disconnect(m_activeDocument, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1635             disconnect(m_activeDocument, SIGNAL(deleteTimelineClip(const QString &)), m_activeTimeline, SLOT(slotDeleteClip(const QString &)));
1636             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
1637             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
1638             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*, bool)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*, bool)));
1639             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*, bool)), this, SLOT(slotActivateTransitionView(Transition *)));
1640             disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
1641             disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1642             disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1643             disconnect(m_activeTimeline, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1644             disconnect(m_activeTimeline, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
1645             disconnect(m_activeTimeline, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
1646             disconnect(m_activeTimeline, SIGNAL(changeTrack(int)), this, SLOT(slotChangeTrack(int)));
1647             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1648             disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1649             disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1650             disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1651             disconnect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), m_activeTimeline->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1652             disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1653             disconnect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1654             disconnect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), m_activeTimeline->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1655             disconnect(transitionConfig, SIGNAL(seekTimeline(int)), m_activeTimeline->projectView() , SLOT(setCursorPos(int)));
1656             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1657             disconnect(m_activeTimeline, SIGNAL(zoneMoved(int, int)), this, SLOT(slotZoneMoved(int, int)));
1658             disconnect(m_projectList, SIGNAL(loadingIsOver()), m_activeTimeline->projectView(), SLOT(slotUpdateAllThumbs()));
1659             effectStack->clear();
1660         }
1661         //m_activeDocument->setRenderer(NULL);
1662         disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1663         m_clipMonitor->stop();
1664     }
1665     KdenliveSettings::setCurrent_profile(doc->profilePath());
1666     KdenliveSettings::setProject_fps(doc->fps());
1667     m_monitorManager->resetProfiles(doc->timecode());
1668     m_projectList->setDocument(doc);
1669     transitionConfig->updateProjectFormat(doc->mltProfile(), doc->timecode(), trackView->tracksNumber());
1670     effectStack->updateProjectFormat(doc->mltProfile(), doc->timecode());
1671     connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1672     connect(m_projectList, SIGNAL(projectModified()), doc, SLOT(setModified()));
1673     connect(m_projectList, SIGNAL(clipNameChanged(const QString, const QString)), trackView->projectView(), SLOT(clipNameChanged(const QString, const QString)));
1674
1675
1676     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1677     connect(trackView, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
1678     connect(trackView, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
1679     connect(trackView, SIGNAL(changeTrack(int)), this, SLOT(slotChangeTrack(int)));
1680     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
1681     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
1682     connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), trackView, SLOT(slotSetZone(QPoint)));
1683     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
1684     connect(doc, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
1685     connect(doc, SIGNAL(resetProjectList()), m_projectList, SLOT(slotResetProjectList()));
1686     connect(doc, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1687     connect(doc, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1688     connect(doc, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1689
1690     connect(doc, SIGNAL(deleteTimelineClip(const QString &)), trackView, SLOT(slotDeleteClip(const QString &)));
1691     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1692     connect(doc, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1693
1694
1695     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
1696     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
1697     connect(trackView, SIGNAL(transitionItemSelected(Transition*, bool)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*, bool)));
1698     connect(trackView, SIGNAL(transitionItemSelected(Transition*, bool)), this, SLOT(slotActivateTransitionView(Transition *)));
1699     m_zoomSlider->setValue(doc->zoom());
1700     connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
1701     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
1702     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
1703     connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1704
1705     connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1706
1707
1708     connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1709     connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1710     connect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1711     connect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1712     connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1713     connect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1714     connect(transitionConfig, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
1715     connect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1716
1717     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1718     connect(trackView, SIGNAL(zoneMoved(int, int)), this, SLOT(slotZoneMoved(int, int)));
1719     connect(m_projectList, SIGNAL(loadingIsOver()), trackView->projectView(), SLOT(slotUpdateAllThumbs()));
1720
1721     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
1722     m_activeTimeline = trackView;
1723     if (m_renderWidget) {
1724         m_renderWidget->setProfile(doc->mltProfile());
1725         m_renderWidget->setDocumentPath(doc->projectFolder().path());
1726     }
1727     //doc->setRenderer(m_projectMonitor->render);
1728     m_commandStack->setActiveStack(doc->commandStack());
1729     KdenliveSettings::setProject_display_ratio(doc->dar());
1730     m_projectList->updateAllClips();
1731     //doc->clipManager()->checkAudioThumbs();
1732
1733     //m_overView->setScene(trackView->projectScene());
1734     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
1735     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
1736
1737     setCaption(doc->description(), doc->isModified());
1738     m_saveAction->setEnabled(doc->isModified());
1739     m_activeDocument = doc;
1740     if (KdenliveSettings::dropbframes()) slotUpdatePreviewSettings();
1741
1742     // set tool to select tool
1743     m_buttonSelectTool->setChecked(true);
1744 }
1745
1746 void MainWindow::slotZoneMoved(int start, int end) {
1747     m_activeDocument->setZone(start, end);
1748     m_projectMonitor->slotZoneMoved(start, end);
1749 }
1750
1751 void MainWindow::slotGuidesUpdated() {
1752     if (m_renderWidget) m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1753 }
1754
1755 void MainWindow::slotPreferences(int page, int option) {
1756     //An instance of your dialog could be already created and could be
1757     // cached, in which case you want to display the cached dialog
1758     // instead of creating another one
1759     if (KConfigDialog::showDialog("settings")) {
1760         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
1761         if (page != -1) d->showPage(page, option);
1762         return;
1763     }
1764
1765     // KConfigDialog didn't find an instance of this dialog, so lets
1766     // create it :
1767     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
1768     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
1769     connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(slotResetProfiles()));
1770     connect(dialog, SIGNAL(updatePreviewSettings()), this, SLOT(slotUpdatePreviewSettings()));
1771     connect(dialog, SIGNAL(updateCaptureFolder()), m_recMonitor, SLOT(slotUpdateCaptureFolder()));
1772     //connect(dialog, SIGNAL(updatePreviewSettings()), this, SLOT(slotUpdatePreviewSettings()));
1773     dialog->show();
1774     if (page != -1) dialog->showPage(page, option);
1775 }
1776
1777 void MainWindow::slotUpdatePreviewSettings() {
1778     if (m_activeDocument) {
1779         m_clipMonitor->slotSetXml(NULL, 0);
1780         m_activeDocument->updatePreviewSettings();
1781     }
1782 }
1783
1784 void MainWindow::updateConfiguration() {
1785     //TODO: we should apply settings to all projects, not only the current one
1786     if (m_activeTimeline) {
1787         m_activeTimeline->refresh();
1788         m_activeTimeline->projectView()->checkAutoScroll();
1789         m_activeTimeline->projectView()->checkTrackHeight();
1790         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1791     }
1792     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1793     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1794 #ifndef NO_JOGSHUTTLE
1795     activateShuttleDevice();
1796 #endif /* NO_JOGSHUTTLE */
1797
1798 }
1799
1800
1801 void MainWindow::slotSwitchVideoThumbs() {
1802     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
1803     if (m_activeTimeline) {
1804         m_activeTimeline->projectView()->slotUpdateAllThumbs();
1805     }
1806     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1807 }
1808
1809 void MainWindow::slotSwitchAudioThumbs() {
1810     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
1811     if (m_activeTimeline) {
1812         m_activeTimeline->refresh();
1813         m_activeTimeline->projectView()->checkAutoScroll();
1814         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1815     }
1816     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1817 }
1818
1819 void MainWindow::slotSwitchMarkersComments() {
1820     KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
1821     if (m_activeTimeline) {
1822         m_activeTimeline->refresh();
1823     }
1824     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
1825 }
1826
1827 void MainWindow::slotSwitchSnap() {
1828     KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
1829     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
1830 }
1831
1832
1833 void MainWindow::slotDeleteTimelineClip() {
1834     if (QApplication::focusWidget()->parentWidget()->parentWidget() == projectListDock) m_projectList->slotRemoveClip();
1835     else if (m_activeTimeline) {
1836         m_activeTimeline->projectView()->deleteSelectedClips();
1837     }
1838 }
1839
1840 void MainWindow::slotChangeClipSpeed() {
1841     if (m_activeTimeline) {
1842         m_activeTimeline->projectView()->changeClipSpeed();
1843     }
1844 }
1845
1846 void MainWindow::slotAddClipMarker() {
1847     DocClipBase *clip = NULL;
1848     GenTime pos;
1849     if (m_projectMonitor->isActive()) {
1850         if (m_activeTimeline) {
1851             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1852             if (item) {
1853                 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
1854                 clip = item->baseClip();
1855             }
1856         }
1857     } else {
1858         clip = m_clipMonitor->activeClip();
1859         pos = m_clipMonitor->position();
1860     }
1861     if (!clip) {
1862         m_messageLabel->setMessage(i18n("Cannot find clip to add marker"), ErrorMessage);
1863         return;
1864     }
1865     QString id = clip->getId();
1866     CommentedTime marker(pos, i18n("Marker"));
1867     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Add Marker"), this);
1868     if (d.exec() == QDialog::Accepted) {
1869         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
1870     }
1871     if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1872 }
1873
1874 void MainWindow::slotDeleteClipMarker() {
1875     DocClipBase *clip = NULL;
1876     GenTime pos;
1877     if (m_projectMonitor->isActive()) {
1878         if (m_activeTimeline) {
1879             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1880             if (item) {
1881                 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
1882                 clip = item->baseClip();
1883             }
1884         }
1885     } else {
1886         clip = m_clipMonitor->activeClip();
1887         pos = m_clipMonitor->position();
1888     }
1889     if (!clip) {
1890         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
1891         return;
1892     }
1893
1894     QString id = clip->getId();
1895     QString comment = clip->markerComment(pos);
1896     if (comment.isEmpty()) {
1897         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
1898         return;
1899     }
1900     m_activeTimeline->projectView()->slotDeleteClipMarker(comment, id, pos);
1901     if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1902
1903 }
1904
1905 void MainWindow::slotDeleteAllClipMarkers() {
1906     DocClipBase *clip = NULL;
1907     if (m_projectMonitor->isActive()) {
1908         if (m_activeTimeline) {
1909             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1910             if (item) {
1911                 clip = item->baseClip();
1912             }
1913         }
1914     } else {
1915         clip = m_clipMonitor->activeClip();
1916     }
1917     if (!clip) {
1918         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
1919         return;
1920     }
1921     m_activeTimeline->projectView()->slotDeleteAllClipMarkers(clip->getId());
1922     if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1923 }
1924
1925 void MainWindow::slotEditClipMarker() {
1926     DocClipBase *clip = NULL;
1927     GenTime pos;
1928     if (m_projectMonitor->isActive()) {
1929         if (m_activeTimeline) {
1930             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1931             if (item) {
1932                 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
1933                 clip = item->baseClip();
1934             }
1935         }
1936     } else {
1937         clip = m_clipMonitor->activeClip();
1938         pos = m_clipMonitor->position();
1939     }
1940     if (!clip) {
1941         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
1942         return;
1943     }
1944
1945     QString id = clip->getId();
1946     QString oldcomment = clip->markerComment(pos);
1947     if (oldcomment.isEmpty()) {
1948         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
1949         return;
1950     }
1951
1952     CommentedTime marker(pos, oldcomment);
1953     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Edit Marker"), this);
1954     if (d.exec() == QDialog::Accepted) {
1955         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
1956         if (d.newMarker().time() != pos) {
1957             // remove old marker
1958             m_activeTimeline->projectView()->slotAddClipMarker(id, pos, QString());
1959         }
1960         if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1961     }
1962 }
1963
1964 void MainWindow::slotAddGuide() {
1965     if (m_activeTimeline)
1966         m_activeTimeline->projectView()->slotAddGuide();
1967 }
1968
1969 void MainWindow::slotInsertSpace() {
1970     if (m_activeTimeline)
1971         m_activeTimeline->projectView()->slotInsertSpace();
1972 }
1973
1974 void MainWindow::slotRemoveSpace() {
1975     if (m_activeTimeline)
1976         m_activeTimeline->projectView()->slotRemoveSpace();
1977 }
1978
1979 void MainWindow::slotInsertTrack(int ix) {
1980     m_projectMonitor->activateMonitor();
1981     if (m_activeTimeline)
1982         m_activeTimeline->projectView()->slotInsertTrack(ix);
1983 }
1984
1985 void MainWindow::slotDeleteTrack(int ix) {
1986     m_projectMonitor->activateMonitor();
1987     if (m_activeTimeline)
1988         m_activeTimeline->projectView()->slotDeleteTrack(ix);
1989 }
1990
1991 void MainWindow::slotChangeTrack(int ix) {
1992     m_projectMonitor->activateMonitor();
1993     if (m_activeTimeline)
1994         m_activeTimeline->projectView()->slotChangeTrack(ix);
1995 }
1996
1997 void MainWindow::slotEditGuide() {
1998     if (m_activeTimeline)
1999         m_activeTimeline->projectView()->slotEditGuide();
2000 }
2001
2002 void MainWindow::slotDeleteGuide() {
2003     if (m_activeTimeline)
2004         m_activeTimeline->projectView()->slotDeleteGuide();
2005 }
2006
2007 void MainWindow::slotDeleteAllGuides() {
2008     if (m_activeTimeline)
2009         m_activeTimeline->projectView()->slotDeleteAllGuides();
2010 }
2011
2012 void MainWindow::slotCutTimelineClip() {
2013     if (m_activeTimeline) {
2014         m_activeTimeline->projectView()->cutSelectedClips();
2015     }
2016 }
2017
2018 void MainWindow::slotGroupClips() {
2019     if (m_activeTimeline) {
2020         m_activeTimeline->projectView()->groupClips();
2021     }
2022 }
2023
2024 void MainWindow::slotUnGroupClips() {
2025     if (m_activeTimeline) {
2026         m_activeTimeline->projectView()->groupClips(false);
2027     }
2028 }
2029
2030 void MainWindow::slotAddProjectClip(KUrl url) {
2031     if (m_activeDocument)
2032         m_activeDocument->slotAddClipFile(url, QString());
2033 }
2034
2035 void MainWindow::slotAddTransition(QAction *result) {
2036     if (!result) return;
2037     QStringList info = result->data().toStringList();
2038     if (info.isEmpty()) return;
2039     QDomElement transition = transitions.getEffectByTag(info.at(1), info.at(2));
2040     if (m_activeTimeline && !transition.isNull()) {
2041         m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(transition.cloneNode().toElement());
2042     }
2043 }
2044
2045 void MainWindow::slotAddVideoEffect(QAction *result) {
2046     if (!result) return;
2047     QStringList info = result->data().toStringList();
2048     if (info.isEmpty()) return;
2049     QDomElement effect = videoEffects.getEffectByTag(info.at(1), info.at(2));
2050     slotAddEffect(effect);
2051 }
2052
2053 void MainWindow::slotAddAudioEffect(QAction *result) {
2054     if (!result) return;
2055     QStringList info = result->data().toStringList();
2056     if (info.isEmpty()) return;
2057     QDomElement effect = audioEffects.getEffectByTag(info.at(1), info.at(2));
2058     slotAddEffect(effect);
2059 }
2060
2061 void MainWindow::slotAddCustomEffect(QAction *result) {
2062     if (!result) return;
2063     QStringList info = result->data().toStringList();
2064     if (info.isEmpty()) return;
2065     QDomElement effect = customEffects.getEffectByTag(info.at(1), info.at(2));
2066     slotAddEffect(effect);
2067 }
2068
2069 void MainWindow::slotZoomIn() {
2070     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
2071 }
2072
2073 void MainWindow::slotZoomOut() {
2074     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
2075 }
2076
2077 void MainWindow::slotFitZoom() {
2078     if (m_activeTimeline) {
2079         m_zoomSlider->setValue(m_activeTimeline->fitZoom());
2080     }
2081 }
2082
2083 void MainWindow::slotGotProgressInfo(const QString &message, int progress) {
2084     statusProgressBar->setValue(progress);
2085     if (progress >= 0) {
2086         if (!message.isEmpty()) m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
2087         statusProgressBar->setVisible(true);
2088     } else {
2089         m_messageLabel->setMessage(QString(), DefaultMessage);
2090         statusProgressBar->setVisible(false);
2091     }
2092 }
2093
2094 void MainWindow::slotShowClipProperties(DocClipBase *clip) {
2095     if (clip->clipType() == TEXT) {
2096         QString titlepath = m_activeDocument->projectFolder().path() + "/titles/";
2097         QString path = clip->getProperty("resource");
2098         TitleWidget *dia_ui = new TitleWidget(KUrl(), titlepath, m_projectMonitor->render, this);
2099         QDomDocument doc;
2100         doc.setContent(clip->getProperty("xmldata"));
2101         dia_ui->setXml(doc);
2102         if (dia_ui->exec() == QDialog::Accepted) {
2103             QImage pix = dia_ui->renderedPixmap();
2104             pix.save(path);
2105             //slotAddClipFile(KUrl("/tmp/kdenlivetitle.png"), QString(), -1);
2106             //m_clipManager->slotEditTextClipFile(id, dia_ui->xml().toString());
2107             QMap <QString, QString> newprops;
2108             newprops.insert("xmldata", dia_ui->xml().toString());
2109             EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
2110             m_activeDocument->commandStack()->push(command);
2111             m_clipMonitor->refreshMonitor(true);
2112             m_activeDocument->setModified(true);
2113         }
2114         delete dia_ui;
2115
2116         //m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
2117         return;
2118     }
2119     ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
2120     connect(&dia, SIGNAL(addMarker(const QString &, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(const QString &, GenTime, QString)));
2121     if (dia.exec() == QDialog::Accepted) {
2122         EditClipCommand *command = new EditClipCommand(m_projectList, dia.clipId(), clip->properties(), dia.properties(), true);
2123         m_activeDocument->commandStack()->push(command);
2124
2125         //m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
2126         if (dia.needsTimelineRefresh()) {
2127             // update clip occurences in timeline
2128             m_activeTimeline->projectView()->slotUpdateClip(dia.clipId());
2129         }
2130     }
2131 }
2132
2133 void MainWindow::customEvent(QEvent* e) {
2134     if (e->type() == QEvent::User) {
2135         // The timeline playing position changed...
2136         kDebug() << "RECEIVED JOG EVEMNT!!!";
2137     }
2138 }
2139 void MainWindow::slotActivateEffectStackView() {
2140     effectStack->raiseWindow(effectStackDock);
2141 }
2142
2143 void MainWindow::slotActivateTransitionView(Transition *t) {
2144     if (t) transitionConfig->raiseWindow(transitionConfigDock);
2145 }
2146
2147 void MainWindow::slotSnapRewind() {
2148     if (m_projectMonitor->isActive()) {
2149         if (m_activeTimeline)
2150             m_activeTimeline->projectView()->slotSeekToPreviousSnap();
2151     } else m_clipMonitor->slotSeekToPreviousSnap();
2152 }
2153
2154 void MainWindow::slotSnapForward() {
2155     if (m_projectMonitor->isActive()) {
2156         if (m_activeTimeline)
2157             m_activeTimeline->projectView()->slotSeekToNextSnap();
2158     } else m_clipMonitor->slotSeekToNextSnap();
2159 }
2160
2161 void MainWindow::slotClipStart() {
2162     if (m_projectMonitor->isActive()) {
2163         if (m_activeTimeline)
2164             m_activeTimeline->projectView()->clipStart();
2165     }
2166 }
2167
2168 void MainWindow::slotClipEnd() {
2169     if (m_projectMonitor->isActive()) {
2170         if (m_activeTimeline)
2171             m_activeTimeline->projectView()->clipEnd();
2172     }
2173 }
2174
2175 void MainWindow::slotChangeTool(QAction * action) {
2176     if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
2177     else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
2178     else if (action == m_buttonSpacerTool) slotSetTool(SPACERTOOL);
2179 }
2180
2181 void MainWindow::slotSetTool(PROJECTTOOL tool) {
2182     if (m_activeDocument && m_activeTimeline) {
2183         //m_activeDocument->setTool(tool);
2184         m_activeTimeline->projectView()->setTool(tool);
2185     }
2186 }
2187
2188 void MainWindow::slotCopy() {
2189     if (!m_activeDocument || !m_activeTimeline) return;
2190     m_activeTimeline->projectView()->copyClip();
2191 }
2192
2193 void MainWindow::slotPaste() {
2194     if (!m_activeDocument || !m_activeTimeline) return;
2195     m_activeTimeline->projectView()->pasteClip();
2196 }
2197
2198 void MainWindow::slotPasteEffects() {
2199     if (!m_activeDocument || !m_activeTimeline) return;
2200     m_activeTimeline->projectView()->pasteClipEffects();
2201 }
2202
2203 void MainWindow::slotFind() {
2204     if (!m_activeDocument || !m_activeTimeline) return;
2205     m_projectSearch->setEnabled(false);
2206     m_findActivated = true;
2207     m_findString.clear();
2208     m_activeTimeline->projectView()->initSearchStrings();
2209     statusBar()->showMessage(i18n("Starting -- find text as you type"));
2210     m_findTimer.start(5000);
2211     qApp->installEventFilter(this);
2212 }
2213
2214 void MainWindow::slotFindNext() {
2215     if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString)) {
2216         statusBar()->showMessage(i18n("Found : %1", m_findString));
2217     } else {
2218         statusBar()->showMessage(i18n("Reached end of project"));
2219     }
2220     m_findTimer.start(4000);
2221 }
2222
2223 void MainWindow::findAhead() {
2224     if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
2225         m_projectSearchNext->setEnabled(true);
2226         statusBar()->showMessage(i18n("Found : %1", m_findString));
2227     } else {
2228         m_projectSearchNext->setEnabled(false);
2229         statusBar()->showMessage(i18n("Not found : %1", m_findString));
2230     }
2231 }
2232
2233 void MainWindow::findTimeout() {
2234     m_projectSearchNext->setEnabled(false);
2235     m_findActivated = false;
2236     m_findString.clear();
2237     statusBar()->showMessage(i18n("Find stopped"), 3000);
2238     if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
2239     m_projectSearch->setEnabled(true);
2240     removeEventFilter(this);
2241 }
2242
2243 void MainWindow::keyPressEvent(QKeyEvent *ke) {
2244     if (m_findActivated) {
2245         if (ke->key() == Qt::Key_Backspace) {
2246             m_findString = m_findString.left(m_findString.length() - 1);
2247
2248             if (!m_findString.isEmpty()) {
2249                 findAhead();
2250             } else {
2251                 findTimeout();
2252             }
2253
2254             m_findTimer.start(4000);
2255             ke->accept();
2256             return;
2257         } else if (ke->key() == Qt::Key_Escape) {
2258             findTimeout();
2259             ke->accept();
2260             return;
2261         } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
2262             m_findString += ke->text();
2263
2264             findAhead();
2265
2266             m_findTimer.start(4000);
2267             ke->accept();
2268             return;
2269         }
2270     } else KXmlGuiWindow::keyPressEvent(ke);
2271 }
2272
2273
2274 /** Gets called when the window gets hidden */
2275 void MainWindow::hideEvent(QHideEvent */*event*/) {
2276     // kDebug() << "I was hidden";
2277     // issue http://www.kdenlive.org/mantis/view.php?id=231
2278     if (this->isMinimized()) {
2279         // kDebug() << "I am minimized";
2280         if (m_monitorManager) m_monitorManager->stopActiveMonitor();
2281     }
2282 }
2283
2284 bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
2285     if (m_findActivated) {
2286         if (event->type() == QEvent::ShortcutOverride) {
2287             QKeyEvent* ke = (QKeyEvent*) event;
2288             if (ke->text().trimmed().isEmpty()) return false;
2289             ke->accept();
2290             return true;
2291         } else return false;
2292     } else {
2293         // pass the event on to the parent class
2294         return QMainWindow::eventFilter(obj, event);
2295     }
2296 }
2297
2298 void MainWindow::slotSaveZone(Render *render, QPoint zone) {
2299     KDialog *dialog = new KDialog(this);
2300     dialog->setCaption("Save clip zone");
2301     dialog->setButtons(KDialog::Ok | KDialog::Cancel);
2302
2303     QWidget *widget = new QWidget(dialog);
2304     dialog->setMainWidget(widget);
2305
2306     QVBoxLayout *vbox = new QVBoxLayout(widget);
2307     QLabel *label1 = new QLabel(i18n("Save clip zone as:"), this);
2308     QString path = m_activeDocument->projectFolder().path();
2309     path.append("/");
2310     path.append("untitled.westley");
2311     KUrlRequester *url = new KUrlRequester(KUrl(path), this);
2312     url->setFilter("video/mlt-playlist");
2313     QLabel *label2 = new QLabel(i18n("Description:"), this);
2314     KLineEdit *edit = new KLineEdit(this);
2315     vbox->addWidget(label1);
2316     vbox->addWidget(url);
2317     vbox->addWidget(label2);
2318     vbox->addWidget(edit);
2319     if (dialog->exec() == QDialog::Accepted) render->saveZone(url->url(), edit->text(), zone);
2320
2321 }
2322
2323 void MainWindow::slotSetInPoint() {
2324     if (m_clipMonitor->isActive()) {
2325         m_clipMonitor->slotSetZoneStart();
2326     } else m_activeTimeline->projectView()->setInPoint();
2327 }
2328
2329 void MainWindow::slotSetOutPoint() {
2330     if (m_clipMonitor->isActive()) {
2331         m_clipMonitor->slotSetZoneEnd();
2332     } else m_activeTimeline->projectView()->setOutPoint();
2333 }
2334
2335 void MainWindow::slotGetNewLumaStuff() {
2336     //KNS::Entry::List download();
2337     KNS::Entry::List entries = KNS::Engine::download();
2338     // list of changed entries
2339     kDebug() << "// PARSING KNS";
2340     foreach(KNS::Entry* entry, entries) {
2341         // care only about installed ones
2342         if (entry->status() == KNS::Entry::Installed) {
2343             foreach(const QString &file, entry->installedFiles()) {
2344                 kDebug() << "// CURRENTLY INSTALLED: " << file;
2345             }
2346         }
2347     }
2348     qDeleteAll(entries);
2349     initEffects::refreshLumas();
2350 }
2351
2352 void MainWindow::slotGetNewRenderStuff() {
2353     //KNS::Entry::List download();
2354
2355     KNS::Engine engine(0);
2356     if (engine.init("kdenlive_render.knsrc")) {
2357         KNS::Entry::List entries = engine.downloadDialogModal(this);
2358
2359         if (entries.size() > 0) {
2360             foreach(KNS::Entry* entry, entries) {
2361                 // care only about installed ones
2362                 if (entry->status() == KNS::Entry::Installed) {
2363                     foreach(const QString &file, entry->installedFiles()) {
2364                         kDebug() << "// CURRENTLY INSTALLED: " << file;
2365                     }
2366                 }
2367             }
2368         }
2369         if (m_renderWidget) m_renderWidget->reloadProfiles();
2370     }
2371 }
2372
2373 void MainWindow::slotGetNewMltProfileStuff() {
2374     //KNS::Entry::List download();
2375
2376     KNS::Engine engine(0);
2377     if (engine.init("kdenlive_mltprofiles.knsrc")) {
2378         KNS::Entry::List entries = engine.downloadDialogModal(this);
2379
2380         if (entries.size() > 0) {
2381             foreach(KNS::Entry* entry, entries) {
2382                 // care only about installed ones
2383                 if (entry->status() == KNS::Entry::Installed) {
2384                     foreach(const QString &file, entry->installedFiles()) {
2385                         kDebug() << "// CURRENTLY INSTALLED: " << file;
2386                     }
2387                 }
2388             }
2389
2390             // update the list of profiles in settings dialog
2391             KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
2392             if (d) d->checkProfile();
2393         }
2394     }
2395 }
2396
2397 void MainWindow::slotAutoTransition() {
2398     if (m_activeTimeline) m_activeTimeline->projectView()->autoTransition();
2399 }
2400
2401 void MainWindow::slotSplitAudio() {
2402     if (m_activeTimeline) m_activeTimeline->projectView()->splitAudio();
2403 }
2404
2405 void MainWindow::slotAudioOnly() {
2406     if (m_activeTimeline) m_activeTimeline->projectView()->audioOnly();
2407 }
2408
2409 void MainWindow::slotVideoOnly() {
2410     if (m_activeTimeline) m_activeTimeline->projectView()->videoOnly();
2411 }
2412
2413 void MainWindow::slotDvdWizard(const QString &url, const QString &profile) {
2414     DvdWizard *w = new DvdWizard(url, profile, this);
2415     w->exec();
2416 }
2417
2418
2419 #include "mainwindow.moc"