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