@@ -67,13 +67,15 @@ RadioTrayLite::~RadioTrayLite()
6767}
6868
6969bool
70- RadioTrayLite::init (int argc, char ** argv)
70+ RadioTrayLite::init (int argc, char ** argv, std::shared_ptr<CmdLineOptions>& opts )
7171{
72+ cmd_line_options = opts;
7273 config = std::make_shared<Config>();
7374
7475 load_configuration ();
7576
76- app = Gtk::Application::create (argc, argv, " github.com.thekvs.radiotray-lite" );
77+ // app = Gtk::Application::create(argc, argv, "github.com.thekvs.radiotray-lite");
78+ app = Gtk::Application::create (" github.com.thekvs.radiotray-lite" );
7779 app->register_application ();
7880 if (app->is_remote ()) {
7981 LOG (WARNING) << " This application is already running!" ;
@@ -124,6 +126,11 @@ RadioTrayLite::run()
124126 build_menu ();
125127
126128 app->hold ();
129+
130+ // resume the last played staion in timer callback
131+ sigc::slot<bool > resume_slot = sigc::bind (sigc::mem_fun (*this , &RadioTrayLite::resume), cmd_line_options->resume );
132+ sigc::connection conn = Glib::signal_timeout ().connect (resume_slot, 200 );
133+
127134 auto rc = app->run ();
128135
129136 return rc;
@@ -175,6 +182,34 @@ RadioTrayLite::on_current_station_button()
175182 }
176183}
177184
185+ bool
186+ RadioTrayLite::resume (bool resume_last_station)
187+ {
188+ if (resume_last_station) {
189+ if (config->has_last_station ()) {
190+ Glib::ustring data_url;
191+ try {
192+ std::stringstream xpath_query;
193+ xpath_query << " //bookmark[@name='" << config->get_last_played_station () << " ']" ;
194+
195+ pugi::xpath_node node = bookmarks_doc.select_node (xpath_query.str ().c_str ());
196+ if (not node.node ().empty ()) {
197+ data_url = node.node ().attribute (" url" ).as_string ();
198+ }
199+ } catch (pugi::xpath_exception& exc) {
200+ LOG (WARNING) << " XPath error: " << exc.what ();
201+ }
202+
203+ LOG (DEBUG) << " Resuming the last played station: " << config->get_last_played_station () << " (stream url: " << data_url << " )" ;
204+ player->play (data_url, config->get_last_played_station ());
205+ }
206+ }
207+
208+ // When we return false from the timer callback it deletes itself automatically
209+ // and won't be executed any more. So we have one time event here.
210+ return false ;
211+ }
212+
178213void
179214RadioTrayLite::build_menu ()
180215{
0 commit comments