コード例 #1
0
QVariant QVariantTree::internalDelTreeValue(const QVariant& root,
                                    const QVariantList& address,
                                    bool* isValid) const
{
    QVariant result = root;
    bool trueValid = true;

    if (address.isEmpty())
        result.clear(); // if no address -> invalid
    else if (address.count() == 1) {
        QVariantTreeElementContainer* containerType = containerOf(result.type());
        if (containerType == NULL)
            trueValid = false;
        else
            result = containerType->delItem(result, address.first());
    }
    else {
        QVariantTreeElementContainer* containerType = containerOf(result.type());
        if (containerType && containerType->keys(result).contains(address.first())) {
            result = containerType->item(result, address.first());
            result = internalDelTreeValue(result, address.mid(1));
            result = containerType->setItem(root, address.first(), result);
        }
        else
            trueValid = false;
    }

    if (isValid)
        *isValid = trueValid;

    return result;
}
コード例 #2
0
ファイル: btjson.cpp プロジェクト: AlexTalker/qBittorrent
/**
 * Returns all the torrents in JSON format.
 *
 * The return value is a JSON-formatted list of dictionaries.
 * The dictionary keys are:
 *   - "hash": Torrent hash
 *   - "name": Torrent name
 *   - "size": Torrent size
 *   - "progress: Torrent progress
 *   - "dlspeed": Torrent download speed
 *   - "upspeed": Torrent upload speed
 *   - "priority": Torrent priority (-1 if queuing is disabled)
 *   - "num_seeds": Torrent seeds connected to
 *   - "num_complete": Torrent seeds in the swarm
 *   - "num_leechs": Torrent leechers connected to
 *   - "num_incomplete": Torrent leechers in the swarm
 *   - "ratio": Torrent share ratio
 *   - "eta": Torrent ETA
 *   - "state": Torrent state
 *   - "seq_dl": Torrent sequential download state
 *   - "f_l_piece_prio": Torrent first last piece priority state
 *   - "force_start": Torrent force start state
 *   - "category": Torrent category
 */
QByteArray btjson::getTorrents(QString filter, QString category,
                               QString sortedColumn, bool reverse, int limit, int offset)
{
    QVariantList torrentList;
    TorrentFilter torrentFilter(filter, TorrentFilter::AnyHash, category);
    foreach (BitTorrent::TorrentHandle *const torrent, BitTorrent::Session::instance()->torrents()) {
        if (torrentFilter.match(torrent))
            torrentList.append(toMap(torrent));
    }

    std::sort(torrentList.begin(), torrentList.end(), QTorrentCompare(sortedColumn, reverse));
    int size = torrentList.size();
    // normalize offset
    if (offset < 0)
        offset = size + offset;
    if ((offset >= size) || (offset < 0))
        offset = 0;
    // normalize limit
    if (limit <= 0)
        limit = -1; // unlimited

    if ((limit > 0) || (offset > 0))
        return json::toJson(torrentList.mid(offset, limit));
    else
        return json::toJson(torrentList);
}
コード例 #3
0
QVariant QVariantTree::internalSetTreeValue(const QVariant& root,
                                    const QVariantList& address,
                                    const QVariant& value,
                                    bool* isValid) const
{
    QVariant result = root;
    bool trueValid = true;

    if (address.isEmpty())
        result = value;
    else {
        QVariantTreeElementContainer* containerType = containerOf(result.type());
        if (containerType && containerType->keys(result).contains(address.first())) {
            result = containerType->item(result, address.first());
            result = internalSetTreeValue(result, address.mid(1), value);
            result = containerType->setItem(root, address.first(), result);
        }
        else
            trueValid = false;
    }

    if (isValid)
        *isValid = trueValid;

    return result;
}
コード例 #4
0
ファイル: NetReply.cpp プロジェクト: Artanomell/schat
NetReply::NetReply(const QVariantList &list)
{
  if (list.size() < 6)
    return;

  id      = list.at(1).toString();
  date    = list.at(2).toLongLong();
  status  = list.at(3).toInt();
  headers = list.at(4).toMap();
  data    = list.mid(5);
}
コード例 #5
0
ファイル: shotgun.cpp プロジェクト: mjmvisser/pug
const QVariantMap Shotgun::translateFiltersSimple(const QVariantList sgFilter) const
{
    QVariantMap condition;
    condition.insert("path", sgFilter[0]);
    condition.insert("relation", sgFilter[1]);

    QVariantList values = sgFilter.mid(2);
    if (values.length() == 1 && values[0].canConvert<QVariantList>())
        values = values[0].toList();

    condition["values"] = values;

    return condition;
}
コード例 #6
0
/**
 * @brief If is currently a server, reports updates in sync journal to the central services.
 * @return True if success
 */
