From 21f119060181898a20ef0d2c766277e6de49d673 Mon Sep 17 00:00:00 2001 From: Nikola Pajkovsky Date: Fri, 27 Aug 2010 15:50:51 +0200 Subject: get rid of CApplet class Signed-off-by: Nikola Pajkovsky Acked-off-by: Denys Vlasenko --- src/applet/Applet.cpp | 18 +++--- src/applet/CCApplet.cpp | 154 +++++++++++++++++++++++++----------------------- src/applet/CCApplet.h | 100 +++++++++++++++---------------- 3 files changed, 136 insertions(+), 136 deletions(-) (limited to 'src') diff --git a/src/applet/Applet.cpp b/src/applet/Applet.cpp index be9c662d..2f35cab5 100644 --- a/src/applet/Applet.cpp +++ b/src/applet/Applet.cpp @@ -31,7 +31,7 @@ #include "CCApplet.h" -static CApplet* applet; +static struct applet* applet = NULL; static void Crash(DBusMessage* signal) @@ -80,8 +80,8 @@ static void Crash(DBusMessage* signal) if (package_name[0] == '\0') message = _("A crash has been detected"); //applet->AddEvent(uid, package_name); - applet->SetIconTooltip(message, package_name); - applet->ShowIcon(); + SetIconTooltip(applet, message, package_name); + ShowIcon(applet); /* If this crash seems to be repeating, do not annoy user with popup dialog. * (The icon in the tray is not suppressed) @@ -103,7 +103,7 @@ static void Crash(DBusMessage* signal) free(last_crash_id); last_crash_id = xstrdup(crash_id); - applet->CrashNotify(crash_id, message, package_name); + CrashNotify(applet, crash_id, message, package_name); } static void QuotaExceed(DBusMessage* signal) @@ -121,8 +121,8 @@ static void QuotaExceed(DBusMessage* signal) //if (m_pSessionDBus->has_name("com.redhat.abrt.gui")) // return; - applet->ShowIcon(); - applet->MessageNotify("%s", str); + ShowIcon(applet); + MessageNotify(applet, "%s", str); } static void NameOwnerChanged(DBusMessage* signal) @@ -159,7 +159,7 @@ static void NameOwnerChanged(DBusMessage* signal) // hide icon if it's visible - as NM and don't show it, if it's not if (!new_owner[0]) - applet->HideIcon(); + HideIcon(applet); } static DBusHandlerResult handle_message(DBusConnection* conn, DBusMessage* msg, void* user_data) @@ -261,7 +261,7 @@ int main(int argc, char** argv) /* Initialize GUI stuff. * Note: inside CApplet ctor, libnotify hooks session dbus * to glib main loop */ - applet = new CApplet(app_name); + applet = applet_new(app_name); /* dbus_abrt cannot handle more than one bus, and we don't really need to. * The only thing we want to do is to announce ourself on session dbus */ DBusConnection* session_conn = dbus_bus_get(DBUS_BUS_SESSION, &err); @@ -291,6 +291,6 @@ int main(int argc, char** argv) gtk_main(); gdk_threads_leave(); - delete applet; + applet_destroy(applet); return 0; } diff --git a/src/applet/CCApplet.cpp b/src/applet/CCApplet.cpp index 4f6c2c65..587f568a 100644 --- a/src/applet/CCApplet.cpp +++ b/src/applet/CCApplet.cpp @@ -48,7 +48,7 @@ static NotifyNotification *new_warn_notification() static void on_hide_cb(GtkMenuItem *menuitem, gpointer applet) { if (applet) - ((CApplet*)applet)->HideIcon(); + HideIcon((struct applet*)applet); } static void on_about_cb(GtkMenuItem *menuitem, gpointer dialog) @@ -101,7 +101,7 @@ static GtkWidget *create_about_dialog() return about_d; } -static GtkWidget *create_menu(CApplet *applet) +static GtkWidget *create_menu(struct applet *applet) { GtkWidget *menu = gtk_menu_new(); GtkWidget *b_quit = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, NULL); @@ -126,59 +126,64 @@ static GtkWidget *create_menu(CApplet *applet) return menu; } -CApplet::CApplet(const char* app_name) +struct applet *applet_new(const char* app_name) { - m_bDaemonRunning = true; + struct applet *applet = (struct applet*)xmalloc(sizeof(struct applet)); + applet->m_bDaemonRunning = true; /* set-up icon buffers */ - m_iAnimator = 0; - m_iAnimationStage = ICON_DEFAULT; - m_bIconsLoaded = load_icons(); + applet->m_iAnimator = 0; + applet->m_iAnimationStage = ICON_DEFAULT; + applet->m_bIconsLoaded = load_icons(applet); /* - animation - */ - if (m_bIconsLoaded == true) + if (applet->m_bIconsLoaded == true) { //FIXME: animation is disabled for now - m_pStatusIcon = gtk_status_icon_new_from_pixbuf(icon_stages_buff[ICON_DEFAULT]); + applet->m_pStatusIcon = gtk_status_icon_new_from_pixbuf(applet->icon_stages_buff[ICON_DEFAULT]); } else { - m_pStatusIcon = gtk_status_icon_new_from_icon_name("abrt"); + applet->m_pStatusIcon = gtk_status_icon_new_from_icon_name("abrt"); } notify_init(app_name); - gtk_status_icon_set_visible(m_pStatusIcon, FALSE); + gtk_status_icon_set_visible(applet->m_pStatusIcon, FALSE); - g_signal_connect(G_OBJECT(m_pStatusIcon), "activate", GTK_SIGNAL_FUNC(CApplet::OnAppletActivate_CB), this); - g_signal_connect(G_OBJECT(m_pStatusIcon), "popup_menu", GTK_SIGNAL_FUNC(CApplet::OnMenuPopup_cb), this); + g_signal_connect(G_OBJECT(applet->m_pStatusIcon), "activate", GTK_SIGNAL_FUNC(OnAppletActivate_CB), applet); + g_signal_connect(G_OBJECT(applet->m_pStatusIcon), "popup_menu", GTK_SIGNAL_FUNC(OnMenuPopup_cb), applet); // SetIconTooltip(_("Pending events: %i"), m_mapEvents.size()); - m_pMenu = create_menu(this); + applet->m_pMenu = create_menu(applet); + return applet; } -CApplet::~CApplet() +void applet_destroy(struct applet *applet) { if (notify_is_initted()) notify_uninit(); + + free(applet); } -void CApplet::SetIconTooltip(const char *format, ...) +void SetIconTooltip(struct applet *applet, const char *format, ...) { va_list args; int n; char *buf; + // xvasprintf? va_start(args, format); buf = NULL; n = vasprintf(&buf, format, args); va_end(args); - gtk_status_icon_set_tooltip_text(m_pStatusIcon, (n >= 0 && buf) ? buf : ""); + gtk_status_icon_set_tooltip_text(applet->m_pStatusIcon, (n >= 0 && buf) ? buf : ""); free(buf); } -void CApplet::action_report(NotifyNotification *notification, gchar *action, gpointer user_data) +void action_report(NotifyNotification *notification, gchar *action, gpointer user_data) { - CApplet *applet = (CApplet *)user_data; + struct applet *applet = (struct applet *)user_data; if (applet->m_bDaemonRunning) { pid_t pid = vfork(); @@ -202,13 +207,13 @@ void CApplet::action_report(NotifyNotification *notification, gchar *action, gpo g_error_free(err); } gtk_status_icon_set_visible(applet->m_pStatusIcon, false); - applet->stop_animate_icon(); + stop_animate_icon(applet); } } -void CApplet::action_open_gui(NotifyNotification *notification, gchar *action, gpointer user_data) +void action_open_gui(NotifyNotification *notification, gchar *action, gpointer user_data) { - CApplet *applet = (CApplet *)user_data; + struct applet *applet = (struct applet*)user_data; if (applet->m_bDaemonRunning) { pid_t pid = vfork(); @@ -231,13 +236,13 @@ void CApplet::action_open_gui(NotifyNotification *notification, gchar *action, g g_error_free(err); } gtk_status_icon_set_visible(applet->m_pStatusIcon, false); - applet->stop_animate_icon(); + stop_animate_icon(applet); } } -void CApplet::CrashNotify(const char* crash_id, const char *format, ...) +void CrashNotify(struct applet *applet, const char* crash_id, const char *format, ...) { - m_pLastCrashID = crash_id; + applet->m_pLastCrashID = crash_id; va_list args; va_start(args, format); char *buf = xvasprintf(format, args); @@ -245,11 +250,11 @@ void CApplet::CrashNotify(const char* crash_id, const char *format, ...) NotifyNotification *notification = new_warn_notification(); notify_notification_add_action(notification, "REPORT", _("Report"), - NOTIFY_ACTION_CALLBACK(CApplet::action_report), - this, NULL); + NOTIFY_ACTION_CALLBACK(action_report), + applet, NULL); notify_notification_add_action(notification, "OPEN_MAIN_WINDOW", _("Open ABRT"), - NOTIFY_ACTION_CALLBACK(CApplet::action_open_gui), - this, NULL); + NOTIFY_ACTION_CALLBACK(action_open_gui), + applet, NULL); notify_notification_update(notification, _("Warning"), buf, NULL); free(buf); @@ -262,7 +267,7 @@ void CApplet::CrashNotify(const char* crash_id, const char *format, ...) } } -void CApplet::MessageNotify(const char *format, ...) +void MessageNotify(struct applet *applet, const char *format, ...) { va_list args; @@ -276,8 +281,8 @@ void CApplet::MessageNotify(const char *format, ...) */ NotifyNotification *notification = new_warn_notification(); notify_notification_add_action(notification, "OPEN_MAIN_WINDOW", _("Open ABRT"), - NOTIFY_ACTION_CALLBACK(CApplet::action_open_gui), - this, NULL); + NOTIFY_ACTION_CALLBACK(action_open_gui), + applet, NULL); notify_notification_update(notification, _("Warning"), buf, NULL); free(buf); GError *err = NULL; @@ -289,9 +294,9 @@ void CApplet::MessageNotify(const char *format, ...) } } -void CApplet::OnAppletActivate_CB(GtkStatusIcon *status_icon, gpointer user_data) +void OnAppletActivate_CB(GtkStatusIcon *status_icon, gpointer user_data) { - CApplet *applet = (CApplet *)user_data; + struct applet *applet = (struct applet*)user_data; if (applet->m_bDaemonRunning) { pid_t pid = vfork(); @@ -307,48 +312,48 @@ void CApplet::OnAppletActivate_CB(GtkStatusIcon *status_icon, gpointer user_data perror_msg_and_die("Can't execute abrt-gui"); } gtk_status_icon_set_visible(applet->m_pStatusIcon, false); - applet->stop_animate_icon(); + stop_animate_icon(applet); } } -void CApplet::OnMenuPopup_cb(GtkStatusIcon *status_icon, - guint button, - guint activate_time, - gpointer user_data) +void OnMenuPopup_cb(GtkStatusIcon *status_icon, + guint button, + guint activate_time, + gpointer user_data) { - CApplet *applet = (CApplet *)user_data; + struct applet *applet = (struct applet*)user_data; /* stop the animation */ - applet->stop_animate_icon(); + stop_animate_icon(applet); if (applet->m_pMenu != NULL) { - gtk_menu_popup(GTK_MENU(((CApplet *)user_data)->m_pMenu), + gtk_menu_popup(GTK_MENU(applet->m_pMenu), NULL, NULL, gtk_status_icon_position_menu, status_icon, button, activate_time); } } -void CApplet::ShowIcon() +void ShowIcon(struct applet *applet) { - gtk_status_icon_set_visible(m_pStatusIcon, true); + gtk_status_icon_set_visible(applet->m_pStatusIcon, true); /* only animate if all icons are loaded, use the "gtk-warning" instead */ - if (m_bIconsLoaded) - animate_icon(); + if (applet->m_bIconsLoaded) + animate_icon(applet); } -void CApplet::HideIcon() +void HideIcon(struct applet *applet) { - gtk_status_icon_set_visible(m_pStatusIcon, false); - stop_animate_icon(); + gtk_status_icon_set_visible(applet->m_pStatusIcon, false); + stop_animate_icon(applet); } -void CApplet::Disable(const char *reason) +void Disable(struct applet *applet, const char *reason) { /* FIXME: once we have our icon */ - m_bDaemonRunning = false; + applet->m_bDaemonRunning = false; GdkPixbuf *gray_scaled; GdkPixbuf *pixbuf = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), GTK_STOCK_DIALOG_WARNING, 24, GTK_ICON_LOOKUP_USE_BUILTIN, NULL); @@ -356,27 +361,28 @@ void CApplet::Disable(const char *reason) { gray_scaled = gdk_pixbuf_copy(pixbuf); gdk_pixbuf_saturate_and_pixelate(pixbuf, gray_scaled, 0.0, false); - gtk_status_icon_set_from_pixbuf(m_pStatusIcon, gray_scaled); + gtk_status_icon_set_from_pixbuf(applet->m_pStatusIcon, gray_scaled); //do we need to free pixbufs nere? } else error_msg("Can't load icon"); - SetIconTooltip(reason); - ShowIcon(); + SetIconTooltip(applet, reason); + ShowIcon(applet); } -void CApplet::Enable(const char *reason) +void Enable(struct applet *applet, const char *reason) { /* restore the original icon */ - m_bDaemonRunning = true; - SetIconTooltip(reason); - gtk_status_icon_set_from_stock(m_pStatusIcon, GTK_STOCK_DIALOG_WARNING); - ShowIcon(); + applet->m_bDaemonRunning = true; + SetIconTooltip(applet, reason); + gtk_status_icon_set_from_stock(applet->m_pStatusIcon, GTK_STOCK_DIALOG_WARNING); + ShowIcon(applet); } -gboolean CApplet::update_icon(void *user_data) +// why it is not named with suffix _cb when it is callback for g_timeout_add? +gboolean update_icon(void *user_data) { - CApplet* applet = (CApplet*)user_data; + struct applet *applet = (struct applet*)user_data; if (applet->m_pStatusIcon && applet->m_iAnimationStage < ICON_STAGE_LAST) { gtk_status_icon_set_from_pixbuf(applet->m_pStatusIcon, @@ -388,32 +394,34 @@ gboolean CApplet::update_icon(void *user_data) } if (--applet->m_iAnimCountdown == 0) { - applet->stop_animate_icon(); + stop_animate_icon(applet); } return true; } -void CApplet::animate_icon() +void animate_icon(struct applet* applet) { - if (m_iAnimator == 0) + if (applet->m_iAnimator == 0) { - m_iAnimator = g_timeout_add(100, update_icon, this); - m_iAnimCountdown = 10 * 3; /* 3 sec */ + applet->m_iAnimator = g_timeout_add(100, update_icon, applet); + applet->m_iAnimCountdown = 10 * 3; /* 3 sec */ } } -void CApplet::stop_animate_icon() +void stop_animate_icon(struct applet *applet) { /* animator should be 0 if icons are not loaded, so this should be safe */ - if (m_iAnimator != 0) + if (applet->m_iAnimator != 0) { - g_source_remove(m_iAnimator); - gtk_status_icon_set_from_pixbuf(m_pStatusIcon, icon_stages_buff[ICON_DEFAULT]); - m_iAnimator = 0; + g_source_remove(applet->m_iAnimator); + gtk_status_icon_set_from_pixbuf(applet->m_pStatusIcon, + applet->icon_stages_buff[ICON_DEFAULT] + ); + applet->m_iAnimator = 0; } } -bool CApplet::load_icons() +bool load_icons(struct applet *applet) { //FIXME: just a tmp workaround return false; @@ -424,7 +432,7 @@ bool CApplet::load_icons() GError *error = NULL; if (snprintf(name, sizeof(ICON_DIR"/abrt%02d.png"), ICON_DIR"/abrt%02d.png", stage) > 0) { - icon_stages_buff[stage] = gdk_pixbuf_new_from_file(name, &error); + applet->icon_stages_buff[stage] = gdk_pixbuf_new_from_file(name, &error); if (error != NULL) { error_msg("Can't load pixbuf from %s, animation is disabled", name); diff --git a/src/applet/CCApplet.h b/src/applet/CCApplet.h index a58ec687..ebcf78da 100644 --- a/src/applet/CCApplet.h +++ b/src/applet/CCApplet.h @@ -24,65 +24,57 @@ #include #include -class CApplet +enum ICON_STAGES { - private: - GtkStatusIcon* m_pStatusIcon; - GtkWidget *m_pMenu; + ICON_DEFAULT, + ICON_STAGE1, + ICON_STAGE2, + ICON_STAGE3, + ICON_STAGE4, + ICON_STAGE5, + /* this must be always the last */ + ICON_STAGE_LAST +}; + +struct applet { + GtkStatusIcon* m_pStatusIcon; + GtkWidget *m_pMenu; // std::map m_mapEvents; - bool m_bDaemonRunning; - int m_iAnimationStage; - guint m_iAnimator; - unsigned m_iAnimCountdown; - bool m_bIconsLoaded; - const char *m_pLastCrashID; + bool m_bDaemonRunning; + int m_iAnimationStage; + guint m_iAnimator; + unsigned m_iAnimCountdown; + bool m_bIconsLoaded; + const char *m_pLastCrashID; - enum ICON_STAGES - { - ICON_DEFAULT, - ICON_STAGE1, - ICON_STAGE2, - ICON_STAGE3, - ICON_STAGE4, - ICON_STAGE5, - /* this must be always the last */ - ICON_STAGE_LAST - } icon_stages; - GdkPixbuf *icon_stages_buff[ICON_STAGE_LAST]; + GdkPixbuf *icon_stages_buff[ICON_STAGE_LAST]; +}; - public: - CApplet(const char* app_name); - ~CApplet(); - void ShowIcon(); - void HideIcon(); - void SetIconTooltip(const char *format, ...); - void CrashNotify(const char* crash_id, const char *format, ...); - void MessageNotify(const char *format, ...); - void Disable(const char *reason); - void Enable(const char *reason); - // create some event storage, to let user choose - // or ask the daemon every time? - // maybe just events which occured during current session - // map:: -// int AddEvent(int pUUID, const char *pProgname); -// int RemoveEvent(int pUUID); +struct applet* applet_new(const char *app_name); +void applet_destroy(struct applet *applet); - protected: - //@@TODO applet menus - static void OnAppletActivate_CB(GtkStatusIcon *status_icon, gpointer user_data); - //this action should open the reporter dialog directly, without showing the main window - static void action_report(NotifyNotification *notification, gchar *action, gpointer user_data); - //this action should open the main window - static void action_open_gui(NotifyNotification *notification, gchar *action, gpointer user_data); - static void OnMenuPopup_cb(GtkStatusIcon *status_icon, - guint button, - guint activate_time, - gpointer user_data); - static gboolean update_icon(void *data); - void animate_icon(); - void stop_animate_icon(); - bool load_icons(); -}; +void ShowIcon(struct applet *applet); +void HideIcon(struct applet *applet); +void SetIconTooltip(struct applet *applet, const char *format, ...); +void CrashNotify(struct applet *applet, const char* crash_id, const char *format, ...); +void MessageNotify(struct applet *applet, const char *format, ...); +void Disable(struct applet *applet, const char *reason); +void Enable(struct applet *applet, const char *reason); + +// static in next patch +void OnAppletActivate_CB(GtkStatusIcon *status_icon, gpointer user_data); +//this action should open the reporter dialog directly, without showing the main window +void action_report(NotifyNotification *notification, gchar *action, gpointer user_data); +//this action should open the main window +void action_open_gui(NotifyNotification *notification, gchar *action, gpointer user_data); +void OnMenuPopup_cb(GtkStatusIcon *status_icon, + guint button, + guint activate_time, + gpointer user_data); +gboolean update_icon(void *data); +void animate_icon(struct applet *applet); +void stop_animate_icon(struct applet *applet); +bool load_icons(struct applet *applet); #endif -- cgit From 896c9b5ab9d3daf2c3254da5b9eb022a01e5c19d Mon Sep 17 00:00:00 2001 From: Nikola Pajkovsky Date: Fri, 27 Aug 2010 16:03:06 +0200 Subject: lower case variable in struct applet Signed-off-by: Nikola Pajkovsky Acked-off-by: Denys Vlasenko --- src/applet/Applet.cpp | 12 ++--- src/applet/CCApplet.cpp | 120 ++++++++++++++++++++++++------------------------ src/applet/CCApplet.h | 36 +++++++-------- 3 files changed, 84 insertions(+), 84 deletions(-) (limited to 'src') diff --git a/src/applet/Applet.cpp b/src/applet/Applet.cpp index 2f35cab5..239f7a04 100644 --- a/src/applet/Applet.cpp +++ b/src/applet/Applet.cpp @@ -80,8 +80,8 @@ static void Crash(DBusMessage* signal) if (package_name[0] == '\0') message = _("A crash has been detected"); //applet->AddEvent(uid, package_name); - SetIconTooltip(applet, message, package_name); - ShowIcon(applet); + set_icon_tooltip(applet, message, package_name); + show_icon(applet); /* If this crash seems to be repeating, do not annoy user with popup dialog. * (The icon in the tray is not suppressed) @@ -103,7 +103,7 @@ static void Crash(DBusMessage* signal) free(last_crash_id); last_crash_id = xstrdup(crash_id); - CrashNotify(applet, crash_id, message, package_name); + show_crash_notification(applet, crash_id, message, package_name); } static void QuotaExceed(DBusMessage* signal) @@ -121,8 +121,8 @@ static void QuotaExceed(DBusMessage* signal) //if (m_pSessionDBus->has_name("com.redhat.abrt.gui")) // return; - ShowIcon(applet); - MessageNotify(applet, "%s", str); + show_icon(applet); + show_msg_notification(applet, "%s", str); } static void NameOwnerChanged(DBusMessage* signal) @@ -159,7 +159,7 @@ static void NameOwnerChanged(DBusMessage* signal) // hide icon if it's visible - as NM and don't show it, if it's not if (!new_owner[0]) - HideIcon(applet); + hide_icon(applet); } static DBusHandlerResult handle_message(DBusConnection* conn, DBusMessage* msg, void* user_data) diff --git a/src/applet/CCApplet.cpp b/src/applet/CCApplet.cpp index 587f568a..1b18dba5 100644 --- a/src/applet/CCApplet.cpp +++ b/src/applet/CCApplet.cpp @@ -48,7 +48,7 @@ static NotifyNotification *new_warn_notification() static void on_hide_cb(GtkMenuItem *menuitem, gpointer applet) { if (applet) - HideIcon((struct applet*)applet); + hide_icon((struct applet*)applet); } static void on_about_cb(GtkMenuItem *menuitem, gpointer dialog) @@ -128,32 +128,32 @@ static GtkWidget *create_menu(struct applet *applet) struct applet *applet_new(const char* app_name) { - struct applet *applet = (struct applet*)xmalloc(sizeof(struct applet)); - applet->m_bDaemonRunning = true; + struct applet *applet = (struct applet*)xzalloc(sizeof(struct applet)); + applet->ap_daemon_running = true; /* set-up icon buffers */ - applet->m_iAnimator = 0; - applet->m_iAnimationStage = ICON_DEFAULT; - applet->m_bIconsLoaded = load_icons(applet); + if (ICON_DEFAULT != 0) + applet->ap_animation_stage = ICON_DEFAULT; + applet->ap_icons_loaded = load_icons(applet); /* - animation - */ - if (applet->m_bIconsLoaded == true) + if (applet->ap_icons_loaded == true) { //FIXME: animation is disabled for now - applet->m_pStatusIcon = gtk_status_icon_new_from_pixbuf(applet->icon_stages_buff[ICON_DEFAULT]); + applet->ap_status_icon = gtk_status_icon_new_from_pixbuf(applet->ap_icon_stages_buff[ICON_DEFAULT]); } else { - applet->m_pStatusIcon = gtk_status_icon_new_from_icon_name("abrt"); + applet->ap_status_icon = gtk_status_icon_new_from_icon_name("abrt"); } notify_init(app_name); - gtk_status_icon_set_visible(applet->m_pStatusIcon, FALSE); + gtk_status_icon_set_visible(applet->ap_status_icon, FALSE); - g_signal_connect(G_OBJECT(applet->m_pStatusIcon), "activate", GTK_SIGNAL_FUNC(OnAppletActivate_CB), applet); - g_signal_connect(G_OBJECT(applet->m_pStatusIcon), "popup_menu", GTK_SIGNAL_FUNC(OnMenuPopup_cb), applet); + g_signal_connect(G_OBJECT(applet->ap_status_icon), "activate", GTK_SIGNAL_FUNC(on_applet_activate_cb), applet); + g_signal_connect(G_OBJECT(applet->ap_status_icon), "popup_menu", GTK_SIGNAL_FUNC(on_menu_popup_cb), applet); // SetIconTooltip(_("Pending events: %i"), m_mapEvents.size()); - applet->m_pMenu = create_menu(applet); + applet->ap_menu = create_menu(applet); return applet; } @@ -165,7 +165,7 @@ void applet_destroy(struct applet *applet) free(applet); } -void SetIconTooltip(struct applet *applet, const char *format, ...) +void set_icon_tooltip(struct applet *applet, const char *format, ...) { va_list args; int n; @@ -177,21 +177,21 @@ void SetIconTooltip(struct applet *applet, const char *format, ...) n = vasprintf(&buf, format, args); va_end(args); - gtk_status_icon_set_tooltip_text(applet->m_pStatusIcon, (n >= 0 && buf) ? buf : ""); + gtk_status_icon_set_tooltip_text(applet->ap_status_icon, (n >= 0 && buf) ? buf : ""); free(buf); } void action_report(NotifyNotification *notification, gchar *action, gpointer user_data) { struct applet *applet = (struct applet *)user_data; - if (applet->m_bDaemonRunning) + if (applet->ap_daemon_running) { pid_t pid = vfork(); if (pid < 0) perror_msg("vfork"); if (pid == 0) { /* child */ - char *buf = xasprintf("--report=%s", applet->m_pLastCrashID); + char *buf = xasprintf("--report=%s", applet->ap_last_crash_id); signal(SIGCHLD, SIG_DFL); /* undo SIG_IGN in abrt-applet */ execl(BIN_DIR"/abrt-gui", "abrt-gui", buf, (char*) NULL); /* Did not find abrt-gui in installation directory. Oh well */ @@ -206,7 +206,7 @@ void action_report(NotifyNotification *notification, gchar *action, gpointer use error_msg("%s", err->message); g_error_free(err); } - gtk_status_icon_set_visible(applet->m_pStatusIcon, false); + gtk_status_icon_set_visible(applet->ap_status_icon, false); stop_animate_icon(applet); } } @@ -214,7 +214,7 @@ void action_report(NotifyNotification *notification, gchar *action, gpointer use void action_open_gui(NotifyNotification *notification, gchar *action, gpointer user_data) { struct applet *applet = (struct applet*)user_data; - if (applet->m_bDaemonRunning) + if (applet->ap_daemon_running) { pid_t pid = vfork(); if (pid < 0) @@ -235,14 +235,14 @@ void action_open_gui(NotifyNotification *notification, gchar *action, gpointer u error_msg("%s", err->message); g_error_free(err); } - gtk_status_icon_set_visible(applet->m_pStatusIcon, false); + gtk_status_icon_set_visible(applet->ap_status_icon, false); stop_animate_icon(applet); } } -void CrashNotify(struct applet *applet, const char* crash_id, const char *format, ...) +void show_crash_notification(struct applet *applet, const char* crash_id, const char *format, ...) { - applet->m_pLastCrashID = crash_id; + applet->ap_last_crash_id = crash_id; va_list args; va_start(args, format); char *buf = xvasprintf(format, args); @@ -267,7 +267,7 @@ void CrashNotify(struct applet *applet, const char* crash_id, const char *format } } -void MessageNotify(struct applet *applet, const char *format, ...) +void show_msg_notification(struct applet *applet, const char *format, ...) { va_list args; @@ -294,10 +294,10 @@ void MessageNotify(struct applet *applet, const char *format, ...) } } -void OnAppletActivate_CB(GtkStatusIcon *status_icon, gpointer user_data) +void on_applet_activate_cb(GtkStatusIcon *status_icon, gpointer user_data) { struct applet *applet = (struct applet*)user_data; - if (applet->m_bDaemonRunning) + if (applet->ap_daemon_running) { pid_t pid = vfork(); if (pid < 0) @@ -311,12 +311,12 @@ void OnAppletActivate_CB(GtkStatusIcon *status_icon, gpointer user_data) execlp("abrt-gui", "abrt-gui", (char*) NULL); perror_msg_and_die("Can't execute abrt-gui"); } - gtk_status_icon_set_visible(applet->m_pStatusIcon, false); + gtk_status_icon_set_visible(applet->ap_status_icon, false); stop_animate_icon(applet); } } -void OnMenuPopup_cb(GtkStatusIcon *status_icon, +void on_menu_popup_cb(GtkStatusIcon *status_icon, guint button, guint activate_time, gpointer user_data) @@ -325,35 +325,35 @@ void OnMenuPopup_cb(GtkStatusIcon *status_icon, /* stop the animation */ stop_animate_icon(applet); - if (applet->m_pMenu != NULL) + if (applet->ap_menu != NULL) { - gtk_menu_popup(GTK_MENU(applet->m_pMenu), + gtk_menu_popup(GTK_MENU(applet->ap_menu), NULL, NULL, gtk_status_icon_position_menu, status_icon, button, activate_time); } } -void ShowIcon(struct applet *applet) +void show_icon(struct applet *applet) { - gtk_status_icon_set_visible(applet->m_pStatusIcon, true); + gtk_status_icon_set_visible(applet->ap_status_icon, true); /* only animate if all icons are loaded, use the "gtk-warning" instead */ - if (applet->m_bIconsLoaded) + if (applet->ap_icons_loaded) animate_icon(applet); } -void HideIcon(struct applet *applet) +void hide_icon(struct applet *applet) { - gtk_status_icon_set_visible(applet->m_pStatusIcon, false); + gtk_status_icon_set_visible(applet->ap_status_icon, false); stop_animate_icon(applet); } -void Disable(struct applet *applet, const char *reason) +void disable(struct applet *applet, const char *reason) { /* FIXME: once we have our icon */ - applet->m_bDaemonRunning = false; + applet->ap_daemon_running = false; GdkPixbuf *gray_scaled; GdkPixbuf *pixbuf = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), GTK_STOCK_DIALOG_WARNING, 24, GTK_ICON_LOOKUP_USE_BUILTIN, NULL); @@ -361,38 +361,38 @@ void Disable(struct applet *applet, const char *reason) { gray_scaled = gdk_pixbuf_copy(pixbuf); gdk_pixbuf_saturate_and_pixelate(pixbuf, gray_scaled, 0.0, false); - gtk_status_icon_set_from_pixbuf(applet->m_pStatusIcon, gray_scaled); + gtk_status_icon_set_from_pixbuf(applet->ap_status_icon, gray_scaled); //do we need to free pixbufs nere? } else error_msg("Can't load icon"); - SetIconTooltip(applet, reason); - ShowIcon(applet); + set_icon_tooltip(applet, reason); + show_icon(applet); } -void Enable(struct applet *applet, const char *reason) +void enable(struct applet *applet, const char *reason) { /* restore the original icon */ - applet->m_bDaemonRunning = true; - SetIconTooltip(applet, reason); - gtk_status_icon_set_from_stock(applet->m_pStatusIcon, GTK_STOCK_DIALOG_WARNING); - ShowIcon(applet); + applet->ap_daemon_running = true; + set_icon_tooltip(applet, reason); + gtk_status_icon_set_from_stock(applet->ap_status_icon, GTK_STOCK_DIALOG_WARNING); + show_icon(applet); } // why it is not named with suffix _cb when it is callback for g_timeout_add? gboolean update_icon(void *user_data) { struct applet *applet = (struct applet*)user_data; - if (applet->m_pStatusIcon && applet->m_iAnimationStage < ICON_STAGE_LAST) + if (applet->ap_status_icon && applet->ap_animation_stage < ICON_STAGE_LAST) { - gtk_status_icon_set_from_pixbuf(applet->m_pStatusIcon, - applet->icon_stages_buff[applet->m_iAnimationStage++]); + gtk_status_icon_set_from_pixbuf(applet->ap_status_icon, + applet->ap_icon_stages_buff[applet->ap_animation_stage++]); } - if (applet->m_iAnimationStage == ICON_STAGE_LAST) + if (applet->ap_animation_stage == ICON_STAGE_LAST) { - applet->m_iAnimationStage = 0; + applet->ap_animation_stage = 0; } - if (--applet->m_iAnimCountdown == 0) + if (--applet->ap_anim_countdown == 0) { stop_animate_icon(applet); } @@ -401,23 +401,23 @@ gboolean update_icon(void *user_data) void animate_icon(struct applet* applet) { - if (applet->m_iAnimator == 0) + if (applet->ap_animator == 0) { - applet->m_iAnimator = g_timeout_add(100, update_icon, applet); - applet->m_iAnimCountdown = 10 * 3; /* 3 sec */ + applet->ap_animator = g_timeout_add(100, update_icon, applet); + applet->ap_anim_countdown = 10 * 3; /* 3 sec */ } } void stop_animate_icon(struct applet *applet) { - /* animator should be 0 if icons are not loaded, so this should be safe */ - if (applet->m_iAnimator != 0) + /* ap_animator should be 0 if icons are not loaded, so this should be safe */ + if (applet->ap_animator != 0) { - g_source_remove(applet->m_iAnimator); - gtk_status_icon_set_from_pixbuf(applet->m_pStatusIcon, - applet->icon_stages_buff[ICON_DEFAULT] + g_source_remove(applet->ap_animator); + gtk_status_icon_set_from_pixbuf(applet->ap_status_icon, + applet->ap_icon_stages_buff[ICON_DEFAULT] ); - applet->m_iAnimator = 0; + applet->ap_animator = 0; } } @@ -432,7 +432,7 @@ bool load_icons(struct applet *applet) GError *error = NULL; if (snprintf(name, sizeof(ICON_DIR"/abrt%02d.png"), ICON_DIR"/abrt%02d.png", stage) > 0) { - applet->icon_stages_buff[stage] = gdk_pixbuf_new_from_file(name, &error); + applet->ap_icon_stages_buff[stage] = gdk_pixbuf_new_from_file(name, &error); if (error != NULL) { error_msg("Can't load pixbuf from %s, animation is disabled", name); diff --git a/src/applet/CCApplet.h b/src/applet/CCApplet.h index ebcf78da..00e30862 100644 --- a/src/applet/CCApplet.h +++ b/src/applet/CCApplet.h @@ -37,38 +37,38 @@ enum ICON_STAGES }; struct applet { - GtkStatusIcon* m_pStatusIcon; - GtkWidget *m_pMenu; + GtkStatusIcon *ap_status_icon; + GtkWidget *ap_menu; // std::map m_mapEvents; - bool m_bDaemonRunning; - int m_iAnimationStage; - guint m_iAnimator; - unsigned m_iAnimCountdown; - bool m_bIconsLoaded; - const char *m_pLastCrashID; + bool ap_daemon_running; + int ap_animation_stage; + guint ap_animator; + unsigned ap_anim_countdown; + bool ap_icons_loaded; + const char *ap_last_crash_id; - GdkPixbuf *icon_stages_buff[ICON_STAGE_LAST]; + GdkPixbuf *ap_icon_stages_buff[ICON_STAGE_LAST]; }; struct applet* applet_new(const char *app_name); void applet_destroy(struct applet *applet); -void ShowIcon(struct applet *applet); -void HideIcon(struct applet *applet); -void SetIconTooltip(struct applet *applet, const char *format, ...); -void CrashNotify(struct applet *applet, const char* crash_id, const char *format, ...); -void MessageNotify(struct applet *applet, const char *format, ...); -void Disable(struct applet *applet, const char *reason); -void Enable(struct applet *applet, const char *reason); +void show_icon(struct applet *applet); +void hide_icon(struct applet *applet); +void set_icon_tooltip(struct applet *applet, const char *format, ...); +void show_crash_notification(struct applet *applet, const char* crash_id, const char *format, ...); +void show_msg_notification(struct applet *applet, const char *format, ...); +void disable(struct applet *applet, const char *reason); +void enable(struct applet *applet, const char *reason); // static in next patch -void OnAppletActivate_CB(GtkStatusIcon *status_icon, gpointer user_data); +void on_applet_activate_cb(GtkStatusIcon *status_icon, gpointer user_data); //this action should open the reporter dialog directly, without showing the main window void action_report(NotifyNotification *notification, gchar *action, gpointer user_data); //this action should open the main window void action_open_gui(NotifyNotification *notification, gchar *action, gpointer user_data); -void OnMenuPopup_cb(GtkStatusIcon *status_icon, +void on_menu_popup_cb(GtkStatusIcon *status_icon, guint button, guint activate_time, gpointer user_data); -- cgit From a4ac49be48d414cab013dee91ba08fa92d46a8cc Mon Sep 17 00:00:00 2001 From: Nikola Pajkovsky Date: Fri, 27 Aug 2010 16:39:32 +0200 Subject: make some function static Signed-off-by: Nikola Pajkovsky Acked-off-by: Denys Vlasenko --- src/applet/CCApplet.cpp | 329 ++++++++++++++++++++++++------------------------ src/applet/CCApplet.h | 15 --- 2 files changed, 165 insertions(+), 179 deletions(-) (limited to 'src') diff --git a/src/applet/CCApplet.cpp b/src/applet/CCApplet.cpp index 1b18dba5..425e087e 100644 --- a/src/applet/CCApplet.cpp +++ b/src/applet/CCApplet.cpp @@ -22,6 +22,149 @@ #include "abrtlib.h" #include "CCApplet.h" +static bool load_icons(struct applet *applet) +{ + //FIXME: just a tmp workaround + return false; + int stage; + for (stage = ICON_DEFAULT; stage < ICON_STAGE_LAST; stage++) + { + char name[sizeof(ICON_DIR"/abrt%02d.png")]; + GError *error = NULL; + if (snprintf(name, sizeof(ICON_DIR"/abrt%02d.png"), ICON_DIR"/abrt%02d.png", stage) > 0) + { + applet->ap_icon_stages_buff[stage] = gdk_pixbuf_new_from_file(name, &error); + if (error != NULL) + { + error_msg("Can't load pixbuf from %s, animation is disabled", name); + return false; + } + } + } + return true; +} + +static void stop_animate_icon(struct applet *applet) +{ + /* applet->ap_animator should be 0 if icons are not loaded, so this should be safe */ + if (applet->ap_animator != 0) + { + g_source_remove(applet->ap_animator); + gtk_status_icon_set_from_pixbuf(applet->ap_status_icon, + applet->ap_icon_stages_buff[ICON_DEFAULT] + ); + applet->ap_animator = 0; + } +} + +//this action should open the reporter dialog directly, without showing the main window +static void action_report(NotifyNotification *notification, gchar *action, gpointer user_data) +{ + struct applet *applet = (struct applet *)user_data; + if (applet->ap_daemon_running) + { + pid_t pid = vfork(); + if (pid < 0) + perror_msg("vfork"); + if (pid == 0) + { /* child */ + char *buf = xasprintf("--report=%s", applet->ap_last_crash_id); + signal(SIGCHLD, SIG_DFL); /* undo SIG_IGN in abrt-applet */ + execl(BIN_DIR"/abrt-gui", "abrt-gui", buf, (char*) NULL); + /* Did not find abrt-gui in installation directory. Oh well */ + /* Trying to find it in PATH */ + execlp("abrt-gui", "abrt-gui", buf, (char*) NULL); + perror_msg_and_die("Can't execute abrt-gui"); + } + GError *err = NULL; + notify_notification_close(notification, &err); + if (err != NULL) + { + error_msg("%s", err->message); + g_error_free(err); + } + gtk_status_icon_set_visible(applet->ap_status_icon, false); + stop_animate_icon(applet); + } +} + +//this action should open the main window +static void action_open_gui(NotifyNotification *notification, gchar *action, gpointer user_data) +{ + struct applet *applet = (struct applet*)user_data; + if (applet->ap_daemon_running) + { + pid_t pid = vfork(); + if (pid < 0) + perror_msg("vfork"); + if (pid == 0) + { /* child */ + signal(SIGCHLD, SIG_DFL); /* undo SIG_IGN in abrt-applet */ + execl(BIN_DIR"/abrt-gui", "abrt-gui", (char*) NULL); + /* Did not find abrt-gui in installation directory. Oh well */ + /* Trying to find it in PATH */ + execlp("abrt-gui", "abrt-gui", (char*) NULL); + perror_msg_and_die("Can't execute abrt-gui"); + } + GError *err = NULL; + notify_notification_close(notification, &err); + if (err != NULL) + { + error_msg("%s", err->message); + g_error_free(err); + } + gtk_status_icon_set_visible(applet->ap_status_icon, false); + stop_animate_icon(applet); + } +} + +static void on_menu_popup_cb(GtkStatusIcon *status_icon, + guint button, + guint activate_time, + gpointer user_data) +{ + struct applet *applet = (struct applet*)user_data; + /* stop the animation */ + stop_animate_icon(applet); + + if (applet->ap_menu != NULL) + { + gtk_menu_popup(GTK_MENU(applet->ap_menu), + NULL, NULL, + gtk_status_icon_position_menu, + status_icon, button, activate_time); + } +} + +// why it is not named with suffix _cb when it is callback for g_timeout_add? +static gboolean update_icon(void *user_data) +{ + struct applet *applet = (struct applet*)user_data; + if (applet->ap_status_icon && applet->ap_animation_stage < ICON_STAGE_LAST) + { + gtk_status_icon_set_from_pixbuf(applet->ap_status_icon, + applet->ap_icon_stages_buff[applet->ap_animation_stage++]); + } + if (applet->ap_animation_stage == ICON_STAGE_LAST) + { + applet->ap_animation_stage = 0; + } + if (--applet->ap_anim_countdown == 0) + { + stop_animate_icon(applet); + } + return true; +} + +static void animate_icon(struct applet* applet) +{ + if (applet->ap_animator == 0) + { + applet->ap_animator = g_timeout_add(100, update_icon, applet); + applet->ap_anim_countdown = 10 * 3; /* 3 sec */ + } +} + static void on_notify_close(NotifyNotification *notification, gpointer user_data) { g_object_unref(notification); @@ -126,6 +269,28 @@ static GtkWidget *create_menu(struct applet *applet) return menu; } +static void on_applet_activate_cb(GtkStatusIcon *status_icon, gpointer user_data) +{ + struct applet *applet = (struct applet*)user_data; + if (applet->ap_daemon_running) + { + pid_t pid = vfork(); + if (pid < 0) + perror_msg("vfork"); + if (pid == 0) + { /* child */ + signal(SIGCHLD, SIG_DFL); /* undo SIG_IGN in abrt-applet */ + execl(BIN_DIR"/abrt-gui", "abrt-gui", (char*) NULL); + /* Did not find abrt-gui in installation directory. Oh well */ + /* Trying to find it in PATH */ + execlp("abrt-gui", "abrt-gui", (char*) NULL); + perror_msg_and_die("Can't execute abrt-gui"); + } + gtk_status_icon_set_visible(applet->ap_status_icon, false); + stop_animate_icon(applet); + } +} + struct applet *applet_new(const char* app_name) { struct applet *applet = (struct applet*)xzalloc(sizeof(struct applet)); @@ -181,65 +346,6 @@ void set_icon_tooltip(struct applet *applet, const char *format, ...) free(buf); } -void action_report(NotifyNotification *notification, gchar *action, gpointer user_data) -{ - struct applet *applet = (struct applet *)user_data; - if (applet->ap_daemon_running) - { - pid_t pid = vfork(); - if (pid < 0) - perror_msg("vfork"); - if (pid == 0) - { /* child */ - char *buf = xasprintf("--report=%s", applet->ap_last_crash_id); - signal(SIGCHLD, SIG_DFL); /* undo SIG_IGN in abrt-applet */ - execl(BIN_DIR"/abrt-gui", "abrt-gui", buf, (char*) NULL); - /* Did not find abrt-gui in installation directory. Oh well */ - /* Trying to find it in PATH */ - execlp("abrt-gui", "abrt-gui", buf, (char*) NULL); - perror_msg_and_die("Can't execute abrt-gui"); - } - GError *err = NULL; - notify_notification_close(notification, &err); - if (err != NULL) - { - error_msg("%s", err->message); - g_error_free(err); - } - gtk_status_icon_set_visible(applet->ap_status_icon, false); - stop_animate_icon(applet); - } -} - -void action_open_gui(NotifyNotification *notification, gchar *action, gpointer user_data) -{ - struct applet *applet = (struct applet*)user_data; - if (applet->ap_daemon_running) - { - pid_t pid = vfork(); - if (pid < 0) - perror_msg("vfork"); - if (pid == 0) - { /* child */ - signal(SIGCHLD, SIG_DFL); /* undo SIG_IGN in abrt-applet */ - execl(BIN_DIR"/abrt-gui", "abrt-gui", (char*) NULL); - /* Did not find abrt-gui in installation directory. Oh well */ - /* Trying to find it in PATH */ - execlp("abrt-gui", "abrt-gui", (char*) NULL); - perror_msg_and_die("Can't execute abrt-gui"); - } - GError *err = NULL; - notify_notification_close(notification, &err); - if (err != NULL) - { - error_msg("%s", err->message); - g_error_free(err); - } - gtk_status_icon_set_visible(applet->ap_status_icon, false); - stop_animate_icon(applet); - } -} - void show_crash_notification(struct applet *applet, const char* crash_id, const char *format, ...) { applet->ap_last_crash_id = crash_id; @@ -294,46 +400,6 @@ void show_msg_notification(struct applet *applet, const char *format, ...) } } -void on_applet_activate_cb(GtkStatusIcon *status_icon, gpointer user_data) -{ - struct applet *applet = (struct applet*)user_data; - if (applet->ap_daemon_running) - { - pid_t pid = vfork(); - if (pid < 0) - perror_msg("vfork"); - if (pid == 0) - { /* child */ - signal(SIGCHLD, SIG_DFL); /* undo SIG_IGN in abrt-applet */ - execl(BIN_DIR"/abrt-gui", "abrt-gui", (char*) NULL); - /* Did not find abrt-gui in installation directory. Oh well */ - /* Trying to find it in PATH */ - execlp("abrt-gui", "abrt-gui", (char*) NULL); - perror_msg_and_die("Can't execute abrt-gui"); - } - gtk_status_icon_set_visible(applet->ap_status_icon, false); - stop_animate_icon(applet); - } -} - -void on_menu_popup_cb(GtkStatusIcon *status_icon, - guint button, - guint activate_time, - gpointer user_data) -{ - struct applet *applet = (struct applet*)user_data; - /* stop the animation */ - stop_animate_icon(applet); - - if (applet->ap_menu != NULL) - { - gtk_menu_popup(GTK_MENU(applet->ap_menu), - NULL, NULL, - gtk_status_icon_position_menu, - status_icon, button, activate_time); - } -} - void show_icon(struct applet *applet) { gtk_status_icon_set_visible(applet->ap_status_icon, true); @@ -379,71 +445,6 @@ void enable(struct applet *applet, const char *reason) show_icon(applet); } -// why it is not named with suffix _cb when it is callback for g_timeout_add? -gboolean update_icon(void *user_data) -{ - struct applet *applet = (struct applet*)user_data; - if (applet->ap_status_icon && applet->ap_animation_stage < ICON_STAGE_LAST) - { - gtk_status_icon_set_from_pixbuf(applet->ap_status_icon, - applet->ap_icon_stages_buff[applet->ap_animation_stage++]); - } - if (applet->ap_animation_stage == ICON_STAGE_LAST) - { - applet->ap_animation_stage = 0; - } - if (--applet->ap_anim_countdown == 0) - { - stop_animate_icon(applet); - } - return true; -} - -void animate_icon(struct applet* applet) -{ - if (applet->ap_animator == 0) - { - applet->ap_animator = g_timeout_add(100, update_icon, applet); - applet->ap_anim_countdown = 10 * 3; /* 3 sec */ - } -} - -void stop_animate_icon(struct applet *applet) -{ - /* ap_animator should be 0 if icons are not loaded, so this should be safe */ - if (applet->ap_animator != 0) - { - g_source_remove(applet->ap_animator); - gtk_status_icon_set_from_pixbuf(applet->ap_status_icon, - applet->ap_icon_stages_buff[ICON_DEFAULT] - ); - applet->ap_animator = 0; - } -} - -bool load_icons(struct applet *applet) -{ - //FIXME: just a tmp workaround - return false; - int stage; - for (stage = ICON_DEFAULT; stage < ICON_STAGE_LAST; stage++) - { - char name[sizeof(ICON_DIR"/abrt%02d.png")]; - GError *error = NULL; - if (snprintf(name, sizeof(ICON_DIR"/abrt%02d.png"), ICON_DIR"/abrt%02d.png", stage) > 0) - { - applet->ap_icon_stages_buff[stage] = gdk_pixbuf_new_from_file(name, &error); - if (error != NULL) - { - error_msg("Can't load pixbuf from %s, animation is disabled", name); - return false; - } - } - } - return true; -} - - //int CApplet::AddEvent(int pUUID, const char *pProgname) //{ // m_mapEvents[pUUID] = "pProgname"; diff --git a/src/applet/CCApplet.h b/src/applet/CCApplet.h index 00e30862..a6045fbe 100644 --- a/src/applet/CCApplet.h +++ b/src/applet/CCApplet.h @@ -62,19 +62,4 @@ void show_msg_notification(struct applet *applet, const char *format, ...); void disable(struct applet *applet, const char *reason); void enable(struct applet *applet, const char *reason); -// static in next patch -void on_applet_activate_cb(GtkStatusIcon *status_icon, gpointer user_data); -//this action should open the reporter dialog directly, without showing the main window -void action_report(NotifyNotification *notification, gchar *action, gpointer user_data); -//this action should open the main window -void action_open_gui(NotifyNotification *notification, gchar *action, gpointer user_data); -void on_menu_popup_cb(GtkStatusIcon *status_icon, - guint button, - guint activate_time, - gpointer user_data); -gboolean update_icon(void *data); -void animate_icon(struct applet *applet); -void stop_animate_icon(struct applet *applet); -bool load_icons(struct applet *applet); - #endif -- cgit From f439923af5fb38430fd839296e27a965c2ea6a13 Mon Sep 17 00:00:00 2001 From: Nikola Pajkovsky Date: Fri, 27 Aug 2010 16:49:15 +0200 Subject: remove unused std::map and std::string Signed-off-by: Nikola Pajkovsky Acked-off-by: Denys Vlasenko --- src/applet/CCApplet.cpp | 15 --------------- src/applet/CCApplet.h | 5 ----- 2 files changed, 20 deletions(-) (limited to 'src') diff --git a/src/applet/CCApplet.cpp b/src/applet/CCApplet.cpp index 425e087e..ff4387c5 100644 --- a/src/applet/CCApplet.cpp +++ b/src/applet/CCApplet.cpp @@ -316,8 +316,6 @@ struct applet *applet_new(const char* app_name) g_signal_connect(G_OBJECT(applet->ap_status_icon), "activate", GTK_SIGNAL_FUNC(on_applet_activate_cb), applet); g_signal_connect(G_OBJECT(applet->ap_status_icon), "popup_menu", GTK_SIGNAL_FUNC(on_menu_popup_cb), applet); -// SetIconTooltip(_("Pending events: %i"), m_mapEvents.size()); - applet->ap_menu = create_menu(applet); return applet; } @@ -444,16 +442,3 @@ void enable(struct applet *applet, const char *reason) gtk_status_icon_set_from_stock(applet->ap_status_icon, GTK_STOCK_DIALOG_WARNING); show_icon(applet); } - -//int CApplet::AddEvent(int pUUID, const char *pProgname) -//{ -// m_mapEvents[pUUID] = "pProgname"; -// SetIconTooltip(_("Pending events: %i"), m_mapEvents.size()); -// return 0; -//} -// -//int CApplet::RemoveEvent(int pUUID) -//{ -// m_mapEvents.erase(pUUID); -// return 0; -//} diff --git a/src/applet/CCApplet.h b/src/applet/CCApplet.h index a6045fbe..6e599a19 100644 --- a/src/applet/CCApplet.h +++ b/src/applet/CCApplet.h @@ -20,8 +20,6 @@ #define CC_APPLET_H_ #include -#include -#include #include enum ICON_STAGES @@ -39,15 +37,12 @@ enum ICON_STAGES struct applet { GtkStatusIcon *ap_status_icon; GtkWidget *ap_menu; - -// std::map m_mapEvents; bool ap_daemon_running; int ap_animation_stage; guint ap_animator; unsigned ap_anim_countdown; bool ap_icons_loaded; const char *ap_last_crash_id; - GdkPixbuf *ap_icon_stages_buff[ICON_STAGE_LAST]; }; -- cgit From daeb21ab2819d1581979311faa87c45e17dacd03 Mon Sep 17 00:00:00 2001 From: Nikola Pajkovsky Date: Fri, 27 Aug 2010 17:03:56 +0200 Subject: CCApplet.cpp -> applet_gtk.c Signed-off-by: Nikola Pajkovsky Acked-off-by: Denys Vlasenko --- src/applet/Applet.cpp | 2 +- src/applet/CCApplet.cpp | 444 ------------------------------------------------ src/applet/CCApplet.h | 60 ------- src/applet/Makefile.am | 2 +- src/applet/applet_gtk.c | 444 ++++++++++++++++++++++++++++++++++++++++++++++++ src/applet/applet_gtk.h | 68 ++++++++ 6 files changed, 514 insertions(+), 506 deletions(-) delete mode 100644 src/applet/CCApplet.cpp delete mode 100644 src/applet/CCApplet.h create mode 100644 src/applet/applet_gtk.c create mode 100644 src/applet/applet_gtk.h (limited to 'src') diff --git a/src/applet/Applet.cpp b/src/applet/Applet.cpp index 239f7a04..7529e854 100644 --- a/src/applet/Applet.cpp +++ b/src/applet/Applet.cpp @@ -28,7 +28,7 @@ #include "abrtlib.h" #include "abrt_dbus.h" #include "dbus_common.h" -#include "CCApplet.h" +#include "applet_gtk.h" static struct applet* applet = NULL; diff --git a/src/applet/CCApplet.cpp b/src/applet/CCApplet.cpp deleted file mode 100644 index ff4387c5..00000000 --- a/src/applet/CCApplet.cpp +++ /dev/null @@ -1,444 +0,0 @@ -/* - Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com) - Copyright (C) 2009 RedHat inc. - - 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 Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#if HAVE_CONFIG_H -# include -#endif -#include "abrtlib.h" -#include "CCApplet.h" - -static bool load_icons(struct applet *applet) -{ - //FIXME: just a tmp workaround - return false; - int stage; - for (stage = ICON_DEFAULT; stage < ICON_STAGE_LAST; stage++) - { - char name[sizeof(ICON_DIR"/abrt%02d.png")]; - GError *error = NULL; - if (snprintf(name, sizeof(ICON_DIR"/abrt%02d.png"), ICON_DIR"/abrt%02d.png", stage) > 0) - { - applet->ap_icon_stages_buff[stage] = gdk_pixbuf_new_from_file(name, &error); - if (error != NULL) - { - error_msg("Can't load pixbuf from %s, animation is disabled", name); - return false; - } - } - } - return true; -} - -static void stop_animate_icon(struct applet *applet) -{ - /* applet->ap_animator should be 0 if icons are not loaded, so this should be safe */ - if (applet->ap_animator != 0) - { - g_source_remove(applet->ap_animator); - gtk_status_icon_set_from_pixbuf(applet->ap_status_icon, - applet->ap_icon_stages_buff[ICON_DEFAULT] - ); - applet->ap_animator = 0; - } -} - -//this action should open the reporter dialog directly, without showing the main window -static void action_report(NotifyNotification *notification, gchar *action, gpointer user_data) -{ - struct applet *applet = (struct applet *)user_data; - if (applet->ap_daemon_running) - { - pid_t pid = vfork(); - if (pid < 0) - perror_msg("vfork"); - if (pid == 0) - { /* child */ - char *buf = xasprintf("--report=%s", applet->ap_last_crash_id); - signal(SIGCHLD, SIG_DFL); /* undo SIG_IGN in abrt-applet */ - execl(BIN_DIR"/abrt-gui", "abrt-gui", buf, (char*) NULL); - /* Did not find abrt-gui in installation directory. Oh well */ - /* Trying to find it in PATH */ - execlp("abrt-gui", "abrt-gui", buf, (char*) NULL); - perror_msg_and_die("Can't execute abrt-gui"); - } - GError *err = NULL; - notify_notification_close(notification, &err); - if (err != NULL) - { - error_msg("%s", err->message); - g_error_free(err); - } - gtk_status_icon_set_visible(applet->ap_status_icon, false); - stop_animate_icon(applet); - } -} - -//this action should open the main window -static void action_open_gui(NotifyNotification *notification, gchar *action, gpointer user_data) -{ - struct applet *applet = (struct applet*)user_data; - if (applet->ap_daemon_running) - { - pid_t pid = vfork(); - if (pid < 0) - perror_msg("vfork"); - if (pid == 0) - { /* child */ - signal(SIGCHLD, SIG_DFL); /* undo SIG_IGN in abrt-applet */ - execl(BIN_DIR"/abrt-gui", "abrt-gui", (char*) NULL); - /* Did not find abrt-gui in installation directory. Oh well */ - /* Trying to find it in PATH */ - execlp("abrt-gui", "abrt-gui", (char*) NULL); - perror_msg_and_die("Can't execute abrt-gui"); - } - GError *err = NULL; - notify_notification_close(notification, &err); - if (err != NULL) - { - error_msg("%s", err->message); - g_error_free(err); - } - gtk_status_icon_set_visible(applet->ap_status_icon, false); - stop_animate_icon(applet); - } -} - -static void on_menu_popup_cb(GtkStatusIcon *status_icon, - guint button, - guint activate_time, - gpointer user_data) -{ - struct applet *applet = (struct applet*)user_data; - /* stop the animation */ - stop_animate_icon(applet); - - if (applet->ap_menu != NULL) - { - gtk_menu_popup(GTK_MENU(applet->ap_menu), - NULL, NULL, - gtk_status_icon_position_menu, - status_icon, button, activate_time); - } -} - -// why it is not named with suffix _cb when it is callback for g_timeout_add? -static gboolean update_icon(void *user_data) -{ - struct applet *applet = (struct applet*)user_data; - if (applet->ap_status_icon && applet->ap_animation_stage < ICON_STAGE_LAST) - { - gtk_status_icon_set_from_pixbuf(applet->ap_status_icon, - applet->ap_icon_stages_buff[applet->ap_animation_stage++]); - } - if (applet->ap_animation_stage == ICON_STAGE_LAST) - { - applet->ap_animation_stage = 0; - } - if (--applet->ap_anim_countdown == 0) - { - stop_animate_icon(applet); - } - return true; -} - -static void animate_icon(struct applet* applet) -{ - if (applet->ap_animator == 0) - { - applet->ap_animator = g_timeout_add(100, update_icon, applet); - applet->ap_anim_countdown = 10 * 3; /* 3 sec */ - } -} - -static void on_notify_close(NotifyNotification *notification, gpointer user_data) -{ - g_object_unref(notification); -} - -static NotifyNotification *new_warn_notification() -{ - NotifyNotification *notification; - notification = notify_notification_new(_("Warning"), NULL, NULL, NULL); - g_signal_connect(notification, "closed", G_CALLBACK(on_notify_close), NULL); - - GdkPixbuf *pixbuf = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), - GTK_STOCK_DIALOG_WARNING, 48, GTK_ICON_LOOKUP_USE_BUILTIN, NULL); - - if (pixbuf) - notify_notification_set_icon_from_pixbuf(notification, pixbuf); - notify_notification_set_urgency(notification, NOTIFY_URGENCY_NORMAL); - notify_notification_set_timeout(notification, NOTIFY_EXPIRES_DEFAULT); - - return notification; -} - - -static void on_hide_cb(GtkMenuItem *menuitem, gpointer applet) -{ - if (applet) - hide_icon((struct applet*)applet); -} - -static void on_about_cb(GtkMenuItem *menuitem, gpointer dialog) -{ - if (dialog) - { - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_hide(GTK_WIDGET(dialog)); - } -} - -static GtkWidget *create_about_dialog() -{ - const char *copyright_str = "Copyright © 2009 Red Hat, Inc\nCopyright © 2010 Red Hat, Inc"; - const char *license_str = "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." - "\n\nThis 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." - "\n\nYou should have received a copy of the GNU General Public License along with this program. If not, see ."; - - const char *website_url = "https://fedorahosted.org/abrt/"; - const char *authors[] = {"Anton Arapov ", - "Karel Klic ", - "Jiri Moskovcak ", - "Nikola Pajkovsky ", - "Zdenek Prikryl ", - "Denys Vlasenko ", - NULL}; - - const char *artists[] = {"Patrick Connelly ", - "Lapo Calamandrei", - NULL}; - - const char *comments = _("Notification area applet that notifies users about " - "issues detected by ABRT"); - GtkWidget *about_d = gtk_about_dialog_new(); - if (about_d) - { - gtk_window_set_default_icon_name("abrt"); - gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(about_d), VERSION); - gtk_about_dialog_set_logo_icon_name(GTK_ABOUT_DIALOG(about_d), "abrt"); - gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(about_d), comments); - gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(about_d), "ABRT"); - gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(about_d), copyright_str); - gtk_about_dialog_set_license(GTK_ABOUT_DIALOG(about_d), license_str); - gtk_about_dialog_set_wrap_license(GTK_ABOUT_DIALOG(about_d),true); - gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(about_d), website_url); - gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(about_d), authors); - gtk_about_dialog_set_artists(GTK_ABOUT_DIALOG(about_d), artists); - gtk_about_dialog_set_translator_credits(GTK_ABOUT_DIALOG(about_d), _("translator-credits")); - } - return about_d; -} - -static GtkWidget *create_menu(struct applet *applet) -{ - GtkWidget *menu = gtk_menu_new(); - GtkWidget *b_quit = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, NULL); - g_signal_connect(b_quit, "activate", gtk_main_quit, NULL); - GtkWidget *b_hide = gtk_menu_item_new_with_label(_("Hide")); - g_signal_connect(b_hide, "activate", G_CALLBACK(on_hide_cb), applet); - GtkWidget *b_about = gtk_image_menu_item_new_from_stock(GTK_STOCK_ABOUT, NULL); - GtkWidget *about_dialog = create_about_dialog(); - g_signal_connect(b_about, "activate", G_CALLBACK(on_about_cb), about_dialog); - GtkWidget *separator = gtk_separator_menu_item_new(); - if (menu) - { - gtk_menu_shell_append(GTK_MENU_SHELL(menu),b_hide); - gtk_widget_show(b_hide); - gtk_menu_shell_append(GTK_MENU_SHELL(menu),b_about); - gtk_widget_show(b_about); - gtk_menu_shell_append(GTK_MENU_SHELL(menu),separator); - gtk_widget_show(separator); - gtk_menu_shell_append(GTK_MENU_SHELL(menu),b_quit); - gtk_widget_show(b_quit); - } - return menu; -} - -static void on_applet_activate_cb(GtkStatusIcon *status_icon, gpointer user_data) -{ - struct applet *applet = (struct applet*)user_data; - if (applet->ap_daemon_running) - { - pid_t pid = vfork(); - if (pid < 0) - perror_msg("vfork"); - if (pid == 0) - { /* child */ - signal(SIGCHLD, SIG_DFL); /* undo SIG_IGN in abrt-applet */ - execl(BIN_DIR"/abrt-gui", "abrt-gui", (char*) NULL); - /* Did not find abrt-gui in installation directory. Oh well */ - /* Trying to find it in PATH */ - execlp("abrt-gui", "abrt-gui", (char*) NULL); - perror_msg_and_die("Can't execute abrt-gui"); - } - gtk_status_icon_set_visible(applet->ap_status_icon, false); - stop_animate_icon(applet); - } -} - -struct applet *applet_new(const char* app_name) -{ - struct applet *applet = (struct applet*)xzalloc(sizeof(struct applet)); - applet->ap_daemon_running = true; - /* set-up icon buffers */ - if (ICON_DEFAULT != 0) - applet->ap_animation_stage = ICON_DEFAULT; - applet->ap_icons_loaded = load_icons(applet); - /* - animation - */ - if (applet->ap_icons_loaded == true) - { - //FIXME: animation is disabled for now - applet->ap_status_icon = gtk_status_icon_new_from_pixbuf(applet->ap_icon_stages_buff[ICON_DEFAULT]); - } - else - { - applet->ap_status_icon = gtk_status_icon_new_from_icon_name("abrt"); - } - notify_init(app_name); - - gtk_status_icon_set_visible(applet->ap_status_icon, FALSE); - - g_signal_connect(G_OBJECT(applet->ap_status_icon), "activate", GTK_SIGNAL_FUNC(on_applet_activate_cb), applet); - g_signal_connect(G_OBJECT(applet->ap_status_icon), "popup_menu", GTK_SIGNAL_FUNC(on_menu_popup_cb), applet); - - applet->ap_menu = create_menu(applet); - return applet; -} - -void applet_destroy(struct applet *applet) -{ - if (notify_is_initted()) - notify_uninit(); - - free(applet); -} - -void set_icon_tooltip(struct applet *applet, const char *format, ...) -{ - va_list args; - int n; - char *buf; - - // xvasprintf? - va_start(args, format); - buf = NULL; - n = vasprintf(&buf, format, args); - va_end(args); - - gtk_status_icon_set_tooltip_text(applet->ap_status_icon, (n >= 0 && buf) ? buf : ""); - free(buf); -} - -void show_crash_notification(struct applet *applet, const char* crash_id, const char *format, ...) -{ - applet->ap_last_crash_id = crash_id; - va_list args; - va_start(args, format); - char *buf = xvasprintf(format, args); - va_end(args); - - NotifyNotification *notification = new_warn_notification(); - notify_notification_add_action(notification, "REPORT", _("Report"), - NOTIFY_ACTION_CALLBACK(action_report), - applet, NULL); - notify_notification_add_action(notification, "OPEN_MAIN_WINDOW", _("Open ABRT"), - NOTIFY_ACTION_CALLBACK(action_open_gui), - applet, NULL); - - notify_notification_update(notification, _("Warning"), buf, NULL); - free(buf); - GError *err = NULL; - notify_notification_show(notification, &err); - if (err != NULL) - { - error_msg("%s", err->message); - g_error_free(err); - } -} - -void show_msg_notification(struct applet *applet, const char *format, ...) -{ - va_list args; - - va_start(args, format); - char *buf = xvasprintf(format, args); - va_end(args); - - /* we don't want to show any buttons now, - maybe later we can add action binded to message - like >>Clear old dumps<< for quota exceeded - */ - NotifyNotification *notification = new_warn_notification(); - notify_notification_add_action(notification, "OPEN_MAIN_WINDOW", _("Open ABRT"), - NOTIFY_ACTION_CALLBACK(action_open_gui), - applet, NULL); - notify_notification_update(notification, _("Warning"), buf, NULL); - free(buf); - GError *err = NULL; - notify_notification_show(notification, &err); - if (err != NULL) - { - error_msg("%s", err->message); - g_error_free(err); - } -} - -void show_icon(struct applet *applet) -{ - gtk_status_icon_set_visible(applet->ap_status_icon, true); - /* only animate if all icons are loaded, use the "gtk-warning" instead */ - if (applet->ap_icons_loaded) - animate_icon(applet); -} - -void hide_icon(struct applet *applet) -{ - gtk_status_icon_set_visible(applet->ap_status_icon, false); - stop_animate_icon(applet); -} - -void disable(struct applet *applet, const char *reason) -{ - /* - FIXME: once we have our icon - */ - applet->ap_daemon_running = false; - GdkPixbuf *gray_scaled; - GdkPixbuf *pixbuf = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), - GTK_STOCK_DIALOG_WARNING, 24, GTK_ICON_LOOKUP_USE_BUILTIN, NULL); - if (pixbuf) - { - gray_scaled = gdk_pixbuf_copy(pixbuf); - gdk_pixbuf_saturate_and_pixelate(pixbuf, gray_scaled, 0.0, false); - gtk_status_icon_set_from_pixbuf(applet->ap_status_icon, gray_scaled); -//do we need to free pixbufs nere? - } - else - error_msg("Can't load icon"); - set_icon_tooltip(applet, reason); - show_icon(applet); -} - -void enable(struct applet *applet, const char *reason) -{ - /* restore the original icon */ - applet->ap_daemon_running = true; - set_icon_tooltip(applet, reason); - gtk_status_icon_set_from_stock(applet->ap_status_icon, GTK_STOCK_DIALOG_WARNING); - show_icon(applet); -} diff --git a/src/applet/CCApplet.h b/src/applet/CCApplet.h deleted file mode 100644 index 6e599a19..00000000 --- a/src/applet/CCApplet.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com) - Copyright (C) 2009 RedHat inc. - - 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 Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#ifndef CC_APPLET_H_ -#define CC_APPLET_H_ - -#include -#include - -enum ICON_STAGES -{ - ICON_DEFAULT, - ICON_STAGE1, - ICON_STAGE2, - ICON_STAGE3, - ICON_STAGE4, - ICON_STAGE5, - /* this must be always the last */ - ICON_STAGE_LAST -}; - -struct applet { - GtkStatusIcon *ap_status_icon; - GtkWidget *ap_menu; - bool ap_daemon_running; - int ap_animation_stage; - guint ap_animator; - unsigned ap_anim_countdown; - bool ap_icons_loaded; - const char *ap_last_crash_id; - GdkPixbuf *ap_icon_stages_buff[ICON_STAGE_LAST]; -}; - -struct applet* applet_new(const char *app_name); -void applet_destroy(struct applet *applet); - -void show_icon(struct applet *applet); -void hide_icon(struct applet *applet); -void set_icon_tooltip(struct applet *applet, const char *format, ...); -void show_crash_notification(struct applet *applet, const char* crash_id, const char *format, ...); -void show_msg_notification(struct applet *applet, const char *format, ...); -void disable(struct applet *applet, const char *reason); -void enable(struct applet *applet, const char *reason); - -#endif diff --git a/src/applet/Makefile.am b/src/applet/Makefile.am index 743c18df..55e28733 100644 --- a/src/applet/Makefile.am +++ b/src/applet/Makefile.am @@ -2,7 +2,7 @@ bin_PROGRAMS = abrt-applet abrt_applet_SOURCES = \ Applet.cpp \ - CCApplet.h CCApplet.cpp + applet_gtk.h applet_gtk.c abrt_applet_CPPFLAGS = \ -Wall -Werror \ -I$(srcdir)/../../inc \ diff --git a/src/applet/applet_gtk.c b/src/applet/applet_gtk.c new file mode 100644 index 00000000..7a9fcc0c --- /dev/null +++ b/src/applet/applet_gtk.c @@ -0,0 +1,444 @@ +/* + Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com) + Copyright (C) 2009 RedHat inc. + + 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 Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +#if HAVE_CONFIG_H +# include +#endif +#include "abrtlib.h" +#include "applet_gtk.h" + +static bool load_icons(struct applet *applet) +{ + //FIXME: just a tmp workaround + return false; + int stage; + for (stage = ICON_DEFAULT; stage < ICON_STAGE_LAST; stage++) + { + char name[sizeof(ICON_DIR"/abrt%02d.png")]; + GError *error = NULL; + if (snprintf(name, sizeof(ICON_DIR"/abrt%02d.png"), ICON_DIR"/abrt%02d.png", stage) > 0) + { + applet->ap_icon_stages_buff[stage] = gdk_pixbuf_new_from_file(name, &error); + if (error != NULL) + { + error_msg("Can't load pixbuf from %s, animation is disabled", name); + return false; + } + } + } + return true; +} + +static void stop_animate_icon(struct applet *applet) +{ + /* applet->ap_animator should be 0 if icons are not loaded, so this should be safe */ + if (applet->ap_animator != 0) + { + g_source_remove(applet->ap_animator); + gtk_status_icon_set_from_pixbuf(applet->ap_status_icon, + applet->ap_icon_stages_buff[ICON_DEFAULT] + ); + applet->ap_animator = 0; + } +} + +//this action should open the reporter dialog directly, without showing the main window +static void action_report(NotifyNotification *notification, gchar *action, gpointer user_data) +{ + struct applet *applet = (struct applet *)user_data; + if (applet->ap_daemon_running) + { + pid_t pid = vfork(); + if (pid < 0) + perror_msg("vfork"); + if (pid == 0) + { /* child */ + char *buf = xasprintf("--report=%s", applet->ap_last_crash_id); + signal(SIGCHLD, SIG_DFL); /* undo SIG_IGN in abrt-applet */ + execl(BIN_DIR"/abrt-gui", "abrt-gui", buf, (char*) NULL); + /* Did not find abrt-gui in installation directory. Oh well */ + /* Trying to find it in PATH */ + execlp("abrt-gui", "abrt-gui", buf, (char*) NULL); + perror_msg_and_die("Can't execute abrt-gui"); + } + GError *err = NULL; + notify_notification_close(notification, &err); + if (err != NULL) + { + error_msg("%s", err->message); + g_error_free(err); + } + gtk_status_icon_set_visible(applet->ap_status_icon, false); + stop_animate_icon(applet); + } +} + +//this action should open the main window +static void action_open_gui(NotifyNotification *notification, gchar *action, gpointer user_data) +{ + struct applet *applet = (struct applet*)user_data; + if (applet->ap_daemon_running) + { + pid_t pid = vfork(); + if (pid < 0) + perror_msg("vfork"); + if (pid == 0) + { /* child */ + signal(SIGCHLD, SIG_DFL); /* undo SIG_IGN in abrt-applet */ + execl(BIN_DIR"/abrt-gui", "abrt-gui", (char*) NULL); + /* Did not find abrt-gui in installation directory. Oh well */ + /* Trying to find it in PATH */ + execlp("abrt-gui", "abrt-gui", (char*) NULL); + perror_msg_and_die("Can't execute abrt-gui"); + } + GError *err = NULL; + notify_notification_close(notification, &err); + if (err != NULL) + { + error_msg("%s", err->message); + g_error_free(err); + } + gtk_status_icon_set_visible(applet->ap_status_icon, false); + stop_animate_icon(applet); + } +} + +static void on_menu_popup_cb(GtkStatusIcon *status_icon, + guint button, + guint activate_time, + gpointer user_data) +{ + struct applet *applet = (struct applet*)user_data; + /* stop the animation */ + stop_animate_icon(applet); + + if (applet->ap_menu != NULL) + { + gtk_menu_popup(GTK_MENU(applet->ap_menu), + NULL, NULL, + gtk_status_icon_position_menu, + status_icon, button, activate_time); + } +} + +// why it is not named with suffix _cb when it is callback for g_timeout_add? +static gboolean update_icon(void *user_data) +{ + struct applet *applet = (struct applet*)user_data; + if (applet->ap_status_icon && applet->ap_animation_stage < ICON_STAGE_LAST) + { + gtk_status_icon_set_from_pixbuf(applet->ap_status_icon, + applet->ap_icon_stages_buff[applet->ap_animation_stage++]); + } + if (applet->ap_animation_stage == ICON_STAGE_LAST) + { + applet->ap_animation_stage = 0; + } + if (--applet->ap_anim_countdown == 0) + { + stop_animate_icon(applet); + } + return true; +} + +static void animate_icon(struct applet* applet) +{ + if (applet->ap_animator == 0) + { + applet->ap_animator = g_timeout_add(100, update_icon, applet); + applet->ap_anim_countdown = 10 * 3; /* 3 sec */ + } +} + +static void on_notify_close(NotifyNotification *notification, gpointer user_data) +{ + g_object_unref(notification); +} + +static NotifyNotification *new_warn_notification() +{ + NotifyNotification *notification; + notification = notify_notification_new(_("Warning"), NULL, NULL, NULL); + g_signal_connect(notification, "closed", G_CALLBACK(on_notify_close), NULL); + + GdkPixbuf *pixbuf = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), + GTK_STOCK_DIALOG_WARNING, 48, GTK_ICON_LOOKUP_USE_BUILTIN, NULL); + + if (pixbuf) + notify_notification_set_icon_from_pixbuf(notification, pixbuf); + notify_notification_set_urgency(notification, NOTIFY_URGENCY_NORMAL); + notify_notification_set_timeout(notification, NOTIFY_EXPIRES_DEFAULT); + + return notification; +} + + +static void on_hide_cb(GtkMenuItem *menuitem, gpointer applet) +{ + if (applet) + hide_icon((struct applet*)applet); +} + +static void on_about_cb(GtkMenuItem *menuitem, gpointer dialog) +{ + if (dialog) + { + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_hide(GTK_WIDGET(dialog)); + } +} + +static GtkWidget *create_about_dialog() +{ + const char *copyright_str = "Copyright © 2009 Red Hat, Inc\nCopyright © 2010 Red Hat, Inc"; + const char *license_str = "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." + "\n\nThis 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." + "\n\nYou should have received a copy of the GNU General Public License along with this program. If not, see ."; + + const char *website_url = "https://fedorahosted.org/abrt/"; + const char *authors[] = {"Anton Arapov ", + "Karel Klic ", + "Jiri Moskovcak ", + "Nikola Pajkovsky ", + "Zdenek Prikryl ", + "Denys Vlasenko ", + NULL}; + + const char *artists[] = {"Patrick Connelly ", + "Lapo Calamandrei", + NULL}; + + const char *comments = _("Notification area applet that notifies users about " + "issues detected by ABRT"); + GtkWidget *about_d = gtk_about_dialog_new(); + if (about_d) + { + gtk_window_set_default_icon_name("abrt"); + gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(about_d), VERSION); + gtk_about_dialog_set_logo_icon_name(GTK_ABOUT_DIALOG(about_d), "abrt"); + gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(about_d), comments); + gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(about_d), "ABRT"); + gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(about_d), copyright_str); + gtk_about_dialog_set_license(GTK_ABOUT_DIALOG(about_d), license_str); + gtk_about_dialog_set_wrap_license(GTK_ABOUT_DIALOG(about_d),true); + gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(about_d), website_url); + gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(about_d), authors); + gtk_about_dialog_set_artists(GTK_ABOUT_DIALOG(about_d), artists); + gtk_about_dialog_set_translator_credits(GTK_ABOUT_DIALOG(about_d), _("translator-credits")); + } + return about_d; +} + +static GtkWidget *create_menu(struct applet *applet) +{ + GtkWidget *menu = gtk_menu_new(); + GtkWidget *b_quit = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, NULL); + g_signal_connect(b_quit, "activate", gtk_main_quit, NULL); + GtkWidget *b_hide = gtk_menu_item_new_with_label(_("Hide")); + g_signal_connect(b_hide, "activate", G_CALLBACK(on_hide_cb), applet); + GtkWidget *b_about = gtk_image_menu_item_new_from_stock(GTK_STOCK_ABOUT, NULL); + GtkWidget *about_dialog = create_about_dialog(); + g_signal_connect(b_about, "activate", G_CALLBACK(on_about_cb), about_dialog); + GtkWidget *separator = gtk_separator_menu_item_new(); + if (menu) + { + gtk_menu_shell_append(GTK_MENU_SHELL(menu),b_hide); + gtk_widget_show(b_hide); + gtk_menu_shell_append(GTK_MENU_SHELL(menu),b_about); + gtk_widget_show(b_about); + gtk_menu_shell_append(GTK_MENU_SHELL(menu),separator); + gtk_widget_show(separator); + gtk_menu_shell_append(GTK_MENU_SHELL(menu),b_quit); + gtk_widget_show(b_quit); + } + return menu; +} + +static void on_applet_activate_cb(GtkStatusIcon *status_icon, gpointer user_data) +{ + struct applet *applet = (struct applet*)user_data; + if (applet->ap_daemon_running) + { + pid_t pid = vfork(); + if (pid < 0) + perror_msg("vfork"); + if (pid == 0) + { /* child */ + signal(SIGCHLD, SIG_DFL); /* undo SIG_IGN in abrt-applet */ + execl(BIN_DIR"/abrt-gui", "abrt-gui", (char*) NULL); + /* Did not find abrt-gui in installation directory. Oh well */ + /* Trying to find it in PATH */ + execlp("abrt-gui", "abrt-gui", (char*) NULL); + perror_msg_and_die("Can't execute abrt-gui"); + } + gtk_status_icon_set_visible(applet->ap_status_icon, false); + stop_animate_icon(applet); + } +} + +struct applet *applet_new(const char* app_name) +{ + struct applet *applet = (struct applet*)xzalloc(sizeof(struct applet)); + applet->ap_daemon_running = true; + /* set-up icon buffers */ + if (ICON_DEFAULT != 0) + applet->ap_animation_stage = ICON_DEFAULT; + applet->ap_icons_loaded = load_icons(applet); + /* - animation - */ + if (applet->ap_icons_loaded == true) + { + //FIXME: animation is disabled for now + applet->ap_status_icon = gtk_status_icon_new_from_pixbuf(applet->ap_icon_stages_buff[ICON_DEFAULT]); + } + else + { + applet->ap_status_icon = gtk_status_icon_new_from_icon_name("abrt"); + } + notify_init(app_name); + + gtk_status_icon_set_visible(applet->ap_status_icon, FALSE); + + g_signal_connect(G_OBJECT(applet->ap_status_icon), "activate", GTK_SIGNAL_FUNC(on_applet_activate_cb), applet); + g_signal_connect(G_OBJECT(applet->ap_status_icon), "popup_menu", GTK_SIGNAL_FUNC(on_menu_popup_cb), applet); + + applet->ap_menu = create_menu(applet); + return applet; +} + +void applet_destroy(struct applet *applet) +{ + if (notify_is_initted()) + notify_uninit(); + + free(applet); +} + +void set_icon_tooltip(struct applet *applet, const char *format, ...) +{ + va_list args; + int n; + char *buf; + + // xvasprintf? + va_start(args, format); + buf = NULL; + n = vasprintf(&buf, format, args); + va_end(args); + + gtk_status_icon_set_tooltip_text(applet->ap_status_icon, (n >= 0 && buf) ? buf : ""); + free(buf); +} + +void show_crash_notification(struct applet *applet, const char* crash_id, const char *format, ...) +{ + applet->ap_last_crash_id = crash_id; + va_list args; + va_start(args, format); + char *buf = xvasprintf(format, args); + va_end(args); + + NotifyNotification *notification = new_warn_notification(); + notify_notification_add_action(notification, "REPORT", _("Report"), + NOTIFY_ACTION_CALLBACK(action_report), + applet, NULL); + notify_notification_add_action(notification, "OPEN_MAIN_WINDOW", _("Open ABRT"), + NOTIFY_ACTION_CALLBACK(action_open_gui), + applet, NULL); + + notify_notification_update(notification, _("Warning"), buf, NULL); + free(buf); + GError *err = NULL; + notify_notification_show(notification, &err); + if (err != NULL) + { + error_msg("%s", err->message); + g_error_free(err); + } +} + +void show_msg_notification(struct applet *applet, const char *format, ...) +{ + va_list args; + + va_start(args, format); + char *buf = xvasprintf(format, args); + va_end(args); + + /* we don't want to show any buttons now, + maybe later we can add action binded to message + like >>Clear old dumps<< for quota exceeded + */ + NotifyNotification *notification = new_warn_notification(); + notify_notification_add_action(notification, "OPEN_MAIN_WINDOW", _("Open ABRT"), + NOTIFY_ACTION_CALLBACK(action_open_gui), + applet, NULL); + notify_notification_update(notification, _("Warning"), buf, NULL); + free(buf); + GError *err = NULL; + notify_notification_show(notification, &err); + if (err != NULL) + { + error_msg("%s", err->message); + g_error_free(err); + } +} + +void show_icon(struct applet *applet) +{ + gtk_status_icon_set_visible(applet->ap_status_icon, true); + /* only animate if all icons are loaded, use the "gtk-warning" instead */ + if (applet->ap_icons_loaded) + animate_icon(applet); +} + +void hide_icon(struct applet *applet) +{ + gtk_status_icon_set_visible(applet->ap_status_icon, false); + stop_animate_icon(applet); +} + +void disable(struct applet *applet, const char *reason) +{ + /* + FIXME: once we have our icon + */ + applet->ap_daemon_running = false; + GdkPixbuf *gray_scaled; + GdkPixbuf *pixbuf = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), + GTK_STOCK_DIALOG_WARNING, 24, GTK_ICON_LOOKUP_USE_BUILTIN, NULL); + if (pixbuf) + { + gray_scaled = gdk_pixbuf_copy(pixbuf); + gdk_pixbuf_saturate_and_pixelate(pixbuf, gray_scaled, 0.0, false); + gtk_status_icon_set_from_pixbuf(applet->ap_status_icon, gray_scaled); +//do we need to free pixbufs nere? + } + else + error_msg("Can't load icon"); + set_icon_tooltip(applet, reason); + show_icon(applet); +} + +void enable(struct applet *applet, const char *reason) +{ + /* restore the original icon */ + applet->ap_daemon_running = true; + set_icon_tooltip(applet, reason); + gtk_status_icon_set_from_stock(applet->ap_status_icon, GTK_STOCK_DIALOG_WARNING); + show_icon(applet); +} diff --git a/src/applet/applet_gtk.h b/src/applet/applet_gtk.h new file mode 100644 index 00000000..0bcf47b7 --- /dev/null +++ b/src/applet/applet_gtk.h @@ -0,0 +1,68 @@ +/* + Copyright (C) 2009 Jiri Moskovcak (jmoskovc@redhat.com) + Copyright (C) 2009 RedHat inc. + + 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 Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +#ifndef CC_APPLET_H_ +#define CC_APPLET_H_ + +#include +#include + +enum ICON_STAGES +{ + ICON_DEFAULT, + ICON_STAGE1, + ICON_STAGE2, + ICON_STAGE3, + ICON_STAGE4, + ICON_STAGE5, + /* this must be always the last */ + ICON_STAGE_LAST +}; + +#ifdef __cplusplus +extern "C" { +#endif + +struct applet { + GtkStatusIcon *ap_status_icon; + GtkWidget *ap_menu; + bool ap_daemon_running; + int ap_animation_stage; + guint ap_animator; + unsigned ap_anim_countdown; + bool ap_icons_loaded; + const char *ap_last_crash_id; + GdkPixbuf *ap_icon_stages_buff[ICON_STAGE_LAST]; +}; + +struct applet* applet_new(const char *app_name); +void applet_destroy(struct applet *applet); + +void show_icon(struct applet *applet); +void hide_icon(struct applet *applet); +void set_icon_tooltip(struct applet *applet, const char *format, ...); +void show_crash_notification(struct applet *applet, const char* crash_id, const char *format, ...); +void show_msg_notification(struct applet *applet, const char *format, ...); +void disable(struct applet *applet, const char *reason); +void enable(struct applet *applet, const char *reason); + +#ifdef __cplusplus +} +#endif + +#endif -- cgit From d781199df58b5cb6561a0ce0e04f4e54359c5fb5 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 30 Aug 2010 16:43:37 +0200 Subject: abrt_dbus: preparatory patch for C++ -> c conversion Signed-off-by: Denys Vlasenko --- src/applet/Applet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/applet/Applet.cpp b/src/applet/Applet.cpp index 7529e854..b83c3d2c 100644 --- a/src/applet/Applet.cpp +++ b/src/applet/Applet.cpp @@ -242,7 +242,7 @@ int main(int argc, char** argv) dbus_error_init(&err); DBusConnection* system_conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err); die_if_dbus_error(system_conn == NULL, &err, "Can't connect to system dbus"); - attach_dbus_conn_to_glib_main_loop(system_conn); + attach_dbus_conn_to_glib_main_loop(system_conn, NULL, NULL); if (!dbus_connection_add_filter(system_conn, handle_message, NULL, NULL)) error_msg_and_die("Can't add dbus filter"); /* which messages do we want to be fed to handle_message()? */ -- cgit From bd71db9397fbf2fa585ada04bce151e800801c73 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 30 Aug 2010 16:56:03 +0200 Subject: consolidate HAVE_CONFIG_H in abrtlib.h Signed-off-by: Denys Vlasenko --- src/applet/Applet.cpp | 3 --- src/applet/applet_gtk.c | 3 --- src/cli/CLI.cpp | 3 --- src/cli/report.cpp | 3 --- src/daemon/CommLayerServerDBus.cpp | 3 --- src/daemon/Daemon.cpp | 3 --- 6 files changed, 18 deletions(-) (limited to 'src') diff --git a/src/applet/Applet.cpp b/src/applet/Applet.cpp index b83c3d2c..cc29fbde 100644 --- a/src/applet/Applet.cpp +++ b/src/applet/Applet.cpp @@ -16,9 +16,6 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#if HAVE_CONFIG_H -# include -#endif #if HAVE_LOCALE_H # include #endif diff --git a/src/applet/applet_gtk.c b/src/applet/applet_gtk.c index 7a9fcc0c..e7b18bda 100644 --- a/src/applet/applet_gtk.c +++ b/src/applet/applet_gtk.c @@ -16,9 +16,6 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#if HAVE_CONFIG_H -# include -#endif #include "abrtlib.h" #include "applet_gtk.h" diff --git a/src/cli/CLI.cpp b/src/cli/CLI.cpp index 425ab2d5..b9c0397a 100644 --- a/src/cli/CLI.cpp +++ b/src/cli/CLI.cpp @@ -15,9 +15,6 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#if HAVE_CONFIG_H -# include -#endif #if HAVE_LOCALE_H # include #endif diff --git a/src/cli/report.cpp b/src/cli/report.cpp index 9584feb5..f56050fb 100644 --- a/src/cli/report.cpp +++ b/src/cli/report.cpp @@ -18,9 +18,6 @@ #include #include #include -#if HAVE_CONFIG_H -# include -#endif #include "report.h" #include "run-command.h" #include "dbus.h" diff --git a/src/daemon/CommLayerServerDBus.cpp b/src/daemon/CommLayerServerDBus.cpp index 4a3c5add..e40b1093 100644 --- a/src/daemon/CommLayerServerDBus.cpp +++ b/src/daemon/CommLayerServerDBus.cpp @@ -16,9 +16,6 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#if HAVE_CONFIG_H -# include -#endif #include #include "abrtlib.h" #include "abrt_dbus.h" diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp index 83fc46ec..028c466c 100644 --- a/src/daemon/Daemon.cpp +++ b/src/daemon/Daemon.cpp @@ -16,9 +16,6 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#if HAVE_CONFIG_H -# include -#endif #if HAVE_LOCALE_H # include #endif -- cgit From f4b916d62e69bd2e6ff9690456a4a4557f449d24 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 30 Aug 2010 17:24:09 +0200 Subject: Use abrtlib.h instead of component header files Signed-off-by: Denys Vlasenko --- src/daemon/rpm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/daemon/rpm.c b/src/daemon/rpm.c index f9474d60..b85de015 100644 --- a/src/daemon/rpm.c +++ b/src/daemon/rpm.c @@ -16,10 +16,9 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -//#include "abrtlib.h" +#include "abrtlib.h" #include "rpm.h" #include "abrt_packages.h" -#include "logging.h" /** * A set, which contains finger prints. -- cgit From 57217567c66fdc728387e7222b2044a1cd0d68a6 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 30 Aug 2010 17:43:51 +0200 Subject: preparatory patch for dirsize.cpp -> dirsize.c conversion Signed-off-by: Denys Vlasenko --- src/daemon/Daemon.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp index 028c466c..ac845b1f 100644 --- a/src/daemon/Daemon.cpp +++ b/src/daemon/Daemon.cpp @@ -501,18 +501,19 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin if (g_settings_nMaxCrashReportsSize > 0) { - std::string worst_dir; + char *worst_dir = NULL; while (g_settings_nMaxCrashReportsSize > 0 && get_dirsize_find_largest_dir(DEBUG_DUMPS_DIR, &worst_dir, name) / (1024*1024) >= g_settings_nMaxCrashReportsSize - && worst_dir != "" + && worst_dir ) { - log("Size of '%s' >= %u MB, deleting '%s'", DEBUG_DUMPS_DIR, g_settings_nMaxCrashReportsSize, worst_dir.c_str()); + log("Size of '%s' >= %u MB, deleting '%s'", DEBUG_DUMPS_DIR, g_settings_nMaxCrashReportsSize, worst_dir); g_pCommLayer->QuotaExceed(_("The size of the report exceeded the quota. Please check system's MaxCrashReportsSize value in abrt.conf.")); /* deletes both directory and DB record */ - char *d = concat_path_file(DEBUG_DUMPS_DIR, worst_dir.c_str()); + char *d = concat_path_file(DEBUG_DUMPS_DIR, worst_dir); + free(worst_dir); + worst_dir = NULL; DeleteDebugDump_by_dir(d); free(d); - worst_dir = ""; } } -- cgit From dac728745922a717db05f2e8dcbe6c533dc0df6f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 30 Aug 2010 19:22:22 +0200 Subject: abrtlib.h: include and "strbuf.h" Signed-off-by: Denys Vlasenko --- src/daemon/MiddleWare.cpp | 1 - src/daemon/Settings.cpp | 3 +-- src/daemon/dumpsocket.cpp | 7 ++----- src/hooks/dumpoops.cpp | 1 - 4 files changed, 3 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/daemon/MiddleWare.cpp b/src/daemon/MiddleWare.cpp index 52131c5f..9872a412 100644 --- a/src/daemon/MiddleWare.cpp +++ b/src/daemon/MiddleWare.cpp @@ -21,7 +21,6 @@ #include #include #include "abrtlib.h" -#include "abrt_types.h" #include "Daemon.h" #include "Settings.h" #include "rpm.h" diff --git a/src/daemon/Settings.cpp b/src/daemon/Settings.cpp index 5dda12a0..6e0a82a5 100644 --- a/src/daemon/Settings.cpp +++ b/src/daemon/Settings.cpp @@ -16,9 +16,8 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "Settings.h" #include "abrtlib.h" -#include "abrt_types.h" +#include "Settings.h" #include "Polkit.h" #define SECTION_COMMON "Common" diff --git a/src/daemon/dumpsocket.cpp b/src/daemon/dumpsocket.cpp index 21421b81..f95197f6 100644 --- a/src/daemon/dumpsocket.cpp +++ b/src/daemon/dumpsocket.cpp @@ -15,17 +15,14 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "dumpsocket.h" -#include "abrtlib.h" #include -#include -#include #include +#include "abrtlib.h" +#include "dumpsocket.h" #include "debug_dump.h" #include "crash_types.h" #include "abrt_exception.h" #include "hooklib.h" -#include "strbuf.h" #define SOCKET_FILE VAR_RUN"/abrt/abrt.socket" #define SOCKET_PERMISSION 0666 diff --git a/src/hooks/dumpoops.cpp b/src/hooks/dumpoops.cpp index a14fb65b..04400373 100644 --- a/src/hooks/dumpoops.cpp +++ b/src/hooks/dumpoops.cpp @@ -22,7 +22,6 @@ */ #include "abrtlib.h" -#include "abrt_types.h" #include "abrt_exception.h" #include "KerneloopsScanner.h" #include -- cgit From eb6a80fe031f648d11344ed912e9a5e1e722545e Mon Sep 17 00:00:00 2001 From: Nikola Pajkovsky Date: Mon, 30 Aug 2010 19:28:08 +0200 Subject: get rid of CDebugDump class Signed-off-by: Denys Vlasenko --- src/daemon/MiddleWare.cpp | 230 ++++++++++++++++++++++++------------------- src/daemon/dumpsocket.cpp | 24 ++--- src/hooks/abrt-hook-ccpp.cpp | 22 ++--- 3 files changed, 153 insertions(+), 123 deletions(-) (limited to 'src') diff --git a/src/daemon/MiddleWare.cpp b/src/daemon/MiddleWare.cpp index 9872a412..e8c7d856 100644 --- a/src/daemon/MiddleWare.cpp +++ b/src/daemon/MiddleWare.cpp @@ -130,48 +130,52 @@ static char* is_text_file(const char *name, ssize_t *sz) return NULL; /* it's binary */ } -static void load_crash_data_from_debug_dump(CDebugDump& dd, map_crash_data_t& data) +static void load_crash_data_from_debug_dump(dump_dir_t *dd, map_crash_data_t& data) { - VERB3 log("load_crash_data_from_debug_dump: directory %s", dd.Directory()); - std::string short_name; - std::string full_name; + char *short_name; + char *full_name; - dd.InitGetNextFile(); - while (dd.GetNextFile(&short_name, &full_name)) + dd_init_next_file(dd); + while (dd_get_next_file(dd, &short_name, &full_name)) { - VERB3 log("load_crash_data_from_debug_dump: file '%s', '%s'", short_name.c_str(), full_name.c_str()); ssize_t sz = 4*1024; char *text = NULL; - bool editable = is_editable_file(short_name.c_str()); + bool editable = is_editable_file(short_name); if (!editable) { - text = is_text_file(full_name.c_str(), &sz); + text = is_text_file(full_name, &sz); if (!text) { add_to_crash_data_ext(data, - short_name.c_str(), + short_name, CD_BIN, CD_ISNOTEDITABLE, - full_name.c_str() + full_name ); + + free(short_name); + free(full_name); continue; } } - std::string content; + char *content; if (sz < 4*1024) /* is_text_file did read entire file */ - content.assign(text, sz); + content = xstrndup(text, sz); //TODO: can avoid this copying if is_text_file() adds NUL else /* no, need to read it all */ - dd.LoadText(short_name.c_str(), content); + content = dd_loadtxt(dd, short_name); free(text); add_to_crash_data_ext(data, - short_name.c_str(), + short_name, CD_TXT, editable ? CD_ISEDITABLE : CD_ISNOTEDITABLE, - content.c_str() + content ); + free(short_name); + free(full_name); + free(content); } } @@ -185,25 +189,28 @@ static bool DebugDumpToCrashReport(const char *pDebugDumpDir, map_crash_data_t& { VERB3 log(" DebugDumpToCrashReport('%s')", pDebugDumpDir); - CDebugDump dd; - if (dd.Open(pDebugDumpDir)) + dump_dir_t *dd = dd_init(); + if (dd_opendir(dd, pDebugDumpDir)) { const char *const *v = must_have_files; while (*v) { - if (!dd.Exist(*v)) + if (!dd_exist(dd, *v)) { + dd_close(dd); throw CABRTException(EXCEP_ERROR, "DebugDumpToCrashReport(): important file '%s' is missing", *v); } + v++; } load_crash_data_from_debug_dump(dd, pCrashData); - dd.Close(); + dd_close(dd); return true; } + dd_close(dd); return false; } @@ -293,14 +300,15 @@ mw_result_t CreateCrashReport(const char *crash_id, mw_result_t r = MW_OK; try { - CDebugDump dd; - if (dd.Open(row.m_sDebugDumpDir.c_str())) + dump_dir_t *dd = dd_init(); + if (!dd_opendir(dd, row.m_sDebugDumpDir.c_str())) { - load_crash_data_from_debug_dump(dd, pCrashData); - dd.Close(); - } - else + dd_close(dd); return MW_ERROR; + } + + load_crash_data_from_debug_dump(dd, pCrashData); + dd_close(dd); std::string analyzer = get_crash_data_item_content(pCrashData, FILENAME_ANALYZER); const char* package = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_PACKAGE); @@ -446,27 +454,26 @@ report_status_t Report(const map_crash_data_t& client_report, const char *backtrace = get_crash_data_item_content_or_NULL(client_report, FILENAME_BACKTRACE); if (comment || reproduce || backtrace) { - CDebugDump dd; - if (dd.Open(pDumpDir.c_str())) + dump_dir_t *dd = dd_init(); + if (dd_opendir(dd, pDumpDir.c_str())) { if (comment) { - dd.SaveText(FILENAME_COMMENT, comment); + dd_savetxt(dd, FILENAME_COMMENT, comment); add_to_crash_data_ext(stored_report, FILENAME_COMMENT, CD_TXT, CD_ISEDITABLE, comment); } if (reproduce) { - dd.SaveText(FILENAME_REPRODUCE, reproduce); + dd_savetxt(dd, FILENAME_REPRODUCE, reproduce); add_to_crash_data_ext(stored_report, FILENAME_REPRODUCE, CD_TXT, CD_ISEDITABLE, reproduce); } if (backtrace) { - dd.SaveText(FILENAME_BACKTRACE, backtrace); + dd_savetxt(dd, FILENAME_BACKTRACE, backtrace); add_to_crash_data_ext(stored_report, FILENAME_BACKTRACE, CD_TXT, CD_ISEDITABLE, backtrace); } - - dd.Close(); } + dd_close(dd); } /* Remove BIN filenames from stored_report if they are not present in client's data */ @@ -721,18 +728,19 @@ static mw_result_t SavePackageDescriptionToDebugDump( { VERB2 log("Crash in unpackaged executable '%s', proceeding without packaging information", pExecutable); - CDebugDump dd; - if (dd.Open(pDebugDumpDir)) + dump_dir_t *dd = dd_init(); + if (!dd_opendir(dd, pDebugDumpDir)) { - dd.SaveText(FILENAME_PACKAGE, ""); - dd.SaveText(FILENAME_COMPONENT, ""); - dd.SaveText(FILENAME_DESCRIPTION, "Crashed executable does not belong to any installed package"); - - dd.Close(); - return MW_OK; - } - else + dd_close(dd); return MW_ERROR; + } + + dd_savetxt(dd, FILENAME_PACKAGE, ""); + dd_savetxt(dd, FILENAME_COMPONENT, ""); + dd_savetxt(dd, FILENAME_DESCRIPTION, "Crashed executable does not belong to any installed package"); + + dd_close(dd); + return MW_OK; } else { @@ -845,32 +853,34 @@ static mw_result_t SavePackageDescriptionToDebugDump( } } - CDebugDump dd; - if (dd.Open(pDebugDumpDir)) + dump_dir_t *dd = dd_init(); + if (dd_opendir(dd, pDebugDumpDir)) { if (rpm_pkg) { - dd.SaveText(FILENAME_PACKAGE, rpm_pkg); + dd_savetxt(dd, FILENAME_PACKAGE, rpm_pkg); free(rpm_pkg); } if (dsc) { - dd.SaveText(FILENAME_DESCRIPTION, dsc); + dd_savetxt(dd, FILENAME_DESCRIPTION, dsc); free(dsc); } if (component) { - dd.SaveText(FILENAME_COMPONENT, component); + dd_savetxt(dd, FILENAME_COMPONENT, component); free(component); } if (!remote) - dd.SaveText(FILENAME_HOSTNAME, host); + dd_savetxt(dd, FILENAME_HOSTNAME, host); + dd_close(dd); return MW_OK; } + dd_close(dd); return MW_ERROR; } @@ -1027,66 +1037,85 @@ static mw_result_t SaveDebugDumpToDatabase(const char *crash_id, mw_result_t SaveDebugDump(const char *pDebugDumpDir, map_crash_data_t& pCrashData) { - std::string UID; - std::string time; - std::string analyzer; - std::string executable; - std::string cmdline; - bool remote = false; + mw_result_t res; + int remote = 0; - CDebugDump dd; - if (dd.Open(pDebugDumpDir)) + dump_dir_t *dd = dd_init(); + if (!dd_opendir(dd, pDebugDumpDir)) { - dd.LoadText(FILENAME_TIME, time); - dd.LoadText(CD_UID, UID); - dd.LoadText(FILENAME_ANALYZER, analyzer); - dd.LoadText(FILENAME_EXECUTABLE, executable); - dd.LoadText(FILENAME_CMDLINE, cmdline); - if (dd.Exist(FILENAME_REMOTE)) - { - std::string remote_str; - dd.LoadText(FILENAME_REMOTE, remote_str); - remote = (remote_str.find('1') != std::string::npos); - } - - dd.Close(); - } - else + dd_close(dd); return MW_ERROR; + } + + char *time = dd_loadtxt(dd, FILENAME_TIME); + char *uid = dd_loadtxt(dd, CD_UID); + char *analyzer = dd_loadtxt(dd, FILENAME_ANALYZER); + char *executable = dd_loadtxt(dd, FILENAME_EXECUTABLE); + char *cmdline = dd_loadtxt(dd, FILENAME_CMDLINE); + + char *remote_str = xstrdup(""); + if (dd_exist(dd, FILENAME_REMOTE)) + remote_str = dd_loadtxt(dd, FILENAME_REMOTE); + + dd_close(dd); /* Convert UID string to number uid_num. The UID string can be modified by user or wrongly saved (empty or non-numeric), so xatou() cannot be used here, because it would kill the daemon. */ char *endptr; errno = 0; - unsigned long uid_num = strtoul(UID.c_str(), &endptr, 10); - if (errno || UID.c_str() == endptr || *endptr != '\0' || uid_num > UINT_MAX) + unsigned long uid_num = strtoul(uid, &endptr, 10); + if (errno || uid == endptr || *endptr != '\0' || uid_num > UINT_MAX) { - error_msg("Invalid UID '%s' loaded from %s", UID.c_str(), pDebugDumpDir); - return MW_ERROR; + error_msg("Invalid UID '%s' loaded from %s", uid, pDebugDumpDir); + res = MW_ERROR; + goto error; } if (is_debug_dump_saved(uid_num, pDebugDumpDir)) - return MW_IN_DB; + { + res = MW_IN_DB; + goto error; + } - mw_result_t res = SavePackageDescriptionToDebugDump(executable.c_str(), cmdline.c_str(), remote, pDebugDumpDir); + if (remote_str[0]) + remote = remote_str[0] != '1'; + + res = SavePackageDescriptionToDebugDump(executable, + cmdline, + remote, + pDebugDumpDir + ); if (res != MW_OK) - return res; - - std::string UUID = GetLocalUUID(analyzer.c_str(), pDebugDumpDir); - std::string crash_id = ssprintf("%s:%s", UID.c_str(), UUID.c_str()); - /* Loads pCrashData (from the *first debugdump dir* if this one is a dup) - * Returns: - * MW_REPORTED: "the crash is flagged as reported in DB" (which also means it's a dup) - * MW_OCCURRED: "crash count is != 1" (iow: it is > 1 - dup) - * MW_OK: "crash count is 1" (iow: this is a new crash, not a dup) - * else: an error code - */ - return SaveDebugDumpToDatabase(crash_id.c_str(), - analyzer_has_InformAllUsers(analyzer.c_str()), - time.c_str(), - pDebugDumpDir, - pCrashData); + goto error; + + { + std::string UUID = GetLocalUUID((analyzer) ? analyzer : "", pDebugDumpDir); + std::string crash_id = ssprintf("%s:%s", uid, UUID.c_str()); + /* Loads pCrashData (from the *first debugdump dir* if this one is a dup) + * Returns: + * MW_REPORTED: "the crash is flagged as reported in DB" (which also means it's a dup) + * MW_OCCURRED: "crash count is != 1" (iow: it is > 1 - dup) + * MW_OK: "crash count is 1" (iow: this is a new crash, not a dup) + * else: an error code + */ + + res = SaveDebugDumpToDatabase(crash_id.c_str(), + analyzer_has_InformAllUsers(analyzer), + time, + pDebugDumpDir, + pCrashData); + } + +error: + free(remote_str); + free(time); + free(executable); + free(cmdline); + free(uid); + free(analyzer); + + return res; } mw_result_t FillCrashInfo(const char *crash_id, @@ -1102,14 +1131,15 @@ mw_result_t FillCrashInfo(const char *crash_id, std::string description; std::string analyzer; - CDebugDump dd; - if (dd.Open(row.m_sDebugDumpDir.c_str())) + dump_dir_t *dd = dd_init(); + if (!dd_opendir(dd, row.m_sDebugDumpDir.c_str())) { - load_crash_data_from_debug_dump(dd, pCrashData); - dd.Close(); - } - else + dd_close(dd); return MW_ERROR; + } + + load_crash_data_from_debug_dump(dd, pCrashData); + dd_close(dd); add_to_crash_data(pCrashData, CD_UID , row.m_sUID.c_str() ); add_to_crash_data(pCrashData, CD_UUID , row.m_sUUID.c_str() ); diff --git a/src/daemon/dumpsocket.cpp b/src/daemon/dumpsocket.cpp index f95197f6..999df00f 100644 --- a/src/daemon/dumpsocket.cpp +++ b/src/daemon/dumpsocket.cpp @@ -170,33 +170,33 @@ static void create_debug_dump(struct client *client) client->basename, (long)time(NULL), client->pid); - /* No need to check the path length, as all variables used are limited, and dd.Create() + /* No need to check the path length, as all variables used are limited, and dd_create() fails if the path is too long. */ - CDebugDump dd; - if (!dd.Create(path, client->uid)) + dump_dir_t *dd = dd_init();; + if (!dd_create(dd, path, client->uid)) { - dd.Delete(); - dd.Close(); + dd_delete(dd); + dd_close(dd); error_msg_and_die("dumpsocket: Error while creating crash dump %s", path); } - dd.SaveText(FILENAME_ANALYZER, client->analyzer); - dd.SaveText(FILENAME_EXECUTABLE, client->executable); - dd.SaveText(FILENAME_BACKTRACE, client->backtrace); - dd.SaveText(FILENAME_REASON, client->reason); + dd_savetxt(dd, FILENAME_ANALYZER, client->analyzer); + dd_savetxt(dd, FILENAME_EXECUTABLE, client->executable); + dd_savetxt(dd, FILENAME_BACKTRACE, client->backtrace); + dd_savetxt(dd, FILENAME_REASON, client->reason); /* Obtain and save the command line. */ char *cmdline = get_cmdline(client->pid); // never NULL - dd.SaveText(FILENAME_CMDLINE, cmdline); + dd_savetxt(dd, FILENAME_CMDLINE, cmdline); free(cmdline); /* Store id of the user whose application crashed. */ char uid_str[sizeof(long) * 3 + 2]; sprintf(uid_str, "%lu", (long)client->uid); - dd.SaveText(CD_UID, uid_str); + dd_savetxt(dd, CD_UID, uid_str); - dd.Close(); + dd_close(dd); /* Move the completely created debug dump to final directory. */ diff --git a/src/hooks/abrt-hook-ccpp.cpp b/src/hooks/abrt-hook-ccpp.cpp index 1e469890..4862c6c1 100644 --- a/src/hooks/abrt-hook-ccpp.cpp +++ b/src/hooks/abrt-hook-ccpp.cpp @@ -415,15 +415,15 @@ int main(int argc, char** argv) if (path_len >= (sizeof(path) - sizeof("/"FILENAME_COREDUMP))) return 1; - CDebugDump dd; - if (dd.Create(path, uid)) + dump_dir_t *dd = dd_init(); + if (dd_create(dd, path, uid)) { char *cmdline = get_cmdline(pid); /* never NULL */ char *reason = xasprintf("Process %s was killed by signal %s (SIG%s)", executable, signal_str, signame ? signame : signal_str); - dd.SaveText(FILENAME_ANALYZER, "CCpp"); - dd.SaveText(FILENAME_EXECUTABLE, executable); - dd.SaveText(FILENAME_CMDLINE, cmdline); - dd.SaveText(FILENAME_REASON, reason); + dd_savetxt(dd, FILENAME_ANALYZER, "CCpp"); + dd_savetxt(dd, FILENAME_EXECUTABLE, executable); + dd_savetxt(dd, FILENAME_CMDLINE, cmdline); + dd_savetxt(dd, FILENAME_REASON, reason); free(cmdline); free(reason); @@ -451,8 +451,8 @@ int main(int argc, char** argv) if (abrt_core_fd < 0) { int sv_errno = errno; - dd.Delete(); - dd.Close(); + dd_delete(dd); + dd_close(dd); if (user_core_fd >= 0) { xchdir(user_pwd); @@ -480,8 +480,8 @@ int main(int argc, char** argv) if (core_size < 0 || fsync(abrt_core_fd) != 0) { unlink(path); - dd.Delete(); - dd.Close(); + dd_delete(dd); + dd_close(dd); if (user_core_fd >= 0) { xchdir(user_pwd); @@ -505,7 +505,7 @@ int main(int argc, char** argv) * will wait for us), and we won't be able to delete their dumps. * Classic deadlock. */ - dd.Close(); + dd_close(dd); path[path_len] = '\0'; /* path now contains only directory name */ char *newpath = xstrndup(path, path_len - (sizeof(".new")-1)); if (rename(path, newpath) == 0) -- cgit