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