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