Ejemplo n.º 1
0
void GroovePlaylistModel::setCurrentTrackIndex(int trackIndex)
{
    if (GROOVE_VERIFY(trackIndex >= -1, "trackIndex too low")) return;
    if (GROOVE_VERIFY(trackIndex < m_songs.count(), "trackIndex too high")) return;

    m_currentTrack = trackIndex;
}
Ejemplo n.º 2
0
void GroovePlaylistModel::removeAt(int songPosition)
{
    if (GROOVE_VERIFY(songPosition >= 0, "songPosition is less than 0")) return;
    if (GROOVE_VERIFY(songPosition < m_songs.count(), "songPosition is greater than the number of songs")) return;

    beginRemoveRows(QModelIndex(), songPosition, songPosition);
    m_songs.at(songPosition)->deref();
    m_songs.removeAt(songPosition);
    endRemoveRows();
}
Ejemplo n.º 3
0
int GroovePlaylistModel::indexOf(GrooveSong *song, int from)
{
    if (GROOVE_VERIFY(song, "song is NULL")) return -1;
    if (GROOVE_VERIFY(from >= 0, "from is negative")) return -1;
    if (GROOVE_VERIFY(from <= m_songs.count(), "from is higher than the playlist length")) return -1;

    for (int i = from; i != m_songs.count(); ++i) {
        if (m_songs.at(i) == song)
            return i;
    }

    return -1;
}
Ejemplo n.º 4
0
void GroovePlaylistModel::insert(int position, GrooveSong *song)
{
    if (GROOVE_VERIFY(song, "song is NULL")) return;
    if (GROOVE_VERIFY(position >= 0, "position is less than 0")) return;
    if (GROOVE_VERIFY(position <= m_songs.count(), "position is greater than it should be")) return;

    // acquire a ref
    song->ref();

    beginInsertRows(QModelIndex(), position, position);
    m_songs.insert(position, song);
    endInsertRows();
}
Ejemplo n.º 5
0
void GroovePlaylistModel::append(GrooveSong *song)
{
    if (GROOVE_VERIFY(song, "song is NULL")) return;

    // ref is made inside insert()
    insert(m_songs.count(), song);
}
Ejemplo n.º 6
0
QString
GrooveClient::Private::grooveMessageToken (QString const &method) const
{
  if (GROOVE_VERIFY (m_sessionToken.length (), "made a request to create message without session token"))
    return QString ();

  QString rnum = QString (qrand () % 9 + 48)
               + QString (qrand () % 9 + 48)
               + QString (qrand () % 9 + 48)
               + QString (qrand () % 9 + 48)
               + QString (qrand () % 9 + 48)
               + QString (qrand () % 9 + 48)
               ;

  QString messageToken;
  messageToken.append (method);
  messageToken.append (":");
  messageToken.append (m_sessionToken.toAscii ());
  messageToken.append (":quitStealinMahShit:");
  messageToken.append (rnum);

  QString rs;
  rs.append (rnum);
  rs.append (QCryptographicHash::hash (messageToken.toAscii (), QCryptographicHash::Sha1).toHex ());

  LDEBUG << "Produced token: " << rs;
  return rs;
}
Ejemplo n.º 7
0
void
GrooveClient::Private::processSessionToken ()
{
  QNetworkReply *reply = qobject_cast<QNetworkReply *> (sender ());

  if (GROOVE_VERIFY (reply, "called without a QNetworkReply as sender"))
    return;

  bool ok;
  QJson::Parser parser;

  QByteArray sessionTokenReply = reply->readAll ();
  QVariantMap result = parser.parse (sessionTokenReply, &ok).toMap ();

  if (!ok)
    LDEBUG << "Session token request failed:" << sessionTokenReply;

  GROOVE_VERIFY_OR_DIE (ok, "couldn't parse reply to session token request");
  GROOVE_VERIFY_OR_DIE (result["message"].toString ().isEmpty (), qPrintable (result["message"].toString ()));

  m_sessionToken = result["result"].toString ();
  LDEBUG << "Got session token: " << m_sessionToken;

  if (!m_sessionToken.length ())
    {
      LDEBUG << "Session token empty:";
      LDEBUG << sessionTokenReply;
      LDEBUG << reply->errorString ();
    }

  emit connected ();
}
Ejemplo n.º 8
0
void
GroovePlaylistModel::append (GrooveSongPointer song)
{
  if (GROOVE_VERIFY (song, "song is NULL"))
    return;

  insert (m_songs.count (), song);
}
Ejemplo n.º 9
0
int
GroovePlaylistModel::indexOf (GrooveSongPointer song, int from)
{
  if (GROOVE_VERIFY (song, "song is NULL"))
    return -1;
  if (GROOVE_VERIFY (from >= 0, "from is negative"))
    return -1;
  if (GROOVE_VERIFY (from <= m_songs.count (), "from is higher than the playlist length"))
    return -1;

#if 0
  for (int i = from; i != m_songs.count (); ++i)
    if (m_songs.at (i) == song)
      return i;
#else
  auto found = std::find (m_songs.begin (), m_songs.end (), song);
  if (found != m_songs.end ())
    return found - m_songs.begin ();
#endif

  return -1;
}
Ejemplo n.º 10
0
void GrooveRequest::onFinished()
{
    QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
    if (GROOVE_VERIFY(reply, "search returned without a QNetworkReply")) return;

    if (!reply->error()) {
        QByteArray response = reply->readAll();

        bool success = processData(response);

        // don't cache if there was a fault code
        if (success) {
            QString cacheKey = generateCacheKey();

            // TODO: codeshare with GrooveStream so we don't reinvent caching like this
            if (cacheKey.length()) {
                qDebug() << Q_FUNC_INFO << "Cached a " << response.size() << " byte response with cache key " << cacheKey;
                QString cachePath = QDesktopServices::storageLocation(QDesktopServices::CacheLocation) + "/libgroove/cache/api/";
                QDir dir;
                if (!dir.mkpath(cachePath)) {
                } else {
                    cachePath += cacheKey;
                    QFile cacheFile(cachePath);
                    if (!cacheFile.open(QIODevice::WriteOnly)) {
                        qDebug() << Q_FUNC_INFO << "Cannot open cache file! " << cacheFile.errorString();
                    } else {
                        cacheFile.write(response);
                    }
                }
            }
        }
    } else {
        qDebug() << Q_FUNC_INFO << "Not emitting for failed RPC";
        return;
    }

    qDebug() << Q_FUNC_INFO << "Destroying response";
    deleteLater();
}
Ejemplo n.º 11
0
qint64 GrooveStream::readData(char *data, qint64 maxlen)
{
    if (GROOVE_VERIFY(data, "data pointer is NULL")) return 0;

    return d->readData(data, maxlen);
}