From 6a23a1c36a34cdd757763190a11f0971a61c36bb Mon Sep 17 00:00:00 2001 From: defans Date: Mon, 29 Dec 2014 21:06:18 +0100 Subject: [PATCH] CScreenSaver: add class CScreenSaver --- src/gui/Makefile.am | 1 + src/gui/audioplayer.cpp | 33 +------ src/gui/audioplayer.h | 1 - src/gui/screensaver.cpp | 193 ++++++++++++++++++++++++++++++++++++++++ src/gui/screensaver.h | 55 ++++++++++++ src/neutrino.cpp | 6 ++ src/system/settings.h | 3 + 7 files changed, 262 insertions(+), 30 deletions(-) create mode 100644 src/gui/screensaver.cpp create mode 100644 src/gui/screensaver.h diff --git a/src/gui/Makefile.am b/src/gui/Makefile.am index 8b78680cd..4133761b9 100644 --- a/src/gui/Makefile.am +++ b/src/gui/Makefile.am @@ -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 \ diff --git a/src/gui/audioplayer.cpp b/src/gui/audioplayer.cpp index caf99d898..08cefc6ca 100644 --- a/src/gui/audioplayer.cpp +++ b/src/gui/audioplayer.cpp @@ -65,7 +65,7 @@ #include #include #include - +#include #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"); diff --git a/src/gui/audioplayer.h b/src/gui/audioplayer.h index 17f8fca92..073bf7b65 100644 --- a/src/gui/audioplayer.h +++ b/src/gui/audioplayer.h @@ -140,7 +140,6 @@ class CAudioPlayerGui : public CMenuTarget int m_idletime; bool m_screensaver; bool m_inetmode; - uint32_t stimer; CComponentsDetailLine *dline; CComponentsInfoBox *ibox; diff --git a/src/gui/screensaver.cpp b/src/gui/screensaver.cpp new file mode 100644 index 000000000..12208cbb8 --- /dev/null +++ b/src/gui/screensaver.cpp @@ -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 . +*/ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // std::sort +#include +#include "audiomute.h" +#include "screensaver.h" + +#include +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(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; +} diff --git a/src/gui/screensaver.h b/src/gui/screensaver.h new file mode 100644 index 000000000..87c0ec02c --- /dev/null +++ b/src/gui/screensaver.h @@ -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 . +*/ + +#ifndef __CSCREENSAVER_H__ +#define __CSCREENSAVER_H__ + +#include +#include +#include + +using namespace std; + +class CScreenSaver +{ + private: + CFrameBuffer *m_frameBuffer; + pthread_t thrScreenSaver; + static void* ScreenSaverPrg(void *arg); + vector v_bg_files; + unsigned int index; + + bool ReadDir(); + void PaintPicture(); + + public: + CScreenSaver(); + ~CScreenSaver(); + static CScreenSaver* getInstance(); + + void Start(); + void Stop(); +}; + +#endif // __CSCREENSAVER_H__ diff --git a/src/neutrino.cpp b/src/neutrino.cpp index 5fde3e832..1040eb66f 100644 --- a/src/neutrino.cpp +++ b/src/neutrino.cpp @@ -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 ); diff --git a/src/system/settings.h b/src/system/settings.h index 957ec06b6..5ce10bd09 100644 --- a/src/system/settings.h +++ b/src/system/settings.h @@ -206,6 +206,9 @@ struct SNeutrinoSettings int radiotext_enable; int easymenu; + //screen saver + std::string screensaver_dir; + //vcr int vcr_AutoSwitch;