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