battery_monitor.cpp

00001
00002 /***************************************************************************
00003  *  battery_monitor.cpp - Fawkes Battery Monitor
00004  *
00005  *  Created: Mon Apr 06 17:11:55 2009
00006  *  Copyright  2009  Daniel Beck
00007  *
00008  ****************************************************************************/
00009
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL file in the doc directory.
00021  */
00022
00023 #include "battery_monitor.h"
00024 #include "battery_monitor_treeview.h"
00025
00026 #include <netcomm/dns-sd/avahi_thread.h>
00027
00028 #include <gui_utils/utils.h>
00029
00030 using namespace std;
00031 using namespace fawkes;
00032 
00033 /** @class BatteryMonitor tools/battery_monitor/battery_monitor.h
00034  * A battery monitor.
00035  * @author Daniel Beck
00036  */
00037 
00038 /** Constructor.
00039  * @param ref_xml Glade XML object
00040  */
00041 BatteryMonitor::BatteryMonitor( Glib::RefPtr< Gnome::Glade::Xml > ref_xml )
00042 {
00043   m_wnd_main = dynamic_cast< Gtk::Window* >( get_widget( ref_xml, "wndMain" ) );
00044   m_trv_battery = NULL;
00045   ref_xml->get_widget_derived( "trvBattery", m_trv_battery );
00046   m_btn_quit = dynamic_cast< Gtk::Button* >( get_widget( ref_xml, "btnQuit" ) );
00047   m_btn_quit->signal_clicked().connect( sigc::mem_fun( *this, &BatteryMonitor::on_btn_quit_clicked ) );
00048
00049   m_avahi = new AvahiThread();
00050   m_avahi->watch_service( "_fawkes._tcp", this );
00051   m_avahi->start();
00052 }
00053 
00054 /** Destructor */
00055 BatteryMonitor::~BatteryMonitor()
00056 {
00057   m_avahi->cancel();
00058   m_avahi->join();
00059   delete m_avahi;
00060 }
00061 
00062 /** Obtain the main window.
00063  * @return the main window
00064  */
00065 Gtk::Window&
00066 BatteryMonitor::get_window() const
00067 {
00068   return *m_wnd_main;
00069 }
00070
00071 void
00072 BatteryMonitor::all_for_now()
00073 {
00074 }
00075
00076 void
00077 BatteryMonitor::cache_exhausted()
00078 {
00079 }
00080
00081 void
00082 BatteryMonitor::browse_failed( const char* name,
00083                                const char* type,
00084                                const char* domain )
00085 {
00086 }
00087
00088 void
00089 BatteryMonitor::service_added( const char* name,
00090                                const char* type,
00091                                const char* domain,
00092                                const char* host_name,
00093                                const struct sockaddr* addr,
00094                                const socklen_t addr_size,
00095                                uint16_t port,
00096                                std::list<std::string>& txt,
00097                                int flags )
00098 {
00099   string host( host_name );
00100   string service( name );
00101   m_services[ service ] = host_name;
00102   m_trv_battery->add_host( host_name );
00103 }
00104
00105 void
00106 BatteryMonitor::service_removed( const char* name,
00107                                  const char* type,
00108                                  const char* domain )
00109 {
00110   std::map< string, string >::iterator i =  m_services.find( string( name ) );
00111   if ( i != m_services.end() )
00112   { m_trv_battery->rem_host( (i->second).c_str() ); }
00113 }
00114
00115 void
00116 BatteryMonitor::on_btn_quit_clicked()
00117 {
00118   m_wnd_main->hide();
00119 }