22
22
from gi .repository import Gtk , Gdk , Gio , XApp , GdkPixbuf
23
23
24
24
# 3. Local application/library specific imports.
25
- from common import _async , idle , WebAppManager , download_favicon , BROWSER_TYPE_FIREFOX , BROWSER_TYPE_FIREFOX_FLATPAK , BROWSER_TYPE_ZEN_FLATPAK , BROWSER_TYPE_FIREFOX_SNAP , export_config , import_config , ei_task , check_browser_directories_tar
25
+ from common import _async , idle , WebAppManager , download_favicon , BROWSER_TYPE_FIREFOX , BROWSER_TYPE_FIREFOX_FLATPAK , BROWSER_TYPE_ZEN_FLATPAK , BROWSER_TYPE_FIREFOX_SNAP , export_config , import_config , ei_task , ICONS_DIR
26
26
27
27
setproctitle .setproctitle ("webapp-manager" )
28
28
38
38
CATEGORY_ID , CATEGORY_NAME = range (2 )
39
39
BROWSER_OBJ , BROWSER_NAME = range (2 )
40
40
41
+ # Gladefiles
42
+ MAIN_WINDOW_GLADEFILE = "/usr/share/webapp-manager/webapp-manager.ui"
43
+ SHORTCUTS_GLADEFILE = "/usr/share/webapp-manager/shortcuts.ui"
44
+ EI_TOOL_GLADEFILE = "/usr/share/webapp-manager/ei_tool.ui"
41
45
42
46
class MyApplication (Gtk .Application ):
43
47
# Main initialization routine
@@ -68,10 +72,9 @@ def __init__(self, application):
68
72
self .icon_theme = Gtk .IconTheme .get_default ()
69
73
70
74
# Set the Glade file
71
- gladefile = "/usr/share/webapp-manager/webapp-manager.ui"
72
75
self .builder = Gtk .Builder ()
73
76
self .builder .set_translation_domain (APP )
74
- self .builder .add_from_file (gladefile )
77
+ self .builder .add_from_file (MAIN_WINDOW_GLADEFILE )
75
78
self .window = self .builder .get_object ("main_window" )
76
79
self .window .set_title (_ ("Web Apps" ))
77
80
self .window .set_icon_name ("webapp-manager" )
@@ -238,10 +241,9 @@ def data_func_surface(self, column, cell, model, iter_, *args):
238
241
cell .set_property ("surface" , surface )
239
242
240
243
def open_keyboard_shortcuts (self , widget ):
241
- gladefile = "/usr/share/webapp-manager/shortcuts.ui"
242
244
builder = Gtk .Builder ()
243
245
builder .set_translation_domain (APP )
244
- builder .add_from_file (gladefile )
246
+ builder .add_from_file (SHORTCUTS_GLADEFILE )
245
247
window = builder .get_object ("shortcuts-webappmanager" )
246
248
window .set_title (_ ("Web Apps" ))
247
249
window .show ()
@@ -555,28 +557,23 @@ def load_webapps(self):
555
557
# Export and Import feature "ei"
556
558
def open_ei_tool (self , action ):
557
559
# Open the import / export window
558
- gladefile = "/usr/share/webapp-manager/ei_tool.ui"
559
560
builder = Gtk .Builder ()
560
561
builder .set_translation_domain (APP )
561
- builder .add_from_file (gladefile )
562
+ builder .add_from_file (EI_TOOL_GLADEFILE )
562
563
window = builder .get_object ("window" )
564
+
563
565
# Translate text and prepare widgets
564
566
if action == "export" :
565
567
window .set_title (_ ("Export Tool" ))
566
568
else :
567
569
window .set_title (_ ("Import Tool" ))
568
570
builder .get_object ("choose_location_text" ).set_text (_ ("Choose a location" ))
569
- builder .get_object ("include_browserdata" ).set_label (_ ("BETA: Include Browser data (Config, Cache, Extensions...)\n It requires the same browser version on the destination computer\n It might take some time." ))
570
- builder .get_object ("no_browser_data" ).set_text (_ ("Browser data import not available because \n it is not included in the importet file." ))
571
- builder .get_object ("no_browser_data" ).set_visible (False )
572
571
builder .get_object ("start_button" ).set_label (_ ("Start" ))
573
572
builder .get_object ("start_button" ).connect ("clicked" , lambda button : self .ei_start_process (button , ei_task_info ))
574
- builder .get_object ("cancel_button" ).set_visible (False )
575
- builder .get_object ("select_location_button" ).connect ("clicked" , lambda widget : self .select_location (ei_task_info ))
573
+ builder .get_object ("select_location_button" ).connect ("clicked" , lambda widget : self .ei_select_location (ei_task_info ))
576
574
577
575
# Prepare ei_task_info which stores all the values for the import / export
578
- stop_event = threading .Event ()
579
- ei_task_info = ei_task (self .show_ei_result , self .update_ei_progress , builder , self , window , stop_event , action )
576
+ ei_task_info = ei_task (self .show_ei_result , self .update_ei_progress , builder , self , window , action )
580
577
window .show ()
581
578
582
579
def ei_start_process (self , button , ei_task_info : ei_task ):
@@ -585,25 +582,24 @@ def ei_start_process(self, button, ei_task_info: ei_task):
585
582
path = buffer .get_text (buffer .get_start_iter (), buffer .get_end_iter (), True )
586
583
if path != "" :
587
584
ei_task_info .path = path
588
- ei_task_info .include_browserdata = ei_task_info .builder .get_object ("include_browserdata" ).get_active ()
589
585
button .set_sensitive (False )
590
586
if ei_task_info .task == "export" :
591
- thread = threading .Thread (target = export_config , args = (ei_task_info ,))
587
+ export_config (ei_task_info )
588
+ #thread = threading.Thread(target=export_config, args=(ei_task_info,))
592
589
else :
593
- thread = threading .Thread (target = import_config , args = (ei_task_info ,))
594
- thread .start ()
595
- ei_task_info .builder .get_object ("cancel_button" ).set_visible (True )
596
- ei_task_info .builder .get_object ("cancel_button" ).connect ("clicked" , lambda button : self .abort_ei (button , ei_task_info , thread ))
590
+ import_config (ei_task_info )
591
+ #thread = threading.Thread(target=import_config, args=(ei_task_info,))
592
+ #thread.start()
597
593
598
594
599
- def select_location (self , ei_task_info : ei_task ):
595
+ def ei_select_location (self , ei_task_info : ei_task ):
600
596
# Open the file chooser window
601
597
if ei_task_info .task == "export" :
602
598
buttons = (Gtk .STOCK_CANCEL , Gtk .ResponseType .CANCEL , Gtk .STOCK_SAVE , Gtk .ResponseType .OK )
603
599
dialog = Gtk .FileChooserDialog (_ ("Export Configuration - Please choose a file location" ), self .window , Gtk .FileChooserAction .SAVE , buttons )
604
600
else :
605
601
buttons = (Gtk .STOCK_CANCEL , Gtk .ResponseType .CANCEL , Gtk .STOCK_OPEN , Gtk .ResponseType .OK )
606
- dialog = Gtk .FileChooserDialog (_ ("Import Configuration - Please select the file " ), self .window , Gtk .FileChooserAction .OPEN , buttons )
602
+ dialog = Gtk .FileChooserDialog (_ ("Import Configuration - Please select the archive " ), self .window , Gtk .FileChooserAction .OPEN , buttons )
607
603
608
604
filter = Gtk .FileFilter ()
609
605
filter .set_name (".tar.gz" )
@@ -615,41 +611,20 @@ def select_location(self, ei_task_info: ei_task):
615
611
if ei_task_info .task == "export" :
616
612
path += ".tar.gz"
617
613
ei_task_info .builder .get_object ("file_path" ).get_buffer ().set_text (path )
618
-
619
- # Check if include browser data is available
620
- include_browser_available = True
621
- if ei_task_info .task == "import" :
622
- if not check_browser_directories_tar (path ):
623
- include_browser_available = False
624
-
625
- ei_task_info .builder .get_object ("include_browserdata" ).set_sensitive (include_browser_available )
626
- ei_task_info .builder .get_object ("no_browser_data" ).set_visible (not include_browser_available )
627
- ei_task_info .builder .get_object ("include_browserdata" ).set_active (include_browser_available )
628
614
dialog .destroy ()
629
615
630
-
631
- def abort_ei (self , button , ei_task_info :ei_task , thread ):
632
- # Abort the export / import process
633
- button .set_sensitive (False )
634
- self .update_ei_progress (ei_task_info , 0 )
635
- # The backend function will automatically clean up after the stop flag is triggered.
636
- ei_task_info .stop_event .set ()
637
- thread .join ()
638
-
639
616
def update_ei_progress (self , ei_task_info :ei_task , progress ):
640
- # Update the progress bar or close the tool window by 100%.
617
+ # Update the progress bar
641
618
try :
642
- ei_task_info .builder .get_object ("progress" ).set_fraction (progress )
643
- if progress == 1 :
644
- ei_task_info .window .destroy ()
619
+ ei_task_info .builder .get_object ("progress" ).set_fraction (progress )
645
620
except :
646
621
# The user closed the progress window
647
622
pass
648
623
649
624
650
625
def show_ei_result (self , ei_task_info :ei_task ):
651
626
# Displays a success or failure message when the process is complete.
652
- ei_task_info .window . destroy ()
627
+ ei_task_info .webAppLauncherSelf . load_webapps ()
653
628
if ei_task_info .result == "ok" :
654
629
message = _ (ei_task_info .task .capitalize () + " completed!" )
655
630
else :
@@ -663,16 +638,19 @@ def show_ei_result(self, ei_task_info:ei_task):
663
638
result = dialog .run ()
664
639
if result == 10 :
665
640
# Open Containing Folder
666
- print ("open folder" )
667
641
os .system ("xdg-open " + os .path .dirname (ei_task_info .path ))
668
642
else :
669
643
dialog = Gtk .MessageDialog (text = message , message_type = Gtk .MessageType .INFO , buttons = Gtk .ButtonsType .OK )
670
644
dialog .run ()
671
645
672
646
dialog .destroy ()
673
- ei_task_info .webAppLauncherSelf .load_webapps ()
647
+ try :
648
+ ei_task_info .window .destroy ()
649
+ except :
650
+ # User closed the window manually
651
+ pass
652
+
674
653
675
654
if __name__ == "__main__" :
676
655
application = MyApplication ("org.x.webapp-manager" , Gio .ApplicationFlags .FLAGS_NONE )
677
- application .run ()
678
-
656
+ application .run ()
0 commit comments