14 |
14 |
15 from eric7 import Preferences |
15 from eric7 import Preferences |
16 from eric7.EricGui.EricOverrideCursor import EricOverridenCursor |
16 from eric7.EricGui.EricOverrideCursor import EricOverridenCursor |
17 from eric7.EricWidgets import EricMessageBox |
17 from eric7.EricWidgets import EricMessageBox |
18 from eric7.EricWidgets.EricApplication import ericApp |
18 from eric7.EricWidgets.EricApplication import ericApp |
|
19 from eric7.SystemUtilities import FileSystemUtilities |
19 |
20 |
20 from .Task import TaskPriority, TaskType |
21 from .Task import TaskPriority, TaskType |
21 |
22 |
22 |
23 |
23 class TasksFile(QObject): |
24 class TasksFile(QObject): |
83 for task in ericApp().getObject("TaskViewer").getProjectTasks() |
88 for task in ericApp().getObject("TaskViewer").getProjectTasks() |
84 ] |
89 ] |
85 |
90 |
86 try: |
91 try: |
87 jsonString = json.dumps(tasksDict, indent=2) + "\n" |
92 jsonString = json.dumps(tasksDict, indent=2) + "\n" |
88 with open(filename, "w") as f: |
93 if FileSystemUtilities.isRemoteFileName(filename): |
89 f.write(jsonString) |
94 title = self.tr("Save Remote Tasks") |
|
95 fsInterface.writeFile(filename, jsonString.encode("utf-8")) |
|
96 else: |
|
97 title = self.tr("Save Tasks") |
|
98 with open(filename, "w") as f: |
|
99 f.write(jsonString) |
90 except (OSError, TypeError) as err: |
100 except (OSError, TypeError) as err: |
91 with EricOverridenCursor(): |
101 with EricOverridenCursor(): |
92 EricMessageBox.critical( |
102 EricMessageBox.critical( |
93 None, |
103 None, |
94 self.tr("Save Tasks"), |
104 title, |
95 self.tr( |
105 self.tr( |
96 "<p>The tasks file <b>{0}</b> could not be" |
106 "<p>The tasks file <b>{0}</b> could not be" |
97 " written.</p><p>Reason: {1}</p>" |
107 " written.</p><p>Reason: {1}</p>" |
98 ).format(filename, str(err)), |
108 ).format(filename, str(err)), |
99 ) |
109 ) |
108 @param filename name of the project file |
118 @param filename name of the project file |
109 @type str |
119 @type str |
110 @return flag indicating a successful read |
120 @return flag indicating a successful read |
111 @rtype bool |
121 @rtype bool |
112 """ |
122 """ |
|
123 fsInterface = ( |
|
124 ericApp().getObject("EricServer").getServiceInterface("FileSystem") |
|
125 ) |
|
126 |
113 try: |
127 try: |
114 with open(filename, "r") as f: |
128 if FileSystemUtilities.isRemoteFileName(filename): |
115 jsonString = f.read() |
129 title = self.tr("Read Remote Tasks") |
|
130 jsonString = fsInterface.readFile(filename).decode("utf-8") |
|
131 else: |
|
132 title = self.tr("Read Tasks") |
|
133 with open(filename, "r") as f: |
|
134 jsonString = f.read() |
116 tasksDict = json.loads(jsonString) |
135 tasksDict = json.loads(jsonString) |
117 except (OSError, json.JSONDecodeError) as err: |
136 except (OSError, json.JSONDecodeError) as err: |
118 EricMessageBox.critical( |
137 EricMessageBox.critical( |
119 None, |
138 None, |
120 self.tr("Read Tasks"), |
139 title, |
121 self.tr( |
140 self.tr( |
122 "<p>The tasks file <b>{0}</b> could not be read.</p>" |
141 "<p>The tasks file <b>{0}</b> could not be read.</p>" |
123 "<p>Reason: {1}</p>" |
142 "<p>Reason: {1}</p>" |
124 ).format(filename, str(err)), |
143 ).format(filename, str(err)), |
125 ) |
144 ) |