File: info_window.cpp

package info (click to toggle)
alsaplayer 0.99.82-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,892 kB
  • sloc: ansic: 40,741; cpp: 14,400; makefile: 983; sh: 796; lex: 751; asm: 45; python: 29; sed: 16
file content (215 lines) | stat: -rw-r--r-- 6,825 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*  info_window.cpp
 *  Copyright (C) 2007 Madej
 *
 *  This file is part of AlsaPlayer.
 *
 *  AlsaPlayer is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  AlsaPlayer 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, see <http://www.gnu.org/licenses/>.
 *
*/

#include "info_window.h"
#include "prefs.h"

#ifdef ENABLE_NLS
#include <libintl.h>
#define _(String) gettext(String)
#define N_(String) noop_gettext(String)
#else
#define _(String) (String)
#define N_(String) String
#endif

static GtkWidget*
create_info_window()
{
	GtkWidget *block;
	GtkWidget *main_box;
	GtkWidget *speed_label;
	GtkWidget *balance_label;
	GtkWidget *title_label;
	GtkWidget *format_label;
	GtkWidget *volume_label;
	GtkWidget *position_label;

	block = gtk_frame_new(NULL);
	main_box = gtk_layout_new(NULL, NULL);

	g_object_set_data(G_OBJECT(block), "layout", main_box);
	gtk_container_add(GTK_CONTAINER(block), main_box);

	speed_label = gtk_label_new(NULL);
	g_object_set_data(G_OBJECT(block), "speed_label", speed_label);
	gtk_layout_put(GTK_LAYOUT(main_box), speed_label, 2, 0);

	balance_label = gtk_label_new(NULL);
	g_object_set_data(G_OBJECT(block), "balance_label", balance_label);
	gtk_layout_put(GTK_LAYOUT(main_box), balance_label, 0, 0);

	title_label = gtk_label_new(NULL);
	g_object_set_data(G_OBJECT(block), "title_label", title_label);
	gtk_layout_put(GTK_LAYOUT(main_box), title_label, 0, 0);

	format_label = gtk_label_new(NULL);
	g_object_set_data(G_OBJECT(block), "format_label", format_label);
	gtk_layout_put(GTK_LAYOUT(main_box), format_label, 0, 0);

	volume_label = gtk_label_new(NULL);
	g_object_set_data(G_OBJECT(block), "volume_label", volume_label);
	gtk_layout_put(GTK_LAYOUT(main_box), volume_label, 0, 0);

	position_label = gtk_label_new(NULL);
	g_object_set_data(G_OBJECT(block), "position_label", position_label);
	gtk_layout_put(GTK_LAYOUT(main_box), position_label, 0, 25);

	return block;
}

InfoWindow::InfoWindow()
{
	window = create_info_window();
	volume = GTK_WIDGET(g_object_get_data(G_OBJECT(window), "volume_label"));
	balance = GTK_WIDGET(g_object_get_data(G_OBJECT(window), "balance_label"));
	position = GTK_WIDGET(g_object_get_data(G_OBJECT(window), "position_label"));
	title = GTK_WIDGET(g_object_get_data(G_OBJECT(window), "title_label"));
	format = GTK_WIDGET(g_object_get_data(G_OBJECT(window), "format_label"));
	speed = GTK_WIDGET(g_object_get_data(G_OBJECT(window), "speed_label"));
	layout = GTK_WIDGET(g_object_get_data(G_OBJECT(window), "layout"));

	leftwidth = 0;
	rightwidth = 0;
	labelheight = 0;

	const char *val = prefs_get_string(ap_prefs, "gtk2_interface", "background_colour", "#000000");
	this->set_background_color(val);
	val = prefs_get_string(ap_prefs, "gtk2_interface", "font_colour", "#ffffff");
	this->set_font_color(val);
	val = prefs_get_string(ap_prefs, "gtk2_interface", "fonts", "");
	this->set_fonts(val);
}

InfoWindow::~InfoWindow()
{
	gtk_widget_destroy(this->window);
}

