]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
7477b95d611c3bdd828e4a0415a010cdcb2aa025
[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
55 #include <KApplication>
56 #include <KAction>
57 #include <KLocale>
58 #include <KGlobal>
59 #include <KActionCollection>
60 #include <KStandardAction>
61 #include <KFileDialog>
62 #include <KMessageBox>
63 #include <KDebug>
64 #include <KIO/NetAccess>
65 #include <KSaveFile>
66 #include <KRuler>
67 #include <KConfigDialog>
68 #include <KXMLGUIFactory>
69 #include <KStatusBar>
70 #include <kstandarddirs.h>
71 #include <KUrlRequesterDialog>
72 #include <KTemporaryFile>
73 #include <KProcess>
74 #include <KActionMenu>
75 #include <KMenu>
76 #include <locale.h>
77 #include <ktogglefullscreenaction.h>
78 #include <KFileItem>
79 #include <KNotification>
80 #include <KNotifyConfigWidget>
81 #include <knewstuff2/engine.h>
82 #include <knewstuff2/ui/knewstuffaction.h>
83
84 #include <QTextStream>
85 #include <QTimer>
86 #include <QAction>
87 #include <QKeyEvent>
88
89 #include <stdlib.h>
90
91 static const char version[] = VERSION;
92
93 static const int ID_TIMELINE_POS = 0;
94
95 namespace Mlt
96 {
97 class Producer;
98 };
99
100 EffectsList MainWindow::videoEffects;
101 EffectsList MainWindow::audioEffects;
102 EffectsList MainWindow::customEffects;
103 EffectsList MainWindow::transitions;
104
105 MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, QWidget *parent) :
106         KXmlGuiWindow(parent),
107         m_activeDocument(NULL),
108         m_activeTimeline(NULL),
109         m_renderWidget(NULL),
110 #ifndef NO_JOGSHUTTLE
111         m_jogProcess(NULL),
112 #endif /* NO_JOGSHUTTLE */
113         m_findActivated(false)
114 {
115
116     // Create DBus interface
117     new MainWindowAdaptor(this);
118     QDBusConnection dbus = QDBusConnection::sessionBus();
119     dbus.registerObject("/MainWindow", this);
120
121     setlocale(LC_NUMERIC, "POSIX");
122     setFont(KGlobalSettings::toolBarFont());
123     parseProfiles(MltPath);
124     m_commandStack = new QUndoGroup;
125     m_timelineArea = new KTabWidget(this);
126     m_timelineArea->setTabReorderingEnabled(true);
127     m_timelineArea->setTabBarHidden(true);
128
129     QToolButton *closeTabButton = new QToolButton;
130     connect(closeTabButton, SIGNAL(clicked()), this, SLOT(closeCurrentDocument()));
131     closeTabButton->setIcon(KIcon("tab-close"));
132     closeTabButton->adjustSize();
133     closeTabButton->setToolTip(i18n("Close the current tab"));
134     m_timelineArea->setCornerWidget(closeTabButton);
135     connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
136
137     connect(&m_findTimer, SIGNAL(timeout()), this, SLOT(findTimeout()));
138     m_findTimer.setSingleShot(true);
139
140     // FIXME: the next call returns a newly allocated object, which leaks
141     initEffects::parseEffectFiles();
142     //initEffects::parseCustomEffectsFile();
143
144     m_monitorManager = new MonitorManager();
145
146     m_projectListDock = new QDockWidget(i18n("Project Tree"), this);
147     m_projectListDock->setObjectName("project_tree");
148     m_projectList = new ProjectList(this);
149     m_projectListDock->setWidget(m_projectList);
150     addDockWidget(Qt::TopDockWidgetArea, m_projectListDock);
151
152     m_effectListDock = new QDockWidget(i18n("Effect List"), this);
153     m_effectListDock->setObjectName("effect_list");
154     m_effectList = new EffectsListView();
155
156     //m_effectList = new KListWidget(this);
157     m_effectListDock->setWidget(m_effectList);
158     addDockWidget(Qt::TopDockWidgetArea, m_effectListDock);
159
160     m_effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
161     m_effectStackDock->setObjectName("effect_stack");
162     m_effectStack = new EffectStackView(this);
163     m_effectStackDock->setWidget(m_effectStack);
164     addDockWidget(Qt::TopDockWidgetArea, m_effectStackDock);
165
166     m_transitionConfigDock = new QDockWidget(i18n("Transition"), this);
167     m_transitionConfigDock->setObjectName("transition");
168     m_transitionConfig = new TransitionSettings(this);
169     m_transitionConfigDock->setWidget(m_transitionConfig);
170     addDockWidget(Qt::TopDockWidgetArea, m_transitionConfigDock);
171
172     KdenliveSettings::setCurrent_profile(KdenliveSettings::default_profile());
173     m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
174                        actionCollection());
175     readOptions();
176
177     slotDetectAudioDriver();
178
179     m_clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
180     m_clipMonitorDock->setObjectName("clip_monitor");
181     m_clipMonitor = new Monitor("clip", m_monitorManager, this);
182     m_clipMonitorDock->setWidget(m_clipMonitor);
183     addDockWidget(Qt::TopDockWidgetArea, m_clipMonitorDock);
184     //m_clipMonitor->stop();
185
186     m_projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
187     m_projectMonitorDock->setObjectName("project_monitor");
188     m_projectMonitor = new Monitor("project", m_monitorManager, this);
189     m_projectMonitorDock->setWidget(m_projectMonitor);
190     addDockWidget(Qt::TopDockWidgetArea, m_projectMonitorDock);
191
192     m_recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
193     m_recMonitorDock->setObjectName("record_monitor");
194     m_recMonitor = new RecMonitor("record", this);
195     m_recMonitorDock->setWidget(m_recMonitor);
196     addDockWidget(Qt::TopDockWidgetArea, m_recMonitorDock);
197
198     connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
199     connect(m_recMonitor, SIGNAL(showConfigDialog(int, int)), this, SLOT(slotPreferences(int, int)));
200
201     m_undoViewDock = new QDockWidget(i18n("Undo History"), this);
202     m_undoViewDock->setObjectName("undo_history");
203     m_undoView = new QUndoView(this);
204     m_undoView->setCleanIcon(KIcon("edit-clear"));
205     m_undoView->setEmptyLabel(i18n("Clean"));
206     m_undoViewDock->setWidget(m_undoView);
207     m_undoView->setGroup(m_commandStack);
208     addDockWidget(Qt::TopDockWidgetArea, m_undoViewDock);
209
210     //overviewDock = new QDockWidget(i18n("Project Overview"), this);
211     //overviewDock->setObjectName("project_overview");
212     //m_overView = new CustomTrackView(NULL, NULL, this);
213     //overviewDock->setWidget(m_overView);
214     //addDockWidget(Qt::TopDockWidgetArea, overviewDock);
215
216     setupActions();
217     //tabifyDockWidget(projectListDock, effectListDock);
218     tabifyDockWidget(m_projectListDock, m_effectStackDock);
219     tabifyDockWidget(m_projectListDock, m_transitionConfigDock);
220     //tabifyDockWidget(projectListDock, undoViewDock);
221
222
223     tabifyDockWidget(m_clipMonitorDock, m_projectMonitorDock);
224     tabifyDockWidget(m_clipMonitorDock, m_recMonitorDock);
225     setCentralWidget(m_timelineArea);
226
227
228     setupGUI();
229     /*ScriptingPart* sp = new ScriptingPart(this, QStringList());
230     guiFactory()->addClient(sp);*/
231
232     loadPlugins();
233     loadTranscoders();
234     //kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
235
236     m_projectMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)), m_playZone, m_loopZone);
237     m_clipMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)), m_playZone, m_loopZone, static_cast<QMenu*>(factory()->container("marker_menu", this)));
238     m_projectList->setupGeneratorMenu(static_cast<QMenu*>(factory()->container("generators", this)), static_cast<QMenu*>(factory()->container("transcoders", this)));
239
240     // build effects menus
241     QAction *action;
242     QMenu *videoEffectsMenu = static_cast<QMenu*>(factory()->container("video_effects_menu", this));
243
244     QStringList effectInfo;
245     QMap<QString, QStringList> effectsList;
246     for (int ix = 0; ix < videoEffects.count(); ix++) {
247         effectInfo = videoEffects.effectIdInfo(ix);
248         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
249     }
250
251     foreach(const QStringList &value, effectsList) {
252         action = new QAction(value.at(0), this);
253         action->setData(value);
254         videoEffectsMenu->addAction(action);
255     }
256
257     QMenu *audioEffectsMenu = static_cast<QMenu*>(factory()->container("audio_effects_menu", this));
258
259
260     effectsList.clear();
261     for (int ix = 0; ix < audioEffects.count(); ix++) {
262         effectInfo = audioEffects.effectIdInfo(ix);
263         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
264     }
265
266     foreach(const QStringList &value, effectsList) {
267         action = new QAction(value.at(0), this);
268         action->setData(value);
269         audioEffectsMenu->addAction(action);
270     }
271
272     m_customEffectsMenu = static_cast<QMenu*>(factory()->container("custom_effects_menu", this));
273
274     if (customEffects.isEmpty()) m_customEffectsMenu->setEnabled(false);
275     else m_customEffectsMenu->setEnabled(true);
276
277     effectsList.clear();
278     for (int ix = 0; ix < customEffects.count(); ix++) {
279         effectInfo = customEffects.effectIdInfo(ix);
280         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
281     }
282
283     foreach(const QStringList &value, effectsList) {
284         action = new QAction(value.at(0), this);
285         action->setData(value);
286         m_customEffectsMenu->addAction(action);
287     }
288
289     QMenu *newEffect = new QMenu(this);
290     newEffect->addMenu(videoEffectsMenu);
291     newEffect->addMenu(audioEffectsMenu);
292     newEffect->addMenu(m_customEffectsMenu);
293     m_effectStack->setMenu(newEffect);
294
295
296     QMenu *viewMenu = static_cast<QMenu*>(factory()->container("dockwindows", this));
297     const QList<QAction *> viewActions = createPopupMenu()->actions();
298     viewMenu->insertActions(NULL, viewActions);
299
300     connect(videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
301     connect(audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
302     connect(m_customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
303
304     m_timelineContextMenu = new QMenu(this);
305     m_timelineContextClipMenu = new QMenu(this);
306     m_timelineContextTransitionMenu = new QMenu(this);
307
308
309     QMenu *transitionsMenu = new QMenu(i18n("Add Transition"), this);
310     QStringList effects = transitions.effectNames();
311
312     effectsList.clear();
313     for (int ix = 0; ix < transitions.count(); ix++) {
314         effectInfo = transitions.effectIdInfo(ix);
315         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
316     }
317     foreach(const QStringList &value, effectsList) {
318         action = new QAction(value.at(0), this);
319         action->setData(value);
320         transitionsMenu->addAction(action);
321     }
322     connect(transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
323
324     m_timelineContextMenu->addAction(actionCollection()->action("insert_space"));
325     m_timelineContextMenu->addAction(actionCollection()->action("delete_space"));
326     m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));
327
328     m_timelineContextClipMenu->addAction(actionCollection()->action("delete_timeline_clip"));
329     m_timelineContextClipMenu->addAction(actionCollection()->action("change_clip_speed"));
330     m_timelineContextClipMenu->addAction(actionCollection()->action("group_clip"));
331     m_timelineContextClipMenu->addAction(actionCollection()->action("ungroup_clip"));
332     m_timelineContextClipMenu->addAction(actionCollection()->action("cut_timeline_clip"));
333     m_timelineContextClipMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
334     m_timelineContextClipMenu->addAction(actionCollection()->action("paste_effects"));
335     m_timelineContextClipMenu->addAction(actionCollection()->action("split_audio"));
336
337     QMenu *markersMenu = (QMenu*)(factory()->container("marker_menu", this));
338     m_timelineContextClipMenu->addMenu(markersMenu);
339     m_timelineContextClipMenu->addMenu(transitionsMenu);
340     m_timelineContextClipMenu->addMenu(videoEffectsMenu);
341     m_timelineContextClipMenu->addMenu(audioEffectsMenu);
342     //TODO: re-enable custom effects menu when it is implemented
343     m_timelineContextClipMenu->addMenu(m_customEffectsMenu);
344
345     m_timelineContextTransitionMenu->addAction(actionCollection()->action("delete_timeline_clip"));
346     m_timelineContextTransitionMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
347
348     m_timelineContextTransitionMenu->addAction(actionCollection()->action("auto_transition"));
349
350     connect(m_projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
351     connect(m_clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
352     //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
353     connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
354     connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
355     connect(m_effectList, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
356
357     m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
358     slotConnectMonitors();
359
360     // Open or create a file.  Command line argument passed in Url has
361     // precedence, then "openlastproject", then just a plain empty file.
362     // If opening Url fails, openlastproject will _not_ be used.
363     if (!Url.isEmpty()) {
364         openFile(Url);
365     } else {
366         if (KdenliveSettings::openlastproject()) {
367             openLastFile();
368         }
369     }
370     if (m_timelineArea->count() == 0) {
371         newFile(false);
372     }
373
374 #ifndef NO_JOGSHUTTLE
375     activateShuttleDevice();
376 #endif /* NO_JOGSHUTTLE */
377     m_projectListDock->raise();
378 }
379
380 void MainWindow::queryQuit()
381 {
382     kDebug() << "----- SAVING CONFUIG";
383     if (queryClose()) {
384         Mlt::Factory::close();
385         kapp->quit();
386     }
387 }
388
389 //virtual
390 bool MainWindow::queryClose()
391 {
392     saveOptions();
393     if (m_monitorManager) m_monitorManager->stopActiveMonitor();
394     if (m_activeDocument && m_activeDocument->isModified()) {
395         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document?"))) {
396         case KMessageBox::Yes :
397             // save document here. If saving fails, return false;
398             return saveFile();
399         case KMessageBox::No :
400             // User does not want to save the changes, clear recovery files
401             m_activeDocument->m_autosave->resize(0);
402             return true;
403         default: // cancel
404             return false;
405         }
406     }
407     return true;
408 }
409
410
411 void MainWindow::loadPlugins()
412 {
413     foreach(QObject *plugin, QPluginLoader::staticInstances())
414     populateMenus(plugin);
415
416     QStringList directories = KGlobal::dirs()->findDirs("module", QString());
417     QStringList filters;
418     filters << "libkdenlive*";
419     foreach(const QString &folder, directories) {
420         kDebug() << "// PARSING FIOLER: " << folder;
421         QDir pluginsDir(folder);
422         foreach(const QString &fileName, pluginsDir.entryList(filters, QDir::Files)) {
423             kDebug() << "// FOUND PLUGIN: " << fileName << "= " << pluginsDir.absoluteFilePath(fileName);
424             QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
425             QObject *plugin = loader.instance();
426             if (plugin) {
427                 populateMenus(plugin);
428                 m_pluginFileNames += fileName;
429             } else kDebug() << "// ERROR LOADING PLUGIN: " << fileName << ", " << loader.errorString();
430         }
431     }
432     //exit(1);
433 }
434
435 void MainWindow::populateMenus(QObject *plugin)
436 {
437     QMenu *addMenu = static_cast<QMenu*>(factory()->container("generators", this));
438     ClipGenerator *iGenerator = qobject_cast<ClipGenerator *>(plugin);
439     if (iGenerator)
440         addToMenu(plugin, iGenerator->generators(KdenliveSettings::producerslist()), addMenu, SLOT(generateClip()),
441                   NULL);
442 }
443
444 void MainWindow::addToMenu(QObject *plugin, const QStringList &texts,
445                            QMenu *menu, const char *member,
446                            QActionGroup *actionGroup)
447 {
448     kDebug() << "// ADD to MENU" << texts;
449     foreach(const QString &text, texts) {
450         QAction *action = new QAction(text, plugin);
451         action->setData(text);
452         connect(action, SIGNAL(triggered()), this, member);
453         menu->addAction(action);
454
455         if (actionGroup) {
456             action->setCheckable(true);
457             actionGroup->addAction(action);
458         }
459     }
460 }
461
462 void MainWindow::aboutPlugins()
463 {
464     //PluginDialog dialog(pluginsDir.path(), m_pluginFileNames, this);
465     //dialog.exec();
466 }
467
468
469 void MainWindow::generateClip()
470 {
471     QAction *action = qobject_cast<QAction *>(sender());
472     ClipGenerator *iGenerator = qobject_cast<ClipGenerator *>(action->parent());
473
474     KUrl clipUrl = iGenerator->generatedClip(action->data().toString(), m_activeDocument->projectFolder(), QStringList(), QStringList(), 25, 720, 576);
475     if (!clipUrl.isEmpty()) {
476         m_projectList->slotAddClip(QList <QUrl> () << clipUrl);
477     }
478 }
479
480 void MainWindow::saveProperties(KConfig*)
481 {
482     // save properties here,used by session management
483     saveFile();
484 }
485
486
487 void MainWindow::readProperties(KConfig *config)
488 {
489     // read properties here,used by session management
490     QString Lastproject = config->group("Recent Files").readPathEntry("File1", QString());
491     openFile(KUrl(Lastproject));
492 }
493
494 void MainWindow::slotReloadEffects()
495 {
496     initEffects::parseCustomEffectsFile();
497     m_customEffectsMenu->clear();
498     const QStringList effects = customEffects.effectNames();
499     QAction *action;
500     if (effects.isEmpty()) m_customEffectsMenu->setEnabled(false);
501     else m_customEffectsMenu->setEnabled(true);
502
503     foreach(const QString &name, effects) {
504         action = new QAction(name, this);
505         action->setData(name);
506         m_customEffectsMenu->addAction(action);
507     }
508     m_effectList->reloadEffectList();
509 }
510
511 #ifndef NO_JOGSHUTTLE
512 void MainWindow::activateShuttleDevice()
513 {
514     delete m_jogProcess;
515     m_jogProcess = NULL;
516     if (KdenliveSettings::enableshuttle() == false) return;
517     m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
518     connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
519     connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
520     connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
521     connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
522     connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
523     connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
524 }
525
526 void MainWindow::slotShuttleButton(int code)
527 {
528     switch (code) {
529     case 5:
530         slotShuttleAction(KdenliveSettings::shuttle1());
531         break;
532     case 6:
533         slotShuttleAction(KdenliveSettings::shuttle2());
534         break;
535     case 7:
536         slotShuttleAction(KdenliveSettings::shuttle3());
537         break;
538     case 8:
539         slotShuttleAction(KdenliveSettings::shuttle4());
540         break;
541     case 9:
542         slotShuttleAction(KdenliveSettings::shuttle5());
543         break;
544     }
545 }
546
547 void MainWindow::slotShuttleAction(int code)
548 {
549     switch (code) {
550     case 0:
551         return;
552     case 1:
553         m_monitorManager->slotPlay();
554         break;
555     default:
556         m_monitorManager->slotPlay();
557         break;
558     }
559 }
560 #endif /* NO_JOGSHUTTLE */
561
562 void MainWindow::configureNotifications()
563 {
564     KNotifyConfigWidget::configure(this);
565 }
566
567 void MainWindow::slotFullScreen()
568 {
569     KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
570 }
571
572 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track)
573 {
574     if (!m_activeDocument) return;
575     if (effect.isNull()) {
576         kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
577         return;
578     }
579     m_activeTimeline->projectView()->slotAddEffect(effect.cloneNode().toElement(), pos, track);
580 }
581
582 void MainWindow::slotRaiseMonitor(bool clipMonitor)
583 {
584     if (clipMonitor) m_clipMonitorDock->raise();
585     else m_projectMonitorDock->raise();
586 }
587
588 void MainWindow::slotUpdateClip(const QString &id)
589 {
590     if (!m_activeDocument) return;
591     m_activeTimeline->projectView()->slotUpdateClip(id);
592 }
593
594 void MainWindow::slotConnectMonitors()
595 {
596
597     m_projectList->setRenderer(m_projectMonitor->render);
598     connect(m_projectList, SIGNAL(receivedClipDuration(const QString &)), this, SLOT(slotUpdateClip(const QString &)));
599     connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
600     connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, const QString &, bool)), m_projectMonitor->render, SLOT(getFileProperties(const QDomElement &, const QString &, bool)));
601     connect(m_projectMonitor->render, SIGNAL(replyGetImage(const QString &, const QPixmap &)), m_projectList, SLOT(slotReplyGetImage(const QString &, const QPixmap &)));
602     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)));
603
604     connect(m_projectMonitor->render, SIGNAL(removeInvalidClip(const QString &, bool)), m_projectList, SLOT(slotRemoveInvalidClip(const QString &, bool)));
605
606     connect(m_clipMonitor, SIGNAL(refreshClipThumbnail(const QString &)), m_projectList, SLOT(slotRefreshClipThumbnail(const QString &)));
607
608     connect(m_clipMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustClipMonitor()));
609     connect(m_projectMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustProjectMonitor()));
610
611     connect(m_clipMonitor, SIGNAL(saveZone(Render *, QPoint)), this, SLOT(slotSaveZone(Render *, QPoint)));
612     connect(m_projectMonitor, SIGNAL(saveZone(Render *, QPoint)), this, SLOT(slotSaveZone(Render *, QPoint)));
613 }
614
615 void MainWindow::slotAdjustClipMonitor()
616 {
617     m_clipMonitorDock->updateGeometry();
618     m_clipMonitorDock->adjustSize();
619     m_clipMonitor->resetSize();
620 }
621
622 void MainWindow::slotAdjustProjectMonitor()
623 {
624     m_projectMonitorDock->updateGeometry();
625     m_projectMonitorDock->adjustSize();
626     m_projectMonitor->resetSize();
627 }
628
629 void MainWindow::setupActions()
630 {
631
632     KActionCollection* collection = actionCollection();
633     m_timecodeFormat = new KComboBox(this);
634     m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
635     m_timecodeFormat->addItem(i18n("Frames"));
636
637     m_statusProgressBar = new QProgressBar(this);
638     m_statusProgressBar->setMinimum(0);
639     m_statusProgressBar->setMaximum(100);
640     m_statusProgressBar->setMaximumWidth(150);
641     m_statusProgressBar->setVisible(false);
642
643     QWidget *w = new QWidget;
644
645     QHBoxLayout *layout = new QHBoxLayout;
646     w->setLayout(layout);
647     layout->setContentsMargins(5, 0, 5, 0);
648     QToolBar *toolbar = new QToolBar("statusToolBar", this);
649
650
651     m_toolGroup = new QActionGroup(this);
652
653     QString style1 = "QToolButton {background-color: rgba(230, 230, 230, 220); 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;}";
654
655     m_buttonSelectTool = new KAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"), this);
656     toolbar->addAction(m_buttonSelectTool);
657     m_buttonSelectTool->setCheckable(true);
658     m_buttonSelectTool->setChecked(true);
659
660     m_buttonRazorTool = new KAction(KIcon("edit-cut"), i18n("Razor tool"), this);
661     toolbar->addAction(m_buttonRazorTool);
662     m_buttonRazorTool->setCheckable(true);
663     m_buttonRazorTool->setChecked(false);
664
665     m_buttonSpacerTool = new KAction(KIcon("kdenlive-spacer-tool"), i18n("Spacer tool"), this);
666     toolbar->addAction(m_buttonSpacerTool);
667     m_buttonSpacerTool->setCheckable(true);
668     m_buttonSpacerTool->setChecked(false);
669
670     m_toolGroup->addAction(m_buttonSelectTool);
671     m_toolGroup->addAction(m_buttonRazorTool);
672     m_toolGroup->addAction(m_buttonSpacerTool);
673     m_toolGroup->setExclusive(true);
674     toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
675
676     QWidget * actionWidget;
677     actionWidget = toolbar->widgetForAction(m_buttonSelectTool);
678     actionWidget->setMaximumWidth(24);
679     actionWidget->setMinimumHeight(18);
680
681     actionWidget = toolbar->widgetForAction(m_buttonRazorTool);
682     actionWidget->setMaximumWidth(24);
683     actionWidget->setMinimumHeight(18);
684
685     actionWidget = toolbar->widgetForAction(m_buttonSpacerTool);
686     actionWidget->setMaximumWidth(24);
687     actionWidget->setMinimumHeight(18);
688
689     toolbar->setStyleSheet(style1);
690     connect(m_toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
691
692     toolbar->addSeparator();
693     m_buttonFitZoom = new KAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"), this);
694     toolbar->addAction(m_buttonFitZoom);
695     m_buttonFitZoom->setCheckable(false);
696     connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
697
698     actionWidget = toolbar->widgetForAction(m_buttonFitZoom);
699     actionWidget->setMaximumWidth(24);
700     actionWidget->setMinimumHeight(18);
701
702     m_zoomSlider = new QSlider(Qt::Horizontal, this);
703     m_zoomSlider->setMaximum(13);
704     m_zoomSlider->setPageStep(1);
705
706     m_zoomSlider->setMaximumWidth(150);
707     m_zoomSlider->setMinimumWidth(100);
708
709     const int contentHeight = QFontMetrics(w->font()).height() + 8;
710
711     QString style = "QSlider::groove:horizontal { background-color: rgba(230, 230, 230, 220);border: 1px solid #999999;height: 8px;border-radius: 3px;margin-top:3px }";
712     style.append("QSlider::handle:horizontal {  background-color: white; border: 1px solid #999999;width: 9px;margin: -2px 0;border-radius: 3px; }");
713
714     m_zoomSlider->setStyleSheet(style);
715
716     //m_zoomSlider->height() + 5;
717     statusBar()->setMinimumHeight(contentHeight);
718
719
720     toolbar->addWidget(m_zoomSlider);
721
722     m_buttonVideoThumbs = new KAction(KIcon("kdenlive-show-videothumb"), i18n("Show video thumbnails"), this);
723     toolbar->addAction(m_buttonVideoThumbs);
724     m_buttonVideoThumbs->setCheckable(true);
725     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
726     connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
727
728     m_buttonAudioThumbs = new KAction(KIcon("kdenlive-show-audiothumb"), i18n("Show audio thumbnails"), this);
729     toolbar->addAction(m_buttonAudioThumbs);
730     m_buttonAudioThumbs->setCheckable(true);
731     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
732     connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
733
734     m_buttonShowMarkers = new KAction(KIcon("kdenlive-show-markers"), i18n("Show markers comments"), this);
735     toolbar->addAction(m_buttonShowMarkers);
736     m_buttonShowMarkers->setCheckable(true);
737     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
738     connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
739
740     m_buttonSnap = new KAction(KIcon("kdenlive-snap"), i18n("Snap"), this);
741     toolbar->addAction(m_buttonSnap);
742     m_buttonSnap->setCheckable(true);
743     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
744     connect(m_buttonSnap, SIGNAL(triggered()), this, SLOT(slotSwitchSnap()));
745     layout->addWidget(toolbar);
746
747
748     actionWidget = toolbar->widgetForAction(m_buttonVideoThumbs);
749     actionWidget->setMaximumWidth(24);
750     actionWidget->setMinimumHeight(18);
751
752     actionWidget = toolbar->widgetForAction(m_buttonAudioThumbs);
753     actionWidget->setMaximumWidth(24);
754     actionWidget->setMinimumHeight(18);
755
756     actionWidget = toolbar->widgetForAction(m_buttonShowMarkers);
757     actionWidget->setMaximumWidth(24);
758     actionWidget->setMinimumHeight(18);
759
760     actionWidget = toolbar->widgetForAction(m_buttonSnap);
761     actionWidget->setMaximumWidth(24);
762     actionWidget->setMinimumHeight(18);
763
764     m_messageLabel = new StatusBarMessageLabel(this);
765     m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
766
767     statusBar()->addWidget(m_messageLabel, 10);
768     statusBar()->addWidget(m_statusProgressBar, 0);
769     statusBar()->addPermanentWidget(w);
770     statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
771     statusBar()->addPermanentWidget(m_timecodeFormat);
772     statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
773     m_messageLabel->hide();
774
775     collection->addAction("select_tool", m_buttonSelectTool);
776     collection->addAction("razor_tool", m_buttonRazorTool);
777     collection->addAction("spacer_tool", m_buttonSpacerTool);
778
779     collection->addAction("show_video_thumbs", m_buttonVideoThumbs);
780     collection->addAction("show_audio_thumbs", m_buttonAudioThumbs);
781     collection->addAction("show_markers", m_buttonShowMarkers);
782     collection->addAction("snap", m_buttonSnap);
783     collection->addAction("zoom_fit", m_buttonFitZoom);
784
785     KAction* zoomIn = new KAction(KIcon("zoom-in"), i18n("Zoom In"), this);
786     collection->addAction("zoom_in", zoomIn);
787     connect(zoomIn, SIGNAL(triggered(bool)), this, SLOT(slotZoomIn()));
788     zoomIn->setShortcut(Qt::CTRL + Qt::Key_Plus);
789
790     KAction* zoomOut = new KAction(KIcon("zoom-out"), i18n("Zoom Out"), this);
791     collection->addAction("zoom_out", zoomOut);
792     connect(zoomOut, SIGNAL(triggered(bool)), this, SLOT(slotZoomOut()));
793     zoomOut->setShortcut(Qt::CTRL + Qt::Key_Minus);
794
795     m_projectSearch = new KAction(KIcon("edit-find"), i18n("Find"), this);
796     collection->addAction("project_find", m_projectSearch);
797     connect(m_projectSearch, SIGNAL(triggered(bool)), this, SLOT(slotFind()));
798     m_projectSearch->setShortcut(Qt::Key_Slash);
799
800     m_projectSearchNext = new KAction(KIcon("go-down-search"), i18n("Find Next"), this);
801     collection->addAction("project_find_next", m_projectSearchNext);
802     connect(m_projectSearchNext, SIGNAL(triggered(bool)), this, SLOT(slotFindNext()));
803     m_projectSearchNext->setShortcut(Qt::Key_F3);
804     m_projectSearchNext->setEnabled(false);
805
806     KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Project Profiles"), this);
807     collection->addAction("manage_profiles", profilesAction);
808     connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
809
810     KNS::standardAction(i18n("Download New Wipes..."), this, SLOT(slotGetNewLumaStuff()), actionCollection(), "get_new_lumas");
811
812     KNS::standardAction(i18n("Download New Render Profiles..."), this, SLOT(slotGetNewRenderStuff()), actionCollection(), "get_new_profiles");
813
814     KNS::standardAction(i18n("Download New Project Profiles..."), this, SLOT(slotGetNewMltProfileStuff()), actionCollection(), "get_new_mlt_profiles");
815
816     KAction* wizAction = new KAction(KIcon("configure"), i18n("Run Config Wizard"), this);
817     collection->addAction("run_wizard", wizAction);
818     connect(wizAction, SIGNAL(triggered(bool)), this, SLOT(slotRunWizard()));
819
820     KAction* projectAction = new KAction(KIcon("configure"), i18n("Project Settings"), this);
821     collection->addAction("project_settings", projectAction);
822     connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
823
824     KAction* projectRender = new KAction(KIcon("media-record"), i18n("Render"), this);
825     collection->addAction("project_render", projectRender);
826     projectRender->setShortcut(Qt::CTRL + Qt::Key_Return);
827     connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
828
829     KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
830     KShortcut playShortcut;
831     playShortcut.setPrimary(Qt::Key_Space);
832     playShortcut.setAlternate(Qt::Key_K);
833     monitorPlay->setShortcut(playShortcut);
834     collection->addAction("monitor_play", monitorPlay);
835     connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
836
837     m_playZone = new KAction(KIcon("media-playback-start"), i18n("Play Zone"), this);
838     m_playZone->setShortcut(Qt::CTRL + Qt::Key_Space);
839     collection->addAction("monitor_play_zone", m_playZone);
840     connect(m_playZone, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlayZone()));
841
842     m_loopZone = new KAction(KIcon("media-playback-start"), i18n("Loop Zone"), this);
843     m_loopZone->setShortcut(Qt::ALT + Qt::Key_Space);
844     collection->addAction("monitor_loop_zone", m_loopZone);
845     connect(m_loopZone, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotLoopZone()));
846
847     KAction *dvdWizard =  new KAction(KIcon("media-optical"), i18n("DVD Wizard"), this);
848     collection->addAction("dvd_wizard", dvdWizard);
849     connect(dvdWizard, SIGNAL(triggered(bool)), this, SLOT(slotDvdWizard()));
850
851     KAction *transcodeClip =  new KAction(KIcon("edit-copy"), i18n("Transcode Clip"), this);
852     collection->addAction("transcode_clip", transcodeClip);
853     connect(transcodeClip, SIGNAL(triggered(bool)), this, SLOT(slotTranscodeClip()));
854
855     KAction *markIn = collection->addAction("mark_in");
856     markIn->setText(i18n("Set In Point"));
857     markIn->setShortcut(Qt::Key_I);
858     connect(markIn, SIGNAL(triggered(bool)), this, SLOT(slotSetInPoint()));
859
860     KAction *markOut = collection->addAction("mark_out");
861     markOut->setText(i18n("Set Out Point"));
862     markOut->setShortcut(Qt::Key_O);
863     connect(markOut, SIGNAL(triggered(bool)), this, SLOT(slotSetOutPoint()));
864
865     KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
866     monitorSeekBackward->setShortcut(Qt::Key_J);
867     collection->addAction("monitor_seek_backward", monitorSeekBackward);
868     connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
869
870     KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
871     monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
872     collection->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
873     connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
874
875     KAction* monitorSeekBackwardOneSecond = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Second"), this);
876     monitorSeekBackwardOneSecond->setShortcut(Qt::SHIFT + Qt::Key_Left);
877     collection->addAction("monitor_seek_backward-one-second", monitorSeekBackwardOneSecond);
878     connect(monitorSeekBackwardOneSecond, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneSecond()));
879
880     KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
881     monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
882     collection->addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
883     connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
884
885     KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
886     monitorSeekForward->setShortcut(Qt::Key_L);
887     collection->addAction("monitor_seek_forward", monitorSeekForward);
888     connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
889
890     KAction* clipStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Clip Start"), this);
891     clipStart->setShortcut(Qt::Key_Home);
892     collection->addAction("seek_clip_start", clipStart);
893     connect(clipStart, SIGNAL(triggered(bool)), this, SLOT(slotClipStart()));
894
895     KAction* clipEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Clip End"), this);
896     clipEnd->setShortcut(Qt::Key_End);
897     collection->addAction("seek_clip_end", clipEnd);
898     connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
899
900     KAction* projectStart = new KAction(KIcon("go-first"), i18n("Go to Project Start"), this);
901     projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
902     collection->addAction("seek_start", projectStart);
903     connect(projectStart, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotStart()));
904
905     KAction* projectEnd = new KAction(KIcon("go-last"), i18n("Go to Project End"), this);
906     projectEnd->setShortcut(Qt::CTRL + Qt::Key_End);
907     collection->addAction("seek_end", projectEnd);
908     connect(projectEnd, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotEnd()));
909
910     KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
911     monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
912     collection->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
913     connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
914
915     KAction* monitorSeekForwardOneSecond = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Second"), this);
916     monitorSeekForwardOneSecond->setShortcut(Qt::SHIFT + Qt::Key_Right);
917     collection->addAction("monitor_seek_forward-one-second", monitorSeekForwardOneSecond);
918     connect(monitorSeekForwardOneSecond, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneSecond()));
919
920     KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
921     monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
922     collection->addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
923     connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
924
925     KAction* deleteTimelineClip = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
926     deleteTimelineClip->setShortcut(Qt::Key_Delete);
927     collection->addAction("delete_timeline_clip", deleteTimelineClip);
928     connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
929
930     KAction* editTimelineClipSpeed = new KAction(i18n("Change Clip Speed"), this);
931     collection->addAction("change_clip_speed", editTimelineClipSpeed);
932     editTimelineClipSpeed->setData("change_speed");
933     connect(editTimelineClipSpeed, SIGNAL(triggered(bool)), this, SLOT(slotChangeClipSpeed()));
934
935     KAction *stickTransition = collection->addAction("auto_transition");
936     stickTransition->setData(QString("auto"));
937     stickTransition->setCheckable(true);
938     stickTransition->setEnabled(false);
939     stickTransition->setText(i18n("Automatic Transition"));
940     connect(stickTransition, SIGNAL(triggered(bool)), this, SLOT(slotAutoTransition()));
941
942     KAction* groupClip = new KAction(KIcon("object-group"), i18n("Group Clips"), this);
943     collection->addAction("group_clip", groupClip);
944     connect(groupClip, SIGNAL(triggered(bool)), this, SLOT(slotGroupClips()));
945
946     KAction* ungroupClip = new KAction(KIcon("object-ungroup"), i18n("Ungroup Clips"), this);
947     collection->addAction("ungroup_clip", ungroupClip);
948     ungroupClip->setData("ungroup_clip");
949     connect(ungroupClip, SIGNAL(triggered(bool)), this, SLOT(slotUnGroupClips()));
950
951     KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
952     cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
953     collection->addAction("cut_timeline_clip", cutTimelineClip);
954     connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
955
956     KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker"), this);
957     collection->addAction("add_clip_marker", addClipMarker);
958     connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
959
960     KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker"), this);
961     collection->addAction("delete_clip_marker", deleteClipMarker);
962     connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
963
964     KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers"), this);
965     collection->addAction("delete_all_clip_markers", deleteAllClipMarkers);
966     connect(deleteAllClipMarkers, SIGNAL(triggered(bool)), this, SLOT(slotDeleteAllClipMarkers()));
967
968     KAction* editClipMarker = new KAction(KIcon("document-properties"), i18n("Edit Marker"), this);
969     collection->addAction("edit_clip_marker", editClipMarker);
970     connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker()));
971
972     KAction* splitAudio = new KAction(KIcon("document-new"), i18n("Split Audio"), this);
973     collection->addAction("split_audio", splitAudio);
974     connect(splitAudio, SIGNAL(triggered(bool)), this, SLOT(slotSplitAudio()));
975
976     KAction* audioOnly = new KAction(KIcon("document-new"), i18n("Audio Only"), this);
977     collection->addAction("clip_audio_only", audioOnly);
978     audioOnly->setData("clip_audio_only");
979     audioOnly->setCheckable(true);
980
981     KAction* videoOnly = new KAction(KIcon("document-new"), i18n("Video Only"), this);
982     collection->addAction("clip_video_only", videoOnly);
983     videoOnly->setData("clip_video_only");
984     videoOnly->setCheckable(true);
985
986     KAction* audioAndVideo = new KAction(KIcon("document-new"), i18n("Audio and Video"), this);
987     collection->addAction("clip_audio_and_video", audioAndVideo);
988     audioAndVideo->setData("clip_audio_and_video");
989     audioAndVideo->setCheckable(true);
990
991     m_clipTypeGroup = new QActionGroup(this);
992     m_clipTypeGroup->addAction(audioOnly);
993     m_clipTypeGroup->addAction(videoOnly);
994     m_clipTypeGroup->addAction(audioAndVideo);
995     connect(m_clipTypeGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotUpdateClipType(QAction *)));
996     m_clipTypeGroup->setEnabled(false);
997
998     KAction *insertSpace = new KAction(KIcon(), i18n("Insert Space"), this);
999     collection->addAction("insert_space", insertSpace);
1000     connect(insertSpace, SIGNAL(triggered()), this, SLOT(slotInsertSpace()));
1001
1002     KAction *removeSpace = new KAction(KIcon(), i18n("Remove Space"), this);
1003     collection->addAction("delete_space", removeSpace);
1004     connect(removeSpace, SIGNAL(triggered()), this, SLOT(slotRemoveSpace()));
1005
1006     KAction *insertTrack = new KAction(KIcon(), i18n("Insert Track"), this);
1007     collection->addAction("insert_track", insertTrack);
1008     connect(insertTrack, SIGNAL(triggered()), this, SLOT(slotInsertTrack()));
1009
1010     KAction *deleteTrack = new KAction(KIcon(), i18n("Delete Track"), this);
1011     collection->addAction("delete_track", deleteTrack);
1012     connect(deleteTrack, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
1013
1014     KAction *changeTrack = new KAction(KIcon(), i18n("Change Track"), this);
1015     collection->addAction("change_track", changeTrack);
1016     connect(changeTrack, SIGNAL(triggered()), this, SLOT(slotChangeTrack()));
1017
1018     KAction *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
1019     collection->addAction("add_guide", addGuide);
1020     connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
1021
1022     QAction *delGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
1023     collection->addAction("delete_guide", delGuide);
1024     connect(delGuide, SIGNAL(triggered()), this, SLOT(slotDeleteGuide()));
1025
1026     QAction *editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
1027     collection->addAction("edit_guide", editGuide);
1028     connect(editGuide, SIGNAL(triggered()), this, SLOT(slotEditGuide()));
1029
1030     QAction *delAllGuides = new KAction(KIcon("edit-delete"), i18n("Delete All Guides"), this);
1031     collection->addAction("delete_all_guides", delAllGuides);
1032     connect(delAllGuides, SIGNAL(triggered()), this, SLOT(slotDeleteAllGuides()));
1033
1034     QAction *pasteEffects = new KAction(KIcon("edit-paste"), i18n("Paste Effects"), this);
1035     collection->addAction("paste_effects", pasteEffects);
1036     pasteEffects->setData("paste_effects");
1037     connect(pasteEffects , SIGNAL(triggered()), this, SLOT(slotPasteEffects()));
1038
1039     QAction *showTimeline = new KAction(i18n("Show Timeline"), this);
1040     collection->addAction("show_timeline", showTimeline);
1041     showTimeline->setCheckable(true);
1042     showTimeline->setChecked(true);
1043     connect(showTimeline, SIGNAL(triggered(bool)), this, SLOT(slotShowTimeline(bool)));
1044
1045     /*QAction *maxCurrent = new KAction(i18n("Maximize Current Widget"), this);
1046     collection->addAction("maximize_current", maxCurrent);
1047     maxCurrent->setCheckable(true);
1048     maxCurrent->setChecked(false);
1049     connect(maxCurrent, SIGNAL(triggered(bool)), this, SLOT(slotMaximizeCurrent(bool)));*/
1050
1051
1052     m_closeAction = KStandardAction::close(this, SLOT(closeCurrentDocument()), collection);
1053
1054     KStandardAction::quit(this, SLOT(queryQuit()), collection);
1055
1056     KStandardAction::open(this, SLOT(openFile()), collection);
1057
1058     m_saveAction = KStandardAction::save(this, SLOT(saveFile()), collection);
1059
1060     KStandardAction::saveAs(this, SLOT(saveFileAs()), collection);
1061
1062     KStandardAction::openNew(this, SLOT(newFile()), collection);
1063
1064     KStandardAction::preferences(this, SLOT(slotPreferences()), collection);
1065
1066     KStandardAction::configureNotifications(this , SLOT(configureNotifications()), collection);
1067
1068     KStandardAction::copy(this, SLOT(slotCopy()), collection);
1069
1070     KStandardAction::paste(this, SLOT(slotPaste()), collection);
1071
1072     KAction *undo = KStandardAction::undo(m_commandStack, SLOT(undo()), collection);
1073     undo->setEnabled(false);
1074     connect(m_commandStack, SIGNAL(canUndoChanged(bool)), undo, SLOT(setEnabled(bool)));
1075
1076     KAction *redo = KStandardAction::redo(m_commandStack, SLOT(redo()), collection);
1077     redo->setEnabled(false);
1078     connect(m_commandStack, SIGNAL(canRedoChanged(bool)), redo, SLOT(setEnabled(bool)));
1079
1080     KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, collection);
1081
1082     /*
1083     //TODO: Add status tooltip to actions ?
1084     connect(collection, SIGNAL(actionHovered(QAction*)),
1085             this, SLOT(slotDisplayActionMessage(QAction*)));*/
1086
1087
1088     QAction *addClip = new KAction(KIcon("kdenlive-add-clip"), i18n("Add Clip"), this);
1089     collection->addAction("add_clip", addClip);
1090     connect(addClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddClip()));
1091
1092     QAction *addColorClip = new KAction(KIcon("kdenlive-add-color-clip"), i18n("Add Color Clip"), this);
1093     collection->addAction("add_color_clip", addColorClip);
1094     connect(addColorClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddColorClip()));
1095
1096     QAction *addSlideClip = new KAction(KIcon("kdenlive-add-slide-clip"), i18n("Add Slideshow Clip"), this);
1097     collection->addAction("add_slide_clip", addSlideClip);
1098     connect(addSlideClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddSlideshowClip()));
1099
1100     QAction *addTitleClip = new KAction(KIcon("kdenlive-add-text-clip"), i18n("Add Title Clip"), this);
1101     collection->addAction("add_text_clip", addTitleClip);
1102     connect(addTitleClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddTitleClip()));
1103
1104     QAction *addFolderButton = new KAction(KIcon("folder-new"), i18n("Create Folder"), this);
1105     collection->addAction("add_folder", addFolderButton);
1106     connect(addFolderButton , SIGNAL(triggered()), m_projectList, SLOT(slotAddFolder()));
1107
1108     QAction *clipProperties = new KAction(KIcon("document-edit"), i18n("Clip Properties"), this);
1109     collection->addAction("clip_properties", clipProperties);
1110     clipProperties->setData("clip_properties");
1111     connect(clipProperties , SIGNAL(triggered()), m_projectList, SLOT(slotEditClip()));
1112     clipProperties->setEnabled(false);
1113
1114     QAction *openClip = new KAction(KIcon("document-open"), i18n("Edit Clip"), this);
1115     collection->addAction("edit_clip", openClip);
1116     openClip->setData("edit_clip");
1117     connect(openClip , SIGNAL(triggered()), m_projectList, SLOT(slotOpenClip()));
1118     openClip->setEnabled(false);
1119
1120     QAction *deleteClip = new KAction(KIcon("edit-delete"), i18n("Delete Clip"), this);
1121     collection->addAction("delete_clip", deleteClip);
1122     deleteClip->setData("delete_clip");
1123     connect(deleteClip , SIGNAL(triggered()), m_projectList, SLOT(slotRemoveClip()));
1124     deleteClip->setEnabled(false);
1125
1126     QAction *reloadClip = new KAction(KIcon("view-refresh"), i18n("Reload Clip"), this);
1127     collection->addAction("reload_clip", reloadClip);
1128     reloadClip->setData("reload_clip");
1129     connect(reloadClip , SIGNAL(triggered()), m_projectList, SLOT(slotReloadClip()));
1130     reloadClip->setEnabled(false);
1131
1132     QMenu *addClips = new QMenu();
1133     addClips->addAction(addClip);
1134     addClips->addAction(addColorClip);
1135     addClips->addAction(addSlideClip);
1136     addClips->addAction(addTitleClip);
1137     addClips->addAction(addFolderButton);
1138
1139     addClips->addAction(reloadClip);
1140     addClips->addAction(clipProperties);
1141     addClips->addAction(openClip);
1142     addClips->addAction(deleteClip);
1143     m_projectList->setupMenu(addClips, addClip);
1144
1145     //connect(collection, SIGNAL( clearStatusText() ),
1146     //statusBar(), SLOT( clear() ) );
1147 }
1148
1149 void MainWindow::slotDisplayActionMessage(QAction *a)
1150 {
1151     statusBar()->showMessage(a->data().toString(), 3000);
1152 }
1153
1154 void MainWindow::saveOptions()
1155 {
1156     KdenliveSettings::self()->writeConfig();
1157     KSharedConfigPtr config = KGlobal::config();
1158     m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
1159     KConfigGroup treecolumns(config, "Project Tree");
1160     treecolumns.writeEntry("columns", m_projectList->headerInfo());
1161     config->sync();
1162 }
1163
1164 void MainWindow::readOptions()
1165 {
1166     KSharedConfigPtr config = KGlobal::config();
1167     m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
1168     KConfigGroup initialGroup(config, "version");
1169     bool upgrade = false;
1170     if (initialGroup.exists()) {
1171         if (initialGroup.readEntry("version", QString()).section(' ', 0, 0) != QString(version).section(' ', 0, 0))
1172             upgrade = true;
1173
1174         if (initialGroup.readEntry("version") == "0.7") {
1175             //Add new settings from 0.7.1
1176             if (KdenliveSettings::defaultprojectfolder().isEmpty()) {
1177                 QString path = QDir::homePath() + "/kdenlive";
1178                 if (KStandardDirs::makeDir(path)  == false) kDebug() << "/// ERROR CREATING PROJECT FOLDER: " << path;
1179                 KdenliveSettings::setDefaultprojectfolder(path);
1180             }
1181         }
1182
1183     }
1184
1185     if (!initialGroup.exists() || upgrade) {
1186         // this is our first run, show Wizard
1187         Wizard *w = new Wizard(upgrade, this);
1188         if (w->exec() == QDialog::Accepted && w->isOk()) {
1189             w->adjustSettings();
1190             initialGroup.writeEntry("version", version);
1191             delete w;
1192         } else {
1193             ::exit(1);
1194         }
1195     }
1196     KConfigGroup treecolumns(config, "Project Tree");
1197     const QByteArray state = treecolumns.readEntry("columns", QByteArray());
1198     if (!state.isEmpty())
1199         m_projectList->setHeaderInfo(state);
1200 }
1201
1202 void MainWindow::slotRunWizard()
1203 {
1204     Wizard *w = new Wizard(false, this);
1205     if (w->exec() == QDialog::Accepted && w->isOk()) {
1206         w->adjustSettings();
1207     }
1208     delete w;
1209 }
1210
1211 void MainWindow::newFile(bool showProjectSettings)
1212 {
1213     QString profileName;
1214     KUrl projectFolder;
1215     QPoint projectTracks(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks());
1216     if (!showProjectSettings && m_timelineArea->count() == 0) {
1217         if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1218         profileName = KdenliveSettings::default_profile();
1219         projectFolder = KdenliveSettings::defaultprojectfolder();
1220     } else {
1221         ProjectSettings *w = new ProjectSettings(projectTracks.x(), projectTracks.y(), KdenliveSettings::defaultprojectfolder(), false, this);
1222         if (w->exec() != QDialog::Accepted) return;
1223         if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1224         KdenliveSettings::setVideothumbnails(w->enableVideoThumbs());
1225         m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1226         KdenliveSettings::setAudiothumbnails(w->enableAudioThumbs());
1227         m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1228         profileName = w->selectedProfile();
1229         projectFolder = w->selectedFolder();
1230         projectTracks = w->tracks();
1231         delete w;
1232     }
1233     KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, profileName, projectTracks, m_projectMonitor->render, this);
1234     doc->m_autosave = new KAutoSaveFile(KUrl(), doc);
1235     TrackView *trackView = new TrackView(doc, this);
1236     m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
1237     if (m_timelineArea->count() == 1) {
1238         connectDocumentInfo(doc);
1239         connectDocument(trackView, doc);
1240     } else m_timelineArea->setTabBarHidden(false);
1241     m_closeAction->setEnabled(m_timelineArea->count() > 1);
1242 }
1243
1244 void MainWindow::activateDocument()
1245 {
1246     if (m_timelineArea->currentWidget() == NULL) return;
1247     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1248     KdenliveDoc *currentDoc = currentTab->document();
1249     connectDocumentInfo(currentDoc);
1250     connectDocument(currentTab, currentDoc);
1251 }
1252
1253 void MainWindow::closeCurrentDocument()
1254 {
1255     QWidget *w = m_timelineArea->currentWidget();
1256     if (!w) return;
1257     // closing current document
1258     int ix = m_timelineArea->currentIndex() + 1;
1259     if (ix == m_timelineArea->count()) ix = 0;
1260     m_timelineArea->setCurrentIndex(ix);
1261     TrackView *tabToClose = (TrackView *) w;
1262     KdenliveDoc *docToClose = tabToClose->document();
1263     if (docToClose && docToClose->isModified()) {
1264         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document?"))) {
1265         case KMessageBox::Yes :
1266             // save document here. If saving fails, return false;
1267             if (saveFile() == false) return;
1268             break;
1269         case KMessageBox::Cancel :
1270             return;
1271             break;
1272         default:
1273             break;
1274         }
1275     }
1276     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
1277     if (m_timelineArea->count() == 1) {
1278         m_timelineArea->setTabBarHidden(true);
1279         m_closeAction->setEnabled(false);
1280     }
1281     if (docToClose == m_activeDocument) {
1282         delete m_activeDocument;
1283         m_activeDocument = NULL;
1284         m_effectStack->clear();
1285         m_transitionConfig->slotTransitionItemSelected(NULL, 0, QPoint(), false);
1286     } else delete docToClose;
1287     if (w == m_activeTimeline) {
1288         delete m_activeTimeline;
1289         m_activeTimeline = NULL;
1290     } else delete w;
1291 }
1292
1293 bool MainWindow::saveFileAs(const QString &outputFileName)
1294 {
1295     QString currentSceneList;
1296     if (KdenliveSettings::dropbframes()) {
1297         KdenliveSettings::setDropbframes(false);
1298         m_activeDocument->clipManager()->updatePreviewSettings();
1299         currentSceneList = m_projectMonitor->sceneList();
1300         KdenliveSettings::setDropbframes(true);
1301         m_activeDocument->clipManager()->updatePreviewSettings();
1302     } else currentSceneList = m_projectMonitor->sceneList();
1303
1304     if (m_activeDocument->saveSceneList(outputFileName, currentSceneList) == false)
1305         return false;
1306
1307     // Save timeline thumbnails
1308     m_activeTimeline->projectView()->saveThumbnails();
1309     m_activeDocument->setUrl(KUrl(outputFileName));
1310     if (m_activeDocument->m_autosave == NULL) {
1311         m_activeDocument->m_autosave = new KAutoSaveFile(KUrl(outputFileName), this);
1312     } else m_activeDocument->m_autosave->setManagedFile(KUrl(outputFileName));
1313     setCaption(m_activeDocument->description());
1314     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1315     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
1316     m_activeDocument->setModified(false);
1317     m_fileOpenRecent->addUrl(KUrl(outputFileName));
1318     return true;
1319 }
1320
1321 bool MainWindow::saveFileAs()
1322 {
1323     // Check that the Kdenlive mime type is correctly installed
1324     QString mimetype = "application/x-kdenlive";
1325     KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
1326     if (!mime) mimetype = "*.kdenlive";
1327
1328     QString outputFile = KFileDialog::getSaveFileName(KUrl(), mimetype);
1329     if (outputFile.isEmpty()) return false;
1330     if (QFile::exists(outputFile)) {
1331         if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it?")) == KMessageBox::No) return false;
1332     }
1333     return saveFileAs(outputFile);
1334 }
1335
1336 bool MainWindow::saveFile()
1337 {
1338     if (!m_activeDocument) return true;
1339     if (m_activeDocument->url().isEmpty()) {
1340         return saveFileAs();
1341     } else {
1342         bool result = saveFileAs(m_activeDocument->url().path());
1343         m_activeDocument->m_autosave->resize(0);
1344         return result;
1345     }
1346 }
1347
1348 void MainWindow::openFile()
1349 {
1350     // Check that the Kdenlive mime type is correctly installed
1351     QString mimetype = "application/x-kdenlive";
1352     KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
1353     if (!mime) mimetype = "*.kdenlive";
1354
1355     KUrl url = KFileDialog::getOpenUrl(KUrl("kfiledialog:///projectfolder"), mimetype);
1356     if (url.isEmpty()) return;
1357     m_fileOpenRecent->addUrl(url);
1358     openFile(url);
1359 }
1360
1361 void MainWindow::openLastFile()
1362 {
1363     KSharedConfigPtr config = KGlobal::config();
1364     KUrl::List urls = m_fileOpenRecent->urls();
1365     //WARNING: this is buggy, we get a random url, not the last one. Bug in KRecentFileAction?
1366     if (urls.isEmpty()) newFile(false);
1367     else openFile(urls.last());
1368 }
1369
1370 void MainWindow::openFile(const KUrl &url)
1371 {
1372     // Check if the document is already opened
1373     const int ct = m_timelineArea->count();
1374     bool isOpened = false;
1375     int i;
1376     for (i = 0; i < ct; i++) {
1377         TrackView *tab = (TrackView *) m_timelineArea->widget(i);
1378         KdenliveDoc *doc = tab->document();
1379         if (doc->url() == url) {
1380             isOpened = true;
1381             break;
1382         }
1383     }
1384     if (isOpened) {
1385         m_timelineArea->setCurrentIndex(i);
1386         return;
1387     }
1388
1389     // Check for backup file
1390     QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::staleFiles(url);
1391     if (!staleFiles.isEmpty()) {
1392         if (KMessageBox::questionYesNo(this,
1393                                        i18n("Auto-saved files exist. Do you want to recover them now?"),
1394                                        i18n("File Recovery"),
1395                                        KGuiItem(i18n("Recover")), KGuiItem(i18n("Don't recover"))) == KMessageBox::Yes) {
1396             recoverFiles(staleFiles);
1397             return;
1398         } else {
1399             // remove the stale files
1400             foreach(KAutoSaveFile *stale, staleFiles) {
1401                 stale->open(QIODevice::ReadWrite);
1402                 delete stale;
1403             }
1404         }
1405     }
1406     if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1407     doOpenFile(url, NULL);
1408 }
1409
1410 void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale)
1411 {
1412     KdenliveDoc *doc = new KdenliveDoc(url, KdenliveSettings::defaultprojectfolder(), m_commandStack, KdenliveSettings::default_profile(), QPoint(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks()), m_projectMonitor->render, this);
1413     if (stale == NULL) {
1414         stale = new KAutoSaveFile(url, doc);
1415         doc->m_autosave = stale;
1416     } else {
1417         doc->m_autosave = stale;
1418         doc->setUrl(stale->managedFile());
1419         doc->setModified(true);
1420         stale->setParent(doc);
1421     }
1422     connectDocumentInfo(doc);
1423     TrackView *trackView = new TrackView(doc, this);
1424     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
1425     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
1426     trackView->setDuration(trackView->duration());
1427     trackView->projectView()->initCursorPos(m_projectMonitor->render->seekPosition().frames(doc->fps()));
1428
1429     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
1430     slotGotProgressInfo(QString(), -1);
1431     m_clipMonitor->refreshMonitor(true);
1432     m_projectMonitor->adjustRulerSize(trackView->duration());
1433     m_projectMonitor->slotZoneMoved(trackView->inPoint(), trackView->outPoint());
1434 }
1435
1436 void MainWindow::recoverFiles(QList<KAutoSaveFile *> staleFiles)
1437 {
1438     if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1439     foreach(KAutoSaveFile *stale, staleFiles) {
1440         /*if (!stale->open(QIODevice::QIODevice::ReadOnly)) {
1441                   // show an error message; we could not steal the lockfile
1442                   // maybe another application got to the file before us?
1443                   delete stale;
1444                   continue;
1445         }*/
1446         kDebug() << "// OPENING RECOVERY: " << stale->fileName() << "\nMANAGED: " << stale->managedFile().path();
1447         // the stalefiles also contain ".lock" files so we must ignore them... bug in KAutoSaveFile?
1448         if (!stale->fileName().endsWith(".lock")) doOpenFile(KUrl(stale->fileName()), stale);
1449         else KIO::NetAccess::del(KUrl(stale->fileName()), this);
1450     }
1451 }
1452
1453
1454 void MainWindow::parseProfiles(const QString &mltPath)
1455 {
1456     // kDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
1457
1458     //KdenliveSettings::setDefaulttmpfolder();
1459     if (!mltPath.isEmpty()) {
1460         KdenliveSettings::setMltpath(mltPath + "/share/mlt/profiles/");
1461         KdenliveSettings::setRendererpath(mltPath + "/bin/melt");
1462     }
1463
1464     if (KdenliveSettings::mltpath().isEmpty()) {
1465         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
1466     }
1467     if (KdenliveSettings::rendererpath().isEmpty() || KdenliveSettings::rendererpath().endsWith("inigo")) {
1468         QString meltPath = QString(MLT_PREFIX) + QString("/bin/melt");
1469         if (!QFile::exists(meltPath))
1470             meltPath = KStandardDirs::findExe("melt");
1471         KdenliveSettings::setRendererpath(meltPath);
1472     }
1473     QStringList profilesFilter;
1474     profilesFilter << "*";
1475     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1476
1477     if (profilesList.isEmpty()) {
1478         // Cannot find MLT path, try finding melt
1479         QString profilePath = KdenliveSettings::rendererpath();
1480         if (!profilePath.isEmpty()) {
1481             profilePath = profilePath.section('/', 0, -3);
1482             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
1483             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1484         }
1485
1486         if (profilesList.isEmpty()) {
1487             // Cannot find the MLT profiles, ask for location
1488             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
1489             getUrl->fileDialog()->setMode(KFile::Directory);
1490             if (getUrl->exec() == QDialog::Rejected) {
1491                 ::exit(0);
1492             }
1493             KUrl mltPath = getUrl->selectedUrl();
1494             delete getUrl;
1495             if (mltPath.isEmpty()) ::exit(0);
1496             KdenliveSettings::setMltpath(mltPath.path());
1497             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1498         }
1499     }
1500
1501     if (KdenliveSettings::rendererpath().isEmpty()) {
1502         // Cannot find the MLT melt renderer, ask for location
1503         KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(QString(), i18n("Cannot find the melt program required for rendering (part of Mlt)"), this);
1504         if (getUrl->exec() == QDialog::Rejected) {
1505             ::exit(0);
1506         }
1507         KUrl rendererPath = getUrl->selectedUrl();
1508         delete getUrl;
1509         if (rendererPath.isEmpty()) ::exit(0);
1510         KdenliveSettings::setRendererpath(rendererPath.path());
1511     }
1512
1513     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
1514
1515     // Parse MLT profiles to build a list of available video formats
1516     if (profilesList.isEmpty()) parseProfiles();
1517 }
1518
1519
1520 void MainWindow::slotEditProfiles()
1521 {
1522     ProfilesDialog *w = new ProfilesDialog;
1523     if (w->exec() == QDialog::Accepted) {
1524         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
1525         if (d) d->checkProfile();
1526     }
1527     delete w;
1528 }
1529
1530 void MainWindow::slotDetectAudioDriver()
1531 {
1532     //decide which audio driver is really best, in some cases SDL is wrong
1533     if (KdenliveSettings::audiodrivername().isEmpty()) {
1534         QString driver;
1535         KProcess readProcess;
1536         //PulseAudio needs to be selected if it exists, the ALSA pulse pcm device is not fast enough.
1537         if (!KStandardDirs::findExe("pactl").isEmpty()) {
1538             readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
1539             readProcess.setProgram("pactl", QStringList() << "stat");
1540             readProcess.execute(2000); // Kill it after 2 seconds
1541
1542             QString result = QString(readProcess.readAllStandardOutput());
1543             kDebug() << "// / / / / / READING PACTL: ";
1544             kDebug() << result;
1545             if (!result.isEmpty()) {
1546                 driver = "pulse";
1547                 kDebug() << "// / / / / PULSEAUDIO DETECTED";
1548             }
1549         }
1550         //put others here
1551         KdenliveSettings::setAutoaudiodrivername(driver);
1552     }
1553 }
1554
1555 void MainWindow::slotEditProjectSettings()
1556 {
1557     QPoint p = m_activeDocument->getTracksCount();
1558     ProjectSettings *w = new ProjectSettings(p.x(), p.y(), m_activeDocument->projectFolder().path(), true, this);
1559
1560     if (w->exec() == QDialog::Accepted) {
1561         QString profile = w->selectedProfile();
1562         m_activeDocument->setProjectFolder(w->selectedFolder());
1563         if (m_renderWidget) m_renderWidget->setDocumentPath(w->selectedFolder().path());
1564         if (m_activeDocument->profilePath() != profile) {
1565             // Profile was changed
1566             double dar = m_activeDocument->dar();
1567             m_activeDocument->setProfilePath(profile);
1568             KdenliveSettings::setCurrent_profile(profile);
1569             KdenliveSettings::setProject_fps(m_activeDocument->fps());
1570             setCaption(m_activeDocument->description(), m_activeDocument->isModified());
1571             m_monitorManager->resetProfiles(m_activeDocument->timecode());
1572             if (m_renderWidget) m_renderWidget->setProfile(m_activeDocument->mltProfile());
1573             m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1574             m_activeDocument->clipManager()->resetProducersList(m_projectMonitor->render->producersList());
1575             if (dar != m_activeDocument->dar()) m_projectList->reloadClipThumbnails();
1576             // We need to desactivate & reactivate monitors to get a refresh
1577             m_monitorManager->switchMonitors();
1578         }
1579     }
1580     delete w;
1581 }
1582
1583 void MainWindow::slotRenderProject()
1584 {
1585     if (!m_renderWidget) {
1586         QString projectfolder = m_activeDocument ? m_activeDocument->projectFolder().path() : KdenliveSettings::defaultprojectfolder();
1587         m_renderWidget = new RenderWidget(projectfolder, this);
1588         connect(m_renderWidget, SIGNAL(doRender(const QStringList&, const QStringList&)), this, SLOT(slotDoRender(const QStringList&, const QStringList&)));
1589         connect(m_renderWidget, SIGNAL(abortProcess(const QString &)), this, SIGNAL(abortRenderJob(const QString &)));
1590         connect(m_renderWidget, SIGNAL(openDvdWizard(const QString &, const QString &)), this, SLOT(slotDvdWizard(const QString &, const QString &)));
1591         if (m_activeDocument) {
1592             m_renderWidget->setProfile(m_activeDocument->mltProfile());
1593             m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1594         }
1595     }
1596     /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1597     if (currentTab) m_renderWidget->setTimeline(currentTab);
1598     m_renderWidget->setDocument(m_activeDocument);*/
1599     m_renderWidget->show();
1600 }
1601
1602 void MainWindow::slotDoRender(const QStringList args, const QStringList overlay_args)
1603 {
1604     QString dest = args.at(0);
1605     QString render = args.at(1);
1606     QStringList avformat_args = args.at(2).split(' ');
1607     bool zoneOnly = args.at(3).toInt();
1608     bool playAfter = args.at(4).toInt();
1609     double guideStart = args.at(5).toDouble();
1610     double guideEnd = args.at(6).toDouble();
1611     bool resizeProfile = args.at(7).toInt();
1612     QString scriptExport = args.at(8);
1613     bool createChapterFile = args.at(9).toInt();
1614
1615     if (dest.isEmpty()) return;
1616     int in = 0;
1617     int out = 0;
1618
1619     if (m_activeTimeline && zoneOnly) {
1620         in = m_activeTimeline->inPoint();
1621         out = m_activeTimeline->outPoint();
1622     }
1623
1624     KTemporaryFile temp;
1625     temp.setAutoRemove(false);
1626     temp.setSuffix(".mlt");
1627     if (!scriptExport.isEmpty() || temp.open()) {
1628         if (KdenliveSettings::dropbframes()) {
1629             KdenliveSettings::setDropbframes(false);
1630             m_activeDocument->clipManager()->updatePreviewSettings();
1631             if (!scriptExport.isEmpty()) m_projectMonitor->saveSceneList(scriptExport + ".mlt");
1632             else m_projectMonitor->saveSceneList(temp.fileName());
1633             KdenliveSettings::setDropbframes(true);
1634             m_activeDocument->clipManager()->updatePreviewSettings();
1635         } else {
1636             if (!scriptExport.isEmpty()) m_projectMonitor->saveSceneList(scriptExport + ".mlt");
1637             else m_projectMonitor->saveSceneList(temp.fileName());
1638         }
1639
1640         QStringList args;
1641         if (scriptExport.isEmpty()) args << "-erase";
1642         if (KdenliveSettings::usekuiserver()) args << "-kuiserver";
1643         if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
1644         else if (guideStart != -1) {
1645             args << "in=" + QString::number(GenTime(guideStart).frames(m_activeDocument->fps())) << "out=" + QString::number(GenTime(guideEnd).frames(m_activeDocument->fps()));
1646         }
1647         if (!overlay_args.isEmpty()) args << "preargs=" + overlay_args.join(" ");
1648         QString videoPlayer = "-";
1649         if (playAfter) {
1650             videoPlayer = KdenliveSettings::defaultplayerapp();
1651             if (videoPlayer.isEmpty()) KMessageBox::sorry(this, i18n("Cannot play video after rendering because the default video player application is not set.\nPlease define it in Kdenlive settings dialog."));
1652         }
1653         if (!QFile::exists(KdenliveSettings::rendererpath())) {
1654             KMessageBox::sorry(this, i18n("Cannot find the melt program required for rendering (part of Mlt)"));
1655             setRenderingProgress(dest, -3);
1656             return;
1657         }
1658         args << KdenliveSettings::rendererpath() << m_activeDocument->profilePath() << render << videoPlayer;
1659
1660         for (int i = 0; i < avformat_args.count(); i++) {
1661             if (avformat_args.at(i).startsWith("profile=")) {
1662                 if (avformat_args.at(i).section('=', 1) != m_activeDocument->profilePath()) resizeProfile = true;
1663                 break;
1664             }
1665         }
1666
1667         if (resizeProfile) {
1668             // The rendering profile is different from project profile, so use MLT's special producer_consumer
1669             if (scriptExport.isEmpty()) args << "consumer:" + temp.fileName();
1670             else args << "consumer:$SOURCE";
1671         } else {
1672             if (scriptExport.isEmpty()) args << temp.fileName();
1673             else args << "$SOURCE";
1674         }
1675         if (scriptExport.isEmpty()) args << dest;
1676         else args << "$TARGET";
1677         args << avformat_args;
1678         QString renderer = QCoreApplication::applicationDirPath() + QString("/kdenlive_render");
1679         if (!QFile::exists(renderer)) renderer = "kdenlive_render";
1680         if (scriptExport.isEmpty()) {
1681             QProcess::startDetached(renderer, args);
1682             KNotification::event("RenderStarted", i18n("Rendering <i>%1</i> started", dest), QPixmap(), this);
1683         } else {
1684             // Generate script file
1685             QFile file(scriptExport);
1686             if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1687                 KMessageBox::error(this, i18n("Cannot write to file %1", scriptExport));
1688                 return;
1689             }
1690
1691             QTextStream outStream(&file);
1692             outStream << "#! /bin/sh" << "\n" << "\n";
1693             outStream << "SOURCE=" << "\"" + scriptExport + ".mlt\"" << "\n";
1694             outStream << "TARGET=" << "\"" + dest + "\"" << "\n";
1695             outStream << renderer << " " << args.join(" ") << "\n" << "\n";
1696             if (file.error() != QFile::NoError) {
1697                 KMessageBox::error(this, i18n("Cannot write to file %1", scriptExport));
1698                 file.close();
1699                 return;
1700             }
1701             file.close();
1702             QFile::setPermissions(scriptExport, file.permissions() | QFile::ExeUser);
1703         }
1704
1705         if (createChapterFile) {
1706             QDomDocument doc;
1707             QDomElement chapters = doc.createElement("chapters");
1708             chapters.setAttribute("fps", m_activeDocument->fps());
1709             doc.appendChild(chapters);
1710
1711             QDomElement guidesxml = m_activeDocument->guidesXml();
1712             if (!zoneOnly) out = (int) GenTime(m_activeDocument->projectDuration()).frames(m_activeDocument->fps());
1713
1714             QDomNodeList nodes = guidesxml.elementsByTagName("guide");
1715             for (int i = 0; i < nodes.count(); i++) {
1716                 QDomElement e = nodes.item(i).toElement();
1717                 if (!e.isNull()) {
1718                     QString comment = e.attribute("comment");
1719                     int time = (int) GenTime(e.attribute("time").toDouble()).frames(m_activeDocument->fps());
1720                     if (time >= in && time < out) {
1721                         if (zoneOnly) time = time - in;
1722                         QDomElement chapter = doc.createElement("chapter");
1723                         chapters.appendChild(chapter);
1724                         chapter.setAttribute("title", comment);
1725                         chapter.setAttribute("time", time);
1726                     }
1727                 }
1728             }
1729             if (chapters.childNodes().count() > 0) {
1730                 if (m_activeTimeline->projectView()->hasGuide(out, 0) == -1) {
1731                     // Always insert a guide in pos 0
1732                     QDomElement chapter = doc.createElement("chapter");
1733                     chapters.insertBefore(chapter, QDomNode());
1734                     chapter.setAttribute("title", i18n("Start"));
1735                     chapter.setAttribute("time", "0");
1736                 }
1737                 // save chapters file
1738                 QFile file(dest + ".dvdchapter");
1739                 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1740                     kWarning() << "//////  ERROR writing DVD CHAPTER file: " << dest + ".dvdchapter";
1741                 } else {
1742                     file.write(doc.toString().toUtf8());
1743                     if (file.error() != QFile::NoError)
1744                         kWarning() << "//////  ERROR writing DVD CHAPTER file: " << dest + ".dvdchapter";
1745                     file.close();
1746                 }
1747             }
1748         }
1749     }
1750 }
1751
1752 void MainWindow::setRenderingProgress(const QString &url, int progress)
1753 {
1754     if (m_renderWidget) m_renderWidget->setRenderJob(url, progress);
1755 }
1756
1757 void MainWindow::setRenderingFinished(const QString &url, int status, const QString &error)
1758 {
1759     if (m_renderWidget) m_renderWidget->setRenderStatus(url, status, error);
1760 }
1761
1762 void MainWindow::slotUpdateMousePosition(int pos)
1763 {
1764     if (m_activeDocument)
1765         switch (m_timecodeFormat->currentIndex()) {
1766         case 0:
1767             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
1768             break;
1769         default:
1770             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
1771         }
1772 }
1773
1774 void MainWindow::slotUpdateDocumentState(bool modified)
1775 {
1776     if (!m_activeDocument) return;
1777     setCaption(m_activeDocument->description(), modified);
1778     m_saveAction->setEnabled(modified);
1779     if (modified) {
1780         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
1781         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
1782     } else {
1783         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
1784         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
1785     }
1786 }
1787
1788 void MainWindow::connectDocumentInfo(KdenliveDoc *doc)
1789 {
1790     if (m_activeDocument) {
1791         if (m_activeDocument == doc) return;
1792         disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1793     }
1794     connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1795 }
1796
1797 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc)   //changed
1798 {
1799     //m_projectMonitor->stop();
1800     m_closeAction->setEnabled(m_timelineArea->count() > 1);
1801     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
1802     if (m_activeDocument) {
1803         if (m_activeDocument == doc) return;
1804         if (m_activeTimeline) {
1805             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
1806             disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeTimeline, SLOT(slotSetZone(QPoint)));
1807             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
1808             disconnect(m_projectList, SIGNAL(projectModified()), m_activeDocument, SLOT(setModified()));
1809             disconnect(m_projectMonitor->render, SIGNAL(refreshDocumentProducers()), m_activeDocument, SLOT(checkProjectClips()));
1810
1811
1812             disconnect(m_activeDocument, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1813             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
1814             disconnect(m_activeDocument, SIGNAL(resetProjectList()), m_projectList, SLOT(slotResetProjectList()));
1815             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1816             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1817             disconnect(m_activeDocument, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1818             disconnect(m_activeDocument, SIGNAL(deleteTimelineClip(const QString &)), m_activeTimeline, SLOT(slotDeleteClip(const QString &)));
1819             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), m_effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
1820             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
1821             disconnect(m_activeTimeline->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), m_transitionConfig, SLOT(slotTransitionItemSelected(Transition*, int, QPoint, bool)));
1822             disconnect(m_activeTimeline->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), this, SLOT(slotActivateTransitionView(Transition *)));
1823             disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
1824             disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1825             disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1826             disconnect(m_activeTimeline, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1827             disconnect(m_activeTimeline, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
1828             disconnect(m_activeTimeline, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
1829             disconnect(m_activeTimeline, SIGNAL(changeTrack(int)), this, SLOT(slotChangeTrack(int)));
1830             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1831             disconnect(m_effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1832             disconnect(m_effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1833             disconnect(m_effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1834             disconnect(m_effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), m_activeTimeline->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1835             disconnect(m_effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1836             disconnect(m_effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1837             disconnect(m_transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), m_activeTimeline->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1838             disconnect(m_transitionConfig, SIGNAL(seekTimeline(int)), m_activeTimeline->projectView() , SLOT(setCursorPos(int)));
1839             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1840             disconnect(m_activeTimeline, SIGNAL(zoneMoved(int, int)), this, SLOT(slotZoneMoved(int, int)));
1841             disconnect(m_projectList, SIGNAL(loadingIsOver()), m_activeTimeline->projectView(), SLOT(slotUpdateAllThumbs()));
1842             m_effectStack->clear();
1843         }
1844         //m_activeDocument->setRenderer(NULL);
1845         disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1846         m_clipMonitor->stop();
1847     }
1848     KdenliveSettings::setCurrent_profile(doc->profilePath());
1849     KdenliveSettings::setProject_fps(doc->fps());
1850     m_monitorManager->resetProfiles(doc->timecode());
1851     m_projectList->setDocument(doc);
1852     m_transitionConfig->updateProjectFormat(doc->mltProfile(), doc->timecode(), trackView->tracksNumber());
1853     m_effectStack->updateProjectFormat(doc->mltProfile(), doc->timecode());
1854     connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1855     connect(m_projectList, SIGNAL(projectModified()), doc, SLOT(setModified()));
1856     connect(m_projectList, SIGNAL(clipNameChanged(const QString, const QString)), trackView->projectView(), SLOT(clipNameChanged(const QString, const QString)));
1857
1858
1859     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1860     connect(trackView, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
1861     connect(trackView, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
1862     connect(trackView, SIGNAL(changeTrack(int)), this, SLOT(slotChangeTrack(int)));
1863     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
1864     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
1865     connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), trackView, SLOT(slotSetZone(QPoint)));
1866     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
1867     connect(m_projectMonitor->render, SIGNAL(refreshDocumentProducers()), doc, SLOT(checkProjectClips()));
1868     connect(doc, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
1869     connect(doc, SIGNAL(resetProjectList()), m_projectList, SLOT(slotResetProjectList()));
1870     connect(doc, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1871     connect(doc, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1872     connect(doc, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1873
1874     connect(doc, SIGNAL(deleteTimelineClip(const QString &)), trackView, SLOT(slotDeleteClip(const QString &)));
1875     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1876     connect(doc, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1877
1878
1879     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), m_effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
1880     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
1881     connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), m_transitionConfig, SLOT(slotTransitionItemSelected(Transition*, int, QPoint, bool)));
1882     connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), this, SLOT(slotActivateTransitionView(Transition *)));
1883     m_zoomSlider->setValue(doc->zoom());
1884     connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
1885     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
1886     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
1887     connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1888
1889     connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1890
1891
1892     connect(m_effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1893     connect(m_effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1894     connect(m_effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1895     connect(m_effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1896     connect(m_effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1897     connect(m_transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1898     connect(m_transitionConfig, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
1899     connect(m_effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1900
1901     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1902     connect(trackView, SIGNAL(zoneMoved(int, int)), this, SLOT(slotZoneMoved(int, int)));
1903     connect(m_projectList, SIGNAL(loadingIsOver()), trackView->projectView(), SLOT(slotUpdateAllThumbs()));
1904
1905     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu, m_clipTypeGroup);
1906     m_activeTimeline = trackView;
1907     if (m_renderWidget) {
1908         m_renderWidget->setProfile(doc->mltProfile());
1909         m_renderWidget->setDocumentPath(doc->projectFolder().path());
1910     }
1911     //doc->setRenderer(m_projectMonitor->render);
1912     m_commandStack->setActiveStack(doc->commandStack());
1913     KdenliveSettings::setProject_display_ratio(doc->dar());
1914     m_projectList->updateAllClips();
1915     //doc->clipManager()->checkAudioThumbs();
1916
1917     //m_overView->setScene(trackView->projectScene());
1918     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
1919     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
1920
1921     setCaption(doc->description(), doc->isModified());
1922     m_saveAction->setEnabled(doc->isModified());
1923     m_activeDocument = doc;
1924     if (KdenliveSettings::dropbframes()) slotUpdatePreviewSettings();
1925
1926     // set tool to select tool
1927     m_buttonSelectTool->setChecked(true);
1928 }
1929
1930 void MainWindow::slotZoneMoved(int start, int end)
1931 {
1932     m_activeDocument->setZone(start, end);
1933     m_projectMonitor->slotZoneMoved(start, end);
1934 }
1935
1936 void MainWindow::slotGuidesUpdated()
1937 {
1938     if (m_renderWidget) m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1939 }
1940
1941 void MainWindow::slotPreferences(int page, int option)
1942 {
1943     //An instance of your dialog could be already created and could be
1944     // cached, in which case you want to display the cached dialog
1945     // instead of creating another one
1946     if (KConfigDialog::showDialog("settings")) {
1947         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
1948         if (page != -1) d->showPage(page, option);
1949         return;
1950     }
1951
1952     // KConfigDialog didn't find an instance of this dialog, so lets
1953     // create it :
1954     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
1955     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
1956     connect(dialog, SIGNAL(doResetProfile()), this, SLOT(slotDetectAudioDriver()));
1957     connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(slotResetProfiles()));
1958     connect(dialog, SIGNAL(updatePreviewSettings()), this, SLOT(slotUpdatePreviewSettings()));
1959     connect(dialog, SIGNAL(updateCaptureFolder()), m_recMonitor, SLOT(slotUpdateCaptureFolder()));
1960     //connect(dialog, SIGNAL(updatePreviewSettings()), this, SLOT(slotUpdatePreviewSettings()));
1961     dialog->show();
1962     if (page != -1) dialog->showPage(page, option);
1963 }
1964
1965 void MainWindow::slotUpdatePreviewSettings()
1966 {
1967     if (m_activeDocument) {
1968         m_clipMonitor->slotSetXml(NULL, 0);
1969         m_activeDocument->updatePreviewSettings();
1970     }
1971 }
1972
1973 void MainWindow::updateConfiguration()
1974 {
1975     //TODO: we should apply settings to all projects, not only the current one
1976     if (m_activeTimeline) {
1977         m_activeTimeline->refresh();
1978         m_activeTimeline->projectView()->checkAutoScroll();
1979         m_activeTimeline->projectView()->checkTrackHeight();
1980         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1981     }
1982     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1983     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1984
1985     // Update list of transcoding profiles
1986     loadTranscoders();
1987 #ifndef NO_JOGSHUTTLE
1988     activateShuttleDevice();
1989 #endif /* NO_JOGSHUTTLE */
1990
1991 }
1992
1993
1994 void MainWindow::slotSwitchVideoThumbs()
1995 {
1996     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
1997     if (m_activeTimeline) {
1998         m_activeTimeline->projectView()->slotUpdateAllThumbs();
1999     }
2000     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
2001 }
2002
2003 void MainWindow::slotSwitchAudioThumbs()
2004 {
2005     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
2006     if (m_activeTimeline) {
2007         m_activeTimeline->refresh();
2008         m_activeTimeline->projectView()->checkAutoScroll();
2009         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
2010     }
2011     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
2012 }
2013
2014 void MainWindow::slotSwitchMarkersComments()
2015 {
2016     KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
2017     if (m_activeTimeline) {
2018         m_activeTimeline->refresh();
2019     }
2020     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
2021 }
2022
2023 void MainWindow::slotSwitchSnap()
2024 {
2025     KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
2026     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
2027 }
2028
2029
2030 void MainWindow::slotDeleteTimelineClip()
2031 {
2032     if (QApplication::focusWidget()->parentWidget()->parentWidget() == m_projectListDock) m_projectList->slotRemoveClip();
2033     else if (m_activeTimeline) {
2034         m_activeTimeline->projectView()->deleteSelectedClips();
2035     }
2036 }
2037
2038 void MainWindow::slotChangeClipSpeed()
2039 {
2040     if (m_activeTimeline) {
2041         m_activeTimeline->projectView()->changeClipSpeed();
2042     }
2043 }
2044
2045 void MainWindow::slotAddClipMarker()
2046 {
2047     DocClipBase *clip = NULL;
2048     GenTime pos;
2049     if (m_projectMonitor->isActive()) {
2050         if (m_activeTimeline) {
2051             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2052             if (item) {
2053                 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
2054                 clip = item->baseClip();
2055             }
2056         }
2057     } else {
2058         clip = m_clipMonitor->activeClip();
2059         pos = m_clipMonitor->position();
2060     }
2061     if (!clip) {
2062         m_messageLabel->setMessage(i18n("Cannot find clip to add marker"), ErrorMessage);
2063         return;
2064     }
2065     QString id = clip->getId();
2066     CommentedTime marker(pos, i18n("Marker"));
2067     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Add Marker"), this);
2068     if (d.exec() == QDialog::Accepted) {
2069         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
2070     }
2071     if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
2072 }
2073
2074 void MainWindow::slotDeleteClipMarker()
2075 {
2076     DocClipBase *clip = NULL;
2077     GenTime pos;
2078     if (m_projectMonitor->isActive()) {
2079         if (m_activeTimeline) {
2080             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2081             if (item) {
2082                 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
2083                 clip = item->baseClip();
2084             }
2085         }
2086     } else {
2087         clip = m_clipMonitor->activeClip();
2088         pos = m_clipMonitor->position();
2089     }
2090     if (!clip) {
2091         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2092         return;
2093     }
2094
2095     QString id = clip->getId();
2096     QString comment = clip->markerComment(pos);
2097     if (comment.isEmpty()) {
2098         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
2099         return;
2100     }
2101     m_activeTimeline->projectView()->slotDeleteClipMarker(comment, id, pos);
2102     if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
2103
2104 }
2105
2106 void MainWindow::slotDeleteAllClipMarkers()
2107 {
2108     DocClipBase *clip = NULL;
2109     if (m_projectMonitor->isActive()) {
2110         if (m_activeTimeline) {
2111             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2112             if (item) {
2113                 clip = item->baseClip();
2114             }
2115         }
2116     } else {
2117         clip = m_clipMonitor->activeClip();
2118     }
2119     if (!clip) {
2120         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2121         return;
2122     }
2123     m_activeTimeline->projectView()->slotDeleteAllClipMarkers(clip->getId());
2124     if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
2125 }
2126
2127 void MainWindow::slotEditClipMarker()
2128 {
2129     DocClipBase *clip = NULL;
2130     GenTime pos;
2131     if (m_projectMonitor->isActive()) {
2132         if (m_activeTimeline) {
2133             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2134             if (item) {
2135                 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
2136                 clip = item->baseClip();
2137             }
2138         }
2139     } else {
2140         clip = m_clipMonitor->activeClip();
2141         pos = m_clipMonitor->position();
2142     }
2143     if (!clip) {
2144         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2145         return;
2146     }
2147
2148     QString id = clip->getId();
2149     QString oldcomment = clip->markerComment(pos);
2150     if (oldcomment.isEmpty()) {
2151         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
2152         return;
2153     }
2154
2155     CommentedTime marker(pos, oldcomment);
2156     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Edit Marker"), this);
2157     if (d.exec() == QDialog::Accepted) {
2158         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
2159         if (d.newMarker().time() != pos) {
2160             // remove old marker
2161             m_activeTimeline->projectView()->slotAddClipMarker(id, pos, QString());
2162         }
2163         if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
2164     }
2165 }
2166
2167 void MainWindow::slotAddGuide()
2168 {
2169     if (m_activeTimeline)
2170         m_activeTimeline->projectView()->slotAddGuide();
2171 }
2172
2173 void MainWindow::slotInsertSpace()
2174 {
2175     if (m_activeTimeline)
2176         m_activeTimeline->projectView()->slotInsertSpace();
2177 }
2178
2179 void MainWindow::slotRemoveSpace()
2180 {
2181     if (m_activeTimeline)
2182         m_activeTimeline->projectView()->slotRemoveSpace();
2183 }
2184
2185 void MainWindow::slotInsertTrack(int ix)
2186 {
2187     m_projectMonitor->activateMonitor();
2188     if (m_activeTimeline)
2189         m_activeTimeline->projectView()->slotInsertTrack(ix);
2190 }
2191
2192 void MainWindow::slotDeleteTrack(int ix)
2193 {
2194     m_projectMonitor->activateMonitor();
2195     if (m_activeTimeline)
2196         m_activeTimeline->projectView()->slotDeleteTrack(ix);
2197 }
2198
2199 void MainWindow::slotChangeTrack(int ix)
2200 {
2201     m_projectMonitor->activateMonitor();
2202     if (m_activeTimeline)
2203         m_activeTimeline->projectView()->slotChangeTrack(ix);
2204 }
2205
2206 void MainWindow::slotEditGuide()
2207 {
2208     if (m_activeTimeline)
2209         m_activeTimeline->projectView()->slotEditGuide();
2210 }
2211
2212 void MainWindow::slotDeleteGuide()
2213 {
2214     if (m_activeTimeline)
2215         m_activeTimeline->projectView()->slotDeleteGuide();
2216 }
2217
2218 void MainWindow::slotDeleteAllGuides()
2219 {
2220     if (m_activeTimeline)
2221         m_activeTimeline->projectView()->slotDeleteAllGuides();
2222 }
2223
2224 void MainWindow::slotCutTimelineClip()
2225 {
2226     if (m_activeTimeline) {
2227         m_activeTimeline->projectView()->cutSelectedClips();
2228     }
2229 }
2230
2231 void MainWindow::slotGroupClips()
2232 {
2233     if (m_activeTimeline) {
2234         m_activeTimeline->projectView()->groupClips();
2235     }
2236 }
2237
2238 void MainWindow::slotUnGroupClips()
2239 {
2240     if (m_activeTimeline) {
2241         m_activeTimeline->projectView()->groupClips(false);
2242     }
2243 }
2244
2245 void MainWindow::slotAddProjectClip(KUrl url)
2246 {
2247     if (m_activeDocument)
2248         m_activeDocument->slotAddClipFile(url, QString());
2249 }
2250
2251 void MainWindow::slotAddTransition(QAction *result)
2252 {
2253     if (!result) return;
2254     QStringList info = result->data().toStringList();
2255     if (info.isEmpty()) return;
2256     QDomElement transition = transitions.getEffectByTag(info.at(1), info.at(2));
2257     if (m_activeTimeline && !transition.isNull()) {
2258         m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(transition.cloneNode().toElement());
2259     }
2260 }
2261
2262 void MainWindow::slotAddVideoEffect(QAction *result)
2263 {
2264     if (!result) return;
2265     QStringList info = result->data().toStringList();
2266     if (info.isEmpty()) return;
2267     QDomElement effect = videoEffects.getEffectByTag(info.at(1), info.at(2));
2268     slotAddEffect(effect);
2269 }
2270
2271 void MainWindow::slotAddAudioEffect(QAction *result)
2272 {
2273     if (!result) return;
2274     QStringList info = result->data().toStringList();
2275     if (info.isEmpty()) return;
2276     QDomElement effect = audioEffects.getEffectByTag(info.at(1), info.at(2));
2277     slotAddEffect(effect);
2278 }
2279
2280 void MainWindow::slotAddCustomEffect(QAction *result)
2281 {
2282     if (!result) return;
2283     QStringList info = result->data().toStringList();
2284     if (info.isEmpty()) return;
2285     QDomElement effect = customEffects.getEffectByTag(info.at(1), info.at(2));
2286     slotAddEffect(effect);
2287 }
2288
2289 void MainWindow::slotZoomIn()
2290 {
2291     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
2292 }
2293
2294 void MainWindow::slotZoomOut()
2295 {
2296     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
2297 }
2298
2299 void MainWindow::slotFitZoom()
2300 {
2301     if (m_activeTimeline) {
2302         m_zoomSlider->setValue(m_activeTimeline->fitZoom());
2303     }
2304 }
2305
2306 void MainWindow::slotGotProgressInfo(const QString &message, int progress)
2307 {
2308     m_statusProgressBar->setValue(progress);
2309     if (progress >= 0) {
2310         if (!message.isEmpty()) m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
2311         m_statusProgressBar->setVisible(true);
2312     } else {
2313         m_messageLabel->setMessage(QString(), DefaultMessage);
2314         m_statusProgressBar->setVisible(false);
2315     }
2316 }
2317
2318 void MainWindow::slotShowClipProperties(DocClipBase *clip)
2319 {
2320     if (clip->clipType() == TEXT) {
2321         QString titlepath = m_activeDocument->projectFolder().path() + "/titles/";
2322         QString path = clip->getProperty("resource");
2323         TitleWidget *dia_ui = new TitleWidget(KUrl(), titlepath, m_projectMonitor->render, this);
2324         QDomDocument doc;
2325         doc.setContent(clip->getProperty("xmldata"));
2326         dia_ui->setXml(doc);
2327         if (dia_ui->exec() == QDialog::Accepted) {
2328             QImage pix = dia_ui->renderedPixmap();
2329             pix.save(path);
2330             //slotAddClipFile(KUrl("/tmp/kdenlivetitle.png"), QString(), -1);
2331             //m_clipManager->slotEditTextClipFile(id, dia_ui->xml().toString());
2332             QMap <QString, QString> newprops;
2333             newprops.insert("xmldata", dia_ui->xml().toString());
2334             newprops.insert("frame_size", QString::number(pix.width()) + 'x' + QString::number(pix.height()));
2335             EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
2336             m_activeDocument->commandStack()->push(command);
2337             m_clipMonitor->refreshMonitor(true);
2338             m_activeDocument->setModified(true);
2339         }
2340         delete dia_ui;
2341
2342         //m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
2343         return;
2344     }
2345     ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
2346     connect(&dia, SIGNAL(addMarker(const QString &, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(const QString &, GenTime, QString)));
2347     if (dia.exec() == QDialog::Accepted) {
2348         EditClipCommand *command = new EditClipCommand(m_projectList, dia.clipId(), clip->properties(), dia.properties(), true);
2349         m_activeDocument->commandStack()->push(command);
2350
2351         //m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
2352         if (dia.needsTimelineRefresh()) {
2353             // update clip occurences in timeline
2354             m_activeTimeline->projectView()->slotUpdateClip(dia.clipId());
2355         }
2356     }
2357 }
2358
2359 void MainWindow::customEvent(QEvent* e)
2360 {
2361     if (e->type() == QEvent::User) {
2362         // The timeline playing position changed...
2363         kDebug() << "RECEIVED JOG EVEMNT!!!";
2364     }
2365 }
2366 void MainWindow::slotActivateEffectStackView()
2367 {
2368     m_effectStack->raiseWindow(m_effectStackDock);
2369 }
2370
2371 void MainWindow::slotActivateTransitionView(Transition *t)
2372 {
2373     if (t) m_transitionConfig->raiseWindow(m_transitionConfigDock);
2374 }
2375
2376 void MainWindow::slotSnapRewind()
2377 {
2378     if (m_projectMonitor->isActive()) {
2379         if (m_activeTimeline)
2380             m_activeTimeline->projectView()->slotSeekToPreviousSnap();
2381     } else m_clipMonitor->slotSeekToPreviousSnap();
2382 }
2383
2384 void MainWindow::slotSnapForward()
2385 {
2386     if (m_projectMonitor->isActive()) {
2387         if (m_activeTimeline)
2388             m_activeTimeline->projectView()->slotSeekToNextSnap();
2389     } else m_clipMonitor->slotSeekToNextSnap();
2390 }
2391
2392 void MainWindow::slotClipStart()
2393 {
2394     if (m_projectMonitor->isActive()) {
2395         if (m_activeTimeline)
2396             m_activeTimeline->projectView()->clipStart();
2397     }
2398 }
2399
2400 void MainWindow::slotClipEnd()
2401 {
2402     if (m_projectMonitor->isActive()) {
2403         if (m_activeTimeline)
2404             m_activeTimeline->projectView()->clipEnd();
2405     }
2406 }
2407
2408 void MainWindow::slotChangeTool(QAction * action)
2409 {
2410     if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
2411     else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
2412     else if (action == m_buttonSpacerTool) slotSetTool(SPACERTOOL);
2413 }
2414
2415 void MainWindow::slotSetTool(PROJECTTOOL tool)
2416 {
2417     if (m_activeDocument && m_activeTimeline) {
2418         //m_activeDocument->setTool(tool);
2419         m_activeTimeline->projectView()->setTool(tool);
2420     }
2421 }
2422
2423 void MainWindow::slotCopy()
2424 {
2425     if (!m_activeDocument || !m_activeTimeline) return;
2426     m_activeTimeline->projectView()->copyClip();
2427 }
2428
2429 void MainWindow::slotPaste()
2430 {
2431     if (!m_activeDocument || !m_activeTimeline) return;
2432     m_activeTimeline->projectView()->pasteClip();
2433 }
2434
2435 void MainWindow::slotPasteEffects()
2436 {
2437     if (!m_activeDocument || !m_activeTimeline) return;
2438     m_activeTimeline->projectView()->pasteClipEffects();
2439 }
2440
2441 void MainWindow::slotFind()
2442 {
2443     if (!m_activeDocument || !m_activeTimeline) return;
2444     m_projectSearch->setEnabled(false);
2445     m_findActivated = true;
2446     m_findString.clear();
2447     m_activeTimeline->projectView()->initSearchStrings();
2448     statusBar()->showMessage(i18n("Starting -- find text as you type"));
2449     m_findTimer.start(5000);
2450     qApp->installEventFilter(this);
2451 }
2452
2453 void MainWindow::slotFindNext()
2454 {
2455     if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString)) {
2456         statusBar()->showMessage(i18n("Found: %1", m_findString));
2457     } else {
2458         statusBar()->showMessage(i18n("Reached end of project"));
2459     }
2460     m_findTimer.start(4000);
2461 }
2462
2463 void MainWindow::findAhead()
2464 {
2465     if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
2466         m_projectSearchNext->setEnabled(true);
2467         statusBar()->showMessage(i18n("Found: %1", m_findString));
2468     } else {
2469         m_projectSearchNext->setEnabled(false);
2470         statusBar()->showMessage(i18n("Not found: %1", m_findString));
2471     }
2472 }
2473
2474 void MainWindow::findTimeout()
2475 {
2476     m_projectSearchNext->setEnabled(false);
2477     m_findActivated = false;
2478     m_findString.clear();
2479     statusBar()->showMessage(i18n("Find stopped"), 3000);
2480     if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
2481     m_projectSearch->setEnabled(true);
2482     removeEventFilter(this);
2483 }
2484
2485 void MainWindow::keyPressEvent(QKeyEvent *ke)
2486 {
2487     if (m_findActivated) {
2488         if (ke->key() == Qt::Key_Backspace) {
2489             m_findString = m_findString.left(m_findString.length() - 1);
2490
2491             if (!m_findString.isEmpty()) {
2492                 findAhead();
2493             } else {
2494                 findTimeout();
2495             }
2496
2497             m_findTimer.start(4000);
2498             ke->accept();
2499             return;
2500         } else if (ke->key() == Qt::Key_Escape) {
2501             findTimeout();
2502             ke->accept();
2503             return;
2504         } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
2505             m_findString += ke->text();
2506
2507             findAhead();
2508
2509             m_findTimer.start(4000);
2510             ke->accept();
2511             return;
2512         }
2513     } else KXmlGuiWindow::keyPressEvent(ke);
2514 }
2515
2516
2517 /** Gets called when the window gets hidden */
2518 void MainWindow::hideEvent(QHideEvent */*event*/)
2519 {
2520     // kDebug() << "I was hidden";
2521     // issue http://www.kdenlive.org/mantis/view.php?id=231
2522     if (isMinimized()) {
2523         // kDebug() << "I am minimized";
2524         if (m_monitorManager) m_monitorManager->stopActiveMonitor();
2525     }
2526 }
2527
2528 bool MainWindow::eventFilter(QObject *obj, QEvent *event)
2529 {
2530     if (m_findActivated) {
2531         if (event->type() == QEvent::ShortcutOverride) {
2532             QKeyEvent* ke = (QKeyEvent*) event;
2533             if (ke->text().trimmed().isEmpty()) return false;
2534             ke->accept();
2535             return true;
2536         } else return false;
2537     } else {
2538         // pass the event on to the parent class
2539         return QMainWindow::eventFilter(obj, event);
2540     }
2541 }
2542
2543 void MainWindow::slotSaveZone(Render *render, QPoint zone)
2544 {
2545     KDialog *dialog = new KDialog(this);
2546     dialog->setCaption("Save clip zone");
2547     dialog->setButtons(KDialog::Ok | KDialog::Cancel);
2548
2549     QWidget *widget = new QWidget(dialog);
2550     dialog->setMainWidget(widget);
2551
2552     QVBoxLayout *vbox = new QVBoxLayout(widget);
2553     QLabel *label1 = new QLabel(i18n("Save clip zone as:"), this);
2554     QString path = m_activeDocument->projectFolder().path();
2555     path.append("/");
2556     path.append("untitled.mlt");
2557     KUrlRequester *url = new KUrlRequester(KUrl(path), this);
2558     url->setFilter("video/mlt-playlist");
2559     QLabel *label2 = new QLabel(i18n("Description:"), this);
2560     KLineEdit *edit = new KLineEdit(this);
2561     vbox->addWidget(label1);
2562     vbox->addWidget(url);
2563     vbox->addWidget(label2);
2564     vbox->addWidget(edit);
2565     if (dialog->exec() == QDialog::Accepted) render->saveZone(url->url(), edit->text(), zone);
2566
2567 }
2568
2569 void MainWindow::slotSetInPoint()
2570 {
2571     if (m_clipMonitor->isActive()) {
2572         m_clipMonitor->slotSetZoneStart();
2573     } else m_activeTimeline->projectView()->setInPoint();
2574 }
2575
2576 void MainWindow::slotSetOutPoint()
2577 {
2578     if (m_clipMonitor->isActive()) {
2579         m_clipMonitor->slotSetZoneEnd();
2580     } else m_activeTimeline->projectView()->setOutPoint();
2581 }
2582
2583 void MainWindow::slotGetNewLumaStuff()
2584 {
2585     //KNS::Entry::List download();
2586     KNS::Entry::List entries = KNS::Engine::download();
2587     // list of changed entries
2588     kDebug() << "// PARSING KNS";
2589     foreach(KNS::Entry* entry, entries) {
2590         // care only about installed ones
2591         if (entry->status() == KNS::Entry::Installed) {
2592             foreach(const QString &file, entry->installedFiles()) {
2593                 kDebug() << "// CURRENTLY INSTALLED: " << file;
2594             }
2595         }
2596     }
2597     qDeleteAll(entries);
2598     initEffects::refreshLumas();
2599     m_activeTimeline->projectView()->reloadTransitionLumas();
2600 }
2601
2602 void MainWindow::slotGetNewRenderStuff()
2603 {
2604     //KNS::Entry::List download();
2605
2606     KNS::Engine engine(0);
2607     if (engine.init("kdenlive_render.knsrc")) {
2608         KNS::Entry::List entries = engine.downloadDialogModal(this);
2609
2610         if (entries.size() > 0) {
2611             foreach(KNS::Entry* entry, entries) {
2612                 // care only about installed ones
2613                 if (entry->status() == KNS::Entry::Installed) {
2614                     foreach(const QString &file, entry->installedFiles()) {
2615                         kDebug() << "// CURRENTLY INSTALLED: " << file;
2616                     }
2617                 }
2618             }
2619         }
2620         if (m_renderWidget) m_renderWidget->reloadProfiles();
2621     }
2622 }
2623
2624 void MainWindow::slotGetNewMltProfileStuff()
2625 {
2626     //KNS::Entry::List download();
2627
2628     KNS::Engine engine(0);
2629     if (engine.init("kdenlive_mltprofiles.knsrc")) {
2630         KNS::Entry::List entries = engine.downloadDialogModal(this);
2631
2632         if (entries.size() > 0) {
2633             foreach(KNS::Entry* entry, entries) {
2634                 // care only about installed ones
2635                 if (entry->status() == KNS::Entry::Installed) {
2636                     foreach(const QString &file, entry->installedFiles()) {
2637                         kDebug() << "// CURRENTLY INSTALLED: " << file;
2638                     }
2639                 }
2640             }
2641
2642             // update the list of profiles in settings dialog
2643             KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
2644             if (d) d->checkProfile();
2645         }
2646     }
2647 }
2648
2649 void MainWindow::slotAutoTransition()
2650 {
2651     if (m_activeTimeline) m_activeTimeline->projectView()->autoTransition();
2652 }
2653
2654 void MainWindow::slotSplitAudio()
2655 {
2656     if (m_activeTimeline) m_activeTimeline->projectView()->splitAudio();
2657 }
2658
2659 void MainWindow::slotUpdateClipType(QAction *action)
2660 {
2661     if (m_activeTimeline) {
2662         if (action->data().toString() == "clip_audio_only") m_activeTimeline->projectView()->setAudioOnly();
2663         else if (action->data().toString() == "clip_video_only") m_activeTimeline->projectView()->setVideoOnly();
2664         else m_activeTimeline->projectView()->setAudioAndVideo();
2665     }
2666 }
2667
2668 void MainWindow::slotDvdWizard(const QString &url, const QString &profile)
2669 {
2670     DvdWizard *w = new DvdWizard(url, profile, this);
2671     w->exec();
2672 }
2673
2674 void MainWindow::slotShowTimeline(bool show)
2675 {
2676     if (show == false) {
2677         m_timelineState = saveState();
2678         centralWidget()->setHidden(true);
2679     } else {
2680         centralWidget()->setHidden(false);
2681         restoreState(m_timelineState);
2682     }
2683 }
2684
2685 void MainWindow::slotMaximizeCurrent(bool /*show*/)
2686 {
2687     //TODO: is there a way to maximize current widget?
2688     //if (show == true)
2689     {
2690         m_timelineState = saveState();
2691         QWidget *par = focusWidget()->parentWidget();
2692         while (par->parentWidget() && par->parentWidget() != this) {
2693             par = par->parentWidget();
2694         }
2695         kDebug() << "CURRENT WIDGET: " << par->objectName();
2696     }
2697     /*else {
2698     //centralWidget()->setHidden(false);
2699     //restoreState(m_timelineState);
2700     }*/
2701 }
2702
2703 void MainWindow::loadTranscoders()
2704 {
2705     QMenu *transMenu = static_cast<QMenu*>(factory()->container("transcoders", this));
2706     transMenu->clear();
2707
2708     KSharedConfigPtr config = KSharedConfig::openConfig("kdenlivetranscodingrc");
2709     KConfigGroup transConfig(config, "Transcoding");
2710     // read the entries
2711     QMap< QString, QString > profiles = transConfig.entryMap();
2712     QMapIterator<QString, QString> i(profiles);
2713     while (i.hasNext()) {
2714         i.next();
2715         QAction *a = transMenu->addAction(i.key());
2716         a->setData(i.value());
2717         connect(a, SIGNAL(triggered()), this, SLOT(slotTranscode()));
2718     }
2719 }
2720
2721 void MainWindow::slotTranscode(KUrl::List urls)
2722 {
2723     QString params;
2724     if (urls.isEmpty()) {
2725         urls.append(m_projectList->currentClipUrl());
2726         QAction *action = qobject_cast<QAction *>(sender());
2727         params = action->data().toString();
2728     }
2729     if (urls.isEmpty()) return;
2730     ClipTranscode *d = new ClipTranscode(urls, params);
2731     connect(d, SIGNAL(addClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
2732     d->show();
2733     //QProcess::startDetached("ffmpeg", parameters);
2734 }
2735
2736 void MainWindow::slotTranscodeClip()
2737 {
2738     KUrl::List urls = KFileDialog::getOpenUrls(KUrl("kfiledialog:///projectfolder"));
2739     if (urls.isEmpty()) return;
2740     slotTranscode(urls);
2741 }
2742
2743 #include "mainwindow.moc"