summaryrefslogtreecommitdiffstats
path: root/src/extension/error-file.cpp
blob: ad65457b2df135cc80dac8215d2a503acd6bb49d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Authors:
 *   Ted Gould <ted@gould.cx>
 *
 * Copyright (C) 2005 Authors
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#include "ui/dialog/extensions.h"

#include <glibmm/i18n.h>
#include "inkscape.h"
#include "preferences.h"
#include "extension/extension.h"
#include "io/resource.h"

#include "error-file.h"

/** The name and group of the preference to say whether the error
    dialog should be shown on startup. */
#define PREFERENCE_ID  "/dialogs/extension-error/show-on-startup"

namespace Inkscape {
namespace Extension {

/** \brief  An initializer which builds the dialog

    Really a simple function.  Basically the message dialog itself gets
    built with the first initializer.  The next step is to add in the
    message, and attach the filename for the error file.  After that
    the checkbox is built, and has the call back attached to it.  Also,
    it is set based on the preferences setting for show on startup (really,
    it should always be checked if you can see the dialog, but it is
    probably good to check anyway).
*/
ErrorFileNotice::ErrorFileNotice () :
    Gtk::MessageDialog(
            "",                    /* message */
            false,                 /* use markup */
            Gtk::MESSAGE_WARNING,  /* dialog type */
            Gtk::BUTTONS_OK,       /* buttons */
            true                   /* modal */
        )

{
    // \FIXME change this
    /* This is some filler text, needs to change before release */
    Glib::ustring dialog_text(_("<span weight=\"bold\" size=\"larger\">One or more extensions failed to load</span>\n\nThe failed extensions have been skipped.  Inkscape will continue to run normally but those extensions will be unavailable.  For details to troubleshoot this problem, please refer to the error log located at: "));
    gchar * ext_error_file = Inkscape::IO::Resource::log_path(EXTENSION_ERROR_LOG_FILENAME);
    dialog_text += ext_error_file;
    g_free(ext_error_file);
    set_message(dialog_text, true);

    auto vbox = get_content_area();

    /* This is some filler text, needs to change before release */
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    checkbutton = Gtk::manage(new Gtk::CheckButton(_("Show dialog on startup")));
    vbox->pack_start(*checkbutton, true, false, 5);
    checkbutton->show();
    checkbutton->set_active(prefs->getBool(PREFERENCE_ID, true));

    checkbutton->signal_toggled().connect(sigc::mem_fun(this, &ErrorFileNotice::checkbox_toggle));

    set_resizable(true);

    Inkscape::UI::Dialogs::ExtensionsPanel* extens = new Inkscape::UI::Dialogs::ExtensionsPanel();
    extens->set_full(false);
    vbox->pack_start( *extens, true, true );
    extens->show();

    return;
}

/** \brief Sets the preferences based on the checkbox value */
void
ErrorFileNotice::checkbox_toggle ()
{
    // std::cout << "Toggle value" << std::endl;
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    prefs->setBool(PREFERENCE_ID, checkbutton->get_active());
}

/** \brief Shows the dialog

    This function only shows the dialog if the preferences say that the
    user wants to see the dialog, otherwise it just exits.
*/
int
ErrorFileNotice::run ()
{
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    if (!prefs->getBool(PREFERENCE_ID, true))
        return 0;
    return Gtk::Dialog::run();
}

}; };  /* namespace Inkscape, Extension */

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :