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