#! /bin/bash

NICOTINEDIR=~/.nicotine
NICOTINEPREFIX="$NICOTINEDIR"/config
PYSLSKPREFIX=~/.pyslsk

function go()
{
exec /usr/bin/nicotine
}

function errgo()
{
/usr/bin/python << EOF
import pygtk
pygtk.require('2.0')
import gtk
dialog = gtk.MessageDialog(None,gtk.DIALOG_MODAL,gtk.MESSAGE_ERROR, gtk.BUTTONS_OK,"An error occurred while trying to convert your PySoulSeek settings to Nicotine. Nicotine will now start with a fresh configuration.")
dialog.run()
EOF
go
}

function okgo()
{
/usr/bin/python << EOF
import pygtk
pygtk.require('2.0')
import gtk
dialog = gtk.MessageDialog(None,gtk.DIALOG_MODAL,gtk.MESSAGE_INFO, gtk.BUTTONS_OK,"Your PySoulSeek configuration was successfully moved to Nicotine. This new client will now be used instead of PySoulSeek. You will find the same functionality, with a more up-to-date UI.")
dialog.run()
EOF
go
}

# do we have a pyslsk config lying around?
test -f "$PYSLSKPREFIX" || go

# is the configuration already here?
test -f "$NICOTINEPREFIX" && go

# create the dir if necessary
mkdir -p "$NICOTINEDIR" || errgo

for i in "$PYSLSKPREFIX"* ; do
	cp "$i" "$NICOTINEPREFIX"${i#"$PYSLSKPREFIX"} || errgo
done

okgo
