de.axelwernicke.mypod
Class Backend

java.lang.Object
  extended byde.axelwernicke.mypod.Backend

public class Backend
extends java.lang.Object

Contains all the application logic for myPod

Author:
axel wernicke

Constructor Summary
Backend()
          Creates a new instance of Backend
- deserialize preferences
- initialize datapool & ipod
- deserialize playlists
- validate playlists
- initialize list view table model
 
Method Summary
 void addPlaylist(Playlist playlist)
          Adds a playlist to the list of playlists
 Playlist createAutoPlaylist(java.lang.String name)
          creates a new auto playlist
 Playlist createPlaylist(java.lang.String name)
          creates a new playlist.
 void deleteClips(java.util.Vector oids)
          Deletes clips from myPod and filesystem.
protected  ClipsTableModel getClipsListTableModel(Playlist playlist)
          get the TableModel with data for a specific playlist
 long getClipsTotalCount()
          Gets the total count of clips known by myPods data pool - get the size of a list of oids for all clips
 long getClipsTotalSize()
          Gets the total size of all clips known by myPods data pool - get a list of oids for all clips
- summarize the size of each clip
 long getClipsTotalSize(java.util.Vector oids)
          Gets the summarized filesize for all clips.
 long getClipsTotalTime()
          Gets the total duration of all clips known by myPods data pool - get a list of oids for all clips
- summarize the duration of each clip
protected  DataPool getDataPool()
          Gets the data pool.
 IPod getIPod()
          Getter for property iPod.
protected  Playlist getPlaylist(int index)
          Gets a playlist by its index
 Playlist getPlaylist(java.lang.String name)
          Gets a playlist by its name, or null if it not exists...
protected  javax.swing.DefaultListModel getPlaylistList()
          get list of playlists
 Preferences getPreferences()
          Gets the myPod preferences
protected  javax.swing.DefaultListModel getSpreaderListModel(int columnCode, int playlistIdx)
          get spreader list model
 long getTotalFilesize(java.util.Vector oids)
          Gets the total filesize of a couple clips.
 int getTotalTime(java.util.Vector oids)
          Gets the total time of a couple of clips
 Playlist loadPlaylistM3U(java.io.File file)
          creates a new playlist from an m3u file.
 void playExtern(Playlist playlist, boolean append)
          Sends a playlist to an external player
- determine parameter (add or append)
- check that tmp directory exists to store playlist in
- check that configured player can be found
- store playlist
- call player
 void relocateClips(ProgressDialog dialog, java.util.Collection missingClips)
          Relocates clips if their media files where moved.
 void removeClipsFromMyPod(java.util.Vector oids)
          Removes clips from myPod First the clip is removed from all playlist, the from data pool.
 void removeClipsFromPlaylist(Playlist playlist, java.util.Vector oids)
          Removes a list of clips vom a playlist
 void removePlaylist(int index)
          deletes a playlist
 void removePlaylist(Playlist playlist)
          Removes a playlist
 void reorganizeClips(ReorganizeClipsProgressDialog dialog, java.lang.String baseDirectory, int dirStructureIndex, int filenameStructureIndex, boolean removeEmptyDirectories)
          Reorganizes filestructure and renames files based on id3 tags
determine clips that are below base directory
for all clips to reorganize: determine new pathname
for all clips to reorganize: determine new filename
for all clips to reorganize: create new file
 void savePlaylistM3U(java.lang.String filename, Playlist playlist)
          Saves a playlist as m3u file.
 int scanFiles(java.io.File[] selection, ScanDialog dialog)
          Scans a list of files and directories for mp3 files.
 java.util.Vector scanForMissingMediaFiles(ProgressDialog dialog)
          Gets all clips that are missing.
 void serializeIPodMapper(java.util.Hashtable mapper)
          serializes iPod mapper.
 void setClipsProperties(MP3MetaV2 newMeta, java.util.Vector oids)
          Set new id3 tags for a couple of clips
 void setClipsProperties(ProgressDialog dialog, MP3MetaV2 newMeta, java.util.Vector oids)
          Set new id3 tags for a couple of clips
 void setIPod(IPod iPod)
          Setter for property iPod.
 void setPreferences(Preferences prefs)
          Sets myPod preferences
 void shutdown()
          shuts the backend down.
 long synchronizeIPod(IPodSyncDialog dialog)
          Synchronizes myPod playlists with iPod.
 void updateAllAutoplaylists()
          Update all autoplaylists
- iterate over all playlists and update the autoplaylists
- additionally total time and total filesize are validated
 void updateAutoplaylist(int index)
          Applies the filters to an autoplaylist
- get the playlist
- check if we have an autoplaylist
- get all enabled filters
- remove clips from the playlist if they not apply to the filter (anymore)
- find all clips that apply to the filter
- add found clips, if they are not in the playlist yet
- update playtime for the playlist
 void updateAutoplaylist(Playlist playlist, java.util.List oids)
          Applies the filters to an autoplaylist
- get the playlist
- check if we have an autoplaylist
- get all enabled filters
- remove clips from the playlist if they not apply to the filter (anymore)
- find all clips that apply to the filter
- add found clips, if they are not in the playlist yet
- update playtime for the playlist
 void validatePlaylists()
          Validates all playlists.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Backend

public Backend()
Creates a new instance of Backend
- deserialize preferences
- initialize datapool & ipod
- deserialize playlists
- validate playlists
- initialize list view table model

Method Detail

shutdown

public void shutdown()
shuts the backend down.
- serialzie myPod preferences
- serialize playlists
- shut down the data pool


getDataPool

protected DataPool getDataPool()
Gets the data pool.

Returns:
current data pool

getPlaylistList

protected javax.swing.DefaultListModel getPlaylistList()
get list of playlists

Returns:
list of playlists

getSpreaderListModel

protected javax.swing.DefaultListModel getSpreaderListModel(int columnCode,
                                                            int playlistIdx)
get spreader list model

Parameters:
columnCode - for the column to get a model for
playlistIdx - index of playlist to collect list items from
Returns:
list model containing a distinct selection of the specified column, ordered

getClipsListTableModel

protected ClipsTableModel getClipsListTableModel(Playlist playlist)
get the TableModel with data for a specific playlist

Parameters:
playlist - to get the model for
Returns:
table model for the playlist

addPlaylist

public void addPlaylist(Playlist playlist)
Adds a playlist to the list of playlists

Parameters:
playlist - to add

createPlaylist

public Playlist createPlaylist(java.lang.String name)
creates a new playlist.

Parameters:
name - name of the new playlist
Returns:
new created playlist

createAutoPlaylist

public Playlist createAutoPlaylist(java.lang.String name)
creates a new auto playlist

Parameters:
name - name of the new autoplaylist
Returns:
index of the new autoplaylist in the list of playlists

removePlaylist

public void removePlaylist(int index)
deletes a playlist

Parameters:
index - index of the playlist to delete in the list of playlists

removePlaylist

public void removePlaylist(Playlist playlist)
Removes a playlist

Parameters:
playlist - to remove

getPlaylist

protected Playlist getPlaylist(int index)
Gets a playlist by its index

Parameters:
index - index of the playlist in the list of playlists
Returns:
the playlist

getPlaylist

public Playlist getPlaylist(java.lang.String name)
Gets a playlist by its name, or null if it not exists...

Parameters:
name - of the playlist to get
Returns:
first playlist found for the name given as argument

updateAutoplaylist

public void updateAutoplaylist(int index)
Applies the filters to an autoplaylist
- get the playlist
- check if we have an autoplaylist
- get all enabled filters
- remove clips from the playlist if they not apply to the filter (anymore)
- find all clips that apply to the filter
- add found clips, if they are not in the playlist yet
- update playtime for the playlist

Parameters:
index - index of the playlist in the list of playlists

updateAutoplaylist

public void updateAutoplaylist(Playlist playlist,
                               java.util.List oids)
Applies the filters to an autoplaylist
- get the playlist
- check if we have an autoplaylist
- get all enabled filters
- remove clips from the playlist if they not apply to the filter (anymore)
- find all clips that apply to the filter
- add found clips, if they are not in the playlist yet
- update playtime for the playlist

Parameters:
playlist - to update
oids - to update the playlist to

updateAllAutoplaylists

public void updateAllAutoplaylists()
Update all autoplaylists
- iterate over all playlists and update the autoplaylists
- additionally total time and total filesize are validated


validatePlaylists

public void validatePlaylists()
Validates all playlists. Each entry in each playlists is checked. If the entry (oid) is not contained in the data pool, its removed from the playlist. Attention: This is pretty time consuming!


getTotalTime

public int getTotalTime(java.util.Vector oids)
Gets the total time of a couple of clips

Parameters:
oids - of the clips to summarize duration for
Returns:
summarized duration of the clips in oids

getTotalFilesize

public long getTotalFilesize(java.util.Vector oids)
Gets the total filesize of a couple clips.

Parameters:
oids - to summarize filesize
Returns:
summarized filesize

scanFiles

public int scanFiles(java.io.File[] selection,
                     ScanDialog dialog)
Scans a list of files and directories for mp3 files.
- get all selected files and all files in selected direcories
- if file is not known yet, scan file
- if not, check if the file was touched since last scan, if so, rescan and update meta data

Parameters:
dialog - scan progress dialog
selection - list of files and directories
Returns:
the number of clips updated or added

getPreferences

public Preferences getPreferences()
Gets the myPod preferences

Returns:
myPod preferences

setPreferences

public void setPreferences(Preferences prefs)
Sets myPod preferences

Parameters:
prefs - to set

loadPlaylistM3U

public Playlist loadPlaylistM3U(java.io.File file)
creates a new playlist from an m3u file.
- determine name of the playlist from filename

Parameters:
file - m3u playlist
Returns:
playlist loaded from file

savePlaylistM3U

public void savePlaylistM3U(java.lang.String filename,
                            Playlist playlist)
