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