our current experimental Neutrino branch

git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@27 e54a6e83-5905-42d5-8d5c-058d10e6a962
This commit is contained in:
mrcolor
2009-12-08 11:05:11 +00:00
commit bc5bd4154e
876 changed files with 193775 additions and 0 deletions

22
src/system/Makefile.am Normal file
View File

@@ -0,0 +1,22 @@
AM_CPPFLAGS = -fno-rtti -fno-exceptions
INCLUDES = \
-I$(top_srcdir)/lib \
-I$(top_srcdir)/src \
-I$(top_srcdir)/src/zapit/include \
-I$(top_srcdir)/lib/connection \
-I$(top_srcdir)/lib/libeventserver \
-I$(top_srcdir)/lib/libnet \
-I$(top_srcdir)/lib/libconfigfile \
-I$(top_srcdir)/lib/libcoolstream \
-I$(top_srcdir)/lib/libmd5sum \
-I$(top_srcdir)/lib/xmltree \
@FREETYPE_CFLAGS@
noinst_LIBRARIES = libneutrino_system.a
libneutrino_system_a_SOURCES = \
localize.cpp setting_helpers.cpp debug.cpp \
ping.c flashtool.cpp httptool.cpp \
settings.cpp lastchannel.cpp \
configure_network.cpp fsmounter.cpp

View File

@@ -0,0 +1,117 @@
/*
* $Header: /cvsroot/tuxbox/apps/tuxbox/neutrino/src/system/configure_network.cpp,v 1.6 2003/03/26 17:53:12 thegoodguy Exp $
*
* (C) 2003 by thegoodguy <thegoodguy@berlios.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <config.h>
#include <sys/wait.h>
#include "configure_network.h"
#include "libnet.h" /* netGetNameserver, netSetNameserver */
#include "network_interfaces.h" /* getInetAttributes, setInetAttributes */
#include <stdlib.h> /* system */
CNetworkConfig::CNetworkConfig(void)
{
char our_nameserver[16];
netGetNameserver(our_nameserver);
nameserver = our_nameserver;
inet_static = getInetAttributes("eth0", automatic_start, address, netmask, broadcast, gateway);
copy_to_orig();
}
void CNetworkConfig::copy_to_orig(void)
{
orig_automatic_start = automatic_start;
orig_address = address;
orig_netmask = netmask;
orig_broadcast = broadcast;
orig_gateway = gateway;
orig_inet_static = inet_static;
}
bool CNetworkConfig::modified_from_orig(void)
{
return (
(orig_automatic_start != automatic_start) ||
(orig_address != address ) ||
(orig_netmask != netmask ) ||
(orig_broadcast != broadcast ) ||
(orig_gateway != gateway ) ||
(orig_inet_static != inet_static )
);
}
void CNetworkConfig::commitConfig(void)
{
if (modified_from_orig())
{
copy_to_orig();
if (inet_static)
{
addLoopbackDevice("lo", true);
setStaticAttributes("eth0", automatic_start, address, netmask, broadcast, gateway);
}
else
{
addLoopbackDevice("lo", true);
setDhcpAttributes("eth0", automatic_start);
}
}
if (nameserver != orig_nameserver)
{
orig_nameserver = nameserver;
netSetNameserver(nameserver.c_str());
}
}
int mysystem(char * cmd, char * arg1, char * arg2)
{
int pid, i;
switch (pid = fork())
{
case -1: /* can't fork */
perror("fork");
return -1;
case 0: /* child process */
for(i = 3; i < 256; i++)
close(i);
if(execlp(cmd, cmd, arg1, arg2, NULL))
{
perror("exec");
}
exit(0);
default: /* parent returns to calling process */
break;
}
waitpid(pid, 0, 0);
return 0;
}
void CNetworkConfig::startNetwork(void)
{
system("/sbin/ifup -v eth0");
//mysystem((char *) "ifup", (char *) "-v", (char *) "eth0");
}
void CNetworkConfig::stopNetwork(void)
{
//mysystem("ifdown eth0", NULL, NULL);
system("/sbin/ifdown eth0");
}

View File

@@ -0,0 +1,58 @@
#ifndef __configure_network_h__
#define __configure_network_h__
/*
* $Header: /cvsroot/tuxbox/apps/tuxbox/neutrino/src/system/configure_network.h,v 1.3 2003/03/10 21:22:41 thegoodguy Exp $
*
* (C) 2003 by thegoodguy <thegoodguy@berlios.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <string>
class CNetworkConfig
{
private:
bool orig_automatic_start;
std::string orig_address;
std::string orig_netmask;
std::string orig_broadcast;
std::string orig_gateway;
std::string orig_nameserver;
bool orig_inet_static;
void copy_to_orig(void);
bool modified_from_orig(void);
public:
bool automatic_start;
std::string address;
std::string netmask;
std::string broadcast;
std::string gateway;
std::string nameserver;
bool inet_static;
CNetworkConfig(void);
void commitConfig(void);
void startNetwork(void);
void stopNetwork(void);
};
#endif /* __configure_network_h__ */

32
src/system/debug.cpp Normal file
View File

@@ -0,0 +1,32 @@
/*
NeutrinoNG - DBoxII-Project
Copyright (C) 2001 Steffen Hehn 'McClean'
Homepage: http://dbox.cyberphoria.org/
License: GPL
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "debug.h"
int debug = DEBUG_NORMAL;
void setDebugLevel( int level )
{
debug = level;
}

40
src/system/debug.h Normal file
View File

@@ -0,0 +1,40 @@
/*
NeutrinoNG - DBoxII-Project
Copyright (C) 2001 Steffen Hehn 'McClean'
Homepage: http://dbox.cyberphoria.org/
License: GPL
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __neutrino_debug__
#define __neutrino_debug__
extern int debug;
#define DEBUG_NORMAL 0
#define DEBUG_INFO 1
#define DEBUG_DEBUG 2
void setDebugLevel( int level );
#define dprintf(debuglevel, fmt, args...) {if(debug>=debuglevel) printf( "[neutrino] " fmt, ## args);}
#define dperror(str) {perror("[neutrino] " str);}
#endif

538
src/system/flashtool.cpp Normal file
View File

@@ -0,0 +1,538 @@
/*
Neutrino-GUI - DBoxII-Project
License: GPL
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <libmd5sum.h>
#include <system/flashtool.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/reboot.h>
#include <linux/version.h>
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,7)
//#include <linux/compiler.h>
#include <mtd/mtd-user.h>
#else
#include <mtd/mtd-user.h>
//#include <linux/mtd/mtd.h>
#endif
//#include <libcramfs.h>
#include <driver/encoding.h>
#include <global.h>
CFlashTool::CFlashTool()
{
statusViewer = NULL;
mtdDevice = "";
ErrorMessage = "";
}
CFlashTool::~CFlashTool()
{
}
const std::string & CFlashTool::getErrorMessage(void) const
{
return ErrorMessage;
}
void CFlashTool::setMTDDevice( const std::string & mtddevice )
{
mtdDevice = mtddevice;
printf("flashtool.cpp: set mtd device to %s\n", mtddevice.c_str());
}
void CFlashTool::setStatusViewer( CProgress_StatusViewer* statusview )
{
statusViewer = statusview;
}
bool CFlashTool::readFromMTD( const std::string & filename, int globalProgressEnd )
{
int fd1, fd2;
long filesize;
int globalProgressBegin = 0;
if(statusViewer)
{
statusViewer->showLocalStatus(0);
}
if (mtdDevice.empty())
{
ErrorMessage = "mtd-device not set";
return false;
}
if( (fd1 = open( mtdDevice.c_str(), O_RDONLY )) < 0 )
{
ErrorMessage = g_Locale->getText(LOCALE_FLASHUPDATE_CANTOPENMTD);
return false;
}
if( (fd2 = open( filename.c_str(), O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)) < 0 )
{
ErrorMessage = g_Locale->getText(LOCALE_FLASHUPDATE_CANTOPENFILE);
close(fd1);
return false;
}
if(statusViewer)
{
globalProgressBegin = statusViewer->getGlobalStatus();
}
filesize = CMTDInfo::getInstance()->getMTDSize(mtdDevice);
char buf[1024];
long fsize = filesize;
while(fsize>0)
{
long block = fsize;
if(block>(long)sizeof(buf))
{
block = sizeof(buf);
}
read( fd1, &buf, block);
write( fd2, &buf, block);
fsize -= block;
char prog = char(100-(100./filesize*fsize));
if(statusViewer)
{
statusViewer->showLocalStatus(prog);
if(globalProgressEnd!=-1)
{
int globalProg = globalProgressBegin + int((globalProgressEnd-globalProgressBegin) * prog/100. );
statusViewer->showGlobalStatus(globalProg);
}
}
}
if(statusViewer)
{
statusViewer->showLocalStatus(100);
}
close(fd1);
close(fd2);
return true;
}
bool CFlashTool::program( const std::string & filename, int globalProgressEndErase, int globalProgressEndFlash )
{
int fd1, fd2;
long filesize;
int globalProgressBegin = 0;
if(statusViewer)
{
statusViewer->showLocalStatus(0);
}
if (mtdDevice.empty())
{
ErrorMessage = "mtd-device not set";
return false;
}
if( (fd1 = open( filename.c_str(), O_RDONLY )) < 0 )
{
ErrorMessage = g_Locale->getText(LOCALE_FLASHUPDATE_CANTOPENFILE);
return false;
}
filesize = lseek( fd1, 0, SEEK_END);
lseek( fd1, 0, SEEK_SET);
if(filesize==0)
{
ErrorMessage = g_Locale->getText(LOCALE_FLASHUPDATE_FILEIS0BYTES);
return false;
}
if(statusViewer)
{
statusViewer->showLocalStatus(0);
statusViewer->showStatusMessageUTF(g_Locale->getText(LOCALE_FLASHUPDATE_ERASING)); // UTF-8
}
//g_Zapit->shutdown(); sleep(2);
if(!erase(globalProgressEndErase))
{
return false;
}
if(statusViewer)
{
if(globalProgressEndErase!=-1)
{
statusViewer->showGlobalStatus(globalProgressEndErase);
}
statusViewer->showLocalStatus(0);
statusViewer->showStatusMessageUTF(g_Locale->getText(LOCALE_FLASHUPDATE_PROGRAMMINGFLASH)); // UTF-8
}
if( (fd2 = open( mtdDevice.c_str(), O_WRONLY )) < 0 )
{
ErrorMessage = g_Locale->getText(LOCALE_FLASHUPDATE_CANTOPENMTD);
close(fd1);
return false;
}
if(statusViewer)
{
globalProgressBegin = statusViewer->getGlobalStatus();
}
char buf[1024];
long fsize = filesize;
while(fsize>0)
{
long block = fsize;
if(block>(long)sizeof(buf))
{
block = sizeof(buf);
}
read( fd1, &buf, block);
write( fd2, &buf, block);
fsize -= block;
char prog = char(100-(100./filesize*fsize));
if(statusViewer)
{
statusViewer->showLocalStatus(prog);
if(globalProgressEndFlash!=-1)
{
int globalProg = globalProgressBegin + int((globalProgressEndFlash-globalProgressBegin) * prog/100. );
statusViewer->showGlobalStatus(globalProg);
}
}
}
if(statusViewer)
{
statusViewer->showLocalStatus(100);
}
close(fd1);
close(fd2);
return true;
}
bool CFlashTool::erase(int globalProgressEnd)
{
int fd;
mtd_info_t meminfo;
erase_info_t erase;
int globalProgressBegin = 0;
if( (fd = open( mtdDevice.c_str(), O_RDWR )) < 0 )
{
ErrorMessage = g_Locale->getText(LOCALE_FLASHUPDATE_CANTOPENMTD);
return false;
}
if( ioctl( fd, MEMGETINFO, &meminfo ) != 0 )
{
#warning TODO: localize error message
ErrorMessage = "can't get mtd-info";
return false;
}
if(statusViewer)
{
globalProgressBegin = statusViewer->getGlobalStatus();
}
erase.length = meminfo.erasesize;
for (erase.start = 0; erase.start < meminfo.size;erase.start += meminfo.erasesize)
{
printf( "Erasing %s erase size %x start %x size %x\n",
mtdDevice.c_str(), meminfo.erasesize, erase.start,
meminfo.size );
printf( "\rErasing %u Kbyte @ %x -- %2u %% complete.",
meminfo.erasesize/1024, erase.start,
erase.start*100/meminfo.size );
if(statusViewer)
{
int prog = int(erase.start*100./meminfo.size);
statusViewer->showLocalStatus(prog);
if(globalProgressEnd!=-1)
{
int globalProg = globalProgressBegin + int((globalProgressEnd-globalProgressBegin) * prog/100. );
statusViewer->showGlobalStatus(globalProg);
}
}
if(ioctl( fd, MEMERASE, &erase) != 0)
{
ErrorMessage = g_Locale->getText(LOCALE_FLASHUPDATE_ERASEFAILED);
close(fd);
return false;
}
}
close(fd);
return true;
}
bool CFlashTool::check_cramfs( const std::string & filename )
{
int retVal = 0; //cramfs_crc( (char*) filename.c_str() );
printf("flashcheck returned: %d\n", retVal);
return retVal==1;
}
#define FROMHEX(c) ((c)>='a' ? (c)-'a'+10 : ((c)>='A' ? (c)-'A'+10 : (c)-'0'))
bool CFlashTool::check_md5( const std::string & filename, const std::string & smd5)
{
unsigned char md5[16];
unsigned char omd5[16];
const char * ptr = smd5.c_str();
if(strlen(ptr) < 32)
return false;
//printf("[flashtool] check file %s md5 %s\n", filename.c_str(), ptr);
for(int i = 0; i < 16; i++)
omd5[i] = FROMHEX(ptr[i*2])*16 + FROMHEX(ptr[i*2+1]);
md5_file(filename.c_str(), 1, md5);
if(memcmp(md5, omd5, 16))
return false;
return true;
}
void CFlashTool::reboot()
{
::sync();
::reboot(RB_AUTOBOOT);
::exit(0);
}
//-----------------------------------------------------------------------------------------------------------------
CFlashVersionInfo::CFlashVersionInfo(const std::string & versionString)
{
//SBBBYYYYMMTTHHMM -- formatsting
// recover type
snapshot = versionString[0];
// recover release cycle version
releaseCycle[0] = versionString[1];
releaseCycle[1] = '.';
/*
if (versionString[2] == '0')
{
releaseCycle[2] = versionString[3];
releaseCycle[3] = 0;
}
else
*/
{
releaseCycle[2] = versionString[2];
releaseCycle[3] = versionString[3];
releaseCycle[4] = 0;
}
// recover date
date[0] = versionString[10];
date[1] = versionString[11];
date[2] = '.';
date[3] = versionString[8];
date[4] = versionString[9];
date[5] = '.';
date[6] = versionString[4];
date[7] = versionString[5];
date[8] = versionString[6];
date[9] = versionString[7];
date[10] = 0;
// recover time stamp
time[0] = versionString[12];
time[1] = versionString[13];
time[2] = ':';
time[3] = versionString[14];
time[4] = versionString[15];
time[5] = 0;
}
const char * const CFlashVersionInfo::getDate(void) const
{
return date;
}
const char * const CFlashVersionInfo::getTime(void) const
{
return time;
}
const char * const CFlashVersionInfo::getReleaseCycle(void) const
{
return releaseCycle;
}
const char * const CFlashVersionInfo::getType(void) const
{
switch (snapshot)
{
case '0':
return "Release";
case '1':
return "Beta";
case '2':
return "Internal";
case 'L':
return "Locale";
case 'S':
return "Settings";
case 'A':
return "Addon";
case 'T':
return "Text";
default:
return "Unknown";
}
}
//-----------------------------------------------------------------------------------------------------------------
CMTDInfo::CMTDInfo()
{
getPartitionInfo();
}
CMTDInfo::~CMTDInfo()
{
for(int x=0;x<getMTDCount();x++)
{
delete mtdData[x];
}
mtdData.clear();
}
CMTDInfo* CMTDInfo::getInstance()
{
static CMTDInfo* MTDInfo = NULL;
if(!MTDInfo)
{
MTDInfo = new CMTDInfo();
}
return MTDInfo;
}
void CMTDInfo::getPartitionInfo()
{
FILE* fd = fopen("/proc/mtd", "r");
if(!fd)
{
perror("cannot read /proc/mtd");
return;
}
char buf[1000];
fgets(buf,sizeof(buf),fd);
while(!feof(fd))
{
if(fgets(buf,sizeof(buf),fd)!=NULL)
{
char mtdname[50]="";
int mtdnr=0;
int mtdsize=0;
int mtderasesize=0;
sscanf(buf, "mtd%d: %x %x \"%s\"\n", &mtdnr, &mtdsize, &mtderasesize, mtdname);
SMTDPartition* tmp = new SMTDPartition;
tmp->size = mtdsize;
tmp->erasesize = mtderasesize;
std::string tmpstr = buf;
tmp->name = tmpstr.substr( tmpstr.find('\"')+1, tmpstr.rfind('\"')-tmpstr.find('\"')-1);
sprintf((char*) &buf, "/dev/mtd%d", mtdnr);
tmp->filename = buf;
mtdData.push_back(tmp);
}
}
fclose(fd);
}
int CMTDInfo::getMTDCount()
{
return mtdData.size();
}
std::string CMTDInfo::getMTDName(const int pos)
{
#warning TODO: check /proc/mtd specification to determine mtdname encoding
return FILESYSTEM_ENCODING_TO_UTF8_STRING(mtdData[pos]->name);
}
std::string CMTDInfo::getMTDFileName(const int pos)
{
return mtdData[pos]->filename;
}
int CMTDInfo::getMTDSize(const int pos)
{
return mtdData[pos]->size;
}
int CMTDInfo::getMTDEraseSize(const int pos)
{
return mtdData[pos]->erasesize;
}
int CMTDInfo::findMTDNumber(const std::string & filename)
{
for(int x=0;x<getMTDCount();x++)
{
if(filename == getMTDFileName(x))
{
return x;
}
}
return -1;
}
std::string CMTDInfo::getMTDName(const std::string & filename)
{
return getMTDName( findMTDNumber(filename) );
}
int CMTDInfo::getMTDSize( const std::string & filename )
{
return getMTDSize( findMTDNumber(filename) );
}
int CMTDInfo::getMTDEraseSize( const std::string & filename )
{
return getMTDEraseSize( findMTDNumber(filename) );
}