bool CentralServiceReporter::reportSyncJournal()
{
    QObject parent;
    if (!m_proxyConnection->session(&parent)->isServer())
        return true;

    bool ok;
    QVariantMap serverState = getServerSyncState(&ok);
    if (!ok) {
        m_proxyConnection->message("Central Service Report: Failed to access the service");
        return false;
    }

    SyncServer syncServer(m_proxyConnection);
    QVariantList updates = syncServer.updates(serverState, true, QString());
    if (!updates.count())
        return true;

    ISettings *settings = m_proxyConnection->settings(&parent);
    settings->beginGroup("current_workspace");

    QVariantMap message;
    message.insert("workspace_id", settings->value("id").toString());
    message.insert("workspace_name", settings->value("name").toString());

    bool success = true;
    if (updates.count() < MaxUpdatesInReport) {
        message.insert("updates", updates);
        success = sendUpdates(message);
    } else {
        for (int i = 0; i < updates.count() && success; i += MaxUpdatesInReport) {
            message.insert("updates", updates.mid(i, MaxUpdatesInReport));
            success = sendUpdates(message);
        }
    }
    if (!success)
        m_proxyConnection->message("Central Service Report: Failed to report updates to the service");
    return success;
}
コード例 #7
0
ファイル: TabRow.cpp プロジェクト: Foorgol/DatabaseOverlayLib
  bool TabRow::doInit(const QString& whereClause, const QVariantList& params)
  {
    // make sure the database handle is correct
    if (db == NULL)
    {
      throw EmptyDatabaseHandleException();
    }
    
    // make sure the table name exists
    // the check is performed by the DbTab constructor (so we don't
    // need to re-write it here) and we can reuse the DbTab instance later
    // in this method
    DbTab tab = db->getTab(tabName);
    
    // Case 1: we already have a where clause for identifying the row
    if (whereClause.length() > 0)
    {
      QVariant result = db->execScalarQuery("SELECT id FROM " + tabName + " WHERE " + whereClause, params);
      if (result.isNull())
      {
        throw InvalidRowQualifierException();
      }
      rowId = result.toInt();
      
      return true;
    }
    
    // if we made it this far, we need to construct the where clause from either
    //    - the first argument in the params list; or
    //    - a standard where clause that ANDs all column/value pairs in the params list
    //
    
    // whatever case: we need a non-empty params list
    if (params.isEmpty())
    {
      throw InvalidRowQualifierException();
    }
    
    QString firstPara = params.at(0).toString();
    
    // Case 2:
    // all params are column/value pairs that should be ANDed
    //
    // We generate the where clause and transform this case into
    // "Case 3" (see below)
    QVariantList convertedParams;
    if (tab.hasColumn(firstPara))
    {
      convertedParams = prepWhereClause(params);
    } else {
      convertedParams = params;
    }

    // Case 3:
    // where clause in the first parameter entry and
    // all subsequent entries are placeholder-values
    // for the where-clause
    QString where = convertedParams.at(0).toString();
    QVariantList placeholders;
    if (convertedParams.length() > 1)
    {
      placeholders = convertedParams.mid(1);
    }

    QVariant result = db->execScalarQuery("SELECT id FROM " + tabName + " WHERE " + where, placeholders);
    if (result.isNull())
    {
      throw InvalidRowQualifierException();
    }
    rowId = result.toInt();

    return true;
  }
コード例 #8
0
QSPatch QSDiffRunnerAlgo::createInsertPatch(int from, int to, const QVariantList &source)
{
    int count = to - from + 1;

    return QSPatch(QSPatch::Insert, from, to, count, source.mid(from, count));
}