|
|
@ -20,6 +20,7 @@ |
|
|
|
package org.libresonic.player.controller; |
|
|
|
package org.libresonic.player.controller; |
|
|
|
|
|
|
|
|
|
|
|
import org.libresonic.player.command.MusicFolderSettingsCommand; |
|
|
|
import org.libresonic.player.command.MusicFolderSettingsCommand; |
|
|
|
|
|
|
|
import org.libresonic.player.command.NetworkSettingsCommand; |
|
|
|
import org.libresonic.player.dao.AlbumDao; |
|
|
|
import org.libresonic.player.dao.AlbumDao; |
|
|
|
import org.libresonic.player.dao.ArtistDao; |
|
|
|
import org.libresonic.player.dao.ArtistDao; |
|
|
|
import org.libresonic.player.dao.MediaFileDao; |
|
|
|
import org.libresonic.player.dao.MediaFileDao; |
|
|
@ -27,6 +28,13 @@ import org.libresonic.player.domain.MusicFolder; |
|
|
|
import org.libresonic.player.service.MediaScannerService; |
|
|
|
import org.libresonic.player.service.MediaScannerService; |
|
|
|
import org.libresonic.player.service.SettingsService; |
|
|
|
import org.libresonic.player.service.SettingsService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
import org.springframework.stereotype.Controller; |
|
|
|
|
|
|
|
import org.springframework.ui.Model; |
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute; |
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod; |
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
|
import org.springframework.web.servlet.ModelAndView; |
|
|
|
import org.springframework.web.servlet.ModelAndView; |
|
|
|
import org.springframework.web.servlet.mvc.SimpleFormController; |
|
|
|
import org.springframework.web.servlet.mvc.SimpleFormController; |
|
|
|
import org.springframework.web.servlet.view.RedirectView; |
|
|
|
import org.springframework.web.servlet.view.RedirectView; |
|
|
@ -40,22 +48,33 @@ import java.util.List; |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Sindre Mehus |
|
|
|
* @author Sindre Mehus |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class MusicFolderSettingsController extends SimpleFormController { |
|
|
|
@Controller |
|
|
|
|
|
|
|
@RequestMapping("/musicFolderSettings") |
|
|
|
|
|
|
|
public class MusicFolderSettingsController { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
private SettingsService settingsService; |
|
|
|
private SettingsService settingsService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private MediaScannerService mediaScannerService; |
|
|
|
private MediaScannerService mediaScannerService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ArtistDao artistDao; |
|
|
|
private ArtistDao artistDao; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private AlbumDao albumDao; |
|
|
|
private AlbumDao albumDao; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private MediaFileDao mediaFileDao; |
|
|
|
private MediaFileDao mediaFileDao; |
|
|
|
|
|
|
|
|
|
|
|
protected Object formBackingObject(HttpServletRequest request) throws Exception { |
|
|
|
@RequestMapping(method = RequestMethod.GET) |
|
|
|
|
|
|
|
protected String formBackingObject(@RequestParam(value = "scanNow",required = false) String scanNow, |
|
|
|
|
|
|
|
@RequestParam(value = "expunge",required = false) String expunge, |
|
|
|
|
|
|
|
@RequestParam(value = "reload",required = false) String reload, |
|
|
|
|
|
|
|
Model model) throws Exception { |
|
|
|
MusicFolderSettingsCommand command = new MusicFolderSettingsCommand(); |
|
|
|
MusicFolderSettingsCommand command = new MusicFolderSettingsCommand(); |
|
|
|
|
|
|
|
|
|
|
|
if (request.getParameter("scanNow") != null) { |
|
|
|
if (scanNow != null) { |
|
|
|
settingsService.clearMusicFolderCache(); |
|
|
|
settingsService.clearMusicFolderCache(); |
|
|
|
mediaScannerService.scanLibrary(); |
|
|
|
mediaScannerService.scanLibrary(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (request.getParameter("expunge") != null) { |
|
|
|
if (expunge != null) { |
|
|
|
expunge(); |
|
|
|
expunge(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -66,8 +85,10 @@ public class MusicFolderSettingsController extends SimpleFormController { |
|
|
|
command.setScanning(mediaScannerService.isScanning()); |
|
|
|
command.setScanning(mediaScannerService.isScanning()); |
|
|
|
command.setMusicFolders(wrap(settingsService.getAllMusicFolders(true, true))); |
|
|
|
command.setMusicFolders(wrap(settingsService.getAllMusicFolders(true, true))); |
|
|
|
command.setNewMusicFolder(new MusicFolderSettingsCommand.MusicFolderInfo()); |
|
|
|
command.setNewMusicFolder(new MusicFolderSettingsCommand.MusicFolderInfo()); |
|
|
|
command.setReload(request.getParameter("reload") != null || request.getParameter("scanNow") != null); |
|
|
|
command.setReload(reload != null || scanNow != null); |
|
|
|
return command; |
|
|
|
|
|
|
|
|
|
|
|
model.addAttribute("command",command); |
|
|
|
|
|
|
|
return "musicFolderSettings"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void expunge() { |
|
|
|
private void expunge() { |
|
|
@ -84,17 +105,18 @@ public class MusicFolderSettingsController extends SimpleFormController { |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@RequestMapping(method = RequestMethod.POST) |
|
|
|
protected ModelAndView onSubmit(Object comm) throws Exception { |
|
|
|
protected String onSubmit(@ModelAttribute MusicFolderSettingsCommand command, Model model) throws Exception { |
|
|
|
MusicFolderSettingsCommand command = (MusicFolderSettingsCommand) comm; |
|
|
|
|
|
|
|
|
|
|
|
if (command.getMusicFolders() != null) { |
|
|
|
for (MusicFolderSettingsCommand.MusicFolderInfo musicFolderInfo : command.getMusicFolders()) { |
|
|
|
for (MusicFolderSettingsCommand.MusicFolderInfo musicFolderInfo : command.getMusicFolders()) { |
|
|
|
if (musicFolderInfo.isDelete()) { |
|
|
|
if (musicFolderInfo.isDelete()) { |
|
|
|
settingsService.deleteMusicFolder(musicFolderInfo.getId()); |
|
|
|
settingsService.deleteMusicFolder(musicFolderInfo.getId()); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
MusicFolder musicFolder = musicFolderInfo.toMusicFolder(); |
|
|
|
MusicFolder musicFolder = musicFolderInfo.toMusicFolder(); |
|
|
|
if (musicFolder != null) { |
|
|
|
if (musicFolder != null) { |
|
|
|
settingsService.updateMusicFolder(musicFolder); |
|
|
|
settingsService.updateMusicFolder(musicFolder); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -111,26 +133,8 @@ public class MusicFolderSettingsController extends SimpleFormController { |
|
|
|
settingsService.save(); |
|
|
|
settingsService.save(); |
|
|
|
|
|
|
|
|
|
|
|
mediaScannerService.schedule(); |
|
|
|
mediaScannerService.schedule(); |
|
|
|
return new ModelAndView(new RedirectView(getSuccessView() + ".view?reload")); |
|
|
|
model.addAttribute("command",command); |
|
|
|
} |
|
|
|
return "redirect:musicFolderSettings.view"; |
|
|
|
|
|
|
|
|
|
|
|
public void setSettingsService(SettingsService settingsService) { |
|
|
|
|
|
|
|
this.settingsService = settingsService; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setMediaScannerService(MediaScannerService mediaScannerService) { |
|
|
|
|
|
|
|
this.mediaScannerService = mediaScannerService; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setArtistDao(ArtistDao artistDao) { |
|
|
|
|
|
|
|
this.artistDao = artistDao; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setAlbumDao(AlbumDao albumDao) { |
|
|
|
|
|
|
|
this.albumDao = albumDao; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setMediaFileDao(MediaFileDao mediaFileDao) { |
|
|
|
|
|
|
|
this.mediaFileDao = mediaFileDao; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |