upnpbrowser: change code format

Origin commit data
------------------
Commit: 774247789b
Author: Thilo Graf <dbt@novatux.de>
Date: 2021-11-14 (Sun, 14 Nov 2021)
This commit is contained in:
2021-11-14 22:12:27 +01:00
committed by vanhofen
parent a5056cd696
commit f35a74f78d
2 changed files with 379 additions and 309 deletions

View File

@@ -168,10 +168,12 @@ CUpnpBrowserGui::~CUpnpBrowserGui()
sigPall.disconnect();
delete m_socket;
if (dline){
if (dline)
{
delete dline; dline = NULL;
}
if (image){
if (image)
{
delete image; image = NULL;
}
}
@@ -265,7 +267,8 @@ bool CUpnpBrowserGui::discoverDevices()
CHintBox hintbox(LOCALE_MESSAGEBOX_INFO, g_Locale->getText(LOCALE_UPNPBROWSER_SCANNING)); // UTF-8
hintbox.paint();
try {
try
{
m_devices = m_socket->Discover("urn:schemas-upnp-org:service:ContentDirectory:1");
}
catch (std::runtime_error &error)
@@ -316,7 +319,8 @@ std::vector<UPnPEntry> *CUpnpBrowserGui::decodeResult(std::string result)
xmlNodePtr root, node, snode;
xmlDocPtr parser = parseXml(result.c_str(), "UTF-8");
root = xmlDocGetRootElement(parser);
if (!root) {
if (!root)
{
xmlFreeDoc(parser);
return NULL;
}
@@ -510,7 +514,8 @@ void CUpnpBrowserGui::updateDeviceSelection(int newpos)
{
if (newpos < 0) /* do not explode if called with -1 arg... */
return;
if((int) m_selecteddevice != newpos) {
if ((int) m_selecteddevice != newpos)
{
int prev_selected = m_selecteddevice;
unsigned int oldliststart = m_deviceliststart;
@@ -518,7 +523,8 @@ void CUpnpBrowserGui::updateDeviceSelection(int newpos)
m_deviceliststart = (m_selecteddevice / m_listmaxshow) * m_listmaxshow;
if (oldliststart != m_deviceliststart)
paintDevices();
else {
else
{
paintDevice(prev_selected - m_deviceliststart);
paintDevice(m_selecteddevice - m_deviceliststart);
}
@@ -557,10 +563,12 @@ void CUpnpBrowserGui::selectDevice()
{
loop = false;
}
else if (msg_repeatok == (neutrino_msg_t) g_settings.key_list_start) {
else if (msg_repeatok == (neutrino_msg_t) g_settings.key_list_start)
{
updateDeviceSelection(0);
}
else if (msg_repeatok == (neutrino_msg_t) g_settings.key_list_end) {
else if (msg_repeatok == (neutrino_msg_t) g_settings.key_list_end)
{
updateDeviceSelection(m_devices.size() - 1);
}
else if (msg_repeatok == CRCInput::RC_up || (int)msg == g_settings.key_pageup ||
@@ -622,7 +630,8 @@ void CUpnpBrowserGui::playnext(void)
std::list<UPnPAttribute>::iterator i;
printf("playnext: getResults m_playfolder %s m_playid %d\n", m_playfolder.c_str(), m_playid);
if (!getResults(m_playfolder, m_playid, 1, results)) {
if (!getResults(m_playfolder, m_playid, 1, results))
{
m_folderplay = false;
return;
}
@@ -648,17 +657,20 @@ void CUpnpBrowserGui::playnext(void)
if (preferred != -1)
{
std::string &mime = (*entries)[0].mime;
if (mime.substr(0,6) == "audio/") {
if (mime.substr(0, 6) == "audio/")
{
m_playing_entry = (*entries)[0];
m_playing_entry_is_shown = false;
playAudio((*entries)[0].resources[preferred].url, (*entries)[0].type);
}
else if (mime.substr(0,6) == "video/") {
else if (mime.substr(0, 6) == "video/")
{
m_frameBuffer->Clear();
m_folderplay = true;
playVideo((*entries)[0].title, (*entries)[0].resources[preferred].url);
}
else if (mime.substr(0,6) == "image/") {
else if (mime.substr(0, 6) == "image/")
{
if (m_folderplay)
timeout = time(NULL) + g_settings.picviewer_slide_time;
showPicture((*entries)[0].resources[preferred].url);
@@ -666,12 +678,17 @@ void CUpnpBrowserGui::playnext(void)
delete entries;
entries = NULL;
return;
}else{
}
else
{
delete entries;
entries = NULL;
}
} else {
if(entries){
}
else
{
if (entries)
{
delete entries;
entries = NULL;
}
@@ -686,7 +703,8 @@ void CUpnpBrowserGui::playnext(void)
}
}
}
if(entries){
if (entries)
{
delete entries;
entries = NULL;
}
@@ -709,20 +727,28 @@ bool CUpnpBrowserGui::getItems(std::string id, unsigned int index, std::vector<U
if (!getResults(id, index, m_listmaxshow, results))
return false;
for (i=results.begin(); i!=results.end(); ++i) {
if (i->first=="NumberReturned") {
for (i = results.begin(); i != results.end(); ++i)
{
if (i->first == "NumberReturned")
{
returned = atoi(i->second.c_str());
nfound = true;
} else if (i->first=="TotalMatches") {
}
else if (i->first == "TotalMatches")
{
total = atoi(i->second.c_str());
tfound = true;
} else if (i->first=="Result") {
}
else if (i->first == "Result")
{
entries = decodeResult(i->second);
rfound = true;
}
}
if (!entries || !nfound || !tfound || !rfound || returned != entries->size() || returned == 0){
if(entries){
if (!entries || !nfound || !tfound || !rfound || returned != entries->size() || returned == 0)
{
if (entries)
{
delete entries;
entries = NULL;
}
@@ -733,19 +759,23 @@ bool CUpnpBrowserGui::getItems(std::string id, unsigned int index, std::vector<U
bool CUpnpBrowserGui::updateItemSelection(std::string id, std::vector<UPnPEntry>*&entries, int newpos, unsigned int &selected, unsigned int &liststart)
{
if((int) selected != newpos) {
if ((int) selected != newpos)
{
int prev_selected = selected;
unsigned int oldliststart = liststart;
selected = newpos;
liststart = (selected / m_listmaxshow) * m_listmaxshow;
printf("updateItemSelection: list start old %u new %d selected old %d new %d\n", oldliststart, liststart, prev_selected, selected);
if (oldliststart != liststart) {
if (oldliststart != liststart)
{
unsigned int total;
if (!getItems(id, liststart, entries, total))
return false;
paintItems(entries, selected - liststart, total - liststart, liststart);
} else {
}
else
{
paintItem(entries, prev_selected - liststart, selected - liststart);
paintItem(entries, selected - liststart, selected - liststart);
}
@@ -771,11 +801,13 @@ bool CUpnpBrowserGui::selectItem(std::string id)
if (!getItems(id, liststart, entries, total))
return endall;
while (loop && entries!=NULL) {
while (loop && entries != NULL)
{
updateTimes();
updateMode();
if (refresh) {
if (refresh)
{
printf("selectItem: refresh, timeout = %d\n", (int) timeout);
if (!timeout)
paintItems(entries, selected - liststart, total - liststart, liststart);
@@ -785,26 +817,33 @@ bool CUpnpBrowserGui::selectItem(std::string id)
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) {
if (msg == CRCInput::RC_timeout)
{
// nothing
}
else if (msg == CRCInput::RC_home) {
else if (msg == CRCInput::RC_home)
{
loop = false;
endall = true;
}
else if (!timeout && (msg == CRCInput::RC_left)) {
else if (!timeout && (msg == CRCInput::RC_left))
{
loop = false;
}
else if (!timeout && (msg_repeatok == (neutrino_msg_t) g_settings.key_list_start)) {
else if (!timeout && (msg_repeatok == (neutrino_msg_t) g_settings.key_list_start))
{
updateItemSelection(id, entries, 0, selected, liststart);
}
else if (!timeout && (msg_repeatok == (neutrino_msg_t) g_settings.key_list_end)) {
else if (!timeout && (msg_repeatok == (neutrino_msg_t) g_settings.key_list_end))
{
updateItemSelection(id, entries, total - 1, selected, liststart);
}
else if (!timeout && (msg_repeatok == CRCInput::RC_up || (int) msg == g_settings.key_pageup)) {
else if (!timeout && (msg_repeatok == CRCInput::RC_up || (int) msg == g_settings.key_pageup))
{
int step = ((int) msg == g_settings.key_pageup) ? m_listmaxshow : 1; // browse or step 1
int new_selected = selected - step;
if (new_selected < 0) {
if (new_selected < 0)
{
if (selected != 0 && step != 1)
new_selected = 0;
else
@@ -812,10 +851,12 @@ bool CUpnpBrowserGui::selectItem(std::string id)
}
updateItemSelection(id, entries, new_selected, selected, liststart);
}
else if (!timeout && (msg_repeatok == CRCInput::RC_down || (int) msg == g_settings.key_pagedown)) {
else if (!timeout && (msg_repeatok == CRCInput::RC_down || (int) msg == g_settings.key_pagedown))
{
int step = ((int) msg == g_settings.key_pagedown) ? m_listmaxshow : 1; // browse or step 1
int new_selected = selected + step;
if (new_selected >= (int) total) {
if (new_selected >= (int) total)
{
if ((total - m_listmaxshow - 1 < selected) && (selected != (total - 1)) && (step != 1))
new_selected = total - 1;
else if (((total / m_listmaxshow) + 1) * m_listmaxshow == total + m_listmaxshow) // last page has full entries
@@ -825,15 +866,19 @@ bool CUpnpBrowserGui::selectItem(std::string id)
}
updateItemSelection(id, entries, new_selected, selected, liststart);
}
else if (!timeout && (msg == CRCInput::RC_ok || msg == CRCInput::RC_right)) {
else if (!timeout && (msg == CRCInput::RC_ok || msg == CRCInput::RC_right))
{
if ((selected - liststart) >= (*entries).size())
continue;
if ((*entries)[selected - liststart].isdir) {
if ((*entries)[selected - liststart].isdir)
{
endall = selectItem((*entries)[selected - liststart].id);
if (endall)
loop = false;
refresh = true;
} else {
}
else
{
m_folderplay = false;
int preferred = (*entries)[selected - liststart].preferred;
if (preferred != -1)
@@ -863,18 +908,21 @@ bool CUpnpBrowserGui::selectItem(std::string id)
if (msg == CRCInput::RC_home || msg == CRCInput::RC_ok)
break;
else if (msg == CRCInput::RC_right || msg == CRCInput::RC_down) {
else if (msg == CRCInput::RC_right || msg == CRCInput::RC_down)
{
m_playfolder = id;
m_playid = (m_playid + 1) % total;
playnext();
}
else if (msg == CRCInput::RC_left || msg == CRCInput::RC_up) {
else if (msg == CRCInput::RC_left || msg == CRCInput::RC_up)
{
m_playfolder = id;
m_playid--;
if (m_playid < 0)
m_playid = total - 1;
playnext();
} else
}
else
CNeutrinoApp::getInstance()->handleMsg(msg, data);
}
m_frameBuffer->Clear();
@@ -884,7 +932,8 @@ bool CUpnpBrowserGui::selectItem(std::string id)
}
}
}
else if (msg == CRCInput::RC_play || msg == CRCInput::RC_playpause) {
else if (msg == CRCInput::RC_play || msg == CRCInput::RC_playpause)
{
if ((selected - liststart) >= (*entries).size())
continue;
m_folderplay = true;
@@ -893,26 +942,30 @@ bool CUpnpBrowserGui::selectItem(std::string id)
playnext();
m_playid++;
}
else if (msg == CRCInput::RC_yellow) {
else if (msg == CRCInput::RC_yellow)
{
m_folderplay = false;
stopAudio();
}
else if (m_folderplay && (msg == (neutrino_msg_t) CRCInput::RC_stop
|| video_key_msg == CMoviePlayerGui::PLUGIN_PLAYSTATE_STOP
|| video_key_msg == CMoviePlayerGui::PLUGIN_PLAYSTATE_LEAVE_ALL)){
|| video_key_msg == CMoviePlayerGui::PLUGIN_PLAYSTATE_LEAVE_ALL))
{
timeout = 0;
m_folderplay = false;
m_frameBuffer->Clear();
refresh = true;
}
else if (m_folderplay && ((msg == (neutrino_msg_t) CRCInput::RC_prev) || video_key_msg == CMoviePlayerGui::PLUGIN_PLAYSTATE_PREV)){
else if (m_folderplay && ((msg == (neutrino_msg_t) CRCInput::RC_prev) || video_key_msg == CMoviePlayerGui::PLUGIN_PLAYSTATE_PREV))
{
timeout = 0;
m_playid -= 2;
if (m_playid < 0)
m_playid = 0;
}
else if (m_folderplay && (msg == (neutrino_msg_t) CRCInput::RC_next
|| video_key_msg == CMoviePlayerGui::PLUGIN_PLAYSTATE_NEXT)){
|| video_key_msg == CMoviePlayerGui::PLUGIN_PLAYSTATE_NEXT))
{
timeout = 0;
stopAudio();
}
@@ -940,7 +993,8 @@ bool CUpnpBrowserGui::selectItem(std::string id)
//refresh=true;
}
if (m_folderplay && ((!timeout || (timeout <= time(NULL))) && (CAudioPlayer::getInstance()->getState() == CBaseDec::STOP))) {
if (m_folderplay && ((!timeout || (timeout <= time(NULL))) && (CAudioPlayer::getInstance()->getState() == CBaseDec::STOP)))
{
playnext();
m_playid++;
}
@@ -1170,7 +1224,8 @@ void CUpnpBrowserGui::paintItemInfo(UPnPEntry *entry)
tmpname = g_PicViewer->DownloadImage(tmpname);
int h_image = infobox.getHeight() - 2 * OFFSET_INNER_SMALL - infobox.getCornerRadius();
int y_image = infobox.getYPos() + infobox.getHeight() / 2 - h_image / 2;
if (!image){
if (!image)
{
image = new CComponentsPicture(0, y_image, tmpname, NULL, CC_SHADOW_OFF, COL_MENUCONTENTDARK_PLUS_0);
image->doPaintBg(false);
image->SetTransparent(CFrameBuffer::TM_BLACK);
@@ -1179,8 +1234,11 @@ void CUpnpBrowserGui::paintItemInfo(UPnPEntry *entry)
image->setHeight(h_image);
int x_image = infobox.getXPos() + infobox.getWidth() - image->getWidth() - OFFSET_INTER - infobox.getCornerRadius();
image->setXPos(x_image);
}else{
if (image){
}
else
{
if (image)
{
delete image; image = NULL;
}
}
@@ -1235,14 +1293,19 @@ void CUpnpBrowserGui::paintDetails(UPnPEntry *entry, bool use_playing)
timebox.setCorner(RADIUS_LARGE);
printf("paintDetails: use_playing %d shown %d\n", use_playing, m_playing_entry_is_shown);
if ((!use_playing) && entry->isdir){
if ((!use_playing) && entry->isdir)
{
infobox.kill();
timebox.kill();
m_playing_entry_is_shown = false;
}else{
}
else
{
std::string text = "";
if (use_playing){
if (!m_playing_entry_is_shown){
if (use_playing)
{
if (!m_playing_entry_is_shown)
{
m_playing_entry_is_shown = true;
text = m_playing_entry.title;
text += !m_playing_entry.artist.empty() ? " - " + m_playing_entry.artist : "";
@@ -1250,7 +1313,9 @@ void CUpnpBrowserGui::paintDetails(UPnPEntry *entry, bool use_playing)
if (infobox.setText(text, CTextBox::AUTO_WIDTH))
infobox.paint0();
}
}else{
}
else
{
if (!entry)
return;
m_playing_entry_is_shown = false;
@@ -1268,8 +1333,10 @@ void CUpnpBrowserGui::paintDetails(UPnPEntry *entry, bool use_playing)
void CUpnpBrowserGui::paintItem2DetailsLine(int pos)
{
if (pos < 0){
if (dline){
if (pos < 0)
{
if (dline)
{
dline->kill();
infobox.kill();
timebox.kill();
@@ -1291,10 +1358,12 @@ void CUpnpBrowserGui::paintItem2DetailsLine(int pos)
void CUpnpBrowserGui::updateTimes(const bool force)
{
if (CAudioPlayer::getInstance()->getState() != CBaseDec::STOP){
if (CAudioPlayer::getInstance()->getState() != CBaseDec::STOP)
{
bool updatePlayed = force;
if ((m_time_played != CAudioPlayer::getInstance()->getTimePlayed())){
if ((m_time_played != CAudioPlayer::getInstance()->getTimePlayed()))
{
m_time_played = CAudioPlayer::getInstance()->getTimePlayed();
updatePlayed = true;
}
@@ -1303,7 +1372,8 @@ void CUpnpBrowserGui::updateTimes(const bool force)
char play_time[14];
snprintf(play_time, sizeof(play_time), "%ld:%02ld", m_time_played / 60, m_time_played % 60);
if (updatePlayed){
if (updatePlayed)
{
timebox.setText(play_time, CTextBox::CENTER);
timebox.paint0();
}