[ABRT PATCH 1/3] expose abrt configuration GUI in public API

Jakub Filak jfilak at redhat.com
Wed Aug 7 11:33:31 UTC 2013


Related to rhbz#993591

Signed-off-by: Jakub Filak <jfilak at redhat.com>
---
 configure.ac                               |   1 +
 po/POTFILES.in                             |   1 +
 src/configuration-gui/Makefile.am          |  31 ++++--
 src/configuration-gui/abrt_gui.pc.in       |  11 ++
 src/configuration-gui/main.c               | 163 +++++++++++++++++++++++++++++
 src/configuration-gui/system-config-abrt.c | 153 +++++----------------------
 src/configuration-gui/system-config-abrt.h |  35 +++++++
 7 files changed, 262 insertions(+), 133 deletions(-)
 create mode 100644 src/configuration-gui/abrt_gui.pc.in
 create mode 100644 src/configuration-gui/main.c
 create mode 100644 src/configuration-gui/system-config-abrt.h

diff --git a/configure.ac b/configure.ac
index 70fafe1..0719295 100644
--- a/configure.ac
+++ b/configure.ac
@@ -237,6 +237,7 @@ AC_CONFIG_FILES([
 	src/applet/Makefile
 	src/cli/Makefile
 	src/configuration-gui/Makefile
+	src/configuration-gui/abrt_gui.pc
 	src/dbus/Makefile
 	src/plugins/abrt-action-install-debuginfo
 	src/plugins/abrt-action-analyze-vmcore
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 752e982..f88c6ca 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -6,6 +6,7 @@ src/applet/applet.c
 src/configuration-gui/abrt-config-widget.ui
 src/configuration-gui/system-config-abrt.c
 src/configuration-gui/system-config-abrt.desktop.in
+src/configuration-gui/main.c
 src/daemon/abrt-action-save-package-data.c
 src/daemon/abrt-server.c
 src/dbus/abrt-dbus.c
diff --git a/src/configuration-gui/Makefile.am b/src/configuration-gui/Makefile.am
index 9d5ec53..1fe4e8f 100644
--- a/src/configuration-gui/Makefile.am
+++ b/src/configuration-gui/Makefile.am
@@ -1,8 +1,17 @@
-lib_LTLIBRARIES = libabrtconfigui.la
+libabrt_gui_includedir = \
+	$(includedir)/abrt
 
-libabrtconfigui_la_SOURCES = \
+libabrt_gui_include_HEADERS = \
+	abrt-config-widget.h \
+	system-config-abrt.h
+
+lib_LTLIBRARIES = libabrt_gui.la
+
+libabrt_gui_la_SOURCES = \
 	abrt-config-widget.c \
-	abrt-config-widget.h
+	abrt-config-widget.h \
+	system-config-abrt.c \
+	system-config-abrt.h
 
 # G_DEFINE_TYPE(...) macros result in
 # typedef '_GStaticAssertCompileTimeAssertion_0' locally defined but not used
@@ -11,7 +20,7 @@ libabrtconfigui_la_SOURCES = \
 # -Wno-error=unused-local-typedefs in CPPFLAGS suppresses this warning.
 # Newer glib may have it fixed.
 
-libabrtconfigui_la_CPPFLAGS = \
+libabrt_gui_la_CPPFLAGS = \
 	-I$(srcdir)/../include \
 	-I$(srcdir)/../lib \
 	-Wno-error=unused-local-typedefs \
@@ -20,10 +29,10 @@ libabrtconfigui_la_CPPFLAGS = \
 	-DABRT_UI_DIR="\"$(uidir)\"" \
 	-DLOCALEDIR="\"$(localedir)\""
 
-libabrtconfigui_la_LDFLAGS = \
+libabrt_gui_la_LDFLAGS = \
 	-version-info 0:1:0
 
-libabrtconfigui_la_LIBADD = \
+libabrt_gui_la_LIBADD = \
 	$(GLIB_LIBS) \
 	$(GTK_LIBS) \
 	$(LIBREPORT_LIBS)
@@ -38,11 +47,11 @@ system_config_abrt_CPPFLAGS = \
 	$(LIBREPORT_CFLAGS)
 
 system_config_abrt_SOURCES = \
-	system-config-abrt.c
+	main.c
 
 system_config_abrt_LDADD = \
 	../lib/libabrt.la \
-	libabrtconfigui.la
+	libabrt_gui.la
 	$(GLIB_LIBS) \
 	$(GTK_LIBS) \
 	$(LIBREPORT_LIBS)
@@ -56,4 +65,8 @@ desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
 @INTLTOOL_DESKTOP_RULE@
 
 CLEANFILES = $(desktop_DATA)
-EXTRA_DIST = $(desktop_in_files)
+EXTRA_DIST = $(desktop_in_files) \
+	abrt_gui.pc.in
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = abrt_gui.pc
diff --git a/src/configuration-gui/abrt_gui.pc.in b/src/configuration-gui/abrt_gui.pc.in
new file mode 100644
index 0000000..7f22ec7
--- /dev/null
+++ b/src/configuration-gui/abrt_gui.pc.in
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: abrt_gui
+Description: abrt UI library
+Version: @VERSION@
+Requires: abrt
+Libs: -L${libdir} -labrt_gui
+Cflags: -fPIC -I${includedir}/abrt
diff --git a/src/configuration-gui/main.c b/src/configuration-gui/main.c
new file mode 100644
index 0000000..15e0796
--- /dev/null
+++ b/src/configuration-gui/main.c
@@ -0,0 +1,163 @@
+/*
+ *  Copyright (C) 2013  Red Hat
+ *
+ *  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 2 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, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+#include "system-config-abrt.h"
+
+#include <stdlib.h>
+#include <libabrt.h>
+
+#define APP_NAME "System Config ABRT"
+
+static GtkWidget *
+system_config_abrt_window_new(GApplication *app)
+{
+    GtkWidget *wnd = gtk_application_window_new(GTK_APPLICATION(app));
+    gtk_window_set_default_size(GTK_WINDOW(wnd), 640, 480);
+    gtk_window_set_title(GTK_WINDOW(wnd), _("Problem Reporting Configuration"));
+
+    GtkWidget *sca = system_config_abrt_widget_new();
+    gtk_container_add(GTK_CONTAINER(wnd), sca);
+
+    return wnd;
+}
+
+/* SystemConfigAbrt : GtkApplication */
+
+typedef struct
+{
+    GtkApplication parent_instance;
+} SystemConfigAbrt;
+
+typedef GtkApplicationClass SystemConfigAbrtClass;
+
+G_DEFINE_TYPE (SystemConfigAbrt, system_config_abrt, GTK_TYPE_APPLICATION)
+
+static void
+system_config_abrt_finalize (GObject *object)
+{
+    G_OBJECT_CLASS(system_config_abrt_parent_class)->finalize(object);
+}
+
+static void
+about_activated (GSimpleAction *action,
+        GVariant      *parameter,
+        gpointer       user_data)
+{
+    const gchar *authors[] = {
+        "ABRT Team &lt;crash-catcher at lists.fedorahosted.org&gt;",
+        NULL
+    };
+
+    gtk_show_about_dialog (NULL,
+            "program-name", APP_NAME,
+            "title", _("About System Config ABRT"),
+            "version", VERSION,
+            "website", "https://github.com/abrt/abrt/wiki/overview",
+            "authors", authors,
+            NULL);
+}
+
+static void
+quit_activated (GSimpleAction *action,
+        GVariant      *parameter,
+        gpointer       user_data)
+{
+    GApplication *app = user_data;
+
+    g_application_quit(app);
+}
+
+static GActionEntry app_entries[] = {
+    { "about", about_activated, NULL, NULL, NULL },
+    { "quit", quit_activated, NULL, NULL, NULL },
+};
+
+static void
+system_config_abrt_startup(GApplication *application)
+{
+    G_APPLICATION_CLASS(system_config_abrt_parent_class)->startup(application);
+
+    g_action_map_add_action_entries(G_ACTION_MAP(application), app_entries, G_N_ELEMENTS(app_entries), application);
+
+    GMenu *app_menu = g_menu_new();
+    g_menu_append(app_menu, _("About"), "app.about");
+    g_menu_append(app_menu, _("Quit"), "app.quit");
+
+    gtk_application_set_app_menu(GTK_APPLICATION(application), G_MENU_MODEL(app_menu));
+}
+
+static void
+system_config_abrt_shutdown(GApplication *application)
+{
+    G_APPLICATION_CLASS(system_config_abrt_parent_class)->shutdown (application);
+}
+
+static void
+system_config_abrt_activate(GApplication *application)
+{
+    GtkWidget *wnd = system_config_abrt_window_new(application);
+    gtk_widget_show_all(wnd);
+    gtk_application_add_window(GTK_APPLICATION(application), GTK_WINDOW(wnd));
+}
+
+static void
+system_config_abrt_init (SystemConfigAbrt *app)
+{
+}
+
+static void
+system_config_abrt_class_init (SystemConfigAbrtClass *class)
+{
+    GApplicationClass *application_class = G_APPLICATION_CLASS(class);
+    GObjectClass *object_class = G_OBJECT_CLASS(class);
+
+    application_class->startup = system_config_abrt_startup;
+    application_class->shutdown = system_config_abrt_shutdown;
+    application_class->activate = system_config_abrt_activate;
+
+    object_class->finalize = system_config_abrt_finalize;
+}
+
+SystemConfigAbrt *
+system_config_abrt_new (void)
+{
+    SystemConfigAbrt *system_config_abrt;
+
+    g_set_application_name(APP_NAME);
+
+    system_config_abrt = g_object_new(system_config_abrt_get_type(),
+            "application-id", "org.freedesktop.SystemConfigAbrt",
+            "flags", G_APPLICATION_HANDLES_OPEN,
+            NULL);
+
+    return system_config_abrt;
+}
+
+/* End class */
+
+int main(int argc, char *argv[])
+{
+    glib_init();
+
+    SystemConfigAbrt *system_config_abrt = system_config_abrt_new();
+
+    const int status = g_application_run(G_APPLICATION(system_config_abrt), argc, argv);
+
+    g_object_unref(system_config_abrt);
+
+    return status;
+}
diff --git a/src/configuration-gui/system-config-abrt.c b/src/configuration-gui/system-config-abrt.c
index 22773de..f15ce01 100644
--- a/src/configuration-gui/system-config-abrt.c
+++ b/src/configuration-gui/system-config-abrt.c
@@ -15,14 +15,11 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
-
+#include "system-config-abrt.h"
 #include "abrt-config-widget.h"
-#include "libabrt.h"
 
-#include <stdlib.h>
-#include <gtk/gtk.h>
+#include <libabrt.h>
 
-#define APP_NAME "System Config ABRT"
 
 static void
 system_config_abrt_apply_cb(GtkButton *button, gpointer user_data)
@@ -39,15 +36,9 @@ system_config_abrt_changed_cb(AbrtConfigWidget *config, gpointer user_data)
     gtk_widget_set_sensitive(button, TRUE);
 }
 
-static GtkWidget *
-system_config_abrt_window_new(GApplication *app)
+GtkWidget *system_config_abrt_widget_new(void)
 {
-    GtkWidget *wnd = gtk_application_window_new(GTK_APPLICATION(app));
-    gtk_window_set_default_size(GTK_WINDOW(wnd), 640, 480);
-    gtk_window_set_title(GTK_WINDOW(wnd), _("Problem Reporting Configuration"));
-
     GtkBox *box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, /*spacing*/0));
