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.
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"
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();
54 gui
->GetWindowManager().SwitchToFullScreen();
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
,
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)
87 if (data
.isMember("transaction") && data
["transaction"].asBoolean())
90 if (message
== "OnScanStarted" || message
== "OnCleanStarted")
93 bool onUpdate
= message
== "OnUpdate";
94 // always update Totals except on an OnUpdate with no playcount update
95 if (!onUpdate
|| data
.isMember("playcount"))
98 // always update the full list except on an OnUpdate
101 if (flag
& ANNOUNCEMENT::VideoLibrary
)
103 else if (flag
& ANNOUNCEMENT::AudioLibrary
)
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
)
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
130 m_recentlyAddedRunning
= true; // this will happen in the if clause below
133 // since we're going to skip a job, mark that one came in and ...
134 m_cumulativeUpdateFlag
|= flag
; // this will be used later
138 CServiceBroker::GetJobManager()->AddJob(new CRecentlyAddedJob(flag
), this);
143 void CGUIWindowHome::OnJobComplete(unsigned int jobID
, bool success
, CJob
*job
)
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.
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
);
171 AddRecentlyAddedJobs(updateRA
);
173 m_updateRA
|= updateRA
;
181 return CGUIWindow::OnMessage(message
);