From fda1ba64daa6aadcbc9e176c3a9221abbf9a7318 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Fri, 4 Jan 2019 18:55:14 +1100 Subject: [PATCH] fix #242 --- main.cpp | 5 +++-- mainwindow.cpp | 31 ++++++++++++++++++++++++------- mainwindow.h | 8 ++++++++ 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/main.cpp b/main.cpp index 4286a3bd0..8dd018067 100644 --- a/main.cpp +++ b/main.cpp @@ -9,10 +9,11 @@ extern "C" { int main(int argc, char *argv[]) { // init ffmpeg subsystem av_register_all(); - avfilter_register_all(); + avfilter_register_all(); - QApplication a(argc, argv); + QApplication a(argc, argv); MainWindow w; + if (argc > 1) w.launch_with_project(argv[1]); w.showMaximized(); return a.exec(); diff --git a/mainwindow.cpp b/mainwindow.cpp index f84212d13..2d1f6b7b1 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -96,6 +96,8 @@ void MainWindow::setup_layout(bool reset) { MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { + enable_launch_with_project = false; + setup_debug(); mainWindow = this; @@ -211,8 +213,7 @@ MainWindow::MainWindow(QWidget *parent) : autorecovery_filename = data_dir + "/autorecovery.ove"; if (QFile::exists(autorecovery_filename)) { if (QMessageBox::question(NULL, "Auto-recovery", "Olive didn't close properly and an autorecovery file was detected. Would you like to open it?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) { - updateTitle(autorecovery_filename); - panel_project->load_project(true); + open_project_worker(autorecovery_filename, true); } } autorecovery_timer.setInterval(60000); @@ -268,6 +269,11 @@ MainWindow::~MainWindow() { close_debug(); } +void MainWindow::launch_with_project(const char* s) { + project_url = s; + enable_launch_with_project = true; +} + void MainWindow::make_new_menu(QMenu *parent) { parent->addAction("&Project", this, SLOT(new_project()), QKeySequence("Ctrl+N")); parent->addSeparator(); @@ -810,6 +816,10 @@ void MainWindow::closeEvent(QCloseEvent *e) { void MainWindow::paintEvent(QPaintEvent *event) { QMainWindow::paintEvent(event); + if (enable_launch_with_project) { + QTimer::singleShot(10, this, SLOT(load_with_launch())); + enable_launch_with_project = false; + } #ifndef QT_DEBUG if (!demoNoticeShown) { DemoNotice* d = new DemoNotice(this); @@ -826,12 +836,20 @@ void MainWindow::clear_undo_stack() { void MainWindow::open_project() { QString fn = QFileDialog::getOpenFileName(this, "Open Project...", "", OLIVE_FILE_FILTER); if (!fn.isEmpty() && can_close_project()) { - updateTitle(fn); - panel_project->load_project(false); - undo_stack.clear(); + open_project_worker(fn, false); } } +void MainWindow::open_project_worker(const QString& fn, bool autorecovery) { + updateTitle(fn); + panel_project->load_project(autorecovery); + undo_stack.clear(); +} + +void MainWindow::load_with_launch() { + open_project_worker(project_url, false); +} + void MainWindow::reset_layout() { setup_layout(true); } @@ -1012,8 +1030,7 @@ void MainWindow::load_recent_project() { panel_project->save_recent_projects(); } } else if (can_close_project()) { - updateTitle(recent_url); - panel_project->load_project(false); + open_project_worker(recent_url, false); } } diff --git a/mainwindow.h b/mainwindow.h index 043b083b3..fc9f32e88 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -15,6 +15,8 @@ public: void updateTitle(const QString &url); ~MainWindow(); + void launch_with_project(const char *s); + void make_new_menu(QMenu* parent); void make_inout_menu(QMenu* parent); @@ -111,6 +113,10 @@ private slots: void toggle_panel_visibility(); void set_timecode_view(); + void open_project_worker(const QString &fn, bool autorecovery); + + void load_with_launch(); + private: void setup_layout(bool reset); bool can_close_project(); @@ -169,6 +175,8 @@ private: void set_bool_action_checked(QAction* a); void set_int_action_checked(QAction* a, const int& i); void set_button_action_checked(QAction* a); + + bool enable_launch_with_project; }; extern MainWindow* mainWindow;