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