mirror of
https://github.com/morgan9e/warehouse
synced 2026-04-14 00:04:08 +09:00
More work on local installs
This commit is contained in:
@@ -20,22 +20,26 @@ class FileInstallDialog(Adw.AlertDialog):
|
||||
if response != "continue":
|
||||
return
|
||||
|
||||
def __init__(self, parent_page, files, **kwargs):
|
||||
# self.installation_row.get_selected_item().get_string()
|
||||
self.on_add("user", self.files)
|
||||
|
||||
def __init__(self, parent_page, files, on_add, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
# Extra Object Creation
|
||||
self.parent_page = parent_page
|
||||
self.files = files
|
||||
self.on_add = on_add
|
||||
|
||||
# Apply
|
||||
self.generate_list()
|
||||
self.installation_row.set_model(Gtk.StringList(strings=HostInfo.installations))
|
||||
if len(files) > 1:
|
||||
self.set_heading(_("Add These Files?"))
|
||||
self.set_body(_("Add these files to the queue to be installed"))
|
||||
self.set_heading(_("Add These Packages?"))
|
||||
self.set_body(_("Queue these packages to be installed"))
|
||||
else:
|
||||
self.set_heading(_("Add This File?"))
|
||||
self.set_body(_("Add this file to the queue to be installed"))
|
||||
self.set_heading(_("Add This Package?"))
|
||||
self.set_body(_("Queue this package to be installed"))
|
||||
|
||||
# Connections
|
||||
self.connect("response", self.on_response)
|
||||
|
||||
@@ -69,6 +69,11 @@ class PendingPage(Adw.NavigationPage):
|
||||
added_row.connect("activated", self.remove_package_row, group)
|
||||
self.stack.set_visible_child(self.main_view)
|
||||
|
||||
def add_local_package_rows(self, installation, files):
|
||||
print("Installation:", installation)
|
||||
for file in files:
|
||||
print(file.get_basename())
|
||||
|
||||
def remove_package_row(self, row, group):
|
||||
# row.origin_row.set_state(ResultRow.PackageState.NEW)
|
||||
for item in row.origin_list_box:
|
||||
@@ -107,7 +112,7 @@ class PendingPage(Adw.NavigationPage):
|
||||
def reset(self):
|
||||
for key, group in self.groups.items():
|
||||
self.preferences_page.remove(group)
|
||||
|
||||
|
||||
self.groups.clear()
|
||||
self.added_packages.clear()
|
||||
self.stack.set_visible_child(self.none_pending)
|
||||
|
||||
@@ -53,10 +53,13 @@ class ResultsPage(Adw.NavigationPage):
|
||||
self.search_entry.grab_focus()
|
||||
if nav_view:
|
||||
nav_view.push(self)
|
||||
|
||||
|
||||
def add_package_row(self, row):
|
||||
self.pending_page.add_package_row(row)
|
||||
|
||||
|
||||
def add_local_package_rows(self, installation, files):
|
||||
self.pending_page.add_local_package_rows(installation, files)
|
||||
|
||||
def on_search(self, *args):
|
||||
self.packages.clear()
|
||||
self.stack.set_visible_child(self.loading)
|
||||
@@ -65,14 +68,14 @@ class ResultsPage(Adw.NavigationPage):
|
||||
if search_text == "":
|
||||
self.stack.set_visible_child(self.new_search)
|
||||
return
|
||||
|
||||
|
||||
def thread(*args):
|
||||
installation = ""
|
||||
if self.installation == "user" or self.installation == "system":
|
||||
installation = f"--{self.installation}"
|
||||
else:
|
||||
installation = f"--installation={self.installation}"
|
||||
|
||||
|
||||
try:
|
||||
output = subprocess.run(
|
||||
['flatpak-spawn', '--host', 'flatpak', 'search', '--columns=all', installation, self.search_entry.get_text()],
|
||||
@@ -81,64 +84,64 @@ class ResultsPage(Adw.NavigationPage):
|
||||
if len(output) > 100:
|
||||
GLib.idle_add(lambda *_: self.stack.set_visible_child(self.too_many))
|
||||
return
|
||||
|
||||
|
||||
for line in output:
|
||||
line = line.strip()
|
||||
|
||||
info = line.split('\t')
|
||||
if len(info) != 6:
|
||||
continue
|
||||
|
||||
|
||||
remotes = info[5].split(',')
|
||||
if not self.remote.name in remotes:
|
||||
continue
|
||||
|
||||
|
||||
package = AddedPackage(info[0], info[2], info[4], info[3], self.remote, self.installation)
|
||||
row = ResultRow(package, ResultRow.PackageState.NEW, self.results_list)
|
||||
for item in self.pending_page.added_packages:
|
||||
if package.is_similar(item):
|
||||
row.set_state(ResultRow.PackageState.SELECTED)
|
||||
|
||||
|
||||
if package.app_id in HostInfo.id_to_flatpak:
|
||||
installed_package = HostInfo.id_to_flatpak[package.app_id]
|
||||
if installed_package.info["id"] == package.app_id and installed_package.info["branch"] == package.branch:
|
||||
row.set_state(ResultRow.PackageState.INSTALLED)
|
||||
|
||||
|
||||
row.connect("activated", self.add_package_row)
|
||||
self.packages.append(package)
|
||||
GLib.idle_add(lambda *_, _row=row: self.results_list.append(_row))
|
||||
|
||||
|
||||
if len(self.packages) > 0:
|
||||
GLib.idle_add(lambda *_: self.stack.set_visible_child(self.results_view))
|
||||
else:
|
||||
GLib.idle_add(lambda *_: self.stack.set_visible_child(self.no_results))
|
||||
|
||||
|
||||
except subprocess.CalledProcessError as cpe:
|
||||
print(cpe)
|
||||
|
||||
|
||||
def callback(*args):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
Gio.Task.new(None, None, callback).run_in_thread(thread)
|
||||
|
||||
|
||||
def on_back(self, *args):
|
||||
self.results_list.remove_all()
|
||||
self.stack.set_visible_child(self.new_search)
|
||||
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
|
||||
# Extra Object Creation
|
||||
self.remote = None
|
||||
self.installation = None
|
||||
self.packages = []
|
||||
self.pending_page = None
|
||||
self.loading = LoadingStatus(_("Searching"), _("This should only take a moment"))
|
||||
|
||||
|
||||
# Connections
|
||||
self.search_entry.connect("activate", self.on_search)
|
||||
self.search_apply_button.connect("clicked", self.on_search)
|
||||
|
||||
|
||||
# Apply
|
||||
self.stack.add_child(self.loading)
|
||||
|
||||
@@ -36,17 +36,13 @@ class SelectPage(Adw.NavigationPage):
|
||||
|
||||
self.remotes_group.set_visible(len(self.remote_rows) != 0)
|
||||
|
||||
def on_file_dialog_response(self, dialog, response, row):
|
||||
installation = row.get_selected_item().get_string()
|
||||
HostInfo.main_window.toast_overlay.add_toast(ErrorToast(response, installation).toast)
|
||||
|
||||
def file_choose_callback(self, object, result):
|
||||
files = object.open_multiple_finish(result)
|
||||
if not files:
|
||||
HostInfo.toast_overlay.add_toast(ErrorToast(_("Could not add files"), _("No files were found to install")))
|
||||
return
|
||||
|
||||
FileInstallDialog(self, files).present(HostInfo.main_window)
|
||||
FileInstallDialog(self, files, self.results_page.add_local_package_rows).present(HostInfo.main_window)
|
||||
|
||||
def on_open(self, *args):
|
||||
file_filter = Gtk.FileFilter(name=_("Flatpaks"))
|
||||
|
||||
Reference in New Issue
Block a user