hythmbox-2.98/plugins/visualizer/rb-visualizer-menu.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found rb-visualizer-menu.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
  1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  2  *
  3  *  Copyright (C) 2010  Jonathan Matthew <jonathan@d14n.org>
  4  *
  5  *  This program is free software; you can redistribute it and/or modify
  6  *  it under the terms of the GNU General Public License as published by
  7  *  the Free Software Foundation; either version 2 of the License, or
  8  *  (at your option) any later version.
  9  *
 10  *  The Rhythmbox authors hereby grant permission for non-GPL compatible
 11  *  GStreamer plugins to be used and distributed together with GStreamer
 12  *  and Rhythmbox. This permission is above and beyond the permissions granted
 13  *  by the GPL license by which Rhythmbox is covered. If you modify this code
 14  *  you may extend this exception to your version of the code, but you are not
 15  *  obligated to do so. If you do not wish to do so, delete this exception
 16  *  statement from your version.
 17  *
 18  *  This program is distributed in the hope that it will be useful,
 19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 21  *  GNU General Public License for more details.
 22  *
 23  *  You should have received a copy of the GNU General Public License
 24  *  along with this program; if not, write to the Free Software
 25  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 26  */
 27 
 28 #include "config.h"
 29 
 30 #include <gtk/gtk.h>
 31 #include <glib/gi18n.h>
 32 #include <gio/gio.h>
 33 #include <gst/gst.h>
 34 
 35 #include "rb-visualizer-menu.h"
 36 #include <lib/rb-debug.h>
 37 
 38 const VisualizerQuality rb_visualizer_quality[] = {
 39 	{ N_("Low quality"),	"low",	320,	240,	20, 	1 },
 40 	{ N_("Normal quality"),	"medium", 640,	480,	25,	1 },
 41 	{ N_("High quality"),	"high",	800,	600,	30,	1 }
 42 };
 43 
 44 static void
 45 set_check_item_foreach (GtkWidget *widget, GtkCheckMenuItem *item)
 46 {
 47 	GtkCheckMenuItem *check = GTK_CHECK_MENU_ITEM (widget);
 48 	gtk_check_menu_item_set_active (check, check == item);
 49 }
 50 
 51 static void
 52 quality_item_toggled_cb (GtkMenuItem *item, gpointer data)
 53 {
 54 	int index = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "quality"));
 55 	GSettings *settings = g_object_get_data (G_OBJECT (item), "settings");
 56 
 57 	if (gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (item)) == FALSE) {
 58 		return;
 59 	}
 60 
 61 	rb_debug ("vis quality %d (%s) activated", index, rb_visualizer_quality[index].setting);
 62 	g_settings_set_string (settings, "quality", rb_visualizer_quality[index].setting);
 63 
 64 	g_signal_handlers_block_by_func (item, quality_item_toggled_cb, data);
 65 	gtk_container_foreach (GTK_CONTAINER (data),
 66 			       (GtkCallback) set_check_item_foreach,
 67 			       GTK_CHECK_MENU_ITEM (item));
 68 	g_signal_handlers_unblock_by_func (item, quality_item_toggled_cb, data);
 69 }
 70 
 71 static void
 72 vis_plugin_item_activate_cb (GtkMenuItem *item, gpointer data)
 73 {
 74 	const char *name = g_object_get_data (G_OBJECT (item), "element-name");
 75 	GSettings *settings = g_object_get_data (G_OBJECT (item), "settings");
 76 
 77 	if (gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (item)) == FALSE) {
 78 		return;
 79 	}
 80 
 81 	rb_debug ("vis element %s activated", name);
 82 	g_settings_set_string (settings, "vis-plugin", name);
 83 
 84 	g_signal_handlers_block_by_func (item, vis_plugin_item_activate_cb, data);
 85 	gtk_container_foreach (GTK_CONTAINER (data),
 86 			       (GtkCallback) set_check_item_foreach,
 87 			       GTK_CHECK_MENU_ITEM (item));
 88 	g_signal_handlers_unblock_by_func (item, vis_plugin_item_activate_cb, data);
 89 }
 90 
 91 static gboolean
 92 vis_plugin_filter (GstPluginFeature *feature, gpointer data)
 93 {
 94 	GstElementFactory *f;
 95 
 96 	if  (!GST_IS_ELEMENT_FACTORY (feature))
 97 		return FALSE;
 98 	f = GST_ELEMENT_FACTORY (feature);
 99 
100 	return (g_strrstr (gst_element_factory_get_klass (f), "Visualization") != NULL);
101 }
102 
103 GtkWidget *
104 rb_visualizer_create_popup_menu (GtkToggleAction *fullscreen_action)
105 {
106 	GSettings *settings;
107 	GtkWidget *menu;
108 	GtkWidget *submenu;
109 	GtkWidget *item;
110 	GList *features;
111 	GList *t;
112 	char *active_element;
113 	int quality;
114 	int i;
115 
116 	menu = gtk_menu_new ();
117 
118 	settings = g_settings_new ("org.gnome.rhythmbox.plugins.visualizer");
119 
120 	/* fullscreen item */
121 	item = gtk_action_create_menu_item (GTK_ACTION (fullscreen_action));
122 	gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
123 
124 	/* quality submenu */
125 	quality = g_settings_get_enum (settings, "quality");
126 	submenu = gtk_menu_new ();
127 	for (i = 0; i < G_N_ELEMENTS (rb_visualizer_quality); i++) {
128 		item = gtk_check_menu_item_new_with_label (_(rb_visualizer_quality[i].name));
129 
130 		gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), (i == quality));
131 
132 		g_object_set_data (G_OBJECT (item), "quality", GINT_TO_POINTER (i));
133 		g_object_set_data (G_OBJECT (item), "settings", settings);
134 		g_signal_connect (item, "toggled", G_CALLBACK (quality_item_toggled_cb), submenu);
135 		gtk_menu_shell_append (GTK_MENU_SHELL (submenu), item);
136 	}
137 
138 	item = gtk_menu_item_new_with_mnemonic (_("_Quality"));
139 	gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
140 	gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
141 
142 	/* effect submenu */
143 	submenu = gtk_menu_new ();
144 
145 	rb_debug ("building vis plugin list");
146 	active_element = g_settings_get_string (settings, "vis-plugin");
147 	features = gst_registry_feature_filter (gst_registry_get_default (),
148 						vis_plugin_filter,
149 						FALSE, NULL);
150 	for (t = features; t != NULL; t = t->next) {
151 		GstPluginFeature *f;
152 		const char *name;
153 		const char *element_name;
154 
155 		f = GST_PLUGIN_FEATURE (t->data);
156 		name = gst_element_factory_get_longname (GST_ELEMENT_FACTORY (f));
157 		element_name = gst_plugin_feature_get_name (f);
158 		rb_debug ("adding visualizer element %s (%s)", element_name, name);
159 
160 		item = gtk_check_menu_item_new_with_label (name);
161 		gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
162 						g_strcmp0 (element_name, active_element) == 0);
163 		g_object_set_data (G_OBJECT (item), "element-name", g_strdup (element_name));
164 		g_object_set_data (G_OBJECT (item), "settings", settings);
165 		gtk_menu_shell_append (GTK_MENU_SHELL (submenu), item);
166 		g_signal_connect (item,
167 				  "activate",
168 				  G_CALLBACK (vis_plugin_item_activate_cb),
169 				  submenu);
170 	}
171 	gst_plugin_feature_list_free (features);
172 
173 	item = gtk_menu_item_new_with_mnemonic (_("_Visual Effect"));
174 	gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
175 	gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
176 
177 	gtk_widget_show_all (menu);
178 	return menu;
179 }
180 
181 int
182 rb_visualizer_menu_clip_quality (int value)
183 {
184 	if (value < 0) {
185 		return 0;
186 	} else if (value >= G_N_ELEMENTS (rb_visualizer_quality)) {
187 		return G_N_ELEMENTS (rb_visualizer_quality) - 1;
188 	} else {
189 		return value;
190 	}
191 }