diff --git a/data/io.github.flattool.Warehouse.gschema.xml b/data/io.github.flattool.Warehouse.gschema.xml
index 095be40..788abef 100644
--- a/data/io.github.flattool.Warehouse.gschema.xml
+++ b/data/io.github.flattool.Warehouse.gschema.xml
@@ -21,11 +21,11 @@
false
-
- ""
-
- ""
+ "all"
+
+
+ "all"
diff --git a/data/ui/filter.blp b/data/ui/filter.blp
index 3196bf6..a285fa4 100644
--- a/data/ui/filter.blp
+++ b/data/ui/filter.blp
@@ -16,7 +16,7 @@ template $FilterWindow: Adw.Window {
Button cancel_button {
label: _("Cancel");
}
-
+
[end]
Button apply_button {
label: _("Apply");
@@ -53,31 +53,31 @@ template $FilterWindow: Adw.Window {
Adw.ActionRow apps_row {
title: _("Show Apps");
- Switch apps_switch {
+ Switch show_apps_switch {
valign: center;
}
- activatable-widget: apps_switch;
+ activatable-widget: show_apps_switch;
}
- Adw.ActionRow runtimes_row {
+ Adw.ActionRow show_runtimes_row {
title: _("Show Runtimes");
- Switch runtimes_switch {
+ Switch show_runtimes_switch {
valign: center;
}
- activatable-widget: runtimes_switch;
+ activatable-widget: show_runtimes_switch;
}
Adw.ExpanderRow remotes_expander {
enable-expansion: false;
- title: _("Filter Apps by Remotes");
+ title: _("Filter by Remotes");
}
Adw.ExpanderRow runtimes_expander {
enable-expansion: false;
- title: _("Filter Apps by Runtime");
+ title: _("Filter by Runtimes");
}
}
diff --git a/src/downgrade_window.py b/src/downgrade_window.py
index 693ff54..9ebf9ee 100644
--- a/src/downgrade_window.py
+++ b/src/downgrade_window.py
@@ -116,7 +116,8 @@ class DowngradeWindow(Adw.Window):
if self.response != 0:
self.toast_overlay.add_toast(
- Adw.TThis is toast.new(_("Could not downgrade {}").format(self.app_name))
+ Adw.TThis
+ is toast.new(_("Could not downgrade {}").format(self.app_name))
)
self.apply_button.set_sensitive(True)
self.cancel_button.set_sensitive(True)
diff --git a/src/filter_window.py b/src/filter_window.py
index fa22ceb..9a38e8a 100644
--- a/src/filter_window.py
+++ b/src/filter_window.py
@@ -11,52 +11,113 @@ class FilterWindow(Adw.Window):
cancel_button = Gtk.Template.Child()
apply_button = Gtk.Template.Child()
- apps_switch = Gtk.Template.Child()
- runtimes_switch = Gtk.Template.Child()
+ show_apps_switch = Gtk.Template.Child()
+ show_runtimes_switch = Gtk.Template.Child()
remotes_expander = Gtk.Template.Child()
runtimes_expander = Gtk.Template.Child()
+ reset_button = Gtk.Template.Child()
def key_handler(self, _a, event, _c, _d):
if event == Gdk.KEY_Escape:
self.close()
- # Unused for now. !!!! Don't forget!
def is_list_applicable(self):
- # self.apply_button.set_sensitive(True)
+ self.apply_button.set_sensitive(True)
- # if not self.filter_list[0] == True and not self.filter_list[1] == True:
- # self.apply_button.set_sensitive(False)
- # return
+ show_apps = self.show_apps_switch.get_active()
+ show_runtimes = self.show_runtimes_switch.get_active()
+ filter_by_remotes = self.remotes_switch.get_active()
+ filter_by_runtimes = self.runtimes_switch.get_active()
- # if self.filter_list[3] == []:
- # self.apply_button.set_sensitive(False)
- # return
+ if (not show_apps) and (not show_runtimes):
+ self.apply_button.set_sensitive(False)
+ return
- # if self.filter_list[4] == []:
- # self.apply_button.set_sensitive(False)
- # return
+ if show_runtimes and filter_by_runtimes:
+ self.apply_button.set_sensitive(False)
+ return
- # if (
- # self.apps_switch.get_active()
- # and (not self.runtimes_switch.get_active())
- # and (not self.remotes_expander_switch.get_active())
- # and (not self.runtimes_expander_switch.get_active())
- # ):
- # self.apply_button.set_sensitive(False)
- # return
- pass
+ if filter_by_remotes and self.remotes_string_staging == ["all"]:
+ self.apply_button.set_sensitive(False)
+ return
+
+ if filter_by_runtimes and self.runtimes_string_staging == ["all"]:
+ self.apply_button.set_sensitive(False)
+ return
+
+ if(show_apps == self.settings.get_boolean("show-apps")) and (show_runtimes == self.settings.get_boolean("show-runtimes")) and (self.remotes_string_staging == self.settings.get_string("remotes-list").split(',')) and (self.runtimes_string_staging == self.settings.get_string("runtimes-string").split(',')):
+ self.apply_button.set_sensitive(False)
+ return
+
+ def show_apps_handler(self, switch, state):
+ self.is_list_applicable()
+ self.show_apps_staging = state
+
+ def show_runtimes_handler(self, switch, state):
+ self.is_list_applicable()
+ self.show_runtimes_staging = state
+
+ def remote_handler(self, remote, should_add):
+ the_list = self.remotes_string_staging
+ if should_add:
+ the_list.append(remote)
+ if "all" in the_list and len(the_list) > 1:
+ the_list.remove("all")
+ else:
+ the_list.remove(remote)
+ if len(the_list) < 1:
+ the_list.append("all")
- def gschema_bool_setter(key, state):
- self.settings.set_boolean(key, state)
self.is_list_applicable()
- def gschema_string_setter(key, state):
- self.settings.set_string(key, state)
+ def runtime_handler(self, runtime, should_add):
+ the_list = self.runtimes_string_staging
+ if should_add:
+ the_list.append(runtime)
+ if "all" in the_list and len(the_list) > 1:
+ the_list.remove("all")
+ else:
+ the_list.remove(runtime)
+ if len(the_list) < 1:
+ the_list.append("all")
+
self.is_list_applicable()
-
+
+ def remotes_switch_handler(self, switch, state):
+ self.is_list_applicable()
+ for box in self.remote_checkboxes:
+ box.set_sensitive(state)
+ box.set_active(False)
+ self.remotes_expander.set_enable_expansion(state)
+ if not state:
+ self.remotes_string_staging = ["all"]
+
+ def runtimes_switch_handler(self, switch, state):
+ self.is_list_applicable()
+ for box in self.runtime_checkboxes:
+ box.set_sensitive(state)
+ box.set_active(False)
+ self.runtimes_expander.set_enable_expansion(state)
+ if not state:
+ self.runtimes_string_staging = ["all"]
+
+ def reset_filter_gsettings(self):
+ self.show_apps_switch.set_active(True)
+ self.show_runtimes_switch.set_active(False)
+ self.remotes_switch.set_active(False)
+ self.runtimes_switch.set_active(False)
+
+ def on_apply(self):
+ self.settings.set_boolean("show-apps", self.show_apps_staging)
+ self.settings.set_boolean("show-runtimes", self.show_runtimes_staging)
+ self.settings.set_string("remotes-list", ",".join(self.remotes_string_staging))
+ self.settings.set_string(
+ "runtimes-list", ",".join(self.runtimes_string_staging)
+ )
+ self.main_window.apply_filter()
+ self.close()
+
def generate_list(self):
- self.remotes_expander_switch = Gtk.Switch(valign=Gtk.Align.CENTER)
- self.runtimes_expander_switch = Gtk.Switch(valign=Gtk.Align.CENTER)
dependent_runtimes = self.my_utils.get_dependent_runtimes()
@@ -71,7 +132,11 @@ class FilterWindow(Adw.Window):
self.runtimes_expander.set_visible(False)
self.remote_checkboxes = []
+ remotes_list = self.remotes_string_staging
total = 0
+ self.remotes_switch.connect("state-set", self.remotes_switch_handler)
+ self.remotes_expander.add_suffix(self.remotes_switch)
+ self.remotes_switch.set_active(remotes_list[0] != "all")
for i in range(len(self.host_remotes)):
try:
name = self.host_remotes[i][0]
@@ -88,6 +153,13 @@ class FilterWindow(Adw.Window):
label = Gtk.Label(label=("{} wide").format(install_type))
label.add_css_class("subtitle")
remote_check = Gtk.CheckButton()
+ remote_check.set_active(name in remotes_list)
+ remote_check.connect(
+ "toggled",
+ lambda button=remote_check, remote=name: self.remote_handler(
+ remote, button.get_active()
+ ),
+ )
if "user" in install_type:
remote_row.set_subtitle(_("User wide"))
@@ -98,86 +170,76 @@ class FilterWindow(Adw.Window):
remote_row.add_suffix(remote_check)
remote_row.set_activatable_widget(remote_check)
- # remote_check.connect(
- # "toggled", self.remotes_check_handler, install_type, name
- # )
self.remote_checkboxes.append(remote_check)
except Exception as e:
- print("error at filter_window.generate_list: Could not make remote row. error", e)
+ print(
+ "error at filter_window.generate_list: Could not make remote row. error",
+ e,
+ )
if total < 2:
self.remotes_expander.set_visible(False)
- self.remotes_expander.add_suffix(self.remotes_expander_switch)
-
self.runtime_checkboxes = []
- for i in range(len(dependent_runtimes)):
- current = dependent_runtimes[i]
+ runtimes_list = self.runtimes_string_staging
+ self.runtimes_switch.connect("state-set", self.runtimes_switch_handler)
+ self.runtimes_expander.add_suffix(self.runtimes_switch)
+ self.runtimes_switch.set_active(runtimes_list[0] != "all")
+ for current in dependent_runtimes:
runtime_row = Adw.ActionRow(title=current)
runtime_check = Gtk.CheckButton()
- # runtime_check.connect(
- # "toggled", self.runtimes_check_handler, current
- # )
- runtime_check.set_active(True)
+ runtime_check.set_active(current in runtimes_list)
+ runtime_check.connect(
+ "toggled",
+ lambda button=runtime_check, runtime=current: self.runtime_handler(
+ runtime, button.get_active()
+ ),
+ )
self.runtime_checkboxes.append(runtime_check)
runtime_row.add_suffix(runtime_check)
runtime_row.set_activatable_widget(runtime_check)
self.runtimes_expander.add_row(runtime_row)
-
- self.runtimes_expander.add_suffix(self.runtimes_expander_switch)
def __init__(self, main_window, **kwargs):
super().__init__(**kwargs)
- self.present()
-
-
-
-
-
- self.settings = Gio.Settings.new("io.github.flattool.Warehouse.filter")
-
- self.apps_switch.set_active(self.settings.get_boolean("show-apps"))
- self.apps_switch.connect("state-set", lambda switch, state: gschema_bool_setter("show-apps", state))
- self.runtimes_switch.set_active(self.settings.get_boolean("show-runtimes"))
- self.runtimes_switch.connect("state-set", lambda switch, state: gschema_bool_setter("show-runtimes", state))
-
-
# Create Variables
event_controller = Gtk.EventControllerKey()
+ self.remotes_switch = Gtk.Switch(valign=Gtk.Align.CENTER)
+ self.runtimes_switch = Gtk.Switch(valign=Gtk.Align.CENTER)
+ self.main_window = main_window
+ self.settings = Gio.Settings.new("io.github.flattool.Warehouse.filter")
self.my_utils = myUtils(self)
self.host_remotes = self.my_utils.get_host_remotes()
- self.host_flatpaks = main_window.host_flatpaks
- self.filter_list = [False, False, [], [], []]
- self.app_window = main_window
- self.has_apply_button_been_clicked = False
+ self.show_apps_staging = self.settings.get_boolean("show-apps")
+ self.show_runtimes_staging = self.settings.get_boolean("show-runtimes")
+ self.remotes_string_staging = self.settings.get_string("remotes-list").split(
+ ","
+ )
+ self.runtimes_string_staging = self.settings.get_string("runtimes-list").split(
+ ","
+ )
# Window Things
self.set_transient_for(main_window)
self.add_controller(event_controller)
+ self.set_size_request(260, 230)
# Connections
- self.apply_button.connect(
- "clicked", lambda *_: self.set_has_apply_button_been_clicked(True)
- )
- # self.apply_button.connect(
- # "clicked", lambda *_: main_window.apply_filter(self.filter_list)
- # )
- # self.apply_button.connect("clicked", lambda *_: self.close())
-
- self.cancel_button.connect("clicked", lambda *_: self.close())
-
- # self.apps_switch.connect("state-set", self.apps_handler)
- # self.runtimes_switch.connect("state-set", self.runtimes_handler)
event_controller.connect("key-pressed", self.key_handler)
+ self.show_runtimes_switch.connect("state-set", self.show_runtimes_handler)
+ self.show_apps_switch.connect("state-set", self.show_apps_handler)
+ self.apply_button.connect("clicked", lambda *_: self.on_apply())
+ self.cancel_button.connect("clicked", lambda *_: self.close())
+ self.reset_button.connect("clicked", lambda *_: self.reset_filter_gsettings())
# Calls
- self.set_size_request(260, 230)
if not self.host_remotes[0][0] == "":
self.generate_list()
else:
self.remotes_expander.set_visible(False)
self.runtimes_expander.set_visible(False)
- self.filter_list[2] = "all"
- self.filter_list[3] = "all"
- self.filter_list[4] = "all"
+
+ self.show_apps_switch.set_active(self.show_apps_staging)
+ self.show_runtimes_switch.set_active(self.show_runtimes_staging)
+ self.present()
diff --git a/src/main.py b/src/main.py
index 40c0454..d5dff78 100644
--- a/src/main.py
+++ b/src/main.py
@@ -29,6 +29,7 @@ from gi.repository import Gtk, Gio, Adw, GLib
from .window import WarehouseWindow
from .remotes_window import RemotesWindow
from .orphans_window import OrphansWindow
+from .filter_window import FilterWindow
from .search_install_window import SearchInstallWindow
from .const import Config
@@ -115,8 +116,7 @@ class WarehouseApplication(Adw.Application):
RemotesWindow(self.props.active_window).present()
def filters_shortcut(self, widget, _):
- window = self.props.active_window
- window.filterWindowKeyboardHandler(window)
+ FilterWindow(self.props.active_window)
def main_menu_shortcut(self, widget, _):
window = self.props.active_window
diff --git a/src/window.py b/src/window.py
index fe4ca5e..04c255f 100644
--- a/src/window.py
+++ b/src/window.py
@@ -80,6 +80,7 @@ class WarehouseWindow(Adw.ApplicationWindow):
currently_uninstalling = False
is_result = False
is_empty = False
+ total_selected = 0
def filter_func(self, row):
if (self.search_entry.get_text().lower() in row.get_title().lower()) or (
@@ -336,6 +337,7 @@ class WarehouseWindow(Adw.ApplicationWindow):
self.create_row(index)
# self.windowSetEmpty(not self.flatpaks_list_box.get_row_at_index(0))
+ self.apply_filter()
self.batch_actions_enable(False)
self.main_stack.set_visible_child(self.main_box)
@@ -348,6 +350,36 @@ class WarehouseWindow(Adw.ApplicationWindow):
self.generate_list_of_flatpaks()
self.batch_mode_button.set_active(False)
+ def apply_filter(self):
+ settings = Gio.Settings.new("io.github.flattool.Warehouse.filter")
+ show_apps = settings.get_boolean("show-apps")
+ show_runtimes = settings.get_boolean("show-runtimes")
+ remotes_list = settings.get_string("remotes-list").split(",")
+ runtimes_list = settings.get_string("runtimes-list").split(",")
+ i = 0
+ while self.flatpaks_list_box.get_row_at_index(i) != None:
+ current = self.flatpaks_list_box.get_row_at_index(i)
+ id = current.app_id
+ dependant = current.dependent_runtime
+ remote = current.origin_remote
+ is_runtime = current.is_runtime
+
+ visible = True
+ if (not show_apps) and (not is_runtime):
+ visible = False
+
+ if (not show_runtimes) and is_runtime:
+ visible = False
+
+ if (not "all" in remotes_list) and (not remote in remotes_list):
+ visible = False
+
+ if (not "all" in runtimes_list) and (not dependant in runtimes_list):
+ visible = False
+
+ current.set_is_visible(visible)
+ i += 1
+
def open_data_folder(self, path):
try:
Gio.AppInfo.launch_default_for_uri(f"file://{path}", None)