bool CExtUpdate::applySettings(std::string & filename, int mode) { if(!FileHelpers) FileHelpers = new CFileHelpers(); if (mode == MODE_EXPERT) imgFilename = (std::string)g_settings.update_dir + "/" + FILESYSTEM_ENCODING_TO_UTF8_STRING(filename); else imgFilename = FILESYSTEM_ENCODING_TO_UTF8_STRING(filename); DBG_TIMER_START() std::string oldFilename = imgFilename; std::string hostName = netGetHostname(); std::string orgPath = getPathName(imgFilename); std::string orgName = getBaseName(imgFilename); orgName = getFileName(orgName); std::string orgExt = "." + getFileExt(imgFilename); std::string timeStr = getNowTimeStr("_%Y%m%d_%H%M"); std::string settingsStr = "+settings"; if (orgPath != "/tmp") { if (g_settings.softupdate_name_mode_apply == CExtUpdate::SOFTUPDATE_NAME_HOSTNAME_TIME) imgFilename = orgPath + "/" + hostName + timeStr + settingsStr + orgExt; else if (g_settings.softupdate_name_mode_apply == CExtUpdate::SOFTUPDATE_NAME_ORGNAME_TIME) imgFilename = orgPath + "/" + orgName + timeStr + settingsStr + orgExt; else imgFilename = orgPath + "/" + orgName + settingsStr + orgExt; FileHelpers->copyFile(oldFilename.c_str(), imgFilename.c_str(), 0644); } else imgFilename = oldFilename; filename = imgFilename; bool ret = applySettings(); DBG_TIMER_STOP("Image editing") if (!ret) { if ((mtdRamError != "") && (!flashErrorFlag)) DisplayErrorMessage(mtdRamError.c_str()); // error, delete image file unlink(imgFilename.c_str()); } else { if (mode == MODE_EXPERT) { if ((mtdNumber < 3) || (mtdNumber > 4)) { const char *err = "invalid mtdNumber\n"; printf(err); DisplayErrorMessage(err); WRITE_UPDATE_LOG("ERROR: %s", err); return false; } } WRITE_UPDATE_LOG("\n"); WRITE_UPDATE_LOG("##### Settings taken. #####\n"); if (mode == MODE_EXPERT) CFlashExpert::getInstance()->writemtd(filename, mtdNumber); } return ret; }
std::string CMTDInfo::getMTDName(const int pos) { // TODO: check /proc/mtd specification to determine mtdname encoding if (pos >= 0) return FILESYSTEM_ENCODING_TO_UTF8_STRING(mtdData[pos]->name); return ""; }
void CFileBrowser::paintHead() { char l_name[100]; frameBuffer->paintBoxRel(x,y, width,theight+0, COL_MENUHEAD_PLUS_0, RADIUS_MID, CORNER_TOP); #ifdef ENABLE_INTERNETRADIO if(m_Mode == ModeSC) snprintf(l_name, sizeof(l_name), "%s %s", g_Locale->getText(LOCALE_AUDIOPLAYER_ADD_SC), FILESYSTEM_ENCODING_TO_UTF8_STRING(name).c_str()); // UTF-8 else #endif snprintf(l_name, sizeof(l_name), "%s %s", g_Locale->getText(LOCALE_FILEBROWSER_HEAD), FILESYSTEM_ENCODING_TO_UTF8_STRING(name).c_str()); // UTF-8 g_Font[SNeutrinoSettings::FONT_TYPE_EVENTLIST_TITLE]->RenderString(x+10,y+theight+1, width-11, l_name, COL_MENUHEAD, 0, true); // UTF-8 }
void CFileBrowser::paintItem(unsigned int pos) { int colwidth1, colwidth2, colwidth3, colwidth1_dir, colwidth2_dir; int c_rad_small; uint8_t color; fb_pixel_t bgcolor; int ypos = y+ theight+0 + pos*fheight; CFile * actual_file = NULL; std::string fileicon; colwidth2_dir = 180; colwidth1_dir = width - 35 - colwidth2_dir - 10; if (liststart + pos == selected) { color = COL_MENUCONTENTSELECTED; bgcolor = COL_MENUCONTENTSELECTED_PLUS_0; c_rad_small = RADIUS_SMALL; // paintFoot(); } else { color = COL_MENUCONTENT;//DARK; bgcolor = COL_MENUCONTENT_PLUS_0;//DARK; c_rad_small = 0; } if( (liststart + pos) < filelist.size() ) { actual_file = &filelist[liststart+pos]; if (actual_file->Marked) { color = COL_MENUCONTENTINACTIVE; //+= 2; FIXME bgcolor = (liststart + pos == selected) ? COL_MENUCONTENTSELECTED_PLUS_2 : COL_MENUCONTENT_PLUS_2; } if (g_settings.filebrowser_showrights == 0 && S_ISREG(actual_file->Mode)) { colwidth2 = 0; colwidth3 = 90; } else { colwidth2 = 90; colwidth3 = 90; } colwidth1 = width - 35 - colwidth2 - colwidth3 - 10; frameBuffer->paintBoxRel(x,ypos, width- 15, fheight, bgcolor, c_rad_small); if ( actual_file->Name.length() > 0 ) { if (liststart+pos==selected) CVFD::getInstance()->showMenuText(0, FILESYSTEM_ENCODING_TO_UTF8_STRING(actual_file->getFileName()).c_str(), -1, true); // UTF-8 switch(actual_file->getType()) { case CFile::FILE_CDR: case CFile::FILE_MP3: case CFile::FILE_OGG: case CFile::FILE_WAV: #ifdef ENABLE_FLAC case CFile::FILE_FLAC: #endif fileicon = "mp3.raw"; // color = COL_MENUCONTENT; break; case CFile::FILE_DIR: fileicon = "folder.raw"; break; case CFile::FILE_PICTURE: case CFile::FILE_TEXT: default: fileicon = "file.raw"; } frameBuffer->paintIcon(fileicon, x+5 , ypos + (fheight-16) / 2 ); g_Font[SNeutrinoSettings::FONT_TYPE_FILEBROWSER_ITEM]->RenderString(x + 35, ypos + fheight, colwidth1 - 10 , FILESYSTEM_ENCODING_TO_UTF8_STRING(actual_file->getFileName()), color, 0, true); // UTF-8 if( S_ISREG(actual_file->Mode) ) { if (g_settings.filebrowser_showrights != 0) { const char * attribute = "xwr"; char modestring[9 + 1]; for (int m = 8; m >= 0; m--) { modestring[8 - m] = (actual_file->Mode & (1 << m)) ? attribute[m % 3] : '-'; } modestring[9] = 0; g_Font[SNeutrinoSettings::FONT_TYPE_FILEBROWSER_ITEM]->RenderString(x + 35 + colwidth1 , ypos+ fheight, colwidth2 - 10, modestring, color, 0, true); // UTF-8 } #define GIGABYTE 1073741824LL #define MEGABYTE 1048576LL #define KILOBYTE 1024LL char tmpstr[256]; const char *unit = ""; long long factor = 0; if (actual_file->Size >= GIGABYTE) { factor = GIGABYTE; unit = "G"; } else if (actual_file->Size >= MEGABYTE) { factor = MEGABYTE; unit = "M"; } else if (actual_file->Size >= KILOBYTE) { factor = KILOBYTE; unit = "k"; } if (factor) { int a = actual_file->Size / factor; int b = (actual_file->Size - a * factor) * 1000 / factor; snprintf(tmpstr, sizeof(tmpstr), "%d.%03d%s", a, b, unit); } else snprintf(tmpstr,sizeof(tmpstr),"%d", (int)actual_file->Size); g_Font[SNeutrinoSettings::FONT_TYPE_FILEBROWSER_ITEM]->RenderString(x + 35 + colwidth1 + colwidth2, ypos+ fheight, colwidth3 - 10, tmpstr, color); } if( S_ISDIR(actual_file->Mode) ) { char timestring[18]; time_t rawtime; rawtime = actual_file->Time; strftime(timestring, 18, "%d-%m-%Y %H:%M", gmtime(&rawtime)); g_Font[SNeutrinoSettings::FONT_TYPE_FILEBROWSER_ITEM]->RenderString(x + 35 + colwidth1_dir, ypos+ fheight, colwidth2_dir - 10, timestring, color); } } } else frameBuffer->paintBoxRel(x,ypos, width- 15, fheight, COL_MENUCONTENT_PLUS_0/*DARK*/); }
void CFileBrowser::addRecursiveDir(CFileList * re_filelist, std::string rpath, bool bRootCall, CProgressWindow * progress) { neutrino_msg_t msg; neutrino_msg_data_t data; int n; //printf("addRecursiveDir %s\n",rpath.c_str()); if (bRootCall) bCancel=false; g_RCInput->getMsg_us(&msg, &data, 1); if (msg==CRCInput::RC_home) { // home key cancel scan bCancel=true; } else if (msg!=CRCInput::RC_timeout) { // other event, save to low priority queue g_RCInput->postMsg( msg, data, false ); } if(bCancel) return; if ((m_Mode != ModeSC) && ((rpath.empty()) || ((*rpath.rbegin()) != '/'))) { rpath += '/'; } CFileList tmplist; if(!readDir(rpath, &tmplist)) { perror(("Recursive scandir: "+rpath).c_str()); } else { n = tmplist.size(); if(progress) { progress->showStatusMessageUTF(FILESYSTEM_ENCODING_TO_UTF8_STRING(rpath)); } for(int i = 0; i < n;i++) { if(progress) { progress->showGlobalStatus(100/n*i); } std::string basename = tmplist[i].Name.substr(tmplist[i].Name.rfind('/')+1); if( basename != ".." ) { if(Filter != NULL && (!S_ISDIR(tmplist[i].Mode)) && use_filter) { if(!Filter->matchFilter(tmplist[i].Name)) { continue; } } if(!S_ISDIR(tmplist[i].Mode)) re_filelist->push_back(tmplist[i]); else addRecursiveDir(re_filelist,tmplist[i].Name, false, progress); } } } }
int CPictureViewerGui::show() { neutrino_msg_t msg; neutrino_msg_data_t data; int res = -1; CLCD::getInstance()->setMode(CLCD::MODE_MENU_UTF8, g_Locale->getText(LOCALE_PICTUREVIEWER_HEAD)); m_state = MENU; int timeout; bool loop = true; bool update = true; while (loop) { if (update) { hide(); update = false; paint(); } if (m_state != SLIDESHOW) timeout = 50; // egal else { timeout = (m_time + atoi(g_settings.picviewer_slide_time) - (long)time(NULL))*10; if (timeout < 0) timeout = 1; } g_RCInput->getMsg(&msg, &data, timeout); neutrino_msg_t msg_repeatok = msg & ~CRCInput::RC_Repeat; if (msg == CRCInput::RC_home) { //Exit after cancel key if (m_state != MENU) { endView(); update = true; } else loop = false; } else if (msg == CRCInput::RC_timeout) { if (m_state == SLIDESHOW) { m_time = (long)time(NULL); unsigned int next = selected + 1; if (next >= playlist.size()) next = 0; view(next); } } else if (msg == CRCInput::RC_left) { if (!playlist.empty()) { if (m_state == MENU) { if (selected < listmaxshow) selected = playlist.size()-1; else selected -= listmaxshow; liststart = (selected / listmaxshow) * listmaxshow; paint(); } else { view((selected == 0) ? (playlist.size() - 1) : (selected - 1)); } } } else if (msg == CRCInput::RC_right) { if (!playlist.empty()) { if (m_state == MENU) { selected += listmaxshow; if (selected >= playlist.size()) if (((playlist.size() / listmaxshow) + 1) * listmaxshow == playlist.size() + listmaxshow) selected = 0; else selected = selected < (((playlist.size() / listmaxshow) + 1) * listmaxshow) ? (playlist.size() - 1) : 0; liststart = (selected / listmaxshow) * listmaxshow; paint(); } else { unsigned int next = selected + 1; if (next >= playlist.size()) next = 0; view(next); } } } else if (msg_repeatok == CRCInput::RC_up || msg_repeatok == CRCInput::RC_down) { if ((m_state == MENU) && (!playlist.empty())) { int prevselected = selected; int direction = (msg_repeatok == CRCInput::RC_up) ? -1 : 1; selected = (selected + playlist.size() + direction) % playlist.size(); unsigned int oldliststart = liststart; liststart = (selected / listmaxshow) * listmaxshow; if (oldliststart != liststart) { update = true; } else { paintItem(prevselected - liststart); paintItem(selected - liststart); } } } else if (msg == CRCInput::RC_ok) { if (!playlist.empty()) view(selected); } else if (msg == CRCInput::RC_red) { if (m_state == MENU) { if (!playlist.empty()) { CViewList::iterator p = playlist.begin() + selected; playlist.erase(p); if (selected >= playlist.size()) selected = playlist.empty() ? 0 : playlist.size() - 1; update = true; } } else if (m_state == SLIDESHOW) { m_state = VIEW; } } else if (msg == CRCInput::RC_green) { if (m_state == MENU) { CFileBrowser filebrowser((g_settings.filebrowser_denydirectoryleave) ? g_settings.picviewer_picturedir : ""); filebrowser.Multi_Select = true; filebrowser.Dirs_Selectable = true; filebrowser.Filter = &picture_filter; hide(); if (filebrowser.exec(Path.c_str())) { Path = filebrowser.getCurrentDir(); CFileList::const_iterator files = filebrowser.getSelectedFiles().begin(); for(; files != filebrowser.getSelectedFiles().end(); ++files) { if(files->getType() == CFile::FILE_PICTURE) { CPicture pic; pic.Filename = files->Name; std::string tmp = files->Name.substr(files->Name.rfind('/')+1); tmp = FILESYSTEM_ENCODING_TO_UTF8_STRING(tmp); pic.Name = tmp.substr(0,tmp.rfind('.')); pic.Type = tmp.substr(tmp.rfind('.')+1); struct stat statbuf; if(stat(pic.Filename.c_str(),&statbuf) != 0) fprintf(stderr, "stat '%s' error: %m\n", pic.Filename.c_str()); pic.Date = statbuf.st_mtime; playlist.push_back(pic); } else printf("Wrong Filetype %s:%d\n",files->Name.c_str(), files->getType()); } if (m_sort == FILENAME) std::sort(playlist.begin(), playlist.end(), comparePictureByFilename); else if (m_sort == DATE) std::sort(playlist.begin(), playlist.end(), comparePictureByDate); } update = true; CLCD::getInstance()->setMode(CLCD::MODE_MENU_UTF8, g_Locale->getText(LOCALE_PICTUREVIEWER_HEAD)); } } else if (msg == CRCInput::RC_yellow) { if (m_state == MENU && !playlist.empty()) { playlist.clear(); selected = 0; update = true; } } else if (msg == CRCInput::RC_blue) { if ((m_state == MENU || m_state == VIEW) && (!playlist.empty())) { m_time = (long)time(NULL); view(selected); m_state=SLIDESHOW; } } else if (msg == CRCInput::RC_help) { if (m_state == MENU) { showHelp(); paint(); } } else if (msg == CRCInput::RC_1) { if (m_state != MENU) m_viewer->Zoom(200/3); } else if (msg == CRCInput::RC_2) { if (m_state != MENU) m_viewer->Move(0,-50); } else if (msg == CRCInput::RC_3) { if (m_state != MENU) m_viewer->Zoom(150); } else if (msg == CRCInput::RC_4) { if (m_state != MENU) m_viewer->Move(-50,0); } else if (msg == CRCInput::RC_5) { if (!playlist.empty()) { if (m_sort == FILENAME) { m_sort=DATE; std::sort(playlist.begin(),playlist.end(),comparePictureByDate); } else if (m_sort==DATE) { m_sort=FILENAME; std::sort(playlist.begin(),playlist.end(),comparePictureByFilename); } update = true; } } else if (msg == CRCInput::RC_6) { if (m_state != MENU) m_viewer->Move(50,0); } else if (msg == CRCInput::RC_8) { if (m_state != MENU) m_viewer->Move(0,50); } else if (msg == CRCInput::RC_0) { if (!playlist.empty()) view(selected, true); } #ifdef ENABLE_GUI_MOUNT else if (msg == CRCInput::RC_setup) { if (m_state == MENU) { CNFSSmallMenu nfsMenu; nfsMenu.exec(this, ""); update = true; CLCD::getInstance()->setMode(CLCD::MODE_MENU_UTF8, g_Locale->getText(LOCALE_PICTUREVIEWER_HEAD)); } } #endif else if (msg == NeutrinoMessages::CHANGEMODE) { if ((data & NeutrinoMessages::mode_mask) != NeutrinoMessages::mode_pic) { loop = false; m_LastMode = data; } } else if (msg == NeutrinoMessages::RECORD_START || msg == NeutrinoMessages::ZAPTO || msg == NeutrinoMessages::STANDBY_ON || msg == NeutrinoMessages::SHUTDOWN || msg == NeutrinoMessages::SLEEPTIMER) { // Exit for Record/Zapto Timers if (m_state != MENU) endView(); loop = false; g_RCInput->postMsg(msg, data); } else { if (CNeutrinoApp::getInstance()->handleMsg(msg, data) & messages_return::cancel_all) { loop = false; } } } hide(); return (res); }
void CFileBrowser::paintHead() { char l_name[100]; frameBuffer->paintBoxRel(x, y, width, theight, COL_MENUHEAD_PLUS_0, RADIUS_MID, CORNER_TOP, g_settings.Head_gradient); // icon int icon_w, icon_h; frameBuffer->getIconSize(NEUTRINO_ICON_FOLDER, &icon_w, &icon_h); frameBuffer->paintIcon(NEUTRINO_ICON_FOLDER, x + BORDER_LEFT, y + (theight - icon_h)/2); snprintf(l_name, sizeof(l_name), "%s %s", g_Locale->getText(LOCALE_FILEBROWSER_HEAD), FILESYSTEM_ENCODING_TO_UTF8_STRING(name).c_str()); // UTF-8 g_Font[SNeutrinoSettings::FONT_TYPE_EVENTLIST_TITLE]->RenderString(x + BORDER_LEFT + icon_w + ICON_OFFSET, y + theight + 1, width - BORDER_LEFT - icon_w - ICON_OFFSET - BORDER_RIGHT, l_name, COL_MENUHEAD, 0, true); // UTF-8 }
void CFileBrowser::paintItem(unsigned int pos) { int colwidth1, colwidth2, colwidth3, colwidth1_dir, colwidth2_dir; uint8_t color; fb_pixel_t bgcolor; int ypos = y + theight + pos*fheight; CFile * actual_file = NULL; std::string fileicon; colwidth2_dir = 180; colwidth1_dir = width - 35 - colwidth2_dir - 10; if (liststart + pos == selected) { color = COL_MENUCONTENTSELECTED; bgcolor = COL_MENUCONTENTSELECTED_PLUS_0; } else { color = COL_MENUCONTENT;//DARK; bgcolor = COL_MENUCONTENT_PLUS_0;//DARK; } if( (liststart + pos) < filelist.size() ) { actual_file = &filelist[liststart + pos]; if (actual_file->Marked) { color = COL_MENUCONTENTINACTIVE; bgcolor = (liststart + pos == selected) ? COL_MENUCONTENTSELECTED_PLUS_2 : COL_MENUCONTENT_PLUS_2; } if (g_settings.filebrowser_showrights == 0 && S_ISREG(actual_file->Mode)) { colwidth2 = 0; colwidth3 = 90; } else { colwidth2 = 90; colwidth3 = 90; } colwidth1 = width - 35 - colwidth2 - colwidth3 - 10; frameBuffer->paintBoxRel(x, ypos, width - SCROLLBAR_WIDTH, fheight, bgcolor); if ( actual_file->Name.length() > 0 ) { if (liststart + pos == selected) CVFD::getInstance()->showMenuText(0, FILESYSTEM_ENCODING_TO_UTF8_STRING(actual_file->getFileName()).c_str(), -1, true); // UTF-8 switch(actual_file->getType()) { case CFile::FILE_AUDIO: fileicon = NEUTRINO_ICON_MP3; break; case CFile::FILE_DIR: fileicon = NEUTRINO_ICON_FOLDER; break; case CFile::FILE_PICTURE: fileicon = NEUTRINO_ICON_PICTURE; break; case CFile::FILE_VIDEO: fileicon = NEUTRINO_ICON_MOVIE; break; case CFile::FILE_TEXT: default: fileicon = NEUTRINO_ICON_FILE; } int ih, iw; frameBuffer->getIconSize(fileicon.c_str(), &iw, &ih); frameBuffer->paintIcon(fileicon, x + ICON_OFFSET, ypos + (fheight - ih) / 2 ); g_Font[SNeutrinoSettings::FONT_TYPE_FILEBROWSER_ITEM]->RenderString(x + 30 + ICON_OFFSET, ypos + fheight, colwidth1 - BORDER_RIGHT, FILESYSTEM_ENCODING_TO_UTF8_STRING(actual_file->getFileName()), color, 0, true); // UTF-8 if( S_ISREG(actual_file->Mode) ) { if (g_settings.filebrowser_showrights != 0) { const char * attribute = "xwr"; char modestring[9 + 1]; for (int m = 8; m >= 0; m--) { modestring[8 - m] = (actual_file->Mode & (1 << m)) ? attribute[m % 3] : '-'; } modestring[9] = 0; g_Font[SNeutrinoSettings::FONT_TYPE_FILEBROWSER_ITEM]->RenderString(x + 35 + colwidth1 , ypos+ fheight, colwidth2 - 10, modestring, color, 0, true); // UTF-8 } #define GIGABYTE 1073741824LL #define MEGABYTE 1048576LL #define KILOBYTE 1024LL char tmpstr[256]; const char *unit = ""; long long factor = 0; if (actual_file->Size >= GIGABYTE) { factor = GIGABYTE; unit = "G"; } else if (actual_file->Size >= MEGABYTE) { factor = MEGABYTE; unit = "M"; } else if (actual_file->Size >= KILOBYTE) { factor = KILOBYTE; unit = "k"; } if (factor) { int a = actual_file->Size / factor; int b = (actual_file->Size - a * factor) * 1000 / factor; snprintf(tmpstr, sizeof(tmpstr), "%d.%03d%s", a, b, unit); } else snprintf(tmpstr,sizeof(tmpstr),"%d", (int)actual_file->Size); g_Font[SNeutrinoSettings::FONT_TYPE_FILEBROWSER_ITEM]->RenderString(x + 35 + colwidth1 + colwidth2, ypos+ fheight, colwidth3 - 10, tmpstr, color); } if( S_ISDIR(actual_file->Mode) ) { char timestring[18]; time_t rawtime; rawtime = actual_file->Time; strftime(timestring, 18, "%d-%m-%Y %H:%M", gmtime(&rawtime)); g_Font[SNeutrinoSettings::FONT_TYPE_FILEBROWSER_ITEM]->RenderString(x + 35 + colwidth1_dir, ypos+ fheight, colwidth2_dir - 10, timestring, color); } } } else frameBuffer->paintBoxRel(x, ypos, width - SCROLLBAR_WIDTH, fheight, COL_MENUCONTENT_PLUS_0); }