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 
9 #include "DialogHelper.h"
10 
11 #include "messaging/ApplicationMessenger.h"
12 
13 #include <cassert>
14 #include <utility>
15 
16 namespace KODI
17 {
18 namespace MESSAGING
19 {
20 namespace HELPERS
21 {
ShowYesNoDialogText(CVariant heading,CVariant text,CVariant noLabel,CVariant yesLabel,uint32_t autoCloseTimeout)22 DialogResponse ShowYesNoDialogText(CVariant heading, CVariant text, CVariant noLabel, CVariant yesLabel, uint32_t autoCloseTimeout)
23 {
24   return ShowYesNoCustomDialog(std::move(heading), std::move(text), std::move(noLabel),
25                                std::move(yesLabel), "", autoCloseTimeout);
26 }
27 
ShowYesNoCustomDialog(CVariant heading,CVariant text,CVariant noLabel,CVariant yesLabel,CVariant customLabel,uint32_t autoCloseTimeout)28 DialogResponse ShowYesNoCustomDialog(CVariant heading, CVariant text, CVariant noLabel, CVariant yesLabel, CVariant customLabel, uint32_t autoCloseTimeout)
29 {
30   DialogYesNoMessage options;
31   options.heading = std::move(heading);
32   options.text = std::move(text);
33   options.noLabel = std::move(noLabel);
34   options.yesLabel = std::move(yesLabel);
35   options.customLabel = std::move(customLabel);
36   options.autoclose = autoCloseTimeout;
37 
38   switch (CApplicationMessenger::GetInstance().SendMsg(TMSG_GUI_DIALOG_YESNO, -1, -1, static_cast<void*>(&options)))
39   {
40   case -1:
41     return DialogResponse::CANCELLED;
42   case 0:
43     return DialogResponse::NO;
44   case 1:
45     return DialogResponse::YES;
46   case 2:
47     return DialogResponse::CUSTOM;
48   default:
49     //If we get here someone changed the return values without updating this code
50     assert(false);
51   }
52   //This is unreachable code but we need to return something to suppress warnings about
53   //no return
54   return DialogResponse::CANCELLED;
55 }
56 
ShowYesNoDialogLines(CVariant heading,CVariant line0,CVariant line1,CVariant line2,CVariant noLabel,CVariant yesLabel,uint32_t autoCloseTimeout)57 DialogResponse ShowYesNoDialogLines(CVariant heading, CVariant line0, CVariant line1, CVariant line2,
58   CVariant noLabel, CVariant yesLabel, uint32_t autoCloseTimeout)
59 {
60   DialogYesNoMessage options;
61   options.heading = std::move(heading);
62   options.lines[0] = std::move(line0);
63   options.lines[1] = std::move(line1);
64   options.lines[2] = std::move(line2);
65   options.noLabel = std::move(noLabel);
66   options.yesLabel = std::move(yesLabel);
67   options.customLabel = "";
68   options.autoclose = autoCloseTimeout;
69 
70   switch (CApplicationMessenger::GetInstance().SendMsg(TMSG_GUI_DIALOG_YESNO, -1, -1, static_cast<void*>(&options)))
71   {
72   case -1:
73     return DialogResponse::CANCELLED;
74   case 0:
75     return DialogResponse::NO;
76   case 1:
77     return DialogResponse::YES;
78   case 2:
79     return DialogResponse::CUSTOM;
80   default:
81     //If we get here someone changed the return values without updating this code
82     assert(false);
83   }
84   //This is unreachable code but we need to return something to suppress warnings about
85   //no return
86   return DialogResponse::CANCELLED;
87 }
88 
89 }
90 }
91 }
92