aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab+samsung@kernel.org>2018-09-06 13:59:38 -0300
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>2018-09-07 11:36:56 -0300
commitcdfeabfbafb64a9ffe0da24328552c18df5fe833 (patch)
treef249f66f9bde546e37b14e5ecf98382c635bc23c /src
parent6d2adf868042fe34d8972f1c3a57883fb10f2bbf (diff)
main: make it use gtk_application_new() & friends
As with gtk 4 there's no way to pass command line arguments anymore to gtk_init, we need to change the logic, in order to use g_application() instead. It should be noticed that g_application() is not supported by gtk 2. So, this patch will temporarely break compatibility with it. The next patch will restore. I opted to add the backward compat on a separate patch as it makes easier to later drop gtk 2 compat, after we test gtk 3 support for a while. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Diffstat (limited to 'src')
-rw-r--r--src/callbacks.c10
-rw-r--r--src/callbacks.h2
-rw-r--r--src/camorama-window.c4
-rw-r--r--src/main.c72
-rw-r--r--src/v4l.h3
5 files changed, 56 insertions, 35 deletions
diff --git a/src/callbacks.c b/src/callbacks.c
index 0adac6b..0145f20 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -228,12 +228,6 @@ void gconf_notify_func_int(GConfClient *client, guint cnxn_id,
}
-int delete_event(GtkWidget *widget, gpointer data)
-{
- gtk_main_quit();
- return FALSE;
-}
-
static int apply_remote_pref(cam_t *cam)
{
int index;
@@ -337,9 +331,9 @@ void prefs_func(GtkWidget *okbutton, cam_t *cam)
}
-void on_quit_activate(GtkMenuItem *menuitem, gpointer user_data)
+void on_quit_activate(GtkMenuItem *menuitem, cam_t *cam)
{
- gtk_main_quit();
+ g_application_quit(G_APPLICATION(cam->app));
}
void on_preferences1_activate(GtkMenuItem *menuitem, gpointer user_data)
diff --git a/src/callbacks.h b/src/callbacks.h
index f52e498..a55105f 100644
--- a/src/callbacks.h
+++ b/src/callbacks.h
@@ -8,7 +8,7 @@
G_BEGIN_DECLS
void on_change_size_activate(GtkWidget * widget, cam_t *cam);
-void on_quit_activate(GtkMenuItem *menuitem, gpointer user_data);
+void on_quit_activate(GtkMenuItem *menuitem, cam_t *cam);
void gconf_notify_func(GConfClient *client, guint cnxn_id,
GConfEntry *entry, char **);
void gconf_notify_func_bool(GConfClient *client, guint cnxn_id,
diff --git a/src/camorama-window.c b/src/camorama-window.c
index 5f752a8..7ea6006 100644
--- a/src/camorama-window.c
+++ b/src/camorama-window.c
@@ -183,6 +183,8 @@ void load_interface(cam_t *cam)
"main_window"));
GtkTreeView *treeview;
+ gtk_application_add_window(cam->app, GTK_WINDOW(window));
+
menu_item_filter_type = g_quark_from_static_string("camorama-menu-item-filter-type");
/* set up the tree view */
@@ -305,8 +307,6 @@ void load_interface(cam_t *cam)
//g_signal_connect(cam->xml, "capture_func", G_CALLBACK(on_change_size_activate), cam);
g_signal_connect(gtk_builder_get_object(cam->xml, "button1"),
"clicked", G_CALLBACK(capture_func), cam);
- g_signal_connect(window, "delete-event", G_CALLBACK(delete_event),
- NULL);
/* sliders */
if (cam->contrast < 0) {
diff --git a/src/main.c b/src/main.c
index 491b7a5..bb29568 100644
--- a/src/main.c
+++ b/src/main.c
@@ -61,15 +61,33 @@ static void get_geometry(cam_t *cam)
#endif
}
-int main(int argc, char *argv[])
+static void close_app(GtkWidget* widget, cam_t *cam)
+{
+ if (cam->idle_id)
+ g_source_remove(cam->idle_id);
+
+ if (cam->read == FALSE)
+ stop_streaming(cam);
+
+ v4l2_close(cam->dev);
+
+ if (cam->timeout_id)
+ g_source_remove(cam->timeout_id);
+
+ if (cam->timeout_fps_id)
+ g_source_remove(cam->timeout_fps_id);
+
+ gtk_widget_destroy(widget);
+}
+
+static cam_t cam_object = { 0 };
+
+static void activate(GtkApplication *app)
{
- cam_t cam_object, *cam;
+ cam_t *cam = &cam_object;
GConfClient *gc;
- GtkWidget *widget;
+ GtkWidget *widget, *window;
unsigned int bufsize;
- GError *error = NULL;
-
- cam = &cam_object;
/* set some default values */
cam->frame_number = 0;
@@ -81,16 +99,7 @@ int main(int argc, char *argv[])
cam->res = NULL;
cam->n_res = 0;
cam->scale = 1.f;
-
- bindtextdomain(PACKAGE_NAME, PACKAGE_LOCALE_DIR);
- bind_textdomain_codeset(PACKAGE_NAME, "UTF-8");
- textdomain(PACKAGE_NAME);
-
- if (!gtk_init_with_args(&argc, &argv, _("camorama"), options,
- PACKAGE_NAME, &error) || error) {
- g_printerr(_("Invalid argument\nRun '%s --help'\n"), argv[0]);
- return 1;
- }
+ cam->app = app;
/* gtk is initialized now */
camorama_filters_init();
@@ -231,20 +240,37 @@ int main(int argc, char *argv[])
g_signal_connect(G_OBJECT(widget), "draw", G_CALLBACK(draw_callback), cam);
#endif
+ window = GTK_WIDGET(gtk_builder_get_object(cam->xml, "main_window"));
+
+ g_signal_connect(G_OBJECT(window), "destroy",
+ G_CALLBACK (close_app), cam);
+
gtk_widget_show(widget);
cam->idle_id = g_idle_add((GSourceFunc) pt2Function, (gpointer) cam);
- g_timeout_add(2000, (GSourceFunc) fps, cam->status);
+ cam->timeout_fps_id = g_timeout_add(2000, (GSourceFunc) fps, cam->status);
if (cam->debug == TRUE)
print_cam(cam);
+}
- gtk_main();
- if (cam->read == FALSE) {
- stop_streaming(cam);
- }
- v4l2_close(cam->dev);
+int main(int argc, char *argv[])
+{
+ GtkApplication *app;
+ gint status;
+
+ bindtextdomain(PACKAGE_NAME, PACKAGE_LOCALE_DIR);
+ bind_textdomain_codeset(PACKAGE_NAME, "UTF-8");
+ textdomain(PACKAGE_NAME);
+
+ app = gtk_application_new(NULL, G_APPLICATION_FLAGS_NONE);
+ g_application_add_main_option_entries(G_APPLICATION(app), options);
+ g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
+
+ status = g_application_run(G_APPLICATION(app), argc, argv);
+
+ g_object_unref(app);
- return 0;
+ return status;
}
diff --git a/src/v4l.h b/src/v4l.h
index f4e7c43..e049d44 100644
--- a/src/v4l.h
+++ b/src/v4l.h
@@ -76,8 +76,9 @@ typedef struct camera {
gboolean timestamp, rtimestamp, usedate, usestring;
gboolean rtimefn, timefn;
GtkWidget *da, *status;
+ GtkApplication *app;
unsigned char *pic_buf, *tmp;
- guint timeout_id, idle_id;
+ guint timeout_id, timeout_fps_id, idle_id;
guint32 timeout_interval;
GConfClient *gc;
GtkBuilder *xml;

Privacy Policy