1 /*
2  * aTunes
3  * Copyright (C) Alex Aranda, Sylvain Gaudard and contributors
4  *
5  * See http://www.atunes.org/wiki/index.php?title=Contributing for information about contributors
6  *
7  * http://www.atunes.org
8  * http://sourceforge.net/projects/atunes
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  */
20 
21 package net.sourceforge.atunes.kernel.modules.process;
22 
23 import java.io.File;
24 import java.io.IOException;
25 import java.util.List;
26 
27 import net.sourceforge.atunes.model.ILocalAudioObject;
28 import net.sourceforge.atunes.model.IStateDevice;
29 import net.sourceforge.atunes.utils.I18nUtils;
30 
31 /**
32  * Transfer files to a partition/device and checks if filename is valid.
33  */
34 public class TransferToDeviceProcess extends
35 		AbstractLocalAudioObjectTransferProcess {
36 
37 	private IStateDevice stateDevice;
38 
39 	/**
40 	 * @param stateDevice
41 	 */
setStateDevice(final IStateDevice stateDevice)42 	public void setStateDevice(final IStateDevice stateDevice) {
43 		this.stateDevice = stateDevice;
44 	}
45 
46 	@Override
getProgressDialogTitle()47 	public String getProgressDialogTitle() {
48 		return I18nUtils.getString("COPYING_TO_DEVICE");
49 	}
50 
51 	@Override
transferAudioFile(final File destination, final ILocalAudioObject file, final List<Exception> thrownExceptions)52 	protected ILocalAudioObject transferAudioFile(final File destination,
53 			final ILocalAudioObject file, final List<Exception> thrownExceptions) {
54 		try {
55 			return getFileManager().copyFile(file,
56 					getDirectory(file, destination, true), getName(file, true));
57 		} catch (IOException e) {
58 			thrownExceptions.add(e);
59 			return null;
60 		}
61 	}
62 
63 	@Override
getDirectory(final ILocalAudioObject song, final File destination, final boolean isMp3Device)64 	public String getDirectory(final ILocalAudioObject song,
65 			final File destination, final boolean isMp3Device) {
66 		return getDirectory(song, destination, isMp3Device,
67 				this.stateDevice.getDeviceFolderPathPattern());
68 	}
69 
70 	@Override
getName(final ILocalAudioObject file, final boolean isMp3Device)71 	public String getName(final ILocalAudioObject file,
72 			final boolean isMp3Device) {
73 		return getName(file, isMp3Device,
74 				this.stateDevice.getDeviceFileNamePattern());
75 	}
76 
77 	@Override
getFileNamePattern()78 	protected String getFileNamePattern() {
79 		return this.stateDevice.getDeviceFileNamePattern();
80 	}
81 
82 	@Override
getFolderPathPattern()83 	protected String getFolderPathPattern() {
84 		return this.stateDevice.getDeviceFolderPathPattern();
85 	}
86 }
87