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