hdd-info: rework CHDDInfoWidget::paint(); use current gui-standards ...

Origin commit data
------------------
Branch: ni/coolstream
Commit: 54606af779
Author: vanhofen <vanhofen@gmx.de>
Date: 2017-09-28 (Thu, 28 Sep 2017)

Origin message was:
------------------
- hdd-info: rework CHDDInfoWidget::paint(); use current gui-standards ...

------------------
No further description and justification available within origin commit message!

------------------
This commit was generated by Migit
This commit is contained in:
vanhofen
2017-09-28 23:41:24 +02:00
parent 1e1394fb56
commit 97bc00bb1c

View File

@@ -220,34 +220,43 @@ CHDDInfoWidget::~CHDDInfoWidget()
} }
#define locale_itemsCount 9 typedef struct items_data_t
static const neutrino_locale_t locale_items[locale_itemsCount] =
{ {
LOCALE_HDD_INFO_MODEL_FAMILY , neutrino_locale_t locale;
LOCALE_HDD_INFO_MODEL , char value[128];
LOCALE_HDD_INFO_SERIAL , }
LOCALE_HDD_INFO_FIRMWARE , items_data_struct;
LOCALE_HDD_INFO_CAPACITY ,
LOCALE_HDD_INFO_SECTOR_SIZE , items_data_t items_data[] =
LOCALE_HDD_INFO_ROTATION_RATE , {
LOCALE_HDD_INFO_SATA_VERSION , { LOCALE_HDD_INFO_MODEL_FAMILY , "" }, // 0
LOCALE_HDD_INFO_TEMPERATURE { LOCALE_HDD_INFO_MODEL , "" }, // 1
{ LOCALE_HDD_INFO_SERIAL , "" }, // 2
{ LOCALE_HDD_INFO_FIRMWARE , "" }, // 3
{ LOCALE_HDD_INFO_CAPACITY , "" }, // 4
{ LOCALE_HDD_INFO_SECTOR_SIZE , "" }, // 5
{ LOCALE_HDD_INFO_ROTATION_RATE , "" }, // 6
{ LOCALE_HDD_INFO_SATA_VERSION , "" }, // 7
{ LOCALE_HDD_INFO_TEMPERATURE , "" } // 8
}; };
#define items_count (sizeof(items_data)/sizeof(struct items_data_t))
void CHDDInfoWidget::paint(const std::string &Key) void CHDDInfoWidget::paint(const std::string &Key)
{ {
frameBuffer = CFrameBuffer::getInstance(); frameBuffer = CFrameBuffer::getInstance();
int hheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getHeight(); CComponentsHeader header;
int mheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight(); CComponentsFooter footer;
int sheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_FOOT]->getHeight();
int offset = 20; Font *item_font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU];
int bheight = offset + locale_itemsCount*mheight + offset; // body height
int fheight = sheight + offset/2; // footer height
width = frameBuffer->getScreenWidth() / 100 * 50; int header_height = header.getHeight();
height = hheight + bheight + fheight; int item_height = item_font->getHeight();
int body_height = items_count*item_height + 2*OFFSET_INNER_SMALL;
int footer_height = header.getHeight();
width = frameBuffer->getScreenWidth()/2;
height = header_height + body_height + footer_height;
x = getScreenStartX(width); x = getScreenStartX(width);
y = getScreenStartY(height); y = getScreenStartY(height);
@@ -261,42 +270,32 @@ void CHDDInfoWidget::paint(const std::string &Key)
unsigned long long mb; unsigned long long mb;
std::ostringstream buf; std::ostringstream buf;
char model_family[128] = "";
char model[128] = "";
char serial[128] = "";
char firmware[128] = "";
char capacity[128] = "";
char sector_size[128] = "";
char rotation_rate[128] = "";
char sata_version[128] = "";
char temperature[128] = "";
buf << "smartctl --all /dev/" << Key; buf << "smartctl --all /dev/" << Key;
buffer=NULL; buffer = NULL;
if((pipe_reader = popen(buf.str().c_str(), "r"))) if((pipe_reader = popen(buf.str().c_str(), "r")))
{ {
while ((read = getline(&buffer, &len, pipe_reader)) != -1) while ((read = getline(&buffer, &len, pipe_reader)) != -1)
{ {
if ((found = strstr(buffer, "Model Family:"))) if ((found = strstr(buffer, "Model Family:")))
sscanf(found+18, "%127[^\n]", (char *) &model_family); sscanf(found+18, "%127[^\n]", (char *) &items_data[0].value);
else if ((found = strstr(buffer, "Device Model:"))) else if ((found = strstr(buffer, "Device Model:")))
sscanf(found+18, "%127[^\n]", (char *) &model); sscanf(found+18, "%127[^\n]", (char *) &items_data[1].value);
else if ((found = strstr(buffer, "Serial Number:"))) else if ((found = strstr(buffer, "Serial Number:")))
sscanf(found+18, "%127[^\n]", (char *) &serial); sscanf(found+18, "%127[^\n]", (char *) &items_data[2].value);
else if ((found = strstr(buffer, "Firmware Version:"))) else if ((found = strstr(buffer, "Firmware Version:")))
sscanf(found+18, "%127[^\n]", (char *) &firmware); sscanf(found+18, "%127[^\n]", (char *) &items_data[3].value);
else if ((found = strstr(buffer, "User Capacity:"))) else if ((found = strstr(buffer, "User Capacity:")))
sscanf(found+18, "%127[^\n]", (char *) &capacity); sscanf(found+18, "%127[^\n]", (char *) &items_data[4].value);
else if ((found = strstr(buffer, "Sector Size:"))) else if ((found = strstr(buffer, "Sector Size:")))
sscanf(found+18, "%127[^\n]", (char *) &sector_size); sscanf(found+18, "%127[^\n]", (char *) &items_data[5].value);
else if ((found = strstr(buffer, "Rotation Rate:"))) else if ((found = strstr(buffer, "Rotation Rate:")))
sscanf(found+18, "%127[^\n]", (char *) &rotation_rate); sscanf(found+18, "%127[^\n]", (char *) &items_data[6].value);
else if ((found = strstr(buffer, "SATA Version is:"))) else if ((found = strstr(buffer, "SATA Version is:")))
sscanf(found+18, "%127[^\n]", (char *) &sata_version); sscanf(found+18, "%127[^\n]", (char *) &items_data[7].value);
else if ((found = strstr(buffer, "Temperature_Celsius"))) else if ((found = strstr(buffer, "Temperature_Celsius")))
sscanf(found+83, "%3[^\n]", (char *) &temperature); sscanf(found+83, "%3[^\n]", (char *) &items_data[8].value);
} }
pclose(pipe_reader); pclose(pipe_reader);
} }
@@ -307,7 +306,7 @@ void CHDDInfoWidget::paint(const std::string &Key)
free(buffer); free(buffer);
// manipulating capacity // manipulating capacity
str_capacity = capacity; str_capacity = items_data[4].value;
str_capacity.erase(std::remove(str_capacity.begin(), str_capacity.end(), ','), str_capacity.end()); str_capacity.erase(std::remove(str_capacity.begin(), str_capacity.end(), ','), str_capacity.end());
mb = strtoull(str_capacity.c_str(),NULL,0)/1000000; mb = strtoull(str_capacity.c_str(),NULL,0)/1000000;
buf.str(""); buf.str("");
@@ -318,147 +317,85 @@ void CHDDInfoWidget::paint(const std::string &Key)
else else
buf << mb/1000 << " GB"; buf << mb/1000 << " GB";
} }
snprintf(capacity, sizeof(capacity), "%s", buf.str().c_str()); snprintf(items_data[4].value, sizeof(items_data[4].value), "%s", buf.str().c_str());
// manipulating temperature // manipulating temperature
buf.str(""); buf.str("");
if (strcmp(temperature, "") != 0) if (strcmp(items_data[8].value, "") != 0)
{ {
buf << trim(temperature) << " Grad Celsius"; buf << trim(items_data[8].value) << " Grad Celsius";
snprintf(temperature, sizeof(temperature), "%s", buf.str().c_str()); snprintf(items_data[8].value, sizeof(items_data[8].value), "%s", buf.str().c_str());
} }
// calculate max width of used LOCALES // calculate max width of locales
int locwidth = 0; int w_loc = 0, w_tmp = 0;
for (int i = 0; i < locale_itemsCount; i++) { for (unsigned int i = 0; i < items_count; i++)
int w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(g_Locale->getText(locale_items[i])); {
locwidth = std::max(locwidth, w); w_tmp = item_font->getRenderWidth(g_Locale->getText(items_data[i].locale));
w_loc = std::max(w_loc, w_tmp);
} }
// calculate width of separator // calculate width of separator
std::string separator = " : "; std::string separator = ":";
int sepwidth = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(separator); int w_sep = item_font->getRenderWidth(separator);
// calculate max width of data // calculate max width of values
int datwidth = 0, w = 0; int w_val = 0;
w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(trim(model_family)); for (unsigned int i = 0; i < items_count; i++)
datwidth = std::max(datwidth, w); {
w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(trim(model)); if (strcmp(items_data[i].value, "") == 0)
datwidth = std::max(datwidth, w); snprintf(items_data[i].value, sizeof(items_data[i].value), "%s", g_Locale->getText(LOCALE_HDD_INFO_UNKNOWN));
w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(trim(serial)); w_tmp = item_font->getRenderWidth(trim(items_data[i].value));
datwidth = std::max(datwidth, w); w_val = std::max(w_val, w_tmp);
w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(trim(firmware)); }
datwidth = std::max(datwidth, w);
w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(trim(capacity));
datwidth = std::max(datwidth, w);
w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(trim(sector_size));
datwidth = std::max(datwidth, w);
w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(trim(rotation_rate));
datwidth = std::max(datwidth, w);
w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(trim(sata_version));
datwidth = std::max(datwidth, w);
w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(trim(temperature));
datwidth = std::max(datwidth, w);
// recalculate width and xpos // recalculate width and xpos
width = std::max(width, offset + locwidth + sepwidth + datwidth + offset); width = std::max(width, w_loc + w_sep + w_val + 4*OFFSET_INNER_MID);
if (width > (int) frameBuffer->getScreenWidth()) if (width > (int) frameBuffer->getScreenWidth())
{ {
// should only happen with very big fonts // should only happen with very big fonts
width = frameBuffer->getScreenWidth(); width = frameBuffer->getScreenWidth();
datwidth = width - offset - locwidth - sepwidth - offset; w_val = width - w_loc - w_sep - 4*OFFSET_INNER_MID;
} }
x = getScreenStartX(width); x = getScreenStartX(width);
fprintf(stderr, "CHDDInfoWidget::CHDDInfoWidget() x = %d, y = %d, width = %d, height = %d\n", x, y, width, height);
// paint backgrounds
frameBuffer->paintBoxRel(x, y, width, hheight, COL_MENUHEAD_PLUS_0, RADIUS_LARGE, CORNER_TOP);
frameBuffer->paintBoxRel(x, y+ hheight, width, bheight, COL_MENUCONTENT_PLUS_0);
frameBuffer->paintBoxRel(x, y+ hheight+ bheight, width, fheight, COL_MENUFOOT_PLUS_0, RADIUS_LARGE, CORNER_BOTTOM);
// header // header
int xpos = x + offset/2;
int ypos = y + hheight;
int icol_w = 0, icol_h = 0, icol_o = 0;
frameBuffer->getIconSize(NEUTRINO_ICON_SETTINGS, &icol_w, &icol_h);
if ( (icol_w) && (icol_h) )
{
frameBuffer->paintIcon(NEUTRINO_ICON_SETTINGS, xpos, y, hheight);
icol_o = icol_w + offset/2;
}
buf.str(""); buf.str("");
buf << g_Locale->getText(LOCALE_HDD_INFO_HEAD) << " (" << Key << ")"; buf << g_Locale->getText(LOCALE_HDD_INFO_HEAD) << " (" << Key << ")";
g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->RenderString(xpos + icol_o, ypos, width - offset - icol_o, buf.str(), COL_MENUHEAD_TEXT); header.setCaption(buf.str());
header.setIcon(NEUTRINO_ICON_SETTINGS);
header.setDimensionsAll(x, y, width, header_height);
header.addContextButton(CComponentsHeader::CC_BTN_EXIT);
header.enableShadow(CC_SHADOW_RIGHT | CC_SHADOW_CORNER_TOP_RIGHT | CC_SHADOW_CORNER_BOTTOM_RIGHT, -1, true);
header.paint(CC_SAVE_SCREEN_NO);
// locale // body
xpos = x + offset; PaintBoxRel(x, y + header_height, width, body_height, COL_MENUCONTENT_PLUS_0, RADIUS_NONE, CORNER_NONE, CC_SHADOW_ON);
ypos += offset;
for (int i = 0; i < locale_itemsCount; i++) { // footer
ypos += mheight; const struct button_label buttons[] =
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(xpos, ypos, locwidth, g_Locale->getText(locale_items[i]), COL_MENUCONTENTINACTIVE_TEXT); {
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(xpos + locwidth, ypos, sepwidth, separator, COL_MENUCONTENTINACTIVE_TEXT); { "", LOCALE_HDD_INFO_INFO }
};
footer.enableShadow(CC_SHADOW_ON, -1, true);
footer.paintButtons(x, y + header_height + body_height, width, footer_height, 1, buttons);
// paint items
int x_loc = x + OFFSET_INNER_MID;
int x_sep = x_loc + w_loc + OFFSET_INNER_MID;
int x_val = x_sep + w_sep + OFFSET_INNER_MID;
int y_item = y + header_height + OFFSET_INNER_SMALL;
for (unsigned int i = 0; i < items_count; i++)
{
y_item += item_height;
item_font->RenderString(x_loc, y_item, w_loc, g_Locale->getText(items_data[i].locale), COL_MENUCONTENTINACTIVE_TEXT);
item_font->RenderString(x_sep, y_item, w_sep, separator, COL_MENUCONTENTINACTIVE_TEXT);
item_font->RenderString(x_val, y_item, w_val, items_data[i].value, COL_MENUCONTENT_TEXT);
} }
// footer with centered content
int wtmp = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_FOOT]->getRenderWidth(g_Locale->getText(LOCALE_HDD_INFO_INFO));
xpos = x + width/2 - wtmp/2;
ypos = y + hheight + bheight + offset/4 + sheight;
g_Font[SNeutrinoSettings::FONT_TYPE_MENU_FOOT]->RenderString(xpos, ypos, wtmp, g_Locale->getText(LOCALE_HDD_INFO_INFO), COL_MENUCONTENTINACTIVE_TEXT);
// finally paint data
xpos = x + offset + locwidth + sepwidth;
ypos = y + hheight + offset;
ypos += mheight;
buf.str("");
buf << model_family;
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(xpos, ypos, datwidth, (!strcmp(model_family, "") ? g_Locale->getText(LOCALE_HDD_INFO_UNKNOWN) : buf.str().c_str()), COL_MENUCONTENT_TEXT);
ypos += mheight;
buf.str("");
buf << model;
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(xpos, ypos, datwidth, (!strcmp(model, "") ? g_Locale->getText(LOCALE_HDD_INFO_UNKNOWN) : buf.str().c_str()), COL_MENUCONTENT_TEXT);
ypos += mheight;
buf.str("");
buf << serial;
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(xpos, ypos, datwidth, (!strcmp(serial, "") ? g_Locale->getText(LOCALE_HDD_INFO_UNKNOWN) : buf.str().c_str()), COL_MENUCONTENT_TEXT);
ypos += mheight;
buf.str("");
buf << firmware;
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(xpos, ypos, datwidth, (!strcmp(firmware, "") ? g_Locale->getText(LOCALE_HDD_INFO_UNKNOWN) : buf.str().c_str()), COL_MENUCONTENT_TEXT);
ypos += mheight;
buf.str("");
buf << capacity;
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(xpos, ypos, datwidth, (!strcmp(capacity, "") ? g_Locale->getText(LOCALE_HDD_INFO_UNKNOWN) : buf.str().c_str()), COL_MENUCONTENT_TEXT);
ypos += mheight;
buf.str("");
buf << sector_size;
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(xpos, ypos, datwidth, (!strcmp(sector_size, "") ? g_Locale->getText(LOCALE_HDD_INFO_UNKNOWN) : buf.str().c_str()), COL_MENUCONTENT_TEXT);
ypos += mheight;
buf.str("");
buf << rotation_rate;
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(xpos, ypos, datwidth, (!strcmp(rotation_rate, "") ? g_Locale->getText(LOCALE_HDD_INFO_UNKNOWN) : buf.str().c_str()), COL_MENUCONTENT_TEXT);
ypos += mheight;
buf.str("");
buf << sata_version;
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(xpos, ypos, datwidth, (!strcmp(sata_version, "") ? g_Locale->getText(LOCALE_HDD_INFO_UNKNOWN) : buf.str().c_str()), COL_MENUCONTENT_TEXT);
ypos += mheight;
buf.str("");
buf << temperature;
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(xpos, ypos, datwidth, (!strcmp(temperature, "") ? g_Locale->getText(LOCALE_HDD_INFO_UNKNOWN) : buf.str().c_str()), COL_MENUCONTENT_TEXT);
} }
void CHDDInfoWidget::hide() void CHDDInfoWidget::hide()
{ {
frameBuffer->paintBackgroundBoxRel(x, y, width, height); frameBuffer->paintBackgroundBoxRel(x, y, width + OFFSET_SHADOW, height + OFFSET_SHADOW);
} }