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