1919from itertools import zip_longest
2020from pathlib import Path
2121from queue import Queue
22+ import datetime
2223
2324# this import has side-effect of import PySide resources
2425import src .qt .resources_rc # noqa: F401
100101from src .qt .widgets .preview_panel import PreviewPanel
101102from src .qt .widgets .progress import ProgressWidget
102103from src .qt .widgets .thumb_renderer import ThumbRenderer
104+ from src .core .tscacheddata import TSCachedData
103105
104106# SIGQUIT is not defined on Windows
105107if sys .platform == "win32" :
@@ -171,19 +173,18 @@ def __init__(self, backend, args):
171173 if not path .exists ():
172174 logger .warning ("Config File does not exist creating" , path = path )
173175 logger .info ("Using Config File" , path = path )
174- self .settings = QSettings ( str ( path ), QSettings . Format . IniFormat )
176+ self .settings = TSSettings . read_settings ( path )
175177 else :
176- self .settings = QSettings (
177- QSettings .Format .IniFormat ,
178- QSettings .Scope .UserScope ,
179- "TagStudio" ,
180- "TagStudio" ,
181- )
178+ path = Path .home () / ".TagStudio" / "config.toml"
179+ self .settings = TSSettings .read_settings (path )
182180 logger .info (
183181 "Config File not specified, using default one" ,
184- filename = self .settings .fileName () ,
182+ filename = self .settings .filename ,
185183 )
186184
185+
186+ self .cache = TSCachedData .open ()
187+
187188 def init_workers (self ):
188189 """Init workers for rendering thumbnails."""
189190 if not self .thumb_threads :
@@ -245,12 +246,6 @@ def start(self) -> None:
245246 self .main_window .dragMoveEvent = self .drag_move_event # type: ignore[method-assign]
246247 self .main_window .dropEvent = self .drop_event # type: ignore[method-assign]
247248
248- self .settings_path = (
249- Path .home () / ".config/TagStudio" / "settings.toml"
250- ) # TODO: put this somewhere else
251- self .newSettings = TSSettings .read_settings (
252- self .settings_path
253- ) # TODO: make this cross-platform
254249
255250 splash_pixmap = QPixmap (":/images/splash.png" )
256251 splash_pixmap .setDevicePixelRatio (self .main_window .devicePixelRatio ())
@@ -382,10 +377,10 @@ def start(self) -> None:
382377 check_action = QAction ("Open library on start" , self )
383378 check_action .setCheckable (True )
384379 check_action .setChecked (
385- bool ( self .settings .value ( SettingItems . START_LOAD_LAST , defaultValue = True , type = bool ))
380+ self .settings .open_last_loaded_on_startup
386381 )
387382 check_action .triggered .connect (
388- lambda checked : self .settings . setValue ( SettingItems . START_LOAD_LAST , checked )
383+ lambda checked : setattr ( self .settings , "open_last_loaded_on_startup" , checked )
389384 )
390385 window_menu .addAction (check_action )
391386
@@ -425,11 +420,11 @@ def create_dupe_files_modal():
425420 show_libs_list_action = QAction ("Show Recent Libraries" , menu_bar )
426421 show_libs_list_action .setCheckable (True )
427422 show_libs_list_action .setChecked (
428- bool ( self .settings .value ( SettingItems . WINDOW_SHOW_LIBS , defaultValue = True , type = bool ))
423+ self .settings .show_library_list
429424 )
430425 show_libs_list_action .triggered .connect (
431426 lambda checked : (
432- self .settings . setValue ( SettingItems . WINDOW_SHOW_LIBS , checked ),
427+ setattr ( self .settings , "show_library_list" , checked ),
433428 self .toggle_libs_list (checked ),
434429 )
435430 )
@@ -597,7 +592,7 @@ def close_library(self, is_shutdown: bool = False):
597592 self .main_window .statusbar .showMessage ("Closing Library..." )
598593 start_time = time .time ()
599594
600- self .settings . setValue ( SettingItems . LAST_LIBRARY , str ( self .lib .library_dir ))
595+ self .cache . last_library = self .lib .library_dir
601596 self .settings .sync ()
602597
603598 self .lib .close ()
@@ -654,7 +649,7 @@ def add_tag_action_callback(self):
654649
655650 def open_settings_menu (self ):
656651 self .modal = PanelModal (
657- SettingsModal (self .newSettings ),
652+ SettingsModal (self .settings ),
658653 "Settings" ,
659654 "Settings" ,
660655 has_save = True ,
@@ -664,8 +659,8 @@ def open_settings_menu(self):
664659 self .modal .show ()
665660
666661 def update_settings (self , settings : TSSettings ):
667- self .newSettings = settings
668- self .newSettings .save (self .settings_path )
662+ self .settings = settings
663+ self .settings .save (self .settings . filename )
669664
670665 def select_all_action_callback (self ):
671666 self .selected = list (range (0 , len (self .frame_content )))
@@ -1183,31 +1178,52 @@ def remove_recent_library(self, item_key: str):
11831178 self .settings .endGroup ()
11841179 self .settings .sync ()
11851180
1181+ self .cache .library_history .pop (datetime .datetime .strptime (item_key ))
1182+
1183+
11861184 def update_libs_list (self , path : Path | str ):
1187- """Add library to list in SettingItems.LIBS_LIST. """
1185+ """Add library to list in tssettings """
11881186 item_limit : int = 5
11891187 path = Path (path )
11901188
1191- self .settings .beginGroup (SettingItems .LIBS_LIST )
1192-
11931189 all_libs = {str (time .time ()): str (path )}
11941190
1195- for item_key in self .settings . allKeys () :
1196- item_path = str ( self .settings . value ( item_key , type = str ))
1197- if Path (item_path ) != path :
1198- all_libs [item_key ] = item_path
1191+ for access_time in self .cache . library_history :
1192+ lib = self .cache . library_history [ access_time ]
1193+ if Path (lib ) != path :
1194+ all_libs [str ( access_time ) ] = lib
11991195
1200- # sort items, most recent first
12011196 all_libs_list = sorted (all_libs .items (), key = lambda item : item [0 ], reverse = True )
1197+ self .cache .library_history = {}
1198+ for key , value in all_libs_list [:item_limit ]:
1199+ self .cache .library_history [key ] = value
12021200
1203- # remove previously saved items
1204- self .settings .remove ("" )
12051201
1206- for item_key , item_value in all_libs_list [:item_limit ]:
1207- self .settings .setValue (item_key , item_value )
1202+ #def update_libs_list(self, path: Path | str):
1203+ # """Add library to list in SettingItems.LIBS_LIST."""
1204+ # item_limit: int = 5
1205+ # path = Path(path)
12081206
1209- self .settings .endGroup ()
1210- self .settings .sync ()
1207+ # self.settings.beginGroup(SettingItems.LIBS_LIST)
1208+
1209+ # all_libs = {str(time.time()): str(path)}
1210+
1211+ # for item_key in self.settings.allKeys():
1212+ # item_path = str(self.settings.value(item_key, type=str))
1213+ # if Path(item_path) != path:
1214+ # all_libs[item_key] = item_path
1215+
1216+ # # sort items, most recent first
1217+ # all_libs_list = sorted(all_libs.items(), key=lambda item: item[0], reverse=True)
1218+
1219+ # # remove previously saved items
1220+ # self.settings.remove("")
1221+
1222+ # for item_key, item_value in all_libs_list[:item_limit]:
1223+ # self.settings.setValue(item_key, item_value)
1224+
1225+ # self.settings.endGroup()
1226+ # self.settings.sync()
12111227
12121228 def open_library (self , path : Path ) -> None :
12131229 """Open a TagStudio library."""
0 commit comments