summaryrefslogtreecommitdiffstats
path: root/xbmc/storage/AutorunMediaJob.cpp
blob: 72e784f48afa85049dd55b4fbb428af1c04ec1d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 *  Copyright (C) 2005-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */
#include "AutorunMediaJob.h"

#include "ServiceBroker.h"
#include "application/ApplicationComponents.h"
#include "application/ApplicationPowerHandling.h"
#include "dialogs/GUIDialogSelect.h"
#include "guilib/GUIComponent.h"
#include "guilib/GUIWindowManager.h"
#include "guilib/LocalizeStrings.h"
#include "interfaces/builtins/Builtins.h"
#include "utils/StringUtils.h"
#include "utils/Variant.h"

CAutorunMediaJob::CAutorunMediaJob(const std::string &label, const std::string &path):
  m_path(path),
  m_label(label)
{
}

bool CAutorunMediaJob::DoWork()
{
  CGUIDialogSelect* pDialog= CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogSelect>(WINDOW_DIALOG_SELECT);

  // wake up and turn off the screensaver if it's active
  auto& components = CServiceBroker::GetAppComponents();
  const auto appPower = components.GetComponent<CApplicationPowerHandling>();
  appPower->WakeUpScreenSaverAndDPMS();

  pDialog->Reset();
  if (!m_label.empty())
    pDialog->SetHeading(CVariant{m_label});
  else
    pDialog->SetHeading(CVariant{g_localizeStrings.Get(21331)});

  pDialog->Add(g_localizeStrings.Get(21332));
  pDialog->Add(g_localizeStrings.Get(21333));
  pDialog->Add(g_localizeStrings.Get(21334));
  pDialog->Add(g_localizeStrings.Get(21335));

  pDialog->Open();

  int selection = pDialog->GetSelectedItem();
  if (selection >= 0)
  {
    std::string strAction =
        StringUtils::Format("ActivateWindow({}, {})", GetWindowString(selection), m_path);
    CBuiltins::GetInstance().Execute(strAction);
  }

  return true;
}

const char *CAutorunMediaJob::GetWindowString(int selection)
{
  switch (selection)
  {
    case 0:
      return "Videos";
    case 1:
      return "Music";
    case 2:
      return "Pictures";
    case 3:
      return "FileManager";
    default:
      return "FileManager";
  }
}