~ubuntu-branches/ubuntu/wily/me-tv/wily

1.2.2 by Michael Lamothe
Import upstream version 0.7.14
1
/*
2
 * Copyright (C) 2009 Michael Lamothe
3
 *
4
 * This file is part of Me TV
5
 *
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 2 of the License, or
9
 * (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU Library General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
19
 */
20
21
#include <libgnomeuimm.h>
22
#include <gdk/gdk.h>
23
#include "application.h"
24
#include "me-tv-ui.h"
25
1.1.7 by Scott Evans
Import upstream version 0.9.4
26
ComboBoxText::ComboBoxText(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& xml)
27
	: Gtk::ComboBox(cobject)
28
{
29
	list_store = Gtk::ListStore::create(columns);
30
	clear();
31
	set_model(list_store);
32
	pack_start(columns.column_string);
33
	set_active(0);
34
}
35
1.1.8 by Scott Evans
Import upstream version 1.0.0
36
void ComboBoxText::append(const Glib::ustring& text)
1.1.7 by Scott Evans
Import upstream version 0.9.4
37
{
38
	Gtk::TreeModel::Row row = *list_store->append();
39
	row[columns.column_string] = text;
40
}
41
1.1.8 by Scott Evans
Import upstream version 1.0.0
42
void ComboBoxText::set_text(const Glib::ustring& text)
1.1.7 by Scott Evans
Import upstream version 0.9.4
43
{
44
	Gtk::TreeNodeChildren children = get_model()->children();
45
	for (Gtk::TreeNodeChildren::iterator i = children.begin(); i != children.end(); i++)
46
	{
47
		Gtk::TreeModel::Row row = *i;
48
		if (row[columns.column_string] == text)
49
		{
50
			set_active(i);
51
		}
52
	}
53
}
54
55
void ComboBoxText::clear_items()
56
{
57
	list_store->clear();
58
}
59
1.1.8 by Scott Evans
Import upstream version 1.0.0
60
Glib::ustring ComboBoxText::get_text()
1.1.7 by Scott Evans
Import upstream version 0.9.4
61
{
62
	Gtk::TreeModel::iterator i = get_active();
63
	if (i)
64
	{
65
		Gtk::TreeModel::Row row = *i;
66
		if (row)
67
		{
68
			return row[columns.column_string];
69
		}
70
	}
71
	
72
	throw Exception(_("Failed to get active text value"));
73
}
74
75
ComboBoxEntryText::ComboBoxEntryText(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& xml)
1.2.2 by Michael Lamothe
Import upstream version 0.7.14
76
	: Gtk::ComboBoxEntryText(cobject)
77
{
78
}
79
1.1.7 by Scott Evans
Import upstream version 0.9.4
80
ChannelComboBox::ChannelComboBox(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& xml)
1.2.2 by Michael Lamothe
Import upstream version 0.7.14
81
	: Gtk::ComboBox(cobject)
82
{
83
	list_store = Gtk::ListStore::create(columns);
84
}
85
1.1.8 by Scott Evans
Import upstream version 1.0.0
86
void ChannelComboBox::load(const ChannelArray& channels)
1.2.2 by Michael Lamothe
Import upstream version 0.7.14
87
{
88
	clear();
89
	set_model(list_store);
90
	pack_start(columns.column_name);
91
	list_store->clear();
1.1.8 by Scott Evans
Import upstream version 1.0.0
92
	for (ChannelArray::const_iterator i = channels.begin(); i != channels.end(); i++)
1.2.2 by Michael Lamothe
Import upstream version 0.7.14
93
	{
94
		const Channel& channel = *i;
95
		Gtk::TreeModel::Row row = *list_store->append();
96
		row[columns.column_id] = channel.channel_id;
97
		row[columns.column_name] = channel.name;
98
	}
99
	set_active(0);
100
}
101
102
void ChannelComboBox::set_selected_channel_id(guint channel_id)
103
{
104
	Gtk::TreeNodeChildren children = get_model()->children();
105
	for (Gtk::TreeNodeChildren::iterator i = children.begin(); i != children.end(); i++)
106
	{
107
		Gtk::TreeModel::Row row = *i;
108
		if (row[columns.column_id] == channel_id)
109
		{
110
			set_active(i);
111
		}
112
	}
113
}
114
115
guint ChannelComboBox::get_selected_channel_id()
116
{
117
	Gtk::TreeModel::Row row = *get_active();
118
	return row[columns.column_id];
119
}
120
121
GdkLock::GdkLock()
122
{
123
	gdk_threads_enter();
124
}
125
126
GdkLock::~GdkLock()
127
{
128
	gdk_threads_leave();
129
}
130
131
GdkUnlock::GdkUnlock()
132
{
133
	gdk_threads_leave();
134
}
135
136
GdkUnlock::~GdkUnlock()
137
{
138
	gdk_threads_enter();
139
}
1.1.7 by Scott Evans
Import upstream version 0.9.4
140
141
IntComboBox::IntComboBox(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& xml)
142
	: Gtk::ComboBox(cobject)
143
{
144
	list_store = Gtk::ListStore::create(columns);
145
	clear();
146
	set_model(list_store);
147
	pack_start(columns.column_int);
148
	set_size(0);
149
	set_active(0);
150
}
151
152
void IntComboBox::set_size(guint size)
153
{	
154
	g_debug("Setting integer combo box size to %d", size);
155
156
	list_store->clear();
157
	for (guint i = 0; i < size; i++)
158
	{
159
		Gtk::TreeModel::Row row = *list_store->append();
160
		row[columns.column_int] = (i+1);
161
		
162
		if (list_store->children().size() == 1)
163
		{
164
			set_active(0);
165
		}
166
	}
167
	
168
	if (size == 0)
169
	{
170
		Gtk::TreeModel::Row row = *list_store->append();
171
		row[columns.column_int] = 1;
172
	}
173
	
174
	set_sensitive(size > 1);
175
}
176
177
guint IntComboBox::get_size()
178
{
179
	return list_store->children().size();
180
}
181
182
guint IntComboBox::get_active_value()
183
{
184
	Gtk::TreeModel::iterator i = get_active();
185
	if (i)
186
	{
187
		Gtk::TreeModel::Row row = *i;
188
		if (row)
189
		{
190
			return row[columns.column_int];
191
		}
192
	}
193
	
194
	throw Exception(_("Failed to get active integer value"));
195
}
196
197
FullscreenBugWorkaround::FullscreenBugWorkaround()
198
{
199
	apply = false;
200
201
	if (get_application().get_boolean_configuration_value("fullscreen_bug_workaround"))
202
	{
203
		MainWindow& main_window = get_application().get_main_window();
204
		apply = main_window.is_fullscreen();
205
		if (apply)
206
		{
207
			main_window.unfullscreen(false);
208
		}
209
	}
210
}
211
212
FullscreenBugWorkaround::~FullscreenBugWorkaround()
213
{
214
	if (apply)
215
	{
216
		MainWindow& main_window = get_application().get_main_window();
217
		main_window.fullscreen(false);
218
	}
219
}