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