void InfoWindow::set_volume(const gchar *text)
{
	gtk_label_set_text (GTK_LABEL(this->volume), text);
}

void InfoWindow::set_balance(const gchar *text)
{
	gtk_label_set_text (GTK_LABEL(this->balance), text);
}
void InfoWindow::set_positions()
{
	gint x, y, width, height;

	if ((this->labelheight < 2) || (this->leftwidth < 2) || (this->rightwidth < 2) || (this->labelheight != this->volume->allocation.height)) {
		this->leftwidth = (this->speed->allocation.width > this->balance->allocation.width)? this->speed->allocation.width:this->balance->allocation.width;
		this->rightwidth = (this->volume->allocation.width > this->position->allocation.width)? this->volume->allocation.width:this->position->allocation.width;
		this->labelheight = this->volume->allocation.height;

		gtk_widget_set_size_request(this->window, -1, this->labelheight * 2 + this->labelheight / 3);
	}

	width = this->layout->allocation.width;
	height = this->layout->allocation.height;

	//speed has fixed position
	// 2 px padding
	x = 2;
	y = height - this->labelheight;
	gtk_layout_move(GTK_LAYOUT(this->layout), this->balance, x, y);

	x = this->leftwidth + this->labelheight;
	y = 0;
	gtk_widget_set_size_request (this->title, width - x - this->rightwidth - this->labelheight, -1);
	gtk_layout_move(GTK_LAYOUT(this->layout), this->title, x, y);

	x = this->leftwidth + this->labelheight;
	y = height - this->labelheight;
	gtk_widget_set_size_request (this->format, width - x - this->rightwidth - this->labelheight, -1);
	gtk_layout_move(GTK_LAYOUT(this->layout), this->format, x, y);

	x = width - this->volume->allocation.width -2;
	y = 0;
	gtk_layout_move(GTK_LAYOUT(this->layout), this->volume, x, y);

	x = width - this->position->allocation.width - 2;
	y = height - this->labelheight;
	gtk_layout_move(GTK_LAYOUT(this->layout), this->position, x, y);

}

void InfoWindow::set_position(const gchar *text)
{
	gtk_label_set_text (GTK_LABEL(this->position), text);
}

void InfoWindow::set_title(const gchar *text)
{
	gtk_label_set_text (GTK_LABEL(this->title), text);
}

void InfoWindow::set_format(const gchar *text)
{
	gtk_label_set_text (GTK_LABEL(this->format), text);
}

void InfoWindow::set_speed(const gchar *text)
{
	gtk_label_set_text (GTK_LABEL(this->speed), text);
}

void InfoWindow::set_background_color(const gchar* str)
{
	GdkColor color;

	if (!gdk_color_parse(str, &color))
		return;

	gtk_widget_modify_bg(this->layout, GTK_STATE_NORMAL, &color);
}

void InfoWindow::set_font_color(const gchar* str)
{
	GdkColor color;

	if (!gdk_color_parse(str, &color))
		return;

	gtk_widget_modify_fg(this->volume, GTK_STATE_NORMAL, &color);
	gtk_widget_modify_fg(this->position, GTK_STATE_NORMAL, &color);
	gtk_widget_modify_fg(this->title, GTK_STATE_NORMAL, &color);
	gtk_widget_modify_fg(this->format, GTK_STATE_NORMAL, &color);
	gtk_widget_modify_fg(this->speed, GTK_STATE_NORMAL, &color);
	gtk_widget_modify_fg(this->balance, GTK_STATE_NORMAL, &color);
}

void InfoWindow::set_fonts(const gchar* str)
{
	PangoFontDescription *fonts;

	fonts = pango_font_description_from_string(str);

	gtk_widget_modify_font(this->volume, fonts);
	gtk_widget_modify_font(this->position, fonts);
	gtk_widget_modify_font(this->title, fonts);
	gtk_widget_modify_font(this->format, fonts);
	gtk_widget_modify_font(this->speed, fonts);
	gtk_widget_modify_font(this->balance, fonts);

	pango_font_description_free(fonts);
}