]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
Update transitions lumas when user installs a new one:
[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 Wipes..."), 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         projectFolder = KdenliveSettings::defaultprojectfolder();
1214     } else {
1215         ProjectSettings *w = new ProjectSettings(projectTracks.x(), projectTracks.y(), KdenliveSettings::defaultprojectfolder(), false, this);
1216         if (w->exec() != QDialog::Accepted) return;
1217         if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1218         KdenliveSettings::setVideothumbnails(w->enableVideoThumbs());
1219         m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1220         KdenliveSettings::setAudiothumbnails(w->enableAudioThumbs());
1221         m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1222         profileName = w->selectedProfile();
1223         projectFolder = w->selectedFolder();
1224         projectTracks = w->tracks();
1225         delete w;
1226     }
1227     KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, profileName, projectTracks, m_projectMonitor->render, this);
1228     doc->m_autosave = new KAutoSaveFile(KUrl(), doc);
1229     TrackView *trackView = new TrackView(doc, this);
1230     m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
1231     if (m_timelineArea->count() == 1) {
1232         connectDocumentInfo(doc);
1233         connectDocument(trackView, doc);
1234     } else m_timelineArea->setTabBarHidden(false);
1235     m_closeAction->setEnabled(m_timelineArea->count() > 1);
1236 }
1237
1238 void MainWindow::activateDocument()
1239 {
1240     if (m_timelineArea->currentWidget() == NULL) return;
1241     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1242     KdenliveDoc *currentDoc = currentTab->document();
1243     connectDocumentInfo(currentDoc);
1244     connectDocument(currentTab, currentDoc);
1245 }
1246
1247 void MainWindow::closeCurrentDocument()
1248 {
1249     QWidget *w = m_timelineArea->currentWidget();
1250     if (!w) return;
1251     // closing current document
1252     int ix = m_timelineArea->currentIndex() + 1;
1253     if (ix == m_timelineArea->count()) ix = 0;
1254     m_timelineArea->setCurrentIndex(ix);
1255     TrackView *tabToClose = (TrackView *) w;
1256     KdenliveDoc *docToClose = tabToClose->document();
1257     if (docToClose && docToClose->isModified()) {
1258         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document?"))) {
1259         case KMessageBox::Yes :
1260             // save document here. If saving fails, return false;
1261             if (saveFile() == false) return;
1262             break;
1263         case KMessageBox::Cancel :
1264             return;
1265             break;
1266         default:
1267             break;
1268         }
1269     }
1270     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
1271     if (m_timelineArea->count() == 1) {
1272         m_timelineArea->setTabBarHidden(true);
1273         m_closeAction->setEnabled(false);
1274     }
1275     if (docToClose == m_activeDocument) {
1276         delete m_activeDocument;
1277         m_activeDocument = NULL;
1278         m_effectStack->clear();
1279         m_transitionConfig->slotTransitionItemSelected(NULL, QPoint(), false);
1280     } else delete docToClose;
1281     if (w == m_activeTimeline) {
1282         delete m_activeTimeline;
1283         m_activeTimeline = NULL;
1284     } else delete w;
1285 }
1286
1287 bool MainWindow::saveFileAs(const QString &outputFileName)
1288 {
1289     QString currentSceneList;
1290     if (KdenliveSettings::dropbframes()) {
1291         KdenliveSettings::setDropbframes(false);
1292         m_activeDocument->clipManager()->updatePreviewSettings();
1293         currentSceneList = m_projectMonitor->sceneList();
1294         KdenliveSettings::setDropbframes(true);
1295         m_activeDocument->clipManager()->updatePreviewSettings();
1296     } else currentSceneList = m_projectMonitor->sceneList();
1297
1298     if (m_activeDocument->saveSceneList(outputFileName, currentSceneList) == false)
1299         return false;
1300
1301     // Save timeline thumbnails
1302     m_activeTimeline->projectView()->saveThumbnails();
1303     m_activeDocument->setUrl(KUrl(outputFileName));
1304     if (m_activeDocument->m_autosave == NULL) {
1305         m_activeDocument->m_autosave = new KAutoSaveFile(KUrl(outputFileName), this);
1306     } else m_activeDocument->m_autosave->setManagedFile(KUrl(outputFileName));
1307     setCaption(m_activeDocument->description());
1308     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1309     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
1310     m_activeDocument->setModified(false);
1311     m_fileOpenRecent->addUrl(KUrl(outputFileName));
1312     return true;
1313 }
1314
1315 bool MainWindow::saveFileAs()
1316 {
1317     // Check that the Kdenlive mime type is correctly installed
1318     QString mimetype = "application/x-kdenlive";
1319     KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
1320     if (!mime) mimetype = "*.kdenlive";
1321
1322     QString outputFile = KFileDialog::getSaveFileName(KUrl(), mimetype);
1323     if (outputFile.isEmpty()) return false;
1324     if (QFile::exists(outputFile)) {
1325         if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it?")) == KMessageBox::No) return false;
1326     }
1327     return saveFileAs(outputFile);
1328 }
1329
1330 bool MainWindow::saveFile()
1331 {
1332     if (!m_activeDocument) return true;
1333     if (m_activeDocument->url().isEmpty()) {
1334         return saveFileAs();
1335     } else {
1336         bool result = saveFileAs(m_activeDocument->url().path());
1337         m_activeDocument->m_autosave->resize(0);
1338         return result;
1339     }
1340 }
1341
1342 void MainWindow::openFile()
1343 {
1344     // Check that the Kdenlive mime type is correctly installed
1345     QString mimetype = "application/x-kdenlive";
1346     KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
1347     if (!mime) mimetype = "*.kdenlive";
1348
1349     KUrl url = KFileDialog::getOpenUrl(KUrl("kfiledialog:///projectfolder"), mimetype);
1350     if (url.isEmpty()) return;
1351     m_fileOpenRecent->addUrl(url);
1352     openFile(url);
1353 }
1354
1355 void MainWindow::openLastFile()
1356 {
1357     KSharedConfigPtr config = KGlobal::config();
1358     KUrl::List urls = m_fileOpenRecent->urls();
1359     //WARNING: this is buggy, we get a random url, not the last one. Bug in KRecentFileAction?
1360     if (urls.isEmpty()) newFile(false);
1361     else openFile(urls.last());
1362 }
1363
1364 void MainWindow::openFile(const KUrl &url)
1365 {
1366     // Check if the document is already opened
1367     const int ct = m_timelineArea->count();
1368     bool isOpened = false;
1369     int i;
1370     for (i = 0; i < ct; i++) {
1371         TrackView *tab = (TrackView *) m_timelineArea->widget(i);
1372         KdenliveDoc *doc = tab->document();
1373         if (doc->url() == url) {
1374             isOpened = true;
1375             break;
1376         }
1377     }
1378     if (isOpened) {
1379         m_timelineArea->setCurrentIndex(i);
1380         return;
1381     }
1382
1383     // Check for backup file
1384     QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::staleFiles(url);
1385     if (!staleFiles.isEmpty()) {
1386         if (KMessageBox::questionYesNo(this,
1387                                        i18n("Auto-saved files exist. Do you want to recover them now?"),
1388                                        i18n("File Recovery"),
1389                                        KGuiItem(i18n("Recover")), KGuiItem(i18n("Don't recover"))) == KMessageBox::Yes) {
1390             recoverFiles(staleFiles);
1391             return;
1392         } else {
1393             // remove the stale files
1394             foreach(KAutoSaveFile *stale, staleFiles) {
1395                 stale->open(QIODevice::ReadWrite);
1396                 delete stale;
1397             }
1398         }
1399     }
1400     if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1401     doOpenFile(url, NULL);
1402 }
1403
1404 void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale)
1405 {
1406     KdenliveDoc *doc = new KdenliveDoc(url, KUrl(), m_commandStack, QString(), QPoint(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks()), m_projectMonitor->render, this);
1407     if (stale == NULL) {
1408         stale = new KAutoSaveFile(url, doc);
1409         doc->m_autosave = stale;
1410     } else {
1411         doc->m_autosave = stale;
1412         doc->setUrl(stale->managedFile());
1413         doc->setModified(true);
1414         stale->setParent(doc);
1415     }
1416     connectDocumentInfo(doc);
1417     TrackView *trackView = new TrackView(doc, this);
1418     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
1419     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
1420     trackView->setDuration(trackView->duration());
1421     trackView->projectView()->initCursorPos(m_projectMonitor->render->seekPosition().frames(doc->fps()));
1422
1423     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
1424     slotGotProgressInfo(QString(), -1);
1425     m_clipMonitor->refreshMonitor(true);
1426     m_projectMonitor->adjustRulerSize(trackView->duration());
1427     m_projectMonitor->slotZoneMoved(trackView->inPoint(), trackView->outPoint());
1428 }
1429
1430 void MainWindow::recoverFiles(QList<KAutoSaveFile *> staleFiles)
1431 {
1432     if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1433     foreach(KAutoSaveFile *stale, staleFiles) {
1434         /*if (!stale->open(QIODevice::QIODevice::ReadOnly)) {
1435                   // show an error message; we could not steal the lockfile
1436                   // maybe another application got to the file before us?
1437                   delete stale;
1438                   continue;
1439         }*/
1440         kDebug() << "// OPENING RECOVERY: " << stale->fileName() << "\nMANAGED: " << stale->managedFile().path();
1441         // the stalefiles also contain ".lock" files so we must ignore them... bug in KAutoSaveFile?
1442         if (!stale->fileName().endsWith(".lock")) doOpenFile(KUrl(stale->fileName()), stale);
1443         else KIO::NetAccess::del(KUrl(stale->fileName()), this);
1444     }
1445 }
1446
1447
1448 void MainWindow::parseProfiles(const QString &mltPath)
1449 {
1450     // kDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
1451
1452     //KdenliveSettings::setDefaulttmpfolder();
1453     if (!mltPath.isEmpty()) {
1454         KdenliveSettings::setMltpath(mltPath + "/share/mlt/profiles/");
1455         KdenliveSettings::setRendererpath(mltPath + "/bin/melt");
1456     }
1457
1458     if (KdenliveSettings::mltpath().isEmpty()) {
1459         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
1460     }
1461     if (KdenliveSettings::rendererpath().isEmpty() || KdenliveSettings::rendererpath().endsWith("inigo")) {
1462         QString meltPath = QString(MLT_PREFIX) + QString("/bin/melt");
1463         if (!QFile::exists(meltPath))
1464             meltPath = KStandardDirs::findExe("melt");
1465         KdenliveSettings::setRendererpath(meltPath);
1466     }
1467     QStringList profilesFilter;
1468     profilesFilter << "*";
1469     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1470
1471     if (profilesList.isEmpty()) {
1472         // Cannot find MLT path, try finding melt
1473         QString profilePath = KdenliveSettings::rendererpath();
1474         if (!profilePath.isEmpty()) {
1475             profilePath = profilePath.section('/', 0, -3);
1476             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
1477             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1478         }
1479
1480         if (profilesList.isEmpty()) {
1481             // Cannot find the MLT profiles, ask for location
1482             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
1483             getUrl->fileDialog()->setMode(KFile::Directory);
1484             if (getUrl->exec() == QDialog::Rejected) {
1485                 ::exit(0);
1486             }
1487             KUrl mltPath = getUrl->selectedUrl();
1488             delete getUrl;
1489             if (mltPath.isEmpty()) ::exit(0);
1490             KdenliveSettings::setMltpath(mltPath.path());
1491             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1492         }
1493     }
1494
1495     if (KdenliveSettings::rendererpath().isEmpty()) {
1496         // Cannot find the MLT melt renderer, ask for location
1497         KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(QString(), i18n("Cannot find the melt program required for rendering (part of Mlt)"), this);
1498         if (getUrl->exec() == QDialog::Rejected) {
1499             ::exit(0);
1500         }
1501         KUrl rendererPath = getUrl->selectedUrl();
1502         delete getUrl;
1503         if (rendererPath.isEmpty()) ::exit(0);
1504         KdenliveSettings::setRendererpath(rendererPath.path());
1505     }
1506
1507     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
1508
1509     // Parse MLT profiles to build a list of available video formats
1510     if (profilesList.isEmpty()) parseProfiles();
1511 }
1512
1513
1514 void MainWindow::slotEditProfiles()
1515 {
1516     ProfilesDialog *w = new ProfilesDialog;
1517     if (w->exec() == QDialog::Accepted) {
1518         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
1519         if (d) d->checkProfile();
1520     }
1521     delete w;
1522 }
1523
1524 void MainWindow::slotEditProjectSettings()
1525 {
1526     QPoint p = m_activeDocument->getTracksCount();
1527     ProjectSettings *w = new ProjectSettings(p.x(), p.y(), m_activeDocument->projectFolder().path(), true, this);
1528
1529     if (w->exec() == QDialog::Accepted) {
1530         QString profile = w->selectedProfile();
1531         m_activeDocument->setProjectFolder(w->selectedFolder());
1532         if (m_renderWidget) m_renderWidget->setDocumentPath(w->selectedFolder().path());
1533         if (m_activeDocument->profilePath() != profile) {
1534             // Profile was changed
1535             double dar = m_activeDocument->dar();
1536             m_activeDocument->setProfilePath(profile);
1537             KdenliveSettings::setCurrent_profile(profile);
1538             KdenliveSettings::setProject_fps(m_activeDocument->fps());
1539             setCaption(m_activeDocument->description(), m_activeDocument->isModified());
1540             m_monitorManager->resetProfiles(m_activeDocument->timecode());
1541             if (m_renderWidget) m_renderWidget->setProfile(m_activeDocument->mltProfile());
1542             m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1543             m_activeDocument->clipManager()->resetProducersList(m_projectMonitor->render->producersList());
1544             if (dar != m_activeDocument->dar()) m_projectList->reloadClipThumbnails();
1545             // We need to desactivate & reactivate monitors to get a refresh
1546             m_monitorManager->switchMonitors();
1547         }
1548     }
1549     delete w;
1550 }
1551
1552 void MainWindow::slotRenderProject()
1553 {
1554     if (!m_renderWidget) {
1555         QString projectfolder = m_activeDocument ? m_activeDocument->projectFolder().path() : KdenliveSettings::defaultprojectfolder();
1556         m_renderWidget = new RenderWidget(projectfolder, this);
1557         connect(m_renderWidget, SIGNAL(doRender(const QStringList&, const QStringList&)), this, SLOT(slotDoRender(const QStringList&, const QStringList&)));
1558         connect(m_renderWidget, SIGNAL(abortProcess(const QString &)), this, SIGNAL(abortRenderJob(const QString &)));
1559         connect(m_renderWidget, SIGNAL(openDvdWizard(const QString &, const QString &)), this, SLOT(slotDvdWizard(const QString &, const QString &)));
1560         if (m_activeDocument) {
1561             m_renderWidget->setProfile(m_activeDocument->mltProfile());
1562             m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1563         }
1564     }
1565     /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1566     if (currentTab) m_renderWidget->setTimeline(currentTab);
1567     m_renderWidget->setDocument(m_activeDocument);*/
1568     m_renderWidget->show();
1569 }
1570
1571 void MainWindow::slotDoRender(const QStringList args, const QStringList overlay_args)
1572 {
1573     QString dest = args.at(0);
1574     QString render = args.at(1);
1575     QStringList avformat_args = args.at(2).split(' ');
1576     bool zoneOnly = args.at(3).toInt();
1577     bool playAfter = args.at(4).toInt();
1578     double guideStart = args.at(5).toDouble();
1579     double guideEnd = args.at(6).toDouble();
1580     bool resizeProfile = args.at(7).toInt();
1581     QString scriptExport = args.at(8);
1582     bool createChapterFile = args.at(9).toInt();
1583
1584     if (dest.isEmpty()) return;
1585     int in = 0;
1586     int out = 0;
1587
1588     if (m_activeTimeline && zoneOnly) {
1589         in = m_activeTimeline->inPoint();
1590         out = m_activeTimeline->outPoint();
1591     }
1592
1593     KTemporaryFile temp;
1594     temp.setAutoRemove(false);
1595     temp.setSuffix(".mlt");
1596     if (!scriptExport.isEmpty() || temp.open()) {
1597         if (KdenliveSettings::dropbframes()) {
1598             KdenliveSettings::setDropbframes(false);
1599             m_activeDocument->clipManager()->updatePreviewSettings();
1600             if (!scriptExport.isEmpty()) m_projectMonitor->saveSceneList(scriptExport + ".mlt");
1601             else m_projectMonitor->saveSceneList(temp.fileName());
1602             KdenliveSettings::setDropbframes(true);
1603             m_activeDocument->clipManager()->updatePreviewSettings();
1604         } else {
1605             if (!scriptExport.isEmpty()) m_projectMonitor->saveSceneList(scriptExport + ".mlt");
1606             else m_projectMonitor->saveSceneList(temp.fileName());
1607         }
1608
1609         QStringList args;
1610         if (scriptExport.isEmpty()) args << "-erase";
1611         if (KdenliveSettings::usekuiserver()) args << "-kuiserver";
1612         if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
1613         else if (guideStart != -1) {
1614             args << "in=" + QString::number(GenTime(guideStart).frames(m_activeDocument->fps())) << "out=" + QString::number(GenTime(guideEnd).frames(m_activeDocument->fps()));
1615         }
1616         if (!overlay_args.isEmpty()) args << "preargs=" + overlay_args.join(" ");
1617         QString videoPlayer = "-";
1618         if (playAfter) {
1619             videoPlayer = KdenliveSettings::defaultplayerapp();
1620             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."));
1621         }
1622         if (!QFile::exists(KdenliveSettings::rendererpath())) {
1623             KMessageBox::sorry(this, i18n("Cannot find the melt program required for rendering (part of Mlt)"));
1624             setRenderingProgress(dest, -3);
1625             return;
1626         }
1627         args << KdenliveSettings::rendererpath() << m_activeDocument->profilePath() << render << videoPlayer;
1628
1629         for (int i = 0; i < avformat_args.count(); i++) {
1630             if (avformat_args.at(i).startsWith("profile=")) {
1631                 if (avformat_args.at(i).section('=', 1) != m_activeDocument->profilePath()) resizeProfile = true;
1632                 break;
1633             }
1634         }
1635
1636         if (resizeProfile) {
1637             // The rendering profile is different from project profile, so use MLT's special producer_consumer
1638             if (scriptExport.isEmpty()) args << "consumer:" + temp.fileName();
1639             else args << "consumer:$SOURCE";
1640         } else {
1641             if (scriptExport.isEmpty()) args << temp.fileName();
1642             else args << "$SOURCE";
1643         }
1644         if (scriptExport.isEmpty()) args << dest;
1645         else args << "$TARGET";
1646         args << avformat_args;
1647         QString renderer = QCoreApplication::applicationDirPath() + QString("/kdenlive_render");
1648         if (!QFile::exists(renderer)) renderer = "kdenlive_render";
1649         if (scriptExport.isEmpty()) {
1650             QProcess::startDetached(renderer, args);
1651             KNotification::event("RenderStarted", i18n("Rendering <i>%1</i> started", dest), QPixmap(), this);
1652         } else {
1653             // Generate script file
1654             QFile file(scriptExport);
1655             if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1656                 KMessageBox::error(this, i18n("Cannot write to file %1", scriptExport));
1657                 return;
1658             }
1659
1660             QTextStream outStream(&file);
1661             outStream << "#! /bin/sh" << "\n" << "\n";
1662             outStream << "SOURCE=" << "\"" + scriptExport + ".mlt\"" << "\n";
1663             outStream << "TARGET=" << "\"" + dest + "\"" << "\n";
1664             outStream << renderer << " " << args.join(" ") << "\n" << "\n";
1665             if (file.error() != QFile::NoError) {
1666                 KMessageBox::error(this, i18n("Cannot write to file %1", scriptExport));
1667                 file.close();
1668                 return;
1669             }
1670             file.close();
1671             QFile::setPermissions(scriptExport, file.permissions() | QFile::ExeUser);
1672         }
1673
1674         if (createChapterFile) {
1675             QDomDocument doc;
1676             QDomElement chapters = doc.createElement("chapters");
1677             chapters.setAttribute("fps", m_activeDocument->fps());
1678             doc.appendChild(chapters);
1679
1680             QDomElement guidesxml = m_activeDocument->guidesXml();
1681             if (!zoneOnly) out = (int) GenTime(m_activeDocument->projectDuration()).frames(m_activeDocument->fps());
1682
1683             QDomNodeList nodes = guidesxml.elementsByTagName("guide");
1684             for (int i = 0; i < nodes.count(); i++) {
1685                 QDomElement e = nodes.item(i).toElement();
1686                 if (!e.isNull()) {
1687                     QString comment = e.attribute("comment");
1688                     int time = (int) GenTime(e.attribute("time").toDouble()).frames(m_activeDocument->fps());
1689                     if (time >= in && time < out) {
1690                         if (zoneOnly) time = time - in;
1691                         QDomElement chapter = doc.createElement("chapter");
1692                         chapters.appendChild(chapter);
1693                         chapter.setAttribute("title", comment);
1694                         chapter.setAttribute("time", time);
1695                     }
1696                 }
1697             }
1698             if (chapters.childNodes().count() > 0) {
1699                 if (m_activeTimeline->projectView()->hasGuide(out, 0) == -1) {
1700                     // Always insert a guide in pos 0
1701                     QDomElement chapter = doc.createElement("chapter");
1702                     chapters.insertBefore(chapter, QDomNode());
1703                     chapter.setAttribute("title", i18n("Start"));
1704                     chapter.setAttribute("time", "0");
1705                 }
1706                 // save chapters file
1707                 QFile file(dest + ".dvdchapter");
1708                 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1709                     kWarning() << "//////  ERROR writing DVD CHAPTER file: " << dest + ".dvdchapter";
1710                 } else {
1711                     file.write(doc.toString().toUtf8());
1712                     if (file.error() != QFile::NoError)
1713                         kWarning() << "//////  ERROR writing DVD CHAPTER file: " << dest + ".dvdchapter";
1714                     file.close();
1715                 }
1716             }
1717         }
1718     }
1719 }
1720
1721 void MainWindow::setRenderingProgress(const QString &url, int progress)
1722 {
1723     if (m_renderWidget) m_renderWidget->setRenderJob(url, progress);
1724 }
1725
1726 void MainWindow::setRenderingFinished(const QString &url, int status, const QString &error)
1727 {
1728     if (m_renderWidget) m_renderWidget->setRenderStatus(url, status, error);
1729 }
1730
1731 void MainWindow::slotUpdateMousePosition(int pos)
1732 {
1733     if (m_activeDocument)
1734         switch (m_timecodeFormat->currentIndex()) {
1735         case 0:
1736             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
1737             break;
1738         default:
1739             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
1740         }
1741 }
1742
1743 void MainWindow::slotUpdateDocumentState(bool modified)
1744 {
1745     if (!m_activeDocument) return;
1746     setCaption(m_activeDocument->description(), modified);
1747     m_saveAction->setEnabled(modified);
1748     if (modified) {
1749         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
1750         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
1751     } else {
1752         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
1753         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
1754     }
1755 }
1756
1757 void MainWindow::connectDocumentInfo(KdenliveDoc *doc)
1758 {
1759     if (m_activeDocument) {
1760         if (m_activeDocument == doc) return;
1761         disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1762     }
1763     connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1764 }
1765
1766 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc)   //changed
1767 {
1768     //m_projectMonitor->stop();
1769     m_closeAction->setEnabled(m_timelineArea->count() > 1);
1770     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
1771     if (m_activeDocument) {
1772         if (m_activeDocument == doc) return;
1773         if (m_activeTimeline) {
1774             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
1775             disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeTimeline, SLOT(slotSetZone(QPoint)));
1776             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
1777             disconnect(m_projectList, SIGNAL(projectModified()), m_activeDocument, SLOT(setModified()));
1778             disconnect(m_projectMonitor->render, SIGNAL(refreshDocumentProducers()), m_activeDocument, SLOT(checkProjectClips()));
1779
1780
1781             disconnect(m_activeDocument, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1782             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
1783             disconnect(m_activeDocument, SIGNAL(resetProjectList()), m_projectList, SLOT(slotResetProjectList()));
1784             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1785             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1786             disconnect(m_activeDocument, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1787             disconnect(m_activeDocument, SIGNAL(deleteTimelineClip(const QString &)), m_activeTimeline, SLOT(slotDeleteClip(const QString &)));
1788             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), m_effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
1789             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
1790             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*, QPoint, bool)), m_transitionConfig, SLOT(slotTransitionItemSelected(Transition*, QPoint, bool)));
1791             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*, QPoint, bool)), this, SLOT(slotActivateTransitionView(Transition *)));
1792             disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
1793             disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1794             disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1795             disconnect(m_activeTimeline, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1796             disconnect(m_activeTimeline, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
1797             disconnect(m_activeTimeline, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
1798             disconnect(m_activeTimeline, SIGNAL(changeTrack(int)), this, SLOT(slotChangeTrack(int)));
1799             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1800             disconnect(m_effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1801             disconnect(m_effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1802             disconnect(m_effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1803             disconnect(m_effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), m_activeTimeline->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1804             disconnect(m_effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1805             disconnect(m_effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1806             disconnect(m_transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), m_activeTimeline->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1807             disconnect(m_transitionConfig, SIGNAL(seekTimeline(int)), m_activeTimeline->projectView() , SLOT(setCursorPos(int)));
1808             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1809             disconnect(m_activeTimeline, SIGNAL(zoneMoved(int, int)), this, SLOT(slotZoneMoved(int, int)));
1810             disconnect(m_projectList, SIGNAL(loadingIsOver()), m_activeTimeline->projectView(), SLOT(slotUpdateAllThumbs()));
1811             m_effectStack->clear();
1812         }
1813         //m_activeDocument->setRenderer(NULL);
1814         disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1815         m_clipMonitor->stop();
1816     }
1817     KdenliveSettings::setCurrent_profile(doc->profilePath());
1818     KdenliveSettings::setProject_fps(doc->fps());
1819     m_monitorManager->resetProfiles(doc->timecode());
1820     m_projectList->setDocument(doc);
1821     m_transitionConfig->updateProjectFormat(doc->mltProfile(), doc->timecode(), trackView->tracksNumber());
1822     m_effectStack->updateProjectFormat(doc->mltProfile(), doc->timecode());
1823     connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1824     connect(m_projectList, SIGNAL(projectModified()), doc, SLOT(setModified()));
1825     connect(m_projectList, SIGNAL(clipNameChanged(const QString, const QString)), trackView->projectView(), SLOT(clipNameChanged(const QString, const QString)));
1826
1827
1828     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1829     connect(trackView, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
1830     connect(trackView, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
1831     connect(trackView, SIGNAL(changeTrack(int)), this, SLOT(slotChangeTrack(int)));
1832     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
1833     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
1834     connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), trackView, SLOT(slotSetZone(QPoint)));
1835     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
1836     connect(m_projectMonitor->render, SIGNAL(refreshDocumentProducers()), doc, SLOT(checkProjectClips()));
1837     connect(doc, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
1838     connect(doc, SIGNAL(resetProjectList()), m_projectList, SLOT(slotResetProjectList()));
1839     connect(doc, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1840     connect(doc, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1841     connect(doc, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1842
1843     connect(doc, SIGNAL(deleteTimelineClip(const QString &)), trackView, SLOT(slotDeleteClip(const QString &)));
1844     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1845     connect(doc, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1846
1847
1848     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), m_effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
1849     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
1850     connect(trackView, SIGNAL(transitionItemSelected(Transition*, QPoint, bool)), m_transitionConfig, SLOT(slotTransitionItemSelected(Transition*, QPoint, bool)));
1851     connect(trackView, SIGNAL(transitionItemSelected(Transition*, QPoint, bool)), this, SLOT(slotActivateTransitionView(Transition *)));
1852     m_zoomSlider->setValue(doc->zoom());
1853     connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
1854     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
1855     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
1856     connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1857
1858     connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1859
1860
1861     connect(m_effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1862     connect(m_effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1863     connect(m_effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1864     connect(m_effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1865     connect(m_effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1866     connect(m_transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1867     connect(m_transitionConfig, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
1868     connect(m_effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1869
1870     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1871     connect(trackView, SIGNAL(zoneMoved(int, int)), this, SLOT(slotZoneMoved(int, int)));
1872     connect(m_projectList, SIGNAL(loadingIsOver()), trackView->projectView(), SLOT(slotUpdateAllThumbs()));
1873
1874     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu, m_clipTypeGroup);
1875     m_activeTimeline = trackView;
1876     if (m_renderWidget) {
1877         m_renderWidget->setProfile(doc->mltProfile());
1878         m_renderWidget->setDocumentPath(doc->projectFolder().path());
1879     }
1880     //doc->setRenderer(m_projectMonitor->render);
1881     m_commandStack->setActiveStack(doc->commandStack());
1882     KdenliveSettings::setProject_display_ratio(doc->dar());
1883     m_projectList->updateAllClips();
1884     //doc->clipManager()->checkAudioThumbs();
1885
1886     //m_overView->setScene(trackView->projectScene());
1887     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
1888     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
1889
1890     setCaption(doc->description(), doc->isModified());
1891     m_saveAction->setEnabled(doc->isModified());
1892     m_activeDocument = doc;
1893     if (KdenliveSettings::dropbframes()) slotUpdatePreviewSettings();
1894
1895     // set tool to select tool
1896     m_buttonSelectTool->setChecked(true);
1897 }
1898
1899 void MainWindow::slotZoneMoved(int start, int end)
1900 {
1901     m_activeDocument->setZone(start, end);
1902     m_projectMonitor->slotZoneMoved(start, end);
1903 }
1904
1905 void MainWindow::slotGuidesUpdated()
1906 {
1907     if (m_renderWidget) m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1908 }
1909
1910 void MainWindow::slotPreferences(int page, int option)
1911 {
1912     //An instance of your dialog could be already created and could be
1913     // cached, in which case you want to display the cached dialog
1914     // instead of creating another one
1915     if (KConfigDialog::showDialog("settings")) {
1916         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
1917         if (page != -1) d->showPage(page, option);
1918         return;
1919     }
1920
1921     // KConfigDialog didn't find an instance of this dialog, so lets
1922     // create it :
1923     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
1924     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
1925     connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(slotResetProfiles()));
1926     connect(dialog, SIGNAL(updatePreviewSettings()), this, SLOT(slotUpdatePreviewSettings()));
1927     connect(dialog, SIGNAL(updateCaptureFolder()), m_recMonitor, SLOT(slotUpdateCaptureFolder()));
1928     //connect(dialog, SIGNAL(updatePreviewSettings()), this, SLOT(slotUpdatePreviewSettings()));
1929     dialog->show();
1930     if (page != -1) dialog->showPage(page, option);
1931 }
1932
1933 void MainWindow::slotUpdatePreviewSettings()
1934 {
1935     if (m_activeDocument) {
1936         m_clipMonitor->slotSetXml(NULL, 0);
1937         m_activeDocument->updatePreviewSettings();
1938     }
1939 }
1940
1941 void MainWindow::updateConfiguration()
1942 {
1943     //TODO: we should apply settings to all projects, not only the current one
1944     if (m_activeTimeline) {
1945         m_activeTimeline->refresh();
1946         m_activeTimeline->projectView()->checkAutoScroll();
1947         m_activeTimeline->projectView()->checkTrackHeight();
1948         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1949     }
1950     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1951     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1952
1953     // Update list of transcoding profiles
1954     loadTranscoders();
1955 #ifndef NO_JOGSHUTTLE
1956     activateShuttleDevice();
1957 #endif /* NO_JOGSHUTTLE */
1958
1959 }
1960
1961
1962 void MainWindow::slotSwitchVideoThumbs()
1963 {
1964     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
1965     if (m_activeTimeline) {
1966         m_activeTimeline->projectView()->slotUpdateAllThumbs();
1967     }
1968     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1969 }
1970
1971 void MainWindow::slotSwitchAudioThumbs()
1972 {
1973     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
1974     if (m_activeTimeline) {
1975         m_activeTimeline->refresh();
1976         m_activeTimeline->projectView()->checkAutoScroll();
1977         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1978     }
1979     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1980 }
1981
1982 void MainWindow::slotSwitchMarkersComments()
1983 {
1984     KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
1985     if (m_activeTimeline) {
1986         m_activeTimeline->refresh();
1987     }
1988     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
1989 }
1990
1991 void MainWindow::slotSwitchSnap()
1992 {
1993     KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
1994     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
1995 }
1996
1997
1998 void MainWindow::slotDeleteTimelineClip()
1999 {
2000     if (QApplication::focusWidget()->parentWidget()->parentWidget() == m_projectListDock) m_projectList->slotRemoveClip();
2001     else if (m_activeTimeline) {
2002         m_activeTimeline->projectView()->deleteSelectedClips();
2003     }
2004 }
2005
2006 void MainWindow::slotChangeClipSpeed()
2007 {
2008     if (m_activeTimeline) {
2009         m_activeTimeline->projectView()->changeClipSpeed();
2010     }
2011 }
2012
2013 void MainWindow::slotAddClipMarker()
2014 {
2015     DocClipBase *clip = NULL;
2016     GenTime pos;
2017     if (m_projectMonitor->isActive()) {
2018         if (m_activeTimeline) {
2019             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2020             if (item) {
2021                 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
2022                 clip = item->baseClip();
2023             }
2024         }
2025     } else {
2026         clip = m_clipMonitor->activeClip();
2027         pos = m_clipMonitor->position();
2028     }
2029     if (!clip) {
2030         m_messageLabel->setMessage(i18n("Cannot find clip to add marker"), ErrorMessage);
2031         return;
2032     }
2033     QString id = clip->getId();
2034     CommentedTime marker(pos, i18n("Marker"));
2035     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Add Marker"), this);
2036     if (d.exec() == QDialog::Accepted) {
2037         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
2038     }
2039     if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
2040 }
2041
2042 void MainWindow::slotDeleteClipMarker()
2043 {
2044     DocClipBase *clip = NULL;
2045     GenTime pos;
2046     if (m_projectMonitor->isActive()) {
2047         if (m_activeTimeline) {
2048             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2049             if (item) {
2050                 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
2051                 clip = item->baseClip();
2052             }
2053         }
2054     } else {
2055         clip = m_clipMonitor->activeClip();
2056         pos = m_clipMonitor->position();
2057     }
2058     if (!clip) {
2059         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2060         return;
2061     }
2062
2063     QString id = clip->getId();
2064     QString comment = clip->markerComment(pos);
2065     if (comment.isEmpty()) {
2066         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
2067         return;
2068     }
2069     m_activeTimeline->projectView()->slotDeleteClipMarker(comment, id, pos);
2070     if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
2071
2072 }
2073
2074 void MainWindow::slotDeleteAllClipMarkers()
2075 {
2076     DocClipBase *clip = NULL;
2077     if (m_projectMonitor->isActive()) {
2078         if (m_activeTimeline) {
2079             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2080             if (item) {
2081                 clip = item->baseClip();
2082             }
2083         }
2084     } else {
2085         clip = m_clipMonitor->activeClip();
2086     }
2087     if (!clip) {
2088         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2089         return;
2090     }
2091     m_activeTimeline->projectView()->slotDeleteAllClipMarkers(clip->getId());
2092     if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
2093 }
2094
2095 void MainWindow::slotEditClipMarker()
2096 {
2097     DocClipBase *clip = NULL;
2098     GenTime pos;
2099     if (m_projectMonitor->isActive()) {
2100         if (m_activeTimeline) {
2101             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2102             if (item) {
2103                 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
2104                 clip = item->baseClip();
2105             }
2106         }
2107     } else {
2108         clip = m_clipMonitor->activeClip();
2109         pos = m_clipMonitor->position();
2110     }
2111     if (!clip) {
2112         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2113         return;
2114     }
2115
2116     QString id = clip->getId();
2117     QString oldcomment = clip->markerComment(pos);
2118     if (oldcomment.isEmpty()) {
2119         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
2120         return;
2121     }
2122
2123     CommentedTime marker(pos, oldcomment);
2124     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Edit Marker"), this);
2125     if (d.exec() == QDialog::Accepted) {
2126         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
2127         if (d.newMarker().time() != pos) {
2128             // remove old marker
2129             m_activeTimeline->projectView()->slotAddClipMarker(id, pos, QString());
2130         }
2131         if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
2132     }
2133 }
2134
2135 void MainWindow::slotAddGuide()
2136 {
2137     if (m_activeTimeline)
2138         m_activeTimeline->projectView()->slotAddGuide();
2139 }
2140
2141 void MainWindow::slotInsertSpace()
2142 {
2143     if (m_activeTimeline)
2144         m_activeTimeline->projectView()->slotInsertSpace();
2145 }
2146
2147 void MainWindow::slotRemoveSpace()
2148 {
2149     if (m_activeTimeline)
2150         m_activeTimeline->projectView()->slotRemoveSpace();
2151 }
2152
2153 void MainWindow::slotInsertTrack(int ix)
2154 {
2155     m_projectMonitor->activateMonitor();
2156     if (m_activeTimeline)
2157         m_activeTimeline->projectView()->slotInsertTrack(ix);
2158 }
2159
2160 void MainWindow::slotDeleteTrack(int ix)
2161 {
2162     m_projectMonitor->activateMonitor();
2163     if (m_activeTimeline)
2164         m_activeTimeline->projectView()->slotDeleteTrack(ix);
2165 }
2166
2167 void MainWindow::slotChangeTrack(int ix)
2168 {
2169     m_projectMonitor->activateMonitor();
2170     if (m_activeTimeline)
2171         m_activeTimeline->projectView()->slotChangeTrack(ix);
2172 }
2173
2174 void MainWindow::slotEditGuide()
2175 {
2176     if (m_activeTimeline)
2177         m_activeTimeline->projectView()->slotEditGuide();
2178 }
2179
2180 void MainWindow::slotDeleteGuide()
2181 {
2182     if (m_activeTimeline)
2183         m_activeTimeline->projectView()->slotDeleteGuide();
2184 }
2185
2186 void MainWindow::slotDeleteAllGuides()
2187 {
2188     if (m_activeTimeline)
2189         m_activeTimeline->projectView()->slotDeleteAllGuides();
2190 }
2191
2192 void MainWindow::slotCutTimelineClip()
2193 {
2194     if (m_activeTimeline) {
2195         m_activeTimeline->projectView()->cutSelectedClips();
2196     }
2197 }
2198
2199 void MainWindow::slotGroupClips()
2200 {
2201     if (m_activeTimeline) {
2202         m_activeTimeline->projectView()->groupClips();
2203     }
2204 }
2205
2206 void MainWindow::slotUnGroupClips()
2207 {
2208     if (m_activeTimeline) {
2209         m_activeTimeline->projectView()->groupClips(false);
2210     }
2211 }
2212
2213 void MainWindow::slotAddProjectClip(KUrl url)
2214 {
2215     if (m_activeDocument)
2216         m_activeDocument->slotAddClipFile(url, QString());
2217 }
2218
2219 void MainWindow::slotAddTransition(QAction *result)
2220 {
2221     if (!result) return;
2222     QStringList info = result->data().toStringList();
2223     if (info.isEmpty()) return;
2224     QDomElement transition = transitions.getEffectByTag(info.at(1), info.at(2));
2225     if (m_activeTimeline && !transition.isNull()) {
2226         m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(transition.cloneNode().toElement());
2227     }
2228 }
2229
2230 void MainWindow::slotAddVideoEffect(QAction *result)
2231 {
2232     if (!result) return;
2233     QStringList info = result->data().toStringList();
2234     if (info.isEmpty()) return;
2235     QDomElement effect = videoEffects.getEffectByTag(info.at(1), info.at(2));
2236     slotAddEffect(effect);
2237 }
2238
2239 void MainWindow::slotAddAudioEffect(QAction *result)
2240 {
2241     if (!result) return;
2242     QStringList info = result->data().toStringList();
2243     if (info.isEmpty()) return;
2244     QDomElement effect = audioEffects.getEffectByTag(info.at(1), info.at(2));
2245     slotAddEffect(effect);
2246 }
2247
2248 void MainWindow::slotAddCustomEffect(QAction *result)
2249 {
2250     if (!result) return;
2251     QStringList info = result->data().toStringList();
2252     if (info.isEmpty()) return;
2253     QDomElement effect = customEffects.getEffectByTag(info.at(1), info.at(2));
2254     slotAddEffect(effect);
2255 }
2256
2257 void MainWindow::slotZoomIn()
2258 {
2259     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
2260 }
2261
2262 void MainWindow::slotZoomOut()
2263 {
2264     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
2265 }
2266
2267 void MainWindow::slotFitZoom()
2268 {
2269     if (m_activeTimeline) {
2270         m_zoomSlider->setValue(m_activeTimeline->fitZoom());
2271     }
2272 }
2273
2274 void MainWindow::slotGotProgressInfo(const QString &message, int progress)
2275 {
2276     m_statusProgressBar->setValue(progress);
2277     if (progress >= 0) {
2278         if (!message.isEmpty()) m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
2279         m_statusProgressBar->setVisible(true);
2280     } else {
2281         m_messageLabel->setMessage(QString(), DefaultMessage);
2282         m_statusProgressBar->setVisible(false);
2283     }
2284 }
2285
2286 void MainWindow::slotShowClipProperties(DocClipBase *clip)
2287 {
2288     if (clip->clipType() == TEXT) {
2289         QString titlepath = m_activeDocument->projectFolder().path() + "/titles/";
2290         QString path = clip->getProperty("resource");
2291         TitleWidget *dia_ui = new TitleWidget(KUrl(), titlepath, m_projectMonitor->render, this);
2292         QDomDocument doc;
2293         doc.setContent(clip->getProperty("xmldata"));
2294         dia_ui->setXml(doc);
2295         if (dia_ui->exec() == QDialog::Accepted) {
2296             QImage pix = dia_ui->renderedPixmap();
2297             pix.save(path);
2298             //slotAddClipFile(KUrl("/tmp/kdenlivetitle.png"), QString(), -1);
2299             //m_clipManager->slotEditTextClipFile(id, dia_ui->xml().toString());
2300             QMap <QString, QString> newprops;
2301             newprops.insert("xmldata", dia_ui->xml().toString());
2302             newprops.insert("frame_size", QString::number(pix.width()) + 'x' + QString::number(pix.height()));
2303             EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
2304             m_activeDocument->commandStack()->push(command);
2305             m_clipMonitor->refreshMonitor(true);
2306             m_activeDocument->setModified(true);
2307         }
2308         delete dia_ui;
2309
2310         //m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
2311         return;
2312     }
2313     ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
2314     connect(&dia, SIGNAL(addMarker(const QString &, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(const QString &, GenTime, QString)));
2315     if (dia.exec() == QDialog::Accepted) {
2316         EditClipCommand *command = new EditClipCommand(m_projectList, dia.clipId(), clip->properties(), dia.properties(), true);
2317         m_activeDocument->commandStack()->push(command);
2318
2319         //m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
2320         if (dia.needsTimelineRefresh()) {
2321             // update clip occurences in timeline
2322             m_activeTimeline->projectView()->slotUpdateClip(dia.clipId());
2323         }
2324     }
2325 }
2326
2327 void MainWindow::customEvent(QEvent* e)
2328 {
2329     if (e->type() == QEvent::User) {
2330         // The timeline playing position changed...
2331         kDebug() << "RECEIVED JOG EVEMNT!!!";
2332     }
2333 }
2334 void MainWindow::slotActivateEffectStackView()
2335 {
2336     m_effectStack->raiseWindow(m_effectStackDock);
2337 }
2338
2339 void MainWindow::slotActivateTransitionView(Transition *t)
2340 {
2341     if (t) m_transitionConfig->raiseWindow(m_transitionConfigDock);
2342 }
2343
2344 void MainWindow::slotSnapRewind()
2345 {
2346     if (m_projectMonitor->isActive()) {
2347         if (m_activeTimeline)
2348             m_activeTimeline->projectView()->slotSeekToPreviousSnap();
2349     } else m_clipMonitor->slotSeekToPreviousSnap();
2350 }
2351
2352 void MainWindow::slotSnapForward()
2353 {
2354     if (m_projectMonitor->isActive()) {
2355         if (m_activeTimeline)
2356             m_activeTimeline->projectView()->slotSeekToNextSnap();
2357     } else m_clipMonitor->slotSeekToNextSnap();
2358 }
2359
2360 void MainWindow::slotClipStart()
2361 {
2362     if (m_projectMonitor->isActive()) {
2363         if (m_activeTimeline)
2364             m_activeTimeline->projectView()->clipStart();
2365     }
2366 }
2367
2368 void MainWindow::slotClipEnd()
2369 {
2370     if (m_projectMonitor->isActive()) {
2371         if (m_activeTimeline)
2372             m_activeTimeline->projectView()->clipEnd();
2373     }
2374 }
2375
2376 void MainWindow::slotChangeTool(QAction * action)
2377 {
2378     if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
2379     else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
2380     else if (action == m_buttonSpacerTool) slotSetTool(SPACERTOOL);
2381 }
2382
2383 void MainWindow::slotSetTool(PROJECTTOOL tool)
2384 {
2385     if (m_activeDocument && m_activeTimeline) {
2386         //m_activeDocument->setTool(tool);
2387         m_activeTimeline->projectView()->setTool(tool);
2388     }
2389 }
2390
2391 void MainWindow::slotCopy()
2392 {
2393     if (!m_activeDocument || !m_activeTimeline) return;
2394     m_activeTimeline->projectView()->copyClip();
2395 }
2396
2397 void MainWindow::slotPaste()
2398 {
2399     if (!m_activeDocument || !m_activeTimeline) return;
2400     m_activeTimeline->projectView()->pasteClip();
2401 }
2402
2403 void MainWindow::slotPasteEffects()
2404 {
2405     if (!m_activeDocument || !m_activeTimeline) return;
2406     m_activeTimeline->projectView()->pasteClipEffects();
2407 }
2408
2409 void MainWindow::slotFind()
2410 {
2411     if (!m_activeDocument || !m_activeTimeline) return;
2412     m_projectSearch->setEnabled(false);
2413     m_findActivated = true;
2414     m_findString.clear();
2415     m_activeTimeline->projectView()->initSearchStrings();
2416     statusBar()->showMessage(i18n("Starting -- find text as you type"));
2417     m_findTimer.start(5000);
2418     qApp->installEventFilter(this);
2419 }
2420
2421 void MainWindow::slotFindNext()
2422 {
2423     if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString)) {
2424         statusBar()->showMessage(i18n("Found: %1", m_findString));
2425     } else {
2426         statusBar()->showMessage(i18n("Reached end of project"));
2427     }
2428     m_findTimer.start(4000);
2429 }
2430
2431 void MainWindow::findAhead()
2432 {
2433     if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
2434         m_projectSearchNext->setEnabled(true);
2435         statusBar()->showMessage(i18n("Found: %1", m_findString));
2436     } else {
2437         m_projectSearchNext->setEnabled(false);
2438         statusBar()->showMessage(i18n("Not found: %1", m_findString));
2439     }
2440 }
2441
2442 void MainWindow::findTimeout()
2443 {
2444     m_projectSearchNext->setEnabled(false);
2445     m_findActivated = false;
2446     m_findString.clear();
2447     statusBar()->showMessage(i18n("Find stopped"), 3000);
2448     if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
2449     m_projectSearch->setEnabled(true);
2450     removeEventFilter(this);
2451 }
2452
2453 void MainWindow::keyPressEvent(QKeyEvent *ke)
2454 {
2455     if (m_findActivated) {
2456         if (ke->key() == Qt::Key_Backspace) {
2457             m_findString = m_findString.left(m_findString.length() - 1);
2458
2459             if (!m_findString.isEmpty()) {
2460                 findAhead();
2461             } else {
2462                 findTimeout();
2463             }
2464
2465             m_findTimer.start(4000);
2466             ke->accept();
2467             return;
2468         } else if (ke->key() == Qt::Key_Escape) {
2469             findTimeout();
2470             ke->accept();
2471             return;
2472         } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
2473             m_findString += ke->text();
2474
2475             findAhead();
2476
2477             m_findTimer.start(4000);
2478             ke->accept();
2479             return;
2480         }
2481     } else KXmlGuiWindow::keyPressEvent(ke);
2482 }
2483
2484
2485 /** Gets called when the window gets hidden */
2486 void MainWindow::hideEvent(QHideEvent */*event*/)
2487 {
2488     // kDebug() << "I was hidden";
2489     // issue http://www.kdenlive.org/mantis/view.php?id=231
2490     if (isMinimized()) {
2491         // kDebug() << "I am minimized";
2492         if (m_monitorManager) m_monitorManager->stopActiveMonitor();
2493     }
2494 }
2495
2496 bool MainWindow::eventFilter(QObject *obj, QEvent *event)
2497 {
2498     if (m_findActivated) {
2499         if (event->type() == QEvent::ShortcutOverride) {
2500             QKeyEvent* ke = (QKeyEvent*) event;
2501             if (ke->text().trimmed().isEmpty()) return false;
2502             ke->accept();
2503             return true;
2504         } else return false;
2505     } else {
2506         // pass the event on to the parent class
2507         return QMainWindow::eventFilter(obj, event);
2508     }
2509 }
2510
2511 void MainWindow::slotSaveZone(Render *render, QPoint zone)
2512 {
2513     KDialog *dialog = new KDialog(this);
2514     dialog->setCaption("Save clip zone");
2515     dialog->setButtons(KDialog::Ok | KDialog::Cancel);
2516
2517     QWidget *widget = new QWidget(dialog);
2518     dialog->setMainWidget(widget);
2519
2520     QVBoxLayout *vbox = new QVBoxLayout(widget);
2521     QLabel *label1 = new QLabel(i18n("Save clip zone as:"), this);
2522     QString path = m_activeDocument->projectFolder().path();
2523     path.append("/");
2524     path.append("untitled.mlt");
2525     KUrlRequester *url = new KUrlRequester(KUrl(path), this);
2526     url->setFilter("video/mlt-playlist");
2527     QLabel *label2 = new QLabel(i18n("Description:"), this);
2528     KLineEdit *edit = new KLineEdit(this);
2529     vbox->addWidget(label1);
2530     vbox->addWidget(url);
2531     vbox->addWidget(label2);
2532     vbox->addWidget(edit);
2533     if (dialog->exec() == QDialog::Accepted) render->saveZone(url->url(), edit->text(), zone);
2534
2535 }
2536
2537 void MainWindow::slotSetInPoint()
2538 {
2539     if (m_clipMonitor->isActive()) {
2540         m_clipMonitor->slotSetZoneStart();
2541     } else m_activeTimeline->projectView()->setInPoint();
2542 }
2543
2544 void MainWindow::slotSetOutPoint()
2545 {
2546     if (m_clipMonitor->isActive()) {
2547         m_clipMonitor->slotSetZoneEnd();
2548     } else m_activeTimeline->projectView()->setOutPoint();
2549 }
2550
2551 void MainWindow::slotGetNewLumaStuff()
2552 {
2553     //KNS::Entry::List download();
2554     KNS::Entry::List entries = KNS::Engine::download();
2555     // list of changed entries
2556     kDebug() << "// PARSING KNS";
2557     foreach(KNS::Entry* entry, entries) {
2558         // care only about installed ones
2559         if (entry->status() == KNS::Entry::Installed) {
2560             foreach(const QString &file, entry->installedFiles()) {
2561                 kDebug() << "// CURRENTLY INSTALLED: " << file;
2562             }
2563         }
2564     }
2565     qDeleteAll(entries);
2566     initEffects::refreshLumas();
2567     m_activeTimeline->projectView()->reloadTransitionLumas();
2568 }
2569
2570 void MainWindow::slotGetNewRenderStuff()
2571 {
2572     //KNS::Entry::List download();
2573
2574     KNS::Engine engine(0);
2575     if (engine.init("kdenlive_render.knsrc")) {
2576         KNS::Entry::List entries = engine.downloadDialogModal(this);
2577
2578         if (entries.size() > 0) {
2579             foreach(KNS::Entry* entry, entries) {
2580                 // care only about installed ones
2581                 if (entry->status() == KNS::Entry::Installed) {
2582                     foreach(const QString &file, entry->installedFiles()) {
2583                         kDebug() << "// CURRENTLY INSTALLED: " << file;
2584                     }
2585                 }
2586             }
2587         }
2588         if (m_renderWidget) m_renderWidget->reloadProfiles();
2589     }
2590 }
2591
2592 void MainWindow::slotGetNewMltProfileStuff()
2593 {
2594     //KNS::Entry::List download();
2595
2596     KNS::Engine engine(0);
2597     if (engine.init("kdenlive_mltprofiles.knsrc")) {
2598         KNS::Entry::List entries = engine.downloadDialogModal(this);
2599
2600         if (entries.size() > 0) {
2601             foreach(KNS::Entry* entry, entries) {
2602                 // care only about installed ones
2603                 if (entry->status() == KNS::Entry::Installed) {
2604                     foreach(const QString &file, entry->installedFiles()) {
2605                         kDebug() << "// CURRENTLY INSTALLED: " << file;
2606                     }
2607                 }
2608             }
2609
2610             // update the list of profiles in settings dialog
2611             KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
2612             if (d) d->checkProfile();
2613         }
2614     }
2615 }
2616
2617 void MainWindow::slotAutoTransition()
2618 {
2619     if (m_activeTimeline) m_activeTimeline->projectView()->autoTransition();
2620 }
2621
2622 void MainWindow::slotSplitAudio()
2623 {
2624     if (m_activeTimeline) m_activeTimeline->projectView()->splitAudio();
2625 }
2626
2627 void MainWindow::slotUpdateClipType(QAction *action)
2628 {
2629     if (m_activeTimeline) {
2630         if (action->data().toString() == "clip_audio_only") m_activeTimeline->projectView()->setAudioOnly();
2631         else if (action->data().toString() == "clip_video_only") m_activeTimeline->projectView()->setVideoOnly();
2632         else m_activeTimeline->projectView()->setAudioAndVideo();
2633     }
2634 }
2635
2636 void MainWindow::slotDvdWizard(const QString &url, const QString &profile)
2637 {
2638     DvdWizard *w = new DvdWizard(url, profile, this);
2639     w->exec();
2640 }
2641
2642 void MainWindow::slotShowTimeline(bool show)
2643 {
2644     if (show == false) {
2645         m_timelineState = saveState();
2646         centralWidget()->setHidden(true);
2647     } else {
2648         centralWidget()->setHidden(false);
2649         restoreState(m_timelineState);
2650     }
2651 }
2652
2653 void MainWindow::slotMaximizeCurrent(bool /*show*/)
2654 {
2655     //TODO: is there a way to maximize current widget?
2656     //if (show == true)
2657     {
2658         m_timelineState = saveState();
2659         QWidget *par = focusWidget()->parentWidget();
2660         while (par->parentWidget() && par->parentWidget() != this) {
2661             par = par->parentWidget();
2662         }
2663         kDebug() << "CURRENT WIDGET: " << par->objectName();
2664     }
2665     /*else {
2666     //centralWidget()->setHidden(false);
2667     //restoreState(m_timelineState);
2668     }*/
2669 }
2670
2671 void MainWindow::loadTranscoders()
2672 {
2673     QMenu *transMenu = static_cast<QMenu*>(factory()->container("transcoders", this));
2674     transMenu->clear();
2675
2676     KSharedConfigPtr config = KSharedConfig::openConfig("kdenlivetranscodingrc");
2677     KConfigGroup transConfig(config, "Transcoding");
2678     // read the entries
2679     QMap< QString, QString > profiles = transConfig.entryMap();
2680     QMapIterator<QString, QString> i(profiles);
2681     while (i.hasNext()) {
2682         i.next();
2683         QAction *a = transMenu->addAction(i.key());
2684         a->setData(i.value());
2685         connect(a, SIGNAL(triggered()), this, SLOT(slotTranscode()));
2686     }
2687 }
2688
2689 void MainWindow::slotTranscode(KUrl::List urls)
2690 {
2691     QString params;
2692     if (urls.isEmpty()) {
2693         urls.append(m_projectList->currentClipUrl());
2694         QAction *action = qobject_cast<QAction *>(sender());
2695         params = action->data().toString();
2696     }
2697     if (urls.isEmpty()) return;
2698     ClipTranscode *d = new ClipTranscode(urls, params);
2699     connect(d, SIGNAL(addClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
2700     d->show();
2701     //QProcess::startDetached("ffmpeg", parameters);
2702 }
2703
2704 void MainWindow::slotTranscodeClip()
2705 {
2706     KUrl::List urls = KFileDialog::getOpenUrls(KUrl("kfiledialog:///projectfolder"));
2707     if (urls.isEmpty()) return;
2708     slotTranscode(urls);
2709 }
2710
2711 #include "mainwindow.moc"