Two hours should be fine provided your flight is on time. The train station is about a five minute walk from the (old) terminal. I don't know if the new terminal (on the far side of the airfield) is open yet, or if the train line has been extended to serve it.
Either way the journey from the airport to Sants station takes about 15-20 minutes, and they're fairly frequent.