diff --git a/ede-panel/AppletManager.cpp b/ede-panel/AppletManager.cpp index a1dacdd..9cdaa53 100644 --- a/ede-panel/AppletManager.cpp +++ b/ede-panel/AppletManager.cpp @@ -33,10 +33,10 @@ struct AppletData { Fl_Widget *awidget; /* widget from the applet */ AppletInfo *ainfo; /* applet informations */ - applet_create_t create_func; - applet_destroy_t destroy_func; + applet_create_t create_func; + applet_destroy_t destroy_func; - applet_destroy_info_t destroy_info_func; + applet_destroy_info_t destroy_info_func; }; static void clear_applet(AppletData *a) { @@ -112,7 +112,6 @@ bool AppletManager::load(const char *path) { return false; } - AppletData *data = new AppletData; data->dl = a; data->awidget = NULL; @@ -132,11 +131,10 @@ bool AppletManager::load(const char *path) { } void AppletManager::clear(void) { - if(applet_list.empty()) - return; + E_RETURN_IF_FAIL(applet_list.size() > 0); - AListIter it = applet_list.begin(), it_end = applet_list.end(); - while(it != it_end) { + AListIter it = applet_list.begin(), ite = applet_list.end(); + while(it != ite) { clear_applet(*it); it = applet_list.erase(it); } @@ -147,29 +145,29 @@ void AppletManager::clear(void) { * added to the group. */ void AppletManager::fill_group(Panel *p) { - AListIter it = applet_list.begin(), it_end = applet_list.end(); + AListIter it = applet_list.begin(), ite = applet_list.end(); AppletData *applet; - for(; it != it_end; ++it) { + for(; it != ite; ++it) { applet = *it; - /* allocate memory for widget and append it to group */ + /* allocate memory for widget and append it to the group */ applet->awidget = applet->create_func(); p->add(applet->awidget); } } void AppletManager::unfill_group(Panel *p) { - AListIter it = applet_list.begin(), it_end = applet_list.end(); + AListIter it = applet_list.begin(), ite = applet_list.end(); - for(; it != it_end; ++it) + for(; it != ite; ++it) p->remove((*it)->awidget); } bool AppletManager::get_applet_options(Fl_Widget *o, unsigned long &opts) { - AListIter it = applet_list.begin(), it_end = applet_list.end(); + AListIter it = applet_list.begin(), ite = applet_list.end(); - for(; it != it_end; ++it) { + for(; it != ite; ++it) { if(o == (*it)->awidget) { opts = (*it)->ainfo->options; return true; diff --git a/ede-panel/Jamfile b/ede-panel/Jamfile index dbc6e6a..d528c5c 100644 --- a/ede-panel/Jamfile +++ b/ede-panel/Jamfile @@ -11,7 +11,7 @@ SubDir TOP ede-panel ; EdeProgram ede-panel : Hider.cpp Panel.cpp AppletManager.cpp ede-panel.cpp ; -#ObjectC++Flags Panel.cpp : -DEDE_PANEL_LOCAL_APPLETS ; +ObjectC++Flags Panel.cpp : -DEDE_PANEL_LOCAL_APPLETS ; if $(OS) != "SOLARIS" { # also must use this flag (on anything but Solaris) or program will crash diff --git a/ede-panel/Panel.cpp b/ede-panel/Panel.cpp index 420d3ea..c974ee0 100644 --- a/ede-panel/Panel.cpp +++ b/ede-panel/Panel.cpp @@ -534,8 +534,8 @@ void Panel::load_applets(void) { mgr.fill_group(this); #else - mgr.load("./applets/quick-launch/quick_launch.so"); mgr.load("./applets/start-menu/start_menu.so"); + mgr.load("./applets/quick-launch/quick_launch.so"); mgr.load("./applets/pager/pager.so"); mgr.load("./applets/clock/clock.so"); mgr.load("./applets/taskbar/taskbar.so"); diff --git a/ede-panel/applets/mem-monitor/MemMonitor.cpp b/ede-panel/applets/mem-monitor/MemMonitor.cpp index c73320c..547901e 100644 --- a/ede-panel/applets/mem-monitor/MemMonitor.cpp +++ b/ede-panel/applets/mem-monitor/MemMonitor.cpp @@ -1,5 +1,7 @@ +/* assume Linux here */ +#include + #include -#include #include #include #include @@ -13,25 +15,10 @@ EDELIB_NS_USING(color_rgb_to_fltk) #define UPDATE_INTERVAL 1.0f #define STR_CMP(first, second, n) (strncmp(first, second, n) == 0) -static int height_from_perc(int perc, int h) { +inline int height_from_perc(int perc, int h) { return (perc * h) / 100; } -static long get_number(const char *ln) { - char *s = edelib_strndup(ln, 128); - int i = 1; - - for(char *p = strtok(s, " "); p; p = strtok(NULL, " "), i++) { - if(i == 2) { - long ret = atol(p); - free(s); - return ret; - } - } - - free(s); - return 0; -} static void mem_timeout_cb(void *d) { ((MemMonitor*)d)->update_status(); Fl::repeat_timeout(UPDATE_INTERVAL, mem_timeout_cb, d); @@ -42,25 +29,14 @@ MemMonitor::MemMonitor() : Fl_Box(0, 0, 45, 25), mem_usedp(0), swap_usedp(0) { } void MemMonitor::update_status(void) { - FILE *fd = fopen("/proc/meminfo", "r"); - if(!fd) return; + struct sysinfo sys; + if(sysinfo(&sys) != 0) return; long mem_total, mem_free, swap_total, swap_free; - mem_total = mem_free = swap_total = swap_free = 0; - - static char buf[128]; - while(fgets(buf, sizeof(buf), fd) != 0) { - if(STR_CMP(buf, "MemTotal:", 9)) - mem_total = get_number(buf); - else if(STR_CMP(buf, "MemFree:", 8)) - mem_free = get_number(buf); - else if(STR_CMP(buf, "SwapTotal:", 10)) - swap_total = get_number(buf); - else if(STR_CMP(buf, "SwapFree:", 9)) - swap_free = get_number(buf); - } - - fclose(fd); + mem_total = (float)sys.totalram * (float)sys.mem_unit / 1048576.0f; + mem_free = (float)sys.freeram * (float)sys.mem_unit / 1048576.0f; + swap_total = (float)sys.totalswap * (float)sys.mem_unit / 1048576.0f; + swap_free = (float)sys.freeswap * (float)sys.mem_unit / 1048576.0f; mem_usedp = 100 - (int)(((float)mem_free / (float)mem_total) * 100); swap_usedp = 100 - (int)(((float)swap_free / (float)swap_total) * 100);