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