71 |
71 |
import vlcplayerrcp.MessagesMP;
|
72 |
72 |
|
73 |
73 |
/**
|
74 |
|
* open the VLCPlayer Editor and go back to time
|
|
74 |
* open the VLCPlayer Editor and go back to time
|
|
75 |
*
|
75 |
76 |
* @author mdecorde.
|
76 |
77 |
*/
|
77 |
78 |
public class BackToMedia extends AbstractHandler {
|
78 |
|
|
|
79 |
|
79 |
80 |
/** The ID. */
|
80 |
81 |
public static String ID = "org.txm.rcp.commands.BackToMedia"; //$NON-NLS-1$
|
81 |
|
|
|
82 |
|
82 |
83 |
/** The selection. */
|
83 |
84 |
private IStructuredSelection selection;
|
84 |
|
|
|
85 |
|
85 |
86 |
private static HashMap<ITXMResultEditor<?>, VLCPlayerEditor> associatedEditors = new HashMap<ITXMResultEditor<?>, VLCPlayerEditor>();
|
86 |
|
|
87 |
|
/* (non-Javadoc)
|
88 |
|
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
|
87 |
|
|
88 |
/*
|
|
89 |
* (non-Javadoc)
|
|
90 |
* @see
|
|
91 |
* org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.
|
|
92 |
* ExecutionEvent)
|
89 |
93 |
*/
|
90 |
94 |
@Override
|
91 |
95 |
public Object execute(ExecutionEvent event) throws ExecutionException {
|
92 |
|
|
|
96 |
|
93 |
97 |
String corpus_parameter = event.getParameter("corpus"); //$NON-NLS-1$
|
94 |
98 |
String text_parameter = event.getParameter("text"); //$NON-NLS-1$
|
95 |
99 |
String word_parameter = event.getParameter("word"); //$NON-NLS-1$
|
96 |
100 |
String time_parameter = event.getParameter("time"); //$NON-NLS-1$
|
97 |
|
|
|
101 |
|
98 |
102 |
if (corpus_parameter != null && text_parameter != null && (word_parameter != null || time_parameter != null)) {
|
99 |
|
|
|
103 |
|
100 |
104 |
try {
|
101 |
105 |
CQPCorpus cqpCorpus = CorpusManager.getCorpusManager().getCorpus(corpus_parameter);
|
102 |
106 |
if (cqpCorpus == null) {
|
103 |
107 |
Log.warning(NLS.bind("Corpus with ID={0} not found.", corpus_parameter));
|
104 |
108 |
return null;
|
105 |
109 |
}
|
106 |
|
|
|
110 |
|
107 |
111 |
if (time_parameter != null) {
|
108 |
|
return backToMedia(cqpCorpus, text_parameter, 0,0,0,0, time_parameter, time_parameter, null, HandlerUtil.getActiveWorkbenchWindow(event).getShell());
|
109 |
|
} else {
|
|
112 |
return backToMedia(cqpCorpus, text_parameter, 0, 0, 0, 0, time_parameter, time_parameter, null, HandlerUtil.getActiveWorkbenchWindow(event).getShell());
|
|
113 |
}
|
|
114 |
else {
|
110 |
115 |
CQLQuery query = new CQLQuery(NLS.bind("[id=\"{0}\" & _.text_id=\"{1}\"]", word_parameter, text_parameter));
|
111 |
116 |
QueryResult rez = cqpCorpus.query(query, "TMP", false);
|
112 |
|
if(rez.getNMatch() == 1) {
|
|
117 |
if (rez.getNMatch() == 1) {
|
113 |
118 |
Match m = rez.getMatch(0);
|
114 |
119 |
return backToMedia(cqpCorpus, text_parameter, m.getStart(), m.getEnd(), 10, 10, null, null, null, HandlerUtil.getActiveWorkbenchWindow(event).getShell());
|
115 |
|
} else {
|
116 |
|
Log.warning(NLS.bind("Fail to find word with id={0} in text with id={1}",word_parameter, text_parameter));
|
117 |
120 |
}
|
|
121 |
else {
|
|
122 |
Log.warning(NLS.bind("Fail to find word with id={0} in text with id={1}", word_parameter, text_parameter));
|
|
123 |
}
|
118 |
124 |
}
|
119 |
|
} catch (Exception e) {
|
120 |
|
Log.warning(TXMCoreMessages.bind("Fail open media for parameters corpus={0} text={1} word={2}: {3}",corpus_parameter, text_parameter, word_parameter, e));
|
|
125 |
}
|
|
126 |
catch (Exception e) {
|
|
127 |
Log.warning(TXMCoreMessages.bind("Fail open media for parameters corpus={0} text={1} word={2}: {3}", corpus_parameter, text_parameter, word_parameter, e));
|
121 |
128 |
Log.printStackTrace(e);
|
122 |
129 |
}
|
123 |
130 |
return null;
|
124 |
|
} else {
|
|
131 |
}
|
|
132 |
else {
|
125 |
133 |
Object o = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
|
126 |
134 |
if (!(o instanceof IStructuredSelection)) {
|
127 |
135 |
Log.fine(MessagesMP.BackToMedia_0);
|
128 |
136 |
return null;
|
129 |
137 |
}
|
130 |
|
|
|
138 |
|
131 |
139 |
IWorkbenchPart page = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getActivePart();
|
132 |
|
|
|
140 |
|
133 |
141 |
if (!(page instanceof ConcordanceEditor)) {
|
134 |
142 |
Log.fine(MessagesMP.BackToMedia_1);
|
135 |
143 |
System.out.println("Active page is not a ConcordanceEditor"); //$NON-NLS-1$
|
136 |
144 |
return null;
|
137 |
145 |
}
|
138 |
146 |
ConcordanceEditor ce = (ConcordanceEditor) page;
|
139 |
|
selection = (IStructuredSelection)o;
|
140 |
|
|
|
147 |
selection = (IStructuredSelection) o;
|
|
148 |
|
141 |
149 |
Object s = selection.getFirstElement();
|
142 |
|
|
143 |
|
//System.out.println("Selected object: "+s);
|
144 |
|
if (!(s instanceof Line)) {
|
145 |
|
return null;
|
146 |
|
}
|
147 |
|
|
148 |
|
Line line = (Line)s;
|
|
150 |
|
|
151 |
// System.out.println("Selected object: "+s);
|
|
152 |
if (!(s instanceof Line)) { return null; }
|
|
153 |
|
|
154 |
Line line = (Line) s;
|
149 |
155 |
org.txm.objects.Match m = line.getMatch();
|
150 |
|
String textid = line.getTextId();//line.getMatch().getValueForProperty(textP);// get text via text struc property id
|
|
156 |
String textid = line.getTextId();// line.getMatch().getValueForProperty(textP);// get text via text struc property id
|
151 |
157 |
CQPCorpus corpus = line.getConcordance().getCorpus();
|
152 |
|
|
153 |
|
return backToMedia(corpus, textid, m.getStart(), m.getEnd(), line.getConcordance().getLeftContextSize(), line.getConcordance().getRightContextSize(), null, null, ce, ce.getContainer().getShell());
|
|
158 |
|
|
159 |
return backToMedia(corpus, textid, m.getStart(), m.getEnd(), line.getConcordance().getLeftContextSize(), line.getConcordance().getRightContextSize(), null, null, ce, ce.getContainer()
|
|
160 |
.getShell());
|
154 |
161 |
}
|
155 |
162 |
}
|
156 |
|
|
157 |
|
public static Object backToMedia(CQPCorpus corpus, String textid, int keywordPosition, int keywordEndPosition, int leftContext, int rightContext, String sStartTime, String sEndTime, ITXMResultEditor<?> editor, Shell shell) {
|
158 |
|
|
|
163 |
|
|
164 |
public static Object backToMedia(CQPCorpus corpus, String textid, int keywordPosition, int keywordEndPosition, int leftContext, int rightContext, String sStartTime, String sEndTime,
|
|
165 |
ITXMResultEditor<?> editor, Shell shell) {
|
|
166 |
|
159 |
167 |
TXMPreferences alternative = BackToMediaPreferences.getInstance();
|
160 |
|
|
|
168 |
|
161 |
169 |
// try reading project specific preferences
|
162 |
|
//TODO see with SJ how to implement the "command > project > preferences > default preferences" preference order
|
|
170 |
// TODO see with SJ how to implement the "command > project > preferences >
|
|
171 |
// default preferences" preference order
|
163 |
172 |
CorpusCommandPreferences commandPreferences = corpus.getProject().getCommandPreferences("backtomedia"); //$NON-NLS-1$
|
164 |
173 |
String structurePropertyName = commandPreferences.get(BackToMediaPreferences.STRUCTURE, alternative);
|
165 |
174 |
String startPropertyName = commandPreferences.get(BackToMediaPreferences.STRUCTURE_START_PROPERTY, alternative);
|
... | ... | |
171 |
180 |
String secured_media_password = System.getProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD);
|
172 |
181 |
String media_format = commandPreferences.get(BackToMediaPreferences.MEDIA_EXTENSION, alternative);
|
173 |
182 |
String media_index = commandPreferences.get(BackToMediaPreferences.MEDIA_INDEX_NODE, alternative);
|
174 |
|
|
|
183 |
|
175 |
184 |
try {
|
176 |
|
|
177 |
|
Log.fine(MessagesMP.BackToMedia_7+textid);
|
178 |
|
|
|
185 |
|
|
186 |
Log.fine(MessagesMP.BackToMedia_7 + textid);
|
|
187 |
|
179 |
188 |
if (sStartTime == null || sEndTime == null) { // we need to find out the time to play
|
180 |
|
|
|
189 |
|
181 |
190 |
if (BackToMediaPreferences.WORDMODE.equals(sync_mode)) {
|
182 |
191 |
String pTimeName = BackToMediaPreferences.getInstance().getString(BackToMediaPreferences.WORD_PROPERTY);
|
183 |
192 |
if ("".equals(pTimeName)) pTimeName = "time"; //$NON-NLS-1$ //$NON-NLS-2$
|
184 |
|
|
|
193 |
|
185 |
194 |
Property timeP = corpus.getProperty(pTimeName);
|
186 |
195 |
if (timeP == null) {
|
187 |
|
System.out.println(MessagesMP.BackToMedia_11+pTimeName);
|
|
196 |
System.out.println(MessagesMP.BackToMedia_11 + pTimeName);
|
188 |
197 |
return false;
|
189 |
198 |
}
|
190 |
|
|
|
199 |
|
191 |
200 |
int leftPosition = Math.max(keywordPosition - leftContext, 0);
|
192 |
201 |
int rightPosition = Math.min(keywordPosition + rightContext, corpus.getSize());
|
193 |
|
int[] positions = {leftPosition, rightPosition};
|
|
202 |
int[] positions = { leftPosition, rightPosition };
|
194 |
203 |
String[] times = CQPSearchEngine.getCqiClient().cpos2Str(timeP.getQualifiedName(), positions);
|
195 |
204 |
sStartTime = times[0];
|
196 |
205 |
sEndTime = times[1];
|
197 |
|
} else if (BackToMediaPreferences.STRUCTUREMODE.equals(sync_mode)){
|
|
206 |
}
|
|
207 |
else if (BackToMediaPreferences.STRUCTUREMODE.equals(sync_mode)) {
|
198 |
208 |
StructuralUnit structure = corpus.getStructuralUnit(structurePropertyName);
|
199 |
209 |
if (structure == null) {
|
200 |
210 |
System.out.println(MessagesMP.bind(MessagesMP.BackToMedia_12, structurePropertyName));
|
... | ... | |
205 |
215 |
System.out.println(MessagesMP.bind(MessagesMP.BackToMedia_14, startPropertyName));
|
206 |
216 |
return null;
|
207 |
217 |
}
|
208 |
|
|
|
218 |
|
209 |
219 |
sStartTime = Match.getValueForProperty(startProperty, keywordPosition);
|
210 |
|
Log.fine(MessagesMP.BackToMedia_16+sStartTime);
|
211 |
|
|
|
220 |
Log.fine(MessagesMP.BackToMedia_16 + sStartTime);
|
|
221 |
|
212 |
222 |
Property endProperty = structure.getProperty(endPropertyName);
|
213 |
223 |
if (endProperty == null) {
|
214 |
224 |
System.out.println(MessagesMP.bind(MessagesMP.BackToMedia_17, endPropertyName));
|
215 |
225 |
return null;
|
216 |
226 |
}
|
217 |
|
sEndTime = Match.getValueForProperty(endProperty, keywordEndPosition);
|
218 |
|
Log.fine(MessagesMP.BackToMedia_19+sEndTime);
|
219 |
|
} else { // MILESTONE MODE
|
|
227 |
sEndTime = Match.getValueForProperty(endProperty, keywordEndPosition);
|
|
228 |
Log.fine(MessagesMP.BackToMedia_19 + sEndTime);
|
|
229 |
}
|
|
230 |
else { // MILESTONE MODE
|
220 |
231 |
StructuralUnit structure = corpus.getStructuralUnit(structurePropertyName);
|
221 |
232 |
if (structure == null) {
|
222 |
233 |
System.out.println(MessagesMP.bind(MessagesMP.BackToMedia_12, structurePropertyName));
|
... | ... | |
227 |
238 |
System.out.println(MessagesMP.bind(MessagesMP.BackToMedia_14, startPropertyName));
|
228 |
239 |
return null;
|
229 |
240 |
}
|
230 |
|
|
|
241 |
|
231 |
242 |
AbstractCqiClient cqiClient = CorpusManager.getCorpusManager().getCqiClient();
|
232 |
243 |
try {
|
233 |
244 |
int[] struc = cqiClient.cpos2Struc(startProperty.getQualifiedName(),
|
234 |
|
new int[] {keywordPosition, keywordEndPosition});
|
235 |
|
int[] struc2 = new int[] {struc[0], struc[1], struc[1]+1};
|
|
245 |
new int[] { keywordPosition, keywordEndPosition });
|
|
246 |
int[] struc2 = new int[] { struc[0], struc[1], struc[1] + 1 };
|
236 |
247 |
String[] times = cqiClient.struc2Str(startProperty.getQualifiedName(), struc2);
|
237 |
248 |
sStartTime = times[0];
|
238 |
249 |
if (times[2] != null) {
|
239 |
250 |
sEndTime = times[2];
|
240 |
|
} else {
|
|
251 |
}
|
|
252 |
else {
|
241 |
253 |
sEndTime = times[1];
|
242 |
254 |
}
|
243 |
|
|
244 |
|
} catch (Exception e) {
|
|
255 |
|
|
256 |
}
|
|
257 |
catch (Exception e) {
|
245 |
258 |
return null;
|
246 |
259 |
}
|
247 |
260 |
}
|
248 |
261 |
}
|
249 |
|
|
|
262 |
|
250 |
263 |
File binDir = corpus.getProject().getProjectDirectory();
|
251 |
264 |
String path = null;
|
252 |
265 |
if (media_index != null && media_index.length() > 0) {
|
... | ... | |
258 |
271 |
InputStream conn = audioFile.toURI().toURL().openStream();
|
259 |
272 |
conn.close();
|
260 |
273 |
path = path2;
|
261 |
|
} catch(Exception e) {
|
262 |
|
Log.info("Could not open media file: "+path2);
|
263 |
274 |
}
|
264 |
|
} else if (!audioFile.exists()) {
|
265 |
|
Log.info("Media file register in the index not found: "+audioFile);
|
|
275 |
catch (Exception e) {
|
|
276 |
Log.info("Could not open media file: " + path2);
|
|
277 |
}
|
|
278 |
}
|
|
279 |
else if (!audioFile.exists()) {
|
|
280 |
Log.info("Media file register in the index not found: " + audioFile);
|
266 |
281 |
return null;
|
267 |
282 |
}
|
268 |
|
} else if (((media_directory != null && media_directory.length() > 0) || (media_auth) )
|
|
283 |
}
|
|
284 |
else if (((media_directory != null && media_directory.length() > 0) || (media_auth))
|
269 |
285 |
&& media_format != null && media_format.length() > 0) {
|
270 |
|
|
|
286 |
|
271 |
287 |
String path_prefix = media_directory;
|
272 |
288 |
if (media_auth) {
|
273 |
|
|
|
289 |
|
274 |
290 |
if (secured_media_password == null) {
|
275 |
|
UsernamePasswordDialog dialog = new UsernamePasswordDialog(shell, new boolean[]{false, true}, media_directory);
|
|
291 |
UsernamePasswordDialog dialog = new UsernamePasswordDialog(shell, new boolean[] { false, true }, media_directory);
|
276 |
292 |
if (dialog.open() == dialog.OK) {
|
277 |
293 |
System.setProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD, dialog.getPassword());
|
278 |
294 |
secured_media_password = dialog.getPassword();
|
... | ... | |
280 |
296 |
}
|
281 |
297 |
path_prefix = NLS.bind(media_directory, secured_media_login, secured_media_password);
|
282 |
298 |
}
|
283 |
|
|
284 |
|
File audioFile = new File(path_prefix, textid+"."+media_format); //$NON-NLS-1$
|
|
299 |
|
|
300 |
File audioFile = new File(path_prefix, textid + "." + media_format); //$NON-NLS-1$
|
285 |
301 |
if (path_prefix.startsWith("http")) {
|
286 |
302 |
URL url = null;
|
287 |
303 |
try {
|
288 |
|
url = new URL(path_prefix+textid+"."+media_format);
|
|
304 |
url = new URL(path_prefix + textid + "." + media_format);
|
289 |
305 |
if (!(media_auth)) {
|
290 |
|
System.out.println("URL="+url);
|
|
306 |
System.out.println("URL=" + url);
|
291 |
307 |
InputStream conn = url.openStream();
|
292 |
308 |
conn.close();
|
293 |
309 |
}
|
294 |
310 |
path = url.toString();
|
295 |
|
} catch(Exception e) {
|
296 |
|
Log.info("Could not open media file: "+url);
|
297 |
311 |
}
|
298 |
|
} else { // local file
|
|
312 |
catch (Exception e) {
|
|
313 |
Log.info("Could not open media file: " + url);
|
|
314 |
}
|
|
315 |
}
|
|
316 |
else { // local file
|
299 |
317 |
if (!new File(path_prefix).exists()) {
|
300 |
|
Log.info("Media directory not found: "+path_prefix);
|
|
318 |
Log.info("Media directory not found: " + path_prefix);
|
301 |
319 |
return null;
|
302 |
|
} else if (!audioFile.exists()) {
|
303 |
|
Log.info("Media file not found: "+audioFile);
|
|
320 |
}
|
|
321 |
else if (!audioFile.exists()) {
|
|
322 |
Log.info("Media file not found: " + audioFile);
|
304 |
323 |
return null;
|
305 |
324 |
}
|
306 |
325 |
path = audioFile.getAbsolutePath();
|
307 |
326 |
}
|
308 |
|
} else {
|
|
327 |
}
|
|
328 |
else {
|
309 |
329 |
File mediaDir = new File(binDir, "media"); //$NON-NLS-1$
|
310 |
|
File audioFile = new File(mediaDir, textid+".mp3"); //$NON-NLS-1$
|
311 |
|
if (!audioFile.exists()) audioFile = new File(mediaDir, textid+".ogg"); //$NON-NLS-1$
|
312 |
|
if (!audioFile.exists()) audioFile = new File(mediaDir, textid+".wav"); //$NON-NLS-1$
|
313 |
|
if (!audioFile.exists()) audioFile = new File(mediaDir, textid+".mp4"); //$NON-NLS-1$
|
314 |
|
if (!audioFile.exists()) audioFile = new File(mediaDir, textid+".avi"); //$NON-NLS-1$
|
315 |
|
if (!audioFile.exists()) audioFile = new File(mediaDir, textid+".mov"); //$NON-NLS-1$
|
|
330 |
File audioFile = new File(mediaDir, textid + ".mp3"); //$NON-NLS-1$
|
|
331 |
if (!audioFile.exists()) audioFile = new File(mediaDir, textid + ".ogg"); //$NON-NLS-1$
|
|
332 |
if (!audioFile.exists()) audioFile = new File(mediaDir, textid + ".wav"); //$NON-NLS-1$
|
|
333 |
if (!audioFile.exists()) audioFile = new File(mediaDir, textid + ".mp4"); //$NON-NLS-1$
|
|
334 |
if (!audioFile.exists()) audioFile = new File(mediaDir, textid + ".avi"); //$NON-NLS-1$
|
|
335 |
if (!audioFile.exists()) audioFile = new File(mediaDir, textid + ".mov"); //$NON-NLS-1$
|
316 |
336 |
if (!audioFile.exists()) {
|
317 |
337 |
System.out.println(NLS.bind(MessagesMP.BackToMedia_26, textid));
|
318 |
338 |
System.out.println(NLS.bind(MessagesMP.BackToMedia_27, mediaDir));
|
... | ... | |
321 |
341 |
}
|
322 |
342 |
path = audioFile.getAbsolutePath();
|
323 |
343 |
}
|
324 |
|
|
325 |
|
Log.fine(MessagesMP.BackToMedia_25+path);
|
326 |
|
|
327 |
|
//System.out.println("Linked editors: "+associatedEditors);
|
|
344 |
|
|
345 |
Log.fine(MessagesMP.BackToMedia_25 + path);
|
|
346 |
|
|
347 |
// System.out.println("Linked editors: "+associatedEditors);
|
328 |
348 |
VLCPlayerEditor vlcEditor = null;
|
329 |
349 |
if (editor != null) {
|
330 |
350 |
vlcEditor = associatedEditors.get(editor);
|
... | ... | |
332 |
352 |
if (vlcEditor != null && !editor.isDirty() && !vlcEditor.getPlayer().isDisposed()) {
|
333 |
353 |
vlcEditor.getPlayer().play(path, sStartTime, sEndTime);
|
334 |
354 |
vlcEditor.getPlayer().setRepeat(true);
|
335 |
|
} else {
|
336 |
|
//System.out.println("new editor linked to "+ce);
|
|
355 |
}
|
|
356 |
else {
|
|
357 |
// System.out.println("new editor linked to "+ce);
|
337 |
358 |
vlcEditor = OpenVLCPlayer.openEditor(path, sStartTime, sEndTime);
|
338 |
|
|
339 |
|
//editor.getPlayer().setRepeat(true);
|
340 |
|
if (vlcEditor == null) {
|
341 |
|
return null;
|
342 |
|
}
|
343 |
|
|
|
359 |
|
|
360 |
// editor.getPlayer().setRepeat(true);
|
|
361 |
if (vlcEditor == null) { return null; }
|
|
362 |
|
344 |
363 |
// move the editor in the window
|
345 |
364 |
int position = BackToMediaPreferences.getInstance().getInt(BackToMediaPreferences.BACKTOMEDIA_POSITION);
|
346 |
365 |
if (editor != null) {
|
347 |
366 |
SWTEditorsUtils.addEditor(vlcEditor, (EditorPart) editor, position);
|
348 |
367 |
}
|
349 |
|
|
|
368 |
|
350 |
369 |
VLCPlayer player = vlcEditor.getPlayer();
|
351 |
370 |
if (player != null) {
|
352 |
371 |
player.hideStopButton();
|
353 |
372 |
associatedEditors.put(editor, vlcEditor);
|
354 |
373 |
}
|
355 |
374 |
}
|
356 |
|
|
|
375 |
|
357 |
376 |
if (path != null) {
|
358 |
377 |
vlcEditor.setPartName(textid);
|
359 |
378 |
}
|
360 |
379 |
return null;
|
361 |
|
|
362 |
|
} catch (Exception e2) {
|
363 |
|
System.out.println(MessagesMP.BackToMedia_30+e2);
|
|
380 |
|
|
381 |
}
|
|
382 |
catch (Exception e2) {
|
|
383 |
System.out.println(MessagesMP.BackToMedia_30 + e2);
|
364 |
384 |
Log.printStackTrace(e2);
|
365 |
385 |
return null;
|
366 |
386 |
}
|