| 1 |
/* |
| 2 |
* Copyright (C) 2005-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
#include "AutorunMediaJob.h" |
| 9 |
|
| 10 |
#include "ServiceBroker.h" |
| 11 |
#include "application/ApplicationComponents.h" |
| 12 |
#include "application/ApplicationPowerHandling.h" |
| 13 |
#include "dialogs/GUIDialogSelect.h" |
| 14 |
#include "guilib/GUIComponent.h" |
| 15 |
#include "guilib/GUIWindowManager.h" |
| 16 |
#include "guilib/LocalizeStrings.h" |
| 17 |
#include "interfaces/builtins/Builtins.h" |
| 18 |
#include "utils/StringUtils.h" |
| 19 |
#include "utils/Variant.h" |
| 20 |
|
| 21 |
CAutorunMediaJob::CAutorunMediaJob(const std::string &label, const std::string &path): |
| 22 |
m_path(path), |
| 23 |
m_label(label) |
| 24 |
{ |
| 25 |
} |
| 26 |
|
| 27 |
bool CAutorunMediaJob::DoWork() |
| 28 |
{ |
| 29 |
CGUIDialogSelect* pDialog= CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogSelect>(WINDOW_DIALOG_SELECT); |
| 30 |
|
| 31 |
// wake up and turn off the screensaver if it's active |
| 32 |
auto& components = CServiceBroker::GetAppComponents(); |
| 33 |
const auto appPower = components.GetComponent<CApplicationPowerHandling>(); |
| 34 |
appPower->WakeUpScreenSaverAndDPMS(); |
| 35 |
|
| 36 |
pDialog->Reset(); |
| 37 |
if (!m_label.empty()) |
| 38 |
pDialog->SetHeading(CVariant{m_label}); |
| 39 |
else |
| 40 |
pDialog->SetHeading(CVariant{g_localizeStrings.Get(21331)}); |
| 41 |
|
| 42 |
pDialog->Add(g_localizeStrings.Get(21332)); |
| 43 |
pDialog->Add(g_localizeStrings.Get(21333)); |
| 44 |
pDialog->Add(g_localizeStrings.Get(21334)); |
| 45 |
pDialog->Add(g_localizeStrings.Get(21335)); |
| 46 |
|
| 47 |
pDialog->Open(); |
| 48 |
|
| 49 |
int selection = pDialog->GetSelectedItem(); |
| 50 |
if (selection >= 0) |
| 51 |
{ |
| 52 |
std::string strAction = |
| 53 |
StringUtils::Format("ActivateWindow({}, {})", GetWindowString(selection), m_path); |
| 54 |
CBuiltins::GetInstance().Execute(strAction); |
| 55 |
} |
| 56 |
|
| 57 |
return true; |
| 58 |
} |
| 59 |
|
| 60 |
const char *CAutorunMediaJob::GetWindowString(int selection) |
| 61 |
{ |
| 62 |
switch (selection) |
| 63 |
{ |
| 64 |
case 0: |
| 65 |
return "Videos"; |
| 66 |
case 1: |
| 67 |
return "Music"; |
| 68 |
case 2: |
| 69 |
return "Pictures"; |
| 70 |
case 3: |
| 71 |
return "FileManager"; |
| 72 |
default: |
| 73 |
return "FileManager"; |
| 74 |
} |
| 75 |
} |