Skip to content

Commit

Permalink
Sync current work
Browse files Browse the repository at this point in the history
  • Loading branch information
heliguy4599 committed Sep 21, 2023
1 parent aae54f2 commit f4ab22b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
13 changes: 6 additions & 7 deletions src/functions.py → src/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import subprocess
import pathlib

class functions():
class myUtils:
def __init__(self, window, **kwargs):
super().__init__(**kwargs)
self.main_window = window
self.host_home = str(pathlib.Path.home())
self.user_data_path = self.host_home + "/.var/app/"

def trash_folder(self, path):
def trashFolder(self, path):
if not os.path.exists(path):
return 1
try:
Expand All @@ -19,7 +18,7 @@ def trash_folder(self, path):
except subprocess.CalledProcessError:
return 2

def get_size_format(self, b):
def getSizeFormat(self, b):
factor = 1024
suffix = "B"
for unit in ["", "K", "M", "G", "T", "P", "E", "Z"]:
Expand All @@ -28,7 +27,7 @@ def get_size_format(self, b):
b /= factor
return f"{b:.1f}{suffix}"

def get_directory_size(self, directory):
def getDirectorySize(self, directory):
"""Returns the `directory` size in bytes."""
total = 0
try:
Expand All @@ -42,7 +41,7 @@ def get_directory_size(self, directory):
elif entry.is_dir():
# if it's a directory, recursively call this function
try:
total += self.get_directory_size(entry.path)
total += self.getDirectorySize(entry.path)
except FileNotFoundError:
pass
except NotADirectoryError:
Expand All @@ -53,7 +52,7 @@ def get_directory_size(self, directory):
return 0
return total

def find_app_icon(self, app_id):
def findAppIcon(self, app_id):
icon_theme = Gtk.IconTheme.new()
icon_theme.add_search_path("/var/lib/flatpak/exports/share/icons/")
icon_theme.add_search_path(self.host_home + "/.local/share/flatpak/exports/share/icons")
Expand Down
2 changes: 1 addition & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ warehouse_sources = [
'properties_window.py',
'orphans_window.py',
'remotes.py',
'functions.py',
'common.py',
]

install_data(warehouse_sources, install_dir: moduledir)
10 changes: 5 additions & 5 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from gi.repository import Adw, Gdk, Gio, GLib, Gtk
from .properties_window import show_properties_window
from .orphans_window import show_orphans_window
from .functions import functions
from .common import myUtils

@Gtk.Template(resource_path="/io/github/heliguy4599/Warehouse/window.ui")
class WarehouseWindow(Adw.ApplicationWindow):
Expand Down Expand Up @@ -258,7 +258,7 @@ def generate_list(widget, is_select_all):
if not file_list[i] in id_list:
row_index += 1
select_orphans_tickbox = Gtk.CheckButton(halign=Gtk.Align.CENTER)
orphans_row = Adw.ActionRow(title=GLib.markup_escape_text(file_list[i]), subtitle=_("~") + self.func.get_size_format(self.func.get_directory_size(f"{self.user_data_path}{file_list[i]}")))
orphans_row = Adw.ActionRow(title=GLib.markup_escape_text(file_list[i]), subtitle=_("~") + self.my_utils.getSizeFormat(self.my_utils.getDirectorySize(f"{self.user_data_path}{file_list[i]}")))
orphans_row.add_suffix(select_orphans_tickbox)
orphans_row.set_activatable_widget(select_orphans_tickbox)
select_orphans_tickbox.connect("toggled", selection_handler, orphans_row.get_title())
Expand Down Expand Up @@ -458,7 +458,7 @@ def get_host_flatpaks():
app_id = self.host_flatpaks[index][2]
app_ref = self.host_flatpaks[index][8]
flatpak_row = Adw.ActionRow(title=GLib.markup_escape_text(app_name))
flatpak_row.add_prefix(self.func.find_app_icon(app_id))
flatpak_row.add_prefix(self.my_utils.findAppIcon(app_id))

if (not self.show_runtimes) and "runtime" in self.host_flatpaks[index][12]:
continue
Expand Down Expand Up @@ -543,7 +543,7 @@ def on_batch_clean_response(self, dialog, response, _a):
app_id = self.host_flatpaks[self.selected_host_flatpak_indexes[i]][2]
app_name = self.host_flatpaks[self.selected_host_flatpak_indexes[i]][0]
path = f"{self.user_data_path}{app_id}"
trash = self.func.trash_folder(None, path)
trash = self.my_utils.trash_folder(None, path)
if trash == 1:
show_success = False
self.toast_overlay.add_toast(Adw.Toast.new(_("No user data for {}").format(app_name)))
Expand Down Expand Up @@ -588,7 +588,7 @@ def flatpak_row_select_handler(self, tickbox, index):

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.func = functions(self)
self.my_utils = myUtils(self)
self.list_of_flatpaks.set_filter_func(self.filter_func)
self.set_size_request(0, 230)
self.generate_list_of_flatpaks()
Expand Down

0 comments on commit f4ab22b

Please sign in to comment.