/* * Copyright (c) Linux community. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ #include "win-settings.h" #include "audio-sources.h" #include "support.h" #include "utility.h" #include "timer.h" #include "gconf.h" #include "rec-window.h" #include "auto-start.h" #include "help.h" #include "dbus-skype.h" // Show [Additonal settings] dialog. static void win_settings_get_folder_name(GtkWidget *widget, gpointer data) { GtkWidget *entry = (GtkWidget*)data; GtkWidget *dialog; // Translators: This is a title in a directory chooser dialog. dialog = gtk_file_chooser_dialog_new(_("Select Directory"), NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); gchar *path = g_strdup((gchar*)gtk_entry_get_text(GTK_ENTRY(entry))); if (str_length(path, 2048) < 1) { g_free(path); path = get_home_dir(); } gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path); guint response = gtk_dialog_run(GTK_DIALOG(dialog)); g_free(path); path = NULL; switch (response) { case GTK_RESPONSE_ACCEPT: { path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (dialog)); } } gtk_widget_destroy(dialog); if (path) { gtk_entry_set_text(GTK_ENTRY(entry), path); g_free(path); } } #ifdef APP_HAS_MENU void show_menu_checkbox_cb(GtkWidget *menu, gpointer data) { gboolean active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(menu)); win_set_main_menu(active); } #endif void win_settings_show_filename_help() { // Show help file help_show_page("filename-format.html"); } void show_icon_checkbox_cb(GtkWidget *menu, gpointer data) { gboolean active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(menu)); // Save in gconf conf_save_boolean_value("show_systray_icon", active); // Recreate or remove systray icon systray_icon_setup(); } gboolean device_filter(DeviceItem *item) { if (!item) return FALSE; // Accept if the device is: DEFAULT_DEVICE or // it is an AUDIO_SOURCE that is related to a real audio sink/audio card. if (item->type == DEFAULT_DEVICE || (item->type == AUDIO_SOURCE && item->sink_index >= 0)) { return TRUE; } return FALSE; } void win_settings_show_dialog(GtkWindow *parent) { // Translators: This is a title in the additional settings dialog GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Additional settings"), parent, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_window_set_transient_for(GTK_WINDOW(dialog), parent); gtk_dialog_set_has_separator(GTK_DIALOG(dialog), TRUE); gtk_window_set_default_size(GTK_WINDOW(dialog), 420, -1); gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); // --------------------------------------- GtkWidget *content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); // A notebook GtkWidget *notebook = gtk_notebook_new(); gtk_container_add(GTK_CONTAINER(content_area), notebook); // ----------------------------------- // Tab page 0, General // ----------------------------------- GtkWidget *vbox0 = gtk_vbox_new(FALSE, 3); // Translators: This is a [Tab-page] in the [Additional settings] dialog. GtkWidget *page_label = gtk_label_new(_("General")); GtkWidget *table0 = gtk_table_new(9, 3, FALSE); gtk_box_pack_start(GTK_BOX(vbox0), table0, FALSE, FALSE, 0); gtk_table_set_row_spacings(GTK_TABLE(table0), 3); // "Folder name:" label // Translators: This is a GUI label. Keep it short. GtkWidget *label0 = gtk_label_new(_("Folder name:")); gtk_table_attach(GTK_TABLE(table0), label0, 0, 1, 3, 4, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment(GTK_MISC(label0), 0, 0.5); GtkWidget *folder_name_field = gtk_entry_new(); gtk_table_attach(GTK_TABLE(table0), folder_name_field, 1, 2, 3, 4, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_entry_set_invisible_char(GTK_ENTRY(folder_name_field), 9679); GtkWidget *button0 = gtk_button_new_with_mnemonic("..."); gtk_table_attach(GTK_TABLE(table0), button0, 2, 3, 3, 4, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); g_signal_connect(button0, "clicked", G_CALLBACK(win_settings_get_folder_name), folder_name_field); // Get and show current folder name (/home/username/Audio) gchar *folder_name = get_audio_folder(); gtk_entry_set_text(GTK_ENTRY(folder_name_field), folder_name); g_free(folder_name); // "Filename format:" label // Translators: This is a GUI label. Keep it short. label0 = gtk_label_new(_("Filename format:")); gtk_table_attach(GTK_TABLE(table0), label0, 0, 1, 4, 5, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment(GTK_MISC(label0), 0, 0.5); GtkWidget *file_name_pattern = gtk_entry_new(); gtk_table_attach(GTK_TABLE(table0), file_name_pattern, 1, 2, 4, 5, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_entry_set_invisible_char(GTK_ENTRY(file_name_pattern), 9679); button0 = gtk_button_new(); GtkWidget *image = gtk_image_new_from_stock("gtk-info", GTK_ICON_SIZE_BUTTON); gtk_button_set_image(GTK_BUTTON(button0), image); g_signal_connect(button0, "clicked", G_CALLBACK(win_settings_show_filename_help), NULL); gtk_table_attach (GTK_TABLE (table0), button0, 2, 3, 4, 5, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); // Get filename pattern gchar *str_value = get_filename_pattern(FALSE/*do not cut*/); gtk_entry_set_text(GTK_ENTRY(file_name_pattern), str_value); g_free(str_value); gboolean bool_val = FALSE; #ifdef APP_HAS_MENU // Setting for "show menu" // Translators: This is a checkbox (label). GtkWidget *show_menu_checkbox = gtk_check_button_new_with_label(_("Show main menu.")); g_signal_connect(show_menu_checkbox, "toggled", G_CALLBACK(show_menu_checkbox_cb), NULL); conf_get_boolean_value("show_main_menu", &bool_val); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(show_menu_checkbox), bool_val); gtk_table_attach(GTK_TABLE(table0), show_menu_checkbox, 1, 2, 5, 6, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); #endif // Setting for "Show systray icon" // Translators: This is a checkbox (label). GtkWidget *show_icon_checkbox = gtk_check_button_new_with_label(_("Show an icon on the system tray.")); conf_get_boolean_value("show_systray_icon", &bool_val); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(show_icon_checkbox), bool_val); g_signal_connect(show_icon_checkbox, "toggled", G_CALLBACK(show_icon_checkbox_cb), NULL); gtk_table_attach(GTK_TABLE(table0), show_icon_checkbox, 1, 2, 6, 7, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); // Setting for "Auto-start application at login" // Translators: This is a checkbox (label). GtkWidget *autostart_checkbox = gtk_check_button_new_with_label(_("Auto-start this application at login.")); // Get auto-start value gboolean saved_autostart_val = autostart_get(); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(autostart_checkbox), saved_autostart_val); gtk_table_attach(GTK_TABLE(table0), autostart_checkbox, 1, 2, 7, 8, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); // Add new tab page gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox0, page_label); // ----------------------------------- // Tab page 1, Players // ----------------------------------- GtkWidget *vbox1 = gtk_vbox_new(FALSE, 3); // Media Player, Skype etc on the DBus. // Translators: This is a [Tab-page] in the [Additional settings] dialog. page_label = gtk_label_new(_("Players")); GtkWidget *table1 = gtk_table_new(5, 3, FALSE); gtk_box_pack_start(GTK_BOX(vbox1), table1, FALSE, FALSE, 0); gtk_table_set_row_spacings(GTK_TABLE(table1), 3); // Get all (Audio output) devices. These are normally audio cards with loudspeakers. Add also DEFAULT_DEVICE. GList *dev_list = audio_sources_get_with_filter(device_filter); // Translators: This is a GUI label (bad one ;-) label0 = gtk_label_new(_("Set audio device for Media Players and Skype.\nSet to blank if you are in doubt.")); gtk_table_attach(GTK_TABLE(table1), label0, 1, 5, 0, 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment(GTK_MISC(label0), 0, 0.5); // Label for device combo. // Translators: This is a GUI label. label0 = gtk_label_new(_("Device name:")); gtk_table_attach(GTK_TABLE(table1), label0, 0, 1, 1, 2, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment(GTK_MISC(label0), 0, 0.5); GtkWidget *device_combo = gtk_combo_box_new_text(); gtk_table_attach(GTK_TABLE(table1), device_combo, 1, 2, 1, 2, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); // Get current selection from GConf str_value = NULL; conf_get_string_value("device_for_media_players", &str_value); // Save this (old) value gchar *saved_device_id = g_strdup(str_value); // Add blank line to the combo (index 0) gtk_combo_box_append_text(GTK_COMBO_BOX(device_combo), ""); gint found_index = 0; // Add devices to the combo GList *n = g_list_first(dev_list); gint i = 1; while (n) { DeviceItem *item = (DeviceItem*)n->data; gtk_combo_box_append_text(GTK_COMBO_BOX(device_combo), item->description); if (!g_strcmp0(str_value, item->id)) { found_index = i; } // Next item n = g_list_next(n); i++; } // Set current selection gtk_combo_box_set_active(GTK_COMBO_BOX(device_combo), found_index); g_free(str_value); // TODO: // This is a fix. // A hard-coded setting for the Skype. // We should create a properties class for device items, so they can expose this type of settings without hardcoding. DeviceItem *item = audio_sources_find_id("com.Skype.API"); GtkWidget *skype_checkbox = NULL; if (item) { // Separartor GtkWidget *hseparator0 = gtk_hseparator_new(); gtk_table_attach(GTK_TABLE(table1), hseparator0, 1, 2, 2, 3, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (GTK_FILL), 0, 0); hseparator0 = gtk_hseparator_new(); gtk_table_attach(GTK_TABLE(table1), hseparator0, 2, 3, 2, 3, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (GTK_FILL), 0, 0); // Translators: This is a checkbox (label). skype_checkbox = gtk_check_button_new_with_label(_("Record ringing sound for Skype.")); gboolean bool_val = FALSE; conf_get_boolean_value("skype/record_ringing_sound", &bool_val); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(skype_checkbox), bool_val); gtk_table_attach(GTK_TABLE(table1), skype_checkbox, 1, 2, 3, 4, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); } // Add new tab page gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox1, page_label); // Show dialog gtk_widget_show_all(dialog); gint res = gtk_dialog_run(GTK_DIALOG(dialog)); switch (res) { case GTK_RESPONSE_ACCEPT: case GTK_RESPONSE_OK: // Save folder name str_value = (gchar*)gtk_entry_get_text(GTK_ENTRY(folder_name_field)); conf_save_string_value("folder_name", str_value); // Do not g_free() str_value // Ref: http://library.gnome.org/devel/gtk/unstable/GtkEntry.html#gtk-entry-get-text // Save filename pattern str_value = (gchar*)gtk_entry_get_text(GTK_ENTRY(file_name_pattern)); conf_save_string_value("filename_pattern", str_value); // Do not g_free() str_value gboolean bool_val = FALSE; #ifdef APP_HAS_MENU // Save setting for "show main menu" bool_val = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(show_menu_checkbox)); conf_save_boolean_value("show_main_menu", bool_val); #endif // Auto start at login? bool_val = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(autostart_checkbox)); // Changed? if (saved_autostart_val != bool_val) { // Save auto-start value autostart_set(bool_val); } // Device for external Media Players, Skype, etc. str_value = NULL; gint index = gtk_combo_box_get_active(GTK_COMBO_BOX(device_combo)); index = index - 1; // Get the dev item DeviceItem *item = g_list_nth_data(dev_list, index); gchar *p = NULL; if (item) { p = item->id; } else { p = ""; } // Save in GConf conf_save_string_value("device_for_media_players", p); // Value changed? if (g_strcmp0(saved_device_id, p)) { // Let timer know that the settings have been altered, so it can re-start the listener etc. timer_settings_changed(); } // Record ringing sound for Skype? if (GTK_IS_TOGGLE_BUTTON(skype_checkbox)) { bool_val = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(skype_checkbox)); skype_set_record_ringing_sound(bool_val); } break; default: break; } g_free(saved_device_id); // Free the dev_list and its data audio_sources_free_list(dev_list); dev_list = NULL; // Destroy this dialog gtk_widget_destroy(dialog); }