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