CImageInfo: implement CComponents

TODO:
- format of license text
- button bar or header buttons ?
This commit is contained in:
2013-03-19 08:24:14 +01:00
parent 7e1ef5d325
commit 2387b27b73
2 changed files with 197 additions and 202 deletions

View File

@@ -1,6 +1,9 @@
/* /*
Neutrino-GUI - DBoxII-Project Based up Neutrino-GUI - Tuxbox-Project
Copyright (C) 2001 by Steffen Hehn 'McClean'
Implementation of component classes
Copyright (C) 2013, Thilo Graf 'dbt'
License: GPL License: GPL
@@ -14,9 +17,10 @@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU Library General Public
along with this program; if not, write to the Free Software License along with this library; if not, write to the
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301, USA.
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
@@ -28,83 +32,45 @@
#include <global.h> #include <global.h>
#include <neutrino.h> #include <neutrino.h>
#include <driver/fontrenderer.h>
#include <driver/rcinput.h> #include <driver/rcinput.h>
#include <driver/screen_max.h>
#include <sys/utsname.h> #include <sys/utsname.h>
#include <string>
#include <fstream>
#include <errno.h>
#include <daemonc/remotecontrol.h> #include <daemonc/remotecontrol.h>
#include <system/flashtool.h> #include <system/flashtool.h>
#include <video.h>
#include "git_version.h" #include "git_version.h"
#define GIT_DESC "GIT Desc.:" #define GIT_DESC "GIT Desc.:"
#define GIT_REV "GIT Build:" #define GIT_REV "GIT Build:"
#define LICENSEDIR DATADIR "/neutrino/license/"
using namespace std;
extern CRemoteControl * g_RemoteControl; /* neutrino.cpp */ extern CRemoteControl * g_RemoteControl; /* neutrino.cpp */
CImageInfo::CImageInfo() CImageInfo::CImageInfo(): config ('\t')
{ {
Init(); Init();
} }
static const neutrino_locale_t info_items[8] = //init all var members
{
LOCALE_IMAGEINFO_IMAGE,
LOCALE_IMAGEINFO_DATE,
LOCALE_IMAGEINFO_VERSION,
LOCALE_IMAGEINFO_CREATOR,
LOCALE_IMAGEINFO_HOMEPAGE,
LOCALE_IMAGEINFO_DOKUMENTATION,
LOCALE_IMAGEINFO_FORUM,
LOCALE_IMAGEINFO_LICENSE
};
void CImageInfo::Init(void) void CImageInfo::Init(void)
{ {
frameBuffer = CFrameBuffer::getInstance(); cc_win = NULL;
pip = NULL; item_offset = 20;
font_head = SNeutrinoSettings::FONT_TYPE_INFOBAR_CHANNAME;; item_top = item_offset;
font_small = SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL; license_txt = "";
font_info = SNeutrinoSettings::FONT_TYPE_MENU; v_info.clear();
v_info_supp.clear();
hheight = g_Font[font_head]->getHeight(); config.loadConfig("/.version");
iheight = g_Font[font_info]->getHeight();
sheight = g_Font[font_small]->getHeight();
max_width = frameBuffer->getScreenWidth(true);
max_height = frameBuffer->getScreenHeight(true);
width = frameBuffer->getScreenWidth() - 10;
height = frameBuffer->getScreenHeight() - 10;
x=getScreenStartX( width );
y=getScreenStartY( height );
// calculate max width of used LOCALES
offset = 0;
for (int i = 0; i < 8; i++) {
int tmpoffset = g_Font[font_info]->getRenderWidth(g_Locale->getText (info_items[i]));
if (tmpoffset > offset) {
offset = tmpoffset;
}
}
#ifdef GITVERSION
int off_tmp = g_Font[font_info]->getRenderWidth(GIT_DESC);
#else
int off_tmp = g_Font[font_info]->getRenderWidth(GIT_REV);
#endif
if(off_tmp > offset)
offset = off_tmp;
offset = offset + 15;
} }
CImageInfo::~CImageInfo() CImageInfo::~CImageInfo()
{ {
delete pip; //deallocate window object, deletes also added cc_items
delete cc_win;
} }
int CImageInfo::exec(CMenuTarget* parent, const std::string &) int CImageInfo::exec(CMenuTarget* parent, const std::string &)
@@ -113,12 +79,8 @@ int CImageInfo::exec(CMenuTarget* parent, const std::string &)
if (parent) if (parent)
parent->hide(); parent->hide();
width = frameBuffer->getScreenWidth() - 10; //init window object and add cc_items
height = frameBuffer->getScreenHeight() - 10; ShowWindow();
x=getScreenStartX( width );
y=getScreenStartY( height );
paint();
neutrino_msg_t msg; neutrino_msg_t msg;
while (1) while (1)
@@ -136,67 +98,80 @@ int CImageInfo::exec(CMenuTarget* parent, const std::string &)
res = menu_return::RETURN_EXIT_ALL; res = menu_return::RETURN_EXIT_ALL;
break; break;
} }
else if (msg <= CRCInput::RC_MaxRC) else if (msg <= CRCInput::RC_MaxRC){
{
break; break;
} }
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(); //hide window
cc_win->hide();
//deallocate of the window object causes also deallocate added items,
delete cc_win;
//it's important to set here a null pointer
cc_win = NULL;
return res; return res;
} }
void CImageInfo::hide() //contains all actions to init and add the window object and items
void CImageInfo::ShowWindow()
{ {
pip->hide(true); if (cc_win == NULL){
frameBuffer->paintBackground(); cc_win = new CComponentsWindow(LOCALE_IMAGEINFO_HEAD, NEUTRINO_ICON_INFO);
item_top = cc_win->getStartY() + item_offset;
}
//prepare minitv: important! init the minitv object as first
InitMinitv();
//prepare infos
InitInfos();
//add section space
item_top += 5;
//prepare suppoprt infos
InitSupportInfos();
//prepare license text
InitLicenseText();
//paint window
cc_win->paint();
} }
void CImageInfo::paintLine(int xpos, int font, const char* text) //prepare minitv
void CImageInfo::InitMinitv()
{ {
char buf[100]; //init the minitv object
snprintf((char*) buf,sizeof(buf), "%s", text); CComponentsPIP *cc_tv = new CComponentsPIP (0, item_top, 33/*%*/);
//g_Font[font]->RenderString(xpos, ypos, width-10, buf, COL_MENUCONTENT, 0, true);
g_Font[font]->RenderString(xpos, ypos, width-10, buf, COL_INFOBAR, 0, true); //init x pos and use as parameter for setXPos
int cc_tv_x = (cc_win->getWidth() - cc_tv->getWidth()) - item_offset;
cc_tv->setXPos(cc_tv_x);
//add minitv to container
cc_win->addCCItem(cc_tv);
} }
void CImageInfo::paint() //prepare distribution infos
void CImageInfo::InitInfos()
{ {
const char * head_string; v_info.clear();
char imagedate[18] = "";
int xpos = x+10;
ypos = y+5;
head_string = g_Locale->getText(LOCALE_IMAGEINFO_HEAD);
CVFD::getInstance()->setMode(CVFD::MODE_MENU_UTF8, head_string);
frameBuffer->paintBoxRel(0, 0, max_width, max_height, COL_INFOBAR_PLUS_0);
g_Font[font_head]->RenderString(xpos, ypos+ hheight+1, width, head_string, COL_MENUHEAD, 0, true);
ypos += hheight;
ypos += (iheight >>1);
CConfigFile config('\t');
config.loadConfig("/.version");
const char * imagename = config.getString("imagename", "Neutrino-HD").c_str();
const char * homepage = config.getString("homepage", "n/a").c_str();
const char * creator = config.getString("creator", "n/a").c_str();
const char * version = config.getString("version", "no version").c_str();
const char * docs = config.getString("docs", "http://wiki.neutrino-hd.de").c_str();
const char * forum = config.getString("forum", "http://forum.tuxbox.org").c_str();
#ifdef GITVERSION #ifdef GITVERSION
const char * builddate = GITVERSION; const char * builddate = GITVERSION;
#else #else
const char * builddate = config.getString("builddate", BUILT_DATE).c_str(); const char * builddate = config.getString("builddate", BUILT_DATE).c_str();
#endif #endif
const char * version = config.getString("version", "no version").c_str();
config.getString("version", "no version");
static CFlashVersionInfo versionInfo(version); static CFlashVersionInfo versionInfo(version);
const char * releaseCycle = versionInfo.getReleaseCycle(); const char * releaseCycle = versionInfo.getReleaseCycle();
@@ -214,79 +189,99 @@ void CImageInfo::paint()
Version_Kernel += uts_info.release; Version_Kernel += uts_info.release;
} }
snprintf((char*) imagedate,sizeof(imagedate), "%s %s", versionInfo.getDate(), versionInfo.getTime()); image_info_t imagename = {LOCALE_IMAGEINFO_IMAGE, config.getString("imagename", "Neutrino-HD")};
v_info.push_back(imagename);
image_info_t date = {LOCALE_IMAGEINFO_DATE, builddate};
v_info.push_back(date);
image_info_t kversion = {LOCALE_IMAGEINFO_VERSION, Version_Kernel};
v_info.push_back(kversion);
image_info_t creator = {LOCALE_IMAGEINFO_CREATOR, config.getString("creator", "n/a")};
v_info.push_back(creator);
ypos += iheight; //create label and text items
paintLine(xpos , font_info, g_Locale->getText(LOCALE_IMAGEINFO_IMAGE)); for (size_t i = 0; i < v_info.size(); i++) {
paintLine(xpos+offset, font_info, imagename); CComponentsLabel *cc_txt = new CComponentsLabel();
cc_txt->setDimensionsAll(item_offset, item_top, 200, g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight());
cc_txt->setText(v_info[i].caption, CTextBox::NO_AUTO_LINEBREAK, g_Font[SNeutrinoSettings::FONT_TYPE_MENU]);
ypos += iheight; //add label to container
paintLine(xpos , font_info, g_Locale->getText(LOCALE_IMAGEINFO_DATE)); cc_win->addCCItem(cc_txt);
paintLine(xpos+offset, font_info, imagedate);
ypos += iheight; CComponentsText *cc_info = new CComponentsText();
paintLine(xpos , font_info, g_Locale->getText(LOCALE_IMAGEINFO_VERSION)); cc_info->setDimensionsAll(item_offset+cc_txt->getWidth(), item_top, 450, g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight());
paintLine(xpos+offset, font_info, Version_Kernel.c_str()); cc_info->setText(v_info[i].info_text.c_str(), CTextBox::NO_AUTO_LINEBREAK, g_Font[SNeutrinoSettings::FONT_TYPE_MENU]);
ypos += iheight; //add text to container
#ifdef GITVERSION cc_win->addCCItem(cc_info);
paintLine(xpos , font_info, GIT_DESC);
#else
paintLine(xpos , font_info, GIT_REV);
#endif
paintLine(xpos+offset, font_info, builddate );
ypos += iheight; item_top += item_offset*2-5;
paintLine(xpos , font_info, g_Locale->getText(LOCALE_IMAGEINFO_CREATOR)); }
paintLine(xpos+offset, font_info, creator); }
ypos += iheight+15; //prepare support infos
paintLine(xpos , font_info, g_Locale->getText(LOCALE_IMAGEINFO_HOMEPAGE)); void CImageInfo::InitSupportInfos()
paintLine(xpos+offset, font_info, homepage); {
v_info_supp.clear();
ypos += iheight;
paintLine(xpos , font_info, g_Locale->getText(LOCALE_IMAGEINFO_DOKUMENTATION)); image_info_t www = {LOCALE_IMAGEINFO_HOMEPAGE, config.getString("homepage", "n/a")};
paintLine(xpos+offset, font_info, docs); v_info_supp.push_back(www);
image_info_t doc = {LOCALE_IMAGEINFO_DOKUMENTATION, config.getString("docs", "http://wiki.neutrino-hd.de")};
ypos += iheight; v_info_supp.push_back(doc);
paintLine(xpos , font_info, g_Locale->getText(LOCALE_IMAGEINFO_FORUM)); image_info_t forum = {LOCALE_IMAGEINFO_FORUM, config.getString("forum", "http://forum.tuxbox.org")};
paintLine(xpos+offset, font_info, forum); v_info_supp.push_back(forum);
image_info_t license = {LOCALE_IMAGEINFO_LICENSE, "GPL"};
ypos += iheight+15; v_info_supp.push_back(license);
paintLine(xpos, font_info,g_Locale->getText(LOCALE_IMAGEINFO_LICENSE));
paintLine(xpos+offset, font_small, "This program is free software; you can redistribute it and/or modify"); //create text an label items
for (size_t i = 0; i < v_info_supp.size(); i++) {
ypos+= sheight; CComponentsLabel *cc_txt = new CComponentsLabel();
paintLine(xpos+offset, font_small, "it under the terms of the GNU General Public License as published by"); cc_txt->setDimensionsAll(item_offset, item_top, 200, g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight());
cc_txt->setText(v_info_supp[i].caption, CTextBox::NO_AUTO_LINEBREAK, g_Font[SNeutrinoSettings::FONT_TYPE_MENU]);
ypos+= sheight;
paintLine(xpos+offset, font_small, "the Free Software Foundation; either version 2 of the License, or"); cc_win->addCCItem(cc_txt);
ypos+= sheight; CComponentsText *cc_info = new CComponentsText();
paintLine(xpos+offset, font_small, "(at your option) any later version."); cc_info->setDimensionsAll(item_offset+cc_txt->getWidth(), item_top, 450, g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight());
cc_info->setText(v_info_supp[i].info_text.c_str(), CTextBox::NO_AUTO_LINEBREAK, g_Font[SNeutrinoSettings::FONT_TYPE_MENU]);
ypos+= sheight+10;
paintLine(xpos+offset, font_small, "This program is distributed in the hope that it will be useful,"); cc_win->addCCItem(cc_info);
ypos+= sheight; item_top += item_offset*2-5;
paintLine(xpos+offset, font_small, "but WITHOUT ANY WARRANTY; without even the implied warranty of"); }
}
ypos+= sheight;
paintLine(xpos+offset, font_small, "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."); //prepare license infos
void CImageInfo::InitLicenseText()
ypos+= sheight; {
paintLine(xpos+offset, font_small, "See the GNU General Public License for more details."); license_txt = "";
char line[256];
ypos+= sheight+10; string file = LICENSEDIR;
paintLine(xpos+offset, font_small, "You should have received a copy of the GNU General Public License"); file += g_settings.language;
file += ".license";
ypos+= sheight; ifstream in (file.c_str(), ios::in);
paintLine(xpos+offset, font_small, "along with this program; if not, write to the Free Software");
if (!in){
ypos+= sheight; printf("[CImageInfo] [%s - %d] error while open %s -> %s\n", __FUNCTION__, __LINE__, file.c_str(), strerror(errno));
paintLine(xpos+offset, font_small, "Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA."); return;
}
if (pip == NULL)
pip = new CComponentsPIP(width-width/3-10, y+10, 33); while (in.getline (line, 256)){
pip->paint(); string lline = (string)line;
license_txt += lline + '\n';
}
in.close();
CComponentsInfoBox *cc_lic = new CComponentsInfoBox(item_offset, item_top, cc_win->getWidth()-2*item_offset, cc_win->getHeight()-item_top);
cc_lic->removeLineBreaks(license_txt);
cc_lic->setText(license_txt, CTextBox::AUTO_WIDTH, g_Font[SNeutrinoSettings::FONT_TYPE_MENU_HINT]);
//add text to container
cc_win->addCCItem(cc_lic);
}
void CImageInfo::hide()
{
cc_win->hide();
} }