Saves a playlist as m3u file.
- make sure, that the filename ends to .m3u
- create file
- write file header
- write filter information for autoplaylists
-

Parameters:
filename - of the playlist
playlist - to save

removeClipsFromMyPod

public void removeClipsFromMyPod(java.util.Vector oids)
Removes clips from myPod First the clip is removed from all playlist, the from data pool.

Parameters:
oids - of the clips to delete

deleteClips

public void deleteClips(java.util.Vector oids)
Deletes clips from myPod and filesystem.

Parameters:
oids - to delete media files for

removeClipsFromPlaylist

public void removeClipsFromPlaylist(Playlist playlist,
                                    java.util.Vector oids)
Removes a list of clips vom a playlist

Parameters:
playlist - to remove clips from
oids - of the clips to remove

scanForMissingMediaFiles

public java.util.Vector scanForMissingMediaFiles(ProgressDialog dialog)
Gets all clips that are missing. all clips in the data pool are checked for their files. If the file can not be opended, the oid is added to the vector of missing clips

Parameters:
dialog - to show the progress of the action
Returns:
vector containing oids of missing clips or null, if action was canceled

serializeIPodMapper

public void serializeIPodMapper(java.util.Hashtable mapper)
serializes iPod mapper.

Parameters:
mapper - to serialize

synchronizeIPod

public long synchronizeIPod(IPodSyncDialog dialog)
Synchronizes myPod playlists with iPod.
- load iTunes database from iPod
- load iMapper
- determine all clips to synchronize
- determine clips to remove from iPod
- determine clips to move to iPod
- check space left on iPod
- remove clips from iPod
- remove empty playlists from iPod
- copy clips to iPod
- create playlists on iPod
- save iTunes database to iPod
- serialize iMapper

Parameters:
dialog - to show progress
Returns:
space left on iPod after sync in bytes

getClipsTotalCount

public long getClipsTotalCount()
Gets the total count of clips known by myPods data pool - get the size of a list of oids for all clips

Returns:
total count of clips known managed by myPod

getClipsTotalSize

public long getClipsTotalSize()
Gets the total size of all clips known by myPods data pool - get a list of oids for all clips
- summarize the size of each clip

Returns:
total size of clips known managed by myPod in bytes

getClipsTotalTime

public long getClipsTotalTime()
Gets the total duration of all clips known by myPods data pool - get a list of oids for all clips
- summarize the duration of each clip

Returns:
total duration of clips known managed by myPod

getClipsTotalSize

public long getClipsTotalSize(java.util.Vector oids)
Gets the summarized filesize for all clips. It tries to determine clip size from local db via oid. The oid _must_ be known by myPod!

Parameters:
oids - vector of oids to summarize filesizes
Returns:
filesize of all specified oids

playExtern

public void playExtern(Playlist playlist,
                       boolean append)
Sends a playlist to an external player
- determine parameter (add or append)
- check that tmp directory exists to store playlist in
- check that configured player can be found
- store playlist
- call player

Parameters:
playlist - to play
append - if true, playlist is appended to the clips on the player

getIPod

public IPod getIPod()
Getter for property iPod.

Returns:
Value of property iPod.

setIPod

public void setIPod(IPod iPod)
Setter for property iPod.

Parameters:
iPod - New value of property iPod.

reorganizeClips

public void reorganizeClips(ReorganizeClipsProgressDialog dialog,
                            java.lang.String baseDirectory,
                            int dirStructureIndex,
                            int filenameStructureIndex,
                            boolean removeEmptyDirectories)
Reorganizes filestructure and renames files based on id3 tags
determine clips that are below base directory
for all clips to reorganize: determine new pathname
for all clips to reorganize: determine new filename
for all clips to reorganize: create new file

Parameters:
dialog - reorganizing progress dialog
removeEmptyDirectories - flag, if true - empty directories are removed
baseDirectory - all files below are reorganized
dirStructureIndex - index that determines how the filestructure is reorganized
filenameStructureIndex - index that determines how the files are renamed

setClipsProperties

public void setClipsProperties(ProgressDialog dialog,
                               MP3MetaV2 newMeta,
                               java.util.Vector oids)
Set new id3 tags for a couple of clips

Parameters:
dialog - to visualize progress
newMeta - mp3 meta data to set
oids - of the clips to update id3 tags

setClipsProperties

public void setClipsProperties(MP3MetaV2 newMeta,
                               java.util.Vector oids)
Set new id3 tags for a couple of clips

Parameters:
newMeta - mp3 meta data to set
oids - of the clips to update id3 tags

relocateClips

public void relocateClips(ProgressDialog dialog,
                          java.util.Collection missingClips)
Relocates clips if their media files where moved. e.g: a:\bbb\ccc\ddd\fool.mp3 --> k:\lll\mmm\nnn\ddd\fool.mp3 - baseSrc - | -- file -- -- baseDest -- | -- file --

Parameters:
dialog - to show progress
missingClips - clips where media file is missing