| 1 |
/* |
| 2 |
* Copyright (C) 2005-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "GUIWindowHome.h" |
| 10 |
|
| 11 |
#include "ServiceBroker.h" |
| 12 |
#include "application/ApplicationComponents.h" |
| 13 |
#include "application/ApplicationPlayer.h" |
| 14 |
#include "guilib/GUIComponent.h" |
| 15 |
#include "guilib/GUIWindowManager.h" |
| 16 |
#include "guilib/WindowIDs.h" |
| 17 |
#include "input/actions/Action.h" |
| 18 |
#include "input/actions/ActionIDs.h" |
| 19 |
#include "interfaces/AnnouncementManager.h" |
| 20 |
#include "settings/AdvancedSettings.h" |
| 21 |
#include "settings/SettingsComponent.h" |
| 22 |
#include "utils/JobManager.h" |
| 23 |
#include "utils/RecentlyAddedJob.h" |
| 24 |
#include "utils/StringUtils.h" |
| 25 |
#include "utils/Variant.h" |
| 26 |
#include "utils/log.h" |
| 27 |
|
| 28 |
#include <mutex> |
| 29 |
|
| 30 |
CGUIWindowHome::CGUIWindowHome(void) : CGUIWindow(WINDOW_HOME, "Home.xml") |
| 31 |
{ |
| 32 |
m_updateRA = (Audio | Video | Totals); |
| 33 |
m_loadType = KEEP_IN_MEMORY; |
| 34 |
|
| 35 |
CServiceBroker::GetAnnouncementManager()->AddAnnouncer(this); |
| 36 |
} |
| 37 |
|
| 38 |
CGUIWindowHome::~CGUIWindowHome(void) |
| 39 |
{ |
| 40 |
CServiceBroker::GetAnnouncementManager()->RemoveAnnouncer(this); |
| 41 |
} |
| 42 |
|
| 43 |
bool CGUIWindowHome::OnAction(const CAction &action) |
| 44 |
{ |
| 45 |
static unsigned int min_hold_time = 1000; |
| 46 |
if (action.GetID() == ACTION_NAV_BACK && action.GetHoldTime() < min_hold_time) |
| 47 |
{ |
| 48 |
const auto& components = CServiceBroker::GetAppComponents(); |
| 49 |
const auto appPlayer = components.GetComponent<CApplicationPlayer>(); |
| 50 |
if (appPlayer->IsPlaying() && (!appPlayer->IsRemotePlaying() || appPlayer->HasAudio())) |
| 51 |
{ |
| 52 |
CGUIComponent* gui = CServiceBroker::GetGUI(); |
| 53 |
if (gui) |
| 54 |
gui->GetWindowManager().SwitchToFullScreen(); |
| 55 |
|
| 56 |
return true; |
| 57 |
} |
| 58 |
} |
| 59 |
return CGUIWindow::OnAction(action); |
| 60 |
} |
| 61 |
|
| 62 |
void CGUIWindowHome::OnInitWindow() |
| 63 |
{ |
| 64 |
// for shared databases (ie mysql) always force an update on return to home |
| 65 |
// this is a temporary solution until remote announcements can be delivered |
| 66 |
if (StringUtils::EqualsNoCase(CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_databaseVideo.type, "mysql") || |
| 67 |
StringUtils::EqualsNoCase(CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_databaseMusic.type, "mysql") ) |
| 68 |
m_updateRA = (Audio | Video | Totals); |
| 69 |
AddRecentlyAddedJobs( m_updateRA ); |
| 70 |
|
| 71 |
CGUIWindow::OnInitWindow(); |
| 72 |
} |
| 73 |
|
| 74 |
void CGUIWindowHome::Announce(ANNOUNCEMENT::AnnouncementFlag flag, |
| 75 |
const std::string& sender, |
| 76 |
const std::string& message, |
| 77 |
const CVariant& data) |
| 78 |
{ |
| 79 |
int ra_flag = 0; |
| 80 |
|
| 81 |
CLog::Log(LOGDEBUG, LOGANNOUNCE, "GOT ANNOUNCEMENT, type: {}, from {}, message {}", |
| 82 |
AnnouncementFlagToString(flag), sender, message); |
| 83 |
|
| 84 |
// we are only interested in library changes |
| 85 |
if ((flag & (ANNOUNCEMENT::VideoLibrary | ANNOUNCEMENT::AudioLibrary)) == 0) |
| 86 |
return; |
| 87 |
|
| 88 |
if (data.isMember("transaction") && data["transaction"].asBoolean()) |
| 89 |
return; |
| 90 |
|
| 91 |
if (message == "OnScanStarted" || message == "OnCleanStarted") |
| 92 |
return; |
| 93 |
|
| 94 |
bool onUpdate = message == "OnUpdate"; |
| 95 |
// always update Totals except on an OnUpdate with no playcount update |
| 96 |
if (!onUpdate || data.isMember("playcount")) |
| 97 |
ra_flag |= Totals; |
| 98 |
|
| 99 |
// always update the full list except on an OnUpdate |
| 100 |
if (!onUpdate) |
| 101 |
{ |
| 102 |
if (flag & ANNOUNCEMENT::VideoLibrary) |
| 103 |
ra_flag |= Video; |
| 104 |
else if (flag & ANNOUNCEMENT::AudioLibrary) |
| 105 |
ra_flag |= Audio; |
| 106 |
} |
| 107 |
|
| 108 |
CGUIMessage reload(GUI_MSG_NOTIFY_ALL, GetID(), 0, GUI_MSG_REFRESH_THUMBS, ra_flag); |
| 109 |
CServiceBroker::GetGUI()->GetWindowManager().SendThreadMessage(reload, GetID()); |
| 110 |
} |
| 111 |
|
| 112 |
void CGUIWindowHome::AddRecentlyAddedJobs(int flag) |
| 113 |
{ |
| 114 |
bool getAJob = false; |
| 115 |
|
| 116 |
// this block checks to see if another one is running |
| 117 |
// and keeps track of the flag |
| 118 |
{ |
| 119 |
std::unique_lock<CCriticalSection> lockMe(*this); |
| 120 |
if (!m_recentlyAddedRunning) |
| 121 |
{ |
| 122 |
getAJob = true; |
| 123 |
|
| 124 |
flag |= m_cumulativeUpdateFlag; // add the flags from previous calls to AddRecentlyAddedJobs |
| 125 |
|
| 126 |
m_cumulativeUpdateFlag = 0; // now taken care of in flag. |
| 127 |
// reset this since we're going to execute a job |
| 128 |
|
| 129 |
// we're about to add one so set the indicator |
| 130 |
if (flag) |
| 131 |
m_recentlyAddedRunning = true; // this will happen in the if clause below |
| 132 |
} |
| 133 |
else |
| 134 |
// since we're going to skip a job, mark that one came in and ... |
| 135 |
m_cumulativeUpdateFlag |= flag; // this will be used later |
| 136 |
} |
| 137 |
|
| 138 |
if (flag && getAJob) |
| 139 |
CServiceBroker::GetJobManager()->AddJob(new CRecentlyAddedJob(flag), this); |
| 140 |
|
| 141 |
m_updateRA = 0; |
| 142 |
} |
| 143 |
|
| 144 |
void CGUIWindowHome::OnJobComplete(unsigned int jobID, bool success, CJob *job) |
| 145 |
{ |
| 146 |
int flag = 0; |
| 147 |
|
| 148 |
{ |
| 149 |
std::unique_lock<CCriticalSection> lockMe(*this); |
| 150 |
|
| 151 |
// the job is finished. |
| 152 |
// did one come in the meantime? |
| 153 |
flag = m_cumulativeUpdateFlag; |
| 154 |
m_recentlyAddedRunning = false; /// we're done. |
| 155 |
} |
| 156 |
|
| 157 |
if (flag) |
| 158 |
AddRecentlyAddedJobs(0 /* the flag will be set inside AddRecentlyAddedJobs via m_cumulativeUpdateFlag */ ); |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
bool CGUIWindowHome::OnMessage(CGUIMessage& message) |
| 163 |
{ |
| 164 |
switch ( message.GetMessage() ) |
| 165 |
{ |
| 166 |
case GUI_MSG_NOTIFY_ALL: |
| 167 |
if (message.GetParam1() == GUI_MSG_WINDOW_RESET || message.GetParam1() == GUI_MSG_REFRESH_THUMBS) |
| 168 |
{ |
| 169 |
int updateRA = (message.GetSenderId() == GetID()) ? message.GetParam2() : (Video | Audio | Totals); |
| 170 |
|
| 171 |
if (IsActive()) |
| 172 |
AddRecentlyAddedJobs(updateRA); |
| 173 |
else |
| 174 |
m_updateRA |= updateRA; |
| 175 |
} |
| 176 |
break; |
| 177 |
|
| 178 |
default: |
| 179 |
break; |
| 180 |
} |
| 181 |
|
| 182 |
return CGUIWindow::OnMessage(message); |
| 183 |
} |