[filesystem][SpecialProtocol] Removed assert from GetPath
[xbmc.git] / xbmc / windows / GUIWindowHome.cpp
blobc42e073c48ced6bc78f60a38508c903b3e1f5eb4
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);
38 CGUIWindowHome::~CGUIWindowHome(void)
40 CServiceBroker::GetAnnouncementManager()->RemoveAnnouncer(this);
43 bool CGUIWindowHome::OnAction(const CAction &action)
45 static unsigned int min_hold_time = 1000;
46 if (action.GetID() == ACTION_NAV_BACK && action.GetHoldTime() < min_hold_time)
48 const auto& components = CServiceBroker::GetAppComponents();
49 const auto appPlayer = components.GetComponent<CApplicationPlayer>();
50 if (appPlayer->IsPlaying())
52 CGUIComponent* gui = CServiceBroker::GetGUI();
53 if (gui)
54 gui->GetWindowManager().SwitchToFullScreen();
56 return true;
59 return CGUIWindow::OnAction(action);
62 void CGUIWindowHome::OnInitWindow()
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 );
71 CGUIWindow::OnInitWindow();
74 void CGUIWindowHome::Announce(ANNOUNCEMENT::AnnouncementFlag flag,
75 const std::string& sender,
76 const std::string& message,
77 const CVariant& data)
79 int ra_flag = 0;
81 CLog::Log(LOGDEBUG, LOGANNOUNCE, "GOT ANNOUNCEMENT, type: {}, from {}, message {}", flag, sender, message);
83 // we are only interested in library changes
84 if ((flag & (ANNOUNCEMENT::VideoLibrary | ANNOUNCEMENT::AudioLibrary)) == 0)
85 return;
87 if (data.isMember("transaction") && data["transaction"].asBoolean())
88 return;
90 if (message == "OnScanStarted" || message == "OnCleanStarted")
91 return;
93 bool onUpdate = message == "OnUpdate";
94 // always update Totals except on an OnUpdate with no playcount update
95 if (!onUpdate || data.isMember("playcount"))
96 ra_flag |= Totals;
98 // always update the full list except on an OnUpdate
99 if (!onUpdate)
101 if (flag & ANNOUNCEMENT::VideoLibrary)
102 ra_flag |= Video;
103 else if (flag & ANNOUNCEMENT::AudioLibrary)
104 ra_flag |= Audio;
107 CGUIMessage reload(GUI_MSG_NOTIFY_ALL, GetID(), 0, GUI_MSG_REFRESH_THUMBS, ra_flag);
108 CServiceBroker::GetGUI()->GetWindowManager().SendThreadMessage(reload, GetID());
111 void CGUIWindowHome::AddRecentlyAddedJobs(int flag)
113 bool getAJob = false;
115 // this block checks to see if another one is running
116 // and keeps track of the flag
118 std::unique_lock<CCriticalSection> lockMe(*this);
119 if (!m_recentlyAddedRunning)
121 getAJob = true;
123 flag |= m_cumulativeUpdateFlag; // add the flags from previous calls to AddRecentlyAddedJobs
125 m_cumulativeUpdateFlag = 0; // now taken care of in flag.
126 // reset this since we're going to execute a job
128 // we're about to add one so set the indicator
129 if (flag)
130 m_recentlyAddedRunning = true; // this will happen in the if clause below
132 else
133 // since we're going to skip a job, mark that one came in and ...
134 m_cumulativeUpdateFlag |= flag; // this will be used later
137 if (flag && getAJob)
138 CServiceBroker::GetJobManager()->AddJob(new CRecentlyAddedJob(flag), this);
140 m_updateRA = 0;
143 void CGUIWindowHome::OnJobComplete(unsigned int jobID, bool success, CJob *job)
145 int flag = 0;
148 std::unique_lock<CCriticalSection> lockMe(*this);
150 // the job is finished.
151 // did one come in the meantime?
152 flag = m_cumulativeUpdateFlag;
153 m_recentlyAddedRunning = false; /// we're done.
156 if (flag)
157 AddRecentlyAddedJobs(0 /* the flag will be set inside AddRecentlyAddedJobs via m_cumulativeUpdateFlag */ );
161 bool CGUIWindowHome::OnMessage(CGUIMessage& message)
163 switch ( message.GetMessage() )
165 case GUI_MSG_NOTIFY_ALL:
166 if (message.GetParam1() == GUI_MSG_WINDOW_RESET || message.GetParam1() == GUI_MSG_REFRESH_THUMBS)
168 int updateRA = (message.GetSenderId() == GetID()) ? message.GetParam2() : (Video | Audio | Totals);
170 if (IsActive())
171 AddRecentlyAddedJobs(updateRA);
172 else
173 m_updateRA |= updateRA;
175 break;
177 default:
178 break;
181 return CGUIWindow::OnMessage(message);