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 "me-tv.h" |
|
22 |
#include <libgnomeuimm.h> |
|
1.1.7
by Scott Evans
Import upstream version 0.9.4 |
23 |
#include "scan_dialog.h" |
1.2.2
by Michael Lamothe
Import upstream version 0.7.14 |
24 |
#include "application.h" |
25 |
#include "channels_dialog.h" |
|
26 |
||
1.1.7
by Scott Evans
Import upstream version 0.9.4 |
27 |
ChannelsDialog& ChannelsDialog::create(Glib::RefPtr<Gtk::Builder> builder) |
1.2.2
by Michael Lamothe
Import upstream version 0.7.14 |
28 |
{
|
29 |
ChannelsDialog* channels_dialog = NULL; |
|
1.1.7
by Scott Evans
Import upstream version 0.9.4 |
30 |
builder->get_widget_derived("dialog_channels", channels_dialog); |
1.2.2
by Michael Lamothe
Import upstream version 0.7.14 |
31 |
return *channels_dialog; |
32 |
}
|
|
33 |
||
1.1.7
by Scott Evans
Import upstream version 0.9.4 |
34 |
ChannelsDialog::ChannelsDialog(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& builder) : |
35 |
Gtk::Dialog(cobject), builder(builder) |
|
1.2.2
by Michael Lamothe
Import upstream version 0.7.14 |
36 |
{
|
1.1.7
by Scott Evans
Import upstream version 0.9.4 |
37 |
Gtk::Button* button = NULL; |
38 |
||
39 |
builder->get_widget("button_scan", button); |
|
40 |
button->signal_clicked().connect(sigc::mem_fun(*this, &ChannelsDialog::on_button_scan_clicked)); |
|
41 |
||
42 |
builder->get_widget("button_remove_selected_channels", button); |
|
43 |
button->signal_clicked().connect(sigc::mem_fun(*this, &ChannelsDialog::on_button_remove_selected_channels_clicked)); |
|
44 |
||
45 |
tree_view_displayed_channels = NULL; |
|
46 |
||
47 |
builder->get_widget("tree_view_displayed_channels", tree_view_displayed_channels); |
|
1.2.2
by Michael Lamothe
Import upstream version 0.7.14 |
48 |
|
49 |
list_store = Gtk::ListStore::create(columns); |
|
50 |
tree_view_displayed_channels->set_model(list_store); |
|
51 |
tree_view_displayed_channels->append_column(_("Channel Name"), columns.column_name); |
|
52 |
||
53 |
Glib::RefPtr<Gtk::TreeSelection> selection = tree_view_displayed_channels->get_selection(); |
|
54 |
selection->set_mode(Gtk::SELECTION_MULTIPLE); |
|
55 |
}
|
|
56 |
||
1.1.8
by Scott Evans
Import upstream version 1.0.0 |
57 |
gboolean ChannelsDialog::import_channel(const Channel& channel) |
58 |
{
|
|
59 |
gboolean abort_import = false; |
|
60 |
gboolean add = true; |
|
61 |
||
62 |
const Gtk::TreeModel::Children& children = list_store->children(); |
|
63 |
for (Gtk::TreeModel::Children::const_iterator iterator = children.begin(); iterator != children.end(); iterator++) |
|
64 |
{
|
|
65 |
Gtk::TreeModel::Row row = *iterator; |
|
66 |
if (row[columns.column_name] == channel.name) |
|
67 |
{
|
|
68 |
g_debug("Channel import: conflict with '%s'", channel.name.c_str()); |
|
69 |
||
70 |
add = false; |
|
71 |
||
72 |
Glib::ustring message = Glib::ustring::compose( |
|
73 |
_("A channel named '%1' already exists. Do you want to overwrite it?"), |
|
74 |
channel.name); |
|
75 |
||
76 |
Gtk::MessageDialog dialog(*this, message, false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_NONE, true); |
|
77 |
dialog.add_button(_("Overwrite existing channel"), Gtk::RESPONSE_ACCEPT); |
|
78 |
dialog.add_button(_("Keep existing channel"), Gtk::RESPONSE_REJECT); |
|
79 |
dialog.add_button(_("Cancel scan/import"), Gtk::RESPONSE_CANCEL); |
|
80 |
||
81 |
Glib::ustring title = PACKAGE_NAME " - "; |
|
82 |
title += _("Channel conflict"); |
|
83 |
dialog.set_title(title); |
|
84 |
dialog.set_icon_from_file(PACKAGE_DATA_DIR"/me-tv/glade/me-tv.xpm"); |
|
85 |
int response = dialog.run(); |
|
86 |
||
87 |
switch (response) |
|
88 |
{
|
|
89 |
case Gtk::RESPONSE_ACCEPT: // Overwrite |
|
90 |
g_debug("Channel accepted"); |
|
91 |
row[columns.column_name] = channel.name; |
|
92 |
row[columns.column_channel] = channel; |
|
93 |
break; |
|
94 |
case Gtk::RESPONSE_REJECT: |
|
95 |
g_debug("Channel rejected"); |
|
96 |
break; |
|
97 |
default: // Cancel |
|
98 |
g_debug("Import cancelled"); |
|
99 |
abort_import = true; |
|
100 |
break; |
|
101 |
}
|
|
102 |
}
|
|
103 |
}
|
|
104 |
||
105 |
if (add && !abort_import) |
|
106 |
{
|
|
107 |
Gtk::TreeModel::iterator row_iterator = list_store->append(); |
|
108 |
Gtk::TreeModel::Row row = *row_iterator; |
|
109 |
row[columns.column_name] = channel.name; |
|
110 |
row[columns.column_channel] = channel; |
|
111 |
}
|
|
112 |
||
113 |
return !abort_import; |
|
114 |
}
|
|
115 |
||
1.1.7
by Scott Evans
Import upstream version 0.9.4 |
116 |
void ChannelsDialog::show_scan_dialog() |
1.2.2
by Michael Lamothe
Import upstream version 0.7.14 |
117 |
{
|
1.1.7
by Scott Evans
Import upstream version 0.9.4 |
118 |
// Check for a valid frontend device
|
119 |
get_application().device_manager.get_frontend(); |
|
120 |
||
121 |
FullscreenBugWorkaround fullscreen_bug_workaround; |
|
122 |
||
123 |
ScanDialog& scan_dialog = ScanDialog::create(builder); |
|
124 |
scan_dialog.show(); |
|
125 |
Gtk::Main::run(scan_dialog); |
|
1.1.8
by Scott Evans
Import upstream version 1.0.0 |
126 |
|
127 |
ChannelArray channels = scan_dialog.get_channels(); |
|
128 |
for (ChannelArray::const_iterator iterator = channels.begin(); iterator != channels.end(); iterator++) |
|
1.1.7
by Scott Evans
Import upstream version 0.9.4 |
129 |
{
|
1.1.8
by Scott Evans
Import upstream version 1.0.0 |
130 |
if (!import_channel(*iterator)) |
131 |
{
|
|
132 |
break; |
|
133 |
}
|
|
1.1.7
by Scott Evans
Import upstream version 0.9.4 |
134 |
}
|
1.2.2
by Michael Lamothe
Import upstream version 0.7.14 |
135 |
}
|
136 |
||
137 |
void ChannelsDialog::on_button_scan_clicked() |
|
138 |
{
|
|
139 |
TRY
|
|
1.1.7
by Scott Evans
Import upstream version 0.9.4 |
140 |
show_scan_dialog(); |
1.2.2
by Michael Lamothe
Import upstream version 0.7.14 |
141 |
CATCH
|
142 |
}
|
|
143 |
||
1.1.7
by Scott Evans
Import upstream version 0.9.4 |
144 |
void ChannelsDialog::on_button_remove_selected_channels_clicked() |
1.2.2
by Michael Lamothe
Import upstream version 0.7.14 |
145 |
{
|
146 |
get_window()->freeze_updates(); |
|
147 |
Glib::RefPtr<Gtk::TreeSelection> tree_selection = tree_view_displayed_channels->get_selection(); |
|
148 |
std::list<Gtk::TreeModel::Path> selected_channels = tree_selection->get_selected_rows(); |
|
149 |
while (selected_channels.size() > 0) |
|
150 |
{
|
|
151 |
list_store->erase(list_store->get_iter(*selected_channels.begin())); |
|
152 |
selected_channels = tree_selection->get_selected_rows(); |
|
153 |
}
|
|
154 |
get_window()->thaw_updates(); |
|
155 |
}
|
|
156 |
||
1.1.8
by Scott Evans
Import upstream version 1.0.0 |
157 |
ChannelArray ChannelsDialog::get_channels() |
1.2.2
by Michael Lamothe
Import upstream version 0.7.14 |
158 |
{
|
1.1.8
by Scott Evans
Import upstream version 1.0.0 |
159 |
ChannelArray result; |
1.2.2
by Michael Lamothe
Import upstream version 0.7.14 |
160 |
Glib::RefPtr<Gtk::TreeModel> model = tree_view_displayed_channels->get_model(); |
161 |
Gtk::TreeModel::Children children = model->children(); |
|
162 |
Gtk::TreeIter iterator = children.begin(); |
|
163 |
guint sort_order = 0; |
|
164 |
while (iterator != children.end()) |
|
165 |
{
|
|
166 |
Gtk::TreeModel::Row row(*iterator); |
|
167 |
Channel channel = row.get_value(columns.column_channel); |
|
168 |
channel.sort_order = sort_order++; |
|
169 |
result.push_back(channel); |
|
170 |
iterator++; |
|
171 |
}
|
|
172 |
return result; |
|
173 |
}
|
|
174 |
||
1.1.7
by Scott Evans
Import upstream version 0.9.4 |
175 |
void ChannelsDialog::on_show() |
176 |
{
|
|
177 |
TRY
|
|
1.2.2
by Michael Lamothe
Import upstream version 0.7.14 |
178 |
list_store->clear(); |
179 |
||
1.1.7
by Scott Evans
Import upstream version 0.9.4 |
180 |
Application& application = get_application(); |
181 |
||
1.1.8
by Scott Evans
Import upstream version 1.0.0 |
182 |
ChannelArray& channels = application.channel_manager.get_channels(); |
1.1.7
by Scott Evans
Import upstream version 0.9.4 |
183 |
if (channels.empty() && !application.device_manager.get_frontends().empty()) |
184 |
{
|
|
185 |
show_scan_dialog(); |
|
186 |
}
|
|
187 |
else
|
|
188 |
{
|
|
1.1.8
by Scott Evans
Import upstream version 1.0.0 |
189 |
for (ChannelArray::const_iterator iterator = channels.begin(); iterator != channels.end(); iterator++) |
1.1.7
by Scott Evans
Import upstream version 0.9.4 |
190 |
{
|
191 |
const Channel& channel = *iterator; |
|
192 |
||
193 |
Gtk::TreeModel::iterator row_iterator = list_store->append(); |
|
194 |
Gtk::TreeModel::Row row = *row_iterator; |
|
195 |
row[columns.column_name] = channel.name; |
|
196 |
row[columns.column_channel] = channel; |
|
197 |
}
|
|
198 |
}
|
|
1.2.2
by Michael Lamothe
Import upstream version 0.7.14 |
199 |
Gtk::Dialog::on_show(); |
200 |
||
201 |
CATCH
|
|
202 |
}
|