1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | import gi |
---|
4 | gi.require_version('Gtk', '3.0') |
---|
5 | from gi.repository import Gtk, Pango, GdkPixbuf, Gdk, Gio, GObject,GLib |
---|
6 | |
---|
7 | |
---|
8 | |
---|
9 | import signal |
---|
10 | import os |
---|
11 | import json |
---|
12 | import sys |
---|
13 | import Core |
---|
14 | |
---|
15 | |
---|
16 | signal.signal(signal.SIGINT, signal.SIG_DFL) |
---|
17 | |
---|
18 | import gettext |
---|
19 | gettext.textdomain('lliurex-gdrive') |
---|
20 | _ = gettext.gettext |
---|
21 | |
---|
22 | RSRC="/usr/share/lliurex-gdrive/" |
---|
23 | #CONFIG_DIR=os.path.expanduser("~/.config/lliurex-google-drive-profiles/config") |
---|
24 | CSS_FILE="/usr/share/lliurex-gdrive/lliurex-gdrive.css" |
---|
25 | LOCK_INDICATOR="~/.config/lliurex-google-drive-profiles/lgdIndicator.lock" |
---|
26 | LOCK_GUI="~/.config/lliurex-google-drive-profiles/lgdGUI.lock" |
---|
27 | DISABLE_INDICATOR="~/.config/lliurex-google-drive-profiles/disableIndicator" |
---|
28 | |
---|
29 | |
---|
30 | class LliurexGdrive: |
---|
31 | |
---|
32 | def __init__(self): |
---|
33 | |
---|
34 | self.islgd_running() |
---|
35 | self.core=Core.Core.get_core() |
---|
36 | self.disable_indicator=os.path.expanduser(DISABLE_INDICATOR) |
---|
37 | self.lock_gui=os.path.expanduser(LOCK_GUI) |
---|
38 | self.lock_indicator=os.path.expanduser(LOCK_INDICATOR) |
---|
39 | |
---|
40 | self.createLockToken() |
---|
41 | |
---|
42 | #def init |
---|
43 | |
---|
44 | |
---|
45 | def islgd_running(self): |
---|
46 | |
---|
47 | if os.path.exists(LOCK_GUI): |
---|
48 | dialog = Gtk.MessageDialog(None,0,Gtk.MessageType.ERROR, Gtk.ButtonsType.CANCEL, "Lliurex GDrive") |
---|
49 | dialog.format_secondary_text(_("Lliurex GDrive is now running.")) |
---|
50 | dialog.run() |
---|
51 | sys.exit(1) |
---|
52 | |
---|
53 | |
---|
54 | def createLockToken(self): |
---|
55 | |
---|
56 | if not os.path.exists(self.lock_gui): |
---|
57 | f=open(self.lock_gui,'w') |
---|
58 | f.close |
---|
59 | |
---|
60 | #def createLockToken |
---|
61 | |
---|
62 | def load_gui(self): |
---|
63 | |
---|
64 | builder=Gtk.Builder() |
---|
65 | builder.set_translation_domain('lliurex-gdrive') |
---|
66 | ui_path=RSRC + "rsrc/lliurex-gdrive.ui" |
---|
67 | builder.add_from_file(ui_path) |
---|
68 | |
---|
69 | |
---|
70 | self.main_window=builder.get_object("main_window") |
---|
71 | self.main_window.set_title("Lliurex GDrive") |
---|
72 | self.main_box=builder.get_object("main_box") |
---|
73 | self.exit_button=builder.get_object("exit_button") |
---|
74 | self.check_window=builder.get_object("check_window") |
---|
75 | self.check_pbar=builder.get_object("check_pbar") |
---|
76 | self.check_plabel=builder.get_object("check_plabel") |
---|
77 | self.check_window.set_transient_for(self.main_window) |
---|
78 | |
---|
79 | |
---|
80 | self.indicator_label=builder.get_object("indicator_label") |
---|
81 | self.indicator_switch=builder.get_object("indicator_switch") |
---|
82 | if os.path.exists(self.disable_indicator): |
---|
83 | self.indicator_switch.set_active(False) |
---|
84 | |
---|
85 | |
---|
86 | self.profile_box=self.core.profile_box |
---|
87 | self.main_box.add(self.profile_box) |
---|
88 | |
---|
89 | |
---|
90 | # Add components |
---|
91 | |
---|
92 | self.set_css_info() |
---|
93 | self.connect_signals() |
---|
94 | self.load_info() |
---|
95 | |
---|
96 | self.main_window.show_all() |
---|
97 | |
---|
98 | #def load_gui |
---|
99 | |
---|
100 | |
---|
101 | |
---|
102 | def load_info(self): |
---|
103 | |
---|
104 | self.load_profiles=self.core.LliurexGoogleDriveManager.profiles_config.copy() |
---|
105 | |
---|
106 | self.profile_box.load_info(self.load_profiles) |
---|
107 | |
---|
108 | |
---|
109 | def set_css_info(self): |
---|
110 | |
---|
111 | |
---|
112 | self.style_provider=Gtk.CssProvider() |
---|
113 | f=Gio.File.new_for_path(CSS_FILE) |
---|
114 | self.style_provider.load_from_file(f) |
---|
115 | Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(),self.style_provider,Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) |
---|
116 | self.main_window.set_name("WINDOW") |
---|
117 | self.indicator_label.set_name("OPTION_LABEL") |
---|
118 | self.check_plabel.set_name("MSG_LABEL") |
---|
119 | |
---|
120 | |
---|
121 | |
---|
122 | def connect_signals(self): |
---|
123 | |
---|
124 | self.main_window.connect("destroy",self.quit) |
---|
125 | self.exit_button.connect("clicked",self.quit) |
---|
126 | |
---|
127 | |
---|
128 | #def connect_signals |
---|
129 | |
---|
130 | def launch_indicator(self): |
---|
131 | |
---|
132 | |
---|
133 | #self.lockpath=R=os.path(LOCK_INDICATOR) |
---|
134 | if len(self.load_profiles): |
---|
135 | if not os.path.exists(self.lock_indicator): |
---|
136 | cmd="/usr/bin/lliurexGdriveIndicator" + "&" |
---|
137 | os.system(cmd) |
---|
138 | |
---|
139 | #def launch_indicator |
---|
140 | |
---|
141 | def config_indicator(self): |
---|
142 | |
---|
143 | if self.show_indicator: |
---|
144 | if os.path.exists(self.disable_indicator): |
---|
145 | os.remove(self.disable_indicator) |
---|
146 | else: |
---|
147 | if not os.path.exists(self.disable_indicator): |
---|
148 | f=open(self.disable_indicator,'w') |
---|
149 | f.close |
---|
150 | |
---|
151 | |
---|
152 | def cleanLockToken(self): |
---|
153 | |
---|
154 | if os.path.exists(self.lock_gui): |
---|
155 | os.remove(self.lock_gui) |
---|
156 | |
---|
157 | #def cleanIndicatorLock |
---|
158 | |
---|
159 | def quit(self,widget): |
---|
160 | |
---|
161 | self.show_indicator=self.indicator_switch.get_state() |
---|
162 | self.config_indicator() |
---|
163 | |
---|
164 | if self.show_indicator: |
---|
165 | self.launch_indicator() |
---|
166 | |
---|
167 | self.cleanLockToken() |
---|
168 | Gtk.main_quit() |
---|
169 | |
---|
170 | def start_gui(self): |
---|
171 | |
---|
172 | GObject.threads_init() |
---|
173 | Gtk.main() |
---|
174 | |
---|
175 | #def start_gui |
---|
176 | |
---|
177 | |
---|
178 | |
---|
179 | |
---|
180 | |
---|
181 | #class LliurexRemoteInstaller |
---|
182 | |
---|
183 | |
---|
184 | if __name__=="__main__": |
---|
185 | |
---|
186 | lgd=LliurexGdrive() |
---|
187 | lgd.start_gui() |
---|
188 | |
---|