~ubuntu-branches/ubuntu/utopic/gnome-chemistry-utils/utopic

« back to all changes in this revision

Viewing changes to plugins/paint/wikipedia/plugin.cc

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-05-10 21:30:51 UTC
  • mfrom: (1.1.15) (2.1.25 sid)
  • Revision ID: package-import@ubuntu.com-20130510213051-mswxsp3vitsgqspm
Tags: 0.14.2-1ubuntu1
* Sync with Debian. Remaining change:
  - Build-depend on firefox-dev instead of xulrunner-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- C++ -*-
2
 
 
3
 
/* 
4
 
 * GChemPaint Wikipedia plugin
5
 
 * plugin.cc 
6
 
 *
7
 
 * Copyright (C) 2007 Jean Bréfort <jean.brefort@normalesup.org>
8
 
 *
9
 
 * This program is free software; you can redistribute it and/or 
10
 
 * modify it under the terms of the GNU General Public License as 
11
 
 * published by the Free Software Foundation; either version 2 of the
12
 
 * License, or (at your option) any later version.
13
 
 *
14
 
 * This program is distributed in the hope that it will be useful,
15
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 
 * GNU General Public License for more details.
18
 
 *
19
 
 * You should have received a copy of the GNU General Public License
20
 
 * along with this program; if not, write to the Free Software
21
 
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
22
 
 * USA
23
 
 */
24
 
 
25
 
#include "config.h"
26
 
#include "plugin.h"
27
 
#include <gcp/application.h>
28
 
#include <gcp/document.h>
29
 
#include <gcp/tool.h>
30
 
#include "wikipediatool.h"
31
 
#include "gcp-stock-pixbufs.h"
32
 
#include <glib/gi18n-lib.h>
33
 
 
34
 
using namespace gcu;
35
 
 
36
 
gcpWikipediaPlugin plugin;
37
 
 
38
 
gcpWikipediaPlugin::gcpWikipediaPlugin (): gcp::Plugin ()
39
 
{
40
 
}
41
 
 
42
 
gcpWikipediaPlugin::~gcpWikipediaPlugin ()
43
 
{
44
 
}
45
 
 
46
 
static gcp::IconDesc icon_descs[] = {
47
 
        {"gcp_Wikipedia", favicon},
48
 
        {NULL, NULL},
49
 
};
50
 
 
51
 
static GtkRadioActionEntry entries[] = {
52
 
        {       "Wikipedia", "gcp_Wikipedia", N_("Wikipedia export"), NULL,
53
 
                N_("Export for Wikipedia publication"),
54
 
                0       },
55
 
};
56
 
 
57
 
static const char *ui_description =
58
 
"<ui>"
59
 
"  <toolbar name='SelectToolbar'>"
60
 
"        <placeholder name='Select1'/>"
61
 
"        <placeholder name='Select2'/>"
62
 
"        <placeholder name='Select3'>"
63
 
"          <separator/>"
64
 
"          <toolitem action='Wikipedia'/>"
65
 
"        </placeholder>"
66
 
"  </toolbar>"
67
 
"</ui>";
68
 
 
69
 
struct CallbackData {
70
 
        Object *Mol;
71
 
        double x, y;
72
 
};
73
 
 
74
 
static void do_image_export (struct CallbackData *data)
75
 
{
76
 
        gcp::Document *Doc = dynamic_cast <gcp::Document*> (data->Mol->GetDocument ());
77
 
        if (!Doc)
78
 
                return;
79
 
        gcp::Application *App = dynamic_cast <gcp::Application*> (Doc->GetApp ());
80
 
        gcp::Tool *Tool = App->GetTool ("Wikipedia");
81
 
        Tool->OnClicked (Doc->GetView (), data->Mol, data->x, data->y, 0);
82
 
}
83
 
 
84
 
static void do_free_data (struct CallbackData *data)
85
 
{
86
 
        delete data;
87
 
}
88
 
 
89
 
static bool on_molecule_menu (Object *target, GtkUIManager *UIManager, G_GNUC_UNUSED Object *object, double x, double y)
90
 
{
91
 
        gcp::Document *Doc = dynamic_cast <gcp::Document*> (target->GetDocument ());
92
 
        if (!Doc)
93
 
                return false;
94
 
        GtkActionGroup *group = gtk_action_group_new ("wikipedia");
95
 
        struct CallbackData *data = new struct CallbackData ();
96
 
        data->Mol = target;
97
 
        data->x = x;
98
 
        data->y = y;
99
 
        GtkAction *action = gtk_action_new ("wikipedia", _("Generate Wikipedia conformant PNG image"), NULL, NULL);
100
 
        g_object_set_data_full (G_OBJECT (action), "data", data, (GDestroyNotify) do_free_data);
101
 
        g_signal_connect_swapped (action, "activate", G_CALLBACK (do_image_export), data);
102
 
        gtk_action_group_add_action (group, action);
103
 
        g_object_unref (action);
104
 
        gtk_ui_manager_add_ui_from_string (UIManager, "<ui><popup><menu action='Molecule'><menuitem action='wikipedia'/></menu></popup></ui>", -1, NULL);
105
 
        gtk_ui_manager_insert_action_group (UIManager, group, 0);
106
 
        g_object_unref (group);
107
 
        return true;
108
 
}
109
 
 
110
 
void gcpWikipediaPlugin::Populate (gcp::Application *App)
111
 
{
112
 
        App->AddActions (entries, G_N_ELEMENTS (entries), ui_description, icon_descs);
113
 
        Object::AddMenuCallback (MoleculeType, on_molecule_menu);
114
 
        new gcpWikipediaTool (App);
115
 
}