bool CUpnpBrowserGui::selectItem(std::string id) { bool loop = true; bool endall = false; bool changed = true; bool rchanged = true; neutrino_msg_t msg; neutrino_msg_data_t data; std::vector<UPnPEntry> *entries; unsigned int index, selected, dirnum; index=0; selected=0; dirnum=0; entries=NULL; while (loop) { updateTimes(); if (rchanged) { if (entries) delete entries; entries=NULL; std::list<UPnPAttribute>attribs; std::list<UPnPAttribute>results; std::list<UPnPAttribute>::iterator i; std::stringstream sindex; std::stringstream scount; unsigned int returned = 0; bool rfound = false; bool nfound = false; bool tfound = false; sindex << index; scount << m_listmaxshow; attribs.push_back(UPnPAttribute("ObjectID", id)); attribs.push_back(UPnPAttribute("BrowseFlag", "BrowseDirectChildren")); attribs.push_back(UPnPAttribute("Filter", "*")); attribs.push_back(UPnPAttribute("StartingIndex", sindex.str())); attribs.push_back(UPnPAttribute("RequestedCount", scount.str())); attribs.push_back(UPnPAttribute("SortCriteria", "")); #if 0 try { results=m_devices[m_selecteddevice].SendSOAP("urn:schemas-upnp-org:service:ContentDirectory:1", "Browse", attribs); } catch (std::runtime_error error) { ShowMsgUTF(LOCALE_MESSAGEBOX_INFO, error.what(), CMessageBox::mbrBack, CMessageBox::mbBack, "info.raw"); if (entries) delete entries; return endall; } #endif results=m_devices[m_selecteddevice].SendSOAP("urn:schemas-upnp-org:service:ContentDirectory:1", "Browse", attribs); for (i=results.begin(); i!=results.end(); i++) { if (i->first=="NumberReturned") { returned=atoi(i->second.c_str()); nfound=true; } if (i->first=="TotalMatches") { dirnum=atoi(i->second.c_str()); tfound=true; } if (i->first=="Result") { entries=decodeResult(i->second); rfound=true; } } if (!entries) return endall; if (!nfound || !tfound || !rfound) { delete entries; return endall; } if (returned != entries->size()) { delete entries; return endall; } if (returned == 0) { delete entries; return endall; } rchanged=false; changed=true; } if (changed) { paintItem(entries, selected - index, dirnum - index, index); changed=false; } g_RCInput->getMsg(&msg, &data, 10); // 1 sec timeout to update play/stop state display neutrino_msg_t msg_repeatok = msg & ~CRCInput::RC_Repeat; if( msg == CRCInput::RC_timeout) { // nothing } else if(msg == CRCInput::RC_home) { loop=false; endall=true; } else if(msg == CRCInput::RC_left) { loop=false; } else if (msg_repeatok == CRCInput::RC_up && selected > 0) { selected--; if (selected < index) { index-=m_listmaxshow; rchanged=true; } changed=true; } else if(msg == CRCInput::RC_green && selected > 0) { if (index > 0) { index-=m_listmaxshow; selected-=m_listmaxshow; rchanged=true; } else selected=0; changed=true; } else if (msg_repeatok == CRCInput::RC_down && selected + 1 < dirnum) { selected++; if (selected + 1 > index + m_listmaxshow) { index+=m_listmaxshow; rchanged=true; } changed=true; } else if(msg == CRCInput::RC_red && selected + 1 < dirnum) { if (index < ((dirnum - 1) / m_listmaxshow) * m_listmaxshow) { index+=m_listmaxshow; selected+=m_listmaxshow; if (selected + 1 >= dirnum) selected=dirnum - 1; rchanged=true; } else selected=dirnum - 1; changed=true; } else if(msg == CRCInput::RC_right) { if ((*entries)[selected - index].isdir) { endall=selectItem((*entries)[selected - index].id); if (endall) loop=false; } changed=true; } else if(msg == CRCInput::RC_ok) { if (!(*entries)[selected - index].isdir) { m_folderplay = false; int preferred=(*entries)[selected - index].preferred; if (preferred != -1) { std::string protocol, prot, network, mime, additional; protocol=(*entries)[selected - index].resources[preferred].protocol; splitProtocol(protocol, prot, network, mime, additional); if (mime == "audio/mpeg") { CAudiofile mp3((*entries)[selected - index].resources[preferred].url, CFile::FILE_MP3); CAudioPlayer::getInstance()->play(&mp3, g_settings.audioplayer_highprio == 1); } else if (mime == "audio/x-vorbis+ogg") { CAudiofile mp3((*entries)[selected - index].resources[preferred].url, CFile::FILE_OGG); CAudioPlayer::getInstance()->play(&mp3, g_settings.audioplayer_highprio == 1); } m_playing_entry = (*entries)[selected - index]; #if 0 // #ifdef ENABLE_PICTUREVIEWER else if ((mime == "image/gif") || (mime == "image/jpeg")) { CPictureViewer *viewer = new CPictureViewer(); bool loop=true; viewer->SetScaling((CPictureViewer::ScalingMode)g_settings.picviewer_scaling); viewer->SetVisible(g_settings.screen_StartX, g_settings.screen_EndX, g_settings.screen_StartY, g_settings.screen_EndY); if(g_settings.video_Format==1) viewer->SetAspectRatio(16.0/9); else if(g_settings.video_Format==0) { CControldClient cdc; cdc.setVideoFormat(CControldClient::VIDEOFORMAT_4_3); viewer->SetAspectRatio(4.0/3); } else viewer->SetAspectRatio(4.0/3); m_frameBuffer->setMode(720, 576, 16); m_frameBuffer->setTransparency(0); viewer->ShowImage((*entries)[selected - index].resources[preferred].url, true); while (loop) { g_RCInput->getMsg(&msg, &data, 10); // 1 sec timeout to update play/stop state display if( msg == CRCInput::RC_home) loop=false; } m_frameBuffer->setMode(720, 576, 8 * sizeof(fb_pixel_t)); m_frameBuffer->setBlendLevel(g_settings.gtx_alpha1, g_settings.gtx_alpha2); m_frameBuffer->ClearFrameBuffer(); delete viewer; } // #endif #endif } }
std::vector<UPnPEntry> *CUpnpBrowserGui::decodeResult(std::string result) { XMLTreeParser *parser; XMLTreeNode *root, *node, *snode; std::vector<UPnPEntry> *entries; parser = new XMLTreeParser("UTF-8"); parser->Parse(result.c_str(), result.size(), 1); root=parser->RootNode(); if (!root){ delete parser; return NULL; } entries = new std::vector<UPnPEntry>; for (node=root->GetChild(); node; node=node->GetNext()) { bool isdir; std::string title, artist = "", album = "", id, children; char *type, *p; if (!strcmp(node->GetType(), "container")) { std::vector<UPnPResource> resources; isdir=true; for (snode=node->GetChild(); snode; snode=snode->GetNext()) { type=snode->GetType(); p = strchr(type,':'); if (p) type=p+1; if (!strcmp(type,"title")) { p=snode->GetData(); if (!p) p=(char *) ""; title=std::string(p); } } p = node->GetAttributeValue((char *) "id"); if (!p) p=(char *) ""; id=std::string(p); p = node->GetAttributeValue((char *) "childCount"); if (!p) p=(char *) ""; children=std::string(p); UPnPEntry entry={id, isdir, title, artist, album, children, resources, -1}; entries->push_back(entry); } if (!strcmp(node->GetType(), "item")) { std::vector<UPnPResource> resources; int preferred = -1; std::string protocol, prot, network, mime, additional; isdir=false; for (snode=node->GetChild(); snode; snode=snode->GetNext()) { std::string duration, url, size; unsigned int i; type=snode->GetType(); p = strchr(type,':'); if (p) type=p+1; if (!strcmp(type,"title")) { p=snode->GetData(); if (!p) p=(char *) ""; title=std::string(p); } else if (!strcmp(type,"artist")) { p=snode->GetData(); if (!p) p=(char *) ""; artist=std::string(p); } else if (!strcmp(type,"album")) { p=snode->GetData(); if (!p) p=(char *) ""; album=std::string(p); } else if (!strcmp(type,"res")) { p = snode->GetData(); if (!p) p=(char *) ""; url=std::string(p); p = snode->GetAttributeValue((char *) "size"); if (!p) p=(char *) "0"; size=std::string(p); p = snode->GetAttributeValue((char *) "duration"); if (!p) p=(char *) ""; duration=std::string(p); p = snode->GetAttributeValue((char *) "protocolInfo"); if (!p) p=(char *) ""; protocol=std::string(p); UPnPResource resource = {url, protocol, size, duration}; resources.push_back(resource); } int pref=0; preferred=-1; for (i=0; i<resources.size(); i++) { protocol=resources[i].protocol; splitProtocol(protocol, prot, network, mime, additional); if (prot != "http-get") continue; #if 0 if (mime == "image/jpeg" && pref < 1) { preferred=i; pref=1; } if (mime == "image/gif" && pref < 2) { preferred=i; pref=2; } #endif if (mime == "audio/mpeg" && pref < 3) { preferred=i; pref=3; } if (mime == "audio/x-vorbis+ogg" && pref < 4) { preferred=i; pref=4; } } } p = node->GetAttributeValue((char *) "id"); if (!p) p=(char *) ""; id=std::string(p); p = node->GetAttributeValue((char *) "childCount"); if (!p) p=(char *) ""; children=std::string(p); UPnPEntry entry={id, isdir, title, artist, album, children, resources, preferred}; entries->push_back(entry); } } delete parser; return entries; }
void CUpnpBrowserGui::playnext(void) { while (true) { std::list<UPnPAttribute>attribs; std::list<UPnPAttribute>results; std::list<UPnPAttribute>::iterator i; std::stringstream sindex; std::vector<UPnPEntry> *entries = NULL; bool rfound = false; bool nfound = false; bool tfound = false; sindex << m_playid; attribs.push_back(UPnPAttribute("ObjectID", m_playfolder)); attribs.push_back(UPnPAttribute("BrowseFlag", "BrowseDirectChildren")); attribs.push_back(UPnPAttribute("Filter", "*")); attribs.push_back(UPnPAttribute("StartingIndex", sindex.str())); attribs.push_back(UPnPAttribute("RequestedCount", "1")); attribs.push_back(UPnPAttribute("SortCriteria", "")); #if 0 try { results=m_devices[m_selecteddevice].SendSOAP("urn:schemas-upnp-org:service:ContentDirectory:1", "Browse", attribs); } catch (std::runtime_error error) { ShowMsgUTF(LOCALE_MESSAGEBOX_INFO, error.what(), CMessageBox::mbrBack, CMessageBox::mbBack, "info.raw"); m_folderplay = false; return; } #endif results=m_devices[m_selecteddevice].SendSOAP("urn:schemas-upnp-org:service:ContentDirectory:1", "Browse", attribs); for (i=results.begin(); i!=results.end(); i++) { if (i->first=="NumberReturned") { if (atoi(i->second.c_str()) != 1) { m_folderplay = false; return; } nfound=true; } if (i->first=="TotalMatches") { tfound=true; } if (i->first=="Result") { entries=decodeResult(i->second); rfound=true; } } m_playid++; if ((entries != NULL) && (!(*entries)[0].isdir)) { int preferred=(*entries)[0].preferred; if (preferred != -1) { std::string protocol, prot, network, mime, additional; protocol=(*entries)[0].resources[preferred].protocol; splitProtocol(protocol, prot, network, mime, additional); if (mime == "audio/mpeg") { m_playing_entry = (*entries)[0]; m_playing_entry_is_shown = false; CAudiofile mp3((*entries)[0].resources[preferred].url, CFile::FILE_MP3); CAudioPlayer::getInstance()->play(&mp3, g_settings.audioplayer_highprio == 1); return; } else if (mime == "audio/x-vorbis+ogg") { m_playing_entry = (*entries)[0]; m_playing_entry_is_shown = false; CAudiofile mp3((*entries)[0].resources[preferred].url, CFile::FILE_OGG); CAudioPlayer::getInstance()->play(&mp3, g_settings.audioplayer_highprio == 1); return; } } } else { neutrino_msg_t msg; neutrino_msg_data_t data; g_RCInput->getMsg(&msg, &data, 10); // 1 sec timeout to update play/stop state display if( msg == CRCInput::RC_home) { m_folderplay = false; break; } } } }
void CUpnpBrowserGui::paintItemPos(std::vector<UPnPEntry> *entry, unsigned int pos, unsigned int selected) { int ypos = m_y + m_title_height + m_theight + pos*m_fheight; uint8_t color; fb_pixel_t bgcolor; if (pos == selected) { color = COL_MENUCONTENTSELECTED; bgcolor = COL_MENUCONTENTSELECTED_PLUS_0; if ((*entry)[pos].isdir) clearItem2DetailsLine(); // clear it else paintItem2DetailsLine(pos); paintDetails(entry, pos); } else { color = COL_MENUCONTENT; bgcolor = COL_MENUCONTENT_PLUS_0; } // item box m_frameBuffer->paintBoxRel(m_x, ypos, m_width - SCROLLBAR_WIDTH, m_fheight, bgcolor); if (pos >= entry->size()) return; int preferred = (*entry)[pos].preferred; std::string info; std::string fileicon; if ((*entry)[pos].isdir) { info = "<DIR>"; fileicon = NEUTRINO_ICON_FOLDER; } else { //FIXME: revise this if (preferred != -1) { info = (*entry)[pos].resources[preferred].duration; // icon std::string protocol, prot, network, mime, additional; protocol = (*entry)[pos].resources[preferred].protocol; splitProtocol(protocol, prot, network, mime, additional); if (mime.substr(0, 6) == "audio/") { fileicon = NEUTRINO_ICON_MP3; } else if (mime.substr(0, 6) == "image/") { fileicon = NEUTRINO_ICON_PICTURE; } else if (mime.substr(0, 6) == "video/") { fileicon = NEUTRINO_ICON_MOVIE; } } else { info = "(none)"; fileicon = NEUTRINO_ICON_FILE; } } std::string name = (*entry)[pos].title; char tmp_time[] = "00:00:00.0"; int w = g_Font[SNeutrinoSettings::FONT_TYPE_FILEBROWSER_ITEM]->getRenderWidth(tmp_time); m_frameBuffer->paintIcon(fileicon, m_x + 5 , ypos + (m_fheight - 16) / 2); g_Font[SNeutrinoSettings::FONT_TYPE_FILEBROWSER_ITEM]->RenderString(m_x + m_width - 15 - w, ypos + m_fheight, w, info, color, m_fheight); g_Font[SNeutrinoSettings::FONT_TYPE_FILEBROWSER_ITEM]->RenderString(m_x + 30, ypos + m_fheight, m_width - 50 - w, name, color, m_fheight, true); // UTF-8 }
bool CUpnpBrowserGui::selectItem(std::string id) { bool loop = true; bool endall = false; bool changed = true; bool rchanged = true; neutrino_msg_t msg; neutrino_msg_data_t data; std::vector<UPnPEntry> *entries; unsigned int index, selected, dirnum; index = 0; selected = 0; dirnum = 0; entries = NULL; while (loop) { updateTimes(); if (rchanged) { if (entries) delete entries; entries = NULL; std::list<UPnPAttribute>attribs; std::list<UPnPAttribute>results; std::list<UPnPAttribute>::iterator i; std::stringstream sindex; std::stringstream scount; unsigned int returned = 0; bool rfound = false; bool nfound = false; bool tfound = false; sindex << index; scount << m_listmaxshow; attribs.push_back(UPnPAttribute("ObjectID", id)); attribs.push_back(UPnPAttribute("BrowseFlag", "BrowseDirectChildren")); attribs.push_back(UPnPAttribute("Filter", "*")); attribs.push_back(UPnPAttribute("StartingIndex", sindex.str())); attribs.push_back(UPnPAttribute("RequestedCount", scount.str())); attribs.push_back(UPnPAttribute("SortCriteria", "")); results = m_devices[m_selecteddevice].SendSOAP("urn:schemas-upnp-org:service:ContentDirectory:1", "Browse", attribs); for (i = results.begin(); i != results.end(); i++) { if (i->first == "NumberReturned") { returned = atoi(i->second.c_str()); nfound = true; } if (i->first == "TotalMatches") { dirnum = atoi(i->second.c_str()); tfound = true; } if (i->first == "Result") { entries = decodeResult(i->second); rfound = true; } } if (!entries) return endall; if (!nfound || !tfound || !rfound) { delete entries; return endall; } if (returned != entries->size()) { delete entries; return endall; } if (returned == 0) { delete entries; return endall; } rchanged=false; changed=true; } if (changed) { paintItem(entries, selected - index, dirnum - index, index); changed = false; } m_frameBuffer->blit(); g_RCInput->getMsg(&msg, &data, 10); // 1 sec timeout to update play/stop state display neutrino_msg_t msg_repeatok = msg & ~CRCInput::RC_Repeat; if( msg == CRCInput::RC_timeout) { // nothing } else if(msg == CRCInput::RC_home) { loop = false; endall = true; } else if(msg == CRCInput::RC_left) { loop = false; } else if (msg_repeatok == CRCInput::RC_up && selected > 0) { selected--; if (selected < index) { index -= m_listmaxshow; rchanged = true; } changed = true; } else if( (msg == CRCInput::RC_yellow || (int) msg == g_settings.key_channelList_pageup) && selected > 0) { if (index > 0) { index-=m_listmaxshow; selected-=m_listmaxshow; rchanged=true; } else selected=0; changed = true; } else if (msg_repeatok == CRCInput::RC_down && selected + 1 < dirnum) { selected++; if (selected + 1 > index + m_listmaxshow) { index += m_listmaxshow; rchanged = true; } changed=true; } else if( (msg == CRCInput::RC_green || (int) msg == g_settings.key_channelList_pagedown)&& selected + 1 < dirnum) { if (index < ((dirnum - 1) / m_listmaxshow) * m_listmaxshow) { index += m_listmaxshow; selected += m_listmaxshow; if (selected + 1 >= dirnum) selected = dirnum - 1; rchanged = true; } else selected = dirnum - 1; changed = true; } else if(msg == CRCInput::RC_right) { if ((*entries)[selected - index].isdir) { endall = selectItem((*entries)[selected - index].id); if (endall) loop = false; } changed = true; } else if(msg == CRCInput::RC_ok) { if (!(*entries)[selected - index].isdir) { m_folderplay = false; int preferred = (*entries)[selected - index].preferred; if (preferred != -1) { std::string protocol, prot, network, mime, additional; protocol=(*entries)[selected - index].resources[preferred].protocol; splitProtocol(protocol, prot, network, mime, additional); if (mime == "audio/mpeg") { CAudioPlayerGui tmpAudioPlayerGui; CAudiofileExt audiofile((*entries)[selected - index].resources[preferred].url, CFile::EXTENSION_MP3); tmpAudioPlayerGui.addToPlaylist(audiofile); tmpAudioPlayerGui.exec(NULL, "urlplayback"); } else if ((mime == "image/gif") || (mime == "image/jpeg")) { CPictureViewerGui tmpPictureViewerGui; CPicture pic; struct stat statbuf; pic.Filename = (*entries)[selected - index].resources[preferred].url; std::string tmp = (*entries)[selected - index].resources[preferred].url.substr((*entries)[selected - index].resources[preferred].url.rfind('/') + 1); pic.Name = tmp.substr(0, tmp.rfind('.')); pic.Type = tmp.substr(tmp.rfind('.') + 1); if(stat(pic.Filename.c_str(), &statbuf) != 0) printf("stat error"); pic.Date = statbuf.st_mtime; tmpPictureViewerGui.addToPlaylist(pic); tmpPictureViewerGui.exec(NULL, "urlplayback"); changed = true; } else if (mime.substr(0,6) == "video/") { m_frameBuffer->ClearFrameBuffer(); m_frameBuffer->blit(); CFile file; file.Name = (*entries)[selected - index].resources[preferred].url.c_str(); //FIXME CMoviePlayerGui tmpMoviePlayerGui; tmpMoviePlayerGui.addToPlaylist(file); tmpMoviePlayerGui.exec(NULL, "urlplayback"); changed = true; } m_playing_entry = (*entries)[selected - index]; } } else { m_folderplay = true; m_playfolder = (*entries)[selected - index].id; m_playid = 0; playnext(); } changed = true; } else if( msg == CRCInput::RC_red) { if(CAudioPlayer::getInstance()->getState() != CBaseDec::STOP) CAudioPlayer::getInstance()->stop(); m_folderplay = false; } else if(msg == NeutrinoMessages::RECORD_START || msg == NeutrinoMessages::ZAPTO || msg == NeutrinoMessages::STANDBY_ON || msg == NeutrinoMessages::SHUTDOWN || msg == NeutrinoMessages::SLEEPTIMER) { loop = false; g_RCInput->postMsg(msg, data); } else if(msg == NeutrinoMessages::EVT_TIMER) { CNeutrinoApp::getInstance()->handleMsg( msg, data ); } else { if( CNeutrinoApp::getInstance()->handleMsg( msg, data ) & messages_return::cancel_all ) loop = false; changed = true; } if (m_folderplay && (CAudioPlayer::getInstance()->getState() == CBaseDec::STOP)) playnext(); m_frameBuffer->blit(); } if (entries) delete entries; m_frameBuffer->ClearFrameBuffer(); m_frameBuffer->blit(); return endall; }
void CUpnpBrowserGui::playnext(void) { while (true) { std::list<UPnPAttribute>attribs; std::list<UPnPAttribute>results; std::list<UPnPAttribute>::iterator i; std::stringstream sindex; std::vector<UPnPEntry> *entries = NULL; bool rfound = false; bool nfound = false; bool tfound = false; sindex << m_playid; attribs.push_back(UPnPAttribute("ObjectID", m_playfolder)); attribs.push_back(UPnPAttribute("BrowseFlag", "BrowseDirectChildren")); attribs.push_back(UPnPAttribute("Filter", "*")); attribs.push_back(UPnPAttribute("StartingIndex", sindex.str())); attribs.push_back(UPnPAttribute("RequestedCount", "1")); attribs.push_back(UPnPAttribute("SortCriteria", "")); results = m_devices[m_selecteddevice].SendSOAP("urn:schemas-upnp-org:service:ContentDirectory:1", "Browse", attribs); for (i = results.begin(); i!=results.end(); i++) { if (i->first=="NumberReturned") { if (atoi(i->second.c_str()) != 1) { m_folderplay = false; return; } nfound=true; } if (i->first=="TotalMatches") { tfound=true; } if (i->first=="Result") { entries=decodeResult(i->second); rfound=true; } } m_playid++; if ((entries != NULL) && (!(*entries)[0].isdir)) { int preferred=(*entries)[0].preferred; if (preferred != -1) { std::string protocol, prot, network, mime, additional; protocol=(*entries)[0].resources[preferred].protocol; splitProtocol(protocol, prot, network, mime, additional); if (mime == "audio/mpeg") { m_playing_entry = (*entries)[0]; m_playing_entry_is_shown = false; CAudioPlayerGui tmpAudioPlayerGui; CAudiofileExt audiofile((*entries)[0].resources[preferred].url, CFile::EXTENSION_MP3); tmpAudioPlayerGui.addToPlaylist(audiofile); tmpAudioPlayerGui.exec(NULL, "urlplayback"); return; } else if (mime.substr(0,6) == "video/") { m_frameBuffer->ClearFrameBuffer(); m_frameBuffer->blit(); CFile mfile; mfile.Name = (*entries)[0].resources[preferred].url.c_str(); //FIXME CMoviePlayerGui tmpMoviePlayerGui; tmpMoviePlayerGui.addToPlaylist(mfile); tmpMoviePlayerGui.exec(NULL, "urlplayback"); return; } else if (mime.substr(0,6) == "image/") { CPictureViewerGui tmpPictureViewerGui; CPicture pic; struct stat statbuf; pic.Filename = (*entries)[0].resources[preferred].url; std::string tmp = (*entries)[0].resources[preferred].url.substr((*entries)[0].resources[preferred].url.rfind('/') + 1); pic.Name = tmp.substr(0, tmp.rfind('.')); pic.Type = tmp.substr(tmp.rfind('.') + 1); if(stat(pic.Filename.c_str(), &statbuf) != 0) printf("stat error"); pic.Date = statbuf.st_mtime; tmpPictureViewerGui.addToPlaylist(pic); tmpPictureViewerGui.exec(NULL, "urlplayback"); return; } } } else { neutrino_msg_t msg; neutrino_msg_data_t data; g_RCInput->getMsg(&msg, &data, 10); // 1 sec timeout to update play/stop state display if( msg == CRCInput::RC_home) { m_folderplay = false; break; } } } // m_frameBuffer->ClearFrameBuffer(); m_frameBuffer->blit(); }
void CUpnpBrowserGui::paintItem(std::vector<UPnPEntry> *entry, unsigned int selected, unsigned int max, unsigned int offset) { std::string tmp; std::stringstream ts; int w, xstart, ypos, top; int preferred=(*entry)[selected].preferred; // LCD CVFD::getInstance()->setMode(CVFD::MODE_MENU_UTF8, "Select UPnP Entry"); CVFD::getInstance()->showMenuText(0, (*entry)[selected].title.c_str(), -1, true); // Info m_frameBuffer->paintBoxRel(m_x, m_y, m_width, m_title_height - 10, COL_MENUCONTENT_PLUS_6); m_frameBuffer->paintBoxRel(m_x + 2, m_y + 2, m_width - 4, m_title_height - 14, COL_MENUCONTENTSELECTED_PLUS_0); // first line ts << "Resources: " << (*entry)[selected].resources.size() << " Selected: " << preferred+1 << " "; tmp = ts.str(); if (preferred != -1) tmp = tmp + "Duration: " + (*entry)[selected].resources[preferred].duration; else tmp = tmp + "No resource for Item"; w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(tmp, true); // UTF-8 if (w > m_width - 20) w = m_width - 20; xstart = (m_width - w) / 2; if(xstart < 10) xstart = 10; g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(m_x + xstart, m_y + 4 + 1*m_mheight, m_width - 20, tmp, COL_MENUCONTENTSELECTED, 0, true); // UTF-8 // second line if ((*entry)[selected].isdir) tmp = "Directory"; else { tmp = ""; if (preferred != -1) { std::string proto, network, mime, info; splitProtocol((*entry)[selected].resources[preferred].protocol, proto, network, mime, info); tmp = "Protocol: " + proto + ", MIME-Type: " + mime; } } w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(tmp, true); // UTF-8 if (w > m_width - 20) w = m_width - 20; xstart = (m_width - w) / 2; if(xstart < 10) xstart = 10; g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(m_x + xstart, m_y + 4 + 2*m_mheight, m_width - 20, tmp, COL_MENUCONTENTSELECTED, 0, true); // UTF-8 //third line tmp = ""; if (!(*entry)[selected].isdir) { if (preferred != -1) { tmp = "URL: " + (*entry)[selected].resources[preferred].url; } } w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(tmp, true); // UTF-8 if (w > m_width - 20) w = m_width - 20; xstart = (m_width - w) / 2; if(xstart < 10) xstart = 10; g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(m_x + xstart, m_y + 4 + 3*m_mheight, m_width - 20, tmp, COL_MENUCONTENTSELECTED, 0, true); // UTF-8 // Head tmp = g_Locale->getText(LOCALE_UPNPBROWSER_HEAD); m_frameBuffer->paintBoxRel(m_x, m_y + m_title_height, m_width, m_theight, COL_MENUHEAD_PLUS_0, RADIUS_MID, CORNER_TOP, true); m_frameBuffer->paintIcon(NEUTRINO_ICON_UPNP, m_x + BORDER_LEFT, m_y + m_title_height + (m_theight - icon_head_h)/2); g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->RenderString(m_x + BORDER_LEFT + icon_head_w + 5, m_y + m_theight + m_title_height, m_width - 45, tmp, COL_MENUHEAD, 0, true); // UTF-8 // ypos = m_y + m_title_height; if(m_theight > icon_head_h) ypos = (m_theight - icon_head_h) / 2 + m_y + m_title_height; // Items for (unsigned int count = 0; count < m_listmaxshow; count++) paintItemPos(entry, count, selected); ypos = m_y + m_title_height + m_theight; int sb = m_fheight * m_listmaxshow; m_frameBuffer->paintBoxRel(m_x + m_width - SCROLLBAR_WIDTH, ypos, SCROLLBAR_WIDTH, sb, COL_MENUCONTENT_PLUS_1); int sbc = ((max + offset - 1) / m_listmaxshow) + 1; int sbs = ((selected + offset) / m_listmaxshow); int sbh = 0; if ((sbc > 0) && (sbc > sb - 4)) sbh = 2; m_frameBuffer->paintBoxRel(m_x + m_width - 13, ypos + 2 + sbs*((sb - 4)/sbc + sbh), 11, (sb - 4)/sbc + sbh, COL_MENUCONTENT_PLUS_3); // Foot buttons top = m_y + m_height - (m_info_height + m_buttonHeight); int ButtonWidth = (m_width - 20) / 4; m_frameBuffer->paintBoxRel(m_x, top, m_width, m_buttonHeight, COL_MENUHEAD_PLUS_0, RADIUS_MID, CORNER_BOTTOM, g_settings.menu_Foot_gradient); ::paintButtons(m_frameBuffer, g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL], g_Locale, m_x + BORDER_LEFT, top, ButtonWidth, 1, &StopButton, m_buttonHeight); ::paintButtons(m_frameBuffer, g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL], g_Locale, m_x + BORDER_LEFT + ButtonWidth, top, ButtonWidth, 1, &PUpButton, m_buttonHeight); ::paintButtons(m_frameBuffer, g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL], g_Locale, m_x + BORDER_LEFT + 2*ButtonWidth, top, ButtonWidth, 1, &PDownButton, m_buttonHeight); m_frameBuffer->paintIcon(NEUTRINO_ICON_BUTTON_OKAY, m_x + BORDER_LEFT + 3*ButtonWidth, top + (m_buttonHeight - icon_foot_h)/2); g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->RenderString(m_x + BORDER_LEFT + 3*ButtonWidth + icon_foot_w + 5, top + (m_buttonHeight - g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getHeight())/2 + g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getHeight(), ButtonWidth - 40, g_Locale->getText(LOCALE_AUDIOPLAYER_PLAY), COL_INFOBAR, 0, true); // UTF-8 }
std::vector<UPnPEntry> *CUpnpBrowserGui::decodeResult(std::string result) { xmlNodePtr root, node, snode; std::vector<UPnPEntry> *entries; xmlDocPtr parser = parseXml(result.c_str(),"UTF-8"); root = xmlDocGetRootElement(parser); if (!root) { xmlFreeDoc(parser); return NULL; } entries = new std::vector<UPnPEntry>; for (node=xmlChildrenNode(root); node; node=xmlNextNode(node)) { bool isdir; std::string title, artist = "", album = "", albumArtURI = "", id, children; const char *type, *p; if (!strcmp(xmlGetName(node), "container")) { std::vector<UPnPResource> resources; isdir=true; for (snode=xmlChildrenNode(node); snode; snode=xmlNextNode(snode)) { type=xmlGetName(snode); p = strchr(type,':'); if (p) type=p+1; if (!strcmp(type,"title")) { p=xmlGetData(snode); if (!p) p = ""; title=std::string(p); } } p = xmlGetAttribute(node, "id"); if (!p) p = ""; id=std::string(p); p = xmlGetAttribute(node, "childCount"); if (!p) p = ""; children=std::string(p); UPnPEntry entry={id, isdir, title, artist, album, albumArtURI, children, "", "", resources, -1, CFile::FILE_DIR}; entries->push_back(entry); } if (!strcmp(xmlGetName(node), "item")) { std::vector<UPnPResource> resources; int preferred = -1; std::string protocol, prot, network, mime, additional; CFile::FileType ftype = CFile::FILE_UNKNOWN; isdir=false; for (snode=xmlChildrenNode(node); snode; snode=xmlNextNode(snode)) { std::string duration, url, size; unsigned int i; type=xmlGetName(snode); p = strchr(type,':'); if (p) type=p+1; if (!strcmp(type,"title")) { p=xmlGetData(snode); if (!p) p = ""; title=std::string(p); } else if (!strcmp(type,"artist")) { p=xmlGetData(snode); if (!p) p = ""; artist=std::string(p); } else if (!strcmp(type,"album")) { p=xmlGetData(snode); if (!p) p = ""; album=std::string(p); } else if (!strcmp(type,"albumArtURI")) { p=xmlGetData(snode); if (!p) p = ""; albumArtURI=std::string(p); } else if (!strcmp(type,"res")) { p = xmlGetData(snode); if (!p) p = ""; url=std::string(p); p = xmlGetAttribute(snode, "size"); if (!p) p = "0"; size=std::string(p); p = xmlGetAttribute(snode, "duration"); if (!p) p = ""; duration=std::string(p); p = xmlGetAttribute(snode, "protocolInfo"); if (!p) p = ""; protocol=std::string(p); UPnPResource resource = {url, protocol, size, duration}; resources.push_back(resource); } int pref=0; preferred=-1; for (i=0; i<resources.size(); i++) { protocol=resources[i].protocol; splitProtocol(protocol, prot, network, mime, additional); if (prot != "http-get") continue; if (mime.substr(0,6) == "image/" && pref < 1) { preferred=i; } if (mime == "image/jpeg" && pref < 1) { preferred=i; pref=1; } if (mime == "image/gif" && pref < 2) { preferred=i; pref=2; } if (mime == "audio/mpeg" && pref < 3) { preferred=i; pref=3; ftype = CFile::FILE_MP3; } if ((mime == "audio/ogg" || mime == "audio/x-ogg") && pref < 4) { ftype = CFile::FILE_OGG; preferred=i; pref=4; } if (mime == "audio/x-flac" && pref < 5) { preferred=i; pref=5; ftype = CFile::FILE_FLAC; } if (mime == "audio/x-wav" && pref < 6) { preferred=i; pref=6; ftype = CFile::FILE_WAV; } if (mime.substr(0,6) == "video/" && pref < 7) { preferred=i; pref=7; } if (mime == "video/x-flv" && pref < 8) { preferred=i; pref=8; } if (mime == "video/mp4" && pref < 9) { preferred=i; pref=9; } } } p = xmlGetAttribute(node, "id"); if (!p) p = ""; id=std::string(p); p = xmlGetAttribute(node, "childCount"); if (!p) p = ""; children=std::string(p); UPnPEntry entry={id, isdir, title, artist, album, albumArtURI, children, prot, mime, resources, preferred, ftype}; entries->push_back(entry); } } xmlFreeDoc(parser); return entries; }