]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
* Vectorscope added
[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 #include "cliptranscode.h"
54 #include "ui_templateclip_ui.h"
55 #include "vectorscope.h"
56
57 #include <KApplication>
58 #include <KAction>
59 #include <KLocale>
60 #include <KGlobal>
61 #include <KActionCollection>
62 #include <KActionCategory>
63 #include <KStandardAction>
64 #include <KShortcutsDialog>
65 #include <KFileDialog>
66 #include <KMessageBox>
67 #include <KDebug>
68 #include <KIO/NetAccess>
69 #include <KSaveFile>
70 #include <KRuler>
71 #include <KConfigDialog>
72 #include <KXMLGUIFactory>
73 #include <KStatusBar>
74 #include <kstandarddirs.h>
75 #include <KUrlRequesterDialog>
76 #include <KTemporaryFile>
77 #include <KProcess>
78 #include <KActionMenu>
79 #include <KMenu>
80 #include <locale.h>
81 #include <ktogglefullscreenaction.h>
82 #include <KFileItem>
83 #include <KNotification>
84 #include <KNotifyConfigWidget>
85 #if KDE_IS_VERSION(4,3,80)
86 #include <knewstuff3/downloaddialog.h>
87 #include <knewstuff3/knewstuffaction.h>
88 #else
89 #include <knewstuff2/engine.h>
90 #include <knewstuff2/ui/knewstuffaction.h>
91 #define KNS3 KNS
92 #endif /* KDE_IS_VERSION(4,3,80) */
93 #include <KToolBar>
94 #include <KColorScheme>
95
96 #include <QTextStream>
97 #include <QTimer>
98 #include <QAction>
99 #include <QKeyEvent>
100 #include <QInputDialog>
101 #include <QDesktopWidget>
102 #include <QBitmap>
103
104 #include <stdlib.h>
105
106 static const char version[] = VERSION;
107
108 static const int ID_TIMELINE_POS = 0;
109
110 namespace Mlt
111 {
112 class Producer;
113 };
114
115 EffectsList MainWindow::videoEffects;
116 EffectsList MainWindow::audioEffects;
117 EffectsList MainWindow::customEffects;
118 EffectsList MainWindow::transitions;
119
120 MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, QWidget *parent) :
121         KXmlGuiWindow(parent),
122         m_activeDocument(NULL),
123         m_activeTimeline(NULL),
124         m_renderWidget(NULL),
125 #ifndef NO_JOGSHUTTLE
126         m_jogProcess(NULL),
127 #endif /* NO_JOGSHUTTLE */
128         m_findActivated(false)
129 {
130
131     // Create DBus interface
132     new MainWindowAdaptor(this);
133     QDBusConnection dbus = QDBusConnection::sessionBus();
134     dbus.registerObject("/MainWindow", this);
135
136     setlocale(LC_NUMERIC, "POSIX");
137     if (!KdenliveSettings::colortheme().isEmpty()) slotChangePalette(NULL, KdenliveSettings::colortheme());
138     setFont(KGlobalSettings::toolBarFont());
139     parseProfiles(MltPath);
140     m_commandStack = new QUndoGroup;
141     m_timelineArea = new KTabWidget(this);
142     m_timelineArea->setTabReorderingEnabled(true);
143     m_timelineArea->setTabBarHidden(true);
144     m_timelineArea->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
145     m_timelineArea->setMinimumHeight(200);
146
147     QToolButton *closeTabButton = new QToolButton;
148     connect(closeTabButton, SIGNAL(clicked()), this, SLOT(closeCurrentDocument()));
149     closeTabButton->setIcon(KIcon("tab-close"));
150     closeTabButton->adjustSize();
151     closeTabButton->setToolTip(i18n("Close the current tab"));
152     m_timelineArea->setCornerWidget(closeTabButton);
153     connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
154
155     connect(&m_findTimer, SIGNAL(timeout()), this, SLOT(findTimeout()));
156     m_findTimer.setSingleShot(true);
157
158     // FIXME: the next call returns a newly allocated object, which leaks
159     initEffects::parseEffectFiles();
160     //initEffects::parseCustomEffectsFile();
161
162     m_monitorManager = new MonitorManager();
163
164     m_shortcutRemoveFocus = new QShortcut(QKeySequence("Esc"), this);
165     connect(m_shortcutRemoveFocus, SIGNAL(activated()), this, SLOT(slotRemoveFocus()));
166
167
168     /// Add Widgets ///
169
170     m_projectListDock = new QDockWidget(i18n("Project Tree"), this);
171     m_projectListDock->setObjectName("project_tree");
172     m_projectList = new ProjectList(this);
173     m_projectListDock->setWidget(m_projectList);
174     addDockWidget(Qt::TopDockWidgetArea, m_projectListDock);
175
176     m_effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
177     m_effectStackDock->setObjectName("effect_stack");
178     m_effectStack = new EffectStackView(this);
179     m_effectStackDock->setWidget(m_effectStack);
180     addDockWidget(Qt::TopDockWidgetArea, m_effectStackDock);
181
182     m_transitionConfigDock = new QDockWidget(i18n("Transition"), this);
183     m_transitionConfigDock->setObjectName("transition");
184     m_transitionConfig = new TransitionSettings(this);
185     m_transitionConfigDock->setWidget(m_transitionConfig);
186     addDockWidget(Qt::TopDockWidgetArea, m_transitionConfigDock);
187
188     m_clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
189     m_clipMonitorDock->setObjectName("clip_monitor");
190     m_clipMonitor = new Monitor("clip", m_monitorManager, QString(), this);
191     m_clipMonitorDock->setWidget(m_clipMonitor);
192     addDockWidget(Qt::TopDockWidgetArea, m_clipMonitorDock);
193
194     m_projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
195     m_projectMonitorDock->setObjectName("project_monitor");
196     m_projectMonitor = new Monitor("project", m_monitorManager, QString(), this);
197     m_projectMonitorDock->setWidget(m_projectMonitor);
198     addDockWidget(Qt::TopDockWidgetArea, m_projectMonitorDock);
199
200 #ifndef Q_WS_MAC
201     m_recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
202     m_recMonitorDock->setObjectName("record_monitor");
203     m_recMonitor = new RecMonitor("record", this);
204     m_recMonitorDock->setWidget(m_recMonitor);
205     addDockWidget(Qt::TopDockWidgetArea, m_recMonitorDock);
206
207     connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
208     connect(m_recMonitor, SIGNAL(showConfigDialog(int, int)), this, SLOT(slotPreferences(int, int)));
209 #endif
210
211     m_effectListDock = new QDockWidget(i18n("Effect List"), this);
212     m_effectListDock->setObjectName("effect_list");
213     m_effectList = new EffectsListView();
214     m_effectListDock->setWidget(m_effectList);
215     addDockWidget(Qt::TopDockWidgetArea, m_effectListDock);
216
217     m_vectorscope = new Vectorscope(m_projectMonitor->render, this);
218     m_vectorscopeDock = new QDockWidget(i18n("Vectorscope"), this);
219     m_vectorscopeDock->setObjectName("vectorscope");
220     m_vectorscopeDock->setWidget(m_vectorscope);
221     addDockWidget(Qt::TopDockWidgetArea, m_vectorscopeDock);
222
223
224     m_undoViewDock = new QDockWidget(i18n("Undo History"), this);
225     m_undoViewDock->setObjectName("undo_history");
226     m_undoView = new QUndoView(this);
227     m_undoView->setCleanIcon(KIcon("edit-clear"));
228     m_undoView->setEmptyLabel(i18n("Clean"));
229     m_undoViewDock->setWidget(m_undoView);
230     m_undoView->setGroup(m_commandStack);
231     addDockWidget(Qt::TopDockWidgetArea, m_undoViewDock);
232
233     //overviewDock = new QDockWidget(i18n("Project Overview"), this);
234     //overviewDock->setObjectName("project_overview");
235     //m_overView = new CustomTrackView(NULL, NULL, this);
236     //overviewDock->setWidget(m_overView);
237     //addDockWidget(Qt::TopDockWidgetArea, overviewDock);
238
239
240     setupActions();
241
242     /// Tabify Widgets ///
243     tabifyDockWidget(m_projectListDock, m_effectStackDock);
244     tabifyDockWidget(m_projectListDock, m_transitionConfigDock);
245
246
247     tabifyDockWidget(m_clipMonitorDock, m_projectMonitorDock);
248 #ifndef Q_WS_MAC
249     tabifyDockWidget(m_clipMonitorDock, m_recMonitorDock);
250 #endif
251
252     tabifyDockWidget(m_vectorscopeDock, m_undoViewDock);
253     tabifyDockWidget(m_vectorscopeDock, m_effectListDock);
254
255
256     setCentralWidget(m_timelineArea);
257
258
259     KdenliveSettings::setCurrent_profile(KdenliveSettings::default_profile());
260     m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)), actionCollection());
261     readOptions();
262     m_fileRevert = KStandardAction::revert(this, SLOT(slotRevert()), actionCollection());
263     m_fileRevert->setEnabled(false);
264
265
266     setupGUI();
267
268
269     // Find QDockWidget tab bars and show / hide widget title bars on right click
270     QList <QTabBar *> tabs = findChildren<QTabBar *>();
271     for (int i = 0; i < tabs.count(); i++) {
272         tabs.at(i)->setContextMenuPolicy(Qt::CustomContextMenu);
273         connect(tabs.at(i), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(slotSwitchTitles()));
274     }
275
276     /*ScriptingPart* sp = new ScriptingPart(this, QStringList());
277     guiFactory()->addClient(sp);*/
278
279     loadPlugins();
280     loadTranscoders();
281     //kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
282
283     m_projectMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)), m_playZone, m_loopZone);
284     m_clipMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)), m_playZone, m_loopZone, static_cast<QMenu*>(factory()->container("marker_menu", this)));
285
286     QMenu *clipInTimeline = static_cast<QMenu*>(factory()->container("clip_in_timeline", this));
287     clipInTimeline->setIcon(KIcon("go-jump"));
288     m_projectList->setupGeneratorMenu(static_cast<QMenu*>(factory()->container("generators", this)),
289                                       static_cast<QMenu*>(factory()->container("transcoders", this)),
290                                       clipInTimeline);
291
292     KAction *action;
293     // build themes menus
294     QMenu *themesMenu = static_cast<QMenu*>(factory()->container("themes_menu", this));
295     QActionGroup *themegroup = new QActionGroup(this);
296     themegroup->setExclusive(true);
297     action = new KAction(i18n("Default"), this);
298     action->setCheckable(true);
299     themegroup->addAction(action);
300     if (KdenliveSettings::colortheme().isEmpty()) action->setChecked(true);
301
302     const QStringList schemeFiles = KGlobal::dirs()->findAllResources("data", "color-schemes/*.colors", KStandardDirs::NoDuplicates);
303
304     for (int i = 0; i < schemeFiles.size(); ++i) {
305         // get the file name
306         const QString filename = schemeFiles.at(i);
307         const QFileInfo info(filename);
308
309         // add the entry
310         KSharedConfigPtr config = KSharedConfig::openConfig(filename);
311         QIcon icon = createSchemePreviewIcon(config);
312         KConfigGroup group(config, "General");
313         const QString name = group.readEntry("Name", info.baseName());
314         action = new KAction(name, this);
315         action->setData(filename);
316         action->setIcon(icon);
317         action->setCheckable(true);
318         themegroup->addAction(action);
319         if (KdenliveSettings::colortheme() == filename) action->setChecked(true);
320     }
321
322     /*KGlobal::dirs()->addResourceDir("themes", KStandardDirs::installPath("data") + QString("kdenlive/themes"));
323     QStringList themes = KGlobal::dirs()->findAllResources("themes", QString(), KStandardDirs::Recursive | KStandardDirs::NoDuplicates);
324     for (QStringList::const_iterator it = themes.constBegin(); it != themes.constEnd(); ++it)
325     {
326     QFileInfo fi(*it);
327         action = new QAction(fi.fileName(), this);
328         action->setData(*it);
329     action->setCheckable(true);
330     themegroup->addAction(action);
331     if (KdenliveSettings::colortheme() == *it) action->setChecked(true);
332     }*/
333     themesMenu->addActions(themegroup->actions());
334     connect(themesMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotChangePalette(QAction*)));
335
336     // Setup and fill effects and transitions menus.
337     m_videoEffectsMenu = static_cast<QMenu*>(factory()->container("video_effects_menu", this));
338     for (int i = 0; i < videoEffects.count(); ++i)
339         m_videoEffectsMenu->addAction(m_videoEffects[i]);
340     m_audioEffectsMenu = static_cast<QMenu*>(factory()->container("audio_effects_menu", this));
341     for (int i = 0; i < audioEffects.count(); ++i)
342         m_audioEffectsMenu->addAction(m_audioEffects[i]);
343     m_customEffectsMenu = static_cast<QMenu*>(factory()->container("custom_effects_menu", this));
344     if (customEffects.isEmpty())
345         m_customEffectsMenu->setEnabled(false);
346     else
347         m_customEffectsMenu->setEnabled(true);
348     for (int i = 0; i < customEffects.count(); ++i)
349         m_customEffectsMenu->addAction(m_customEffects[i]);
350     m_transitionsMenu = new QMenu(i18n("Add Transition"), this);
351     for (int i = 0; i < transitions.count(); ++i)
352         m_transitionsMenu->addAction(m_transitions[i]);
353
354     connect(m_videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
355     connect(m_audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
356     connect(m_customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
357     connect(m_transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
358
359     QMenu *newEffect = new QMenu(this);
360     newEffect->addMenu(m_videoEffectsMenu);
361     newEffect->addMenu(m_audioEffectsMenu);
362     newEffect->addMenu(m_customEffectsMenu);
363     m_effectStack->setMenu(newEffect);
364
365     QMenu *viewMenu = static_cast<QMenu*>(factory()->container("dockwindows", this));
366     const QList<QAction *> viewActions = createPopupMenu()->actions();
367     viewMenu->insertActions(NULL, viewActions);
368
369     m_timelineContextMenu = new QMenu(this);
370     m_timelineContextClipMenu = new QMenu(this);
371     m_timelineContextTransitionMenu = new QMenu(this);
372
373     m_timelineContextMenu->addAction(actionCollection()->action("insert_space"));
374     m_timelineContextMenu->addAction(actionCollection()->action("delete_space"));
375     m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));
376
377     m_timelineContextClipMenu->addAction(actionCollection()->action("clip_in_project_tree"));
378     //m_timelineContextClipMenu->addAction(actionCollection()->action("clip_to_project_tree"));
379     m_timelineContextClipMenu->addAction(actionCollection()->action("edit_item_duration"));
380     m_timelineContextClipMenu->addAction(actionCollection()->action("delete_item"));
381     m_timelineContextClipMenu->addAction(actionCollection()->action("group_clip"));
382     m_timelineContextClipMenu->addAction(actionCollection()->action("ungroup_clip"));
383     m_timelineContextClipMenu->addAction(actionCollection()->action("cut_timeline_clip"));
384     m_timelineContextClipMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
385     m_timelineContextClipMenu->addAction(actionCollection()->action("paste_effects"));
386     m_timelineContextClipMenu->addAction(actionCollection()->action("split_audio"));
387
388     QMenu *markersMenu = (QMenu*)(factory()->container("marker_menu", this));
389     m_timelineContextClipMenu->addMenu(markersMenu);
390     m_timelineContextClipMenu->addMenu(m_transitionsMenu);
391     m_timelineContextClipMenu->addMenu(m_videoEffectsMenu);
392     m_timelineContextClipMenu->addMenu(m_audioEffectsMenu);
393     //TODO: re-enable custom effects menu when it is implemented
394     m_timelineContextClipMenu->addMenu(m_customEffectsMenu);
395
396     m_timelineContextTransitionMenu->addAction(actionCollection()->action("edit_item_duration"));
397     m_timelineContextTransitionMenu->addAction(actionCollection()->action("delete_item"));
398     m_timelineContextTransitionMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
399
400     m_timelineContextTransitionMenu->addAction(actionCollection()->action("auto_transition"));
401
402     connect(m_projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
403     connect(m_clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
404     //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
405     connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
406     connect(m_effectList, SIGNAL(addEffect(const QDomElement)), this, SLOT(slotAddEffect(const QDomElement)));
407     connect(m_effectList, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
408
409     m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
410     slotConnectMonitors();
411
412     // Disable drop B frames, see Kdenlive issue #1330, see also kdenlivesettingsdialog.cpp
413     KdenliveSettings::setDropbframes(false);
414
415     // Open or create a file.  Command line argument passed in Url has
416     // precedence, then "openlastproject", then just a plain empty file.
417     // If opening Url fails, openlastproject will _not_ be used.
418     if (!Url.isEmpty()) {
419         // delay loading so that the window shows up
420         m_startUrl = Url;
421         QTimer::singleShot(500, this, SLOT(openFile()));
422     } else if (KdenliveSettings::openlastproject()) {
423         QTimer::singleShot(500, this, SLOT(openLastFile()));
424     } else { //if (m_timelineArea->count() == 0) {
425         newFile(false);
426     }
427
428 #ifndef NO_JOGSHUTTLE
429     activateShuttleDevice();
430 #endif /* NO_JOGSHUTTLE */
431     m_projectListDock->raise();
432 }
433
434 void MainWindow::queryQuit()
435 {
436     if (queryClose()) {
437         if (m_projectMonitor) m_projectMonitor->stop();
438         if (m_clipMonitor) m_clipMonitor->stop();
439         delete m_effectStack;
440         delete m_activeTimeline;
441 #ifndef Q_WS_MAC
442         // This sometimes causes crash on exit on OS X for some reason.
443         delete m_projectMonitor;
444         delete m_clipMonitor;
445 #endif
446         delete m_activeDocument;
447         delete m_shortcutRemoveFocus;
448         Mlt::Factory::close();
449         kapp->quit();
450     }
451 }
452
453 //virtual
454 bool MainWindow::queryClose()
455 {
456     if (m_renderWidget) {
457         int waitingJobs = m_renderWidget->waitingJobsCount();
458         if (waitingJobs > 0) {
459             switch (KMessageBox::warningYesNoCancel(this, i18np("You have 1 rendering job waiting in the queue.\nWhat do you want to do with this job?", "You have %1 rendering jobs waiting in the queue.\nWhat do you want to do with these jobs?", waitingJobs), QString(), KGuiItem(i18n("Start them now")), KGuiItem(i18n("Delete them")))) {
460             case KMessageBox::Yes :
461                 // create script with waiting jobs and start it
462                 if (m_renderWidget->startWaitingRenderJobs() == false) return false;
463                 break;
464             case KMessageBox::No :
465                 // Don't do anything, jobs will be deleted
466                 break;
467             default:
468                 return false;
469             }
470         }
471     }
472     saveOptions();
473     if (m_monitorManager) m_monitorManager->stopActiveMonitor();
474     // warn the user to save if document is modified and we have clips in our project list
475     if (m_activeDocument && m_activeDocument->isModified() &&
476         ((m_projectList->documentClipList().isEmpty() && !m_activeDocument->url().isEmpty()) ||
477             !m_projectList->documentClipList().isEmpty())) {
478         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document?"))) {
479         case KMessageBox::Yes :
480             // save document here. If saving fails, return false;
481             return saveFile();
482         case KMessageBox::No :
483             // User does not want to save the changes, clear recovery files
484             m_activeDocument->m_autosave->resize(0);
485             return true;
486         default: // cancel
487             return false;
488         }
489     }
490     return true;
491 }
492
493 void MainWindow::loadPlugins()
494 {
495     foreach(QObject *plugin, QPluginLoader::staticInstances()) {
496         populateMenus(plugin);
497     }
498
499     QStringList directories = KGlobal::dirs()->findDirs("module", QString());
500     QStringList filters;
501     filters << "libkdenlive*";
502     foreach(const QString &folder, directories) {
503         kDebug() << "Parsing plugin folder: " << folder;
504         QDir pluginsDir(folder);
505         foreach(const QString &fileName,
506                 pluginsDir.entryList(filters, QDir::Files)) {
507             /*
508              * Avoid loading the same plugin twice when there is more than one
509              * installation.
510              */
511             if (!m_pluginFileNames.contains(fileName)) {
512                 kDebug() << "Found plugin: " << fileName;
513                 QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
514                 QObject *plugin = loader.instance();
515                 if (plugin) {
516                     populateMenus(plugin);
517                     m_pluginFileNames += fileName;
518                 } else
519                     kDebug() << "Error loading plugin: " << fileName << ", " << loader.errorString();
520             }
521         }
522     }
523 }
524
525 void MainWindow::populateMenus(QObject *plugin)
526 {
527     QMenu *addMenu = static_cast<QMenu*>(factory()->container("generators", this));
528     ClipGenerator *iGenerator = qobject_cast<ClipGenerator *>(plugin);
529     if (iGenerator)
530         addToMenu(plugin, iGenerator->generators(KdenliveSettings::producerslist()), addMenu, SLOT(generateClip()),
531                   NULL);
532 }
533
534 void MainWindow::addToMenu(QObject *plugin, const QStringList &texts,
535                            QMenu *menu, const char *member,
536                            QActionGroup *actionGroup)
537 {
538     kDebug() << "// ADD to MENU" << texts;
539     foreach(const QString &text, texts) {
540         QAction *action = new QAction(text, plugin);
541         action->setData(text);
542         connect(action, SIGNAL(triggered()), this, member);
543         menu->addAction(action);
544
545         if (actionGroup) {
546             action->setCheckable(true);
547             actionGroup->addAction(action);
548         }
549     }
550 }
551
552 void MainWindow::aboutPlugins()
553 {
554     //PluginDialog dialog(pluginsDir.path(), m_pluginFileNames, this);
555     //dialog.exec();
556 }
557
558
559 void MainWindow::generateClip()
560 {
561     QAction *action = qobject_cast<QAction *>(sender());
562     ClipGenerator *iGenerator = qobject_cast<ClipGenerator *>(action->parent());
563
564     KUrl clipUrl = iGenerator->generatedClip(action->data().toString(), m_activeDocument->projectFolder(),
565                    QStringList(), QStringList(), m_activeDocument->fps(), m_activeDocument->width(), m_activeDocument->height());
566     if (!clipUrl.isEmpty()) {
567         m_projectList->slotAddClip(QList <QUrl> () << clipUrl);
568     }
569 }
570
571 void MainWindow::saveProperties(KConfigGroup &config)
572 {
573     // save properties here,used by session management
574     saveFile();
575     KMainWindow::saveProperties(config);
576 }
577
578
579 void MainWindow::readProperties(const KConfigGroup &config)
580 {
581     // read properties here,used by session management
582     KMainWindow::readProperties(config);
583     QString Lastproject = config.group("Recent Files").readPathEntry("File1", QString());
584     openFile(KUrl(Lastproject));
585 }
586
587 void MainWindow::slotReloadEffects()
588 {
589     m_customEffectsMenu->clear();
590     initEffects::parseCustomEffectsFile();
591     QAction *action;
592     QStringList effectInfo;
593     QMap<QString, QStringList> effectsList;
594     for (int ix = 0; ix < customEffects.count(); ix++) {
595         effectInfo = customEffects.effectIdInfo(ix);
596         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
597     }
598     if (effectsList.isEmpty())
599         m_customEffectsMenu->setEnabled(false);
600     else
601         m_customEffectsMenu->setEnabled(true);
602
603     foreach(const QStringList &value, effectsList) {
604         action = new QAction(value.at(0), this);
605         action->setData(value);
606         m_customEffectsMenu->addAction(action);
607     }
608     m_effectList->reloadEffectList();
609 }
610
611 #ifndef NO_JOGSHUTTLE
612 void MainWindow::activateShuttleDevice()
613 {
614     delete m_jogProcess;
615     m_jogProcess = NULL;
616     if (KdenliveSettings::enableshuttle() == false) return;
617     m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
618     connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
619     connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
620     connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
621     connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
622     connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
623     connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
624 }
625
626 void MainWindow::slotShuttleButton(int code)
627 {
628     switch (code) {
629     case 5:
630         slotShuttleAction(KdenliveSettings::shuttle1());
631         break;
632     case 6:
633         slotShuttleAction(KdenliveSettings::shuttle2());
634         break;
635     case 7:
636         slotShuttleAction(KdenliveSettings::shuttle3());
637         break;
638     case 8:
639         slotShuttleAction(KdenliveSettings::shuttle4());
640         break;
641     case 9:
642         slotShuttleAction(KdenliveSettings::shuttle5());
643         break;
644     }
645 }
646
647 void MainWindow::slotShuttleAction(int code)
648 {
649     switch (code) {
650     case 0:
651         return;
652     case 1:
653         m_monitorManager->slotPlay();
654         break;
655     default:
656         m_monitorManager->slotPlay();
657         break;
658     }
659 }
660 #endif /* NO_JOGSHUTTLE */
661
662 void MainWindow::configureNotifications()
663 {
664     KNotifyConfigWidget::configure(this);
665 }
666
667 void MainWindow::slotFullScreen()
668 {
669     KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
670 }
671
672 void MainWindow::slotAddEffect(const QDomElement effect, GenTime pos, int track)
673 {
674     if (!m_activeDocument) return;
675     if (effect.isNull()) {
676         kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
677         return;
678     }
679     QDomElement effectToAdd = effect.cloneNode().toElement();
680     m_activeTimeline->projectView()->slotAddEffect(effectToAdd, pos, track);
681 }
682
683 void MainWindow::slotRaiseMonitor(bool clipMonitor)
684 {
685     if (clipMonitor) m_clipMonitorDock->raise();
686     else m_projectMonitorDock->raise();
687 }
688
689 void MainWindow::slotUpdateClip(const QString &id)
690 {
691     if (!m_activeDocument) return;
692     m_activeTimeline->projectView()->slotUpdateClip(id);
693 }
694
695 void MainWindow::slotConnectMonitors()
696 {
697     m_projectList->setRenderer(m_projectMonitor->render);
698     //connect(m_projectList, SIGNAL(receivedClipDuration(const QString &)), this, SLOT(slotUpdateClip(const QString &)));
699     connect(m_projectList, SIGNAL(deleteProjectClips(QStringList, QMap<QString, QString>)), this, SLOT(slotDeleteProjectClips(QStringList, QMap<QString, QString>)));
700     connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
701     connect(m_projectList, SIGNAL(showClipProperties(QList <DocClipBase *>, QMap<QString, QString>)), this, SLOT(slotShowClipProperties(QList <DocClipBase *>, QMap<QString, QString>)));
702     connect(m_projectList, SIGNAL(getFileProperties(const QDomElement, const QString &, int, bool)), m_projectMonitor->render, SLOT(getFileProperties(const QDomElement, const QString &, int, bool)));
703     connect(m_projectMonitor->render, SIGNAL(replyGetImage(const QString &, const QPixmap &)), m_projectList, SLOT(slotReplyGetImage(const QString &, const QPixmap &)));
704     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)));
705
706     connect(m_projectMonitor->render, SIGNAL(removeInvalidClip(const QString &, bool)), m_projectList, SLOT(slotRemoveInvalidClip(const QString &, bool)));
707
708     connect(m_clipMonitor, SIGNAL(refreshClipThumbnail(const QString &)), m_projectList, SLOT(slotRefreshClipThumbnail(const QString &)));
709
710     connect(m_clipMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustClipMonitor()));
711     connect(m_projectMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustProjectMonitor()));
712
713     connect(m_clipMonitor, SIGNAL(saveZone(Render *, QPoint)), this, SLOT(slotSaveZone(Render *, QPoint)));
714     connect(m_projectMonitor, SIGNAL(saveZone(Render *, QPoint)), this, SLOT(slotSaveZone(Render *, QPoint)));
715 }
716
717 void MainWindow::slotAdjustClipMonitor()
718 {
719     m_clipMonitorDock->updateGeometry();
720     m_clipMonitorDock->adjustSize();
721     m_clipMonitor->resetSize();
722 }
723
724 void MainWindow::slotAdjustProjectMonitor()
725 {
726     m_projectMonitorDock->updateGeometry();
727     m_projectMonitorDock->adjustSize();
728     m_projectMonitor->resetSize();
729 }
730
731 void MainWindow::setupActions()
732 {
733
734     KActionCollection* collection = actionCollection();
735     m_timecodeFormat = new KComboBox(this);
736     m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
737     m_timecodeFormat->addItem(i18n("Frames"));
738     if (KdenliveSettings::frametimecode()) m_timecodeFormat->setCurrentIndex(1);
739     connect(m_timecodeFormat, SIGNAL(activated(int)), this, SLOT(slotUpdateTimecodeFormat(int)));
740
741     m_statusProgressBar = new QProgressBar(this);
742     m_statusProgressBar->setMinimum(0);
743     m_statusProgressBar->setMaximum(100);
744     m_statusProgressBar->setMaximumWidth(150);
745     m_statusProgressBar->setVisible(false);
746
747     KToolBar *toolbar = new KToolBar("statusToolBar", this, Qt::BottomToolBarArea);
748     toolbar->setMovable(false);
749     statusBar()->setStyleSheet(QString("QStatusBar QLabel {font-size:%1pt;} QStatusBar::item { border: 0px; font-size:%1pt;padding:0px; }").arg(statusBar()->font().pointSize()));
750     QString style1 = "QToolBar { border: 0px } QToolButton { 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;}";
751     QString styleBorderless = "QToolButton { border-width: 0px;margin: 1px 3px 0px;padding: 0px;}";
752
753     //create edit mode buttons
754     m_normalEditTool = new KAction(KIcon("kdenlive-normal-edit"), i18n("Normal mode"), this);
755     m_normalEditTool->setShortcut(i18nc("Normal editing", "n"));
756     toolbar->addAction(m_normalEditTool);
757     m_normalEditTool->setCheckable(true);
758     m_normalEditTool->setChecked(true);
759
760     m_overwriteEditTool = new KAction(KIcon("kdenlive-overwrite-edit"), i18n("Overwrite mode"), this);
761     //m_overwriteEditTool->setShortcut(i18nc("Overwrite mode shortcut", "o"));
762     toolbar->addAction(m_overwriteEditTool);
763     m_overwriteEditTool->setCheckable(true);
764     m_overwriteEditTool->setChecked(false);
765
766     m_insertEditTool = new KAction(KIcon("kdenlive-insert-edit"), i18n("Insert mode"), this);
767     //m_insertEditTool->setShortcut(i18nc("Insert mode shortcut", "i"));
768     toolbar->addAction(m_insertEditTool);
769     m_insertEditTool->setCheckable(true);
770     m_insertEditTool->setChecked(false);
771     // not implemented yet
772     m_insertEditTool->setEnabled(false);
773
774     QActionGroup *editGroup = new QActionGroup(this);
775     editGroup->addAction(m_normalEditTool);
776     editGroup->addAction(m_overwriteEditTool);
777     editGroup->addAction(m_insertEditTool);
778     editGroup->setExclusive(true);
779     connect(editGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeEdit(QAction *)));
780     //connect(m_overwriteEditTool, SIGNAL(toggled(bool)), this, SLOT(slotSetOverwriteMode(bool)));
781
782     toolbar->addSeparator();
783
784     // create tools buttons
785     m_buttonSelectTool = new KAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"), this);
786     m_buttonSelectTool->setShortcut(i18nc("Selection tool shortcut", "s"));
787     toolbar->addAction(m_buttonSelectTool);
788     m_buttonSelectTool->setCheckable(true);
789     m_buttonSelectTool->setChecked(true);
790
791     m_buttonRazorTool = new KAction(KIcon("edit-cut"), i18n("Razor tool"), this);
792     m_buttonRazorTool->setShortcut(i18nc("Razor tool shortcut", "x"));
793     toolbar->addAction(m_buttonRazorTool);
794     m_buttonRazorTool->setCheckable(true);
795     m_buttonRazorTool->setChecked(false);
796
797     m_buttonSpacerTool = new KAction(KIcon("kdenlive-spacer-tool"), i18n("Spacer tool"), this);
798     m_buttonSpacerTool->setShortcut(i18nc("Spacer tool shortcut", "m"));
799     toolbar->addAction(m_buttonSpacerTool);
800     m_buttonSpacerTool->setCheckable(true);
801     m_buttonSpacerTool->setChecked(false);
802
803     QActionGroup *toolGroup = new QActionGroup(this);
804     toolGroup->addAction(m_buttonSelectTool);
805     toolGroup->addAction(m_buttonRazorTool);
806     toolGroup->addAction(m_buttonSpacerTool);
807     toolGroup->setExclusive(true);
808     toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
809
810     QWidget * actionWidget;
811     int max = toolbar->iconSizeDefault() + 2;
812     actionWidget = toolbar->widgetForAction(m_normalEditTool);
813     actionWidget->setMaximumWidth(max);
814     actionWidget->setMaximumHeight(max - 4);
815
816     actionWidget = toolbar->widgetForAction(m_insertEditTool);
817     actionWidget->setMaximumWidth(max);
818     actionWidget->setMaximumHeight(max - 4);
819
820     actionWidget = toolbar->widgetForAction(m_overwriteEditTool);
821     actionWidget->setMaximumWidth(max);
822     actionWidget->setMaximumHeight(max - 4);
823
824     actionWidget = toolbar->widgetForAction(m_buttonSelectTool);
825     actionWidget->setMaximumWidth(max);
826     actionWidget->setMaximumHeight(max - 4);
827
828     actionWidget = toolbar->widgetForAction(m_buttonRazorTool);
829     actionWidget->setMaximumWidth(max);
830     actionWidget->setMaximumHeight(max - 4);
831
832     actionWidget = toolbar->widgetForAction(m_buttonSpacerTool);
833     actionWidget->setMaximumWidth(max);
834     actionWidget->setMaximumHeight(max - 4);
835
836     toolbar->setStyleSheet(style1);
837     connect(toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
838
839     toolbar->addSeparator();
840     m_buttonFitZoom = new KAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"), this);
841     toolbar->addAction(m_buttonFitZoom);
842     m_buttonFitZoom->setCheckable(false);
843
844     m_zoomOut = new KAction(KIcon("zoom-out"), i18n("Zoom Out"), this);
845     toolbar->addAction(m_zoomOut);
846     m_zoomOut->setShortcut(Qt::CTRL + Qt::Key_Minus);
847
848     m_zoomSlider = new QSlider(Qt::Horizontal, this);
849     m_zoomSlider->setMaximum(13);
850     m_zoomSlider->setPageStep(1);
851     m_zoomSlider->setInvertedAppearance(true);
852
853     m_zoomSlider->setMaximumWidth(150);
854     m_zoomSlider->setMinimumWidth(100);
855     toolbar->addWidget(m_zoomSlider);
856
857     m_zoomIn = new KAction(KIcon("zoom-in"), i18n("Zoom In"), this);
858     toolbar->addAction(m_zoomIn);
859     m_zoomIn->setShortcut(Qt::CTRL + Qt::Key_Plus);
860
861     actionWidget = toolbar->widgetForAction(m_buttonFitZoom);
862     actionWidget->setMaximumWidth(max);
863     actionWidget->setMaximumHeight(max - 4);
864     actionWidget->setStyleSheet(styleBorderless);
865
866     actionWidget = toolbar->widgetForAction(m_zoomIn);
867     actionWidget->setMaximumWidth(max);
868     actionWidget->setMaximumHeight(max - 4);
869     actionWidget->setStyleSheet(styleBorderless);
870
871     actionWidget = toolbar->widgetForAction(m_zoomOut);
872     actionWidget->setMaximumWidth(max);
873     actionWidget->setMaximumHeight(max - 4);
874     actionWidget->setStyleSheet(styleBorderless);
875
876     connect(m_zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(slotSetZoom(int)));
877     connect(m_zoomSlider, SIGNAL(sliderMoved(int)), this, SLOT(slotShowZoomSliderToolTip(int)));
878     connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
879     connect(m_zoomIn, SIGNAL(triggered(bool)), this, SLOT(slotZoomIn()));
880     connect(m_zoomOut, SIGNAL(triggered(bool)), this, SLOT(slotZoomOut()));
881
882     toolbar->addSeparator();
883
884     //create automatic audio split button
885     m_buttonAutomaticSplitAudio = new KAction(KIcon("kdenlive-split-audio"), i18n("Split audio and video automatically"), this);
886     toolbar->addAction(m_buttonAutomaticSplitAudio);
887     m_buttonAutomaticSplitAudio->setCheckable(true);
888     m_buttonAutomaticSplitAudio->setChecked(KdenliveSettings::splitaudio());
889     connect(m_buttonAutomaticSplitAudio, SIGNAL(triggered()), this, SLOT(slotSwitchSplitAudio()));
890
891     m_buttonVideoThumbs = new KAction(KIcon("kdenlive-show-videothumb"), i18n("Show video thumbnails"), this);
892     toolbar->addAction(m_buttonVideoThumbs);
893     m_buttonVideoThumbs->setCheckable(true);
894     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
895     connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
896
897     m_buttonAudioThumbs = new KAction(KIcon("kdenlive-show-audiothumb"), i18n("Show audio thumbnails"), this);
898     toolbar->addAction(m_buttonAudioThumbs);
899     m_buttonAudioThumbs->setCheckable(true);
900     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
901     connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
902
903     m_buttonShowMarkers = new KAction(KIcon("kdenlive-show-markers"), i18n("Show markers comments"), this);
904     toolbar->addAction(m_buttonShowMarkers);
905     m_buttonShowMarkers->setCheckable(true);
906     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
907     connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
908
909     m_buttonSnap = new KAction(KIcon("kdenlive-snap"), i18n("Snap"), this);
910     toolbar->addAction(m_buttonSnap);
911     m_buttonSnap->setCheckable(true);
912     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
913     connect(m_buttonSnap, SIGNAL(triggered()), this, SLOT(slotSwitchSnap()));
914
915     actionWidget = toolbar->widgetForAction(m_buttonAutomaticSplitAudio);
916     actionWidget->setMaximumWidth(max);
917     actionWidget->setMaximumHeight(max - 4);
918
919     actionWidget = toolbar->widgetForAction(m_buttonVideoThumbs);
920     actionWidget->setMaximumWidth(max);
921     actionWidget->setMaximumHeight(max - 4);
922
923     actionWidget = toolbar->widgetForAction(m_buttonAudioThumbs);
924     actionWidget->setMaximumWidth(max);
925     actionWidget->setMaximumHeight(max - 4);
926
927     actionWidget = toolbar->widgetForAction(m_buttonShowMarkers);
928     actionWidget->setMaximumWidth(max);
929     actionWidget->setMaximumHeight(max - 4);
930
931     actionWidget = toolbar->widgetForAction(m_buttonSnap);
932     actionWidget->setMaximumWidth(max);
933     actionWidget->setMaximumHeight(max - 4);
934
935     m_messageLabel = new StatusBarMessageLabel(this);
936     m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
937
938     statusBar()->addWidget(m_messageLabel, 10);
939     statusBar()->addWidget(m_statusProgressBar, 0);
940     statusBar()->addPermanentWidget(toolbar);
941     statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
942     statusBar()->addPermanentWidget(m_timecodeFormat);
943     //statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 3);
944
945     collection->addAction("normal_mode", m_normalEditTool);
946     collection->addAction("overwrite_mode", m_overwriteEditTool);
947     collection->addAction("insert_mode", m_insertEditTool);
948     collection->addAction("select_tool", m_buttonSelectTool);
949     collection->addAction("razor_tool", m_buttonRazorTool);
950     collection->addAction("spacer_tool", m_buttonSpacerTool);
951
952     collection->addAction("automatic_split_audio", m_buttonAutomaticSplitAudio);
953     collection->addAction("show_video_thumbs", m_buttonVideoThumbs);
954     collection->addAction("show_audio_thumbs", m_buttonAudioThumbs);
955     collection->addAction("show_markers", m_buttonShowMarkers);
956     collection->addAction("snap", m_buttonSnap);
957     collection->addAction("zoom_fit", m_buttonFitZoom);
958     collection->addAction("zoom_in", m_zoomIn);
959     collection->addAction("zoom_out", m_zoomOut);
960
961     m_projectSearch = new KAction(KIcon("edit-find"), i18n("Find"), this);
962     collection->addAction("project_find", m_projectSearch);
963     connect(m_projectSearch, SIGNAL(triggered(bool)), this, SLOT(slotFind()));
964     m_projectSearch->setShortcut(Qt::Key_Slash);
965
966     m_projectSearchNext = new KAction(KIcon("go-down-search"), i18n("Find Next"), this);
967     collection->addAction("project_find_next", m_projectSearchNext);
968     connect(m_projectSearchNext, SIGNAL(triggered(bool)), this, SLOT(slotFindNext()));
969     m_projectSearchNext->setShortcut(Qt::Key_F3);
970     m_projectSearchNext->setEnabled(false);
971
972     KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Project Profiles"), this);
973     collection->addAction("manage_profiles", profilesAction);
974     connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
975
976     KNS3::standardAction(i18n("Download New Wipes..."),            this, SLOT(slotGetNewLumaStuff()),       actionCollection(), "get_new_lumas");
977     KNS3::standardAction(i18n("Download New Render Profiles..."),  this, SLOT(slotGetNewRenderStuff()),     actionCollection(), "get_new_profiles");
978     KNS3::standardAction(i18n("Download New Project Profiles..."), this, SLOT(slotGetNewMltProfileStuff()), actionCollection(), "get_new_mlt_profiles");
979     KNS3::standardAction(i18n("Download New Title Templates..."),  this, SLOT(slotGetNewTitleStuff()),      actionCollection(), "get_new_titles");
980
981     KAction* wizAction = new KAction(KIcon("configure"), i18n("Run Config Wizard"), this);
982     collection->addAction("run_wizard", wizAction);
983     connect(wizAction, SIGNAL(triggered(bool)), this, SLOT(slotRunWizard()));
984
985     KAction* projectAction = new KAction(KIcon("configure"), i18n("Project Settings"), this);
986     collection->addAction("project_settings", projectAction);
987     connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
988
989     KAction* projectRender = new KAction(KIcon("media-record"), i18n("Render"), this);
990     collection->addAction("project_render", projectRender);
991     projectRender->setShortcut(Qt::CTRL + Qt::Key_Return);
992     connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
993
994     KAction* projectClean = new KAction(KIcon("edit-clear"), i18n("Clean Project"), this);
995     collection->addAction("project_clean", projectClean);
996     connect(projectClean, SIGNAL(triggered(bool)), this, SLOT(slotCleanProject()));
997
998     KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
999     KShortcut playShortcut;
1000     playShortcut.setPrimary(Qt::Key_Space);
1001     playShortcut.setAlternate(Qt::Key_K);
1002     monitorPlay->setShortcut(playShortcut);
1003     collection->addAction("monitor_play", monitorPlay);
1004     connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
1005
1006     m_playZone = new KAction(KIcon("media-playback-start"), i18n("Play Zone"), this);
1007     m_playZone->setShortcut(Qt::CTRL + Qt::Key_Space);
1008     collection->addAction("monitor_play_zone", m_playZone);
1009     connect(m_playZone, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlayZone()));
1010
1011     m_loopZone = new KAction(KIcon("media-playback-start"), i18n("Loop Zone"), this);
1012     m_loopZone->setShortcut(Qt::ALT + Qt::Key_Space);
1013     collection->addAction("monitor_loop_zone", m_loopZone);
1014     connect(m_loopZone, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotLoopZone()));
1015
1016     KAction *dvdWizard =  new KAction(KIcon("media-optical"), i18n("DVD Wizard"), this);
1017     collection->addAction("dvd_wizard", dvdWizard);
1018     connect(dvdWizard, SIGNAL(triggered(bool)), this, SLOT(slotDvdWizard()));
1019
1020     KAction *transcodeClip =  new KAction(KIcon("edit-copy"), i18n("Transcode Clips"), this);
1021     collection->addAction("transcode_clip", transcodeClip);
1022     connect(transcodeClip, SIGNAL(triggered(bool)), this, SLOT(slotTranscodeClip()));
1023
1024     KAction *markIn = collection->addAction("mark_in");
1025     markIn->setText(i18n("Set Zone In"));
1026     markIn->setShortcut(Qt::Key_I);
1027     connect(markIn, SIGNAL(triggered(bool)), this, SLOT(slotSetInPoint()));
1028
1029     KAction *markOut = collection->addAction("mark_out");
1030     markOut->setText(i18n("Set Zone Out"));
1031     markOut->setShortcut(Qt::Key_O);
1032     connect(markOut, SIGNAL(triggered(bool)), this, SLOT(slotSetOutPoint()));
1033
1034     KAction *switchMon = collection->addAction("switch_monitor");
1035     switchMon->setText(i18n("Switch monitor"));
1036     switchMon->setShortcut(Qt::Key_T);
1037     connect(switchMon, SIGNAL(triggered(bool)), this, SLOT(slotSwitchMonitors()));
1038
1039     KAction *insertTree = collection->addAction("insert_project_tree");
1040     insertTree->setText(i18n("Insert zone in project tree"));
1041     insertTree->setShortcut(Qt::CTRL + Qt::Key_I);
1042     connect(insertTree, SIGNAL(triggered(bool)), this, SLOT(slotInsertZoneToTree()));
1043
1044     KAction *insertTimeline = collection->addAction("insert_timeline");
1045     insertTimeline->setText(i18n("Insert zone in timeline"));
1046     insertTimeline->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_I);
1047     connect(insertTimeline, SIGNAL(triggered(bool)), this, SLOT(slotInsertZoneToTimeline()));
1048
1049     KAction *resizeStart =  new KAction(KIcon(), i18n("Resize Item Start"), this);
1050     collection->addAction("resize_timeline_clip_start", resizeStart);
1051     resizeStart->setShortcut(Qt::Key_1);
1052     connect(resizeStart, SIGNAL(triggered(bool)), this, SLOT(slotResizeItemStart()));
1053
1054     KAction *resizeEnd =  new KAction(KIcon(), i18n("Resize Item End"), this);
1055     collection->addAction("resize_timeline_clip_end", resizeEnd);
1056     resizeEnd->setShortcut(Qt::Key_2);
1057     connect(resizeEnd, SIGNAL(triggered(bool)), this, SLOT(slotResizeItemEnd()));
1058
1059     KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
1060     monitorSeekBackward->setShortcut(Qt::Key_J);
1061     collection->addAction("monitor_seek_backward", monitorSeekBackward);
1062     connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
1063
1064     KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
1065     monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
1066     collection->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
1067     connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
1068
1069     KAction* monitorSeekBackwardOneSecond = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Second"), this);
1070     monitorSeekBackwardOneSecond->setShortcut(Qt::SHIFT + Qt::Key_Left);
1071     collection->addAction("monitor_seek_backward-one-second", monitorSeekBackwardOneSecond);
1072     connect(monitorSeekBackwardOneSecond, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneSecond()));
1073
1074     KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
1075     monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
1076     collection->addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
1077     connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
1078
1079     KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
1080     monitorSeekForward->setShortcut(Qt::Key_L);
1081     collection->addAction("monitor_seek_forward", monitorSeekForward);
1082     connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
1083
1084     KAction* clipStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Clip Start"), this);
1085     clipStart->setShortcut(Qt::Key_Home);
1086     collection->addAction("seek_clip_start", clipStart);
1087     connect(clipStart, SIGNAL(triggered(bool)), this, SLOT(slotClipStart()));
1088
1089     KAction* clipEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Clip End"), this);
1090     clipEnd->setShortcut(Qt::Key_End);
1091     collection->addAction("seek_clip_end", clipEnd);
1092     connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
1093
1094     KAction* zoneStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Zone Start"), this);
1095     zoneStart->setShortcut(Qt::SHIFT + Qt::Key_I);
1096     collection->addAction("seek_zone_start", zoneStart);
1097     connect(zoneStart, SIGNAL(triggered(bool)), this, SLOT(slotZoneStart()));
1098
1099     KAction* zoneEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Zone End"), this);
1100     zoneEnd->setShortcut(Qt::SHIFT + Qt::Key_O);
1101     collection->addAction("seek_zone_end", zoneEnd);
1102     connect(zoneEnd, SIGNAL(triggered(bool)), this, SLOT(slotZoneEnd()));
1103
1104     KAction* projectStart = new KAction(KIcon("go-first"), i18n("Go to Project Start"), this);
1105     projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
1106     collection->addAction("seek_start", projectStart);
1107     connect(projectStart, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotStart()));
1108
1109     KAction* projectEnd = new KAction(KIcon("go-last"), i18n("Go to Project End"), this);
1110     projectEnd->setShortcut(Qt::CTRL + Qt::Key_End);
1111     collection->addAction("seek_end", projectEnd);
1112     connect(projectEnd, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotEnd()));
1113
1114     KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
1115     monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
1116     collection->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
1117     connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
1118
1119     KAction* monitorSeekForwardOneSecond = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Second"), this);
1120     monitorSeekForwardOneSecond->setShortcut(Qt::SHIFT + Qt::Key_Right);
1121     collection->addAction("monitor_seek_forward-one-second", monitorSeekForwardOneSecond);
1122     connect(monitorSeekForwardOneSecond, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneSecond()));
1123
1124     KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
1125     monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
1126     collection->addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
1127     connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
1128
1129     KAction* deleteItem = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
1130     deleteItem->setShortcut(Qt::Key_Delete);
1131     collection->addAction("delete_timeline_clip", deleteItem);
1132     connect(deleteItem, SIGNAL(triggered(bool)), this, SLOT(slotDeleteItem()));
1133
1134     /*KAction* editTimelineClipSpeed = new KAction(i18n("Change Clip Speed"), this);
1135     collection->addAction("change_clip_speed", editTimelineClipSpeed);
1136     editTimelineClipSpeed->setData("change_speed");
1137     connect(editTimelineClipSpeed, SIGNAL(triggered(bool)), this, SLOT(slotChangeClipSpeed()));*/
1138
1139     KAction *stickTransition = collection->addAction("auto_transition");
1140     stickTransition->setData(QString("auto"));
1141     stickTransition->setCheckable(true);
1142     stickTransition->setEnabled(false);
1143     stickTransition->setText(i18n("Automatic Transition"));
1144     connect(stickTransition, SIGNAL(triggered(bool)), this, SLOT(slotAutoTransition()));
1145
1146     KAction* groupClip = new KAction(KIcon("object-group"), i18n("Group Clips"), this);
1147     groupClip->setShortcut(Qt::CTRL + Qt::Key_G);
1148     collection->addAction("group_clip", groupClip);
1149     connect(groupClip, SIGNAL(triggered(bool)), this, SLOT(slotGroupClips()));
1150
1151     KAction* ungroupClip = new KAction(KIcon("object-ungroup"), i18n("Ungroup Clips"), this);
1152     collection->addAction("ungroup_clip", ungroupClip);
1153     ungroupClip->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_G);
1154     ungroupClip->setData("ungroup_clip");
1155     connect(ungroupClip, SIGNAL(triggered(bool)), this, SLOT(slotUnGroupClips()));
1156
1157     KAction* editItemDuration = new KAction(KIcon("measure"), i18n("Edit Duration"), this);
1158     collection->addAction("edit_item_duration", editItemDuration);
1159     connect(editItemDuration, SIGNAL(triggered(bool)), this, SLOT(slotEditItemDuration()));
1160
1161     KAction* clipInProjectTree = new KAction(KIcon("go-jump-definition"), i18n("Clip in Project Tree"), this);
1162     collection->addAction("clip_in_project_tree", clipInProjectTree);
1163     connect(clipInProjectTree, SIGNAL(triggered(bool)), this, SLOT(slotClipInProjectTree()));
1164
1165     /*KAction* clipToProjectTree = new KAction(KIcon("go-jump-definition"), i18n("Add Clip to Project Tree"), this);
1166     collection->addAction("clip_to_project_tree", clipToProjectTree);
1167     connect(clipToProjectTree, SIGNAL(triggered(bool)), this, SLOT(slotClipToProjectTree()));*/
1168
1169     KAction* insertOvertwrite = new KAction(KIcon(), i18n("Insert Clip Zone in Timeline (Overwrite)"), this);
1170     insertOvertwrite->setShortcut(Qt::Key_V);
1171     collection->addAction("overwrite_to_in_point", insertOvertwrite);
1172     connect(insertOvertwrite, SIGNAL(triggered(bool)), this, SLOT(slotInsertClipOverwrite()));
1173
1174     KAction* selectTimelineClip = new KAction(KIcon("edit-select"), i18n("Select Clip"), this);
1175     selectTimelineClip->setShortcut(Qt::Key_Plus);
1176     collection->addAction("select_timeline_clip", selectTimelineClip);
1177     connect(selectTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotSelectTimelineClip()));
1178
1179     KAction* deselectTimelineClip = new KAction(KIcon("edit-select"), i18n("Deselect Clip"), this);
1180     deselectTimelineClip->setShortcut(Qt::Key_Minus);
1181     collection->addAction("deselect_timeline_clip", deselectTimelineClip);
1182     connect(deselectTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeselectTimelineClip()));
1183
1184     KAction* selectAddTimelineClip = new KAction(KIcon("edit-select"), i18n("Add Clip To Selection"), this);
1185     selectAddTimelineClip->setShortcut(Qt::ALT + Qt::Key_Plus);
1186     collection->addAction("select_add_timeline_clip", selectAddTimelineClip);
1187     connect(selectAddTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotSelectAddTimelineClip()));
1188
1189     KAction* selectTimelineTransition = new KAction(KIcon("edit-select"), i18n("Select Transition"), this);
1190     selectTimelineTransition->setShortcut(Qt::SHIFT + Qt::Key_Plus);
1191     collection->addAction("select_timeline_transition", selectTimelineTransition);
1192     connect(selectTimelineTransition, SIGNAL(triggered(bool)), this, SLOT(slotSelectTimelineTransition()));
1193
1194     KAction* deselectTimelineTransition = new KAction(KIcon("edit-select"), i18n("Deselect Transition"), this);
1195     deselectTimelineTransition->setShortcut(Qt::SHIFT + Qt::Key_Minus);
1196     collection->addAction("deselect_timeline_transition", deselectTimelineTransition);
1197     connect(deselectTimelineTransition, SIGNAL(triggered(bool)), this, SLOT(slotDeselectTimelineTransition()));
1198
1199     KAction* selectAddTimelineTransition = new KAction(KIcon("edit-select"), i18n("Add Transition To Selection"), this);
1200     selectAddTimelineTransition->setShortcut(Qt::ALT + Qt::SHIFT + Qt::Key_Plus);
1201     collection->addAction("select_add_timeline_transition", selectAddTimelineTransition);
1202     connect(selectAddTimelineTransition, SIGNAL(triggered(bool)), this, SLOT(slotSelectAddTimelineTransition()));
1203
1204     KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
1205     cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
1206     collection->addAction("cut_timeline_clip", cutTimelineClip);
1207     connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
1208
1209     KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker"), this);
1210     collection->addAction("add_clip_marker", addClipMarker);
1211     connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
1212
1213     KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker"), this);
1214     collection->addAction("delete_clip_marker", deleteClipMarker);
1215     connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
1216
1217     KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers"), this);
1218     collection->addAction("delete_all_clip_markers", deleteAllClipMarkers);
1219     connect(deleteAllClipMarkers, SIGNAL(triggered(bool)), this, SLOT(slotDeleteAllClipMarkers()));
1220
1221     KAction* editClipMarker = new KAction(KIcon("document-properties"), i18n("Edit Marker"), this);
1222     collection->addAction("edit_clip_marker", editClipMarker);
1223     connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker()));
1224
1225     KAction* splitAudio = new KAction(KIcon("document-new"), i18n("Split Audio"), this);
1226     collection->addAction("split_audio", splitAudio);
1227     connect(splitAudio, SIGNAL(triggered(bool)), this, SLOT(slotSplitAudio()));
1228
1229     KAction* audioOnly = new KAction(KIcon("document-new"), i18n("Audio Only"), this);
1230     collection->addAction("clip_audio_only", audioOnly);
1231     audioOnly->setData("clip_audio_only");
1232     audioOnly->setCheckable(true);
1233
1234     KAction* videoOnly = new KAction(KIcon("document-new"), i18n("Video Only"), this);
1235     collection->addAction("clip_video_only", videoOnly);
1236     videoOnly->setData("clip_video_only");
1237     videoOnly->setCheckable(true);
1238
1239     KAction* audioAndVideo = new KAction(KIcon("document-new"), i18n("Audio and Video"), this);
1240     collection->addAction("clip_audio_and_video", audioAndVideo);
1241     audioAndVideo->setData("clip_audio_and_video");
1242     audioAndVideo->setCheckable(true);
1243
1244     m_clipTypeGroup = new QActionGroup(this);
1245     m_clipTypeGroup->addAction(audioOnly);
1246     m_clipTypeGroup->addAction(videoOnly);
1247     m_clipTypeGroup->addAction(audioAndVideo);
1248     connect(m_clipTypeGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotUpdateClipType(QAction *)));
1249     m_clipTypeGroup->setEnabled(false);
1250
1251     KAction *insertSpace = new KAction(KIcon(), i18n("Insert Space"), this);
1252     collection->addAction("insert_space", insertSpace);
1253     connect(insertSpace, SIGNAL(triggered()), this, SLOT(slotInsertSpace()));
1254
1255     KAction *removeSpace = new KAction(KIcon(), i18n("Remove Space"), this);
1256     collection->addAction("delete_space", removeSpace);
1257     connect(removeSpace, SIGNAL(triggered()), this, SLOT(slotRemoveSpace()));
1258
1259     KAction *insertTrack = new KAction(KIcon(), i18n("Insert Track"), this);
1260     collection->addAction("insert_track", insertTrack);
1261     connect(insertTrack, SIGNAL(triggered()), this, SLOT(slotInsertTrack()));
1262
1263     KAction *deleteTrack = new KAction(KIcon(), i18n("Delete Track"), this);
1264     collection->addAction("delete_track", deleteTrack);
1265     connect(deleteTrack, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
1266
1267     KAction *configTracks = new KAction(KIcon("configure"), i18n("Configure Tracks"), this);
1268     collection->addAction("config_tracks", configTracks);
1269     connect(configTracks, SIGNAL(triggered()), this, SLOT(slotConfigTrack()));
1270
1271     KAction *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
1272     collection->addAction("add_guide", addGuide);
1273     connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
1274
1275     QAction *delGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
1276     collection->addAction("delete_guide", delGuide);
1277     connect(delGuide, SIGNAL(triggered()), this, SLOT(slotDeleteGuide()));
1278
1279     QAction *editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
1280     collection->addAction("edit_guide", editGuide);
1281     connect(editGuide, SIGNAL(triggered()), this, SLOT(slotEditGuide()));
1282
1283     QAction *delAllGuides = new KAction(KIcon("edit-delete"), i18n("Delete All Guides"), this);
1284     collection->addAction("delete_all_guides", delAllGuides);
1285     connect(delAllGuides, SIGNAL(triggered()), this, SLOT(slotDeleteAllGuides()));
1286
1287     QAction *pasteEffects = new KAction(KIcon("edit-paste"), i18n("Paste Effects"), this);
1288     collection->addAction("paste_effects", pasteEffects);
1289     pasteEffects->setData("paste_effects");
1290     connect(pasteEffects , SIGNAL(triggered()), this, SLOT(slotPasteEffects()));
1291
1292     QAction *showTimeline = new KAction(i18n("Show Timeline"), this);
1293     collection->addAction("show_timeline", showTimeline);
1294     showTimeline->setCheckable(true);
1295     showTimeline->setChecked(true);
1296     connect(showTimeline, SIGNAL(triggered(bool)), this, SLOT(slotShowTimeline(bool)));
1297
1298     QAction *showTitleBar = new KAction(i18n("Show Title Bars"), this);
1299     collection->addAction("show_titlebars", showTitleBar);
1300     showTitleBar->setCheckable(true);
1301     connect(showTitleBar, SIGNAL(triggered(bool)), this, SLOT(slotShowTitleBars(bool)));
1302     showTitleBar->setChecked(KdenliveSettings::showtitlebars());
1303     slotShowTitleBars(KdenliveSettings::showtitlebars());
1304
1305     /*QAction *maxCurrent = new KAction(i18n("Maximize Current Widget"), this);
1306     collection->addAction("maximize_current", maxCurrent);
1307     maxCurrent->setCheckable(true);
1308     maxCurrent->setChecked(false);
1309     connect(maxCurrent, SIGNAL(triggered(bool)), this, SLOT(slotMaximizeCurrent(bool)));*/
1310
1311     m_closeAction = KStandardAction::close(this,  SLOT(closeCurrentDocument()),   collection);
1312     KStandardAction::quit(this,                   SLOT(queryQuit()),              collection);
1313     KStandardAction::open(this,                   SLOT(openFile()),               collection);
1314     m_saveAction = KStandardAction::save(this,    SLOT(saveFile()),               collection);
1315     KStandardAction::saveAs(this,                 SLOT(saveFileAs()),             collection);
1316     KStandardAction::openNew(this,                SLOT(newFile()),                collection);
1317     // TODO: make the following connection to slotEditKeys work
1318     KStandardAction::keyBindings(this,            SLOT(slotEditKeys()),           collection);
1319     KStandardAction::preferences(this,            SLOT(slotPreferences()),        collection);
1320     KStandardAction::configureNotifications(this, SLOT(configureNotifications()), collection);
1321     KStandardAction::copy(this,                   SLOT(slotCopy()),               collection);
1322     KStandardAction::paste(this,                  SLOT(slotPaste()),              collection);
1323     KStandardAction::fullScreen(this,             SLOT(slotFullScreen()), this,   collection);
1324
1325     KAction *undo = KStandardAction::undo(m_commandStack, SLOT(undo()), collection);
1326     undo->setEnabled(false);
1327     connect(m_commandStack, SIGNAL(canUndoChanged(bool)), undo, SLOT(setEnabled(bool)));
1328
1329     KAction *redo = KStandardAction::redo(m_commandStack, SLOT(redo()), collection);
1330     redo->setEnabled(false);
1331     connect(m_commandStack, SIGNAL(canRedoChanged(bool)), redo, SLOT(setEnabled(bool)));
1332
1333     /*
1334     //TODO: Add status tooltip to actions ?
1335     connect(collection, SIGNAL(actionHovered(QAction*)),
1336             this, SLOT(slotDisplayActionMessage(QAction*)));*/
1337
1338
1339     QAction *addClip = new KAction(KIcon("kdenlive-add-clip"), i18n("Add Clip"), this);
1340     collection->addAction("add_clip", addClip);
1341     connect(addClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddClip()));
1342
1343     QAction *addColorClip = new KAction(KIcon("kdenlive-add-color-clip"), i18n("Add Color Clip"), this);
1344     collection->addAction("add_color_clip", addColorClip);
1345     connect(addColorClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddColorClip()));
1346
1347     QAction *addSlideClip = new KAction(KIcon("kdenlive-add-slide-clip"), i18n("Add Slideshow Clip"), this);
1348     collection->addAction("add_slide_clip", addSlideClip);
1349     connect(addSlideClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddSlideshowClip()));
1350
1351     QAction *addTitleClip = new KAction(KIcon("kdenlive-add-text-clip"), i18n("Add Title Clip"), this);
1352     collection->addAction("add_text_clip", addTitleClip);
1353     connect(addTitleClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddTitleClip()));
1354
1355     QAction *addTitleTemplateClip = new KAction(KIcon("kdenlive-add-text-clip"), i18n("Add Template Title"), this);
1356     collection->addAction("add_text_template_clip", addTitleTemplateClip);
1357     connect(addTitleTemplateClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddTitleTemplateClip()));
1358
1359     QAction *addFolderButton = new KAction(KIcon("folder-new"), i18n("Create Folder"), this);
1360     collection->addAction("add_folder", addFolderButton);
1361     connect(addFolderButton , SIGNAL(triggered()), m_projectList, SLOT(slotAddFolder()));
1362
1363     QAction *clipProperties = new KAction(KIcon("document-edit"), i18n("Clip Properties"), this);
1364     collection->addAction("clip_properties", clipProperties);
1365     clipProperties->setData("clip_properties");
1366     connect(clipProperties , SIGNAL(triggered()), m_projectList, SLOT(slotEditClip()));
1367     clipProperties->setEnabled(false);
1368
1369     QAction *openClip = new KAction(KIcon("document-open"), i18n("Edit Clip"), this);
1370     collection->addAction("edit_clip", openClip);
1371     openClip->setData("edit_clip");
1372     connect(openClip , SIGNAL(triggered()), m_projectList, SLOT(slotOpenClip()));
1373     openClip->setEnabled(false);
1374
1375     QAction *deleteClip = new KAction(KIcon("edit-delete"), i18n("Delete Clip"), this);
1376     collection->addAction("delete_clip", deleteClip);
1377     deleteClip->setData("delete_clip");
1378     connect(deleteClip , SIGNAL(triggered()), m_projectList, SLOT(slotRemoveClip()));
1379     deleteClip->setEnabled(false);
1380
1381     QAction *reloadClip = new KAction(KIcon("view-refresh"), i18n("Reload Clip"), this);
1382     collection->addAction("reload_clip", reloadClip);
1383     reloadClip->setData("reload_clip");
1384     connect(reloadClip , SIGNAL(triggered()), m_projectList, SLOT(slotReloadClip()));
1385     reloadClip->setEnabled(false);
1386
1387     QMenu *addClips = new QMenu();
1388     addClips->addAction(addClip);
1389     addClips->addAction(addColorClip);
1390     addClips->addAction(addSlideClip);
1391     addClips->addAction(addTitleClip);
1392     addClips->addAction(addTitleTemplateClip);
1393     addClips->addAction(addFolderButton);
1394
1395     addClips->addAction(reloadClip);
1396     addClips->addAction(clipProperties);
1397     addClips->addAction(openClip);
1398     addClips->addAction(deleteClip);
1399     m_projectList->setupMenu(addClips, addClip);
1400
1401     // Setup effects and transitions actions.
1402     m_effectsActionCollection = new KActionCollection(this, KGlobal::mainComponent());
1403     //KActionCategory *videoEffectActions = new KActionCategory(i18n("Video Effects"), m_effectsActionCollection);
1404     KActionCategory *videoEffectActions = new KActionCategory(i18n("Video Effects"), collection);
1405     m_videoEffects = new KAction*[videoEffects.count()];
1406     for (int i = 0; i < videoEffects.count(); ++i) {
1407         QStringList effectInfo = videoEffects.effectIdInfo(i);
1408         m_videoEffects[i] = new KAction(KIcon("kdenlive-show-video"), effectInfo.at(0), this);
1409         m_videoEffects[i]->setData(effectInfo);
1410         m_videoEffects[i]->setIconVisibleInMenu(false);
1411         videoEffectActions->addAction("video_effect_" + effectInfo.at(0), m_videoEffects[i]);
1412     }
1413     //KActionCategory *audioEffectActions = new KActionCategory(i18n("Audio Effects"), m_effectsActionCollection);
1414     KActionCategory *audioEffectActions = new KActionCategory(i18n("Audio Effects"), collection);
1415     m_audioEffects = new KAction*[audioEffects.count()];
1416     for (int i = 0; i < audioEffects.count(); ++i) {
1417         QStringList effectInfo = audioEffects.effectIdInfo(i);
1418         m_audioEffects[i] = new KAction(KIcon("kdenlive-show-audio"), effectInfo.at(0), this);
1419         m_audioEffects[i]->setData(effectInfo);
1420         m_audioEffects[i]->setIconVisibleInMenu(false);
1421         audioEffectActions->addAction("audio_effect_" + effectInfo.at(0), m_audioEffects[i]);
1422     }
1423     //KActionCategory *customEffectActions = new KActionCategory(i18n("Custom Effects"), m_effectsActionCollection);
1424     KActionCategory *customEffectActions = new KActionCategory(i18n("Custom Effects"), collection);
1425     m_customEffects = new KAction*[customEffects.count()];
1426     for (int i = 0; i < customEffects.count(); ++i) {
1427         QStringList effectInfo = customEffects.effectIdInfo(i);
1428         m_customEffects[i] = new KAction(KIcon("kdenlive-custom-effect"), effectInfo.at(0), this);
1429         m_customEffects[i]->setData(effectInfo);
1430         m_customEffects[i]->setIconVisibleInMenu(false);
1431         customEffectActions->addAction("custom_effect_" + effectInfo.at(0), m_customEffects[i]);
1432     }
1433     //KActionCategory *transitionActions = new KActionCategory(i18n("Transitions"), m_effectsActionCollection);
1434     KActionCategory *transitionActions = new KActionCategory(i18n("Transitions"), collection);
1435     m_transitions = new KAction*[transitions.count()];
1436     for (int i = 0; i < transitions.count(); i++) {
1437         QStringList effectInfo = transitions.effectIdInfo(i);
1438         m_transitions[i] = new KAction(effectInfo.at(0), this);
1439         m_transitions[i]->setData(effectInfo);
1440         m_transitions[i]->setIconVisibleInMenu(false);
1441         transitionActions->addAction("transition_" + effectInfo.at(0), m_transitions[i]);
1442     }
1443     m_effectsActionCollection->readSettings();
1444
1445     //connect(collection, SIGNAL( clearStatusText() ),
1446     //statusBar(), SLOT( clear() ) );
1447 }
1448
1449 void MainWindow::slotDisplayActionMessage(QAction *a)
1450 {
1451     statusBar()->showMessage(a->data().toString(), 3000);
1452 }
1453
1454 void MainWindow::saveOptions()
1455 {
1456     KdenliveSettings::self()->writeConfig();
1457     KSharedConfigPtr config = KGlobal::config();
1458     m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
1459     KConfigGroup treecolumns(config, "Project Tree");
1460     treecolumns.writeEntry("columns", m_projectList->headerInfo());
1461     config->sync();
1462 }
1463
1464 void MainWindow::readOptions()
1465 {
1466     KSharedConfigPtr config = KGlobal::config();
1467     m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
1468     KConfigGroup initialGroup(config, "version");
1469     bool upgrade = false;
1470     if (initialGroup.exists()) {
1471         if (initialGroup.readEntry("version", QString()).section(' ', 0, 0) != QString(version).section(' ', 0, 0)) {
1472             upgrade = true;
1473         }
1474
1475         if (initialGroup.readEntry("version") == "0.7") {
1476             //Add new settings from 0.7.1
1477             if (KdenliveSettings::defaultprojectfolder().isEmpty()) {
1478                 QString path = QDir::homePath() + "/kdenlive";
1479                 if (KStandardDirs::makeDir(path)  == false) {
1480                     kDebug() << "/// ERROR CREATING PROJECT FOLDER: " << path;
1481                 } else KdenliveSettings::setDefaultprojectfolder(path);
1482             }
1483         }
1484
1485     }
1486
1487     if (!initialGroup.exists() || upgrade) {
1488         // this is our first run, show Wizard
1489         Wizard *w = new Wizard(upgrade, this);
1490         if (w->exec() == QDialog::Accepted && w->isOk()) {
1491             w->adjustSettings();
1492             initialGroup.writeEntry("version", version);
1493             delete w;
1494         } else {
1495             ::exit(1);
1496         }
1497     }
1498     KConfigGroup treecolumns(config, "Project Tree");
1499     const QByteArray state = treecolumns.readEntry("columns", QByteArray());
1500     if (!state.isEmpty())
1501         m_projectList->setHeaderInfo(state);
1502 }
1503
1504 void MainWindow::slotRunWizard()
1505 {
1506     Wizard *w = new Wizard(false, this);
1507     if (w->exec() == QDialog::Accepted && w->isOk()) {
1508         w->adjustSettings();
1509     }
1510     delete w;
1511 }
1512
1513 void MainWindow::newFile(bool showProjectSettings, bool force)
1514 {
1515     if (!m_timelineArea->isEnabled() && !force) return;
1516     m_fileRevert->setEnabled(false);
1517     QString profileName;
1518     KUrl projectFolder;
1519     QPoint projectTracks(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks());
1520     if (!showProjectSettings) {
1521         if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1522         profileName = KdenliveSettings::default_profile();
1523         projectFolder = KdenliveSettings::defaultprojectfolder();
1524     } else {
1525         ProjectSettings *w = new ProjectSettings(NULL, QStringList(), projectTracks.x(), projectTracks.y(), KdenliveSettings::defaultprojectfolder(), false, true, this);
1526         if (w->exec() != QDialog::Accepted) return;
1527         if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1528         if (KdenliveSettings::videothumbnails() != w->enableVideoThumbs()) slotSwitchVideoThumbs();
1529         if (KdenliveSettings::audiothumbnails() != w->enableAudioThumbs()) slotSwitchAudioThumbs();
1530         profileName = w->selectedProfile();
1531         projectFolder = w->selectedFolder();
1532         projectTracks = w->tracks();
1533         delete w;
1534     }
1535     m_timelineArea->setEnabled(true);
1536     m_projectList->setEnabled(true);
1537     KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, profileName, projectTracks, m_projectMonitor->render, this);
1538     doc->m_autosave = new KAutoSaveFile(KUrl(), doc);
1539     bool ok;
1540     TrackView *trackView = new TrackView(doc, &ok, this);
1541     m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
1542     if (!ok) {
1543         // MLT is broken
1544         //m_timelineArea->setEnabled(false);
1545         //m_projectList->setEnabled(false);
1546         slotPreferences(6);
1547         return;
1548     }
1549     if (m_timelineArea->count() == 1) {
1550         connectDocumentInfo(doc);
1551         connectDocument(trackView, doc);
1552     } else m_timelineArea->setTabBarHidden(false);
1553     m_monitorManager->activateMonitor("clip");
1554     m_closeAction->setEnabled(m_timelineArea->count() > 1);
1555 }
1556
1557 void MainWindow::activateDocument()
1558 {
1559     if (m_timelineArea->currentWidget() == NULL || !m_timelineArea->isEnabled()) return;
1560     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1561     KdenliveDoc *currentDoc = currentTab->document();
1562     connectDocumentInfo(currentDoc);
1563     connectDocument(currentTab, currentDoc);
1564 }
1565
1566 void MainWindow::closeCurrentDocument(bool saveChanges)
1567 {
1568     QWidget *w = m_timelineArea->currentWidget();
1569     if (!w) return;
1570     // closing current document
1571     int ix = m_timelineArea->currentIndex() + 1;
1572     if (ix == m_timelineArea->count()) ix = 0;
1573     m_timelineArea->setCurrentIndex(ix);
1574     TrackView *tabToClose = (TrackView *) w;
1575     KdenliveDoc *docToClose = tabToClose->document();
1576     if (docToClose && docToClose->isModified() && saveChanges) {
1577         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document?"))) {
1578         case KMessageBox::Yes :
1579             // save document here. If saving fails, return false;
1580             if (saveFile() == false) return;
1581             break;
1582         case KMessageBox::Cancel :
1583             return;
1584             break;
1585         default:
1586             break;
1587         }
1588     }
1589     m_clipMonitor->slotSetXml(NULL);
1590     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
1591     if (m_timelineArea->count() == 1) {
1592         m_timelineArea->setTabBarHidden(true);
1593         m_closeAction->setEnabled(false);
1594     }
1595     if (docToClose == m_activeDocument) {
1596         delete m_activeDocument;
1597         m_activeDocument = NULL;
1598         m_effectStack->clear();
1599         m_transitionConfig->slotTransitionItemSelected(NULL, 0, QPoint(), false);
1600     } else delete docToClose;
1601     if (w == m_activeTimeline) {
1602         delete m_activeTimeline;
1603         m_activeTimeline = NULL;
1604     } else delete w;
1605 }
1606
1607 bool MainWindow::saveFileAs(const QString &outputFileName)
1608 {
1609     QString currentSceneList;
1610     m_monitorManager->stopActiveMonitor();
1611     if (KdenliveSettings::dropbframes()) {
1612         KdenliveSettings::setDropbframes(false);
1613         m_activeDocument->clipManager()->updatePreviewSettings();
1614         currentSceneList = m_projectMonitor->sceneList();
1615         KdenliveSettings::setDropbframes(true);
1616         m_activeDocument->clipManager()->updatePreviewSettings();
1617     } else currentSceneList = m_projectMonitor->sceneList();
1618
1619     if (m_activeDocument->saveSceneList(outputFileName, currentSceneList) == false)
1620         return false;
1621
1622     // Save timeline thumbnails
1623     m_activeTimeline->projectView()->saveThumbnails();
1624     m_activeDocument->setUrl(KUrl(outputFileName));
1625     if (m_activeDocument->m_autosave == NULL) {
1626         m_activeDocument->m_autosave = new KAutoSaveFile(KUrl(outputFileName), this);
1627     } else m_activeDocument->m_autosave->setManagedFile(KUrl(outputFileName));
1628     setCaption(m_activeDocument->description());
1629     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1630     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
1631     m_activeDocument->setModified(false);
1632     m_fileOpenRecent->addUrl(KUrl(outputFileName));
1633     m_fileRevert->setEnabled(true);
1634     return true;
1635 }
1636
1637 bool MainWindow::saveFileAs()
1638 {
1639     QString outputFile = KFileDialog::getSaveFileName(KUrl(), getMimeType());
1640     if (outputFile.isEmpty()) return false;
1641     if (QFile::exists(outputFile)) {
1642         // Show the file dialog again if the user does not want to overwrite the file
1643         if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it?")) == KMessageBox::No)
1644             return saveFileAs();
1645     }
1646     return saveFileAs(outputFile);
1647 }
1648
1649 bool MainWindow::saveFile()
1650 {
1651     if (!m_activeDocument) return true;
1652     if (m_activeDocument->url().isEmpty()) {
1653         return saveFileAs();
1654     } else {
1655         bool result = saveFileAs(m_activeDocument->url().path());
1656         m_activeDocument->m_autosave->resize(0);
1657         return result;
1658     }
1659 }
1660
1661 void MainWindow::openFile()
1662 {
1663     if (!m_startUrl.isEmpty()) {
1664         openFile(m_startUrl);
1665         m_startUrl = KUrl();
1666         return;
1667     }
1668     KUrl url = KFileDialog::getOpenUrl(KUrl("kfiledialog:///projectfolder"), getMimeType());
1669     if (url.isEmpty()) return;
1670     m_fileOpenRecent->addUrl(url);
1671     openFile(url);
1672 }
1673
1674 void MainWindow::openLastFile()
1675 {
1676     KSharedConfigPtr config = KGlobal::config();
1677     KUrl::List urls = m_fileOpenRecent->urls();
1678     //WARNING: this is buggy, we get a random url, not the last one. Bug in KRecentFileAction?
1679     if (urls.isEmpty()) newFile(false);
1680     else openFile(urls.last());
1681 }
1682
1683 void MainWindow::openFile(const KUrl &url)
1684 {
1685     // Check if the document is already opened
1686     const int ct = m_timelineArea->count();
1687     bool isOpened = false;
1688     int i;
1689     for (i = 0; i < ct; i++) {
1690         TrackView *tab = (TrackView *) m_timelineArea->widget(i);
1691         KdenliveDoc *doc = tab->document();
1692         if (doc->url() == url) {
1693             isOpened = true;
1694             break;
1695         }
1696     }
1697     if (isOpened) {
1698         m_timelineArea->setCurrentIndex(i);
1699         return;
1700     }
1701
1702     // Check for backup file
1703     QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::staleFiles(url);
1704     if (!staleFiles.isEmpty()) {
1705         if (KMessageBox::questionYesNo(this,
1706                                        i18n("Auto-saved files exist. Do you want to recover them now?"),
1707                                        i18n("File Recovery"),
1708                                        KGuiItem(i18n("Recover")), KGuiItem(i18n("Don't recover"))) == KMessageBox::Yes) {
1709             recoverFiles(staleFiles);
1710             return;
1711         } else {
1712             // remove the stale files
1713             foreach(KAutoSaveFile *stale, staleFiles) {
1714                 stale->open(QIODevice::ReadWrite);
1715                 delete stale;
1716             }
1717         }
1718     }
1719     if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1720     m_messageLabel->setMessage(i18n("Opening file %1", url.path()), InformationMessage);
1721     m_messageLabel->repaint();
1722     doOpenFile(url, NULL);
1723 }
1724
1725 void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale)
1726 {
1727     if (!m_timelineArea->isEnabled()) return;
1728     m_fileRevert->setEnabled(true);
1729     KdenliveDoc *doc = new KdenliveDoc(url, KdenliveSettings::defaultprojectfolder(), m_commandStack, KdenliveSettings::default_profile(), QPoint(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks()), m_projectMonitor->render, this);
1730     if (stale == NULL) {
1731         stale = new KAutoSaveFile(url, doc);
1732         doc->m_autosave = stale;
1733     } else {
1734         doc->m_autosave = stale;
1735         doc->setUrl(stale->managedFile());
1736         doc->setModified(true);
1737         stale->setParent(doc);
1738     }
1739     connectDocumentInfo(doc);
1740     bool ok;
1741     TrackView *trackView = new TrackView(doc, &ok, this);
1742     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
1743     if (!ok) {
1744         m_timelineArea->setEnabled(false);
1745         m_projectList->setEnabled(false);
1746         KMessageBox::sorry(this, i18n("Cannot open file %1.\nProject is corrupted.", url.path()));
1747         slotGotProgressInfo(QString(), -1);
1748         newFile(false, true);
1749         return;
1750     }
1751     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
1752     trackView->setDuration(trackView->duration());
1753     trackView->projectView()->initCursorPos(m_projectMonitor->render->seekPosition().frames(doc->fps()));
1754
1755     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
1756     slotGotProgressInfo(QString(), -1);
1757     m_projectMonitor->adjustRulerSize(trackView->duration());
1758     m_projectMonitor->slotZoneMoved(trackView->inPoint(), trackView->outPoint());
1759     m_clipMonitor->refreshMonitor(true);
1760 }
1761
1762 void MainWindow::recoverFiles(QList<KAutoSaveFile *> staleFiles)
1763 {
1764     if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1765     foreach(KAutoSaveFile *stale, staleFiles) {
1766         /*if (!stale->open(QIODevice::QIODevice::ReadOnly)) {
1767                   // show an error message; we could not steal the lockfile
1768                   // maybe another application got to the file before us?
1769                   delete stale;
1770                   continue;
1771         }*/
1772         kDebug() << "// OPENING RECOVERY: " << stale->fileName() << "\nMANAGED: " << stale->managedFile().path();
1773         // the stalefiles also contain ".lock" files so we must ignore them... bug in KAutoSaveFile?
1774         if (!stale->fileName().endsWith(".lock")) doOpenFile(KUrl(stale->fileName()), stale);
1775         else KIO::NetAccess::del(KUrl(stale->fileName()), this);
1776     }
1777 }
1778
1779 void MainWindow::parseProfiles(const QString &mltPath)
1780 {
1781     //KdenliveSettings::setDefaulttmpfolder();
1782     if (!mltPath.isEmpty()) {
1783         KdenliveSettings::setMltpath(mltPath + "/share/mlt/profiles/");
1784         KdenliveSettings::setRendererpath(mltPath + "/bin/melt");
1785     }
1786
1787     if (KdenliveSettings::mltpath().isEmpty())
1788         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
1789
1790     if (KdenliveSettings::rendererpath().isEmpty() || KdenliveSettings::rendererpath().endsWith("inigo")) {
1791         QString meltPath = QString(MLT_PREFIX) + QString("/bin/melt");
1792         if (!QFile::exists(meltPath))
1793             meltPath = KStandardDirs::findExe("melt");
1794         KdenliveSettings::setRendererpath(meltPath);
1795     }
1796
1797     if (KdenliveSettings::rendererpath().isEmpty()) {
1798         // Cannot find the MLT melt renderer, ask for location
1799         KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(QString(), i18n("Cannot find the melt program required for rendering (part of MLT)"), this);
1800         if (getUrl->exec() == QDialog::Rejected) {
1801             ::exit(0);
1802         }
1803         KUrl rendererPath = getUrl->selectedUrl();
1804         delete getUrl;
1805         if (rendererPath.isEmpty()) ::exit(0);
1806         KdenliveSettings::setRendererpath(rendererPath.path());
1807     }
1808
1809     QStringList profilesFilter;
1810     profilesFilter << "*";
1811     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1812     if (profilesList.isEmpty()) {
1813         // Cannot find MLT path, try finding melt
1814         QString profilePath = KdenliveSettings::rendererpath();
1815         if (!profilePath.isEmpty()) {
1816             profilePath = profilePath.section('/', 0, -3);
1817             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
1818             profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1819         }
1820         if (profilesList.isEmpty()) {
1821             // Cannot find the MLT profiles, ask for location
1822             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your MLT profiles, please give the path"), this);
1823             getUrl->fileDialog()->setMode(KFile::Directory);
1824             if (getUrl->exec() == QDialog::Rejected) {
1825                 ::exit(0);
1826             }
1827             KUrl mltPath = getUrl->selectedUrl();
1828             delete getUrl;
1829             if (mltPath.isEmpty()) ::exit(0);
1830             KdenliveSettings::setMltpath(mltPath.path(KUrl::AddTrailingSlash));
1831             profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1832         }
1833     }
1834
1835     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
1836
1837     // Parse again MLT profiles to build a list of available video formats
1838     if (profilesList.isEmpty()) parseProfiles();
1839 }
1840
1841
1842 void MainWindow::slotEditProfiles()
1843 {
1844     ProfilesDialog *w = new ProfilesDialog;
1845     if (w->exec() == QDialog::Accepted) {
1846         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
1847         if (d) d->checkProfile();
1848     }
1849     delete w;
1850 }
1851
1852 void MainWindow::slotDetectAudioDriver()
1853 {
1854     /* WARNING: do not use this method because sometimes detects wrong driver (pulse instead of alsa),
1855     leading to no audio output, see bug #934 */
1856
1857     //decide which audio driver is really best, in some cases SDL is wrong
1858     if (KdenliveSettings::audiodrivername().isEmpty()) {
1859         QString driver;
1860         KProcess readProcess;
1861         //PulseAudio needs to be selected if it exists, the ALSA pulse pcm device is not fast enough.
1862         if (!KStandardDirs::findExe("pactl").isEmpty()) {
1863             readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
1864             readProcess.setProgram("pactl", QStringList() << "stat");
1865             readProcess.execute(2000); // Kill it after 2 seconds
1866
1867             QString result = QString(readProcess.readAllStandardOutput());
1868             kDebug() << "// / / / / / READING PACTL: ";
1869             kDebug() << result;
1870             if (!result.isEmpty()) {
1871                 driver = "pulse";
1872                 kDebug() << "// / / / / PULSEAUDIO DETECTED";
1873             }
1874         }
1875         //put others here
1876         KdenliveSettings::setAutoaudiodrivername(driver);
1877     }
1878 }
1879
1880 void MainWindow::slotEditProjectSettings()
1881 {
1882     QPoint p = m_activeDocument->getTracksCount();
1883     ProjectSettings *w = new ProjectSettings(m_projectList, m_activeTimeline->projectView()->extractTransitionsLumas(), p.x(), p.y(), m_activeDocument->projectFolder().path(), true, !m_activeDocument->isModified(), this);
1884
1885     if (w->exec() == QDialog::Accepted) {
1886         QString profile = w->selectedProfile();
1887         m_activeDocument->setProjectFolder(w->selectedFolder());
1888         if (m_renderWidget) m_renderWidget->setDocumentPath(w->selectedFolder().path(KUrl::AddTrailingSlash));
1889         if (KdenliveSettings::videothumbnails() != w->enableVideoThumbs()) slotSwitchVideoThumbs();
1890         if (KdenliveSettings::audiothumbnails() != w->enableAudioThumbs()) slotSwitchAudioThumbs();
1891         if (m_activeDocument->profilePath() != profile) {
1892             // Profile was changed
1893             double dar = m_activeDocument->dar();
1894
1895             // Deselect current effect / transition
1896             m_effectStack->slotClipItemSelected(NULL, 0);
1897             m_transitionConfig->slotTransitionItemSelected(NULL, 0, QPoint(), false);
1898             m_clipMonitor->slotSetXml(NULL);
1899             bool updateFps = m_activeDocument->setProfilePath(profile);
1900             KdenliveSettings::setCurrent_profile(profile);
1901             KdenliveSettings::setProject_fps(m_activeDocument->fps());
1902             setCaption(m_activeDocument->description(), m_activeDocument->isModified());
1903
1904             m_activeDocument->clipManager()->clearUnusedProducers();
1905             m_monitorManager->resetProfiles(m_activeDocument->timecode());
1906
1907             m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
1908             m_effectStack->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode());
1909             m_projectList->updateProjectFormat(m_activeDocument->timecode());
1910             if (m_renderWidget) m_renderWidget->setProfile(m_activeDocument->mltProfile());
1911             m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1912             //m_activeDocument->clipManager()->resetProducersList(m_projectMonitor->render->producersList());
1913             if (dar != m_activeDocument->dar()) m_projectList->reloadClipThumbnails();
1914             if (updateFps) m_activeTimeline->updateProjectFps();
1915             m_activeDocument->setModified(true);
1916             m_commandStack->activeStack()->clear();
1917             //Update the mouse position display so it will display in DF/NDF format by default based on the project setting.
1918             slotUpdateMousePosition(0);
1919             // We need to desactivate & reactivate monitors to get a refresh
1920             //m_monitorManager->switchMonitors();
1921         }
1922     }
1923     delete w;
1924 }
1925
1926
1927 void MainWindow::slotRenderProject()
1928 {
1929     if (!m_renderWidget) {
1930         QString projectfolder = m_activeDocument ? m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash) : KdenliveSettings::defaultprojectfolder();
1931         m_renderWidget = new RenderWidget(projectfolder, this);
1932         connect(m_renderWidget, SIGNAL(shutdown()), this, SLOT(slotShutdown()));
1933         connect(m_renderWidget, SIGNAL(selectedRenderProfile(const QString &, const QString &, const QString &, const QString&)), this, SLOT(slotSetDocumentRenderProfile(const QString &, const QString &, const QString &, const QString&)));
1934         connect(m_renderWidget, SIGNAL(prepareRenderingData(bool, bool, const QString&)), this, SLOT(slotPrepareRendering(bool, bool, const QString&)));
1935         connect(m_renderWidget, SIGNAL(abortProcess(const QString &)), this, SIGNAL(abortRenderJob(const QString &)));
1936         connect(m_renderWidget, SIGNAL(openDvdWizard(const QString &, const QString &)), this, SLOT(slotDvdWizard(const QString &, const QString &)));
1937         if (m_activeDocument) {
1938             m_renderWidget->setProfile(m_activeDocument->mltProfile());
1939             m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1940             m_renderWidget->setDocumentPath(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
1941             m_renderWidget->setRenderProfile(m_activeDocument->getDocumentProperty("renderdestination"), m_activeDocument->getDocumentProperty("rendercategory"), m_activeDocument->getDocumentProperty("renderprofile"), m_activeDocument->getDocumentProperty("renderurl"));
1942         }
1943     }
1944     slotCheckRenderStatus();
1945     /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1946     if (currentTab) m_renderWidget->setTimeline(currentTab);
1947     m_renderWidget->setDocument(m_activeDocument);*/
1948     m_renderWidget->show();
1949     m_renderWidget->showNormal();
1950
1951     m_activeTimeline->tracksNumber();
1952     m_renderWidget->enableAudio(false);
1953     //m_renderWidget->export_audio;
1954 }
1955
1956 void MainWindow::slotCheckRenderStatus()
1957 {
1958     // Make sure there are no missing clips
1959     if (m_renderWidget)
1960         m_renderWidget->missingClips(m_projectList->hasMissingClips());
1961 }
1962
1963 void MainWindow::setRenderingProgress(const QString &url, int progress)
1964 {
1965     if (m_renderWidget)
1966         m_renderWidget->setRenderJob(url, progress);
1967 }
1968
1969 void MainWindow::setRenderingFinished(const QString &url, int status, const QString &error)
1970 {
1971     if (m_renderWidget)
1972         m_renderWidget->setRenderStatus(url, status, error);
1973 }
1974
1975 void MainWindow::slotCleanProject()
1976 {
1977     if (KMessageBox::warningContinueCancel(this, i18n("This will remove all unused clips from your project."), i18n("Clean up project")) == KMessageBox::Cancel) return;
1978     m_projectList->cleanup();
1979 }
1980
1981 void MainWindow::slotUpdateMousePosition(int pos)
1982 {
1983     if (m_activeDocument)
1984         switch (m_timecodeFormat->currentIndex()) {
1985         case 0:
1986             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
1987             break;
1988         default:
1989             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
1990         }
1991 }
1992
1993 void MainWindow::slotUpdateDocumentState(bool modified)
1994 {
1995     if (!m_activeDocument) return;
1996     setCaption(m_activeDocument->description(), modified);
1997     m_saveAction->setEnabled(modified);
1998     if (modified) {
1999         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
2000         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
2001     } else {
2002         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
2003         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
2004     }
2005 }
2006
2007 void MainWindow::connectDocumentInfo(KdenliveDoc *doc)
2008 {
2009     if (m_activeDocument) {
2010         if (m_activeDocument == doc) return;
2011         disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
2012     }
2013     connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
2014 }
2015
2016 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc)   //changed
2017 {
2018     //m_projectMonitor->stop();
2019     m_closeAction->setEnabled(m_timelineArea->count() > 1);
2020     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
2021     if (m_activeDocument) {
2022         if (m_activeDocument == doc) return;
2023         if (m_activeTimeline) {
2024             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
2025             disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeTimeline, SLOT(slotSetZone(QPoint)));
2026             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
2027             disconnect(m_projectList, SIGNAL(projectModified()), m_activeDocument, SLOT(setModified()));
2028             disconnect(m_projectMonitor->render, SIGNAL(refreshDocumentProducers()), m_activeDocument, SLOT(checkProjectClips()));
2029
2030             disconnect(m_activeDocument, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
2031             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
2032             disconnect(m_activeDocument, SIGNAL(resetProjectList()), m_projectList, SLOT(slotResetProjectList()));
2033             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
2034             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
2035             disconnect(m_activeDocument, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
2036             disconnect(m_activeDocument, SIGNAL(deleteTimelineClip(const QString &)), m_activeTimeline, SLOT(slotDeleteClip(const QString &)));
2037             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), m_effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
2038             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
2039             disconnect(m_activeTimeline->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), m_transitionConfig, SLOT(slotTransitionItemSelected(Transition*, int, QPoint, bool)));
2040             disconnect(m_activeTimeline->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), this, SLOT(slotActivateTransitionView(Transition *)));
2041             disconnect(m_activeTimeline->projectView(), SIGNAL(playMonitor()), m_projectMonitor, SLOT(slotPlay()));
2042             disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
2043             disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, QPoint, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, QPoint, const int)));
2044             disconnect(m_activeTimeline, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
2045             disconnect(m_activeTimeline, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
2046             disconnect(m_activeTimeline, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
2047             disconnect(m_activeTimeline, SIGNAL(configTrack(int)), this, SLOT(slotConfigTrack(int)));
2048             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
2049             disconnect(m_effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
2050             disconnect(m_effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
2051             disconnect(m_effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
2052             disconnect(m_effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), m_activeTimeline->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
2053             disconnect(m_effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
2054             disconnect(m_effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
2055             disconnect(m_transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), m_activeTimeline->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
2056             disconnect(m_transitionConfig, SIGNAL(seekTimeline(int)), m_activeTimeline->projectView() , SLOT(setCursorPos(int)));
2057             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
2058             disconnect(m_activeTimeline, SIGNAL(zoneMoved(int, int)), this, SLOT(slotZoneMoved(int, int)));
2059             disconnect(m_projectList, SIGNAL(loadingIsOver()), m_activeTimeline->projectView(), SLOT(slotUpdateAllThumbs()));
2060             disconnect(m_projectList, SIGNAL(displayMessage(const QString&, int)), this, SLOT(slotGotProgressInfo(const QString&, int)));
2061             disconnect(m_projectList, SIGNAL(updateRenderStatus()), this, SLOT(slotCheckRenderStatus()));
2062             disconnect(m_projectList, SIGNAL(clipNeedsReload(const QString&, bool)), m_activeTimeline->projectView(), SLOT(slotUpdateClip(const QString &, bool)));
2063             m_effectStack->clear();
2064         }
2065         //m_activeDocument->setRenderer(NULL);
2066         disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
2067         disconnect(m_projectList, SIGNAL(refreshClip()), m_clipMonitor, SLOT(refreshMonitor()));
2068         m_clipMonitor->stop();
2069     }
2070     KdenliveSettings::setCurrent_profile(doc->profilePath());
2071     KdenliveSettings::setProject_fps(doc->fps());
2072     m_monitorManager->resetProfiles(doc->timecode());
2073     m_projectList->setDocument(doc);
2074     m_transitionConfig->updateProjectFormat(doc->mltProfile(), doc->timecode(), doc->tracksList());
2075     m_effectStack->updateProjectFormat(doc->mltProfile(), doc->timecode());
2076     connect(m_projectList, SIGNAL(clipSelected(DocClipBase *, QPoint)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, QPoint)));
2077     connect(m_projectList, SIGNAL(refreshClip()), m_clipMonitor, SLOT(refreshMonitor()));
2078     connect(m_projectList, SIGNAL(clipNeedsReload(const QString&, bool)), trackView->projectView(), SLOT(slotUpdateClip(const QString &, bool)));
2079
2080     connect(m_projectList, SIGNAL(projectModified()), doc, SLOT(setModified()));
2081     connect(m_projectList, SIGNAL(clipNameChanged(const QString, const QString)), trackView->projectView(), SLOT(clipNameChanged(const QString, const QString)));
2082
2083     connect(m_projectList, SIGNAL(findInTimeline(const QString&)), this, SLOT(slotClipInTimeline(const QString&)));
2084
2085
2086     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
2087     connect(trackView, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
2088     connect(trackView, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
2089     connect(trackView, SIGNAL(configTrack(int)), this, SLOT(slotConfigTrack(int)));
2090     connect(trackView, SIGNAL(updateTracksInfo()), this, SLOT(slotUpdateTrackInfo()));
2091     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
2092     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
2093     connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), trackView, SLOT(slotSetZone(QPoint)));
2094     connect(m_clipMonitor, SIGNAL(zoneUpdated(QPoint)), m_projectList, SLOT(slotUpdateClipCut(QPoint)));
2095     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
2096     connect(m_projectMonitor->render, SIGNAL(refreshDocumentProducers()), doc, SLOT(checkProjectClips()));
2097
2098     connect(doc, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
2099     connect(doc, SIGNAL(resetProjectList()), m_projectList, SLOT(slotResetProjectList()));
2100     connect(doc, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
2101     connect(doc, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
2102     connect(doc, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
2103
2104     connect(doc, SIGNAL(deleteTimelineClip(const QString &)), trackView, SLOT(slotDeleteClip(const QString &)));
2105     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
2106     connect(doc, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
2107
2108
2109     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), m_effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
2110     connect(trackView->projectView(), SIGNAL(updateClipMarkers(DocClipBase *)), this, SLOT(slotUpdateClipMarkers(DocClipBase*)));
2111
2112     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
2113     connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), m_transitionConfig, SLOT(slotTransitionItemSelected(Transition*, int, QPoint, bool)));
2114     connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), this, SLOT(slotActivateTransitionView(Transition *)));
2115     m_zoomSlider->setValue(doc->zoom().x());
2116     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
2117     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
2118     connect(trackView, SIGNAL(setZoom(int)), this, SLOT(slotSetZoom(int)));
2119     connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
2120
2121     connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, QPoint, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, QPoint, const int)));
2122     connect(trackView->projectView(), SIGNAL(playMonitor()), m_projectMonitor, SLOT(slotPlay()));
2123
2124
2125     connect(m_effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
2126     connect(m_effectStack, SIGNAL(updateClipRegion(ClipItem*, int, QString)), trackView->projectView(), SLOT(slotUpdateClipRegion(ClipItem*, int, QString)));
2127     connect(m_effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
2128     connect(m_effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
2129     connect(m_effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
2130     connect(m_effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
2131     connect(m_transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
2132     connect(m_transitionConfig, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
2133     connect(m_effectStack, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
2134     connect(m_effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
2135
2136     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
2137     connect(trackView, SIGNAL(zoneMoved(int, int)), this, SLOT(slotZoneMoved(int, int)));
2138     connect(m_projectList, SIGNAL(loadingIsOver()), trackView->projectView(), SLOT(slotUpdateAllThumbs()));
2139     connect(m_projectList, SIGNAL(displayMessage(const QString&, int)), this, SLOT(slotGotProgressInfo(const QString&, int)));
2140     connect(m_projectList, SIGNAL(updateRenderStatus()), this, SLOT(slotCheckRenderStatus()));
2141
2142
2143     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu, m_clipTypeGroup, (QMenu*)(factory()->container("marker_menu", this)));
2144     m_activeTimeline = trackView;
2145     if (m_renderWidget) {
2146         slotCheckRenderStatus();
2147         m_renderWidget->setProfile(doc->mltProfile());
2148         m_renderWidget->setGuides(doc->guidesXml(), doc->projectDuration());
2149         m_renderWidget->setDocumentPath(doc->projectFolder().path(KUrl::AddTrailingSlash));
2150         m_renderWidget->setRenderProfile(doc->getDocumentProperty("renderdestination"), doc->getDocumentProperty("rendercategory"), doc->getDocumentProperty("renderprofile"), doc->getDocumentProperty("renderurl"));
2151     }
2152     //doc->setRenderer(m_projectMonitor->render);
2153     m_commandStack->setActiveStack(doc->commandStack());
2154     KdenliveSettings::setProject_display_ratio(doc->dar());
2155     //doc->clipManager()->checkAudioThumbs();
2156
2157     //m_overView->setScene(trackView->projectScene());
2158     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
2159     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
2160
2161     setCaption(doc->description(), doc->isModified());
2162     m_saveAction->setEnabled(doc->isModified());
2163     m_normalEditTool->setChecked(true);
2164     m_activeDocument = doc;
2165     m_activeTimeline->updateProjectFps();
2166     m_activeDocument->checkProjectClips();
2167     if (KdenliveSettings::dropbframes()) slotUpdatePreviewSettings();
2168     //Update the mouse position display so it will display in DF/NDF format by default based on the project setting.
2169     slotUpdateMousePosition(0);
2170     // set tool to select tool
2171     m_buttonSelectTool->setChecked(true);
2172 }
2173
2174 void MainWindow::slotZoneMoved(int start, int end)
2175 {
2176     m_activeDocument->setZone(start, end);
2177     m_projectMonitor->slotZoneMoved(start, end);
2178 }
2179
2180 void MainWindow::slotGuidesUpdated()
2181 {
2182     if (m_renderWidget)
2183         m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
2184 }
2185
2186 void MainWindow::slotEditKeys()
2187 {
2188     KShortcutsDialog dialog(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, this);
2189     dialog.addCollection(actionCollection(), i18nc("general keyboard shortcuts", "General"));
2190     dialog.addCollection(m_effectsActionCollection, i18nc("effects and transitions keyboard shortcuts", "Effects & Transitions"));
2191     dialog.configure();
2192 }
2193
2194 void MainWindow::slotPreferences(int page, int option)
2195 {
2196     //An instance of your dialog could be already created and could be
2197     // cached, in which case you want to display the cached dialog
2198     // instead of creating another one
2199     if (KConfigDialog::showDialog("settings")) {
2200         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
2201         if (page != -1) d->showPage(page, option);
2202         return;
2203     }
2204
2205     // KConfigDialog didn't find an instance of this dialog, so lets
2206     // create it :
2207     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
2208     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
2209     //connect(dialog, SIGNAL(doResetProfile()), this, SLOT(slotDetectAudioDriver()));
2210     connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(slotResetProfiles()));
2211     connect(dialog, SIGNAL(updatePreviewSettings()), this, SLOT(slotUpdatePreviewSettings()));
2212 #ifndef Q_WS_MAC
2213     connect(dialog, SIGNAL(updateCaptureFolder()), m_recMonitor, SLOT(slotUpdateCaptureFolder()));
2214 #endif
2215     //connect(dialog, SIGNAL(updatePreviewSettings()), this, SLOT(slotUpdatePreviewSettings()));
2216     dialog->show();
2217     if (page != -1) dialog->showPage(page, option);
2218 }
2219
2220 void MainWindow::slotUpdatePreviewSettings()
2221 {
2222     if (m_activeDocument) {
2223         m_clipMonitor->slotSetXml(NULL);
2224         m_activeDocument->updatePreviewSettings();
2225     }
2226 }
2227
2228 void MainWindow::updateConfiguration()
2229 {
2230     //TODO: we should apply settings to all projects, not only the current one
2231     if (m_activeTimeline) {
2232         m_activeTimeline->refresh();
2233         m_activeTimeline->projectView()->checkAutoScroll();
2234         m_activeTimeline->projectView()->checkTrackHeight();
2235         if (m_activeDocument)
2236             m_activeDocument->clipManager()->checkAudioThumbs();
2237     }
2238     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
2239     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
2240     m_buttonAutomaticSplitAudio->setChecked(KdenliveSettings::splitaudio());
2241
2242     // Update list of transcoding profiles
2243     loadTranscoders();
2244 #ifndef NO_JOGSHUTTLE
2245     activateShuttleDevice();
2246 #endif /* NO_JOGSHUTTLE */
2247
2248 }
2249
2250 void MainWindow::slotSwitchSplitAudio()
2251 {
2252     KdenliveSettings::setSplitaudio(!KdenliveSettings::splitaudio());
2253     m_buttonAutomaticSplitAudio->setChecked(KdenliveSettings::splitaudio());
2254 }
2255
2256 void MainWindow::slotSwitchVideoThumbs()
2257 {
2258     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
2259     if (m_activeTimeline)
2260         m_activeTimeline->projectView()->slotUpdateAllThumbs();
2261     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
2262 }
2263
2264 void MainWindow::slotSwitchAudioThumbs()
2265 {
2266     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
2267     if (m_activeTimeline) {
2268         m_activeTimeline->refresh();
2269         m_activeTimeline->projectView()->checkAutoScroll();
2270         if (m_activeDocument)
2271             m_activeDocument->clipManager()->checkAudioThumbs();
2272     }
2273     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
2274 }
2275
2276 void MainWindow::slotSwitchMarkersComments()
2277 {
2278     KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
2279     if (m_activeTimeline)
2280         m_activeTimeline->refresh();
2281     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
2282 }
2283
2284 void MainWindow::slotSwitchSnap()
2285 {
2286     KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
2287     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
2288 }
2289
2290
2291 void MainWindow::slotDeleteItem()
2292 {
2293     if (QApplication::focusWidget() &&
2294         QApplication::focusWidget()->parentWidget() &&
2295         QApplication::focusWidget()->parentWidget()->parentWidget() &&
2296         QApplication::focusWidget()->parentWidget()->parentWidget() == m_projectListDock) {
2297         m_projectList->slotRemoveClip();
2298
2299     } else {
2300         QWidget *widget = QApplication::focusWidget();
2301         while (widget) {
2302             if (widget == m_effectStackDock) {
2303                 m_effectStack->slotItemDel();
2304                 return;
2305             }
2306             widget = widget->parentWidget();
2307         }
2308
2309         // effect stack has no focus
2310         if (m_activeTimeline)
2311             m_activeTimeline->projectView()->deleteSelectedClips();
2312     }
2313 }
2314
2315 void MainWindow::slotUpdateClipMarkers(DocClipBase *clip)
2316 {
2317     if (m_clipMonitor->isActive())
2318         m_clipMonitor->checkOverlay();
2319     m_clipMonitor->updateMarkers(clip);
2320 }
2321
2322 void MainWindow::slotAddClipMarker()
2323 {
2324     DocClipBase *clip = NULL;
2325     GenTime pos;
2326     if (m_projectMonitor->isActive()) {
2327         if (m_activeTimeline) {
2328             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2329             if (item) {
2330                 pos = GenTime((int)((m_projectMonitor->position() - item->startPos() + item->cropStart()).frames(m_activeDocument->fps()) * item->speed() + 0.5), m_activeDocument->fps());
2331                 clip = item->baseClip();
2332             }
2333         }
2334     } else {
2335         clip = m_clipMonitor->activeClip();
2336         pos = m_clipMonitor->position();
2337     }
2338     if (!clip) {
2339         m_messageLabel->setMessage(i18n("Cannot find clip to add marker"), ErrorMessage);
2340         return;
2341     }
2342     QString id = clip->getId();
2343     CommentedTime marker(pos, i18n("Marker"));
2344     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Add Marker"), this);
2345     if (d.exec() == QDialog::Accepted)
2346         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
2347 }
2348
2349 void MainWindow::slotDeleteClipMarker()
2350 {
2351     DocClipBase *clip = NULL;
2352     GenTime pos;
2353     if (m_projectMonitor->isActive()) {
2354         if (m_activeTimeline) {
2355             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2356             if (item) {
2357                 pos = (m_projectMonitor->position() - item->startPos() + item->cropStart()) / item->speed();
2358                 clip = item->baseClip();
2359             }
2360         }
2361     } else {
2362         clip = m_clipMonitor->activeClip();
2363         pos = m_clipMonitor->position();
2364     }
2365     if (!clip) {
2366         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2367         return;
2368     }
2369
2370     QString id = clip->getId();
2371     QString comment = clip->markerComment(pos);
2372     if (comment.isEmpty()) {
2373         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
2374         return;
2375     }
2376     m_activeTimeline->projectView()->slotDeleteClipMarker(comment, id, pos);
2377 }
2378
2379 void MainWindow::slotDeleteAllClipMarkers()
2380 {
2381     DocClipBase *clip = NULL;
2382     if (m_projectMonitor->isActive()) {
2383         if (m_activeTimeline) {
2384             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2385             if (item) {
2386                 clip = item->baseClip();
2387             }
2388         }
2389     } else {
2390         clip = m_clipMonitor->activeClip();
2391     }
2392     if (!clip) {
2393         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2394         return;
2395     }
2396     m_activeTimeline->projectView()->slotDeleteAllClipMarkers(clip->getId());
2397 }
2398
2399 void MainWindow::slotEditClipMarker()
2400 {
2401     DocClipBase *clip = NULL;
2402     GenTime pos;
2403     if (m_projectMonitor->isActive()) {
2404         if (m_activeTimeline) {
2405             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2406             if (item) {
2407                 pos = (m_projectMonitor->position() - item->startPos() + item->cropStart()) / item->speed();
2408                 clip = item->baseClip();
2409             }
2410         }
2411     } else {
2412         clip = m_clipMonitor->activeClip();
2413         pos = m_clipMonitor->position();
2414     }
2415     if (!clip) {
2416         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2417         return;
2418     }
2419
2420     QString id = clip->getId();
2421     QString oldcomment = clip->markerComment(pos);
2422     if (oldcomment.isEmpty()) {
2423         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
2424         return;
2425     }
2426
2427     CommentedTime marker(pos, oldcomment);
2428     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Edit Marker"), this);
2429     if (d.exec() == QDialog::Accepted) {
2430         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
2431         if (d.newMarker().time() != pos) {
2432             // remove old marker
2433             m_activeTimeline->projectView()->slotAddClipMarker(id, pos, QString());
2434         }
2435     }
2436 }
2437
2438 void MainWindow::slotAddGuide()
2439 {
2440     if (m_activeTimeline)
2441         m_activeTimeline->projectView()->slotAddGuide();
2442 }
2443
2444 void MainWindow::slotInsertSpace()
2445 {
2446     if (m_activeTimeline)
2447         m_activeTimeline->projectView()->slotInsertSpace();
2448 }
2449
2450 void MainWindow::slotRemoveSpace()
2451 {
2452     if (m_activeTimeline)
2453         m_activeTimeline->projectView()->slotRemoveSpace();
2454 }
2455
2456 void MainWindow::slotInsertTrack(int ix)
2457 {
2458     m_projectMonitor->activateMonitor();
2459     if (m_activeTimeline)
2460         m_activeTimeline->projectView()->slotInsertTrack(ix);
2461     if (m_activeDocument)
2462         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
2463 }
2464
2465 void MainWindow::slotDeleteTrack(int ix)
2466 {
2467     m_projectMonitor->activateMonitor();
2468     if (m_activeTimeline)
2469         m_activeTimeline->projectView()->slotDeleteTrack(ix);
2470     if (m_activeDocument)
2471         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
2472 }
2473
2474 void MainWindow::slotConfigTrack(int ix)
2475 {
2476     m_projectMonitor->activateMonitor();
2477     if (m_activeTimeline)
2478         m_activeTimeline->projectView()->slotConfigTracks(ix);
2479     if (m_activeDocument)
2480         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
2481 }
2482
2483 void MainWindow::slotEditGuide()
2484 {
2485     if (m_activeTimeline)
2486         m_activeTimeline->projectView()->slotEditGuide();
2487 }
2488
2489 void MainWindow::slotDeleteGuide()
2490 {
2491     if (m_activeTimeline)
2492         m_activeTimeline->projectView()->slotDeleteGuide();
2493 }
2494
2495 void MainWindow::slotDeleteAllGuides()
2496 {
2497     if (m_activeTimeline)
2498         m_activeTimeline->projectView()->slotDeleteAllGuides();
2499 }
2500
2501 void MainWindow::slotCutTimelineClip()
2502 {
2503     if (m_activeTimeline)
2504         m_activeTimeline->projectView()->cutSelectedClips();
2505 }
2506
2507 void MainWindow::slotInsertClipOverwrite()
2508 {
2509     if (m_activeTimeline) {
2510         QStringList data = m_clipMonitor->getZoneInfo();
2511         m_activeTimeline->projectView()->insertZoneOverwrite(data, m_activeTimeline->inPoint());
2512     }
2513 }
2514
2515 void MainWindow::slotSelectTimelineClip()
2516 {
2517     if (m_activeTimeline)
2518         m_activeTimeline->projectView()->selectClip(true);
2519 }
2520
2521 void MainWindow::slotSelectTimelineTransition()
2522 {
2523     if (m_activeTimeline)
2524         m_activeTimeline->projectView()->selectTransition(true);
2525 }
2526
2527 void MainWindow::slotDeselectTimelineClip()
2528 {
2529     if (m_activeTimeline)
2530         m_activeTimeline->projectView()->selectClip(false, true);
2531 }
2532
2533 void MainWindow::slotDeselectTimelineTransition()
2534 {
2535     if (m_activeTimeline)
2536         m_activeTimeline->projectView()->selectTransition(false, true);
2537 }
2538
2539 void MainWindow::slotSelectAddTimelineClip()
2540 {
2541     if (m_activeTimeline)
2542         m_activeTimeline->projectView()->selectClip(true, true);
2543 }
2544
2545 void MainWindow::slotSelectAddTimelineTransition()
2546 {
2547     if (m_activeTimeline)
2548         m_activeTimeline->projectView()->selectTransition(true, true);
2549 }
2550
2551 void MainWindow::slotGroupClips()
2552 {
2553     if (m_activeTimeline)
2554         m_activeTimeline->projectView()->groupClips();
2555 }
2556
2557 void MainWindow::slotUnGroupClips()
2558 {
2559     if (m_activeTimeline)
2560         m_activeTimeline->projectView()->groupClips(false);
2561 }
2562
2563 void MainWindow::slotEditItemDuration()
2564 {
2565     if (m_activeTimeline)
2566         m_activeTimeline->projectView()->editItemDuration();
2567 }
2568
2569 void MainWindow::slotAddProjectClip(KUrl url)
2570 {
2571     if (m_activeDocument)
2572         m_activeDocument->slotAddClipFile(url, QString());
2573 }
2574
2575 void MainWindow::slotAddTransition(QAction *result)
2576 {
2577     if (!result) return;
2578     QStringList info = result->data().toStringList();
2579     if (info.isEmpty()) return;
2580     QDomElement transition = transitions.getEffectByTag(info.at(1), info.at(2));
2581     if (m_activeTimeline && !transition.isNull()) {
2582         m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(transition.cloneNode().toElement());
2583     }
2584 }
2585
2586 void MainWindow::slotAddVideoEffect(QAction *result)
2587 {
2588     if (!result) return;
2589     QStringList info = result->data().toStringList();
2590     if (info.isEmpty()) return;
2591     QDomElement effect = videoEffects.getEffectByTag(info.at(1), info.at(2));
2592     slotAddEffect(effect);
2593 }
2594
2595 void MainWindow::slotAddAudioEffect(QAction *result)
2596 {
2597     if (!result) return;
2598     QStringList info = result->data().toStringList();
2599     if (info.isEmpty()) return;
2600     QDomElement effect = audioEffects.getEffectByTag(info.at(1), info.at(2));
2601     slotAddEffect(effect);
2602 }
2603
2604 void MainWindow::slotAddCustomEffect(QAction *result)
2605 {
2606     if (!result) return;
2607     QStringList info = result->data().toStringList();
2608     if (info.isEmpty()) return;
2609     QDomElement effect = customEffects.getEffectByTag(info.at(1), info.at(2));
2610     slotAddEffect(effect);
2611 }
2612
2613 void MainWindow::slotZoomIn()
2614 {
2615     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
2616     slotShowZoomSliderToolTip();
2617 }
2618
2619 void MainWindow::slotZoomOut()
2620 {
2621     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
2622     slotShowZoomSliderToolTip();
2623 }
2624
2625 void MainWindow::slotFitZoom()
2626 {
2627     if (m_activeTimeline)
2628         m_zoomSlider->setValue(m_activeTimeline->fitZoom());
2629 }
2630
2631 void MainWindow::slotSetZoom(int value)
2632 {
2633     if (m_activeTimeline)
2634         m_activeTimeline->slotChangeZoom(value);
2635
2636     m_zoomOut->setEnabled(value < m_zoomSlider->maximum());
2637     m_zoomIn->setEnabled(value > m_zoomSlider->minimum());
2638     slotUpdateZoomSliderToolTip(value);
2639
2640     m_zoomSlider->blockSignals(true);
2641     m_zoomSlider->setValue(value);
2642     m_zoomSlider->blockSignals(false);
2643 }
2644
2645 void MainWindow::slotShowZoomSliderToolTip(int zoomlevel)
2646 {
2647     if (zoomlevel != -1)
2648         slotUpdateZoomSliderToolTip(zoomlevel);
2649
2650     QPoint global = m_zoomSlider->rect().topLeft();
2651     global.ry() += m_zoomSlider->height() / 2;
2652     QHelpEvent toolTipEvent(QEvent::ToolTip, QPoint(0, 0), m_zoomSlider->mapToGlobal(global));
2653     QApplication::sendEvent(m_zoomSlider, &toolTipEvent);
2654 }
2655
2656 void MainWindow::slotUpdateZoomSliderToolTip(int zoomlevel)
2657 {
2658     m_zoomSlider->setToolTip(i18n("Zoom Level: %1/13", (13 - zoomlevel)));
2659 }
2660
2661 void MainWindow::slotGotProgressInfo(const QString &message, int progress)
2662 {
2663     m_statusProgressBar->setValue(progress);
2664     if (progress >= 0) {
2665         if (!message.isEmpty())
2666             m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
2667         m_statusProgressBar->setVisible(true);
2668     } else if (progress == -2) {
2669         if (!message.isEmpty())
2670             m_messageLabel->setMessage(message, ErrorMessage);
2671         m_statusProgressBar->setVisible(false);
2672     } else {
2673         m_messageLabel->setMessage(QString(), DefaultMessage);
2674         m_statusProgressBar->setVisible(false);
2675     }
2676 }
2677
2678 void MainWindow::slotShowClipProperties(DocClipBase *clip)
2679 {
2680     if (clip->clipType() == TEXT) {
2681         QString titlepath = m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
2682         if (!clip->getProperty("resource").isEmpty() && clip->getProperty("xmldata").isEmpty()) {
2683             // template text clip
2684
2685             // Get the list of existing templates
2686             QStringList filter;
2687             filter << "*.kdenlivetitle";
2688             QStringList templateFiles = QDir(titlepath).entryList(filter, QDir::Files);
2689
2690             QDialog *dia = new QDialog(this);
2691             Ui::TemplateClip_UI dia_ui;
2692             dia_ui.setupUi(dia);
2693             int ix = -1;
2694             const QString templatePath = clip->getProperty("resource");
2695             for (int i = 0; i < templateFiles.size(); ++i) {
2696                 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), titlepath + templateFiles.at(i));
2697                 if (templatePath == KUrl(titlepath + templateFiles.at(i)).path()) ix = i;
2698             }
2699             if (ix != -1) dia_ui.template_list->comboBox()->setCurrentIndex(ix);
2700             else dia_ui.template_list->comboBox()->insertItem(0, templatePath);
2701             dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
2702             //warning: setting base directory doesn't work??
2703             KUrl startDir(titlepath);
2704             dia_ui.template_list->fileDialog()->setUrl(startDir);
2705             dia_ui.description->setText(clip->getProperty("description"));
2706             if (dia->exec() == QDialog::Accepted) {
2707                 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
2708                 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
2709
2710                 QMap <QString, QString> newprops;
2711
2712                 if (KUrl(textTemplate).path() != templatePath) {
2713                     // The template was changed
2714                     newprops.insert("resource", textTemplate);
2715                 }
2716
2717                 if (dia_ui.description->toPlainText() != clip->getProperty("description")) {
2718                     newprops.insert("description", dia_ui.description->toPlainText());
2719                 }
2720
2721                 QString newtemplate = newprops.value("xmltemplate");
2722                 if (newtemplate.isEmpty()) newtemplate = templatePath;
2723
2724                 // template modified we need to update xmldata
2725                 QString description = newprops.value("description");
2726                 if (description.isEmpty()) description = clip->getProperty("description");
2727                 else newprops.insert("templatetext", description);
2728                 //newprops.insert("xmldata", m_projectList->generateTemplateXml(newtemplate, description).toString());
2729                 if (!newprops.isEmpty()) {
2730                     EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
2731                     m_activeDocument->commandStack()->push(command);
2732                 }
2733             }
2734             delete dia;
2735             return;
2736         }
2737         QString path = clip->getProperty("resource");
2738         TitleWidget *dia_ui = new TitleWidget(KUrl(), m_activeDocument->timecode(), titlepath, m_projectMonitor->render, this);
2739         QDomDocument doc;
2740         doc.setContent(clip->getProperty("xmldata"));
2741         dia_ui->setXml(doc);
2742         if (dia_ui->exec() == QDialog::Accepted) {
2743             QMap <QString, QString> newprops;
2744             newprops.insert("xmldata", dia_ui->xml().toString());
2745             if (dia_ui->outPoint() != clip->duration().frames(m_activeDocument->fps()) - 1) {
2746                 // duration changed, we need to update duration
2747                 newprops.insert("out", QString::number(dia_ui->outPoint()));
2748             }
2749             EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
2750             m_activeDocument->commandStack()->push(command);
2751             //m_activeTimeline->projectView()->slotUpdateClip(clip->getId());
2752             m_activeDocument->setModified(true);
2753         }
2754         delete dia_ui;
2755
2756         //m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
2757         return;
2758     }
2759     ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
2760     connect(&dia, SIGNAL(addMarker(const QString &, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(const QString &, GenTime, QString)));
2761     if (dia.exec() == QDialog::Accepted) {
2762         QMap <QString, QString> newprops = dia.properties();
2763         if (newprops.isEmpty()) return;
2764         EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
2765         m_activeDocument->commandStack()->push(command);
2766
2767         if (dia.needsTimelineRefresh()) {
2768             // update clip occurences in timeline
2769             m_activeTimeline->projectView()->slotUpdateClip(clip->getId(), dia.needsTimelineReload());
2770         }
2771     }
2772 }
2773
2774
2775 void MainWindow::slotShowClipProperties(QList <DocClipBase *> cliplist, QMap<QString, QString> commonproperties)
2776 {
2777     ClipProperties dia(cliplist, m_activeDocument->timecode(), commonproperties, this);
2778     if (dia.exec() == QDialog::Accepted) {
2779         QUndoCommand *command = new QUndoCommand();
2780         command->setText(i18n("Edit clips"));
2781         for (int i = 0; i < cliplist.count(); i++) {
2782             DocClipBase *clip = cliplist.at(i);
2783             new EditClipCommand(m_projectList, clip->getId(), clip->properties(), dia.properties(), true, command);
2784         }
2785         m_activeDocument->commandStack()->push(command);
2786         for (int i = 0; i < cliplist.count(); i++)
2787             m_activeTimeline->projectView()->slotUpdateClip(cliplist.at(i)->getId(), dia.needsTimelineReload());
2788     }
2789 }
2790
2791 void MainWindow::customEvent(QEvent* e)
2792 {
2793     if (e->type() == QEvent::User)
2794         m_messageLabel->setMessage(static_cast <MltErrorEvent *>(e)->message(), MltError);
2795 }
2796 void MainWindow::slotActivateEffectStackView()
2797 {
2798     m_effectStack->raiseWindow(m_effectStackDock);
2799 }
2800
2801 void MainWindow::slotActivateTransitionView(Transition *t)
2802 {
2803     if (t)
2804         m_transitionConfig->raiseWindow(m_transitionConfigDock);
2805 }
2806
2807 void MainWindow::slotSnapRewind()
2808 {
2809     if (m_projectMonitor->isActive()) {
2810         if (m_activeTimeline)
2811             m_activeTimeline->projectView()->slotSeekToPreviousSnap();
2812     } else  {
2813         m_clipMonitor->slotSeekToPreviousSnap();
2814     }
2815 }
2816
2817 void MainWindow::slotSnapForward()
2818 {
2819     if (m_projectMonitor->isActive()) {
2820         if (m_activeTimeline)
2821             m_activeTimeline->projectView()->slotSeekToNextSnap();
2822     } else {
2823         m_clipMonitor->slotSeekToNextSnap();
2824     }
2825 }
2826
2827 void MainWindow::slotClipStart()
2828 {
2829     if (m_projectMonitor->isActive()) {
2830         if (m_activeTimeline)
2831             m_activeTimeline->projectView()->clipStart();
2832     }
2833 }
2834
2835 void MainWindow::slotClipEnd()
2836 {
2837     if (m_projectMonitor->isActive()) {
2838         if (m_activeTimeline)
2839             m_activeTimeline->projectView()->clipEnd();
2840     }
2841 }
2842
2843 void MainWindow::slotZoneStart()
2844 {
2845     if (m_projectMonitor->isActive())
2846         m_projectMonitor->slotZoneStart();
2847     else
2848         m_clipMonitor->slotZoneStart();
2849 }
2850
2851 void MainWindow::slotZoneEnd()
2852 {
2853     if (m_projectMonitor->isActive())
2854         m_projectMonitor->slotZoneEnd();
2855     else
2856         m_clipMonitor->slotZoneEnd();
2857 }
2858
2859 void MainWindow::slotChangeTool(QAction * action)
2860 {
2861     if (action == m_buttonSelectTool)
2862         slotSetTool(SELECTTOOL);
2863     else if (action == m_buttonRazorTool)
2864         slotSetTool(RAZORTOOL);
2865     else if (action == m_buttonSpacerTool)
2866         slotSetTool(SPACERTOOL);
2867 }
2868
2869 void MainWindow::slotChangeEdit(QAction * action)
2870 {
2871     if (!m_activeTimeline)
2872         return;
2873
2874     if (action == m_overwriteEditTool)
2875         m_activeTimeline->projectView()->setEditMode(OVERWRITEEDIT);
2876     else if (action == m_insertEditTool)
2877         m_activeTimeline->projectView()->setEditMode(INSERTEDIT);
2878     else
2879         m_activeTimeline->projectView()->setEditMode(NORMALEDIT);
2880 }
2881
2882 void MainWindow::slotSetTool(PROJECTTOOL tool)
2883 {
2884     if (m_activeDocument && m_activeTimeline) {
2885         //m_activeDocument->setTool(tool);
2886         QString message;
2887         switch (tool)  {
2888         case SPACERTOOL:
2889             message = i18n("Ctrl + click to use spacer on current track only");
2890             break;
2891         case RAZORTOOL:
2892             message = i18n("Click on a clip to cut it");
2893             break;
2894         default:
2895             message = i18n("Shift + click to create a selection rectangle, Ctrl + click to add an item to selection");
2896             break;
2897         }
2898         m_messageLabel->setMessage(message, InformationMessage);
2899         m_activeTimeline->projectView()->setTool(tool);
2900     }
2901 }
2902
2903 void MainWindow::slotCopy()
2904 {
2905     if (m_activeDocument && m_activeTimeline)
2906         m_activeTimeline->projectView()->copyClip();
2907 }
2908
2909 void MainWindow::slotPaste()
2910 {
2911     if (m_activeDocument && m_activeTimeline)
2912         m_activeTimeline->projectView()->pasteClip();
2913 }
2914
2915 void MainWindow::slotPasteEffects()
2916 {
2917     if (m_activeDocument && m_activeTimeline)
2918         m_activeTimeline->projectView()->pasteClipEffects();
2919 }
2920
2921 void MainWindow::slotFind()
2922 {
2923     if (!m_activeDocument || !m_activeTimeline) return;
2924     m_projectSearch->setEnabled(false);
2925     m_findActivated = true;
2926     m_findString.clear();
2927     m_activeTimeline->projectView()->initSearchStrings();
2928     statusBar()->showMessage(i18n("Starting -- find text as you type"));
2929     m_findTimer.start(5000);
2930     qApp->installEventFilter(this);
2931 }
2932
2933 void MainWindow::slotFindNext()
2934 {
2935     if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString))
2936         statusBar()->showMessage(i18n("Found: %1", m_findString));
2937     else
2938         statusBar()->showMessage(i18n("Reached end of project"));
2939     m_findTimer.start(4000);
2940 }
2941
2942 void MainWindow::findAhead()
2943 {
2944     if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
2945         m_projectSearchNext->setEnabled(true);
2946         statusBar()->showMessage(i18n("Found: %1", m_findString));
2947     } else {
2948         m_projectSearchNext->setEnabled(false);
2949         statusBar()->showMessage(i18n("Not found: %1", m_findString));
2950     }
2951 }
2952
2953 void MainWindow::findTimeout()
2954 {
2955     m_projectSearchNext->setEnabled(false);
2956     m_findActivated = false;
2957     m_findString.clear();
2958     statusBar()->showMessage(i18n("Find stopped"), 3000);
2959     if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
2960     m_projectSearch->setEnabled(true);
2961     removeEventFilter(this);
2962 }
2963
2964 void MainWindow::slotClipInTimeline(const QString &clipId)
2965 {
2966     if (m_activeTimeline && m_activeDocument) {
2967         QList<ItemInfo> matching = m_activeTimeline->projectView()->findId(clipId);
2968
2969         QMenu *inTimelineMenu = static_cast<QMenu*>(factory()->container("clip_in_timeline", this));
2970         inTimelineMenu->clear();
2971
2972         QList <QAction *> actionList;
2973
2974         for (int i = 0; i < matching.count(); ++i) {
2975             QString track = QString::number(matching.at(i).track);
2976             QString start = m_activeDocument->timecode().getTimecode(matching.at(i).startPos);
2977             int j = 0;
2978             QAction *a = new QAction(track + ": " + start, this);
2979             a->setData(QStringList() << track << start);
2980             connect(a, SIGNAL(triggered()), this, SLOT(slotSelectClipInTimeline()));
2981             while (j < actionList.count()) {
2982                 if (actionList.at(j)->text() > a->text()) break;
2983                 j++;
2984             }
2985             actionList.insert(j, a);
2986         }
2987         inTimelineMenu->addActions(actionList);
2988
2989         if (matching.empty())
2990             inTimelineMenu->setEnabled(false);
2991         else
2992             inTimelineMenu->setEnabled(true);
2993     }
2994 }
2995
2996 void MainWindow::slotClipInProjectTree()
2997 {
2998     if (m_activeTimeline) {
2999         const QStringList &clipIds = m_activeTimeline->projectView()->selectedClips();
3000         if (clipIds.isEmpty())
3001             return;
3002         m_projectListDock->raise();
3003         for (int i = 0; i < clipIds.count(); i++)
3004             m_projectList->selectItemById(clipIds.at(i));
3005         if (m_projectMonitor->isActive())
3006             slotSwitchMonitors();
3007     }
3008 }
3009
3010 /*void MainWindow::slotClipToProjectTree()
3011 {
3012     if (m_activeTimeline) {
3013     const QList<ClipItem *> clips =  m_activeTimeline->projectView()->selectedClipItems();
3014         if (clips.isEmpty()) return;
3015         for (int i = 0; i < clips.count(); i++) {
3016         m_projectList->slotAddXmlClip(clips.at(i)->itemXml());
3017         }
3018         //m_projectList->selectItemById(clipIds.at(i));
3019     }
3020 }*/
3021
3022 void MainWindow::slotSelectClipInTimeline()
3023 {
3024     if (m_activeTimeline) {
3025         QAction *action = qobject_cast<QAction *>(sender());
3026         QStringList data = action->data().toStringList();
3027         m_activeTimeline->projectView()->selectFound(data.at(0), data.at(1));
3028     }
3029 }
3030
3031 void MainWindow::keyPressEvent(QKeyEvent *ke)
3032 {
3033     if (m_findActivated) {
3034         if (ke->key() == Qt::Key_Backspace) {
3035             m_findString = m_findString.left(m_findString.length() - 1);
3036
3037             if (!m_findString.isEmpty())
3038                 findAhead();
3039             else
3040                 findTimeout();
3041
3042             m_findTimer.start(4000);
3043             ke->accept();
3044             return;
3045         } else if (ke->key() == Qt::Key_Escape) {
3046             findTimeout();
3047             ke->accept();
3048             return;
3049         } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
3050             m_findString += ke->text();
3051
3052             findAhead();
3053
3054             m_findTimer.start(4000);
3055             ke->accept();
3056             return;
3057         }
3058     } else {
3059         KXmlGuiWindow::keyPressEvent(ke);
3060     }
3061 }
3062
3063
3064 /** Gets called when the window gets hidden */
3065 void MainWindow::hideEvent(QHideEvent */*event*/)
3066 {
3067     if (isMinimized())
3068         if (m_monitorManager)
3069             m_monitorManager->stopActiveMonitor();
3070 }
3071
3072 bool MainWindow::eventFilter(QObject *obj, QEvent *event)
3073 {
3074     if (m_findActivated) {
3075         if (event->type() == QEvent::ShortcutOverride) {
3076             QKeyEvent* ke = (QKeyEvent*) event;
3077             if (ke->text().trimmed().isEmpty()) return false;
3078             ke->accept();
3079             return true;
3080         } else {
3081             return false;
3082         }
3083     } else {
3084         // pass the event on to the parent class
3085         return QMainWindow::eventFilter(obj, event);
3086     }
3087 }
3088
3089
3090 void MainWindow::slotSaveZone(Render *render, QPoint zone)
3091 {
3092     KDialog *dialog = new KDialog(this);
3093     dialog->setCaption("Save clip zone");
3094     dialog->setButtons(KDialog::Ok | KDialog::Cancel);
3095
3096     QWidget *widget = new QWidget(dialog);
3097     dialog->setMainWidget(widget);
3098
3099     QVBoxLayout *vbox = new QVBoxLayout(widget);
3100     QLabel *label1 = new QLabel(i18n("Save clip zone as:"), this);
3101     QString path = m_activeDocument->projectFolder().path();
3102     path.append("/");
3103     path.append("untitled.mlt");
3104     KUrlRequester *url = new KUrlRequester(KUrl(path), this);
3105     url->setFilter("video/mlt-playlist");
3106     QLabel *label2 = new QLabel(i18n("Description:"), this);
3107     KLineEdit *edit = new KLineEdit(this);
3108     vbox->addWidget(label1);
3109     vbox->addWidget(url);
3110     vbox->addWidget(label2);
3111     vbox->addWidget(edit);
3112     if (dialog->exec() == QDialog::Accepted)
3113         render->saveZone(url->url(), edit->text(), zone);
3114
3115 }
3116
3117 void MainWindow::slotSetInPoint()
3118 {
3119     if (m_clipMonitor->isActive())
3120         m_clipMonitor->slotSetZoneStart();
3121     else
3122         m_projectMonitor->slotSetZoneStart();
3123     //else m_activeTimeline->projectView()->setInPoint();
3124 }
3125
3126 void MainWindow::slotSetOutPoint()
3127 {
3128     if (m_clipMonitor->isActive())
3129         m_clipMonitor->slotSetZoneEnd();
3130     else
3131         m_projectMonitor->slotSetZoneEnd();
3132     // else m_activeTimeline->projectView()->setOutPoint();
3133 }
3134
3135 void MainWindow::slotResizeItemStart()
3136 {
3137     if (m_activeTimeline)
3138         m_activeTimeline->projectView()->setInPoint();
3139 }
3140
3141 void MainWindow::slotResizeItemEnd()
3142 {
3143     if (m_activeTimeline)
3144         m_activeTimeline->projectView()->setOutPoint();
3145 }
3146
3147 int MainWindow::getNewStuff(const QString &configFile)
3148 {
3149     KNS3::Entry::List entries;
3150 #if KDE_IS_VERSION(4,3,80)
3151     KNS3::DownloadDialog dialog(configFile);
3152     dialog.exec();
3153     entries = dialog.changedEntries();
3154     foreach(const KNS3::Entry &entry, entries) {
3155         if (entry.status() == KNS3::Entry::Installed)
3156             kDebug() << "// Installed files: " << entry.installedFiles();
3157     }
3158 #else
3159     KNS::Engine engine(0);
3160     if (engine.init(configFile))
3161         entries = engine.downloadDialogModal(this);
3162     foreach(KNS::Entry *entry, entries) {
3163         if (entry->status() == KNS::Entry::Installed)
3164             kDebug() << "// Installed files: " << entry->installedFiles();
3165     }
3166 #endif /* KDE_IS_VERSION(4,3,80) */
3167     return entries.size();
3168 }
3169
3170 void MainWindow::slotGetNewTitleStuff()
3171 {
3172     if (getNewStuff("kdenlive_titles.knsrc") > 0)
3173         TitleWidget::refreshTitleTemplates();
3174 }
3175
3176 void MainWindow::slotGetNewLumaStuff()
3177 {
3178     if (getNewStuff("kdenlive_wipes.knsrc") > 0) {
3179         initEffects::refreshLumas();
3180         m_activeTimeline->projectView()->reloadTransitionLumas();
3181     }
3182 }
3183
3184 void MainWindow::slotGetNewRenderStuff()
3185 {
3186     if (getNewStuff("kdenlive_renderprofiles.knsrc") > 0)
3187         if (m_renderWidget)
3188             m_renderWidget->reloadProfiles();
3189 }
3190
3191 void MainWindow::slotGetNewMltProfileStuff()
3192 {
3193     if (getNewStuff("kdenlive_projectprofiles.knsrc") > 0) {
3194         // update the list of profiles in settings dialog
3195         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
3196         if (d)
3197             d->checkProfile();
3198     }
3199 }
3200
3201 void MainWindow::slotAutoTransition()
3202 {
3203     if (m_activeTimeline)
3204         m_activeTimeline->projectView()->autoTransition();
3205 }
3206
3207 void MainWindow::slotSplitAudio()
3208 {
3209     if (m_activeTimeline)
3210         m_activeTimeline->projectView()->splitAudio();
3211 }
3212
3213 void MainWindow::slotUpdateClipType(QAction *action)
3214 {
3215     if (m_activeTimeline) {
3216         if (action->data().toString() == "clip_audio_only") m_activeTimeline->projectView()->setAudioOnly();
3217         else if (action->data().toString() == "clip_video_only") m_activeTimeline->projectView()->setVideoOnly();
3218         else m_activeTimeline->projectView()->setAudioAndVideo();
3219     }
3220 }
3221
3222 void MainWindow::slotDvdWizard(const QString &url, const QString &profile)
3223 {
3224     // We must stop the monitors since we create a new on in the dvd wizard
3225     m_clipMonitor->stop();
3226     m_projectMonitor->stop();
3227     DvdWizard w(url, profile, this);
3228     w.exec();
3229     m_projectMonitor->start();
3230 }
3231
3232 void MainWindow::slotShowTimeline(bool show)
3233 {
3234     if (show == false) {
3235         m_timelineState = saveState();
3236         centralWidget()->setHidden(true);
3237     } else {
3238         centralWidget()->setHidden(false);
3239         restoreState(m_timelineState);
3240     }
3241 }
3242
3243 void MainWindow::slotMaximizeCurrent(bool /*show*/)
3244 {
3245     //TODO: is there a way to maximize current widget?
3246     //if (show == true)
3247     {
3248         m_timelineState = saveState();
3249         QWidget *par = focusWidget()->parentWidget();
3250         while (par->parentWidget() && par->parentWidget() != this)
3251             par = par->parentWidget();
3252         kDebug() << "CURRENT WIDGET: " << par->objectName();
3253     }
3254     /*else {
3255     //centralWidget()->setHidden(false);
3256     //restoreState(m_timelineState);
3257     }*/
3258 }
3259
3260 void MainWindow::loadTranscoders()
3261 {
3262     QMenu *transMenu = static_cast<QMenu*>(factory()->container("transcoders", this));
3263     transMenu->clear();
3264
3265     KSharedConfigPtr config = KSharedConfig::openConfig("kdenlivetranscodingrc");
3266     KConfigGroup transConfig(config, "Transcoding");
3267     // read the entries
3268     QMap< QString, QString > profiles = transConfig.entryMap();
3269     QMapIterator<QString, QString> i(profiles);
3270     while (i.hasNext()) {
3271         i.next();
3272         QStringList data = i.value().split(";", QString::SkipEmptyParts);
3273         QAction *a = transMenu->addAction(i.key());
3274         a->setData(data);
3275         if (data.count() > 1)
3276             a->setToolTip(data.at(1));
3277         connect(a, SIGNAL(triggered()), this, SLOT(slotTranscode()));
3278     }
3279 }
3280
3281 void MainWindow::slotTranscode(KUrl::List urls)
3282 {
3283     QString params;
3284     QString desc;
3285     QString condition;
3286     if (urls.isEmpty()) {
3287         QAction *action = qobject_cast<QAction *>(sender());
3288         QStringList data = action->data().toStringList();
3289         params = data.at(0);
3290         if (data.count() > 1) desc = data.at(1);
3291         if (data.count() > 2) condition = data.at(2);
3292         urls << m_projectList->getConditionalUrls(condition);
3293         urls.removeAll(KUrl());
3294     }
3295     if (urls.isEmpty()) {
3296         m_messageLabel->setMessage(i18n("No clip to transcode"), ErrorMessage);
3297         return;
3298     }
3299     ClipTranscode *d = new ClipTranscode(urls, params, desc);
3300     connect(d, SIGNAL(addClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
3301     d->show();
3302     //QProcess::startDetached("ffmpeg", parameters);
3303 }
3304
3305 void MainWindow::slotTranscodeClip()
3306 {
3307     KUrl::List urls = KFileDialog::getOpenUrls(KUrl("kfiledialog:///projectfolder"));
3308     if (urls.isEmpty()) return;
3309     slotTranscode(urls);
3310 }
3311
3312 void MainWindow::slotSetDocumentRenderProfile(const QString &dest, const QString &group, const QString &name, const QString &file)
3313 {
3314     if (m_activeDocument == NULL) return;
3315     m_activeDocument->setDocumentProperty("renderdestination", dest);
3316     m_activeDocument->setDocumentProperty("rendercategory", group);
3317     m_activeDocument->setDocumentProperty("renderprofile", name);
3318     m_activeDocument->setDocumentProperty("renderurl", file);
3319     m_activeDocument->setModified(true);
3320 }
3321
3322
3323 void MainWindow::slotPrepareRendering(bool scriptExport, bool zoneOnly, const QString &chapterFile)
3324 {
3325     if (m_activeDocument == NULL || m_renderWidget == NULL) return;
3326     QString scriptPath;
3327     QString playlistPath;
3328     if (scriptExport) {
3329         bool ok;
3330         QString scriptsFolder = m_activeDocument->projectFolder().path() + "/scripts/";
3331         QString path = m_renderWidget->getFreeScriptName();
3332         scriptPath = QInputDialog::getText(this, i18n("Create Render Script"), i18n("Script name (will be saved in: %1)", scriptsFolder), QLineEdit::Normal, KUrl(path).fileName(), &ok);
3333         if (!ok || scriptPath.isEmpty()) return;
3334         scriptPath.prepend(scriptsFolder);
3335         QFile f(scriptPath);
3336         if (f.exists()) {
3337             if (KMessageBox::warningYesNo(this, i18n("Script file already exists. Do you want to overwrite it?")) != KMessageBox::Yes)
3338                 return;
3339         }
3340         playlistPath = scriptPath + ".mlt";
3341         m_projectMonitor->saveSceneList(playlistPath);
3342     } else {
3343         KTemporaryFile temp;
3344         temp.setAutoRemove(false);
3345         temp.setSuffix(".mlt");
3346         temp.open();
3347         playlistPath = temp.fileName();
3348         m_projectMonitor->saveSceneList(playlistPath);
3349     }
3350
3351     if (!chapterFile.isEmpty()) {
3352         int in = 0;
3353         int out;
3354         if (!zoneOnly) out = (int) GenTime(m_activeDocument->projectDuration()).frames(m_activeDocument->fps());
3355         else {
3356             in = m_activeTimeline->inPoint();
3357             out = m_activeTimeline->outPoint();
3358         }
3359         QDomDocument doc;
3360         QDomElement chapters = doc.createElement("chapters");
3361         chapters.setAttribute("fps", m_activeDocument->fps());
3362         doc.appendChild(chapters);
3363
3364         QDomElement guidesxml = m_activeDocument->guidesXml();
3365         QDomNodeList nodes = guidesxml.elementsByTagName("guide");
3366         for (int i = 0; i < nodes.count(); i++) {
3367             QDomElement e = nodes.item(i).toElement();
3368             if (!e.isNull()) {
3369                 QString comment = e.attribute("comment");
3370                 int time = (int) GenTime(e.attribute("time").toDouble()).frames(m_activeDocument->fps());
3371                 if (time >= in && time < out) {
3372                     if (zoneOnly) time = time - in;
3373                     QDomElement chapter = doc.createElement("chapter");
3374                     chapters.appendChild(chapter);
3375                     chapter.setAttribute("title", comment);
3376                     chapter.setAttribute("time", time);
3377                 }
3378             }
3379         }
3380         if (chapters.childNodes().count() > 0) {
3381             if (m_activeTimeline->projectView()->hasGuide(out, 0) == -1) {
3382                 // Always insert a guide in pos 0
3383                 QDomElement chapter = doc.createElement("chapter");
3384                 chapters.insertBefore(chapter, QDomNode());
3385                 chapter.setAttribute("title", i18n("Start"));
3386                 chapter.setAttribute("time", "0");
3387             }
3388             // save chapters file
3389             QFile file(chapterFile);
3390             if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
3391                 kWarning() << "//////  ERROR writing DVD CHAPTER file: " << chapterFile;
3392             } else {
3393                 file.write(doc.toString().toUtf8());
3394                 if (file.error() != QFile::NoError) {
3395                     kWarning() << "//////  ERROR writing DVD CHAPTER file: " << chapterFile;
3396                 }
3397                 file.close();
3398             }
3399         }
3400     }
3401
3402     m_renderWidget->slotExport(scriptExport, m_activeTimeline->inPoint(), m_activeTimeline->outPoint(), playlistPath, scriptPath);
3403 }
3404
3405 void MainWindow::slotUpdateTimecodeFormat(int ix)
3406 {
3407     KdenliveSettings::setFrametimecode(ix == 1);
3408     m_clipMonitor->updateTimecodeFormat();
3409     m_projectMonitor->updateTimecodeFormat();
3410     m_transitionConfig->updateTimecodeFormat();
3411     m_effectStack->updateTimecodeFormat();
3412     //m_activeTimeline->projectView()->clearSelection();
3413     m_activeTimeline->updateRuler();
3414 }
3415
3416 void MainWindow::slotRemoveFocus()
3417 {
3418     statusBar()->setFocus();
3419     statusBar()->clearFocus();
3420 }
3421
3422 void MainWindow::slotRevert()
3423 {
3424     if (KMessageBox::warningContinueCancel(this, i18n("This will delete all changes made since you last saved your project. Are you sure you want to continue?"), i18n("Revert to last saved version")) == KMessageBox::Cancel) return;
3425     KUrl url = m_activeDocument->url();
3426     closeCurrentDocument(false);
3427     doOpenFile(url, NULL);
3428 }
3429
3430
3431 void MainWindow::slotShutdown()
3432 {
3433     if (m_activeDocument) m_activeDocument->setModified(false);
3434     // Call shutdown
3435     QDBusConnectionInterface* interface = QDBusConnection::sessionBus().interface();
3436     if (interface && interface->isServiceRegistered("org.kde.ksmserver")) {
3437         QDBusInterface smserver("org.kde.ksmserver", "/KSMServer", "org.kde.KSMServerInterface");
3438         smserver.call("logout", 1, 2, 2);
3439     } else if (interface && interface->isServiceRegistered("org.gnome.SessionManager")) {
3440         QDBusInterface smserver("org.gnome.SessionManager", "/org/gnome/SessionManager", "org.gnome.SessionManager");
3441         smserver.call("Shutdown");
3442     }
3443 }
3444
3445 void MainWindow::slotUpdateTrackInfo()
3446 {
3447     if (m_activeDocument)
3448         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
3449 }
3450
3451 void MainWindow::slotChangePalette(QAction *action, const QString &themename)
3452 {
3453     // Load the theme file
3454     QString theme;
3455     if (action == NULL) theme = themename;
3456     else theme = action->data().toString();
3457     KdenliveSettings::setColortheme(theme);
3458     // Make palette for all widgets.
3459     QPalette plt;
3460     if (theme.isEmpty())
3461         plt = QApplication::desktop()->palette();
3462     else {
3463         KSharedConfigPtr config = KSharedConfig::openConfig(theme);
3464         plt = KGlobalSettings::createApplicationPalette(config);
3465     }
3466
3467     kapp->setPalette(plt);
3468     const QObjectList children = statusBar()->children();
3469
3470     foreach(QObject *child, children) {
3471         if (child->isWidgetType())
3472             ((QWidget*)child)->setPalette(plt);
3473         const QObjectList subchildren = child->children();
3474         foreach(QObject *subchild, subchildren) {
3475             if (subchild->isWidgetType())
3476                 ((QWidget*)subchild)->setPalette(plt);
3477         }
3478     }
3479     if (m_activeTimeline)
3480         m_activeTimeline->projectView()->updatePalette();
3481 }
3482
3483
3484 QPixmap MainWindow::createSchemePreviewIcon(const KSharedConfigPtr &config)
3485 {
3486     // code taken from kdebase/workspace/kcontrol/colors/colorscm.cpp
3487     const uchar bits1[] = { 0xff, 0xff, 0xff, 0x2c, 0x16, 0x0b };
3488     const uchar bits2[] = { 0x68, 0x34, 0x1a, 0xff, 0xff, 0xff };
3489     const QSize bitsSize(24, 2);
3490     const QBitmap b1 = QBitmap::fromData(bitsSize, bits1);
3491     const QBitmap b2 = QBitmap::fromData(bitsSize, bits2);
3492
3493     QPixmap pixmap(23, 16);
3494     pixmap.fill(Qt::black); // ### use some color other than black for borders?
3495
3496     KConfigGroup group(config, "WM");
3497     QPainter p(&pixmap);
3498     KColorScheme windowScheme(QPalette::Active, KColorScheme::Window, config);
3499     p.fillRect(1,  1, 7, 7, windowScheme.background());
3500     p.fillRect(2,  2, 5, 2, QBrush(windowScheme.foreground().color(), b1));
3501
3502     KColorScheme buttonScheme(QPalette::Active, KColorScheme::Button, config);
3503     p.fillRect(8,  1, 7, 7, buttonScheme.background());
3504     p.fillRect(9,  2, 5, 2, QBrush(buttonScheme.foreground().color(), b1));
3505
3506     p.fillRect(15,  1, 7, 7, group.readEntry("activeBackground", QColor(96, 148, 207)));
3507     p.fillRect(16,  2, 5, 2, QBrush(group.readEntry("activeForeground", QColor(255, 255, 255)), b1));
3508
3509     KColorScheme viewScheme(QPalette::Active, KColorScheme::View, config);
3510     p.fillRect(1,  8, 7, 7, viewScheme.background());
3511     p.fillRect(2, 12, 5, 2, QBrush(viewScheme.foreground().color(), b2));
3512
3513     KColorScheme selectionScheme(QPalette::Active, KColorScheme::Selection, config);
3514     p.fillRect(8,  8, 7, 7, selectionScheme.background());
3515     p.fillRect(9, 12, 5, 2, QBrush(selectionScheme.foreground().color(), b2));
3516
3517     p.fillRect(15,  8, 7, 7, group.readEntry("inactiveBackground", QColor(224, 223, 222)));
3518     p.fillRect(16, 12, 5, 2, QBrush(group.readEntry("inactiveForeground", QColor(20, 19, 18)), b2));
3519
3520     p.end();
3521     return pixmap;
3522 }
3523
3524 void MainWindow::slotSwitchMonitors()
3525 {
3526     m_monitorManager->slotSwitchMonitors(!m_clipMonitor->isActive());
3527     if (m_projectMonitor->isActive()) m_activeTimeline->projectView()->setFocus();
3528     else m_projectList->focusTree();
3529 }
3530
3531 void MainWindow::slotInsertZoneToTree()
3532 {
3533     if (!m_clipMonitor->isActive() || m_clipMonitor->activeClip() == NULL) return;
3534     QStringList info = m_clipMonitor->getZoneInfo();
3535     m_projectList->slotAddClipCut(info.at(0), info.at(1).toInt(), info.at(2).toInt());
3536 }
3537
3538 void MainWindow::slotInsertZoneToTimeline()
3539 {
3540     if (m_activeTimeline == NULL || m_clipMonitor->activeClip() == NULL) return;
3541     QStringList info = m_clipMonitor->getZoneInfo();
3542     m_activeTimeline->projectView()->insertClipCut(m_clipMonitor->activeClip(), info.at(1).toInt(), info.at(2).toInt());
3543 }
3544
3545
3546 void MainWindow::slotDeleteProjectClips(QStringList ids, QMap<QString, QString> folderids)
3547 {
3548     if (m_activeDocument && m_activeTimeline) {
3549         if (!ids.isEmpty()) {
3550             for (int i = 0; i < ids.size(); ++i) {
3551                 m_activeTimeline->slotDeleteClip(ids.at(i));
3552             }
3553             m_activeDocument->clipManager()->slotDeleteClips(ids);
3554         }
3555         if (!folderids.isEmpty()) m_projectList->deleteProjectFolder(folderids);
3556         m_activeDocument->setModified(true);
3557     }
3558 }
3559
3560 void MainWindow::slotShowTitleBars(bool show)
3561 {
3562     if (show) {
3563         m_effectStackDock->setTitleBarWidget(0);
3564         m_clipMonitorDock->setTitleBarWidget(0);
3565         m_projectMonitorDock->setTitleBarWidget(0);
3566 #ifndef Q_WS_MAC
3567         m_recMonitorDock->setTitleBarWidget(0);
3568 #endif
3569         m_effectListDock->setTitleBarWidget(0);
3570         m_transitionConfigDock->setTitleBarWidget(0);
3571         m_projectListDock->setTitleBarWidget(0);
3572         m_undoViewDock->setTitleBarWidget(0);
3573         m_vectorscopeDock->setTitleBarWidget(0);
3574     } else {
3575         if (!m_effectStackDock->isFloating()) { m_effectStackDock->setTitleBarWidget(new QWidget(this)); }
3576         if (!m_clipMonitorDock->isFloating()) { m_clipMonitorDock->setTitleBarWidget(new QWidget(this)); }
3577         if (!m_projectMonitorDock->isFloating()) { m_projectMonitorDock->setTitleBarWidget(new QWidget(this)); }
3578 #ifndef Q_WS_MAC
3579         if (!m_recMonitorDock->isFloating()) { m_recMonitorDock->setTitleBarWidget(new QWidget(this)); }
3580 #endif
3581         if (!m_effectListDock->isFloating()) { m_effectListDock->setTitleBarWidget(new QWidget(this)); }
3582         if (!m_transitionConfigDock->isFloating()) { m_transitionConfigDock->setTitleBarWidget(new QWidget(this)); }
3583         if (!m_projectListDock->isFloating()) { m_projectListDock->setTitleBarWidget(new QWidget(this)); }
3584         if (!m_undoViewDock->isFloating()) { m_undoViewDock->setTitleBarWidget(new QWidget(this)); }
3585         if (!m_vectorscopeDock->isFloating()) { m_vectorscopeDock->setTitleBarWidget(new QWidget(this)); }
3586     }
3587     KdenliveSettings::setShowtitlebars(show);
3588 }
3589
3590 void MainWindow::slotSwitchTitles()
3591 {
3592     slotShowTitleBars(!KdenliveSettings::showtitlebars());
3593 }
3594
3595 QString MainWindow::getMimeType()
3596 {
3597     QString mimetype = "application/x-kdenlive";
3598     KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
3599     if (!mime) mimetype = "*.kdenlive";
3600     return mimetype;
3601 }
3602
3603 #include "mainwindow.moc"
3604