131
src/system/flashtool.h Normal file
View File

@@ -0,0 +1,131 @@
/*
Neutrino-GUI - DBoxII-Project
Copyright (C) 2001 Steffen Hehn 'McClean'
Homepage: http://dbox.cyberphoria.org/
Kommentar:
Diese GUI wurde von Grund auf neu programmiert und sollte nun vom
Aufbau und auch den Ausbaumoeglichkeiten gut aussehen. Neutrino basiert
auf der Client-Server Idee, diese GUI ist also von der direkten DBox-
Steuerung getrennt. Diese wird dann von Daemons uebernommen.
License: GPL
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __flashtool__
#define __flashtool__
#include <gui/widget/progressstatus.h>
#include <string>
#include <vector>
class CFlashTool
{
private:
CProgress_StatusViewer* statusViewer;
std::string mtdDevice;
std::string ErrorMessage;
bool erase(int globalProgressEnd=-1);
public:
CFlashTool();
~CFlashTool();
const std::string & getErrorMessage(void) const;
void setMTDDevice( const std::string & mtddevice );
void setStatusViewer( CProgress_StatusViewer* statusview );
bool program( const std::string & filename, int globalProgressEndErase=-1, int globalProgressEndFlash=-1 );
bool readFromMTD( const std::string & filename, int globalProgressEnd=-1 );
bool check_cramfs( const std::string & filename );
bool check_md5( const std::string & filename, const std::string & smd5);
void reboot();
};
class CFlashVersionInfo
{
private:
char date[11];
char time[6];
char releaseCycle[5];
public:
char snapshot;
CFlashVersionInfo(const std::string & versionString);
const char * const getDate(void) const;
const char * const getTime(void) const;
const char * const getReleaseCycle(void) const;
const char * const getType(void) const;
};
class CMTDInfo
{
private:
struct SMTDPartition
{
int size;
int erasesize;
std::string name;
std::string filename;
};
std::vector<SMTDPartition*> mtdData;
void getPartitionInfo();
CMTDInfo();
~CMTDInfo();
public:
static CMTDInfo* getInstance();
int getMTDCount();
//mtdinfos abfragen (nach mtdnummer)
std::string getMTDName(const int pos );
std::string getMTDFileName(const int pos );
int getMTDSize(const int pos );
int getMTDEraseSize(const int pos );
//mtdinfos abfragen (nach mtd-filename)
std::string getMTDName(const std::string & filename);
int getMTDSize( const std::string & filename );
int getMTDEraseSize( const std::string & filename );
int findMTDNumber(const std::string & filename);
};
#endif

384
src/system/fsmounter.cpp Normal file
View File

@@ -0,0 +1,384 @@
/*
Neutrino-GUI - DBoxII-Project
FSMount/Umount by Zwen
Homepage: http://dbox.cyberphoria.org/
Kommentar:
Diese GUI wurde von Grund auf neu programmiert und sollte nun vom
Aufbau und auch den Ausbaumoeglichkeiten gut aussehen. Neutrino basiert
auf der Client-Server Idee, diese GUI ist also von der direkten DBox-
Steuerung getrennt. Diese wird dann von Daemons uebernommen.
License: GPL
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <system/fsmounter.h>
#include <cstdlib>
#include <fstream>
#include <limits>
#include <global.h>
#include <errno.h>
#include <pthread.h>
#include <sys/mount.h>
#include <unistd.h>
pthread_mutex_t g_mut;
pthread_cond_t g_cond;
pthread_t g_mnt;
int g_mntstatus;
void *mount_thread(void* cmd)
{
int ret;
ret=system((const char *) cmd);
pthread_mutex_lock(&g_mut);
g_mntstatus=ret;
pthread_cond_broadcast(&g_cond);
pthread_mutex_unlock(&g_mut);
pthread_exit(NULL);
}
CFSMounter::CFSMounter()
{
}
bool in_proc_filesystems(const char * const fsname)
{
std::string s;
std::string t;
std::ifstream in("/proc/filesystems", std::ifstream::in);
t = fsname;
while (in >> s)
{
if (s == t)
{
in.close();
return true;
}
}
in.close();
return false;
}
bool insert_modules(const CFSMounter::FSType fstype)
{
if (fstype == CFSMounter::NFS)
{
#ifdef HAVE_MODPROBE
return (system("modprobe nfs") == 0);
#else
return ((system("insmod sunrpc") == 0) && (system("insmod lockd") == 0) && (system("insmod nfs") == 0));
#endif
}
else if (fstype == CFSMounter::CIFS)
return (system("insmod cifs") == 0);
else if (fstype == CFSMounter::LUFS)
return (system("insmod lufs") == 0);
return false;
}
bool nfs_mounted_once = false;
bool remove_modules(const CFSMounter::FSType fstype)
{
if (fstype == CFSMounter::NFS)
{
return ((system("rmmod nfs") == 0) && (system("rmmod lockd") == 0) && (system("rmmod sunrpc") == 0));
}
else if (fstype == CFSMounter::CIFS)
return (system("rmmod cifs") == 0);
else if (fstype == CFSMounter::LUFS)
return (system("rmmod lufs") == 0);
return false;
}
CFSMounter::FS_Support CFSMounter::fsSupported(const CFSMounter::FSType fstype, const bool keep_modules)
{
const char * fsname = NULL;
if (fstype == CFSMounter::NFS)
fsname = "nfs";
else if (fstype == CFSMounter::CIFS)
fsname = "cifs";
else if (fstype == CFSMounter::LUFS)
fsname = "lufs";
if (in_proc_filesystems(fsname))
return CFSMounter::FS_READY;
if (insert_modules(fstype))
{
if (in_proc_filesystems(fsname))
{
if (keep_modules)
{
if (fstype == CFSMounter::NFS)
nfs_mounted_once = true;
}
else
{
remove_modules(fstype);
}
return CFSMounter::FS_NEEDS_MODULES;
}
}
remove_modules(fstype);
return CFSMounter::FS_UNSUPPORTED;
}
bool CFSMounter::isMounted(const char * const local_dir)
{
std::ifstream in;
if (local_dir == NULL)
return false;
// according to the man page realpath() sucks, but there's nothing better :(
int path_max = 0;
#ifdef PATH_MAX
path_max = PATH_MAX;
#else
path_max = 4096;
#endif
char mount_point[path_max];
if (realpath(local_dir, mount_point) == NULL) {
printf("[CFSMounter] could not resolve dir: %s: %s\n",local_dir, strerror(errno));
return false;
}
in.open("/proc/mounts", std::ifstream::in);
while(in.good())
{
MountInfo mi;
in >> mi.device >> mi.mountPoint >> mi.type;
if (strcmp(mi.mountPoint.c_str(),mount_point) == 0)
{
return true;
}
in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
return false;
}
CFSMounter::MountRes CFSMounter::mount(const char * const ip, const char * const dir, const char * const local_dir,
const FSType fstype, const char * const username, const char * const password,
char * options1, char * options2)
{
std::string cmd;
pthread_mutex_init(&g_mut, NULL);
pthread_cond_init(&g_cond, NULL);
g_mntstatus=-1;
FS_Support sup = fsSupported(fstype, true); /* keep modules if necessary */
if (sup == CFSMounter::FS_UNSUPPORTED)
{
printf("[CFSMounter] FS type %d not supported\n", (int) fstype);
return MRES_FS_NOT_SUPPORTED;
}
printf("[CFSMounter] Mount(%d) %s:%s -> %s\n", (int) fstype, ip, dir, local_dir);
if (isMounted(local_dir))
{
printf("[CFSMounter] FS mount error %s already mounted\n", local_dir);
return MRES_FS_ALREADY_MOUNTED;
}
if(options1[0] == '\0')
{
strcpy(options1,options2);
options2[0] = '\0';
}
if((options1[0] == '\0') && (options2[0] == '\0'))
{
if(fstype == NFS)
{
strcpy(options1,"ro,soft,udp");
strcpy(options2,"nolock,rsize=8192,wsize=8192");
}
else if(fstype == CIFS)
{
strcpy(options1,"ro");
strcpy(options2,"");
}
else if(fstype == LUFS)
{
strcpy(options1,"");
strcpy(options2,"");
}
}
if(fstype == NFS)
{
cmd = "mount -t nfs ";
cmd += ip;
cmd += ':';
cmd += dir;
cmd += ' ';
cmd += local_dir;
cmd += " -o ";
cmd += options1;
}
else if(fstype == CIFS)
{
cmd = "mount -t cifs //";
cmd += ip;
cmd += '/';
cmd += dir;
cmd += ' ';
cmd += local_dir;
cmd += " -o username=";
cmd += username;
cmd += ",password=";
cmd += password;
//cmd += ",unc=//"; for whats needed?
//cmd += ip;
//cmd += '/';
//cmd += dir;
//cmd += ',';
//cmd += options1;
}
else
{
cmd = "lufsd none ";
cmd += local_dir;
cmd += " -o fs=ftpfs,username=";
cmd += username;
cmd += ",password=";
cmd += password;
cmd += ",host=";
cmd += ip;
cmd += ",root=/";
cmd += dir;
cmd += ',';
cmd += options1;
}
if (options2[0] !='\0')
{
cmd += ',';
cmd += options2;
}
pthread_create(&g_mnt, 0, mount_thread, (void *) cmd.c_str());
struct timespec timeout;
int retcode;
pthread_mutex_lock(&g_mut);
timeout.tv_sec = time(NULL) + 5;
timeout.tv_nsec = 0;
retcode = pthread_cond_timedwait(&g_cond, &g_mut, &timeout);
if (retcode == ETIMEDOUT)
{ // timeout occurred
pthread_cancel(g_mnt);
}
pthread_mutex_unlock(&g_mut);
pthread_join(g_mnt, NULL);
if ( g_mntstatus != 0 )
{
printf("[CFSMounter] FS mount error: \"%s\"\n", cmd.c_str());
return (retcode == ETIMEDOUT) ? MRES_TIMEOUT : MRES_UNKNOWN;
}
return MRES_OK;
}
bool CFSMounter::automount()
{
bool res = true;
for(int i = 0; i < NETWORK_NFS_NR_OF_ENTRIES; i++)
{
if(g_settings.network_nfs_automount[i])
{
res = (MRES_OK == mount(g_settings.network_nfs_ip[i].c_str(), g_settings.network_nfs_dir[i], g_settings.network_nfs_local_dir[i],
(FSType) g_settings.network_nfs_type[i], g_settings.network_nfs_username[i],
g_settings.network_nfs_password[i], g_settings.network_nfs_mount_options1[i],
g_settings.network_nfs_mount_options2[i])) && res;
}
}
return res;
}
CFSMounter::UMountRes CFSMounter::umount(const char * const dir)
{
UMountRes res = UMRES_OK;
if (dir != NULL)
{
if (umount2(dir, MNT_FORCE) != 0)
{
return UMRES_ERR;
}
}
else
{
MountInfo mi;
std::ifstream in("/proc/mounts", std::ifstream::in);
while(in.good())
{
in >> mi.device >> mi.mountPoint >> mi.type;
in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
if(strcmp(mi.type.c_str(),"nfs")==0 && strcmp(mi.mountPoint.c_str(),"/")==0)
{
if (umount2(mi.mountPoint.c_str(),MNT_FORCE) != 0)
{
printf("[CFSMounter] Error umounting %s\n",mi.device.c_str());
res = UMRES_ERR;
}
}
}
}
if (nfs_mounted_once)
remove_modules(CFSMounter::NFS);
return res;
}
void CFSMounter::getMountedFS(MountInfos& info)
{
std::ifstream in("/proc/mounts", std::ifstream::in);
while(in.good())
{
MountInfo mi;
in >> mi.device >> mi.mountPoint >> mi.type;
in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
if (mi.type == "nfs" ||
mi.type == "cifs" ||
mi.type == "lufs")
{
info.push_back(mi);
printf("[CFSMounter] mounted fs: dev: %s, mp: %s, type: %s\n",
mi.device.c_str(),mi.mountPoint.c_str(),mi.type.c_str());
}
}
}

110
src/system/fsmounter.h Normal file
View File

@@ -0,0 +1,110 @@
/*
Neutrino-GUI - DBoxII-Project
FS Mount/Umount by Zwen
Homepage: http://dbox.cyberphoria.org/
Kommentar:
Diese GUI wurde von Grund auf neu programmiert und sollte nun vom
Aufbau und auch den Ausbaumoeglichkeiten gut aussehen. Neutrino basiert
auf der Client-Server Idee, diese GUI ist also von der direkten DBox-
Steuerung getrennt. Diese wird dann von Daemons uebernommen.
License: GPL
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __neutrino_fs_mounter__
#define __neutrino_fs_mounter__
#include <system/settings.h>
#include <vector>
class CFSMounter
{
// protected
public:
enum FS_Support
{
FS_UNSUPPORTED = 0,
FS_READY = 1,
FS_NEEDS_MODULES = 2,
FS_UNPROBED = 3
};
public:
enum FSType
{
NFS = 0,
CIFS = 1,
LUFS = 2
};
enum MountRes
{
MRES_FS_NOT_SUPPORTED = 0,
MRES_FS_ALREADY_MOUNTED = 1,
MRES_TIMEOUT = 2,
MRES_UNKNOWN = 3,
MRES_OK = 4
};
enum UMountRes
{
UMRES_ERR = 0,
UMRES_OK = 1
};
struct MountInfo
{
std::string device;
std::string mountPoint;
std::string type;
};
typedef std::vector<CFSMounter::MountInfo> MountInfos;
private:
/*
FS_Support m_nfs_sup;
FS_Support m_cifs_sup;
FS_Support m_lufs_sup;
*/
public:
CFSMounter();
static bool isMounted(const char * const local_dir);
static CFSMounter::MountRes mount(const char * const ip, const char * const dir, const char * const local_dir,
const FSType fstype, const char * const username, const char * const password,
char * options1, char * options2);
static bool automount();
static CFSMounter::UMountRes umount(const char * const dir = NULL);
static void getMountedFS(MountInfos& fs);
static FS_Support fsSupported(const FSType fs, const bool keep_modules = false);
};
bool in_proc_filesystems(const char * const fsname);
bool insert_modules(const CFSMounter::FSType fstype);
bool remove_modules(const CFSMounter::FSType fstype);
extern bool nfs_mounted_once; /* needed by update.cpp to prevent removal of modules after flashing a new cramfs, since rmmod (busybox) might no longer be available */
#endif

128
src/system/httptool.cpp Normal file
View File

