Add ability to add local remotes

This commit is contained in:
heliguy
2024-07-22 17:58:06 -04:00
parent 49f557d9ee
commit 1f6ae74063
3 changed files with 39 additions and 5 deletions

View File

@@ -96,12 +96,17 @@ class AddRemoteDialog(Adw.Dialog):
self.installation_row.set_model(self.string_list)
if remote_info:
self.title_row.set_text(remote_info["title"])
self.title_row.set_editable(False)
self.name_row.set_text(remote_info["name"])
self.name_row.set_editable(False)
self.url_row.set_text(remote_info["link"])
self.url_row.set_editable(False)
self.apply_button.set_sensitive(True)
if remote_info["description"] == "local file":
self.check_entries(self.title_row)
self.check_entries(self.name_row)
self.check_entries(self.url_row)
else:
self.title_row.set_editable(False)
self.name_row.set_editable(False)
self.url_row.set_editable(False)
self.apply_button.set_sensitive(True)
# Connections
self.apply_button.connect("clicked", self.on_apply)

View File

@@ -64,7 +64,6 @@ template $RemotesPage : Adw.NavigationPage {
title: _("Add Other Remotes");
Adw.ActionRow file_remote_row {
activatable: true;
sensitive: false;
title: _("Add a Repo File");
subtitle: _("Open a downloaded repo file to add");
[suffix]

View File

@@ -182,6 +182,35 @@ class RemotesPage(Adw.NavigationPage):
self.stack.set_visible_child(self.content_page if total > 0 else self.no_results)
def file_callback(self, chooser, result):
try:
file = chooser.open_finish(result)
path = file.get_path()
name = path.split("/")[-1].split(".")[0]
info = {
"title": name.title(),
"name": name,
"description": "local file",
"link": path,
}
AddRemoteDialog(self.main_window, self, info).present(self.main_window)
except GLib.GError as ge:
if "Dismissed by user" in str(ge):
return
self.toast_overlay.add_toast(ErrorToast(_("Could not open file"), str(ge)).toast)
except Exception as e:
self.toast_overlay.add_toast(ErrorToast(_("Could not open file"), str(e)).toast)
def add_file_handler(self):
file_filter = Gtk.FileFilter(name=_("Flatpak Repos"))
file_filter.add_suffix("flatpakrepo")
filters = Gio.ListStore.new(Gtk.FileFilter)
filters.append(file_filter)
file_chooser = Gtk.FileDialog()
file_chooser.set_filters(filters)
file_chooser.set_default_filter(file_filter)
file_chooser.open(self.main_window, None, self.file_callback)
def __init__(self, main_window, **kwargs):
super().__init__(**kwargs)
@@ -196,6 +225,7 @@ class RemotesPage(Adw.NavigationPage):
# Connections
ms.connect("notify::show-sidebar", lambda *_: self.sidebar_button.set_active(ms.get_show_sidebar()))
self.sidebar_button.connect("toggled", lambda *_: ms.set_show_sidebar(self.sidebar_button.get_active()))
self.file_remote_row.connect("activated", lambda *_: self.add_file_handler())
self.custom_remote_row.connect("activated", lambda *_: AddRemoteDialog(main_window, self).present(main_window))
self.search_entry.connect("search-changed", self.on_search)