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