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