diff options
| author | manuel <manuel@mausz.at> | 2015-03-03 16:53:59 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2015-03-03 16:53:59 +0100 |
| commit | ffca21f2743a7b367fa212799c6e2fea6190dd5d (patch) | |
| tree | 0608ea3a29cf644ec9ab204e2b4bb9bfaae1c381 /xbmc/addons/AddonStatusHandler.cpp | |
| download | kodi-pvr-build-ffca21f2743a7b367fa212799c6e2fea6190dd5d.tar.gz kodi-pvr-build-ffca21f2743a7b367fa212799c6e2fea6190dd5d.tar.bz2 kodi-pvr-build-ffca21f2743a7b367fa212799c6e2fea6190dd5d.zip | |
initial commit for kodi master
Diffstat (limited to 'xbmc/addons/AddonStatusHandler.cpp')
| -rw-r--r-- | xbmc/addons/AddonStatusHandler.cpp | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/xbmc/addons/AddonStatusHandler.cpp b/xbmc/addons/AddonStatusHandler.cpp new file mode 100644 index 0000000..7bb874a --- /dev/null +++ b/xbmc/addons/AddonStatusHandler.cpp | |||
| @@ -0,0 +1,175 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2005-2013 Team XBMC | ||
| 3 | * http://xbmc.org | ||
| 4 | * | ||
| 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) | ||
| 8 | * any later version. | ||
| 9 | * | ||
| 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. | ||
| 14 | * | ||
| 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/>. | ||
| 18 | * | ||
| 19 | */ | ||
| 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" | ||
| 32 | |||
| 33 | namespace ADDON | ||
| 34 | { | ||
| 35 | |||
| 36 | /********************************************************** | ||
| 37 | * CAddonStatusHandler - AddOn Status Report Class | ||
| 38 | * | ||
| 39 | * Used to informate the user about occurred errors and | ||
| 40 | * changes inside Add-on's, and ask him what to do. | ||
| 41 | * | ||
| 42 | */ | ||
| 43 | |||
| 44 | CCriticalSection CAddonStatusHandler::m_critSection; | ||
| 45 | |||
| 46 | CAddonStatusHandler::CAddonStatusHandler(const std::string &addonID, ADDON_STATUS status, std::string message, bool sameThread) | ||
| 47 | : CThread(("AddonStatus " + addonID).c_str()) | ||
| 48 | { | ||
| 49 | if (!CAddonMgr::Get().GetAddon(addonID, m_addon)) | ||
| 50 | return; | ||
| 51 | |||
| 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"); | ||
| 53 | |||
| 54 | m_status = status; | ||
| 55 | m_message = message; | ||
| 56 | |||
| 57 | if (sameThread) | ||
| 58 | { | ||
| 59 | Process(); | ||
| 60 | } | ||
| 61 | else | ||
| 62 | { | ||
| 63 | Create(true, THREAD_MINSTACKSIZE); | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | CAddonStatusHandler::~CAddonStatusHandler() | ||
| 68 | { | ||
| 69 | StopThread(); | ||
| 70 | } | ||
| 71 | |||
| 72 | void CAddonStatusHandler::OnStartup() | ||
| 73 | { | ||
| 74 | SetPriority(GetMinPriority()); | ||
| 75 | } | ||
| 76 | |||
| 77 | void CAddonStatusHandler::OnExit() | ||
| 78 | { | ||
| 79 | } | ||
| 80 | |||
| 81 | void CAddonStatusHandler::Process() | ||
| 82 | { | ||
| 83 | CSingleLock lock(m_critSection); | ||
| 84 | |||
| 85 | std::string heading = StringUtils::Format("%s: %s", TranslateType(m_addon->Type(), true).c_str(), m_addon->Name().c_str()); | ||
| 86 | |||
| 87 | /* AddOn lost connection to his backend (for ones that use Network) */ | ||
| 88 | if (m_status == ADDON_STATUS_LOST_CONNECTION) | ||
| 89 | { | ||
| 90 | if (m_addon->Type() == ADDON_PVRDLL) | ||
| 91 | { | ||
| 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 | ||
| 95 | } | ||
| 96 | else | ||
| 97 | { | ||
| 98 | CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO); | ||
| 99 | if (!pDialog) return; | ||
| 100 | |||
| 101 | pDialog->SetHeading(heading); | ||
| 102 | pDialog->SetLine(1, 24070); | ||
| 103 | pDialog->SetLine(2, 24073); | ||
| 104 | |||
| 105 | //send message and wait for user input | ||
| 106 | ThreadMessage tMsg = {TMSG_DIALOG_DOMODAL, WINDOW_DIALOG_YES_NO, g_windowManager.GetActiveWindow()}; | ||
| 107 | CApplicationMessenger::Get().SendMessage(tMsg, true); | ||
| 108 | |||
| 109 | if (pDialog->IsConfirmed()) | ||
| 110 | CAddonMgr::Get().GetCallbackForType(m_addon->Type())->RequestRestart(m_addon, false); | ||
| 111 | } | ||
| 112 | } | ||
| 113 | /* Request to restart the AddOn and data structures need updated */ | ||
| 114 | else if (m_status == ADDON_STATUS_NEED_RESTART) | ||
| 115 | { | ||
| 116 | CGUIDialogOK* pDialog = (CGUIDialogOK*)g_windowManager.GetWindow(WINDOW_DIALOG_OK); | ||
| 117 | if (!pDialog) return; | ||
| 118 | |||
| 119 | pDialog->SetHeading(heading); | ||
| 120 | pDialog->SetLine(1, 24074); | ||
| 121 | |||
| 122 | //send message and wait for user input | ||
| 123 | ThreadMessage tMsg = {TMSG_DIALOG_DOMODAL, WINDOW_DIALOG_OK, g_windowManager.GetActiveWindow()}; | ||
| 124 | CApplicationMessenger::Get().SendMessage(tMsg, true); | ||
| 125 | |||
| 126 | CAddonMgr::Get().GetCallbackForType(m_addon->Type())->RequestRestart(m_addon, true); | ||
| 127 | } | ||
| 128 | /* Some required settings are missing/invalid */ | ||
| 129 | else if ((m_status == ADDON_STATUS_NEED_SETTINGS) || (m_status == ADDON_STATUS_NEED_SAVEDSETTINGS)) | ||
| 130 | { | ||
| 131 | CGUIDialogYesNo* pDialogYesNo = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO); | ||
| 132 | if (!pDialogYesNo) return; | ||
| 133 | |||
| 134 | pDialogYesNo->SetHeading(heading); | ||
| 135 | pDialogYesNo->SetLine(1, 24070); | ||
| 136 | pDialogYesNo->SetLine(2, 24072); | ||
| 137 | pDialogYesNo->SetLine(3, m_message); | ||
| 138 | |||
| 139 | //send message and wait for user input | ||
| 140 | ThreadMessage tMsg = {TMSG_DIALOG_DOMODAL, WINDOW_DIALOG_YES_NO, g_windowManager.GetActiveWindow()}; | ||
| 141 | CApplicationMessenger::Get().SendMessage(tMsg, true); | ||
| 142 | |||
| 143 | if (!pDialogYesNo->IsConfirmed()) return; | ||
| 144 | |||
| 145 | if (!m_addon->HasSettings()) | ||
| 146 | return; | ||
| 147 | |||
| 148 | if (CGUIDialogAddonSettings::ShowAndGetInput(m_addon)) | ||
| 149 | { | ||
| 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); | ||
| 153 | } | ||
| 154 | } | ||
| 155 | /* A unknown event has occurred */ | ||
| 156 | else if (m_status == ADDON_STATUS_UNKNOWN) | ||
| 157 | { | ||
| 158 | //CAddonMgr::Get().DisableAddon(m_addon->ID()); | ||
| 159 | CGUIDialogOK* pDialog = (CGUIDialogOK*)g_windowManager.GetWindow(WINDOW_DIALOG_OK); | ||
| 160 | if (!pDialog) return; | ||
| 161 | |||
| 162 | pDialog->SetHeading(heading); | ||
| 163 | pDialog->SetLine(1, 24070); | ||
| 164 | pDialog->SetLine(2, 24071); | ||
| 165 | pDialog->SetLine(3, m_message); | ||
| 166 | |||
| 167 | //send message and wait for user input | ||
| 168 | ThreadMessage tMsg = {TMSG_DIALOG_DOMODAL, WINDOW_DIALOG_OK, g_windowManager.GetActiveWindow()}; | ||
| 169 | CApplicationMessenger::Get().SendMessage(tMsg, true); | ||
| 170 | } | ||
| 171 | } | ||
| 172 | |||
| 173 | |||
| 174 | } /*namespace ADDON*/ | ||
| 175 | |||
