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/>.
20 #include "AddonStatusHandler.h"
21 #include "AddonManager.h"
22 #include "threads/SingleLock.h"
23 #include "ApplicationMessenger.h"
24 #include "guilib/GUIWindowManager.h"
25 #include "GUIDialogAddonSettings.h"
26 #include "dialogs/GUIDialogYesNo.h"
27 #include "dialogs/GUIDialogOK.h"
28 #include "dialogs/GUIDialogKaiToast.h"
29 #include "settings/Settings.h"
30 #include "utils/log.h"
31 #include "utils/StringUtils.h"
36 /**********************************************************
37 * CAddonStatusHandler - AddOn Status Report Class
39 * Used to informate the user about occurred errors and
40 * changes inside Add-on's, and ask him what to do.
44 CCriticalSection CAddonStatusHandler::m_critSection;
46 CAddonStatusHandler::CAddonStatusHandler(const CStdString &addonID, ADDON_STATUS status, CStdString message, bool sameThread)
47 : CThread("AddonStatus " + addonID)
49 if (!CAddonMgr::Get().GetAddon(addonID, m_addon))
52 CLog::Log(LOGINFO, "Called Add-on status handler for '%u' of clientName:%s, clientID:%s (same Thread=%s)", status, m_addon->Name().c_str(), m_addon->ID().c_str(), sameThread ? "yes" : "no");
63 Create(true, THREAD_MINSTACKSIZE);
67 CAddonStatusHandler::~CAddonStatusHandler()
72 void CAddonStatusHandler::OnStartup()
74 SetPriority(GetMinPriority());
77 void CAddonStatusHandler::OnExit()
81 void CAddonStatusHandler::Process()
83 CSingleLock lock(m_critSection);
85 CStdString heading = StringUtils::Format("%s: %s", TranslateType(m_addon->Type(), true).c_str(), m_addon->Name().c_str());
87 /* AddOn lost connection to his backend (for ones that use Network) */
88 if (m_status == ADDON_STATUS_LOST_CONNECTION)
90 if (m_addon->Type() == ADDON_PVRDLL)
92 if (!CSettings::Get().GetBool("pvrmanager.hideconnectionlostwarning"))
93 CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info, m_addon->Name().c_str(), g_localizeStrings.Get(36030)); // connection lost
94 // TODO handle disconnects after the add-on's been initialised
98 CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO);
101 pDialog->SetHeading(heading);
102 pDialog->SetLine(1, 24070);
103 pDialog->SetLine(2, 24073);
105 //send message and wait for user input
106 ThreadMessage tMsg = {TMSG_DIALOG_DOMODAL, WINDOW_DIALOG_YES_NO, (unsigned int)g_windowManager.GetActiveWindow()};
107 CApplicationMessenger::Get().SendMessage(tMsg, true);
109 if (pDialog->IsConfirmed())
110 CAddonMgr::Get().GetCallbackForType(m_addon->Type())->RequestRestart(m_addon, false);
113 /* Request to restart the AddOn and data structures need updated */
114 else if (m_status == ADDON_STATUS_NEED_RESTART)
116 CGUIDialogOK* pDialog = (CGUIDialogOK*)g_windowManager.GetWindow(WINDOW_DIALOG_OK);
117 if (!pDialog) return;
119 pDialog->SetHeading(heading);
120 pDialog->SetLine(1, 24074);
122 //send message and wait for user input
123 ThreadMessage tMsg = {TMSG_DIALOG_DOMODAL, WINDOW_DIALOG_OK, (unsigned int)g_windowManager.GetActiveWindow()};
124 CApplicationMessenger::Get().SendMessage(tMsg, true);
126 CAddonMgr::Get().GetCallbackForType(m_addon->Type())->RequestRestart(m_addon, true);
128 /* Some required settings are missing/invalid */
129 else if ((m_status == ADDON_STATUS_NEED_SETTINGS) || (m_status == ADDON_STATUS_NEED_SAVEDSETTINGS))
131 CGUIDialogYesNo* pDialogYesNo = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO);
132 if (!pDialogYesNo) return;
134 pDialogYesNo->SetHeading(heading);
135 pDialogYesNo->SetLine(1, 24070);
136 pDialogYesNo->SetLine(2, 24072);
137 pDialogYesNo->SetLine(3, m_message);
139 //send message and wait for user input
140 ThreadMessage tMsg = {TMSG_DIALOG_DOMODAL, WINDOW_DIALOG_YES_NO, (unsigned int)g_windowManager.GetActiveWindow()};
141 CApplicationMessenger::Get().SendMessage(tMsg, true);
143 if (!pDialogYesNo->IsConfirmed()) return;
145 if (!m_addon->HasSettings())
148 if (CGUIDialogAddonSettings::ShowAndGetInput(m_addon))
150 //todo doesn't dialogaddonsettings save these automatically? should do
151 m_addon->SaveSettings();
152 CAddonMgr::Get().GetCallbackForType(m_addon->Type())->RequestRestart(m_addon, true);
155 /* A unknown event has occurred */
156 else if (m_status == ADDON_STATUS_UNKNOWN)
158 //CAddonMgr::Get().DisableAddon(m_addon->ID());
159 CGUIDialogOK* pDialog = (CGUIDialogOK*)g_windowManager.GetWindow(WINDOW_DIALOG_OK);
160 if (!pDialog) return;
162 pDialog->SetHeading(heading);
163 pDialog->SetLine(1, 24070);
164 pDialog->SetLine(2, 24071);
165 pDialog->SetLine(3, m_message);
167 //send message and wait for user input
168 ThreadMessage tMsg = {TMSG_DIALOG_DOMODAL, WINDOW_DIALOG_OK, (unsigned int)g_windowManager.GetActiveWindow()};
169 CApplicationMessenger::Get().SendMessage(tMsg, true);
174 } /*namespace ADDON*/