From 9fefdaeed15039877f525d2c6fae3e02318c4234 Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Sun, 15 Nov 2009 19:39:28 +0100 Subject: don't show icon on abrtd start/stop rhbz#537630 - this feature would show the icon even after abrt update, which would show the icon and thus might confuse user with the warning sign --- src/Applet/CCApplet.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/Applet/CCApplet.cpp') diff --git a/src/Applet/CCApplet.cpp b/src/Applet/CCApplet.cpp index bae0cf8..c230051 100644 --- a/src/Applet/CCApplet.cpp +++ b/src/Applet/CCApplet.cpp @@ -243,10 +243,10 @@ void CApplet::onAbout_cb(GtkMenuItem *menuitem, gpointer dialog) gtk_widget_hide(GTK_WIDGET(dialog)); } -//void CApplet::HideIcon() -//{ -// gtk_status_icon_set_visible(m_pStatusIcon, false); -//} +void CApplet::HideIcon() +{ + gtk_status_icon_set_visible(m_pStatusIcon, false); +} void CApplet::Disable(const char *reason) { -- cgit From b497ec740fa242d71d9c5bb2b168707ac13b001b Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Mon, 16 Nov 2009 10:08:03 +0100 Subject: APPLET: changed icon from default gtk-warning to abrt specific, add animation - there were complaints about abrt using standard warning icon, which is confusing, so I changed it to use abrt spefic icon and made it move, to attract user attention --- src/Applet/CCApplet.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 3 deletions(-) (limited to 'src/Applet/CCApplet.cpp') diff --git a/src/Applet/CCApplet.cpp b/src/Applet/CCApplet.cpp index c230051..228c6b9 100644 --- a/src/Applet/CCApplet.cpp +++ b/src/Applet/CCApplet.cpp @@ -108,9 +108,13 @@ You should have received a copy of the GNU General Public License along with thi CApplet::CApplet() { - m_pStatusIcon = gtk_status_icon_new_from_stock(GTK_STOCK_DIALOG_WARNING); m_bDaemonRunning = true; - + /* set-up icon buffers */ + animator = 0; + animation_stage = ICON_DEFAULT; + load_icons(); + /* - animation - */ + m_pStatusIcon = gtk_status_icon_new_from_pixbuf(icon_stages_buff[ICON_DEFAULT]); notify_init("ABRT"); m_pNotification = notify_notification_new_with_status_icon("Warning", NULL, NULL, m_pStatusIcon); notify_notification_set_urgency(m_pNotification, NOTIFY_URGENCY_CRITICAL); @@ -215,18 +219,26 @@ void CApplet::OnMenuPopup_cb(GtkStatusIcon *status_icon, guint activate_time, gpointer user_data) { - if (((CApplet *)user_data)->m_pMenu != NULL) + CApplet *applet = (CApplet *)user_data; + /* stop the animation */ + applet->stop_animate_icon(); + gtk_status_icon_set_from_pixbuf(applet->m_pStatusIcon, applet->icon_stages_buff[ICON_DEFAULT]); + + if (applet->m_pMenu != NULL) { gtk_menu_popup(GTK_MENU(((CApplet *)user_data)->m_pMenu), NULL, NULL, gtk_status_icon_position_menu, status_icon, button, activate_time); } + } void CApplet::ShowIcon() { gtk_status_icon_set_visible(m_pStatusIcon, true); + animate_icon(); + //gtk_status_icon_set_visible(m_pStatusIcon, true); //Active wait for icon to be REALLY visible in status area //while(!gtk_status_icon_is_embedded(m_pStatusIcon)) continue; } @@ -246,6 +258,7 @@ void CApplet::onAbout_cb(GtkMenuItem *menuitem, gpointer dialog) void CApplet::HideIcon() { gtk_status_icon_set_visible(m_pStatusIcon, false); + stop_animate_icon(); } void CApplet::Disable(const char *reason) @@ -279,6 +292,52 @@ void CApplet::Enable(const char *reason) ShowIcon(); } +gboolean CApplet::update_icon(void *applet) +{ + if(((CApplet*)applet)->m_pStatusIcon && ((CApplet*)applet)->animation_stage < ICON_STAGE_LAST){ + gtk_status_icon_set_from_pixbuf(((CApplet*)applet)->m_pStatusIcon, + ((CApplet*)applet)->icon_stages_buff[((CApplet*)applet)->animation_stage++]); + } + else + error_msg("icon is null"); + if(((CApplet*)applet)->animation_stage == ICON_STAGE_LAST){ + ((CApplet*)applet)->animation_stage = 0; + } + return true; +} + +void CApplet::animate_icon() +{ + if(animator == 0) + { + animator = g_timeout_add(100, update_icon, this); + } +} + +void CApplet::stop_animate_icon() +{ + if(animator != 0){ + g_source_remove(animator); + animator = 0; + } +} + +void CApplet::load_icons() +{ + int stage = ICON_DEFAULT; + for(stage = ICON_DEFAULT; stage < ICON_STAGE_LAST; stage++) + { + char *name; + GError *error = NULL; + name = g_strdup_printf(ICON_DIR"/abrt%02d.png", stage); + icon_stages_buff[stage] = gdk_pixbuf_new_from_file(name, &error); + if(error != NULL) + error_msg("Can't load pixbuf from %s\n", name); + g_free(name); + } +} + + //int CApplet::AddEvent(int pUUID, const std::string& pProgname) //{ // m_mapEvents[pUUID] = "pProgname"; -- cgit From 80a2d45c6ce729fc778d2ecc00569635cf886e7b Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Mon, 16 Nov 2009 19:31:03 +0100 Subject: APPLET: fixes based on review from Denys - fixed coding style - some optimalization - added fallback if loading icons fails --- src/Applet/CCApplet.cpp | 69 ++++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 29 deletions(-) (limited to 'src/Applet/CCApplet.cpp') diff --git a/src/Applet/CCApplet.cpp b/src/Applet/CCApplet.cpp index 228c6b9..704ecce 100644 --- a/src/Applet/CCApplet.cpp +++ b/src/Applet/CCApplet.cpp @@ -110,11 +110,18 @@ CApplet::CApplet() { m_bDaemonRunning = true; /* set-up icon buffers */ - animator = 0; - animation_stage = ICON_DEFAULT; - load_icons(); + m_iAnimator = 0; + m_iAnimationStage = ICON_DEFAULT; + m_bIconsLoaded = load_icons(); /* - animation - */ - m_pStatusIcon = gtk_status_icon_new_from_pixbuf(icon_stages_buff[ICON_DEFAULT]); + if(m_bIconsLoaded == true) + { + m_pStatusIcon = gtk_status_icon_new_from_pixbuf(icon_stages_buff[ICON_DEFAULT]); + } + else + { + m_pStatusIcon = gtk_status_icon_new_from_stock(GTK_STOCK_DIALOG_WARNING); + } notify_init("ABRT"); m_pNotification = notify_notification_new_with_status_icon("Warning", NULL, NULL, m_pStatusIcon); notify_notification_set_urgency(m_pNotification, NOTIFY_URGENCY_CRITICAL); @@ -190,7 +197,7 @@ void CApplet::CrashNotify(const char *format, ...) if (gtk_status_icon_is_embedded(m_pStatusIcon)) notify_notification_show(m_pNotification, &err); if (err != NULL) - g_print(err->message); + error_msg(err->message); } void CApplet::OnAppletActivate_CB(GtkStatusIcon *status_icon, gpointer user_data) @@ -222,7 +229,6 @@ void CApplet::OnMenuPopup_cb(GtkStatusIcon *status_icon, CApplet *applet = (CApplet *)user_data; /* stop the animation */ applet->stop_animate_icon(); - gtk_status_icon_set_from_pixbuf(applet->m_pStatusIcon, applet->icon_stages_buff[ICON_DEFAULT]); if (applet->m_pMenu != NULL) { @@ -237,10 +243,9 @@ void CApplet::OnMenuPopup_cb(GtkStatusIcon *status_icon, void CApplet::ShowIcon() { gtk_status_icon_set_visible(m_pStatusIcon, true); - animate_icon(); - //gtk_status_icon_set_visible(m_pStatusIcon, true); - //Active wait for icon to be REALLY visible in status area - //while(!gtk_status_icon_is_embedded(m_pStatusIcon)) continue; + /* only animate if all icons are loaded, use the "gtk-warning" instead */ + if(m_bIconsLoaded) + animate_icon(); } void CApplet::onHide_cb(GtkMenuItem *menuitem, gpointer applet) @@ -292,49 +297,55 @@ void CApplet::Enable(const char *reason) ShowIcon(); } -gboolean CApplet::update_icon(void *applet) +gboolean CApplet::update_icon(void *user_data) { - if(((CApplet*)applet)->m_pStatusIcon && ((CApplet*)applet)->animation_stage < ICON_STAGE_LAST){ - gtk_status_icon_set_from_pixbuf(((CApplet*)applet)->m_pStatusIcon, - ((CApplet*)applet)->icon_stages_buff[((CApplet*)applet)->animation_stage++]); + CApplet* applet = (CApplet*)user_data; + if(applet->m_pStatusIcon && applet->m_iAnimationStage < ICON_STAGE_LAST){ + gtk_status_icon_set_from_pixbuf(applet->m_pStatusIcon, + applet->icon_stages_buff[applet->m_iAnimationStage++]); } else error_msg("icon is null"); - if(((CApplet*)applet)->animation_stage == ICON_STAGE_LAST){ - ((CApplet*)applet)->animation_stage = 0; + if(applet->m_iAnimationStage == ICON_STAGE_LAST){ + applet->m_iAnimationStage = 0; } return true; } void CApplet::animate_icon() { - if(animator == 0) + if(m_iAnimator == 0) { - animator = g_timeout_add(100, update_icon, this); + m_iAnimator = g_timeout_add(100, update_icon, this); } } void CApplet::stop_animate_icon() { - if(animator != 0){ - g_source_remove(animator); - animator = 0; + /* animator should be 0 if icons are not loaded, so this should be safe */ + if(m_iAnimator != 0){ + g_source_remove(m_iAnimator); + gtk_status_icon_set_from_pixbuf(m_pStatusIcon, icon_stages_buff[ICON_DEFAULT]); + m_iAnimator = 0; } } -void CApplet::load_icons() +bool CApplet::load_icons() { - int stage = ICON_DEFAULT; + int stage; for(stage = ICON_DEFAULT; stage < ICON_STAGE_LAST; stage++) { - char *name; + char name[sizeof(ICON_DIR"/abrt%02d.png")]; GError *error = NULL; - name = g_strdup_printf(ICON_DIR"/abrt%02d.png", stage); - icon_stages_buff[stage] = gdk_pixbuf_new_from_file(name, &error); - if(error != NULL) - error_msg("Can't load pixbuf from %s\n", name); - g_free(name); + 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); + if(error != NULL){ + error_msg("Can't load pixbuf from %s, animation is disabled!", name); + return false; + } + } } + return true; } -- cgit From 344a3dcc7a22e0e5dd74fe0bfb0483220c3dc7ad Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 18 Nov 2009 14:00:56 +0100 Subject: whitespace cleanups Signed-off-by: Denys Vlasenko --- src/Applet/CCApplet.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/Applet/CCApplet.cpp') diff --git a/src/Applet/CCApplet.cpp b/src/Applet/CCApplet.cpp index 704ecce..e6a3cf0 100644 --- a/src/Applet/CCApplet.cpp +++ b/src/Applet/CCApplet.cpp @@ -229,7 +229,7 @@ void CApplet::OnMenuPopup_cb(GtkStatusIcon *status_icon, CApplet *applet = (CApplet *)user_data; /* stop the animation */ applet->stop_animate_icon(); - + if (applet->m_pMenu != NULL) { gtk_menu_popup(GTK_MENU(((CApplet *)user_data)->m_pMenu), @@ -237,7 +237,6 @@ void CApplet::OnMenuPopup_cb(GtkStatusIcon *status_icon, gtk_status_icon_position_menu, status_icon, button, activate_time); } - } void CApplet::ShowIcon() -- cgit