#!/bin/bash

DEFAULT_NICK='parabola-user' # ASSERT: as defined in ~/.purple/accounts.xml and ~/.purple/blist.xml


if [ -z "$(grep $DEFAULT_NICK@irc.freenode.net ~/.purple/accounts.xml)" ] || \
   [ -z "$(grep $DEFAULT_NICK@irc.freenode.net ~/.purple/blist.xml   )" ]
then if zenity --question --width=320 \
               --title="Parabola IRC Login" \
               --text="The default 'parabola-user' freenode IRC account has been modified. \
This desktop shortcut is only for that account. You can either restore Pidgin to it's default \
configuration (deleting any changes you have made); or delete this shortcut from the desktop." \
               --ok-label="Reset Pidgin completely" \
               --cancel-label="Remove this desktop shortcut"
     then cp ~/.purple/accounts.default.xml ~/.purple/accounts.xml
          cp ~/.purple/blist.default.xml    ~/.purple/blist.xml
     else rm ~/Desktop/parabola-irc.desktop
          rm ~/parabola-irc.sh
          exit
     fi
fi

nick=$(zenity --entry --width=320          \
              --title="Parabola IRC Login" \
              --text="Choose a nick-name:" \
              --entry-text=$DEFAULT_NICK   )
nick=${nick// /} ; [ "$nick" ] || nick=$DEFAULT_NICK ;

sed -i "s|$DEFAULT_NICK@irc.freenode.net|$nick@irc.freenode.net|" ~/.purple/accounts.xml
sed -i "s|$DEFAULT_NICK@irc.freenode.net|$nick@irc.freenode.net|" ~/.purple/blist.xml

pidgin
