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