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