forked from mltframework/shotcut
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
2612 lines (2410 loc) · 96.3 KB
/
mainwindow.cpp
File metadata and controls
2612 lines (2410 loc) · 96.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2011-2015 Meltytech, LLC
* Author: Dan Dennedy <dan@dennedy.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "scrubbar.h"
#include "openotherdialog.h"
#include "player.h"
#include "widgets/alsawidget.h"
#include "widgets/colorbarswidget.h"
#include "widgets/colorproducerwidget.h"
#include "widgets/decklinkproducerwidget.h"
#include "widgets/directshowvideowidget.h"
#include "widgets/isingwidget.h"
#include "widgets/jackproducerwidget.h"
#include "widgets/toneproducerwidget.h"
#include "widgets/lissajouswidget.h"
#include "widgets/networkproducerwidget.h"
#include "widgets/noisewidget.h"
#include "widgets/plasmawidget.h"
#include "widgets/pulseaudiowidget.h"
#include "widgets/video4linuxwidget.h"
#include "widgets/x11grabwidget.h"
#include "widgets/avformatproducerwidget.h"
#include "widgets/imageproducerwidget.h"
#include "widgets/webvfxproducer.h"
#include "docks/recentdock.h"
#include "docks/encodedock.h"
#include "docks/jobsdock.h"
#include "jobqueue.h"
#include "docks/playlistdock.h"
#include "glwidget.h"
#include "mvcp/meltedserverdock.h"
#include "mvcp/meltedplaylistdock.h"
#include "mvcp/meltedunitsmodel.h"
#include "mvcp/meltedplaylistmodel.h"
#include "controllers/filtercontroller.h"
#include "controllers/scopecontroller.h"
#include "docks/filtersdock.h"
#include "dialogs/customprofiledialog.h"
#include "htmleditor/htmleditor.h"
#include "settings.h"
#include "leapnetworklistener.h"
#include "database.h"
#include "widgets/gltestwidget.h"
#include "docks/timelinedock.h"
#include "widgets/lumamixtransition.h"
#include "qmltypes/qmlutilities.h"
#include "qmltypes/qmlapplication.h"
#include "autosavefile.h"
#include "commands/playlistcommands.h"
#include "shotcut_mlt_properties.h"
#include <QtWidgets>
#include <QDebug>
#include <QThreadPool>
#include <QtConcurrent/QtConcurrentRun>
#include <QMutexLocker>
static const int STATUS_TIMEOUT_MS = 5000;
static const int AUTOSAVE_TIMEOUT_MS = 10000;
MainWindow::MainWindow()
: QMainWindow(0)
, ui(new Ui::MainWindow)
, m_isKKeyPressed(false)
, m_keyerGroup(0)
, m_keyerMenu(0)
, m_isPlaylistLoaded(false)
, m_htmlEditor(0)
, m_autosaveFile(0)
, m_exitCode(EXIT_SUCCESS)
, m_navigationPosition(0)
{
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
QLibrary libJack("libjack.so.0");
if (!libJack.load()) {
QMessageBox::critical(this, qApp->applicationName(),
tr("Error: This program requires the JACK 1 library.\n\nPlease install it using your package manager. It may be named libjack0, jack-audio-connection-kit, jack, or similar."));
::exit(EXIT_FAILURE);
} else {
libJack.unload();
}
QLibrary libSDL("libSDL-1.2.so.0");
if (!libSDL.load()) {
QMessageBox::critical(this, qApp->applicationName(),
tr("Error: This program requires the SDL 1.2 library.\n\nPlease install it using your package manager. It may be named libsdl1.2debian, SDL, or similar."));
::exit(EXIT_FAILURE);
} else {
libSDL.unload();
}
#endif
if (!qgetenv("OBSERVE_FOCUS").isEmpty())
connect(qApp, &QApplication::focusChanged,
this, &MainWindow::onFocusChanged);
qDebug() << "begin";
#ifndef Q_OS_WIN
new GLTestWidget(this);
#endif
Database::singleton(this);
m_autosaveTimer.setSingleShot(true);
m_autosaveTimer.setInterval(AUTOSAVE_TIMEOUT_MS);
connect(&m_autosaveTimer, SIGNAL(timeout()), this, SLOT(onAutosaveTimeout()));
// Initialize all QML types
QmlUtilities::registerCommonTypes();
// Create the UI.
ui->setupUi(this);
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
ui->mainToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
#endif
#ifdef Q_OS_MAC
// Qt 5 on OS X supports the standard Full Screen window widget.
ui->mainToolBar->removeAction(ui->actionFullscreen);
// OS X has a standard Full Screen shortcut we should use.
ui->actionEnter_Full_Screen->setShortcut(QKeySequence((Qt::CTRL + Qt::META + Qt::Key_F)));
#endif
setDockNestingEnabled(true);
// Connect UI signals.
connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(openVideo()));
connect(ui->actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
connect(this, SIGNAL(producerOpened()), this, SLOT(onProducerOpened()));
connect(ui->actionFullscreen, SIGNAL(triggered()), this, SLOT(on_actionEnter_Full_Screen_triggered()));
connect(ui->mainToolBar, SIGNAL(visibilityChanged(bool)), SLOT(onToolbarVisibilityChanged(bool)));
// Accept drag-n-drop of files.
this->setAcceptDrops(true);
// Setup the undo stack.
m_undoStack = new QUndoStack(this);
QAction *undoAction = m_undoStack->createUndoAction(this);
QAction *redoAction = m_undoStack->createRedoAction(this);
undoAction->setIcon(QIcon::fromTheme("edit-undo", QIcon(":/icons/oxygen/16x16/actions/edit-undo.png")));
redoAction->setIcon(QIcon::fromTheme("edit-redo", QIcon(":/icons/oxygen/32x32/actions/edit-redo.png")));
undoAction->setShortcut(QApplication::translate("MainWindow", "Ctrl+Z", 0));
redoAction->setShortcut(QApplication::translate("MainWindow", "Ctrl+Shift+Z", 0));
ui->menuEdit->addAction(undoAction);
ui->menuEdit->addAction(redoAction);
ui->actionUndo->setIcon(undoAction->icon());
ui->actionRedo->setIcon(redoAction->icon());
ui->actionUndo->setToolTip(undoAction->toolTip());
ui->actionRedo->setToolTip(redoAction->toolTip());
connect(m_undoStack, SIGNAL(canUndoChanged(bool)), ui->actionUndo, SLOT(setEnabled(bool)));
connect(m_undoStack, SIGNAL(canRedoChanged(bool)), ui->actionRedo, SLOT(setEnabled(bool)));
// Add the player widget.
m_player = new Player;
MLT.videoWidget()->installEventFilter(this);
ui->centralWidget->layout()->addWidget(m_player);
connect(this, SIGNAL(producerOpened()), m_player, SLOT(onProducerOpened()));
connect(m_player, SIGNAL(showStatusMessage(QString)), this, SLOT(showStatusMessage(QString)));
connect(m_player, SIGNAL(inChanged(int)), this, SLOT(onCutModified()));
connect(m_player, SIGNAL(outChanged(int)), this, SLOT(onCutModified()));
connect(MLT.videoWidget(), SIGNAL(started()), SLOT(processMultipleFiles()));
connect(MLT.videoWidget(), SIGNAL(paused()), m_player, SLOT(showPaused()));
connect(MLT.videoWidget(), SIGNAL(playing()), m_player, SLOT(showPlaying()));
setupSettingsMenu();
readPlayerSettings();
configureVideoWidget();
// Add the docks.
m_scopeController = new ScopeController(this, ui->menuView);
QDockWidget* audioMeterDock = findChild<QDockWidget*>("AudioPeakMeterDock");
if (audioMeterDock) {
connect(ui->actionAudioMeter, SIGNAL(triggered()), audioMeterDock->toggleViewAction(), SLOT(trigger()));
}
m_propertiesDock = new QDockWidget(tr("Properties"), this);
m_propertiesDock->hide();
m_propertiesDock->setObjectName("propertiesDock");
m_propertiesDock->setWindowIcon(ui->actionProperties->icon());
m_propertiesDock->toggleViewAction()->setIcon(ui->actionProperties->icon());
m_propertiesDock->setMinimumWidth(300);
QScrollArea* scroll = new QScrollArea;
scroll->setWidgetResizable(true);
m_propertiesDock->setWidget(scroll);
addDockWidget(Qt::LeftDockWidgetArea, m_propertiesDock);
ui->menuView->addAction(m_propertiesDock->toggleViewAction());
connect(m_propertiesDock->toggleViewAction(), SIGNAL(triggered(bool)), this, SLOT(onPropertiesDockTriggered(bool)));
connect(ui->actionProperties, SIGNAL(triggered()), this, SLOT(onPropertiesDockTriggered()));
m_recentDock = new RecentDock(this);
m_recentDock->hide();
addDockWidget(Qt::RightDockWidgetArea, m_recentDock);
ui->menuView->addAction(m_recentDock->toggleViewAction());
connect(m_recentDock, SIGNAL(itemActivated(QString)), this, SLOT(open(QString)));
connect(m_recentDock->toggleViewAction(), SIGNAL(triggered(bool)), this, SLOT(onRecentDockTriggered(bool)));
connect(ui->actionRecent, SIGNAL(triggered()), this, SLOT(onRecentDockTriggered()));
connect(this, SIGNAL(openFailed(QString)), m_recentDock, SLOT(remove(QString)));
m_playlistDock = new PlaylistDock(this);
m_playlistDock->hide();
addDockWidget(Qt::LeftDockWidgetArea, m_playlistDock);
ui->menuView->addAction(m_playlistDock->toggleViewAction());
connect(m_playlistDock->toggleViewAction(), SIGNAL(triggered(bool)), this, SLOT(onPlaylistDockTriggered(bool)));
connect(ui->actionPlaylist, SIGNAL(triggered()), this, SLOT(onPlaylistDockTriggered()));
connect(m_playlistDock, SIGNAL(clipOpened(void*)), this, SLOT(openCut(void*)));
connect(m_playlistDock, SIGNAL(itemActivated(int)), this, SLOT(seekPlaylist(int)));
connect(m_playlistDock, SIGNAL(showStatusMessage(QString)), this, SLOT(showStatusMessage(QString)));
connect(m_playlistDock->model(), SIGNAL(created()), this, SLOT(onPlaylistCreated()));
connect(m_playlistDock->model(), SIGNAL(cleared()), this, SLOT(onPlaylistCleared()));
connect(m_playlistDock->model(), SIGNAL(cleared()), this, SLOT(updateAutoSave()));
connect(m_playlistDock->model(), SIGNAL(closed()), this, SLOT(onPlaylistClosed()));
connect(m_playlistDock->model(), SIGNAL(modified()), this, SLOT(onPlaylistModified()));
connect(m_playlistDock->model(), SIGNAL(modified()), this, SLOT(updateAutoSave()));
connect(m_playlistDock->model(), SIGNAL(loaded()), this, SLOT(onPlaylistLoaded()));
if (!Settings.playerGPU())
connect(m_playlistDock->model(), SIGNAL(loaded()), this, SLOT(updateThumbnails()));
m_timelineDock = new TimelineDock(this);
m_timelineDock->hide();
addDockWidget(Qt::BottomDockWidgetArea, m_timelineDock);
ui->menuView->addAction(m_timelineDock->toggleViewAction());
connect(m_timelineDock->toggleViewAction(), SIGNAL(triggered(bool)), this, SLOT(onTimelineDockTriggered(bool)));
connect(ui->actionTimeline, SIGNAL(triggered()), SLOT(onTimelineDockTriggered()));
connect(m_player, SIGNAL(seeked(int)), m_timelineDock, SLOT(onSeeked(int)));
connect(m_timelineDock, SIGNAL(seeked(int)), SLOT(seekTimeline(int)));
connect(m_timelineDock, SIGNAL(clipClicked()), SLOT(moveNavigationPositionToCurrentSelection()));
connect(m_timelineDock->model(), SIGNAL(created()), SLOT(onMultitrackCreated()));
connect(m_timelineDock->model(), SIGNAL(closed()), SLOT(onMultitrackClosed()));
connect(m_timelineDock->model(), SIGNAL(modified()), SLOT(onMultitrackModified()));
connect(m_timelineDock->model(), SIGNAL(modified()), SLOT(updateAutoSave()));
connect(m_timelineDock, SIGNAL(clipOpened(void*)), SLOT(openCut(void*)));
connect(m_timelineDock->model(), SIGNAL(seeked(int)), SLOT(seekTimeline(int)));
connect(m_playlistDock, SIGNAL(addAllTimeline(Mlt::Playlist*)), SLOT(onTimelineDockTriggered()));
connect(m_playlistDock, SIGNAL(addAllTimeline(Mlt::Playlist*)), SLOT(onAddAllToTimeline(Mlt::Playlist*)));
connect(m_player, SIGNAL(previousSought()), m_timelineDock, SLOT(seekPreviousEdit()));
connect(m_player, SIGNAL(nextSought()), m_timelineDock, SLOT(seekNextEdit()));
m_filterController = new FilterController(this);
m_filtersDock = new FiltersDock(m_filterController->metadataModel(), m_filterController->attachedModel(), this);
m_filtersDock->hide();
addDockWidget(Qt::LeftDockWidgetArea, m_filtersDock);
ui->menuView->addAction(m_filtersDock->toggleViewAction());
connect(m_filtersDock, SIGNAL(currentFilterRequested(int)), m_filterController, SLOT(setCurrentFilter(int)), Qt::QueuedConnection);
connect(m_filtersDock->toggleViewAction(), SIGNAL(triggered(bool)), this, SLOT(onFiltersDockTriggered(bool)));
connect(ui->actionFilters, SIGNAL(triggered()), this, SLOT(onFiltersDockTriggered()));
connect(m_filterController, SIGNAL(currentFilterChanged(QmlFilter*, QmlMetadata*, int)), m_filtersDock, SLOT(setCurrentFilter(QmlFilter*, QmlMetadata*, int)), Qt::QueuedConnection);
connect(m_filterController, SIGNAL(currentFilterAboutToChange()), m_filtersDock, SLOT(clearCurrentFilter()));
connect(this, SIGNAL(producerOpened()), m_filterController, SLOT(setProducer()));
connect(m_filterController->attachedModel(), SIGNAL(changed()), SLOT(onFilterModelChanged()));
connect(m_filtersDock, SIGNAL(changed()), SLOT(onFilterModelChanged()));
connect(m_filterController, SIGNAL(statusChanged(QString)), this, SLOT(showStatusMessage(QString)));
connect(m_timelineDock, SIGNAL(fadeInChanged(int)), m_filtersDock, SLOT(setFadeInDuration(int)));
connect(m_timelineDock, SIGNAL(fadeOutChanged(int)), m_filtersDock, SLOT(setFadeOutDuration(int)));
connect(m_timelineDock, SIGNAL(trackSelected(Mlt::Producer*)), m_filterController, SLOT(setProducer(Mlt::Producer*)));
connect(m_timelineDock, SIGNAL(clipSelected(Mlt::Producer*)), m_filterController, SLOT(setProducer(Mlt::Producer*)));
m_historyDock = new QDockWidget(tr("History"), this);
m_historyDock->hide();
m_historyDock->setObjectName("historyDock");
m_historyDock->setWindowIcon(ui->actionHistory->icon());
m_historyDock->toggleViewAction()->setIcon(ui->actionHistory->icon());
m_historyDock->setMinimumWidth(150);
addDockWidget(Qt::RightDockWidgetArea, m_historyDock);
ui->menuView->addAction(m_historyDock->toggleViewAction());
connect(m_historyDock->toggleViewAction(), SIGNAL(triggered(bool)), this, SLOT(onHistoryDockTriggered(bool)));
connect(ui->actionHistory, SIGNAL(triggered()), this, SLOT(onHistoryDockTriggered()));
QUndoView* undoView = new QUndoView(m_undoStack, m_historyDock);
undoView->setObjectName("historyView");
undoView->setAlternatingRowColors(true);
undoView->setSpacing(2);
m_historyDock->setWidget(undoView);
ui->actionUndo->setDisabled(true);
ui->actionRedo->setDisabled(true);
m_encodeDock = new EncodeDock(this);
m_encodeDock->hide();
addDockWidget(Qt::LeftDockWidgetArea, m_encodeDock);
ui->menuView->addAction(m_encodeDock->toggleViewAction());
connect(this, SIGNAL(producerOpened()), m_encodeDock, SLOT(onProducerOpened()));
connect(ui->actionEncode, SIGNAL(triggered()), this, SLOT(onEncodeTriggered()));
connect(m_encodeDock->toggleViewAction(), SIGNAL(triggered(bool)), this, SLOT(onEncodeTriggered(bool)));
connect(m_encodeDock, SIGNAL(captureStateChanged(bool)), m_player, SLOT(onCaptureStateChanged(bool)));
connect(m_encodeDock, SIGNAL(captureStateChanged(bool)), m_propertiesDock, SLOT(setDisabled(bool)));
connect(m_encodeDock, SIGNAL(captureStateChanged(bool)), m_recentDock, SLOT(setDisabled(bool)));
connect(m_encodeDock, SIGNAL(captureStateChanged(bool)), m_filtersDock, SLOT(setDisabled(bool)));
connect(m_encodeDock, SIGNAL(captureStateChanged(bool)), ui->actionOpen, SLOT(setDisabled(bool)));
connect(m_encodeDock, SIGNAL(captureStateChanged(bool)), ui->actionOpenOther, SLOT(setDisabled(bool)));
connect(m_encodeDock, SIGNAL(captureStateChanged(bool)), ui->actionExit, SLOT(setDisabled(bool)));
connect(m_encodeDock, SIGNAL(captureStateChanged(bool)), this, SLOT(onCaptureStateChanged(bool)));
connect(m_encodeDock, SIGNAL(captureStateChanged(bool)), m_historyDock, SLOT(setDisabled(bool)));
connect(m_player, SIGNAL(profileChanged()), m_encodeDock, SLOT(onProfileChanged()));
connect(this, SIGNAL(profileChanged()), m_encodeDock, SLOT(onProfileChanged()));
m_encodeDock->onProfileChanged();
m_jobsDock = new JobsDock(this);
m_jobsDock->hide();
addDockWidget(Qt::RightDockWidgetArea, m_jobsDock);
ui->menuView->addAction(m_jobsDock->toggleViewAction());
connect(&JOBS, SIGNAL(jobAdded()), m_jobsDock, SLOT(show()));
connect(&JOBS, SIGNAL(jobAdded()), m_jobsDock, SLOT(raise()));
connect(m_jobsDock->toggleViewAction(), SIGNAL(triggered(bool)), this, SLOT(onJobsDockTriggered(bool)));
tabifyDockWidget(m_propertiesDock, m_playlistDock);
tabifyDockWidget(m_playlistDock, m_filtersDock);
tabifyDockWidget(m_filtersDock, m_encodeDock);
QDockWidget* audioWaveformDock = findChild<QDockWidget*>("AudioWaveformDock");
splitDockWidget(m_recentDock, audioWaveformDock, Qt::Vertical);
splitDockWidget(audioMeterDock, m_recentDock, Qt::Horizontal);
tabifyDockWidget(m_recentDock, m_historyDock);
tabifyDockWidget(m_historyDock, m_jobsDock);
m_recentDock->raise();
m_meltedServerDock = new MeltedServerDock(this);
m_meltedServerDock->hide();
addDockWidget(Qt::BottomDockWidgetArea, m_meltedServerDock);
m_meltedServerDock->toggleViewAction()->setIcon(m_meltedServerDock->windowIcon());
ui->menuView->addAction(m_meltedServerDock->toggleViewAction());
m_meltedPlaylistDock = new MeltedPlaylistDock(this);
m_meltedPlaylistDock->hide();
addDockWidget(Qt::BottomDockWidgetArea, m_meltedPlaylistDock);
splitDockWidget(m_meltedServerDock, m_meltedPlaylistDock, Qt::Horizontal);
m_meltedPlaylistDock->toggleViewAction()->setIcon(m_meltedPlaylistDock->windowIcon());
ui->menuView->addAction(m_meltedPlaylistDock->toggleViewAction());
connect(m_meltedServerDock, SIGNAL(connected(QString, quint16)), m_meltedPlaylistDock, SLOT(onConnected(QString,quint16)));
connect(m_meltedServerDock, SIGNAL(disconnected()), m_meltedPlaylistDock, SLOT(onDisconnected()));
connect(m_meltedServerDock, SIGNAL(unitActivated(quint8)), m_meltedPlaylistDock, SLOT(onUnitChanged(quint8)));
connect(m_meltedServerDock, SIGNAL(unitActivated(quint8)), this, SLOT(onMeltedUnitActivated()));
connect(m_meltedPlaylistDock, SIGNAL(appendRequested()), m_meltedServerDock, SLOT(onAppendRequested()));
connect(m_meltedServerDock, SIGNAL(append(QString,int,int)), m_meltedPlaylistDock, SLOT(onAppend(QString,int,int)));
connect(m_meltedPlaylistDock, SIGNAL(insertRequested(int)), m_meltedServerDock, SLOT(onInsertRequested(int)));
connect(m_meltedServerDock, SIGNAL(insert(QString,int,int,int)), m_meltedPlaylistDock, SLOT(onInsert(QString,int,int,int)));
connect(m_meltedServerDock, SIGNAL(unitOpened(quint8)), this, SLOT(onMeltedUnitOpened()));
connect(m_meltedServerDock, SIGNAL(unitOpened(quint8)), m_player, SLOT(onMeltedUnitOpened()));
connect(m_meltedServerDock->actionFastForward(), SIGNAL(triggered()), m_meltedPlaylistDock->transportControl(), SLOT(fastForward()));
connect(m_meltedServerDock->actionPause(), SIGNAL(triggered()), m_meltedPlaylistDock->transportControl(), SLOT(pause()));
connect(m_meltedServerDock->actionPlay(), SIGNAL(triggered()), m_meltedPlaylistDock->transportControl(), SLOT(play()));
connect(m_meltedServerDock->actionRewind(), SIGNAL(triggered()), m_meltedPlaylistDock->transportControl(), SLOT(rewind()));
connect(m_meltedServerDock->actionStop(), SIGNAL(triggered()), m_meltedPlaylistDock->transportControl(), SLOT(stop()));
connect(m_meltedServerDock, SIGNAL(openLocal(QString)), SLOT(open(QString)));
MeltedUnitsModel* unitsModel = (MeltedUnitsModel*) m_meltedServerDock->unitsModel();
MeltedPlaylistModel* playlistModel = (MeltedPlaylistModel*) m_meltedPlaylistDock->model();
connect(m_meltedServerDock, SIGNAL(connected(QString,quint16)), unitsModel, SLOT(onConnected(QString,quint16)));
connect(unitsModel, SIGNAL(clipIndexChanged(quint8, int)), playlistModel, SLOT(onClipIndexChanged(quint8, int)));
connect(unitsModel, SIGNAL(generationChanged(quint8)), playlistModel, SLOT(onGenerationChanged(quint8)));
// connect video widget signals
Mlt::GLWidget* videoWidget = (Mlt::GLWidget*) &(MLT);
connect(videoWidget, SIGNAL(dragStarted()), m_playlistDock, SLOT(onPlayerDragStarted()));
connect(videoWidget, SIGNAL(seekTo(int)), m_player, SLOT(seek(int)));
connect(videoWidget, SIGNAL(gpuNotSupported()), this, SLOT(onGpuNotSupported()));
connect(videoWidget, SIGNAL(frameDisplayed(const SharedFrame&)), m_scopeController, SLOT(onFrameDisplayed(const SharedFrame&)));
connect(m_filterController, SIGNAL(currentFilterChanged(QmlFilter*, QmlMetadata*, int)), videoWidget, SLOT(setCurrentFilter(QmlFilter*, QmlMetadata*)), Qt::QueuedConnection);
connect(m_filterController, SIGNAL(currentFilterAboutToChange()), videoWidget, SLOT(setBlankScene()));
readWindowSettings();
setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
setCorner(Qt::BottomLeftCorner, Qt::BottomDockWidgetArea);
setCorner(Qt::BottomRightCorner, Qt::BottomDockWidgetArea);
setDockNestingEnabled(true);
setFocus();
setCurrentFile("");
LeapNetworkListener* leap = new LeapNetworkListener(this);
connect(leap, SIGNAL(shuttle(float)), SLOT(onShuttle(float)));
connect(leap, SIGNAL(jogRightFrame()), SLOT(stepRightOneFrame()));
connect(leap, SIGNAL(jogRightSecond()), SLOT(stepRightOneSecond()));
connect(leap, SIGNAL(jogLeftFrame()), SLOT(stepLeftOneFrame()));
connect(leap, SIGNAL(jogLeftSecond()), SLOT(stepLeftOneSecond()));
qDebug() << "end";
}
void MainWindow::moveNavigationPositionToCurrentSelection()
{
TimelineDock * t = m_timelineDock;
if (t->selection().isEmpty())
return;
m_navigationPosition = t->centerOfClip(t->currentTrack(), t->selection().first());
}
void MainWindow::onAddAllToTimeline(Mlt::Playlist* playlist)
{
// We stop the player because of a bug on Windows that results in some
// strange memory leak when using Add All To Timeline, more noticeable
// with (high res?) still image files.
if (MLT.isSeekable())
m_player->pause();
else
m_player->stop();
m_timelineDock->appendFromPlaylist(playlist);
}
MainWindow& MainWindow::singleton()
{
static MainWindow* instance = new MainWindow;
return *instance;
}
MainWindow::~MainWindow()
{
m_autosaveMutex.lock();
delete m_autosaveFile;
m_autosaveFile = 0;
m_autosaveMutex.unlock();
delete m_htmlEditor;
delete ui;
Mlt::Controller::destroy();
}
void MainWindow::setupSettingsMenu()
{
qDebug() << "begin";
QActionGroup* group = new QActionGroup(this);
group->addAction(ui->actionOneField);
group->addAction(ui->actionLinearBlend);
group->addAction(ui->actionYadifTemporal);
group->addAction(ui->actionYadifSpatial);
group = new QActionGroup(this);
group->addAction(ui->actionNearest);
group->addAction(ui->actionBilinear);
group->addAction(ui->actionBicubic);
group->addAction(ui->actionHyper);
if (Settings.playerGPU()) {
group = new QActionGroup(this);
group->addAction(ui->actionGammaRec709);
group->addAction(ui->actionGammaSRGB);
} else {
delete ui->menuGamma;
}
m_profileGroup = new QActionGroup(this);
m_profileGroup->addAction(ui->actionProfileAutomatic);
ui->actionProfileAutomatic->setData(QString());
ui->menuProfile->addAction(addProfile(m_profileGroup, "HD 720p 50 fps", "atsc_720p_50"));
ui->menuProfile->addAction(addProfile(m_profileGroup, "HD 720p 59.94 fps", "atsc_720p_5994"));
ui->menuProfile->addAction(addProfile(m_profileGroup, "HD 720p 60 fps", "atsc_720p_60"));
ui->menuProfile->addAction(addProfile(m_profileGroup, "HD 1080i 25 fps", "atsc_1080i_50"));
ui->menuProfile->addAction(addProfile(m_profileGroup, "HD 1080i 29.97 fps", "atsc_1080i_5994"));
ui->menuProfile->addAction(addProfile(m_profileGroup, "HD 1080p 23.98 fps", "atsc_1080p_2398"));
ui->menuProfile->addAction(addProfile(m_profileGroup, "HD 1080p 24 fps", "atsc_1080p_24"));
ui->menuProfile->addAction(addProfile(m_profileGroup, "HD 1080p 25 fps", "atsc_1080p_25"));
ui->menuProfile->addAction(addProfile(m_profileGroup, "HD 1080p 29.97 fps", "atsc_1080p_2997"));
ui->menuProfile->addAction(addProfile(m_profileGroup, "HD 1080p 30 fps", "atsc_1080p_30"));
ui->menuProfile->addAction(addProfile(m_profileGroup, "SD NTSC", "dv_ntsc"));
ui->menuProfile->addAction(addProfile(m_profileGroup, "SD PAL", "dv_pal"));
ui->menuProfile->addAction(addProfile(m_profileGroup, "UHD 2160p 23.98 fps", "uhd_2160p_2398"));
ui->menuProfile->addAction(addProfile(m_profileGroup, "UHD 2160p 24 fps", "uhd_2160p_24"));
ui->menuProfile->addAction(addProfile(m_profileGroup, "UHD 2160p 25 fps", "uhd_2160p_25"));
ui->menuProfile->addAction(addProfile(m_profileGroup, "UHD 2160p 29.97 fps", "uhd_2160p_2997"));
ui->menuProfile->addAction(addProfile(m_profileGroup, "UHD 2160p 30 fps", "uhd_2160p_30"));
ui->menuProfile->addAction(addProfile(m_profileGroup, "UHD 2160p 50 fps", "uhd_2160p_50"));
ui->menuProfile->addAction(addProfile(m_profileGroup, "UHD 2160p 59.94 fps", "uhd_2160p_5994"));
ui->menuProfile->addAction(addProfile(m_profileGroup, "UHD 2160p 60 fps", "uhd_2160p_60"));
QMenu* menu = ui->menuProfile->addMenu(tr("Non-Broadcast"));
menu->addAction(addProfile(m_profileGroup, "HD 720p 23.98 fps", "atsc_720p_2398"));
menu->addAction(addProfile(m_profileGroup, "HD 720p 24 fps", "atsc_720p_24"));
menu->addAction(addProfile(m_profileGroup, "HD 720p 25 fps", "atsc_720p_25"));
menu->addAction(addProfile(m_profileGroup, "HD 720p 29.97 fps", "atsc_720p_2997"));
menu->addAction(addProfile(m_profileGroup, "HD 720p 30 fps", "atsc_720p_30"));
menu->addAction(addProfile(m_profileGroup, "HD 1080i 60 fps", "atsc_1080i_60"));
menu->addAction(addProfile(m_profileGroup, "HDV 1080i 25 fps", "hdv_1080_50i"));
menu->addAction(addProfile(m_profileGroup, "HDV 1080i 29.97 fps", "hdv_1080_60i"));
menu->addAction(addProfile(m_profileGroup, "HDV 1080p 25 fps", "hdv_1080_25p"));
menu->addAction(addProfile(m_profileGroup, "HDV 1080p 29.97 fps", "hdv_1080_30p"));
menu->addAction(addProfile(m_profileGroup, tr("DVD Widescreen NTSC"), "dv_ntsc_wide"));
menu->addAction(addProfile(m_profileGroup, tr("DVD Widescreen PAL"), "dv_pal_wide"));
menu->addAction(addProfile(m_profileGroup, "640x480 4:3 NTSC", "square_ntsc"));
menu->addAction(addProfile(m_profileGroup, "768x576 4:3 PAL", "square_pal"));
menu->addAction(addProfile(m_profileGroup, "854x480 16:9 NTSC", "square_ntsc_wide"));
menu->addAction(addProfile(m_profileGroup, "1024x576 16:9 PAL", "square_pal_wide"));
m_customProfileMenu = ui->menuProfile->addMenu(tr("Custom"));
m_customProfileMenu->addAction(ui->actionAddCustomProfile);
// Load custom profiles
QDir dir(QStandardPaths::standardLocations(QStandardPaths::DataLocation).first());
if (dir.cd("profiles")) {
QStringList profiles = dir.entryList(QDir::Files | QDir::NoDotAndDotDot | QDir::Readable);
if (profiles.length() > 0)
m_customProfileMenu->addSeparator();
foreach (QString name, profiles)
m_customProfileMenu->addAction(addProfile(m_profileGroup, name, dir.filePath(name)));
}
// Add the SDI and HDMI devices to the Settings menu.
m_externalGroup = new QActionGroup(this);
ui->actionExternalNone->setData(QString());
m_externalGroup->addAction(ui->actionExternalNone);
int n = QApplication::desktop()->screenCount();
for (int i = 0; n > 1 && i < n; i++) {
QAction* action = new QAction(tr("Screen %1").arg(i), this);
action->setCheckable(true);
action->setData(i);
m_externalGroup->addAction(action);
}
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
Mlt::Consumer linsys(MLT.profile(), "sdi");
if (linsys.is_valid()) {
QAction* action = new QAction("DVEO VidPort", this);
action->setCheckable(true);
action->setData(QString("sdi"));
m_externalGroup->addAction(action);
}
#endif
Mlt::Profile profile;
Mlt::Consumer decklink(profile, "decklink:");
if (decklink.is_valid()) {
decklink.set("list_devices", 1);
int n = decklink.get_int("devices");
for (int i = 0; i < n; ++i) {
QString device(decklink.get(QString("device.%1").arg(i).toLatin1().constData()));
if (!device.isEmpty()) {
QAction* action = new QAction(device, this);
action->setCheckable(true);
action->setData(QString("decklink:%1").arg(i));
m_externalGroup->addAction(action);
if (!m_keyerGroup) {
m_keyerGroup = new QActionGroup(this);
action = new QAction(tr("Off"), m_keyerGroup);
action->setData(QVariant(0));
action->setCheckable(true);
action = new QAction(tr("Internal"), m_keyerGroup);
action->setData(QVariant(1));
action->setCheckable(true);
action = new QAction(tr("External"), m_keyerGroup);
action->setData(QVariant(2));
action->setCheckable(true);
}
}
}
}
if (m_externalGroup->actions().count() > 1)
ui->menuExternal->addActions(m_externalGroup->actions());
else {
delete ui->menuExternal;
ui->menuExternal = 0;
}
if (m_keyerGroup) {
m_keyerMenu = ui->menuExternal->addMenu(tr("DeckLink Keyer"));
m_keyerMenu->addActions(m_keyerGroup->actions());
m_keyerMenu->setDisabled(true);
connect(m_keyerGroup, SIGNAL(triggered(QAction*)), this, SLOT(onKeyerTriggered(QAction*)));
}
connect(m_externalGroup, SIGNAL(triggered(QAction*)), this, SLOT(onExternalTriggered(QAction*)));
connect(m_profileGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProfileTriggered(QAction*)));
// Setup the language menu actions
m_languagesGroup = new QActionGroup(this);
QAction* a = new QAction(QLocale::languageToString(QLocale::Catalan), m_languagesGroup);
a->setCheckable(true);
a->setData("ca");
ui->menuLanguage->addActions(m_languagesGroup->actions());
a = new QAction(QLocale::languageToString(QLocale::Chinese), m_languagesGroup);
a->setCheckable(true);
a->setData("zh");
a = new QAction(QLocale::languageToString(QLocale::Czech), m_languagesGroup);
a->setCheckable(true);
a->setData("cs");
ui->menuLanguage->addActions(m_languagesGroup->actions());
a = new QAction(QLocale::languageToString(QLocale::Danish), m_languagesGroup);
a->setCheckable(true);
a->setData("da");
ui->menuLanguage->addActions(m_languagesGroup->actions());
a = new QAction(QLocale::languageToString(QLocale::Dutch), m_languagesGroup);
a->setCheckable(true);
a->setData("nl");
ui->menuLanguage->addActions(m_languagesGroup->actions());
a = new QAction(QLocale::languageToString(QLocale::English), m_languagesGroup);
a->setCheckable(true);
a->setData("en");
ui->menuLanguage->addActions(m_languagesGroup->actions());
a = new QAction(QLocale::languageToString(QLocale::Greek), m_languagesGroup);
a->setCheckable(true);
a->setData("el");
ui->menuLanguage->addActions(m_languagesGroup->actions());
a = new QAction(QLocale::languageToString(QLocale::French), m_languagesGroup);
a->setCheckable(true);
a->setData("fr");
ui->menuLanguage->addActions(m_languagesGroup->actions());
a = new QAction(QLocale::languageToString(QLocale::German), m_languagesGroup);
a->setCheckable(true);
a->setData("de");
a = new QAction(QLocale::languageToString(QLocale::Italian), m_languagesGroup);
a->setCheckable(true);
a->setData("it");
ui->menuLanguage->addActions(m_languagesGroup->actions());
a = new QAction(QLocale::languageToString(QLocale::Polish), m_languagesGroup);
a->setCheckable(true);
a->setData("pl");
ui->menuLanguage->addActions(m_languagesGroup->actions());
a = new QAction(QLocale::languageToString(QLocale::Portuguese).append(" (Brazil)"), m_languagesGroup);
a->setCheckable(true);
a->setData("pt_BR");
ui->menuLanguage->addActions(m_languagesGroup->actions());
a = new QAction(QLocale::languageToString(QLocale::Portuguese).append(" (Portugal)"), m_languagesGroup);
a->setCheckable(true);
a->setData("pt_PT");
ui->menuLanguage->addActions(m_languagesGroup->actions());
a = new QAction(QLocale::languageToString(QLocale::Spanish), m_languagesGroup);
a->setCheckable(true);
a->setData("es");
ui->menuLanguage->addActions(m_languagesGroup->actions());
a = new QAction(QLocale::languageToString(QLocale::Russian), m_languagesGroup);
a->setCheckable(true);
a->setData("ru");
ui->menuLanguage->addActions(m_languagesGroup->actions());
const QString locale = Settings.language();
foreach (QAction* action, m_languagesGroup->actions()) {
if (action->data().toString().startsWith(locale)) {
action->setChecked(true);
break;
}
}
connect(m_languagesGroup, SIGNAL(triggered(QAction*)), this, SLOT(onLanguageTriggered(QAction*)));
// Setup the themes actions
group = new QActionGroup(this);
group->addAction(ui->actionSystemTheme);
group->addAction(ui->actionFusionDark);
group->addAction(ui->actionFusionLight);
if (Settings.theme() == "dark")
ui->actionFusionDark->setChecked(true);
else if (Settings.theme() == "light")
ui->actionFusionLight->setChecked(true);
else
ui->actionSystemTheme->setChecked(true);
// Setup the display method actions.
#ifdef Q_OS_WIN
if (!Settings.playerGPU()) {
group = new QActionGroup(this);
ui->actionDrawingAutomatic->setData(0);
group->addAction(ui->actionDrawingAutomatic);
ui->actionDrawingDirectX->setData(Qt::AA_UseOpenGLES);
group->addAction(ui->actionDrawingDirectX);
ui->actionDrawingOpenGL->setData(Qt::AA_UseDesktopOpenGL);
group->addAction(ui->actionDrawingOpenGL);
// Software rendering is not currently working.
delete ui->actionDrawingSoftware;
// ui->actionDrawingSoftware->setData(Qt::AA_UseSoftwareOpenGL);
// group->addAction(ui->actionDrawingSoftware);
connect(group, SIGNAL(triggered(QAction*)), this, SLOT(onDrawingMethodTriggered(QAction*)));
switch (Settings.drawMethod()) {
case Qt::AA_UseDesktopOpenGL:
ui->actionDrawingOpenGL->setChecked(true);
break;
case Qt::AA_UseOpenGLES:
delete ui->actionGPU;
ui->actionGPU = 0;
ui->actionDrawingDirectX->setChecked(true);
break;
case Qt::AA_UseSoftwareOpenGL:
delete ui->actionGPU;
ui->actionGPU = 0;
ui->actionDrawingSoftware->setChecked(true);
break;
default:
ui->actionDrawingAutomatic->setChecked(true);
break;
}
} else {
// GPU mode only works with OpenGL.
delete ui->menuDrawingMethod;
ui->menuDrawingMethod = 0;
}
#else
delete ui->menuDrawingMethod;
ui->menuDrawingMethod = 0;
#endif
qDebug() << "end";
}
QAction* MainWindow::addProfile(QActionGroup* actionGroup, const QString& desc, const QString& name)
{
QAction* action = new QAction(desc, this);
action->setCheckable(true);
action->setData(name);
actionGroup->addAction(action);
return action;
}
void MainWindow::open(Mlt::Producer* producer)
{
if (!producer->is_valid())
ui->statusBar->showMessage(tr("Failed to open "), STATUS_TIMEOUT_MS);
else if (producer->get_int("error"))
ui->statusBar->showMessage(tr("Failed to open ") + producer->get("resource"), STATUS_TIMEOUT_MS);
bool ok = false;
int screen = Settings.playerExternal().toInt(&ok);
if (ok && screen != QApplication::desktop()->screenNumber(this))
m_player->moveVideoToScreen(screen);
// no else here because open() will delete the producer if open fails
if (!MLT.setProducer(producer))
emit producerOpened();
m_player->setFocus();
m_playlistDock->setUpdateButtonEnabled(false);
// Needed on Windows. Upon first file open, window is deactivated, perhaps OpenGL-related.
activateWindow();
}
bool MainWindow::isCompatibleWithGpuMode(MltXmlChecker& checker)
{
if (checker.needsGPU() && !Settings.playerGPU()) {
QMessageBox dialog(QMessageBox::Question,
qApp->applicationName(),
tr("The file you opened uses GPU effects, but GPU processing is not enabled.\n"
"Do you want to enable GPU processing and restart?"),
QMessageBox::No |
QMessageBox::Yes,
this);
dialog.setWindowModality(QmlApplication::dialogModality());
dialog.setDefaultButton(QMessageBox::Yes);
dialog.setEscapeButton(QMessageBox::No);
int r = dialog.exec();
if (r == QMessageBox::Yes) {
Settings.setPlayerGPU(true);
m_exitCode = EXIT_RESTART;
QApplication::closeAllWindows();
}
return false;
}
return true;
}
bool MainWindow::isXmlRepaired(MltXmlChecker& checker, QString& fileName)
{
if (checker.isCorrected()) {
QMessageBox dialog(QMessageBox::Question,
qApp->applicationName(),
tr("Shotcut noticed some problems in your project.\n"
"Do you want Shotcut to try to repair it?\n\n"
"If you choose Yes, Shotcut will create a copy of your project\n"
"with \"- Repaired\" in the file name and open it."),
QMessageBox::No |
QMessageBox::Yes,
this);
dialog.setWindowModality(QmlApplication::dialogModality());
dialog.setDefaultButton(QMessageBox::Yes);
dialog.setEscapeButton(QMessageBox::No);
int r = dialog.exec();
if (r == QMessageBox::Yes) {
QFileInfo fi(fileName);
QFile repaired(QString("%1/%2 - %3.%4").arg(fi.path())
.arg(fi.completeBaseName()).arg(tr("Repaired")).arg(fi.suffix()));
repaired.open(QIODevice::WriteOnly);
qDebug() << "repaired MLT XML file name" << repaired.fileName();
QFile temp(checker.tempFileName());
if (temp.exists() && repaired.exists()) {
temp.open(QIODevice::ReadOnly);
QByteArray xml = temp.readAll();
temp.close();
qint64 n = repaired.write(xml);
while (n > 0 && n < xml.size()) {
qint64 x = repaired.write(xml.right(xml.size() - n));
if (x > 0)
n += x;
else
n = x;
}
repaired.close();
if (n == xml.size()) {
fileName = repaired.fileName();
return true;
}
}
QMessageBox::warning(this, qApp->applicationName(), tr("Repairing the project failed."));
}
}
return false;
}
bool MainWindow::checkAutoSave(QString &url)
{
QMutexLocker locker(&m_autosaveMutex);
// check whether autosave files exist:
AutoSaveFile* stale = AutoSaveFile::getFile(url);
if (stale) {
QMessageBox dialog(QMessageBox::Question, qApp->applicationName(),
tr("Auto-saved files exist. Do you want to recover them now?"),
QMessageBox::No | QMessageBox::Yes, this);
dialog.setWindowModality(QmlApplication::dialogModality());
dialog.setDefaultButton(QMessageBox::Yes);
dialog.setEscapeButton(QMessageBox::No);
int r = dialog.exec();
if (r == QMessageBox::Yes) {
if (!stale->open(QIODevice::ReadWrite)) {
qWarning() << "failed to recover autosave file" << url;
delete stale;
} else {
delete m_autosaveFile;
m_autosaveFile = stale;
url = stale->fileName();
return true;
}
} else {
// remove the stale file
delete stale;
}
}
// create new autosave object
delete m_autosaveFile;
m_autosaveFile = new AutoSaveFile(url);
return false;
}
void MainWindow::stepLeftBySeconds(int sec)
{
m_player->seek(m_player->position() + sec * qRound(MLT.profile().fps()));
}
void MainWindow::doAutosave()
{
m_autosaveMutex.lock();
if (m_autosaveFile) {
if (m_autosaveFile->isOpen() || m_autosaveFile->open(QIODevice::ReadWrite)) {
saveXML(m_autosaveFile->fileName());
} else {
qWarning() << "failed to open autosave file for writing" << m_autosaveFile->fileName();
}
}
m_autosaveMutex.unlock();
}
void MainWindow::setFullScreen(bool isFullScreen)
{
if (isFullScreen) {
showFullScreen();
ui->actionEnter_Full_Screen->setVisible(false);
ui->actionFullscreen->setVisible(false);
}
}
QString MainWindow::removeFileScheme(QUrl &url)
{
QString path = url.url();
if (url.scheme() == "file")
path = url.url(QUrl::RemoveScheme);
if (path.length() > 2 && path.startsWith("///"))
#ifdef Q_OS_WIN
path.remove(0, 3);
#else
path.remove(0, 2);
#endif
return path;
}
static void autosaveTask(MainWindow* p)
{
qDebug() << "running";
p->doAutosave();
}
void MainWindow::onAutosaveTimeout()
{
if (isWindowModified())
QtConcurrent::run(autosaveTask, this);
}
void MainWindow::updateAutoSave()
{
if (!m_autosaveTimer.isActive())
m_autosaveTimer.start();
}
void MainWindow::open(QString url, const Mlt::Properties* properties)
{
bool modified = false;
MltXmlChecker checker;
if (checker.check(url)) {
if (!isCompatibleWithGpuMode(checker))
return;
}
if (url.endsWith(".mlt") || url.endsWith(".xml")) {
// only check for a modified project when loading a project, not a simple producer
if (!continueModified())
return;
// close existing project
if (playlist())
m_playlistDock->model()->close();
if (multitrack())
m_timelineDock->model()->close();
// let the new project change the profile
MLT.profile().set_explicit(false);
if (!isXmlRepaired(checker, url))
modified = checkAutoSave(url);
setWindowModified(modified);
}
if (!playlist() && !multitrack()) {
if (!modified && !continueModified())
return;
setCurrentFile("");
setWindowModified(modified);
MLT.resetURL();
// Return to automatic video mode if selected.
if (m_profileGroup->checkedAction()->data().toString().isEmpty())
MLT.profile().set_explicit(false);
}
if (!MLT.open(url)) {
Mlt::Properties* props = const_cast<Mlt::Properties*>(properties);
if (props && props->is_valid())
mlt_properties_inherit(MLT.producer()->get_properties(), props->get_properties());
m_player->setPauseAfterOpen(!MLT.isClip());
open(MLT.producer());
m_recentDock->add(m_autosaveFile? m_autosaveFile->managedFileName() : url);
}
else {
ui->statusBar->showMessage(tr("Failed to open ") + url, STATUS_TIMEOUT_MS);
emit openFailed(url);
}
}
void MainWindow::openVideo()
{
QString path = Settings.openPath();
#ifdef Q_OS_MAC
path.append("/*");
#endif
QStringList filenames = QFileDialog::getOpenFileNames(this, tr("Open File"), path);
if (filenames.length() > 0) {
Settings.setOpenPath(QFileInfo(filenames.first()).path());
activateWindow();
if (filenames.length() > 1)
m_multipleFiles = filenames;
open(filenames.first());
}
else {
// If file invalid, then on some platforms the dialog messes up SDL.
MLT.onWindowResize();
activateWindow();
}
}
void MainWindow::openCut(void* producer)
{
m_player->setPauseAfterOpen(true);
Mlt::Producer* p = (Mlt::Producer*) producer;
open(p);
MLT.seek(p->get_in());
}
void MainWindow::showStatusMessage(QString message)
{
ui->statusBar->showMessage(message, STATUS_TIMEOUT_MS);
}
void MainWindow::seekPlaylist(int start)
{
if (!playlist()) return;
// we bypass this->open() to prevent sending producerOpened signal to self, which causes to reload playlist
if (!MLT.producer() || (void*) MLT.producer()->get_producer() != (void*) playlist()->get_playlist())
MLT.setProducer(new Mlt::Producer(*playlist()));
m_player->setIn(-1);
m_player->setOut(-1);
// since we do not emit producerOpened, these components need updating
on_actionJack_triggered(ui->actionJack->isChecked());
m_player->onProducerOpened(false);
m_encodeDock->onProducerOpened();
m_filterController->setProducer();
updateMarkers();
MLT.seek(start);
m_player->setFocus();
m_player->switchToTab(Player::ProgramTabIndex);
}
void MainWindow::seekTimeline(int position)
{
if (!multitrack()) return;
// we bypass this->open() to prevent sending producerOpened signal to self, which causes to reload playlist
if (MLT.producer() && (void*) MLT.producer()->get_producer() != (void*) multitrack()->get_producer()) {
MLT.setProducer(new Mlt::Producer(*multitrack()));
m_player->setIn(-1);
m_player->setOut(-1);