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