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