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