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* LAST_RUN_ERROR_MSG =
43 _("<p>The last opencpn run seems to have failed. Do you want to run\n"
44 "in safe mode without plugins and other possibly problematic\n"
45 "features?\n</p><br/></br><p>You may consider visiting the <a "
46 "href=\"https://github.com/OpenCPN/OpenCPN/wiki/"
47 "OpenCPN-5.10-known-issues\">list of known issues</a>.</p>");
48
54 std::string path = check_file_path();
55 if (!ocpn::exists(path)) {
56 std::ofstream dest(path, std::ios::binary);
57 dest << "Internal opencpn use" << std::endl;
58 dest.close();
59 return;
60 }
61
62 std::string title = _("Safe Restart").ToStdString();
63 std::string action = _("Safe mode start").ToStdString();
64 AlertDialog dlg(0, title, action);
65 dlg.SetCancelLabel(_("Normal start").ToStdString());
66 dlg.SetDefaultButton(wxID_CANCEL);
67 dlg.SetInitialSize();
68 dlg.SetTimer(15);
69
70 std::stringstream html;
71 html << "<html><body>";
72 html << LAST_RUN_ERROR_MSG;
73 html << "</body></html>";
74 dlg.AddHtmlContent(html);
75
76 int reply = dlg.ShowModal();
77 safe_mode = reply == wxID_OK;
78}
79
80} // namespace safe_mode
A modal message dialog with confirmation button and cancel button.
int ShowModal() override
Show dialog and return response.
void SetDefaultButton(int id)
Set default button (for enter).
void SetTimer(int seconds)
Activate timer.
void SetCancelLabel(const std::string &label)
Overwrite cancel button label.
void AddHtmlContent(const std::stringstream &html)
Display HTML content with dark support.
void SetInitialSize()
Initialize by display geometry.
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
void check_last_start()
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.