Example #1
0
MainWindow::MainWindow(QWindow *parent)
    : QQuickView(parent)
{
    setSource(QUrl::fromLocalFile("H:/VK/main.qml").toString());

    photoSize = "130";


    // !!! SET QNAM AND CACHE
    manager = new QNetworkAccessManager(this);
    cache = new QNetworkDiskCache(this);
    // 500 Mb
    cache->setMaximumCacheSize(500*1024*1024);
    cache->setCacheDirectory("cacheDir");
    manager->setCache(cache);

    // SET CACHED NAM TO QMLENGINE TO
    MyNetworkAccessManagerFactory* namFactory = new MyNetworkAccessManagerFactory();
    QQmlEngine* eng =  engine();
    eng->setNetworkAccessManagerFactory(namFactory);


    QQmlProperty((QObject*)rootObject(), "color").write("#F5F5F5");
    QQmlProperty((QObject*)rootObject(), "height").write(height());


    wallObj = rootObject();
    //wallObj->setProperty("color", "#F5F5F5");
    //wallObj->setProperty("height",height());

    connect((QObject*)wallObj, SIGNAL(login()),this,SLOT(login()));
    connect((QObject*)wallObj, SIGNAL(getGroups()),this, SLOT(getGroups()));
    connect((QObject*)wallObj, SIGNAL(getWall(QString)),this, SLOT(getWall(QString)));
    connect((QObject*)wallObj, SIGNAL(morePosts()), this, SLOT(morePosts()));
    connect((QObject*)wallObj, SIGNAL(setPhotoSize(QString)), this, SLOT(setPhotoSize(QString)));


    LoadIni("H:/VK/config.ini");
    // do we have token
    if( settings->contains("token")){
        // its a unlimit token
        qDebug() << " HAVE TOKEN ";
        if(ReadConfig("expires").toInt()==0){
            Token = ReadConfig("token").toString();
        }
        // if no doesnt it token expire
        else if(ReadConfig("expDate").toDate()<=QDate::currentDate()){
            Token = ReadConfig("token").toString();
        }
    // if havent token login
    }else{
        login();
        qDebug() << " NEED LOGIN ";
    }
}
RequestOut<TGetLabInfoListReplyData> LabService::getLabInfoList(const RequestIn<TGetLabInfoListRequestData> &in,
        quint64 userId)
{
    typedef RequestOut<TGetLabInfoListReplyData> Out;
    Translator t(in.locale());
    QString error;
    if (!commonCheck(t, &error))
        return Out(error);
    if (!checkUserId(t, userId, &error))
        return Out(error);
    QDateTime dt = QDateTime::currentDateTime();
    bool ok = false;
    int lvlSelf = UserRepo->findAccessLevel(userId, &ok).level();
    if (!ok)
        return Out(t.translate("LabService", "Failed to get user access level (internal)", "error"));
    TIdList groups = (lvlSelf < TAccessLevel::ModeratorLevel) ? getGroups(userId, &ok) : getAllGroups(&ok);
    if (!ok)
        return Out(t.translate("LabService", "Failed to get user group list (internal)", "error"));
    QList<Lab> entities = LabRepo->findAllNewerThan(userId, in.lastRequestDateTime(), groups, &ok);
    if (!ok)
        return Out(t.translate("LabService", "Failed to get lab list (internal)", "error"));
    TLabInfoList newLabs;
    TIdList deletedLabs = LabRepo->findAllDeletedNewerThan(userId, in.lastRequestDateTime(), groups, &ok);
    if (!ok)
        return Out(t.translate("LabService", "Failed to get deleted lab list (internal)", "error"));
    foreach (const Lab &entity, entities) {
        newLabs << labToLabInfo(entity, &ok);
        if (!ok)
            return Out(t.translate("LabService", "Failed to create lab info (internal)", "error"));
    }
Example #3
0
void FiGroupWidget::groupOpen(int row, int)
{
  mMotherName->setText(mGroupView->item(row, 1)->text());
  mMotherId = mGroupView->item(row, 0)->text().toInt();
  getGroups();
  setActiveGroup("");
}
Example #4
0
void
OSXKeyState::checkKeyboardLayout()
{
	// XXX -- should call this when notified that groups have changed.
	// if no notification for that then we should poll.
	GroupList groups;
	if (getGroups(groups) && groups != m_groups) {
		updateKeyMap();
		updateKeyState();
	}
}
Example #5
0
OP_ERROR
SOP_Cleave::cookMySop(OP_Context &context)
{

    const GA_PrimitiveGroup  *polyGroup;

    GEO_Primitive     	*prim;
    GQ_Detail           *gqd;
    int                  i,j,k;
    UT_Vector4           np,p;

    // Before we do anything, we must lock our inputs.  Before returning,
    //	we have to make sure that the inputs get unlocked.
    if (lockInputs(context) >= UT_ERROR_ABORT) return error();

    float now = context.getTime();
    duplicateSource(0, context, 0, 1);

    // Here we determine which groups we have to work on.  We only
    //	handle poly groups.

    UT_String groups;
    getGroups(groups);

    if (groups.isstring()) polyGroup = parsePrimitiveGroups(groups);
    else                   polyGroup = 0;

    if (error() >= UT_ERROR_ABORT) {
        unlockInputs();
        return error();
    }

    UT_Interrupt* boss = UTgetInterrupt();

    // Start the interrupt server
    boss->opStart("Cleaving Polys");


    // separate out all polys to be cleaved
    GA_PrimitiveGroup* cleave_group = gdp->newPrimitiveGroup("cleave",1);
    GA_PrimitiveGroup* not_cleave_group = gdp->newPrimitiveGroup("not_cleave",1);

    if (polyGroup) {

        GA_FOR_ALL_PRIMITIVES(gdp,prim)
        {

            if ( (prim->getTypeId()==GEO_PRIMPOLY) && (polyGroup->contains(prim)!=0))
                cleave_group->add(prim);
            else
                not_cleave_group->add(prim);
        }

    } else {
Example #6
0
void MapAnalyzer::closeChokepoint(std::set<pTileNode>& chokePoint) {
	auto el = *chokePoint.begin();
	pred unwalkable = [](pTileNode n) {
		return n->value == 0;
	};
	const auto& neighbors = getSurroundingNodeInSquare(el->pos, 4, unwalkable);
	auto groups = getGroups(neighbors, 1);

	for (auto g : groups) {
		auto pointFromGroup = *g.begin();
		closeLine(pointFromGroup, el);
	}
}
Example #7
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QTextCodec *utfCodec = QTextCodec::codecForName("UTF-8");
    QTextCodec::setCodecForLocale(utfCodec);
    MainWindow w;
    w.show();
    GroupForm groupForm;
    QObject::connect(&w,SIGNAL(gotUser(QString,QString)), &groupForm, SLOT(getGroups(QString,QString)));
    QObject::connect(&groupForm,SIGNAL(authenticateGroups(QVector<QString>)), &w, SLOT(authenticateGroups(QVector<QString>)));


    return a.exec();
}
Example #8
0
void FiGroupWidget::groupEdited(int row, int /*column*/)
{
  if(!mEditing) return;

  mGroupView->resizeColumnsToContents();

  int groupId  = mGroupView->item(row, 0)->text().toInt();
  QString name = mGroupView->item(row, 1)->text();
  int motherId = mGroupView->item(row, 2)->text().toInt();
//qDebug() << groupId << name << motherId;
  mFilu->putGroup(groupId, name, motherId);
  getGroups();
  setActiveGroup(name);
}
Example #9
0
void FiGroupWidget::loadSettings()
{
  mSplitter->restoreState(mRcFile->getBA("SplitterSizes"));
  mMotherName->setText(mRcFile->getST("MotherName"));
  mMotherId = mRcFile->getIT("MotherGroupId");
  mCurrendGroupId = mRcFile->getIT("CurrentGroupId");

  getGroups();
  // Activate group (highlight)
  for(int i = 0; i < mGroupView->rowCount(); ++i)
  {
    if(mGroupView->item(i, 0)->text().toInt() != mCurrendGroupId) continue;
    mGroupView->setCurrentCell(i, 1);
    getGMembers();
    break;
  }
}
Example #10
0
void
OSXKeyState::getKeyMap(synergy::KeyMap& keyMap)
{
	// update keyboard groups
	if (getGroups(m_groups)) {
		m_groupMap.clear();
		SInt32 numGroups = (SInt32)m_groups.size();
		for (SInt32 g = 0; g < numGroups; ++g) {
			m_groupMap[m_groups[g]] = g;
		}
	}

	UInt32 keyboardType = LMGetKbdType();
	for (SInt32 g = 0, n = (SInt32)m_groups.size(); g < n; ++g) {
		// add special keys
		getKeyMapForSpecialKeys(keyMap, g);

		const void* resource;
		bool layoutValid = false;
		
		// add regular keys
		// try uchr resource first
		#if defined(MAC_OS_X_VERSION_10_5)
		CFDataRef resourceRef = (CFDataRef)TISGetInputSourceProperty(
			m_groups[g], kTISPropertyUnicodeKeyLayoutData);
		layoutValid = resourceRef != NULL;
		if (layoutValid)
			resource = CFDataGetBytePtr(resourceRef);
		#else
		layoutValid = KLGetKeyboardLayoutProperty(
			m_groups[g], kKLuchrData, &resource);
		#endif

		if (layoutValid) {
			CUCHRKeyResource uchr(resource, keyboardType);
			if (uchr.isValid()) {
				LOG((CLOG_DEBUG1 "using uchr resource for group %d", g));
				getKeyMap(keyMap, g, uchr);
				continue;
			}
		}

		LOG((CLOG_DEBUG1 "no keyboard resource for group %d", g));
	}
}
Example #11
0
void FiGroupWidget::groupUp()
{
  QSqlQuery* query = mFilu->getGroups(-1); // Get all groups
  if(!query)
  {
    // Absolutly no groups. Make a 'reset'.
    mMotherId = 0;
    mCurrendGroupId = 0;
    mMotherName->setText("");
    return;
  }

  // query looks like
  // group_id, name, mothergroup_id
  while(query->next())
  {
    // Search mother
    if(query->value(0).toInt() == mMotherId) break;
  }

  // Check if found. Could happens when group was deleted meanwhile.
  mMotherId = 0;
  mMotherName->setText("");
  QString actGroup;
  if(query->isValid())
  {
    actGroup  = query->value(1).toString();
    mMotherId = query->value(2).toInt();
  }

  if(mMotherId)
  {
    query->seek(-1);
    while(query->next())
    {
      // Search grandmother
      if(query->value(0).toInt() == mMotherId) break;
    }
    mMotherName->setText(query->value(1).toString());
  }

  getGroups();
  setActiveGroup(actGroup);
}
Example #12
0
void MapAnalyzer::CalculateChokepoints() {
	auto mw = Broodwar->mapWidth();
	auto mh = Broodwar->mapHeight();
	const auto& groupedUnwalkables = getUnwalkableGroups();

	for (auto g : groupedUnwalkables) {
		if (g.isSignificant()) {
			for (auto t : g.tiles) {
				auto node = getNode(t);
				if (t.y != mh - 1)
					node->value = 0;
				else
					node->value = getNode(t.x, t.y - 1)->value;
			}
		}
	}

	CalculateDistancesToUnWalkables();
	CalcChokePoints();

	std::vector<pTileNode> tmp;
	tmp = getNodes([](pTileNode n){return n->inChokepoint; });

	for (auto it = tmp.begin(); it != tmp.end(); it++) {
		auto c = *it;
		if (!isCornerChokepoint(c)) {
			cp.insert(c);
		}
	}

	auto cps = getGroups(cp, 1);
	std::vector<ChokePoint> chokpoints;
	for (int i = 0; i < cps.size(); ++i) {
		closeChokepoint(cps[i]);
		for (auto c : cps[i]) {
			c->chokePointId = i;
		}
		auto cp = pChokePoint(new ChokePoint(cps[i], nodeMap));
		cp->id = i;
		chokpts[i] = cp;
	}
}
Example #13
0
std::shared_ptr<Group> OsgManager::getOrCreateGroup(const std::string& name)
{
	std::shared_ptr<Group> result;
	auto groups = getGroups();

	auto group = groups.find(name);

	if (group == std::end(groups))
	{
		auto newGroup = std::make_shared<OsgGroup>(name);
		addGroup(newGroup);
		result = newGroup;
	}
	else
	{
		result = group->second;
	}

	return result;
}
Example #14
0
void FiGroupWidget::removeGroup()
{
  //qDebug() << "removeGroup";
  QModelIndexList mil = mGroupView->selectionModel()->selectedIndexes();

  for(int i = 0; i< mil.size(); ++i)
  {
    if(mil.at(i).column() != 0) continue;
    QString message = tr("\nAre you sure to delete '<Group>' and all its contents?.\n");
    message.replace("<Group>", mGroupView->item(mil.at(i).row(), 1)->text());

    int ret = QMessageBox::question(this, tr("performerf - question box"),
                   message,
                   QMessageBox::Yes | QMessageBox::No);

    if(ret == QMessageBox::Yes)
      mFilu->deleteRecord("group", mil.at(i).data().toInt(), Filu::eUser);
  }

  getGroups();
}
Example #15
0
void GroupDetectors2::exec()
{
  // Get the input workspace
  const MatrixWorkspace_const_sptr inputWS = getProperty("InputWorkspace");

  //Check if it is an event workspace
  const bool preserveEvents = getProperty("PreserveEvents");
  EventWorkspace_const_sptr eventW = boost::dynamic_pointer_cast<const EventWorkspace>(inputWS);
  if (eventW != NULL && preserveEvents)
  {
    this->execEvent();
    return;
  }

  const size_t numInHists = inputWS->getNumberHistograms();
  // Bin boundaries need to be the same, so do the full check on whether they actually are
  if (!API::WorkspaceHelpers::commonBoundaries(inputWS))
  {
    g_log.error() << "Can only group if the histograms have common bin boundaries\n";
    throw std::invalid_argument("Can only group if the histograms have common bin boundaries");
  }
  progress( m_FracCompl = CHECKBINS );
  interruption_point();

  // some values loaded into this vector can be negative so this needs to be a signed type
  std::vector<int64_t> unGroupedInds;
  //the ungrouped list could be very big but might be none at all
  unGroupedInds.reserve(numInHists);
  for( size_t i = 0; i < numInHists ; i++ )
  {
    unGroupedInds.push_back(i);
  }

  // read in the input parameters to make that map, if KeepUngroupedSpectra was set we'll need a list of the ungrouped spectrra too
  getGroups(inputWS, unGroupedInds);

  // converting the list into a set gets rid of repeated values, here the multiple GroupDetectors2::USED become one USED at the start
  const std::set<int64_t> unGroupedSet(unGroupedInds.begin(), unGroupedInds.end());

  // Check what the user asked to be done with ungrouped spectra
  const bool keepAll = getProperty("KeepUngroupedSpectra");
  // ignore the one USED value in set or ignore all the ungrouped if the user doesn't want them
  const size_t numUnGrouped = keepAll ? unGroupedSet.size()-1 : 0;

  MatrixWorkspace_sptr outputWS =
    WorkspaceFactory::Instance().create(inputWS, m_GroupSpecInds.size()+ numUnGrouped,
                                        inputWS->readX(0).size(), inputWS->blocksize());

  // prepare to move the requested histograms into groups, first estimate how long for progress reporting. +1 in the demonator gets rid of any divide by zero risk
  double prog4Copy=( (1.0 - m_FracCompl)/(static_cast<double>(numInHists-unGroupedSet.size())+1.) )*
    (keepAll ? static_cast<double>(numInHists-unGroupedSet.size())/static_cast<double>(numInHists): 1.);

  // Build a new map
  const size_t outIndex = formGroups(inputWS, outputWS, prog4Copy);

  // If we're keeping ungrouped spectra
  if (keepAll)
  {
    // copy them into the output workspace
    moveOthers(unGroupedSet, inputWS, outputWS, outIndex);
  } 
  
  g_log.information() << name() << " algorithm has finished\n";

  setProperty("OutputWorkspace",outputWS);
}
Example #16
0
void GroupDetectors2::execEvent()
{
    // Get the input workspace
    const MatrixWorkspace_const_sptr matrixInputWS = getProperty("InputWorkspace");
    EventWorkspace_const_sptr inputWS= boost::dynamic_pointer_cast<const EventWorkspace>(matrixInputWS);


    const size_t numInHists = inputWS->getNumberHistograms();
    progress( m_FracCompl = CHECKBINS );
    interruption_point();

    // some values loaded into this vector can be negative so this needs to be a signed type
    std::vector<int64_t> unGroupedInds;
    //the ungrouped list could be very big but might be none at all
    unGroupedInds.reserve(numInHists);
    for( size_t i = 0; i < numInHists ; i++ )
    {
      unGroupedInds.push_back(i);
    }

    // read in the input parameters to make that map, if KeepUngroupedSpectra was set we'll need a list of the ungrouped spectrra too
    getGroups(inputWS, unGroupedInds);

    // converting the list into a set gets rid of repeated values, here the multiple GroupDetectors2::USED become one USED at the start
    const std::set<int64_t> unGroupedSet(unGroupedInds.begin(), unGroupedInds.end());

    // Check what the user asked to be done with ungrouped spectra
    const bool keepAll = getProperty("KeepUngroupedSpectra");
    // ignore the one USED value in set or ignore all the ungrouped if the user doesn't want them
    const size_t numUnGrouped = keepAll ? unGroupedSet.size()-1 : 0;

    //Make a brand new EventWorkspace
    EventWorkspace_sptr outputWS = boost::dynamic_pointer_cast<EventWorkspace>(
        WorkspaceFactory::Instance().create("EventWorkspace",  m_GroupSpecInds.size()+ numUnGrouped,
                                                  inputWS->readX(0).size(), inputWS->blocksize()));
    //Copy geometry over.
    WorkspaceFactory::Instance().initializeFromParent(inputWS, outputWS, true);

    // prepare to move the requested histograms into groups, first estimate how long for progress reporting. +1 in the demonator gets rid of any divide by zero risk
    double prog4Copy=( (1.0 - m_FracCompl)/(static_cast<double>(numInHists-unGroupedSet.size())+1.) )*
      (keepAll ? static_cast<double>(numInHists-unGroupedSet.size())/static_cast<double>(numInHists): 1.);

    // Build a new map
    const size_t outIndex = formGroupsEvent(inputWS, outputWS, prog4Copy);

    // If we're keeping ungrouped spectra
    if (keepAll)
    {
      // copy them into the output workspace
      moveOthersEvent(unGroupedSet, inputWS, outputWS, outIndex);
    }

    //Set all X bins on the output
    cow_ptr<MantidVec> XValues;
    XValues.access() = inputWS->readX(0);
    outputWS->setAllX(XValues);

    g_log.information() << name() << " algorithm has finished\n";

    setProperty("OutputWorkspace",outputWS);
}
Example #17
0
void TextSprite::createGeometry()
{
	Model::GroupMap &groups = getGroups();
	GeometryPtr &g = groups[bRenderer::DEFAULT_GROUP_NAME()];
	if (!g)
		g = GeometryPtr(new Geometry);

	GeometryDataPtr gData = GeometryDataPtr(new GeometryData);

	GLuint verNum = 6;
	GLuint fontPixelSize = _font->getPixelSize();
	// Initialize position of the first sprite
	GLfloat pos_x = 0.f;
	GLfloat pos_y = 0.f;
	GLfloat z = 0.f;
	bool beginningofLine = true;

	// Create a sprite per character
	for (GLuint i = 0; i < _text.length(); i++){
		if (_text.at(i) == '\n')
		{
			beginningofLine = true;
			pos_x = 0.f;
			pos_y -= 1.0f;
			// The line break has to be erased instead of just increasing i
			// otherwise the indices wouldn't be correct anymore
			_text.erase(_text.begin() + i);
			// If the line break was at the end of the string we have to leave the loop
			if (i >= _text.length())
				break;
		}

		// load character
		ftgl::texture_glyph_t* glyph = _font->getCharacter(_text.at(i));

		if (glyph != NULL)
		{

			GLfloat u0 = glyph->s0;
			GLfloat v0 = glyph->t0;
			GLfloat u1 = glyph->s1;
			GLfloat v1 = glyph->t1;

			GLfloat x0 = pos_x + (beginningofLine ? 0.f : (static_cast<GLfloat>(glyph->offset_x) / fontPixelSize));
			GLfloat y0 = pos_y + (static_cast<GLfloat>(glyph->offset_y) / fontPixelSize);
			GLfloat x1 = x0 + (static_cast<GLfloat>(glyph->width) / fontPixelSize);
			GLfloat y1 = y0 - (static_cast<GLfloat>(glyph->height) / fontPixelSize);

			pos_x += static_cast<GLfloat>(glyph->advance_x) / fontPixelSize;
			pos_y += static_cast<GLfloat>(glyph->advance_y) / fontPixelSize;

			beginningofLine = false;

			// Add vertices
			gData->vboVertices.push_back(Vertex(
				x0, y0, z,					// position
				0.0f, 0.0f, -1.0f,			// normal
				-1.0f, 0.0f, 0.0f,			// tangent
				0.0f, 1.0f, 0.0f,			// bitangent
				u0, v0						// texCoord
			));
			gData->vboVertices.push_back(Vertex(
				x1, y1, z,					// position
				0.0f, 0.0f, -1.0f,			// normal
				-1.0f, 0.0f, 0.0f,			// tangent
				0.0f, 1.0f, 0.0f,			// bitangent
				u1, v1						// texCoord
				));
			gData->vboVertices.push_back(Vertex(
				x1, y0, z,					// position
				0.0f, 0.0f, -1.0f,			// normal
				-1.0f, 0.0f, 0.0f,			// tangent
				0.0f, 1.0f, 0.0f,			// bitangent
				u1, v0						// texCoord
				));
			gData->vboVertices.push_back(Vertex(
				x0, y0, z,					// position
				0.0f, 0.0f, -1.0f,			// normal
				-1.0f, 0.0f, 0.0f,			// tangent
				0.0f, 1.0f, 0.0f,			// bitangent
				u0, v0						// texCoord
				));
			gData->vboVertices.push_back(Vertex(
				x0, y1, z, 					// position
				0.0f, 0.0f, -1.0f,			// normal
				-1.0f, 0.0f, 0.0f,			// tangent
				0.0f, 1.0f, 0.0f,			// bitangent
				u0, v1						// texCoord
				));
			gData->vboVertices.push_back(Vertex(
				x1, y1, z,					// position
				0.0f, 0.0f, -1.0f,			// normal
				-1.0f, 0.0f, 0.0f,			// tangent
				0.0f, 1.0f, 0.0f,			// bitangent
				u1, v1						// texCoord	
				));

			// Add indices
			for (GLushort j = (0 + i*verNum); j < (6 + i*verNum); j++)
				gData->vboIndices.push_back(j);

			// Add index data
			gData->indices.push_back(IndexData(3 + i*verNum, 2 + i*verNum, 0 + i*verNum));
			gData->indices.push_back(IndexData(2 + i*verNum, 1 + i*verNum, 0 + i*verNum));
			gData->indices.push_back(IndexData(0 + i*verNum, 0 + i*verNum, 0 + i*verNum));
			gData->indices.push_back(IndexData(1 + i*verNum, 5 + i*verNum, 0 + i*verNum));
			gData->indices.push_back(IndexData(3 + i*verNum, 4 + i*verNum, 0 + i*verNum));
			gData->indices.push_back(IndexData(0 + i*verNum, 3 + i*verNum, 0 + i*verNum));
		}
	}

	g->initialize(gData);

	setBoundingBoxObjectSpace(g->getBoundingBoxObjectSpace());
}
bool
CMSWindowsKeyState::didGroupsChange() const
{
	GroupList groups;
	return (getGroups(groups) && groups != m_groups);
}
Example #19
0
RCType
TDFParser::processTracePointDetail(const char *line, J9TDFTracepoint *tp, const char *module, unsigned int id, const char *fileName, unsigned int lineNumber)
{
	RCType rc = RC_FAILED;
	char *tok = NULL;
	tp->level = -1;
	tp->hasEnv = true;

	/* Save original string because strtok mangles the source string by placing \0 at delimiter */
	char *tokLine = strdup(line);

	/* read the first token */
	tok = strtok(tokLine, " \t");
	line = line + strlen(tok) + 1;
	while ((' ' == *line  || '\t' == *line) && '\0' != *line) {
		line = line + 1;
	}

	tp->name = strdup(strchr(tok, '=') + 1);
	Port::omrmem_free((void **)&tokLine);

	/* now parse all of the optional fields */
	tokLine = strdup(line);

	tok = strtok(tokLine, " \t");
	while (NULL != tok) {
		if (StringUtils::startsWithUpperLower(tok, "Explicit")) {
			/* tp->isExplicit = true; */
			FileUtils::printError("WARNING : obsolete keyword 'Explicit' in %s:%u\n", fileName, lineNumber);
			line = line + strlen(tok);
			while ((' ' == *line  || '\t' == *line) && '\0' != *line) {
				line = line + 1;
			}
			tok = strtok(NULL, " \t");
		} else if (StringUtils::startsWithUpperLower(tok, "Suffix")) {
			/* tp->isSuffix = true; */
			FileUtils::printError("WARNING : obsolete keyword 'Suffix' in %s:%u\n", fileName, lineNumber);
			line = line + strlen(tok);
			while ((' ' == *line  || '\t' == *line) && '\0' != *line) {
				line = line + 1;
			}
			tok = strtok(NULL, " \t");
		} else if (StringUtils::startsWithUpperLower(tok, "Prefix")) {
			/* tp->isPrefix = true; */
			FileUtils::printError("WARNING : obsolete keyword 'Prefix' in %s:%u\n", fileName, lineNumber);
			line = line + strlen(tok);
			while ((' ' == *line  || '\t' == *line) && '\0' != *line) {
				line = line + 1;
			}
			tok = strtok(NULL, " \t");
		} else if (StringUtils::startsWithUpperLower(tok, "Exception")) {
			/* tp->isException = true; */
			FileUtils::printError("WARNING : obsolete keyword 'Exception' in %s:%u\n", fileName, lineNumber);
			line = line + strlen(tok);
			while ((' ' == *line  || '\t' == *line) && '\0' != *line) {
				line = line + 1;
			}
			tok = strtok(NULL, " \t");
		} else if (StringUtils::startsWithUpperLower(tok, "Private")) {
			/* tp->isPrivate = true; */
			FileUtils::printError("WARNING : obsolete keyword 'Private' in %s:%u\n", fileName, lineNumber);
			line = line + strlen(tok);
			while ((' ' == *line  || '\t' == *line) && '\0' != *line) {
				line = line + 1;
			}
			tok = strtok(NULL, " \t");
		} else if (StringUtils::startsWithUpperLower(tok, "Test")) {
			tp->test = true;
			line = line + strlen(tok);
			while ((' ' == *line  || '\t' == *line) && '\0' != *line) {
				line = line + 1;
			}
			tok = strtok(NULL, " \t");
		} else if (StringUtils::startsWithUpperLower(tok, "NoEnv")) {
			tp->hasEnv = false;
			line = line + strlen(tok);
			while ((' ' == *line  || '\t' == *line) && '\0' != *line) {
				line = line + 1;
			}
			tok = strtok(NULL, " \t");
		} else if (StringUtils::startsWithUpperLower(tok, "Obsolete")) {
			tp->obsolete = true;
			line = line + strlen(tok);
			while ((' ' == *line  || '\t' == *line) && '\0' != *line) {
				line = line + 1;
			}
			tok = strtok(NULL, " \t");
		} else if (StringUtils::startsWithUpperLower(tok, (UT_ASSERT_TYPE == tp->type ? "Assert=" : "Template="))) {
			tp->format = getTemplate(line, (UT_ASSERT_TYPE == tp->type ? "Assert=" : "Template="));
			if (NULL == tp->format){
				goto failed;
			}
			line = line + strlen((UT_ASSERT_TYPE == tp->type ? "Assert=" : "Template=")) + (strlen(tp->format) + 2 /* two quotes */);
			while ((' ' == *line  || '\t' == *line) && '\0' != *line) {
				line = line + 1;
			}
			Port::omrmem_free((void **)&tokLine);
			tokLine = strdup(line);

			tok = strtok(tokLine, " \t");
		} else if (StringUtils::startsWithUpperLower(tok, "Level=")) {
			if (RC_OK != StringUtils::getPositiveIntValue(tok, "Level=", &tp->level)) {
				goto failed;
			}
			line = line + strlen(tok);
			while ((' ' == *line  || '\t' == *line) && '\0' != *line) {
				line = line + 1;
			}
			Port::omrmem_free((void **)&tokLine);
			tokLine = strdup(line);

			tok = strtok(tokLine, " \t");
		} else if (StringUtils::startsWithUpperLower(tok, "Overhead=")) {
			if (RC_OK != StringUtils::getPositiveIntValue(tok, "Overhead=", &tp->overhead)) {
				goto failed;
			}
			line = line + strlen(tok);
			while ((' ' == *line  || '\t' == *line) && '\0' != *line) {
				line = line + 1;
			}
			Port::omrmem_free((void **)&tokLine);
			tokLine = strdup(line);
			tok = strtok(tokLine, " \t");
		} else if (StringUtils::startsWithUpperLower(tok, "Group=")) {
			tp->groups = getGroups(tok);
			line = line + strlen(tok);
			while ((' ' == *line  || '\t' == *line) && '\0' != *line) {
				line = line + 1;
			}
			Port::omrmem_free((void **)&tokLine);
			tokLine = strdup(line);

			tok = strtok(tokLine, " \t");
		} else {
			line = line + strlen(tok);
			while ((' ' == *line  || '\t' == *line) && '\0' != *line) {
				line = line + 1;
			}
			Port::omrmem_free((void **)&tokLine);
			tokLine = strdup(line);
			tok = strtok(tokLine, " \t");
		}
	}

	/* Assign default level */
	if ((unsigned int)-1 == tp->level) {
		tp->level = 1;
	}

	if (NULL == tp->format) {
		tp ->format = (char *)Port::omrmem_calloc(1, (strlen("null") + 1));
		strncpy(tp ->format,  "null", strlen("null"));
	}

	if (UT_ASSERT_TYPE == tp->type) {
		/* Assertion parameters are always \"\\377\\4\\377\" for "** ASSERTION FAILED ** at %s:%d: %s" */
		tp->parameters = NULL;
		rc = processAssertTemplate(tp->format, &tp->parmCount);
	} else {
		const char *key = "%";
		const char *pch = strpbrk(tp->format, key);
		unsigned int percentSignCount = 0;
		while (NULL != pch) {
			percentSignCount += 1;
			pch = strpbrk(pch + 1, key);
		}

		size_t len = 5 /* \\\"\\\"\0 when no parameters specified */ + (percentSignCount * (strlen(TRACE_DATA_TYPE_STRING) + strlen(TRACE_DATA_TYPE_PRECISION))) /* TRACE_DATA_TYPE_STRING is the longest parameter string + precision specifier*/;
		tp->parameters = (char *)Port::omrmem_calloc(1, len);
		if (NULL == tp->parameters) {
			FileUtils::printError("Failed to allocate memory\n");
			goto failed;
		}

		rc = processTemplate(tp->format, tp->parameters, &tp->parmCount, fileName, lineNumber);

		/* We pass NULL for no parameters not the empty string "". */
		if (0 == tp->parmCount) {
			Port::omrmem_free((void **)&tp->parameters);
			tp->parameters = (char *)Port::omrmem_calloc(1, strlen("NULL") + 1);
			strcpy(tp->parameters, "NULL");
		}
	}

	return rc;

failed:
	return rc;
}
void
CMSWindowsKeyState::getKeyMap(CKeyMap& keyMap)
{
	// update keyboard groups
	if (getGroups(m_groups)) {
		m_groupMap.clear();
		SInt32 numGroups = (SInt32)m_groups.size();
		for (SInt32 g = 0; g < numGroups; ++g) {
			m_groupMap[m_groups[g]] = g;
		}
	}
	HKL activeLayout = GetKeyboardLayout(0);

	// clear table
	memset(m_virtualKeyToButton, 0, sizeof(m_virtualKeyToButton));
	m_keyToVKMap.clear();

	CKeyMap::KeyItem item;
	SInt32 numGroups = (SInt32)m_groups.size();
	for (SInt32 g = 0; g < numGroups; ++g) {
		item.m_group = g;
		ActivateKeyboardLayout(m_groups[g], 0);

		// clear tables
		memset(m_buttonToVK, 0, sizeof(m_buttonToVK));
		memset(m_buttonToNumpadVK, 0, sizeof(m_buttonToNumpadVK));

		// map buttons (scancodes) to virtual keys
		for (KeyButton i = 1; i < 256; ++i) {
			UINT vk = MapVirtualKey(i, 1);
			if (vk == 0) {
				// unmapped
				continue;
			}

			// deal with certain virtual keys specially
			switch (vk) {
			case VK_SHIFT:
				vk = VK_LSHIFT;
				break;

			case VK_CONTROL:
				vk = VK_LCONTROL;
				break;

			case VK_MENU:
				vk = VK_LMENU;
				break;

			case VK_NUMLOCK:
				vk = VK_PAUSE;
				break;

			case VK_NUMPAD0:
			case VK_NUMPAD1:
			case VK_NUMPAD2:
			case VK_NUMPAD3:
			case VK_NUMPAD4:
			case VK_NUMPAD5:
			case VK_NUMPAD6:
			case VK_NUMPAD7:
			case VK_NUMPAD8:
			case VK_NUMPAD9:
			case VK_DECIMAL:
				// numpad keys are saved in their own table
				m_buttonToNumpadVK[i] = vk;
				continue;

			case VK_LWIN:
			case VK_RWIN:
				// add extended key only for these on 95 family
				if (m_is95Family) {
					m_buttonToVK[i | 0x100u] = vk;
					continue;
				}
				break;

			case VK_RETURN:
			case VK_PRIOR:
			case VK_NEXT:
			case VK_END:
			case VK_HOME:
			case VK_LEFT:
			case VK_UP:
			case VK_RIGHT:
			case VK_DOWN:
			case VK_INSERT:
			case VK_DELETE:
				// also add extended key for these
				m_buttonToVK[i | 0x100u] = vk;
				break;
			}

			if (m_buttonToVK[i] == 0) {
				m_buttonToVK[i] = vk;
			}
		}

		// now map virtual keys to buttons.  multiple virtual keys may map
		// to a single button.  if the virtual key matches the one in
		// m_buttonToVK then we use the button as is.  if not then it's
		// either a numpad key and we use the button as is or it's an
		// extended button.
		for (UINT i = 1; i < 255; ++i) {
			// skip virtual keys we don't want
			switch (i) {
			case VK_LBUTTON:
			case VK_RBUTTON:
			case VK_MBUTTON:
			case VK_XBUTTON1:
			case VK_XBUTTON2:
			case VK_SHIFT:
			case VK_CONTROL:
			case VK_MENU:
				continue;
			}

			// get the button
			KeyButton button = static_cast<KeyButton>(MapVirtualKey(i, 0));
			if (button == 0) {
				continue;
			}

			// deal with certain virtual keys specially
			switch (i) {
			case VK_NUMPAD0:
			case VK_NUMPAD1:
			case VK_NUMPAD2:
			case VK_NUMPAD3:
			case VK_NUMPAD4:
			case VK_NUMPAD5:
			case VK_NUMPAD6:
			case VK_NUMPAD7:
			case VK_NUMPAD8:
			case VK_NUMPAD9:
			case VK_DECIMAL:
				m_buttonToNumpadVK[button] = i;
				break;

			default:
				// add extended key if virtual keys don't match
				if (m_buttonToVK[button] != i) {
					m_buttonToVK[button | 0x100u] = i;
				}
				break;
			}
		}

		// add alt+printscreen
		if (m_buttonToVK[0x54u] == 0) {
			m_buttonToVK[0x54u] = VK_SNAPSHOT;
		}

		// set virtual key to button table
		if (GetKeyboardLayout(0) == m_groups[g]) {
			for (KeyButton i = 0; i < 512; ++i) {
				if (m_buttonToVK[i] != 0) {
					if (m_virtualKeyToButton[m_buttonToVK[i]] == 0) {
						m_virtualKeyToButton[m_buttonToVK[i]] = i;
					}
				}
				if (m_buttonToNumpadVK[i] != 0) {
					if (m_virtualKeyToButton[m_buttonToNumpadVK[i]] == 0) {
						m_virtualKeyToButton[m_buttonToNumpadVK[i]] = i;
					}
				}
			}
		}

		// add numpad keys
		for (KeyButton i = 0; i < 512; ++i) {
			if (m_buttonToNumpadVK[i] != 0) {
				item.m_id        = getKeyID(m_buttonToNumpadVK[i], i);
				item.m_button    = i;
				item.m_required  = KeyModifierNumLock;
				item.m_sensitive = KeyModifierNumLock | KeyModifierShift;
				item.m_generates = 0;
				item.m_client    = m_buttonToNumpadVK[i];
				addKeyEntry(keyMap, item);
			}
		}

		// add other keys
		BYTE keys[256];
		memset(keys, 0, sizeof(keys));
		for (KeyButton i = 0; i < 512; ++i) {
			if (m_buttonToVK[i] != 0) {
				// initialize item
				item.m_id        = getKeyID(m_buttonToVK[i], i);
				item.m_button    = i;
				item.m_required  = 0;
				item.m_sensitive = 0;
				item.m_client    = m_buttonToVK[i];

				// get flags for modifier keys
				CKeyMap::initModifierKey(item);

				if (item.m_id == 0) {
					// translate virtual key to a character with and without
					// shift, caps lock, and AltGr.
					struct Modifier {
						UINT			m_vk1;
						UINT			m_vk2;
						BYTE			m_state;
						KeyModifierMask	m_mask;
					};
					static const Modifier modifiers[] = {
						{ VK_SHIFT,   VK_SHIFT,   0x80u, KeyModifierShift    },
						{ VK_CAPITAL, VK_CAPITAL, 0x01u, KeyModifierCapsLock },
						{ VK_CONTROL, VK_MENU,    0x80u, KeyModifierControl |
														 KeyModifierAlt      }
					};
					static const size_t s_numModifiers =
						sizeof(modifiers) / sizeof(modifiers[0]);
					static const size_t s_numCombinations = 1 << s_numModifiers;
					KeyID id[s_numCombinations];

					bool anyFound = false;
					KeyButton button = static_cast<KeyButton>(i & 0xffu);
					for (size_t j = 0; j < s_numCombinations; ++j) {
						for (size_t k = 0; k < s_numModifiers; ++k) {
							//if ((j & (1 << k)) != 0) {
							// http://msdn.microsoft.com/en-us/library/ke55d167.aspx
							if ((j & (1i64 << k)) != 0) {
								keys[modifiers[k].m_vk1] = modifiers[k].m_state;
								keys[modifiers[k].m_vk2] = modifiers[k].m_state;
							}
							else {
								keys[modifiers[k].m_vk1] = 0;
								keys[modifiers[k].m_vk2] = 0;
							}
						}
						id[j] = getIDForKey(item, button,
										m_buttonToVK[i], keys, m_groups[g]);
						if (id[j] != 0) {
							anyFound = true;
						}
					}

					if (anyFound) {
						// determine what modifiers we're sensitive to.
						// we're sensitive if the KeyID changes when the
						// modifier does.
						item.m_sensitive = 0;
						for (size_t k = 0; k < s_numModifiers; ++k) {
							for (size_t j = 0; j < s_numCombinations; ++j) {
								//if (id[j] != id[j ^ (1u << k)]) {
								// http://msdn.microsoft.com/en-us/library/ke55d167.aspx
								if (id[j] != id[j ^ (1ui64 << k)]) {
									item.m_sensitive |= modifiers[k].m_mask;
									break;
								}
							}
						}
						
						// save each key.  the map will automatically discard
						// duplicates, like an unshift and shifted version of
						// a key that's insensitive to shift.
						for (size_t j = 0; j < s_numCombinations; ++j) {
							item.m_id       = id[j];
							item.m_required = 0;
							for (size_t k = 0; k < s_numModifiers; ++k) {
								if ((j & (1i64 << k)) != 0) {
									item.m_required |= modifiers[k].m_mask;
								}
							}
							addKeyEntry(keyMap, item);
						}
					}
				}
				else {
					// found in table
					switch (m_buttonToVK[i]) {
					case VK_TAB:
						// add kKeyLeftTab, too
						item.m_id         = kKeyLeftTab;
						item.m_required  |= KeyModifierShift;
						item.m_sensitive |= KeyModifierShift;
						addKeyEntry(keyMap, item);
						item.m_id         = kKeyTab;
						item.m_required  &= ~KeyModifierShift;
						break;

					case VK_CANCEL:
						item.m_required  |= KeyModifierControl;
						item.m_sensitive |= KeyModifierControl;
						break;

					case VK_SNAPSHOT:
						item.m_sensitive |= KeyModifierAlt;
						if ((i & 0x100u) == 0) {
							// non-extended snapshot key requires alt
							item.m_required |= KeyModifierAlt;
						}
						break;
					}
					addKeyEntry(keyMap, item);
				}
			}
		}
	}

	// restore keyboard layout
	ActivateKeyboardLayout(activeLayout, 0);
}
Example #21
0
void
WorkflowTest::testDefaultWorkflow()
{
    // TODO: init/begin/end trans

    // STEP 1: create transaction object
    SwdbPrivate::Transaction trans(conn);
    CPPUNIT_ASSERT(trans.getDone() == false);

    // STEP 2: set vars
    trans.setReleasever("26");

    // populate goal
    // resolve dependencies
    // prepare RPM transaction

    // STEP 3: associate RPMs to the transaction
    // bash-4.4.12-5.fc26.x86_64
    auto rpm_bash = std::make_shared< RPMItem >(conn);
    rpm_bash->setName("bash");
    rpm_bash->setEpoch(0);
    rpm_bash->setVersion("4.4.12");
    rpm_bash->setRelease("5.fc26");
    rpm_bash->setArch("x86_64");
    std::string repoid = "base";
    TransactionItemAction action = TransactionItemAction::INSTALL;
    TransactionItemReason reason = TransactionItemReason::GROUP;
    trans.addItem(rpm_bash, repoid, action, reason);

    // systemd-233-6.fc26
    auto rpm_systemd = std::make_shared< RPMItem >(conn);
    rpm_systemd->setName("systemd");
    rpm_systemd->setEpoch(0);
    rpm_systemd->setVersion("233");
    rpm_systemd->setRelease("6.fc26");
    rpm_systemd->setArch("x86_64");
    repoid = "base";
    action = TransactionItemAction::OBSOLETE;
    reason = TransactionItemReason::USER;
    auto ti_rpm_systemd = trans.addItem(rpm_systemd, repoid, action, reason);

    // sysvinit-2.88-14.dsf.fc20
    auto rpm_sysvinit = std::make_shared< RPMItem >(conn);
    rpm_sysvinit->setName("sysvinit");
    rpm_sysvinit->setEpoch(0);
    rpm_sysvinit->setVersion("2.88");
    rpm_sysvinit->setRelease("14.dsf.fc20");
    rpm_sysvinit->setArch("x86_64");
    repoid = "f20";
    action = TransactionItemAction::OBSOLETED;
    reason = TransactionItemReason::USER;
    auto ti_rpm_sysvinit = trans.addItem(rpm_sysvinit, repoid, action, reason);
    ti_rpm_sysvinit->addReplacedBy(ti_rpm_systemd);

    auto comps_group_core = std::make_shared< CompsGroupItem >(conn);
    comps_group_core->setGroupId("core");
    comps_group_core->setName("Core");
    comps_group_core->setTranslatedName("Úplný základ");
    comps_group_core->addPackage("bash", true, CompsPackageType::MANDATORY);
    repoid = "";
    action = TransactionItemAction::INSTALL;
    reason = TransactionItemReason::USER;
    trans.addItem(comps_group_core, repoid, action, reason);

    auto comps_environment_minimal = std::make_shared< CompsEnvironmentItem >(conn);
    comps_environment_minimal->setEnvironmentId("minimal");
    comps_environment_minimal->setName("Minimal");
    comps_environment_minimal->setTranslatedName("mmm");
    comps_environment_minimal->addGroup("core", true, CompsPackageType::MANDATORY);
    repoid = "";
    action = TransactionItemAction::INSTALL;
    reason = TransactionItemReason::USER;
    trans.addItem(comps_environment_minimal, repoid, action, reason);

    // STEP 4: save transaction and all associated items
    trans.begin();

    // STEP 5: run RPM transaction; callback: mark completed items
    for (auto i : trans.getItems()) {
        i->setDone(true);
        i->save();
    }

    // STEP 6
    // mark completed transaction
    trans.finish(true);
    CPPUNIT_ASSERT(trans.getDone() == true);

    // VERIFY
    // verify that data is available via public API
    auto trans2 = libdnf::Transaction(conn, trans.getId());
    CPPUNIT_ASSERT(trans2.getDone() == true);

    CPPUNIT_ASSERT(trans2.getItems().size() == 5);

    for (auto i : trans2.getItems()) {
        if (i->getId() == 1) {
            CPPUNIT_ASSERT(i->getAction() == TransactionItemAction::INSTALL);
            CPPUNIT_ASSERT(i->getReason() == TransactionItemReason::GROUP);
            CPPUNIT_ASSERT(i->getRepoid() == "base");
        } else if (i->getId() == 2) {
            CPPUNIT_ASSERT(i->getAction() == TransactionItemAction::OBSOLETE);
            CPPUNIT_ASSERT(i->getReason() == TransactionItemReason::USER);
            CPPUNIT_ASSERT(i->getRepoid() == "base");
        } else if (i->getId() == 3) {
            CPPUNIT_ASSERT(i->getAction() == TransactionItemAction::OBSOLETED);
            CPPUNIT_ASSERT(i->getReason() == TransactionItemReason::USER);
            CPPUNIT_ASSERT(i->getRepoid() == "f20");
        }

        // CPPUNIT_ASSERT(i->getItem()->getItemType() == "rpm");
        CPPUNIT_ASSERT(i->getDone() == true);
        // std::cout << "TransactionItem: " << i->getItem()->toStr() << std::endl;
        if (i->getItem()->getItemType() == ItemType::GROUP) {
            auto grp = std::dynamic_pointer_cast< CompsGroupItem >(i->getItem());
            CPPUNIT_ASSERT(grp->getPackages().size() == 1);
            for (auto i : grp->getPackages()) {
                // std::cout << "  CompsGroupPackage: " << i->getName() << std::endl;
            }
        }
        if (i->getItem()->getItemType() == ItemType::ENVIRONMENT) {
            auto env = std::dynamic_pointer_cast< CompsEnvironmentItem >(i->getItem());
            CPPUNIT_ASSERT(env->getGroups().size() == 1);
            for (auto i : env->getGroups()) {
                // std::cout << "  CompsEnvironmentGroup: @" << i->getGroupId() << std::endl;
            }
        }
    }
}