Skip to content

Commit

Permalink
Merge pull request #136 from SylviaSK/main
Browse files Browse the repository at this point in the history
Fix for #119, Prompt for new location user if library cannot be saved
  • Loading branch information
CyanVoxel committed May 5, 2024
2 parents c27f99e + 78ea0b3 commit ec55e92
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions tagstudio/src/qt/ts_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,23 +551,42 @@ def shutdown(self):
thread.wait()
QApplication.quit()

def save_library(self):
def save_library(self, show_status=True):
logging.info(f"Saving Library...")
self.main_window.statusbar.showMessage(f"Saving Library...")
start_time = time.time()
self.lib.save_library_to_disk()
end_time = time.time()
self.main_window.statusbar.showMessage(
f"Library Saved! ({format_timespan(end_time - start_time)})"
)
if show_status:
self.main_window.statusbar.showMessage(f"Saving Library...")
start_time = time.time()
# This might still be able to error, if the selected directory deletes in a race condition
# or something silly like that. Hence the loop, but if this is considered overkill, thats fair.
while True:
try:
self.lib.save_library_to_disk()
break
# If the parent directory got moved, or deleted, prompt user for where to save.
except FileNotFoundError:
logging.info(
"Library parent directory not found, prompting user to select the directory"
)
dir = QFileDialog.getExistingDirectory(
None,
"Library Location not found, please select location to save Library",
"/",
QFileDialog.ShowDirsOnly,
)
if dir not in (None, ""):
self.lib.library_dir = dir
if show_status:
end_time = time.time()
self.main_window.statusbar.showMessage(
f"Library Saved! ({format_timespan(end_time - start_time)})"
)

def close_library(self):
if self.lib.library_dir:
# TODO: it is kinda the same code from "save_library"...
logging.info(f"Closing & Saving Library...")
self.main_window.statusbar.showMessage(f"Closed & Saving Library...")
logging.info(f"Closing Library...")
self.main_window.statusbar.showMessage(f"Closing & Saving Library...")
start_time = time.time()
self.lib.save_library_to_disk()
self.save_library(show_status=False)
self.settings.setValue("last_library", self.lib.library_dir)
self.settings.sync()

Expand Down

0 comments on commit ec55e92

Please sign in to comment.