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