enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / libs / surfaces / osc / osc_gui.cc
1 /*
2     Copyright (C) 2016 Robin Gareus <robin@gareus.org
3     Copyright (C) 2009-2012 Paul Davis
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #include <iostream>
22 #include <list>
23 #include <string>
24
25 #include <gtkmm/box.h>
26 #include <gtkmm/table.h>
27 #include <gtkmm/label.h>
28 #include <gtkmm/comboboxtext.h>
29
30 #include "gtkmm2ext/gtk_ui.h"
31 #include "gtkmm2ext/gui_thread.h"
32 #include "gtkmm2ext/utils.h"
33
34 #include "osc.h"
35
36 #include "pbd/i18n.h"
37
38 namespace ArdourSurface {
39
40 class OSC_GUI : public Gtk::VBox
41 {
42         public:
43                 OSC_GUI (OSC&);
44                 ~OSC_GUI ();
45
46 private:
47         Gtk::ComboBoxText debug_combo;
48         void debug_changed ();
49
50         OSC& cp;
51 };
52
53
54 void*
55 OSC::get_gui () const
56 {
57         if (!gui) {
58                 const_cast<OSC*>(this)->build_gui ();
59         }
60         static_cast<Gtk::VBox*>(gui)->show_all();
61         return gui;
62 }
63
64 void
65 OSC::tear_down_gui ()
66 {
67         if (gui) {
68                 Gtk::Widget *w = static_cast<Gtk::VBox*>(gui)->get_parent();
69                 if (w) {
70                         w->hide();
71                         delete w;
72                 }
73         }
74         delete (OSC_GUI*) gui;
75         gui = 0;
76 }
77
78 void
79 OSC::build_gui ()
80 {
81         gui = (void*) new OSC_GUI (*this);
82 }
83
84 } // end namespace
85
86 ///////////////////////////////////////////////////////////////////////////////
87
88 using namespace PBD;
89 using namespace Gtk;
90 using namespace Gtkmm2ext;
91 using namespace ArdourSurface;
92
93 OSC_GUI::OSC_GUI (OSC& p)
94         : cp (p)
95 {
96         int n = 0; // table row
97         Table* table = manage (new Table);
98         Label* label;
99
100         label = manage (new Gtk::Label(_("Connection:")));
101         table->attach (*label, 0, 1, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
102         label = manage (new Gtk::Label(cp.get_server_url()));
103         table->attach (*label, 1, 2, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
104         ++n;
105
106         label = manage (new Gtk::Label(_("Debug:")));
107         table->attach (*label, 0, 1, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
108         table->attach (debug_combo, 1, 2, n, n+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
109
110         std::vector<std::string> debug_options;
111         debug_options.push_back (_("Off"));
112         debug_options.push_back (_("Log invalid messages"));
113         debug_options.push_back (_("Log all messages"));
114
115         set_popdown_strings (debug_combo, debug_options);
116         debug_combo.set_active ((int)cp.get_debug_mode());
117
118         table->show_all ();
119         pack_start (*table, false, false);
120
121         debug_combo.signal_changed().connect (sigc::mem_fun (*this, &OSC_GUI::debug_changed));
122 }
123
124 OSC_GUI::~OSC_GUI ()
125 {
126 }
127
128 void
129 OSC_GUI::debug_changed ()
130 {
131         std::string str = debug_combo.get_active_text ();
132         if (str == _("Off")) {
133                 cp.set_debug_mode (OSC::Off);
134         }
135         else if (str == _("Log invalid messages")) {
136                 cp.set_debug_mode (OSC::Unhandled);
137         }
138         else if (str == _("Log all messages")) {
139                 cp.set_debug_mode (OSC::All);
140         }
141         else {
142                 std::cerr << "Invalid OSC Debug Mode\n";
143                 assert (0);
144         }
145 }