CBuildInfo: rework buildinfo class for use as CComponentsWindow

also possible: get partial informations also as strings for usage
in other classes
This commit is contained in:
2013-11-10 23:58:38 +01:00
parent 4cf4857201
commit 6955df5c5e
5 changed files with 123 additions and 162 deletions

View File

@@ -200,7 +200,7 @@ bouquetname.hdtv HD Kanäle
bouquetname.new Neue Kanäle bouquetname.new Neue Kanäle
bouquetname.other Unbekannter Provider bouquetname.other Unbekannter Provider
bouquetname.removed Gelöschte Kanäle bouquetname.removed Gelöschte Kanäle
buildinfo.compiled_on Build PC buildinfo.compiled_on Build Host
buildinfo.compiled_with Compiler Version buildinfo.compiled_with Compiler Version
buildinfo.compiler_flags Compiler Flags buildinfo.compiler_flags Compiler Flags
buildinfo.creator Ersteller buildinfo.creator Ersteller

View File

@@ -200,7 +200,7 @@ bouquetname.hdtv HD channels
bouquetname.new New channels bouquetname.new New channels
bouquetname.other Unknown provider bouquetname.other Unknown provider
bouquetname.removed Removed channels bouquetname.removed Removed channels
buildinfo.compiled_on Build PC buildinfo.compiled_on Build Host
buildinfo.compiled_with Compiler version buildinfo.compiled_with Compiler version
buildinfo.compiler_flags Compiler flags buildinfo.compiler_flags Compiler flags
buildinfo.creator Creator buildinfo.creator Creator

View File

@@ -203,6 +203,12 @@ bouquetname.hdtv HD zenders
bouquetname.new Nieuwe Zenders bouquetname.new Nieuwe Zenders
bouquetname.other Onbekende provider bouquetname.other Onbekende provider
bouquetname.removed Verwijderde zenders bouquetname.removed Verwijderde zenders
buildinfo.compiled_on Build Host
buildinfo.compiled_with Compiler Version
buildinfo.compiler_flags Compiler Flags
buildinfo.creator Creator
buildinfo.kernel Kernel Version
buildinfo.menu Build Informationen
cablesetup.provider kabel provider cablesetup.provider kabel provider
channellist.additional Extra informatie channellist.additional Extra informatie
channellist.additional_off Uit channellist.additional_off Uit

View File