-    gtk_container_add(GTK_CONTAINER(wnd), GTK_WIDGET(box));
 
     AbrtConfigWidget *config = abrt_config_widget_new();
     gtk_widget_set_visible(GTK_WIDGET(config), TRUE);
@@ -79,132 +70,46 @@ system_config_abrt_window_new(GApplication *app)
 
     gtk_widget_show_all(buttons);
 
-    return wnd;
-}
-
-/* SystemConfigAbrt : GtkApplication */
-
-typedef struct
-{
-    GtkApplication parent_instance;
-} SystemConfigAbrt;
-
-typedef GtkApplicationClass SystemConfigAbrtClass;
-
-G_DEFINE_TYPE (SystemConfigAbrt, system_config_abrt, GTK_TYPE_APPLICATION)
-
-static void
-system_config_abrt_finalize (GObject *object)
-{
-    G_OBJECT_CLASS(system_config_abrt_parent_class)->finalize(object);
-}
-
-static void
-about_activated (GSimpleAction *action,
-        GVariant      *parameter,
-        gpointer       user_data)
-{
-    const gchar *authors[] = {
-        "ABRT Team &lt;crash-catcher at lists.fedorahosted.org&gt;",
-        NULL
-    };
-
-    gtk_show_about_dialog (NULL,
-            "program-name", APP_NAME,
-            "title", _("About System Config ABRT"),
-            "version", VERSION,
-            "website", "https://github.com/abrt/abrt/wiki/overview",
-            "authors", authors,
-            NULL);
-}
-
-static void
-quit_activated (GSimpleAction *action,
-        GVariant      *parameter,
-        gpointer       user_data)
-{
-    GApplication *app = user_data;
-
-    g_application_quit(app);
-}
-
-static GActionEntry app_entries[] = {
-    { "about", about_activated, NULL, NULL, NULL },
-    { "quit", quit_activated, NULL, NULL, NULL },
-};
-
-static void
-system_config_abrt_startup(GApplication *application)
-{
-    G_APPLICATION_CLASS(system_config_abrt_parent_class)->startup(application);
-
-    g_action_map_add_action_entries(G_ACTION_MAP(application), app_entries, G_N_ELEMENTS(app_entries), application);
-
-    GMenu *app_menu = g_menu_new();
-    g_menu_append(app_menu, _("About"), "app.about");
-    g_menu_append(app_menu, _("Quit"), "app.quit");
-
-    gtk_application_set_app_menu(GTK_APPLICATION(application), G_MENU_MODEL(app_menu));
-}
-
-static void
-system_config_abrt_shutdown(GApplication *application)
-{
-    G_APPLICATION_CLASS(system_config_abrt_parent_class)->shutdown (application);
-}
-
-static void
-system_config_abrt_activate(GApplication *application)
-{
-    GtkWidget *wnd = system_config_abrt_window_new(application);
-    gtk_widget_show_all(wnd);
-    gtk_application_add_window(GTK_APPLICATION(application), GTK_WINDOW(wnd));
+    return GTK_WIDGET(box);
 }
 
 static void
