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