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