added checking for bouquet names duplicate

This commit is contained in:
DYefremov
2020-01-29 14:50:02 +03:00
parent b7d0ba7f4b
commit 4c6336e75f
2 changed files with 30 additions and 2 deletions

View File

@@ -98,6 +98,8 @@ def parse_bouquets(path, bq_name, bq_type):
bouquets = None
nm_sep = "#NAME"
bq_pattern = re.compile(".*userbouquet\\.+(.*)\\.+[tv|radio].*")
b_names = set()
real_b_names = set()
for line in lines:
if nm_sep in line:
@@ -106,7 +108,18 @@ def parse_bouquets(path, bq_name, bq_type):
if bouquets and "#SERVICE" in line:
name = re.match(bq_pattern, line)
if name:
b_name, services = get_bouquet(path, name.group(1), bq_type)
b_name = name.group(1)
if b_name in b_names:
raise ValueError("The list of bouquets contains duplicate [{}] names!".format(b_name))
else:
b_names.add(b_name)
b_name, services = get_bouquet(path, b_name, bq_type)
if b_name in real_b_names:
raise ValueError("The list of bouquets contains duplicate [{}] names!".format(b_name))
else:
real_b_names.add(b_name)
bouquets[2].append(Bouquet(name=b_name,
type=bq_type,
services=services,

View File

@@ -655,6 +655,16 @@ class Application(Gtk.Application):
bq = response, None, None, bq_type
key = "{}:{}".format(response, bq_type)
while key in self._bouquets:
self.show_error_dialog(get_message("A bouquet with that name exists!"))
response = show_dialog(DialogType.INPUT, self._main_window, bq_name)
if response == Gtk.ResponseType.CANCEL:
return
key = "{}:{}".format(response, bq_type)
bq = response, None, None, bq_type
self._current_bq_name = response
if model.iter_n_children(itr): # parent
@@ -2094,8 +2104,13 @@ class Application(Gtk.Application):
if response == Gtk.ResponseType.CANCEL:
return
bq = "{}:{}".format(response, bq_type)
if bq in self._bouquets:
self.show_error_dialog(get_message("A bouquet with that name exists!"))
return
model.set_value(itr, 0, response)
self._bouquets["{}:{}".format(response, bq_type)] = self._bouquets.pop("{}:{}".format(bq_name, bq_type))
self._bouquets[bq] = self._bouquets.pop("{}:{}".format(bq_name, bq_type))
self._current_bq_name = response
self._bq_name_label.set_text(self._current_bq_name)
self._bq_selected = "{}:{}".format(response, bq_type)