summaryrefslogtreecommitdiffstats
path: root/src/Applet
diff options
context:
space:
mode:
authorJiri Moskovcak <jmoskovc@redhat.com>2009-08-24 14:48:19 +0200
committerJiri Moskovcak <jmoskovc@redhat.com>2009-08-24 14:48:19 +0200
commitd7d556c512c9e22702d4123e95a16398df148489 (patch)
tree1a9d0dac6baffe3807b78cba39c33656a3b9329a /src/Applet
parent5a84344a06a3a75dd9ac74e2692c74aa73717c07 (diff)
downloadabrt-d7d556c512c9e22702d4123e95a16398df148489.tar.gz
abrt-d7d556c512c9e22702d4123e95a16398df148489.tar.xz
abrt-d7d556c512c9e22702d4123e95a16398df148489.zip
APPLET: added popup menu (trac#37, rhbz#518386)
Diffstat (limited to 'src/Applet')
-rw-r--r--src/Applet/CCApplet.cpp56
-rw-r--r--src/Applet/CCApplet.h8
-rw-r--r--src/Applet/Makefile.am2
-rw-r--r--src/Applet/popup.GtkBuilder23
4 files changed, 84 insertions, 5 deletions
diff --git a/src/Applet/CCApplet.cpp b/src/Applet/CCApplet.cpp
index 32c1fe50..bebc2f92 100644
--- a/src/Applet/CCApplet.cpp
+++ b/src/Applet/CCApplet.cpp
@@ -26,6 +26,30 @@
static const char *DBUS_SERVICE_NAME = "org.freedesktop.DBus";
static const char *DBUS_SERVICE_PATH = "/org/freedesktop/DBus";
+const gchar *CApplet::menu_xml =
+ "<?xml version=\"1.0\"?>\
+ <interface>\
+ <requires lib=\"gtk+\" version=\"2.16\"/>\
+ <!-- interface-naming-policy project-wide -->\
+ <object class=\"GtkMenu\" id=\"popup_menu\">\
+ <property name=\"visible\">True</property>\
+ <child>\
+ <object class=\"GtkMenuItem\" id=\"miHide\">\
+ <property name=\"visible\">True</property>\
+ <property name=\"label\" translatable=\"yes\">Hide</property>\
+ </object>\
+ </child>\
+ <child>\
+ <object class=\"GtkImageMenuItem\" id=\"miQuit\">\
+ <property name=\"label\">gtk-quit</property>\
+ <property name=\"visible\">True</property>\
+ <property name=\"use_underline\">True</property>\
+ <property name=\"use_stock\">True</property>\
+ <property name=\"always_show_image\">True</property>\
+ </object>\
+ </child>\
+ </object>\
+ </interface>";
CApplet::CApplet(DBus::Connection &connection, const char *path, const char *name)
: DBus::ObjectProxy(connection, path, name)
@@ -39,11 +63,29 @@ CApplet::CApplet(DBus::Connection &connection, const char *path, const char *nam
notify_notification_set_urgency(m_pNotification, NOTIFY_URGENCY_CRITICAL);
notify_notification_set_timeout(m_pNotification, 5000);
gtk_status_icon_set_visible(m_pStatusIcon, FALSE);
- // LMB click
- //TODO add some actions!
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);
SetIconTooltip("Pending events: %i", m_mapEvents.size());
+ m_pBuilder = gtk_builder_new();
+ if(gtk_builder_add_from_string(m_pBuilder, menu_xml, strlen(menu_xml), NULL))
+ {
+ m_pMenu = gtk_builder_get_object(m_pBuilder, "popup_menu");
+ //gtk_menu_attach_to_widget(GTK_MENU(m_pMenu), GTK_WIDGET(m_pStatusIcon), NULL);
+ m_pmiHide = gtk_builder_get_object(m_pBuilder, "miHide");
+ if(m_pmiHide != NULL)
+ {
+ g_signal_connect(m_pmiHide,"activate", G_CALLBACK(CApplet::onHide_cb), this);
+ }
+ m_pmiQuit = gtk_builder_get_object(m_pBuilder, "miQuit");
+ if(m_pmiQuit != NULL)
+ {
+ g_signal_connect(m_pmiQuit,"activate",G_CALLBACK(gtk_main_quit),NULL);
+ }
+ }
+ else
+ {
+ fprintf(stderr,"Can't create menu from the description, popup won't be available!\n");
+ }
}
CApplet::~CApplet()
@@ -133,7 +175,10 @@ void CApplet::OnMenuPopup_cb(GtkStatusIcon *status_icon,
guint activate_time,
gpointer user_data)
{
- gtk_status_icon_set_visible(((CApplet *)user_data)->m_pStatusIcon, false);
+ if(((CApplet *)user_data)->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()
@@ -141,7 +186,10 @@ void CApplet::ShowIcon()
gtk_status_icon_set_visible(m_pStatusIcon, true);
notify_notification_show(m_pNotification, NULL);
}
-
+void CApplet::onHide_cb(GtkMenuItem *menuitem, gpointer applet)
+{
+ ((CApplet*)applet)->HideIcon();
+}
void CApplet::HideIcon()
{
gtk_status_icon_set_visible(m_pStatusIcon, false);
diff --git a/src/Applet/CCApplet.h b/src/Applet/CCApplet.h
index ff65b03e..faf89d10 100644
--- a/src/Applet/CCApplet.h
+++ b/src/Applet/CCApplet.h
@@ -32,7 +32,14 @@ class CApplet
public DBus::ObjectProxy
{
private:
+ static const gchar *menu_xml;
+
GtkStatusIcon* m_pStatusIcon;
+ GObject *m_pMenu;
+ GtkBuilder *m_pBuilder;
+ GObject *m_pmiHide;
+ GObject *m_pmiQuit;
+
NotifyNotification *m_pNotification;
std::map<int, std::string > m_mapEvents;
DaemonWatcher *m_pDaemonWatcher;
@@ -63,6 +70,7 @@ class CApplet
guint button,
guint activate_time,
gpointer user_data);
+ static void onHide_cb(GtkMenuItem *menuitem, gpointer applet);
private:
/* dbus stuff */
void Crash(std::string &value);
diff --git a/src/Applet/Makefile.am b/src/Applet/Makefile.am
index f0ec5ed2..952703e4 100644
--- a/src/Applet/Makefile.am
+++ b/src/Applet/Makefile.am
@@ -18,7 +18,7 @@ abrt_applet_LDADD = \
-lglib-2.0 -lgthread-2.0 \
$(DBUSCPP_LIBS) $(LIBNOTIFY_LIBS)
-EXTRA_DIST = abrt-applet.desktop
+EXTRA_DIST = abrt-applet.desktop popup.GtkBuilder
autostartdir = $(sysconfdir)/xdg/autostart
autostart_DATA = abrt-applet.desktop
diff --git a/src/Applet/popup.GtkBuilder b/src/Applet/popup.GtkBuilder
new file mode 100644
index 00000000..38240cfb
--- /dev/null
+++ b/src/Applet/popup.GtkBuilder
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+<interface>
+ <requires lib="gtk+" version="2.16"/>
+ <!-- interface-naming-policy project-wide -->
+ <object class="GtkMenu" id="popup_menu">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkMenuItem" id="miHide">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Hide</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImageMenuItem" id="miQuit">
+ <property name="label">gtk-quit</property>
+ <property name="visible">True</property>
+ <property name="use_underline">True</property>
+ <property name="use_stock">True</property>
+ <property name="always_show_image">True</property>
+ </object>
+ </child>
+ </object>
+</interface>