enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / gtk2_ardour / theme_manager.cc
1 /*
2     Copyright (C) 2000-2007 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 <cmath>
21 #include <errno.h>
22
23 #include "fix_carbon.h"
24
25 #include "pbd/gstdio_compat.h"
26
27 #include <gtkmm/settings.h>
28
29 #include "gtkmm2ext/gtk_ui.h"
30 #include "gtkmm2ext/utils.h"
31
32 #include "pbd/compose.h"
33
34 #include "ardour/profile.h"
35
36 #include "canvas/wave_view.h"
37
38 #include "ardour_button.h"
39 #include "ardour_dialog.h"
40 #include "theme_manager.h"
41 #include "ui_config.h"
42 #include "utils.h"
43
44 #include "pbd/i18n.h"
45
46 using namespace std;
47 using namespace Gtk;
48 using namespace PBD;
49 using namespace ARDOUR;
50 using namespace ARDOUR_UI_UTILS;
51
52 ThemeManager::ThemeManager()
53         : flat_buttons (_("Draw \"flat\" buttons"))
54         , blink_rec_button (_("Blink Rec-Arm buttons"))
55         , region_color_button (_("Color regions using their track's color"))
56         , show_clipping_button (_("Show waveform clipping"))
57         , waveform_gradient_depth (0, 1.0, 0.05)
58         , waveform_gradient_depth_label (_("Waveforms color gradient depth"))
59         , timeline_item_gradient_depth (0, 1.0, 0.05)
60         , timeline_item_gradient_depth_label (_("Timeline item gradient depth"))
61         , all_dialogs (_("All floating windows are dialogs"))
62         , transients_follow_front (_("Transient windows follow front window."))
63         , floating_monitor_section (_("Float detached monitor-section window"))
64         , icon_set_label (_("Icon Set"))
65 {
66         Gtk::HBox* hbox;
67
68         /* various buttons */
69
70         set_homogeneous (false);
71
72
73 #ifndef __APPLE__
74         pack_start (all_dialogs, PACK_SHRINK);
75         pack_start (transients_follow_front, PACK_SHRINK);
76 #endif
77         if (!Profile->get_mixbus()) {
78                 pack_start (floating_monitor_section, PACK_SHRINK);
79         }
80         pack_start (flat_buttons, PACK_SHRINK);
81         pack_start (blink_rec_button, PACK_SHRINK);
82         pack_start (region_color_button, PACK_SHRINK);
83         pack_start (show_clipping_button, PACK_SHRINK);
84
85         vector<string> icon_sets = ::get_icon_sets ();
86
87         if (icon_sets.size() > 1) {
88                 Gtkmm2ext::set_popdown_strings (icon_set_dropdown, icon_sets);
89                 icon_set_dropdown.set_active_text (UIConfiguration::instance().get_icon_set());
90
91                 hbox = Gtk::manage (new Gtk::HBox());
92                 hbox->set_spacing (6);
93                 Gtk::Alignment* align = Gtk::manage (new Gtk::Alignment);
94                 align->set (0, 0.5);
95                 align->add (icon_set_dropdown);
96                 hbox->pack_start (icon_set_label, false, false);
97                 hbox->pack_start (*align, true, true);
98                 pack_start (*hbox, PACK_SHRINK);
99         }
100
101         hbox = Gtk::manage (new Gtk::HBox());
102         hbox->set_spacing (6);
103         hbox->pack_start (waveform_gradient_depth, true, true);
104         hbox->pack_start (waveform_gradient_depth_label, false, false);
105         pack_start (*hbox, PACK_SHRINK);
106
107         hbox = Gtk::manage (new Gtk::HBox());
108         hbox->set_spacing (6);
109         hbox->pack_start (timeline_item_gradient_depth, true, true);
110         hbox->pack_start (timeline_item_gradient_depth_label, false, false);
111         pack_start (*hbox, PACK_SHRINK);
112
113         show_all ();
114
115         waveform_gradient_depth.set_update_policy (Gtk::UPDATE_DELAYED);
116         timeline_item_gradient_depth.set_update_policy (Gtk::UPDATE_DELAYED);
117
118         set_ui_to_state();
119
120         flat_buttons.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_flat_buttons_toggled));
121         blink_rec_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_blink_rec_arm_toggled));
122         region_color_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_region_color_toggled));
123         show_clipping_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_show_clip_toggled));
124         waveform_gradient_depth.signal_value_changed().connect (sigc::mem_fun (*this, &ThemeManager::on_waveform_gradient_depth_change));
125         timeline_item_gradient_depth.signal_value_changed().connect (sigc::mem_fun (*this, &ThemeManager::on_timeline_item_gradient_depth_change));
126         all_dialogs.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_all_dialogs_toggled));
127         transients_follow_front.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_transients_follow_front_toggled));
128         floating_monitor_section.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_floating_monitor_section_toggled));
129         icon_set_dropdown.signal_changed().connect (sigc::mem_fun (*this, &ThemeManager::on_icon_set_changed));
130
131         Gtkmm2ext::UI::instance()->set_tip (all_dialogs,
132                                             string_compose (_("Mark all floating windows to be type \"Dialog\" rather than using \"Utility\" for some.\n"
133                                                               "This may help with some window managers. This requires a restart of %1 to take effect"),
134                                                             PROGRAM_NAME));
135         Gtkmm2ext::UI::instance()->set_tip (transients_follow_front,
136                                             string_compose (_("Make transient windows follow the front window when toggling between the editor and mixer.\n"
137                                                               "This requires a restart of %1 to take effect"), PROGRAM_NAME));
138         Gtkmm2ext::UI::instance()->set_tip (floating_monitor_section,
139                                             string_compose (_("When detaching the monitoring section, mark it as \"Utility\" window to stay in front.\n"
140                                                               "This requires a restart of %1 to take effect"), PROGRAM_NAME));
141
142 }
143
144 void
145 ThemeManager::on_flat_buttons_toggled ()
146 {
147         UIConfiguration::instance().set_flat_buttons (flat_buttons.get_active());
148         ArdourButton::set_flat_buttons (flat_buttons.get_active());
149         /* force a redraw */
150         gtk_rc_reset_styles (gtk_settings_get_default());
151 }
152
153 void
154 ThemeManager::on_blink_rec_arm_toggled ()
155 {
156         UIConfiguration::instance().set_blink_rec_arm (blink_rec_button.get_active());
157         UIConfiguration::instance().ParameterChanged("blink-rec-arm");
158 }
159
160 void
161 ThemeManager::on_region_color_toggled ()
162 {
163         UIConfiguration::instance().set_color_regions_using_track_color (region_color_button.get_active());
164 }
165
166 void
167 ThemeManager::on_show_clip_toggled ()
168 {
169         UIConfiguration::instance().set_show_waveform_clipping (show_clipping_button.get_active());
170         // "show-waveform-clipping" was a session config key
171         ArdourCanvas::WaveView::set_global_show_waveform_clipping (UIConfiguration::instance().get_show_waveform_clipping());
172 }
173
174 void
175 ThemeManager::on_all_dialogs_toggled ()
176 {
177         UIConfiguration::instance().set_all_floating_windows_are_dialogs (all_dialogs.get_active());
178 }
179
180 void
181 ThemeManager::on_transients_follow_front_toggled ()
182 {
183         UIConfiguration::instance().set_transients_follow_front (transients_follow_front.get_active());
184 }
185
186 void
187 ThemeManager::on_floating_monitor_section_toggled ()
188 {
189         UIConfiguration::instance().set_floating_monitor_section (floating_monitor_section.get_active());
190 }
191
192 void
193 ThemeManager::on_waveform_gradient_depth_change ()
194 {
195         double v = waveform_gradient_depth.get_value();
196
197         UIConfiguration::instance().set_waveform_gradient_depth (v);
198         ArdourCanvas::WaveView::set_global_gradient_depth (v);
199 }
200
201 void
202 ThemeManager::on_timeline_item_gradient_depth_change ()
203 {
204         double v = timeline_item_gradient_depth.get_value();
205
206         UIConfiguration::instance().set_timeline_item_gradient_depth (v);
207 }
208
209 void
210 ThemeManager::on_icon_set_changed ()
211 {
212         string new_set = icon_set_dropdown.get_active_text();
213         UIConfiguration::instance().set_icon_set (new_set);
214 }
215
216 void
217 ThemeManager::set_ui_to_state()
218 {
219         /* there is no need to block signal handlers, here,
220          * all elements check if the value has changed and ignore NOOPs
221          */
222         all_dialogs.set_active (UIConfiguration::instance().get_all_floating_windows_are_dialogs());
223         transients_follow_front.set_active (UIConfiguration::instance().get_transients_follow_front());
224         floating_monitor_section.set_active (UIConfiguration::instance().get_floating_monitor_section());
225         flat_buttons.set_active (UIConfiguration::instance().get_flat_buttons());
226         blink_rec_button.set_active (UIConfiguration::instance().get_blink_rec_arm());
227         region_color_button.set_active (UIConfiguration::instance().get_color_regions_using_track_color());
228         show_clipping_button.set_active (UIConfiguration::instance().get_show_waveform_clipping());
229         waveform_gradient_depth.set_value(UIConfiguration::instance().get_waveform_gradient_depth());
230         timeline_item_gradient_depth.set_value(UIConfiguration::instance().get_timeline_item_gradient_depth());
231 }
232