summaryrefslogtreecommitdiffstats
path: root/src/ui/dialog/extensions.cpp
blob: f39c7d54983ec8fcc0ad9cda82c25cd0f981698e (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
112
113
114
115
116
117
118
119
120
// SPDX-License-Identifier: GPL-2.0-or-later
/**
 * @file
 * A simple dialog with information about extensions.
 */
/* Authors:
 *   Jon A. Cruz
 *
 * Copyright (C) 2005 Jon A. Cruz
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#include "extensions.h"
#include "extension/extension.h"
#include <gtkmm/scrolledwindow.h>

#include "extension/db.h"


namespace Inkscape {
namespace UI {
namespace Dialogs {

using Inkscape::Extension::Extension;

ExtensionsPanel &ExtensionsPanel::getInstance()
{
    ExtensionsPanel &instance = *new ExtensionsPanel();

    instance.rescan();

    return instance;
}


ExtensionsPanel::ExtensionsPanel() :
        _showAll(false)
{
    Gtk::ScrolledWindow* scroller = new Gtk::ScrolledWindow();

    _view.set_editable(false);

    scroller->add(_view);
    add(*scroller);

    rescan();

    show_all_children();
}

void ExtensionsPanel::set_full(bool full)
{
    if ( full != _showAll ) {
        _showAll = full;
        rescan();
    }
}

void ExtensionsPanel::listCB( Inkscape::Extension::Extension * in_plug, gpointer in_data )
{
    ExtensionsPanel * self = static_cast<ExtensionsPanel*>(in_data);

    const char* stateStr;
    Extension::state_t state = in_plug->get_state();
    switch ( state ) {
        case Extension::STATE_LOADED:
        {
            stateStr = "loaded";
        }
        break;
        case Extension::STATE_UNLOADED:
        {
            stateStr = "unloaded";
        }
        break;
        case Extension::STATE_DEACTIVATED:
        {
            stateStr = "deactivated";
        }
        break;
        default:
            stateStr = "unknown";
    }

    if ( self->_showAll || in_plug->deactivated() ) {
        gchar* line = g_strdup_printf( "%s   %s\n        \"%s\"", stateStr, in_plug->get_name(), in_plug->get_id() );

        self->_view.get_buffer()->insert( self->_view.get_buffer()->end(), line );
        self->_view.get_buffer()->insert( self->_view.get_buffer()->end(), "\n" );
        g_free(line);
    }

    return;
}

void ExtensionsPanel::rescan()
{
    _view.get_buffer()->set_text("Extensions:\n");
//     g_message("/------------------");

    Inkscape::Extension::db.foreach(listCB, (gpointer)this);

//     g_message("\\------------------");
}

} //namespace Dialogs
} //namespace UI
} //namespace Inkscape

/*
  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:fileencoding=utf-8:textwidth=99 :