22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1 |
/*
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
2 |
* Copyright (c) Linux community.
|
3 |
*
|
|
4 |
* This library is free software; you can redistribute it and/or
|
|
5 |
* modify it under the terms of the GNU Library General Public
|
|
6 |
* License as published by the Free Software Foundation; either
|
|
7 |
* version 2 of the License, or (at your option) any later version.
|
|
8 |
*
|
|
9 |
* This library 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 GNU
|
|
12 |
* Library General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU Library General Public
|
|
15 |
* License along with this library; if not, write to the
|
|
16 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
17 |
* Boston, MA 02111-1307, USA.
|
|
18 |
*/
|
|
19 |
#include <gdk/gdk.h> |
|
20 |
#include <string.h> |
|
81
by Osmo Antero Maatta
New GtkLevelBar widget for the level indicator. |
21 |
#include <math.h> // round() |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
22 |
|
23 |
#include "support.h" |
|
24 |
#include "audio-sources.h" |
|
25 |
#include "rec-window.h" |
|
101
by Osmo Antero
New media-player interface that's based on the MediaPlayer2 standard. See src/dbus-mpris2.c. |
26 |
#include "dbus-server.h" |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
27 |
#include "audio-sources.h" |
28 |
#include "media-profiles.h" |
|
29 |
#include "timer.h" |
|
30 |
#include "rec-manager.h" |
|
31 |
#include "utility.h" |
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
32 |
#include "dconf.h" |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
33 |
#include "log.h" |
3
by Osmo Antero Maatta
Updated some filenames and traslations |
34 |
#include "win-settings.h" |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
35 |
#include "auto-start.h" |
36 |
#include "about.h" |
|
37 |
#include "help.h" |
|
81
by Osmo Antero Maatta
New GtkLevelBar widget for the level indicator. |
38 |
#include "gtklevelbar.h" // Level bar widget |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
39 |
|
40 |
// Main window and all its widgets.
|
|
35
by Osmo Antero Maatta
Mainly a small typo in auto-start.c |
41 |
MainWindow g_win; |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
42 |
|
19
by Osmo Antero Maatta
Added instructions for translators |
43 |
// Command line options, arguments.
|
62
by Osmo Antero
The recorder now obeys commands from Banshee Player. |
44 |
static guint g_version_info = -1; |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
45 |
static guint g_show_window = -1; |
46 |
static guint g_show_tray_icon = -1; |
|
47 |
static guint g_debug_levels = -1; |
|
56
by Osmo Antero
Version 0.5 |
48 |
static gchar *g_command_arg = NULL; |
49 |
||
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
50 |
static GOptionEntry option_entries[] = { |
19
by Osmo Antero Maatta
Added instructions for translators |
51 |
// Translators: This is a command line option.
|
62
by Osmo Antero
The recorder now obeys commands from Banshee Player. |
52 |
{ "version", 'v', 0, G_OPTION_ARG_NONE, &g_version_info, N_("Print program name and version."), NULL}, |
53 |
||
54 |
// Translators: This is a command line option.
|
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
55 |
{ "show-window", 'w', 0, G_OPTION_ARG_INT, &g_show_window, N_("Show application window at startup (0=hide main window, 1=force display of main window)."), NULL}, |
19
by Osmo Antero Maatta
Added instructions for translators |
56 |
|
57 |
// Translators: This is a command line option.
|
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
58 |
{ "show-icon", 'i', 0, G_OPTION_ARG_INT, &g_show_tray_icon, N_("Show icon on the system tray (0=hide icon, 1=force display of icon)."), NULL}, |
19
by Osmo Antero Maatta
Added instructions for translators |
59 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
60 |
// Translators: This is a command line option.
|
19
by Osmo Antero Maatta
Added instructions for translators |
61 |
// Output audio level values in a terminal window. This makes it easier to set correct level (dB or %) value in the Timer.
|
62
by Osmo Antero
The recorder now obeys commands from Banshee Player. |
62 |
{ "debug-signal", 'd', 0, G_OPTION_ARG_NONE, &g_debug_levels, N_("List signal level values in a terminal window."), NULL}, |
56
by Osmo Antero
Version 0.5 |
63 |
|
66
by Osmo Antero
Small changes in text strings. |
64 |
// Translators: This is a command line option. Notice: Do not translate the "status,start,stop,pause,show and quit" words.
|
64
by Osmo Antero
Better explanation of various command line options. |
65 |
// Control the recorder from command line with the --command option.
|
56
by Osmo Antero
Version 0.5 |
66 |
// --command=status returns one of: "not running" | "on" | "off" | "paused".
|
66
by Osmo Antero
Small changes in text strings. |
67 |
{ "command", 'c', 0, G_OPTION_ARG_STRING, &g_command_arg, N_("Send a command to the recorder. Valid commands are; status,start,stop,pause,show,hide and quit. The status argument returns; 'not running','on','off' or 'paused'."), NULL}, |
56
by Osmo Antero
Version 0.5 |
68 |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
69 |
{ NULL }, |
70 |
};
|
|
71 |
||
72 |
static void *win_update_gui_ex(gpointer user_data); |
|
73 |
static void *win_set_filename_ex(gpointer user_data); |
|
74 |
static void *win_set_error_text_ex(gpointer user_data); |
|
56
by Osmo Antero
Version 0.5 |
75 |
static void *win_show_window_ex(gpointer user_data); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
76 |
static gboolean win_delete_cb(GtkWidget *widget, GdkEvent *event, gpointer data); |
77 |
||
56
by Osmo Antero
Version 0.5 |
78 |
static void *send_client_request(gpointer data); |
79 |
||
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
80 |
static void win_call_gui_func(GThreadFunc func, gpointer user_data) { |
81 |
// Create a thread to call GUI (GTK) related functions.
|
|
104
by Osmo Antero
Removed fixed icon images. Getting now icon pixmaps from current icon theme. |
82 |
// GUI functions are called from many places (inside/outside threads)
|
83 |
// and we have to set gdk_threads_enter() and gdk_threads_leave().
|
|
84 |
||
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
85 |
GError *error = NULL; |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
86 |
g_thread_create(func, user_data, FALSE, &error); |
104
by Osmo Antero
Removed fixed icon images. Getting now icon pixmaps from current icon theme. |
87 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
88 |
if (error) { |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
89 |
LOG_ERROR("Cannot start thread. %s.\n", error->message); |
90 |
g_error_free(error); |
|
91 |
}
|
|
92 |
}
|
|
93 |
||
94 |
void win_update_gui() { |
|
95 |
// Update GUI.
|
|
96 |
win_call_gui_func(win_update_gui_ex, NULL); |
|
97 |
}
|
|
98 |
||
99 |
static void *win_update_gui_ex(gpointer user_data) { |
|
100 |
// Important: We are calling GTK from a thread. Set lock.
|
|
101 |
gdk_threads_enter(); |
|
102 |
||
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
103 |
// Get recording state
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
104 |
gint state = -1; |
105 |
gint pending = -1; |
|
106 |
||
107 |
rec_manager_get_state(&state, &pending); |
|
108 |
||
56
by Osmo Antero
Version 0.5 |
109 |
if (state == GST_STATE_PAUSED && pending == GST_STATE_NULL) { |
110 |
state = GST_STATE_NULL; |
|
111 |
}
|
|
112 |
||
113 |
gchar *image_file = NULL; |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
114 |
gchar *label = NULL; |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
115 |
gboolean active = FALSE; |
116 |
||
117 |
switch (state) { |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
118 |
case GST_STATE_PLAYING: |
119 |
// Recording is on
|
|
120 |
image_file = (gchar*)get_image_path("audio-recorder-on-small.png"); |
|
56
by Osmo Antero
Version 0.5 |
121 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
122 |
// Translators: This is a button label, also used in the menu.
|
123 |
label = _("Stop recording"); |
|
124 |
active = TRUE; |
|
125 |
break; |
|
126 |
||
127 |
case GST_STATE_PAUSED: |
|
128 |
// Paused
|
|
129 |
image_file = (gchar*)get_image_path("audio-recorder-paused-small.png"); |
|
56
by Osmo Antero
Version 0.5 |
130 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
131 |
// Translators: This is a button label, also used in the menu.
|
132 |
label = _("Continue recording"); |
|
133 |
active = TRUE; |
|
134 |
break; |
|
135 |
||
136 |
case GST_STATE_READY: |
|
137 |
default: |
|
138 |
// Stopped/off
|
|
139 |
image_file = (gchar*)get_image_path("audio-recorder-off-small.png"); |
|
56
by Osmo Antero
Version 0.5 |
140 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
141 |
// Translators: This is a button label, also used in the menu.
|
142 |
label = _("Start recording"); |
|
143 |
active = FALSE; |
|
144 |
}
|
|
145 |
||
146 |
// Set label
|
|
147 |
if (GTK_IS_BUTTON(g_win.recorder_button)) { |
|
148 |
gtk_button_set_label(GTK_BUTTON(g_win.recorder_button), label); |
|
56
by Osmo Antero
Version 0.5 |
149 |
|
150 |
// Set image (a small color dot on the button)
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
151 |
GtkWidget *image = gtk_image_new_from_file(image_file); |
152 |
gtk_button_set_image(GTK_BUTTON(g_win.recorder_button), image); |
|
153 |
}
|
|
56
by Osmo Antero
Version 0.5 |
154 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
155 |
g_free(image_file); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
156 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
157 |
// Reset amplitude/level bar
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
158 |
if (!active) { |
81
by Osmo Antero Maatta
New GtkLevelBar widget for the level indicator. |
159 |
win_update_level_bar(0.0, 0.0); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
160 |
}
|
161 |
||
162 |
// Update systray icon and its menu selections
|
|
163 |
systray_set_menu_items1(state); |
|
164 |
||
165 |
// Important: We are calling GTK from a thread. Free the lock.
|
|
166 |
gdk_threads_leave(); |
|
167 |
||
168 |
return 0; |
|
169 |
}
|
|
170 |
||
171 |
void win_set_filename(gchar *filename) { |
|
172 |
// Set filename label
|
|
173 |
win_call_gui_func(win_set_filename_ex, g_strdup(filename)); |
|
174 |
}
|
|
175 |
||
176 |
static void *win_set_filename_ex(gpointer user_data) { |
|
177 |
// Take filename
|
|
178 |
gchar *filename = (gchar*)user_data; |
|
179 |
||
180 |
// Important: We are calling GTK from a thread. Set lock.
|
|
181 |
gdk_threads_enter(); |
|
182 |
||
183 |
// Remove path from filename
|
|
184 |
gchar *path = NULL; |
|
185 |
gchar *fname = NULL; |
|
186 |
split_filename2(filename, &path, &fname); |
|
187 |
||
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
188 |
// Show the filename
|
189 |
if (GTK_IS_WIDGET(g_win.filename)) { |
|
190 |
gtk_entry_set_text(GTK_ENTRY(g_win.filename), (fname ? fname : "")); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
191 |
}
|
192 |
||
193 |
g_free(path); |
|
194 |
g_free(fname); |
|
195 |
||
196 |
// Important: We are calling GTK from a thread. Free the lock.
|
|
197 |
gdk_threads_leave(); |
|
198 |
||
199 |
// Free the data
|
|
200 |
g_free(filename); |
|
201 |
||
202 |
return 0; |
|
203 |
}
|
|
204 |
||
93
by Osmo Antero
Set right version number in .deb package. |
205 |
const gchar *win_level_value_to_text(gdouble peak, gdouble peak_dB) { |
81
by Osmo Antero Maatta
New GtkLevelBar widget for the level indicator. |
206 |
static gchar text[16]; |
207 |
||
208 |
if (peak <= 0.01) { |
|
209 |
return NULL; |
|
210 |
}
|
|
211 |
||
212 |
// Enum LevelTextType level_ttype;
|
|
213 |
switch (g_win.level_ttype) { |
|
83
by Osmo Antero
Version 0.8 with some clean ups. |
214 |
case LEVEL_TEXT_PERCENT: |
215 |
g_snprintf(text, 10, "%d%%", (int)round(peak*100.0)); |
|
81
by Osmo Antero Maatta
New GtkLevelBar widget for the level indicator. |
216 |
break; |
217 |
||
83
by Osmo Antero
Version 0.8 with some clean ups. |
218 |
case LEVEL_TEXT_DB: |
81
by Osmo Antero Maatta
New GtkLevelBar widget for the level indicator. |
219 |
g_snprintf(text, 10, "%ddB", (int)round(peak_dB)); |
220 |
break; |
|
221 |
||
83
by Osmo Antero
Version 0.8 with some clean ups. |
222 |
default: |
81
by Osmo Antero Maatta
New GtkLevelBar widget for the level indicator. |
223 |
// Do not show any value or text
|
224 |
return NULL; |
|
225 |
}
|
|
226 |
||
227 |
return text; |
|
228 |
}
|
|
229 |
||
230 |
void win_update_level_bar(gdouble peak, gdouble peak_dB) { |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
231 |
// Set amplitude/level bar
|
81
by Osmo Antero Maatta
New GtkLevelBar widget for the level indicator. |
232 |
if (!GTK_IS_LEVEL_BAR(g_win.level_bar)) return; |
233 |
||
234 |
// Value text (eg. "10%" or "-20dB" or simply NULL)
|
|
93
by Osmo Antero
Set right version number in .deb package. |
235 |
const gchar *value_text = win_level_value_to_text(peak, peak_dB); |
81
by Osmo Antero Maatta
New GtkLevelBar widget for the level indicator. |
236 |
|
237 |
// Set level value and text
|
|
238 |
gtk_level_bar_set_fraction(GTK_LEVEL_BAR(g_win.level_bar), peak, value_text); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
239 |
}
|
240 |
||
241 |
void win_set_time_label(gchar *time_txt) { |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
242 |
// Set time label ##:##:##
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
243 |
if (GTK_IS_WIDGET(g_win.time_label)) { |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
244 |
gtk_label_set_text(GTK_LABEL(g_win.time_label), time_txt); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
245 |
}
|
246 |
}
|
|
247 |
||
248 |
void win_set_size_label(gchar *size_txt) { |
|
249 |
// Set label for filesize (recorded filesize)
|
|
250 |
if (GTK_IS_WIDGET(g_win.time_label)) { |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
251 |
gtk_label_set_text(GTK_LABEL(g_win.size_label), size_txt); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
252 |
}
|
253 |
}
|
|
254 |
||
255 |
void win_set_error_text(gchar *error_txt) { |
|
256 |
// Show red error label. Set error text.
|
|
257 |
win_call_gui_func(win_set_error_text_ex, g_strdup(error_txt)); |
|
258 |
}
|
|
259 |
||
260 |
static void *win_set_error_text_ex(gpointer user_data) { |
|
261 |
// Error text
|
|
262 |
gchar *error_txt = (gchar*)user_data; |
|
263 |
||
13
by Osmo Antero Maatta
Beware for long error messages. Small GUI changes. |
264 |
// Long error messages make the GUI too tall/wide
|
265 |
if (str_length(error_txt, 1024) > 256) { |
|
266 |
*(error_txt + 256) = '\0'; |
|
267 |
}
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
268 |
|
13
by Osmo Antero Maatta
Beware for long error messages. Small GUI changes. |
269 |
// Remove last "\n" (it adds an empty line to the label)
|
270 |
if (error_txt) { |
|
271 |
gchar *p = g_strrstr(error_txt, "\n"); |
|
272 |
if (p) { |
|
273 |
*p = '\0'; |
|
274 |
}
|
|
11
by Osmo Antero Maatta
Filename now includes artist name. Like artist/ track.ext |
275 |
}
|
276 |
||
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
277 |
// Important: We are calling GTK from a thread. Set lock.
|
278 |
gdk_threads_enter(); |
|
279 |
||
280 |
// Get the label widget
|
|
104
by Osmo Antero
Removed fixed icon images. Getting now icon pixmaps from current icon theme. |
281 |
GtkWidget *label = NULL; |
282 |
if (GTK_IS_WIDGET(g_win.error_box)) { |
|
283 |
label = (GtkWidget*)g_object_get_data(G_OBJECT(g_win.error_box), "label-widget"); |
|
284 |
}
|
|
285 |
||
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
286 |
if (!GTK_IS_WIDGET(label)) goto LBL_1; |
287 |
||
288 |
if (str_length(error_txt, 1024) < 1) { |
|
289 |
// Hide the error label
|
|
290 |
gtk_label_set_text(GTK_LABEL(label), ""); |
|
291 |
gtk_widget_hide(g_win.error_box); |
|
292 |
||
293 |
} else { |
|
294 |
// Set and show the error label
|
|
295 |
gtk_label_set_text(GTK_LABEL(label), error_txt); |
|
296 |
gtk_widget_show(g_win.error_box); |
|
297 |
}
|
|
298 |
||
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
299 |
LBL_1: |
300 |
// Free the data
|
|
301 |
g_free(error_txt); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
302 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
303 |
// Important: We are calling GTK from a thread. Free the lock.
|
304 |
gdk_threads_leave(); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
305 |
|
306 |
return 0; |
|
307 |
}
|
|
308 |
||
309 |
void win_flip_recording_cb(GtkButton *button, gpointer user_data) { |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
310 |
// Start, continue or stop recording
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
311 |
rec_manager_flip_recording(); |
312 |
}
|
|
313 |
||
314 |
gboolean win_recording_button_cb(GtkWidget *widget, GdkEventButton *event, gpointer user_data) { |
|
315 |
// Click on g_win.recorder_button
|
|
316 |
||
317 |
if (event->button == 3) { |
|
318 |
// Show right click menu
|
|
319 |
win_show_right_click_menu(); |
|
320 |
}
|
|
321 |
return FALSE; |
|
322 |
}
|
|
323 |
||
324 |
void win_show_right_click_menu() { |
|
325 |
// Show a popup menu. Borrow menu from the systray module.
|
|
326 |
GtkWidget *popup_menu = systray_create_menu(FALSE/*not for systray*/); |
|
327 |
gtk_menu_popup(GTK_MENU(popup_menu), NULL, NULL, NULL, NULL, -1, gtk_get_current_event_time()); |
|
328 |
}
|
|
329 |
||
330 |
static void win_expander_click_cb(GObject *object, GParamSpec *param_spec, gpointer userdata) { |
|
331 |
// Handle click on GUI Exapnder>
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
332 |
GtkExpander *expander = GTK_EXPANDER(object); |
333 |
gboolean expanded = gtk_expander_get_expanded(expander); |
|
334 |
gchar *expander_name = (gchar*)userdata; |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
335 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
336 |
// Save the expanded status
|
337 |
conf_save_boolean_value(expander_name, expanded); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
338 |
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
339 |
if (!g_strcmp0(expander_name, "timer-expanded")) { |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
340 |
|
341 |
// Save the timer text
|
|
342 |
win_timer_save_text_cb(g_win.timer_save_button, NULL); |
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
343 |
} else if (!g_strcmp0(expander_name, "settings-expanded")) { |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
344 |
|
345 |
// Show/hide [Additional settings] button
|
|
346 |
if (expanded) |
|
347 |
gtk_widget_show(g_win.settings_button); |
|
348 |
else
|
|
349 |
gtk_widget_hide(g_win.settings_button); |
|
350 |
}
|
|
351 |
}
|
|
352 |
||
353 |
void win_add_to_changed_cb(GtkToggleButton *togglebutton, gpointer user_data) { |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
354 |
// Click on g_win.add_to_file checkbox
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
355 |
|
356 |
// It is active?
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
357 |
gboolean active = gtk_toggle_button_get_active(togglebutton); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
358 |
|
359 |
// Save in GConf registry
|
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
360 |
conf_save_boolean_value("append-to-file", active); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
361 |
|
362 |
// No reason to let the timer know about this.
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
363 |
// Commented out:
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
364 |
// timer_settings_changed();
|
365 |
}
|
|
366 |
||
367 |
void win_timer_active_cb(GtkToggleButton *togglebutton, gpointer user_data) { |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
368 |
// Click on g_win.timer_active checkbox
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
369 |
|
370 |
// Timer is active?
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
371 |
gboolean active = gtk_toggle_button_get_active(togglebutton); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
372 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
373 |
if (GTK_IS_WIDGET(g_win.timer_text)) { |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
374 |
// Always keep the edit field enabled.
|
375 |
// Commented out:
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
376 |
// gtk_widget_set_sensitive(g_win.timer_text, active);
|
377 |
}
|
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
378 |
|
379 |
// Save in GConf registry
|
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
380 |
conf_save_boolean_value("timer-active", active); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
381 |
|
382 |
// Let the timer know that the settings have been altered
|
|
383 |
timer_settings_changed(); |
|
384 |
}
|
|
385 |
||
386 |
void combo_select_string(GtkComboBox *combo, gchar *str, gint sel_row) { |
|
387 |
// Find str in the GtkComboBox (combo).
|
|
388 |
// If str is not found then select sel_row line.
|
|
389 |
// If sel_row < 0, then add a new row (with str) and select it.
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
390 |
GtkTreeModel *model = gtk_combo_box_get_model(combo); |
391 |
GtkTreeIter iter; |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
392 |
|
393 |
// Loop for all rows
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
394 |
gint ret = gtk_tree_model_get_iter_first(model, &iter); |
395 |
while (ret && str) { |
|
396 |
gchar *val = NULL; |
|
397 |
gtk_tree_model_get(model, &iter, 0, &val, -1); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
398 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
399 |
// Strings match?
|
400 |
if (strcmp(val, str) == 0) { |
|
401 |
// Select this item
|
|
402 |
gtk_combo_box_set_active_iter(combo, &iter); |
|
403 |
g_free(val); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
404 |
// And quit
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
405 |
return; |
406 |
}
|
|
407 |
g_free(val); |
|
408 |
ret = gtk_tree_model_iter_next(model, &iter); |
|
409 |
}
|
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
410 |
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
411 |
// Item was not found. Select sel_row.
|
412 |
gtk_combo_box_set_active(combo, sel_row); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
413 |
}
|
414 |
||
415 |
void window_show_timer_help() { |
|
416 |
// Show help file
|
|
417 |
help_show_page("timer-syntax.html"); |
|
418 |
}
|
|
419 |
||
420 |
gboolean win_window_is_visible() { |
|
421 |
// Window is visible?
|
|
422 |
return gtk_widget_get_visible(g_win.window); |
|
423 |
}
|
|
424 |
||
425 |
void win_show_window(gboolean show) { |
|
56
by Osmo Antero
Version 0.5 |
426 |
// Show or hide window
|
427 |
win_call_gui_func(win_show_window_ex, GINT_TO_POINTER(show)); |
|
428 |
}
|
|
429 |
||
430 |
static void *win_show_window_ex(gpointer user_data) { |
|
431 |
gboolean show = GPOINTER_TO_INT(user_data); |
|
432 |
||
433 |
// Important: We are calling GTK from a thread. Set lock.
|
|
434 |
gdk_threads_enter(); |
|
435 |
||
436 |
// Close about dialog if open
|
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
437 |
about_destroy_dialog(); |
438 |
||
439 |
// Show or hide the main window
|
|
56
by Osmo Antero
Version 0.5 |
440 |
if (!GTK_IS_WINDOW(g_win.window)) goto L_END; |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
441 |
|
442 |
if (show) { |
|
443 |
// Show window. Also bring up if window is minimized/iconified.
|
|
444 |
gtk_widget_show(g_win.window); |
|
445 |
gtk_window_deiconify(GTK_WINDOW(g_win.window)); |
|
446 |
gtk_window_present(GTK_WINDOW(g_win.window)); |
|
447 |
} else { |
|
56
by Osmo Antero
Version 0.5 |
448 |
// Close settings dialog if open
|
449 |
win_settings_destroy_dialog(); |
|
450 |
||
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
451 |
// Hide window
|
452 |
gtk_widget_hide(g_win.window); |
|
453 |
}
|
|
454 |
||
455 |
// Update menu on the systray
|
|
456 |
systray_set_menu_items2(show); |
|
56
by Osmo Antero
Version 0.5 |
457 |
|
458 |
L_END: |
|
459 |
// Important: We are calling GTK from a thread. Free the lock.
|
|
460 |
gdk_threads_leave(); |
|
461 |
||
462 |
return 0; |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
463 |
}
|
464 |
||
465 |
void test_0_cb(GtkWidget *widget, gpointer data) { |
|
466 |
// For testing and debugging
|
|
467 |
}
|
|
468 |
||
469 |
void win_settings_cb(GtkWidget *widget, gpointer data) { |
|
470 |
// Show the [Additional settings] dialog
|
|
471 |
win_settings_show_dialog(GTK_WINDOW(g_win.window)); |
|
472 |
}
|
|
473 |
||
474 |
void win_refresh_device_list() { |
|
475 |
// Refresh/reload the list of audio devices and Media Players, Skype
|
|
476 |
||
477 |
// Reset error message
|
|
478 |
win_set_error_text(NULL); |
|
479 |
||
480 |
// Get current selection
|
|
481 |
gchar *dev_name; |
|
482 |
gchar *dev_id; |
|
483 |
gint dev_type; |
|
484 |
audio_sources_combo_get_values(g_win.audio_device, &dev_name, &dev_id, &dev_type); |
|
485 |
||
486 |
// Load the audio sources (device names) from PulseAudio (or Gstreamer) and fill the combobox.
|
|
487 |
// Detect and add also Media Players, Skype (if installed) to the list. These can control the recording via DBus.
|
|
488 |
audio_source_fill_combo(g_win.audio_device); |
|
489 |
||
490 |
if (dev_id) { |
|
491 |
// Set/show the current value
|
|
492 |
audio_sources_combo_set_id(g_win.audio_device, dev_id); |
|
493 |
}
|
|
494 |
||
495 |
// Free the values
|
|
496 |
g_free(dev_name); |
|
497 |
g_free(dev_id); |
|
498 |
}
|
|
499 |
||
500 |
void win_set_device_id() { |
|
501 |
// Simply set the value of g_win.audio_device combo
|
|
502 |
gchar *str_value = NULL; |
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
503 |
conf_get_string_value("audio-device-id", &str_value); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
504 |
audio_sources_combo_set_id(g_win.audio_device, str_value); |
505 |
g_free(str_value); |
|
506 |
}
|
|
507 |
||
508 |
void win_device_list_changed_cb(GtkWidget *widget, gpointer data) { |
|
509 |
// Selection in the device combo
|
|
510 |
||
511 |
// Reset error message (message label)
|
|
512 |
win_set_error_text(NULL); |
|
513 |
||
514 |
// Get values
|
|
515 |
gchar *dev_name; |
|
516 |
gchar *dev_id; |
|
517 |
gint dev_type; |
|
518 |
audio_sources_combo_get_values(g_win.audio_device, &dev_name, &dev_id, &dev_type); |
|
519 |
||
520 |
LOG_DEBUG("-----------------------\n"); |
|
521 |
LOG_DEBUG("Selected device or media player, etc. (g_win.audio_device):%s\n", dev_id); |
|
522 |
LOG_DEBUG("name:%s\n", dev_name); |
|
523 |
LOG_DEBUG("type:%d\n", dev_type); |
|
524 |
LOG_DEBUG("-----------------------\n"); |
|
525 |
||
526 |
// Save id
|
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
527 |
conf_save_string_value("audio-device-id", check_null(dev_id)); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
528 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
529 |
// Save name
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
530 |
conf_save_string_value("audio-device-name", dev_name); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
531 |
|
532 |
// Save type
|
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
533 |
conf_save_int_value("audio-device-type", dev_type); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
534 |
|
535 |
// Tell audio_sources that the device has changed.
|
|
536 |
// This will disconnect/re-connect all DBus signals to Media Players, Skype.
|
|
537 |
audio_sources_device_changed(dev_id); |
|
538 |
||
539 |
// Let timer know that the settings have been altered.
|
|
540 |
timer_settings_changed(); |
|
541 |
||
542 |
// Free the values
|
|
543 |
g_free(dev_name); |
|
544 |
g_free(dev_id); |
|
545 |
}
|
|
546 |
||
547 |
void win_audio_format_changed_cb(GtkWidget *widget, gpointer data) { |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
548 |
// Save media-profile (id)
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
549 |
gchar *txt = media_profiles_get_selected_id(widget/*=g_win.media_format*/); |
550 |
||
551 |
LOG_DEBUG("Selected audio format (g_win.media_format):%s\n", txt); |
|
552 |
||
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
553 |
conf_save_string_value("media-format", txt); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
554 |
g_free(txt); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
555 |
}
|
556 |
||
557 |
void win_timer_text_changed_cb(GtkTextBuffer *textbuffer, gpointer user_data) { |
|
558 |
// Timer text changed. Show [Save] button.
|
|
559 |
gtk_widget_show(g_win.timer_save_button); |
|
560 |
}
|
|
561 |
||
562 |
void win_timer_text_insert_cb(GtkTextBuffer *textbuffer, GtkTextIter *location, gchar *text, gint len, gpointer user_data) { |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
563 |
#define MAX_TEXT_LEN 3500
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
564 |
|
565 |
// Get buffer start and end
|
|
566 |
GtkTextIter start, end; |
|
567 |
gtk_text_buffer_get_bounds(textbuffer, &start, &end); |
|
568 |
||
569 |
// Get approx. character count
|
|
570 |
gint text_len = gtk_text_iter_get_offset(&end); |
|
571 |
||
572 |
if (text_len > MAX_TEXT_LEN) { |
|
573 |
// Buffer becomes too large. Stop this insert!
|
|
574 |
g_signal_stop_emission_by_name(textbuffer, "insert_text"); |
|
575 |
}
|
|
576 |
}
|
|
577 |
||
578 |
void win_timer_save_text_cb(GtkWidget *widget, gpointer user_data) { |
|
579 |
// Save timer text
|
|
580 |
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(g_win.timer_text)); |
|
581 |
||
582 |
// Read timer text
|
|
583 |
GtkTextIter start, end; |
|
584 |
gtk_text_buffer_get_start_iter(buffer, &start); |
|
585 |
gtk_text_buffer_get_end_iter(buffer, &end); |
|
586 |
||
587 |
gchar *text = gtk_text_buffer_get_text(buffer, &start, &end, FALSE); |
|
588 |
||
589 |
// Save it
|
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
590 |
conf_save_string_value("timer-text", text); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
591 |
|
592 |
g_free(text); |
|
593 |
||
594 |
// Hide the [Save] button
|
|
595 |
if (gtk_widget_get_visible(widget)) { |
|
596 |
gtk_widget_hide(widget); |
|
597 |
}
|
|
598 |
||
599 |
// Let the timer know that the settings have been altered
|
|
600 |
timer_settings_changed(); |
|
601 |
}
|
|
602 |
||
603 |
void win_close_button_cb(GtkButton *button, gpointer user_data) { |
|
604 |
// Click on [Close] button
|
|
605 |
||
606 |
gboolean force_quit = (gboolean)GPOINTER_TO_INT(user_data); |
|
607 |
||
608 |
// Has icon on the systen tray?
|
|
609 |
if (!force_quit && systray_icon_is_installed()) { |
|
610 |
// Hide this window
|
|
611 |
win_show_window(FALSE); |
|
612 |
return; |
|
613 |
}
|
|
614 |
||
615 |
// Quit application, destroy this window.
|
|
616 |
about_destroy_dialog(); |
|
617 |
||
618 |
win_delete_cb(g_win.window, NULL, NULL); |
|
619 |
||
620 |
gtk_main_quit(); |
|
621 |
gtk_widget_destroy(g_win.window); |
|
622 |
||
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
623 |
g_win.window = NULL; |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
624 |
}
|
625 |
||
56
by Osmo Antero
Version 0.5 |
626 |
void win_quit_application() { |
627 |
// Quit this application
|
|
628 |
win_close_button_cb(NULL, (gpointer)TRUE); |
|
629 |
}
|
|
630 |
||
631 |
||
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
632 |
gboolean win_close_button_press_cb(GtkWidget *widget, GdkEventButton *event, gpointer user_data) { |
633 |
// Right click on [Close] button?
|
|
634 |
if (event->button == 3) { |
|
635 |
// Show a small "Quit" menu
|
|
636 |
GtkWidget *menu = gtk_menu_new(); |
|
19
by Osmo Antero Maatta
Added instructions for translators |
637 |
// Translators: This is a small right-click-menu on the GUI's [Close] button.
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
638 |
GtkWidget *menu_item = gtk_menu_item_new_with_label(_("Quit")); |
639 |
gtk_widget_show(menu_item); |
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
640 |
|
641 |
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item); |
|
642 |
||
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
643 |
g_signal_connect(menu_item, "activate", G_CALLBACK(win_close_button_cb), GINT_TO_POINTER(TRUE)); |
644 |
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, -1, gtk_get_current_event_time()); |
|
645 |
return TRUE; |
|
646 |
}
|
|
647 |
return FALSE; |
|
648 |
}
|
|
649 |
||
650 |
gboolean win_delete_cb(GtkWidget *widget, GdkEvent *event, gpointer data) { |
|
56
by Osmo Antero
Version 0.5 |
651 |
// Called prior exit.
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
652 |
|
653 |
LOG_DEBUG("win_delete_cb() called.\n"); |
|
654 |
||
56
by Osmo Antero
Version 0.5 |
655 |
dbus_service_module_exit(); |
656 |
||
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
657 |
systray_module_exit(); |
658 |
||
659 |
rec_manager_exit(); |
|
660 |
||
661 |
audio_sources_exit(); |
|
662 |
||
663 |
media_profiles_exit(); |
|
664 |
||
665 |
timer_module_exit(); |
|
666 |
||
667 |
// Allow exit.
|
|
668 |
return FALSE; |
|
669 |
}
|
|
670 |
||
671 |
void win_destroy_cb(GtkWidget *widget, gpointer data) { |
|
672 |
// Quit/exit this application
|
|
673 |
gtk_main_quit (); |
|
674 |
}
|
|
675 |
||
676 |
static gboolean win_state_event_cb(GtkWidget *widget, GdkEventWindowState *event, gpointer data) { |
|
677 |
// Save window's state.
|
|
678 |
// We are interested in GDK_WINDOW_STATE_ICONIFIED and 0 (normal state).
|
|
679 |
g_win.state = event->new_window_state; |
|
680 |
||
681 |
if (g_win.state == 0) { |
|
9
by Osmo Antero Maatta
Cleaning up the rec_stop_recording() code + other improvements |
682 |
// Enable/disbale menu items (on systray icon)
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
683 |
systray_set_menu_items2(TRUE); |
684 |
||
685 |
} else if (g_win.state == GDK_WINDOW_STATE_ICONIFIED) { |
|
9
by Osmo Antero Maatta
Cleaning up the rec_stop_recording() code + other improvements |
686 |
// Enable/disbale menu items (on systray icon)
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
687 |
systray_set_menu_items2(FALSE); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
688 |
}
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
689 |
|
690 |
return TRUE; |
|
691 |
}
|
|
692 |
||
693 |
GdkWindowState win_get_window_state() { |
|
694 |
// Return current window state
|
|
695 |
return g_win.state; |
|
696 |
}
|
|
697 |
||
698 |
gboolean win_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer user_data) { |
|
699 |
// Key press event on the main window
|
|
700 |
||
701 |
if (event->state & GDK_CONTROL_MASK) { |
|
702 |
if (event->keyval == 's' || event->keyval == 'S') { |
|
703 |
// Control + S saves timer text
|
|
704 |
win_timer_save_text_cb(g_win.timer_save_button, NULL); |
|
705 |
||
706 |
} else if (event->keyval == 'x' || event->keyval == 'X') { |
|
707 |
// Control + X stops recording
|
|
708 |
rec_manager_stop_recording(); |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
709 |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
710 |
} else if (event->keyval == 'p' || event->keyval == 'P') { |
711 |
// Control + P pauses recording
|
|
712 |
rec_manager_pause_recording(); |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
713 |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
714 |
} else if (event->keyval == 'r' || event->keyval == 'R') { |
715 |
// Control + R starts recording
|
|
716 |
rec_manager_start_recording(); |
|
717 |
}
|
|
718 |
}
|
|
719 |
||
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
720 |
// Pass this event further
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
721 |
return FALSE; |
722 |
}
|
|
723 |
||
724 |
void win_show_settings_dialog() { |
|
725 |
win_settings_show_dialog(GTK_WINDOW(g_win.window)); |
|
726 |
}
|
|
727 |
||
81
by Osmo Antero Maatta
New GtkLevelBar widget for the level indicator. |
728 |
void win_level_bar_clicked(GtkWidget *widget, GdkEvent *event, gpointer data) { |
729 |
// User clicked the level bar.
|
|
730 |
// Change the level text. Valid types are %-value, dB-value or nothing.
|
|
731 |
GdkEventButton *ev = (GdkEventButton*)event; |
|
732 |
||
733 |
if (ev->button != 1) { |
|
734 |
// return;
|
|
735 |
}
|
|
736 |
||
737 |
// Get from DConf
|
|
738 |
gint text_type = (gint)LEVEL_TEXT_NONE; |
|
739 |
conf_get_int_value("level-bar-text-type", &text_type); |
|
740 |
||
741 |
// Take next type
|
|
742 |
text_type += 1; |
|
743 |
if (text_type < (gint)LEVEL_TEXT_NONE/*first enum*/ || text_type > (gint)LEVEL_TEXT_DB/* last enum*/) { |
|
744 |
text_type = (gint)LEVEL_TEXT_NONE; |
|
745 |
}
|
|
746 |
||
747 |
g_win.level_ttype = text_type; |
|
748 |
||
749 |
// Save in DConf
|
|
750 |
conf_save_int_value("level-bar-text-type", text_type); |
|
751 |
}
|
|
752 |
||
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
753 |
void win_create_window() { |
754 |
// Create main window and all its widgets
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
755 |
g_win.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
756 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
757 |
gtk_window_set_default_size(GTK_WINDOW(g_win.window), PREF_WINDOW_WIDTH, -1); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
758 |
gtk_window_set_position(GTK_WINDOW(g_win.window), GTK_WIN_POS_MOUSE); |
759 |
||
760 |
// Show on all desktops
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
761 |
gtk_window_stick(GTK_WINDOW(g_win.window)); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
762 |
|
56
by Osmo Antero
Version 0.5 |
763 |
// Keep this window on top, above other windows
|
764 |
gtk_window_set_keep_above(GTK_WINDOW(g_win.window), TRUE); |
|
765 |
||
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
766 |
gtk_window_set_default_icon_name("audio-recorder"); |
767 |
||
768 |
gchar *prog_name = get_program_name(); |
|
769 |
gtk_window_set_title(GTK_WINDOW(g_win.window), prog_name); |
|
770 |
g_free(prog_name); |
|
771 |
||
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
772 |
// Set resizable to FALSE.
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
773 |
// Note: This makes the window to shrink when GtkExpanders are shrunk/reduced/contracted.
|
774 |
gtk_window_set_resizable(GTK_WINDOW(g_win.window), FALSE); |
|
775 |
||
776 |
g_signal_connect(g_win.window, "delete-event", G_CALLBACK(win_delete_cb), NULL); |
|
777 |
g_signal_connect(g_win.window, "destroy", G_CALLBACK(win_destroy_cb), NULL); |
|
778 |
g_signal_connect(g_win.window, "window-state-event", G_CALLBACK (win_state_event_cb), NULL); |
|
779 |
||
780 |
// Actions on Control + S/R/P/X keys
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
781 |
g_signal_connect(g_win.window, "key-press-event", G_CALLBACK(win_key_press_cb), NULL); |
782 |
||
783 |
GtkWidget *frame = gtk_frame_new(NULL); |
|
784 |
gtk_widget_show(frame); |
|
785 |
gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); |
|
786 |
gtk_container_add(GTK_CONTAINER(g_win.window), frame); |
|
787 |
gtk_container_set_border_width(GTK_CONTAINER(frame), 7); |
|
788 |
||
77
by Osmo Antero
Updated version (v0.7) for Fedora 16+ and Ubuntu 12.04. |
789 |
GtkWidget *vbox0 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
790 |
gtk_widget_show(vbox0); |
791 |
gtk_container_add(GTK_CONTAINER(frame), vbox0); |
|
792 |
||
793 |
#ifdef APP_HAS_MENU
|
|
794 |
// Create menubar.
|
|
795 |
// EDIT: I have remove the menubar.
|
|
796 |
GtkWidget *menubar = win_create_menubar(); |
|
797 |
gtk_widget_show(menubar); |
|
798 |
gtk_box_pack_start(GTK_BOX(vbox0), menubar, FALSE, FALSE, 0); |
|
799 |
#endif
|
|
800 |
||
77
by Osmo Antero
Updated version (v0.7) for Fedora 16+ and Ubuntu 12.04. |
801 |
GtkWidget *vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 3); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
802 |
gtk_widget_show(vbox1); |
803 |
gtk_box_pack_start(GTK_BOX(vbox0), vbox1, FALSE, TRUE, 0); |
|
804 |
||
77
by Osmo Antero
Updated version (v0.7) for Fedora 16+ and Ubuntu 12.04. |
805 |
GtkWidget *hbox0 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
806 |
gtk_widget_show(hbox0); |
807 |
gtk_box_pack_start(GTK_BOX(vbox1), hbox0, TRUE, TRUE, 0); |
|
808 |
||
809 |
// Get saved values
|
|
810 |
gchar *last_track_name = NULL; // Last saved filename |
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
811 |
conf_get_string_value("track/last-track-name", &last_track_name); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
812 |
|
813 |
gboolean append_to_file = FALSE; |
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
814 |
conf_get_boolean_value("append-to-file", &append_to_file); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
815 |
|
816 |
// [Start/Stop/Continue recording] button
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
817 |
g_win.recorder_button = gtk_button_new_with_mnemonic(""); |
818 |
gtk_widget_show(g_win.recorder_button); |
|
819 |
gtk_box_pack_start(GTK_BOX (hbox0), g_win.recorder_button, FALSE, FALSE, 0); |
|
820 |
g_signal_connect(g_win.recorder_button, "clicked", G_CALLBACK(win_flip_recording_cb), NULL); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
821 |
g_signal_connect(g_win.recorder_button, "button-press-event",G_CALLBACK(win_recording_button_cb), NULL); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
822 |
gtk_button_set_use_underline(GTK_BUTTON(g_win.recorder_button), TRUE); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
823 |
|
824 |
// Time label
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
825 |
g_win.time_label = gtk_label_new("00:00:00"); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
826 |
gtk_widget_show(g_win.time_label); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
827 |
gtk_box_pack_start(GTK_BOX(hbox0), g_win.time_label, FALSE, FALSE, 2); |
828 |
gtk_widget_set_sensitive(g_win.time_label, FALSE); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
829 |
|
830 |
// Label for filesize
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
831 |
g_win.size_label = gtk_label_new("0.0 KB"); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
832 |
gtk_widget_show(g_win.size_label); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
833 |
gtk_box_pack_start(GTK_BOX(hbox0), g_win.size_label, FALSE, FALSE, 7); |
834 |
gtk_widget_set_sensitive(g_win.size_label, FALSE); |
|
835 |
||
836 |
// Show current file size
|
|
837 |
if (g_file_test(last_track_name, G_FILE_TEST_EXISTS)) { |
|
838 |
struct stat fstat; |
|
839 |
if (!stat(last_track_name, &fstat)) { |
|
840 |
gchar *size_txt = format_file_size(fstat.st_size); |
|
841 |
gtk_label_set_text(GTK_LABEL(g_win.size_label), size_txt); |
|
842 |
g_free(size_txt); |
|
843 |
}
|
|
844 |
}
|
|
845 |
||
81
by Osmo Antero Maatta
New GtkLevelBar widget for the level indicator. |
846 |
// Indicator for sound level/amplitude (GtkLevelBar widget)
|
847 |
// Put it in an GtkEventBox so we can catch clicked event.
|
|
848 |
// User can change the text/label type (%, dB, NULL) by clicking it.
|
|
849 |
GtkWidget *event_box = gtk_event_box_new(); |
|
850 |
gtk_box_pack_start(GTK_BOX(hbox0), event_box, TRUE, TRUE, 0); |
|
851 |
gtk_widget_show(event_box); |
|
852 |
||
853 |
// Allow mouse click events
|
|
854 |
gtk_widget_set_events(event_box, GDK_BUTTON_PRESS_MASK); |
|
855 |
g_signal_connect(event_box, "button_press_event", G_CALLBACK(win_level_bar_clicked), NULL); |
|
856 |
||
857 |
// Create GtkLevelBar widget and put it in the GtkEventBox
|
|
858 |
g_win.level_bar = gtk_level_bar_new(); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
859 |
gtk_widget_show(g_win.level_bar); |
81
by Osmo Antero Maatta
New GtkLevelBar widget for the level indicator. |
860 |
gtk_container_add(GTK_CONTAINER(event_box), g_win.level_bar); |
861 |
gtk_level_bar_set_fraction(GTK_LEVEL_BAR(g_win.level_bar), 0.0, NULL); |
|
862 |
||
863 |
// How to display label/text on the level bar?
|
|
864 |
// Get from DConf
|
|
865 |
gint text_ttype = (gint)LEVEL_TEXT_NONE; |
|
866 |
conf_get_int_value("level-bar-text-type", &text_ttype); |
|
867 |
g_win.level_ttype = text_ttype; |
|
868 |
// Notice: User can change this by clicking on the level-bar.
|
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
869 |
|
77
by Osmo Antero
Updated version (v0.7) for Fedora 16+ and Ubuntu 12.04. |
870 |
GtkWidget *hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
871 |
gtk_widget_show(hbox1); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
872 |
gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
873 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
874 |
// Translators: This is a GUI label. Keep it short.
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
875 |
GtkWidget *label0 = gtk_label_new(_("File:")); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
876 |
gtk_widget_show(label0); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
877 |
gtk_box_pack_start(GTK_BOX(hbox1), label0, FALSE, FALSE, 0); |
878 |
gtk_misc_set_alignment(GTK_MISC(label0), 0.01, 0.5); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
879 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
880 |
g_win.filename = gtk_entry_new(); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
881 |
gtk_widget_show(g_win.filename); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
882 |
gtk_box_pack_start(GTK_BOX(hbox1), g_win.filename, TRUE, TRUE, 0); |
883 |
gtk_entry_set_invisible_char(GTK_ENTRY(g_win.filename), 9679); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
884 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
885 |
// Show lastly saved filename; basename.ext
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
886 |
gchar *path = NULL; |
887 |
gchar *fname = NULL; |
|
888 |
split_filename2(last_track_name, &path, &fname); |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
889 |
gtk_entry_set_text(GTK_ENTRY(g_win.filename), (fname ? fname : "")); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
890 |
g_free(path); |
891 |
g_free(fname); |
|
892 |
||
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
893 |
// Free last_track_name
|
894 |
g_free(last_track_name); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
895 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
896 |
// "Add to file" label.
|
897 |
// Translators: This is a GUI label. Keep it VERY short.
|
|
898 |
g_win.add_to_file = gtk_check_button_new_with_mnemonic(_("Add.")); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
899 |
gtk_widget_show(g_win.add_to_file); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
900 |
gtk_box_pack_start(GTK_BOX(hbox1), g_win.add_to_file, FALSE, FALSE, 0); |
901 |
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_win.add_to_file), append_to_file); |
|
902 |
g_signal_connect(g_win.add_to_file, "toggled", G_CALLBACK(win_add_to_changed_cb), NULL); |
|
903 |
||
904 |
// Timer interface
|
|
905 |
gchar *str_value = NULL; |
|
906 |
gboolean bool_value = FALSE; |
|
907 |
||
908 |
// "Timer>" GUI expander.
|
|
909 |
// Translators: This is a GUI label. Keep it short.
|
|
910 |
GtkWidget *timer_expander = gtk_expander_new(_("Timer.")); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
911 |
gtk_widget_show(timer_expander); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
912 |
gtk_box_pack_start(GTK_BOX(vbox1), timer_expander, TRUE, TRUE, 0); |
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
913 |
|
914 |
conf_get_boolean_value("timer-expanded", &bool_value); |
|
915 |
||
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
916 |
gtk_expander_set_expanded(GTK_EXPANDER(timer_expander), bool_value); |
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
917 |
g_signal_connect(timer_expander, "notify::expanded", G_CALLBACK(win_expander_click_cb), "timer-expanded"); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
918 |
|
77
by Osmo Antero
Updated version (v0.7) for Fedora 16+ and Ubuntu 12.04. |
919 |
GtkWidget *hbox2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
920 |
gtk_widget_show(hbox2); |
921 |
gtk_container_add(GTK_CONTAINER(timer_expander), hbox2); |
|
922 |
||
77
by Osmo Antero
Updated version (v0.7) for Fedora 16+ and Ubuntu 12.04. |
923 |
GtkWidget *vbox22 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
924 |
gtk_widget_show(vbox22); |
925 |
gtk_box_pack_start(GTK_BOX(hbox2), vbox22, FALSE, FALSE, 0); |
|
926 |
||
927 |
// Timer checkbox
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
928 |
g_win.timer_active = gtk_check_button_new(); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
929 |
gtk_widget_show(g_win.timer_active); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
930 |
gtk_box_pack_start(GTK_BOX(vbox22), g_win.timer_active, FALSE, FALSE, 0); |
931 |
g_signal_connect(g_win.timer_active, "toggled", G_CALLBACK(win_timer_active_cb), NULL); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
932 |
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
933 |
conf_get_boolean_value("timer-active", &bool_value); |
934 |
||
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
935 |
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_win.timer_active), bool_value); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
936 |
|
937 |
// Timer text/commands; GtkTextView, multiline text view.
|
|
77
by Osmo Antero
Updated version (v0.7) for Fedora 16+ and Ubuntu 12.04. |
938 |
GtkWidget *vbox20 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
939 |
gtk_widget_show(vbox20); |
77
by Osmo Antero
Updated version (v0.7) for Fedora 16+ and Ubuntu 12.04. |
940 |
gtk_box_pack_start(GTK_BOX(hbox2), vbox20, TRUE, TRUE, 0); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
941 |
|
942 |
// Put g_win.timer_text to a GtkFrame so it gets a visible border/frame
|
|
943 |
GtkWidget *frame2 = gtk_frame_new(NULL); |
|
944 |
gtk_widget_show(frame2); |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
945 |
gtk_box_pack_start(GTK_BOX(vbox20), frame2, TRUE, TRUE, 0); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
946 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
947 |
g_win.timer_text = gtk_text_view_new(); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
948 |
gtk_widget_show(g_win.timer_text); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
949 |
gtk_container_add(GTK_CONTAINER(frame2), g_win.timer_text); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
950 |
|
951 |
// Timer [Save] button
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
952 |
g_win.timer_save_button = gtk_button_new_from_stock(GTK_STOCK_SAVE); |
953 |
// Hide it
|
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
954 |
gtk_widget_hide(g_win.timer_save_button); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
955 |
g_signal_connect(g_win.timer_save_button, "clicked", G_CALLBACK(win_timer_save_text_cb), NULL); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
956 |
|
77
by Osmo Antero
Updated version (v0.7) for Fedora 16+ and Ubuntu 12.04. |
957 |
GtkWidget *hbox22 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
958 |
gtk_widget_show(hbox22); |
959 |
gtk_container_add(GTK_CONTAINER(vbox20), hbox22); |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
960 |
gtk_box_pack_end(GTK_BOX(hbox22), g_win.timer_save_button, FALSE, FALSE, 0); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
961 |
|
962 |
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(g_win.timer_text)); |
|
963 |
g_signal_connect(buffer, "changed", G_CALLBACK(win_timer_text_changed_cb), NULL); |
|
964 |
g_signal_connect(buffer, "insert-text", G_CALLBACK(win_timer_text_insert_cb), NULL); |
|
965 |
||
966 |
// Get current timer text
|
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
967 |
conf_get_string_value("timer-text", &str_value); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
968 |
|
7
by Osmo Antero Maatta
Improved timer commands |
969 |
if (str_length(str_value, 4096) > 0) { |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
970 |
gtk_text_buffer_set_text(buffer, str_value, -1); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
971 |
} else { |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
972 |
// Add some examples
|
973 |
GString *str = g_string_new(NULL); |
|
974 |
||
975 |
g_string_append(str, "start at 08:20 pm\n"); |
|
976 |
g_string_append_printf(str, "# stop after 1 h 30 min\n"); |
|
977 |
||
978 |
g_string_append_printf(str, "# stop if silence | 100MB\n"); |
|
979 |
g_string_append_printf(str, "# start if voice 5s 6%%"); |
|
980 |
||
981 |
gchar *str_txt = g_string_free(str, FALSE); |
|
982 |
gtk_text_buffer_set_text(buffer, str_txt, -1); |
|
7
by Osmo Antero Maatta
Improved timer commands |
983 |
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
984 |
conf_save_string_value("timer-text", str_txt); |
7
by Osmo Antero Maatta
Improved timer commands |
985 |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
986 |
g_free(str_txt); |
987 |
}
|
|
988 |
g_free(str_value); |
|
989 |
||
990 |
// The [Info] button
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
991 |
GtkWidget *button0 = gtk_button_new(); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
992 |
gtk_widget_show(button0); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
993 |
GtkWidget *image = gtk_image_new_from_stock("gtk-info", GTK_ICON_SIZE_BUTTON); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
994 |
gtk_widget_show(image); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
995 |
gtk_button_set_image(GTK_BUTTON(button0), image); |
996 |
g_signal_connect(button0, "clicked", G_CALLBACK(window_show_timer_help), NULL); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
997 |
|
77
by Osmo Antero
Updated version (v0.7) for Fedora 16+ and Ubuntu 12.04. |
998 |
vbox22 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
999 |
gtk_widget_show(vbox22); |
1000 |
gtk_box_pack_start(GTK_BOX(hbox2), vbox22, FALSE, FALSE, 0); |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1001 |
gtk_box_pack_start(GTK_BOX(vbox22), button0, FALSE, FALSE, 0); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1002 |
|
77
by Osmo Antero
Updated version (v0.7) for Fedora 16+ and Ubuntu 12.04. |
1003 |
GtkWidget *hseparator0 = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1004 |
gtk_widget_show(hseparator0); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1005 |
gtk_box_pack_start(GTK_BOX(vbox0), hseparator0, FALSE, TRUE, 0); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1006 |
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1007 |
// "Audio settings>" GUI expander.
|
1008 |
// Translators: This is a GUI label.
|
|
1009 |
GtkWidget *setting_expander = gtk_expander_new(_("Audio settings.")); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1010 |
gtk_widget_show(setting_expander); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1011 |
gtk_box_pack_start(GTK_BOX(vbox0), setting_expander, TRUE, TRUE, 2); |
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1012 |
|
1013 |
conf_get_boolean_value("settings-expanded", &bool_value); |
|
1014 |
||
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1015 |
gtk_expander_set_expanded(GTK_EXPANDER(setting_expander), bool_value); |
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1016 |
g_signal_connect(setting_expander, "notify::expanded", G_CALLBACK(win_expander_click_cb), "settings-expanded"); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1017 |
|
77
by Osmo Antero
Updated version (v0.7) for Fedora 16+ and Ubuntu 12.04. |
1018 |
GtkWidget *vbox2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 3); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1019 |
gtk_widget_show(vbox2); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1020 |
gtk_container_add(GTK_CONTAINER(setting_expander), vbox2); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1021 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1022 |
GtkWidget *table0 = gtk_table_new(5, 3, FALSE); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1023 |
gtk_widget_show(table0); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1024 |
gtk_box_pack_start(GTK_BOX (vbox2), table0, FALSE, FALSE, 0); |
1025 |
gtk_table_set_row_spacings(GTK_TABLE(table0), 2); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1026 |
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1027 |
// Audio Source label (meaning Audio Source, the device or program that produces sound).
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1028 |
// Translators: This is a GUI label. Keep it short.
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1029 |
label0 = gtk_label_new(_("Source:")); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1030 |
gtk_widget_show(label0); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1031 |
gtk_table_attach (GTK_TABLE(table0), label0, 0, 1, 0, 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); |
1032 |
gtk_misc_set_alignment(GTK_MISC(label0), 0, 0.5); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1033 |
|
1034 |
// Create combobox for audio devices and Media Players, Skype, etc.
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1035 |
g_win.audio_device = audio_sources_create_combo(); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1036 |
gtk_widget_show(g_win.audio_device); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1037 |
gtk_table_attach(GTK_TABLE(table0), g_win.audio_device, 1, 2, 0, 1,(GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (GTK_FILL), 0, 0); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1038 |
|
1039 |
// Combobox "changed" signal
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1040 |
gulong signal_id = g_signal_connect(g_win.audio_device, "changed", G_CALLBACK(win_device_list_changed_cb), NULL); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1041 |
// Save signal handle so we can block/unblock it
|
1042 |
g_object_set_data(G_OBJECT(g_win.audio_device), "selection-changed-signal", GINT_TO_POINTER(signal_id)); |
|
1043 |
||
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1044 |
// Fill the combo with audio devices and media players.
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1045 |
win_refresh_device_list(); |
1046 |
||
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1047 |
// Set/show the current value.
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1048 |
conf_get_string_value("audio-device-name", &str_value); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1049 |
|
1050 |
// Has value?
|
|
1051 |
if (str_length(str_value, 1024) < 1) { |
|
1052 |
||
1053 |
// Set first (Audio Output) device as default.
|
|
40
by Osmo Antero Maatta
Added ability to record from multiple devices. Major changes in all modules. |
1054 |
GList *lst = audio_sources_get_for_type(AUDIO_SINK_MONITOR); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1055 |
DeviceItem *dev_item = g_list_nth_data(lst, 0); |
1056 |
if (dev_item) { |
|
47
by Osmo Antero Maatta
Formatted code (in src/*.[ch]) with astyle. Ref. README file. |
1057 |
// Save values
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1058 |
conf_save_string_value("audio-device-name", check_null(dev_item->description)); |
1059 |
conf_save_string_value("audio-device-id", dev_item->id); |
|
1060 |
conf_save_int_value("audio-device-type", dev_item->type); |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1061 |
}
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1062 |
|
1063 |
// Free the list and its data
|
|
1064 |
audio_sources_free_list(lst); |
|
1065 |
lst = NULL; |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1066 |
}
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1067 |
|
1068 |
g_free(str_value); |
|
1069 |
||
1070 |
// Add [Reload] button
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1071 |
button0 = gtk_button_new(); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1072 |
gtk_widget_show(button0); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1073 |
image = gtk_image_new_from_stock("gtk-refresh", GTK_ICON_SIZE_BUTTON); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1074 |
gtk_widget_show(image); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1075 |
gtk_button_set_image(GTK_BUTTON(button0), image); |
1076 |
gtk_table_attach(GTK_TABLE(table0), button0, 2, 3, 0, 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); |
|
1077 |
g_signal_connect(button0, "clicked", G_CALLBACK(win_refresh_device_list), NULL); |
|
1078 |
||
1079 |
// Audio format; .OGG, .MP3, .WAV, etc. See media-profiles.c.
|
|
1080 |
// Translators: This is a GUI label. Keep it short.
|
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1081 |
label0 = gtk_label_new (_("Format:")); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1082 |
gtk_widget_show(label0); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1083 |
gtk_table_attach(GTK_TABLE(table0), label0, 0, 1, 1, 2, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); |
1084 |
gtk_misc_set_alignment(GTK_MISC(label0), 0, 0.5); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1085 |
|
1086 |
// Get the media-profiles combobox filled with values.
|
|
86
by Osmo Antero Maatta
Some GUI improvements |
1087 |
// Start dconf/gconf-editor and browse to: system -> gstreamer -> 0.10 -> audio -> profiles.
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1088 |
g_win.media_format = media_profiles_create_combobox(); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1089 |
gtk_widget_show(g_win.media_format); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1090 |
gtk_table_attach(GTK_TABLE(table0), g_win.media_format, 1, 2, 1, 2, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (GTK_FILL), 0, 0); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1091 |
|
1092 |
// Combox "changed" signal
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1093 |
g_signal_connect(g_win.media_format, "changed", G_CALLBACK(win_audio_format_changed_cb), NULL); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1094 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1095 |
// Show current value
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1096 |
conf_get_string_value("media-format", &str_value); |
1097 |
||
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1098 |
combo_select_string(GTK_COMBO_BOX(g_win.media_format), str_value, 0/*select 0'th row if str_value not found*/); |
1099 |
g_free(str_value); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1100 |
|
1101 |
// Separator
|
|
77
by Osmo Antero
Updated version (v0.7) for Fedora 16+ and Ubuntu 12.04. |
1102 |
hseparator0 = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1103 |
gtk_widget_show(hseparator0); |
86
by Osmo Antero Maatta
Some GUI improvements |
1104 |
gtk_box_pack_start(GTK_BOX(vbox0), hseparator0, FALSE, TRUE, 1); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1105 |
|
1106 |
// Place for error messages
|
|
1107 |
{
|
|
77
by Osmo Antero
Updated version (v0.7) for Fedora 16+ and Ubuntu 12.04. |
1108 |
g_win.error_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1109 |
// Hide it
|
1110 |
gtk_widget_hide(g_win.error_box); |
|
13
by Osmo Antero Maatta
Beware for long error messages. Small GUI changes. |
1111 |
gtk_box_pack_start(GTK_BOX(vbox0), g_win.error_box, TRUE, FALSE, 0); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1112 |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1113 |
// Label
|
13
by Osmo Antero Maatta
Beware for long error messages. Small GUI changes. |
1114 |
label0 = gtk_label_new(""); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1115 |
gtk_widget_show(label0); |
13
by Osmo Antero Maatta
Beware for long error messages. Small GUI changes. |
1116 |
gtk_box_pack_start(GTK_BOX(g_win.error_box), label0, TRUE, FALSE, 0); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1117 |
// Left align it
|
1118 |
gtk_misc_set_alignment(GTK_MISC(label0), 0.0f, 0.0f); |
|
1119 |
||
1120 |
// Set red foreground/text color
|
|
1121 |
GdkColor color; |
|
1122 |
gdk_color_parse("red", &color); |
|
1123 |
gtk_widget_modify_fg(label0, GTK_STATE_NORMAL, &color); |
|
13
by Osmo Antero Maatta
Beware for long error messages. Small GUI changes. |
1124 |
// Wrap lines
|
1125 |
gtk_label_set_line_wrap(GTK_LABEL(label0), TRUE); |
|
31
by Osmo Antero Maatta
Timer commands are no longer translatable. Timer commands must be in English language. |
1126 |
gtk_label_set_line_wrap_mode(GTK_LABEL(label0), PANGO_WRAP_WORD); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1127 |
|
1128 |
// Remember the label widget
|
|
1129 |
g_object_set_data(G_OBJECT(g_win.error_box), "label-widget", label0); |
|
1130 |
||
1131 |
// Separator
|
|
77
by Osmo Antero
Updated version (v0.7) for Fedora 16+ and Ubuntu 12.04. |
1132 |
hseparator0 = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1133 |
gtk_widget_show(hseparator0); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1134 |
gtk_box_pack_start(GTK_BOX(g_win.error_box), hseparator0, FALSE, TRUE, 0); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1135 |
}
|
1136 |
||
13
by Osmo Antero Maatta
Beware for long error messages. Small GUI changes. |
1137 |
// Buttons
|
77
by Osmo Antero
Updated version (v0.7) for Fedora 16+ and Ubuntu 12.04. |
1138 |
GtkWidget *hbox4 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1139 |
gtk_widget_show(hbox4); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1140 |
gtk_box_pack_start(GTK_BOX(vbox0), hbox4, FALSE, TRUE, 0); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1141 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1142 |
button0 = gtk_button_new_from_stock("gtk-close"); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1143 |
gtk_widget_show(button0); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1144 |
gtk_box_pack_end(GTK_BOX(hbox4), button0, FALSE, FALSE, 0); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1145 |
g_signal_connect(button0, "clicked", G_CALLBACK(win_close_button_cb), GINT_TO_POINTER(FALSE)); |
1146 |
// Show a small menu on right-mouse click
|
|
1147 |
g_signal_connect(button0, "button-press-event", G_CALLBACK(win_close_button_press_cb), NULL); |
|
1148 |
||
19
by Osmo Antero Maatta
Added instructions for translators |
1149 |
// [Additional settings] button.
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1150 |
// Translators: This is a label on the [Additional settings] button.
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1151 |
g_win.settings_button = gtk_button_new_with_label(_("Additional settings")); |
1152 |
||
1153 |
// Settings> box is expanded?
|
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1154 |
conf_get_boolean_value("settings-expanded", &bool_value); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1155 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1156 |
if (bool_value) |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1157 |
gtk_widget_show(g_win.settings_button); |
1158 |
else
|
|
1159 |
gtk_widget_hide(g_win.settings_button); |
|
1160 |
||
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1161 |
g_signal_connect(g_win.settings_button, "clicked", G_CALLBACK(win_settings_cb), NULL); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1162 |
gtk_box_pack_end(GTK_BOX(hbox4), g_win.settings_button, FALSE, TRUE, 0); |
1163 |
||
1164 |
// This button is for testing and debugging
|
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1165 |
button0 = gtk_button_new_with_label("Test button"); |
1166 |
// ATM hide it
|
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1167 |
gtk_widget_hide(button0); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1168 |
gtk_box_pack_end(GTK_BOX(hbox4), button0, FALSE, FALSE, 0); |
1169 |
g_signal_connect(button0, "clicked", G_CALLBACK(test_0_cb), NULL); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1170 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1171 |
#ifdef APP_HAS_MENU
|
1172 |
// Show/hide main menu?
|
|
1173 |
gboolean bool_val = FALSE; |
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1174 |
conf_get_boolean_value("show-main-menu", &bool_val); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1175 |
win_set_main_menu(bool_val); |
1176 |
#endif
|
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1177 |
|
1178 |
// Hide the [Save] widget (if it's visible)
|
|
1179 |
gtk_widget_hide(g_win.timer_save_button); |
|
1180 |
||
1181 |
// Hide the error_box widget (if it's visible)
|
|
1182 |
gtk_widget_hide(g_win.error_box); |
|
1183 |
||
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1184 |
// Set/reset button images and labels
|
1185 |
win_update_gui(); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1186 |
}
|
1187 |
||
1188 |
int main(int argc, char *argv[]) { |
|
1189 |
g_type_init(); |
|
1190 |
||
1191 |
// Parse command line arguments
|
|
1192 |
GError *error = NULL; |
|
1193 |
GOptionContext *context = g_option_context_new("Command line aguments."); |
|
1194 |
g_option_context_set_help_enabled(context, TRUE); |
|
1195 |
g_option_context_add_main_entries(context, option_entries, GETTEXT_PACKAGE); |
|
1196 |
||
1197 |
GOptionGroup *opt_group = gtk_get_option_group(TRUE); |
|
1198 |
g_option_context_add_group(context, opt_group); |
|
1199 |
g_option_context_parse(context, &argc, &argv, &error); |
|
1200 |
||
1201 |
if (error) { |
|
1202 |
LOG_ERROR("Invalid command line argument. %s\n", error->message); |
|
1203 |
g_error_free(error); |
|
1204 |
}
|
|
1205 |
||
1206 |
g_option_context_free(context); |
|
1207 |
context = NULL; |
|
1208 |
||
62
by Osmo Antero
The recorder now obeys commands from Banshee Player. |
1209 |
LOG_DEBUG("Value of --version (-v)=%d\n", g_version_info); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1210 |
LOG_DEBUG("Value of --show-icon (-i)=%d\n", g_show_tray_icon); |
1211 |
LOG_DEBUG("Value of --show-window (-w)=%d\n", g_show_window); |
|
1212 |
LOG_DEBUG("Value of --debug-signal (-d)=%d\n", g_debug_levels); |
|
56
by Osmo Antero
Version 0.5 |
1213 |
LOG_DEBUG("Value of --command (-c)=%s\n", g_command_arg); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1214 |
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1215 |
if (g_version_info != -1) { |
1216 |
// Print program name and version info
|
|
1217 |
// Eg. "Audio Recorder 1.0"
|
|
1218 |
gchar *name = about_program_name(); |
|
1219 |
g_print("%s\n", name); |
|
1220 |
g_free(name); |
|
1221 |
// Exit
|
|
1222 |
exit(0); |
|
1223 |
}
|
|
62
by Osmo Antero
The recorder now obeys commands from Banshee Player. |
1224 |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1225 |
// Initialize the i18n stuff
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1226 |
bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); |
1227 |
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); |
|
1228 |
textdomain(GETTEXT_PACKAGE); |
|
56
by Osmo Antero
Version 0.5 |
1229 |
|
77
by Osmo Antero
Updated version (v0.7) for Fedora 16+ and Ubuntu 12.04. |
1230 |
setlocale(LC_ALL, ""); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1231 |
|
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1232 |
// Initialize all modules
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1233 |
gtk_init(&argc, &argv); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1234 |
gdk_init(&argc, &argv); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1235 |
|
1236 |
g_thread_init(NULL); |
|
1237 |
gdk_threads_init(); |
|
1238 |
||
1239 |
gst_init(&argc, &argv); |
|
1240 |
||
56
by Osmo Antero
Version 0.5 |
1241 |
// Check if user wants to control the recorder (the running instance of the recorder) from the command line.
|
1242 |
if (g_command_arg != NULL) { |
|
1243 |
||
1244 |
// $ audio-recorder --command <argument>
|
|
1245 |
||
1246 |
// Check if we find existing instance of Audio-Recorder. Do not start this program twice.
|
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1247 |
// Get state returns: "not running" | "on" | "off" | "paused"
|
62
by Osmo Antero
The recorder now obeys commands from Banshee Player. |
1248 |
gchar *state = dbus_service_client_request("get_state", NULL); |
56
by Osmo Antero
Version 0.5 |
1249 |
|
62
by Osmo Antero
The recorder now obeys commands from Banshee Player. |
1250 |
// Got a valid answer ("on", "off" or "paused") from existing instance?
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1251 |
// Or got "not running" or NULL?
|
62
by Osmo Antero
The recorder now obeys commands from Banshee Player. |
1252 |
if (state && (!g_strrstr(state, "not"))) { |
56
by Osmo Antero
Version 0.5 |
1253 |
// Send client request (execute methode call over DBus)
|
1254 |
send_client_request(g_command_arg); |
|
1255 |
||
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1256 |
g_free(state); |
1257 |
state = NULL; |
|
56
by Osmo Antero
Version 0.5 |
1258 |
|
1259 |
// And kill this duplicate instance of audio-recorder
|
|
1260 |
exit(0); |
|
1261 |
}
|
|
1262 |
||
62
by Osmo Antero
The recorder now obeys commands from Banshee Player. |
1263 |
g_free(state); |
56
by Osmo Antero
Version 0.5 |
1264 |
|
1265 |
// Let this instance run
|
|
1266 |
// ...
|
|
1267 |
}
|
|
1268 |
||
1269 |
// Simply print recording status (not running | on | off | paused) and exit?
|
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1270 |
if (!g_strcmp0(g_command_arg, "status")) { |
56
by Osmo Antero
Version 0.5 |
1271 |
send_client_request(g_command_arg); |
62
by Osmo Antero
The recorder now obeys commands from Banshee Player. |
1272 |
// This will call exit()
|
56
by Osmo Antero
Version 0.5 |
1273 |
}
|
1274 |
||
1275 |
// Simply quit?
|
|
1276 |
else if (!g_strcmp0(g_command_arg, "quit")) { |
|
1277 |
send_client_request(g_command_arg); |
|
62
by Osmo Antero
The recorder now obeys commands from Banshee Player. |
1278 |
// This will call exit()
|
56
by Osmo Antero
Version 0.5 |
1279 |
}
|
1280 |
||
1281 |
// Initialize modules
|
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1282 |
media_profiles_init(); |
1283 |
||
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1284 |
rec_manager_init(); |
1285 |
||
1286 |
audio_sources_init(); |
|
1287 |
||
1288 |
timer_module_init(); |
|
1289 |
||
56
by Osmo Antero
Version 0.5 |
1290 |
// Setup DBus server for this program
|
1291 |
dbus_service_module_init(); |
|
1292 |
||
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1293 |
systray_module_init(); |
1294 |
||
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1295 |
// Show button images (normally not shown in the GNOME)
|
1296 |
// See also gconf-editor, setting '/desktop/gnome/interface'
|
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1297 |
GtkSettings *settings = gtk_settings_get_default(); |
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1298 |
g_object_set(settings, "gtk-button-images", TRUE, NULL); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1299 |
|
56
by Osmo Antero
Version 0.5 |
1300 |
// Create main window and all its widgets
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1301 |
win_create_window(); |
1302 |
||
1303 |
// Determine how to display the window and tray icon
|
|
1304 |
gboolean show_icon = FALSE; |
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1305 |
conf_get_boolean_value("show-systray-icon", &show_icon); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1306 |
|
1307 |
gboolean show_window = TRUE; |
|
1308 |
||
1309 |
if (!g_show_tray_icon) { |
|
1310 |
// Override the setting
|
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1311 |
conf_save_boolean_value("show-systray-icon", FALSE); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1312 |
|
1313 |
// Cannot hide both window and the tray icon
|
|
1314 |
g_show_window = 1/*TRUE*/; |
|
1315 |
||
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1316 |
// g_show_tray_icon != -1: if --show-icon or -i option was seen
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1317 |
} else if (g_show_tray_icon && g_show_tray_icon !=-1) { |
1318 |
||
1319 |
// Override the setting
|
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1320 |
conf_save_boolean_value("show-systray-icon", TRUE); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1321 |
}
|
1322 |
||
1323 |
// Show/hide tray icon
|
|
1324 |
systray_icon_setup(); |
|
1325 |
||
1326 |
// Running this application first time?
|
|
1327 |
gboolean first_time = FALSE; |
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1328 |
conf_get_boolean_value("started-first-time", &first_time); |
1329 |
if (first_time) { |
|
1330 |
conf_save_boolean_value("started-first-time", FALSE); |
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1331 |
|
1332 |
// Force: show window
|
|
1333 |
g_show_window = TRUE; |
|
1334 |
||
1335 |
// Auto-start this application on login
|
|
15
by Osmo Antero Maatta
Betterments after first test on Ubuntu 11.04 (Natty) |
1336 |
autostart_set(TRUE); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1337 |
}
|
1338 |
||
1339 |
if (!g_show_window) { |
|
1340 |
show_window = FALSE; |
|
1341 |
||
22
by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions. |
1342 |
// g_show_window != -1: if --show-window or -w option was seen
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1343 |
} else if (g_show_window && g_show_window != -1) { |
1344 |
show_window = TRUE; |
|
1345 |
}
|
|
1346 |
||
56
by Osmo Antero
Version 0.5 |
1347 |
// Let "--command show" and "--command hide" override the window visibility
|
62
by Osmo Antero
The recorder now obeys commands from Banshee Player. |
1348 |
if (g_strrstr0(g_command_arg, "show")) { |
56
by Osmo Antero
Version 0.5 |
1349 |
show_window = TRUE; |
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1350 |
} else if (g_strrstr0(g_command_arg, "hide")) { |
56
by Osmo Antero
Version 0.5 |
1351 |
show_window = FALSE; |
1352 |
}
|
|
1353 |
||
1354 |
||
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1355 |
if (show_window) { |
1356 |
// Show
|
|
1357 |
win_show_window(TRUE); |
|
1358 |
} else { |
|
1359 |
// Hide
|
|
1360 |
win_show_window(FALSE); |
|
1361 |
}
|
|
1362 |
||
1363 |
// Debugging:
|
|
7
by Osmo Antero Maatta
Improved timer commands |
1364 |
// Show values from the gst-listener.c process. This will print out audio level values.
|
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1365 |
// User must start this application from a terminal window to see these values.
|
1366 |
if (g_debug_levels == 1) { |
|
51
by Osmo Antero Maatta
Formatted code with astyle (instructions about astyle in README) |
1367 |
// Set flag via timer.c
|
49
by Osmo Antero Maatta
Employ listener (in gst-listener.c) ONLY when needed. Also listener process was created 2 times (was unstoppable) |
1368 |
timer_set_debug_flag(TRUE); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1369 |
}
|
1370 |
||
1371 |
// g_win.audio_device must be set here at very end.
|
|
1372 |
// Otherwise Media Players and Skype may show up before this app's main window. Skype may even block.
|
|
1373 |
win_set_device_id(); |
|
1374 |
||
56
by Osmo Antero
Version 0.5 |
1375 |
// Send client request (execute method call over DBus).
|
1376 |
// We must call this from a thread. Otherwise DBus server (in dbus-service.c) and
|
|
1377 |
// client request (also in dbus-service.c) will conflict & block.
|
|
1378 |
g_thread_create(send_client_request, (gpointer)g_command_arg, FALSE, NULL); |
|
1379 |
||
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1380 |
// Main loop
|
56
by Osmo Antero
Version 0.5 |
1381 |
gdk_threads_enter(); |
1
by Osmo Antero Maatta
Initial import 17.jan.2011 |
1382 |
gtk_main (); |
1383 |
gdk_threads_leave(); |
|
1384 |
||
1385 |
return 0; |
|
1386 |
}
|
|
1387 |
||
56
by Osmo Antero
Version 0.5 |
1388 |
static void *send_client_request(gpointer data) { |
1389 |
// Send command via DBus to the existing instance of audio-recorder
|
|
1390 |
||
1391 |
// $ audio-recorder --command start
|
|
1392 |
// $ audio-recorder --command stop
|
|
1393 |
// $ audio-recorder --command pause
|
|
1394 |
||
1395 |
// $ audio-recorder --command status // Print status; "not running" | "on" | "off" | "paused"
|
|
1396 |
||
1397 |
// $ audio-recorder --command show
|
|
1398 |
// $ audio-recorder --command quit
|
|
1399 |
||
1400 |
// You can also combine
|
|
1401 |
// $ audio-recorder --command start+show
|
|
1402 |
// $ audio-recorder --command stop+hide
|
|
1403 |
// $ audio-recorder --command stop+quit
|
|
1404 |
||
62
by Osmo Antero
The recorder now obeys commands from Banshee Player. |
1405 |
if (!data) return 0; |
1406 |
||
56
by Osmo Antero
Version 0.5 |
1407 |
// To lower case
|
1408 |
gchar *command = g_ascii_strdown((gchar*)data, -1); |
|
1409 |
||
1410 |
gboolean done = FALSE; |
|
1411 |
gchar *ret = NULL; |
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1412 |
gint exit_val = 0; |
62
by Osmo Antero
The recorder now obeys commands from Banshee Player. |
1413 |
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1414 |
if (!g_strcmp0(command, "status")) { |
56
by Osmo Antero
Version 0.5 |
1415 |
|
1416 |
// Call get_state()
|
|
1417 |
ret = dbus_service_client_request("get_state", NULL/*no args*/); |
|
1418 |
if (!ret) { |
|
1419 |
// Audio-recorder is not running
|
|
1420 |
ret = g_strdup("not running"); |
|
69
by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2 |
1421 |
exit_val = -1; |
56
by Osmo Antero
Version 0.5 |
1422 |
}
|
1423 |
g_print("%s\n", ret); |
|
1424 |
g_free(ret); |
|
1425 |
// Exit
|
|
62
by Osmo Antero
The recorder now obeys commands from Banshee Player. |
1426 |
exit(exit_val); |
56
by Osmo Antero
Version 0.5 |
1427 |
}
|
1428 |
||
1429 |
// -------------------------------------------------
|
|
1430 |
||
1431 |
if (g_strrstr(command, "start")) { |
|
1432 |
||
1433 |
// Call set_state("start")
|
|
1434 |
ret = dbus_service_client_request("set_state", "start"); |
|
1435 |
if (g_strcmp0(ret, "OK")) { |
|
1436 |
LOG_ERROR("Cannot execute client/dbus request %s.\n", "set_state(\"start\")"); |
|
1437 |
}
|
|
1438 |
g_free(ret); |
|
1439 |
done = TRUE; |
|
1440 |
}
|
|
1441 |
||
1442 |
if (g_strrstr(command, "stop")) { |
|
1443 |
||
1444 |
// Call set_state("stop")
|
|
1445 |
ret = dbus_service_client_request("set_state", "stop"); |
|
1446 |
if (g_strcmp0(ret, "OK")) { |
|
1447 |
LOG_ERROR("Cannot execute client/dbus request %s.\n", "set_state(\"stop\")"); |
|
1448 |
}
|
|
1449 |
g_free(ret); |
|
1450 |
done = TRUE; |
|
1451 |
}
|
|
1452 |
||
1453 |
if (g_strrstr(command, "pause")) { |
|
1454 |
||
1455 |
// Call set_state("pause")
|
|
1456 |
ret = dbus_service_client_request("set_state", "pause"); |
|
1457 |
if (g_strcmp0(ret, "OK")) { |
|
1458 |
LOG_ERROR("Cannot execute client/dbus request %s.\n", "set_state(\"pause\")"); |
|
1459 |
}
|
|
1460 |
g_free(ret); |
|
1461 |
done = TRUE; |
|
1462 |
}
|
|
1463 |
||
1464 |
if (g_strrstr(command, "show")) { |
|
1465 |
||
1466 |
// Call set_state("show")
|
|
1467 |
ret = dbus_service_client_request("set_state", "show"); |
|
1468 |
if (g_strcmp0(ret, "OK")) { |
|
1469 |
LOG_ERROR("Cannot execute client/dbus request %s.\n", "set_state(\"show\")"); |
|
1470 |
}
|
|
1471 |
g_free(ret); |
|
1472 |
done = TRUE; |
|
1473 |
}
|
|
1474 |
||
1475 |
if (g_strrstr(command, "hide")) { |
|
1476 |
||
1477 |
// Call set_state("hide")
|
|
1478 |
ret = dbus_service_client_request("set_state", "hide"); |
|
1479 |
if (g_strcmp0(ret, "OK")) { |
|
1480 |
LOG_ERROR("Cannot execute client/dbus request %s.\n", "set_state(\"hide\")"); |
|
1481 |
}
|
|
1482 |
g_free(ret); |
|
1483 |
done = TRUE; |
|
1484 |
}
|
|
1485 |
||
1486 |
if (g_strrstr(command, "status")) { |
|
1487 |
||
1488 |
// Call get_state()
|
|
1489 |
ret = dbus_service_client_request("get_state", NULL /*no args*/); |
|
1490 |
if (!ret) { |
|
1491 |
// Audio-recorder is not running
|
|
1492 |
ret = g_strdup("not running"); |
|
1493 |
}
|
|
1494 |
// Print state; not running|on|off|paused
|
|
1495 |
g_print("%s\n", ret); |
|
1496 |
g_free(ret); |
|
1497 |
done = TRUE; |
|
1498 |
}
|
|
1499 |
||
63
by Osmo Antero
A minor fix for audio-recorder --command=stop+quit command. |
1500 |
if (g_strrstr(command, "quit")) { |
1501 |
||
1502 |
// Call set_state("quit"). Terminate running instance of this application.
|
|
1503 |
ret = dbus_service_client_request("set_state", "quit"); |
|
1504 |
g_free(ret); |
|
1505 |
// Exit also this instance
|
|
1506 |
exit(0); |
|
1507 |
}
|
|
1508 |
||
1509 |
||
56
by Osmo Antero
Version 0.5 |
1510 |
if (!done) { |
1511 |
LOG_ERROR("Invalid argument in --command=%s. See --help for more information.\n", command); |
|
1512 |
}
|
|
1513 |
||
1514 |
g_free(command); |
|
1515 |
||
1516 |
// FALSE: Remove idle function
|
|
1517 |
return 0; |
|
1518 |
}
|
|
1519 |
||
1520 |