@@ -0,0 +1,128 @@
/*
Neutrino-GUI - DBoxII-Project
License: GPL
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA
*/
#include <system/httptool.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
#include <global.h>
CHTTPTool::CHTTPTool()
{
statusViewer = NULL;
userAgent = "neutrino/httpdownloader";
}
void CHTTPTool::setStatusViewer( CProgress_StatusViewer* statusview )
{
statusViewer = statusview;
}
int CHTTPTool::show_progress( void *clientp, double dltotal, double dlnow, double ultotal, double ulnow )
{
CHTTPTool* hTool = ((CHTTPTool*)clientp);
if(hTool->statusViewer)
{
int progress = int( dlnow*100.0/dltotal);
hTool->statusViewer->showLocalStatus(progress);
if(hTool->iGlobalProgressEnd!=-1)
{
int globalProg = hTool->iGlobalProgressBegin + int((hTool->iGlobalProgressEnd-hTool->iGlobalProgressBegin) * progress/100. );
hTool->statusViewer->showGlobalStatus(globalProg);
}
}
return 0;
}
//#define DEBUG
bool CHTTPTool::downloadFile(const std::string & URL, const char * const downloadTarget, int globalProgressEnd)
{
CURL *curl;
CURLcode res;
FILE *headerfile;
#ifdef DEBUG
printf("open file %s\n", downloadTarget);
#endif
headerfile = fopen(downloadTarget, "w");
if (!headerfile)
return false;
#ifdef DEBUG
printf("open file ok\n");
printf("url is %s\n", URL.c_str());
#endif
res = (CURLcode) 1;
curl = curl_easy_init();
if(curl)
{
iGlobalProgressEnd = globalProgressEnd;
if(statusViewer)
{
iGlobalProgressBegin = statusViewer->getGlobalStatus();
}
curl_easy_setopt(curl, CURLOPT_URL, URL.c_str() );
curl_easy_setopt(curl, CURLOPT_FILE, headerfile);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, show_progress);
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, this);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgent.c_str());
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, (long)1);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 1800);
#ifdef DEBUG
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
#endif
if(strcmp(g_settings.softupdate_proxyserver, "")!=0)
{//use proxyserver
#ifdef DEBUG
printf("use proxyserver : %s\n", g_settings.softupdate_proxyserver);
#endif
curl_easy_setopt(curl, CURLOPT_PROXY, g_settings.softupdate_proxyserver);
if(strcmp(g_settings.softupdate_proxyusername,"")!=0)
{//use auth
//printf("use proxyauth\n");
char tmp[200];
strcpy(tmp, g_settings.softupdate_proxyusername);
strcat(tmp, ":");
strcat(tmp, g_settings.softupdate_proxypassword);
curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, tmp);
}
}
#ifdef DEBUG
printf("going to download\n");
#endif
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
#ifdef DEBUG
printf("download code %d\n", res);
#endif
if (headerfile)
{
fflush(headerfile);
fclose(headerfile);
}
return res==0;
}

59
src/system/httptool.h Normal file
View File

@@ -0,0 +1,59 @@
/*
Neutrino-GUI - DBoxII-Project
Copyright (C) 2001 Steffen Hehn 'McClean'
Homepage: http://dbox.cyberphoria.org/
Kommentar:
Diese GUI wurde von Grund auf neu programmiert und sollte nun vom
Aufbau und auch den Ausbaumoeglichkeiten gut aussehen. Neutrino basiert
auf der Client-Server Idee, diese GUI ist also von der direkten DBox-
Steuerung getrennt. Diese wird dann von Daemons uebernommen.
License: GPL
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __httptool__
#define __httptool__
#include <gui/widget/progressstatus.h>
#include <string>
class CHTTPTool
{
private:
std::string userAgent;
int iGlobalProgressEnd;
int iGlobalProgressBegin;
CProgress_StatusViewer* statusViewer;
static int show_progress( void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
public:
CHTTPTool();
void setStatusViewer( CProgress_StatusViewer* statusview );
bool downloadFile( const std::string & URL, const char * const downloadTarget, int globalProgressEnd=-1 );
};
#endif

150
src/system/lastchannel.cpp Normal file
View File

@@ -0,0 +1,150 @@
/*
DBOX2 -- Projekt
(c) 2001 rasc Lizenz: GPL
Lastchannel History buffer
Einfache Klasse fuer schnelles Zappen zum letzten Kanal.
Ggf. laesst sich damit ein kleines ChannelHistory-Menue aufbauen-
Das ganze ist als sich selbst ueberschreibender Ringpuffer realisiert,
welcher nach dem LIFO-prinzip wieder ausgelesen wird.
Es wird aber gecheckt, ob ein Neuer Wert ein Mindestzeitabstand zum alten
vorherigen Wert hat, damit bei schnellem Hochzappen, die "Skipped Channels"
nicht gespeichert werden.
*/
#include <sys/time.h>
#include <unistd.h>
#include "lastchannel.h"
// // -- Init Class Contructor //
CLastChannel::CLastChannel (void)
: secs_diff_before_store(3)
, maxSize(11)
, shallRemoveEqualChannel(true)
{
}
// // -- Clear the last channel buffer //
void CLastChannel::clear (void)
{
this->lastChannels.clear();
}
// -- Store a channelnumber in Buffer
// -- Store only if channel != last channel...
// -- and time store delay is large enough
void CLastChannel::store (int channel, t_channel_id channel_id, bool forceStoreToLastChannels)
{
struct timeval tv;
gettimeofday (&tv, NULL);
int lastChannel(-1);
t_channel_id lastChannel_id(0);
unsigned long lastTimestamp(0);
if (!this->lastChannels.empty())
{
lastChannel = this->lastChannels.front().channel;
lastChannel_id = this->lastChannels.front().channel_id;
lastTimestamp = this->lastChannels.front().timestamp;
}
if (((forceStoreToLastChannels || (tv.tv_sec - lastTimestamp) > secs_diff_before_store))
&& (lastChannel != channel) )
{
if (this->shallRemoveEqualChannel && (this->lastChannels.size() > 1))
{
std::list<_LastCh>::iterator It = this->lastChannels.begin();
++It;
for (; It != this->lastChannels.end() ; ++It) {
if (lastChannel_id == It->channel_id) {
this->lastChannels.erase(It);
break;
}
}
}
// -- store channel on next pos (new channel)
_LastCh newChannel = {channel, channel_id, tv.tv_sec};
this->lastChannels.push_front(newChannel);
if (this->lastChannels.size() > this->maxSize)
{
this->lastChannels.pop_back();
}
}
// -- remember time (secs)
if (!this->lastChannels.empty())
{
this->lastChannels.front().channel = channel;
this->lastChannels.front().channel_id = channel_id;
this->lastChannels.front().timestamp = tv.tv_sec;
}
}
unsigned int CLastChannel::size () const
{
return this->lastChannels.size();
}
//
// -- Clear store time delay
// -- means: set last time stamp to zero
// -- means: store next channel with "store" always
//
void CLastChannel::clear_storedelay (void)
{
if (!this->lastChannels.empty())
{
this->lastChannels.front().timestamp = 0;
}
}
//
// -- Get last Channel-Entry
// -- IN: n number of last channel in queue [0..]
// -- 0 = current channel
// -- Return: channelnumber or <0 (end of list)
t_channel_id CLastChannel::getlast (int n)
{
if ( (n < int(this->lastChannels.size()))
&&(n > -1)
&&(!this->lastChannels.empty())
)
{
std::list<_LastCh>::const_iterator It = this->lastChannels.begin();
std::advance(It, n);
//return It->channel;
return It->channel_id;
}
//return -1;
return 0;
}
//
// -- set delaytime in secs, for accepting a new value
// -- get returns the value
//
void CLastChannel::set_store_difftime (int secs)
{
secs_diff_before_store = secs;
}
int CLastChannel::get_store_difftime (void) const
{
return secs_diff_before_store;
}

58
src/system/lastchannel.h Normal file
View File

@@ -0,0 +1,58 @@
/*
DBoX2 -- Projekt
(c) 2001 rasc
Lizenz: GPL
Lastchannel History buffer
Einfache Klasse fuer schnelles Zappen zum letzten Kanal.
Ggf. laesst sich damit ein kleines ChannelHistory-Menue aufbauen-
Das ganze ist als sich selbst ueberschreibender Ringpuffer realisiert,
welcher nach dem LIFO-prinzip wieder ausgelesen wird.
Es wird aber gecheckt, ob ein Neuer Wert ein Mindestzeitabstand zum alten
vorherigen Wert hat, damit bei schnellem Hochzappen, die "Skipped Channels"
nicht gespeichert werden.
*/
#ifndef SEEN_LastChannel
#define SEEN_LastChannel
#include <zapit/client/zapitclient.h>
#include <list>
class CLastChannel
{
private:
struct _LastCh
{
int channel;
unsigned long timestamp;
t_channel_id channel_id;
};
std::list<_LastCh> lastChannels;
unsigned long secs_diff_before_store;
unsigned int maxSize;
bool shallRemoveEqualChannel;
public:
CLastChannel (void);
void clear (void);
void store (int channelnr, t_channel_id channel_id, bool forceStoreToLastChannels = false);
t_channel_id getlast (int n);
unsigned int size () const;
void clear_storedelay (void);
void set_store_difftime (int secs);
int get_store_difftime (void) const;
};
#endif

350
src/system/localize.cpp Normal file
View File

@@ -0,0 +1,350 @@
/*
Neutrino-GUI - DBoxII-Project
Copyright (C) 2001 Steffen Hehn 'McClean'
Homepage: http://dbox.cyberphoria.org/
Kommentar:
Diese GUI wurde von Grund auf neu programmiert und sollte nun vom
Aufbau und auch den Ausbaumoeglichkeiten gut aussehen. Neutrino basiert
auf der Client-Server Idee, diese GUI ist also von der direkten DBox-
Steuerung getrennt. Diese wird dann von Daemons uebernommen.
License: GPL
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <system/localize.h>
#include <system/locals_intern.h>
#include <cstring>
#include <fstream>
#include <string>
//static const char * iso639filename = "/usr/share/iso-codes/iso-639.tab";
static const char * iso639filename = "/share/iso-codes/iso-639.tab";
#if 1
#include <stdlib.h>
#include <stdio.h>
#define ISO639_TABLE_SIZE 489
typedef struct
{
char * iso_639_2_code;
char * name;
} iso639_t;
iso639_t iso639[ISO639_TABLE_SIZE];
int mycompare(const void * a, const void * b)
{
return strcmp(((iso639_t *)a)->iso_639_2_code, ((iso639_t *)b)->iso_639_2_code);
}
void initialize_iso639_map(void)
{
unsigned i = 0;
std::string s, t, v;
std::ifstream in(iso639filename);
if (in.is_open())
{
while (in.peek() == '#')
getline(in, s);
while (in >> s >> t >> v >> std::ws)
{
getline(in, v);
if (i == ISO639_TABLE_SIZE)
{
printf("ISO639 table overflow\n");
goto do_sorting;
}
iso639[i].iso_639_2_code = strdup(s.c_str());
iso639[i].name = strdup(v.c_str());
i++;
if (s != t)
{
if (i == ISO639_TABLE_SIZE)
{
printf("ISO639 table overflow\n");
goto do_sorting;
}
iso639[i].iso_639_2_code = strdup(t.c_str());
// iso639[i].name = strdup(v.c_str());
iso639[i].name = iso639[i - 1].name;
i++;
}
}
if (i != ISO639_TABLE_SIZE)
{
printf("ISO639 table underflow\n");
while(i < ISO639_TABLE_SIZE)
{
iso639[i].iso_639_2_code = iso639[i].name = (char *)iso639filename; // fill with junk
i++;
}
}
do_sorting:
qsort(iso639, ISO639_TABLE_SIZE, sizeof(iso639_t), mycompare);
}
else
printf("Loading %s failed.\n", iso639filename);
}
const char * getISO639Description(const char * const iso)
{
iso639_t tmp;
tmp.iso_639_2_code = (char *)iso;
void * value = bsearch(&tmp, iso639, ISO639_TABLE_SIZE, sizeof(iso639_t), mycompare);
if (value == NULL)
return iso;
else
return ((iso639_t *)value)->name;
}
#else
#include <iostream>
#include <map>
static std::map<std::string, std::string> iso639;
void initialize_iso639_map(void)
{
std::string s, t, u, v;
std::ifstream in(iso639filename);
if (in.is_open())
{
while (in.peek() == '#')
getline(in, s);
while (in >> s >> t >> u >> std::ws)
{
getline(in, v);
iso639[s] = v;
if (s != t)
iso639[t] = v;
}
}
else
std::cout << "Loading " << iso639filename << " failed." << std::endl;
}
const char * getISO639Description(const char * const iso)
{
std::map<std::string, std::string>::const_iterator it = iso639.find(std::string(iso));
if (it == iso639.end())
return iso;
else
return it->second.c_str();
}
#endif
CLocaleManager::CLocaleManager()
{
localeData = new char * [sizeof(locale_real_names)/sizeof(const char *)];
for (unsigned int i = 0; i < (sizeof(locale_real_names)/sizeof(const char *)); i++)
localeData[i] = (char *)locale_real_names[i];
}
CLocaleManager::~CLocaleManager()
{
for (unsigned j = 0; j < (sizeof(locale_real_names)/sizeof(const char *)); j++)
if (localeData[j] != locale_real_names[j])
free(localeData[j]);
delete localeData;
}
const char * path[2] = {"/var/tuxbox/config/locale/", DATADIR "/neutrino/locale/"};
CLocaleManager::loadLocale_ret_t CLocaleManager::loadLocale(const char * const locale)
{
unsigned int i;
FILE * fd;
initialize_iso639_map();
for (i = 0; i < 2; i++)
{
std::string filename = path[i];
filename += locale;
filename += ".locale";
fd = fopen(filename.c_str(), "r");
if (fd)
break;
}
if (i == 2)
{
perror("cannot read locale");
return NO_SUCH_LOCALE;
}
for (unsigned j = 0; j < (sizeof(locale_real_names)/sizeof(const char *)); j++)
if (localeData[j] != locale_real_names[j])
{
free(localeData[j]);
localeData[j] = (char *)locale_real_names[j];
}
char buf[1000];
i = 1;
while(!feof(fd))
{
if(fgets(buf,sizeof(buf),fd)!=NULL)
{
char * val = NULL;
char * tmpptr = buf;
for(; (*tmpptr!=10) && (*tmpptr!=13);tmpptr++)
{
if ((*tmpptr == ' ') && (val == NULL))
{
*tmpptr = 0;
val = tmpptr + 1;
}
}
*tmpptr = 0;
if (val == NULL)
continue;
std::string text = val;
int pos;
do
{
pos = text.find("\\n");
if ( pos!=-1 )
{
text.replace(pos, 2, "\n", 1);
}
} while ( ( pos != -1 ) );
for(i = 1; i < sizeof(locale_real_names)/sizeof(const char *); i++)
{
//printf("[%s] [%s]\n", buf,locale_real_names[i]);
if(!strcmp(buf,locale_real_names[i]))
{
if(localeData[i] == locale_real_names[i])
localeData[i] = strdup(text.c_str());
else
printf("[%s.locale] dup entry: %s\n", locale, locale_real_names[i]);
break;
}
}
// printf("i=%d\n", i);
if(i == sizeof(locale_real_names)/sizeof(const char *))
printf("[%s.locale] superfluous entry: %s\n", locale, buf);
#if 0
while (1)
{
j = (i >= (sizeof(locale_real_names)/sizeof(const char *))) ? -1 : strcmp(buf, locale_real_names[i]);
if (j > 0)
{
printf("[%s.locale] missing entry: %s\n", locale, locale_real_names[i]);
i++;
}
else
break;
}
if (j == 0)
{
localeData[i] = strdup(text.c_str());
i++;
}
else
{
printf("[%s.locale] superfluous entry: %s\n", locale, buf);
}
#endif
}
}
fclose(fd);
for (unsigned j = 1; j < (sizeof(locale_real_names)/sizeof(const char *)); j++)
if (localeData[j] == locale_real_names[j])
{
printf("[%s.locale] missing entry: %s\n", locale, locale_real_names[j]);
}
return (
(strcmp(locale, "bosanski") == 0) ||
(strcmp(locale, "ellinika") == 0) ||
(strcmp(locale, "russkij") == 0) ||
(strcmp(locale, "utf8") == 0)
/* utf8.locale is a generic name that can be used for new locales which need characters outside the ISO-8859-1 character set */
) ? UNICODE_FONT : ISO_8859_1_FONT;
}
const char * CLocaleManager::getText(const neutrino_locale_t keyName) const
{
return localeData[keyName];
}
static const neutrino_locale_t locale_weekday[7] =
{
LOCALE_DATE_SUN,
LOCALE_DATE_MON,
LOCALE_DATE_TUE,
LOCALE_DATE_WED,
LOCALE_DATE_THU,
LOCALE_DATE_FRI,
LOCALE_DATE_SAT
};
static const neutrino_locale_t locale_month[12] =
{
LOCALE_DATE_JAN,
LOCALE_DATE_FEB,
LOCALE_DATE_MAR,
LOCALE_DATE_APR,
LOCALE_DATE_MAY,
LOCALE_DATE_JUN,
LOCALE_DATE_JUL,
LOCALE_DATE_AUG,
LOCALE_DATE_SEP,
LOCALE_DATE_OCT,
LOCALE_DATE_NOV,
LOCALE_DATE_DEC
};
neutrino_locale_t CLocaleManager::getMonth(const struct tm * struct_tm_p)
{
return locale_month[struct_tm_p->tm_mon];
}
neutrino_locale_t CLocaleManager::getWeekday(const struct tm * struct_tm_p)
{
return locale_weekday[struct_tm_p->tm_wday];
}

