2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "GUIWindowHome.h"
22 #include "guilib/Key.h"
23 #include "guilib/WindowIDs.h"
24 #include "utils/JobManager.h"
25 #include "utils/RecentlyAddedJob.h"
26 #include "interfaces/AnnouncementManager.h"
27 #include "utils/log.h"
28 #include "settings/AdvancedSettings.h"
29 #include "utils/Variant.h"
30 #include "guilib/GUIWindowManager.h"
31 #include "Application.h"
33 using namespace ANNOUNCEMENT;
35 CGUIWindowHome::CGUIWindowHome(void) : CGUIWindow(WINDOW_HOME, "Home.xml"),
36 m_recentlyAddedRunning(false),
37 m_cumulativeUpdateFlag(0),
40 m_updateRA = (Audio | Video | Totals);
41 m_loadType = KEEP_IN_MEMORY;
43 CAnnouncementManager::AddAnnouncer(this);
46 CGUIWindowHome::~CGUIWindowHome(void)
48 CAnnouncementManager::RemoveAnnouncer(this);
51 bool CGUIWindowHome::OnAction(const CAction &action)
53 static unsigned int min_hold_time = 1000;
54 if (action.GetID() == ACTION_NAV_BACK &&
55 action.GetHoldTime() < min_hold_time &&
56 g_application.m_pPlayer->IsPlaying())
58 g_application.SwitchToFullScreen();
61 return CGUIWindow::OnAction(action);
64 void CGUIWindowHome::OnInitWindow()
66 // for shared databases (ie mysql) always force an update on return to home
67 // this is a temporary solution until remote announcements can be delivered
68 if ( g_advancedSettings.m_databaseVideo.type.Equals("mysql") ||
69 g_advancedSettings.m_databaseMusic.type.Equals("mysql") )
70 m_updateRA = (Audio | Video | Totals);
71 AddRecentlyAddedJobs( m_updateRA );
73 CGUIWindow::OnInitWindow();
76 void CGUIWindowHome::Announce(AnnouncementFlag flag, const char *sender, const char *message, const CVariant &data)
80 CLog::Log(LOGDEBUG, "GOT ANNOUNCEMENT, type: %i, from %s, message %s",(int)flag, sender, message);
82 // we are only interested in library changes
83 if ((flag & (VideoLibrary | AudioLibrary)) == 0)
86 if (strcmp(message, "OnScanStarted") == 0 ||
87 strcmp(message, "OnCleanStarted") == 0)
93 if (strcmp(message, "OnScanFinished") == 0 ||
94 strcmp(message, "OnCleanFinished") == 0)
97 // we are in an update/clean
101 bool onUpdate = strcmp(message, "OnUpdate") == 0;
102 // always update Totals except on an OnUpdate with no playcount update
103 if (!onUpdate || data.isMember("playcount"))
106 // always update the full list except on an OnUpdate
109 if (flag & VideoLibrary)
111 else if (flag & AudioLibrary)
115 CGUIMessage reload(GUI_MSG_NOTIFY_ALL, GetID(), 0, GUI_MSG_REFRESH_THUMBS, ra_flag);
116 g_windowManager.SendThreadMessage(reload, GetID());
119 void CGUIWindowHome::AddRecentlyAddedJobs(int flag)
121 bool getAJob = false;
123 // this block checks to see if another one is running
124 // and keeps track of the flag
126 CSingleLock lockMe(*this);
127 if (!m_recentlyAddedRunning)
131 flag |= m_cumulativeUpdateFlag; // add the flags from previous calls to AddRecentlyAddedJobs
133 m_cumulativeUpdateFlag = 0; // now taken care of in flag.
134 // reset this since we're going to execute a job
136 // we're about to add one so set the indicator
138 m_recentlyAddedRunning = true; // this will happen in the if clause below
141 // since we're going to skip a job, mark that one came in and ...
142 m_cumulativeUpdateFlag |= flag; // this will be used later
146 CJobManager::GetInstance().AddJob(new CRecentlyAddedJob(flag), this);
151 void CGUIWindowHome::OnJobComplete(unsigned int jobID, bool success, CJob *job)
156 CSingleLock lockMe(*this);
158 // the job is finished.
159 // did one come in in the meantime?
160 flag = m_cumulativeUpdateFlag;
161 m_recentlyAddedRunning = false; /// we're done.
165 AddRecentlyAddedJobs(0 /* the flag will be set inside AddRecentlyAddedJobs via m_cumulativeUpdateFlag */ );
169 bool CGUIWindowHome::OnMessage(CGUIMessage& message)
171 switch ( message.GetMessage() )
173 case GUI_MSG_NOTIFY_ALL:
174 if (message.GetParam1() == GUI_MSG_WINDOW_RESET || message.GetParam1() == GUI_MSG_REFRESH_THUMBS)
176 int updateRA = (message.GetSenderId() == GetID()) ? message.GetParam2() : (Video | Audio | Totals);
179 AddRecentlyAddedJobs(updateRA);
181 m_updateRA |= updateRA;
189 return CGUIWindow::OnMessage(message);