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