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 "threads/SystemClock.h"
22 #include "GUIDialogCache.h"
23 #include "ApplicationMessenger.h"
24 #include "guilib/GUIWindowManager.h"
25 #include "dialogs/GUIDialogProgress.h"
26 #include "guilib/LocalizeStrings.h"
27 #include "utils/log.h"
28 #include "threads/SingleLock.h"
29 #include "utils/TimeUtils.h"
31 CGUIDialogCache::CGUIDialogCache(DWORD dwDelay
, const CStdString
& strHeader
, const CStdString
& strMsg
) : CThread("GUIDialogCache")
33 m_strHeader
= strHeader
;
34 m_strLinePrev
= strMsg
;
37 m_pDlg
= (CGUIDialogProgress
*)g_windowManager
.GetWindow(WINDOW_DIALOG_PROGRESS
);
42 /* if progress dialog is already running, take it over */
43 if( m_pDlg
->IsDialogRunning() )
49 m_endtime
.Set((unsigned int)dwDelay
);
54 void CGUIDialogCache::Close(bool bForceClose
)
58 // we cannot wait for the app thread to process the close message
59 // as this might happen during player startup which leads to a deadlock
60 if (m_pDlg
&& m_pDlg
->IsDialogRunning())
61 CApplicationMessenger::Get().Close(m_pDlg
,bForceClose
,false);
63 //Set stop, this will kill this object, when thread stops
64 CThread::m_bStop
= true;
67 CGUIDialogCache::~CGUIDialogCache()
69 if(m_pDlg
&& m_pDlg
->IsDialogRunning())
73 void CGUIDialogCache::OpenDialog()
77 if (m_strHeader
.empty())
78 m_pDlg
->SetHeading(438);
80 m_pDlg
->SetHeading(m_strHeader
);
82 m_pDlg
->SetLine(2, m_strLinePrev
);
88 void CGUIDialogCache::SetHeader(const CStdString
& strHeader
)
90 m_strHeader
= strHeader
;
93 void CGUIDialogCache::SetHeader(int nHeader
)
95 SetHeader(g_localizeStrings
.Get(nHeader
));
98 void CGUIDialogCache::SetMessage(const CStdString
& strMessage
)
102 m_pDlg
->SetLine(0, m_strLinePrev2
);
103 m_pDlg
->SetLine(1, m_strLinePrev
);
104 m_pDlg
->SetLine(2, strMessage
);
106 m_strLinePrev2
= m_strLinePrev
;
107 m_strLinePrev
= strMessage
;
110 bool CGUIDialogCache::OnFileCallback(void* pContext
, int ipercent
, float avgSpeed
)
114 m_pDlg
->ShowProgressBar(true);
115 m_pDlg
->SetPercentage(ipercent
);
124 void CGUIDialogCache::Process()
132 { //Section to make the lock go out of scope before sleep
134 if( CThread::m_bStop
) break;
138 CSingleLock
lock(g_graphicsContext
);
146 if(m_pDlg
->IsCanceled())
150 else if( !m_pDlg
->IsDialogRunning() && m_endtime
.IsTimePast()
151 && !g_windowManager
.IsWindowActive(WINDOW_DIALOG_YES_NO
) )
156 CLog::Log(LOGERROR
, "Exception in CGUIDialogCache::Process()");
164 void CGUIDialogCache::ShowProgressBar(bool bOnOff
)
167 m_pDlg
->ShowProgressBar(bOnOff
);
170 void CGUIDialogCache::SetPercentage(int iPercentage
)
173 m_pDlg
->SetPercentage(iPercentage
);
176 bool CGUIDialogCache::IsCanceled() const
178 if (m_pDlg
&& m_pDlg
->IsDialogRunning())
179 return m_pDlg
->IsCanceled();