Skip to content

Commit 4be67b8

Browse files
authored
Improve the importing process (#515)
2 parents 6a6483a + 44813aa commit 4be67b8

File tree

5 files changed

+98
-31
lines changed

5 files changed

+98
-31
lines changed

data/io.github.vikdevelop.SaveDesktop.metainfo.xml.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<li>Redesigned Flatpak apps selection: shows app names (not IDs) and backs up selected apps together with their user data</li>
7575
<li>New: Sync selected configuration items across PCs to keep archives consistent</li>
7676
<li>Updated archive structure with full backward compatibility for older backups</li>
77+
<li>During import, only what is actually in the archive will be displayed in the item selection dialog</li>
7778
<li>Updated translations</li>
7879
</ul>
7980
</description>

io.github.vikdevelop.SaveDesktop.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
{
4848
"type" : "git",
4949
"url" : "https://github.com/ip7z/7zip.git",
50-
"tag" : "25.01",
51-
"commit" : "5e96a8279489832924056b1fa82f29d5837c9469"
50+
"tag" : "26.00",
51+
"commit" : "839151eaaad24771892afaae6bac690e31e58384"
5252
}
5353
],
5454
"x-checker-data" : {

src/core/de_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def export_flatpaks(path, output_file, install_type):
8484
f.write(f"flatpak install --{install_type} {app} -y\n")
8585

8686
def create_flatpak_list():
87+
os.makedirs("Flatpak_Apps", exist_ok=True)
8788
export_flatpaks('/var/lib/flatpak/app/', 'Flatpak_Apps/installed_flatpaks.sh', 'system')
8889
export_flatpaks(f'{home}/.local/share/flatpak/app', 'Flatpak_Apps/installed_user_flatpaks.sh', 'user')
8990
print("[OK] Saving Flatpak app list")
@@ -264,8 +265,6 @@ class Save:
264265
def __init__(self):
265266
os.makedirs("General", exist_ok=True)
266267
os.makedirs("DE", exist_ok=True)
267-
os.makedirs("Flatpak_Apps", exist_ok=True)
268-
os.makedirs("Custom_Dirs", exist_ok=True)
269268

270269
# General dirs
271270
for item in GENERAL_ITEMS.values():
@@ -280,6 +279,7 @@ def __init__(self):
280279

281280
# Custom dirs
282281
for folder in settings["custom-dirs"]:
282+
os.makedirs("Custom_Dirs", exist_ok=True)
283283
short_folder = Path(folder).relative_to(home)
284284
safe_copytree(folder, f"Custom_Dirs/{short_folder}")
285285

src/gui/items_dialog.py

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
from savedesktop.gui.flatpak_apps_dialog import FolderSwitchRow, FlatpakAppsDialog
77
from savedesktop.core.synchronization_setup import create_savedesktop_json
88
from savedesktop.globals import *
9-
9+
1010
class itemsDialog(Adw.AlertDialog):
11-
def __init__(self, parent):
11+
def __init__(self, parent, items_list=None):
1212
super().__init__()
1313
self.parent = parent
14+
self.items_list = items_list if items_list is not None else []
15+
print(self.items_list)
1416

1517
self.set_heading(_("Select configuration items"))
1618
self.set_body(_("These settings are used for manual and periodic saves, imports, and synchronization."))
@@ -34,7 +36,8 @@ def __init__(self, parent):
3436
self.icons_row.set_subtitle_lines(3)
3537
self.icons_row.add_suffix(self.switch_01)
3638
self.icons_row.set_activatable_widget(self.switch_01)
37-
self.itemsBox.append(child=self.icons_row)
39+
if self.should_show("icon-themes.tgz", "icon-themes-legacy.tgz"):
40+
self.itemsBox.append(child=self.icons_row)
3841

3942
# Switch and row of option 'Save themes'
4043
self.switch_02 = Gtk.Switch.new()
@@ -49,7 +52,8 @@ def __init__(self, parent):
4952
self.themes_row.set_subtitle_lines(3)
5053
self.themes_row.add_suffix(self.switch_02)
5154
self.themes_row.set_activatable_widget(self.switch_02)
52-
self.itemsBox.append(child=self.themes_row)
55+
if self.should_show(".themes", "themes"):
56+
self.itemsBox.append(child=self.themes_row)
5357

5458
# Switch and row of option 'Save fonts'
5559
self.switch_03 = Gtk.Switch.new()
@@ -64,7 +68,8 @@ def __init__(self, parent):
6468
self.fonts_row.set_subtitle_lines(3)
6569
self.fonts_row.add_suffix(self.switch_03)
6670
self.fonts_row.set_activatable_widget(self.switch_03)
67-
self.itemsBox.append(child=self.fonts_row)
71+
if self.should_show("fonts", ".fonts"):
72+
self.itemsBox.append(child=self.fonts_row)
6873

6974
# Switch and row of option 'Save backgrounds'
7075
self.switch_04 = Gtk.Switch.new()
@@ -79,7 +84,8 @@ def __init__(self, parent):
7984
self.backgrounds_row.set_subtitle_lines(3)
8085
self.backgrounds_row.add_suffix(self.switch_04)
8186
self.backgrounds_row.set_activatable_widget(self.switch_04)
82-
self.itemsBox.append(child=self.backgrounds_row)
87+
if self.should_show("backgrounds"):
88+
self.itemsBox.append(child=self.backgrounds_row)
8389

8490
# show extension switch and row if user has installed these environments
8591
if environment["de_name"] in ["GNOME", "Cinnamon", "COSMIC (Old)", "KDE Plasma"]:
@@ -100,7 +106,8 @@ def __init__(self, parent):
100106
self.gtk_row.set_subtitle_lines(3)
101107
self.gtk_row.add_suffix(self.switch_gtk)
102108
self.gtk_row.set_activatable_widget(self.switch_gtk)
103-
self.itemsBox.append(child=self.gtk_row)
109+
if self.should_show("gtk-3.0"):
110+
self.itemsBox.append(child=self.gtk_row)
104111

105112
# Switch and row of option 'Save Desktop' (~/Desktop)
106113
self.switch_de = Gtk.Switch.new()
@@ -116,7 +123,8 @@ def __init__(self, parent):
116123
self.desktop_row.set_title_lines(2)
117124
self.desktop_row.add_suffix(self.switch_de)
118125
self.desktop_row.set_activatable_widget(self.switch_de)
119-
self.itemsBox.append(child=self.desktop_row)
126+
if self.should_show("desktop-folder.tgz"):
127+
self.itemsBox.append(child=self.desktop_row)
120128

121129
# Custom directories section
122130
self.custom_button = Gtk.Button.new_from_icon_name("go-next-symbolic")
@@ -128,9 +136,10 @@ def __init__(self, parent):
128136
self.custom_row.set_title("Custom folders")
129137
self.custom_row.add_suffix(self.custom_button)
130138
self.custom_row.set_activatable_widget(self.custom_button)
131-
self.itemsBox.append(child=self.custom_row)
139+
if self.should_show("Custom_Dirs"):
140+
self.itemsBox.append(child=self.custom_row)
132141

133-
if flatpak:
142+
if flatpak and self.should_show("installed_flatpaks.sh"):
134143
self.flatpak_row = Adw.ExpanderRow.new()
135144
self.flatpak_row.set_title(title=_("Flatpak apps"))
136145
self.flatpak_row.set_subtitle(f"<a href='https://vikdevelop.github.io/SaveDesktop/wiki/flatpak_apps/{language}'>{_('Learn more')}</a>")
@@ -178,7 +187,6 @@ def __init__(self, parent):
178187
if settings["save-flatpak-data"]:
179188
self.switch_06.set_active(True)
180189
self.data_row.add_suffix(self.appsButton)
181-
self.flatpak_data_sw_state = settings["save-flatpak-data"]
182190
self.switch_06.set_valign(align=Gtk.Align.CENTER)
183191

184192
self.switch_07 = Gtk.Switch.new()
@@ -207,7 +215,18 @@ def __init__(self, parent):
207215
self.add_response('ok', _("Apply"))
208216
self.set_response_appearance('ok', Adw.ResponseAppearance.SUGGESTED)
209217
self.connect('response', self.itemsdialog_closed)
210-
218+
219+
def should_show(self, *search_terms):
220+
if not self.items_list:
221+
return True
222+
223+
for term in search_terms:
224+
for item in self.items_list:
225+
if term in item:
226+
return True
227+
228+
return False
229+
211230
def _set_sw05_sensitivity(self, GParamBoolean, switch_05):
212231
if not self.switch_05.get_active():
213232
self.switch_06.set_sensitive(False)
@@ -219,7 +238,7 @@ def _set_sw05_sensitivity(self, GParamBoolean, switch_05):
219238
self.switch_07.set_sensitive(True)
220239

221240
def _show_custom_dirs_dialog(self, w):
222-
self.CDDialog = CustomDirsDialog(self.parent)
241+
self.CDDialog = CustomDirsDialog(self.parent, self.items_list)
223242
self.CDDialog.choose(self.parent, None, None, None)
224243
self.CDDialog.present(self.parent)
225244

@@ -244,7 +263,8 @@ def show_extensions_row(self):
244263
self.ext_row.set_subtitle_lines(3)
245264
self.ext_row.add_suffix(self.switch_ext)
246265
self.ext_row.set_activatable_widget(self.switch_ext)
247-
self.itemsBox.append(child=self.ext_row)
266+
if self.should_show("cinnamon", "gnome-shell", "plasma"):
267+
self.itemsBox.append(child=self.ext_row)
248268

249269
# Action after closing itemsDialog
250270
def itemsdialog_closed(self, w, response):
@@ -265,8 +285,3 @@ def itemsdialog_closed(self, w, response):
265285
settings["keep-flatpaks"] = self.switch_07.get_active()
266286
if hasattr(self, "switch_ext"):
267287
settings["save-extensions"] = self.switch_ext.get_active()
268-
self.save_ext_switch_state = False
269-
elif response == 'cancel':
270-
if flatpak:
271-
switch_status = self.flatpak_data_sw_state
272-
settings["save-flatpak-data"] = switch_status

src/gui/window.py

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
2-
import os, sys, re, zipfile, random, string, gi, subprocess, locale, shutil
2+
import os, sys, re, zipfile, random, string, gi, subprocess, locale, shutil, tarfile
33
gi.require_version('Gtk', '4.0')
44
gi.require_version('Adw', '1')
55
from gi.repository import Gtk, Adw, Gio, GLib, Gdk
@@ -537,20 +537,71 @@ def import_config(self):
537537

538538
self._show_items_dialog()
539539

540+
# Get items which are available in the configuration archive or folder
541+
def _get_archive_items(self):
542+
tmp_file_path = f"{CACHE}/workspace/temp_file"
543+
if os.path.exists(tmp_file_path):
544+
with open(tmp_file_path) as f:
545+
password = f.read().strip()
546+
else:
547+
password = None
548+
549+
if self.archive_name.endswith(".sd.zip"):
550+
if password:
551+
result = subprocess.run(
552+
["7z", "l", "-slt", f"-p{password}", self.archive_name],
553+
capture_output=True,
554+
text=True,
555+
check=True
556+
)
557+
else:
558+
result = subprocess.run(
559+
["7z", "l", "-slt", self.archive_name],
560+
capture_output=True,
561+
text=True,
562+
check=True
563+
)
564+
565+
paths = []
566+
for line in result.stdout.splitlines():
567+
if line.startswith("Path = "):
568+
paths.append(line[7:])
569+
570+
elif self.archive_name.endswith(".sd.tar.gz"):
571+
with tarfile.open(self.archive_name, "r:*") as tar:
572+
paths = [m.name for m in tar.getmembers()]
573+
else:
574+
cfg = Path(self.archive_name)
575+
576+
paths = [
577+
str(f.relative_to(cfg))
578+
for f in cfg.rglob("*")
579+
if f.is_file()
580+
]
581+
582+
return paths
583+
540584
def _show_items_dialog(self):
541-
self.items_dialog = itemsDialog(self)
542-
self.items_dialog.choose(self, None, None, None)
543-
self.items_dialog.connect("response", self._on_items_dialog_response)
544-
self.items_dialog.present(self)
585+
self.archive_items = self._get_archive_items()
586+
self.items_dialog = itemsDialog(self, self.archive_items)
587+
if not self.items_dialog.itemsBox.observe_children().get_n_items() == 0:
588+
self.items_dialog.choose(self, None, None, None)
589+
self.items_dialog.connect("response", self._on_items_dialog_response)
590+
self.items_dialog.present(self)
591+
else:
592+
self._start_gui()
545593

546594
def _on_items_dialog_response(self, dialog, response, *args):
547595
if response == "cancel":
548596
pass
549597
elif response == "ok":
550598
print("Importing the configuration is in progress…")
551-
self.please_wait()
552-
import_thread = Thread(target=self._call_archive_command)
553-
import_thread.start()
599+
self._start_gui()
600+
601+
def _start_gui(self):
602+
self.please_wait()
603+
import_thread = Thread(target=self._call_archive_command)
604+
import_thread.start()
554605

555606
def _call_archive_command(self):
556607
self.archive_proc = subprocess.Popen(

0 commit comments

Comments
 (0)