int ProcessInfoListView::compareItem(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
	auto descendingOrder = lParamSort < 0;
	if (descendingOrder)
	{
		lParamSort = abs(lParamSort);
		return compareItem(lParam2, lParam1, lParamSort);
	}

	auto firstItem = reinterpret_cast<ProcessInfo*>(lParam1);
	auto secondItem = reinterpret_cast<ProcessInfo*>(lParam2);
	auto sortColumn = lParamSort - 1;
	auto compare = 0;

	switch (sortColumn)
	{
	case 0:
		compare = firstItem->getProcessPid() - secondItem->getProcessPid();
		if (compare != 0)
		{
			return compare;
		}
		return compareItem(lParam1, lParam2, 1);
	case 1:
		return _tcsicmp(firstItem->getProcessName(), secondItem->getProcessName());
	default:
		_ASSERT(false);
		return 0;
	}
}
Beispiel #2
0
bool testImage(const QImage& img, QByteArray *msg, bool *error)
{
    if (!connected && !connect(msg, error))
        return true;

    if (QTest::currentTestFunction() != curFunction || itemList.isEmpty()) {
        qWarning() << "Usage error: QBASELINE_TEST used without corresponding QBaselineTest::newRow()";
        return true;
    }

    if (!gotBaselines) {
        if (!proto.requestBaselineChecksums(QString::fromLatin1(QTest::currentTestFunction()), &itemList) || itemList.isEmpty()) {
            *msg = "Communication with baseline server failed: " + proto.errorMessage().toLatin1();
            *error = true;
            return true;
        }
        gotBaselines = true;
    }

    QString curTag = QString::fromLatin1(QTest::currentDataTag());
    ImageItemList::const_iterator it = itemList.constBegin();
    while (it != itemList.constEnd() && it->itemName != curTag)
        ++it;
    if (it == itemList.constEnd()) {
        qWarning() << "Usage error: QBASELINE_TEST used without corresponding QBaselineTest::newRow() for row" << curTag;
        return true;
    }
    return compareItem(*it, img, msg, error);
}
Beispiel #3
0
bool checkImage(const QImage &img, const char *name, quint16 checksum, QByteArray *msg, bool *error)
{
    if (!connected && !connect(msg, error))
        return true;

    QByteArray itemName;
    bool hasName = qstrlen(name);
    const char *tag = QTest::currentDataTag();
    if (qstrlen(tag)) {
        itemName = tag;
        if (hasName)
            itemName.append('_').append(name);
    } else {
        itemName = hasName ? name : "default_name";
    }

    *msg = "Baseline check of image '" + itemName + "': ";


    ImageItem item;
    item.itemName = QString::fromLatin1(itemName);
    item.itemChecksum = checksum;
    item.testFunction = QString::fromLatin1(QTest::currentTestFunction());
    ImageItemList list;
    list.append(item);
    if (!proto.requestBaselineChecksums(QLatin1String(QTest::currentTestFunction()), &list) || list.isEmpty()) {
        *msg = "Communication with baseline server failed: " + proto.errorMessage().toLatin1();
        *error = true;
        return true;
    }

    return compareItem(list.at(0), img, msg, error);
}
Beispiel #4
0
void ChannelAgent::AddUser(const char* nick, const int32 status)
{
	NameItem* compareItem(NULL);

	// make sure this nick doesn't already exist in the list
	// can happen since some ircds allow stealth quits that don't
	// broadcast a quit message
	int32 i;
	for (i = 0; i < fNamesList->CountItems(); i++) {
		compareItem = static_cast<NameItem*>(fNamesList->ItemAt(i));
		if (compareItem && compareItem->Name().ICompare(nick) == 0) return;
	}

	fNamesList->AddItem(new NameItem(nick, status));
	fNamesList->SortItems(SortNames);

	++fUserCount;
	BString buffer;
	buffer << fUserCount;
	BString* comparator(NULL);

	// check if new nickname matches against tab completion sequence and update nick list
	// if so
	if (fLastExpansion.Length() > 0 &&
		fLastExpansion.ICompare(nick, fLastExpansion.Length()) == 0) {
		int32 count(fCompletionNicks.CountItems());
		for (i = count - 1; i >= 0; i--) {
			comparator = fCompletionNicks.ItemAt(i);
			if (comparator && comparator->ICompare(nick) < 0) {
				BString* string(new BString(nick));
				fCompletionNicks.AddItem(string, i + 1);
				break;
			}
		}
	}

	if (!IsHidden())
		vision_app->pClientWin()->pStatusView()->SetItemValue(STATUS_USERS, buffer.String());
}
int FileInfoListView::compareItem(LPARAM lParam1,
                                   LPARAM lParam2,
                                   LPARAM lParamSort)
{
  // check ascending order
  bool sortAscending = lParamSort > 0;

  FileInfo *firstItem = reinterpret_cast<FileInfo *>(lParam1);
  FileInfo *secondItem = reinterpret_cast<FileInfo *>(lParam2);

  // Fake directory ".." should be into top list.
  if (_tcscmp(firstItem->getFileName(), _T("..")) == 0) {
    return -1;
  }

  if (_tcscmp(secondItem->getFileName(), _T("..")) == 0) {
    return 1;
  }

  // Directories should be upper, than files.
  if (firstItem->isDirectory() && !secondItem->isDirectory()) {
    return -1;
  }
  if (!firstItem->isDirectory() && secondItem->isDirectory()) {
    return 1;
  }
  
  // change lParam1 and lParam2 with each other if order is descending
  if (sortAscending) {
    firstItem = reinterpret_cast<FileInfo *>(lParam1);
    secondItem = reinterpret_cast<FileInfo *>(lParam2);
  } else {
    firstItem = reinterpret_cast<FileInfo *>(lParam2);
    secondItem = reinterpret_cast<FileInfo *>(lParam1);
  }

  if (lParamSort < 0) {
    // calculate column number when order is descending
    lParamSort = abs(lParamSort) - 1;
  } else {
    // calculate column number when order is ascending
    lParamSort -= 1;
  }
 
  switch (lParamSort) {
  // It's column "FileName".
  case 0:
    return _tcsicmp(firstItem->getFileName(), secondItem->getFileName());

  // It's column "FileSize".
  case 1:
    {
      // Size of directory is 0. Sort him by name.
      if (firstItem->isDirectory()) {
        return compareItem(lParam1, lParam2, 1);
      }
      int compareSize = compareUInt64(firstItem->getSize(), secondItem->getSize());
      // Sort by name, if sizes is equal.
      if (compareSize == 0) {
        return compareItem(lParam1, lParam2, 1);
      }
      return compareSize;
    }
  // It's column "Last modified".
  case 2:
    {
      int compareTime = compareUInt64(firstItem->lastModified(), secondItem->lastModified());
      // Sort by name, if time stamps is equal.
      if (compareTime == 0) {
        return compareItem(lParam1, lParam2, 1);
      }
      return compareTime;
    }
  // It's unknown column.
  default:
    _ASSERT(false);
    return 0;
  }
}