Changeset View
Changeset View
Standalone View
Standalone View
src/snoretoastactions.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | SnoreToast is capable to invoke Windows 8 toast notifications. | ||||
3 | Copyright (C) 2013-2019 Hannah von Reth <vonreth@kde.org> | ||||
4 | | ||||
5 | SnoreToast is free software: you can redistribute it and/or modify | ||||
6 | it under the terms of the GNU Lesser General Public License as published by | ||||
7 | the Free Software Foundation, either version 3 of the License, or | ||||
8 | (at your option) any later version. | ||||
9 | | ||||
10 | SnoreToast 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 Lesser General Public License for more details. | ||||
14 | | ||||
15 | You should have received a copy of the GNU Lesser General Public License | ||||
16 | along with SnoreToast. If not, see <http://www.gnu.org/licenses/>. | ||||
17 | */ | ||||
18 | #pragma once | ||||
19 | | ||||
20 | #include <string> | ||||
21 | #include <map> | ||||
22 | #include <vector> | ||||
23 | | ||||
24 | class SnoreToastActions | ||||
25 | { | ||||
26 | public: | ||||
27 | enum class Actions { | ||||
28 | Clicked, | ||||
29 | Hidden, | ||||
30 | Dismissed, | ||||
31 | Timedout, | ||||
32 | ButtonClicked, | ||||
33 | TextEntered, | ||||
34 | | ||||
35 | Error = -1 | ||||
36 | }; | ||||
37 | | ||||
38 | static const inline std::wstring& getActionString(const Actions &a) | ||||
39 | { | ||||
40 | return actionMap().at(a); | ||||
41 | } | ||||
42 | | ||||
43 | template<typename T> | ||||
44 | static inline SnoreToastActions::Actions getAction(const T &s) | ||||
45 | { | ||||
46 | for (const auto &a : actionMap()) { | ||||
47 | if (a.second.compare(s) == 0) { | ||||
48 | return a.first; | ||||
49 | } | ||||
50 | } | ||||
51 | return SnoreToastActions::Actions::Error; | ||||
52 | } | ||||
53 | | ||||
54 | | ||||
55 | | ||||
56 | private: | ||||
57 | static const std::map<Actions, std::wstring> &actionMap(){ | ||||
58 | static const std::map<Actions, std::wstring> _ActionStrings = { | ||||
59 | {Actions::Clicked, L"clicked"}, | ||||
60 | {Actions::Hidden, L"hidden"}, | ||||
61 | {Actions::Dismissed, L"dismissed"}, | ||||
62 | {Actions::Timedout, L"timedout"}, | ||||
63 | {Actions::ButtonClicked, L"buttonClicked"}, | ||||
64 | {Actions::TextEntered, L"textEntered"} | ||||
65 | }; | ||||
66 | return _ActionStrings; | ||||
67 | } | ||||
68 | }; |