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