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