[Windows] Remove redundant DirectSound error codes
[xbmc.git] / xbmc / windows / GUIWindowHome.cpp
blob6505db0356c166c7a57d3c89a255b7aaf90c76b2
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "GUIWindowHome.h"
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"
28 #include <mutex>
30 CGUIWindowHome::CGUIWindowHome(void) : CGUIWindow(WINDOW_HOME, "Home.xml")
32 m_updateRA = (Audio | Video | Totals);
33 m_loadType = KEEP_IN_MEMORY;
35 CServiceBroker::GetAnnouncementManager()->AddAnnouncer(this, ANNOUNCEMENT::VideoLibrary |
36 ANNOUNCEMENT::AudioLibrary);
39 CGUIWindowHome::~CGUIWindowHome(void)
41 CServiceBroker::GetAnnouncementManager()->RemoveAnnouncer(this);
44 bool CGUIWindowHome::OnAction(const CAction &action)
46 static unsigned int min_hold_time = 1000;
47 if (action.GetID() == ACTION_NAV_BACK && action.GetHoldTime() < min_hold_time)
49 const auto& components = CServiceBroker::GetAppComponents();
50 const auto appPlayer = components.GetComponent<CApplicationPlayer>();
51 if (appPlayer->IsPlaying() && (!appPlayer->IsRemotePlaying() || appPlayer->HasAudio()))
53 CGUIComponent* gui = CServiceBroker::GetGUI();
54 if (gui)
55 gui->GetWindowManager().SwitchToFullScreen();
57 return true;
60 return CGUIWindow::OnAction(action);
63 void CGUIWindowHome::OnInitWindow()
65 // for shared databases (ie mysql) always force an update on return to home
66 // this is a temporary solution until remote announcements can be delivered
67 if (StringUtils::EqualsNoCase(CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_databaseVideo.type, "mysql") ||
68 StringUtils::EqualsNoCase(CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_databaseMusic.type, "mysql") )
69 m_updateRA = (Audio | Video | Totals);
70 AddRecentlyAddedJobs( m_updateRA );
72 CGUIWindow::OnInitWindow();
75 void CGUIWindowHome::Announce(ANNOUNCEMENT::AnnouncementFlag flag,
76 const std::string& sender,
77 const std::string& message,
78 const CVariant& data)
80 int ra_flag = 0;
82 CLog::Log(LOGDEBUG, LOGANNOUNCE, "GOT ANNOUNCEMENT, type: {}, from {}, message {}",
83 AnnouncementFlagToString(flag), sender, message);
85 if (data.isMember("transaction") && data["transaction"].asBoolean())
86 return;
88 if (message == "OnScanStarted" || message == "OnCleanStarted")
89 return;
91 bool onUpdate = message == "OnUpdate";
92 // always update Totals except on an OnUpdate with no playcount update
93 if (!onUpdate || data.isMember("playcount"))
94 ra_flag |= Totals;
96 // always update the full list except on an OnUpdate
97 if (!onUpdate)
99 if (flag & ANNOUNCEMENT::VideoLibrary)
100 ra_flag |= Video;
101 else if (flag & ANNOUNCEMENT::AudioLibrary)
102 ra_flag |= Audio;
105 CGUIMessage reload(GUI_MSG_NOTIFY_ALL, GetID(), 0, GUI_MSG_REFRESH_THUMBS, ra_flag);
106 CServiceBroker::GetGUI()->GetWindowManager().SendThreadMessage(reload, GetID());
109 void CGUIWindowHome::AddRecentlyAddedJobs(int flag)
111 bool getAJob = false;
113 // this block checks to see if another one is running
114 // and keeps track of the flag
116 std::unique_lock<CCriticalSection> lockMe(*this);
117 if (!m_recentlyAddedRunning)
119 getAJob = true;
121 flag |= m_cumulativeUpdateFlag; // add the flags from previous calls to AddRecentlyAddedJobs
123 m_cumulativeUpdateFlag = 0; // now taken care of in flag.
124 // reset this since we're going to execute a job
126 // we're about to add one so set the indicator
127 if (flag)
128 m_recentlyAddedRunning = true; // this will happen in the if clause below
130 else
131 // since we're going to skip a job, mark that one came in and ...
132 m_cumulativeUpdateFlag |= flag; // this will be used later
135 if (flag && getAJob)
136 CServiceBroker::GetJobManager()->AddJob(new CRecentlyAddedJob(flag), this);
138 m_updateRA = 0;
141 void CGUIWindowHome::OnJobComplete(unsigned int jobID, bool success, CJob *job)
143 int flag = 0;
146 std::unique_lock<CCriticalSection> lockMe(*this);
148 // the job is finished.
149 // did one come in the meantime?
150 flag = m_cumulativeUpdateFlag;
151 m_recentlyAddedRunning = false; /// we're done.
154 if (flag)
155 AddRecentlyAddedJobs(0 /* the flag will be set inside AddRecentlyAddedJobs via m_cumulativeUpdateFlag */ );
159 bool CGUIWindowHome::OnMessage(CGUIMessage& message)
161 switch ( message.GetMessage() )
163 case GUI_MSG_NOTIFY_ALL:
164 if (message.GetParam1() == GUI_MSG_WINDOW_RESET || message.GetParam1() == GUI_MSG_REFRESH_THUMBS)
166 int updateRA = (message.GetSenderId() == GetID()) ? message.GetParam2() : (Video | Audio | Totals);
168 if (IsActive())
169 AddRecentlyAddedJobs(updateRA);
170 else
171 m_updateRA |= updateRA;
173 break;
175 default:
176 break;
179 return CGUIWindow::OnMessage(message);