enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / libs / gtkmm2ext / cursors.cc
1 /*
2     Copyright (C) 2014 Paul Davis
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, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <sstream>
21
22 #include "pbd/gstdio_compat.h"
23 #include "pbd/error.h"
24 #include "pbd/compose.h"
25
26 #include "gtkmm2ext/cursors.h"
27
28 #include "pbd/i18n.h"
29
30 using namespace Gtkmm2ext;
31
32 CursorInfo::Infos CursorInfo::infos;
33
34 CursorInfo::CursorInfo (const std::string& n, int hotspot_x, int hotspot_y)
35         : name (n)
36         , x (hotspot_x)
37         , y (hotspot_y)
38 {
39 }
40
41 int
42 CursorInfo::load_cursor_info (const std::string& path)
43 {
44         gchar *buf = NULL;
45         if (!g_file_get_contents (path.c_str(), &buf, NULL, NULL))  {
46                 return -1;
47         }
48         std::stringstream infofile (buf);
49         g_free (buf);
50
51         std::string name;
52         int x;
53         int y;
54         bool parse_ok;
55         int line_number = 1;
56
57         do {
58                 parse_ok = false;
59                 infofile >> name;
60                 if (!infofile) {
61                         /* failing here is OK ... EOF */
62                         parse_ok = true;
63                         break;
64                 }
65                 infofile >> x;
66                 if (!infofile) {
67                         break;
68                 }
69                 infofile >> y;
70                 if (!infofile) {
71                         break;
72                 }
73
74                 parse_ok = true;
75                 line_number++;
76
77                 infos[name] = new CursorInfo (name, x, y);
78
79         } while (true);
80
81         if (!parse_ok) {
82                 PBD::error << string_compose (_("cursor hotspots info file %1 has an error on line %2"), path, line_number) << endmsg;
83                 infos.clear ();
84                 return -1;
85         }
86
87         return 0;
88 }
89
90 void
91 CursorInfo::drop_cursor_info ()
92 {
93         infos.clear ();
94 }
95
96 CursorInfo*
97 CursorInfo::lookup_cursor_info (const std::string& name)
98 {
99         Infos::iterator i = infos.find (name);
100
101         if (i == infos.end()) {
102                 return 0;
103         }
104         return i->second;
105 }