Diff for revision 1224
=== modified file 'src/com/pugh/sockso/Console.java'
--- src/com/pugh/sockso/Console.java 2010-02-07 19:43:38 +0000
+++ src/com/pugh/sockso/Console.java 2010-02-08 23:44:17 +0000
@@ -58,8 +58,8 @@
private static final String PROMPT = "#SoCkSo#> ";
- public Console( final Database db, final Properties p, final CollectionManager cm, final Resources r ) {
- this( db, p, cm, System.out, System.in, r.getCurrentLocale() );
+ public Console( final Database db, final Properties p, final CollectionManager cm, final Locale locale ) {
+ this( db, p, cm, System.out, System.in, locale );
}
public Console( final Database db, final Properties p, final CollectionManager cm, final PrintStream out, final InputStream is, final Locale locale ) {
=== modified file 'src/com/pugh/sockso/Main.java'
--- src/com/pugh/sockso/Main.java 2010-02-08 19:02:08 +0000
+++ src/com/pugh/sockso/Main.java 2010-02-08 23:44:17 +0000
@@ -28,6 +28,7 @@
import com.pugh.sockso.resources.FileResources;
import com.pugh.sockso.resources.JarResources;
import com.pugh.sockso.resources.Resources;
+import com.pugh.sockso.resources.Locale;
import com.pugh.sockso.web.Dispatcher;
import com.pugh.sockso.web.IpFinder;
import com.pugh.sockso.web.Server;
@@ -60,6 +61,7 @@
private static CollectionManager cm;
private static Manager manager;
private static Resources r;
+ private static Locale locale;
private static Indexer indexer;
private static Scheduler sched;
@@ -163,14 +165,16 @@
*/
private static void actionAdmin( final OptionSet options ) throws Exception {
-
+
final boolean useGui = getUseGui( options );
- final String locale = getLocale( options );
+ final String localeString = getLocale( options );
log.info( "Initializing Resources (" + locale + ")" );
r = getResources( options );
- r.init( locale );
+ r.init( localeString );
+ locale = r.getCurrentLocale();
+
if ( useGui ) {
Splash.start( r );
}
@@ -186,9 +190,7 @@
ipFinder.init();
// show GUI or console?
- manager = ( useGui )
- ? new AppFrame( db, p, null, cm, r, ipFinder )
- : new Console( db, p, cm, r );
+ manager = getManager( useGui, ipFinder );
manager.open();
}
@@ -247,11 +249,13 @@
private static void actionDefault( final OptionSet options ) throws Exception {
final boolean useGui = getUseGui( options );
- final String locale = getLocale( options );
+ final String localeString = getLocale( options );
log.info( "Initializing Resources (" + locale + ")" );
r = getResources( options );
- r.init( locale );
+ r.init( localeString );
+
+ locale = r.getCurrentLocale();
if ( useGui ) {
Splash.start( r );
@@ -292,10 +296,7 @@
UPNP.tryPortForwarding( sv.getPort() );
}
- // show GUI or console?
- manager = ( useGui )
- ? new AppFrame( db, p, sv, cm, r, ipFinder )
- : new Console( db, p, cm, r );
+ manager = getManager( useGui, ipFinder );
final VersionChecker versionChecker = new VersionChecker( p );
versionChecker.addLatestVersionListener( manager );
@@ -306,6 +307,24 @@
}
/**
+ * Works out if we're using the GUI or the console
+ *
+ * @param useGui
+ * @param ipFinder
+ *
+ * @return
+ *
+ */
+
+ public static Manager getManager( final boolean useGui, final IpFinder ipFinder ) {
+
+ return ( useGui )
+ ? new AppFrame( db, p, sv, cm, r, ipFinder )
+ : new Console( db, p, cm, locale );
+
+ }
+
+ /**
* returns the correct database to use
*
* @param options
=== modified file 'src/com/pugh/sockso/gui/AppFrame.java'
--- src/com/pugh/sockso/gui/AppFrame.java 2010-02-07 19:43:38 +0000
+++ src/com/pugh/sockso/gui/AppFrame.java 2010-02-08 23:44:17 +0000
@@ -75,7 +75,7 @@
public AppFrame( final Database db, final Properties p, final Server sv, final CollectionManager cm, final Resources r, final IpFinder ipFinder ) {
- super( r.getCurrentLocale().getString("gui.window.main") + " (" +Sockso.VERSION+ ")" );
+ super( r == null ? "" : r.getCurrentLocale().getString("gui.window.main") + " (" +Sockso.VERSION+ ")" );
this.db = db;
this.p = p;
=== modified file 'src/com/pugh/sockso/gui/PlaylistPanel.java'
--- src/com/pugh/sockso/gui/PlaylistPanel.java 2008-09-28 21:08:07 +0000
+++ src/com/pugh/sockso/gui/PlaylistPanel.java 2010-02-08 23:44:17 +0000
@@ -302,33 +302,56 @@
final Track[] tracks = getTracks();
+ try {
+
+ if ( playlistExists(playlistName) ) {
+ if ( JOptionPane.showConfirmDialog( this, "That playlist already exists, replace it?",
+ "Overwrite Playlist", JOptionPane.YES_NO_OPTION ) != JOptionPane.YES_OPTION ) {
+ return;
+ }
+ }
+
+ cm.savePlaylist( playlistName, tracks );
+
+ }
+
+ catch ( SQLException e ) {
+ JOptionPane.showMessageDialog( parent, e.getMessage() );
+ log.error( e.getMessage() );
+ }
+
+ }
+
+ /**
+ * Checks if a playlist by this name exists in the database
+ *
+ * @param name
+ *
+ * @return
+ *
+ * @throws SQLException
+ *
+ */
+
+ protected boolean playlistExists( final String name ) throws SQLException {
+
ResultSet rs = null;
PreparedStatement st = null;
try {
-
+
final String sql = " select id " +
" from playlists p " +
" where name = ? ";
-
+
st = db.prepare( sql );
- st.setString( 1, playlistName );
+ st.setString( 1, name );
rs = st.executeQuery();
-
- if ( rs.next() )
- if ( JOptionPane.showConfirmDialog( this, "That playlist already exists, replace it?",
- "Overwrite Playlist", JOptionPane.YES_NO_OPTION ) != JOptionPane.YES_OPTION )
- return;
-
- cm.savePlaylist( playlistName, tracks );
-
- }
-
- catch ( SQLException e ) {
- JOptionPane.showMessageDialog( parent, e.getMessage() );
- log.error( e.getMessage() );
- }
-
+
+ return rs.next();
+
+ }
+
finally {
Utils.close( rs );
Utils.close( st );
=== added file 'test-data/fixtures/singlePlaylist.fix'
--- test-data/fixtures/singlePlaylist.fix 1970-01-01 00:00:00 +0000
+++ test-data/fixtures/singlePlaylist.fix 2010-02-08 23:44:17 +0000
@@ -0,0 +1,2 @@
+
+playlists:1,Foo Bar,now(),now(),-1
=== modified file 'test/com/pugh/sockso/MainTest.java'
--- test/com/pugh/sockso/MainTest.java 2010-01-04 21:14:34 +0000
+++ test/com/pugh/sockso/MainTest.java 2010-02-08 23:44:17 +0000
@@ -4,6 +4,7 @@
import com.pugh.sockso.db.HSQLDatabase;
import com.pugh.sockso.db.MySQLDatabase;
import com.pugh.sockso.db.SQLiteDatabase;
+import com.pugh.sockso.gui.AppFrame;
import com.pugh.sockso.music.indexing.TrackIndexer;
import com.pugh.sockso.music.scheduling.CronScheduler;
import com.pugh.sockso.music.scheduling.ManualScheduler;
@@ -136,4 +137,12 @@
assertEquals( Main.getProtocol(stdOptions), "http" );
}
+ public void testGettingTheGuiAsManager() {
+ assertEquals( AppFrame.class, Main.getManager(true,null).getClass() );
+ }
+
+ public void testGettingConsoleAsManager() {
+ assertEquals( Console.class, Main.getManager(false,null).getClass() );
+ }
+
}
=== added file 'test/com/pugh/sockso/gui/PlaylistPanelTest.java'
--- test/com/pugh/sockso/gui/PlaylistPanelTest.java 1970-01-01 00:00:00 +0000
+++ test/com/pugh/sockso/gui/PlaylistPanelTest.java 2010-02-08 23:44:17 +0000
@@ -0,0 +1,17 @@
+
+package com.pugh.sockso.gui;
+
+import com.pugh.sockso.tests.SocksoTestCase;
+import com.pugh.sockso.tests.TestDatabase;
+
+public class PlaylistPanelTest extends SocksoTestCase {
+
+ public void testCheckingPlaylistExists() throws Exception {
+ TestDatabase db = new TestDatabase();
+ PlaylistPanel p = new PlaylistPanel( null, db, null );
+ db.fixture( "singlePlaylist" );
+ assertTrue( p.playlistExists("Foo Bar") );
+ assertFalse( p.playlistExists("Bar Foo") );
+ }
+
+}