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