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