-system_config_abrt_init (SystemConfigAbrt *app)
+system_config_abrt_dialog_close(GtkDialog *dialog, gpointer user_data)
 {
+    gtk_widget_destroy(GTK_WIDGET(dialog));
 }
 
-static void
-system_config_abrt_class_init (SystemConfigAbrtClass *class)
+static gboolean
+system_config_abrt_dialog_delete_event(GtkWidget *dialog, GdkEvent *event, gpointer user_data)
 {
-    GApplicationClass *application_class = G_APPLICATION_CLASS(class);
-    GObjectClass *object_class = G_OBJECT_CLASS(class);
-
-    application_class->startup = system_config_abrt_startup;
-    application_class->shutdown = system_config_abrt_shutdown;
-    application_class->activate = system_config_abrt_activate;
-
-    object_class->finalize = system_config_abrt_finalize;
+    gtk_widget_destroy(GTK_WIDGET(dialog));
+    return TRUE; /*do not propagate the event*/
 }
 
-SystemConfigAbrt *
-system_config_abrt_new (void)
+void show_system_config_abrt_dialog(GtkWindow *parent)
 {
-    SystemConfigAbrt *system_config_abrt;
+    GtkWidget *dialog = gtk_dialog_new();
 
-    g_set_application_name(APP_NAME);
+    gtk_window_set_title(GTK_WINDOW(dialog), _("Problem Reporting Configuration"));
+    gtk_window_set_default_size(GTK_WINDOW(dialog), 640, 480);
+    gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
 
-    system_config_abrt = g_object_new(system_config_abrt_get_type(),
-            "application-id", "org.freedesktop.SystemConfigAbrt",
-            "flags", G_APPLICATION_HANDLES_OPEN,
-            NULL);
-
-    return system_config_abrt;
-}
-
-/* End class */
-
-int main(int argc, char *argv[])
-{
-    glib_init();
+    if (parent != NULL)
+    {
+        gtk_window_set_icon_name(GTK_WINDOW(dialog), gtk_window_get_icon_name(parent));
+        gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
+        gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE);
+    }
 
