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