1 /*
2  * Copyright (C) 2019-2021 Alexandros Theodotou <alex at zrythm dot org>
3  *
4  * This file is part of Zrythm
5  *
6  * Zrythm is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Zrythm is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with Zrythm.  If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #include "zrythm-config.h"
21 
22 #include "gui/accel.h"
23 #include "gui/widgets/header.h"
24 #include "gui/widgets/help_toolbar.h"
25 #include "gui/widgets/home_toolbar.h"
26 #include "gui/widgets/live_waveform.h"
27 #include "gui/widgets/midi_activity_bar.h"
28 #include "gui/widgets/project_toolbar.h"
29 #include "gui/widgets/snap_box.h"
30 #include "gui/widgets/snap_grid.h"
31 #include "gui/widgets/toolbox.h"
32 #include "gui/widgets/view_toolbar.h"
33 #include "utils/gtk.h"
34 #include "utils/resources.h"
35 
36 #include <glib/gi18n.h>
37 
G_DEFINE_TYPE(HeaderWidget,header_widget,GTK_TYPE_BOX)38 G_DEFINE_TYPE (HeaderWidget,
39                header_widget,
40                GTK_TYPE_BOX)
41 
42 void
43 header_widget_refresh (
44   HeaderWidget * self)
45 {
46   g_debug (
47     "refreshing header widget: "
48     "has pending warnings: %d",
49     self->log_has_pending_warnings);
50   GtkButton * btn =
51     GTK_BUTTON (
52       gtk_bin_get_child (
53         GTK_BIN (self->log_viewer)));
54   z_gtk_button_set_emblem (
55     btn,
56     self->log_has_pending_warnings ?
57       "media-record" : NULL);
58 }
59 
60 void
header_widget_setup(HeaderWidget * self,const char * title)61 header_widget_setup (
62   HeaderWidget * self,
63   const char * title)
64 {
65   header_widget_set_subtitle (
66     self, title);
67 
68   home_toolbar_widget_setup (self->home_toolbar);
69 }
70 
71 void
header_widget_set_subtitle(HeaderWidget * self,const char * title)72 header_widget_set_subtitle (
73   HeaderWidget * self,
74   const char * title)
75 {
76   char title_w_spaces[600];
77   strcpy (title_w_spaces, title);
78   strcat (
79     title_w_spaces,
80     "   ");
81   gtk_label_set_text (
82     self->prj_name_label, title_w_spaces);
83 }
84 
85 static void
header_widget_init(HeaderWidget * self)86 header_widget_init (
87   HeaderWidget * self)
88 {
89   g_type_ensure (HOME_TOOLBAR_WIDGET_TYPE);
90   g_type_ensure (TOOLBOX_WIDGET_TYPE);
91   g_type_ensure (SNAP_BOX_WIDGET_TYPE);
92   g_type_ensure (SNAP_GRID_WIDGET_TYPE);
93   g_type_ensure (HELP_TOOLBAR_WIDGET_TYPE);
94   g_type_ensure (VIEW_TOOLBAR_WIDGET_TYPE);
95   g_type_ensure (PROJECT_TOOLBAR_WIDGET_TYPE);
96   g_type_ensure (LIVE_WAVEFORM_WIDGET_TYPE);
97   g_type_ensure (MIDI_ACTIVITY_BAR_WIDGET_TYPE);
98 
99   gtk_widget_init_template (GTK_WIDGET (self));
100 
101   GtkStyleContext *context;
102   context =
103     gtk_widget_get_style_context (
104       GTK_WIDGET (self));
105   gtk_style_context_add_class (
106     context, "header");
107 
108   live_waveform_widget_setup_engine (
109     self->live_waveform);
110   midi_activity_bar_widget_setup_engine (
111     self->midi_activity);
112   midi_activity_bar_widget_set_animation (
113     self->midi_activity,
114     MAB_ANIMATION_FLASH);
115 
116   /* set tooltips */
117   char about_tooltip[500];
118   sprintf (
119     about_tooltip, _("About %s"), PROGRAM_NAME);
120 #define SET_TOOLTIP(x, tooltip) \
121   z_gtk_set_tooltip_for_actionable ( \
122     GTK_ACTIONABLE (self->x), \
123     tooltip)
124   SET_TOOLTIP (z_icon, _("About Zrythm"));
125   SET_TOOLTIP (preferences, _("Preferences"));
126   SET_TOOLTIP (log_viewer, _("Log viewer"));
127   SET_TOOLTIP (
128     scripting_interface, _("Scripting interface"));
129 #undef SET_TOOLTIP
130 }
131 
132 static void
header_widget_class_init(HeaderWidgetClass * _klass)133 header_widget_class_init (
134   HeaderWidgetClass * _klass)
135 {
136   GtkWidgetClass * klass =
137     GTK_WIDGET_CLASS (_klass);
138 
139   resources_set_class_template (
140     klass, "header.ui");
141 
142 #define BIND_CHILD(x) \
143   gtk_widget_class_bind_template_child ( \
144     klass, \
145     HeaderWidget, \
146     x)
147 
148   BIND_CHILD (home_toolbar);
149   BIND_CHILD (project_toolbar);
150   BIND_CHILD (view_toolbar);
151   BIND_CHILD (help_toolbar);
152   BIND_CHILD (preferences);
153   BIND_CHILD (prj_name_label);
154   BIND_CHILD (z_icon);
155   BIND_CHILD (preferences);
156   BIND_CHILD (log_viewer);
157   BIND_CHILD (scripting_interface);
158   BIND_CHILD (live_waveform);
159   BIND_CHILD (midi_activity);
160 
161 #undef BIND_CHILD
162 }
163