]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
In case of locale bug (system locale != Qt locale), force C locale
[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 "effectstack/effectstackview2.h"
39 #include "transitionsettings.h"
40 #include "renderwidget.h"
41 #include "renderer.h"
42 #ifdef USE_JOGSHUTTLE
43 #include "jogshuttle.h"
44 #include "jogaction.h"
45 #include "jogshuttleconfig.h"
46 #endif
47 #include "clipproperties.h"
48 #include "wizard.h"
49 #include "commands/editclipcommand.h"
50 #include "titlewidget.h"
51 #include "markerdialog.h"
52 #include "clipitem.h"
53 #include "interfaces.h"
54 #include "config-kdenlive.h"
55 #include "cliptranscode.h"
56 #include "ui_templateclip_ui.h"
57 #include "scopes/scopemanager.h"
58 #include "scopes/colorscopes/vectorscope.h"
59 #include "scopes/colorscopes/waveform.h"
60 #include "scopes/colorscopes/rgbparade.h"
61 #include "scopes/colorscopes/histogram.h"
62 #include "scopes/audioscopes/audiosignal.h"
63 #include "scopes/audioscopes/audiospectrum.h"
64 #include "scopes/audioscopes/spectrogram.h"
65 #include "archivewidget.h"
66 #include "databackup/backupwidget.h"
67 #include "utils/resourcewidget.h"
68
69
70 #include <KApplication>
71 #include <KAction>
72 #include <KLocale>
73 #include <KGlobal>
74 #include <KActionCollection>
75 #include <KActionCategory>
76 #include <KStandardAction>
77 #include <KShortcutsDialog>
78 #include <KFileDialog>
79 #include <KMessageBox>
80 #include <KDebug>
81 #include <KIO/NetAccess>
82 #include <KSaveFile>
83 #include <KRuler>
84 #include <KConfigDialog>
85 #include <KXMLGUIFactory>
86 #include <KStatusBar>
87 #include <kstandarddirs.h>
88 #include <KUrlRequesterDialog>
89 #include <KTemporaryFile>
90 #include <KProcess>
91 #include <KActionMenu>
92 #include <KMenu>
93 #include <ktogglefullscreenaction.h>
94 #include <KFileItem>
95 #include <KNotification>
96 #include <KNotifyConfigWidget>
97 #if KDE_IS_VERSION(4,3,80)
98 #include <knewstuff3/downloaddialog.h>
99 #include <knewstuff3/knewstuffaction.h>
100 #else
101 #include <knewstuff2/engine.h>
102 #include <knewstuff2/ui/knewstuffaction.h>
103 #define KNS3 KNS
104 #endif
105 #include <KToolBar>
106 #include <KColorScheme>
107 #include <KProgressDialog>
108
109 #include <QTextStream>
110 #include <QTimer>
111 #include <QAction>
112 #include <QKeyEvent>
113 #include <QInputDialog>
114 #include <QDesktopWidget>
115 #include <QBitmap>
116
117 #include <stdlib.h>
118 #include <locale.h>
119
120 // Uncomment for deeper debugging
121 //#define DEBUG_MAINW
122
123 #ifdef DEBUG_MAINW
124 #include <QDebug>
125 #endif
126
127 static const char version[] = VERSION;
128
129 static const int ID_TIMELINE_POS = 0;
130 namespace Mlt
131 {
132 class Producer;
133 };
134
135 Q_DECLARE_METATYPE(QVector<int16_t>)
136
137
138 EffectsList MainWindow::videoEffects;
139 EffectsList MainWindow::audioEffects;
140 EffectsList MainWindow::customEffects;
141 EffectsList MainWindow::transitions;
142
143 QMap <QString,QImage> MainWindow::m_lumacache;
144
145 MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, const QString & clipsToLoad, QWidget *parent) :
146     KXmlGuiWindow(parent),
147     m_activeDocument(NULL),
148     m_activeTimeline(NULL),
149     m_projectList(NULL),
150     m_effectList(NULL),
151     m_effectStack(NULL),
152     m_clipMonitor(NULL),
153     m_projectMonitor(NULL),
154     m_recMonitor(NULL),
155     m_renderWidget(NULL),
156 #ifdef USE_JOGSHUTTLE
157     m_jogProcess(NULL),
158     m_jogShuttle(NULL),
159 #endif
160     m_findActivated(false),
161     m_stopmotion(NULL)
162 {
163     qRegisterMetaType<QVector<int16_t> > ();
164     qRegisterMetaType<stringMap> ("stringMap");
165     qRegisterMetaType<audioByteArray> ("audioByteArray");
166
167     // Init locale
168     QLocale systemLocale = QLocale();
169     setlocale(LC_NUMERIC, NULL);
170     char *separator = localeconv()->decimal_point;
171     if (separator != systemLocale.decimalPoint()) {
172         kDebug()<<"------\n!!! system locale is not similar to Qt's locale... be prepared for bugs!!!\n------";
173         // HACK: There is a locale conflict, so set locale to C
174         // Make sure to override exported values or it won't work
175         setenv("LANG", "C", 1);
176         setlocale(LC_NUMERIC, "C");
177         systemLocale = QLocale::c();
178     }
179
180     systemLocale.setNumberOptions(QLocale::OmitGroupSeparator);
181     QLocale::setDefault(systemLocale);
182
183     // Create DBus interface
184     new MainWindowAdaptor(this);
185     QDBusConnection dbus = QDBusConnection::sessionBus();
186     dbus.registerObject("/MainWindow", this);
187
188     if (!KdenliveSettings::colortheme().isEmpty()) slotChangePalette(NULL, KdenliveSettings::colortheme());
189     setFont(KGlobalSettings::toolBarFont());
190     parseProfiles(MltPath);
191     KdenliveSettings::setCurrent_profile(KdenliveSettings::default_profile());
192     m_commandStack = new QUndoGroup;
193     setDockNestingEnabled(true);
194     m_timelineArea = new KTabWidget(this);
195     m_timelineArea->setTabReorderingEnabled(true);
196     m_timelineArea->setTabBarHidden(true);
197     m_timelineArea->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
198     m_timelineArea->setMinimumHeight(200);
199
200     QToolButton *closeTabButton = new QToolButton;
201     connect(closeTabButton, SIGNAL(clicked()), this, SLOT(closeCurrentDocument()));
202     closeTabButton->setIcon(KIcon("tab-close"));
203     closeTabButton->adjustSize();
204     closeTabButton->setToolTip(i18n("Close the current tab"));
205     m_timelineArea->setCornerWidget(closeTabButton);
206     //connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
207
208     connect(&m_findTimer, SIGNAL(timeout()), this, SLOT(findTimeout()));
209     m_findTimer.setSingleShot(true);
210
211     // FIXME: the next call returns a newly allocated object, which leaks
212     initEffects::parseEffectFiles();
213     //initEffects::parseCustomEffectsFile();
214     
215     m_monitorManager = new MonitorManager();
216
217     m_shortcutRemoveFocus = new QShortcut(QKeySequence("Esc"), this);
218     connect(m_shortcutRemoveFocus, SIGNAL(activated()), this, SLOT(slotRemoveFocus()));
219
220
221     /// Add Widgets ///
222
223     m_projectListDock = new QDockWidget(i18n("Project Tree"), this);
224     m_projectListDock->setObjectName("project_tree");
225     m_projectList = new ProjectList();
226     m_projectListDock->setWidget(m_projectList);
227     addDockWidget(Qt::TopDockWidgetArea, m_projectListDock);
228
229     m_clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
230     m_clipMonitorDock->setObjectName("clip_monitor");
231     m_clipMonitor = new Monitor(Kdenlive::clipMonitor, m_monitorManager, QString(), m_timelineArea);
232     m_clipMonitorDock->setWidget(m_clipMonitor);
233
234     // Connect the project list
235     connect(m_projectList, SIGNAL(clipSelected(DocClipBase *, QPoint, bool)), m_clipMonitor, SLOT(slotSetClipProducer(DocClipBase *, QPoint, bool)));
236     connect(m_projectList, SIGNAL(raiseClipMonitor()), m_clipMonitor, SLOT(slotActivateMonitor()));
237     connect(m_projectList, SIGNAL(loadingIsOver()), this, SLOT(slotElapsedTime()));
238     connect(m_projectList, SIGNAL(displayMessage(const QString&, int)), this, SLOT(slotGotProgressInfo(const QString&, int)));
239     connect(m_projectList, SIGNAL(updateRenderStatus()), this, SLOT(slotCheckRenderStatus()));
240     connect(m_projectList, SIGNAL(clipNeedsReload(const QString&)),this, SLOT(slotUpdateClip(const QString &)));
241     connect(m_projectList, SIGNAL(updateProfile(const QString &)), this, SLOT(slotUpdateProjectProfile(const QString &)));
242     connect(m_projectList, SIGNAL(refreshClip(const QString &, bool)), m_monitorManager, SLOT(slotRefreshCurrentMonitor(const QString &)));
243     connect(m_projectList, SIGNAL(findInTimeline(const QString&)), this, SLOT(slotClipInTimeline(const QString&)));
244     connect(m_clipMonitor, SIGNAL(zoneUpdated(QPoint)), m_projectList, SLOT(slotUpdateClipCut(QPoint)));
245     connect(m_clipMonitor, SIGNAL(extractZone(const QString &, QPoint)), m_projectList, SLOT(slotCutClipJob(const QString &, QPoint)));
246
247     m_projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
248     m_projectMonitorDock->setObjectName("project_monitor");
249     m_projectMonitor = new Monitor(Kdenlive::projectMonitor, m_monitorManager, QString());
250     m_projectMonitorDock->setWidget(m_projectMonitor);
251
252 #ifndef Q_WS_MAC
253     m_recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
254     m_recMonitorDock->setObjectName("record_monitor");
255     m_recMonitor = new RecMonitor(Kdenlive::recordMonitor, m_monitorManager);
256     m_recMonitorDock->setWidget(m_recMonitor);
257     connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
258     connect(m_recMonitor, SIGNAL(addProjectClipList(KUrl::List)), this, SLOT(slotAddProjectClipList(KUrl::List)));
259     connect(m_recMonitor, SIGNAL(showConfigDialog(int, int)), this, SLOT(slotPreferences(int, int)));
260
261 #endif /* ! Q_WS_MAC */
262     m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor, m_recMonitor);
263
264     m_notesDock = new QDockWidget(i18n("Project Notes"), this);
265     m_notesDock->setObjectName("notes_widget");
266     m_notesWidget = new NotesWidget();
267     connect(m_notesWidget, SIGNAL(insertNotesTimecode()), this, SLOT(slotInsertNotesTimecode()));
268     connect(m_notesWidget, SIGNAL(seekProject(int)), m_projectMonitor->render, SLOT(seekToFrame(int)));
269
270     m_notesWidget->setTabChangesFocus(true);
271 #if KDE_IS_VERSION(4,4,0)
272     m_notesWidget->setClickMessage(i18n("Enter your project notes here ..."));
273 #endif
274     m_notesDock->setWidget(m_notesWidget);
275     addDockWidget(Qt::TopDockWidgetArea, m_notesDock);
276
277     m_effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
278     m_effectStackDock->setObjectName("effect_stack");
279     m_effectStack = new EffectStackView2(m_projectMonitor);
280     m_effectStackDock->setWidget(m_effectStack);
281     addDockWidget(Qt::TopDockWidgetArea, m_effectStackDock);
282     connect(m_effectStack, SIGNAL(startFilterJob(ItemInfo, const QString&,const QString&,const QString&,const QString&,const QString&,const QString&,const QString&)), m_projectList, SLOT(slotStartFilterJob(ItemInfo, const QString&,const QString&,const QString&,const QString&,const QString&,const QString&,const QString&)));
283
284     m_transitionConfigDock = new QDockWidget(i18n("Transition"), this);
285     m_transitionConfigDock->setObjectName("transition");
286     m_transitionConfig = new TransitionSettings(m_projectMonitor);
287     m_transitionConfigDock->setWidget(m_transitionConfig);
288     addDockWidget(Qt::TopDockWidgetArea, m_transitionConfigDock);
289
290     m_effectListDock = new QDockWidget(i18n("Effect List"), this);
291     m_effectListDock->setObjectName("effect_list");
292     m_effectList = new EffectsListView();
293     m_effectListDock->setWidget(m_effectList);
294     addDockWidget(Qt::TopDockWidgetArea, m_effectListDock);
295
296     m_scopeManager = new ScopeManager(m_monitorManager);
297     m_vectorscope = new Vectorscope();
298     m_vectorscopeDock = new QDockWidget(i18n("Vectorscope"), this);
299     m_vectorscopeDock->setObjectName(m_vectorscope->widgetName());
300     m_vectorscopeDock->setWidget(m_vectorscope);
301     addDockWidget(Qt::TopDockWidgetArea, m_vectorscopeDock);
302     m_scopeManager->addScope(m_vectorscope, m_vectorscopeDock);
303
304     m_waveform = new Waveform();
305     m_waveformDock = new QDockWidget(i18n("Waveform"), this);
306     m_waveformDock->setObjectName(m_waveform->widgetName());
307     m_waveformDock->setWidget(m_waveform);
308     addDockWidget(Qt::TopDockWidgetArea, m_waveformDock);
309     m_scopeManager->addScope(m_waveform, m_waveformDock);
310
311     m_RGBParade = new RGBParade();
312     m_RGBParadeDock = new QDockWidget(i18n("RGB Parade"), this);
313     m_RGBParadeDock->setObjectName(m_RGBParade->widgetName());
314     m_RGBParadeDock->setWidget(m_RGBParade);
315     addDockWidget(Qt::TopDockWidgetArea, m_RGBParadeDock);
316     m_scopeManager->addScope(m_RGBParade, m_RGBParadeDock);
317
318     m_histogram = new Histogram();
319     m_histogramDock = new QDockWidget(i18n("Histogram"), this);
320     m_histogramDock->setObjectName(m_histogram->widgetName());
321     m_histogramDock->setWidget(m_histogram);
322     addDockWidget(Qt::TopDockWidgetArea, m_histogramDock);
323     m_scopeManager->addScope(m_histogram, m_histogramDock);
324
325     m_audiosignal = new AudioSignal;
326     m_audiosignalDock = new QDockWidget(i18n("Audio Signal"), this);
327     m_audiosignalDock->setObjectName("audiosignal");
328     m_audiosignalDock->setWidget(m_audiosignal);
329     addDockWidget(Qt::TopDockWidgetArea, m_audiosignalDock);
330     m_scopeManager->addScope(m_audiosignal, m_audiosignalDock);
331
332     m_audioSpectrum = new AudioSpectrum();
333     m_audioSpectrumDock = new QDockWidget(i18n("AudioSpectrum"), this);
334     m_audioSpectrumDock->setObjectName(m_audioSpectrum->widgetName());
335     m_audioSpectrumDock->setWidget(m_audioSpectrum);
336     addDockWidget(Qt::TopDockWidgetArea, m_audioSpectrumDock);
337     m_scopeManager->addScope(m_audioSpectrum, m_audioSpectrumDock);
338
339     m_spectrogram = new Spectrogram();
340     m_spectrogramDock = new QDockWidget(i18n("Spectrogram"), this);
341     m_spectrogramDock->setObjectName(m_spectrogram->widgetName());
342     m_spectrogramDock->setWidget(m_spectrogram);
343     addDockWidget(Qt::TopDockWidgetArea, m_spectrogramDock);
344     m_scopeManager->addScope(m_spectrogram, m_spectrogramDock);
345
346     // Add monitors here to keep them at the right of the window
347     addDockWidget(Qt::TopDockWidgetArea, m_clipMonitorDock);
348     addDockWidget(Qt::TopDockWidgetArea, m_projectMonitorDock);
349 #ifndef Q_WS_MAC
350     addDockWidget(Qt::TopDockWidgetArea, m_recMonitorDock);
351 #endif
352
353     m_undoViewDock = new QDockWidget(i18n("Undo History"), this);
354     m_undoViewDock->setObjectName("undo_history");
355     m_undoView = new QUndoView();
356     m_undoView->setCleanIcon(KIcon("edit-clear"));
357     m_undoView->setEmptyLabel(i18n("Clean"));
358     m_undoViewDock->setWidget(m_undoView);
359     m_undoView->setGroup(m_commandStack);
360     addDockWidget(Qt::TopDockWidgetArea, m_undoViewDock);
361
362
363     setupActions();
364     connect(m_commandStack, SIGNAL(cleanChanged(bool)), m_saveAction, SLOT(setDisabled(bool)));
365
366
367     // Close non-general docks for the initial layout
368     // only show important ones
369     m_histogramDock->close();
370     m_RGBParadeDock->close();
371     m_waveformDock->close();
372     m_vectorscopeDock->close();
373
374     m_audioSpectrumDock->close();
375     m_spectrogramDock->close();
376     m_audiosignalDock->close();
377
378     m_undoViewDock->close();
379
380
381
382     /// Tabify Widgets ///
383     tabifyDockWidget(m_effectListDock, m_effectStackDock);
384     tabifyDockWidget(m_effectListDock, m_transitionConfigDock);
385     tabifyDockWidget(m_projectListDock, m_notesDock);
386
387     tabifyDockWidget(m_clipMonitorDock, m_projectMonitorDock);
388 #ifndef Q_WS_MAC
389     tabifyDockWidget(m_clipMonitorDock, m_recMonitorDock);
390 #endif
391     setCentralWidget(m_timelineArea);
392
393     m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)), actionCollection());
394     readOptions();
395     m_fileRevert = KStandardAction::revert(this, SLOT(slotRevert()), actionCollection());
396     m_fileRevert->setEnabled(false);
397
398     // Prepare layout actions
399     KActionCategory *layoutActions = new KActionCategory(i18n("Layouts"), actionCollection());
400     m_loadLayout = new KSelectAction(i18n("Load Layout"), actionCollection());
401     for (int i = 1; i < 5; i++) {
402         KAction *load = new KAction(KIcon(), i18n("Layout %1").arg(i), this);
403         load->setData("_" + QString::number(i));
404         layoutActions->addAction("load_layout" + QString::number(i), load);
405         m_loadLayout->addAction(load);
406         KAction *save = new KAction(KIcon(), i18n("Save As Layout %1").arg(i), this);
407         save->setData("_" + QString::number(i));
408         layoutActions->addAction("save_layout" + QString::number(i), save);
409     }
410     layoutActions->addAction("load_layouts", m_loadLayout);
411     connect(m_loadLayout, SIGNAL(triggered(QAction*)), this, SLOT(slotLoadLayout(QAction*)));
412
413     KAction *action;
414     // Stop motion actions. Beware of the order, we MUST use the same order in stopmotion/stopmotion.cpp
415     m_stopmotion_actions = new KActionCategory(i18n("Stop Motion"), actionCollection());
416     action = new KAction(KIcon("media-record"), i18n("Capture frame"), this);
417     //action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
418     m_stopmotion_actions->addAction("stopmotion_capture", action);
419     action = new KAction(i18n("Switch live / captured frame"), this);
420     //action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
421     m_stopmotion_actions->addAction("stopmotion_switch", action);
422     action = new KAction(KIcon("edit-paste"), i18n("Show last frame over video"), this);
423     action->setCheckable(true);
424     action->setChecked(false);
425     m_stopmotion_actions->addAction("stopmotion_overlay", action);
426
427     // Build effects menu
428     m_effectsMenu = new QMenu(i18n("Add Effect"));
429     m_effectActions = new KActionCategory(i18n("Effects"), actionCollection());
430     m_effectList->reloadEffectList(m_effectsMenu, m_effectActions);
431     m_effectsActionCollection->readSettings();
432
433     setupGUI();
434
435     // Find QDockWidget tab bars and show / hide widget title bars on right click
436     QList <QTabBar *> tabs = findChildren<QTabBar *>();
437     for (int i = 0; i < tabs.count(); i++) {
438         tabs.at(i)->setContextMenuPolicy(Qt::CustomContextMenu);
439         connect(tabs.at(i), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(slotSwitchTitles()));
440     }
441
442     /*ScriptingPart* sp = new ScriptingPart(this, QStringList());
443     guiFactory()->addClient(sp);*/
444     QMenu *trackMenu = (QMenu*)(factory()->container("track_menu", this));
445     if (trackMenu) trackMenu->addActions(m_tracksActionCollection->actions());
446
447
448     QMenu *saveLayout = (QMenu*)(factory()->container("layout_save_as", this));
449     if (saveLayout)
450         connect(saveLayout, SIGNAL(triggered(QAction*)), this, SLOT(slotSaveLayout(QAction*)));
451
452
453     // Load layout names from config file
454     loadLayouts();
455
456     loadPlugins();
457     loadTranscoders();
458     loadStabilize();
459
460     m_projectMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)), m_playZone, m_loopZone, NULL, m_loopClip);
461     m_clipMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)), m_playZone, m_loopZone, static_cast<QMenu*>(factory()->container("marker_menu", this)));
462
463     QMenu *clipInTimeline = static_cast<QMenu*>(factory()->container("clip_in_timeline", this));
464     clipInTimeline->setIcon(KIcon("go-jump"));
465         QHash<QString,QMenu*> menus;
466         menus.insert("addMenu",static_cast<QMenu*>(factory()->container("generators", this)));
467         menus.insert("extractAudioMenu",static_cast<QMenu*>(factory()->container("extract_audio", this)));
468         menus.insert("transcodeMenu",static_cast<QMenu*>(factory()->container("transcoders", this)));
469         menus.insert("stabilizeMenu",static_cast<QMenu*>(factory()->container("stabilize", this)));
470         menus.insert("inTimelineMenu",clipInTimeline);
471     m_projectList->setupGeneratorMenu(menus);
472
473     // build themes menus
474     QMenu *themesMenu = static_cast<QMenu*>(factory()->container("themes_menu", this));
475     QActionGroup *themegroup = new QActionGroup(this);
476     themegroup->setExclusive(true);
477     action = new KAction(i18n("Default"), this);
478     action->setCheckable(true);
479     themegroup->addAction(action);
480     if (KdenliveSettings::colortheme().isEmpty()) action->setChecked(true);
481
482     const QStringList schemeFiles = KGlobal::dirs()->findAllResources("data", "color-schemes/*.colors", KStandardDirs::NoDuplicates);
483
484     for (int i = 0; i < schemeFiles.size(); ++i) {
485         // get the file name
486         const QString filename = schemeFiles.at(i);
487         const QFileInfo info(filename);
488
489         // add the entry
490         KSharedConfigPtr config = KSharedConfig::openConfig(filename);
491         QIcon icon = createSchemePreviewIcon(config);
492         KConfigGroup group(config, "General");
493         const QString name = group.readEntry("Name", info.baseName());
494         action = new KAction(name, this);
495         action->setData(filename);
496         action->setIcon(icon);
497         action->setCheckable(true);
498         themegroup->addAction(action);
499         if (KdenliveSettings::colortheme() == filename) action->setChecked(true);
500     }
501
502     /*KGlobal::dirs()->addResourceDir("themes", KStandardDirs::installPath("data") + QString("kdenlive/themes"));
503     QStringList themes = KGlobal::dirs()->findAllResources("themes", QString(), KStandardDirs::Recursive | KStandardDirs::NoDuplicates);
504     for (QStringList::const_iterator it = themes.constBegin(); it != themes.constEnd(); ++it)
505     {
506     QFileInfo fi(*it);
507         action = new QAction(fi.fileName(), this);
508         action->setData(*it);
509     action->setCheckable(true);
510     themegroup->addAction(action);
511     if (KdenliveSettings::colortheme() == *it) action->setChecked(true);
512     }*/
513     themesMenu->addActions(themegroup->actions());
514     connect(themesMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotChangePalette(QAction*)));
515
516     // Setup and fill effects and transitions menus.
517
518
519     QMenu *m = static_cast<QMenu*>(factory()->container("video_effects_menu", this));
520     m->addActions(m_effectsMenu->actions());
521
522
523     m_transitionsMenu = new QMenu(i18n("Add Transition"), this);
524     for (int i = 0; i < transitions.count(); ++i)
525         m_transitionsMenu->addAction(m_transitions[i]);
526
527     connect(m, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
528     connect(m_effectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
529     connect(m_transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
530
531     QMenu *viewMenu = static_cast<QMenu*>(factory()->container("dockwindows", this));
532     const QList<QAction *> viewActions = createPopupMenu()->actions();
533     viewMenu->insertActions(NULL, viewActions);
534
535     m_timelineContextMenu = new QMenu(this);
536     m_timelineContextClipMenu = new QMenu(this);
537     m_timelineContextTransitionMenu = new QMenu(this);
538
539     m_timelineContextMenu->addAction(actionCollection()->action("insert_space"));
540     m_timelineContextMenu->addAction(actionCollection()->action("delete_space"));
541     m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));
542
543     m_timelineContextClipMenu->addAction(actionCollection()->action("clip_in_project_tree"));
544     //m_timelineContextClipMenu->addAction(actionCollection()->action("clip_to_project_tree"));
545     m_timelineContextClipMenu->addAction(actionCollection()->action("delete_item"));
546     m_timelineContextClipMenu->addSeparator();
547     m_timelineContextClipMenu->addAction(actionCollection()->action("group_clip"));
548     m_timelineContextClipMenu->addAction(actionCollection()->action("ungroup_clip"));
549     m_timelineContextClipMenu->addAction(actionCollection()->action("split_audio"));
550     if (KdenliveSettings::enableaudioalign()) {
551         m_timelineContextClipMenu->addAction(actionCollection()->action("set_audio_align_ref"));
552         m_timelineContextClipMenu->addAction(actionCollection()->action("align_audio"));
553     }
554     m_timelineContextClipMenu->addSeparator();
555     m_timelineContextClipMenu->addAction(actionCollection()->action("cut_timeline_clip"));
556     m_timelineContextClipMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
557     m_timelineContextClipMenu->addAction(actionCollection()->action("paste_effects"));
558     m_timelineContextClipMenu->addSeparator();
559
560     QMenu *markersMenu = (QMenu*)(factory()->container("marker_menu", this));
561     m_timelineContextClipMenu->addMenu(markersMenu);
562     m_timelineContextClipMenu->addSeparator();
563     m_timelineContextClipMenu->addMenu(m_transitionsMenu);
564     m_timelineContextClipMenu->addMenu(m_effectsMenu);
565
566     m_timelineContextTransitionMenu->addAction(actionCollection()->action("delete_item"));
567     m_timelineContextTransitionMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
568
569     m_timelineContextTransitionMenu->addAction(actionCollection()->action("auto_transition"));
570
571     connect(m_projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
572     connect(m_clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
573     connect(m_effectList, SIGNAL(addEffect(const QDomElement)), this, SLOT(slotAddEffect(const QDomElement)));
574     connect(m_effectList, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
575
576     slotConnectMonitors();
577
578     // Open or create a file.  Command line argument passed in Url has
579     // precedence, then "openlastproject", then just a plain empty file.
580     // If opening Url fails, openlastproject will _not_ be used.
581     if (!Url.isEmpty()) {
582         // delay loading so that the window shows up
583         m_startUrl = Url;
584         QTimer::singleShot(500, this, SLOT(openFile()));
585     } else if (KdenliveSettings::openlastproject()) {
586         QTimer::singleShot(500, this, SLOT(openLastFile()));
587     } else { //if (m_timelineArea->count() == 0) {
588         newFile(false);
589     }
590
591     if (!clipsToLoad.isEmpty() && m_activeDocument) {
592         QStringList list = clipsToLoad.split(',');
593         QList <QUrl> urls;
594         foreach(QString path, list) {
595             kDebug() << QDir::current().absoluteFilePath(path);
596             urls << QUrl::fromLocalFile(QDir::current().absoluteFilePath(path));
597         }
598         m_projectList->slotAddClip(urls);
599     }
600
601 #ifdef USE_JOGSHUTTLE
602     activateShuttleDevice();
603 #endif
604     m_projectListDock->raise();
605
606     actionCollection()->addAssociatedWidget(m_clipMonitor->container());
607     actionCollection()->addAssociatedWidget(m_projectMonitor->container());
608
609     // Populate encoding profiles
610     KConfig conf("encodingprofiles.rc", KConfig::FullConfig, "appdata");
611     if (KdenliveSettings::proxyparams().isEmpty() || KdenliveSettings::proxyextension().isEmpty()) {
612         KConfigGroup group(&conf, "proxy");
613         QMap< QString, QString > values = group.entryMap();
614         QMapIterator<QString, QString> i(values);
615         if (i.hasNext()) {
616             i.next();
617             QString data = i.value();
618             KdenliveSettings::setProxyparams(data.section(';', 0, 0));
619             KdenliveSettings::setProxyextension(data.section(';', 1, 1));
620         }
621     }
622     if (KdenliveSettings::v4l_parameters().isEmpty() || KdenliveSettings::v4l_extension().isEmpty()) {
623         KConfigGroup group(&conf, "video4linux");
624         QMap< QString, QString > values = group.entryMap();
625         QMapIterator<QString, QString> i(values);
626         if (i.hasNext()) {
627             i.next();
628             QString data = i.value();
629             KdenliveSettings::setV4l_parameters(data.section(';', 0, 0));
630             KdenliveSettings::setV4l_extension(data.section(';', 1, 1));
631         }
632     }
633     if (KdenliveSettings::decklink_parameters().isEmpty() || KdenliveSettings::decklink_extension().isEmpty()) {
634         KConfigGroup group(&conf, "decklink");
635         QMap< QString, QString > values = group.entryMap();
636         QMapIterator<QString, QString> i(values);
637         if (i.hasNext()) {
638             i.next();
639             QString data = i.value();
640             KdenliveSettings::setDecklink_parameters(data.section(';', 0, 0));
641             KdenliveSettings::setDecklink_extension(data.section(';', 1, 1));
642         }
643     }
644     
645     connect (KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), this, SLOT(slotChangePalette()));
646 }
647
648 MainWindow::~MainWindow()
649 {
650     if (m_stopmotion) {
651         delete m_stopmotion;
652     }
653     m_effectStack->slotClipItemSelected(NULL);
654     m_transitionConfig->slotTransitionItemSelected(NULL, 0, QPoint(), false);
655
656     if (m_projectMonitor) m_projectMonitor->stop();
657     if (m_clipMonitor) m_clipMonitor->stop();
658
659     delete m_activeTimeline;
660     delete m_effectStack;
661     delete m_transitionConfig;
662     delete m_activeDocument;
663     delete m_projectMonitor;
664     delete m_clipMonitor;
665     delete m_shortcutRemoveFocus;
666     delete[] m_transitions;
667     delete m_monitorManager;
668     delete m_scopeManager;
669     Mlt::Factory::close();
670 }
671
672 //virtual
673 bool MainWindow::queryClose()
674 {
675     if (m_renderWidget) {
676         int waitingJobs = m_renderWidget->waitingJobsCount();
677         if (waitingJobs > 0) {
678             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")))) {
679             case KMessageBox::Yes :
680                 // create script with waiting jobs and start it
681                 if (m_renderWidget->startWaitingRenderJobs() == false) return false;
682                 break;
683             case KMessageBox::No :
684                 // Don't do anything, jobs will be deleted
685                 break;
686             default:
687                 return false;
688             }
689         }
690     }
691     saveOptions();
692     if (m_monitorManager) m_monitorManager->stopActiveMonitor();
693     // warn the user to save if document is modified and we have clips in our project list
694     if (m_activeDocument && m_activeDocument->isModified() &&
695             ((m_projectList->documentClipList().isEmpty() && !m_activeDocument->url().isEmpty()) ||
696              !m_projectList->documentClipList().isEmpty())) {
697         raise();
698         activateWindow();
699         QString message;
700         if (m_activeDocument->url().fileName().isEmpty())
701             message = i18n("Save changes to document?");
702         else
703             message = i18n("The project <b>\"%1\"</b> has been changed.\nDo you want to save your changes?").arg(m_activeDocument->url().fileName());
704         switch (KMessageBox::warningYesNoCancel(this, message)) {
705         case KMessageBox::Yes :
706             // save document here. If saving fails, return false;
707             return saveFile();
708         case KMessageBox::No :
709             // User does not want to save the changes, clear recovery files
710             m_activeDocument->m_autosave->resize(0);
711             return true;
712         default: // cancel
713             return false;
714         }
715     }
716     return true;
717 }
718
719 void MainWindow::loadPlugins()
720 {
721     foreach(QObject * plugin, QPluginLoader::staticInstances()) {
722         populateMenus(plugin);
723     }
724
725     QStringList directories = KGlobal::dirs()->findDirs("module", QString());
726     QStringList filters;
727     filters << "libkdenlive*";
728     foreach(const QString & folder, directories) {
729         kDebug() << "Parsing plugin folder: " << folder;
730         QDir pluginsDir(folder);
731         foreach(const QString & fileName,
732                 pluginsDir.entryList(filters, QDir::Files)) {
733             /*
734              * Avoid loading the same plugin twice when there is more than one
735              * installation.
736              */
737             if (!m_pluginFileNames.contains(fileName)) {
738                 kDebug() << "Found plugin: " << fileName;
739                 QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
740                 QObject *plugin = loader.instance();
741                 if (plugin) {
742                     populateMenus(plugin);
743                     m_pluginFileNames += fileName;
744                 } else
745                     kDebug() << "Error loading plugin: " << fileName << ", " << loader.errorString();
746             }
747         }
748     }
749 }
750
751 void MainWindow::populateMenus(QObject *plugin)
752 {
753     QMenu *addMenu = static_cast<QMenu*>(factory()->container("generators", this));
754     ClipGenerator *iGenerator = qobject_cast<ClipGenerator *>(plugin);
755     if (iGenerator)
756         addToMenu(plugin, iGenerator->generators(KdenliveSettings::producerslist()), addMenu, SLOT(generateClip()),
757                   NULL);
758 }
759
760 void MainWindow::addToMenu(QObject *plugin, const QStringList &texts,
761                            QMenu *menu, const char *member,
762                            QActionGroup *actionGroup)
763 {
764     kDebug() << "// ADD to MENU" << texts;
765     foreach(const QString & text, texts) {
766         QAction *action = new QAction(text, plugin);
767         action->setData(text);
768         connect(action, SIGNAL(triggered()), this, member);
769         menu->addAction(action);
770
771         if (actionGroup) {
772             action->setCheckable(true);
773             actionGroup->addAction(action);
774         }
775     }
776 }
777
778 void MainWindow::aboutPlugins()
779 {
780     //PluginDialog dialog(pluginsDir.path(), m_pluginFileNames, this);
781     //dialog.exec();
782 }
783
784
785 void MainWindow::generateClip()
786 {
787     QAction *action = qobject_cast<QAction *>(sender());
788     ClipGenerator *iGenerator = qobject_cast<ClipGenerator *>(action->parent());
789
790     KUrl clipUrl = iGenerator->generatedClip(action->data().toString(), m_activeDocument->projectFolder(),
791                    QStringList(), QStringList(), m_activeDocument->fps(), m_activeDocument->width(), m_activeDocument->height());
792     if (!clipUrl.isEmpty()) {
793         m_projectList->slotAddClip(QList <QUrl> () << clipUrl);
794     }
795 }
796
797 void MainWindow::saveProperties(KConfigGroup &config)
798 {
799     // save properties here,used by session management
800     saveFile();
801     KMainWindow::saveProperties(config);
802 }
803
804
805 void MainWindow::readProperties(const KConfigGroup &config)
806 {
807     // read properties here,used by session management
808     KMainWindow::readProperties(config);
809     QString Lastproject = config.group("Recent Files").readPathEntry("File1", QString());
810     openFile(KUrl(Lastproject));
811 }
812
813 void MainWindow::slotReloadEffects()
814 {
815     initEffects::parseCustomEffectsFile();
816     m_effectList->reloadEffectList(m_effectsMenu, m_effectActions);
817 }
818
819 #ifdef USE_JOGSHUTTLE
820 void MainWindow::activateShuttleDevice()
821 {
822     delete m_jogShuttle;
823     m_jogShuttle = NULL;
824     delete m_jogProcess;
825     m_jogProcess = NULL;
826     if (KdenliveSettings::enableshuttle() == false) return;
827
828     m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
829     m_jogShuttle = new JogShuttleAction(m_jogProcess, JogShuttleConfig::actionMap(KdenliveSettings::shuttlebuttons()));
830
831     connect(m_jogShuttle, SIGNAL(rewindOneFrame()), m_monitorManager, SLOT(slotRewindOneFrame()));
832     connect(m_jogShuttle, SIGNAL(forwardOneFrame()), m_monitorManager, SLOT(slotForwardOneFrame()));
833     connect(m_jogShuttle, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
834     connect(m_jogShuttle, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
835     connect(m_jogShuttle, SIGNAL(action(const QString&)), this, SLOT(slotDoAction(const QString&)));
836 }
837 #endif /* USE_JOGSHUTTLE */
838
839 void MainWindow::slotDoAction(const QString& action_name)
840 {
841     QAction* action = actionCollection()->action(action_name);
842     if (!action) {
843         fprintf(stderr, "%s", QString("shuttle action '%1' unknown\n").arg(action_name).toAscii().constData());
844         return;
845     }
846     action->trigger();
847 }
848
849 void MainWindow::configureNotifications()
850 {
851     KNotifyConfigWidget::configure(this);
852 }
853
854 void MainWindow::slotFullScreen()
855 {
856     KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
857 }
858
859 void MainWindow::slotAddEffect(const QDomElement effect)
860 {
861     if (!m_activeDocument) return;
862     if (effect.isNull()) {
863         kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
864         return;
865     }
866     QDomElement effectToAdd = effect.cloneNode().toElement();
867     bool ok;
868     int ix = m_effectStack->isTrackMode(&ok);
869     if (ok) m_activeTimeline->projectView()->slotAddTrackEffect(effectToAdd, m_activeDocument->tracksCount() - ix);
870     else m_activeTimeline->projectView()->slotAddEffect(effectToAdd, GenTime(), -1);
871 }
872
873 void MainWindow::slotUpdateClip(const QString &id)
874 {
875     if (!m_activeDocument) return;
876     DocClipBase *clip = m_activeDocument->clipManager()->getClipById(id);
877     if (!clip) return;
878     if (clip->numReferences() > 0) m_activeTimeline->projectView()->slotUpdateClip(id);
879     if (m_clipMonitor->activeClip() && m_clipMonitor->activeClip()->getId() == id) {
880         Mlt::Producer *monitorProducer = clip->getCloneProducer();
881         m_clipMonitor->updateClipProducer(monitorProducer);
882     }
883     clip->cleanupProducers();
884 }
885
886 void MainWindow::slotConnectMonitors()
887 {
888     m_projectList->setRenderer(m_projectMonitor->render);
889     connect(m_projectList, SIGNAL(deleteProjectClips(QStringList, QMap<QString, QString>)), this, SLOT(slotDeleteProjectClips(QStringList, QMap<QString, QString>)));
890     connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
891     connect(m_projectList, SIGNAL(showClipProperties(QList <DocClipBase *>, QMap<QString, QString>)), this, SLOT(slotShowClipProperties(QList <DocClipBase *>, QMap<QString, QString>)));
892     connect(m_projectMonitor->render, SIGNAL(replyGetImage(const QString &, const QString &, int, int)), m_projectList, SLOT(slotReplyGetImage(const QString &, const QString &, int, int)));
893     connect(m_projectMonitor->render, SIGNAL(replyGetImage(const QString &, const QImage &)), m_projectList, SLOT(slotReplyGetImage(const QString &, const QImage &)));
894     connect(m_projectMonitor->render, SIGNAL(replyGetFileProperties(const QString &, Mlt::Producer*, const stringMap &, const stringMap &, bool)), m_projectList, SLOT(slotReplyGetFileProperties(const QString &, Mlt::Producer*, const stringMap &, const stringMap &, bool)));
895
896     connect(m_projectMonitor->render, SIGNAL(removeInvalidClip(const QString &, bool)), m_projectList, SLOT(slotRemoveInvalidClip(const QString &, bool)));
897
898     connect(m_projectMonitor->render, SIGNAL(removeInvalidProxy(const QString &, bool)), m_projectList, SLOT(slotRemoveInvalidProxy(const QString &, bool)));
899
900     connect(m_clipMonitor, SIGNAL(refreshClipThumbnail(const QString &, bool)), m_projectList, SLOT(slotRefreshClipThumbnail(const QString &, bool)));
901
902     connect(m_clipMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustClipMonitor()));
903     connect(m_projectMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustProjectMonitor()));
904
905     connect(m_projectMonitor, SIGNAL(requestFrameForAnalysis(bool)), this, SLOT(slotMonitorRequestRenderFrame(bool)));
906
907     connect(m_clipMonitor, SIGNAL(saveZone(Render *, QPoint, DocClipBase *)), this, SLOT(slotSaveZone(Render *, QPoint, DocClipBase *)));
908     connect(m_projectMonitor, SIGNAL(saveZone(Render *, QPoint, DocClipBase *)), this, SLOT(slotSaveZone(Render *, QPoint, DocClipBase *)));
909 }
910
911 void MainWindow::slotAdjustClipMonitor()
912 {
913     m_clipMonitorDock->updateGeometry();
914     m_clipMonitorDock->adjustSize();
915     m_clipMonitor->resetSize();
916 }
917
918 void MainWindow::slotAdjustProjectMonitor()
919 {
920     m_projectMonitorDock->updateGeometry();
921     m_projectMonitorDock->adjustSize();
922     m_projectMonitor->resetSize();
923 }
924
925
926 class NameGrabbingKActionCollection {
927 public:
928   NameGrabbingKActionCollection(KActionCollection* collection, QStringList& action_names)
929     : m_collection(collection), m_action_names(action_names) {
930       m_action_names.clear();
931     }
932   KAction* addAction(const QString& action_name) {
933     m_action_names << action_name;
934     return m_collection->addAction(action_name);
935   }
936   void addAction(const QString& action_name, QAction* action) {
937     m_action_names << action_name;
938     m_collection->addAction(action_name, action);
939   }
940   operator KActionCollection*() { return m_collection; }
941   const QStringList& actionNames() const { return m_action_names; }
942 private:
943   KActionCollection* m_collection;
944   QStringList& m_action_names;
945 };
946
947 void MainWindow::setupActions()
948 {
949
950     NameGrabbingKActionCollection collection(actionCollection(), m_action_names);
951     m_timecodeFormat = new KComboBox(this);
952     m_timecodeFormat->addItem(i18n("hh:mm:ss:ff"));
953     m_timecodeFormat->addItem(i18n("Frames"));
954     if (KdenliveSettings::frametimecode()) m_timecodeFormat->setCurrentIndex(1);
955     connect(m_timecodeFormat, SIGNAL(activated(int)), this, SLOT(slotUpdateTimecodeFormat(int)));
956
957     m_statusProgressBar = new QProgressBar(this);
958     m_statusProgressBar->setMinimum(0);
959     m_statusProgressBar->setMaximum(100);
960     m_statusProgressBar->setMaximumWidth(150);
961     m_statusProgressBar->setVisible(false);
962
963     KToolBar *toolbar = new KToolBar("statusToolBar", this, Qt::BottomToolBarArea);
964     toolbar->setMovable(false);
965     
966     setStatusBarStyleSheet(palette());
967     QString styleBorderless = "QToolButton { border-width: 0px;margin: 1px 3px 0px;padding: 0px;}";
968
969     //create edit mode buttons
970     m_normalEditTool = new KAction(KIcon("kdenlive-normal-edit"), i18n("Normal mode"), this);
971     m_normalEditTool->setShortcut(i18nc("Normal editing", "n"));
972     toolbar->addAction(m_normalEditTool);
973     m_normalEditTool->setCheckable(true);
974     m_normalEditTool->setChecked(true);
975
976     m_overwriteEditTool = new KAction(KIcon("kdenlive-overwrite-edit"), i18n("Overwrite mode"), this);
977     //m_overwriteEditTool->setShortcut(i18nc("Overwrite mode shortcut", "o"));
978     toolbar->addAction(m_overwriteEditTool);
979     m_overwriteEditTool->setCheckable(true);
980     m_overwriteEditTool->setChecked(false);
981
982     m_insertEditTool = new KAction(KIcon("kdenlive-insert-edit"), i18n("Insert mode"), this);
983     //m_insertEditTool->setShortcut(i18nc("Insert mode shortcut", "i"));
984     toolbar->addAction(m_insertEditTool);
985     m_insertEditTool->setCheckable(true);
986     m_insertEditTool->setChecked(false);
987     // not implemented yet
988     m_insertEditTool->setEnabled(false);
989
990     QActionGroup *editGroup = new QActionGroup(this);
991     editGroup->addAction(m_normalEditTool);
992     editGroup->addAction(m_overwriteEditTool);
993     editGroup->addAction(m_insertEditTool);
994     editGroup->setExclusive(true);
995     connect(editGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeEdit(QAction *)));
996     //connect(m_overwriteEditTool, SIGNAL(toggled(bool)), this, SLOT(slotSetOverwriteMode(bool)));
997
998     toolbar->addSeparator();
999
1000     // create tools buttons
1001     m_buttonSelectTool = new KAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"), this);
1002     m_buttonSelectTool->setShortcut(i18nc("Selection tool shortcut", "s"));
1003     toolbar->addAction(m_buttonSelectTool);
1004     m_buttonSelectTool->setCheckable(true);
1005     m_buttonSelectTool->setChecked(true);
1006
1007     m_buttonRazorTool = new KAction(KIcon("edit-cut"), i18n("Razor tool"), this);
1008     m_buttonRazorTool->setShortcut(i18nc("Razor tool shortcut", "x"));
1009     toolbar->addAction(m_buttonRazorTool);
1010     m_buttonRazorTool->setCheckable(true);
1011     m_buttonRazorTool->setChecked(false);
1012
1013     m_buttonSpacerTool = new KAction(KIcon("kdenlive-spacer-tool"), i18n("Spacer tool"), this);
1014     m_buttonSpacerTool->setShortcut(i18nc("Spacer tool shortcut", "m"));
1015     toolbar->addAction(m_buttonSpacerTool);
1016     m_buttonSpacerTool->setCheckable(true);
1017     m_buttonSpacerTool->setChecked(false);
1018
1019     QActionGroup *toolGroup = new QActionGroup(this);
1020     toolGroup->addAction(m_buttonSelectTool);
1021     toolGroup->addAction(m_buttonRazorTool);
1022     toolGroup->addAction(m_buttonSpacerTool);
1023     toolGroup->setExclusive(true);
1024     toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
1025
1026     QWidget * actionWidget;
1027     int max = toolbar->iconSizeDefault() + 2;
1028     actionWidget = toolbar->widgetForAction(m_normalEditTool);
1029     actionWidget->setMaximumWidth(max);
1030     actionWidget->setMaximumHeight(max - 4);
1031
1032     actionWidget = toolbar->widgetForAction(m_insertEditTool);
1033     actionWidget->setMaximumWidth(max);
1034     actionWidget->setMaximumHeight(max - 4);
1035
1036     actionWidget = toolbar->widgetForAction(m_overwriteEditTool);
1037     actionWidget->setMaximumWidth(max);
1038     actionWidget->setMaximumHeight(max - 4);
1039
1040     actionWidget = toolbar->widgetForAction(m_buttonSelectTool);
1041     actionWidget->setMaximumWidth(max);
1042     actionWidget->setMaximumHeight(max - 4);
1043
1044     actionWidget = toolbar->widgetForAction(m_buttonRazorTool);
1045     actionWidget->setMaximumWidth(max);
1046     actionWidget->setMaximumHeight(max - 4);
1047
1048     actionWidget = toolbar->widgetForAction(m_buttonSpacerTool);
1049     actionWidget->setMaximumWidth(max);
1050     actionWidget->setMaximumHeight(max - 4);
1051
1052     connect(toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
1053
1054     toolbar->addSeparator();
1055     m_buttonFitZoom = new KAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"), this);
1056     toolbar->addAction(m_buttonFitZoom);
1057     m_buttonFitZoom->setCheckable(false);
1058
1059     m_zoomOut = new KAction(KIcon("zoom-out"), i18n("Zoom Out"), this);
1060     toolbar->addAction(m_zoomOut);
1061     m_zoomOut->setShortcut(Qt::CTRL + Qt::Key_Minus);
1062
1063     m_zoomSlider = new QSlider(Qt::Horizontal, this);
1064     m_zoomSlider->setMaximum(13);
1065     m_zoomSlider->setPageStep(1);
1066     m_zoomSlider->setInvertedAppearance(true);
1067
1068     m_zoomSlider->setMaximumWidth(150);
1069     m_zoomSlider->setMinimumWidth(100);
1070     toolbar->addWidget(m_zoomSlider);
1071
1072     m_zoomIn = new KAction(KIcon("zoom-in"), i18n("Zoom In"), this);
1073     toolbar->addAction(m_zoomIn);
1074     m_zoomIn->setShortcut(Qt::CTRL + Qt::Key_Plus);
1075
1076     actionWidget = toolbar->widgetForAction(m_buttonFitZoom);
1077     actionWidget->setMaximumWidth(max);
1078     actionWidget->setMaximumHeight(max - 4);
1079     actionWidget->setStyleSheet(styleBorderless);
1080
1081     actionWidget = toolbar->widgetForAction(m_zoomIn);
1082     actionWidget->setMaximumWidth(max);
1083     actionWidget->setMaximumHeight(max - 4);
1084     actionWidget->setStyleSheet(styleBorderless);
1085
1086     actionWidget = toolbar->widgetForAction(m_zoomOut);
1087     actionWidget->setMaximumWidth(max);
1088     actionWidget->setMaximumHeight(max - 4);
1089     actionWidget->setStyleSheet(styleBorderless);
1090
1091     connect(m_zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(slotSetZoom(int)));
1092     connect(m_zoomSlider, SIGNAL(sliderMoved(int)), this, SLOT(slotShowZoomSliderToolTip(int)));
1093     connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
1094     connect(m_zoomIn, SIGNAL(triggered(bool)), this, SLOT(slotZoomIn()));
1095     connect(m_zoomOut, SIGNAL(triggered(bool)), this, SLOT(slotZoomOut()));
1096
1097     toolbar->addSeparator();
1098
1099     //create automatic audio split button
1100     m_buttonAutomaticSplitAudio = new KAction(KIcon("kdenlive-split-audio"), i18n("Split audio and video automatically"), this);
1101     toolbar->addAction(m_buttonAutomaticSplitAudio);
1102     m_buttonAutomaticSplitAudio->setCheckable(true);
1103     m_buttonAutomaticSplitAudio->setChecked(KdenliveSettings::splitaudio());
1104     connect(m_buttonAutomaticSplitAudio, SIGNAL(triggered()), this, SLOT(slotSwitchSplitAudio()));
1105
1106     m_buttonVideoThumbs = new KAction(KIcon("kdenlive-show-videothumb"), i18n("Show video thumbnails"), this);
1107     toolbar->addAction(m_buttonVideoThumbs);
1108     m_buttonVideoThumbs->setCheckable(true);
1109     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1110     connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
1111
1112     m_buttonAudioThumbs = new KAction(KIcon("kdenlive-show-audiothumb"), i18n("Show audio thumbnails"), this);
1113     toolbar->addAction(m_buttonAudioThumbs);
1114     m_buttonAudioThumbs->setCheckable(true);
1115     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1116     connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
1117
1118     m_buttonShowMarkers = new KAction(KIcon("kdenlive-show-markers"), i18n("Show markers comments"), this);
1119     toolbar->addAction(m_buttonShowMarkers);
1120     m_buttonShowMarkers->setCheckable(true);
1121     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
1122     connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
1123
1124     m_buttonSnap = new KAction(KIcon("kdenlive-snap"), i18n("Snap"), this);
1125     toolbar->addAction(m_buttonSnap);
1126     m_buttonSnap->setCheckable(true);
1127     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
1128     connect(m_buttonSnap, SIGNAL(triggered()), this, SLOT(slotSwitchSnap()));
1129
1130     actionWidget = toolbar->widgetForAction(m_buttonAutomaticSplitAudio);
1131     actionWidget->setMaximumWidth(max);
1132     actionWidget->setMaximumHeight(max - 4);
1133
1134     actionWidget = toolbar->widgetForAction(m_buttonVideoThumbs);
1135     actionWidget->setMaximumWidth(max);
1136     actionWidget->setMaximumHeight(max - 4);
1137
1138     actionWidget = toolbar->widgetForAction(m_buttonAudioThumbs);
1139     actionWidget->setMaximumWidth(max);
1140     actionWidget->setMaximumHeight(max - 4);
1141
1142     actionWidget = toolbar->widgetForAction(m_buttonShowMarkers);
1143     actionWidget->setMaximumWidth(max);
1144     actionWidget->setMaximumHeight(max - 4);
1145
1146     actionWidget = toolbar->widgetForAction(m_buttonSnap);
1147     actionWidget->setMaximumWidth(max);
1148     actionWidget->setMaximumHeight(max - 4);
1149
1150     m_messageLabel = new StatusBarMessageLabel(this);
1151     m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
1152
1153     statusBar()->addWidget(m_messageLabel, 10);
1154     statusBar()->addWidget(m_statusProgressBar, 0);
1155     statusBar()->addPermanentWidget(toolbar);
1156     statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
1157     statusBar()->addPermanentWidget(m_timecodeFormat);
1158     //statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 3);
1159
1160     collection.addAction("normal_mode", m_normalEditTool);
1161     collection.addAction("overwrite_mode", m_overwriteEditTool);
1162     collection.addAction("insert_mode", m_insertEditTool);
1163     collection.addAction("select_tool", m_buttonSelectTool);
1164     collection.addAction("razor_tool", m_buttonRazorTool);
1165     collection.addAction("spacer_tool", m_buttonSpacerTool);
1166
1167     collection.addAction("automatic_split_audio", m_buttonAutomaticSplitAudio);
1168     collection.addAction("show_video_thumbs", m_buttonVideoThumbs);
1169     collection.addAction("show_audio_thumbs", m_buttonAudioThumbs);
1170     collection.addAction("show_markers", m_buttonShowMarkers);
1171     collection.addAction("snap", m_buttonSnap);
1172     collection.addAction("zoom_fit", m_buttonFitZoom);
1173     collection.addAction("zoom_in", m_zoomIn);
1174     collection.addAction("zoom_out", m_zoomOut);
1175
1176     m_projectSearch = new KAction(KIcon("edit-find"), i18n("Find"), this);
1177     collection.addAction("project_find", m_projectSearch);
1178     connect(m_projectSearch, SIGNAL(triggered(bool)), this, SLOT(slotFind()));
1179     m_projectSearch->setShortcut(Qt::Key_Slash);
1180
1181     m_projectSearchNext = new KAction(KIcon("go-down-search"), i18n("Find Next"), this);
1182     collection.addAction("project_find_next", m_projectSearchNext);
1183     connect(m_projectSearchNext, SIGNAL(triggered(bool)), this, SLOT(slotFindNext()));
1184     m_projectSearchNext->setShortcut(Qt::Key_F3);
1185     m_projectSearchNext->setEnabled(false);
1186
1187     KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Project Profiles"), this);
1188     collection.addAction("manage_profiles", profilesAction);
1189     connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
1190
1191     KNS3::standardAction(i18n("Download New Wipes..."),            this, SLOT(slotGetNewLumaStuff()),       actionCollection(), "get_new_lumas");
1192     KNS3::standardAction(i18n("Download New Render Profiles..."),  this, SLOT(slotGetNewRenderStuff()),     actionCollection(), "get_new_profiles");
1193     KNS3::standardAction(i18n("Download New Project Profiles..."), this, SLOT(slotGetNewMltProfileStuff()), actionCollection(), "get_new_mlt_profiles");
1194     KNS3::standardAction(i18n("Download New Title Templates..."),  this, SLOT(slotGetNewTitleStuff()),      actionCollection(), "get_new_titles");
1195
1196     KAction* wizAction = new KAction(KIcon("configure"), i18n("Run Config Wizard"), this);
1197     collection.addAction("run_wizard", wizAction);
1198     connect(wizAction, SIGNAL(triggered(bool)), this, SLOT(slotRunWizard()));
1199
1200     KAction* projectAction = new KAction(KIcon("configure"), i18n("Project Settings"), this);
1201     collection.addAction("project_settings", projectAction);
1202     connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
1203
1204     KAction* backupAction = new KAction(KIcon("edit-undo"), i18n("Open Backup File"), this);
1205     collection.addAction("open_backup", backupAction);
1206     connect(backupAction, SIGNAL(triggered(bool)), this, SLOT(slotOpenBackupDialog()));
1207
1208     KAction* projectRender = new KAction(KIcon("media-record"), i18n("Render"), this);
1209     collection.addAction("project_render", projectRender);
1210     projectRender->setShortcut(Qt::CTRL + Qt::Key_Return);
1211     connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
1212
1213     KAction* projectClean = new KAction(KIcon("edit-clear"), i18n("Clean Project"), this);
1214     collection.addAction("project_clean", projectClean);
1215     connect(projectClean, SIGNAL(triggered(bool)), this, SLOT(slotCleanProject()));
1216
1217     KAction* projectAdjust = new KAction(KIcon(), i18n("Adjust Profile to Current Clip"), this);
1218     collection.addAction("project_adjust_profile", projectAdjust);
1219     connect(projectAdjust, SIGNAL(triggered(bool)), m_projectList, SLOT(adjustProjectProfileToItem()));
1220
1221     KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
1222     KShortcut playShortcut;
1223     playShortcut.setPrimary(Qt::Key_Space);
1224     playShortcut.setAlternate(Qt::Key_K);
1225     monitorPlay->setShortcut(playShortcut);
1226     collection.addAction("monitor_play", monitorPlay);
1227     connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
1228
1229     KAction* monitorPause = new KAction(KIcon("media-playback-stop"), i18n("Pause"), this);
1230     collection.addAction("monitor_pause", monitorPause);
1231     connect(monitorPause, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPause()));
1232
1233     m_playZone = new KAction(KIcon("media-playback-start"), i18n("Play Zone"), this);
1234     m_playZone->setShortcut(Qt::CTRL + Qt::Key_Space);
1235     collection.addAction("monitor_play_zone", m_playZone);
1236     connect(m_playZone, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlayZone()));
1237
1238     m_loopZone = new KAction(KIcon("media-playback-start"), i18n("Loop Zone"), this);
1239     m_loopZone->setShortcut(Qt::ALT + Qt::Key_Space);
1240     collection.addAction("monitor_loop_zone", m_loopZone);
1241     connect(m_loopZone, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotLoopZone()));
1242
1243     m_loopClip = new KAction(KIcon("media-playback-start"), i18n("Loop selected clip"), this);
1244     m_loopClip->setEnabled(false);
1245     collection.addAction("monitor_loop_clip", m_loopClip);
1246     connect(m_loopClip, SIGNAL(triggered(bool)), m_projectMonitor, SLOT(slotLoopClip()));
1247
1248     KAction *dvdWizard =  new KAction(KIcon("media-optical"), i18n("DVD Wizard"), this);
1249     collection.addAction("dvd_wizard", dvdWizard);
1250     connect(dvdWizard, SIGNAL(triggered(bool)), this, SLOT(slotDvdWizard()));
1251
1252     KAction *transcodeClip =  new KAction(KIcon("edit-copy"), i18n("Transcode Clips"), this);
1253     collection.addAction("transcode_clip", transcodeClip);
1254     connect(transcodeClip, SIGNAL(triggered(bool)), this, SLOT(slotTranscodeClip()));
1255
1256     KAction *archiveProject =  new KAction(KIcon("file-save"), i18n("Archive Project"), this);
1257     collection.addAction("archive_project", archiveProject);
1258     connect(archiveProject, SIGNAL(triggered(bool)), this, SLOT(slotArchiveProject()));
1259
1260
1261     KAction *markIn = collection.addAction("mark_in");
1262     markIn->setText(i18n("Set Zone In"));
1263     markIn->setShortcut(Qt::Key_I);
1264     connect(markIn, SIGNAL(triggered(bool)), this, SLOT(slotSetInPoint()));
1265
1266     KAction *markOut = collection.addAction("mark_out");
1267     markOut->setText(i18n("Set Zone Out"));
1268     markOut->setShortcut(Qt::Key_O);
1269     connect(markOut, SIGNAL(triggered(bool)), this, SLOT(slotSetOutPoint()));
1270
1271     KAction *switchMon = collection.addAction("switch_monitor");
1272     switchMon->setText(i18n("Switch monitor"));
1273     switchMon->setShortcut(Qt::Key_T);
1274     connect(switchMon, SIGNAL(triggered(bool)), this, SLOT(slotSwitchMonitors()));
1275
1276     KAction *fullMon = collection.addAction("monitor_fullscreen");
1277     fullMon->setText(i18n("Switch monitor fullscreen"));
1278     fullMon->setIcon(KIcon("view-fullscreen"));
1279     connect(fullMon, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotSwitchFullscreen()));
1280
1281     KAction *insertTree = collection.addAction("insert_project_tree");
1282     insertTree->setText(i18n("Insert zone in project tree"));
1283     insertTree->setShortcut(Qt::CTRL + Qt::Key_I);
1284     connect(insertTree, SIGNAL(triggered(bool)), this, SLOT(slotInsertZoneToTree()));
1285
1286     KAction *insertTimeline = collection.addAction("insert_timeline");
1287     insertTimeline->setText(i18n("Insert zone in timeline"));
1288     insertTimeline->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_I);
1289     connect(insertTimeline, SIGNAL(triggered(bool)), this, SLOT(slotInsertZoneToTimeline()));
1290
1291     KAction *resizeStart =  new KAction(KIcon(), i18n("Resize Item Start"), this);
1292     collection.addAction("resize_timeline_clip_start", resizeStart);
1293     resizeStart->setShortcut(Qt::Key_1);
1294     connect(resizeStart, SIGNAL(triggered(bool)), this, SLOT(slotResizeItemStart()));
1295
1296     KAction *resizeEnd =  new KAction(KIcon(), i18n("Resize Item End"), this);
1297     collection.addAction("resize_timeline_clip_end", resizeEnd);
1298     resizeEnd->setShortcut(Qt::Key_2);
1299     connect(resizeEnd, SIGNAL(triggered(bool)), this, SLOT(slotResizeItemEnd()));
1300
1301     KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
1302     monitorSeekBackward->setShortcut(Qt::Key_J);
1303     collection.addAction("monitor_seek_backward", monitorSeekBackward);
1304     connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
1305
1306     KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
1307     monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
1308     collection.addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
1309     connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
1310
1311     KAction* monitorSeekBackwardOneSecond = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Second"), this);
1312     monitorSeekBackwardOneSecond->setShortcut(Qt::SHIFT + Qt::Key_Left);
1313     collection.addAction("monitor_seek_backward-one-second", monitorSeekBackwardOneSecond);
1314     connect(monitorSeekBackwardOneSecond, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneSecond()));
1315
1316     KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
1317     monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
1318     collection.addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
1319     connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
1320
1321     KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
1322     monitorSeekForward->setShortcut(Qt::Key_L);
1323     collection.addAction("monitor_seek_forward", monitorSeekForward);
1324     connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
1325
1326     KAction* clipStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Clip Start"), this);
1327     clipStart->setShortcut(Qt::Key_Home);
1328     collection.addAction("seek_clip_start", clipStart);
1329     connect(clipStart, SIGNAL(triggered(bool)), this, SLOT(slotClipStart()));
1330
1331     KAction* clipEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Clip End"), this);
1332     clipEnd->setShortcut(Qt::Key_End);
1333     collection.addAction("seek_clip_end", clipEnd);
1334     connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
1335
1336     KAction* zoneStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Zone Start"), this);
1337     zoneStart->setShortcut(Qt::SHIFT + Qt::Key_I);
1338     collection.addAction("seek_zone_start", zoneStart);
1339     connect(zoneStart, SIGNAL(triggered(bool)), this, SLOT(slotZoneStart()));
1340
1341     KAction* zoneEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Zone End"), this);
1342     zoneEnd->setShortcut(Qt::SHIFT + Qt::Key_O);
1343     collection.addAction("seek_zone_end", zoneEnd);
1344     connect(zoneEnd, SIGNAL(triggered(bool)), this, SLOT(slotZoneEnd()));
1345
1346     KAction* projectStart = new KAction(KIcon("go-first"), i18n("Go to Project Start"), this);
1347     projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
1348     collection.addAction("seek_start", projectStart);
1349     connect(projectStart, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotStart()));
1350
1351     KAction* projectEnd = new KAction(KIcon("go-last"), i18n("Go to Project End"), this);
1352     projectEnd->setShortcut(Qt::CTRL + Qt::Key_End);
1353     collection.addAction("seek_end", projectEnd);
1354     connect(projectEnd, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotEnd()));
1355
1356     KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
1357     monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
1358     collection.addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
1359     connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
1360
1361     KAction* monitorSeekForwardOneSecond = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Second"), this);
1362     monitorSeekForwardOneSecond->setShortcut(Qt::SHIFT + Qt::Key_Right);
1363     collection.addAction("monitor_seek_forward-one-second", monitorSeekForwardOneSecond);
1364     connect(monitorSeekForwardOneSecond, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneSecond()));
1365
1366     KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
1367     monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
1368     collection.addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
1369     connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
1370
1371     KAction* deleteItem = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
1372     deleteItem->setShortcut(Qt::Key_Delete);
1373     collection.addAction("delete_timeline_clip", deleteItem);
1374     connect(deleteItem, SIGNAL(triggered(bool)), this, SLOT(slotDeleteItem()));
1375
1376     /*KAction* editTimelineClipSpeed = new KAction(i18n("Change Clip Speed"), this);
1377     collection.addAction("change_clip_speed", editTimelineClipSpeed);
1378     editTimelineClipSpeed->setData("change_speed");
1379     connect(editTimelineClipSpeed, SIGNAL(triggered(bool)), this, SLOT(slotChangeClipSpeed()));*/
1380
1381     KAction *stickTransition = collection.addAction("auto_transition");
1382     stickTransition->setData(QString("auto"));
1383     stickTransition->setCheckable(true);
1384     stickTransition->setEnabled(false);
1385     stickTransition->setText(i18n("Automatic Transition"));
1386     connect(stickTransition, SIGNAL(triggered(bool)), this, SLOT(slotAutoTransition()));
1387
1388     KAction* groupClip = new KAction(KIcon("object-group"), i18n("Group Clips"), this);
1389     groupClip->setShortcut(Qt::CTRL + Qt::Key_G);
1390     collection.addAction("group_clip", groupClip);
1391     connect(groupClip, SIGNAL(triggered(bool)), this, SLOT(slotGroupClips()));
1392
1393     KAction* ungroupClip = new KAction(KIcon("object-ungroup"), i18n("Ungroup Clips"), this);
1394     collection.addAction("ungroup_clip", ungroupClip);
1395     ungroupClip->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_G);
1396     ungroupClip->setData("ungroup_clip");
1397     connect(ungroupClip, SIGNAL(triggered(bool)), this, SLOT(slotUnGroupClips()));
1398
1399     KAction* editItemDuration = new KAction(KIcon("measure"), i18n("Edit Duration"), this);
1400     collection.addAction("edit_item_duration", editItemDuration);
1401     connect(editItemDuration, SIGNAL(triggered(bool)), this, SLOT(slotEditItemDuration()));
1402     
1403     KAction* saveTimelineClip = new KAction(KIcon("document-save"), i18n("Save clip"), this);
1404     collection.addAction("save_timeline_clip", saveTimelineClip);
1405     connect(saveTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotSaveTimelineClip()));
1406
1407     KAction* clipInProjectTree = new KAction(KIcon("go-jump-definition"), i18n("Clip in Project Tree"), this);
1408     collection.addAction("clip_in_project_tree", clipInProjectTree);
1409     connect(clipInProjectTree, SIGNAL(triggered(bool)), this, SLOT(slotClipInProjectTree()));
1410
1411     /*KAction* clipToProjectTree = new KAction(KIcon("go-jump-definition"), i18n("Add Clip to Project Tree"), this);
1412     collection.addAction("clip_to_project_tree", clipToProjectTree);
1413     connect(clipToProjectTree, SIGNAL(triggered(bool)), this, SLOT(slotClipToProjectTree()));*/
1414
1415     KAction* insertOvertwrite = new KAction(KIcon(), i18n("Insert Clip Zone in Timeline (Overwrite)"), this);
1416     insertOvertwrite->setShortcut(Qt::Key_V);
1417     collection.addAction("overwrite_to_in_point", insertOvertwrite);
1418     connect(insertOvertwrite, SIGNAL(triggered(bool)), this, SLOT(slotInsertClipOverwrite()));
1419
1420     KAction* selectTimelineClip = new KAction(KIcon("edit-select"), i18n("Select Clip"), this);
1421     selectTimelineClip->setShortcut(Qt::Key_Plus);
1422     collection.addAction("select_timeline_clip", selectTimelineClip);
1423     connect(selectTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotSelectTimelineClip()));
1424
1425     KAction* deselectTimelineClip = new KAction(KIcon("edit-select"), i18n("Deselect Clip"), this);
1426     deselectTimelineClip->setShortcut(Qt::Key_Minus);
1427     collection.addAction("deselect_timeline_clip", deselectTimelineClip);
1428     connect(deselectTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeselectTimelineClip()));
1429
1430     KAction* selectAddTimelineClip = new KAction(KIcon("edit-select"), i18n("Add Clip To Selection"), this);
1431     selectAddTimelineClip->setShortcut(Qt::ALT + Qt::Key_Plus);
1432     collection.addAction("select_add_timeline_clip", selectAddTimelineClip);
1433     connect(selectAddTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotSelectAddTimelineClip()));
1434
1435     KAction* selectTimelineTransition = new KAction(KIcon("edit-select"), i18n("Select Transition"), this);
1436     selectTimelineTransition->setShortcut(Qt::SHIFT + Qt::Key_Plus);
1437     collection.addAction("select_timeline_transition", selectTimelineTransition);
1438     connect(selectTimelineTransition, SIGNAL(triggered(bool)), this, SLOT(slotSelectTimelineTransition()));
1439
1440     KAction* deselectTimelineTransition = new KAction(KIcon("edit-select"), i18n("Deselect Transition"), this);
1441     deselectTimelineTransition->setShortcut(Qt::SHIFT + Qt::Key_Minus);
1442     collection.addAction("deselect_timeline_transition", deselectTimelineTransition);
1443     connect(deselectTimelineTransition, SIGNAL(triggered(bool)), this, SLOT(slotDeselectTimelineTransition()));
1444
1445     KAction* selectAddTimelineTransition = new KAction(KIcon("edit-select"), i18n("Add Transition To Selection"), this);
1446     selectAddTimelineTransition->setShortcut(Qt::ALT + Qt::SHIFT + Qt::Key_Plus);
1447     collection.addAction("select_add_timeline_transition", selectAddTimelineTransition);
1448     connect(selectAddTimelineTransition, SIGNAL(triggered(bool)), this, SLOT(slotSelectAddTimelineTransition()));
1449
1450     KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
1451     cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
1452     collection.addAction("cut_timeline_clip", cutTimelineClip);
1453     connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
1454
1455     KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker"), this);
1456     collection.addAction("add_clip_marker", addClipMarker);
1457     connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
1458
1459     KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker"), this);
1460     collection.addAction("delete_clip_marker", deleteClipMarker);
1461     connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
1462
1463     KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers"), this);
1464     collection.addAction("delete_all_clip_markers", deleteAllClipMarkers);
1465     connect(deleteAllClipMarkers, SIGNAL(triggered(bool)), this, SLOT(slotDeleteAllClipMarkers()));
1466
1467     KAction* editClipMarker = new KAction(KIcon("document-properties"), i18n("Edit Marker"), this);
1468     editClipMarker->setData(QString("edit_marker"));
1469     collection.addAction("edit_clip_marker", editClipMarker);
1470     connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker()));
1471
1472     KAction* addMarkerGuideQuickly = new KAction(KIcon("bookmark-new"), i18n("Add Marker/Guide quickly"), this);
1473     addMarkerGuideQuickly->setShortcut(Qt::Key_Asterisk);
1474     collection.addAction("add_marker_guide_quickly", addMarkerGuideQuickly);
1475     connect(addMarkerGuideQuickly, SIGNAL(triggered(bool)), this, SLOT(slotAddMarkerGuideQuickly()));
1476
1477     KAction* splitAudio = new KAction(KIcon("document-new"), i18n("Split Audio"), this);
1478     collection.addAction("split_audio", splitAudio);
1479     connect(splitAudio, SIGNAL(triggered(bool)), this, SLOT(slotSplitAudio()));
1480
1481     KAction* setAudioAlignReference = new KAction(i18n("Set Audio Reference"), this);
1482     collection.addAction("set_audio_align_ref", setAudioAlignReference);
1483     connect(setAudioAlignReference, SIGNAL(triggered()), this, SLOT(slotSetAudioAlignReference()));
1484
1485     KAction* alignAudio = new KAction(i18n("Align Audio to Reference"), this);
1486     collection.addAction("align_audio", alignAudio);
1487     connect(alignAudio, SIGNAL(triggered()), this, SLOT(slotAlignAudio()));
1488
1489     KAction* audioOnly = new KAction(KIcon("document-new"), i18n("Audio Only"), this);
1490     collection.addAction("clip_audio_only", audioOnly);
1491     audioOnly->setData("clip_audio_only");
1492     audioOnly->setCheckable(true);
1493
1494     KAction* videoOnly = new KAction(KIcon("document-new"), i18n("Video Only"), this);
1495     collection.addAction("clip_video_only", videoOnly);
1496     videoOnly->setData("clip_video_only");
1497     videoOnly->setCheckable(true);
1498
1499     KAction* audioAndVideo = new KAction(KIcon("document-new"), i18n("Audio and Video"), this);
1500     collection.addAction("clip_audio_and_video", audioAndVideo);
1501     audioAndVideo->setData("clip_audio_and_video");
1502     audioAndVideo->setCheckable(true);
1503
1504     m_clipTypeGroup = new QActionGroup(this);
1505     m_clipTypeGroup->addAction(audioOnly);
1506     m_clipTypeGroup->addAction(videoOnly);
1507     m_clipTypeGroup->addAction(audioAndVideo);
1508     connect(m_clipTypeGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotUpdateClipType(QAction *)));
1509     m_clipTypeGroup->setEnabled(false);
1510
1511     KAction *insertSpace = new KAction(KIcon(), i18n("Insert Space"), this);
1512     collection.addAction("insert_space", insertSpace);
1513     connect(insertSpace, SIGNAL(triggered()), this, SLOT(slotInsertSpace()));
1514
1515     KAction *removeSpace = new KAction(KIcon(), i18n("Remove Space"), this);
1516     collection.addAction("delete_space", removeSpace);
1517     connect(removeSpace, SIGNAL(triggered()), this, SLOT(slotRemoveSpace()));
1518
1519     m_tracksActionCollection = new KActionCollection(this, KGlobal::mainComponent());
1520     m_tracksActionCollection->addAssociatedWidget(m_timelineArea);
1521
1522     KAction *insertTrack = new KAction(KIcon(), i18n("Insert Track"), m_tracksActionCollection);
1523     m_tracksActionCollection->addAction("insert_track", insertTrack);
1524     connect(insertTrack, SIGNAL(triggered()), this, SLOT(slotInsertTrack()));
1525
1526     KAction *deleteTrack = new KAction(KIcon(), i18n("Delete Track"), m_tracksActionCollection);
1527     m_tracksActionCollection->addAction("delete_track", deleteTrack);
1528     connect(deleteTrack, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
1529
1530     KAction *configTracks = new KAction(KIcon("configure"), i18n("Configure Tracks"), m_tracksActionCollection);
1531     m_tracksActionCollection->addAction("config_tracks", configTracks);
1532     connect(configTracks, SIGNAL(triggered()), this, SLOT(slotConfigTrack()));
1533
1534     KAction *selectTrack = new KAction(KIcon(), i18n("Select All in Current Track"), m_tracksActionCollection);
1535     connect(selectTrack, SIGNAL(triggered()), this, SLOT(slotSelectTrack()));
1536     m_tracksActionCollection->addAction("select_track", selectTrack);
1537
1538     QAction *selectAll = KStandardAction::selectAll(this, SLOT(slotSelectAllTracks()), m_tracksActionCollection);
1539     selectAll->setShortcutContext(Qt::WidgetWithChildrenShortcut);
1540     m_tracksActionCollection->addAction("select_all_tracks", selectAll);
1541
1542     KAction *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
1543     collection.addAction("add_guide", addGuide);
1544     connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
1545
1546     QAction *delGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
1547     collection.addAction("delete_guide", delGuide);
1548     connect(delGuide, SIGNAL(triggered()), this, SLOT(slotDeleteGuide()));
1549
1550     QAction *editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
1551     collection.addAction("edit_guide", editGuide);
1552     connect(editGuide, SIGNAL(triggered()), this, SLOT(slotEditGuide()));
1553
1554     QAction *delAllGuides = new KAction(KIcon("edit-delete"), i18n("Delete All Guides"), this);
1555     collection.addAction("delete_all_guides", delAllGuides);
1556     connect(delAllGuides, SIGNAL(triggered()), this, SLOT(slotDeleteAllGuides()));
1557
1558     QAction *pasteEffects = new KAction(KIcon("edit-paste"), i18n("Paste Effects"), this);
1559     collection.addAction("paste_effects", pasteEffects);
1560     pasteEffects->setData("paste_effects");
1561     connect(pasteEffects , SIGNAL(triggered()), this, SLOT(slotPasteEffects()));
1562
1563     QAction *showTimeline = new KAction(i18n("Show Timeline"), this);
1564     collection.addAction("show_timeline", showTimeline);
1565     showTimeline->setCheckable(true);
1566     showTimeline->setChecked(true);
1567     connect(showTimeline, SIGNAL(triggered(bool)), this, SLOT(slotShowTimeline(bool)));
1568
1569     QAction *showTitleBar = new KAction(i18n("Show Title Bars"), this);
1570     collection.addAction("show_titlebars", showTitleBar);
1571     showTitleBar->setCheckable(true);
1572     connect(showTitleBar, SIGNAL(triggered(bool)), this, SLOT(slotShowTitleBars(bool)));
1573     showTitleBar->setChecked(KdenliveSettings::showtitlebars());
1574     slotShowTitleBars(KdenliveSettings::showtitlebars());
1575
1576     m_closeAction = KStandardAction::close(this,  SLOT(closeCurrentDocument()),   collection);
1577     KStandardAction::quit(this,                   SLOT(close()),                  collection);
1578     KStandardAction::open(this,                   SLOT(openFile()),               collection);
1579     m_saveAction = KStandardAction::save(this,    SLOT(saveFile()),               collection);
1580     KStandardAction::saveAs(this,                 SLOT(saveFileAs()),             collection);
1581     KStandardAction::openNew(this,                SLOT(newFile()),                collection);
1582     // TODO: make the following connection to slotEditKeys work
1583     KStandardAction::keyBindings(this,            SLOT(slotEditKeys()),           collection);
1584     KStandardAction::preferences(this,            SLOT(slotPreferences()),        collection);
1585     KStandardAction::configureNotifications(this, SLOT(configureNotifications()), collection);
1586     KStandardAction::copy(this,                   SLOT(slotCopy()),               collection);
1587     KStandardAction::paste(this,                  SLOT(slotPaste()),              collection);
1588     KStandardAction::fullScreen(this,             SLOT(slotFullScreen()), this,   collection);
1589
1590     KAction *undo = KStandardAction::undo(m_commandStack, SLOT(undo()), collection);
1591     undo->setEnabled(false);
1592     connect(m_commandStack, SIGNAL(canUndoChanged(bool)), undo, SLOT(setEnabled(bool)));
1593
1594     KAction *redo = KStandardAction::redo(m_commandStack, SLOT(redo()), collection);
1595     redo->setEnabled(false);
1596     connect(m_commandStack, SIGNAL(canRedoChanged(bool)), redo, SLOT(setEnabled(bool)));
1597
1598     /*
1599     //TODO: Add status tooltip to actions ?
1600     connect(collection, SIGNAL(actionHovered(QAction*)),
1601             this, SLOT(slotDisplayActionMessage(QAction*)));*/
1602
1603
1604     QAction *addClip = new KAction(KIcon("kdenlive-add-clip"), i18n("Add Clip"), this);
1605     collection.addAction("add_clip", addClip);
1606     connect(addClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddClip()));
1607
1608     QAction *addColorClip = new KAction(KIcon("kdenlive-add-color-clip"), i18n("Add Color Clip"), this);
1609     collection.addAction("add_color_clip", addColorClip);
1610     connect(addColorClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddColorClip()));
1611
1612     QAction *addSlideClip = new KAction(KIcon("kdenlive-add-slide-clip"), i18n("Add Slideshow Clip"), this);
1613     collection.addAction("add_slide_clip", addSlideClip);
1614     connect(addSlideClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddSlideshowClip()));
1615
1616     QAction *addTitleClip = new KAction(KIcon("kdenlive-add-text-clip"), i18n("Add Title Clip"), this);
1617     collection.addAction("add_text_clip", addTitleClip);
1618     connect(addTitleClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddTitleClip()));
1619
1620     QAction *addTitleTemplateClip = new KAction(KIcon("kdenlive-add-text-clip"), i18n("Add Template Title"), this);
1621     collection.addAction("add_text_template_clip", addTitleTemplateClip);
1622     connect(addTitleTemplateClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddTitleTemplateClip()));
1623
1624     QAction *addFolderButton = new KAction(KIcon("folder-new"), i18n("Create Folder"), this);
1625     collection.addAction("add_folder", addFolderButton);
1626     connect(addFolderButton , SIGNAL(triggered()), m_projectList, SLOT(slotAddFolder()));
1627
1628     QAction *downloadResources = new KAction(KIcon("download"), i18n("Online Resources"), this);
1629     collection.addAction("download_resource", downloadResources);
1630     connect(downloadResources , SIGNAL(triggered()), this, SLOT(slotDownloadResources()));
1631
1632     QAction *clipProperties = new KAction(KIcon("document-edit"), i18n("Clip Properties"), this);
1633     collection.addAction("clip_properties", clipProperties);
1634     clipProperties->setData("clip_properties");
1635     connect(clipProperties , SIGNAL(triggered()), m_projectList, SLOT(slotEditClip()));
1636     clipProperties->setEnabled(false);
1637
1638     QAction *openClip = new KAction(KIcon("document-open"), i18n("Edit Clip"), this);
1639     collection.addAction("edit_clip", openClip);
1640     openClip->setData("edit_clip");
1641     connect(openClip , SIGNAL(triggered()), m_projectList, SLOT(slotOpenClip()));
1642     openClip->setEnabled(false);
1643
1644     QAction *deleteClip = new KAction(KIcon("edit-delete"), i18n("Delete Clip"), this);
1645     collection.addAction("delete_clip", deleteClip);
1646     deleteClip->setData("delete_clip");
1647     connect(deleteClip , SIGNAL(triggered()), m_projectList, SLOT(slotRemoveClip()));
1648     deleteClip->setEnabled(false);
1649
1650     QAction *reloadClip = new KAction(KIcon("view-refresh"), i18n("Reload Clip"), this);
1651     collection.addAction("reload_clip", reloadClip);
1652     reloadClip->setData("reload_clip");
1653     connect(reloadClip , SIGNAL(triggered()), m_projectList, SLOT(slotReloadClip()));
1654     reloadClip->setEnabled(false);
1655
1656     QAction *proxyClip = new KAction(i18n("Proxy Clip"), this);
1657     collection.addAction("proxy_clip", proxyClip);
1658     proxyClip->setData("proxy_clip");
1659     proxyClip->setCheckable(true);
1660     proxyClip->setChecked(false);
1661     connect(proxyClip, SIGNAL(toggled(bool)), m_projectList, SLOT(slotProxyCurrentItem(bool)));
1662
1663     QAction *stopMotion = new KAction(KIcon("image-x-generic"), i18n("Stop Motion Capture"), this);
1664     collection.addAction("stopmotion", stopMotion);
1665     connect(stopMotion , SIGNAL(triggered()), this, SLOT(slotOpenStopmotion()));
1666
1667     QMenu *addClips = new QMenu();
1668     addClips->addAction(addClip);
1669     addClips->addAction(addColorClip);
1670     addClips->addAction(addSlideClip);
1671     addClips->addAction(addTitleClip);
1672     addClips->addAction(addTitleTemplateClip);
1673     addClips->addAction(addFolderButton);
1674     addClips->addAction(downloadResources);
1675
1676     addClips->addAction(reloadClip);
1677     addClips->addAction(proxyClip);
1678     addClips->addAction(clipProperties);
1679     addClips->addAction(openClip);
1680     addClips->addAction(deleteClip);
1681     m_projectList->setupMenu(addClips, addClip);
1682
1683     // Setup effects and transitions actions.
1684     m_effectsActionCollection = new KActionCollection(this, KGlobal::mainComponent());
1685     //KActionCategory *transitionActions = new KActionCategory(i18n("Transitions"), m_effectsActionCollection);
1686     KActionCategory *transitionActions = new KActionCategory(i18n("Transitions"), collection);
1687     m_transitions = new KAction*[transitions.count()];
1688     for (int i = 0; i < transitions.count(); i++) {
1689         QStringList effectInfo = transitions.effectIdInfo(i);
1690         m_transitions[i] = new KAction(effectInfo.at(0), this);
1691         m_transitions[i]->setData(effectInfo);
1692         m_transitions[i]->setIconVisibleInMenu(false);
1693         QString id = effectInfo.at(2);
1694         if (id.isEmpty()) id = effectInfo.at(1);
1695         transitionActions->addAction("transition_" + id, m_transitions[i]);
1696     }
1697     //m_effectsActionCollection->readSettings();
1698
1699 }
1700
1701 void MainWindow::slotDisplayActionMessage(QAction *a)
1702 {
1703     statusBar()->showMessage(a->data().toString(), 3000);
1704 }
1705
1706 void MainWindow::setStatusBarStyleSheet(const QPalette &p)
1707 {
1708     KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
1709     QColor buttonBg = scheme.background(KColorScheme::LinkBackground).color();
1710     QColor buttonBord = scheme.foreground(KColorScheme::LinkText).color();
1711     QColor buttonBord2 = scheme.shade(KColorScheme::LightShade);
1712     statusBar()->setStyleSheet(QString("QStatusBar QLabel {font-size:%1pt;} QStatusBar::item { border: 0px; font-size:%1pt;padding:0px; }").arg(statusBar()->font().pointSize()));
1713     QString style1 = QString("QToolBar { border: 0px } QToolButton { border-style: inset; border:1px solid transparent;border-radius: 3px;margin: 0px 3px;padding: 0px;} QToolButton:hover { background: %3;border-style: inset; border:1px solid %3;border-radius: 3px;} QToolButton:checked { background-color: %1; border-style: inset; border:1px solid %2;border-radius: 3px;}").arg(buttonBg.name()).arg(buttonBord.name()).arg(buttonBord2.name());
1714     statusBar()->setStyleSheet(style1);
1715 }
1716
1717 void MainWindow::loadLayouts()
1718 {
1719     QMenu *saveLayout = (QMenu*)(factory()->container("layout_save_as", this));
1720     if (m_loadLayout == NULL || saveLayout == NULL) return;
1721     KSharedConfigPtr config = KGlobal::config();
1722     KConfigGroup layoutGroup(config, "Layouts");
1723     QStringList entries = layoutGroup.keyList();
1724     QList<QAction *> loadActions = m_loadLayout->actions();
1725     QList<QAction *> saveActions = saveLayout->actions();
1726     for (int i = 1; i < 5; i++) {
1727         // Rename the layouts actions
1728         foreach(const QString & key, entries) {
1729             if (key.endsWith(QString("_%1").arg(i))) {
1730                 // Found previously saved layout
1731                 QString layoutName = key.section("_", 0, -2);
1732                 for (int j = 0; j < loadActions.count(); j++) {
1733                     if (loadActions.at(j)->data().toString().endsWith("_" + QString::number(i))) {
1734                         loadActions[j]->setText(layoutName);
1735                         loadActions[j]->setData(key);
1736                         break;
1737                     }
1738                 }
1739                 for (int j = 0; j < saveActions.count(); j++) {
1740                     if (saveActions.at(j)->data().toString().endsWith("_" + QString::number(i))) {
1741                         saveActions[j]->setText(i18n("Save as %1").arg(layoutName));
1742                         saveActions[j]->setData(key);
1743                         break;
1744                     }
1745                 }
1746             }
1747         }
1748     }
1749 }
1750
1751 void MainWindow::slotLoadLayout(QAction *action)
1752 {
1753     if (!action) return;
1754     QString layoutId = action->data().toString();
1755     if (layoutId.isEmpty()) return;
1756     KSharedConfigPtr config = KGlobal::config();
1757     KConfigGroup layouts(config, "Layouts");
1758     QByteArray state = QByteArray::fromBase64(layouts.readEntry(layoutId).toAscii());
1759     restoreState(state);
1760 }
1761
1762 void MainWindow::slotSaveLayout(QAction *action)
1763 {
1764     QString originallayoutName = action->data().toString();
1765     int layoutId = originallayoutName.section('_', -1).toInt();
1766
1767     QString layoutName = QInputDialog::getText(this, i18n("Save Layout"), i18n("Layout name:"), QLineEdit::Normal, originallayoutName.section('_', 0, -2));
1768     if (layoutName.isEmpty()) return;
1769     KSharedConfigPtr config = KGlobal::config();
1770     KConfigGroup layouts(config, "Layouts");
1771     layouts.deleteEntry(originallayoutName);
1772
1773     QByteArray st = saveState();
1774     layoutName.append("_" + QString::number(layoutId));
1775     layouts.writeEntry(layoutName, st.toBase64());
1776     loadLayouts();
1777 }
1778
1779 void MainWindow::saveOptions()
1780 {
1781     KdenliveSettings::self()->writeConfig();
1782     KSharedConfigPtr config = KGlobal::config();
1783     m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
1784     KConfigGroup treecolumns(config, "Project Tree");
1785     treecolumns.writeEntry("columns", m_projectList->headerInfo());
1786     config->sync();
1787 }
1788
1789 void MainWindow::readOptions()
1790 {
1791     KSharedConfigPtr config = KGlobal::config();
1792     m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
1793     KConfigGroup initialGroup(config, "version");
1794     bool upgrade = false;
1795     if (initialGroup.exists()) {
1796         if (initialGroup.readEntry("version", QString()).section(' ', 0, 0) != QString(version).section(' ', 0, 0)) {
1797             upgrade = true;
1798         }
1799
1800         if (initialGroup.readEntry("version") == "0.7") {
1801             //Add new settings from 0.7.1
1802             if (KdenliveSettings::defaultprojectfolder().isEmpty()) {
1803                 QString path = QDir::homePath() + "/kdenlive";
1804                 if (KStandardDirs::makeDir(path)  == false) {
1805                     kDebug() << "/// ERROR CREATING PROJECT FOLDER: " << path;
1806                 } else KdenliveSettings::setDefaultprojectfolder(path);
1807             }
1808         }
1809
1810     }
1811
1812     if (!initialGroup.exists() || upgrade) {
1813         // this is our first run, show Wizard
1814         Wizard *w = new Wizard(upgrade, this);
1815         if (w->exec() == QDialog::Accepted && w->isOk()) {
1816             w->adjustSettings();
1817             initialGroup.writeEntry("version", version);
1818             delete w;
1819         } else {
1820             ::exit(1);
1821         }
1822     }
1823     KConfigGroup treecolumns(config, "Project Tree");
1824     const QByteArray state = treecolumns.readEntry("columns", QByteArray());
1825     if (!state.isEmpty())
1826         m_projectList->setHeaderInfo(state);
1827 }
1828
1829 void MainWindow::slotRunWizard()
1830 {
1831     Wizard *w = new Wizard(false, this);
1832     if (w->exec() == QDialog::Accepted && w->isOk()) {
1833         w->adjustSettings();
1834     }
1835     delete w;
1836 }
1837
1838 void MainWindow::newFile(bool showProjectSettings, bool force)
1839 {
1840     if (!m_timelineArea->isEnabled() && !force)
1841         return;
1842     m_fileRevert->setEnabled(false);
1843     QString profileName = KdenliveSettings::default_profile();
1844     KUrl projectFolder = KdenliveSettings::defaultprojectfolder();
1845     QMap <QString, QString> documentProperties;
1846     QMap <QString, QString> documentMetadata;
1847     QPoint projectTracks(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks());
1848     if (!showProjectSettings) {
1849         if (!KdenliveSettings::activatetabs())
1850             if (!closeCurrentDocument())
1851                 return;
1852     } else {
1853         ProjectSettings *w = new ProjectSettings(NULL, QMap <QString, QString> (), QStringList(), projectTracks.x(), projectTracks.y(), KdenliveSettings::defaultprojectfolder(), false, true, this);
1854         if (w->exec() != QDialog::Accepted)
1855             return;
1856         if (!KdenliveSettings::activatetabs())
1857             if (!closeCurrentDocument())
1858                 return;
1859         if (KdenliveSettings::videothumbnails() != w->enableVideoThumbs())
1860             slotSwitchVideoThumbs();
1861         if (KdenliveSettings::audiothumbnails() != w->enableAudioThumbs())
1862             slotSwitchAudioThumbs();
1863         profileName = w->selectedProfile();
1864         projectFolder = w->selectedFolder();
1865         projectTracks = w->tracks();
1866         documentProperties.insert("enableproxy", QString::number((int) w->useProxy()));
1867         documentProperties.insert("generateproxy", QString::number((int) w->generateProxy()));
1868         documentProperties.insert("proxyminsize", QString::number(w->proxyMinSize()));
1869         documentProperties.insert("proxyparams", w->proxyParams());
1870         documentProperties.insert("proxyextension", w->proxyExtension());
1871         documentProperties.insert("generateimageproxy", QString::number((int) w->generateImageProxy()));
1872         documentProperties.insert("proxyimageminsize", QString::number(w->proxyImageMinSize()));
1873         documentMetadata = w->metadata();
1874         delete w;
1875     }
1876     m_timelineArea->setEnabled(true);
1877     m_projectList->setEnabled(true);
1878     bool openBackup;
1879     KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, profileName, documentProperties, documentMetadata, projectTracks, m_projectMonitor->render, m_notesWidget, &openBackup, this);
1880     doc->m_autosave = new KAutoSaveFile(KUrl(), doc);
1881     bool ok;
1882     TrackView *trackView = new TrackView(doc, m_tracksActionCollection->actions(), &ok, this);
1883     m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
1884     if (!ok) {
1885         // MLT is broken
1886         //m_timelineArea->setEnabled(false);
1887         //m_projectList->setEnabled(false);
1888         slotPreferences(6);
1889         return;
1890     }
1891     if (m_timelineArea->count() == 1) {
1892         connectDocumentInfo(doc);
1893         connectDocument(trackView, doc);
1894     } else
1895         m_timelineArea->setTabBarHidden(false);
1896     m_monitorManager->activateMonitor(Kdenlive::clipMonitor);
1897     m_closeAction->setEnabled(m_timelineArea->count() > 1);
1898 }
1899
1900 void MainWindow::activateDocument()
1901 {
1902     if (m_timelineArea->currentWidget() == NULL || !m_timelineArea->isEnabled()) return;
1903     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1904     KdenliveDoc *currentDoc = currentTab->document();
1905     connectDocumentInfo(currentDoc);
1906     connectDocument(currentTab, currentDoc);
1907 }
1908
1909 bool MainWindow::closeCurrentDocument(bool saveChanges)
1910 {
1911     QWidget *w = m_timelineArea->currentWidget();
1912     if (!w) return true;
1913     // closing current document
1914     int ix = m_timelineArea->currentIndex() + 1;
1915     if (ix == m_timelineArea->count()) ix = 0;
1916     m_timelineArea->setCurrentIndex(ix);
1917     TrackView *tabToClose = (TrackView *) w;
1918     KdenliveDoc *docToClose = tabToClose->document();
1919     if (docToClose && docToClose->isModified() && saveChanges) {
1920         QString message;
1921         if (m_activeDocument->url().fileName().isEmpty())
1922             message = i18n("Save changes to document?");
1923         else
1924             message = i18n("The project <b>\"%1\"</b> has been changed.\nDo you want to save your changes?").arg(m_activeDocument->url().fileName());
1925         switch (KMessageBox::warningYesNoCancel(this, message)) {
1926         case KMessageBox::Yes :
1927             // save document here. If saving fails, return false;
1928             if (saveFile() == false) return false;
1929             break;
1930         case KMessageBox::Cancel :
1931             return false;
1932             break;
1933         default:
1934             break;
1935         }
1936     }
1937     m_clipMonitor->slotSetClipProducer(NULL);
1938     m_projectList->slotResetProjectList();
1939     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
1940     if (m_timelineArea->count() == 1) {
1941         m_timelineArea->setTabBarHidden(true);
1942         m_closeAction->setEnabled(false);
1943     }
1944     if (docToClose == m_activeDocument) {
1945         delete m_activeDocument;
1946         m_activeDocument = NULL;
1947         m_effectStack->clear();
1948         m_transitionConfig->slotTransitionItemSelected(NULL, 0, QPoint(), false);
1949     } else {
1950         delete docToClose;
1951     }
1952     if (w == m_activeTimeline) {
1953         delete m_activeTimeline;
1954         m_activeTimeline = NULL;
1955     } else {
1956         delete w;
1957     }
1958     return true;
1959 }
1960
1961 bool MainWindow::saveFileAs(const QString &outputFileName)
1962 {
1963     QString currentSceneList;
1964     m_monitorManager->stopActiveMonitor();
1965
1966     if (m_activeDocument->saveSceneList(outputFileName, m_projectMonitor->sceneList(), m_projectList->expandedFolders()) == false)
1967         return false;
1968
1969     // Save timeline thumbnails
1970     m_activeTimeline->projectView()->saveThumbnails();
1971     m_activeDocument->setUrl(KUrl(outputFileName));
1972     QByteArray hash = QCryptographicHash::hash(KUrl(outputFileName).encodedPath(), QCryptographicHash::Md5).toHex();
1973     if (m_activeDocument->m_autosave == NULL) {
1974         m_activeDocument->m_autosave = new KAutoSaveFile(KUrl(hash), this);
1975     } else m_activeDocument->m_autosave->setManagedFile(KUrl(hash));
1976     setCaption(m_activeDocument->description());
1977     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1978     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
1979     m_activeDocument->setModified(false);
1980     m_fileOpenRecent->addUrl(KUrl(outputFileName));
1981     m_fileRevert->setEnabled(true);
1982     m_undoView->stack()->setClean();
1983     return true;
1984 }
1985
1986 bool MainWindow::saveFileAs()
1987 {
1988     QString outputFile = KFileDialog::getSaveFileName(m_activeDocument->projectFolder(), getMimeType(false));
1989     if (outputFile.isEmpty()) {
1990         return false;
1991     }
1992     if (QFile::exists(outputFile)) {
1993         // Show the file dialog again if the user does not want to overwrite the file
1994         if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", outputFile)) == KMessageBox::No)
1995             return saveFileAs();
1996     }
1997     return saveFileAs(outputFile);
1998 }
1999
2000 bool MainWindow::saveFile()
2001 {
2002     if (!m_activeDocument) return true;
2003     if (m_activeDocument->url().isEmpty()) {
2004         return saveFileAs();
2005     } else {
2006         bool result = saveFileAs(m_activeDocument->url().path());
2007         m_activeDocument->m_autosave->resize(0);
2008         return result;
2009     }
2010 }
2011
2012 void MainWindow::openFile()
2013 {
2014     if (!m_startUrl.isEmpty()) {
2015         openFile(m_startUrl);
2016         m_startUrl = KUrl();
2017         return;
2018     }
2019     KUrl url = KFileDialog::getOpenUrl(KUrl("kfiledialog:///projectfolder"), getMimeType());
2020     if (url.isEmpty()) return;
2021     m_fileOpenRecent->addUrl(url);
2022     openFile(url);
2023 }
2024
2025 void MainWindow::openLastFile()
2026 {
2027     KSharedConfigPtr config = KGlobal::config();
2028     KUrl::List urls = m_fileOpenRecent->urls();
2029     //WARNING: this is buggy, we get a random url, not the last one. Bug in KRecentFileAction?
2030     if (urls.isEmpty()) newFile(false);
2031     else openFile(urls.last());
2032 }
2033
2034 void MainWindow::openFile(const KUrl &url)
2035 {
2036     // Make sure the url is a Kdenlive project file
2037     KMimeType::Ptr mime = KMimeType::findByUrl(url);
2038     if (mime.data()->is("application/x-compressed-tar")) {
2039         // Opening a compressed project file, we need to process it
2040         kDebug()<<"Opening archive, processing";
2041         ArchiveWidget *ar = new ArchiveWidget(url);
2042         if (ar->exec() == QDialog::Accepted) openFile(KUrl(ar->extractedProjectFile()));
2043         delete ar;
2044         return;
2045     }
2046     if (!url.fileName().endsWith(".kdenlive")) {
2047         // This is not a Kdenlive project file, abort loading
2048         KMessageBox::sorry(this, i18n("File %1 is not a Kdenlive project file", url.path()));
2049         return;
2050     }
2051
2052     // Check if the document is already opened
2053     const int ct = m_timelineArea->count();
2054     bool isOpened = false;
2055     int i;
2056     for (i = 0; i < ct; i++) {
2057         TrackView *tab = (TrackView *) m_timelineArea->widget(i);
2058         KdenliveDoc *doc = tab->document();
2059         if (doc->url() == url) {
2060             isOpened = true;
2061             break;
2062         }
2063     }
2064     if (isOpened) {
2065         m_timelineArea->setCurrentIndex(i);
2066         return;
2067     }
2068
2069     if (!KdenliveSettings::activatetabs()) if (!closeCurrentDocument()) return;
2070
2071     // Check for backup file
2072     QByteArray hash = QCryptographicHash::hash(url.encodedPath(), QCryptographicHash::Md5).toHex();
2073     QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::staleFiles(KUrl(hash));
2074     if (!staleFiles.isEmpty()) {
2075         if (KMessageBox::questionYesNo(this,
2076                                        i18n("Auto-saved files exist. Do you want to recover them now?"),
2077                                        i18n("File Recovery"),
2078                                        KGuiItem(i18n("Recover")), KGuiItem(i18n("Don't recover"))) == KMessageBox::Yes) {
2079             recoverFiles(staleFiles, url);
2080             return;
2081         } else {
2082             // remove the stale files
2083             foreach(KAutoSaveFile * stale, staleFiles) {
2084                 stale->open(QIODevice::ReadWrite);
2085                 delete stale;
2086             }
2087         }
2088     }
2089     m_messageLabel->setMessage(i18n("Opening file %1", url.path()), InformationMessage);
2090     m_messageLabel->repaint();
2091     doOpenFile(url, NULL);
2092 }
2093
2094 void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale)
2095 {
2096     if (!m_timelineArea->isEnabled()) return;
2097     m_fileRevert->setEnabled(true);
2098
2099     // Recreate stopmotion widget on document change
2100     if (m_stopmotion) {
2101         delete m_stopmotion;
2102         m_stopmotion = NULL;
2103     }
2104
2105     m_timer.start();
2106     KProgressDialog progressDialog(this, i18n("Loading project"), i18n("Loading project"));
2107     progressDialog.setAllowCancel(false);
2108     progressDialog.progressBar()->setMaximum(4);
2109     progressDialog.show();
2110     progressDialog.progressBar()->setValue(0);
2111     qApp->processEvents();
2112
2113     bool openBackup;
2114     KdenliveDoc *doc = new KdenliveDoc(stale ? KUrl(stale->fileName()) : url, KdenliveSettings::defaultprojectfolder(), m_commandStack, KdenliveSettings::default_profile(), QMap <QString, QString> (), QMap <QString, QString> (), QPoint(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks()), m_projectMonitor->render, m_notesWidget, &openBackup, this, &progressDialog);
2115
2116     progressDialog.progressBar()->setValue(1);
2117     progressDialog.progressBar()->setMaximum(4);
2118     progressDialog.setLabelText(i18n("Loading project"));
2119     qApp->processEvents();
2120
2121     if (stale == NULL) {
2122         QByteArray hash = QCryptographicHash::hash(url.encodedPath(), QCryptographicHash::Md5).toHex();
2123         stale = new KAutoSaveFile(KUrl(hash), doc);
2124         doc->m_autosave = stale;
2125     } else {
2126         doc->m_autosave = stale;
2127         doc->setUrl(url);//stale->managedFile());
2128         doc->setModified(true);
2129         stale->setParent(doc);
2130     }
2131     connectDocumentInfo(doc);
2132
2133     progressDialog.progressBar()->setValue(2);
2134     qApp->processEvents();
2135
2136     bool ok;
2137     TrackView *trackView = new TrackView(doc, m_tracksActionCollection->actions(), &ok, this);
2138     connectDocument(trackView, doc);
2139     progressDialog.progressBar()->setValue(3);
2140     qApp->processEvents();
2141
2142     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
2143     if (!ok) {
2144         m_timelineArea->setEnabled(false);
2145         m_projectList->setEnabled(false);
2146         KMessageBox::sorry(this, i18n("Cannot open file %1.\nProject is corrupted.", url.path()));
2147         slotGotProgressInfo(QString(), -1);
2148         newFile(false, true);
2149         return;
2150     }
2151     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
2152     trackView->setDuration(trackView->duration());
2153     trackView->projectView()->initCursorPos(m_projectMonitor->render->seekPosition().frames(doc->fps()));
2154
2155     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
2156     slotGotProgressInfo(QString(), -1);
2157     m_projectMonitor->adjustRulerSize(trackView->duration());
2158     m_projectMonitor->slotZoneMoved(trackView->inPoint(), trackView->outPoint());
2159     progressDialog.progressBar()->setValue(4);
2160     if (openBackup) slotOpenBackupDialog(url);
2161 }
2162
2163 void MainWindow::recoverFiles(QList<KAutoSaveFile *> staleFiles, const KUrl &originUrl)
2164 {
2165     foreach(KAutoSaveFile * stale, staleFiles) {
2166         /*if (!stale->open(QIODevice::QIODevice::ReadOnly)) {
2167                   // show an error message; we could not steal the lockfile
2168                   // maybe another application got to the file before us?
2169                   delete stale;
2170                   continue;
2171         }*/
2172         kDebug() << "// OPENING RECOVERY: " << stale->fileName() << "\nMANAGED: " << stale->managedFile().path();
2173         // the stalefiles also contain ".lock" files so we must ignore them... bug in KAutoSaveFile?
2174         if (!stale->fileName().endsWith(".lock")) doOpenFile(originUrl, stale);
2175         else KIO::NetAccess::del(KUrl(stale->fileName()), this);
2176     }
2177 }
2178
2179 void MainWindow::parseProfiles(const QString &mltPath)
2180 {
2181     //KdenliveSettings::setDefaulttmpfolder();
2182     if (!mltPath.isEmpty()) {
2183         KdenliveSettings::setMltpath(mltPath + "/share/mlt/profiles/");
2184         KdenliveSettings::setRendererpath(mltPath + "/bin/melt");
2185     }
2186
2187     if (KdenliveSettings::mltpath().isEmpty())
2188         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
2189
2190     if (KdenliveSettings::rendererpath().isEmpty() || KdenliveSettings::rendererpath().endsWith("inigo")) {
2191         QString meltPath = QString(MLT_PREFIX) + QString("/bin/melt");
2192         if (!QFile::exists(meltPath))
2193             meltPath = KStandardDirs::findExe("melt");
2194         KdenliveSettings::setRendererpath(meltPath);
2195     }
2196
2197     if (KdenliveSettings::rendererpath().isEmpty()) {
2198         // Cannot find the MLT melt renderer, ask for location
2199         KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(QString(), i18n("Cannot find the melt program required for rendering (part of MLT)"), this);
2200         if (getUrl->exec() == QDialog::Rejected) {
2201             ::exit(0);
2202         }
2203         KUrl rendererPath = getUrl->selectedUrl();
2204         delete getUrl;
2205         if (rendererPath.isEmpty()) ::exit(0);
2206         KdenliveSettings::setRendererpath(rendererPath.path());
2207     }
2208
2209     QStringList profilesFilter;
2210     profilesFilter << "*";
2211     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
2212     if (profilesList.isEmpty()) {
2213         // Cannot find MLT path, try finding melt
2214         QString profilePath = KdenliveSettings::rendererpath();
2215         if (!profilePath.isEmpty()) {
2216             profilePath = profilePath.section('/', 0, -3);
2217             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
2218             profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
2219         }
2220         if (profilesList.isEmpty()) {
2221             // Cannot find the MLT profiles, ask for location
2222             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your MLT profiles, please give the path"), this);
2223             getUrl->fileDialog()->setMode(KFile::Directory);
2224             if (getUrl->exec() == QDialog::Rejected) {
2225                 ::exit(0);
2226             }
2227             KUrl mltPath = getUrl->selectedUrl();
2228             delete getUrl;
2229             if (mltPath.isEmpty()) ::exit(0);
2230             KdenliveSettings::setMltpath(mltPath.path(KUrl::AddTrailingSlash));
2231             profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
2232         }
2233     }
2234
2235     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
2236
2237     // Parse again MLT profiles to build a list of available video formats
2238     if (profilesList.isEmpty()) parseProfiles();
2239 }
2240
2241
2242 void MainWindow::slotEditProfiles()
2243 {
2244     ProfilesDialog *w = new ProfilesDialog;
2245     if (w->exec() == QDialog::Accepted) {
2246         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
2247         if (d) d->checkProfile();
2248     }
2249     delete w;
2250 }
2251
2252 void MainWindow::slotDetectAudioDriver()
2253 {
2254     /* WARNING: do not use this method because sometimes detects wrong driver (pulse instead of alsa),
2255     leading to no audio output, see bug #934 */
2256
2257     //decide which audio driver is really best, in some cases SDL is wrong
2258     if (KdenliveSettings::audiodrivername().isEmpty()) {
2259         QString driver;
2260         KProcess readProcess;
2261         //PulseAudio needs to be selected if it exists, the ALSA pulse pcm device is not fast enough.
2262         if (!KStandardDirs::findExe("pactl").isEmpty()) {
2263             readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
2264             readProcess.setProgram("pactl", QStringList() << "stat");
2265             readProcess.execute(2000); // Kill it after 2 seconds
2266
2267             QString result = QString(readProcess.readAllStandardOutput());
2268             kDebug() << "// / / / / / READING PACTL: ";
2269             kDebug() << result;
2270             if (!result.isEmpty()) {
2271                 driver = "pulse";
2272                 kDebug() << "// / / / / PULSEAUDIO DETECTED";
2273             }
2274         }
2275         //put others here
2276         KdenliveSettings::setAutoaudiodrivername(driver);
2277     }
2278 }
2279
2280 void MainWindow::slotEditProjectSettings()
2281 {
2282     QPoint p = m_activeDocument->getTracksCount();
2283     ProjectSettings *w = new ProjectSettings(m_projectList, m_activeDocument->metadata(), m_activeTimeline->projectView()->extractTransitionsLumas(), p.x(), p.y(), m_activeDocument->projectFolder().path(), true, !m_activeDocument->isModified(), this);
2284     connect(w, SIGNAL(disableProxies()), this, SLOT(slotDisableProxies()));
2285
2286     if (w->exec() == QDialog::Accepted) {
2287         QString profile = w->selectedProfile();
2288         m_activeDocument->setProjectFolder(w->selectedFolder());
2289 #ifndef Q_WS_MAC
2290         m_recMonitor->slotUpdateCaptureFolder(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
2291 #endif
2292         if (m_renderWidget) m_renderWidget->setDocumentPath(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
2293         if (KdenliveSettings::videothumbnails() != w->enableVideoThumbs()) slotSwitchVideoThumbs();
2294         if (KdenliveSettings::audiothumbnails() != w->enableAudioThumbs()) slotSwitchAudioThumbs();
2295         if (m_activeDocument->profilePath() != profile) slotUpdateProjectProfile(profile);
2296         if (m_activeDocument->getDocumentProperty("proxyparams") != w->proxyParams()) {
2297             m_activeDocument->setModified();
2298             m_activeDocument->setDocumentProperty("proxyparams", w->proxyParams());
2299             if (m_activeDocument->clipManager()->clipsCount() > 0 && KMessageBox::questionYesNo(this, i18n("You have changed the proxy parameters. Do you want to recreate all proxy clips for this project?")) == KMessageBox::Yes) {
2300                 //TODO: rebuild all proxies
2301                 //m_projectList->rebuildProxies();
2302             }
2303         }
2304         if (m_activeDocument->getDocumentProperty("proxyextension") != w->proxyExtension()) {
2305             m_activeDocument->setModified();
2306             m_activeDocument->setDocumentProperty("proxyextension", w->proxyExtension());
2307         }
2308         if (m_activeDocument->getDocumentProperty("generateproxy") != QString::number((int) w->generateProxy())) {
2309             m_activeDocument->setModified();
2310             m_activeDocument->setDocumentProperty("generateproxy", QString::number((int) w->generateProxy()));
2311         }
2312         if (m_activeDocument->getDocumentProperty("proxyminsize") != QString::number(w->proxyMinSize())) {
2313             m_activeDocument->setModified();
2314             m_activeDocument->setDocumentProperty("proxyminsize", QString::number(w->proxyMinSize()));
2315         }
2316         if (m_activeDocument->getDocumentProperty("generateimageproxy") != QString::number((int) w->generateImageProxy())) {
2317             m_activeDocument->setModified();
2318             m_activeDocument->setDocumentProperty("generateimageproxy", QString::number((int) w->generateImageProxy()));
2319         }
2320         if (m_activeDocument->getDocumentProperty("proxyimageminsize") != QString::number(w->proxyImageMinSize())) {
2321             m_activeDocument->setModified();
2322             m_activeDocument->setDocumentProperty("proxyimageminsize", QString::number(w->proxyImageMinSize()));
2323         }
2324         if (QString::number((int) w->useProxy()) != m_activeDocument->getDocumentProperty("enableproxy")) {
2325             m_activeDocument->setDocumentProperty("enableproxy", QString::number((int) w->useProxy()));
2326             m_activeDocument->setModified();
2327             slotUpdateProxySettings();
2328         }
2329         m_activeDocument->setMetadata(w->metadata());
2330     }
2331     delete w;
2332 }
2333
2334 void MainWindow::slotDisableProxies()
2335 {
2336     m_activeDocument->setDocumentProperty("enableproxy", QString::number((int) false));
2337     m_activeDocument->setModified();
2338     slotUpdateProxySettings();
2339 }
2340
2341 void MainWindow::slotUpdateProjectProfile(const QString &profile)
2342 {
2343     // Recreate the stopmotion widget if profile changes
2344     if (m_stopmotion) {
2345         delete m_stopmotion;
2346         m_stopmotion = NULL;
2347     }
2348
2349     // Deselect current effect / transition
2350     m_effectStack->slotClipItemSelected(NULL);
2351     m_transitionConfig->slotTransitionItemSelected(NULL, 0, QPoint(), false);
2352     m_clipMonitor->slotSetClipProducer(NULL);
2353     bool updateFps = m_activeDocument->setProfilePath(profile);
2354     KdenliveSettings::setCurrent_profile(profile);
2355     KdenliveSettings::setProject_fps(m_activeDocument->fps());
2356     setCaption(m_activeDocument->description(), m_activeDocument->isModified());
2357
2358     m_activeDocument->clipManager()->clearUnusedProducers();
2359     m_monitorManager->resetProfiles(m_activeDocument->timecode());
2360     m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
2361     m_effectStack->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode());
2362     m_projectList->updateProjectFormat(m_activeDocument->timecode());
2363     if (m_renderWidget) m_renderWidget->setProfile(m_activeDocument->mltProfile());
2364     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
2365     if (updateFps) m_activeTimeline->updateProjectFps();
2366     m_activeDocument->clipManager()->clearCache();
2367     m_activeTimeline->updateProfile();
2368     m_activeDocument->setModified(true);
2369     m_commandStack->activeStack()->clear();
2370     //Update the mouse position display so it will display in DF/NDF format by default based on the project setting.
2371     slotUpdateMousePosition(0);
2372     // We need to desactivate & reactivate monitors to get a refresh
2373     //m_monitorManager->switchMonitors();
2374 }
2375
2376
2377 void MainWindow::slotRenderProject()
2378 {
2379     if (!m_renderWidget) {
2380         QString projectfolder = m_activeDocument ? m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash) : KdenliveSettings::defaultprojectfolder();
2381         MltVideoProfile profile;
2382         if (m_activeDocument) profile = m_activeDocument->mltProfile();
2383         m_renderWidget = new RenderWidget(projectfolder, m_projectList->useProxy(), profile, this);
2384         connect(m_renderWidget, SIGNAL(shutdown()), this, SLOT(slotShutdown()));
2385         connect(m_renderWidget, SIGNAL(selectedRenderProfile(QMap <QString, QString>)), this, SLOT(slotSetDocumentRenderProfile(QMap <QString, QString>)));
2386         connect(m_renderWidget, SIGNAL(prepareRenderingData(bool, bool, const QString&)), this, SLOT(slotPrepareRendering(bool, bool, const QString&)));
2387         connect(m_renderWidget, SIGNAL(abortProcess(const QString &)), this, SIGNAL(abortRenderJob(const QString &)));
2388         connect(m_renderWidget, SIGNAL(openDvdWizard(const QString &, const QString &)), this, SLOT(slotDvdWizard(const QString &, const QString &)));
2389         if (m_activeDocument) {
2390             m_renderWidget->setProfile(m_activeDocument->mltProfile());
2391             m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
2392             m_renderWidget->setDocumentPath(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
2393             m_renderWidget->setRenderProfile(m_activeDocument->getRenderProperties());
2394         }
2395     }
2396     slotCheckRenderStatus();
2397     m_renderWidget->show();
2398     m_renderWidget->showNormal();
2399
2400     // What are the following lines supposed to do?
2401     //m_activeTimeline->tracksNumber();
2402     //m_renderWidget->enableAudio(false);
2403     //m_renderWidget->export_audio;
2404 }
2405
2406 void MainWindow::slotCheckRenderStatus()
2407 {
2408     // Make sure there are no missing clips
2409     if (m_renderWidget)
2410         m_renderWidget->missingClips(m_projectList->hasMissingClips());
2411 }
2412
2413 void MainWindow::setRenderingProgress(const QString &url, int progress)
2414 {
2415     if (m_renderWidget)
2416         m_renderWidget->setRenderJob(url, progress);
2417 }
2418
2419 void MainWindow::setRenderingFinished(const QString &url, int status, const QString &error)
2420 {
2421     if (m_renderWidget)
2422         m_renderWidget->setRenderStatus(url, status, error);
2423 }
2424
2425 void MainWindow::slotCleanProject()
2426 {
2427     if (KMessageBox::warningContinueCancel(this, i18n("This will remove all unused clips from your project."), i18n("Clean up project")) == KMessageBox::Cancel) return;
2428     m_projectList->cleanup();
2429 }
2430
2431 void MainWindow::slotUpdateMousePosition(int pos)
2432 {
2433     if (m_activeDocument)
2434         switch (m_timecodeFormat->currentIndex()) {
2435         case 0:
2436             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
2437             break;
2438         default:
2439             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
2440         }
2441 }
2442
2443 void MainWindow::slotUpdateDocumentState(bool modified)
2444 {
2445     if (!m_activeDocument) return;
2446     setCaption(m_activeDocument->description(), modified);
2447     m_saveAction->setEnabled(modified);
2448     if (modified) {
2449         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
2450         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
2451     } else {
2452         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
2453         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
2454     }
2455 }
2456
2457 void MainWindow::connectDocumentInfo(KdenliveDoc *doc)
2458 {
2459     if (m_activeDocument) {
2460         if (m_activeDocument == doc) return;
2461         disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
2462     }
2463     connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
2464 }
2465
2466 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc)   //changed
2467 {
2468     //m_projectMonitor->stop();
2469     m_closeAction->setEnabled(m_timelineArea->count() > 1);
2470     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
2471     if (m_activeDocument) {
2472         if (m_activeDocument == doc) return;
2473         if (m_activeTimeline) {
2474             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
2475             disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeTimeline, SLOT(slotSetZone(QPoint)));
2476             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
2477             disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeDocument, SLOT(setModified()));
2478             disconnect(m_notesWidget, SIGNAL(textChanged()), m_activeDocument, SLOT(setModified()));
2479             disconnect(m_clipMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeDocument, SLOT(setModified()));
2480             disconnect(m_projectList, SIGNAL(projectModified()), m_activeDocument, SLOT(setModified()));
2481
2482             disconnect(m_projectMonitor->render, SIGNAL(refreshDocumentProducers(bool, bool)), m_activeDocument, SLOT(checkProjectClips(bool, bool)));
2483
2484             disconnect(m_activeDocument, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
2485             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
2486             disconnect(m_activeDocument, SIGNAL(resetProjectList()), m_projectList, SLOT(slotResetProjectList()));
2487             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(const QString &)), this, SLOT(slotDeleteClip(const QString &)));
2488             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
2489             disconnect(m_activeDocument, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
2490             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, bool)), this, SLOT(slotTimelineClipSelected(ClipItem*, bool)));
2491             disconnect(m_activeTimeline->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), m_transitionConfig, SLOT(slotTransitionItemSelected(Transition*, int, QPoint, bool)));
2492             disconnect(m_activeTimeline->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), this, SLOT(slotActivateTransitionView(Transition *)));
2493             disconnect(m_activeTimeline->projectView(), SIGNAL(playMonitor()), m_projectMonitor, SLOT(slotPlay()));
2494             disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
2495             disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, QPoint, bool, const int)), m_clipMonitor, SLOT(slotSetClipProducer(DocClipBase *, QPoint, bool, const int)));
2496             disconnect(m_projectList, SIGNAL(gotFilterJobResults(const QString &, int, int, const QString &, stringMap)), m_activeTimeline->projectView(), SLOT(slotGotFilterJobResults(const QString &, int, int, const QString &, stringMap)));
2497
2498             disconnect(m_activeTimeline, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(slotActivateMonitor()));
2499             disconnect(m_activeTimeline, SIGNAL(configTrack(int)), this, SLOT(slotConfigTrack(int)));
2500             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
2501             disconnect(m_effectStack, SIGNAL(updateEffect(ClipItem*, int, QDomElement, QDomElement, int,bool)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, int, QDomElement, QDomElement, int,bool)));
2502             disconnect(m_effectStack, SIGNAL(removeEffect(ClipItem*, int, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, int, QDomElement)));
2503             disconnect(m_effectStack, SIGNAL(addEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotAddEffect(ClipItem*, QDomElement)));
2504             disconnect(m_effectStack, SIGNAL(changeEffectState(ClipItem*, int, QList <int>, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, QList <int>, bool)));
2505             disconnect(m_effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, QList<int>, int)), m_activeTimeline->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, QList <int>, int)));
2506             disconnect(m_effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
2507             disconnect(m_effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
2508             disconnect(m_effectStack, SIGNAL(displayMessage(const QString&, int)), this, SLOT(slotGotProgressInfo(const QString&, int)));
2509             disconnect(m_transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), m_activeTimeline->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
2510             disconnect(m_transitionConfig, SIGNAL(seekTimeline(int)), m_activeTimeline->projectView() , SLOT(setCursorPos(int)));
2511             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(slotActivateMonitor()));
2512             disconnect(m_activeTimeline, SIGNAL(zoneMoved(int, int)), this, SLOT(slotZoneMoved(int, int)));
2513             disconnect(m_projectList, SIGNAL(loadingIsOver()), m_activeTimeline->projectView(), SLOT(slotUpdateAllThumbs()));
2514             disconnect(m_projectList, SIGNAL(refreshClip(const QString &)), m_activeTimeline->projectView(), SLOT(slotRefreshThumbs(const QString &)));
2515             m_effectStack->clear();
2516         }
2517         //m_activeDocument->setRenderer(NULL);
2518         m_clipMonitor->stop();
2519     }
2520     KdenliveSettings::setCurrent_profile(doc->profilePath());
2521     KdenliveSettings::setProject_fps(doc->fps());
2522     m_monitorManager->resetProfiles(doc->timecode());
2523     m_clipMonitorDock->raise();
2524     m_projectList->setDocument(doc);
2525     m_transitionConfig->updateProjectFormat(doc->mltProfile(), doc->timecode(), doc->tracksList());
2526     m_effectStack->updateProjectFormat(doc->mltProfile(), doc->timecode());
2527     connect(m_projectList, SIGNAL(refreshClip(const QString &, bool)), trackView->projectView(), SLOT(slotRefreshThumbs(const QString &, bool)));
2528
2529     connect(m_projectList, SIGNAL(projectModified()), doc, SLOT(setModified()));
2530     connect(m_projectList, SIGNAL(clipNameChanged(const QString, const QString)), trackView->projectView(), SLOT(clipNameChanged(const QString, const QString)));
2531
2532     //connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
2533     connect(trackView, SIGNAL(configTrack(int)), this, SLOT(slotConfigTrack(int)));
2534     connect(trackView, SIGNAL(updateTracksInfo()), this, SLOT(slotUpdateTrackInfo()));
2535     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
2536     connect(trackView->projectView(), SIGNAL(forceClipProcessing(const QString &)), m_projectList, SLOT(slotForceProcessing(const QString &)));
2537     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
2538     connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), trackView, SLOT(slotSetZone(QPoint)));
2539     connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), doc, SLOT(setModified()));
2540     connect(m_clipMonitor, SIGNAL(zoneUpdated(QPoint)), doc, SLOT(setModified()));
2541     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
2542     connect(m_projectMonitor->render, SIGNAL(refreshDocumentProducers(bool, bool)), doc, SLOT(checkProjectClips(bool, bool)));
2543
2544     connect(doc, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
2545     connect(doc, SIGNAL(resetProjectList()), m_projectList, SLOT(slotResetProjectList()));
2546     connect(doc, SIGNAL(signalDeleteProjectClip(const QString &)), this, SLOT(slotDeleteClip(const QString &)));
2547     connect(doc, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
2548     connect(doc, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
2549
2550     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
2551     connect(doc, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
2552     connect(doc, SIGNAL(saveTimelinePreview(const QString &)), trackView, SLOT(slotSaveTimelinePreview(const QString)));
2553
2554     connect(m_notesWidget, SIGNAL(textChanged()), doc, SLOT(setModified()));
2555
2556     connect(trackView->projectView(), SIGNAL(updateClipMarkers(DocClipBase *)), this, SLOT(slotUpdateClipMarkers(DocClipBase*)));
2557     connect(trackView, SIGNAL(showTrackEffects(int, TrackInfo)), this, SLOT(slotTrackSelected(int, TrackInfo)));
2558
2559     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, bool)), this, SLOT(slotTimelineClipSelected(ClipItem*, bool)));
2560     connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), m_transitionConfig, SLOT(slotTransitionItemSelected(Transition*, int, QPoint, bool)));
2561     connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), this, SLOT(slotActivateTransitionView(Transition *)));
2562     m_zoomSlider->setValue(doc->zoom().x());
2563     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
2564     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
2565     connect(trackView, SIGNAL(setZoom(int)), this, SLOT(slotSetZoom(int)));
2566     connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
2567
2568     connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, QPoint, bool, const int)), m_clipMonitor, SLOT(slotSetClipProducer(DocClipBase *, QPoint, bool, const int)));
2569     connect(trackView->projectView(), SIGNAL(playMonitor()), m_projectMonitor, SLOT(slotPlay()));
2570
2571     connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), m_projectMonitor, SLOT(slotSetSelectedClip(Transition*)));
2572
2573     connect(m_projectList, SIGNAL(gotFilterJobResults(const QString &, int, int, const QString &, stringMap)), trackView->projectView(), SLOT(slotGotFilterJobResults(const QString &, int, int, const QString &, stringMap)));
2574
2575     // Effect stack signals
2576     connect(m_effectStack, SIGNAL(updateEffect(ClipItem*, int, QDomElement, QDomElement, int,bool)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, int, QDomElement, QDomElement, int,bool)));
2577     connect(m_effectStack, SIGNAL(updateClipRegion(ClipItem*, int, QString)), trackView->projectView(), SLOT(slotUpdateClipRegion(ClipItem*, int, QString)));
2578     connect(m_effectStack, SIGNAL(removeEffect(ClipItem*, int, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, int, QDomElement)));
2579     connect(m_effectStack, SIGNAL(addEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotAddEffect(ClipItem*, QDomElement)));
2580     connect(m_effectStack, SIGNAL(changeEffectState(ClipItem*, int, QList <int>, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, QList <int>, bool)));
2581     connect(m_effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, QList <int>, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, QList <int>, int)));
2582     connect(m_effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
2583     connect(m_effectStack, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
2584     connect(m_effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
2585     connect(m_effectStack, SIGNAL(displayMessage(const QString&, int)), this, SLOT(slotGotProgressInfo(const QString&, int)));
2586     
2587     // Transition config signals
2588     connect(m_transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
2589     connect(m_transitionConfig, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
2590
2591     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(slotActivateMonitor()));
2592     connect(trackView, SIGNAL(zoneMoved(int, int)), this, SLOT(slotZoneMoved(int, int)));
2593     connect(m_projectList, SIGNAL(loadingIsOver()), trackView->projectView(), SLOT(slotUpdateAllThumbs()));
2594     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu, m_clipTypeGroup, static_cast<QMenu*>(factory()->container("marker_menu", this)));
2595     m_activeTimeline = trackView;
2596     if (m_renderWidget) {
2597         slotCheckRenderStatus();
2598         m_renderWidget->setProfile(doc->mltProfile());
2599         m_renderWidget->setGuides(doc->guidesXml(), doc->projectDuration());
2600         m_renderWidget->setDocumentPath(doc->projectFolder().path(KUrl::AddTrailingSlash));
2601         m_renderWidget->setRenderProfile(doc->getRenderProperties());
2602     }
2603     //doc->setRenderer(m_projectMonitor->render);
2604     m_commandStack->setActiveStack(doc->commandStack());
2605     KdenliveSettings::setProject_display_ratio(doc->dar());
2606     //doc->clipManager()->checkAudioThumbs();
2607
2608     //m_overView->setScene(trackView->projectScene());
2609     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
2610     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
2611
2612     setCaption(doc->description(), doc->isModified());
2613     m_saveAction->setEnabled(doc->isModified());
2614     m_normalEditTool->setChecked(true);
2615     m_activeDocument = doc;
2616     m_activeTimeline->updateProjectFps();
2617     m_activeDocument->checkProjectClips();
2618 #ifndef Q_WS_MAC
2619     m_recMonitor->slotUpdateCaptureFolder(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
2620 #endif
2621     //Update the mouse position display so it will display in DF/NDF format by default based on the project setting.
2622     slotUpdateMousePosition(0);
2623     m_monitorManager->activateMonitor(Kdenlive::clipMonitor);
2624     // set tool to select tool
2625     m_buttonSelectTool->setChecked(true);
2626 }
2627
2628 void MainWindow::slotZoneMoved(int start, int end)
2629 {
2630     m_activeDocument->setZone(start, end);
2631     m_projectMonitor->slotZoneMoved(start, end);
2632 }
2633
2634 void MainWindow::slotGuidesUpdated()
2635 {
2636     if (m_renderWidget)
2637         m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
2638 }
2639
2640 void MainWindow::slotEditKeys()
2641 {
2642     KShortcutsDialog dialog(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, this);
2643     dialog.addCollection(actionCollection(), i18nc("general keyboard shortcuts", "General"));
2644     dialog.addCollection(m_effectsActionCollection, i18nc("effects and transitions keyboard shortcuts", "Effects & Transitions"));
2645     dialog.addCollection(m_tracksActionCollection, i18nc("timeline track keyboard shortcuts", "Timeline and Tracks"));
2646     dialog.configure();
2647 }
2648
2649 void MainWindow::slotPreferences(int page, int option)
2650 {
2651     /*
2652      * An instance of your dialog could be already created and could be
2653      * cached, in which case you want to display the cached dialog
2654      * instead of creating another one
2655      */
2656     if (m_stopmotion) m_stopmotion->slotLive(false);
2657     if (KConfigDialog::showDialog("settings")) {
2658         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
2659         if (page != -1) d->showPage(page, option);
2660         return;
2661     }
2662
2663     // KConfigDialog didn't find an instance of this dialog, so lets
2664     // create it :
2665
2666     // Get the mappable actions in localized form
2667     QMap<QString, QString> actions;
2668     KActionCollection* collection = actionCollection();
2669     foreach (const QString& action_name, m_action_names) {
2670         actions[collection->action(action_name)->text()] = action_name;
2671     }
2672
2673     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(actions, this);
2674     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
2675     connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(slotResetProfiles()));
2676 #ifndef Q_WS_MAC
2677     connect(dialog, SIGNAL(updateCaptureFolder()), this, SLOT(slotUpdateCaptureFolder()));
2678 #endif
2679     dialog->show();
2680     if (page != -1) dialog->showPage(page, option);
2681 }
2682
2683 void MainWindow::slotUpdateCaptureFolder()
2684 {
2685
2686 #ifndef Q_WS_MAC
2687     if (m_activeDocument) m_recMonitor->slotUpdateCaptureFolder(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
2688     else m_recMonitor->slotUpdateCaptureFolder(KdenliveSettings::defaultprojectfolder());
2689 #endif
2690 }
2691
2692 void MainWindow::updateConfiguration()
2693 {
2694     //TODO: we should apply settings to all projects, not only the current one
2695     if (m_activeTimeline) {
2696         m_activeTimeline->refresh();
2697         m_activeTimeline->projectView()->checkAutoScroll();
2698         m_activeTimeline->checkTrackHeight();
2699         if (m_activeDocument)
2700             m_activeDocument->clipManager()->checkAudioThumbs();
2701     }
2702     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
2703     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
2704     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
2705     m_buttonAutomaticSplitAudio->setChecked(KdenliveSettings::splitaudio());
2706
2707     // Update list of transcoding profiles
2708     loadTranscoders();
2709     loadStabilize();
2710 #ifdef USE_JOGSHUTTLE
2711     activateShuttleDevice();
2712 #endif
2713
2714 }
2715
2716 void MainWindow::slotSwitchSplitAudio()
2717 {
2718     KdenliveSettings::setSplitaudio(!KdenliveSettings::splitaudio());
2719     m_buttonAutomaticSplitAudio->setChecked(KdenliveSettings::splitaudio());
2720 }
2721
2722 void MainWindow::slotSwitchVideoThumbs()
2723 {
2724     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
2725     if (m_activeTimeline)
2726         m_activeTimeline->projectView()->slotUpdateAllThumbs();
2727     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
2728 }
2729
2730 void MainWindow::slotSwitchAudioThumbs()
2731 {
2732     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
2733     if (m_activeTimeline) {
2734         m_activeTimeline->refresh();
2735         m_activeTimeline->projectView()->checkAutoScroll();
2736         if (m_activeDocument)
2737             m_activeDocument->clipManager()->checkAudioThumbs();
2738     }
2739     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
2740 }
2741
2742 void MainWindow::slotSwitchMarkersComments()
2743 {
2744     KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
2745     if (m_activeTimeline)
2746         m_activeTimeline->refresh();
2747     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
2748 }
2749
2750 void MainWindow::slotSwitchSnap()
2751 {
2752     KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
2753     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
2754 }
2755
2756
2757 void MainWindow::slotDeleteItem()
2758 {
2759     if (QApplication::focusWidget() &&
2760             QApplication::focusWidget()->parentWidget() &&
2761             QApplication::focusWidget()->parentWidget()->parentWidget() &&
2762             QApplication::focusWidget()->parentWidget()->parentWidget() == m_projectListDock) {
2763         m_projectList->slotRemoveClip();
2764
2765     } else {
2766         QWidget *widget = QApplication::focusWidget();
2767         while (widget) {
2768             if (widget == m_effectStackDock) {
2769                 m_effectStack->deleteCurrentEffect();
2770                 return;
2771             }
2772             widget = widget->parentWidget();
2773         }
2774
2775         // effect stack has no focus
2776         if (m_activeTimeline)
2777             m_activeTimeline->projectView()->deleteSelectedClips();
2778     }
2779 }
2780
2781 void MainWindow::slotUpdateClipMarkers(DocClipBase *clip)
2782 {
2783     if (m_clipMonitor->isActive())
2784         m_clipMonitor->checkOverlay();
2785     m_clipMonitor->updateMarkers(clip);
2786 }
2787
2788 void MainWindow::slotAddClipMarker()
2789 {
2790     DocClipBase *clip = NULL;
2791     GenTime pos;
2792     if (m_projectMonitor->isActive()) {
2793         if (m_activeTimeline) {
2794             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2795             if (item) {
2796                 pos = GenTime((int)((m_projectMonitor->position() - item->startPos() + item->cropStart()).frames(m_activeDocument->fps()) * item->speed() + 0.5), m_activeDocument->fps());
2797                 clip = item->baseClip();
2798             }
2799         }
2800     } else {
2801         clip = m_clipMonitor->activeClip();
2802         pos = m_clipMonitor->position();
2803     }
2804     if (!clip) {
2805         m_messageLabel->setMessage(i18n("Cannot find clip to add marker"), ErrorMessage);
2806         return;
2807     }
2808     QString id = clip->getId();
2809     CommentedTime marker(pos, i18n("Marker"));
2810     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Add Marker"), this);
2811     if (d.exec() == QDialog::Accepted)
2812         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
2813 }
2814
2815 void MainWindow::slotDeleteClipMarker()
2816 {
2817     DocClipBase *clip = NULL;
2818     GenTime pos;
2819     if (m_projectMonitor->isActive()) {
2820         if (m_activeTimeline) {
2821             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2822             if (item) {
2823                 pos = (m_projectMonitor->position() - item->startPos() + item->cropStart()) / item->speed();
2824                 clip = item->baseClip();
2825             }
2826         }
2827     } else {
2828         clip = m_clipMonitor->activeClip();
2829         pos = m_clipMonitor->position();
2830     }
2831     if (!clip) {
2832         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2833         return;
2834     }
2835
2836     QString id = clip->getId();
2837     QString comment = clip->markerComment(pos);
2838     if (comment.isEmpty()) {
2839         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
2840         return;
2841     }
2842     m_activeTimeline->projectView()->slotDeleteClipMarker(comment, id, pos);
2843 }
2844
2845 void MainWindow::slotDeleteAllClipMarkers()
2846 {
2847     DocClipBase *clip = NULL;
2848     if (m_projectMonitor->isActive()) {
2849         if (m_activeTimeline) {
2850             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2851             if (item) {
2852                 clip = item->baseClip();
2853             }
2854         }
2855     } else {
2856         clip = m_clipMonitor->activeClip();
2857     }
2858     if (!clip) {
2859         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2860         return;
2861     }
2862     m_activeTimeline->projectView()->slotDeleteAllClipMarkers(clip->getId());
2863 }
2864
2865 void MainWindow::slotEditClipMarker()
2866 {
2867     DocClipBase *clip = NULL;
2868     GenTime pos;
2869     if (m_projectMonitor->isActive()) {
2870         if (m_activeTimeline) {
2871             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2872             if (item) {
2873                 pos = (m_projectMonitor->position() - item->startPos() + item->cropStart()) / item->speed();
2874                 clip = item->baseClip();
2875             }
2876         }
2877     } else {
2878         clip = m_clipMonitor->activeClip();
2879         pos = m_clipMonitor->position();
2880     }
2881     if (!clip) {
2882         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2883         return;
2884     }
2885
2886     QString id = clip->getId();
2887     QString oldcomment = clip->markerComment(pos);
2888     if (oldcomment.isEmpty()) {
2889         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
2890         return;
2891     }
2892
2893     CommentedTime marker(pos, oldcomment);
2894     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Edit Marker"), this);
2895     if (d.exec() == QDialog::Accepted) {
2896         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
2897         if (d.newMarker().time() != pos) {
2898             // remove old marker
2899             m_activeTimeline->projectView()->slotAddClipMarker(id, pos, QString());
2900         }
2901     }
2902 }
2903
2904 void MainWindow::slotAddMarkerGuideQuickly()
2905 {
2906     if (!m_activeTimeline || !m_activeDocument)
2907         return;
2908
2909     if (m_clipMonitor->isActive()) {
2910         DocClipBase *clip = m_clipMonitor->activeClip();
2911         GenTime pos = m_clipMonitor->position();
2912
2913         if (!clip) {
2914             m_messageLabel->setMessage(i18n("Cannot find clip to add marker"), ErrorMessage);
2915             return;
2916         }
2917
2918         m_activeTimeline->projectView()->slotAddClipMarker(clip->getId(), pos, m_activeDocument->timecode().getDisplayTimecode(pos, false));
2919     } else {
2920         m_activeTimeline->projectView()->slotAddGuide(false);
2921     }
2922 }
2923
2924 void MainWindow::slotAddGuide()
2925 {
2926     if (m_activeTimeline)
2927         m_activeTimeline->projectView()->slotAddGuide();
2928 }
2929
2930 void MainWindow::slotInsertSpace()
2931 {
2932     if (m_activeTimeline)
2933         m_activeTimeline->projectView()->slotInsertSpace();
2934 }
2935
2936 void MainWindow::slotRemoveSpace()
2937 {
2938     if (m_activeTimeline)
2939         m_activeTimeline->projectView()->slotRemoveSpace();
2940 }
2941
2942 void MainWindow::slotInsertTrack(int ix)
2943 {
2944     m_projectMonitor->slotActivateMonitor();
2945     if (m_activeTimeline) {
2946         if (ix == -1) ix = m_activeTimeline->projectView()->selectedTrack();
2947         m_activeTimeline->projectView()->slotInsertTrack(ix);
2948     }
2949     if (m_activeDocument)
2950         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
2951 }
2952
2953 void MainWindow::slotDeleteTrack(int ix)
2954 {
2955     m_projectMonitor->slotActivateMonitor();
2956     if (m_activeTimeline) {
2957         if (ix == -1) ix = m_activeTimeline->projectView()->selectedTrack();
2958         m_activeTimeline->projectView()->slotDeleteTrack(ix);
2959     }
2960     if (m_activeDocument)
2961         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
2962 }
2963
2964 void MainWindow::slotConfigTrack(int ix)
2965 {
2966     m_projectMonitor->slotActivateMonitor();
2967     if (m_activeTimeline)
2968         m_activeTimeline->projectView()->slotConfigTracks(ix);
2969     if (m_activeDocument)
2970         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
2971 }
2972
2973 void MainWindow::slotSelectTrack()
2974 {
2975     m_projectMonitor->slotActivateMonitor();
2976     if (m_activeTimeline) {
2977         m_activeTimeline->projectView()->slotSelectClipsInTrack();
2978     }
2979 }
2980
2981 void MainWindow::slotSelectAllTracks()
2982 {
2983     m_projectMonitor->slotActivateMonitor();
2984     if (m_activeTimeline)
2985         m_activeTimeline->projectView()->slotSelectAllClips();
2986 }
2987
2988 void MainWindow::slotEditGuide()
2989 {
2990     if (m_activeTimeline)
2991         m_activeTimeline->projectView()->slotEditGuide();
2992 }
2993
2994 void MainWindow::slotDeleteGuide()
2995 {
2996     if (m_activeTimeline)
2997         m_activeTimeline->projectView()->slotDeleteGuide();
2998 }
2999
3000 void MainWindow::slotDeleteAllGuides()
3001 {
3002     if (m_activeTimeline)
3003         m_activeTimeline->projectView()->slotDeleteAllGuides();
3004 }
3005
3006 void MainWindow::slotCutTimelineClip()
3007 {
3008     if (m_activeTimeline)
3009         m_activeTimeline->projectView()->cutSelectedClips();
3010 }
3011
3012 void MainWindow::slotInsertClipOverwrite()
3013 {
3014     if (m_activeTimeline) {
3015         QStringList data = m_clipMonitor->getZoneInfo();
3016         m_activeTimeline->projectView()->insertZoneOverwrite(data, m_activeTimeline->inPoint());
3017     }
3018 }
3019
3020 void MainWindow::slotSelectTimelineClip()
3021 {
3022     if (m_activeTimeline)
3023         m_activeTimeline->projectView()->selectClip(true);
3024 }
3025
3026 void MainWindow::slotSelectTimelineTransition()
3027 {
3028     if (m_activeTimeline)
3029         m_activeTimeline->projectView()->selectTransition(true);
3030 }
3031
3032 void MainWindow::slotDeselectTimelineClip()
3033 {
3034     if (m_activeTimeline)
3035         m_activeTimeline->projectView()->selectClip(false, true);
3036 }
3037
3038 void MainWindow::slotDeselectTimelineTransition()
3039 {
3040     if (m_activeTimeline)
3041         m_activeTimeline->projectView()->selectTransition(false, true);
3042 }
3043
3044 void MainWindow::slotSelectAddTimelineClip()
3045 {
3046     if (m_activeTimeline)
3047         m_activeTimeline->projectView()->selectClip(true, true);
3048 }
3049
3050 void MainWindow::slotSelectAddTimelineTransition()
3051 {
3052     if (m_activeTimeline)
3053         m_activeTimeline->projectView()->selectTransition(true, true);
3054 }
3055
3056 void MainWindow::slotGroupClips()
3057 {
3058     if (m_activeTimeline)
3059         m_activeTimeline->projectView()->groupClips();
3060 }
3061
3062 void MainWindow::slotUnGroupClips()
3063 {
3064     if (m_activeTimeline)
3065         m_activeTimeline->projectView()->groupClips(false);
3066 }
3067
3068 void MainWindow::slotEditItemDuration()
3069 {
3070     if (m_activeTimeline)
3071         m_activeTimeline->projectView()->editItemDuration();
3072 }
3073
3074 void MainWindow::slotAddProjectClip(KUrl url, const QString &comment)
3075 {
3076     if (m_activeDocument)
3077         m_activeDocument->slotAddClipFile(url, QString(), QString(), comment);
3078 }
3079
3080 void MainWindow::slotAddProjectClipList(KUrl::List urls)
3081 {
3082     if (m_activeDocument)
3083         m_activeDocument->slotAddClipList(urls, QString());
3084 }
3085
3086 void MainWindow::slotAddTransition(QAction *result)
3087 {
3088     if (!result) return;
3089     QStringList info = result->data().toStringList();
3090     if (info.isEmpty()) return;
3091     QDomElement transition = transitions.getEffectByTag(info.at(1), info.at(2));
3092     if (m_activeTimeline && !transition.isNull()) {
3093         m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(transition.cloneNode().toElement());
3094     }
3095 }
3096
3097 void MainWindow::slotAddVideoEffect(QAction *result)
3098 {
3099     if (!result) return;
3100     const int EFFECT_VIDEO = 1;
3101     const int EFFECT_AUDIO = 2;
3102     QStringList info = result->data().toStringList();
3103
3104     if (info.isEmpty() || info.size() < 3) return;
3105     QDomElement effect ;
3106     if (info.last() == QString::number((int) EFFECT_VIDEO))
3107             effect = videoEffects.getEffectByTag(info.at(0), info.at(1));
3108     else if (info.last() == QString::number((int) EFFECT_AUDIO))
3109             effect = audioEffects.getEffectByTag(info.at(0), info.at(1));
3110     else
3111             effect = customEffects.getEffectByTag(info.at(0), info.at(1));
3112     if (!effect.isNull()) slotAddEffect(effect);
3113     else m_messageLabel->setMessage(i18n("Cannot find effect %1 / %2").arg(info.at(0)).arg(info.at(1)), ErrorMessage);
3114 }
3115
3116
3117 void MainWindow::slotZoomIn()
3118 {
3119     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
3120     slotShowZoomSliderToolTip();
3121 }
3122
3123 void MainWindow::slotZoomOut()
3124 {
3125     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
3126     slotShowZoomSliderToolTip();
3127 }
3128
3129 void MainWindow::slotFitZoom()
3130 {
3131     if (m_activeTimeline)
3132         m_zoomSlider->setValue(m_activeTimeline->fitZoom());
3133 }
3134
3135 void MainWindow::slotSetZoom(int value)
3136 {
3137     value = qMax(m_zoomSlider->minimum(), value);
3138     value = qMin(m_zoomSlider->maximum(), value);
3139
3140     if (m_activeTimeline)
3141         m_activeTimeline->slotChangeZoom(value);
3142
3143     m_zoomOut->setEnabled(value < m_zoomSlider->maximum());
3144     m_zoomIn->setEnabled(value > m_zoomSlider->minimum());
3145     slotUpdateZoomSliderToolTip(value);
3146
3147     m_zoomSlider->blockSignals(true);
3148     m_zoomSlider->setValue(value);
3149     m_zoomSlider->blockSignals(false);
3150 }
3151
3152 void MainWindow::slotShowZoomSliderToolTip(int zoomlevel)
3153 {
3154     if (zoomlevel != -1)
3155         slotUpdateZoomSliderToolTip(zoomlevel);
3156
3157     QPoint global = m_zoomSlider->rect().topLeft();
3158     global.ry() += m_zoomSlider->height() / 2;
3159     QHelpEvent toolTipEvent(QEvent::ToolTip, QPoint(0, 0), m_zoomSlider->mapToGlobal(global));
3160     QApplication::sendEvent(m_zoomSlider, &toolTipEvent);
3161 }
3162
3163 void MainWindow::slotUpdateZoomSliderToolTip(int zoomlevel)
3164 {
3165     m_zoomSlider->setToolTip(i18n("Zoom Level: %1/13", (13 - zoomlevel)));
3166 }
3167
3168 void MainWindow::slotGotProgressInfo(const QString &message, int progress)
3169 {
3170     m_statusProgressBar->setValue(progress);
3171     if (progress >= 0) {
3172         if (!message.isEmpty())
3173             m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
3174         m_statusProgressBar->setVisible(true);
3175     } else if (progress == -2) {
3176         if (!message.isEmpty())
3177             m_messageLabel->setMessage(message, ErrorMessage);
3178         m_statusProgressBar->setVisible(false);
3179     } else {
3180         m_messageLabel->setMessage(QString(), DefaultMessage);
3181         m_statusProgressBar->setVisible(false);
3182     }
3183 }
3184
3185 void MainWindow::slotShowClipProperties(DocClipBase *clip)
3186 {
3187     if (clip->clipType() == TEXT) {
3188         QString titlepath = m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
3189         if (!clip->getProperty("resource").isEmpty() && clip->getProperty("xmldata").isEmpty()) {
3190             // template text clip
3191
3192             // Get the list of existing templates
3193             QStringList filter;
3194             filter << "*.kdenlivetitle";
3195             QStringList templateFiles = QDir(titlepath).entryList(filter, QDir::Files);
3196
3197             QDialog *dia = new QDialog(this);
3198             Ui::TemplateClip_UI dia_ui;
3199             dia_ui.setupUi(dia);
3200             int ix = -1;
3201             const QString templatePath = clip->getProperty("resource");
3202             for (int i = 0; i < templateFiles.size(); ++i) {
3203                 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), titlepath + templateFiles.at(i));
3204                 if (templatePath == KUrl(titlepath + templateFiles.at(i)).path()) ix = i;
3205             }
3206             if (ix != -1) dia_ui.template_list->comboBox()->setCurrentIndex(ix);
3207             else dia_ui.template_list->comboBox()->insertItem(0, templatePath);
3208             dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
3209             //warning: setting base directory doesn't work??
3210             KUrl startDir(titlepath);
3211             dia_ui.template_list->fileDialog()->setUrl(startDir);
3212             dia_ui.description->setText(clip->getProperty("description"));
3213             if (dia->exec() == QDialog::Accepted) {
3214                 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
3215                 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
3216
3217                 QMap <QString, QString> newprops;
3218
3219                 if (KUrl(textTemplate).path() != templatePath) {
3220                     // The template was changed
3221                     newprops.insert("resource", textTemplate);
3222                 }
3223
3224                 if (dia_ui.description->toPlainText() != clip->getProperty("description")) {
3225                     newprops.insert("description", dia_ui.description->toPlainText());
3226                 }
3227
3228                 QString newtemplate = newprops.value("xmltemplate");
3229                 if (newtemplate.isEmpty()) newtemplate = templatePath;
3230
3231                 // template modified we need to update xmldata
3232                 QString description = newprops.value("description");
3233                 if (description.isEmpty()) description = clip->getProperty("description");
3234                 else newprops.insert("templatetext", description);
3235                 //newprops.insert("xmldata", m_projectList->generateTemplateXml(newtemplate, description).toString());
3236                 if (!newprops.isEmpty()) {
3237                     EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->currentProperties(newprops), newprops, true);
3238                     m_activeDocument->commandStack()->push(command);
3239                 }
3240             }
3241             delete dia;
3242             return;
3243         }
3244         QString path = clip->getProperty("resource");
3245         TitleWidget *dia_ui = new TitleWidget(KUrl(), m_activeDocument->timecode(), titlepath, m_projectMonitor->render, this);
3246         QDomDocument doc;
3247         doc.setContent(clip->getProperty("xmldata"));
3248         dia_ui->setXml(doc);
3249         if (dia_ui->exec() == QDialog::Accepted) {
3250             QMap <QString, QString> newprops;
3251             newprops.insert("xmldata", dia_ui->xml().toString());
3252             if (dia_ui->outPoint() != clip->duration().frames(m_activeDocument->fps())) {
3253                 // duration changed, we need to update duration
3254                 newprops.insert("out", QString::number(dia_ui->outPoint()));
3255                 int currentLength = QString(clip->producerProperty("length")).toInt();
3256                 if (currentLength <= dia_ui->outPoint())
3257                         newprops.insert("length", QString::number(dia_ui->outPoint() + 1));
3258                 else newprops.insert("length", clip->producerProperty("length"));
3259             }
3260             if (!path.isEmpty()) {
3261                 // we are editing an external file, asked if we want to detach from that file or save the result to that title file.
3262                 if (KMessageBox::questionYesNo(this, i18n("You are editing an external title clip (%1). Do you want to save your changes to the title file or save the changes for this project only?", path), i18n("Save Title"), KGuiItem(i18n("Save to title file")), KGuiItem(i18n("Save in project only"))) == KMessageBox::Yes) {
3263                     // save to external file
3264                     dia_ui->saveTitle(path);
3265                 } else newprops.insert("resource", QString());
3266             }
3267             EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->currentProperties(newprops), newprops, true);
3268             m_activeDocument->commandStack()->push(command);
3269             //m_activeTimeline->projectView()->slotUpdateClip(clip->getId());
3270             m_activeDocument->setModified(true);
3271         }
3272         delete dia_ui;
3273
3274         //m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
3275         return;
3276     }
3277
3278     // any type of clip but a title
3279     ClipProperties *dia = new ClipProperties(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
3280     connect(dia, SIGNAL(addMarker(const QString &, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(const QString &, GenTime, QString)));
3281     connect(dia, SIGNAL(deleteProxy(const QString)), m_projectList, SLOT(slotDeleteProxy(const QString)));
3282     connect(dia, SIGNAL(applyNewClipProperties(const QString, QMap <QString, QString> , QMap <QString, QString> , bool, bool)), this, SLOT(slotApplyNewClipProperties(const QString, QMap <QString, QString> , QMap <QString, QString> , bool, bool)));
3283     dia->show();
3284 }
3285
3286
3287 void MainWindow::slotApplyNewClipProperties(const QString id, QMap <QString, QString> props, QMap <QString, QString> newprops, bool refresh, bool reload)
3288 {
3289     if (newprops.isEmpty()) return;
3290     EditClipCommand *command = new EditClipCommand(m_projectList, id, props, newprops, true);
3291     m_activeDocument->commandStack()->push(command);
3292     m_activeDocument->setModified();
3293
3294     if (refresh) {
3295         // update clip occurences in timeline
3296         m_activeTimeline->projectView()->slotUpdateClip(id, reload);
3297     }
3298 }
3299
3300
3301 void MainWindow::slotShowClipProperties(QList <DocClipBase *> cliplist, QMap<QString, QString> commonproperties)
3302 {
3303     ClipProperties dia(cliplist, m_activeDocument->timecode(), commonproperties, this);
3304     if (dia.exec() == QDialog::Accepted) {
3305         QUndoCommand *command = new QUndoCommand();
3306         command->setText(i18n("Edit clips"));
3307         QMap <QString, QString> newImageProps = dia.properties();
3308         // Transparency setting applies only for images
3309         QMap <QString, QString> newProps = newImageProps;
3310         newProps.remove("transparency");
3311
3312         for (int i = 0; i < cliplist.count(); i++) {
3313             DocClipBase *clip = cliplist.at(i);
3314             if (clip->clipType() == IMAGE)
3315                 new EditClipCommand(m_projectList, clip->getId(), clip->currentProperties(newImageProps), newImageProps, true, command);
3316             else
3317                 new EditClipCommand(m_projectList, clip->getId(), clip->currentProperties(newProps), newProps, true, command);
3318         }
3319         m_activeDocument->commandStack()->push(command);
3320         for (int i = 0; i < cliplist.count(); i++)
3321             m_activeTimeline->projectView()->slotUpdateClip(cliplist.at(i)->getId(), dia.needsTimelineReload());
3322     }
3323 }
3324
3325 void MainWindow::customEvent(QEvent* e)
3326 {
3327     if (e->type() == QEvent::User)
3328         m_messageLabel->setMessage(static_cast <MltErrorEvent *>(e)->message(), MltError);
3329 }
3330
3331 void MainWindow::slotTimelineClipSelected(ClipItem* item, bool raise)
3332 {
3333     m_effectStack->slotClipItemSelected(item);
3334     m_projectMonitor->slotSetSelectedClip(item);
3335     if (raise)
3336         m_effectStack->raiseWindow(m_effectStackDock);
3337 }
3338
3339 void MainWindow::slotTrackSelected(int index, TrackInfo info, bool raise)
3340 {
3341     m_effectStack->slotTrackItemSelected(index, info);
3342     if (raise)
3343         m_effectStack->raiseWindow(m_effectStackDock);
3344 }
3345
3346 void MainWindow::slotActivateTransitionView(Transition *t)
3347 {
3348     if (t)
3349         m_transitionConfig->raiseWindow(m_transitionConfigDock);
3350 }
3351
3352 void MainWindow::slotSnapRewind()
3353 {
3354     if (m_projectMonitor->isActive()) {
3355         if (m_activeTimeline)
3356             m_activeTimeline->projectView()->slotSeekToPreviousSnap();
3357     } else  {
3358         m_clipMonitor->slotSeekToPreviousSnap();
3359     }
3360 }
3361
3362 void MainWindow::slotSnapForward()
3363 {
3364     if (m_projectMonitor->isActive()) {
3365         if (m_activeTimeline)
3366             m_activeTimeline->projectView()->slotSeekToNextSnap();
3367     } else {
3368         m_clipMonitor->slotSeekToNextSnap();
3369     }
3370 }
3371
3372 void MainWindow::slotClipStart()
3373 {
3374     if (m_projectMonitor->isActive()) {
3375         if (m_activeTimeline)
3376             m_activeTimeline->projectView()->clipStart();
3377     }
3378 }
3379
3380 void MainWindow::slotClipEnd()
3381 {
3382     if (m_projectMonitor->isActive()) {
3383         if (m_activeTimeline)
3384             m_activeTimeline->projectView()->clipEnd();
3385     }
3386 }
3387
3388 void MainWindow::slotZoneStart()
3389 {
3390     if (m_projectMonitor->isActive())
3391         m_projectMonitor->slotZoneStart();
3392     else
3393         m_clipMonitor->slotZoneStart();
3394 }
3395
3396 void MainWindow::slotZoneEnd()
3397 {
3398     if (m_projectMonitor->isActive())
3399         m_projectMonitor->slotZoneEnd();
3400     else
3401         m_clipMonitor->slotZoneEnd();
3402 }
3403
3404 void MainWindow::slotChangeTool(QAction * action)
3405 {
3406     if (action == m_buttonSelectTool)
3407         slotSetTool(SELECTTOOL);
3408     else if (action == m_buttonRazorTool)
3409         slotSetTool(RAZORTOOL);
3410     else if (action == m_buttonSpacerTool)
3411         slotSetTool(SPACERTOOL);
3412 }
3413
3414 void MainWindow::slotChangeEdit(QAction * action)
3415 {
3416     if (!m_activeTimeline)
3417         return;
3418
3419     if (action == m_overwriteEditTool)
3420         m_activeTimeline->projectView()->setEditMode(OVERWRITEEDIT);
3421     else if (action == m_insertEditTool)
3422         m_activeTimeline->projectView()->setEditMode(INSERTEDIT);
3423     else
3424         m_activeTimeline->projectView()->setEditMode(NORMALEDIT);
3425 }
3426
3427 void MainWindow::slotSetTool(PROJECTTOOL tool)
3428 {
3429     if (m_activeDocument && m_activeTimeline) {
3430         //m_activeDocument->setTool(tool);
3431         QString message;
3432         switch (tool)  {
3433         case SPACERTOOL:
3434             message = i18n("Ctrl + click to use spacer on current track only");
3435             break;
3436         case RAZORTOOL:
3437             message = i18n("Click on a clip to cut it");
3438             break;
3439         default:
3440             message = i18n("Shift + click to create a selection rectangle, Ctrl + click to add an item to selection");
3441             break;
3442         }
3443         m_messageLabel->setMessage(message, InformationMessage);
3444         m_activeTimeline->projectView()->setTool(tool);
3445     }
3446 }
3447
3448 void MainWindow::slotCopy()
3449 {
3450     if (m_activeDocument && m_activeTimeline)
3451         m_activeTimeline->projectView()->copyClip();
3452 }
3453
3454 void MainWindow::slotPaste()
3455 {
3456     if (m_activeDocument && m_activeTimeline)
3457         m_activeTimeline->projectView()->pasteClip();
3458 }
3459
3460 void MainWindow::slotPasteEffects()
3461 {
3462     if (m_activeDocument && m_activeTimeline)
3463         m_activeTimeline->projectView()->pasteClipEffects();
3464 }
3465
3466 void MainWindow::slotFind()
3467 {
3468     if (!m_activeDocument || !m_activeTimeline) return;
3469     m_projectSearch->setEnabled(false);
3470     m_findActivated = true;
3471     m_findString.clear();
3472     m_activeTimeline->projectView()->initSearchStrings();
3473     statusBar()->showMessage(i18n("Starting -- find text as you type"));
3474     m_findTimer.start(5000);
3475     qApp->installEventFilter(this);
3476 }
3477
3478 void MainWindow::slotFindNext()
3479 {
3480     if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString))
3481         statusBar()->showMessage(i18n("Found: %1", m_findString));
3482     else
3483         statusBar()->showMessage(i18n("Reached end of project"));
3484     m_findTimer.start(4000);
3485 }
3486
3487 void MainWindow::findAhead()
3488 {
3489     if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
3490         m_projectSearchNext->setEnabled(true);
3491         statusBar()->showMessage(i18n("Found: %1", m_findString));
3492     } else {
3493         m_projectSearchNext->setEnabled(false);
3494         statusBar()->showMessage(i18n("Not found: %1", m_findString));
3495     }
3496 }
3497
3498 void MainWindow::findTimeout()
3499 {
3500     m_projectSearchNext->setEnabled(false);
3501     m_findActivated = false;
3502     m_findString.clear();
3503     statusBar()->showMessage(i18n("Find stopped"), 3000);
3504     if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
3505     m_projectSearch->setEnabled(true);
3506     removeEventFilter(this);
3507 }
3508
3509 void MainWindow::slotClipInTimeline(const QString &clipId)
3510 {
3511     if (m_activeTimeline && m_activeDocument) {
3512         QList<ItemInfo> matching = m_activeTimeline->projectView()->findId(clipId);
3513
3514         QMenu *inTimelineMenu = static_cast<QMenu*>(factory()->container("clip_in_timeline", this));
3515         inTimelineMenu->clear();
3516
3517         QList <QAction *> actionList;
3518
3519         for (int i = 0; i < matching.count(); ++i) {
3520             QString track = QString::number(matching.at(i).track);
3521             QString start = m_activeDocument->timecode().getTimecode(matching.at(i).startPos);
3522             int j = 0;
3523             QAction *a = new QAction(track + ": " + start, this);
3524             a->setData(QStringList() << track << start);
3525             connect(a, SIGNAL(triggered()), this, SLOT(slotSelectClipInTimeline()));
3526             while (j < actionList.count()) {
3527                 if (actionList.at(j)->text() > a->text()) break;
3528                 j++;
3529             }
3530             actionList.insert(j, a);
3531         }
3532         inTimelineMenu->addActions(actionList);
3533
3534         if (matching.empty())
3535             inTimelineMenu->setEnabled(false);
3536         else
3537             inTimelineMenu->setEnabled(true);
3538     }
3539 }
3540
3541 void MainWindow::slotClipInProjectTree()
3542 {
3543     if (m_activeTimeline) {
3544         const QStringList &clipIds = m_activeTimeline->projectView()->selectedClips();
3545         if (clipIds.isEmpty())
3546             return;
3547         m_projectListDock->raise();
3548         for (int i = 0; i < clipIds.count(); i++)
3549             m_projectList->selectItemById(clipIds.at(i));
3550         if (m_projectMonitor->isActive())
3551             slotSwitchMonitors();
3552     }
3553 }
3554
3555 /*void MainWindow::slotClipToProjectTree()
3556 {
3557     if (m_activeTimeline) {
3558     const QList<ClipItem *> clips =  m_activeTimeline->projectView()->selectedClipItems();
3559         if (clips.isEmpty()) return;
3560         for (int i = 0; i < clips.count(); i++) {
3561         m_projectList->slotAddXmlClip(clips.at(i)->itemXml());
3562         }
3563         //m_projectList->selectItemById(clipIds.at(i));
3564     }
3565 }*/
3566
3567 void MainWindow::slotSelectClipInTimeline()
3568 {
3569     if (m_activeTimeline) {
3570         QAction *action = qobject_cast<QAction *>(sender());
3571         QStringList data = action->data().toStringList();
3572         m_activeTimeline->projectView()->selectFound(data.at(0), data.at(1));
3573     }
3574 }
3575
3576 void MainWindow::keyPressEvent(QKeyEvent *ke)
3577 {
3578     if (m_findActivated) {
3579         if (ke->key() == Qt::Key_Backspace) {
3580             m_findString = m_findString.left(m_findString.length() - 1);
3581
3582             if (!m_findString.isEmpty())
3583                 findAhead();
3584             else
3585                 findTimeout();
3586
3587             m_findTimer.start(4000);
3588             ke->accept();
3589             return;
3590         } else if (ke->key() == Qt::Key_Escape) {
3591             findTimeout();
3592             ke->accept();
3593             return;
3594         } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
3595             m_findString += ke->text();
3596
3597             findAhead();
3598
3599             m_findTimer.start(4000);
3600             ke->accept();
3601             return;
3602         }
3603     } else {
3604         KXmlGuiWindow::keyPressEvent(ke);
3605     }
3606 }
3607
3608
3609 /** Gets called when the window gets hidden */
3610 void MainWindow::hideEvent(QHideEvent */*event*/)
3611 {
3612     if (isMinimized() && m_monitorManager)
3613         m_monitorManager->stopActiveMonitor();
3614 }
3615
3616 bool MainWindow::eventFilter(QObject *obj, QEvent *event)
3617 {
3618     if (m_findActivated) {
3619         if (event->type() == QEvent::ShortcutOverride) {
3620             QKeyEvent* ke = (QKeyEvent*) event;
3621             if (ke->text().trimmed().isEmpty()) return false;
3622             ke->accept();
3623             return true;
3624         } else {
3625             return false;
3626         }
3627     } else {
3628         // pass the event on to the parent class
3629         return QMainWindow::eventFilter(obj, event);
3630     }
3631 }
3632
3633
3634 void MainWindow::slotSaveZone(Render *render, QPoint zone, DocClipBase *baseClip, KUrl path)
3635 {
3636     KDialog *dialog = new KDialog(this);
3637     dialog->setCaption("Save clip zone");
3638     dialog->setButtons(KDialog::Ok | KDialog::Cancel);
3639
3640     QWidget *widget = new QWidget(dialog);
3641     dialog->setMainWidget(widget);
3642
3643     QVBoxLayout *vbox = new QVBoxLayout(widget);
3644     QLabel *label1 = new QLabel(i18n("Save clip zone as:"), this);
3645     if (path.isEmpty()) {
3646         QString tmppath = m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash);
3647         if (baseClip == NULL) tmppath.append("untitled.mlt");
3648         else {
3649             tmppath.append((baseClip->name().isEmpty() ? baseClip->fileURL().fileName() : baseClip->name()) + "-" + QString::number(zone.x()).rightJustified(4, '0') + ".mlt");
3650         }
3651         path = KUrl(tmppath);
3652     }
3653     KUrlRequester *url = new KUrlRequester(path, this);
3654     url->setFilter("video/mlt-playlist");
3655     QLabel *label2 = new QLabel(i18n("Description:"), this);
3656     KLineEdit *edit = new KLineEdit(this);
3657     vbox->addWidget(label1);
3658     vbox->addWidget(url);
3659     vbox->addWidget(label2);
3660     vbox->addWidget(edit);
3661     if (dialog->exec() == QDialog::Accepted) {
3662         if (QFile::exists(url->url().path())) {
3663             if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", url->url().path())) == KMessageBox::No) {
3664                 slotSaveZone(render, zone, baseClip, url->url());
3665                 return;
3666             }
3667         }
3668         if (baseClip && !baseClip->fileURL().isEmpty()) {
3669             // create zone from clip url, so that we don't have problems with proxy clips
3670             QProcess p;
3671 #if QT_VERSION >= 0x040600
3672             QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
3673             env.remove("MLT_PROFILE");
3674             p.setProcessEnvironment(env);
3675 #else
3676             QStringList env = QProcess::systemEnvironment();
3677             env << "MLT_PROFILE='\0'";
3678             p.setEnvironment(env);
3679 #endif
3680             p.start(KdenliveSettings::rendererpath(), QStringList() << baseClip->fileURL().path() << "in=" + QString::number(zone.x()) << "out=" + QString::number(zone.y()) << "-consumer" << "xml:" + url->url().path());
3681             if (!p.waitForStarted(3000)) {
3682                 KMessageBox::sorry(this, i18n("Cannot start MLT's renderer:\n%1", KdenliveSettings::rendererpath()));
3683             }
3684             else if (!p.waitForFinished(5000)) {
3685                 KMessageBox::sorry(this, i18n("Timeout while creating xml output"));
3686             }
3687         }
3688         else render->saveZone(url->url(), edit->text(), zone);
3689     }
3690
3691 }
3692
3693 void MainWindow::slotSetInPoint()
3694 {
3695     if (m_clipMonitor->isActive()) {
3696         m_clipMonitor->slotSetZoneStart();
3697     } else {
3698         m_projectMonitor->slotSetZoneStart();
3699     }
3700 }
3701
3702 void MainWindow::slotSetOutPoint()
3703 {
3704     if (m_clipMonitor->isActive()) {
3705         m_clipMonitor->slotSetZoneEnd();
3706     } else {
3707         m_projectMonitor->slotSetZoneEnd();
3708     }
3709 }
3710
3711 void MainWindow::slotResizeItemStart()
3712 {
3713     if (m_activeTimeline)
3714         m_activeTimeline->projectView()->setInPoint();
3715 }
3716
3717 void MainWindow::slotResizeItemEnd()
3718 {
3719     if (m_activeTimeline)
3720         m_activeTimeline->projectView()->setOutPoint();
3721 }
3722
3723 int MainWindow::getNewStuff(const QString &configFile)
3724 {
3725     KNS3::Entry::List entries;
3726 #if KDE_IS_VERSION(4,3,80)
3727     KNS3::DownloadDialog dialog(configFile);
3728     dialog.exec();
3729     entries = dialog.changedEntries();
3730     foreach(const KNS3::Entry & entry, entries) {
3731         if (entry.status() == KNS3::Entry::Installed)
3732             kDebug() << "// Installed files: " << entry.installedFiles();
3733     }
3734 #else
3735     KNS::Engine engine(0);
3736     if (engine.init(configFile))
3737         entries = engine.downloadDialogModal(this);
3738     foreach(KNS::Entry * entry, entries) {
3739         if (entry->status() == KNS::Entry::Installed)
3740             kDebug() << "// Installed files: " << entry->installedFiles();
3741     }
3742 #endif
3743     return entries.size();
3744 }
3745
3746 void MainWindow::slotGetNewTitleStuff()
3747 {
3748     if (getNewStuff("kdenlive_titles.knsrc") > 0)
3749         TitleWidget::refreshTitleTemplates();
3750 }
3751
3752 void MainWindow::slotGetNewLumaStuff()
3753 {
3754     if (getNewStuff("kdenlive_wipes.knsrc") > 0) {
3755         initEffects::refreshLumas();
3756         m_activeTimeline->projectView()->reloadTransitionLumas();
3757     }
3758 }
3759
3760 void MainWindow::slotGetNewRenderStuff()
3761 {
3762     if (getNewStuff("kdenlive_renderprofiles.knsrc") > 0)
3763         if (m_renderWidget)
3764             m_renderWidget->reloadProfiles();
3765 }
3766
3767 void MainWindow::slotGetNewMltProfileStuff()
3768 {
3769     if (getNewStuff("kdenlive_projectprofiles.knsrc") > 0) {
3770         // update the list of profiles in settings dialog
3771         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
3772         if (d)
3773             d->checkProfile();
3774     }
3775 }
3776
3777 void MainWindow::slotAutoTransition()
3778 {
3779     if (m_activeTimeline)
3780         m_activeTimeline->projectView()->autoTransition();
3781 }
3782
3783 void MainWindow::slotSplitAudio()
3784 {
3785     if (m_activeTimeline)
3786         m_activeTimeline->projectView()->splitAudio();
3787 }
3788
3789 void MainWindow::slotSetAudioAlignReference()
3790 {
3791     if (m_activeTimeline) {
3792         m_activeTimeline->projectView()->setAudioAlignReference();
3793     }
3794 }
3795
3796 void MainWindow::slotAlignAudio()
3797 {
3798     if (m_activeTimeline) {
3799         m_activeTimeline->projectView()->alignAudio();
3800     }
3801 }
3802
3803 void MainWindow::slotUpdateClipType(QAction *action)
3804 {
3805     if (m_activeTimeline) {
3806         if (action->data().toString() == "clip_audio_only") m_activeTimeline->projectView()->setAudioOnly();
3807         else if (action->data().toString() == "clip_video_only") m_activeTimeline->projectView()->setVideoOnly();
3808         else m_activeTimeline->projectView()->setAudioAndVideo();
3809     }
3810 }
3811
3812 void MainWindow::slotDvdWizard(const QString &url, const QString &profile)
3813 {
3814     // We must stop the monitors since we create a new on in the dvd wizard
3815     m_clipMonitor->stop();
3816     m_projectMonitor->stop();
3817     DvdWizard w(url, profile, this);
3818     w.exec();
3819     m_projectMonitor->start();
3820 }
3821
3822 void MainWindow::slotShowTimeline(bool show)
3823 {
3824     if (show == false) {
3825         m_timelineState = saveState();
3826         centralWidget()->setHidden(true);
3827     } else {
3828         centralWidget()->setHidden(false);
3829         restoreState(m_timelineState);
3830     }
3831 }
3832
3833 void MainWindow::slotMaximizeCurrent(bool)
3834 {
3835     //TODO: is there a way to maximize current widget?
3836
3837     m_timelineState = saveState();
3838     QWidget *par = focusWidget()->parentWidget();
3839     while (par->parentWidget() && par->parentWidget() != this)
3840         par = par->parentWidget();
3841     kDebug() << "CURRENT WIDGET: " << par->objectName();
3842 }
3843
3844 void MainWindow::loadStabilize()
3845 {
3846         QMenu* stabMenu= static_cast<QMenu*>(factory()->container("stabilize", this));
3847         if (stabMenu){
3848                 stabMenu->clear();
3849                 Mlt::Profile profile;
3850                 if (Mlt::Factory::filter(profile,(char*)"videostab")){
3851                         QAction *action=stabMenu->addAction("Videostab (vstab)");
3852                         action->setData("videostab");
3853                         connect(action,SIGNAL(triggered()), this, SLOT(slotStabilize()));
3854                 }
3855                 if (Mlt::Factory::filter(profile,(char*)"videostab2")){
3856                         QAction *action=stabMenu->addAction("Videostab (transcode)");
3857                         action->setData("videostab2");
3858                         connect(action,SIGNAL(triggered()), this, SLOT(slotStabilize()));
3859                 }
3860         }
3861
3862
3863 }
3864
3865 void MainWindow::loadTranscoders()
3866 {
3867     QMenu *transMenu = static_cast<QMenu*>(factory()->container("transcoders", this));
3868     transMenu->clear();
3869
3870     QMenu *extractAudioMenu = static_cast<QMenu*>(factory()->container("extract_audio", this));
3871     extractAudioMenu->clear();
3872
3873     KSharedConfigPtr config = KSharedConfig::openConfig("kdenlivetranscodingrc");
3874     KConfigGroup transConfig(config, "Transcoding");
3875     // read the entries
3876     QMap< QString, QString > profiles = transConfig.entryMap();
3877     QMapIterator<QString, QString> i(profiles);
3878     while (i.hasNext()) {
3879         i.next();
3880         QStringList data = i.value().split(";");
3881         QAction *a;
3882         // separate audio transcoding in a separate menu
3883         if (data.count() > 2 && data.at(2) == "audio") {
3884             a = extractAudioMenu->addAction(i.key());
3885         }
3886         else {
3887             a = transMenu->addAction(i.key());
3888         }
3889         a->setData(data);
3890         if (data.count() > 1) a->setToolTip(data.at(1));
3891         connect(a, SIGNAL(triggered()), this, SLOT(slotTranscode()));
3892     }
3893 }
3894
3895 void MainWindow::slotStabilize()
3896 {
3897     QString condition,filtername;
3898     QStringList ids;
3899
3900     // Stablize selected clips
3901     QAction *action = qobject_cast<QAction *>(sender());
3902     if (action){
3903         filtername=action->data().toString();
3904     }
3905     m_projectList->startClipFilterJob(filtername, condition);
3906     /*
3907     if (ids.isEmpty()) {
3908         m_messageLabel->setMessage(i18n("No clip to transcode"), ErrorMessage);
3909         return;
3910     }
3911     QString destination;
3912     ProjectItem *item = m_projectList->getClipById(ids.at(0));
3913     if (ids.count() == 1) {
3914
3915     }
3916     ClipStabilize *d = new ClipStabilize(destination, ids.count(), filtername);
3917     //connect(d, SIGNAL(addClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
3918     if (d->exec() == QDialog::Accepted) {
3919         m_projectList->slotStabilizeClipJob(ids, d->autoAddClip(), d->params(), d->desc());
3920     }
3921     delete d;*/
3922 }
3923
3924 void MainWindow::slotTranscode(KUrl::List urls)
3925 {
3926     QString params;
3927     QString desc;
3928     QString condition;
3929     if (urls.isEmpty()) {
3930         QAction *action = qobject_cast<QAction *>(sender());
3931         QStringList data = action->data().toStringList();
3932         params = data.at(0);
3933         if (data.count() > 1) desc = data.at(1);
3934         if (data.count() > 3) condition = data.at(3);
3935         m_projectList->slotTranscodeClipJob(condition, params, desc);
3936         return;
3937     }
3938     if (urls.isEmpty()) {
3939         m_messageLabel->setMessage(i18n("No clip to transcode"), ErrorMessage);
3940         return;
3941     }
3942     ClipTranscode *d = new ClipTranscode(urls, params, desc);
3943     connect(d, SIGNAL(addClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
3944     d->show();
3945 }
3946
3947 void MainWindow::slotTranscodeClip()
3948 {
3949     KUrl::List urls = KFileDialog::getOpenUrls(KUrl("kfiledialog:///projectfolder"));
3950     if (urls.isEmpty()) return;
3951     slotTranscode(urls);
3952 }
3953
3954 void MainWindow::slotSetDocumentRenderProfile(QMap <QString, QString> props)
3955 {
3956     if (m_activeDocument == NULL) return;
3957     QMapIterator<QString, QString> i(props);
3958     while (i.hasNext()) {
3959         i.next();
3960         m_activeDocument->setDocumentProperty(i.key(), i.value());
3961     }
3962     m_activeDocument->setModified(true);
3963 }
3964
3965
3966 void MainWindow::slotPrepareRendering(bool scriptExport, bool zoneOnly, const QString &chapterFile)
3967 {
3968     if (m_activeDocument == NULL || m_renderWidget == NULL) return;
3969     QString scriptPath;
3970     QString playlistPath;
3971     if (scriptExport) {
3972         bool ok;
3973         QString scriptsFolder = m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash) + "scripts/";
3974         QString path = m_renderWidget->getFreeScriptName();
3975         scriptPath = QInputDialog::getText(this, i18n("Create Render Script"), i18n("Script name (will be saved in: %1)", scriptsFolder), QLineEdit::Normal, KUrl(path).fileName(), &ok);
3976         if (!ok || scriptPath.isEmpty()) return;
3977         scriptPath.prepend(scriptsFolder);
3978         QFile f(scriptPath);
3979         if (f.exists()) {
3980             if (KMessageBox::warningYesNo(this, i18n("Script file already exists. Do you want to overwrite it?")) != KMessageBox::Yes)
3981                 return;
3982         }
3983         playlistPath = scriptPath + ".mlt";
3984     } else {
3985         KTemporaryFile temp;
3986         temp.setAutoRemove(false);
3987         temp.setSuffix(".mlt");
3988         temp.open();
3989         playlistPath = temp.fileName();
3990     }
3991     QString playlistContent = m_projectMonitor->sceneList();
3992     if (!chapterFile.isEmpty()) {
3993         int in = 0;
3994         int out;
3995         if (!zoneOnly) out = (int) GenTime(m_activeDocument->projectDuration()).frames(m_activeDocument->fps());
3996         else {
3997             in = m_activeTimeline->inPoint();
3998             out = m_activeTimeline->outPoint();
3999         }
4000         QDomDocument doc;
4001         QDomElement chapters = doc.createElement("chapters");
4002         chapters.setAttribute("fps", m_activeDocument->fps());
4003         doc.appendChild(chapters);
4004
4005         QDomElement guidesxml = m_activeDocument->guidesXml();
4006         QDomNodeList nodes = guidesxml.elementsByTagName("guide");
4007         for (int i = 0; i < nodes.count(); i++) {
4008             QDomElement e = nodes.item(i).toElement();
4009             if (!e.isNull()) {
4010                 QString comment = e.attribute("comment");
4011                 int time = (int) GenTime(e.attribute("time").toDouble()).frames(m_activeDocument->fps());
4012                 if (time >= in && time < out) {
4013                     if (zoneOnly) time = time - in;
4014                     QDomElement chapter = doc.createElement("chapter");
4015                     chapters.appendChild(chapter);
4016                     chapter.setAttribute("title", comment);
4017                     chapter.setAttribute("time", time);
4018                 }
4019             }
4020         }
4021         if (chapters.childNodes().count() > 0) {
4022             if (m_activeTimeline->projectView()->hasGuide(out, 0) == -1) {
4023                 // Always insert a guide in pos 0
4024                 QDomElement chapter = doc.createElement("chapter");
4025                 chapters.insertBefore(chapter, QDomNode());
4026                 chapter.setAttribute("title", i18n("Start"));
4027                 chapter.setAttribute("time", "0");
4028             }
4029             // save chapters file
4030             QFile file(chapterFile);
4031             if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
4032                 kWarning() << "//////  ERROR writing DVD CHAPTER file: " << chapterFile;
4033             } else {
4034                 file.write(doc.toString().toUtf8());
4035                 if (file.error() != QFile::NoError) {
4036                     kWarning() << "//////  ERROR writing DVD CHAPTER file: " << chapterFile;
4037                 }
4038                 file.close();
4039             }
4040         }
4041     }
4042     bool exportAudio;
4043     if (m_renderWidget->automaticAudioExport()) {
4044         exportAudio = m_activeTimeline->checkProjectAudio();
4045     } else exportAudio = m_renderWidget->selectedAudioExport();
4046
4047     // Set playlist audio volume to 100%
4048     QDomDocument doc;
4049     doc.setContent(playlistContent);
4050     QDomElement tractor = doc.documentElement().firstChildElement("tractor");
4051     if (!tractor.isNull()) {
4052         QDomNodeList props = tractor.elementsByTagName("property");
4053         for (int i = 0; i < props.count(); i++) {
4054             if (props.at(i).toElement().attribute("name") == "meta.volume") {
4055                 props.at(i).firstChild().setNodeValue("1");
4056                 break;
4057             }
4058         }
4059     }
4060
4061     // Do we want proxy rendering
4062     if (m_projectList->useProxy() && !m_renderWidget->proxyRendering()) {
4063         QString root = doc.documentElement().attribute("root");
4064
4065         // replace proxy clips with originals
4066         QMap <QString, QString> proxies = m_projectList->getProxies();
4067
4068         QDomNodeList producers = doc.elementsByTagName("producer");
4069         QString producerResource;
4070         QString suffix;
4071         for (uint n = 0; n < producers.length(); n++) {
4072             QDomElement e = producers.item(n).toElement();
4073             producerResource = EffectsList::property(e, "resource");
4074             if (producerResource.isEmpty()) continue;
4075             if (!producerResource.startsWith("/")) {
4076                 producerResource.prepend(root + "/");
4077             }
4078             if (producerResource.contains('?')) {
4079                 // slowmotion producer
4080                 suffix = "?" + producerResource.section('?', 1);
4081                 producerResource = producerResource.section('?', 0, 0);
4082             }
4083             else suffix.clear();
4084             if (!producerResource.isEmpty()) {
4085                 if (proxies.contains(producerResource)) {
4086                     EffectsList::setProperty(e, "resource", proxies.value(producerResource) + suffix);
4087                     // We need to delete the "aspect_ratio" property because proxy clips
4088                     // sometimes have different ratio than original clips
4089                     EffectsList::removeProperty(e, "aspect_ratio");
4090                     EffectsList::removeMetaProperties(e);
4091                 }
4092             }
4093         }
4094
4095         /*QMapIterator<QString, QString> i(proxies);
4096         while (i.hasNext()) {
4097             i.next();
4098             // Replace all keys with their values (proxy path with original path)
4099             QString key = i.key();
4100             playlistContent.replace(key, i.value());
4101             if (!root.isEmpty() && key.startsWith(root)) {
4102                 // in case the resource path in MLT playlist is relative
4103                 key.remove(0, root.count() + 1);
4104                 playlistContent.replace(key, i.value());
4105             }
4106         }*/
4107     }
4108     playlistContent = doc.toString();
4109
4110     // Do save scenelist
4111     QFile file(playlistPath);
4112     if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
4113         m_messageLabel->setMessage(i18n("Cannot write to file %1").arg(playlistPath), ErrorMessage);
4114         return;
4115     }
4116     file.write(playlistContent.toUtf8());
4117     if (file.error() != QFile::NoError) {
4118         m_messageLabel->setMessage(i18n("Cannot write to file %1").arg(playlistPath), ErrorMessage);
4119         file.close();
4120         return;
4121     }
4122     file.close();
4123     m_renderWidget->slotExport(scriptExport, m_activeTimeline->inPoint(), m_activeTimeline->outPoint(), m_activeDocument->metadata(), playlistPath, scriptPath, exportAudio);
4124 }
4125
4126 void MainWindow::slotUpdateTimecodeFormat(int ix)
4127 {
4128     KdenliveSettings::setFrametimecode(ix == 1);
4129     m_clipMonitor->updateTimecodeFormat();
4130     m_projectMonitor->updateTimecodeFormat();
4131     m_transitionConfig->updateTimecodeFormat();
4132     m_effectStack->updateTimecodeFormat();
4133     //m_activeTimeline->projectView()->clearSelection();
4134     m_activeTimeline->updateRuler();
4135 }
4136
4137 void MainWindow::slotRemoveFocus()
4138 {
4139     statusBar()->setFocus();
4140     statusBar()->clearFocus();
4141 }
4142
4143 void MainWindow::slotRevert()
4144 {
4145     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;
4146     KUrl url = m_activeDocument->url();
4147     if (closeCurrentDocument(false))
4148         doOpenFile(url, NULL);
4149 }
4150
4151
4152 void MainWindow::slotShutdown()
4153 {
4154     if (m_activeDocument) m_activeDocument->setModified(false);
4155     // Call shutdown
4156     QDBusConnectionInterface* interface = QDBusConnection::sessionBus().interface();
4157     if (interface && interface->isServiceRegistered("org.kde.ksmserver")) {
4158         QDBusInterface smserver("org.kde.ksmserver", "/KSMServer", "org.kde.KSMServerInterface");
4159         smserver.call("logout", 1, 2, 2);
4160     } else if (interface && interface->isServiceRegistered("org.gnome.SessionManager")) {
4161         QDBusInterface smserver("org.gnome.SessionManager", "/org/gnome/SessionManager", "org.gnome.SessionManager");
4162         smserver.call("Shutdown");
4163     }
4164 }
4165
4166 void MainWindow::slotUpdateTrackInfo()
4167 {
4168     if (m_activeDocument)
4169         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
4170 }
4171
4172 void MainWindow::slotChangePalette(QAction *action, const QString &themename)
4173 {
4174     // Load the theme file
4175     QString theme;
4176     if (action == NULL) theme = themename;
4177     else theme = action->data().toString();
4178     KdenliveSettings::setColortheme(theme);
4179     // Make palette for all widgets.
4180     QPalette plt = kapp->palette();
4181     if (theme.isEmpty()) {
4182         plt = QApplication::desktop()->palette();
4183     } else {
4184         KSharedConfigPtr config = KSharedConfig::openConfig(theme);
4185
4186 #if KDE_IS_VERSION(4,6,3)
4187         plt = KGlobalSettings::createNewApplicationPalette(config);
4188 #else
4189         // Since there was a bug in createApplicationPalette in KDE < 4.6.3 we need
4190         // to do the palette loading stuff ourselves. (https://bugs.kde.org/show_bug.cgi?id=263497)
4191         QPalette::ColorGroup states[3] = { QPalette::Active, QPalette::Inactive,
4192                                             QPalette::Disabled };
4193         // TT thinks tooltips shouldn't use active, so we use our active colors for all states
4194         KColorScheme schemeTooltip(QPalette::Active, KColorScheme::Tooltip, config);
4195
4196         for ( int i = 0; i < 3 ; i++ ) {
4197             QPalette::ColorGroup state = states[i];
4198             KColorScheme schemeView(state, KColorScheme::View, config);
4199             KColorScheme schemeWindow(state, KColorScheme::Window, config);
4200             KColorScheme schemeButton(state, KColorScheme::Button, config);
4201             KColorScheme schemeSelection(state, KColorScheme::Selection, config);
4202
4203             plt.setBrush( state, QPalette::WindowText, schemeWindow.foreground() );
4204             plt.setBrush( state, QPalette::Window, schemeWindow.background() );
4205             plt.setBrush( state, QPalette::Base, schemeView.background() );
4206             plt.setBrush( state, QPalette::Text, schemeView.foreground() );
4207             plt.setBrush( state, QPalette::Button, schemeButton.background() );
4208             plt.setBrush( state, QPalette::ButtonText, schemeButton.foreground() );
4209             plt.setBrush( state, QPalette::Highlight, schemeSelection.background() );
4210             plt.setBrush( state, QPalette::HighlightedText, schemeSelection.foreground() );
4211             plt.setBrush( state, QPalette::ToolTipBase, schemeTooltip.background() );
4212             plt.setBrush( state, QPalette::ToolTipText, schemeTooltip.foreground() );
4213
4214             plt.setColor( state, QPalette::Light, schemeWindow.shade( KColorScheme::LightShade ) );
4215             plt.setColor( state, QPalette::Midlight, schemeWindow.shade( KColorScheme::MidlightShade ) );
4216             plt.setColor( state, QPalette::Mid, schemeWindow.shade( KColorScheme::MidShade ) );
4217             plt.setColor( state, QPalette::Dark, schemeWindow.shade( KColorScheme::DarkShade ) );
4218             plt.setColor( state, QPalette::Shadow, schemeWindow.shade( KColorScheme::ShadowShade ) );
4219
4220             plt.setBrush( state, QPalette::AlternateBase, schemeView.background( KColorScheme::AlternateBackground) );
4221             plt.setBrush( state, QPalette::Link, schemeView.foreground( KColorScheme::LinkText ) );
4222             plt.setBrush( state, QPalette::LinkVisited, schemeView.foreground( KColorScheme::VisitedText ) );
4223         }
4224 #endif
4225     }
4226
4227     kapp->setPalette(plt);
4228     slotChangePalette();
4229     const QObjectList children = statusBar()->children();
4230
4231     foreach(QObject * child, children) {
4232         if (child->isWidgetType())
4233             ((QWidget*)child)->setPalette(plt);
4234         const QObjectList subchildren = child->children();
4235         foreach(QObject * subchild, subchildren) {
4236             if (subchild->isWidgetType())
4237                 ((QWidget*)subchild)->setPalette(plt);
4238         }
4239     }
4240 }
4241
4242
4243 QPixmap MainWindow::createSchemePreviewIcon(const KSharedConfigPtr &config)
4244 {
4245     // code taken from kdebase/workspace/kcontrol/colors/colorscm.cpp
4246     const uchar bits1[] = { 0xff, 0xff, 0xff, 0x2c, 0x16, 0x0b };
4247     const uchar bits2[] = { 0x68, 0x34, 0x1a, 0xff, 0xff, 0xff };
4248     const QSize bitsSize(24, 2);
4249     const QBitmap b1 = QBitmap::fromData(bitsSize, bits1);
4250     const QBitmap b2 = QBitmap::fromData(bitsSize, bits2);
4251
4252     QPixmap pixmap(23, 16);
4253     pixmap.fill(Qt::black); // ### use some color other than black for borders?
4254
4255     KConfigGroup group(config, "WM");
4256     QPainter p(&pixmap);
4257     KColorScheme windowScheme(QPalette::Active, KColorScheme::Window, config);
4258     p.fillRect(1,  1, 7, 7, windowScheme.background());
4259     p.fillRect(2,  2, 5, 2, QBrush(windowScheme.foreground().color(), b1));
4260
4261     KColorScheme buttonScheme(QPalette::Active, KColorScheme::Button, config);
4262     p.fillRect(8,  1, 7, 7, buttonScheme.background());
4263     p.fillRect(9,  2, 5, 2, QBrush(buttonScheme.foreground().color(), b1));
4264
4265     p.fillRect(15,  1, 7, 7, group.readEntry("activeBackground", QColor(96, 148, 207)));
4266     p.fillRect(16,  2, 5, 2, QBrush(group.readEntry("activeForeground", QColor(255, 255, 255)), b1));
4267
4268     KColorScheme viewScheme(QPalette::Active, KColorScheme::View, config);
4269     p.fillRect(1,  8, 7, 7, viewScheme.background());
4270     p.fillRect(2, 12, 5, 2, QBrush(viewScheme.foreground().color(), b2));
4271
4272     KColorScheme selectionScheme(QPalette::Active, KColorScheme::Selection, config);
4273     p.fillRect(8,  8, 7, 7, selectionScheme.background());
4274     p.fillRect(9, 12, 5, 2, QBrush(selectionScheme.foreground().color(), b2));
4275
4276     p.fillRect(15,  8, 7, 7, group.readEntry("inactiveBackground", QColor(224, 223, 222)));
4277     p.fillRect(16, 12, 5, 2, QBrush(group.readEntry("inactiveForeground", QColor(20, 19, 18)), b2));
4278
4279     p.end();
4280     return pixmap;
4281 }
4282
4283 void MainWindow::slotSwitchMonitors()
4284 {
4285     m_monitorManager->slotSwitchMonitors(!m_clipMonitor->isActive());
4286     if (m_projectMonitor->isActive()) m_activeTimeline->projectView()->setFocus();
4287     else m_projectList->focusTree();
4288 }
4289
4290 void MainWindow::slotInsertZoneToTree()
4291 {
4292     if (!m_clipMonitor->isActive() || m_clipMonitor->activeClip() == NULL) return;
4293     QStringList info = m_clipMonitor->getZoneInfo();
4294     m_projectList->slotAddClipCut(info.at(0), info.at(1).toInt(), info.at(2).toInt());
4295 }
4296
4297 void MainWindow::slotInsertZoneToTimeline()
4298 {
4299     if (m_activeTimeline == NULL || m_clipMonitor->activeClip() == NULL) return;
4300     QStringList info = m_clipMonitor->getZoneInfo();
4301     m_activeTimeline->projectView()->insertClipCut(m_clipMonitor->activeClip(), info.at(1).toInt(), info.at(2).toInt());
4302 }
4303
4304
4305 void MainWindow::slotDeleteProjectClips(QStringList ids, QMap<QString, QString> folderids)
4306 {
4307     if (m_activeDocument && m_activeTimeline) {
4308         if (!ids.isEmpty()) {
4309             for (int i = 0; i < ids.size(); ++i) {
4310                 m_activeTimeline->slotDeleteClip(ids.at(i));
4311             }
4312             m_activeDocument->clipManager()->slotDeleteClips(ids);
4313         }
4314         if (!folderids.isEmpty()) m_projectList->deleteProjectFolder(folderids);
4315         m_activeDocument->setModified(true);
4316     }
4317 }
4318
4319 void MainWindow::slotShowTitleBars(bool show)
4320 {
4321     QList <QDockWidget *> docks = findChildren<QDockWidget *>();
4322     for (int i = 0; i < docks.count(); i++) {
4323         QDockWidget* dock = docks.at(i);
4324         if (show) {
4325             dock->setTitleBarWidget(0);
4326         } else {
4327             if (!dock->isFloating()) {
4328                 dock->setTitleBarWidget(new QWidget);
4329             }
4330         }
4331     }
4332     KdenliveSettings::setShowtitlebars(show);
4333 }
4334
4335 void MainWindow::slotSwitchTitles()
4336 {
4337     slotShowTitleBars(!KdenliveSettings::showtitlebars());
4338 }
4339
4340 QString MainWindow::getMimeType(bool open)
4341 {
4342     QString mimetype = "application/x-kdenlive";
4343     KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
4344     if (!mime) {
4345         mimetype = "*.kdenlive";
4346         if (open) mimetype.append(" *.tar.gz");
4347     }
4348     else if (open) mimetype.append(" application/x-compressed-tar");
4349     return mimetype;
4350 }
4351
4352 void MainWindow::slotMonitorRequestRenderFrame(bool request)
4353 {
4354     if (request) {
4355         m_projectMonitor->render->sendFrameForAnalysis = true;
4356         return;
4357     } else {
4358         for (int i = 0; i < m_gfxScopesList.count(); i++) {
4359             if (m_gfxScopesList.at(i)->isVisible() && tabifiedDockWidgets(m_gfxScopesList.at(i)).isEmpty() && static_cast<AbstractGfxScopeWidget *>(m_gfxScopesList.at(i)->widget())->autoRefreshEnabled()) {
4360                 request = true;
4361                 break;
4362             }
4363         }
4364     }
4365 #ifdef DEBUG_MAINW
4366     qDebug() << "Any scope accepting new frames? " << request;
4367 #endif
4368     if (!request) {
4369         m_projectMonitor->render->sendFrameForAnalysis = false;
4370     }
4371 }
4372
4373
4374 void MainWindow::slotOpenStopmotion()
4375 {
4376     if (m_stopmotion == NULL) {
4377         m_stopmotion = new StopmotionWidget(m_monitorManager, m_activeDocument->projectFolder(), m_stopmotion_actions->actions(), this);
4378         connect(m_stopmotion, SIGNAL(addOrUpdateSequence(const QString &)), m_projectList, SLOT(slotAddOrUpdateSequence(const QString)));
4379         //for (int i = 0; i < m_gfxScopesList.count(); i++) {
4380             // Check if we need the renderer to send a new frame for update
4381             /*if (!m_scopesList.at(i)->widget()->visibleRegion().isEmpty() && !(static_cast<AbstractScopeWidget *>(m_scopesList.at(i)->widget())->autoRefreshEnabled())) request = true;*/
4382             //connect(m_stopmotion, SIGNAL(gotFrame(QImage)), static_cast<AbstractGfxScopeWidget *>(m_gfxScopesList.at(i)->widget()), SLOT(slotRenderZoneUpdated(QImage)));
4383             //static_cast<AbstractScopeWidget *>(m_scopesList.at(i)->widget())->slotMonitorCapture();
4384         //}
4385     }
4386     m_stopmotion->show();
4387 }
4388
4389 void MainWindow::slotDeleteClip(const QString &id)
4390 {
4391     QList <ClipProperties *> list = findChildren<ClipProperties *>();
4392     for (int i = 0; i < list.size(); ++i) {
4393         list.at(i)->disableClipId(id);
4394     }
4395     m_projectList->slotDeleteClip(id);
4396 }
4397
4398 void MainWindow::slotUpdateProxySettings()
4399 {
4400     if (m_renderWidget) m_renderWidget->updateProxyConfig(m_projectList->useProxy());
4401     if (KdenliveSettings::enableproxy())
4402         KStandardDirs::makeDir(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash) + "proxy/");
4403     m_projectList->updateProxyConfig();
4404 }
4405
4406 void MainWindow::slotInsertNotesTimecode()
4407 {
4408     int frames = m_projectMonitor->render->seekPosition().frames(m_activeDocument->fps());
4409     QString position = m_activeDocument->timecode().getTimecodeFromFrames(frames);
4410     m_notesWidget->insertHtml("<a href=\"" + QString::number(frames) + "\">" + position + "</a> ");
4411 }
4412
4413 void MainWindow::slotArchiveProject()
4414 {
4415     QList <DocClipBase*> list = m_projectList->documentClipList();
4416     QDomDocument doc = m_activeDocument->xmlSceneList(m_projectMonitor->sceneList(), m_projectList->expandedFolders());
4417     ArchiveWidget *d = new ArchiveWidget(m_activeDocument->url().fileName(), doc, list, m_activeTimeline->projectView()->extractTransitionsLumas(), this);
4418     d->exec();
4419 }
4420
4421
4422 void MainWindow::slotOpenBackupDialog(const KUrl url)
4423 {
4424     KUrl projectFile;
4425     KUrl projectFolder;
4426     QString projectId;
4427     kDebug()<<"// BACKUP URL: "<<url.path();
4428     if (!url.isEmpty()) {
4429         // we could not open the project file, guess where the backups are
4430         projectFolder = KUrl(KdenliveSettings::defaultprojectfolder());
4431         projectFile = url;
4432     }
4433     else {
4434         projectFolder = m_activeDocument->projectFolder();
4435         projectFile = m_activeDocument->url();
4436         projectId = m_activeDocument->getDocumentProperty("documentid");
4437     }
4438
4439     BackupWidget *dia = new BackupWidget(projectFile, projectFolder, projectId, this);
4440     if (dia->exec() == QDialog::Accepted) {
4441         QString requestedBackup = dia->selectedFile();
4442         m_activeDocument->backupLastSavedVersion(projectFile.path());
4443         closeCurrentDocument(false);
4444         doOpenFile(KUrl(requestedBackup), NULL);
4445         m_activeDocument->setUrl(projectFile);
4446         m_activeDocument->setModified(true);
4447         setCaption(m_activeDocument->description());
4448     }
4449     delete dia;
4450 }
4451
4452 void MainWindow::slotElapsedTime()
4453 {
4454     kDebug()<<"-----------------------------------------\n"<<"Time elapsed: "<<m_timer.elapsed()<<"\n-------------------------";
4455 }
4456
4457
4458 void MainWindow::slotDownloadResources()
4459 {
4460     QString currentFolder;
4461     if (m_activeDocument) currentFolder = m_activeDocument->projectFolder().path();
4462     else currentFolder = KdenliveSettings::defaultprojectfolder();
4463     ResourceWidget *d = new ResourceWidget(currentFolder);
4464     connect(d, SIGNAL(addClip(KUrl, const QString &)), this, SLOT(slotAddProjectClip(KUrl, const QString &)));
4465     d->show();
4466 }
4467
4468 void MainWindow::slotChangePalette()
4469 {
4470     QPalette plt = QApplication::palette();
4471     if (m_effectStack) m_effectStack->updatePalette();
4472     if (m_projectList) m_projectList->updatePalette();
4473     if (m_effectList) m_effectList->updatePalette();
4474     
4475     if (m_clipMonitor) m_clipMonitor->setPalette(plt);
4476     if (m_projectMonitor) m_projectMonitor->setPalette(plt);
4477     
4478     setStatusBarStyleSheet(plt);
4479     if (m_activeTimeline) {
4480         m_activeTimeline->updatePalette();
4481     }
4482 }
4483
4484 void MainWindow::slotSaveTimelineClip()
4485 {
4486     if (m_activeTimeline && m_projectMonitor->render) {
4487         ClipItem *clip = m_activeTimeline->projectView()->getActiveClipUnderCursor(true);
4488         if (!clip) {
4489             m_messageLabel->setMessage(i18n("Select a clip to save"), InformationMessage);
4490             return;
4491         }
4492         KUrl url = KFileDialog::getSaveUrl(m_activeDocument->projectFolder(), "video/mlt-playlist");
4493         if (!url.isEmpty()) m_projectMonitor->render->saveClip(m_activeDocument->tracksCount() - clip->track(), clip->startPos(), url);
4494     }
4495 }
4496
4497
4498 #include "mainwindow.moc"
4499
4500 #ifdef DEBUG_MAINW
4501 #undef DEBUG_MAINW
4502 #endif