SpotifySession::SpotifySession( sessionConfig config, QObject *parent )
   : QObject( parent )
   , m_pcLoaded( false )
   , m_sessionConfig( config )
   , m_loggedIn( false )
   , m_relogin( false )
{

    // Instance
    s_instance = this;
    // Friends
    m_SpotifyPlaylists = new SpotifyPlaylists( this );
    connect( m_SpotifyPlaylists, SIGNAL( sendLoadedPlaylist( SpotifyPlaylists::LoadedPlaylist ) ), this, SLOT(playlistReceived(SpotifyPlaylists::LoadedPlaylist) ) );

    // Playlist cachemiss fix
    // @note: bad way of handling exitfails
    connect( m_SpotifyPlaylists, SIGNAL( forcePruneCache() ), this, SLOT( relogin() ) );

    m_SpotifyPlayback = new SpotifyPlayback( this );

    // Connect to signals
    connect( this, SIGNAL( notifyMainThreadSignal() ), this, SLOT( notifyMainThread() ), Qt::QueuedConnection );
    qDebug() << " === Using LibVersion " << SPOTIFY_API_VERSION << " ===";
    // User needs to create session himself, that way, config
    //createSession();
}
/**
  notifyMainThread
  this will be called when spotify needs to process events
  **/
void SpotifySession::notifyMainThread()
{
    int timeout = 0;
    do {
        sp_session_process_events( m_session, &timeout );
    } while( !timeout );

    QTimer::singleShot( timeout, this, SLOT( notifyMainThread() ) );
}
void BlockDataViewer::flagRefresh(BDV_refresh refresh, const BinaryData& refreshID)
{ 
   if (saf_->bdmIsRunning() == false)
      return;

   unique_lock<mutex> lock(refreshLock_);

   if (refresh_ != BDV_refreshAndRescan)
   {
      if (refresh == BDV_refreshAndRescan)
         refresh_ = BDV_refreshAndRescan;
      else
         refresh_ = BDV_refreshSkipRescan;
   }

   if (refreshID.getSize())
      refreshIDSet_.insert(refreshID);
   
   if (refresh == BDV_filterChanged)
      refreshIDSet_.insert(BinaryData("wallet_filter_changed"));

   notifyMainThread();
}