Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend: Revamp Import #2633

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 91 additions & 1 deletion bottles/frontend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
from bottles.frontend.windows.main_window import MainWindow
from bottles.frontend.views.preferences import PreferencesWindow
from bottles.backend.health import HealthChecker
from bottles.backend.utils.threading import RunAsync
from bottles.backend.managers.backup import BackupManager

from bottles.frontend.utils.filters import add_yaml_filters, add_all_filters

logging = Logger()

Expand Down Expand Up @@ -88,7 +92,8 @@ def __init__(self):
)
self.__create_action('quit', self.__quit, ['<primary>q', '<primary>w'])
self.__create_action('about', self.__show_about_window)
self.__create_action('import', self.__show_importer_view, ['<primary>i'])
self.__create_action('import', self.__import_conf, ['<primary>i'])
self.__create_action('restore', self.__restore_backup, ['<primary>r'])
self.__create_action('preferences', self.__show_preferences, ['<primary>comma'])
self.__create_action('help', self.__help, ['F1'])

Expand Down Expand Up @@ -233,6 +238,7 @@ def do_activate(self):
arg_bottle=self.arg_bottle
)
self.win = win
self.manager = win.manager
win.present()

@staticmethod
Expand Down Expand Up @@ -352,6 +358,90 @@ def __create_action(self, name, callback, shortcuts=None, param=None):
if shortcuts:
self.set_accels_for_action(f"app.{name}", shortcuts)

def __import_conf(self, *_args):
"""
This function shows a dialog to the user, from which it can choose an
archive backup to import into Bottles. It supports only .yml files
which are the Bottles' configuration file. Once selected, it will
be imported.
"""
def set_path(_dialog, response):
if response != Gtk.ResponseType.ACCEPT:
return

def finish(_widget, result, error=False):
if result.status:
self.win.show_toast(_("Configuration imported successfully"))
else:
self.win.show_toast(_("Importing configuration failed"))

self.win.show_toast(_("Importing backup…"))
RunAsync(
task_func=BackupManager.import_backup,
callback=finish,
window=self.win,
scope="config",
path=dialog.get_file().get_path(),
manager=self.manager
)

dialog = Gtk.FileChooserNative.new(
title=_("Select Configuration"),
action=Gtk.FileChooserAction.OPEN,
parent=self.win,
accept_label=_("Import")
)

add_yaml_filters(dialog)
add_all_filters(dialog)
dialog.set_modal(True)
dialog.connect("response", set_path)
dialog.show()

def __restore_backup(self, *_args):
"""
This function shows a dialog to the user, from which it can choose an
archive backup to import into Bottles. It supports only .tar.gz files
as Bottles export bottles in this format. Once selected, it will
be imported.
"""
def set_path(_dialog, response):
if response != Gtk.ResponseType.ACCEPT:
return

def finish(_widget, result, error=False):
if result.status:
self.win.show_toast(_("Backup restored successfully"))
else:
self.win.show_toast(_("Restoring backup failed"))

self.win.show_toast(_("Importing backup…"))
RunAsync(
task_func=BackupManager.import_backup,
callback=finish,
window=self.win,
scope="full",
path=dialog.get_file().get_path(),
manager=self.manager
)

dialog = Gtk.FileChooserNative.new(
title=_("Select Backup Archive"),
action=Gtk.FileChooserAction.OPEN,
parent=self.win,
accept_label=_("Import")
)

filter = Gtk.FileFilter()
filter.set_name("GNU Gzip Archive")
filter.add_mime_type("application/gzip")

dialog.add_filter(filter)
add_all_filters(dialog)
dialog.set_modal(True)
dialog.connect("response", set_path)
dialog.show()

GObject.threads_init()


Expand Down
2 changes: 0 additions & 2 deletions bottles/frontend/ui/bottles.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<file>task-entry.ui</file>
<file>dependency-entry.ui</file>
<file>program-entry.ui</file>
<file>importer-entry.ui</file>
<file>state-entry.ui</file>
<file>installer-entry.ui</file>
<file>dll-override-entry.ui</file>
Expand All @@ -29,7 +28,6 @@
<file>details-versioning.ui</file>
<file>details-taskmanager.ui</file>
<file>preferences.ui</file>
<file>importer.ui</file>
<file>library.ui</file>
<file>dialog-launch-options.ui</file>
<file>dialog-dll-overrides.ui</file>
Expand Down
75 changes: 0 additions & 75 deletions bottles/frontend/ui/importer-entry.blp

This file was deleted.

77 changes: 0 additions & 77 deletions bottles/frontend/ui/importer.blp

This file was deleted.

2 changes: 0 additions & 2 deletions bottles/frontend/ui/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ blueprints = custom_target('blueprints',
'drive-entry.blp',
'env-var-entry.blp',
'exclusion-pattern-entry.blp',
'importer-entry.blp',
'importer.blp',
'installer-entry.blp',
'library-entry.blp',
'library.blp',
Expand Down
6 changes: 5 additions & 1 deletion bottles/frontend/ui/window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,13 @@ template MainWindow : .AdwApplicationWindow {
menu primary_menu {
section {
item {
label: _("Import…");
label: _("Import Configuration…");
action: "app.import";
}
item {
label: _("Restore Backup…");
action: "app.restore";
}
}

section {
Expand Down
1 change: 0 additions & 1 deletion bottles/frontend/views/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ bottles_sources = [
'library.py',
'details.py',
'preferences.py',
'importer.py',
'loading.py',

'bottle_details.py',
Expand Down
7 changes: 0 additions & 7 deletions bottles/frontend/windows/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
from bottles.frontend.params import *
from bottles.frontend.utils.gtk import GtkUtils
from bottles.frontend.views.details import DetailsView
from bottles.frontend.views.importer import ImporterView
from bottles.frontend.views.library import LibraryView
from bottles.frontend.views.list import BottleView
from bottles.frontend.views.loading import LoadingView
Expand Down Expand Up @@ -176,14 +175,11 @@ def set_manager(result: Manager, error=None):
# Pages
self.page_details = DetailsView(self)
self.page_list = BottleView(self, arg_bottle=self.arg_bottle)
self.page_importer = ImporterView(self)
self.page_library = LibraryView(self)

self.main_leaf.append(self.page_details)
self.main_leaf.append(self.page_importer)

self.main_leaf.get_page(self.page_details).set_navigatable(False)
self.main_leaf.get_page(self.page_importer).set_navigatable(False)

self.stack_main.add_titled(
child=self.page_list,
Expand Down Expand Up @@ -276,9 +272,6 @@ def show_add_view(self, widget=False):
def show_list_view(self, widget=False):
self.stack_main.set_visible_child_name("page_list")

def show_importer_view(self, widget=False):
self.main_leaf.set_visible_child(self.page_importer)

def show_prefs_view(self, widget=False, view=0):
preferences_window = PreferencesWindow(self)
preferences_window.present()
Expand Down