[Test] Added tests for CUtil::SplitParams
[xbmc.git] / xbmc / windows / GUIWindowHome.cpp
blobc94c9e6be20e533dc4e73816f994a6538b66531b
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() && (!appPlayer->IsRemotePlaying() || appPlayer->HasAudio()))
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 {}",
82 AnnouncementFlagToString(flag), sender, message);
84 // we are only interested in library changes
85 if ((flag & (ANNOUNCEMENT::VideoLibrary | ANNOUNCEMENT::AudioLibrary)) == 0)
86 return;
88 if (data.isMember("transaction") && data["transaction"].asBoolean())
89 return;
91 if (message == "OnScanStarted" || message == "OnCleanStarted")
92 return;
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;
99 // always update the full list except on an OnUpdate
100 if (!onUpdate)
102 if (flag & ANNOUNCEMENT::VideoLibrary)
103 ra_flag |= Video;
104 else if (flag & ANNOUNCEMENT::AudioLibrary)
105 ra_flag |= Audio;
108 CGUIMessage reload(GUI_MSG_NOTIFY_ALL, GetID(), 0, GUI_MSG_REFRESH_THUMBS, ra_flag);
109 CServiceBroker::GetGUI()->GetWindowManager().SendThreadMessage(reload, GetID());
112 void CGUIWindowHome::AddRecentlyAddedJobs(int flag)
114 bool getAJob = false;
116 // this block checks to see if another one is running
117 // and keeps track of the flag
119 std::unique_lock<CCriticalSection> lockMe(*this);
120 if (!m_recentlyAddedRunning)
122 getAJob = true;
124 flag |= m_cumulativeUpdateFlag; // add the flags from previous calls to AddRecentlyAddedJobs
126 m_cumulativeUpdateFlag = 0; // now taken care of in flag.
127 // reset this since we're going to execute a job
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
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
138 if (flag && getAJob)
139 CServiceBroker::GetJobManager()->AddJob(new CRecentlyAddedJob(flag), this);
141 m_updateRA = 0;
144 void CGUIWindowHome::OnJobComplete(unsigned int jobID, bool success, CJob *job)
146 int flag = 0;
149 std::unique_lock<CCriticalSection> lockMe(*this);
151 // the job is finished.
152 // did one come in the meantime?
153 flag = m_cumulativeUpdateFlag;
154 m_recentlyAddedRunning = false; /// we're done.
157 if (flag)
158 AddRecentlyAddedJobs(0 /* the flag will be set inside AddRecentlyAddedJobs via m_cumulativeUpdateFlag */ );
162 bool CGUIWindowHome::OnMessage(CGUIMessage& message)
164 switch ( message.GetMessage() )
166 case GUI_MSG_NOTIFY_ALL:
167 if (message.GetParam1() == GUI_MSG_WINDOW_RESET || message.GetParam1() == GUI_MSG_REFRESH_THUMBS)
169 int updateRA = (message.GetSenderId() == GetID()) ? message.GetParam2() : (Video | Audio | Totals);
171 if (IsActive())
172 AddRecentlyAddedJobs(updateRA);
173 else
174 m_updateRA |= updateRA;
176 break;
178 default:
179 break;
182 return CGUIWindow::OnMessage(message);