@@ -23,63 +23,60 @@
Boston, MA 02110-1301, USA. Boston, MA 02110-1301, USA.
*/ */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <global.h> #include <global.h>
#include <neutrino.h> #include <neutrino.h>
//#include <sys/utsname.h>
#include <string> #include <string>
#include <driver/screen_max.h>
#include <driver/neutrinofonts.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/buildinfo.h>
#include <gui/widget/messagebox.h>
#include <system/helpers.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 //init all var members
void CBuildInfo::Init(void) void CBuildInfo::initVarBuildInfo()
{ {
cc_win = NULL; x = frameBuffer->getScreenWidth(true)/2 - width/2;
cc_info = NULL; y = frameBuffer->getScreenHeight(true)/2 -height/2;
item_offset = 10;
bodyHeight = 0; append_v_offset = 1;
v_info.clear(); font = NULL;
config.loadConfig("/.version"); setWindowHeaderButtons(CComponentsHeader::CC_BTN_MENU | CComponentsHeader::CC_BTN_EXIT);
InitInfoItems();
shadow = true;
} }
CBuildInfo::~CBuildInfo() CBuildInfo::~CBuildInfo()
{ {
hide(); cleanCCForm();
delete cc_win;
} }
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; int res = menu_return::RETURN_REPAINT;
if (parent) if (parent)
parent->hide(); parent->hide();
//clean up before, because we could have a current instance with already initialized contents //exit if no informations available
Clean(); if (!HasData()){
return res;
}
//paint window
if (!is_painted)
paint();
//init window object, add cc-items and paint all
ShowWindow();
neutrino_msg_t msg; neutrino_msg_t msg;
while (1) while (1)
@@ -104,163 +101,112 @@ int CBuildInfo::exec(CMenuTarget* parent, const std::string &)
if ( msg > CRCInput::RC_MaxRC && msg != CRCInput::RC_timeout){ if ( msg > CRCInput::RC_MaxRC && msg != CRCInput::RC_timeout){
CNeutrinoApp::getInstance()->handleMsg( msg, data ); CNeutrinoApp::getInstance()->handleMsg( msg, data );
} }
} }
//hide window
hide(); hide();
return res; return res;
} }
void CBuildInfo::ShowWindow() void CBuildInfo::setFontType(Font* font_text)
{ {
if (cc_win == NULL){ if (font_text == NULL)
cc_win = new CComponentsWindow(LOCALE_BUILDINFO_MENU, NEUTRINO_ICON_INFO); return;
cc_win->setWindowHeaderButtons(CComponentsHeader::CC_BTN_MENU | CComponentsHeader::CC_BTN_EXIT); font = font_text;
CFrameBuffer *frameBuffer = CFrameBuffer::getInstance(); InitInfoItems();
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();
} }
void CBuildInfo::InitInfos() bool CBuildInfo::HasData()
{ {
v_info.clear(); v_info.clear();
#ifdef USED_COMPILER #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); v_info.push_back(compiler);
#endif #endif
#ifdef USED_CXXFLAGS #ifdef USED_CXXFLAGS
std::string cxxflags = USED_CXXFLAGS; string cxxflags = USED_CXXFLAGS;
cxxflags = trim(cxxflags); cxxflags = trim(cxxflags);
// Remove double spaces // Remove double spaces
size_t pos = cxxflags.find(" "); size_t pos = cxxflags.find(" ");
while (pos != std::string::npos) { while (pos != string::npos) {
cxxflags.erase(pos, 1); cxxflags.erase(pos, 1);
pos = cxxflags.find(" ", pos); 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); v_info.push_back(flags);
#endif #endif
#ifdef USED_BUILD #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); v_info.push_back(build);
#endif #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); v_info.push_back(creator);
#endif
FILE *fp = fopen("/proc/version", "r"); if (v_info.empty()){
if (fp) { DisplayInfoMessage("No Informations available. Please report!");
char zeile[1024]; return false;
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);
} }
// ########################################################### return true;
}
int dx = 0, dy = 27; void CBuildInfo::InitInfoItems()
Font * item_font = *(CNeutrinoFonts::getInstance()->getDynFont(dx, dy)); {
//get and checkup required informations
if (!HasData())
return;
//initialize container for infos //ensure a clean body
if (cc_info == NULL) ccw_body->clearCCItems();
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);
//calculate max width of label and info_text //define size and position
int w_label = 0, w_text = 0, w = 0; int x_info = 10;
for (size_t i = 0; i < v_info.size(); i++) { int h_info = ccw_body->getHeight()/v_info.size(); //default height
w = item_font->getRenderWidth(g_Locale->getText(v_info[i].caption), true); int w_info = width-2*x_info;
w_label = std::max(w_label, w);
w = item_font->getRenderWidth(v_info[i].info_text.c_str(), true); //init info texts
w_text = std::max(w_text, w); 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; build_info_t res;
int x_text = x_label + w_label + item_offset; res.type_id = type_id;
int item_height = item_font->getHeight(); res.caption = NONEXISTANT_LOCALE;
int item_spacer = item_height / 2; res.info_text = "Info not available!";
//recalc w_text to avoid an overlap with pip TODO: calculate within cc_info itself return res;
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));
} }
void CBuildInfo::hide() void CBuildInfo::hide()
{ {
printf("[CBuildInfo] [%s - %d] hide...\n", __FUNCTION__, __LINE__); CComponentsWindow::hide();
if (cc_win){
cc_win->hide();
Clean();
}
} }

View File

@@ -32,37 +32,46 @@
#endif #endif
#include <gui/widget/menue.h> #include <gui/widget/menue.h>
#include <gui/components/cc_frm.h> #include <gui/components/cc.h>
#include <configfile.h>
typedef int info_type_id_t;
typedef struct build_info_t typedef struct build_info_t
{ {
info_type_id_t type_id;
neutrino_locale_t caption; neutrino_locale_t caption;
std::string info_text; std::string info_text;
} build_info_struct_t; } build_info_struct_t;
class CBuildInfo : public CMenuTarget class CBuildInfo : public CMenuTarget, public CComponentsWindow
{ {
private: private:
int item_offset;
int bodyHeight;
std::vector<build_info_t> v_info; std::vector<build_info_t> v_info;
Font* font;
void initVarBuildInfo();
void InitInfoItems();
void Clean(); bool HasData();
void Init();
void InitInfos();
void ShowWindow();
CComponentsWindow *cc_win;
CComponentsForm *cc_info;
CConfigFile config;
public: public:
//type_id's for infos
enum
{
BI_TYPE_ID_USED_COMPILER,
BI_TYPE_ID_USED_CXXFLAGS,
BI_TYPE_ID_USED_BUILD,
BI_TYPE_ID_USED_KERNEL,
BI_TYPE_ID_CREATOR,
BI_TYPE_IDS,
};
CBuildInfo(); CBuildInfo();
~CBuildInfo(); ~CBuildInfo();
///assigns text Font type
void setFontType(Font* font_text);
build_info_t getInfo(const info_type_id_t& type_id);
void hide(); void hide();
int exec(CMenuTarget* parent, const std::string & actionKey); int exec(CMenuTarget* parent, const std::string & actionKey);
}; };