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