67
src/system/localize.h Normal file
View File

@@ -0,0 +1,67 @@
/*
Neutrino-GUI - DBoxII-Project
Copyright (C) 2001 Steffen Hehn 'McClean'
Homepage: http://dbox.cyberphoria.org/
Kommentar:
Diese GUI wurde von Grund auf neu programmiert und sollte nun vom
Aufbau und auch den Ausbaumoeglichkeiten gut aussehen. Neutrino basiert
auf der Client-Server Idee, diese GUI ist also von der direkten DBox-
Steuerung getrennt. Diese wird dann von Daemons uebernommen.
License: GPL
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __locale__
#define __locale__
#include <system/locals.h>
#include_next<locale.h>
#include <time.h>
const char * getISO639Description(const char * const iso);
#define ARE_LOCALES_EQUAL(a,b) (a == b)
class CLocaleManager
{
private:
char * * localeData;
public:
enum loadLocale_ret_t
{
ISO_8859_1_FONT = 0,
UNICODE_FONT = 1,
NO_SUCH_LOCALE = -1
};
CLocaleManager();
~CLocaleManager();
loadLocale_ret_t loadLocale(const char * const locale);
const char * getText(const neutrino_locale_t keyName) const;
static neutrino_locale_t getMonth (const struct tm * struct_tm_p);
static neutrino_locale_t getWeekday(const struct tm * struct_tm_p);
};
#endif

1357
src/system/locals.h Normal file

File diff suppressed because it is too large Load Diff

1356
src/system/locals_intern.h Normal file

File diff suppressed because it is too large Load Diff

118
src/system/ping-config.h Normal file
View File

@@ -0,0 +1,118 @@
/* include/config.h. Generated automatically by configure. */
/* include/config.h.in. Generated automatically from configure.in by autoheader. */
/* Define if on AIX 3.
System headers sometimes define this.
We just want to avoid a redefinition error message. */
#ifndef _ALL_SOURCE
/* #undef _ALL_SOURCE */
#endif
/* Define to empty if the keyword does not work. */
/* #undef const */
/* Define to `unsigned' if <sys/types.h> doesn't define. */
/* #undef size_t */
/* Define if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define if you can safely include both <sys/time.h> and <time.h>. */
#define TIME_WITH_SYS_TIME 1
/* Define if on AIX 3.
System headers sometimes define this.
We just want to avoid a redefinition error message. */
#ifndef _ALL_SOURCE
/* #undef _ALL_SOURCE */
#endif
/* Define to empty if the keyword does not work. */
/* #undef const */
/* Define to `unsigned' if <sys/types.h> doesn't define. */
/* #undef size_t */
/* Define if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define if you can safely include both <sys/time.h> and <time.h>. */
#define TIME_WITH_SYS_TIME 1
/* Define debugging */
/* #undef DEBUG */
/* Define if openssl should be used for https support */
#define HAVE_SSL 1
/* Define if you have the gethostbyname function. */
#define HAVE_GETHOSTBYNAME 1
/* Define if you have the memcpy function. */
#define HAVE_MEMCPY 1
/* Define if you have the socket function. */
#define HAVE_SOCKET 1
/* Define if you have the strcasecmp function. */
#define HAVE_STRCASECMP 1
/* Define if you have the strchr function. */
#define HAVE_STRCHR 1
/* Define if you have the strcmp function. */
#define HAVE_STRCMP 1
/* Define if you have the strlen function. */
#define HAVE_STRLEN 1
/* Define if you have the strncasecmp function. */
#define HAVE_STRNCASECMP 1
/* Define if you have the strncmp function. */
#define HAVE_STRNCMP 1
/* Define if you have the strncpy function. */
#define HAVE_STRNCPY 1
/* Define if you have the strstr function. */
#define HAVE_STRSTR 1
/* Define if you have the <arpa/inet.h> header file. */
#define HAVE_ARPA_INET_H 1
/* Define if you have the <netdb.h> header file. */
#define HAVE_NETDB_H 1
/* Define if you have the <netinet/in.h> header file. */
#define HAVE_NETINET_IN_H 1
/* Define if you have the <netinet/in_systm.h> header file. */
#define HAVE_NETINET_IN_SYSTM_H 1
/* Define if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define if you have the <sys/socket.h> header file. */
#define HAVE_SYS_SOCKET_H 1
/* Define if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
/* Define if you have the <sys/times.h> header file. */
#define HAVE_SYS_TIMES_H 1
/* Define if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Define if you have the resolv library (-lresolv). */
#define HAVE_LIBRESOLV 1
/* Define if you have the socket library (-lsocket). */
/* #undef HAVE_LIBSOCKET */
/* Name of package */
#define PACKAGE "libping"
/* Version number of package */
#define VERSION "1.14"

67
src/system/ping-linux.h Normal file
View File

@@ -0,0 +1,67 @@
#define ICMP_ECHOREPLY 0
#define ICMP_ECHO 8
#define ICMP_MINLEN 8
struct ip {
#if (BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN)
u_char ip_hl:4, /* header length */
ip_v:4; /* version */
#else
u_char ip_v:4, /* version */
ip_hl:4; /* header length */
#endif
u_char ip_tos; /* type of service */
short ip_len; /* total length */
u_short ip_id; /* identification */
short ip_off; /* fragment offset field */
#define IP_DF 0x4000 /* dont fragment flag */
#define IP_MF 0x2000 /* more fragments flag */
u_char ip_ttl; /* time to live */
u_char ip_p; /* protocol */
u_short ip_sum; /* checksum */
struct in_addr ip_src,ip_dst; /* source and dest address */
};
#define n_short u_short /* normally defined in in_systm.h */
#define n_long u_int /* redefine for 64-bit machines */
#define n_time u_int /* redefine for 64-bit machines */
struct icmp {
u_char icmp_type; /* type of message, see below */
u_char icmp_code; /* type sub code */
u_short icmp_cksum; /* ones complement cksum of struct */
union {
u_char ih_pptr; /* ICMP_PARAMPROB */
struct in_addr ih_gwaddr; /* ICMP_REDIRECT */
struct ih_idseq {
n_short icd_id;
n_short icd_seq;
} ih_idseq;
int ih_void;
} icmp_hun;
#define icmp_pptr icmp_hun.ih_pptr
#define icmp_gwaddr icmp_hun.ih_gwaddr
#define icmp_id icmp_hun.ih_idseq.icd_id
#define icmp_seq icmp_hun.ih_idseq.icd_seq
#define icmp_void icmp_hun.ih_void
union {
struct id_ts {
n_time its_otime;
n_time its_rtime;
n_time its_ttime;
} id_ts;
struct id_ip {
struct ip idi_ip;
/* options and then 64 bits of data */
} id_ip;
n_long id_mask;
char id_data[1];
} icmp_dun;
#define icmp_otime icmp_dun.id_ts.its_otime
#define icmp_rtime icmp_dun.id_ts.its_rtime
#define icmp_ttime icmp_dun.id_ts.its_ttime
#define icmp_ip icmp_dun.id_ip.idi_ip
#define icmp_mask icmp_dun.id_mask
#define icmp_data icmp_dun.id_data
};

271
src/system/ping.c Normal file
View File

@@ -0,0 +1,271 @@
/**
* PING module
*
* Copyright (C) 2001 Jeffrey Fulmer <jdfulmer@armstrong.com>
* This file is part of LIBPING
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include "ping.h"
#ifndef EXIT_SUCCESS
# define EXIT_SUCCESS 0
#endif /*EXIT_SUCCESS*/
#ifndef EXIT_FAILURE
# define EXIT_FAILURE 1
#endif /*EXIT_FAILURE*/
#define MAXPACKET 65535
#define PKTSIZE 64
#define HDRLEN ICMP_MINLEN
#define DATALEN (PKTSIZE-HDRLEN)
#define MAXDATA (MAXPKT-HDRLEN-TIMLEN)
#define DEF_TIMEOUT 5
int ident = 0;
int timo = 2;
int rrt;
int sock;
int
in_checksum( u_short *buf, int len )
{
register long sum = 0;
u_short answer = 0;
while( len > 1 ){
sum += *buf++;
len -= 2;
}
if( len == 1 ){
*( u_char* )( &answer ) = *( u_char* )buf;
sum += answer;
}
sum = ( sum >> 16 ) + ( sum & 0xffff );
sum += ( sum >> 16 );
answer = ~sum;
return ( answer );
}
int
send_ping( const char *host, struct sockaddr_in *taddr )
{
int len;
int ss;
unsigned char buf[ HDRLEN + DATALEN ];
struct protoent *proto;
struct hostent *hp;
struct icmp *icp;
unsigned short last;
len = HDRLEN + DATALEN;
if(( proto = getprotobyname( "icmp" )) == NULL ){
return -1;
}
if(( hp = gethostbyname( host )) != NULL ){
memcpy( &taddr->sin_addr, hp->h_addr_list[0], sizeof( taddr->sin_addr ));
taddr->sin_port = 0;
taddr->sin_family = AF_INET;
}
else if( inet_aton( host, &taddr->sin_addr ) == 0 ){
return -1;
}
last = ntohl( taddr->sin_addr.s_addr ) & 0xFF;
if(( last == 0x00 ) || ( last == 0xFF )){
return -1;
}
if(( sock = socket( AF_INET, SOCK_RAW, proto->p_proto )) < 0 ){
#ifdef DEBUG
perror( "sock" );
#endif/*DEBUG*/
return -2;
}
icp = (struct icmp *)buf;
icp->icmp_type = ICMP_ECHO;
icp->icmp_code = 0;
icp->icmp_cksum = 0;
icp->icmp_id = getpid() & 0xFFFF;
icp->icmp_cksum = in_checksum((u_short *)icp, len );
if(( ss = sendto( sock, buf, sizeof( buf ), 0,
(struct sockaddr*)taddr, sizeof( *taddr ))) < 0 ){
#ifdef DEBUG
perror( "sock" );
#endif/*DEBUG*/
close( sock );
return -2;
}
if( ss != len ){
#ifdef DEBUG
perror( "malformed packet" );
#endif/*DEBUG*/
close( sock );
return -2;
}
return 0;
}
int
recv_ping( struct sockaddr_in *taddr )
{
int len;
socklen_t from;
int nf, cc;
unsigned char buf[ HDRLEN + DATALEN ];
struct icmp *icp;
struct sockaddr_in faddr;
struct timeval to;
fd_set readset, writeset;
to.tv_sec = timo / 100000;
to.tv_usec = ( timo - ( to.tv_sec * 100000 ) ) * 10;
FD_ZERO( &readset );
FD_ZERO( &writeset );
FD_SET( sock, &readset );
/* we use select to see if there is any activity
on the socket. If not, then we've requested an
unreachable network and we'll time out here. */
if(( nf = select( sock + 1, &readset, &writeset, NULL, &to )) < 0 ){
#ifdef DEBUG
perror( "select" );
#endif/*DEBUG*/
exit( EXIT_FAILURE );
}
if( nf == 0 ){
return -1;
}
len = HDRLEN + DATALEN;
from = sizeof( faddr );
cc = recvfrom( sock, buf, len, 0, (struct sockaddr*)&faddr, &from );
if( cc < 0 ){
exit( EXIT_FAILURE );
}
icp = (struct icmp *)(buf + HDRLEN + DATALEN );
if( faddr.sin_addr.s_addr != taddr->sin_addr.s_addr ){
return 1;
}
/*****
if( icp->icmp_id != ( getpid() & 0xFFFF )){
printf( "id: %d\n", icp->icmp_id );
return 1;
}
*****/
return 0;
}
/**
* elapsed_time
* returns an int value for the difference
* between now and starttime in milliseconds.
*/
int
elapsed_time( struct timeval *starttime ){
struct timeval *newtime;
int elapsed;
newtime = (struct timeval*)malloc( sizeof(struct timeval));
gettimeofday(newtime,NULL);
elapsed = 0;
if(( newtime->tv_usec - starttime->tv_usec) > 0 ){
elapsed += (newtime->tv_usec - starttime->tv_usec)/1000 ;
}
else{
elapsed += ( 1000000 + newtime->tv_usec - starttime->tv_usec ) /1000;
newtime->tv_sec--;
}
if(( newtime->tv_sec - starttime->tv_sec ) > 0 ){
elapsed += 1000 * ( newtime->tv_sec - starttime->tv_sec );
}
free(newtime);
return( elapsed );
}
int
myping( const char *hostname, int t )
{
int err;
struct sockaddr_in sa;
struct timeval mytime;
ident = getpid() & 0xFFFF;
if( t == 0 ) timo = 2;
else timo = t;
(void) gettimeofday( &mytime, (struct timezone *)NULL);
if(( err = send_ping( hostname, &sa )) < 0 ){
return err;
}
do{
if(( rrt = elapsed_time( &mytime )) > timo * 1000 ){
close( sock );
return 0;
}
} while( recv_ping( &sa ));
close( sock );
return 1;
}
int
pinghost( const char *hostname )
{
return myping( hostname, 0 );
}
int
pingthost( const char *hostname, int t )
{
return myping( hostname, t );
}
int
tpinghost( const char *hostname )
{
int ret;
if(( ret = myping( hostname, 0 )) > 0 )
return rrt;
else
return ret;
}
int
tpingthost( const char *hostname, int t )
{
int ret;
if(( ret = myping( hostname, t )) > 0 )
return rrt;
else
return ret;
}

86
src/system/ping.h Normal file
View File

@@ -0,0 +1,86 @@
/**
* PING header
*
* Copyright (C) 2001 Jeffrey Fulmer <jdfulmer@armstrong.com>
* This file is part of LIBPING
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef PING_H
#define PING_H
#include <stdio.h>
#include "ping-config.h"
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif/*HAVE_UNISTD_H*/
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif/*HAVE_STDLIB_H*/
#ifdef HAVE_SYS_TIMES_H
# include <sys/times.h>
#endif /*HAVE_SYS_TIMES_H*/
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# if HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#endif /*TIME_WITH_SYS_TIME*/
#include <string.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif/*HAVE_SYS_SOCKET_H*/
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif/*HAVE_ARPA_INET_H*/
#ifdef HAVE_NETDB_H
# include <netdb.h>
#endif/*HAVE_NETDB_H*/
#if defined( __linux__ )
# include "ping-linux.h"
#else
# include <netinet/ip.h>
# include <netinet/ip_icmp.h>
#endif /* defined(__linux__) */
int send_ping( const char *host, struct sockaddr_in *taddr );
int recv_ping( struct sockaddr_in *taddr );
int pinghost ( const char *hostname );
int pingthost ( const char *hostname, int t );
int tpinghost ( const char *hostname );
int tpingthost( const char *hostname, int t );
#endif/*PING_H*/

View File

@@ -0,0 +1,966 @@
/*
Neutrino-GUI - DBoxII-Project
Copyright (C) 2001 Steffen Hehn 'McClean'
Homepage: http://dbox.cyberphoria.org/
Kommentar:
Diese GUI wurde von Grund auf neu programmiert und sollte nun vom
Aufbau und auch den Ausbaumoeglichkeiten gut aussehen. Neutrino basiert
auf der Client-Server Idee, diese GUI ist also von der direkten DBox-
Steuerung getrennt. Diese wird dann von Daemons uebernommen.
License: GPL
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <system/setting_helpers.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include "libnet.h"
#include <coolstream/control.h>
#include <config.h>
#include <global.h>
#include <neutrino.h>
#include <gui/widget/stringinput.h>
// obsolete #include <gui/streaminfo.h>
#include <gui/widget/messagebox.h>
#include <gui/widget/hintbox.h>
#include <gui/plugins.h>
#include <daemonc/remotecontrol.h>
#include <xmlinterface.h>
#include <audio_cs.h>
#include <video_cs.h>
#include <dmx_cs.h>
#include <pwrmngr.h>
extern CPlugins * g_PluginList; /* neutrino.cpp */
extern CRemoteControl * g_RemoteControl; /* neutrino.cpp */
extern cVideo *videoDecoder;
extern cAudio *audioDecoder;
extern cDemux *videoDemux;
extern cDemux *audioDemux;
extern cDemux *pcrDemux;
extern "C" int pinghost( const char *hostname );
CSatelliteSetupNotifier::CSatelliteSetupNotifier()
{
}
/* items1 enabled for advanced diseqc settings, items2 for diseqc != NO_DISEQC, items3 disabled for NO_DISEQC */
bool CSatelliteSetupNotifier::changeNotify(const neutrino_locale_t, void * Data)
{
std::vector<CMenuItem*>::iterator it;
int type = *((int*) Data);
if (type == NO_DISEQC) {
for(it = items1.begin(); it != items1.end(); it++) {
//(*it)->init(-1, 0, 0, 0);
(*it)->setActive(false);
}
for(it = items2.begin(); it != items2.end(); it++) {
//(*it)->init(-1, 0, 0, 0);
(*it)->setActive(false);
}
for(it = items3.begin(); it != items3.end(); it++) {
//(*it)->init(-1, 0, 0, 0);
(*it)->setActive(false);
}
}
else if(type < DISEQC_ADVANCED) {
for(it = items1.begin(); it != items1.end(); it++) {
//(*it)->init(-1, 0, 0, 0);
(*it)->setActive(false);
}
for(it = items2.begin(); it != items2.end(); it++) {
//(*it)->init(-1, 0, 0, 0);
(*it)->setActive(true);
}
for(it = items3.begin(); it != items3.end(); it++) {
//(*it)->init(-1, 0, 0, 0);
(*it)->setActive(true);
}
}
else if(type == DISEQC_ADVANCED) {
for(it = items1.begin(); it != items1.end(); it++) {
//(*it)->init(-1, 0, 0, 0);
(*it)->setActive(true);
}
for(it = items2.begin(); it != items2.end(); it++) {
//(*it)->init(-1, 0, 0, 0);
(*it)->setActive(false);
}
for(it = items3.begin(); it != items3.end(); it++) {
//(*it)->init(-1, 0, 0, 0);
(*it)->setActive(true);
}
}
g_Zapit->setDiseqcType((diseqc_t) type);
g_Zapit->setDiseqcRepeat( CNeutrinoApp::getInstance()->getScanSettings().diseqcRepeat);
return true;
}
void CSatelliteSetupNotifier::addItem(int list, CMenuItem* item)
{
switch(list) {
case 0:
items1.push_back(item);
break;
case 1:
items2.push_back(item);
break;
case 2:
items3.push_back(item);
break;
default:
break;
}
}
bool CSatDiseqcNotifier::changeNotify(const neutrino_locale_t, void * Data)
{
if (*((int*) Data) == NO_DISEQC)
{
satMenu->setActive(true);
extMenu->setActive(false);
extMotorMenu->setActive(false);
repeatMenu->init(-1, 0, 0, 0);
repeatMenu->setActive(false);
motorControl->setActive(false);
}
else
if (*((int*) Data) == DISEQC_1_2)
{
satMenu->setActive(true);
extMenu->setActive(true);
extMotorMenu->setActive(true);
repeatMenu->init(-1, 0, 0, 0);
repeatMenu->setActive(true);
motorControl->setActive(true);
}
else
{
satMenu->setActive(true);
extMenu->setActive(true);
extMotorMenu->setActive(false);
repeatMenu->init(-1, 0, 0, 0);
repeatMenu->setActive((*((int*) Data) != DISEQC_1_0));
motorControl->setActive(false);
}
g_Zapit->setDiseqcType( *((diseqc_t*) Data) );
g_Zapit->setDiseqcRepeat( CNeutrinoApp::getInstance()->getScanSettings().diseqcRepeat);
return true;
}
CTP_scanNotifier::CTP_scanNotifier(CMenuOptionChooser* i1, CMenuOptionChooser* i2, CMenuForwarder* i3, CMenuForwarder* i4)
{
toDisable1[0]=i1;
toDisable1[1]=i2;
toDisable2[0]=i3;
toDisable2[1]=i4;
}
bool CTP_scanNotifier::changeNotify(const neutrino_locale_t, void * Data)
{
int val = *((int*) Data);
//printf("CTP_scanNotifier::changeNotify: data %d\n", val);
//FIXME: test
//bool set_true_false=CNeutrinoApp::getInstance()->getScanSettings().TP_scan;
bool set_true_false = (val == 2);
for (int i=0; i<2; i++)
{
toDisable1[i]->setActive(set_true_false);
toDisable2[i]->setActive(set_true_false);
}
return true;
}
CDHCPNotifier::CDHCPNotifier( CMenuForwarder* a1, CMenuForwarder* a2, CMenuForwarder* a3, CMenuForwarder* a4, CMenuForwarder* a5)
{
toDisable[0] = a1;
toDisable[1] = a2;
toDisable[2] = a3;
toDisable[3] = a4;
toDisable[4] = a5;
}
bool CDHCPNotifier::changeNotify(const neutrino_locale_t, void * data)
{
CNeutrinoApp::getInstance()->networkConfig.inet_static = ((*(int*)(data)) == 0);
for(int x=0;x<5;x++)
toDisable[x]->setActive(CNeutrinoApp::getInstance()->networkConfig.inet_static);
return true;
}
CStreamingNotifier::CStreamingNotifier( CMenuItem* i1, CMenuItem* i2, CMenuItem* i3, CMenuItem* i4, CMenuItem* i5, CMenuItem* i6, CMenuItem* i7, CMenuItem* i8, CMenuItem* i9, CMenuItem* i10, CMenuItem* i11)
{
toDisable[0]=i1;
toDisable[1]=i2;
toDisable[2]=i3;
toDisable[3]=i4;
toDisable[4]=i5;
toDisable[5]=i6;
toDisable[6]=i7;
toDisable[7]=i8;
toDisable[8]=i9;
toDisable[9]=i10;
toDisable[10]=i11;
}
bool CStreamingNotifier::changeNotify(const neutrino_locale_t, void *)
{
if(g_settings.streaming_type==0)
{
for (int i=0; i<=10; i++)
toDisable[i]->setActive(false);
}
else if(g_settings.streaming_type==1)
{
for (int i=0; i<=10; i++)
toDisable[i]->setActive(true);
}
return true;
}
COnOffNotifier::COnOffNotifier( CMenuItem* a1,CMenuItem* a2,CMenuItem* a3,CMenuItem* a4,CMenuItem* a5)
{
number = 0;
if(a1 != NULL){ toDisable[0] =a1;number++;};
if(a2 != NULL){ toDisable[1] =a2;number++;};
if(a3 != NULL){ toDisable[2] =a3;number++;};
if(a4 != NULL){ toDisable[3] =a4;number++;};
if(a5 != NULL){ toDisable[4] =a5;number++;};
}
bool COnOffNotifier::changeNotify(const neutrino_locale_t, void *Data)
{
if(*(int*)(Data) == 0)
{
for (int i=0; i<number ; i++)
toDisable[i]->setActive(false);
}
else
{
for (int i=0; i<number ; i++)
toDisable[i]->setActive(true);
}
return true;
}
CRecordingNotifier::CRecordingNotifier(CMenuItem* i1 , CMenuItem* i2 , CMenuItem* i3 ,
CMenuItem* i4 , CMenuItem* i5 , CMenuItem* i6 ,
CMenuItem* i7 , CMenuItem* i8 , CMenuItem* i9)
{
toDisable[ 0] = i1;
toDisable[ 1] = i2;
toDisable[ 2] = i3;
toDisable[ 3] = i4;
toDisable[ 4] = i5;
toDisable[ 5] = i6;
toDisable[ 6] = i7;
toDisable[ 7] = i8;
toDisable[ 8] = i9;
}
bool CRecordingNotifier::changeNotify(const neutrino_locale_t, void *)
{
if ((g_settings.recording_type == CNeutrinoApp::RECORDING_OFF) ||
(g_settings.recording_type == CNeutrinoApp::RECORDING_FILE))
{
for(int i = 0; i < 8; i++) {
toDisable[i]->setActive(false);
}
if (g_settings.recording_type == CNeutrinoApp::RECORDING_FILE)
{
toDisable[7]->setActive(true);
}
}
else if (g_settings.recording_type == CNeutrinoApp::RECORDING_SERVER)
{
toDisable[0]->setActive(true);
toDisable[1]->setActive(true);
toDisable[2]->setActive(true);
toDisable[3]->setActive(g_settings.recording_server_wakeup==1);
toDisable[4]->setActive(true);
toDisable[5]->setActive(true);
toDisable[6]->setActive(false);
toDisable[7]->setActive(false);
}
else if (g_settings.recording_type == CNeutrinoApp::RECORDING_VCR)
{
toDisable[0]->setActive(false);
toDisable[1]->setActive(false);
toDisable[2]->setActive(false);
toDisable[3]->setActive(false);
toDisable[4]->setActive(false);
toDisable[5]->setActive(false);
toDisable[6]->setActive(true);
toDisable[7]->setActive(false);
}
return true;
}
CRecordingNotifier2::CRecordingNotifier2( CMenuItem* i)
{
toDisable[0]=i;
}
bool CRecordingNotifier2::changeNotify(const neutrino_locale_t, void *)
{
toDisable[0]->setActive(g_settings.recording_server_wakeup==1);
return true;
}
bool CRecordingSafetyNotifier::changeNotify(const neutrino_locale_t, void *)
{
g_Timerd->setRecordingSafety(atoi(g_settings.record_safety_time_before)*60, atoi(g_settings.record_safety_time_after)*60);
return true;
}
CMiscNotifier::CMiscNotifier( CMenuItem* i1)
{
toDisable[0]=i1;
}
bool CMiscNotifier::changeNotify(const neutrino_locale_t, void *)
{
toDisable[0]->setActive(!g_settings.shutdown_real);
return true;
}
bool CLcdNotifier::changeNotify(const neutrino_locale_t, void *)
{
CVFD::getInstance()->setlcdparameter();
//CLCD::getInstance()->setAutoDimm(g_settings.lcd_setting[SNeutrinoSettings::LCD_AUTODIMM]);
return true;
}
int CRfExec::exec(CMenuTarget* parent, const std::string& actionKey)
{
g_RFmod->init();
return true;
}
bool CRfNotifier::changeNotify(const neutrino_locale_t OptionName, void * val)
{
//printf("CRfNotifier: Option %d val %d\n", OptionName, *((int *)val));
if (ARE_LOCALES_EQUAL(OptionName, LOCALE_RF_CARRIER)) {
g_RFmod->setSoundSubCarrier(*((int *)val));
}
else if (ARE_LOCALES_EQUAL(OptionName, LOCALE_RF_ENABLE)) {
g_RFmod->setSoundEnable(*((int *)val));
}
else if (ARE_LOCALES_EQUAL(OptionName, LOCALE_RF_CHANNEL)) {
}
else if (ARE_LOCALES_EQUAL(OptionName, LOCALE_RF_FINETUNE)) {
}
else if (ARE_LOCALES_EQUAL(OptionName, LOCALE_RF_STANDBY)) {
g_RFmod->setStandby(*((int *)val));
}
else if (ARE_LOCALES_EQUAL(OptionName, LOCALE_RF_TEST)) {
g_RFmod->setTestPattern(*((int *)val));
}
return true;
}
bool CPauseSectionsdNotifier::changeNotify(const neutrino_locale_t, void * Data)
{
g_Sectionsd->setPauseScanning((*((int *)Data)) == 0);
return true;
}
bool CSectionsdConfigNotifier::changeNotify(const neutrino_locale_t, void *)
{
CNeutrinoApp::getInstance()->SendSectionsdConfig();
return true;
}
bool CTouchFileNotifier::changeNotify(const neutrino_locale_t, void * data)
{
if ((*(int *)data) != 0)
{
FILE * fd = fopen(filename, "w");
if (fd)
fclose(fd);
else
return false;
}
else
remove(filename);
return true;
}
bool CColorSetupNotifier::changeNotify(const neutrino_locale_t, void *)
{
CFrameBuffer *frameBuffer = CFrameBuffer::getInstance();
// unsigned char r,g,b;
//setting colors-..
frameBuffer->paletteGenFade(COL_MENUHEAD,
convertSetupColor2RGB(g_settings.menu_Head_red, g_settings.menu_Head_green, g_settings.menu_Head_blue),
convertSetupColor2RGB(g_settings.menu_Head_Text_red, g_settings.menu_Head_Text_green, g_settings.menu_Head_Text_blue),
8, convertSetupAlpha2Alpha( g_settings.menu_Head_alpha ) );
frameBuffer->paletteGenFade(COL_MENUCONTENT,
convertSetupColor2RGB(g_settings.menu_Content_red, g_settings.menu_Content_green, g_settings.menu_Content_blue),
convertSetupColor2RGB(g_settings.menu_Content_Text_red, g_settings.menu_Content_Text_green, g_settings.menu_Content_Text_blue),
8, convertSetupAlpha2Alpha(g_settings.menu_Content_alpha) );
frameBuffer->paletteGenFade(COL_MENUCONTENTDARK,
convertSetupColor2RGB(int(g_settings.menu_Content_red*0.6), int(g_settings.menu_Content_green*0.6), int(g_settings.menu_Content_blue*0.6)),
convertSetupColor2RGB(g_settings.menu_Content_Text_red, g_settings.menu_Content_Text_green, g_settings.menu_Content_Text_blue),
8, convertSetupAlpha2Alpha(g_settings.menu_Content_alpha) );
frameBuffer->paletteGenFade(COL_MENUCONTENTSELECTED,
convertSetupColor2RGB(g_settings.menu_Content_Selected_red, g_settings.menu_Content_Selected_green, g_settings.menu_Content_Selected_blue),
convertSetupColor2RGB(g_settings.menu_Content_Selected_Text_red, g_settings.menu_Content_Selected_Text_green, g_settings.menu_Content_Selected_Text_blue),
8, convertSetupAlpha2Alpha(g_settings.menu_Content_Selected_alpha) );
frameBuffer->paletteGenFade(COL_MENUCONTENTINACTIVE,
convertSetupColor2RGB(g_settings.menu_Content_inactive_red, g_settings.menu_Content_inactive_green, g_settings.menu_Content_inactive_blue),
convertSetupColor2RGB(g_settings.menu_Content_inactive_Text_red, g_settings.menu_Content_inactive_Text_green, g_settings.menu_Content_inactive_Text_blue),
8, convertSetupAlpha2Alpha(g_settings.menu_Content_inactive_alpha) );
frameBuffer->paletteGenFade(COL_INFOBAR,
convertSetupColor2RGB(g_settings.infobar_red, g_settings.infobar_green, g_settings.infobar_blue),
convertSetupColor2RGB(g_settings.infobar_Text_red, g_settings.infobar_Text_green, g_settings.infobar_Text_blue),
8, convertSetupAlpha2Alpha(g_settings.infobar_alpha) );
/* frameBuffer->paletteSetColor( COL_INFOBAR_SHADOW,
convertSetupColor2RGB(
int(g_settings.infobar_red*0.4),
int(g_settings.infobar_green*0.4),
int(g_settings.infobar_blue*0.4)),
g_settings.infobar_alpha);
*/
frameBuffer->paletteGenFade(COL_INFOBAR_SHADOW,
convertSetupColor2RGB(int(g_settings.infobar_red*0.4), int(g_settings.infobar_green*0.4), int(g_settings.infobar_blue*0.4)),
convertSetupColor2RGB(g_settings.infobar_Text_red, g_settings.infobar_Text_green, g_settings.infobar_Text_blue),
8, convertSetupAlpha2Alpha(g_settings.infobar_alpha) );
frameBuffer->paletteSet();
return false;
}
bool CAudioSetupNotifier::changeNotify(const neutrino_locale_t OptionName, void *)
{
//printf("notify: %d\n", OptionName);
#if 0 //FIXME to do ? manual audio delay
if (ARE_LOCALES_EQUAL(OptionName, LOCALE_AUDIOMENU_PCMOFFSET))
{
}
#endif
if (ARE_LOCALES_EQUAL(OptionName, LOCALE_AUDIOMENU_ANALOGOUT)) {
g_Zapit->setAudioMode(g_settings.audio_AnalogMode);
} else if (ARE_LOCALES_EQUAL(OptionName, LOCALE_AUDIOMENU_HDMI_DD)) {
audioDecoder->SetHdmiDD(g_settings.hdmi_dd ? true : false);
} else if (ARE_LOCALES_EQUAL(OptionName, LOCALE_AUDIOMENU_SPDIF_DD)) {
audioDecoder->SetSpdifDD(g_settings.spdif_dd ? true : false);
} else if (ARE_LOCALES_EQUAL(OptionName, LOCALE_AUDIOMENU_AVSYNC)) {
videoDecoder->SetSyncMode((AVSYNC_TYPE)g_settings.avsync);
audioDecoder->SetSyncMode((AVSYNC_TYPE)g_settings.avsync);
videoDemux->SetSyncMode((AVSYNC_TYPE)g_settings.avsync);
audioDemux->SetSyncMode((AVSYNC_TYPE)g_settings.avsync);
pcrDemux->SetSyncMode((AVSYNC_TYPE)g_settings.avsync);
} else if (ARE_LOCALES_EQUAL(OptionName, LOCALE_AUDIOMENU_CLOCKREC)) {
//.Clock recovery enable/disable
// FIXME add code here.
} else { // FIXME atm used for SRS
audioDecoder->SetSRS(g_settings.srs_enable, g_settings.srs_nmgr_enable, g_settings.srs_algo, g_settings.srs_ref_volume);
}
return true;
}
//FIXME
#define IOC_IR_SET_F_DELAY _IOW(0xDD, 5, unsigned int) /* set the delay time before the first repetition */
#define IOC_IR_SET_X_DELAY _IOW(0xDD, 6, unsigned int) /* set the delay time between all other repetitions */
bool CKeySetupNotifier::changeNotify(const neutrino_locale_t, void *)
{
unsigned int fdelay = atoi(g_settings.repeat_blocker);
unsigned int xdelay = atoi(g_settings.repeat_genericblocker);
g_RCInput->repeat_block = fdelay * 1000;
g_RCInput->repeat_block_generic = xdelay * 1000;
int fd = g_RCInput->getFileHandle();
ioctl(fd, IOC_IR_SET_F_DELAY, fdelay);
ioctl(fd, IOC_IR_SET_X_DELAY, xdelay);
return false;
}
bool CIPChangeNotifier::changeNotify(const neutrino_locale_t, void * Data)
{
char ip[16];
unsigned char _ip[4];
sscanf((char*) Data, "%hhu.%hhu.%hhu.%hhu", &_ip[0], &_ip[1], &_ip[2], &_ip[3]);
sprintf(ip, "%hhu.%hhu.%hhu.255", _ip[0], _ip[1], _ip[2]);
CNeutrinoApp::getInstance()->networkConfig.broadcast = ip;
CNeutrinoApp::getInstance()->networkConfig.netmask = (_ip[0] == 10) ? "255.0.0.0" : "255.255.255.0";
return true;
}
bool CConsoleDestChangeNotifier::changeNotify(const neutrino_locale_t, void * Data)
{
g_settings.uboot_console = *(int *)Data;
return true;
}
bool CTimingSettingsNotifier::changeNotify(const neutrino_locale_t OptionName, void *)
{
for (int i = 0; i < TIMING_SETTING_COUNT; i++)
{
if (ARE_LOCALES_EQUAL(OptionName, timing_setting_name[i]))
{
g_settings.timing[i] = atoi(g_settings.timing_string[i]);
return true;
}
}
return false;
}
bool CFontSizeNotifier::changeNotify(const neutrino_locale_t, void *)
{
CHintBox hintBox(LOCALE_MESSAGEBOX_INFO, g_Locale->getText(LOCALE_FONTSIZE_HINT)); // UTF-8
hintBox.paint();
CNeutrinoApp::getInstance()->SetupFonts();
hintBox.hide();
return true;
}
bool CRecAPIDSettingsNotifier::changeNotify(const neutrino_locale_t, void *)
{
g_settings.recording_audio_pids_default = ( (g_settings.recording_audio_pids_std ? TIMERD_APIDS_STD : 0) |
(g_settings.recording_audio_pids_alt ? TIMERD_APIDS_ALT : 0) |
(g_settings.recording_audio_pids_ac3 ? TIMERD_APIDS_AC3 : 0));
return true;
}
int CAPIDChangeExec::exec(CMenuTarget* parent, const std::string & actionKey)
{
// printf("CAPIDChangeExec exec: %s\n", actionKey.c_str());
unsigned int sel= atoi(actionKey.c_str());
if (g_RemoteControl->current_PIDs.PIDs.selected_apid!= sel )
{
g_RemoteControl->setAPID(sel);
}
return menu_return::RETURN_EXIT;
}
int dvbsub_start(int pid);
int dvbsub_pause();
int dvbsub_stop();
int CSubtitleChangeExec::exec(CMenuTarget* parent, const std::string & actionKey)
{
printf("CSubtitleChangeExec::exec: action %s\n", actionKey.c_str());
if(actionKey == "off") {
dvbsub_stop();
} else {
int pid = atoi(actionKey.c_str());
dvbsub_pause();
dvbsub_start(pid);
}
return menu_return::RETURN_EXIT;
}
int CNVODChangeExec::exec(CMenuTarget* parent, const std::string & actionKey)
{
// printf("CNVODChangeExec exec: %s\n", actionKey.c_str());
unsigned sel= atoi(actionKey.c_str());
g_RemoteControl->setSubChannel(sel);
parent->hide();
g_InfoViewer->showSubchan();
return menu_return::RETURN_EXIT;
}
int CStreamFeaturesChangeExec::exec(CMenuTarget* parent, const std::string & actionKey)
{
//printf("CStreamFeaturesChangeExec exec: %s\n", actionKey.c_str());
int sel= atoi(actionKey.c_str());
if(parent != NULL)
parent->hide();
// -- obsolete (rasc 2004-06-10)
// if (sel==-1)
// {
// CStreamInfo StreamInfo;
// StreamInfo.exec(NULL, "");
// } else
if(actionKey == "teletext") {
g_RCInput->postMsg(CRCInput::RC_text, 0);
#if 0
g_RCInput->clearRCMsg();
tuxtx_main(g_RCInput->getFileHandle(), frameBuffer->getFrameBufferPointer(), g_RemoteControl->current_PIDs.PIDs.vtxtpid);
frameBuffer->paintBackground();
if(!g_settings.cacheTXT)
tuxtxt_stop();
g_RCInput->clearRCMsg();
#endif
}
else if (sel>=0)
{
g_PluginList->startPlugin(sel,0);
}
return menu_return::RETURN_EXIT;
}
int CMoviePluginChangeExec::exec(CMenuTarget* parent, const std::string & actionKey)
{
int sel= atoi(actionKey.c_str());
parent->hide();
if (sel>=0)
{
g_settings.movieplayer_plugin=g_PluginList->getName(sel);
}
return menu_return::RETURN_EXIT;
}
int COnekeyPluginChangeExec::exec(CMenuTarget* parent, const std::string & actionKey)
{
int sel= atoi(actionKey.c_str());
parent->hide();
if (sel>=0)
{
g_settings.onekey_plugin=g_PluginList->getName(sel);
}
return menu_return::RETURN_EXIT;
}
int CUCodeCheckExec::exec(CMenuTarget* parent, const std::string & actionKey)
{
#if 0
std::string text;
char res[60];
text = g_Locale->getText(LOCALE_UCODECHECK_AVIA500);
text += ": ";
checkFile((char *) UCODEDIR "/avia500.ux", (char*) &res);
text += res;
text += '\n';
text += g_Locale->getText(LOCALE_UCODECHECK_AVIA600);
text += ": ";
checkFile(UCODEDIR "/avia600.ux", (char*) &res);
text += res;
text += '\n';
text += g_Locale->getText(LOCALE_UCODECHECK_UCODE);
text += ": ";
checkFile(UCODEDIR "/ucode.bin", (char*) &res);
if (strcmp("not found", res) == 0)
text += "ucode_0014 (built-in)";
else
text += res;
text += '\n';
text += g_Locale->getText(LOCALE_UCODECHECK_CAM_ALPHA);
text += ": ";
checkFile(UCODEDIR "/cam-alpha.bin", (char*) &res);
text += res;
ShowMsgUTF(LOCALE_UCODECHECK_HEAD, text, CMessageBox::mbrBack, CMessageBox::mbBack); // UTF-8
#endif
return 1;
}
const char * mypinghost(const char * const host)
{
int retvalue = pinghost(host);
switch (retvalue)
{
case 1: return (g_Locale->getText(LOCALE_PING_OK));
case 0: return (g_Locale->getText(LOCALE_PING_UNREACHABLE));
case -1: return (g_Locale->getText(LOCALE_PING_PROTOCOL));
case -2: return (g_Locale->getText(LOCALE_PING_SOCKET));
}
return "";
}
void testNetworkSettings(const char* ip, const char* netmask, const char* broadcast, const char* gateway, const char* nameserver, bool ip_static)
{
char our_ip[16];
char our_mask[16];
char our_broadcast[16];
char our_gateway[16];
char our_nameserver[16];
std::string text;
if (ip_static) {
strcpy(our_ip,ip);
strcpy(our_mask,netmask);
strcpy(our_broadcast,broadcast);
strcpy(our_gateway,gateway);
strcpy(our_nameserver,nameserver);
}
else {
netGetIP((char *) "eth0",our_ip,our_mask,our_broadcast);
netGetDefaultRoute(our_gateway);
netGetNameserver(our_nameserver);
}
printf("testNw IP : %s\n", our_ip);
printf("testNw Netmask : %s\n", our_mask);
printf("testNw Broadcast: %s\n", our_broadcast);
printf("testNw Gateway: %s\n", our_gateway);
printf("testNw Nameserver: %s\n", our_nameserver);
text = our_ip;
text += ": ";
text += mypinghost(our_ip);
text += '\n';
text += g_Locale->getText(LOCALE_NETWORKMENU_GATEWAY);
text += ": ";
text += our_gateway;
text += ' ';
text += mypinghost(our_gateway);
text += '\n';
text += g_Locale->getText(LOCALE_NETWORKMENU_NAMESERVER);
text += ": ";
text += our_nameserver;
text += ' ';
text += mypinghost(our_nameserver);
text += "\ndboxupdate.berlios.de: ";
text += mypinghost("195.37.77.138");
ShowMsgUTF(LOCALE_NETWORKMENU_TEST, text, CMessageBox::mbrBack, CMessageBox::mbBack); // UTF-8
}
void showCurrentNetworkSettings()
{
char ip[16];
char mask[16];
char broadcast[16];
char router[16];
char nameserver[16];
std::string text;
netGetIP((char *) "eth0",ip,mask,broadcast);
if (ip[0] == 0) {
text = "Network inactive\n";
}
else {
netGetNameserver(nameserver);
netGetDefaultRoute(router);
text = g_Locale->getText(LOCALE_NETWORKMENU_IPADDRESS );
text += ": ";
text += ip;
text += '\n';
text += g_Locale->getText(LOCALE_NETWORKMENU_NETMASK );
text += ": ";
text += mask;
text += '\n';
text += g_Locale->getText(LOCALE_NETWORKMENU_BROADCAST );
text += ": ";
text += broadcast;
text += '\n';
text += g_Locale->getText(LOCALE_NETWORKMENU_NAMESERVER);
text += ": ";
text += nameserver;
text += '\n';
text += g_Locale->getText(LOCALE_NETWORKMENU_GATEWAY );
text += ": ";
text += router;
}
ShowMsgUTF(LOCALE_NETWORKMENU_SHOW, text, CMessageBox::mbrBack, CMessageBox::mbBack); // UTF-8
}
unsigned long long getcurrenttime()
{
struct timeval tv;
gettimeofday( &tv, NULL );
return (unsigned long long) tv.tv_usec + (unsigned long long)((unsigned long long) tv.tv_sec * (unsigned long long) 1000000);
}
// USERMENU
#define USERMENU_ITEM_OPTION_COUNT SNeutrinoSettings::ITEM_MAX
const CMenuOptionChooser::keyval USERMENU_ITEM_OPTIONS[USERMENU_ITEM_OPTION_COUNT] =
{
{SNeutrinoSettings::ITEM_NONE, LOCALE_USERMENU_ITEM_NONE} ,
{SNeutrinoSettings::ITEM_BAR, LOCALE_USERMENU_ITEM_BAR} ,
{SNeutrinoSettings::ITEM_EPG_LIST, LOCALE_EPGMENU_EVENTLIST} ,
{SNeutrinoSettings::ITEM_EPG_SUPER, LOCALE_EPGMENU_EPGPLUS} ,
{SNeutrinoSettings::ITEM_EPG_INFO, LOCALE_EPGMENU_EVENTINFO} ,
{SNeutrinoSettings::ITEM_EPG_MISC, LOCALE_USERMENU_ITEM_EPG_MISC} ,
{SNeutrinoSettings::ITEM_AUDIO_SELECT, LOCALE_AUDIOSELECTMENUE_HEAD} ,
{SNeutrinoSettings::ITEM_SUBCHANNEL, LOCALE_INFOVIEWER_SUBSERVICE} ,
{SNeutrinoSettings::ITEM_RECORD, LOCALE_TIMERLIST_TYPE_RECORD} ,
{SNeutrinoSettings::ITEM_MOVIEPLAYER_MB, LOCALE_MOVIEBROWSER_HEAD} ,
{SNeutrinoSettings::ITEM_TIMERLIST, LOCALE_TIMERLIST_NAME} ,
{SNeutrinoSettings::ITEM_REMOTE, LOCALE_RCLOCK_MENUEADD} ,
{SNeutrinoSettings::ITEM_FAVORITS, LOCALE_FAVORITES_MENUEADD} ,
{SNeutrinoSettings::ITEM_TECHINFO, LOCALE_EPGMENU_STREAMINFO},
{SNeutrinoSettings::ITEM_PLUGIN, LOCALE_TIMERLIST_PLUGIN},
{SNeutrinoSettings::ITEM_VTXT, LOCALE_USERMENU_ITEM_VTXT} ,
#if 0
{SNeutrinoSettings::ITEM_MOVIEPLAYER_TS, LOCALE_MAINMENU_MOVIEPLAYER} ,
{SNeutrinoSettings::ITEM_RESTART_CAMD, LOCALE_EXTRA_RESTARTCAMD}
#endif
};
int CUserMenuMenu::exec(CMenuTarget* parent, const std::string & actionKey)
{
if(parent != NULL)
parent->hide();
CMenuWidget menu (local , "keybinding.raw");
menu.addItem(GenericMenuSeparator);
menu.addItem(GenericMenuBack);
menu.addItem(GenericMenuSeparatorLine);
CStringInputSMS name(LOCALE_USERMENU_NAME, &g_settings.usermenu_text[button], 11, NONEXISTANT_LOCALE, NONEXISTANT_LOCALE, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz<EFBFBD><EFBFBD>/- ");
menu.addItem(new CMenuForwarder(LOCALE_USERMENU_NAME, true, g_settings.usermenu_text[button],&name));
menu.addItem(GenericMenuSeparatorLine);
char text[10];
for(int item = 0; item < SNeutrinoSettings::ITEM_MAX && item <13; item++) // Do not show more than 13 items
{
snprintf(text,10,"%d:",item);
text[9]=0;// terminate for sure
//menu.addItem( new CMenuOptionChooser(text, &g_settings.usermenu[button][item], USERMENU_ITEM_OPTIONS, USERMENU_ITEM_OPTION_COUNT,true ));
menu.addItem( new CMenuOptionChooser(text, &g_settings.usermenu[button][item], USERMENU_ITEM_OPTIONS, USERMENU_ITEM_OPTION_COUNT,true, NULL, CRCInput::RC_nokey, "", true ));
}
menu.exec(NULL,"");
return menu_return::RETURN_REPAINT;
}
bool CTZChangeNotifier::changeNotify(const neutrino_locale_t, void * Data)
{
bool found = false;
std::string name, zone;
printf("CTZChangeNotifier::changeNotify: %s\n", (char *) Data);
xmlDocPtr parser = parseXmlFile("/etc/timezone.xml");
if (parser != NULL) {
xmlNodePtr search = xmlDocGetRootElement(parser)->xmlChildrenNode;
while (search) {
if (!strcmp(xmlGetName(search), "zone")) {
name = xmlGetAttribute(search, (char *) "name");
zone = xmlGetAttribute(search, (char *) "zone");
if(!strcmp(g_settings.timezone, name.c_str())) {
found = true;
break;
}
}
search = search->xmlNextNode;
}
xmlFreeDoc(parser);
}
if(found) {
printf("Timezone: %s -> %s\n", name.c_str(), zone.c_str());
std::string cmd = "cp /usr/share/zoneinfo/" + zone + " /etc/localtime";
printf("exec %s\n", cmd.c_str());
system(cmd.c_str());
cmd = ":" + zone;
setenv("TZ", cmd.c_str(), 1);
}
return true;
}
extern Zapit_config zapitCfg;
void loadZapitSettings();
void getZapitConfig(Zapit_config *Cfg);
int CDataResetNotifier::exec(CMenuTarget* parent, const std::string& actionKey)
{
bool delete_all = (actionKey == "all");
bool delete_chan = (actionKey == "channels") || delete_all;
bool delete_set = (actionKey == "settings") || delete_all;
neutrino_locale_t msg = delete_all ? LOCALE_RESET_ALL : delete_chan ? LOCALE_RESET_CHANNELS : LOCALE_RESET_SETTINGS;
int result = ShowMsgUTF(msg, g_Locale->getText(LOCALE_RESET_CONFIRM), CMessageBox::mbrNo, CMessageBox::mbYes | CMessageBox::mbNo);
if(result != CMessageBox::mbrYes)
return true;
if(delete_all) {
system("rm -f /var/tuxbox/config/zapit/*.conf");
loadZapitSettings();
getZapitConfig(&zapitCfg);
}
if(delete_set) {
unlink(NEUTRINO_SETTINGS_FILE);
//unlink(NEUTRINO_SCAN_SETTINGS_FILE);
CNeutrinoApp::getInstance()->loadSetup(NEUTRINO_SETTINGS_FILE);
CNeutrinoApp::getInstance()->saveSetup(NEUTRINO_SETTINGS_FILE);
CNeutrinoApp::getInstance()->loadColors(NEUTRINO_SETTINGS_FILE);
//CNeutrinoApp::getInstance()->SetupFonts();
CNeutrinoApp::getInstance()->SetupTiming();
}
if(delete_chan) {
system("rm -f /var/tuxbox/config/zapit/*.xml");
g_Zapit->reinitChannels();
}
return true;
}
bool CFanControlNotifier::changeNotify(const neutrino_locale_t, void * data)
{
int cfd, ret;
//unsigned char speed = (unsigned char) g_settings.fan_speed;
unsigned int speed = * (int *) data;
printf("FAN Speed %d\n", speed);
cfd = open("/dev/cs_control", O_RDONLY);
if(cfd < 0) {
perror("Cannot open /dev/cs_control");
return false;
}
ret = ioctl(cfd, IOC_CONTROL_PWM_SPEED, speed);
close(cfd);
if(ret < 0) {
perror("IOC_CONTROL_PWM_SPEED");
return false;
}
return true;
}
extern cCpuFreqManager * cpuFreq;
bool CCpuFreqNotifier::changeNotify(const neutrino_locale_t, void * data)
{
int freq = * (int *) data;
printf("CCpuFreqNotifier: %d Mhz\n", freq);
freq *= 1000*1000;
cpuFreq->SetCpuFreq(freq);
return true;
}

View File

@@ -0,0 +1,306 @@
#ifndef __setting_helpers__
#define __setting_helpers__
/*
Neutrino-GUI - DBoxII-Project
Copyright (C) 2001 Steffen Hehn 'McClean'
Homepage: http://dbox.cyberphoria.org/
Kommentar:
Diese GUI wurde von Grund auf neu programmiert und sollte nun vom
Aufbau und auch den Ausbaumoeglichkeiten gut aussehen. Neutrino basiert
auf der Client-Server Idee, diese GUI ist also von der direkten DBox-
Steuerung getrennt. Diese wird dann von Daemons uebernommen.
License: GPL
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <gui/widget/menue.h>
#include <string>
unsigned long long getcurrenttime();
class CSatelliteSetupNotifier : public CChangeObserver
{
private:
std::vector<CMenuItem*> items1;
std::vector<CMenuItem*> items2;
std::vector<CMenuItem*> items3;
public:
CSatelliteSetupNotifier();
void addItem(int list, CMenuItem* item);
bool changeNotify(const neutrino_locale_t, void * Data);
};
class CSatDiseqcNotifier : public CChangeObserver
{
private:
CMenuItem* satMenu;
CMenuItem* extMenu;
CMenuItem* extMotorMenu;
CMenuItem* repeatMenu;
CMenuItem* motorControl;
protected:
CSatDiseqcNotifier( ) : CChangeObserver(){}; // prevent calling constructor without data we need
public:
CSatDiseqcNotifier( CMenuItem* SatMenu, CMenuItem* ExtMenu, CMenuItem* ExtMotorMenu, CMenuItem* RepeatMenu, CMenuItem* MotorControl) : CChangeObserver()
{ satMenu = SatMenu; extMenu = ExtMenu; extMotorMenu = ExtMotorMenu; repeatMenu = RepeatMenu; motorControl = MotorControl;};
bool changeNotify(const neutrino_locale_t, void * Data);
};
class CTP_scanNotifier : public CChangeObserver
{
private:
CMenuOptionChooser* toDisable1[2];
CMenuForwarder* toDisable2[2];
public:
CTP_scanNotifier(CMenuOptionChooser*, CMenuOptionChooser*, CMenuForwarder*, CMenuForwarder*);
bool changeNotify(const neutrino_locale_t, void * Data);
};
class CDHCPNotifier : public CChangeObserver
{
private:
CMenuForwarder* toDisable[5];
public:
CDHCPNotifier( CMenuForwarder*, CMenuForwarder*, CMenuForwarder*, CMenuForwarder*, CMenuForwarder*);
bool changeNotify(const neutrino_locale_t, void * data);
};
class CStreamingNotifier : public CChangeObserver
{
private:
CMenuItem* toDisable[11];
public:
CStreamingNotifier( CMenuItem*, CMenuItem*, CMenuItem*, CMenuItem*, CMenuItem*, CMenuItem*, CMenuItem*, CMenuItem*, CMenuItem*, CMenuItem*, CMenuItem*);
bool changeNotify(const neutrino_locale_t, void *);
};
class COnOffNotifier : public CChangeObserver
{
private:
int number;
CMenuItem* toDisable[5];
public:
COnOffNotifier (CMenuItem* a1,CMenuItem* a2 = NULL,CMenuItem* a3 = NULL,CMenuItem* a4 = NULL,CMenuItem* a5 = NULL);
bool changeNotify(const neutrino_locale_t, void *Data);
};
class CRecordingNotifier : public CChangeObserver
{
private:
CMenuItem* toDisable[9];
public:
CRecordingNotifier(CMenuItem*, CMenuItem*, CMenuItem*, CMenuItem*, CMenuItem*, CMenuItem*, CMenuItem*, CMenuItem*, CMenuItem*);
bool changeNotify(const neutrino_locale_t OptionName, void*);
};
class CRecordingSafetyNotifier : public CChangeObserver
{
public:
bool changeNotify(const neutrino_locale_t, void *);
};
class CRecordingNotifier2 : public CChangeObserver
{
private:
CMenuItem* toDisable[1];
public:
CRecordingNotifier2( CMenuItem*);
bool changeNotify(const neutrino_locale_t, void *);
};
class CMiscNotifier : public CChangeObserver
{
private:
CMenuItem* toDisable[1];
public:
CMiscNotifier( CMenuItem* );
bool changeNotify(const neutrino_locale_t, void *);
};
class CLcdNotifier : public CChangeObserver
{
public:
bool changeNotify(const neutrino_locale_t, void *);
};
class CRfNotifier : public CChangeObserver
{
public:
bool changeNotify(const neutrino_locale_t, void *);
};
class CRfExec : public CMenuTarget
{
public:
int exec(CMenuTarget* parent, const std::string & actionKey);
};
class CPauseSectionsdNotifier : public CChangeObserver
{
public:
bool changeNotify(const neutrino_locale_t, void * Data);
};
class CSectionsdConfigNotifier : public CChangeObserver
{
public:
bool changeNotify(const neutrino_locale_t, void * );
};
class CTouchFileNotifier : public CChangeObserver
{
const char * filename;
public:
inline CTouchFileNotifier(const char * file_to_modify)
{
filename = file_to_modify;
};
bool changeNotify(const neutrino_locale_t, void * data);
};
class CColorSetupNotifier : public CChangeObserver
{
public:
bool changeNotify(const neutrino_locale_t, void *);
};
class CAudioSetupNotifier : public CChangeObserver
{
public:
bool changeNotify(const neutrino_locale_t OptionName, void *);
};
class CKeySetupNotifier : public CChangeObserver
{
public:
bool changeNotify(const neutrino_locale_t, void *);
};
class CIPChangeNotifier : public CChangeObserver
{
public:
bool changeNotify(const neutrino_locale_t, void * Data);
};
class CConsoleDestChangeNotifier : public CChangeObserver
{
public:
bool changeNotify(const neutrino_locale_t, void * Data);
};
class CTimingSettingsNotifier : public CChangeObserver
{
public:
bool changeNotify(const neutrino_locale_t OptionName, void *);
};
class CFontSizeNotifier : public CChangeObserver
{
public:
bool changeNotify(const neutrino_locale_t, void *);
};
class CRecAPIDSettingsNotifier : public CChangeObserver
{
public:
bool changeNotify(const neutrino_locale_t OptionName, void*);
};
class CAPIDChangeExec : public CMenuTarget
{
public:
int exec(CMenuTarget* parent, const std::string & actionKey);
};
class CSubtitleChangeExec : public CMenuTarget
{
public:
int exec(CMenuTarget* parent, const std::string & actionKey);
};
void showSubchan(const std::string & subChannelName);
class CNVODChangeExec : public CMenuTarget
{
public:
int exec(CMenuTarget* parent, const std::string & actionKey);
};
class CStreamFeaturesChangeExec : public CMenuTarget
{
public:
int exec(CMenuTarget* parent, const std::string & actionKey);
};
class CMoviePluginChangeExec : public CMenuTarget
{
public:
int exec(CMenuTarget* parent, const std::string & actionKey);
};
class COnekeyPluginChangeExec : public CMenuTarget
{
public:
int exec(CMenuTarget* parent, const std::string & actionKey);
};
class CUCodeCheckExec : public CMenuTarget
{
public:
int exec(CMenuTarget* parent, const std::string & actionKey);
};
void testNetworkSettings(const char* ip, const char* netmask, const char* broadcast, const char* gateway, const char* nameserver, bool dhcp);
void showCurrentNetworkSettings();
// USERMENU
class CUserMenuMenu : public CMenuTarget
{
private:
int button;
neutrino_locale_t local;
public:
CUserMenuMenu(neutrino_locale_t _local, int _button){local = _local;button = _button;};
int exec(CMenuTarget* parent, const std::string & actionKey);
};
class CTZChangeNotifier : public CChangeObserver
{
public:
bool changeNotify(const neutrino_locale_t, void * data);
};
class CDataResetNotifier : public CMenuTarget
{
public:
int exec(CMenuTarget* parent, const std::string& actionKey);
};
class CFanControlNotifier : public CChangeObserver
{
public:
bool changeNotify(const neutrino_locale_t, void * data);
};
class CCpuFreqNotifier : public CChangeObserver
{
public:
bool changeNotify(const neutrino_locale_t, void * data);
};
#endif

199
src/system/settings.cpp Normal file
View File

@@ -0,0 +1,199 @@
/*
$Id: settings.cpp,v 1.38 2005/03/03 19:59:41 diemade Exp $
Neutrino-GUI - DBoxII-Project
License: GPL
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA
*/
#include <cstring>
#include <system/settings.h>
#include <zapit/settings.h>
#include <zapit/satconfig.h>
const int default_timing[TIMING_SETTING_COUNT] =
{
0,
60,
240,
6,
60,
3
};
const neutrino_locale_t timing_setting_name[TIMING_SETTING_COUNT] =
{
LOCALE_TIMING_MENU,
LOCALE_TIMING_CHANLIST,
LOCALE_TIMING_EPG,
LOCALE_TIMING_INFOBAR,
LOCALE_TIMING_FILEBROWSER,
LOCALE_TIMING_NUMERICZAP
};
CScanSettings::CScanSettings(void)
: configfile('\t')
{
delivery_system = DVB_S;
satNameNoDiseqc[0] = 0;
}
void CScanSettings::toSatList( CZapitClient::ScanSatelliteList& satList) const
{
#if 0
satList.clear();
CZapitClient::commandSetScanSatelliteList sat;
sat.diseqc = 0;
strncpy(sat.satName, satNameNoDiseqc, 30);
if(diseqcMode == DISEQC_1_2)
sat.diseqc = -1;
if((scan_mode == 2) || (diseqcMode == DISEQC_1_2)) {
for (int i = 0; i < MAX_SATELLITES; i++) {
if (!strcmp(satName[i], satNameNoDiseqc)) {
if (satDiseqc[i] != -1)
sat.diseqc = satDiseqc[i];
break;
}
}
}
satList.push_back(sat);
#endif
#if 0
if (scan_mode == 2) {
strncpy(sat.satName, satNameNoDiseqc, 30);
sat.diseqc = 0;
for (int i = 0; i < MAX_SATELLITES; i++) {
if (!strcmp(satName[i], satNameNoDiseqc)) {
if (satDiseqc[i] != -1)
sat.diseqc = satDiseqc[i];
break;
}
}
satList.push_back(sat);
}
else if (diseqcMode == NO_DISEQC) {
strncpy(sat.satName, satNameNoDiseqc, 30);
sat.diseqc = 0;
satList.push_back(sat);
}
else if (diseqcMode == DISEQC_1_2) {
strncpy(sat.satName, satNameNoDiseqc, 30);
sat.diseqc = -1;
for (int i = 0; i < MAX_SATELLITES; i++) {
if (!strcmp(satName[i], satNameNoDiseqc)) {
if (satDiseqc[i] != -1)
sat.diseqc = satDiseqc[i];
break;
}
}
satList.push_back(sat);
} else { // scan all sats with configured diseqc
for( int i = 0; i < MAX_SATELLITES; i++) {
if (satDiseqc[i] != -1) {
strncpy(sat.satName, satName[i], 30);
sat.diseqc = satDiseqc[i];
satList.push_back(sat);
}
}
}
#endif
}
void CScanSettings::useDefaults(const delivery_system_t _delivery_system)
{
delivery_system = _delivery_system;
bouquetMode = CZapitClient::BM_UPDATEBOUQUETS;
scanType = CZapitClient::ST_ALL;
diseqcMode = NO_DISEQC;
diseqcRepeat = 0;
TP_mod = 3;
TP_fec = 3;
switch (delivery_system)
{
case DVB_C:
strcpy(satNameNoDiseqc, "none");
break;
case DVB_S:
strcpy(satNameNoDiseqc, "none");
break;
case DVB_T:
strcpy(satNameNoDiseqc, "");
break;
}
}
bool CScanSettings::loadSettings(const char * const fileName, const delivery_system_t _delivery_system)
{
useDefaults(_delivery_system);
if(!configfile.loadConfig(fileName))
return false;
if (configfile.getInt32("delivery_system", -1) != delivery_system)
{
// configfile is not for this delivery system
configfile.clear();
return false;
}
diseqcMode = configfile.getInt32("diseqcMode" , diseqcMode);
diseqcRepeat = configfile.getInt32("diseqcRepeat", diseqcRepeat);
bouquetMode = (CZapitClient::bouquetMode) configfile.getInt32("bouquetMode" , bouquetMode);
scanType=(CZapitClient::scanType) configfile.getInt32("scanType", scanType);
strcpy(satNameNoDiseqc, configfile.getString("satNameNoDiseqc", satNameNoDiseqc).c_str());
scan_mode = configfile.getInt32("scan_mode", 1); // NIT (0) or fast (1)
TP_fec = configfile.getInt32("TP_fec", 1);
TP_pol = configfile.getInt32("TP_pol", 0);
TP_mod = configfile.getInt32("TP_mod", 3);
strcpy(TP_freq, configfile.getString("TP_freq", "10100000").c_str());
strcpy(TP_rate, configfile.getString("TP_rate", "27500000").c_str());
#if HAVE_DVB_API_VERSION >= 3
if(TP_fec == 4) TP_fec = 5;
#endif
scanSectionsd = configfile.getInt32("scanSectionsd", 0);
return true;
}
bool CScanSettings::saveSettings(const char * const fileName)
{
configfile.setInt32("delivery_system", delivery_system);
configfile.setInt32( "diseqcMode", diseqcMode );
configfile.setInt32( "diseqcRepeat", diseqcRepeat );
configfile.setInt32( "bouquetMode", bouquetMode );
configfile.setInt32( "scanType", scanType );
configfile.setString( "satNameNoDiseqc", satNameNoDiseqc );
configfile.setInt32("scan_mode", scan_mode);
configfile.setInt32("TP_fec", TP_fec);
configfile.setInt32("TP_pol", TP_pol);
configfile.setInt32("TP_mod", TP_mod);
configfile.setString("TP_freq", TP_freq);
configfile.setString("TP_rate", TP_rate);
configfile.setInt32("scanSectionsd", scanSectionsd );
if(configfile.getModifiedFlag())
configfile.saveConfig(fileName);
return true;
}

535
src/system/settings.h Normal file
View File

@@ -0,0 +1,535 @@
/*
Neutrino-GUI - DBoxII-Project
Copyright (C) 2001 Steffen Hehn 'McClean'
Homepage: http://dbox.cyberphoria.org/
Kommentar:
Diese GUI wurde von Grund auf neu programmiert und sollte nun vom
Aufbau und auch den Ausbaumoeglichkeiten gut aussehen. Neutrino basiert
auf der Client-Server Idee, diese GUI ist also von der direkten DBox-
Steuerung getrennt. Diese wird dann von Daemons uebernommen.
License: GPL
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __settings__
#define __settings__
#include <system/localize.h>
#include <configfile.h>
#include <zapit/client/zapitclient.h>
#include <string>
#define VIDEOMENU_VIDEOMODE_OPTION_COUNT 12
struct SNeutrinoSettings
{
//video
int video_Format;
int video_Mode;
int analog_mode1;
int analog_mode2;
int video_43mode;
unsigned char video_csync;
char current_volume;
int channel_mode;
//misc
int shutdown_real;
int shutdown_real_rcdelay;
char shutdown_count[4];
char record_safety_time_before[3];
char record_safety_time_after[3];
int infobar_sat_display;
int infobar_subchan_disp_pos;
int misc_spts;
int fan_speed;
//audio
int audio_AnalogMode;
int audio_DolbyDigital;
int audio_avs_Control;
int audio_english;
char audio_PCMOffset[3];
int srs_enable;
int srs_algo;
int srs_ref_volume;
int srs_nmgr_enable;
int hdmi_dd;
int spdif_dd;
int video_dbdr;
int enabled_video_modes[VIDEOMENU_VIDEOMODE_OPTION_COUNT];
int cpufreq;
int standby_cpufreq;
int make_hd_list;
int avsync;
int clockrec;
int rounded_corners;
//vcr
int vcr_AutoSwitch;
//language
char language[25];
char timezone[150];
// EPG
int epg_save;
std::string epg_cache;
std::string epg_old_events;
std::string epg_max_events;
std::string epg_extendedcache;
std::string epg_dir;
std::string network_ntpserver;
std::string network_ntprefresh;
int network_ntpenable;
//timing
#define TIMING_SETTING_COUNT 6
enum TIMING_SETTINGS {
TIMING_MENU = 0,
TIMING_CHANLIST = 1,
TIMING_EPG = 2,
TIMING_INFOBAR = 3,
TIMING_FILEBROWSER = 4,
TIMING_NUMERICZAP = 5
};
int timing [TIMING_SETTING_COUNT] ;
char timing_string[TIMING_SETTING_COUNT][4];
//widget settings
int widget_fade;
//colors
unsigned char gtx_alpha1;
unsigned char gtx_alpha2;
unsigned char menu_Head_alpha;
unsigned char menu_Head_red;
unsigned char menu_Head_green;
unsigned char menu_Head_blue;
unsigned char menu_Head_Text_alpha;
unsigned char menu_Head_Text_red;
unsigned char menu_Head_Text_green;
unsigned char menu_Head_Text_blue;
unsigned char menu_Content_alpha;
unsigned char menu_Content_red;
unsigned char menu_Content_green;
unsigned char menu_Content_blue;
unsigned char menu_Content_Text_alpha;
unsigned char menu_Content_Text_red;
unsigned char menu_Content_Text_green;
unsigned char menu_Content_Text_blue;
unsigned char menu_Content_Selected_alpha;
unsigned char menu_Content_Selected_red;
unsigned char menu_Content_Selected_green;
unsigned char menu_Content_Selected_blue;
unsigned char menu_Content_Selected_Text_alpha;
unsigned char menu_Content_Selected_Text_red;
unsigned char menu_Content_Selected_Text_green;
unsigned char menu_Content_Selected_Text_blue;
unsigned char menu_Content_inactive_alpha;
unsigned char menu_Content_inactive_red;
unsigned char menu_Content_inactive_green;
unsigned char menu_Content_inactive_blue;
unsigned char menu_Content_inactive_Text_alpha;
unsigned char menu_Content_inactive_Text_red;
unsigned char menu_Content_inactive_Text_green;
unsigned char menu_Content_inactive_Text_blue;
unsigned char infobar_alpha;
unsigned char infobar_red;
unsigned char infobar_green;
unsigned char infobar_blue;
unsigned char infobar_Text_alpha;
unsigned char infobar_Text_red;
unsigned char infobar_Text_green;
unsigned char infobar_Text_blue;
//network
#define NETWORK_NFS_NR_OF_ENTRIES 8
std::string network_nfs_ip[NETWORK_NFS_NR_OF_ENTRIES];
char network_nfs_mac[NETWORK_NFS_NR_OF_ENTRIES][31];
char network_nfs_local_dir[NETWORK_NFS_NR_OF_ENTRIES][100];
char network_nfs_dir[NETWORK_NFS_NR_OF_ENTRIES][100];
int network_nfs_automount[NETWORK_NFS_NR_OF_ENTRIES];
char network_nfs_mount_options1[NETWORK_NFS_NR_OF_ENTRIES][31];
char network_nfs_mount_options2[NETWORK_NFS_NR_OF_ENTRIES][31];
int network_nfs_type[NETWORK_NFS_NR_OF_ENTRIES];
char network_nfs_username[NETWORK_NFS_NR_OF_ENTRIES][31];
char network_nfs_password[NETWORK_NFS_NR_OF_ENTRIES][31];
char network_nfs_audioplayerdir[100];
char network_nfs_picturedir[100];
char network_nfs_moviedir[100];
char network_nfs_recordingdir[100];
char timeshiftdir[100];
//recording
int recording_type;
int recording_stopplayback;
int recording_stopsectionsd;
std::string recording_server_ip;
char recording_server_port[10];
int recording_server_wakeup;
char recording_server_mac[31];
int recording_vcr_no_scart;
char recording_splitsize[10];
int recording_use_o_sync;
int recording_use_fdatasync;
unsigned char recording_audio_pids_default;
int recording_audio_pids_std;
int recording_audio_pids_alt;
int recording_audio_pids_ac3;
int recording_stream_vtxt_pid;
int recording_stream_pmt_pid;
char recording_ringbuffers[10];
int recording_choose_direct_rec_dir;
int recording_epg_for_filename;
int recording_save_in_channeldir;
int recording_in_spts_mode;
int recording_zap_on_announce;
//streaming
int streaming_type;
std::string streaming_server_ip;
char streaming_server_port[10];
char streaming_server_cddrive[21];
char streaming_videorate[6];
char streaming_audiorate[6];
char streaming_server_startdir[40];
int streaming_transcode_audio;
int streaming_force_avi_rawaudio;
int streaming_force_transcode_video;
int streaming_transcode_video_codec;
int streaming_resolution;
int filesystem_is_utf8;
// default plugin for ts-movieplayer (red button)
std::string movieplayer_plugin;
std::string onekey_plugin;
//key configuration
int key_tvradio_mode;
int key_channelList_pageup;
int key_channelList_pagedown;
int key_channelList_cancel;
int key_channelList_sort;
int key_channelList_addrecord;
int key_channelList_addremind;
int key_quickzap_up;
int key_quickzap_down;
int key_bouquet_up;
int key_bouquet_down;
int key_subchannel_up;
int key_subchannel_down;
int key_zaphistory;
int key_lastchannel;
int key_list_start;
int key_list_end;
int menu_left_exit;
int audio_run_player;
int key_click;
int timeshift_pause;
int auto_timeshift;
int temp_timeshift;
int auto_delete;
int record_hours;
int mpkey_rewind;
int mpkey_forward;
int mpkey_pause;
int mpkey_stop;
int mpkey_play;
int mpkey_audio;
int mpkey_time;
int mpkey_bookmark;
int mpkey_plugin;
int key_timeshift;
int key_plugin;
int rf_subcarrier;
int rf_soundenable;
int rf_channel;
int rf_finetune;
int rf_standby;
int key_unlock;
int cacheTXT;
int minimode;
int mode_clock;
int virtual_zap_mode;
int spectrum;
int pip_width;
int pip_height;
int pip_x;
int pip_y;
int bigFonts;
int channellist_epgtext_align_right;
int channellist_extended;
char repeat_blocker[4];
char repeat_genericblocker[4];
int audiochannel_up_down_enable;
//screen configuration
int screen_StartX;
int screen_StartY;
int screen_EndX;
int screen_EndY;
int screen_width;
int screen_height;
//Software-update
int softupdate_mode;
char softupdate_url_file[31];
char softupdate_proxyserver[31];
char softupdate_proxyusername[31];
char softupdate_proxypassword[31];
//BouquetHandling
int bouquetlist_mode;
// parentallock
int parentallock_prompt;
int parentallock_lockage;
char parentallock_pincode[5];
// Font sizes
#define FONT_TYPE_COUNT 22
enum FONT_TYPES {
FONT_TYPE_MENU = 0,
FONT_TYPE_MENU_TITLE = 1,
FONT_TYPE_MENU_INFO = 2,
FONT_TYPE_EPG_TITLE = 3,
FONT_TYPE_EPG_INFO1 = 4,
FONT_TYPE_EPG_INFO2 = 5,
FONT_TYPE_EPG_DATE = 6,
FONT_TYPE_EVENTLIST_TITLE = 7,
FONT_TYPE_EVENTLIST_ITEMLARGE = 8,
FONT_TYPE_EVENTLIST_ITEMSMALL = 9,
FONT_TYPE_EVENTLIST_DATETIME = 10,
FONT_TYPE_GAMELIST_ITEMLARGE = 11,
FONT_TYPE_GAMELIST_ITEMSMALL = 12,
FONT_TYPE_CHANNELLIST = 13,
FONT_TYPE_CHANNELLIST_DESCR = 14,
FONT_TYPE_CHANNELLIST_NUMBER = 15,
FONT_TYPE_CHANNEL_NUM_ZAP = 16,
FONT_TYPE_INFOBAR_NUMBER = 17,
FONT_TYPE_INFOBAR_CHANNAME = 18,
FONT_TYPE_INFOBAR_INFO = 19,
FONT_TYPE_INFOBAR_SMALL = 20,
FONT_TYPE_FILEBROWSER_ITEM = 21
};
// lcdd
#define LCD_SETTING_COUNT 7
enum LCD_SETTINGS {
LCD_BRIGHTNESS = 0,
LCD_STANDBY_BRIGHTNESS = 1,
LCD_CONTRAST = 2,
LCD_POWER = 3,
LCD_INVERSE = 4,
LCD_SHOW_VOLUME = 5,
LCD_AUTODIMM = 6,
};
int lcd_setting[LCD_SETTING_COUNT];
char lcd_setting_dim_time[4];
char lcd_setting_dim_brightness[4];
#define FILESYSTEM_ENCODING_TO_UTF8(a) (g_settings.filesystem_is_utf8 ? (a) : ZapitTools::Latin1_to_UTF8(a).c_str())
#define UTF8_TO_FILESYSTEM_ENCODING(a) (g_settings.filesystem_is_utf8 ? (a) : ZapitTools::UTF8_to_Latin1(a).c_str())
#define FILESYSTEM_ENCODING_TO_UTF8_STRING(a) (g_settings.filesystem_is_utf8 ? (a) : Latin1_to_UTF8(a))
#if HAVE_DVB_API_VERSION == 1
#define MISC_SETTING_FILES_COUNT 7
#else
#define MISC_SETTING_FILES_COUNT 4
#endif
// #define MISC_SETTING_SPTS_MODE 0
int misc_option[MISC_SETTING_FILES_COUNT];
// pictureviewer
char picviewer_slide_time[3];
int picviewer_scaling;
std::string picviewer_decode_server_ip;
char picviewer_decode_server_port[6];
//audioplayer
int audioplayer_display;
int audioplayer_follow;
char audioplayer_screensaver[3];
int audioplayer_highprio;
int audioplayer_select_title_by_name;
int audioplayer_repeat_on;
int audioplayer_show_playlist;
int audioplayer_enable_sc_metadata;
//Filebrowser
int filebrowser_showrights;
int filebrowser_sortmethod;
int filebrowser_denydirectoryleave;
//uboot
int uboot_lcd_inverse;
int uboot_lcd_contrast;
int uboot_console;
int uboot_console_bak;
int power_standby;
int emlog;
int rotor_swap;
int ts_mode;
int hw_sect;
int hdd_sleep;
int hdd_noise;
int hdd_fs;
int logo_num;
int zap_cycle;
int sms_channel;
char font_file[100];
char update_dir[100];
// USERMENU
typedef enum
{
BUTTON_RED = 0, // Do not change ordering of members, add new item just before BUTTON_MAX!!!
BUTTON_GREEN = 1,
BUTTON_YELLOW = 2,
BUTTON_BLUE = 3,
BUTTON_MAX // MUST be always the last in the list
}USER_BUTTON;
typedef enum
{
ITEM_NONE = 0, // Do not change ordering of members, add new item just before ITEM_MAX!!!
ITEM_BAR = 1,
ITEM_EPG_LIST = 2,
ITEM_EPG_SUPER = 3,
ITEM_EPG_INFO = 4,
ITEM_EPG_MISC = 5,
ITEM_AUDIO_SELECT = 6,
ITEM_SUBCHANNEL = 7,
ITEM_RECORD = 8,
ITEM_MOVIEPLAYER_MB = 9,
ITEM_TIMERLIST = 10,
ITEM_REMOTE = 11,
ITEM_FAVORITS = 12,
ITEM_TECHINFO = 13,
ITEM_PLUGIN = 14,
ITEM_VTXT = 15,
#if 0
ITEM_MOVIEPLAYER_TS = 16,
ITEM_RESTART_CAMD = 17,
#endif
ITEM_MAX // MUST be always the last in the list
}USER_ITEM;
std::string usermenu_text[BUTTON_MAX];
int usermenu[BUTTON_MAX][ITEM_MAX]; // (USER_ITEM) [button][position in Menue] = feature item
};
/* some default Values */
extern const int default_timing [TIMING_SETTING_COUNT];
extern const neutrino_locale_t timing_setting_name[TIMING_SETTING_COUNT];
// lcdd
#define DEFAULT_VFD_BRIGHTNESS 15
#define DEFAULT_VFD_STANDBYBRIGHTNESS 5
#define DEFAULT_LCD_BRIGHTNESS 0xff
#define DEFAULT_LCD_STANDBYBRIGHTNESS 0xaa
#define DEFAULT_LCD_CONTRAST 0x0F
#define DEFAULT_LCD_POWER 0x01
#define DEFAULT_LCD_INVERSE 0x00
#define DEFAULT_LCD_AUTODIMM 0x00
#define DEFAULT_LCD_SHOW_VOLUME 0x01
#define CORNER_RADIUS_LARGE 12
#define CORNER_RADIUS_MID 9
#define CORNER_RADIUS_SMALL 4
#define RADIUS_LARGE (g_settings.rounded_corners ? CORNER_RADIUS_LARGE : 0)
#define RADIUS_MID (g_settings.rounded_corners ? CORNER_RADIUS_MID : 0)
#define RADIUS_SMALL (g_settings.rounded_corners ? CORNER_RADIUS_SMALL : 0)
/* end default values */
struct SglobalInfo
{
unsigned char box_Type;
delivery_system_t delivery_system;
};
const int RECORDING_OFF = 0;
const int RECORDING_SERVER = 1;
const int RECORDING_VCR = 2;
const int RECORDING_FILE = 3;
const int PARENTALLOCK_PROMPT_NEVER = 0;
const int PARENTALLOCK_PROMPT_ONSTART = 1;
const int PARENTALLOCK_PROMPT_CHANGETOLOCKED = 2;
const int PARENTALLOCK_PROMPT_ONSIGNAL = 3;
#define MAX_SATELLITES 80
class CScanSettings
{
public:
CConfigFile configfile;
int bouquetMode;
int scanType;
int diseqcMode;
uint32_t diseqcRepeat;
char satNameNoDiseqc[50];
delivery_system_t delivery_system;
int scanSectionsd;
int scan_mode;
int TP_fec;
int TP_pol;
int TP_mod;
char TP_freq[10];
char TP_rate[9];
CScanSettings();
void toSatList( CZapitClient::ScanSatelliteList& ) const;
void useDefaults(const delivery_system_t _delivery_system);
bool loadSettings(const char * const fileName, const delivery_system_t _delivery_system);
bool saveSettings(const char * const fileName);
};
#endif

7
src/system/timer.cpp Normal file
View File

@@ -0,0 +1,7 @@
/*
* wegen doppeltentwicklung wieder entfernt.
* die thread-Loesung fliegt raus - das Modul wird durch dirch als timerd
* implementiert werden - rasc
* Grund: Neutrino arbeitet nicht mit internen threaded Klassen, sondern
* ueber externe daemons.
*/

7
src/system/timer.h Normal file
View File

@@ -0,0 +1,7 @@
/*
* wegen doppeltentwicklung wieder entfernt.
* die thread-Loesung fliegt raus - das Modul wird durch dirch als timerd
* implementiert werden - rasc
* Grund: Neutrino arbeitet nicht mit internen threaded Klassen, sondern
* ueber externe daemons.
*/