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