CScreenSaver: add class CScreenSaver

This commit is contained in:
defans
2014-12-29 21:06:18 +01:00
committed by svenhoefer
parent debd7138a0
commit 6a23a1c36a
7 changed files with 262 additions and 30 deletions

View File

@@ -97,6 +97,7 @@ libneutrino_gui_a_SOURCES = \
record_setup.cpp \
scan.cpp \
scan_setup.cpp \
screensaver.cpp \
screensetup.cpp \
settings_manager.cpp \
sleeptimer.cpp \

View File

@@ -65,7 +65,7 @@
#include <gui/widget/stringinput.h>
#include <gui/widget/stringinput_ext.h>
#include <gui/widget/keyboard_input.h>
#include <gui/screensaver.h>
#include "gui/pictureviewer.h"
extern CPictureViewer * g_PicViewer;
@@ -172,7 +172,6 @@ CAudioPlayerGui::CAudioPlayerGui(bool inetmode)
void CAudioPlayerGui::Init(void)
{
stimer = 0;
m_selected = 0;
m_metainfo.clear();
@@ -329,8 +328,6 @@ int CAudioPlayerGui::show()
neutrino_msg_t msg;
neutrino_msg_data_t data;
int pic_index = 0;
int ret = menu_return::RETURN_REPAINT;
// clear whole screen
@@ -378,28 +375,8 @@ int CAudioPlayerGui::show()
{
int timeout = time(NULL) - m_idletime;
int screensaver_timeout = g_settings.audioplayer_screensaver;
if (screensaver_timeout !=0 && timeout > screensaver_timeout*60 && !m_screensaver)
if (screensaver_timeout != 0 && timeout > screensaver_timeout*60 && !m_screensaver)
screensaver(true);
if (msg == NeutrinoMessages::EVT_TIMER && data == stimer) {
if (m_screensaver) {
char fname[255];
sprintf(fname, "%s/mp3-%d.jpg", DATADIR "/neutrino/icons", pic_index);
int lret = access(fname, F_OK);
printf("CAudioPlayerGui::show: new pic %s: %s\n", fname, lret ? "not found" : "found");
if (lret == 0) {
pic_index++;
videoDecoder->StopPicture();
videoDecoder->ShowPicture(fname);
} else if (pic_index) {
pic_index = 0;
}
} else
pic_index = 0;
}
}
else
{
@@ -2224,18 +2201,16 @@ void CAudioPlayerGui::paintLCD()
break;
}
}
void CAudioPlayerGui::screensaver(bool on)
{
if (on)
{
m_screensaver = true;
m_frameBuffer->Clear();
stimer = g_RCInput->addTimer(10*1000*1000, false);
CScreenSaver::getInstance()->Start();
}
else
{
g_RCInput->killTimer(stimer);
CScreenSaver::getInstance()->Stop();
m_screensaver = false;
videoDecoder->StopPicture();
videoDecoder->ShowPicture(DATADIR "/neutrino/icons/mp3.jpg");

View File

@@ -140,7 +140,6 @@ class CAudioPlayerGui : public CMenuTarget
int m_idletime;
bool m_screensaver;
bool m_inetmode;
uint32_t stimer;
CComponentsDetailLine *dline;
CComponentsInfoBox *ibox;

193
src/gui/screensaver.cpp Normal file
View File

@@ -0,0 +1,193 @@
/*
Neutrino-GUI - DBoxII-Project
Copyright (C) 2001 Steffen Hehn 'McClean'
Homepage: http://dbox.cyberphoria.org/
Copyright (C) 2012-2013 defans@bluepeercrew.us
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, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#include <dirent.h>
#include <global.h>
#include <neutrino.h>
#include <pthread.h>
#include <algorithm> // std::sort
#include <ctype.h>
#include "audiomute.h"
#include "screensaver.h"
#include <video.h>
extern cVideo * videoDecoder;
CScreenSaver::CScreenSaver()
{
thrScreenSaver = 0;
m_frameBuffer = CFrameBuffer::getInstance();
index = 0;
}
CScreenSaver::~CScreenSaver()
{
if(thrScreenSaver)
pthread_cancel(thrScreenSaver);
thrScreenSaver = 0;
}
CScreenSaver* CScreenSaver::getInstance()
{
static CScreenSaver * screenSaver = NULL;
if (!screenSaver)
screenSaver = new CScreenSaver();
return screenSaver;
}
void CScreenSaver::Start()
{
CAudioMute::getInstance()->enableMuteIcon(false);
if(!thrScreenSaver)
{
//printf("[%s] %s: starting thread\n", __FILE__, __FUNCTION__);
pthread_create(&thrScreenSaver, NULL, ScreenSaverPrg, (void*) this);
pthread_detach(thrScreenSaver);
}
}
void CScreenSaver::Stop()
{
if(thrScreenSaver)
{
pthread_cancel(thrScreenSaver);
thrScreenSaver = 0;
}
if(thrScreenSaver)
pthread_cancel(thrScreenSaver);
thrScreenSaver = 0;
CAudioMute::getInstance()->enableMuteIcon(true);
}
void* CScreenSaver::ScreenSaverPrg(void* arg)
{
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0);
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
CScreenSaver * PScreenSaver = static_cast<CScreenSaver*>(arg);
PScreenSaver->ReadDir(); //TODO kill Screensaver if false
PScreenSaver->m_frameBuffer->Clear();
while(1)
{
PScreenSaver->PaintPicture();
sleep(10);
}
return 0;
}
bool CScreenSaver::ReadDir()
{
char* dir_name = (char *) g_settings.screensaver_dir.c_str();
struct dirent *dirpointer;
DIR *dir;
char curr_ext[5];
int curr_lenght;
char* p;
bool ret = false;
v_bg_files.clear();
/* open dir */
if((dir=opendir(dir_name)) == NULL) {
fprintf(stderr,"[CScreenSaver] Error opendir ...\n");
return ret;
}
/* read complete dir */
while((dirpointer=readdir(dir)) != NULL)
{
curr_lenght = strlen((*dirpointer).d_name);
string str = dir_name;
// printf("%d\n",curr_lenght);
if(curr_lenght > 4)
{
strncpy(curr_ext,(*dirpointer).d_name+(curr_lenght-4),5);
for (p = curr_ext; *p; ++p)
*p = (char)tolower(*p);
// printf("%s\n",curr_ext);
if((strcmp(".jpg",curr_ext))
//|| (strcmp(".png",curr_ext))
//|| (strcmp(".bmp",curr_ext))
)
continue;
str += "/";
str += (*dirpointer).d_name;
v_bg_files.push_back(str);
}
}
sort(v_bg_files.begin(), v_bg_files.end());
/* close pointer */
if(closedir(dir) == -1)
printf("[CScreenSaver] Error no closed %s\n", dir_name);
if(!v_bg_files.empty())
ret = true;
else
printf("[CScreenSaver] no picture found\n");
return ret;
}
void CScreenSaver::PaintPicture()
{
if(v_bg_files.empty())
return;
if( (index >= v_bg_files.size()) || (access(v_bg_files.at(index).c_str(), F_OK)) )
{
ReadDir();
index = 0;
return;
}
printf("[CScreenSaver] ShowPicture: %s\n", v_bg_files.at(index).c_str());
videoDecoder->StopPicture();
videoDecoder->ShowPicture(v_bg_files.at(index).c_str());
index++;
if(index == v_bg_files.size())
index = 0;
}

55
src/gui/screensaver.h Normal file
View File

@@ -0,0 +1,55 @@
/*
Neutrino-GUI - DBoxII-Project
Copyright (C) 2001 Steffen Hehn 'McClean'
Homepage: http://dbox.cyberphoria.org/
Copyright (C) 2012-2013 defans@bluepeercrew.us
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, see <http://www.gnu.org/licenses/>.
*/
#ifndef __CSCREENSAVER_H__
#define __CSCREENSAVER_H__
#include <driver/framebuffer.h>
#include <vector>
#include <string>
using namespace std;
class CScreenSaver
{
private:
CFrameBuffer *m_frameBuffer;
pthread_t thrScreenSaver;
static void* ScreenSaverPrg(void *arg);
vector<string> v_bg_files;
unsigned int index;
bool ReadDir();
void PaintPicture();
public:
CScreenSaver();
~CScreenSaver();
static CScreenSaver* getInstance();
void Start();
void Stop();
};
#endif // __CSCREENSAVER_H__

View File

@@ -496,6 +496,9 @@ int CNeutrinoApp::loadSetup(const char * fname)
g_settings.subs_charset = configfile.getString("subs_charset", "CP1252");
g_settings.zap_cycle = configfile.getInt32( "zap_cycle", 0 );
//screen saver
g_settings.screensaver_dir = configfile.getString("screensaver_dir", DATADIR "/neutrino/icons/");
//vcr
g_settings.vcr_AutoSwitch = configfile.getBool("vcr_AutoSwitch" , true );
@@ -1020,6 +1023,9 @@ void CNeutrinoApp::saveSetup(const char * fname)
}
configfile.setString("subs_charset", g_settings.subs_charset);
//screen saver
configfile.setString("screensaver_dir", g_settings.screensaver_dir);
//vcr
configfile.setBool("vcr_AutoSwitch" , g_settings.vcr_AutoSwitch );

View File

@@ -206,6 +206,9 @@ struct SNeutrinoSettings
int radiotext_enable;
int easymenu;
//screen saver
std::string screensaver_dir;
//vcr
int vcr_AutoSwitch;