Search in sources :

Example 1 with UserSettings

use of org.libresonic.player.domain.UserSettings in project libresonic by Libresonic.

the class AvatarController method getAvatar.

private Avatar getAvatar(HttpServletRequest request) {
    String id = request.getParameter("id");
    boolean forceCustom = ServletRequestUtils.getBooleanParameter(request, "forceCustom", false);
    if (id != null) {
        return settingsService.getSystemAvatar(Integer.parseInt(id));
    }
    String username = request.getParameter("username");
    if (username == null) {
        return null;
    }
    UserSettings userSettings = settingsService.getUserSettings(username);
    if (userSettings.getAvatarScheme() == AvatarScheme.CUSTOM || forceCustom) {
        return settingsService.getCustomAvatar(username);
    }
    return settingsService.getSystemAvatar(userSettings.getSystemAvatarId());
}
Also used : UserSettings(org.libresonic.player.domain.UserSettings)

Example 2 with UserSettings

use of org.libresonic.player.domain.UserSettings in project libresonic by Libresonic.

the class UserDaoTestCase method testUserSettings.

@Test
public void testUserSettings() {
    assertNull("Error in getUserSettings.", userDao.getUserSettings("sindre"));
    try {
        userDao.updateUserSettings(new UserSettings("sindre"));
        fail("Expected DataIntegrityViolationException.");
    } catch (DataIntegrityViolationException x) {
    }
    userDao.createUser(new User("sindre", "secret", null));
    assertNull("Error in getUserSettings.", userDao.getUserSettings("sindre"));
    userDao.updateUserSettings(new UserSettings("sindre"));
    UserSettings userSettings = userDao.getUserSettings("sindre");
    assertNotNull("Error in getUserSettings().", userSettings);
    assertNull("Error in getUserSettings().", userSettings.getLocale());
    assertNull("Error in getUserSettings().", userSettings.getThemeId());
    assertFalse("Error in getUserSettings().", userSettings.isFinalVersionNotificationEnabled());
    assertFalse("Error in getUserSettings().", userSettings.isBetaVersionNotificationEnabled());
    assertFalse("Error in getUserSettings().", userSettings.isSongNotificationEnabled());
    assertFalse("Error in getUserSettings().", userSettings.isShowSideBar());
    assertFalse("Error in getUserSettings().", userSettings.isLastFmEnabled());
    assertNull("Error in getUserSettings().", userSettings.getLastFmUsername());
    assertNull("Error in getUserSettings().", userSettings.getLastFmPassword());
    assertSame("Error in getUserSettings().", TranscodeScheme.OFF, userSettings.getTranscodeScheme());
    assertFalse("Error in getUserSettings().", userSettings.isShowNowPlayingEnabled());
    assertEquals("Error in getUserSettings().", -1, userSettings.getSelectedMusicFolderId());
    assertFalse("Error in getUserSettings().", userSettings.isPartyModeEnabled());
    assertFalse("Error in getUserSettings().", userSettings.isNowPlayingAllowed());
    assertSame("Error in getUserSettings().", AvatarScheme.NONE, userSettings.getAvatarScheme());
    assertNull("Error in getUserSettings().", userSettings.getSystemAvatarId());
    assertEquals("Error in getUserSettings().", 0, userSettings.getListReloadDelay());
    assertFalse("Error in getUserSettings().", userSettings.isKeyboardShortcutsEnabled());
    assertEquals("Error in getUserSettings().", 0, userSettings.getPaginationSize());
    UserSettings settings = new UserSettings("sindre");
    settings.setLocale(Locale.SIMPLIFIED_CHINESE);
    settings.setThemeId("midnight");
    settings.setBetaVersionNotificationEnabled(true);
    settings.setSongNotificationEnabled(false);
    settings.setShowSideBar(true);
    settings.getMainVisibility().setBitRateVisible(true);
    settings.getPlaylistVisibility().setYearVisible(true);
    settings.setLastFmEnabled(true);
    settings.setLastFmUsername("last_user");
    settings.setLastFmPassword("last_pass");
    settings.setTranscodeScheme(TranscodeScheme.MAX_192);
    settings.setShowNowPlayingEnabled(false);
    settings.setSelectedMusicFolderId(3);
    settings.setPartyModeEnabled(true);
    settings.setNowPlayingAllowed(true);
    settings.setAvatarScheme(AvatarScheme.SYSTEM);
    settings.setSystemAvatarId(1);
    settings.setChanged(new Date(9412L));
    settings.setListReloadDelay(60);
    settings.setKeyboardShortcutsEnabled(true);
    settings.setPaginationSize(120);
    userDao.updateUserSettings(settings);
    userSettings = userDao.getUserSettings("sindre");
    assertNotNull("Error in getUserSettings().", userSettings);
    assertEquals("Error in getUserSettings().", Locale.SIMPLIFIED_CHINESE, userSettings.getLocale());
    assertEquals("Error in getUserSettings().", false, userSettings.isFinalVersionNotificationEnabled());
    assertEquals("Error in getUserSettings().", true, userSettings.isBetaVersionNotificationEnabled());
    assertEquals("Error in getUserSettings().", false, userSettings.isSongNotificationEnabled());
    assertEquals("Error in getUserSettings().", true, userSettings.isShowSideBar());
    assertEquals("Error in getUserSettings().", "midnight", userSettings.getThemeId());
    assertEquals("Error in getUserSettings().", true, userSettings.getMainVisibility().isBitRateVisible());
    assertEquals("Error in getUserSettings().", true, userSettings.getPlaylistVisibility().isYearVisible());
    assertEquals("Error in getUserSettings().", true, userSettings.isLastFmEnabled());
    assertEquals("Error in getUserSettings().", "last_user", userSettings.getLastFmUsername());
    assertEquals("Error in getUserSettings().", "last_pass", userSettings.getLastFmPassword());
    assertSame("Error in getUserSettings().", TranscodeScheme.MAX_192, userSettings.getTranscodeScheme());
    assertFalse("Error in getUserSettings().", userSettings.isShowNowPlayingEnabled());
    assertEquals("Error in getUserSettings().", 3, userSettings.getSelectedMusicFolderId());
    assertTrue("Error in getUserSettings().", userSettings.isPartyModeEnabled());
    assertTrue("Error in getUserSettings().", userSettings.isNowPlayingAllowed());
    assertSame("Error in getUserSettings().", AvatarScheme.SYSTEM, userSettings.getAvatarScheme());
    assertEquals("Error in getUserSettings().", 1, userSettings.getSystemAvatarId().intValue());
    assertEquals("Error in getUserSettings().", new Date(9412L), userSettings.getChanged());
    assertEquals("Error in getUserSettings().", 60, userSettings.getListReloadDelay());
    assertTrue("Error in getUserSettings().", userSettings.isKeyboardShortcutsEnabled());
    assertEquals("Error in getUserSettings().", 120, userSettings.getPaginationSize());
    userDao.deleteUser("sindre");
    assertNull("Error in cascading delete.", userDao.getUserSettings("sindre"));
}
Also used : User(org.libresonic.player.domain.User) UserSettings(org.libresonic.player.domain.UserSettings) Date(java.util.Date) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Test(org.junit.Test)

