mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-29 16:31:05 +02:00
CBuildInfo: rework buildinfo class for use as CComponentsWindow
also possible: get partial informations also as strings for usage
in other classes
Origin commit data
------------------
Commit: 6955df5c5e
Author: Thilo Graf <dbt@novatux.de>
Date: 2013-11-10 (Sun, 10 Nov 2013)
This commit is contained in:
@@ -23,63 +23,60 @@
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <global.h>
|
||||
#include <neutrino.h>
|
||||
//#include <sys/utsname.h>
|
||||
|
||||
#include <string>
|
||||
#include <driver/screen_max.h>
|
||||
#include <driver/neutrinofonts.h>
|
||||
#include <gui/components/cc_item_text.h>
|
||||
#include <gui/components/cc_item_shapes.h>
|
||||
#include <gui/buildinfo.h>
|
||||
#include <gui/widget/messagebox.h>
|
||||
#include <system/helpers.h>
|
||||
|
||||
CBuildInfo::CBuildInfo(): config ('\t')
|
||||
using namespace std;
|
||||
|
||||
CBuildInfo::CBuildInfo() : CComponentsWindow(1, 1, 700, 500, LOCALE_BUILDINFO_MENU, NEUTRINO_ICON_INFO)
|
||||
{
|
||||
Init();
|
||||
initVarBuildInfo();
|
||||
}
|
||||
|
||||
//init all var members
|
||||
void CBuildInfo::Init(void)
|
||||
void CBuildInfo::initVarBuildInfo()
|
||||
{
|
||||
cc_win = NULL;
|
||||
cc_info = NULL;
|
||||
item_offset = 10;
|
||||
bodyHeight = 0;
|
||||
v_info.clear();
|
||||
config.loadConfig("/.version");
|
||||
x = frameBuffer->getScreenWidth(true)/2 - width/2;
|
||||
y = frameBuffer->getScreenHeight(true)/2 -height/2;
|
||||
|
||||
append_v_offset = 1;
|
||||
font = NULL;
|
||||
setWindowHeaderButtons(CComponentsHeader::CC_BTN_MENU | CComponentsHeader::CC_BTN_EXIT);
|
||||
InitInfoItems();
|
||||
|
||||
|
||||
shadow = true;
|
||||
}
|
||||
|
||||
CBuildInfo::~CBuildInfo()
|
||||
{
|
||||
hide();
|
||||
delete cc_win;
|
||||
cleanCCForm();
|
||||
}
|
||||
|
||||
void CBuildInfo::Clean()
|
||||
{
|
||||
if (cc_win){
|
||||
delete cc_win;
|
||||
cc_win = NULL;
|
||||
cc_info = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int CBuildInfo::exec(CMenuTarget* parent, const std::string &)
|
||||
int CBuildInfo::exec(CMenuTarget* parent, const string & /*actionKey*/)
|
||||
{
|
||||
int res = menu_return::RETURN_REPAINT;
|
||||
|
||||
if (parent)
|
||||
parent->hide();
|
||||
|
||||
//exit if no informations available
|
||||
if (!HasData()){
|
||||
return res;
|
||||
}
|
||||
|
||||
//clean up before, because we could have a current instance with already initialized contents
|
||||
Clean();
|
||||
//paint window
|
||||
if (!is_painted)
|
||||
paint();
|
||||
|
||||
//init window object, add cc-items and paint all
|
||||
ShowWindow();
|
||||
|
||||
neutrino_msg_t msg;
|
||||
while (1)
|
||||
@@ -104,163 +101,112 @@ int CBuildInfo::exec(CMenuTarget* parent, const std::string &)
|
||||
if ( msg > CRCInput::RC_MaxRC && msg != CRCInput::RC_timeout){
|
||||
CNeutrinoApp::getInstance()->handleMsg( msg, data );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//hide window
|
||||
hide();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void CBuildInfo::ShowWindow()
|
||||
void CBuildInfo::setFontType(Font* font_text)
|
||||
{
|
||||
if (cc_win == NULL){
|
||||
cc_win = new CComponentsWindow(LOCALE_BUILDINFO_MENU, NEUTRINO_ICON_INFO);
|
||||
cc_win->setWindowHeaderButtons(CComponentsHeader::CC_BTN_MENU | CComponentsHeader::CC_BTN_EXIT);
|
||||
CFrameBuffer *frameBuffer = CFrameBuffer::getInstance();
|
||||
int w = (frameBuffer->getScreenWidth()*2)/3;
|
||||
int h = frameBuffer->getScreenHeight();
|
||||
cc_win->setDimensionsAll(getScreenStartX(w), getScreenStartY(h), w, h);
|
||||
|
||||
CComponentsForm* bo = cc_win->getBodyObject();
|
||||
if (bo) bodyHeight = bo->getHeight();
|
||||
|
||||
}
|
||||
|
||||
InitInfos();
|
||||
|
||||
cc_win->paint();
|
||||
if (font_text == NULL)
|
||||
return;
|
||||
font = font_text;
|
||||
InitInfoItems();
|
||||
}
|
||||
|
||||
void CBuildInfo::InitInfos()
|
||||
bool CBuildInfo::HasData()
|
||||
{
|
||||
v_info.clear();
|
||||
|
||||
#ifdef USED_COMPILER
|
||||
build_info_t compiler = {LOCALE_BUILDINFO_COMPILED_WITH, USED_COMPILER};
|
||||
build_info_t compiler = {BI_TYPE_ID_USED_COMPILER, LOCALE_BUILDINFO_COMPILED_WITH, USED_COMPILER};
|
||||
v_info.push_back(compiler);
|
||||
#endif
|
||||
|
||||
#ifdef USED_CXXFLAGS
|
||||
std::string cxxflags = USED_CXXFLAGS;
|
||||
string cxxflags = USED_CXXFLAGS;
|
||||
cxxflags = trim(cxxflags);
|
||||
// Remove double spaces
|
||||
size_t pos = cxxflags.find(" ");
|
||||
while (pos != std::string::npos) {
|
||||
while (pos != string::npos) {
|
||||
cxxflags.erase(pos, 1);
|
||||
pos = cxxflags.find(" ", pos);
|
||||
}
|
||||
build_info_t flags = {LOCALE_BUILDINFO_COMPILER_FLAGS, cxxflags};
|
||||
build_info_t flags = {BI_TYPE_ID_USED_CXXFLAGS, LOCALE_BUILDINFO_COMPILER_FLAGS, cxxflags};
|
||||
v_info.push_back(flags);
|
||||
#endif
|
||||
|
||||
#ifdef USED_BUILD
|
||||
build_info_t build = {LOCALE_BUILDINFO_COMPILED_ON, USED_BUILD};
|
||||
build_info_t build = {BI_TYPE_ID_USED_BUILD , LOCALE_BUILDINFO_COMPILED_ON, USED_BUILD};
|
||||
v_info.push_back(build);
|
||||
#endif
|
||||
|
||||
build_info_t creator = {LOCALE_BUILDINFO_CREATOR, config.getString("creator", "n/a")};
|
||||
CComponentsText utext;
|
||||
build_info_t kernel = {BI_TYPE_ID_USED_KERNEL, LOCALE_BUILDINFO_KERNEL, utext.getTextFromFile("/proc/version")};
|
||||
v_info.push_back(kernel);
|
||||
|
||||
#if 0
|
||||
CConfigFile data ('\t');
|
||||
data.loadConfig("/.version");
|
||||
build_info_t creator = {BI_TYPE_ID_CREATOR, LOCALE_BUILDINFO_CREATOR, data.getString("creator", "n/a")};
|
||||
v_info.push_back(creator);
|
||||
#endif
|
||||
|
||||
FILE *fp = fopen("/proc/version", "r");
|
||||
if (fp) {
|
||||
char zeile[1024];
|
||||
memset(zeile, 0, sizeof(zeile));
|
||||
fgets(zeile, sizeof(zeile)-1, fp);
|
||||
fclose(fp);
|
||||
std::string zeile_s = zeile;
|
||||
zeile_s = trim(zeile_s);
|
||||
build_info_t kernel = {LOCALE_BUILDINFO_KERNEL, zeile_s};
|
||||
v_info.push_back(kernel);
|
||||
if (v_info.empty()){
|
||||
DisplayInfoMessage("No Informations available. Please report!");
|
||||
return false;
|
||||
}
|
||||
|
||||
// ###########################################################
|
||||
return true;
|
||||
}
|
||||
|
||||
int dx = 0, dy = 27;
|
||||
Font * item_font = *(CNeutrinoFonts::getInstance()->getDynFont(dx, dy));
|
||||
void CBuildInfo::InitInfoItems()
|
||||
{
|
||||
//get and checkup required informations
|
||||
if (!HasData())
|
||||
return;
|
||||
|
||||
//initialize container for infos
|
||||
if (cc_info == NULL)
|
||||
cc_info = new CComponentsForm();
|
||||
cc_win->addWindowItem(cc_info);
|
||||
cc_info->setPos(item_offset, item_offset);
|
||||
cc_info->setWidth((cc_win->getWidth())-2*item_offset);
|
||||
//ensure a clean body
|
||||
ccw_body->clearCCItems();
|
||||
|
||||
//calculate max width of label and info_text
|
||||
int w_label = 0, w_text = 0, w = 0;
|
||||
for (size_t i = 0; i < v_info.size(); i++) {
|
||||
w = item_font->getRenderWidth(g_Locale->getText(v_info[i].caption), true);
|
||||
w_label = std::max(w_label, w);
|
||||
//define size and position
|
||||
int x_info = 10;
|
||||
int h_info = ccw_body->getHeight()/v_info.size(); //default height
|
||||
int w_info = width-2*x_info;
|
||||
|
||||
w = item_font->getRenderWidth(v_info[i].info_text.c_str(), true);
|
||||
w_text = std::max(w_text, w);
|
||||
//init info texts
|
||||
for(size_t i=0; i<v_info.size(); i++){
|
||||
CComponentsExtTextForm *info = new CComponentsExtTextForm(10, CC_APPEND, w_info, h_info, g_Locale->getText(v_info[i].caption), v_info[i].info_text);
|
||||
info->setLabelAndTextFont(font);
|
||||
info->setTextModes(CTextBox::TOP , CTextBox::AUTO_HIGH | CTextBox::TOP | CTextBox::AUTO_LINEBREAK_NO_BREAKCHARS);
|
||||
info->doPaintBg(false);
|
||||
ccw_body->addCCItem(info);
|
||||
}
|
||||
}
|
||||
|
||||
// This allows to retrieve information about build infos.
|
||||
// Use parameter 'type_info' to get specific information.
|
||||
build_info_t CBuildInfo::getInfo(const info_type_id_t& type_id)
|
||||
{
|
||||
for(size_t i=0; i<v_info.size(); i++){
|
||||
if (v_info[i].type_id == type_id)
|
||||
return v_info[i];
|
||||
}
|
||||
|
||||
int x_label = 0, y_text = 0;
|
||||
int x_text = x_label + w_label + item_offset;
|
||||
int item_height = item_font->getHeight();
|
||||
int item_spacer = item_height / 2;
|
||||
build_info_t res;
|
||||
res.type_id = type_id;
|
||||
res.caption = NONEXISTANT_LOCALE;
|
||||
res.info_text = "Info not available!";
|
||||
|
||||
//recalc w_text to avoid an overlap with pip TODO: calculate within cc_info itself
|
||||
w_text = std::min(w_text, cc_win->getWidth() - x_text - 2*item_offset);
|
||||
//create label and text items
|
||||
int h_tmp = 0;
|
||||
size_t i = 0;
|
||||
|
||||
for (i = 0; i < v_info.size(); i++) {
|
||||
CComponentsLabel *cc_label = new CComponentsLabel();
|
||||
cc_label->setDimensionsAll(x_label, y_text, w_label, item_height);
|
||||
cc_label->setText(v_info[i].caption, CTextBox::NO_AUTO_LINEBREAK, item_font);
|
||||
|
||||
//add label object to window body
|
||||
cc_info->addCCItem(cc_label);
|
||||
|
||||
CComponentsText *cc_text = new CComponentsText();
|
||||
cc_text->setDimensionsAll(x_text, y_text, w_text, item_height);
|
||||
int textMode = CTextBox::AUTO_HIGH | CTextBox::TOP | CTextBox::AUTO_LINEBREAK_NO_BREAKCHARS;
|
||||
cc_text->setText(v_info[i].info_text, textMode, item_font);
|
||||
|
||||
//The rest of body height, less 1 line for each additional entry
|
||||
int rest = bodyHeight-h_tmp-((v_info.size()-(i+1))*(item_height+item_spacer));
|
||||
int lines = cc_text->getTextLinesAutoHeight(rest, w_text, textMode);
|
||||
cc_text->setHeight(lines*item_height);
|
||||
y_text += lines*item_height + item_spacer;
|
||||
|
||||
//add text object to window body
|
||||
cc_info->addCCItem(cc_text);
|
||||
|
||||
// <hr style="width: 85%"> ;-)
|
||||
if (v_info[i].caption == LOCALE_BUILDINFO_CREATOR) {
|
||||
int w1 = (cc_win->getWidth()*85)/100;
|
||||
int x1 = cc_win->getRealXPos() + ((cc_win->getWidth() - w1)/2);
|
||||
CComponentsShapeSquare *cc_shape;
|
||||
cc_shape = new CComponentsShapeSquare(x1, y_text, w1, 2, CC_SHADOW_OFF, COL_MENUHEAD_PLUS_0, COL_MENUHEAD_PLUS_0);
|
||||
y_text += item_spacer;
|
||||
h_tmp += item_spacer;
|
||||
cc_info->addCCItem(cc_shape);
|
||||
}
|
||||
|
||||
//set height for info form
|
||||
h_tmp += lines*item_height + item_spacer;
|
||||
}
|
||||
|
||||
//assign height of info form
|
||||
cc_info->setHeight(h_tmp);
|
||||
|
||||
int ho_h = 0, fo_h = 0;
|
||||
CComponentsHeader* ho = cc_win->getHeaderObject();
|
||||
if (ho) ho_h = ho->getHeight();
|
||||
CComponentsFooter* fo = cc_win->getFooterObject();
|
||||
if (fo) fo_h = fo->getHeight();
|
||||
h_tmp += ho_h + fo_h + 12;
|
||||
cc_win->setHeight(h_tmp);
|
||||
cc_win->setYPos(getScreenStartY(h_tmp));
|
||||
return res;
|
||||
}
|
||||
|
||||
void CBuildInfo::hide()
|
||||
{
|
||||
printf("[CBuildInfo] [%s - %d] hide...\n", __FUNCTION__, __LINE__);
|
||||
if (cc_win){
|
||||
cc_win->hide();
|
||||
Clean();
|
||||
}
|
||||
CComponentsWindow::hide();
|
||||
}
|
||||
|
Reference in New Issue
Block a user