diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/gui_gtk.cc | 23 | ||||
| -rw-r--r-- | src/gui_main.hh | 1 | ||||
| -rw-r--r-- | src/gui_qt.cc | 23 | ||||
| -rw-r--r-- | src/monitor-gui.cc | 15 |
4 files changed, 58 insertions, 4 deletions
diff --git a/src/gui_gtk.cc b/src/gui_gtk.cc index c134e5f..20b23ec 100644 --- a/src/gui_gtk.cc +++ b/src/gui_gtk.cc @@ -682,6 +682,13 @@ public: } } + void notify_open(std::string const& file) { + auto it = observers_.notify(); + while (it.has_next()) { + it.next()->open(this, file); + } + } + void add_to_clipboard(std::string const& data, std::string const& mimetype) override { auto clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); @@ -1814,17 +1821,27 @@ void main_app_activate(GApplication* g_app) { app->main_->sync_split(); } -void main_app_window_open(MainAppWindow*, GFile*) { +bool main_app_window_open(MainApp* app, MainAppWindow*, GFile* file) { + auto path = g_file_get_path(file); + if (!path) return false; + app->main_->notify_open(path); + g_free(path); + return true; } void main_app_open(GApplication* app, GFile** files, gint n_files, gchar const*) { + auto menu = static_cast<GtkGuiMenu*>(MAIN_APP(app)->main_->menu()); + if (menu) { + menu->set_map(G_ACTION_MAP(app)); + gtk_application_set_menubar(GTK_APPLICATION(app), menu->model()); + } auto windows = gtk_application_get_windows(GTK_APPLICATION(app)); auto win = windows ? MAIN_APP_WINDOW(windows->data) : main_app_window_new(MAIN_APP(app)); gtk_window_set_title(GTK_WINDOW(win), MAIN_APP(app)->main_->title().c_str()); - for (auto i = 0; i < n_files; i++) { - main_app_window_open(win, files[i]); + for (gint i = 0; i < n_files; ++i) { + if (main_app_window_open(MAIN_APP(app), win, files[i])) break; } gtk_window_present(GTK_WINDOW(win)); diff --git a/src/gui_main.hh b/src/gui_main.hh index 3b98b71..1baee2f 100644 --- a/src/gui_main.hh +++ b/src/gui_main.hh @@ -26,6 +26,7 @@ public: virtual bool about_to_exit(GuiMain* main) = 0; virtual void selected_row(GuiMain* main, size_t index) = 0; virtual void lost_selection(GuiMain* main) = 0; + virtual void open(GuiMain* main, std::string const& file) = 0; protected: Listener() {} diff --git a/src/gui_qt.cc b/src/gui_qt.cc index 5cd16f9..4d6eba1 100644 --- a/src/gui_qt.cc +++ b/src/gui_qt.cc @@ -7,6 +7,7 @@ #include <QCheckBox> #include <QClipboard> #include <QCloseEvent> +#include <QCommandLineParser> #include <QDialogButtonBox> #include <QFileDialog> #include <QGridLayout> @@ -560,6 +561,13 @@ private: } } + void notify_open(std::string const& file) { + auto it = observers_.notify(); + while (it.has_next()) { + it.next()->open(this, file); + } + } + std::string title_; uint32_t width_; uint32_t height_; @@ -1571,6 +1579,15 @@ private: bool QtGuiMain::run(int argc, char** argv) { QApplication app(argc, argv); + app.setApplicationName(QString::fromStdString(title_)); + app.setApplicationVersion(VERSION); + + QCommandLineParser parser; + parser.addHelpOption(); + parser.addVersionOption(); + parser.addPositionalArgument("FILE", "Package capture to load"); + parser.process(app); + app.setStyleSheet("QStatusBar::item { border: 0px }"); main_.reset(new QMainWindow()); main_->setWindowTitle(QString::fromStdString(title_)); @@ -1614,6 +1631,12 @@ bool QtGuiMain::run(int argc, char** argv) { } main_->show(); set_split(split_); + + auto args = parser.positionalArguments(); + if (args.size() > 0) { + notify_open(args[0].toStdString()); + } + auto ret = app.exec() == 0; layout_.reset(); top_ = nullptr; diff --git a/src/monitor-gui.cc b/src/monitor-gui.cc index 4abdd21..3419025 100644 --- a/src/monitor-gui.cc +++ b/src/monitor-gui.cc @@ -927,6 +927,16 @@ public: menu_->enable_item(ACTION_COPY_TEXT, false); } + void open(GuiMain*, std::string const& file) override { + if (abort_if_modified()) return; + file_ = file; + if (!load(file_, packages_.get())) { + file_.clear(); + } + modified_ = false; + update_title(); + } + // GuiTextWindow::Listener bool about_to_close(GuiTextWindow* wnd) override { assert(proxy_logwnd_.get() == wnd); @@ -1066,7 +1076,10 @@ private: file_filter_); if (file_.empty()) return; - load(file_, packages_.get()); + if (!load(file_, packages_.get())) { + file_.clear(); + } + modified_ = false; update_title(); } |