Example 3 with UserSettings

use of org.libresonic.player.domain.UserSettings in project libresonic by Libresonic.

the class IndexController method index.

@RequestMapping(method = { RequestMethod.GET })
public ModelAndView index(HttpServletRequest request) {
    UserSettings userSettings = settingsService.getUserSettings(securityService.getCurrentUsername(request));
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("showRight", userSettings.isShowNowPlayingEnabled());
    map.put("autoHidePlayQueue", userSettings.isAutoHidePlayQueue());
    map.put("listReloadDelay", userSettings.getListReloadDelay());
    map.put("keyboardShortcutsEnabled", userSettings.isKeyboardShortcutsEnabled());
    map.put("showSideBar", userSettings.isShowSideBar());
    map.put("brand", settingsService.getBrand());
    return new ModelAndView("index", "model", map);
}
Also used : HashMap(java.util.HashMap) UserSettings(org.libresonic.player.domain.UserSettings) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with UserSettings

use of org.libresonic.player.domain.UserSettings in project libresonic by Libresonic.

the class PlaylistController method handleRequestInternal.

@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Map<String, Object> map = new HashMap<>();
    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    User user = securityService.getCurrentUser(request);
    String username = user.getUsername();
    UserSettings userSettings = settingsService.getUserSettings(username);
    Player player = playerService.getPlayer(request, response);
    Playlist playlist = playlistService.getPlaylist(id);
    if (playlist == null) {
        return new ModelAndView(new RedirectView("notFound"));
    }
    map.put("playlist", playlist);
    map.put("user", user);
    map.put("player", player);
    map.put("editAllowed", username.equals(playlist.getUsername()) || securityService.isAdmin(username));
    map.put("partyMode", userSettings.isPartyModeEnabled());
    return new ModelAndView("playlist", "model", map);
}
Also used : Player(org.libresonic.player.domain.Player) Playlist(org.libresonic.player.domain.Playlist) User(org.libresonic.player.domain.User) HashMap(java.util.HashMap) UserSettings(org.libresonic.player.domain.UserSettings) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with UserSettings

use of org.libresonic.player.domain.UserSettings in project libresonic by Libresonic.

the class MultiService method setShowSideBar.

public void setShowSideBar(boolean show) {
    HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
    String username = securityService.getCurrentUsername(request);
    UserSettings userSettings = settingsService.getUserSettings(username);
    userSettings.setShowSideBar(show);
    userSettings.setChanged(new Date());
    settingsService.updateUserSettings(userSettings);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) UserSettings(org.libresonic.player.domain.UserSettings) Date(java.util.Date)

Aggregations

UserSettings (org.libresonic.player.domain.UserSettings)14 User (org.libresonic.player.domain.User)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 HashMap (java.util.HashMap)5 ModelAndView (org.springframework.web.servlet.ModelAndView)5 Date (java.util.Date)3 Player (org.libresonic.player.domain.Player)2 Locale (java.util.Locale)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Test (org.junit.Test)1 UserSettingsCommand (org.libresonic.player.command.UserSettingsCommand)1 Avatar (org.libresonic.player.domain.Avatar)1 Playlist (org.libresonic.player.domain.Playlist)1 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)1 RedirectView (org.springframework.web.servlet.view.RedirectView)1