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