Utilities
Utilities header only library
Dialogs.h
1 /*
2  Copyright (C) Skeletex Research, s.r.o. - All Rights Reserved
3  Unauthorized copying of this file, via any medium is strictly prohibited
4  Proprietary and confidential
5 */
6 #ifndef UTILS_DIALOGS_H
7 #define UTILS_DIALOGS_H
8 #include <string>
9 
10 #ifdef _WIN32
11 #include <Windows.h>
12 #elif __linux__
13 #include <iostream>
14 #endif // _WIN32
15 
16 #include <Utils/ExtSTD.h>
17 
18 
20 namespace dialog
21 {
22 
24  inline void Error(const std::string &msg, const std::string &title = "Error")
25  {
26  const std::wstring msgW = std_ext::ToWString(msg);
27  const std::wstring titleW = std_ext::ToWString(title);
28 #ifdef _WIN32
29  MessageBox(0, msgW.c_str(), titleW.c_str(), MB_OK | MB_ICONERROR | MB_TASKMODAL);
30 #elif __linux__
31  std::cout << "Title:" << title << std::endl;
32  std::cout << "Message:" << msg << std::endl;
33 #else
34 #error "platform not supported"
35 #endif
36  }
37 
39  inline void Warning(const std::string &msg, const std::string &title = "Warning")
40  {
41  const std::wstring msgW = std_ext::ToWString(msg);
42  const std::wstring titleW = std_ext::ToWString(title);
43 #ifdef _WIN32
44  MessageBox(0, msgW.c_str(), titleW.c_str(), MB_OK | MB_ICONWARNING | MB_TASKMODAL);
45 #elif __linux__
46  std::cout << "Title:" << title << std::endl;
47  std::cout << "Message:" << msg << std::endl;
48 #else
49 #error "platform not supported"
50 #endif
51  }
52 
54  inline void Info(const std::string &msg, const std::string &title = "Information")
55  {
56  const std::wstring msgW = std_ext::ToWString(msg);
57  const std::wstring titleW = std_ext::ToWString(title);
58 #ifdef _WIN32
59  MessageBox(0, msgW.c_str(), titleW.c_str(), MB_OK | MB_ICONINFORMATION | MB_TASKMODAL);
60 #elif __linux__
61  std::cout << "Title:" << title << std::endl;
62  std::cout << "Message:" << msg << std::endl;
63 #else
64 #error "platform not supported"
65 #endif
66  }
67 
69  inline bool Confirmation(const std::string &question, const std::string &title = "Confirmation")
70  {
71  const std::wstring questionW = std_ext::ToWString(question);
72  const std::wstring titleW = std_ext::ToWString(title);
73 #ifdef _WIN32
74  const int result = MessageBox(0, questionW.c_str(), titleW.c_str(), MB_YESNO | MB_TASKMODAL);
75  return result == IDYES;
76 #elif __linux__
77  std::cout << "implement me" << std::endl;
78  return false;
79 #else
80 #error "platform not supported"
81 #endif
82  }
83 
84 }
85 
86 #endif /* !UTILS_DIALOGS_H */
bool Confirmation(const std::string &question, const std::string &title="Confirmation")
Show dialog with YES and NO buttons and returns answer. Program waits until user selects answer...
Definition: Dialogs.h:69
Dialog message boxes wrapper functions.
Definition: Dialogs.h:20
void Error(const std::string &msg, const std::string &title="Error")
Shows error dialog and displays message. Program waits until user confirms.
Definition: Dialogs.h:24
std::wstring ToWString(const std::string &text)
Convert single-byte std::string to std::wstring.
Definition: ExtSTD.h:68
void Info(const std::string &msg, const std::string &title="Information")
Show information dialog with specified message. Program waits until user confirms.
Definition: Dialogs.h:54
void Warning(const std::string &msg, const std::string &title="Warning")
Show warning dialog and displays message. Program waits until user confirms.
Definition: Dialogs.h:39