Révision 2256

tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/commands/function/MediaPreferencesDialog.java (revision 2256)
29 29
			BackToMediaPreferences.STRUCTURE, 
30 30
			BackToMediaPreferences.WORD_PROPERTY, 
31 31
			BackToMediaPreferences.SYNCMODE, 
32
			BackToMediaPreferences.MEDIA_DIRECTORY, 
33
			BackToMediaPreferences.MEDIA_FORMAT };
32
			BackToMediaPreferences.MEDIA_PATH_PREFIX, 
33
			BackToMediaPreferences.MEDIA_EXTENSION,
34
			BackToMediaPreferences.MEDIA_AUTH,
35
			BackToMediaPreferences.MEDIA_AUTH_LOGIN};
34 36
	
35 37
	HashMap<String, Text> fields = new HashMap<String, Text>();
36 38
	HashMap<String, String> values = new HashMap<String, String>();
tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/commands/function/BackToMedia.java (revision 2256)
29 29

  
30 30
import java.io.File;
31 31
import java.io.InputStream;
32
import java.net.URL;
32 33
import java.util.HashMap;
33 34

  
34 35
import org.eclipse.core.commands.AbstractHandler;
35 36
import org.eclipse.core.commands.ExecutionEvent;
36 37
import org.eclipse.core.commands.ExecutionException;
37 38
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
39
import org.eclipse.jface.dialogs.InputDialog;
38 40
import org.eclipse.jface.viewers.IStructuredSelection;
39 41
import org.eclipse.osgi.util.NLS;
40 42
import org.eclipse.ui.IWorkbenchPart;
......
46 48
import org.txm.concordance.rcp.editors.ConcordanceEditor;
47 49
import org.txm.core.preferences.TXMPreferences;
48 50
import org.txm.objects.CorpusCommandPreferences;
51
import org.txm.rcp.swt.dialog.UsernamePasswordDialog;
49 52
import org.txm.rcp.utils.SWTEditorsUtils;
50 53
import org.txm.searchengine.core.SearchEngine;
51 54
import org.txm.searchengine.cqp.AbstractCqiClient;
......
114 117
		String startPropertyName = commandPreferences.get(BackToMediaPreferences.STRUCTURE_START_PROPERTY, alternative);
115 118
		String endPropertyName = commandPreferences.get(BackToMediaPreferences.STRUCTURE_END_PROPERTY, alternative);
116 119
		String sync_mode = commandPreferences.get(BackToMediaPreferences.SYNCMODE, alternative);
117
		String media_directory = commandPreferences.get(BackToMediaPreferences.MEDIA_DIRECTORY, alternative);
118
		String media_format = commandPreferences.get(BackToMediaPreferences.MEDIA_FORMAT, alternative);
120
		String media_directory = commandPreferences.get(BackToMediaPreferences.MEDIA_PATH_PREFIX, alternative);
121
		boolean media_auth = "true".equals(commandPreferences.get(BackToMediaPreferences.MEDIA_AUTH, alternative));
122
		String secured_media_login = commandPreferences.get(BackToMediaPreferences.MEDIA_AUTH_LOGIN, alternative);
123
		String secured_media_password = System.getProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD);
124
		String media_format = commandPreferences.get(BackToMediaPreferences.MEDIA_EXTENSION, alternative);
119 125
		String media_index = commandPreferences.get(BackToMediaPreferences.MEDIA_INDEX_NODE, alternative);
