"Fossies" - the Fresh Open Source Software Archive

Member "xosview-1.23/bsd/btrymeter.cc" (11 Jul 2020, 2465 Bytes) of package /linux/misc/xosview-1.23.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "btrymeter.cc" see the Fossies "Dox" file reference documentation.

    1 //
    2 //  Copyright (c) 2013 by Tomi Tapper ( tomi.o.tapper@student.jyu.fi )
    3 //
    4 //  Based on linux/btrymeter.cc:
    5 //  Copyright (c) 1997, 2006 by Mike Romberg ( mike.romberg@noaa.gov )
    6 //
    7 //  This file may be distributed under terms of the GPL
    8 //
    9 
   10 #include "btrymeter.h"
   11 #include "kernel.h"
   12 #include <stdlib.h>
   13 
   14 
   15 BtryMeter::BtryMeter( XOSView *parent )
   16     : FieldMeter( parent, 2, "BTRY", "CHRG/USED", 1, 1, 0 ) {
   17     old_state_ = 255;
   18 }
   19 
   20 BtryMeter::~BtryMeter( void ) {
   21 }
   22 
   23 void BtryMeter::checkResources( void ) {
   24     FieldMeter::checkResources();
   25 
   26     leftcolor_ = parent_->allocColor( parent_->getResource("batteryLeftColor") );
   27     usedcolor_ = parent_->allocColor( parent_->getResource("batteryUsedColor") );
   28     chargecolor_ = parent_->allocColor( parent_->getResource("batteryChargeColor") );
   29     fullcolor_ = parent_->allocColor( parent_->getResource("batteryFullColor") );
   30     lowcolor_ = parent_->allocColor( parent_->getResource("batteryLowColor") );
   31     critcolor_ = parent_->allocColor( parent_->getResource("batteryCritColor") );
   32     nonecolor_ = parent_->allocColor( parent_->getResource("batteryNoneColor") );
   33 
   34     setfieldcolor(0, leftcolor_);
   35     setfieldcolor(1, usedcolor_);
   36 
   37     priority_ = atoi( parent_->getResource("batteryPriority") );
   38     SetUsedFormat( parent_->getResource("batteryUsedFormat") );
   39 }
   40 
   41 void BtryMeter::checkevent( void ) {
   42     getstats();
   43     drawfields();
   44 }
   45 
   46 void BtryMeter::getstats( void ) {
   47     int remaining;
   48     unsigned int state;
   49 
   50     BSDGetBatteryInfo(&remaining, &state);
   51 
   52     if (state != old_state_) {
   53         if (state == XOSVIEW_BATT_NONE) { // no battery present
   54             setfieldcolor(0, nonecolor_);
   55             legend("NONE/NONE");
   56         }
   57         else if (state & XOSVIEW_BATT_FULL) { // full battery
   58             setfieldcolor(0, fullcolor_);
   59             legend("CHRG/FULL");
   60         }
   61         else { // present, not full
   62             if (state & XOSVIEW_BATT_CRITICAL) // critical charge
   63                 setfieldcolor(0, critcolor_);
   64             else if (state & XOSVIEW_BATT_LOW) // low charge
   65                 setfieldcolor(0, lowcolor_);
   66             else { // above low, below full
   67                 if (state & XOSVIEW_BATT_CHARGING) // is charging
   68                     setfieldcolor(0, chargecolor_);
   69                 else
   70                     setfieldcolor(0, leftcolor_);
   71             }
   72             // legend tells if charging or discharging
   73             if (state & XOSVIEW_BATT_CHARGING)
   74                 legend("CHRG/AC");
   75             else
   76                 legend("CHRG/USED");
   77         }
   78         drawlegend();
   79         parent_->draw(); // make sure the field changes colour too
   80         old_state_ = state;
   81     }
   82 
   83     total_ = 100.0;
   84     fields_[0] = remaining;
   85     fields_[1] = total_ - remaining;
   86     setUsed(fields_[0], total_);
   87 }