Ejemplo n.º 1
0
// Sort the entries in the hash table.
void SortVector::SortData()
{
    for (unsigned j = 0; j < 256; j++)
    {
        ObjEntry *oentry = &processObjects[j];
        // Sort this entry.  If it's very small just process it now.
        switch (oentry->objCount)
        {
        case 0: break; // Nothing there

        case 1: // Singleton - just restore the length word
            oentry->objList->SetLengthWord(lengthWord);
            break;

        case 2:
            {
                // Two items - process now
                PolyObject *obj1 = oentry->objList;
                PolyObject *obj2 = obj1->GetForwardingPtr();
                obj1->SetLengthWord(lengthWord);
                if (memcmp(obj1, obj2, OBJ_OBJECT_LENGTH(lengthWord)*sizeof(PolyWord)) == 0)
                {
                    shareWith(obj2, obj1);
                    oentry->shareCount++;
                }
                else obj2->SetLengthWord(lengthWord);
                break;
            }

        default:
            gpTaskFarm->AddWorkOrRunNow(sharingTask, this, oentry);
        }
    }
}
Ejemplo n.º 2
0
void ShareUserGroupWidget::slotCompleterActivated(const QModelIndex & index)
{
    if (_disableCompleterActivated)
        return;
    // The index is an index from the QCompletion model which is itelf a proxy
    // model proxying the _completerModel
    auto sharee = qvariant_cast<QSharedPointer<Sharee>>(index.data(Qt::UserRole));
    if (sharee.isNull()) {
        return;
    }

    /*
     * Add spinner to the bottom of the widget list
     */
    auto viewPort = _ui->scrollArea->widget();
    auto layout = viewPort->layout();
    auto indicator = new QProgressIndicator(viewPort);
    indicator->startAnimation();
    layout->addWidget(indicator);

    /*
     * Don't send the reshare permissions for federataed shares
     * https://github.com/owncloud/core/issues/22122#issuecomment-185637344
     */
    if (sharee->type() == Sharee::Federated) {
        int permissions = Share::PermissionRead | Share::PermissionUpdate;
        if (!_isFile) {
            permissions |= Share::PermissionCreate | Share::PermissionDelete;
        }
        _manager->createShare(_sharePath, Share::ShareType(sharee->type()),
                              sharee->shareWith(), Share::Permission(permissions));
    } else {
        _manager->createShare(_sharePath, Share::ShareType(sharee->type()),
                              sharee->shareWith(), Share::PermissionDefault);
    }

    _ui->shareeLineEdit->setEnabled(false);
    _ui->shareeLineEdit->setText(QString());
}
Ejemplo n.º 3
0
void ShareUserGroupWidget::slotCompleterActivated(const QModelIndex & index)
{
    // The index is an index from the QCompletion model which is itelf a proxy
    // model proxying the _completerModel
    auto sharee = qvariant_cast<QSharedPointer<Sharee>>(index.data(Qt::UserRole));
    if (sharee.isNull()) {
        return;
    }

    _manager->createShare(_sharePath, Share::ShareType(sharee->type()),
                          sharee->shareWith(), Share::PermissionDefault);

    _ui->shareeLineEdit->setText(QString());
}
Ejemplo n.º 4
0
void ShareUserGroupWidget::slotLineEditReturn()
{
    _disableCompleterActivated = false;
    // did the user type in one of the options?
    const auto text = _ui->shareeLineEdit->text();
    for (int i = 0; i < _completerModel->rowCount(); ++i) {
        const auto sharee = _completerModel->getSharee(i);
        if (sharee->format() == text
                || sharee->displayName() == text
                || sharee->shareWith() == text) {
            slotCompleterActivated(_completerModel->index(i));
            // make sure we do not send the same item twice (because return is called when we press
            // return to activate an item inthe completer)
            _disableCompleterActivated = true;
            return;
        }
    }

    // nothing found? try to refresh completion
    _completionTimer.start();
}
Ejemplo n.º 5
0
// Quicksort the list to detect cells with the same content.  These are made
// to share and removed from further sorting.
void SortVector::sortList(PolyObject *head, POLYUNSIGNED nItems, POLYUNSIGNED &shareCount)
{
    while (nItems > 2)
    {
        size_t bytesToCompare = OBJ_OBJECT_LENGTH(lengthWord)*sizeof(PolyWord);
        PolyObject *median = head;
        head = head->GetForwardingPtr();
        median->SetLengthWord(lengthWord);
        PolyObject *left = ENDOFLIST, *right = ENDOFLIST;
        POLYUNSIGNED leftCount = 0, rightCount = 0;
        while (head != ENDOFLIST)
        {
            PolyObject *next = head->GetForwardingPtr();
            int res = memcmp(median, head, bytesToCompare);
            if (res == 0)
            {
                // Equal - they can share
                shareWith(head, median);
                shareCount++;
            }
            else if (res < 0)
            {
                head->SetForwardingPtr(left);
                left = head;
                leftCount++;
            }
            else
            {
                head->SetForwardingPtr(right);
                right = head;
                rightCount++;
            }
            head = next;
        }
        // We can now drop the median and anything that shares with it.
        // Process the smaller partition recursively and the larger by
        // tail recursion.
        if (leftCount < rightCount)
        {
            sortList(left, leftCount, shareCount);
            head = right;
            nItems = rightCount;
        }
        else
        {
            sortList(right, rightCount, shareCount);
            head = left;
            nItems = leftCount;
        }
    }
    if (nItems == 1)
        head->SetLengthWord(lengthWord);
    else if (nItems == 2)
    {
        PolyObject *next = head->GetForwardingPtr();
        head->SetLengthWord(lengthWord);
        if (memcmp(head, next, OBJ_OBJECT_LENGTH(lengthWord)*sizeof(PolyWord)) == 0)
        {
            shareWith(next, head);
            shareCount++;
        }
        else next->SetLengthWord(lengthWord);
    }
}