120 126

  
121 127
		try {
......
209 215
			//}
210 216

  
211 217
			File binDir = corpus.getProject().getProjectDirectory();
212
			File audioFile = null;
218
			String path = null;
213 219
			if (media_index != null && media_index.length() > 0) {
214 220
				IEclipsePreferences node = corpus.getProject().getPreferencesScope().getNode(media_index);
215
				String path = node.get(textid, null);
216
				audioFile = new File(path);
217
				if (path.startsWith("http:/")) {
221
				String path2 = node.get(textid, null);
222
				File audioFile = new File(path2);
223
				if (path2.startsWith("http:/")) {
218 224
					try {
219 225
						InputStream conn = audioFile.toURI().toURL().openStream();
220 226
						conn.close();
227
						path = path2;
221 228
					} catch(Exception e) {
222
						Log.info("Could not open media file: "+path);
229
						Log.info("Could not open media file: "+path2);
223 230
					}
224 231
				} else if (!audioFile.exists()) {
225 232
					Log.info("Media file register in the index not found: "+audioFile);
226 233
					return null;
227 234
				}
228
			} else if (media_directory != null && media_directory.length() > 0 && media_format != null && media_format.length() > 0) {
229
				audioFile = new File(media_directory, textid+"."+media_format); //$NON-NLS-1$
230
				if (media_directory.startsWith("http:/")) {
235
			} else if (((media_directory != null && media_directory.length() > 0) || (media_auth) ) 
236
					&& media_format != null && media_format.length() > 0) {
237

  
238
				String path_prefix = media_directory;
239
				if (media_auth) {
240

  
241
					if (secured_media_password == null) {
242
						UsernamePasswordDialog dialog = new UsernamePasswordDialog(ce.getShell(), new boolean[]{false, true}, media_directory);
243
						if (dialog.open() == dialog.OK) {
244
							System.setProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD, dialog.getPassword());
245
							secured_media_password = dialog.getPassword();
246
						}
247
					}
248
					path_prefix = NLS.bind(media_directory, secured_media_login, secured_media_password);
249
				}
250

  
251
				File audioFile = new File(path_prefix, textid+"."+media_format); //$NON-NLS-1$
252
				if (path_prefix.startsWith("http")) {
253
					URL url = null;
231 254
					try {
232
						InputStream conn = audioFile.toURI().toURL().openStream();
233
						conn.close();
255
						url = new URL(path_prefix+textid+"."+media_format);
256
						if (!(media_auth)) {
257
							System.out.println("URL="+url);
258
							InputStream conn = url.openStream();
259
							conn.close();
260
						}
261
						path = url.toString();
234 262
					} catch(Exception e) {
235
						Log.info("Could not open media file: "+audioFile);
263
						Log.info("Could not open media file: "+url);
236 264
					}
237
				} else { // local
238
					if (!new File(media_directory).exists()) {
239
						Log.info("Media directory not found: "+media_directory);
265
				} else { // local file
266
					if (!new File(path_prefix).exists()) {
267
						Log.info("Media directory not found: "+path_prefix);
240 268
						return null;
241 269
					} else if (!audioFile.exists()) {
242 270
						Log.info("Media file not found: "+audioFile);
243 271
						return null;
244 272
					}
273
					path = audioFile.getAbsolutePath();
245 274
				}
246 275
			} else {
247 276
				File mediaDir = new File(binDir, "media"); //$NON-NLS-1$
248
				audioFile = new File(mediaDir, textid+".mp3"); //$NON-NLS-1$
277
				File audioFile = new File(mediaDir, textid+".mp3"); //$NON-NLS-1$
249 278
				if (!audioFile.exists()) audioFile = new File(mediaDir, textid+".ogg"); //$NON-NLS-1$
250 279
				if (!audioFile.exists()) audioFile = new File(mediaDir, textid+".wav"); //$NON-NLS-1$
251 280
				if (!audioFile.exists()) audioFile = new File(mediaDir, textid+".mp4"); //$NON-NLS-1$
......
257 286
					System.out.println(MessagesMP.BackToMedia_29);
258 287
					return null;
259 288
				}
289
				path = audioFile.getAbsolutePath();
260 290
			}
261 291

  
262
			Log.fine(MessagesMP.BackToMedia_25+audioFile);
263
			
292
			Log.fine(MessagesMP.BackToMedia_25+path);
293

  
264 294
			//System.out.println("Linked editors: "+associatedEditors);
265 295
			VLCPlayerEditor editor = associatedEditors.get(ce); 
266
			String path = audioFile.getPath();
267 296
			if (editor != null && !editor.isDirty() && !editor.getPlayer().isDisposed()) {
268 297
				editor.getPlayer().play(path, sStartTime, sEndTime);
269 298
				editor.getPlayer().setRepeat(true);
270 299
			} else {
271 300
				//System.out.println("new editor linked to "+ce);
272 301
				editor = OpenVLCPlayer.openEditor(path, sStartTime, sEndTime);
273
				
302

  
274 303
				//editor.getPlayer().setRepeat(true);
275 304
				if (editor == null) {
276 305
					return null;
277 306
				}
278
				
307

  
279 308
				// move the editor in the window
280 309
				int position = BackToMediaPreferences.getInstance().getInt(BackToMediaPreferences.BACKTOMEDIA_POSITION);
281 310
				SWTEditorsUtils.addEditor(editor, ce, position);
282
				
311

  
283 312
				VLCPlayer player = editor.getPlayer();
284 313
				if (player != null) {
285 314
					player.hideStopButton();
286 315
					associatedEditors.put(ce, editor);
287 316
				}
288 317
			}
289
			
290
			if (audioFile != null) {
291
				editor.setPartName(audioFile.getName());
318

  
319
			if (path != null) {
320
				editor.setPartName(textid);
292 321
			}
293 322
			return null;
294 323

  
tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/preferences/BackToMediaPreferences.java (revision 2256)
26 26
	public static final String STRUCTUREMODE = "Structure";
27 27
	public static final String MILESTONEMODE = "Milestone";
28 28

  
29
	public static final String MEDIA_DIRECTORY = "media_directory";
30
	public static final String MEDIA_FORMAT = "media_format";
29
	public static final String MEDIA_PATH_PREFIX = "media_path_prefix";
30
	public static final String MEDIA_EXTENSION = "media_extension";
31
	
32
	public static final String MEDIA_AUTH = "media_auth";
33
	public static final String MEDIA_AUTH_LOGIN = "media_auth_login";
34
	public static final String MEDIA_AUTH_PASSWORD = "media_auth_password";
31 35

  
36
	/**
37
	 * preferences node to media file access paths
38
	 */
32 39
	public static final String MEDIA_INDEX_NODE = "media_index_node";
33 40
	
34 41
	/**

Formats disponibles : Unified diff