View File

@@ -1,6 +1,9 @@
/* /*
Neutrino-GUI - DBoxII-Project Based up Neutrino-GUI - Tuxbox-Project
Copyright (C) 2001 by Steffen Hehn 'McClean'
Implementation of component classes
Copyright (C) 2013, Thilo Graf 'dbt'
License: GPL License: GPL
@@ -14,49 +17,46 @@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU Library General Public
along with this program; if not, write to the Free Software License along with this library; if not, write to the
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301, USA.
*/ */
#ifndef __imageinfo__ #ifndef __imageinfo__
#define __imageinfo__ #define __imageinfo__
#include <gui/widget/menue.h>
#include <gui/components/cc.h>
#include <configfile.h> #include <configfile.h>
#include <gui/widget/menue.h> typedef struct image_info_t
#include <system/localize.h> {
#include <driver/framebuffer.h> neutrino_locale_t caption;
#include <gui/components/cc.h> std::string info_text;
} image_info_struct_t;
class CImageInfo : public CMenuTarget class CImageInfo : public CMenuTarget
{ {
private: private:
void Init(void); int item_offset; //distance between items and to boarder
CConfigFile * configfile; int item_top; //start line in y below header
CFrameBuffer *frameBuffer; std::string license_txt;
CComponentsPIP * pip;
int x;
int y;
int ypos;
int width;
int height;
int hheight,iheight,sheight; // head/info/small font height
int max_height; // Frambuffer 0.. max std::vector<image_info_t> v_info;
int max_width; std::vector<image_info_t> v_info_supp;
neutrino_locale_t name; void Init();
int offset; void InitMinitv();
void InitInfos();
void InitSupportInfos();
void ShowWindow();
void InitLicenseText();
int font_head; CComponentsWindow *cc_win;
int font_info; CConfigFile config;
int font_small;
void paint();
void paintLine(int xpos, int font, const char* text);
public: public: