Debian Codegraph @

android/app/jni/extern/pfd-fixed/examples/example.cpp

raw
1 //
2 // Portable File Dialogs
3 //
4 // Copyright © 2018—2020 Sam Hocevar <[email protected]>
5 //
6 // This program is free software. It comes without any warranty, to
7 // the extent permitted by applicable law. You can redistribute it
8 // and/or modify it under the terms of the Do What the Fuck You Want
9 // to Public License, Version 2, as published by the WTFPL Task Force.
10 // See http://www.wtfpl.net/ for more details.
11 //
12
13 #include "portable-file-dialogs.h"
14
15 #include <iostream>
16
17 #if _WIN32
18 #define DEFAULT_PATH "C:\\"
19 #else
20 #define DEFAULT_PATH "/tmp"
21 #endif
22
23 int main()
24 {
25 // Check that a backend is available
26 if (!pfd::settings::available())
27 {
28 std::cout << "Portable File Dialogs are not available on this platform.\n";
29 return 1;
30 }
31
32 // Set verbosity to true
33 pfd::settings::verbose(true);
34
35 // Notification
36 pfd::notify("Important Notification",
37 "This is ' a message, pay \" attention \\ to it!",
38 pfd::icon::info);
39
40 // Message box with nice message
41 auto m = pfd::message("Personal Message",
42 "You are an amazing person, don’t let anyone make you think otherwise.",
43 pfd::choice::yes_no_cancel,
44 pfd::icon::warning);
45
46 // Optional: do something while waiting for user action
47 for (int i = 0; i < 10 && !m.ready(1000); ++i)
48 std::cout << "Waited 1 second for user input...\n";
49
50 // Do something according to the selected button
51 switch (m.result())
52 {
53 case pfd::button::yes: std::cout << "User agreed.\n"; break;
54 case pfd::button::no: std::cout << "User disagreed.\n"; break;
55 case pfd::button::cancel: std::cout << "User freaked out.\n"; break;
56 default: break; // Should not happen
57 }
58
59 // Directory selection
60 auto dir = pfd::select_folder("Select any directory", DEFAULT_PATH).result();
61 std::cout << "Selected dir: " << dir << "\n";
62
63 // File open
64 auto f = pfd::open_file("Choose files to read", DEFAULT_PATH,
65 { "Text Files (.txt .text)", "*.txt *.text",
66 "All Files", "*" },
67 pfd::opt::multiselect);
68 std::cout << "Selected files:";
69 for (auto const &name : f.result())
70 std::cout << " " + name;
71 std::cout << "\n";
72 }
73
74 // Unused function that just tests the whole API
75 void api()
76 {
77 // pfd::settings
78 pfd::settings::verbose(true);
79 pfd::settings::rescan();
80
81 // pfd::notify
82 pfd::notify("", "");
83 pfd::notify("", "", pfd::icon::info);
84 pfd::notify("", "", pfd::icon::warning);
85 pfd::notify("", "", pfd::icon::error);
86 pfd::notify("", "", pfd::icon::question);
87
88 pfd::notify a("", "");
89 (void)a.ready();
90 (void)a.ready(42);
91
92 // pfd::message
93 pfd::message("", "");
94 pfd::message("", "", pfd::choice::ok);
95 pfd::message("", "", pfd::choice::ok_cancel);
96 pfd::message("", "", pfd::choice::yes_no);
97 pfd::message("", "", pfd::choice::yes_no_cancel);
98 pfd::message("", "", pfd::choice::retry_cancel);
99 pfd::message("", "", pfd::choice::abort_retry_ignore);
100 pfd::message("", "", pfd::choice::ok, pfd::icon::info);
101 pfd::message("", "", pfd::choice::ok, pfd::icon::warning);
102 pfd::message("", "", pfd::choice::ok, pfd::icon::error);
103 pfd::message("", "", pfd::choice::ok, pfd::icon::question);
104
105 pfd::message b("", "");
106 (void)b.ready();
107 (void)b.ready(42);
108 (void)b.result();
109 }
110