summaryrefslogtreecommitdiffstats
path: root/src/Applet
diff options
context:
space:
mode:
authorZdenek Prikryl <zprikryl@redhat.com>2009-02-12 16:31:10 +0100
committerZdenek Prikryl <zprikryl@redhat.com>2009-02-12 16:31:10 +0100
commit418f70ffb976bbae37e5772f92a7bb983f303d1c (patch)
treed78a875e0d2bc7c4011d6d4ed0cc5cbe2b5d9961 /src/Applet
parent3541999cd3338818cd86583383dbca87606d49fa (diff)
parent164c692385ddf3b17fbc9417b748f198ff19b096 (diff)
downloadabrt-418f70ffb976bbae37e5772f92a7bb983f303d1c.tar.gz
abrt-418f70ffb976bbae37e5772f92a7bb983f303d1c.tar.xz
abrt-418f70ffb976bbae37e5772f92a7bb983f303d1c.zip
Merge branch 'master' of git://git.fedorahosted.org/crash-catcher
Diffstat (limited to 'src/Applet')
-rw-r--r--src/Applet/Applet.cpp50
-rw-r--r--src/Applet/CCApplet.cpp53
-rw-r--r--src/Applet/CCApplet.h13
-rw-r--r--src/Applet/Makefile.am4
4 files changed, 94 insertions, 26 deletions
diff --git a/src/Applet/Applet.cpp b/src/Applet/Applet.cpp
index 39b0cc4..cc40642 100644
--- a/src/Applet/Applet.cpp
+++ b/src/Applet/Applet.cpp
@@ -1,40 +1,54 @@
+/*
+ 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.
+ */
+
#include "CCApplet.h"
-#include "DBusManager.h"
+#include "DBusClient.h"
#include <iostream>
//@@global applet object
CApplet *applet;
static void
-crash_notify_cb(DBusGProxy *proxy, char* progname, gpointer user_data)
+crash_notify_cb(const char* progname)
{
- DBusError error;
- dbus_error_init (&error);
#ifdef DEBUG
std::cerr << "Application " << progname << " has crashed!" << std::endl;
#endif
/* smth happend, show the blinking icon */
applet->BlinkIcon(true);
applet->ShowIcon();
+ //applet->AddEvent(uid, std::string(progname));
+ applet->SetIconTooltip("A crash in package %s has been detected!", progname);
}
int main(int argc, char **argv)
{
Gtk::Main kit(argc, argv);
applet = new CApplet();
- CDBusManager dm;
- /* connect to the daemon */
- try
- {
- dm.ConnectToDaemon();
- }
- catch(std::string err)
- {
- std::cerr << "Applet: " << err << std::endl;
- return -1;
- }
- /* catch the CC crash notify on the dbus */
- dm.RegisterToMessage("Crash",G_CALLBACK(crash_notify_cb),NULL,NULL);
- /* run the main loop and wait for some events */
+ /* move to the DBusClient::connect */
+ DBus::Glib::BusDispatcher dispatcher;
+ /* this should bind the dispatcher with mainloop */
+ dispatcher.attach(NULL);
+ DBus::default_dispatcher = &dispatcher;
+
+ DBus::Connection conn = DBus::Connection::SystemBus();
+ CDBusClient client(conn, CC_DBUS_PATH, CC_DBUS_NAME);
+ client.ConnectCrashHandler(crash_notify_cb);
Gtk::Main::run();
return 0;
}
diff --git a/src/Applet/CCApplet.cpp b/src/Applet/CCApplet.cpp
index fd9741a..17ff6f9 100644
--- a/src/Applet/CCApplet.cpp
+++ b/src/Applet/CCApplet.cpp
@@ -19,33 +19,66 @@
#include "CCApplet.h"
#include <iostream>
+#include <cstdarg>
+#include <sstream>
CApplet::CApplet()
{
-
m_nStatusIcon = Gtk::StatusIcon::create(Gtk::Stock::DIALOG_WARNING);
m_nStatusIcon->set_visible(false);
- // LTM click
+ // LMB click
m_nStatusIcon->signal_activate().connect(sigc::mem_fun(*this, &CApplet::OnAppletActivate_CB));
- SetIconToolip("Pending events:");
+ m_nStatusIcon->signal_popup_menu().connect(sigc::mem_fun(*this, &CApplet::OnMenuPopup_cb));
+ SetIconTooltip("Pending events: %i",m_mapEvents.size());
+
}
CApplet::~CApplet()
{
}
-void CApplet::SetIconToolip(const Glib::ustring& tip)
+void CApplet::SetIconTooltip(const char *format, ...)
{
- m_nStatusIcon->set_tooltip(tip);
+ va_list args;
+ // change to smth sane like MAX_TOOLTIP length or rewrite this whole sh*t
+ size_t n,size = 10;
+ char *buf = new char[size];
+ va_start (args, format);
+ while((n = vsnprintf (buf, size, format, args)) > size)
+ {
+ // string was larger than our buffer
+ // alloc larger buffer
+ size = n+1;
+ delete[] buf;
+ buf = new char[size];
+ }
+ va_end (args);
+ if (n != -1)
+ {
+ m_nStatusIcon->set_tooltip(Glib::ustring((const char*)buf));
+ }
+ else
+ {
+ m_nStatusIcon->set_tooltip("Error while setting tooltip!");
+ }
+ delete[] buf;
}
void CApplet::OnAppletActivate_CB()
{
m_nStatusIcon->set_visible(false);
//std::cout << "Activate" << std::endl;
+ //if(m_pMenuPopup)
+ //m_pMenuPopup->show();
}
+void CApplet::OnMenuPopup_cb(guint button, guint32 activate_time)
+{
+ /* for now just hide the icon on RMB */
+ m_nStatusIcon->set_blinking(false);
+}
+
void CApplet::ShowIcon()
{
m_nStatusIcon->set_visible(true);
@@ -56,6 +89,16 @@ void CApplet::HideIcon()
m_nStatusIcon->set_visible(false);
}
+int CApplet::AddEvent(int pUUID, const std::string& pProgname)
+{
+ m_mapEvents[pUUID] = "pProgname";
+ SetIconTooltip("Pending events: %i",m_mapEvents.size());
+}
+
+int CApplet::RemoveEvent(int pUUID)
+{
+ m_mapEvents.erase(pUUID);
+}
void CApplet::BlinkIcon(bool pBlink)
{
m_nStatusIcon->set_blinking(pBlink);
diff --git a/src/Applet/CCApplet.h b/src/Applet/CCApplet.h
index 428f4a9..86c00ef 100644
--- a/src/Applet/CCApplet.h
+++ b/src/Applet/CCApplet.h
@@ -26,7 +26,7 @@ class CApplet
{
private:
Glib::RefPtr<Gtk::StatusIcon> m_nStatusIcon;
- int m_iPendingEvents;
+ std::map<int, std::string > m_mapEvents;
public:
CApplet();
~CApplet();
@@ -34,9 +34,18 @@ class CApplet
void HideIcon();
//void DisableIcon();
void BlinkIcon(bool pBlink);
- void SetIconToolip(const Glib::ustring& tip);
+ void SetIconTooltip(const char *format, ...);
+ // 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 std::string& pProgname);
+ int RemoveEvent(int pUUID);
protected:
+ //@@TODO applet menus
void OnAppletActivate_CB();
+ void OnMenuPopup_cb(guint button, guint32 activate_time);
+ //menu
Glib::RefPtr<Gtk::UIManager> m_refUIManager;
Glib::RefPtr<Gtk::ActionGroup> m_refActionGroup;
Gtk::Menu* m_pMenuPopup;
diff --git a/src/Applet/Makefile.am b/src/Applet/Makefile.am
index 8500b01..e329acc 100644
--- a/src/Applet/Makefile.am
+++ b/src/Applet/Makefile.am
@@ -2,5 +2,7 @@ bin_PROGRAMS = applet
applet_SOURCES = Applet.cpp CCApplet.cpp CCApplet.h
applet_CPPFLAGS = -I../../lib/DBus \
-DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \
- $(DBUS_GLIB_CFLAGS) $(GTKMM_CFLAGS)
+ $(DBUS_GLIB_CFLAGS) $(GTKMM_CFLAGS) $(DBUSCPP_CFLAGS) \
+ -I../../lib/MiddleWare
+
applet_LDADD = ../../lib/DBus/libDBus.la $(DL_LIBS) $(GTKMM_LIBS)