]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
Fix changing in/out points not setting the document modified:
[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 #include "vectorscope.h"
56
57 #include <KApplication>
58 #include <KAction>
59 #include <KLocale>
60 #include <KGlobal>
61 #include <KActionCollection>
62 #include <KActionCategory>
63 #include <KStandardAction>
64 #include <KShortcutsDialog>
65 #include <KFileDialog>
66 #include <KMessageBox>
67 #include <KDebug>
68 #include <KIO/NetAccess>
69 #include <KSaveFile>
70 #include <KRuler>
71 #include <KConfigDialog>
72 #include <KXMLGUIFactory>
73 #include <KStatusBar>
74 #include <kstandarddirs.h>
75 #include <KUrlRequesterDialog>
76 #include <KTemporaryFile>
77 #include <KProcess>
78 #include <KActionMenu>
79 #include <KMenu>
80 #include <locale.h>
81 #include <ktogglefullscreenaction.h>
82 #include <KFileItem>
83 #include <KNotification>
84 #include <KNotifyConfigWidget>
85 #if KDE_IS_VERSION(4,3,80)
86 #include <knewstuff3/downloaddialog.h>
87 #include <knewstuff3/knewstuffaction.h>
88 #else
89 #include <knewstuff2/engine.h>
90 #include <knewstuff2/ui/knewstuffaction.h>
91 #define KNS3 KNS
92 #endif /* KDE_IS_VERSION(4,3,80) */
93 #include <KToolBar>
94 #include <KColorScheme>
95
96 #include <QTextStream>
97 #include <QTimer>
98 #include <QAction>
99 #include <QKeyEvent>
100 #include <QInputDialog>
101 #include <QDesktopWidget>
102 #include <QBitmap>
103
104 #include <stdlib.h>
105
106 static const char version[] = VERSION;
107
108 static const int ID_TIMELINE_POS = 0;
109
110 namespace Mlt
111 {
112 class Producer;
113 };
114
115 EffectsList MainWindow::videoEffects;
116 EffectsList MainWindow::audioEffects;
117 EffectsList MainWindow::customEffects;
118 EffectsList MainWindow::transitions;
119
120 MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, QWidget *parent) :
121         KXmlGuiWindow(parent),
122         m_activeDocument(NULL),
123         m_activeTimeline(NULL),
124         m_renderWidget(NULL),
125 #ifndef NO_JOGSHUTTLE
126         m_jogProcess(NULL),
127 #endif /* NO_JOGSHUTTLE */
128         m_findActivated(false)
129 {
130
131     // Create DBus interface
132     new MainWindowAdaptor(this);
133     QDBusConnection dbus = QDBusConnection::sessionBus();
134     dbus.registerObject("/MainWindow", this);
135
136     setlocale(LC_NUMERIC, "POSIX");
137     if (!KdenliveSettings::colortheme().isEmpty()) slotChangePalette(NULL, KdenliveSettings::colortheme());
138     setFont(KGlobalSettings::toolBarFont());
139     parseProfiles(MltPath);
140     m_commandStack = new QUndoGroup;
141     m_timelineArea = new KTabWidget(this);
142     m_timelineArea->setTabReorderingEnabled(true);
143     m_timelineArea->setTabBarHidden(true);
144     m_timelineArea->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
145     m_timelineArea->setMinimumHeight(200);
146
147     QToolButton *closeTabButton = new QToolButton;
148     connect(closeTabButton, SIGNAL(clicked()), this, SLOT(closeCurrentDocument()));
149     closeTabButton->setIcon(KIcon("tab-close"));
150     closeTabButton->adjustSize();
151     closeTabButton->setToolTip(i18n("Close the current tab"));
152     m_timelineArea->setCornerWidget(closeTabButton);
153     connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
154
155     connect(&m_findTimer, SIGNAL(timeout()), this, SLOT(findTimeout()));
156     m_findTimer.setSingleShot(true);
157
158     // FIXME: the next call returns a newly allocated object, which leaks
159     initEffects::parseEffectFiles();
160     //initEffects::parseCustomEffectsFile();
161
162     m_monitorManager = new MonitorManager();
163
164     m_shortcutRemoveFocus = new QShortcut(QKeySequence("Esc"), this);
165     connect(m_shortcutRemoveFocus, SIGNAL(activated()), this, SLOT(slotRemoveFocus()));
166
167
168     /// Add Widgets ///
169
170     m_projectListDock = new QDockWidget(i18n("Project Tree"), this);
171     m_projectListDock->setObjectName("project_tree");
172     m_projectList = new ProjectList(this);
173     m_projectListDock->setWidget(m_projectList);
174     addDockWidget(Qt::TopDockWidgetArea, m_projectListDock);
175
176     m_effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
177     m_effectStackDock->setObjectName("effect_stack");
178     m_effectStack = new EffectStackView(this);
179     m_effectStackDock->setWidget(m_effectStack);
180     addDockWidget(Qt::TopDockWidgetArea, m_effectStackDock);
181
182     m_transitionConfigDock = new QDockWidget(i18n("Transition"), this);
183     m_transitionConfigDock->setObjectName("transition");
184     m_transitionConfig = new TransitionSettings(this);
185     m_transitionConfigDock->setWidget(m_transitionConfig);
186     addDockWidget(Qt::TopDockWidgetArea, m_transitionConfigDock);
187
188     m_clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
189     m_clipMonitorDock->setObjectName("clip_monitor");
190     m_clipMonitor = new Monitor("clip", m_monitorManager, QString(), this);
191     m_clipMonitorDock->setWidget(m_clipMonitor);
192     addDockWidget(Qt::TopDockWidgetArea, m_clipMonitorDock);
193
194     m_projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
195     m_projectMonitorDock->setObjectName("project_monitor");
196     m_projectMonitor = new Monitor("project", m_monitorManager, QString(), this);
197     m_projectMonitorDock->setWidget(m_projectMonitor);
198     addDockWidget(Qt::TopDockWidgetArea, m_projectMonitorDock);
199
200 #ifndef Q_WS_MAC
201     m_recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
202     m_recMonitorDock->setObjectName("record_monitor");
203     m_recMonitor = new RecMonitor("record", this);
204     m_recMonitorDock->setWidget(m_recMonitor);
205     addDockWidget(Qt::TopDockWidgetArea, m_recMonitorDock);
206     connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
207     connect(m_recMonitor, SIGNAL(showConfigDialog(int, int)), this, SLOT(slotPreferences(int, int)));
208 #endif
209
210     m_effectListDock = new QDockWidget(i18n("Effect List"), this);
211     m_effectListDock->setObjectName("effect_list");
212     m_effectList = new EffectsListView();
213     m_effectListDock->setWidget(m_effectList);
214     addDockWidget(Qt::TopDockWidgetArea, m_effectListDock);
215
216     m_vectorscope = new Vectorscope(m_projectMonitor, m_clipMonitor, this);
217     m_vectorscopeDock = new QDockWidget(i18n("Vectorscope"), this);
218     m_vectorscopeDock->setObjectName("vectorscope");
219     m_vectorscopeDock->setWidget(m_vectorscope);
220     addDockWidget(Qt::TopDockWidgetArea, m_vectorscopeDock);
221
222
223     m_undoViewDock = new QDockWidget(i18n("Undo History"), this);
224     m_undoViewDock->setObjectName("undo_history");
225     m_undoView = new QUndoView(this);
226     m_undoView->setCleanIcon(KIcon("edit-clear"));
227     m_undoView->setEmptyLabel(i18n("Clean"));
228     m_undoViewDock->setWidget(m_undoView);
229     m_undoView->setGroup(m_commandStack);
230     addDockWidget(Qt::TopDockWidgetArea, m_undoViewDock);
231
232     //overviewDock = new QDockWidget(i18n("Project Overview"), this);
233     //overviewDock->setObjectName("project_overview");
234     //m_overView = new CustomTrackView(NULL, NULL, this);
235     //overviewDock->setWidget(m_overView);
236     //addDockWidget(Qt::TopDockWidgetArea, overviewDock);
237
238
239     setupActions();
240
241     /// Tabify Widgets ///
242     tabifyDockWidget(m_projectListDock, m_effectStackDock);
243     tabifyDockWidget(m_projectListDock, m_transitionConfigDock);
244
245
246     tabifyDockWidget(m_clipMonitorDock, m_projectMonitorDock);
247 #ifndef Q_WS_MAC
248     tabifyDockWidget(m_clipMonitorDock, m_recMonitorDock);
249 #endif
250
251     tabifyDockWidget(m_vectorscopeDock, m_undoViewDock);
252     tabifyDockWidget(m_vectorscopeDock, m_effectListDock);
253
254
255     setCentralWidget(m_timelineArea);
256
257
258     KdenliveSettings::setCurrent_profile(KdenliveSettings::default_profile());
259     m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)), actionCollection());
260     readOptions();
261     m_fileRevert = KStandardAction::revert(this, SLOT(slotRevert()), actionCollection());
262     m_fileRevert->setEnabled(false);
263
264
265     setupGUI();
266
267
268     // Find QDockWidget tab bars and show / hide widget title bars on right click
269     QList <QTabBar *> tabs = findChildren<QTabBar *>();
270     for (int i = 0; i < tabs.count(); i++) {
271         tabs.at(i)->setContextMenuPolicy(Qt::CustomContextMenu);
272         connect(tabs.at(i), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(slotSwitchTitles()));
273     }
274
275     /*ScriptingPart* sp = new ScriptingPart(this, QStringList());
276     guiFactory()->addClient(sp);*/
277
278     loadPlugins();
279     loadTranscoders();
280     //kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
281
282     m_projectMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)), m_playZone, m_loopZone);
283     m_clipMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)), m_playZone, m_loopZone, static_cast<QMenu*>(factory()->container("marker_menu", this)));
284
285     QMenu *clipInTimeline = static_cast<QMenu*>(factory()->container("clip_in_timeline", this));
286     clipInTimeline->setIcon(KIcon("go-jump"));
287     m_projectList->setupGeneratorMenu(static_cast<QMenu*>(factory()->container("generators", this)),
288                                       static_cast<QMenu*>(factory()->container("transcoders", this)),
289                                       clipInTimeline);
290
291     KAction *action;
292     // build themes menus
293     QMenu *themesMenu = static_cast<QMenu*>(factory()->container("themes_menu", this));
294     QActionGroup *themegroup = new QActionGroup(this);
295     themegroup->setExclusive(true);
296     action = new KAction(i18n("Default"), this);
297     action->setCheckable(true);
298     themegroup->addAction(action);
299     if (KdenliveSettings::colortheme().isEmpty()) action->setChecked(true);
300
301     const QStringList schemeFiles = KGlobal::dirs()->findAllResources("data", "color-schemes/*.colors", KStandardDirs::NoDuplicates);
302
303     for (int i = 0; i < schemeFiles.size(); ++i) {
304         // get the file name
305         const QString filename = schemeFiles.at(i);
306         const QFileInfo info(filename);
307
308         // add the entry
309         KSharedConfigPtr config = KSharedConfig::openConfig(filename);
310         QIcon icon = createSchemePreviewIcon(config);
311         KConfigGroup group(config, "General");
312         const QString name = group.readEntry("Name", info.baseName());
313         action = new KAction(name, this);
314         action->setData(filename);
315         action->setIcon(icon);
316         action->setCheckable(true);
317         themegroup->addAction(action);
318         if (KdenliveSettings::colortheme() == filename) action->setChecked(true);
319     }
320
321     /*KGlobal::dirs()->addResourceDir("themes", KStandardDirs::installPath("data") + QString("kdenlive/themes"));
322     QStringList themes = KGlobal::dirs()->findAllResources("themes", QString(), KStandardDirs::Recursive | KStandardDirs::NoDuplicates);
323     for (QStringList::const_iterator it = themes.constBegin(); it != themes.constEnd(); ++it)
324     {
325     QFileInfo fi(*it);
326         action = new QAction(fi.fileName(), this);
327         action->setData(*it);
328     action->setCheckable(true);
329     themegroup->addAction(action);
330     if (KdenliveSettings::colortheme() == *it) action->setChecked(true);
331     }*/
332     themesMenu->addActions(themegroup->actions());
333     connect(themesMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotChangePalette(QAction*)));
334
335     // Setup and fill effects and transitions menus.
336     m_videoEffectsMenu = static_cast<QMenu*>(factory()->container("video_effects_menu", this));
337     for (int i = 0; i < videoEffects.count(); ++i)
338         m_videoEffectsMenu->addAction(m_videoEffects[i]);
339     m_audioEffectsMenu = static_cast<QMenu*>(factory()->container("audio_effects_menu", this));
340     for (int i = 0; i < audioEffects.count(); ++i)
341         m_audioEffectsMenu->addAction(m_audioEffects[i]);
342     m_customEffectsMenu = static_cast<QMenu*>(factory()->container("custom_effects_menu", this));
343     if (customEffects.isEmpty())
344         m_customEffectsMenu->setEnabled(false);
345     else
346         m_customEffectsMenu->setEnabled(true);
347     for (int i = 0; i < customEffects.count(); ++i)
348         m_customEffectsMenu->addAction(m_customEffects[i]);
349     m_transitionsMenu = new QMenu(i18n("Add Transition"), this);
350     for (int i = 0; i < transitions.count(); ++i)
351         m_transitionsMenu->addAction(m_transitions[i]);
352
353     connect(m_videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
354     connect(m_audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
355     connect(m_customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
356     connect(m_transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
357
358     QMenu *newEffect = new QMenu(this);
359     newEffect->addMenu(m_videoEffectsMenu);
360     newEffect->addMenu(m_audioEffectsMenu);
361     newEffect->addMenu(m_customEffectsMenu);
362     m_effectStack->setMenu(newEffect);
363
364     QMenu *viewMenu = static_cast<QMenu*>(factory()->container("dockwindows", this));
365     const QList<QAction *> viewActions = createPopupMenu()->actions();
366     viewMenu->insertActions(NULL, viewActions);
367
368     m_timelineContextMenu = new QMenu(this);
369     m_timelineContextClipMenu = new QMenu(this);
370     m_timelineContextTransitionMenu = new QMenu(this);
371
372     m_timelineContextMenu->addAction(actionCollection()->action("insert_space"));
373     m_timelineContextMenu->addAction(actionCollection()->action("delete_space"));
374     m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));
375
376     m_timelineContextClipMenu->addAction(actionCollection()->action("clip_in_project_tree"));
377     //m_timelineContextClipMenu->addAction(actionCollection()->action("clip_to_project_tree"));
378     m_timelineContextClipMenu->addAction(actionCollection()->action("edit_item_duration"));
379     m_timelineContextClipMenu->addAction(actionCollection()->action("delete_item"));
380     m_timelineContextClipMenu->addSeparator();
381     m_timelineContextClipMenu->addAction(actionCollection()->action("group_clip"));
382     m_timelineContextClipMenu->addAction(actionCollection()->action("ungroup_clip"));
383     m_timelineContextClipMenu->addAction(actionCollection()->action("split_audio"));
384     m_timelineContextClipMenu->addSeparator();
385     m_timelineContextClipMenu->addAction(actionCollection()->action("cut_timeline_clip"));
386     m_timelineContextClipMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
387     m_timelineContextClipMenu->addAction(actionCollection()->action("paste_effects"));
388     m_timelineContextClipMenu->addSeparator();
389
390     QMenu *markersMenu = (QMenu*)(factory()->container("marker_menu", this));
391     m_timelineContextClipMenu->addMenu(markersMenu);
392     m_timelineContextClipMenu->addSeparator();
393     m_timelineContextClipMenu->addMenu(m_transitionsMenu);
394     m_timelineContextClipMenu->addMenu(m_videoEffectsMenu);
395     m_timelineContextClipMenu->addMenu(m_audioEffectsMenu);
396     //TODO: re-enable custom effects menu when it is implemented
397     m_timelineContextClipMenu->addMenu(m_customEffectsMenu);
398
399     m_timelineContextTransitionMenu->addAction(actionCollection()->action("edit_item_duration"));
400     m_timelineContextTransitionMenu->addAction(actionCollection()->action("delete_item"));
401     m_timelineContextTransitionMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
402
403     m_timelineContextTransitionMenu->addAction(actionCollection()->action("auto_transition"));
404
405     connect(m_projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
406     connect(m_clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
407     //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
408     connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
409     connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), m_vectorscope, SLOT(slotActiveMonitorChanged(bool)));
410     connect(m_effectList, SIGNAL(addEffect(const QDomElement)), this, SLOT(slotAddEffect(const QDomElement)));
411     connect(m_effectList, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
412
413     m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
414     slotConnectMonitors();
415
416     // Disable drop B frames, see Kdenlive issue #1330, see also kdenlivesettingsdialog.cpp
417     KdenliveSettings::setDropbframes(false);
418
419     // Open or create a file.  Command line argument passed in Url has
420     // precedence, then "openlastproject", then just a plain empty file.
421     // If opening Url fails, openlastproject will _not_ be used.
422     if (!Url.isEmpty()) {
423         // delay loading so that the window shows up
424         m_startUrl = Url;
425         QTimer::singleShot(500, this, SLOT(openFile()));
426     } else if (KdenliveSettings::openlastproject()) {
427         QTimer::singleShot(500, this, SLOT(openLastFile()));
428     } else { //if (m_timelineArea->count() == 0) {
429         newFile(false);
430     }
431
432 #ifndef NO_JOGSHUTTLE
433     activateShuttleDevice();
434 #endif /* NO_JOGSHUTTLE */
435     m_projectListDock->raise();
436 }
437
438 void MainWindow::queryQuit()
439 {
440     if (queryClose()) {
441         if (m_projectMonitor) m_projectMonitor->stop();
442         if (m_clipMonitor) m_clipMonitor->stop();
443         delete m_effectStack;
444         delete m_activeTimeline;
445 #ifndef Q_WS_MAC
446         // This sometimes causes crash on exit on OS X for some reason.
447         delete m_projectMonitor;
448         delete m_clipMonitor;
449 #endif
450         delete m_activeDocument;
451         delete m_shortcutRemoveFocus;
452         Mlt::Factory::close();
453         kapp->quit();
454     }
455 }
456
457 //virtual
458 bool MainWindow::queryClose()
459 {
460     if (m_renderWidget) {
461         int waitingJobs = m_renderWidget->waitingJobsCount();
462         if (waitingJobs > 0) {
463             switch (KMessageBox::warningYesNoCancel(this, i18np("You have 1 rendering job waiting in the queue.\nWhat do you want to do with this job?", "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")))) {
464             case KMessageBox::Yes :
465                 // create script with waiting jobs and start it
466                 if (m_renderWidget->startWaitingRenderJobs() == false) return false;
467                 break;
468             case KMessageBox::No :
469                 // Don't do anything, jobs will be deleted
470                 break;
471             default:
472                 return false;
473             }
474         }
475     }
476     saveOptions();
477     if (m_monitorManager) m_monitorManager->stopActiveMonitor();
478     // warn the user to save if document is modified and we have clips in our project list
479     if (m_activeDocument && m_activeDocument->isModified() &&
480         ((m_projectList->documentClipList().isEmpty() && !m_activeDocument->url().isEmpty()) ||
481             !m_projectList->documentClipList().isEmpty())) {
482         QString message;
483         if (m_activeDocument->url().fileName().isEmpty())
484             message = i18n("Save changes to document?");
485         else
486             message = i18n("The project <b>\"%1\"</b> has been changed.\nDo you want to save your changes?").arg(m_activeDocument->url().fileName());
487         switch (KMessageBox::warningYesNoCancel(this, message)) {
488         case KMessageBox::Yes :
489             // save document here. If saving fails, return false;
490             return saveFile();
491         case KMessageBox::No :
492             // User does not want to save the changes, clear recovery files
493             m_activeDocument->m_autosave->resize(0);
494             return true;
495         default: // cancel
496             return false;
497         }
498     }
499     return true;
500 }
501
502 void MainWindow::loadPlugins()
503 {
504     foreach(QObject *plugin, QPluginLoader::staticInstances()) {
505         populateMenus(plugin);
506     }
507
508     QStringList directories = KGlobal::dirs()->findDirs("module", QString());
509     QStringList filters;
510     filters << "libkdenlive*";
511     foreach(const QString &folder, directories) {
512         kDebug() << "Parsing plugin folder: " << folder;
513         QDir pluginsDir(folder);
514         foreach(const QString &fileName,
515                 pluginsDir.entryList(filters, QDir::Files)) {
516             /*
517              * Avoid loading the same plugin twice when there is more than one
518              * installation.
519              */
520             if (!m_pluginFileNames.contains(fileName)) {
521                 kDebug() << "Found plugin: " << fileName;
522                 QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
523                 QObject *plugin = loader.instance();
524                 if (plugin) {
525                     populateMenus(plugin);
526                     m_pluginFileNames += fileName;
527                 } else
528                     kDebug() << "Error loading plugin: " << fileName << ", " << loader.errorString();
529             }
530         }
531     }
532 }
533
534 void MainWindow::populateMenus(QObject *plugin)
535 {
536     QMenu *addMenu = static_cast<QMenu*>(factory()->container("generators", this));
537     ClipGenerator *iGenerator = qobject_cast<ClipGenerator *>(plugin);
538     if (iGenerator)
539         addToMenu(plugin, iGenerator->generators(KdenliveSettings::producerslist()), addMenu, SLOT(generateClip()),
540                   NULL);
541 }
542
543 void MainWindow::addToMenu(QObject *plugin, const QStringList &texts,
544                            QMenu *menu, const char *member,
545                            QActionGroup *actionGroup)
546 {
547     kDebug() << "// ADD to MENU" << texts;
548     foreach(const QString &text, texts) {
549         QAction *action = new QAction(text, plugin);
550         action->setData(text);
551         connect(action, SIGNAL(triggered()), this, member);
552         menu->addAction(action);
553
554         if (actionGroup) {
555             action->setCheckable(true);
556             actionGroup->addAction(action);
557         }
558     }
559 }
560
561 void MainWindow::aboutPlugins()
562 {
563     //PluginDialog dialog(pluginsDir.path(), m_pluginFileNames, this);
564     //dialog.exec();
565 }
566
567
568 void MainWindow::generateClip()
569 {
570     QAction *action = qobject_cast<QAction *>(sender());
571     ClipGenerator *iGenerator = qobject_cast<ClipGenerator *>(action->parent());
572
573     KUrl clipUrl = iGenerator->generatedClip(action->data().toString(), m_activeDocument->projectFolder(),
574                    QStringList(), QStringList(), m_activeDocument->fps(), m_activeDocument->width(), m_activeDocument->height());
575     if (!clipUrl.isEmpty()) {
576         m_projectList->slotAddClip(QList <QUrl> () << clipUrl);
577     }
578 }
579
580 void MainWindow::saveProperties(KConfigGroup &config)
581 {
582     // save properties here,used by session management
583     saveFile();
584     KMainWindow::saveProperties(config);
585 }
586
587
588 void MainWindow::readProperties(const KConfigGroup &config)
589 {
590     // read properties here,used by session management
591     KMainWindow::readProperties(config);
592     QString Lastproject = config.group("Recent Files").readPathEntry("File1", QString());
593     openFile(KUrl(Lastproject));
594 }
595
596 void MainWindow::slotReloadEffects()
597 {
598     m_customEffectsMenu->clear();
599     initEffects::parseCustomEffectsFile();
600     QAction *action;
601     QStringList effectInfo;
602     QMap<QString, QStringList> effectsList;
603     for (int ix = 0; ix < customEffects.count(); ix++) {
604         effectInfo = customEffects.effectIdInfo(ix);
605         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
606     }
607     if (effectsList.isEmpty())
608         m_customEffectsMenu->setEnabled(false);
609     else
610         m_customEffectsMenu->setEnabled(true);
611
612     foreach(const QStringList &value, effectsList) {
613         action = new QAction(value.at(0), this);
614         action->setData(value);
615         m_customEffectsMenu->addAction(action);
616     }
617     m_effectList->reloadEffectList();
618 }
619
620 #ifndef NO_JOGSHUTTLE
621 void MainWindow::activateShuttleDevice()
622 {
623     delete m_jogProcess;
624     m_jogProcess = NULL;
625     if (KdenliveSettings::enableshuttle() == false) return;
626     m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
627     connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
628     connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
629     connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
630     connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
631     connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
632     connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
633 }
634
635 void MainWindow::slotShuttleButton(int code)
636 {
637     switch (code) {
638     case 5:
639         slotShuttleAction(KdenliveSettings::shuttle1());
640         break;
641     case 6:
642         slotShuttleAction(KdenliveSettings::shuttle2());
643         break;
644     case 7:
645         slotShuttleAction(KdenliveSettings::shuttle3());
646         break;
647     case 8:
648         slotShuttleAction(KdenliveSettings::shuttle4());
649         break;
650     case 9:
651         slotShuttleAction(KdenliveSettings::shuttle5());
652         break;
653     }
654 }
655
656 void MainWindow::slotShuttleAction(int code)
657 {
658     switch (code) {
659     case 0:
660         return;
661     case 1:
662         m_monitorManager->slotPlay();
663         break;
664     default:
665         m_monitorManager->slotPlay();
666         break;
667     }
668 }
669 #endif /* NO_JOGSHUTTLE */
670
671 void MainWindow::configureNotifications()
672 {
673     KNotifyConfigWidget::configure(this);
674 }
675
676 void MainWindow::slotFullScreen()
677 {
678     KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
679 }
680
681 void MainWindow::slotAddEffect(const QDomElement effect, GenTime pos, int track)
682 {
683     if (!m_activeDocument) return;
684     if (effect.isNull()) {
685         kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
686         return;
687     }
688     QDomElement effectToAdd = effect.cloneNode().toElement();
689     m_activeTimeline->projectView()->slotAddEffect(effectToAdd, pos, track);
690 }
691
692 void MainWindow::slotRaiseMonitor(bool clipMonitor)
693 {
694     if (clipMonitor) m_clipMonitorDock->raise();
695     else m_projectMonitorDock->raise();
696 }
697
698 void MainWindow::slotUpdateClip(const QString &id)
699 {
700     if (!m_activeDocument) return;
701     m_activeTimeline->projectView()->slotUpdateClip(id);
702 }
703
704 void MainWindow::slotConnectMonitors()
705 {
706     m_projectList->setRenderer(m_projectMonitor->render);
707     //connect(m_projectList, SIGNAL(receivedClipDuration(const QString &)), this, SLOT(slotUpdateClip(const QString &)));
708     connect(m_projectList, SIGNAL(deleteProjectClips(QStringList, QMap<QString, QString>)), this, SLOT(slotDeleteProjectClips(QStringList, QMap<QString, QString>)));
709     connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
710     connect(m_projectList, SIGNAL(showClipProperties(QList <DocClipBase *>, QMap<QString, QString>)), this, SLOT(slotShowClipProperties(QList <DocClipBase *>, QMap<QString, QString>)));
711     connect(m_projectList, SIGNAL(getFileProperties(const QDomElement, const QString &, int, bool)), m_projectMonitor->render, SLOT(getFileProperties(const QDomElement, const QString &, int, bool)));
712     connect(m_projectMonitor->render, SIGNAL(replyGetImage(const QString &, const QPixmap &)), m_projectList, SLOT(slotReplyGetImage(const QString &, const QPixmap &)));
713     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)));
714
715     connect(m_projectMonitor->render, SIGNAL(removeInvalidClip(const QString &, bool)), m_projectList, SLOT(slotRemoveInvalidClip(const QString &, bool)));
716
717     connect(m_clipMonitor, SIGNAL(refreshClipThumbnail(const QString &)), m_projectList, SLOT(slotRefreshClipThumbnail(const QString &)));
718
719     connect(m_clipMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustClipMonitor()));
720     connect(m_projectMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustProjectMonitor()));
721
722     connect(m_clipMonitor, SIGNAL(saveZone(Render *, QPoint)), this, SLOT(slotSaveZone(Render *, QPoint)));
723     connect(m_projectMonitor, SIGNAL(saveZone(Render *, QPoint)), this, SLOT(slotSaveZone(Render *, QPoint)));
724 }
725
726 void MainWindow::slotAdjustClipMonitor()
727 {
728     m_clipMonitorDock->updateGeometry();
729     m_clipMonitorDock->adjustSize();
730     m_clipMonitor->resetSize();
731 }
732
733 void MainWindow::slotAdjustProjectMonitor()
734 {
735     m_projectMonitorDock->updateGeometry();
736     m_projectMonitorDock->adjustSize();
737     m_projectMonitor->resetSize();
738 }
739
740 void MainWindow::setupActions()
741 {
742
743     KActionCollection* collection = actionCollection();
744     m_timecodeFormat = new KComboBox(this);
745     m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
746     m_timecodeFormat->addItem(i18n("Frames"));
747     if (KdenliveSettings::frametimecode()) m_timecodeFormat->setCurrentIndex(1);
748     connect(m_timecodeFormat, SIGNAL(activated(int)), this, SLOT(slotUpdateTimecodeFormat(int)));
749
750     m_statusProgressBar = new QProgressBar(this);
751     m_statusProgressBar->setMinimum(0);
752     m_statusProgressBar->setMaximum(100);
753     m_statusProgressBar->setMaximumWidth(150);
754     m_statusProgressBar->setVisible(false);
755
756     KToolBar *toolbar = new KToolBar("statusToolBar", this, Qt::BottomToolBarArea);
757     toolbar->setMovable(false);
758     statusBar()->setStyleSheet(QString("QStatusBar QLabel {font-size:%1pt;} QStatusBar::item { border: 0px; font-size:%1pt;padding:0px; }").arg(statusBar()->font().pointSize()));
759     QString style1 = "QToolBar { border: 0px } QToolButton { 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;}";
760     QString styleBorderless = "QToolButton { border-width: 0px;margin: 1px 3px 0px;padding: 0px;}";
761
762     //create edit mode buttons
763     m_normalEditTool = new KAction(KIcon("kdenlive-normal-edit"), i18n("Normal mode"), this);
764     m_normalEditTool->setShortcut(i18nc("Normal editing", "n"));
765     toolbar->addAction(m_normalEditTool);
766     m_normalEditTool->setCheckable(true);
767     m_normalEditTool->setChecked(true);
768
769     m_overwriteEditTool = new KAction(KIcon("kdenlive-overwrite-edit"), i18n("Overwrite mode"), this);
770     //m_overwriteEditTool->setShortcut(i18nc("Overwrite mode shortcut", "o"));
771     toolbar->addAction(m_overwriteEditTool);
772     m_overwriteEditTool->setCheckable(true);
773     m_overwriteEditTool->setChecked(false);
774
775     m_insertEditTool = new KAction(KIcon("kdenlive-insert-edit"), i18n("Insert mode"), this);
776     //m_insertEditTool->setShortcut(i18nc("Insert mode shortcut", "i"));
777     toolbar->addAction(m_insertEditTool);
778     m_insertEditTool->setCheckable(true);
779     m_insertEditTool->setChecked(false);
780     // not implemented yet
781     m_insertEditTool->setEnabled(false);
782
783     QActionGroup *editGroup = new QActionGroup(this);
784     editGroup->addAction(m_normalEditTool);
785     editGroup->addAction(m_overwriteEditTool);
786     editGroup->addAction(m_insertEditTool);
787     editGroup->setExclusive(true);
788     connect(editGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeEdit(QAction *)));
789     //connect(m_overwriteEditTool, SIGNAL(toggled(bool)), this, SLOT(slotSetOverwriteMode(bool)));
790
791     toolbar->addSeparator();
792
793     // create tools buttons
794     m_buttonSelectTool = new KAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"), this);
795     m_buttonSelectTool->setShortcut(i18nc("Selection tool shortcut", "s"));
796     toolbar->addAction(m_buttonSelectTool);
797     m_buttonSelectTool->setCheckable(true);
798     m_buttonSelectTool->setChecked(true);
799
800     m_buttonRazorTool = new KAction(KIcon("edit-cut"), i18n("Razor tool"), this);
801     m_buttonRazorTool->setShortcut(i18nc("Razor tool shortcut", "x"));
802     toolbar->addAction(m_buttonRazorTool);
803     m_buttonRazorTool->setCheckable(true);
804     m_buttonRazorTool->setChecked(false);
805
806     m_buttonSpacerTool = new KAction(KIcon("kdenlive-spacer-tool"), i18n("Spacer tool"), this);
807     m_buttonSpacerTool->setShortcut(i18nc("Spacer tool shortcut", "m"));
808     toolbar->addAction(m_buttonSpacerTool);
809     m_buttonSpacerTool->setCheckable(true);
810     m_buttonSpacerTool->setChecked(false);
811
812     QActionGroup *toolGroup = new QActionGroup(this);
813     toolGroup->addAction(m_buttonSelectTool);
814     toolGroup->addAction(m_buttonRazorTool);
815     toolGroup->addAction(m_buttonSpacerTool);
816     toolGroup->setExclusive(true);
817     toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
818
819     QWidget * actionWidget;
820     int max = toolbar->iconSizeDefault() + 2;
821     actionWidget = toolbar->widgetForAction(m_normalEditTool);
822     actionWidget->setMaximumWidth(max);
823     actionWidget->setMaximumHeight(max - 4);
824
825     actionWidget = toolbar->widgetForAction(m_insertEditTool);
826     actionWidget->setMaximumWidth(max);
827     actionWidget->setMaximumHeight(max - 4);
828
829     actionWidget = toolbar->widgetForAction(m_overwriteEditTool);
830     actionWidget->setMaximumWidth(max);
831     actionWidget->setMaximumHeight(max - 4);
832
833     actionWidget = toolbar->widgetForAction(m_buttonSelectTool);
834     actionWidget->setMaximumWidth(max);
835     actionWidget->setMaximumHeight(max - 4);
836
837     actionWidget = toolbar->widgetForAction(m_buttonRazorTool);
838     actionWidget->setMaximumWidth(max);
839     actionWidget->setMaximumHeight(max - 4);
840
841     actionWidget = toolbar->widgetForAction(m_buttonSpacerTool);
842     actionWidget->setMaximumWidth(max);
843     actionWidget->setMaximumHeight(max - 4);
844
845     toolbar->setStyleSheet(style1);
846     connect(toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
847
848     toolbar->addSeparator();
849     m_buttonFitZoom = new KAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"), this);
850     toolbar->addAction(m_buttonFitZoom);
851     m_buttonFitZoom->setCheckable(false);
852
853     m_zoomOut = new KAction(KIcon("zoom-out"), i18n("Zoom Out"), this);
854     toolbar->addAction(m_zoomOut);
855     m_zoomOut->setShortcut(Qt::CTRL + Qt::Key_Minus);
856
857     m_zoomSlider = new QSlider(Qt::Horizontal, this);
858     m_zoomSlider->setMaximum(13);
859     m_zoomSlider->setPageStep(1);
860     m_zoomSlider->setInvertedAppearance(true);
861
862     m_zoomSlider->setMaximumWidth(150);
863     m_zoomSlider->setMinimumWidth(100);
864     toolbar->addWidget(m_zoomSlider);
865
866     m_zoomIn = new KAction(KIcon("zoom-in"), i18n("Zoom In"), this);
867     toolbar->addAction(m_zoomIn);
868     m_zoomIn->setShortcut(Qt::CTRL + Qt::Key_Plus);
869
870     actionWidget = toolbar->widgetForAction(m_buttonFitZoom);
871     actionWidget->setMaximumWidth(max);
872     actionWidget->setMaximumHeight(max - 4);
873     actionWidget->setStyleSheet(styleBorderless);
874
875     actionWidget = toolbar->widgetForAction(m_zoomIn);
876     actionWidget->setMaximumWidth(max);
877     actionWidget->setMaximumHeight(max - 4);
878     actionWidget->setStyleSheet(styleBorderless);
879
880     actionWidget = toolbar->widgetForAction(m_zoomOut);
881     actionWidget->setMaximumWidth(max);
882     actionWidget->setMaximumHeight(max - 4);
883     actionWidget->setStyleSheet(styleBorderless);
884
885     connect(m_zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(slotSetZoom(int)));
886     connect(m_zoomSlider, SIGNAL(sliderMoved(int)), this, SLOT(slotShowZoomSliderToolTip(int)));
887     connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
888     connect(m_zoomIn, SIGNAL(triggered(bool)), this, SLOT(slotZoomIn()));
889     connect(m_zoomOut, SIGNAL(triggered(bool)), this, SLOT(slotZoomOut()));
890
891     toolbar->addSeparator();
892
893     //create automatic audio split button
894     m_buttonAutomaticSplitAudio = new KAction(KIcon("kdenlive-split-audio"), i18n("Split audio and video automatically"), this);
895     toolbar->addAction(m_buttonAutomaticSplitAudio);
896     m_buttonAutomaticSplitAudio->setCheckable(true);
897     m_buttonAutomaticSplitAudio->setChecked(KdenliveSettings::splitaudio());
898     connect(m_buttonAutomaticSplitAudio, SIGNAL(triggered()), this, SLOT(slotSwitchSplitAudio()));
899
900     m_buttonVideoThumbs = new KAction(KIcon("kdenlive-show-videothumb"), i18n("Show video thumbnails"), this);
901     toolbar->addAction(m_buttonVideoThumbs);
902     m_buttonVideoThumbs->setCheckable(true);
903     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
904     connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
905
906     m_buttonAudioThumbs = new KAction(KIcon("kdenlive-show-audiothumb"), i18n("Show audio thumbnails"), this);
907     toolbar->addAction(m_buttonAudioThumbs);
908     m_buttonAudioThumbs->setCheckable(true);
909     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
910     connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
911
912     m_buttonShowMarkers = new KAction(KIcon("kdenlive-show-markers"), i18n("Show markers comments"), this);
913     toolbar->addAction(m_buttonShowMarkers);
914     m_buttonShowMarkers->setCheckable(true);
915     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
916     connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
917
918     m_buttonSnap = new KAction(KIcon("kdenlive-snap"), i18n("Snap"), this);
919     toolbar->addAction(m_buttonSnap);
920     m_buttonSnap->setCheckable(true);
921     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
922     connect(m_buttonSnap, SIGNAL(triggered()), this, SLOT(slotSwitchSnap()));
923
924     actionWidget = toolbar->widgetForAction(m_buttonAutomaticSplitAudio);
925     actionWidget->setMaximumWidth(max);
926     actionWidget->setMaximumHeight(max - 4);
927
928     actionWidget = toolbar->widgetForAction(m_buttonVideoThumbs);
929     actionWidget->setMaximumWidth(max);
930     actionWidget->setMaximumHeight(max - 4);
931
932     actionWidget = toolbar->widgetForAction(m_buttonAudioThumbs);
933     actionWidget->setMaximumWidth(max);
934     actionWidget->setMaximumHeight(max - 4);
935
936     actionWidget = toolbar->widgetForAction(m_buttonShowMarkers);
937     actionWidget->setMaximumWidth(max);
938     actionWidget->setMaximumHeight(max - 4);
939
940     actionWidget = toolbar->widgetForAction(m_buttonSnap);
941     actionWidget->setMaximumWidth(max);
942     actionWidget->setMaximumHeight(max - 4);
943
944     m_messageLabel = new StatusBarMessageLabel(this);
945     m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
946
947     statusBar()->addWidget(m_messageLabel, 10);
948     statusBar()->addWidget(m_statusProgressBar, 0);
949     statusBar()->addPermanentWidget(toolbar);
950     statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
951     statusBar()->addPermanentWidget(m_timecodeFormat);
952     //statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 3);
953
954     collection->addAction("normal_mode", m_normalEditTool);
955     collection->addAction("overwrite_mode", m_overwriteEditTool);
956     collection->addAction("insert_mode", m_insertEditTool);
957     collection->addAction("select_tool", m_buttonSelectTool);
958     collection->addAction("razor_tool", m_buttonRazorTool);
959     collection->addAction("spacer_tool", m_buttonSpacerTool);
960
961     collection->addAction("automatic_split_audio", m_buttonAutomaticSplitAudio);
962     collection->addAction("show_video_thumbs", m_buttonVideoThumbs);
963     collection->addAction("show_audio_thumbs", m_buttonAudioThumbs);
964     collection->addAction("show_markers", m_buttonShowMarkers);
965     collection->addAction("snap", m_buttonSnap);
966     collection->addAction("zoom_fit", m_buttonFitZoom);
967     collection->addAction("zoom_in", m_zoomIn);
968     collection->addAction("zoom_out", m_zoomOut);
969
970     m_projectSearch = new KAction(KIcon("edit-find"), i18n("Find"), this);
971     collection->addAction("project_find", m_projectSearch);
972     connect(m_projectSearch, SIGNAL(triggered(bool)), this, SLOT(slotFind()));
973     m_projectSearch->setShortcut(Qt::Key_Slash);
974
975     m_projectSearchNext = new KAction(KIcon("go-down-search"), i18n("Find Next"), this);
976     collection->addAction("project_find_next", m_projectSearchNext);
977     connect(m_projectSearchNext, SIGNAL(triggered(bool)), this, SLOT(slotFindNext()));
978     m_projectSearchNext->setShortcut(Qt::Key_F3);
979     m_projectSearchNext->setEnabled(false);
980
981     KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Project Profiles"), this);
982     collection->addAction("manage_profiles", profilesAction);
983     connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
984
985     KNS3::standardAction(i18n("Download New Wipes..."),            this, SLOT(slotGetNewLumaStuff()),       actionCollection(), "get_new_lumas");
986     KNS3::standardAction(i18n("Download New Render Profiles..."),  this, SLOT(slotGetNewRenderStuff()),     actionCollection(), "get_new_profiles");
987     KNS3::standardAction(i18n("Download New Project Profiles..."), this, SLOT(slotGetNewMltProfileStuff()), actionCollection(), "get_new_mlt_profiles");
988     KNS3::standardAction(i18n("Download New Title Templates..."),  this, SLOT(slotGetNewTitleStuff()),      actionCollection(), "get_new_titles");
989
990     KAction* wizAction = new KAction(KIcon("configure"), i18n("Run Config Wizard"), this);
991     collection->addAction("run_wizard", wizAction);
992     connect(wizAction, SIGNAL(triggered(bool)), this, SLOT(slotRunWizard()));
993
994     KAction* projectAction = new KAction(KIcon("configure"), i18n("Project Settings"), this);
995     collection->addAction("project_settings", projectAction);
996     connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
997
998     KAction* projectRender = new KAction(KIcon("media-record"), i18n("Render"), this);
999     collection->addAction("project_render", projectRender);
1000     projectRender->setShortcut(Qt::CTRL + Qt::Key_Return);
1001     connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
1002
1003     KAction* projectClean = new KAction(KIcon("edit-clear"), i18n("Clean Project"), this);
1004     collection->addAction("project_clean", projectClean);
1005     connect(projectClean, SIGNAL(triggered(bool)), this, SLOT(slotCleanProject()));
1006
1007     KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
1008     KShortcut playShortcut;
1009     playShortcut.setPrimary(Qt::Key_Space);
1010     playShortcut.setAlternate(Qt::Key_K);
1011     monitorPlay->setShortcut(playShortcut);
1012     collection->addAction("monitor_play", monitorPlay);
1013     connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
1014
1015     m_playZone = new KAction(KIcon("media-playback-start"), i18n("Play Zone"), this);
1016     m_playZone->setShortcut(Qt::CTRL + Qt::Key_Space);
1017     collection->addAction("monitor_play_zone", m_playZone);
1018     connect(m_playZone, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlayZone()));
1019
1020     m_loopZone = new KAction(KIcon("media-playback-start"), i18n("Loop Zone"), this);
1021     m_loopZone->setShortcut(Qt::ALT + Qt::Key_Space);
1022     collection->addAction("monitor_loop_zone", m_loopZone);
1023     connect(m_loopZone, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotLoopZone()));
1024
1025     KAction *dvdWizard =  new KAction(KIcon("media-optical"), i18n("DVD Wizard"), this);
1026     collection->addAction("dvd_wizard", dvdWizard);
1027     connect(dvdWizard, SIGNAL(triggered(bool)), this, SLOT(slotDvdWizard()));
1028
1029     KAction *transcodeClip =  new KAction(KIcon("edit-copy"), i18n("Transcode Clips"), this);
1030     collection->addAction("transcode_clip", transcodeClip);
1031     connect(transcodeClip, SIGNAL(triggered(bool)), this, SLOT(slotTranscodeClip()));
1032
1033     KAction *markIn = collection->addAction("mark_in");
1034     markIn->setText(i18n("Set Zone In"));
1035     markIn->setShortcut(Qt::Key_I);
1036     connect(markIn, SIGNAL(triggered(bool)), this, SLOT(slotSetInPoint()));
1037
1038     KAction *markOut = collection->addAction("mark_out");
1039     markOut->setText(i18n("Set Zone Out"));
1040     markOut->setShortcut(Qt::Key_O);
1041     connect(markOut, SIGNAL(triggered(bool)), this, SLOT(slotSetOutPoint()));
1042
1043     KAction *switchMon = collection->addAction("switch_monitor");
1044     switchMon->setText(i18n("Switch monitor"));
1045     switchMon->setShortcut(Qt::Key_T);
1046     connect(switchMon, SIGNAL(triggered(bool)), this, SLOT(slotSwitchMonitors()));
1047
1048     KAction *insertTree = collection->addAction("insert_project_tree");
1049     insertTree->setText(i18n("Insert zone in project tree"));
1050     insertTree->setShortcut(Qt::CTRL + Qt::Key_I);
1051     connect(insertTree, SIGNAL(triggered(bool)), this, SLOT(slotInsertZoneToTree()));
1052
1053     KAction *insertTimeline = collection->addAction("insert_timeline");
1054     insertTimeline->setText(i18n("Insert zone in timeline"));
1055     insertTimeline->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_I);
1056     connect(insertTimeline, SIGNAL(triggered(bool)), this, SLOT(slotInsertZoneToTimeline()));
1057
1058     KAction *resizeStart =  new KAction(KIcon(), i18n("Resize Item Start"), this);
1059     collection->addAction("resize_timeline_clip_start", resizeStart);
1060     resizeStart->setShortcut(Qt::Key_1);
1061     connect(resizeStart, SIGNAL(triggered(bool)), this, SLOT(slotResizeItemStart()));
1062
1063     KAction *resizeEnd =  new KAction(KIcon(), i18n("Resize Item End"), this);
1064     collection->addAction("resize_timeline_clip_end", resizeEnd);
1065     resizeEnd->setShortcut(Qt::Key_2);
1066     connect(resizeEnd, SIGNAL(triggered(bool)), this, SLOT(slotResizeItemEnd()));
1067
1068     KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
1069     monitorSeekBackward->setShortcut(Qt::Key_J);
1070     collection->addAction("monitor_seek_backward", monitorSeekBackward);
1071     connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
1072
1073     KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
1074     monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
1075     collection->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
1076     connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
1077
1078     KAction* monitorSeekBackwardOneSecond = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Second"), this);
1079     monitorSeekBackwardOneSecond->setShortcut(Qt::SHIFT + Qt::Key_Left);
1080     collection->addAction("monitor_seek_backward-one-second", monitorSeekBackwardOneSecond);
1081     connect(monitorSeekBackwardOneSecond, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneSecond()));
1082
1083     KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
1084     monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
1085     collection->addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
1086     connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
1087
1088     KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
1089     monitorSeekForward->setShortcut(Qt::Key_L);
1090     collection->addAction("monitor_seek_forward", monitorSeekForward);
1091     connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
1092
1093     KAction* clipStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Clip Start"), this);
1094     clipStart->setShortcut(Qt::Key_Home);
1095     collection->addAction("seek_clip_start", clipStart);
1096     connect(clipStart, SIGNAL(triggered(bool)), this, SLOT(slotClipStart()));
1097
1098     KAction* clipEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Clip End"), this);
1099     clipEnd->setShortcut(Qt::Key_End);
1100     collection->addAction("seek_clip_end", clipEnd);
1101     connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
1102
1103     KAction* zoneStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Zone Start"), this);
1104     zoneStart->setShortcut(Qt::SHIFT + Qt::Key_I);
1105     collection->addAction("seek_zone_start", zoneStart);
1106     connect(zoneStart, SIGNAL(triggered(bool)), this, SLOT(slotZoneStart()));
1107
1108     KAction* zoneEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Zone End"), this);
1109     zoneEnd->setShortcut(Qt::SHIFT + Qt::Key_O);
1110     collection->addAction("seek_zone_end", zoneEnd);
1111     connect(zoneEnd, SIGNAL(triggered(bool)), this, SLOT(slotZoneEnd()));
1112
1113     KAction* projectStart = new KAction(KIcon("go-first"), i18n("Go to Project Start"), this);
1114     projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
1115     collection->addAction("seek_start", projectStart);
1116     connect(projectStart, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotStart()));
1117
1118     KAction* projectEnd = new KAction(KIcon("go-last"), i18n("Go to Project End"), this);
1119     projectEnd->setShortcut(Qt::CTRL + Qt::Key_End);
1120     collection->addAction("seek_end", projectEnd);
1121     connect(projectEnd, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotEnd()));
1122
1123     KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
1124     monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
1125     collection->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
1126     connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
1127
1128     KAction* monitorSeekForwardOneSecond = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Second"), this);
1129     monitorSeekForwardOneSecond->setShortcut(Qt::SHIFT + Qt::Key_Right);
1130     collection->addAction("monitor_seek_forward-one-second", monitorSeekForwardOneSecond);
1131     connect(monitorSeekForwardOneSecond, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneSecond()));
1132
1133     KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
1134     monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
1135     collection->addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
1136     connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
1137
1138     KAction* deleteItem = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
1139     deleteItem->setShortcut(Qt::Key_Delete);
1140     collection->addAction("delete_timeline_clip", deleteItem);
1141     connect(deleteItem, SIGNAL(triggered(bool)), this, SLOT(slotDeleteItem()));
1142
1143     /*KAction* editTimelineClipSpeed = new KAction(i18n("Change Clip Speed"), this);
1144     collection->addAction("change_clip_speed", editTimelineClipSpeed);
1145     editTimelineClipSpeed->setData("change_speed");
1146     connect(editTimelineClipSpeed, SIGNAL(triggered(bool)), this, SLOT(slotChangeClipSpeed()));*/
1147
1148     KAction *stickTransition = collection->addAction("auto_transition");
1149     stickTransition->setData(QString("auto"));
1150     stickTransition->setCheckable(true);
1151     stickTransition->setEnabled(false);
1152     stickTransition->setText(i18n("Automatic Transition"));
1153     connect(stickTransition, SIGNAL(triggered(bool)), this, SLOT(slotAutoTransition()));
1154
1155     KAction* groupClip = new KAction(KIcon("object-group"), i18n("Group Clips"), this);
1156     groupClip->setShortcut(Qt::CTRL + Qt::Key_G);
1157     collection->addAction("group_clip", groupClip);
1158     connect(groupClip, SIGNAL(triggered(bool)), this, SLOT(slotGroupClips()));
1159
1160     KAction* ungroupClip = new KAction(KIcon("object-ungroup"), i18n("Ungroup Clips"), this);
1161     collection->addAction("ungroup_clip", ungroupClip);
1162     ungroupClip->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_G);
1163     ungroupClip->setData("ungroup_clip");
1164     connect(ungroupClip, SIGNAL(triggered(bool)), this, SLOT(slotUnGroupClips()));
1165
1166     KAction* editItemDuration = new KAction(KIcon("measure"), i18n("Edit Duration"), this);
1167     collection->addAction("edit_item_duration", editItemDuration);
1168     connect(editItemDuration, SIGNAL(triggered(bool)), this, SLOT(slotEditItemDuration()));
1169
1170     KAction* clipInProjectTree = new KAction(KIcon("go-jump-definition"), i18n("Clip in Project Tree"), this);
1171     collection->addAction("clip_in_project_tree", clipInProjectTree);
1172     connect(clipInProjectTree, SIGNAL(triggered(bool)), this, SLOT(slotClipInProjectTree()));
1173
1174     /*KAction* clipToProjectTree = new KAction(KIcon("go-jump-definition"), i18n("Add Clip to Project Tree"), this);
1175     collection->addAction("clip_to_project_tree", clipToProjectTree);
1176     connect(clipToProjectTree, SIGNAL(triggered(bool)), this, SLOT(slotClipToProjectTree()));*/
1177
1178     KAction* insertOvertwrite = new KAction(KIcon(), i18n("Insert Clip Zone in Timeline (Overwrite)"), this);
1179     insertOvertwrite->setShortcut(Qt::Key_V);
1180     collection->addAction("overwrite_to_in_point", insertOvertwrite);
1181     connect(insertOvertwrite, SIGNAL(triggered(bool)), this, SLOT(slotInsertClipOverwrite()));
1182
1183     KAction* selectTimelineClip = new KAction(KIcon("edit-select"), i18n("Select Clip"), this);
1184     selectTimelineClip->setShortcut(Qt::Key_Plus);
1185     collection->addAction("select_timeline_clip", selectTimelineClip);
1186     connect(selectTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotSelectTimelineClip()));
1187
1188     KAction* deselectTimelineClip = new KAction(KIcon("edit-select"), i18n("Deselect Clip"), this);
1189     deselectTimelineClip->setShortcut(Qt::Key_Minus);
1190     collection->addAction("deselect_timeline_clip", deselectTimelineClip);
1191     connect(deselectTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeselectTimelineClip()));
1192
1193     KAction* selectAddTimelineClip = new KAction(KIcon("edit-select"), i18n("Add Clip To Selection"), this);
1194     selectAddTimelineClip->setShortcut(Qt::ALT + Qt::Key_Plus);
1195     collection->addAction("select_add_timeline_clip", selectAddTimelineClip);
1196     connect(selectAddTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotSelectAddTimelineClip()));
1197
1198     KAction* selectTimelineTransition = new KAction(KIcon("edit-select"), i18n("Select Transition"), this);
1199     selectTimelineTransition->setShortcut(Qt::SHIFT + Qt::Key_Plus);
1200     collection->addAction("select_timeline_transition", selectTimelineTransition);
1201     connect(selectTimelineTransition, SIGNAL(triggered(bool)), this, SLOT(slotSelectTimelineTransition()));
1202
1203     KAction* deselectTimelineTransition = new KAction(KIcon("edit-select"), i18n("Deselect Transition"), this);
1204     deselectTimelineTransition->setShortcut(Qt::SHIFT + Qt::Key_Minus);
1205     collection->addAction("deselect_timeline_transition", deselectTimelineTransition);
1206     connect(deselectTimelineTransition, SIGNAL(triggered(bool)), this, SLOT(slotDeselectTimelineTransition()));
1207
1208     KAction* selectAddTimelineTransition = new KAction(KIcon("edit-select"), i18n("Add Transition To Selection"), this);
1209     selectAddTimelineTransition->setShortcut(Qt::ALT + Qt::SHIFT + Qt::Key_Plus);
1210     collection->addAction("select_add_timeline_transition", selectAddTimelineTransition);
1211     connect(selectAddTimelineTransition, SIGNAL(triggered(bool)), this, SLOT(slotSelectAddTimelineTransition()));
1212
1213     KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
1214     cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
1215     collection->addAction("cut_timeline_clip", cutTimelineClip);
1216     connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
1217
1218     KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker"), this);
1219     collection->addAction("add_clip_marker", addClipMarker);
1220     connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
1221
1222     KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker"), this);
1223     collection->addAction("delete_clip_marker", deleteClipMarker);
1224     connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
1225
1226     KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers"), this);
1227     collection->addAction("delete_all_clip_markers", deleteAllClipMarkers);
1228     connect(deleteAllClipMarkers, SIGNAL(triggered(bool)), this, SLOT(slotDeleteAllClipMarkers()));
1229
1230     KAction* editClipMarker = new KAction(KIcon("document-properties"), i18n("Edit Marker"), this);
1231     collection->addAction("edit_clip_marker", editClipMarker);
1232     connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker()));
1233
1234     KAction* splitAudio = new KAction(KIcon("document-new"), i18n("Split Audio"), this);
1235     collection->addAction("split_audio", splitAudio);
1236     connect(splitAudio, SIGNAL(triggered(bool)), this, SLOT(slotSplitAudio()));
1237
1238     KAction* audioOnly = new KAction(KIcon("document-new"), i18n("Audio Only"), this);
1239     collection->addAction("clip_audio_only", audioOnly);
1240     audioOnly->setData("clip_audio_only");
1241     audioOnly->setCheckable(true);
1242
1243     KAction* videoOnly = new KAction(KIcon("document-new"), i18n("Video Only"), this);
1244     collection->addAction("clip_video_only", videoOnly);
1245     videoOnly->setData("clip_video_only");
1246     videoOnly->setCheckable(true);
1247
1248     KAction* audioAndVideo = new KAction(KIcon("document-new"), i18n("Audio and Video"), this);
1249     collection->addAction("clip_audio_and_video", audioAndVideo);
1250     audioAndVideo->setData("clip_audio_and_video");
1251     audioAndVideo->setCheckable(true);
1252
1253     m_clipTypeGroup = new QActionGroup(this);
1254     m_clipTypeGroup->addAction(audioOnly);
1255     m_clipTypeGroup->addAction(videoOnly);
1256     m_clipTypeGroup->addAction(audioAndVideo);
1257     connect(m_clipTypeGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotUpdateClipType(QAction *)));
1258     m_clipTypeGroup->setEnabled(false);
1259
1260     KAction *insertSpace = new KAction(KIcon(), i18n("Insert Space"), this);
1261     collection->addAction("insert_space", insertSpace);
1262     connect(insertSpace, SIGNAL(triggered()), this, SLOT(slotInsertSpace()));
1263
1264     KAction *removeSpace = new KAction(KIcon(), i18n("Remove Space"), this);
1265     collection->addAction("delete_space", removeSpace);
1266     connect(removeSpace, SIGNAL(triggered()), this, SLOT(slotRemoveSpace()));
1267
1268     KAction *insertTrack = new KAction(KIcon(), i18n("Insert Track"), this);
1269     collection->addAction("insert_track", insertTrack);
1270     connect(insertTrack, SIGNAL(triggered()), this, SLOT(slotInsertTrack()));
1271
1272     KAction *deleteTrack = new KAction(KIcon(), i18n("Delete Track"), this);
1273     collection->addAction("delete_track", deleteTrack);
1274     connect(deleteTrack, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
1275
1276     KAction *configTracks = new KAction(KIcon("configure"), i18n("Configure Tracks"), this);
1277     collection->addAction("config_tracks", configTracks);
1278     connect(configTracks, SIGNAL(triggered()), this, SLOT(slotConfigTrack()));
1279
1280     KAction *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
1281     collection->addAction("add_guide", addGuide);
1282     connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
1283
1284     QAction *delGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
1285     collection->addAction("delete_guide", delGuide);
1286     connect(delGuide, SIGNAL(triggered()), this, SLOT(slotDeleteGuide()));
1287
1288     QAction *editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
1289     collection->addAction("edit_guide", editGuide);
1290     connect(editGuide, SIGNAL(triggered()), this, SLOT(slotEditGuide()));
1291
1292     QAction *delAllGuides = new KAction(KIcon("edit-delete"), i18n("Delete All Guides"), this);
1293     collection->addAction("delete_all_guides", delAllGuides);
1294     connect(delAllGuides, SIGNAL(triggered()), this, SLOT(slotDeleteAllGuides()));
1295
1296     QAction *pasteEffects = new KAction(KIcon("edit-paste"), i18n("Paste Effects"), this);
1297     collection->addAction("paste_effects", pasteEffects);
1298     pasteEffects->setData("paste_effects");
1299     connect(pasteEffects , SIGNAL(triggered()), this, SLOT(slotPasteEffects()));
1300
1301     QAction *showTimeline = new KAction(i18n("Show Timeline"), this);
1302     collection->addAction("show_timeline", showTimeline);
1303     showTimeline->setCheckable(true);
1304     showTimeline->setChecked(true);
1305     connect(showTimeline, SIGNAL(triggered(bool)), this, SLOT(slotShowTimeline(bool)));
1306
1307     QAction *showTitleBar = new KAction(i18n("Show Title Bars"), this);
1308     collection->addAction("show_titlebars", showTitleBar);
1309     showTitleBar->setCheckable(true);
1310     connect(showTitleBar, SIGNAL(triggered(bool)), this, SLOT(slotShowTitleBars(bool)));
1311     showTitleBar->setChecked(KdenliveSettings::showtitlebars());
1312     slotShowTitleBars(KdenliveSettings::showtitlebars());
1313
1314     /*QAction *maxCurrent = new KAction(i18n("Maximize Current Widget"), this);
1315     collection->addAction("maximize_current", maxCurrent);
1316     maxCurrent->setCheckable(true);
1317     maxCurrent->setChecked(false);
1318     connect(maxCurrent, SIGNAL(triggered(bool)), this, SLOT(slotMaximizeCurrent(bool)));*/
1319
1320     m_closeAction = KStandardAction::close(this,  SLOT(closeCurrentDocument()),   collection);
1321     KStandardAction::quit(this,                   SLOT(queryQuit()),              collection);
1322     KStandardAction::open(this,                   SLOT(openFile()),               collection);
1323     m_saveAction = KStandardAction::save(this,    SLOT(saveFile()),               collection);
1324     KStandardAction::saveAs(this,                 SLOT(saveFileAs()),             collection);
1325     KStandardAction::openNew(this,                SLOT(newFile()),                collection);
1326     // TODO: make the following connection to slotEditKeys work
1327     KStandardAction::keyBindings(this,            SLOT(slotEditKeys()),           collection);
1328     KStandardAction::preferences(this,            SLOT(slotPreferences()),        collection);
1329     KStandardAction::configureNotifications(this, SLOT(configureNotifications()), collection);
1330     KStandardAction::copy(this,                   SLOT(slotCopy()),               collection);
1331     KStandardAction::paste(this,                  SLOT(slotPaste()),              collection);
1332     KStandardAction::fullScreen(this,             SLOT(slotFullScreen()), this,   collection);
1333
1334     KAction *undo = KStandardAction::undo(m_commandStack, SLOT(undo()), collection);
1335     undo->setEnabled(false);
1336     connect(m_commandStack, SIGNAL(canUndoChanged(bool)), undo, SLOT(setEnabled(bool)));
1337
1338     KAction *redo = KStandardAction::redo(m_commandStack, SLOT(redo()), collection);
1339     redo->setEnabled(false);
1340     connect(m_commandStack, SIGNAL(canRedoChanged(bool)), redo, SLOT(setEnabled(bool)));
1341
1342     /*
1343     //TODO: Add status tooltip to actions ?
1344     connect(collection, SIGNAL(actionHovered(QAction*)),
1345             this, SLOT(slotDisplayActionMessage(QAction*)));*/
1346
1347
1348     QAction *addClip = new KAction(KIcon("kdenlive-add-clip"), i18n("Add Clip"), this);
1349     collection->addAction("add_clip", addClip);
1350     connect(addClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddClip()));
1351
1352     QAction *addColorClip = new KAction(KIcon("kdenlive-add-color-clip"), i18n("Add Color Clip"), this);
1353     collection->addAction("add_color_clip", addColorClip);
1354     connect(addColorClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddColorClip()));
1355
1356     QAction *addSlideClip = new KAction(KIcon("kdenlive-add-slide-clip"), i18n("Add Slideshow Clip"), this);
1357     collection->addAction("add_slide_clip", addSlideClip);
1358     connect(addSlideClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddSlideshowClip()));
1359
1360     QAction *addTitleClip = new KAction(KIcon("kdenlive-add-text-clip"), i18n("Add Title Clip"), this);
1361     collection->addAction("add_text_clip", addTitleClip);
1362     connect(addTitleClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddTitleClip()));
1363
1364     QAction *addTitleTemplateClip = new KAction(KIcon("kdenlive-add-text-clip"), i18n("Add Template Title"), this);
1365     collection->addAction("add_text_template_clip", addTitleTemplateClip);
1366     connect(addTitleTemplateClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddTitleTemplateClip()));
1367
1368     QAction *addFolderButton = new KAction(KIcon("folder-new"), i18n("Create Folder"), this);
1369     collection->addAction("add_folder", addFolderButton);
1370     connect(addFolderButton , SIGNAL(triggered()), m_projectList, SLOT(slotAddFolder()));
1371
1372     QAction *clipProperties = new KAction(KIcon("document-edit"), i18n("Clip Properties"), this);
1373     collection->addAction("clip_properties", clipProperties);
1374     clipProperties->setData("clip_properties");
1375     connect(clipProperties , SIGNAL(triggered()), m_projectList, SLOT(slotEditClip()));
1376     clipProperties->setEnabled(false);
1377
1378     QAction *openClip = new KAction(KIcon("document-open"), i18n("Edit Clip"), this);
1379     collection->addAction("edit_clip", openClip);
1380     openClip->setData("edit_clip");
1381     connect(openClip , SIGNAL(triggered()), m_projectList, SLOT(slotOpenClip()));
1382     openClip->setEnabled(false);
1383
1384     QAction *deleteClip = new KAction(KIcon("edit-delete"), i18n("Delete Clip"), this);
1385     collection->addAction("delete_clip", deleteClip);
1386     deleteClip->setData("delete_clip");
1387     connect(deleteClip , SIGNAL(triggered()), m_projectList, SLOT(slotRemoveClip()));
1388     deleteClip->setEnabled(false);
1389
1390     QAction *reloadClip = new KAction(KIcon("view-refresh"), i18n("Reload Clip"), this);
1391     collection->addAction("reload_clip", reloadClip);
1392     reloadClip->setData("reload_clip");
1393     connect(reloadClip , SIGNAL(triggered()), m_projectList, SLOT(slotReloadClip()));
1394     reloadClip->setEnabled(false);
1395
1396     QMenu *addClips = new QMenu();
1397     addClips->addAction(addClip);
1398     addClips->addAction(addColorClip);
1399     addClips->addAction(addSlideClip);
1400     addClips->addAction(addTitleClip);
1401     addClips->addAction(addTitleTemplateClip);
1402     addClips->addAction(addFolderButton);
1403
1404     addClips->addAction(reloadClip);
1405     addClips->addAction(clipProperties);
1406     addClips->addAction(openClip);
1407     addClips->addAction(deleteClip);
1408     m_projectList->setupMenu(addClips, addClip);
1409
1410     // Setup effects and transitions actions.
1411     m_effectsActionCollection = new KActionCollection(this, KGlobal::mainComponent());
1412     //KActionCategory *videoEffectActions = new KActionCategory(i18n("Video Effects"), m_effectsActionCollection);
1413     KActionCategory *videoEffectActions = new KActionCategory(i18n("Video Effects"), collection);
1414     m_videoEffects = new KAction*[videoEffects.count()];
1415     for (int i = 0; i < videoEffects.count(); ++i) {
1416         QStringList effectInfo = videoEffects.effectIdInfo(i);
1417         m_videoEffects[i] = new KAction(KIcon("kdenlive-show-video"), effectInfo.at(0), this);
1418         m_videoEffects[i]->setData(effectInfo);
1419         m_videoEffects[i]->setIconVisibleInMenu(false);
1420         videoEffectActions->addAction("video_effect_" + effectInfo.at(0), m_videoEffects[i]);
1421     }
1422     //KActionCategory *audioEffectActions = new KActionCategory(i18n("Audio Effects"), m_effectsActionCollection);
1423     KActionCategory *audioEffectActions = new KActionCategory(i18n("Audio Effects"), collection);
1424     m_audioEffects = new KAction*[audioEffects.count()];
1425     for (int i = 0; i < audioEffects.count(); ++i) {
1426         QStringList effectInfo = audioEffects.effectIdInfo(i);
1427         m_audioEffects[i] = new KAction(KIcon("kdenlive-show-audio"), effectInfo.at(0), this);
1428         m_audioEffects[i]->setData(effectInfo);
1429         m_audioEffects[i]->setIconVisibleInMenu(false);
1430         audioEffectActions->addAction("audio_effect_" + effectInfo.at(0), m_audioEffects[i]);
1431     }
1432     //KActionCategory *customEffectActions = new KActionCategory(i18n("Custom Effects"), m_effectsActionCollection);
1433     KActionCategory *customEffectActions = new KActionCategory(i18n("Custom Effects"), collection);
1434     m_customEffects = new KAction*[customEffects.count()];
1435     for (int i = 0; i < customEffects.count(); ++i) {
1436         QStringList effectInfo = customEffects.effectIdInfo(i);
1437         m_customEffects[i] = new KAction(KIcon("kdenlive-custom-effect"), effectInfo.at(0), this);
1438         m_customEffects[i]->setData(effectInfo);
1439         m_customEffects[i]->setIconVisibleInMenu(false);
1440         customEffectActions->addAction("custom_effect_" + effectInfo.at(0), m_customEffects[i]);
1441     }
1442     //KActionCategory *transitionActions = new KActionCategory(i18n("Transitions"), m_effectsActionCollection);
1443     KActionCategory *transitionActions = new KActionCategory(i18n("Transitions"), collection);
1444     m_transitions = new KAction*[transitions.count()];
1445     for (int i = 0; i < transitions.count(); i++) {
1446         QStringList effectInfo = transitions.effectIdInfo(i);
1447         m_transitions[i] = new KAction(effectInfo.at(0), this);
1448         m_transitions[i]->setData(effectInfo);
1449         m_transitions[i]->setIconVisibleInMenu(false);
1450         transitionActions->addAction("transition_" + effectInfo.at(0), m_transitions[i]);
1451     }
1452     m_effectsActionCollection->readSettings();
1453
1454     //connect(collection, SIGNAL( clearStatusText() ),
1455     //statusBar(), SLOT( clear() ) );
1456 }
1457
1458 void MainWindow::slotDisplayActionMessage(QAction *a)
1459 {
1460     statusBar()->showMessage(a->data().toString(), 3000);
1461 }
1462
1463 void MainWindow::saveOptions()
1464 {
1465     KdenliveSettings::self()->writeConfig();
1466     KSharedConfigPtr config = KGlobal::config();
1467     m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
1468     KConfigGroup treecolumns(config, "Project Tree");
1469     treecolumns.writeEntry("columns", m_projectList->headerInfo());
1470     config->sync();
1471 }
1472
1473 void MainWindow::readOptions()
1474 {
1475     KSharedConfigPtr config = KGlobal::config();
1476     m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
1477     KConfigGroup initialGroup(config, "version");
1478     bool upgrade = false;
1479     if (initialGroup.exists()) {
1480         if (initialGroup.readEntry("version", QString()).section(' ', 0, 0) != QString(version).section(' ', 0, 0)) {
1481             upgrade = true;
1482         }
1483
1484         if (initialGroup.readEntry("version") == "0.7") {
1485             //Add new settings from 0.7.1
1486             if (KdenliveSettings::defaultprojectfolder().isEmpty()) {
1487                 QString path = QDir::homePath() + "/kdenlive";
1488                 if (KStandardDirs::makeDir(path)  == false) {
1489                     kDebug() << "/// ERROR CREATING PROJECT FOLDER: " << path;
1490                 } else KdenliveSettings::setDefaultprojectfolder(path);
1491             }
1492         }
1493
1494     }
1495
1496     if (!initialGroup.exists() || upgrade) {
1497         // this is our first run, show Wizard
1498         Wizard *w = new Wizard(upgrade, this);
1499         if (w->exec() == QDialog::Accepted && w->isOk()) {
1500             w->adjustSettings();
1501             initialGroup.writeEntry("version", version);
1502             delete w;
1503         } else {
1504             ::exit(1);
1505         }
1506     }
1507     KConfigGroup treecolumns(config, "Project Tree");
1508     const QByteArray state = treecolumns.readEntry("columns", QByteArray());
1509     if (!state.isEmpty())
1510         m_projectList->setHeaderInfo(state);
1511 }
1512
1513 void MainWindow::slotRunWizard()
1514 {
1515     Wizard *w = new Wizard(false, this);
1516     if (w->exec() == QDialog::Accepted && w->isOk()) {
1517         w->adjustSettings();
1518     }
1519     delete w;
1520 }
1521
1522 void MainWindow::newFile(bool showProjectSettings, bool force)
1523 {
1524     if (!m_timelineArea->isEnabled() && !force) return;
1525     m_fileRevert->setEnabled(false);
1526     QString profileName;
1527     KUrl projectFolder;
1528     QPoint projectTracks(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks());
1529     if (!showProjectSettings) {
1530         if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1531         profileName = KdenliveSettings::default_profile();
1532         projectFolder = KdenliveSettings::defaultprojectfolder();
1533     } else {
1534         ProjectSettings *w = new ProjectSettings(NULL, QStringList(), projectTracks.x(), projectTracks.y(), KdenliveSettings::defaultprojectfolder(), false, true, this);
1535         if (w->exec() != QDialog::Accepted) return;
1536         if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1537         if (KdenliveSettings::videothumbnails() != w->enableVideoThumbs()) slotSwitchVideoThumbs();
1538         if (KdenliveSettings::audiothumbnails() != w->enableAudioThumbs()) slotSwitchAudioThumbs();
1539         profileName = w->selectedProfile();
1540         projectFolder = w->selectedFolder();
1541         projectTracks = w->tracks();
1542         delete w;
1543     }
1544     m_timelineArea->setEnabled(true);
1545     m_projectList->setEnabled(true);
1546     KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, profileName, projectTracks, m_projectMonitor->render, this);
1547     doc->m_autosave = new KAutoSaveFile(KUrl(), doc);
1548     bool ok;
1549     TrackView *trackView = new TrackView(doc, &ok, this);
1550     m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
1551     if (!ok) {
1552         // MLT is broken
1553         //m_timelineArea->setEnabled(false);
1554         //m_projectList->setEnabled(false);
1555         slotPreferences(6);
1556         return;
1557     }
1558     if (m_timelineArea->count() == 1) {
1559         connectDocumentInfo(doc);
1560         connectDocument(trackView, doc);
1561     } else m_timelineArea->setTabBarHidden(false);
1562     m_monitorManager->activateMonitor("clip");
1563     m_closeAction->setEnabled(m_timelineArea->count() > 1);
1564 }
1565
1566 void MainWindow::activateDocument()
1567 {
1568     if (m_timelineArea->currentWidget() == NULL || !m_timelineArea->isEnabled()) return;
1569     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1570     KdenliveDoc *currentDoc = currentTab->document();
1571     connectDocumentInfo(currentDoc);
1572     connectDocument(currentTab, currentDoc);
1573 }
1574
1575 void MainWindow::closeCurrentDocument(bool saveChanges)
1576 {
1577     QWidget *w = m_timelineArea->currentWidget();
1578     if (!w) return;
1579     // closing current document
1580     int ix = m_timelineArea->currentIndex() + 1;
1581     if (ix == m_timelineArea->count()) ix = 0;
1582     m_timelineArea->setCurrentIndex(ix);
1583     TrackView *tabToClose = (TrackView *) w;
1584     KdenliveDoc *docToClose = tabToClose->document();
1585     if (docToClose && docToClose->isModified() && saveChanges) {
1586         QString message;
1587         if (m_activeDocument->url().fileName().isEmpty())
1588             message = i18n("Save changes to document?");
1589         else
1590             message = i18n("The project <b>\"%1\"</b> has been changed.\nDo you want to save your changes?").arg(m_activeDocument->url().fileName());
1591         switch (KMessageBox::warningYesNoCancel(this, message)) {
1592         case KMessageBox::Yes :
1593             // save document here. If saving fails, return false;
1594             if (saveFile() == false) return;
1595             break;
1596         case KMessageBox::Cancel :
1597             return;
1598             break;
1599         default:
1600             break;
1601         }
1602     }
1603     m_clipMonitor->slotSetXml(NULL);
1604     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
1605     if (m_timelineArea->count() == 1) {
1606         m_timelineArea->setTabBarHidden(true);
1607         m_closeAction->setEnabled(false);
1608     }
1609     if (docToClose == m_activeDocument) {
1610         delete m_activeDocument;
1611         m_activeDocument = NULL;
1612         m_effectStack->clear();
1613         m_transitionConfig->slotTransitionItemSelected(NULL, 0, QPoint(), false);
1614     } else {
1615         delete docToClose;
1616     }
1617     if (w == m_activeTimeline) {
1618         delete m_activeTimeline;
1619         m_activeTimeline = NULL;
1620     } else {
1621         delete w;
1622     }
1623 }
1624
1625 bool MainWindow::saveFileAs(const QString &outputFileName)
1626 {
1627     QString currentSceneList;
1628     m_monitorManager->stopActiveMonitor();
1629     if (KdenliveSettings::dropbframes()) {
1630         KdenliveSettings::setDropbframes(false);
1631         m_activeDocument->clipManager()->updatePreviewSettings();
1632         currentSceneList = m_projectMonitor->sceneList();
1633         KdenliveSettings::setDropbframes(true);
1634         m_activeDocument->clipManager()->updatePreviewSettings();
1635     } else currentSceneList = m_projectMonitor->sceneList();
1636
1637     if (m_activeDocument->saveSceneList(outputFileName, currentSceneList) == false)
1638         return false;
1639
1640     // Save timeline thumbnails
1641     m_activeTimeline->projectView()->saveThumbnails();
1642     m_activeDocument->setUrl(KUrl(outputFileName));
1643     if (m_activeDocument->m_autosave == NULL) {
1644         m_activeDocument->m_autosave = new KAutoSaveFile(KUrl(outputFileName), this);
1645     } else m_activeDocument->m_autosave->setManagedFile(KUrl(outputFileName));
1646     setCaption(m_activeDocument->description());
1647     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1648     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
1649     m_activeDocument->setModified(false);
1650     m_fileOpenRecent->addUrl(KUrl(outputFileName));
1651     m_fileRevert->setEnabled(true);
1652     return true;
1653 }
1654
1655 bool MainWindow::saveFileAs()
1656 {
1657     QString outputFile = KFileDialog::getSaveFileName(KUrl(), getMimeType());
1658     if (outputFile.isEmpty()) return false;
1659     if (QFile::exists(outputFile)) {
1660         // Show the file dialog again if the user does not want to overwrite the file
1661         if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it?")) == KMessageBox::No)
1662             return saveFileAs();
1663     }
1664     return saveFileAs(outputFile);
1665 }
1666
1667 bool MainWindow::saveFile()
1668 {
1669     if (!m_activeDocument) return true;
1670     if (m_activeDocument->url().isEmpty()) {
1671         return saveFileAs();
1672     } else {
1673         bool result = saveFileAs(m_activeDocument->url().path());
1674         m_activeDocument->m_autosave->resize(0);
1675         return result;
1676     }
1677 }
1678
1679 void MainWindow::openFile()
1680 {
1681     if (!m_startUrl.isEmpty()) {
1682         openFile(m_startUrl);
1683         m_startUrl = KUrl();
1684         return;
1685     }
1686     KUrl url = KFileDialog::getOpenUrl(KUrl("kfiledialog:///projectfolder"), getMimeType());
1687     if (url.isEmpty()) return;
1688     m_fileOpenRecent->addUrl(url);
1689     openFile(url);
1690 }
1691
1692 void MainWindow::openLastFile()
1693 {
1694     KSharedConfigPtr config = KGlobal::config();
1695     KUrl::List urls = m_fileOpenRecent->urls();
1696     //WARNING: this is buggy, we get a random url, not the last one. Bug in KRecentFileAction?
1697     if (urls.isEmpty()) newFile(false);
1698     else openFile(urls.last());
1699 }
1700
1701 void MainWindow::openFile(const KUrl &url)
1702 {
1703     // Check if the document is already opened
1704     const int ct = m_timelineArea->count();
1705     bool isOpened = false;
1706     int i;
1707     for (i = 0; i < ct; i++) {
1708         TrackView *tab = (TrackView *) m_timelineArea->widget(i);
1709         KdenliveDoc *doc = tab->document();
1710         if (doc->url() == url) {
1711             isOpened = true;
1712             break;
1713         }
1714     }
1715     if (isOpened) {
1716         m_timelineArea->setCurrentIndex(i);
1717         return;
1718     }
1719
1720     // Check for backup file
1721     QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::staleFiles(url);
1722     if (!staleFiles.isEmpty()) {
1723         if (KMessageBox::questionYesNo(this,
1724                                        i18n("Auto-saved files exist. Do you want to recover them now?"),
1725                                        i18n("File Recovery"),
1726                                        KGuiItem(i18n("Recover")), KGuiItem(i18n("Don't recover"))) == KMessageBox::Yes) {
1727             recoverFiles(staleFiles);
1728             return;
1729         } else {
1730             // remove the stale files
1731             foreach(KAutoSaveFile *stale, staleFiles) {
1732                 stale->open(QIODevice::ReadWrite);
1733                 delete stale;
1734             }
1735         }
1736     }
1737     if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1738     m_messageLabel->setMessage(i18n("Opening file %1", url.path()), InformationMessage);
1739     m_messageLabel->repaint();
1740     doOpenFile(url, NULL);
1741 }
1742
1743 void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale)
1744 {
1745     if (!m_timelineArea->isEnabled()) return;
1746     m_fileRevert->setEnabled(true);
1747     KdenliveDoc *doc = new KdenliveDoc(url, KdenliveSettings::defaultprojectfolder(), m_commandStack, KdenliveSettings::default_profile(), QPoint(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks()), m_projectMonitor->render, this);
1748     if (stale == NULL) {
1749         stale = new KAutoSaveFile(url, doc);
1750         doc->m_autosave = stale;
1751     } else {
1752         doc->m_autosave = stale;
1753         doc->setUrl(stale->managedFile());
1754         doc->setModified(true);
1755         stale->setParent(doc);
1756     }
1757     connectDocumentInfo(doc);
1758     bool ok;
1759     TrackView *trackView = new TrackView(doc, &ok, this);
1760     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
1761     if (!ok) {
1762         m_timelineArea->setEnabled(false);
1763         m_projectList->setEnabled(false);
1764         KMessageBox::sorry(this, i18n("Cannot open file %1.\nProject is corrupted.", url.path()));
1765         slotGotProgressInfo(QString(), -1);
1766         newFile(false, true);
1767         return;
1768     }
1769     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
1770     trackView->setDuration(trackView->duration());
1771     trackView->projectView()->initCursorPos(m_projectMonitor->render->seekPosition().frames(doc->fps()));
1772
1773     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
1774     slotGotProgressInfo(QString(), -1);
1775     m_projectMonitor->adjustRulerSize(trackView->duration());
1776     m_projectMonitor->slotZoneMoved(trackView->inPoint(), trackView->outPoint());
1777     m_clipMonitor->refreshMonitor(true);
1778 }
1779
1780 void MainWindow::recoverFiles(QList<KAutoSaveFile *> staleFiles)
1781 {
1782     if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1783     foreach(KAutoSaveFile *stale, staleFiles) {
1784         /*if (!stale->open(QIODevice::QIODevice::ReadOnly)) {
1785                   // show an error message; we could not steal the lockfile
1786                   // maybe another application got to the file before us?
1787                   delete stale;
1788                   continue;
1789         }*/
1790         kDebug() << "// OPENING RECOVERY: " << stale->fileName() << "\nMANAGED: " << stale->managedFile().path();
1791         // the stalefiles also contain ".lock" files so we must ignore them... bug in KAutoSaveFile?
1792         if (!stale->fileName().endsWith(".lock")) doOpenFile(KUrl(stale->fileName()), stale);
1793         else KIO::NetAccess::del(KUrl(stale->fileName()), this);
1794     }
1795 }
1796
1797 void MainWindow::parseProfiles(const QString &mltPath)
1798 {
1799     //KdenliveSettings::setDefaulttmpfolder();
1800     if (!mltPath.isEmpty()) {
1801         KdenliveSettings::setMltpath(mltPath + "/share/mlt/profiles/");
1802         KdenliveSettings::setRendererpath(mltPath + "/bin/melt");
1803     }
1804
1805     if (KdenliveSettings::mltpath().isEmpty())
1806         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
1807
1808     if (KdenliveSettings::rendererpath().isEmpty() || KdenliveSettings::rendererpath().endsWith("inigo")) {
1809         QString meltPath = QString(MLT_PREFIX) + QString("/bin/melt");
1810         if (!QFile::exists(meltPath))
1811             meltPath = KStandardDirs::findExe("melt");
1812         KdenliveSettings::setRendererpath(meltPath);
1813     }
1814
1815     if (KdenliveSettings::rendererpath().isEmpty()) {
1816         // Cannot find the MLT melt renderer, ask for location
1817         KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(QString(), i18n("Cannot find the melt program required for rendering (part of MLT)"), this);
1818         if (getUrl->exec() == QDialog::Rejected) {
1819             ::exit(0);
1820         }
1821         KUrl rendererPath = getUrl->selectedUrl();
1822         delete getUrl;
1823         if (rendererPath.isEmpty()) ::exit(0);
1824         KdenliveSettings::setRendererpath(rendererPath.path());
1825     }
1826
1827     QStringList profilesFilter;
1828     profilesFilter << "*";
1829     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1830     if (profilesList.isEmpty()) {
1831         // Cannot find MLT path, try finding melt
1832         QString profilePath = KdenliveSettings::rendererpath();
1833         if (!profilePath.isEmpty()) {
1834             profilePath = profilePath.section('/', 0, -3);
1835             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
1836             profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1837         }
1838         if (profilesList.isEmpty()) {
1839             // Cannot find the MLT profiles, ask for location
1840             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your MLT profiles, please give the path"), this);
1841             getUrl->fileDialog()->setMode(KFile::Directory);
1842             if (getUrl->exec() == QDialog::Rejected) {
1843                 ::exit(0);
1844             }
1845             KUrl mltPath = getUrl->selectedUrl();
1846             delete getUrl;
1847             if (mltPath.isEmpty()) ::exit(0);
1848             KdenliveSettings::setMltpath(mltPath.path(KUrl::AddTrailingSlash));
1849             profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1850         }
1851     }
1852
1853     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
1854
1855     // Parse again MLT profiles to build a list of available video formats
1856     if (profilesList.isEmpty()) parseProfiles();
1857 }
1858
1859
1860 void MainWindow::slotEditProfiles()
1861 {
1862     ProfilesDialog *w = new ProfilesDialog;
1863     if (w->exec() == QDialog::Accepted) {
1864         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
1865         if (d) d->checkProfile();
1866     }
1867     delete w;
1868 }
1869
1870 void MainWindow::slotDetectAudioDriver()
1871 {
1872     /* WARNING: do not use this method because sometimes detects wrong driver (pulse instead of alsa),
1873     leading to no audio output, see bug #934 */
1874
1875     //decide which audio driver is really best, in some cases SDL is wrong
1876     if (KdenliveSettings::audiodrivername().isEmpty()) {
1877         QString driver;
1878         KProcess readProcess;
1879         //PulseAudio needs to be selected if it exists, the ALSA pulse pcm device is not fast enough.
1880         if (!KStandardDirs::findExe("pactl").isEmpty()) {
1881             readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
1882             readProcess.setProgram("pactl", QStringList() << "stat");
1883             readProcess.execute(2000); // Kill it after 2 seconds
1884
1885             QString result = QString(readProcess.readAllStandardOutput());
1886             kDebug() << "// / / / / / READING PACTL: ";
1887             kDebug() << result;
1888             if (!result.isEmpty()) {
1889                 driver = "pulse";
1890                 kDebug() << "// / / / / PULSEAUDIO DETECTED";
1891             }
1892         }
1893         //put others here
1894         KdenliveSettings::setAutoaudiodrivername(driver);
1895     }
1896 }
1897
1898 void MainWindow::slotEditProjectSettings()
1899 {
1900     QPoint p = m_activeDocument->getTracksCount();
1901     ProjectSettings *w = new ProjectSettings(m_projectList, m_activeTimeline->projectView()->extractTransitionsLumas(), p.x(), p.y(), m_activeDocument->projectFolder().path(), true, !m_activeDocument->isModified(), this);
1902
1903     if (w->exec() == QDialog::Accepted) {
1904         QString profile = w->selectedProfile();
1905         m_activeDocument->setProjectFolder(w->selectedFolder());
1906         if (m_renderWidget) m_renderWidget->setDocumentPath(w->selectedFolder().path(KUrl::AddTrailingSlash));
1907         if (KdenliveSettings::videothumbnails() != w->enableVideoThumbs()) slotSwitchVideoThumbs();
1908         if (KdenliveSettings::audiothumbnails() != w->enableAudioThumbs()) slotSwitchAudioThumbs();
1909         if (m_activeDocument->profilePath() != profile) {
1910             // Profile was changed
1911             double dar = m_activeDocument->dar();
1912
1913             // Deselect current effect / transition
1914             m_effectStack->slotClipItemSelected(NULL, 0);
1915             m_transitionConfig->slotTransitionItemSelected(NULL, 0, QPoint(), false);
1916             m_clipMonitor->slotSetXml(NULL);
1917             bool updateFps = m_activeDocument->setProfilePath(profile);
1918             KdenliveSettings::setCurrent_profile(profile);
1919             KdenliveSettings::setProject_fps(m_activeDocument->fps());
1920             setCaption(m_activeDocument->description(), m_activeDocument->isModified());
1921
1922             m_activeDocument->clipManager()->clearUnusedProducers();
1923             m_monitorManager->resetProfiles(m_activeDocument->timecode());
1924
1925             m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
1926             m_effectStack->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode());
1927             m_projectList->updateProjectFormat(m_activeDocument->timecode());
1928             if (m_renderWidget) m_renderWidget->setProfile(m_activeDocument->mltProfile());
1929             m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1930             //m_activeDocument->clipManager()->resetProducersList(m_projectMonitor->render->producersList());
1931             if (dar != m_activeDocument->dar()) m_projectList->reloadClipThumbnails();
1932             if (updateFps) m_activeTimeline->updateProjectFps();
1933             m_activeDocument->setModified(true);
1934             m_commandStack->activeStack()->clear();
1935             //Update the mouse position display so it will display in DF/NDF format by default based on the project setting.
1936             slotUpdateMousePosition(0);
1937             // We need to desactivate & reactivate monitors to get a refresh
1938             //m_monitorManager->switchMonitors();
1939         }
1940     }
1941     delete w;
1942 }
1943
1944
1945 void MainWindow::slotRenderProject()
1946 {
1947     if (!m_renderWidget) {
1948         QString projectfolder = m_activeDocument ? m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash) : KdenliveSettings::defaultprojectfolder();
1949         m_renderWidget = new RenderWidget(projectfolder, this);
1950         connect(m_renderWidget, SIGNAL(shutdown()), this, SLOT(slotShutdown()));
1951         connect(m_renderWidget, SIGNAL(selectedRenderProfile(const QString &, const QString &, const QString &, const QString&)), this, SLOT(slotSetDocumentRenderProfile(const QString &, const QString &, const QString &, const QString&)));
1952         connect(m_renderWidget, SIGNAL(prepareRenderingData(bool, bool, const QString&)), this, SLOT(slotPrepareRendering(bool, bool, const QString&)));
1953         connect(m_renderWidget, SIGNAL(abortProcess(const QString &)), this, SIGNAL(abortRenderJob(const QString &)));
1954         connect(m_renderWidget, SIGNAL(openDvdWizard(const QString &, const QString &)), this, SLOT(slotDvdWizard(const QString &, const QString &)));
1955         if (m_activeDocument) {
1956             m_renderWidget->setProfile(m_activeDocument->mltProfile());
1957             m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1958             m_renderWidget->setDocumentPath(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
1959             m_renderWidget->setRenderProfile(m_activeDocument->getDocumentProperty("renderdestination"), m_activeDocument->getDocumentProperty("rendercategory"), m_activeDocument->getDocumentProperty("renderprofile"), m_activeDocument->getDocumentProperty("renderurl"));
1960         }
1961     }
1962     slotCheckRenderStatus();
1963     /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1964     if (currentTab) m_renderWidget->setTimeline(currentTab);
1965     m_renderWidget->setDocument(m_activeDocument);*/
1966     m_renderWidget->show();
1967     m_renderWidget->showNormal();
1968
1969     m_activeTimeline->tracksNumber();
1970     m_renderWidget->enableAudio(false);
1971     //m_renderWidget->export_audio;
1972 }
1973
1974 void MainWindow::slotCheckRenderStatus()
1975 {
1976     // Make sure there are no missing clips
1977     if (m_renderWidget)
1978         m_renderWidget->missingClips(m_projectList->hasMissingClips());
1979 }
1980
1981 void MainWindow::setRenderingProgress(const QString &url, int progress)
1982 {
1983     if (m_renderWidget)
1984         m_renderWidget->setRenderJob(url, progress);
1985 }
1986
1987 void MainWindow::setRenderingFinished(const QString &url, int status, const QString &error)
1988 {
1989     if (m_renderWidget)
1990         m_renderWidget->setRenderStatus(url, status, error);
1991 }
1992
1993 void MainWindow::slotCleanProject()
1994 {
1995     if (KMessageBox::warningContinueCancel(this, i18n("This will remove all unused clips from your project."), i18n("Clean up project")) == KMessageBox::Cancel) return;
1996     m_projectList->cleanup();
1997 }
1998
1999 void MainWindow::slotUpdateMousePosition(int pos)
2000 {
2001     if (m_activeDocument)
2002         switch (m_timecodeFormat->currentIndex()) {
2003         case 0:
2004             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
2005             break;
2006         default:
2007             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
2008         }
2009 }
2010
2011 void MainWindow::slotUpdateDocumentState(bool modified)
2012 {
2013     if (!m_activeDocument) return;
2014     setCaption(m_activeDocument->description(), modified);
2015     m_saveAction->setEnabled(modified);
2016     if (modified) {
2017         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
2018         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
2019     } else {
2020         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
2021         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
2022     }
2023 }
2024
2025 void MainWindow::connectDocumentInfo(KdenliveDoc *doc)
2026 {
2027     if (m_activeDocument) {
2028         if (m_activeDocument == doc) return;
2029         disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
2030     }
2031     connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
2032 }
2033
2034 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc)   //changed
2035 {
2036     //m_projectMonitor->stop();
2037     m_closeAction->setEnabled(m_timelineArea->count() > 1);
2038     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
2039     if (m_activeDocument) {
2040         if (m_activeDocument == doc) return;
2041         if (m_activeTimeline) {
2042             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
2043             disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeTimeline, SLOT(slotSetZone(QPoint)));
2044             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
2045             disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeDocument, SLOT(setModified()));
2046             disconnect(m_clipMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeDocument, SLOT(setModified()));
2047             disconnect(m_projectList, SIGNAL(projectModified()), m_activeDocument, SLOT(setModified()));
2048             disconnect(m_projectMonitor->render, SIGNAL(refreshDocumentProducers()), m_activeDocument, SLOT(checkProjectClips()));
2049
2050             disconnect(m_activeDocument, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
2051             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
2052             disconnect(m_activeDocument, SIGNAL(resetProjectList()), m_projectList, SLOT(slotResetProjectList()));
2053             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
2054             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
2055             disconnect(m_activeDocument, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
2056             disconnect(m_activeDocument, SIGNAL(deleteTimelineClip(const QString &)), m_activeTimeline, SLOT(slotDeleteClip(const QString &)));
2057             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), m_effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
2058             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
2059             disconnect(m_activeTimeline->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), m_transitionConfig, SLOT(slotTransitionItemSelected(Transition*, int, QPoint, bool)));
2060             disconnect(m_activeTimeline->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), this, SLOT(slotActivateTransitionView(Transition *)));
2061             disconnect(m_activeTimeline->projectView(), SIGNAL(playMonitor()), m_projectMonitor, SLOT(slotPlay()));
2062             disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
2063             disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, QPoint, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, QPoint, const int)));
2064             disconnect(m_activeTimeline, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
2065             disconnect(m_activeTimeline, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
2066             disconnect(m_activeTimeline, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
2067             disconnect(m_activeTimeline, SIGNAL(configTrack(int)), this, SLOT(slotConfigTrack(int)));
2068             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
2069             disconnect(m_effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
2070             disconnect(m_effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
2071             disconnect(m_effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
2072             disconnect(m_effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), m_activeTimeline->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
2073             disconnect(m_effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
2074             disconnect(m_effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
2075             disconnect(m_transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), m_activeTimeline->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
2076             disconnect(m_transitionConfig, SIGNAL(seekTimeline(int)), m_activeTimeline->projectView() , SLOT(setCursorPos(int)));
2077             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
2078             disconnect(m_activeTimeline, SIGNAL(zoneMoved(int, int)), this, SLOT(slotZoneMoved(int, int)));
2079             disconnect(m_projectList, SIGNAL(loadingIsOver()), m_activeTimeline->projectView(), SLOT(slotUpdateAllThumbs()));
2080             disconnect(m_projectList, SIGNAL(displayMessage(const QString&, int)), this, SLOT(slotGotProgressInfo(const QString&, int)));
2081             disconnect(m_projectList, SIGNAL(updateRenderStatus()), this, SLOT(slotCheckRenderStatus()));
2082             disconnect(m_projectList, SIGNAL(clipNeedsReload(const QString&, bool)), m_activeTimeline->projectView(), SLOT(slotUpdateClip(const QString &, bool)));
2083             m_effectStack->clear();
2084         }
2085         //m_activeDocument->setRenderer(NULL);
2086         disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
2087         disconnect(m_projectList, SIGNAL(refreshClip()), m_clipMonitor, SLOT(refreshMonitor()));
2088         m_clipMonitor->stop();
2089     }
2090     KdenliveSettings::setCurrent_profile(doc->profilePath());
2091     KdenliveSettings::setProject_fps(doc->fps());
2092     m_monitorManager->resetProfiles(doc->timecode());
2093     m_projectList->setDocument(doc);
2094     m_transitionConfig->updateProjectFormat(doc->mltProfile(), doc->timecode(), doc->tracksList());
2095     m_effectStack->updateProjectFormat(doc->mltProfile(), doc->timecode());
2096     connect(m_projectList, SIGNAL(clipSelected(DocClipBase *, QPoint)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, QPoint)));
2097     connect(m_projectList, SIGNAL(refreshClip()), m_clipMonitor, SLOT(refreshMonitor()));
2098     connect(m_projectList, SIGNAL(clipNeedsReload(const QString&, bool)), trackView->projectView(), SLOT(slotUpdateClip(const QString &, bool)));
2099
2100     connect(m_projectList, SIGNAL(projectModified()), doc, SLOT(setModified()));
2101     connect(m_projectList, SIGNAL(clipNameChanged(const QString, const QString)), trackView->projectView(), SLOT(clipNameChanged(const QString, const QString)));
2102
2103     connect(m_projectList, SIGNAL(findInTimeline(const QString&)), this, SLOT(slotClipInTimeline(const QString&)));
2104
2105
2106     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
2107     connect(trackView, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
2108     connect(trackView, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
2109     connect(trackView, SIGNAL(configTrack(int)), this, SLOT(slotConfigTrack(int)));
2110     connect(trackView, SIGNAL(updateTracksInfo()), this, SLOT(slotUpdateTrackInfo()));
2111     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
2112     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
2113     connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), trackView, SLOT(slotSetZone(QPoint)));
2114     connect(m_clipMonitor, SIGNAL(zoneUpdated(QPoint)), m_projectList, SLOT(slotUpdateClipCut(QPoint)));
2115     connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), doc, SLOT(setModified()));
2116     connect(m_clipMonitor, SIGNAL(zoneUpdated(QPoint)), doc, SLOT(setModified()));
2117     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
2118     connect(m_projectMonitor->render, SIGNAL(refreshDocumentProducers()), doc, SLOT(checkProjectClips()));
2119
2120     connect(doc, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
2121     connect(doc, SIGNAL(resetProjectList()), m_projectList, SLOT(slotResetProjectList()));
2122     connect(doc, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
2123     connect(doc, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
2124     connect(doc, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
2125
2126     connect(doc, SIGNAL(deleteTimelineClip(const QString &)), trackView, SLOT(slotDeleteClip(const QString &)));
2127     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
2128     connect(doc, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
2129
2130
2131     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), m_effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
2132     connect(trackView->projectView(), SIGNAL(updateClipMarkers(DocClipBase *)), this, SLOT(slotUpdateClipMarkers(DocClipBase*)));
2133
2134     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
2135     connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), m_transitionConfig, SLOT(slotTransitionItemSelected(Transition*, int, QPoint, bool)));
2136     connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), this, SLOT(slotActivateTransitionView(Transition *)));
2137     m_zoomSlider->setValue(doc->zoom().x());
2138     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
2139     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
2140     connect(trackView, SIGNAL(setZoom(int)), this, SLOT(slotSetZoom(int)));
2141     connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
2142
2143     connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, QPoint, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, QPoint, const int)));
2144     connect(trackView->projectView(), SIGNAL(playMonitor()), m_projectMonitor, SLOT(slotPlay()));
2145
2146
2147     connect(m_effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
2148     connect(m_effectStack, SIGNAL(updateClipRegion(ClipItem*, int, QString)), trackView->projectView(), SLOT(slotUpdateClipRegion(ClipItem*, int, QString)));
2149     connect(m_effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
2150     connect(m_effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
2151     connect(m_effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
2152     connect(m_effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
2153     connect(m_transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
2154     connect(m_transitionConfig, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
2155     connect(m_effectStack, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
2156     connect(m_effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
2157
2158     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
2159     connect(trackView, SIGNAL(zoneMoved(int, int)), this, SLOT(slotZoneMoved(int, int)));
2160     connect(m_projectList, SIGNAL(loadingIsOver()), trackView->projectView(), SLOT(slotUpdateAllThumbs()));
2161     connect(m_projectList, SIGNAL(displayMessage(const QString&, int)), this, SLOT(slotGotProgressInfo(const QString&, int)));
2162     connect(m_projectList, SIGNAL(updateRenderStatus()), this, SLOT(slotCheckRenderStatus()));
2163
2164
2165     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu, m_clipTypeGroup, (QMenu*)(factory()->container("marker_menu", this)));
2166     m_activeTimeline = trackView;
2167     if (m_renderWidget) {
2168         slotCheckRenderStatus();
2169         m_renderWidget->setProfile(doc->mltProfile());
2170         m_renderWidget->setGuides(doc->guidesXml(), doc->projectDuration());
2171         m_renderWidget->setDocumentPath(doc->projectFolder().path(KUrl::AddTrailingSlash));
2172         m_renderWidget->setRenderProfile(doc->getDocumentProperty("renderdestination"), doc->getDocumentProperty("rendercategory"), doc->getDocumentProperty("renderprofile"), doc->getDocumentProperty("renderurl"));
2173     }
2174     //doc->setRenderer(m_projectMonitor->render);
2175     m_commandStack->setActiveStack(doc->commandStack());
2176     KdenliveSettings::setProject_display_ratio(doc->dar());
2177     //doc->clipManager()->checkAudioThumbs();
2178
2179     //m_overView->setScene(trackView->projectScene());
2180     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
2181     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
2182
2183     setCaption(doc->description(), doc->isModified());
2184     m_saveAction->setEnabled(doc->isModified());
2185     m_normalEditTool->setChecked(true);
2186     m_activeDocument = doc;
2187     m_activeTimeline->updateProjectFps();
2188     m_activeDocument->checkProjectClips();
2189     if (KdenliveSettings::dropbframes()) slotUpdatePreviewSettings();
2190     //Update the mouse position display so it will display in DF/NDF format by default based on the project setting.
2191     slotUpdateMousePosition(0);
2192     // set tool to select tool
2193     m_buttonSelectTool->setChecked(true);
2194 }
2195
2196 void MainWindow::slotZoneMoved(int start, int end)
2197 {
2198     m_activeDocument->setZone(start, end);
2199     m_projectMonitor->slotZoneMoved(start, end);
2200 }
2201
2202 void MainWindow::slotGuidesUpdated()
2203 {
2204     if (m_renderWidget)
2205         m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
2206 }
2207
2208 void MainWindow::slotEditKeys()
2209 {
2210     KShortcutsDialog dialog(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, this);
2211     dialog.addCollection(actionCollection(), i18nc("general keyboard shortcuts", "General"));
2212     dialog.addCollection(m_effectsActionCollection, i18nc("effects and transitions keyboard shortcuts", "Effects & Transitions"));
2213     dialog.configure();
2214 }
2215
2216 void MainWindow::slotPreferences(int page, int option)
2217 {
2218     //An instance of your dialog could be already created and could be
2219     // cached, in which case you want to display the cached dialog
2220     // instead of creating another one
2221     if (KConfigDialog::showDialog("settings")) {
2222         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
2223         if (page != -1) d->showPage(page, option);
2224         return;
2225     }
2226
2227     // KConfigDialog didn't find an instance of this dialog, so lets
2228     // create it :
2229     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
2230     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
2231     //connect(dialog, SIGNAL(doResetProfile()), this, SLOT(slotDetectAudioDriver()));
2232     connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(slotResetProfiles()));
2233     connect(dialog, SIGNAL(updatePreviewSettings()), this, SLOT(slotUpdatePreviewSettings()));
2234 #ifndef Q_WS_MAC
2235     connect(dialog, SIGNAL(updateCaptureFolder()), m_recMonitor, SLOT(slotUpdateCaptureFolder()));
2236 #endif
2237     //connect(dialog, SIGNAL(updatePreviewSettings()), this, SLOT(slotUpdatePreviewSettings()));
2238     dialog->show();
2239     if (page != -1) dialog->showPage(page, option);
2240 }
2241
2242 void MainWindow::slotUpdatePreviewSettings()
2243 {
2244     if (m_activeDocument) {
2245         m_clipMonitor->slotSetXml(NULL);
2246         m_activeDocument->updatePreviewSettings();
2247     }
2248 }
2249
2250 void MainWindow::updateConfiguration()
2251 {
2252     //TODO: we should apply settings to all projects, not only the current one
2253     if (m_activeTimeline) {
2254         m_activeTimeline->refresh();
2255         m_activeTimeline->projectView()->checkAutoScroll();
2256         m_activeTimeline->projectView()->checkTrackHeight();
2257         if (m_activeDocument)
2258             m_activeDocument->clipManager()->checkAudioThumbs();
2259     }
2260     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
2261     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
2262     m_buttonAutomaticSplitAudio->setChecked(KdenliveSettings::splitaudio());
2263
2264     // Update list of transcoding profiles
2265     loadTranscoders();
2266 #ifndef NO_JOGSHUTTLE
2267     activateShuttleDevice();
2268 #endif /* NO_JOGSHUTTLE */
2269
2270 }
2271
2272 void MainWindow::slotSwitchSplitAudio()
2273 {
2274     KdenliveSettings::setSplitaudio(!KdenliveSettings::splitaudio());
2275     m_buttonAutomaticSplitAudio->setChecked(KdenliveSettings::splitaudio());
2276 }
2277
2278 void MainWindow::slotSwitchVideoThumbs()
2279 {
2280     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
2281     if (m_activeTimeline)
2282         m_activeTimeline->projectView()->slotUpdateAllThumbs();
2283     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
2284 }
2285
2286 void MainWindow::slotSwitchAudioThumbs()
2287 {
2288     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
2289     if (m_activeTimeline) {
2290         m_activeTimeline->refresh();
2291         m_activeTimeline->projectView()->checkAutoScroll();
2292         if (m_activeDocument)
2293             m_activeDocument->clipManager()->checkAudioThumbs();
2294     }
2295     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
2296 }
2297
2298 void MainWindow::slotSwitchMarkersComments()
2299 {
2300     KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
2301     if (m_activeTimeline)
2302         m_activeTimeline->refresh();
2303     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
2304 }
2305
2306 void MainWindow::slotSwitchSnap()
2307 {
2308     KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
2309     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
2310 }
2311
2312
2313 void MainWindow::slotDeleteItem()
2314 {
2315     if (QApplication::focusWidget() &&
2316         QApplication::focusWidget()->parentWidget() &&
2317         QApplication::focusWidget()->parentWidget()->parentWidget() &&
2318         QApplication::focusWidget()->parentWidget()->parentWidget() == m_projectListDock) {
2319         m_projectList->slotRemoveClip();
2320
2321     } else {
2322         QWidget *widget = QApplication::focusWidget();
2323         while (widget) {
2324             if (widget == m_effectStackDock) {
2325                 m_effectStack->slotItemDel();
2326                 return;
2327             }
2328             widget = widget->parentWidget();
2329         }
2330
2331         // effect stack has no focus
2332         if (m_activeTimeline)
2333             m_activeTimeline->projectView()->deleteSelectedClips();
2334     }
2335 }
2336
2337 void MainWindow::slotUpdateClipMarkers(DocClipBase *clip)
2338 {
2339     if (m_clipMonitor->isActive())
2340         m_clipMonitor->checkOverlay();
2341     m_clipMonitor->updateMarkers(clip);
2342 }
2343
2344 void MainWindow::slotAddClipMarker()
2345 {
2346     DocClipBase *clip = NULL;
2347     GenTime pos;
2348     if (m_projectMonitor->isActive()) {
2349         if (m_activeTimeline) {
2350             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2351             if (item) {
2352                 pos = GenTime((int)((m_projectMonitor->position() - item->startPos() + item->cropStart()).frames(m_activeDocument->fps()) * item->speed() + 0.5), m_activeDocument->fps());
2353                 clip = item->baseClip();
2354             }
2355         }
2356     } else {
2357         clip = m_clipMonitor->activeClip();
2358         pos = m_clipMonitor->position();
2359     }
2360     if (!clip) {
2361         m_messageLabel->setMessage(i18n("Cannot find clip to add marker"), ErrorMessage);
2362         return;
2363     }
2364     QString id = clip->getId();
2365     CommentedTime marker(pos, i18n("Marker"));
2366     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Add Marker"), this);
2367     if (d.exec() == QDialog::Accepted)
2368         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
2369 }
2370
2371 void MainWindow::slotDeleteClipMarker()
2372 {
2373     DocClipBase *clip = NULL;
2374     GenTime pos;
2375     if (m_projectMonitor->isActive()) {
2376         if (m_activeTimeline) {
2377             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2378             if (item) {
2379                 pos = (m_projectMonitor->position() - item->startPos() + item->cropStart()) / item->speed();
2380                 clip = item->baseClip();
2381             }
2382         }
2383     } else {
2384         clip = m_clipMonitor->activeClip();
2385         pos = m_clipMonitor->position();
2386     }
2387     if (!clip) {
2388         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2389         return;
2390     }
2391
2392     QString id = clip->getId();
2393     QString comment = clip->markerComment(pos);
2394     if (comment.isEmpty()) {
2395         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
2396         return;
2397     }
2398     m_activeTimeline->projectView()->slotDeleteClipMarker(comment, id, pos);
2399 }
2400
2401 void MainWindow::slotDeleteAllClipMarkers()
2402 {
2403     DocClipBase *clip = NULL;
2404     if (m_projectMonitor->isActive()) {
2405         if (m_activeTimeline) {
2406             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2407             if (item) {
2408                 clip = item->baseClip();
2409             }
2410         }
2411     } else {
2412         clip = m_clipMonitor->activeClip();
2413     }
2414     if (!clip) {
2415         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2416         return;
2417     }
2418     m_activeTimeline->projectView()->slotDeleteAllClipMarkers(clip->getId());
2419 }
2420
2421 void MainWindow::slotEditClipMarker()
2422 {
2423     DocClipBase *clip = NULL;
2424     GenTime pos;
2425     if (m_projectMonitor->isActive()) {
2426         if (m_activeTimeline) {
2427             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2428             if (item) {
2429                 pos = (m_projectMonitor->position() - item->startPos() + item->cropStart()) / item->speed();
2430                 clip = item->baseClip();
2431             }
2432         }
2433     } else {
2434         clip = m_clipMonitor->activeClip();
2435         pos = m_clipMonitor->position();
2436     }
2437     if (!clip) {
2438         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2439         return;
2440     }
2441
2442     QString id = clip->getId();
2443     QString oldcomment = clip->markerComment(pos);
2444     if (oldcomment.isEmpty()) {
2445         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
2446         return;
2447     }
2448
2449     CommentedTime marker(pos, oldcomment);
2450     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Edit Marker"), this);
2451     if (d.exec() == QDialog::Accepted) {
2452         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
2453         if (d.newMarker().time() != pos) {
2454             // remove old marker
2455             m_activeTimeline->projectView()->slotAddClipMarker(id, pos, QString());
2456         }
2457     }
2458 }
2459
2460 void MainWindow::slotAddGuide()
2461 {
2462     if (m_activeTimeline)
2463         m_activeTimeline->projectView()->slotAddGuide();
2464 }
2465
2466 void MainWindow::slotInsertSpace()
2467 {
2468     if (m_activeTimeline)
2469         m_activeTimeline->projectView()->slotInsertSpace();
2470 }
2471
2472 void MainWindow::slotRemoveSpace()
2473 {
2474     if (m_activeTimeline)
2475         m_activeTimeline->projectView()->slotRemoveSpace();
2476 }
2477
2478 void MainWindow::slotInsertTrack(int ix)
2479 {
2480     m_projectMonitor->activateMonitor();
2481     if (m_activeTimeline)
2482         m_activeTimeline->projectView()->slotInsertTrack(ix);
2483     if (m_activeDocument)
2484         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
2485 }
2486
2487 void MainWindow::slotDeleteTrack(int ix)
2488 {
2489     m_projectMonitor->activateMonitor();
2490     if (m_activeTimeline)
2491         m_activeTimeline->projectView()->slotDeleteTrack(ix);
2492     if (m_activeDocument)
2493         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
2494 }
2495
2496 void MainWindow::slotConfigTrack(int ix)
2497 {
2498     m_projectMonitor->activateMonitor();
2499     if (m_activeTimeline)
2500         m_activeTimeline->projectView()->slotConfigTracks(ix);
2501     if (m_activeDocument)
2502         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
2503 }
2504
2505 void MainWindow::slotEditGuide()
2506 {
2507     if (m_activeTimeline)
2508         m_activeTimeline->projectView()->slotEditGuide();
2509 }
2510
2511 void MainWindow::slotDeleteGuide()
2512 {
2513     if (m_activeTimeline)
2514         m_activeTimeline->projectView()->slotDeleteGuide();
2515 }
2516
2517 void MainWindow::slotDeleteAllGuides()
2518 {
2519     if (m_activeTimeline)
2520         m_activeTimeline->projectView()->slotDeleteAllGuides();
2521 }
2522
2523 void MainWindow::slotCutTimelineClip()
2524 {
2525     if (m_activeTimeline)
2526         m_activeTimeline->projectView()->cutSelectedClips();
2527 }
2528
2529 void MainWindow::slotInsertClipOverwrite()
2530 {
2531     if (m_activeTimeline) {
2532         QStringList data = m_clipMonitor->getZoneInfo();
2533         m_activeTimeline->projectView()->insertZoneOverwrite(data, m_activeTimeline->inPoint());
2534     }
2535 }
2536
2537 void MainWindow::slotSelectTimelineClip()
2538 {
2539     if (m_activeTimeline)
2540         m_activeTimeline->projectView()->selectClip(true);
2541 }
2542
2543 void MainWindow::slotSelectTimelineTransition()
2544 {
2545     if (m_activeTimeline)
2546         m_activeTimeline->projectView()->selectTransition(true);
2547 }
2548
2549 void MainWindow::slotDeselectTimelineClip()
2550 {
2551     if (m_activeTimeline)
2552         m_activeTimeline->projectView()->selectClip(false, true);
2553 }
2554
2555 void MainWindow::slotDeselectTimelineTransition()
2556 {
2557     if (m_activeTimeline)
2558         m_activeTimeline->projectView()->selectTransition(false, true);
2559 }
2560
2561 void MainWindow::slotSelectAddTimelineClip()
2562 {
2563     if (m_activeTimeline)
2564         m_activeTimeline->projectView()->selectClip(true, true);
2565 }
2566
2567 void MainWindow::slotSelectAddTimelineTransition()
2568 {
2569     if (m_activeTimeline)
2570         m_activeTimeline->projectView()->selectTransition(true, true);
2571 }
2572
2573 void MainWindow::slotGroupClips()
2574 {
2575     if (m_activeTimeline)
2576         m_activeTimeline->projectView()->groupClips();
2577 }
2578
2579 void MainWindow::slotUnGroupClips()
2580 {
2581     if (m_activeTimeline)
2582         m_activeTimeline->projectView()->groupClips(false);
2583 }
2584
2585 void MainWindow::slotEditItemDuration()
2586 {
2587     if (m_activeTimeline)
2588         m_activeTimeline->projectView()->editItemDuration();
2589 }
2590
2591 void MainWindow::slotAddProjectClip(KUrl url)
2592 {
2593     if (m_activeDocument)
2594         m_activeDocument->slotAddClipFile(url, QString());
2595 }
2596
2597 void MainWindow::slotAddTransition(QAction *result)
2598 {
2599     if (!result) return;
2600     QStringList info = result->data().toStringList();
2601     if (info.isEmpty()) return;
2602     QDomElement transition = transitions.getEffectByTag(info.at(1), info.at(2));
2603     if (m_activeTimeline && !transition.isNull()) {
2604         m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(transition.cloneNode().toElement());
2605     }
2606 }
2607
2608 void MainWindow::slotAddVideoEffect(QAction *result)
2609 {
2610     if (!result) return;
2611     QStringList info = result->data().toStringList();
2612     if (info.isEmpty()) return;
2613     QDomElement effect = videoEffects.getEffectByTag(info.at(1), info.at(2));
2614     slotAddEffect(effect);
2615 }
2616
2617 void MainWindow::slotAddAudioEffect(QAction *result)
2618 {
2619     if (!result) return;
2620     QStringList info = result->data().toStringList();
2621     if (info.isEmpty()) return;
2622     QDomElement effect = audioEffects.getEffectByTag(info.at(1), info.at(2));
2623     slotAddEffect(effect);
2624 }
2625
2626 void MainWindow::slotAddCustomEffect(QAction *result)
2627 {
2628     if (!result) return;
2629     QStringList info = result->data().toStringList();
2630     if (info.isEmpty()) return;
2631     QDomElement effect = customEffects.getEffectByTag(info.at(1), info.at(2));
2632     slotAddEffect(effect);
2633 }
2634
2635 void MainWindow::slotZoomIn()
2636 {
2637     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
2638     slotShowZoomSliderToolTip();
2639 }
2640
2641 void MainWindow::slotZoomOut()
2642 {
2643     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
2644     slotShowZoomSliderToolTip();
2645 }
2646
2647 void MainWindow::slotFitZoom()
2648 {
2649     if (m_activeTimeline)
2650         m_zoomSlider->setValue(m_activeTimeline->fitZoom());
2651 }
2652
2653 void MainWindow::slotSetZoom(int value)
2654 {
2655     if (m_activeTimeline)
2656         m_activeTimeline->slotChangeZoom(value);
2657
2658     m_zoomOut->setEnabled(value < m_zoomSlider->maximum());
2659     m_zoomIn->setEnabled(value > m_zoomSlider->minimum());
2660     slotUpdateZoomSliderToolTip(value);
2661
2662     m_zoomSlider->blockSignals(true);
2663     m_zoomSlider->setValue(value);
2664     m_zoomSlider->blockSignals(false);
2665 }
2666
2667 void MainWindow::slotShowZoomSliderToolTip(int zoomlevel)
2668 {
2669     if (zoomlevel != -1)
2670         slotUpdateZoomSliderToolTip(zoomlevel);
2671
2672     QPoint global = m_zoomSlider->rect().topLeft();
2673     global.ry() += m_zoomSlider->height() / 2;
2674     QHelpEvent toolTipEvent(QEvent::ToolTip, QPoint(0, 0), m_zoomSlider->mapToGlobal(global));
2675     QApplication::sendEvent(m_zoomSlider, &toolTipEvent);
2676 }
2677
2678 void MainWindow::slotUpdateZoomSliderToolTip(int zoomlevel)
2679 {
2680     m_zoomSlider->setToolTip(i18n("Zoom Level: %1/13", (13 - zoomlevel)));
2681 }
2682
2683 void MainWindow::slotGotProgressInfo(const QString &message, int progress)
2684 {
2685     m_statusProgressBar->setValue(progress);
2686     if (progress >= 0) {
2687         if (!message.isEmpty())
2688             m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
2689         m_statusProgressBar->setVisible(true);
2690     } else if (progress == -2) {
2691         if (!message.isEmpty())
2692             m_messageLabel->setMessage(message, ErrorMessage);
2693         m_statusProgressBar->setVisible(false);
2694     } else {
2695         m_messageLabel->setMessage(QString(), DefaultMessage);
2696         m_statusProgressBar->setVisible(false);
2697     }
2698 }
2699
2700 void MainWindow::slotShowClipProperties(DocClipBase *clip)
2701 {
2702     if (clip->clipType() == TEXT) {
2703         QString titlepath = m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
2704         if (!clip->getProperty("resource").isEmpty() && clip->getProperty("xmldata").isEmpty()) {
2705             // template text clip
2706
2707             // Get the list of existing templates
2708             QStringList filter;
2709             filter << "*.kdenlivetitle";
2710             QStringList templateFiles = QDir(titlepath).entryList(filter, QDir::Files);
2711
2712             QDialog *dia = new QDialog(this);
2713             Ui::TemplateClip_UI dia_ui;
2714             dia_ui.setupUi(dia);
2715             int ix = -1;
2716             const QString templatePath = clip->getProperty("resource");
2717             for (int i = 0; i < templateFiles.size(); ++i) {
2718                 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), titlepath + templateFiles.at(i));
2719                 if (templatePath == KUrl(titlepath + templateFiles.at(i)).path()) ix = i;
2720             }
2721             if (ix != -1) dia_ui.template_list->comboBox()->setCurrentIndex(ix);
2722             else dia_ui.template_list->comboBox()->insertItem(0, templatePath);
2723             dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
2724             //warning: setting base directory doesn't work??
2725             KUrl startDir(titlepath);
2726             dia_ui.template_list->fileDialog()->setUrl(startDir);
2727             dia_ui.description->setText(clip->getProperty("description"));
2728             if (dia->exec() == QDialog::Accepted) {
2729                 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
2730                 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
2731
2732                 QMap <QString, QString> newprops;
2733
2734                 if (KUrl(textTemplate).path() != templatePath) {
2735                     // The template was changed
2736                     newprops.insert("resource", textTemplate);
2737                 }
2738
2739                 if (dia_ui.description->toPlainText() != clip->getProperty("description")) {
2740                     newprops.insert("description", dia_ui.description->toPlainText());
2741                 }
2742
2743                 QString newtemplate = newprops.value("xmltemplate");
2744                 if (newtemplate.isEmpty()) newtemplate = templatePath;
2745
2746                 // template modified we need to update xmldata
2747                 QString description = newprops.value("description");
2748                 if (description.isEmpty()) description = clip->getProperty("description");
2749                 else newprops.insert("templatetext", description);
2750                 //newprops.insert("xmldata", m_projectList->generateTemplateXml(newtemplate, description).toString());
2751                 if (!newprops.isEmpty()) {
2752                     EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
2753                     m_activeDocument->commandStack()->push(command);
2754                 }
2755             }
2756             delete dia;
2757             return;
2758         }
2759         QString path = clip->getProperty("resource");
2760         TitleWidget *dia_ui = new TitleWidget(KUrl(), m_activeDocument->timecode(), titlepath, m_projectMonitor->render, this);
2761         QDomDocument doc;
2762         doc.setContent(clip->getProperty("xmldata"));
2763         dia_ui->setXml(doc);
2764         if (dia_ui->exec() == QDialog::Accepted) {
2765             QMap <QString, QString> newprops;
2766             newprops.insert("xmldata", dia_ui->xml().toString());
2767             if (dia_ui->outPoint() != clip->duration().frames(m_activeDocument->fps()) - 1) {
2768                 // duration changed, we need to update duration
2769                 newprops.insert("out", QString::number(dia_ui->outPoint()));
2770             }
2771             EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
2772             m_activeDocument->commandStack()->push(command);
2773             //m_activeTimeline->projectView()->slotUpdateClip(clip->getId());
2774             m_activeDocument->setModified(true);
2775         }
2776         delete dia_ui;
2777
2778         //m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
2779         return;
2780     }
2781     ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
2782     connect(&dia, SIGNAL(addMarker(const QString &, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(const QString &, GenTime, QString)));
2783     if (dia.exec() == QDialog::Accepted) {
2784         QMap <QString, QString> newprops = dia.properties();
2785         if (newprops.isEmpty()) return;
2786         EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
2787         m_activeDocument->commandStack()->push(command);
2788
2789         if (dia.needsTimelineRefresh()) {
2790             // update clip occurences in timeline
2791             m_activeTimeline->projectView()->slotUpdateClip(clip->getId(), dia.needsTimelineReload());
2792         }
2793     }
2794 }
2795
2796
2797 void MainWindow::slotShowClipProperties(QList <DocClipBase *> cliplist, QMap<QString, QString> commonproperties)
2798 {
2799     ClipProperties dia(cliplist, m_activeDocument->timecode(), commonproperties, this);
2800     if (dia.exec() == QDialog::Accepted) {
2801         QUndoCommand *command = new QUndoCommand();
2802         command->setText(i18n("Edit clips"));
2803         for (int i = 0; i < cliplist.count(); i++) {
2804             DocClipBase *clip = cliplist.at(i);
2805             new EditClipCommand(m_projectList, clip->getId(), clip->properties(), dia.properties(), true, command);
2806         }
2807         m_activeDocument->commandStack()->push(command);
2808         for (int i = 0; i < cliplist.count(); i++)
2809             m_activeTimeline->projectView()->slotUpdateClip(cliplist.at(i)->getId(), dia.needsTimelineReload());
2810     }
2811 }
2812
2813 void MainWindow::customEvent(QEvent* e)
2814 {
2815     if (e->type() == QEvent::User)
2816         m_messageLabel->setMessage(static_cast <MltErrorEvent *>(e)->message(), MltError);
2817 }
2818 void MainWindow::slotActivateEffectStackView()
2819 {
2820     m_effectStack->raiseWindow(m_effectStackDock);
2821 }
2822
2823 void MainWindow::slotActivateTransitionView(Transition *t)
2824 {
2825     if (t)
2826         m_transitionConfig->raiseWindow(m_transitionConfigDock);
2827 }
2828
2829 void MainWindow::slotSnapRewind()
2830 {
2831     if (m_projectMonitor->isActive()) {
2832         if (m_activeTimeline)
2833             m_activeTimeline->projectView()->slotSeekToPreviousSnap();
2834     } else  {
2835         m_clipMonitor->slotSeekToPreviousSnap();
2836     }
2837 }
2838
2839 void MainWindow::slotSnapForward()
2840 {
2841     if (m_projectMonitor->isActive()) {
2842         if (m_activeTimeline)
2843             m_activeTimeline->projectView()->slotSeekToNextSnap();
2844     } else {
2845         m_clipMonitor->slotSeekToNextSnap();
2846     }
2847 }
2848
2849 void MainWindow::slotClipStart()
2850 {
2851     if (m_projectMonitor->isActive()) {
2852         if (m_activeTimeline)
2853             m_activeTimeline->projectView()->clipStart();
2854     }
2855 }
2856
2857 void MainWindow::slotClipEnd()
2858 {
2859     if (m_projectMonitor->isActive()) {
2860         if (m_activeTimeline)
2861             m_activeTimeline->projectView()->clipEnd();
2862     }
2863 }
2864
2865 void MainWindow::slotZoneStart()
2866 {
2867     if (m_projectMonitor->isActive())
2868         m_projectMonitor->slotZoneStart();
2869     else
2870         m_clipMonitor->slotZoneStart();
2871 }
2872
2873 void MainWindow::slotZoneEnd()
2874 {
2875     if (m_projectMonitor->isActive())
2876         m_projectMonitor->slotZoneEnd();
2877     else
2878         m_clipMonitor->slotZoneEnd();
2879 }
2880
2881 void MainWindow::slotChangeTool(QAction * action)
2882 {
2883     if (action == m_buttonSelectTool)
2884         slotSetTool(SELECTTOOL);
2885     else if (action == m_buttonRazorTool)
2886         slotSetTool(RAZORTOOL);
2887     else if (action == m_buttonSpacerTool)
2888         slotSetTool(SPACERTOOL);
2889 }
2890
2891 void MainWindow::slotChangeEdit(QAction * action)
2892 {
2893     if (!m_activeTimeline)
2894         return;
2895
2896     if (action == m_overwriteEditTool)
2897         m_activeTimeline->projectView()->setEditMode(OVERWRITEEDIT);
2898     else if (action == m_insertEditTool)
2899         m_activeTimeline->projectView()->setEditMode(INSERTEDIT);
2900     else
2901         m_activeTimeline->projectView()->setEditMode(NORMALEDIT);
2902 }
2903
2904 void MainWindow::slotSetTool(PROJECTTOOL tool)
2905 {
2906     if (m_activeDocument && m_activeTimeline) {
2907         //m_activeDocument->setTool(tool);
2908         QString message;
2909         switch (tool)  {
2910         case SPACERTOOL:
2911             message = i18n("Ctrl + click to use spacer on current track only");
2912             break;
2913         case RAZORTOOL:
2914             message = i18n("Click on a clip to cut it");
2915             break;
2916         default:
2917             message = i18n("Shift + click to create a selection rectangle, Ctrl + click to add an item to selection");
2918             break;
2919         }
2920         m_messageLabel->setMessage(message, InformationMessage);
2921         m_activeTimeline->projectView()->setTool(tool);
2922     }
2923 }
2924
2925 void MainWindow::slotCopy()
2926 {
2927     if (m_activeDocument && m_activeTimeline)
2928         m_activeTimeline->projectView()->copyClip();
2929 }
2930
2931 void MainWindow::slotPaste()
2932 {
2933     if (m_activeDocument && m_activeTimeline)
2934         m_activeTimeline->projectView()->pasteClip();
2935 }
2936
2937 void MainWindow::slotPasteEffects()
2938 {
2939     if (m_activeDocument && m_activeTimeline)
2940         m_activeTimeline->projectView()->pasteClipEffects();
2941 }
2942
2943 void MainWindow::slotFind()
2944 {
2945     if (!m_activeDocument || !m_activeTimeline) return;
2946     m_projectSearch->setEnabled(false);
2947     m_findActivated = true;
2948     m_findString.clear();
2949     m_activeTimeline->projectView()->initSearchStrings();
2950     statusBar()->showMessage(i18n("Starting -- find text as you type"));
2951     m_findTimer.start(5000);
2952     qApp->installEventFilter(this);
2953 }
2954
2955 void MainWindow::slotFindNext()
2956 {
2957     if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString))
2958         statusBar()->showMessage(i18n("Found: %1", m_findString));
2959     else
2960         statusBar()->showMessage(i18n("Reached end of project"));
2961     m_findTimer.start(4000);
2962 }
2963
2964 void MainWindow::findAhead()
2965 {
2966     if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
2967         m_projectSearchNext->setEnabled(true);
2968         statusBar()->showMessage(i18n("Found: %1", m_findString));
2969     } else {
2970         m_projectSearchNext->setEnabled(false);
2971         statusBar()->showMessage(i18n("Not found: %1", m_findString));
2972     }
2973 }
2974
2975 void MainWindow::findTimeout()
2976 {
2977     m_projectSearchNext->setEnabled(false);
2978     m_findActivated = false;
2979     m_findString.clear();
2980     statusBar()->showMessage(i18n("Find stopped"), 3000);
2981     if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
2982     m_projectSearch->setEnabled(true);
2983     removeEventFilter(this);
2984 }
2985
2986 void MainWindow::slotClipInTimeline(const QString &clipId)
2987 {
2988     if (m_activeTimeline && m_activeDocument) {
2989         QList<ItemInfo> matching = m_activeTimeline->projectView()->findId(clipId);
2990
2991         QMenu *inTimelineMenu = static_cast<QMenu*>(factory()->container("clip_in_timeline", this));
2992         inTimelineMenu->clear();
2993
2994         QList <QAction *> actionList;
2995
2996         for (int i = 0; i < matching.count(); ++i) {
2997             QString track = QString::number(matching.at(i).track);
2998             QString start = m_activeDocument->timecode().getTimecode(matching.at(i).startPos);
2999             int j = 0;
3000             QAction *a = new QAction(track + ": " + start, this);
3001             a->setData(QStringList() << track << start);
3002             connect(a, SIGNAL(triggered()), this, SLOT(slotSelectClipInTimeline()));
3003             while (j < actionList.count()) {
3004                 if (actionList.at(j)->text() > a->text()) break;
3005                 j++;
3006             }
3007             actionList.insert(j, a);
3008         }
3009         inTimelineMenu->addActions(actionList);
3010
3011         if (matching.empty())
3012             inTimelineMenu->setEnabled(false);
3013         else
3014             inTimelineMenu->setEnabled(true);
3015     }
3016 }
3017
3018 void MainWindow::slotClipInProjectTree()
3019 {
3020     if (m_activeTimeline) {
3021         const QStringList &clipIds = m_activeTimeline->projectView()->selectedClips();
3022         if (clipIds.isEmpty())
3023             return;
3024         m_projectListDock->raise();
3025         for (int i = 0; i < clipIds.count(); i++)
3026             m_projectList->selectItemById(clipIds.at(i));
3027         if (m_projectMonitor->isActive())
3028             slotSwitchMonitors();
3029     }
3030 }
3031
3032 /*void MainWindow::slotClipToProjectTree()
3033 {
3034     if (m_activeTimeline) {
3035     const QList<ClipItem *> clips =  m_activeTimeline->projectView()->selectedClipItems();
3036         if (clips.isEmpty()) return;
3037         for (int i = 0; i < clips.count(); i++) {
3038         m_projectList->slotAddXmlClip(clips.at(i)->itemXml());
3039         }
3040         //m_projectList->selectItemById(clipIds.at(i));
3041     }
3042 }*/
3043
3044 void MainWindow::slotSelectClipInTimeline()
3045 {
3046     if (m_activeTimeline) {
3047         QAction *action = qobject_cast<QAction *>(sender());
3048         QStringList data = action->data().toStringList();
3049         m_activeTimeline->projectView()->selectFound(data.at(0), data.at(1));
3050     }
3051 }
3052
3053 void MainWindow::keyPressEvent(QKeyEvent *ke)
3054 {
3055     if (m_findActivated) {
3056         if (ke->key() == Qt::Key_Backspace) {
3057             m_findString = m_findString.left(m_findString.length() - 1);
3058
3059             if (!m_findString.isEmpty())
3060                 findAhead();
3061             else
3062                 findTimeout();
3063
3064             m_findTimer.start(4000);
3065             ke->accept();
3066             return;
3067         } else if (ke->key() == Qt::Key_Escape) {
3068             findTimeout();
3069             ke->accept();
3070             return;
3071         } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
3072             m_findString += ke->text();
3073
3074             findAhead();
3075
3076             m_findTimer.start(4000);
3077             ke->accept();
3078             return;
3079         }
3080     } else {
3081         KXmlGuiWindow::keyPressEvent(ke);
3082     }
3083 }
3084
3085
3086 /** Gets called when the window gets hidden */
3087 void MainWindow::hideEvent(QHideEvent */*event*/)
3088 {
3089     if (isMinimized())
3090         if (m_monitorManager)
3091             m_monitorManager->stopActiveMonitor();
3092 }
3093
3094 bool MainWindow::eventFilter(QObject *obj, QEvent *event)
3095 {
3096     if (m_findActivated) {
3097         if (event->type() == QEvent::ShortcutOverride) {
3098             QKeyEvent* ke = (QKeyEvent*) event;
3099             if (ke->text().trimmed().isEmpty()) return false;
3100             ke->accept();
3101             return true;
3102         } else {
3103             return false;
3104         }
3105     } else {
3106         // pass the event on to the parent class
3107         return QMainWindow::eventFilter(obj, event);
3108     }
3109 }
3110
3111
3112 void MainWindow::slotSaveZone(Render *render, QPoint zone)
3113 {
3114     KDialog *dialog = new KDialog(this);
3115     dialog->setCaption("Save clip zone");
3116     dialog->setButtons(KDialog::Ok | KDialog::Cancel);
3117
3118     QWidget *widget = new QWidget(dialog);
3119     dialog->setMainWidget(widget);
3120
3121     QVBoxLayout *vbox = new QVBoxLayout(widget);
3122     QLabel *label1 = new QLabel(i18n("Save clip zone as:"), this);
3123     QString path = m_activeDocument->projectFolder().path();
3124     path.append("/");
3125     path.append("untitled.mlt");
3126     KUrlRequester *url = new KUrlRequester(KUrl(path), this);
3127     url->setFilter("video/mlt-playlist");
3128     QLabel *label2 = new QLabel(i18n("Description:"), this);
3129     KLineEdit *edit = new KLineEdit(this);
3130     vbox->addWidget(label1);
3131     vbox->addWidget(url);
3132     vbox->addWidget(label2);
3133     vbox->addWidget(edit);
3134     if (dialog->exec() == QDialog::Accepted)
3135         render->saveZone(url->url(), edit->text(), zone);
3136
3137 }
3138
3139 void MainWindow::slotSetInPoint()
3140 {
3141     if (m_clipMonitor->isActive())
3142         m_clipMonitor->slotSetZoneStart();
3143     else
3144         m_projectMonitor->slotSetZoneStart();
3145     //else m_activeTimeline->projectView()->setInPoint();
3146 }
3147
3148 void MainWindow::slotSetOutPoint()
3149 {
3150     if (m_clipMonitor->isActive())
3151         m_clipMonitor->slotSetZoneEnd();
3152     else
3153         m_projectMonitor->slotSetZoneEnd();
3154     // else m_activeTimeline->projectView()->setOutPoint();
3155 }
3156
3157 void MainWindow::slotResizeItemStart()
3158 {
3159     if (m_activeTimeline)
3160         m_activeTimeline->projectView()->setInPoint();
3161 }
3162
3163 void MainWindow::slotResizeItemEnd()
3164 {
3165     if (m_activeTimeline)
3166         m_activeTimeline->projectView()->setOutPoint();
3167 }
3168
3169 int MainWindow::getNewStuff(const QString &configFile)
3170 {
3171     KNS3::Entry::List entries;
3172 #if KDE_IS_VERSION(4,3,80)
3173     KNS3::DownloadDialog dialog(configFile);
3174     dialog.exec();
3175     entries = dialog.changedEntries();
3176     foreach(const KNS3::Entry &entry, entries) {
3177         if (entry.status() == KNS3::Entry::Installed)
3178             kDebug() << "// Installed files: " << entry.installedFiles();
3179     }
3180 #else
3181     KNS::Engine engine(0);
3182     if (engine.init(configFile))
3183         entries = engine.downloadDialogModal(this);
3184     foreach(KNS::Entry *entry, entries) {
3185         if (entry->status() == KNS::Entry::Installed)
3186             kDebug() << "// Installed files: " << entry->installedFiles();
3187     }
3188 #endif /* KDE_IS_VERSION(4,3,80) */
3189     return entries.size();
3190 }
3191
3192 void MainWindow::slotGetNewTitleStuff()
3193 {
3194     if (getNewStuff("kdenlive_titles.knsrc") > 0)
3195         TitleWidget::refreshTitleTemplates();
3196 }
3197
3198 void MainWindow::slotGetNewLumaStuff()
3199 {
3200     if (getNewStuff("kdenlive_wipes.knsrc") > 0) {
3201         initEffects::refreshLumas();
3202         m_activeTimeline->projectView()->reloadTransitionLumas();
3203     }
3204 }
3205
3206 void MainWindow::slotGetNewRenderStuff()
3207 {
3208     if (getNewStuff("kdenlive_renderprofiles.knsrc") > 0)
3209         if (m_renderWidget)
3210             m_renderWidget->reloadProfiles();
3211 }
3212
3213 void MainWindow::slotGetNewMltProfileStuff()
3214 {
3215     if (getNewStuff("kdenlive_projectprofiles.knsrc") > 0) {
3216         // update the list of profiles in settings dialog
3217         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
3218         if (d)
3219             d->checkProfile();
3220     }
3221 }
3222
3223 void MainWindow::slotAutoTransition()
3224 {
3225     if (m_activeTimeline)
3226         m_activeTimeline->projectView()->autoTransition();
3227 }
3228
3229 void MainWindow::slotSplitAudio()
3230 {
3231     if (m_activeTimeline)
3232         m_activeTimeline->projectView()->splitAudio();
3233 }
3234
3235 void MainWindow::slotUpdateClipType(QAction *action)
3236 {
3237     if (m_activeTimeline) {
3238         if (action->data().toString() == "clip_audio_only") m_activeTimeline->projectView()->setAudioOnly();
3239         else if (action->data().toString() == "clip_video_only") m_activeTimeline->projectView()->setVideoOnly();
3240         else m_activeTimeline->projectView()->setAudioAndVideo();
3241     }
3242 }
3243
3244 void MainWindow::slotDvdWizard(const QString &url, const QString &profile)
3245 {
3246     // We must stop the monitors since we create a new on in the dvd wizard
3247     m_clipMonitor->stop();
3248     m_projectMonitor->stop();
3249     DvdWizard w(url, profile, this);
3250     w.exec();
3251     m_projectMonitor->start();
3252 }
3253
3254 void MainWindow::slotShowTimeline(bool show)
3255 {
3256     if (show == false) {
3257         m_timelineState = saveState();
3258         centralWidget()->setHidden(true);
3259     } else {
3260         centralWidget()->setHidden(false);
3261         restoreState(m_timelineState);
3262     }
3263 }
3264
3265 void MainWindow::slotMaximizeCurrent(bool /*show*/)
3266 {
3267     //TODO: is there a way to maximize current widget?
3268     //if (show == true)
3269     {
3270         m_timelineState = saveState();
3271         QWidget *par = focusWidget()->parentWidget();
3272         while (par->parentWidget() && par->parentWidget() != this)
3273             par = par->parentWidget();
3274         kDebug() << "CURRENT WIDGET: " << par->objectName();
3275     }
3276     /*else {
3277     //centralWidget()->setHidden(false);
3278     //restoreState(m_timelineState);
3279     }*/
3280 }
3281
3282 void MainWindow::loadTranscoders()
3283 {
3284     QMenu *transMenu = static_cast<QMenu*>(factory()->container("transcoders", this));
3285     transMenu->clear();
3286
3287     KSharedConfigPtr config = KSharedConfig::openConfig("kdenlivetranscodingrc");
3288     KConfigGroup transConfig(config, "Transcoding");
3289     // read the entries
3290     QMap< QString, QString > profiles = transConfig.entryMap();
3291     QMapIterator<QString, QString> i(profiles);
3292     while (i.hasNext()) {
3293         i.next();
3294         QStringList data = i.value().split(";", QString::SkipEmptyParts);
3295         QAction *a = transMenu->addAction(i.key());
3296         a->setData(data);
3297         if (data.count() > 1)
3298             a->setToolTip(data.at(1));
3299         connect(a, SIGNAL(triggered()), this, SLOT(slotTranscode()));
3300     }
3301 }
3302
3303 void MainWindow::slotTranscode(KUrl::List urls)
3304 {
3305     QString params;
3306     QString desc;
3307     QString condition;
3308     if (urls.isEmpty()) {
3309         QAction *action = qobject_cast<QAction *>(sender());
3310         QStringList data = action->data().toStringList();
3311         params = data.at(0);
3312         if (data.count() > 1) desc = data.at(1);
3313         if (data.count() > 2) condition = data.at(2);
3314         urls << m_projectList->getConditionalUrls(condition);
3315         urls.removeAll(KUrl());
3316     }
3317     if (urls.isEmpty()) {
3318         m_messageLabel->setMessage(i18n("No clip to transcode"), ErrorMessage);
3319         return;
3320     }
3321     ClipTranscode *d = new ClipTranscode(urls, params, desc);
3322     connect(d, SIGNAL(addClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
3323     d->show();
3324     //QProcess::startDetached("ffmpeg", parameters);
3325 }
3326
3327 void MainWindow::slotTranscodeClip()
3328 {
3329     KUrl::List urls = KFileDialog::getOpenUrls(KUrl("kfiledialog:///projectfolder"));
3330     if (urls.isEmpty()) return;
3331     slotTranscode(urls);
3332 }
3333
3334 void MainWindow::slotSetDocumentRenderProfile(const QString &dest, const QString &group, const QString &name, const QString &file)
3335 {
3336     if (m_activeDocument == NULL) return;
3337     m_activeDocument->setDocumentProperty("renderdestination", dest);
3338     m_activeDocument->setDocumentProperty("rendercategory", group);
3339     m_activeDocument->setDocumentProperty("renderprofile", name);
3340     m_activeDocument->setDocumentProperty("renderurl", file);
3341     m_activeDocument->setModified(true);
3342 }
3343
3344
3345 void MainWindow::slotPrepareRendering(bool scriptExport, bool zoneOnly, const QString &chapterFile)
3346 {
3347     if (m_activeDocument == NULL || m_renderWidget == NULL) return;
3348     QString scriptPath;
3349     QString playlistPath;
3350     if (scriptExport) {
3351         bool ok;
3352         QString scriptsFolder = m_activeDocument->projectFolder().path() + "/scripts/";
3353         QString path = m_renderWidget->getFreeScriptName();
3354         scriptPath = QInputDialog::getText(this, i18n("Create Render Script"), i18n("Script name (will be saved in: %1)", scriptsFolder), QLineEdit::Normal, KUrl(path).fileName(), &ok);
3355         if (!ok || scriptPath.isEmpty()) return;
3356         scriptPath.prepend(scriptsFolder);
3357         QFile f(scriptPath);
3358         if (f.exists()) {
3359             if (KMessageBox::warningYesNo(this, i18n("Script file already exists. Do you want to overwrite it?")) != KMessageBox::Yes)
3360                 return;
3361         }
3362         playlistPath = scriptPath + ".mlt";
3363         m_projectMonitor->saveSceneList(playlistPath);
3364     } else {
3365         KTemporaryFile temp;
3366         temp.setAutoRemove(false);
3367         temp.setSuffix(".mlt");
3368         temp.open();
3369         playlistPath = temp.fileName();
3370         m_projectMonitor->saveSceneList(playlistPath);
3371     }
3372
3373     if (!chapterFile.isEmpty()) {
3374         int in = 0;
3375         int out;
3376         if (!zoneOnly) out = (int) GenTime(m_activeDocument->projectDuration()).frames(m_activeDocument->fps());
3377         else {
3378             in = m_activeTimeline->inPoint();
3379             out = m_activeTimeline->outPoint();
3380         }
3381         QDomDocument doc;
3382         QDomElement chapters = doc.createElement("chapters");
3383         chapters.setAttribute("fps", m_activeDocument->fps());
3384         doc.appendChild(chapters);
3385
3386         QDomElement guidesxml = m_activeDocument->guidesXml();
3387         QDomNodeList nodes = guidesxml.elementsByTagName("guide");
3388         for (int i = 0; i < nodes.count(); i++) {
3389             QDomElement e = nodes.item(i).toElement();
3390             if (!e.isNull()) {
3391                 QString comment = e.attribute("comment");
3392                 int time = (int) GenTime(e.attribute("time").toDouble()).frames(m_activeDocument->fps());
3393                 if (time >= in && time < out) {
3394                     if (zoneOnly) time = time - in;
3395                     QDomElement chapter = doc.createElement("chapter");
3396                     chapters.appendChild(chapter);
3397                     chapter.setAttribute("title", comment);
3398                     chapter.setAttribute("time", time);
3399                 }
3400             }
3401         }
3402         if (chapters.childNodes().count() > 0) {
3403             if (m_activeTimeline->projectView()->hasGuide(out, 0) == -1) {
3404                 // Always insert a guide in pos 0
3405                 QDomElement chapter = doc.createElement("chapter");
3406                 chapters.insertBefore(chapter, QDomNode());
3407                 chapter.setAttribute("title", i18n("Start"));
3408                 chapter.setAttribute("time", "0");
3409             }
3410             // save chapters file
3411             QFile file(chapterFile);
3412             if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
3413                 kWarning() << "//////  ERROR writing DVD CHAPTER file: " << chapterFile;
3414             } else {
3415                 file.write(doc.toString().toUtf8());
3416                 if (file.error() != QFile::NoError) {
3417                     kWarning() << "//////  ERROR writing DVD CHAPTER file: " << chapterFile;
3418                 }
3419                 file.close();
3420             }
3421         }
3422     }
3423
3424     m_renderWidget->slotExport(scriptExport, m_activeTimeline->inPoint(), m_activeTimeline->outPoint(), playlistPath, scriptPath);
3425 }
3426
3427 void MainWindow::slotUpdateTimecodeFormat(int ix)
3428 {
3429     KdenliveSettings::setFrametimecode(ix == 1);
3430     m_clipMonitor->updateTimecodeFormat();
3431     m_projectMonitor->updateTimecodeFormat();
3432     m_transitionConfig->updateTimecodeFormat();
3433     m_effectStack->updateTimecodeFormat();
3434     //m_activeTimeline->projectView()->clearSelection();
3435     m_activeTimeline->updateRuler();
3436 }
3437
3438 void MainWindow::slotRemoveFocus()
3439 {
3440     statusBar()->setFocus();
3441     statusBar()->clearFocus();
3442 }
3443
3444 void MainWindow::slotRevert()
3445 {
3446     if (KMessageBox::warningContinueCancel(this, i18n("This will delete all changes made since you last saved your project. Are you sure you want to continue?"), i18n("Revert to last saved version")) == KMessageBox::Cancel) return;
3447     KUrl url = m_activeDocument->url();
3448     closeCurrentDocument(false);
3449     doOpenFile(url, NULL);
3450 }
3451
3452
3453 void MainWindow::slotShutdown()
3454 {
3455     if (m_activeDocument) m_activeDocument->setModified(false);
3456     // Call shutdown
3457     QDBusConnectionInterface* interface = QDBusConnection::sessionBus().interface();
3458     if (interface && interface->isServiceRegistered("org.kde.ksmserver")) {
3459         QDBusInterface smserver("org.kde.ksmserver", "/KSMServer", "org.kde.KSMServerInterface");
3460         smserver.call("logout", 1, 2, 2);
3461     } else if (interface && interface->isServiceRegistered("org.gnome.SessionManager")) {
3462         QDBusInterface smserver("org.gnome.SessionManager", "/org/gnome/SessionManager", "org.gnome.SessionManager");
3463         smserver.call("Shutdown");
3464     }
3465 }
3466
3467 void MainWindow::slotUpdateTrackInfo()
3468 {
3469     if (m_activeDocument)
3470         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
3471 }
3472
3473 void MainWindow::slotChangePalette(QAction *action, const QString &themename)
3474 {
3475     // Load the theme file
3476     QString theme;
3477     if (action == NULL) theme = themename;
3478     else theme = action->data().toString();
3479     KdenliveSettings::setColortheme(theme);
3480     // Make palette for all widgets.
3481     QPalette plt;
3482     if (theme.isEmpty())
3483         plt = QApplication::desktop()->palette();
3484     else {
3485         KSharedConfigPtr config = KSharedConfig::openConfig(theme);
3486         plt = KGlobalSettings::createApplicationPalette(config);
3487     }
3488
3489     kapp->setPalette(plt);
3490     const QObjectList children = statusBar()->children();
3491
3492     foreach(QObject *child, children) {
3493         if (child->isWidgetType())
3494             ((QWidget*)child)->setPalette(plt);
3495         const QObjectList subchildren = child->children();
3496         foreach(QObject *subchild, subchildren) {
3497             if (subchild->isWidgetType())
3498                 ((QWidget*)subchild)->setPalette(plt);
3499         }
3500     }
3501     if (m_activeTimeline)
3502         m_activeTimeline->projectView()->updatePalette();
3503 }
3504
3505
3506 QPixmap MainWindow::createSchemePreviewIcon(const KSharedConfigPtr &config)
3507 {
3508     // code taken from kdebase/workspace/kcontrol/colors/colorscm.cpp
3509     const uchar bits1[] = { 0xff, 0xff, 0xff, 0x2c, 0x16, 0x0b };
3510     const uchar bits2[] = { 0x68, 0x34, 0x1a, 0xff, 0xff, 0xff };
3511     const QSize bitsSize(24, 2);
3512     const QBitmap b1 = QBitmap::fromData(bitsSize, bits1);
3513     const QBitmap b2 = QBitmap::fromData(bitsSize, bits2);
3514
3515     QPixmap pixmap(23, 16);
3516     pixmap.fill(Qt::black); // ### use some color other than black for borders?
3517
3518     KConfigGroup group(config, "WM");
3519     QPainter p(&pixmap);
3520     KColorScheme windowScheme(QPalette::Active, KColorScheme::Window, config);
3521     p.fillRect(1,  1, 7, 7, windowScheme.background());
3522     p.fillRect(2,  2, 5, 2, QBrush(windowScheme.foreground().color(), b1));
3523
3524     KColorScheme buttonScheme(QPalette::Active, KColorScheme::Button, config);
3525     p.fillRect(8,  1, 7, 7, buttonScheme.background());
3526     p.fillRect(9,  2, 5, 2, QBrush(buttonScheme.foreground().color(), b1));
3527
3528     p.fillRect(15,  1, 7, 7, group.readEntry("activeBackground", QColor(96, 148, 207)));
3529     p.fillRect(16,  2, 5, 2, QBrush(group.readEntry("activeForeground", QColor(255, 255, 255)), b1));
3530
3531     KColorScheme viewScheme(QPalette::Active, KColorScheme::View, config);
3532     p.fillRect(1,  8, 7, 7, viewScheme.background());
3533     p.fillRect(2, 12, 5, 2, QBrush(viewScheme.foreground().color(), b2));
3534
3535     KColorScheme selectionScheme(QPalette::Active, KColorScheme::Selection, config);
3536     p.fillRect(8,  8, 7, 7, selectionScheme.background());
3537     p.fillRect(9, 12, 5, 2, QBrush(selectionScheme.foreground().color(), b2));
3538
3539     p.fillRect(15,  8, 7, 7, group.readEntry("inactiveBackground", QColor(224, 223, 222)));
3540     p.fillRect(16, 12, 5, 2, QBrush(group.readEntry("inactiveForeground", QColor(20, 19, 18)), b2));
3541
3542     p.end();
3543     return pixmap;
3544 }
3545
3546 void MainWindow::slotSwitchMonitors()
3547 {
3548     m_monitorManager->slotSwitchMonitors(!m_clipMonitor->isActive());
3549     if (m_projectMonitor->isActive()) m_activeTimeline->projectView()->setFocus();
3550     else m_projectList->focusTree();
3551 }
3552
3553 void MainWindow::slotInsertZoneToTree()
3554 {
3555     if (!m_clipMonitor->isActive() || m_clipMonitor->activeClip() == NULL) return;
3556     QStringList info = m_clipMonitor->getZoneInfo();
3557     m_projectList->slotAddClipCut(info.at(0), info.at(1).toInt(), info.at(2).toInt());
3558 }
3559
3560 void MainWindow::slotInsertZoneToTimeline()
3561 {
3562     if (m_activeTimeline == NULL || m_clipMonitor->activeClip() == NULL) return;
3563     QStringList info = m_clipMonitor->getZoneInfo();
3564     m_activeTimeline->projectView()->insertClipCut(m_clipMonitor->activeClip(), info.at(1).toInt(), info.at(2).toInt());
3565 }
3566
3567
3568 void MainWindow::slotDeleteProjectClips(QStringList ids, QMap<QString, QString> folderids)
3569 {
3570     if (m_activeDocument && m_activeTimeline) {
3571         if (!ids.isEmpty()) {
3572             for (int i = 0; i < ids.size(); ++i) {
3573                 m_activeTimeline->slotDeleteClip(ids.at(i));
3574             }
3575             m_activeDocument->clipManager()->slotDeleteClips(ids);
3576         }
3577         if (!folderids.isEmpty()) m_projectList->deleteProjectFolder(folderids);
3578         m_activeDocument->setModified(true);
3579     }
3580 }
3581
3582 void MainWindow::slotShowTitleBars(bool show)
3583 {
3584     if (show) {
3585         m_effectStackDock->setTitleBarWidget(0);
3586         m_clipMonitorDock->setTitleBarWidget(0);
3587         m_projectMonitorDock->setTitleBarWidget(0);
3588 #ifndef Q_WS_MAC
3589         m_recMonitorDock->setTitleBarWidget(0);
3590 #endif
3591         m_effectListDock->setTitleBarWidget(0);
3592         m_transitionConfigDock->setTitleBarWidget(0);
3593         m_projectListDock->setTitleBarWidget(0);
3594         m_undoViewDock->setTitleBarWidget(0);
3595         m_vectorscopeDock->setTitleBarWidget(0);
3596     } else {
3597         if (!m_effectStackDock->isFloating()) { m_effectStackDock->setTitleBarWidget(new QWidget(this)); }
3598         if (!m_clipMonitorDock->isFloating()) { m_clipMonitorDock->setTitleBarWidget(new QWidget(this)); }
3599         if (!m_projectMonitorDock->isFloating()) { m_projectMonitorDock->setTitleBarWidget(new QWidget(this)); }
3600 #ifndef Q_WS_MAC
3601         if (!m_recMonitorDock->isFloating()) { m_recMonitorDock->setTitleBarWidget(new QWidget(this)); }
3602 #endif
3603         if (!m_effectListDock->isFloating()) { m_effectListDock->setTitleBarWidget(new QWidget(this)); }
3604         if (!m_transitionConfigDock->isFloating()) { m_transitionConfigDock->setTitleBarWidget(new QWidget(this)); }
3605         if (!m_projectListDock->isFloating()) { m_projectListDock->setTitleBarWidget(new QWidget(this)); }
3606         if (!m_undoViewDock->isFloating()) { m_undoViewDock->setTitleBarWidget(new QWidget(this)); }
3607         if (!m_vectorscopeDock->isFloating()) { m_vectorscopeDock->setTitleBarWidget(new QWidget(this)); }
3608     }
3609     KdenliveSettings::setShowtitlebars(show);
3610 }
3611
3612 void MainWindow::slotSwitchTitles()
3613 {
3614     slotShowTitleBars(!KdenliveSettings::showtitlebars());
3615 }
3616
3617 QString MainWindow::getMimeType()
3618 {
3619     QString mimetype = "application/x-kdenlive";
3620     KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
3621     if (!mime) mimetype = "*.kdenlive";
3622     return mimetype;
3623 }
3624
3625 #include "mainwindow.moc"
3626