-    SystemConfigAbrt *system_config_abrt = system_config_abrt_new();
+    /* Have to handle these signals on our own otherwise users must press close button twice */
+    g_signal_connect(dialog, "close", G_CALLBACK(system_config_abrt_dialog_close), /*user_data*/NULL);
+    g_signal_connect(dialog, "delete_event", G_CALLBACK(system_config_abrt_dialog_delete_event), /*user_data*/NULL);
 
-    const int status = g_application_run(G_APPLICATION(system_config_abrt), argc, argv);
+    GtkWidget *content = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+    GtkWidget *sca = system_config_abrt_widget_new();
+    gtk_box_pack_start(GTK_BOX(content), sca, /*expand*/TRUE, /*fill*/TRUE, /*padding*/0);
 
-    g_object_unref(system_config_abrt);
+    gtk_widget_show_all(content);
 
-    return status;
+    gtk_dialog_run(GTK_DIALOG(dialog));
 }
diff --git a/src/configuration-gui/system-config-abrt.h b/src/configuration-gui/system-config-abrt.h
new file mode 100644
index 0000000..453090c
--- /dev/null
+++ b/src/configuration-gui/system-config-abrt.h
@@ -0,0 +1,35 @@
+/*
+ *  Copyright (C) 2013  Red Hat
+ *
+ *  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 2 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, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+#ifndef _SYSTEM_CONFIG_ABRT_H
+#define _SYSTEM_CONFIG_ABRT_H
+
+#include <gtk/gtk.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+GtkWidget *system_config_abrt_widget_new(void);
+
+void show_system_config_abrt_dialog(GtkWindow *parent);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* _SYSTEM_CONFIG_ABRT_H */
-- 
1.8.3.1



More information about the Crash-catcher mailing list