OpenCPN Partial API docs
Loading...
Searching...
No Matches
safe_mode_gui.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2023 Alec Leamas *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
24#include <cstdio>
25#include <string>
26#include <fstream>
27#include <sstream>
28
29#include <wx/dialog.h>
30#include <wx/filename.h>
31#include <wx/sizer.h>
32
33#include "model/cmdline.h"
34#include "model/ocpn_utils.h"
35#include "model/safe_mode.h"
36
37#include "dialog_alert.h"
38#include "gui_lib.h"
39
40namespace safe_mode {
41
42static const char* kLastRunErrorMsg =
43 // clang-format off
44 _(R"( <p>The last opencpn run seems to have failed. Do <br/>
45 you want to run in safe mode without plugins and <br/>
46 other possibly problematic features? </p>
47 <br/><br/>
48 <p> You may consider visiting the OpenCPN-5.16 <br/>
49 <a href="http://repo.opencpn.org/known-issues-5.16.html">
50 list of known issues</a>.</p>)"); // clang-format on
51
56void CheckLastStart() {
57 std::string path = CheckFilePath();
58 if (!ocpn::exists(path)) {
59 std::ofstream dest(path, std::ios::binary);
60 dest << "Internal opencpn use\n";
61 return;
62 }
63 std::string title = _("Safe Restart").ToStdString();
64 std::string action = _("Safe mode start").ToStdString();
65 AlertDialog dlg(0, title, action);
66 dlg.SetCancelLabel(_("Normal start").ToStdString());
67 dlg.SetDefaultButton(wxID_CANCEL);
68 dlg.SetInitialSize();
69 dlg.SetTimer(15);
70
71 std::stringstream html;
72 html << "<html><body>" << kLastRunErrorMsg << "</body></html>";
73 dlg.AddHtmlContent(html);
74
75 int reply = dlg.ShowModal();
76 safe_mode = reply == wxID_OK;
77}
78
79} // namespace safe_mode
A modal message dialog with confirmation button and cancel button.
Global variables reflecting command line options and arguments.
General purpose GUI support.
bool exists(const std::string &name)
Safe mode GUI handling.
Definition safe_mode.cpp:37
std::string CheckFilePath()
Return path to file created when start is commenced and removed when completed.
Definition safe_mode.cpp:47
void CheckLastStart()
Check if the last start failed, possibly invoke user dialog and set safe mode state.
Miscellaneous utilities, many of which string related.
Safe mode non-gui handling.