Exemple #1
0
void TKeyboard::setLayout(const QString &layoutID, const QStringList &keys)
{
	clearLayout();

	QStringList layout = layoutID.split(QChar('/'));

	QVBoxLayout *vLayout = new QVBoxLayout;

	int i;
	for(i = 0; i < layout.size(); i++) {
		QHBoxLayout *hLayout = new QHBoxLayout;

		int j;
		for(j = 0; j < layout[i].size(); j++) {
			QPushButton *button = new QPushButton("", _frame);
			hLayout->addWidget(button);
			_buttons.append(button);

			connect(button, SIGNAL(pressed()), this, SLOT(slotPressed()));
			connect(button, SIGNAL(clicked(bool)), this, SLOT(slotClicked(bool)));
		}

		vLayout->insertLayout(-1, hLayout);
	}

	setKeys(keys);

	_frame->setLayout(vLayout);
}
Exemple #2
0
/********************************************************************
*
* 描述:					对给定的文件进行解密
*
* 参数:
*	sourcename			要解密的文件的文件名
*	destname			存储解密后的文件的文件名
*	key1				密钥1
*	key2				密钥2
*
* 返回值:
*
********************************************************************/
void decrypt(const char* sourcename, const char* destname, const char* key1, const char* key2)
{
	setKeys(key1, key2);
	FILE* sourcefp;
	FILE* destfp;
	fopen_s(&sourcefp, sourcename, "r");
	fopen_s(&destfp, destname, "w");
	char ch[2] = {};
	int ptr = 0;//ch的当前下标
	int qn = 0;//处于两个有效字符之间Q的个数
	int count = 0;//整篇文章的字符个数
	int countq = 0;//整篇文章Q的总个数
	char c = NULL;
	int right_up_row=0;
	int right_up_column=0;
	int left_down_row=0;
	int left_down_column=0;
	int i = 0;
	while ((c = fgetc(sourcefp)) != EOF)
	{
		count++;
		if (c == 'Q')
		{
			countq++;
			if (ptr == 0)//q出现在第一个位置
			{
				fputc('q', destfp);
			}
			if (ptr == 1)//q出现在中间
			{
				qn++;//记录中间出现的q的个数
			}
		}
		else
		{
			ch[ptr++] = c;
			if (ptr == 2)
			{
				getPosition(ch[0], right_up_row, right_up_column, matrix_right_up);
				getPosition(ch[1], left_down_row, left_down_column, matrix_left_down);
				fputc(matrix[right_up_row][left_down_column], destfp);
				for (i = 0; i < qn; i++)
				{
					fputc('q', destfp);
				}
				fputc(matrix[left_down_row][right_up_column], destfp);
				qn = 0;
				ptr = 0;
			}
		}
	}
	if ((count - countq) % 2)//最后一个字符未加密,变成小写字母显示
	{
		fputc(tolower(ch[0]), destfp);
	}
	fclose(sourcefp);
	fclose(destfp);
	sourcefp = NULL;
	destfp = NULL;
}
Exemple #3
0
ExtendibleHash::ExtendibleHash(const int & notFound, int b, int LSize) :
  bits(b), LeafSize(LSize)
{
  notfound = notFound;
  setKeys(b); 
  bits = b;
  Directory = new ExtendibleLeaf*[DSize(bits)];
  ExtendibleLeaf *leafPtr = new ExtendibleLeaf(LSize);
  for(int i=0; i< DSize(b); i++)
    Directory[i] = leafPtr;//makes the initial directory poinmt to an empty leaf

/* TO TEST WHETHER OR NOT ALL DIRECTORIES INITIALLY POINT AT ONE LEAF
 
  for(int i=0; i<LSize; i++)
    leafPtr->binaryNode[i]=i;

  for(int j = 0; j< DSize(b); j++)
  {
A
A
    for(int i=0; i< LSize; i++)
B
    {
      cout<< Directory[j]->binaryNode[i]<< " ";
    }
    cout<< endl;
  }
*/
} // ExtendibleHash()
Exemple #4
0
/** Create a new node from the board state given. 
@param b The board state this node should copy keys from.
@param toPlay The next colour to play. */
Node::Node(const BoardStruct& b, int toPlay) : haveBestNode(false), depthSearchedTo(0), isScoreCalculated(false), isUpperboundCalculated(false),
	isLowerboundCalculated(false), lowerbound((float)INT_MIN), upperbound((float)INT_MAX), nextToPlay(toPlay),
	depth(0), terminal(false), move(b.getLastMove())
{
	setKeys(b);
	setBestNode(NULL);
	InExistence++;
}
Exemple #5
0
SearchProvider::SearchProvider(const KService::Ptr service)
               : m_dirty(false)
{
    setDesktopEntryName(service->desktopEntryName());
    setName(service->name());
    setKeys(service->property("Keys").toStringList());

    m_query = service->property("Query").toString();
    m_charset = service->property("Charset").toString();
}
Exemple #6
0
void EMIChore::update(uint time) {
	if (!_playing || _paused)
		return;

	if (_fadeMode != Animation::None) {
		if (_fadeMode == Animation::FadeIn) {
			_fade += (float)time * (1.0f - _startFade) / _fadeLength;
			if (_fade >= 1.f) {
				_fade = 1.f;
				_fadeMode = Animation::None;
			}
		} else {
			_fade -= (float)time * _startFade / _fadeLength;
			if (_fade <= 0.f) {
				_fade = 0.f;
				stop(0);
				return;
			}
		}
	}

	int newTime;
	if (_currTime < 0)
		newTime = 0; // For first time through
	else
		newTime = _currTime + time;

	setKeys(_currTime, newTime);

	if (_length >= 0 && newTime > _length) {
		if (!_looping && _fadeMode != Animation::FadeOut) {
			stop(0);
		}
		else {
			do {
				newTime -= _length;
				setKeys(-1, newTime);
			} while (newTime > _length);
		}
	}
	_currTime = newTime;
}
Exemple #7
0
Paddle::Paddle (SDL_Surface *field, int x, int y, int w, int h)
{
	this->field = field;

	box.x = x;
	box.y = y;
	box.w = w;
	box.h = h;
	
	// set default keys
	setKeys (SDLK_UP, SDLK_DOWN);
}
Exemple #8
0
void TKeyboard::setKeyboard(const QString &keyboard)
{
	QStringList keys = keyboard.split(QChar(' '));
	QString layoutID = keys.takeFirst();

	if(layoutID != _currentLayoutID) {
		setLayout(layoutID, keys);
		_currentLayoutID = layoutID;
	} else {
		setKeys(keys);
	}
}
Exemple #9
0
//
// KeyRow
//
KeyRow::KeyRow() {
  setPos(0,0);
  setKeys("x|x|x");
  xpadding_small = 30;
  xpadding_large = 30;
  
  // Animation settings
  events.clear();
  newEvent(0, 300, 0, 1); // intro
  newEvent(0, -1, 1, 1); // main
  currentEvent = events[0];
  
  updateDependencyDelays(getDelay());
}
Exemple #10
0
void Chore::update(uint time) {
	if (!_playing)
		return;

	int newTime;
	if (_currTime < 0)
		newTime = 0; // For first time through
	else
		newTime = _currTime + time;

	setKeys(_currTime, newTime);

	if (newTime > _length) {
		if (!_looping) {
			_playing = false;
		} else {
			do {
				newTime -= _length;
				setKeys(-1, newTime);
			} while (newTime > _length);
		}
	}
	_currTime = newTime;
}
Exemple #11
0
void ExtendibleHash::extend(const int &object)
{
  int directorySize = DSize(bits);
  int newDirectorySize = DSize(bits+1); 
  bits++; 
  ExtendibleLeaf** newDirectory = new ExtendibleLeaf*[newDirectorySize];
  for(int iter=0; iter<directorySize; iter++)
  {
    newDirectory[1 + 2*iter] = Directory[iter];
    newDirectory[2*iter] = Directory[iter];
  }
  ExtendibleLeaf** temp = Directory;
  Directory = newDirectory;
  delete temp;
  setKeys(bits);
}  // extednd()
Exemple #12
0
void Node::reset(const BoardStruct& b, int toPlay)
{
	haveBestNode = false;
	depthSearchedTo = 0;
	isScoreCalculated = false;
	isUpperboundCalculated = false;
	isLowerboundCalculated = false;
	lowerbound = (float)INT_MIN;
	upperbound = (float)INT_MAX;

	move = b.getLastMove();

	nextToPlay = toPlay;
	depth = 0;
	terminal = false;
	setKeys(b);
	setBestNode(NULL);
}
Exemple #13
0
void Chore::setLastFrame() {
	// If the chore has already played then don't set it to the end
	// Example: This executing would result in Glottis being
	// choppy when he hands Manny the work order
	// 	if (_hasPlayed)
	// 		return;

	// This comment above is perfectly right, but unfortunately doing that
	// breaks glottis movements when he answers to "i'm calavera, manny calavera".
	// Moreover, the choppy behaviour stated above happens with grim original too,
	// meaning the bug is not in Residual but in the scripts or in GrimE design.

	_currTime = _length;
	_playing = false;
	_hasPlayed = true;
	_looping = false;
	setKeys(-1, _currTime);
	_currTime = -1;
}
Exemple #14
0
void Chore::setLastFrame() {
	// If the chore has already played then don't set it to the end
	// Example: This executing would result in Glottis being
	// choppy when he hands Manny the work order
	// 	if (_hasPlayed)
	// 		return;

	// This comment above is perfectly right, but unfortunately doing that
	// breaks glottis movements when he answers to "i'm calavera, manny calavera".
	// Moreover, the choppy behaviour stated above happens with grim original too,
	// meaning the bug is not in Residual but in the scripts or in GrimE design.

	_currTime = -1;
	_playing = false;
	_hasPlayed = true;
	_looping = false;

	// In the demo, the chore 4 (stop_talk) of ms.cos, has length 67, and 4 keys,
	// the last two of which are at time 133 and 200. We use -1 as stopTime here
	// as a special value, instead of _length, to ensure all the keys are run.
	// (failing to do so will result in manny's mouth not closing when he stops talking)
	setKeys(-1, -1);
}
	ColorGradient::ColorGradient(const Vector<ColorGradientKey>& keys)
	{
		setKeys(keys);
	}
Exemple #16
0
/********************************************************************
*
* 描述:					对给定的文件进行加密
*
* 参数:
*	sourcename			要加密的文件的文件名
*	destname			存储密文的文件的文件名
*	key1				密钥1
*	key2				密钥2
*	msg					要隐藏在文中的信息
*
* 返回值:
*
********************************************************************/
void encrypt(const char* sourename, const char* destname, const char* key1, const char* key2, const char* msg)
{
	setKeys(key1, key2);
	const char* tmpfile = "tmpfile";
	handleText(sourename, tmpfile, msg);
	FILE* tmpfp;
	FILE* destfp;
	fopen_s(&tmpfp, tmpfile, "r");
	fopen_s(&destfp, destname, "w");
	char ch[2] = {};
	int ptr = 0;//ch的当前下标
	int qn = 0;//处于两个有效加密字符之间q的个数
	int count = 0;//整篇文章的字符个数
	int countq = 0;//整篇文章q的总个数
	char c = NULL;
	int left_up_row=0;
	int left_up_column=0;
	int right_down_row=0;
	int right_down_column=0;
	int i = 0;
	while ((c = fgetc(tmpfp)) != EOF)
	{
		count++;
		if (c == 'q')
		{
			countq++;
			if (ptr == 0)//q出现在第一个位置
			{
				fputc('Q', destfp);
			}
			if (ptr == 1)//q出现在中间
			{
				qn++;//记录中间出现的q的个数
			}
		}
		else
		{
			ch[ptr++] = c;
			if (ptr == 2)
			{
				getPosition(ch[0], left_up_row, left_up_column, matrix);
				getPosition(ch[1], right_down_row, right_down_column, matrix);
				fputc(matrix_right_up[left_up_row][right_down_column],destfp);
				for (i = 0; i < qn; i++)
				{
					fputc('Q', destfp);
				}
				fputc(matrix_left_down[right_down_row][left_up_column], destfp);
				qn = 0;
				ptr = 0;
			}
		}
	}
	if ((count - countq) % 2)//最后一个字符未加密,变成大写字母显示
	{
		fputc(toupper(ch[0]), destfp);
	}
	fclose(tmpfp);
	fclose(destfp);
	//remove(tmpfile);
	tmpfp = NULL;
	destfp = NULL;
}
LuaVirtualMachine::LuaVirtualMachine(){		
	DILUCULUM_REGISTER_CLASS(state["GameObject"], LuaGameObject);		
	DILUCULUM_REGISTER_CLASS(state["Input"], LuaInput);		

	setKeys();
}
Exemple #18
0
//parseMessage(tConn->recv.data, tConn->recv.mark, &tConn->resp, ipstr, pHWADDR, tConn->keys);
int parseMessage(struct connection *pConn, unsigned char *pIpBin, unsigned int pIpBinLen, char *pHWID)
{
  int tReturn = 0; // 0 = good, 1 = Needs More Data, -1 = close client socket.
  if(pConn->resp.data == NULL)
  {
    initBuffer(&(pConn->resp), MAX_SIZE);
  }

  char *tContent = getFromHeader(pConn->recv.data, "Content-Length", NULL);
  if(tContent != NULL)
  {
    int tContentSize = atoi(tContent);
    if(pConn->recv.marker == 0 || strlen(pConn->recv.data+pConn->recv.marker) != tContentSize)
    {
      if(isLogEnabledFor(HEADER_LOG_LEVEL))
      {
        slog(HEADER_LOG_LEVEL, "Content-Length: %s value -> %d\n", tContent, tContentSize);
        if(pConn->recv.marker != 0)
        {
          slog(HEADER_LOG_LEVEL, "ContentPtr has %d, but needs %d\n", 
                  strlen(pConn->recv.data+pConn->recv.marker), tContentSize);
        }
      }
      // check if value in tContent > 2nd read from client.
      return 1; // means more content-length needed
    }
  }
  else
  {
    slog(LOG_DEBUG_VV, "No content, header only\n");
  }

  // "Creates" a new Response Header for our response message
  addToShairBuffer(&(pConn->resp), "RTSP/1.0 200 OK\r\n");

  if(isLogEnabledFor(LOG_INFO))
  {
    int tLen = strchr(pConn->recv.data, ' ') - pConn->recv.data;
    if(tLen < 0 || tLen > 20)
    {
      tLen = 20;
    }
    slog(LOG_INFO, "********** RECV %.*s **********\n", tLen, pConn->recv.data);
  }

  if(pConn->password != NULL)
  {
    
  }

  if(buildAppleResponse(pConn, pIpBin, pIpBinLen, pHWID)) // need to free sig
  {
    slog(LOG_DEBUG_V, "Added AppleResponse to Apple-Challenge request\n");
  }

  // Find option, then based on option, do different actions.
  if(strncmp(pConn->recv.data, "OPTIONS", 7) == 0)
  {
    propogateCSeq(pConn);
    addToShairBuffer(&(pConn->resp),
      "Public: ANNOUNCE, SETUP, RECORD, PAUSE, FLUSH, TEARDOWN, OPTIONS, GET_PARAMETER, SET_PARAMETER\r\n");
  }
  else if(!strncmp(pConn->recv.data, "ANNOUNCE", 8))
  {
    char *tContent = pConn->recv.data + pConn->recv.marker;
    int tSize = 0;
    char *tHeaderVal = getFromContent(tContent, "a=aesiv", &tSize); // Not allocated memory, just pointing
    if(tSize > 0)
    {
      int tKeySize = 0;
      char tEncodedAesIV[tSize + 2];
      getTrimmed(tHeaderVal, tSize, TRUE, TRUE, tEncodedAesIV);
      slog(LOG_DEBUG_VV, "AESIV: [%.*s] Size: %d  Strlen: %d\n", tSize, tEncodedAesIV, tSize, strlen(tEncodedAesIV));
      char *tDecodedIV =  decode_base64((unsigned char*) tEncodedAesIV, tSize, &tSize);

      // grab the key, copy it out of the receive buffer
      tHeaderVal = getFromContent(tContent, "a=rsaaeskey", &tKeySize);
      char tEncodedAesKey[tKeySize + 2]; // +1 for nl, +1 for \0
      getTrimmed(tHeaderVal, tKeySize, TRUE, TRUE, tEncodedAesKey);
      slog(LOG_DEBUG_VV, "AES KEY: [%s] Size: %d  Strlen: %d\n", tEncodedAesKey, tKeySize, strlen(tEncodedAesKey));
      // remove base64 coding from key
      char *tDecodedAesKey = decode_base64((unsigned char*) tEncodedAesKey,
                              tKeySize, &tKeySize);  // Need to free DecodedAesKey

      // Grab the formats
      int tFmtpSize = 0;
      char *tFmtp = getFromContent(tContent, "a=fmtp", &tFmtpSize);  // Don't need to free
      tFmtp = getTrimmedMalloc(tFmtp, tFmtpSize, TRUE, FALSE); // will need to free
      slog(LOG_DEBUG_VV, "Format: %s\n", tFmtp);

      RSA *rsa = loadKey();
      // Decrypt the binary aes key
      char *tDecryptedKey = malloc(RSA_size(rsa) * sizeof(char)); // Need to Free Decrypted key
      //char tDecryptedKey[RSA_size(rsa)];
      if(RSA_private_decrypt(tKeySize, (unsigned char *)tDecodedAesKey, 
      (unsigned char*) tDecryptedKey, rsa, RSA_PKCS1_OAEP_PADDING) >= 0)
      {
        slog(LOG_DEBUG, "Decrypted AES key from RSA Successfully\n");
      }
      else
      {
        slog(LOG_INFO, "Error Decrypting AES key from RSA\n");
      }
      free(tDecodedAesKey);
      RSA_free(rsa);

      setKeys(pConn->keys, tDecodedIV, tDecryptedKey, tFmtp);

      propogateCSeq(pConn);
    }
  }
  else if(!strncmp(pConn->recv.data, "SETUP", 5))
  {
    // Setup pipes
//    struct comms *tComms = pConn->hairtunes;
//   if (! (pipe(tComms->in) == 0 && pipe(tComms->out) == 0))
//    {
//      slog(LOG_INFO, "Error setting up hairtunes communications...some things probably wont work very well.\n");
//    }
    
    // Setup fork
    char tPort[8] = "6000";  // get this from dup()'d stdout of child pid

    printf("******** SETUP!!!!!\n");
#ifndef BOXEE
    int tPid = fork();
    if(tPid == 0)
    {
#endif
      int tDataport=0;
      char tCPortStr[8] = "59010";
      char tTPortStr[8] = "59012";
      int tSize = 0;

      char *tFound  =getFromSetup(pConn->recv.data, "control_port", &tSize);
      getTrimmed(tFound, tSize, 1, 0, tCPortStr);
      tFound = getFromSetup(pConn->recv.data, "timing_port", &tSize);
      getTrimmed(tFound, tSize, 1, 0, tTPortStr);

      slog(LOG_DEBUG_VV, "converting %s and %s from str->int\n", tCPortStr, tTPortStr);
      int tControlport = atoi(tCPortStr);
      int tTimingport = atoi(tTPortStr);

      slog(LOG_DEBUG_V, "Got %d for CPort and %d for TPort\n", tControlport, tTimingport);
      char *tRtp = NULL;
      char *tPipe = NULL;
      char *tAoDriver = NULL;
      char *tAoDeviceName = NULL;
      char *tAoDeviceId = NULL;
      struct keyring *tKeys = pConn->keys;

#ifndef BOXEE
      // *************************************************
      // ** Setting up Pipes, AKA no more debug/output  **
      // *************************************************
      dup2(tComms->in[0],0);   // Input to child
      closePipe(&(tComms->in[0]));
      closePipe(&(tComms->in[1]));

      dup2(tComms->out[1], 1); // Output from child
      closePipe(&(tComms->out[1]));
      closePipe(&(tComms->out[0]));

      pConn->keys = NULL;
      pConn->hairtunes = NULL;

      // Free up any recv buffers, etc..
      if(pConn->clientSocket != -1)
      {
        close(pConn->clientSocket);
        pConn->clientSocket = -1;
      }
      cleanupBuffers(pConn);
#endif
      hairtunes_init(tKeys->aeskey, tKeys->aesiv, tKeys->fmt, tControlport, tTimingport,
                      tDataport, tRtp, tPipe, tAoDriver, tAoDeviceName, tAoDeviceId);
#ifndef BOXEE
      // Quit when finished.
      slog(LOG_DEBUG, "Returned from hairtunes init....returning -1, should close out this whole side of the fork\n");
      return -1;
    }
    else if(tPid >0)
    {
      // Ensure Connection has access to the pipe.
      closePipe(&(tComms->in[0]));
      closePipe(&(tComms->out[1]));

      char tFromHairtunes[80];
      int tRead = read(tComms->out[0], tFromHairtunes, 80);
      if(tRead <= 0)
      {
        slog(LOG_INFO, "Error reading port from hairtunes function, assuming default port: %d\n", tPort);
      }
      else
      {
        int tSize = 0;
        char *tPortStr = getFromHeader(tFromHairtunes, "port", &tSize);
        if(tPortStr != NULL)
        {
          getTrimmed(tPortStr, tSize, TRUE, FALSE, tPort);
        }
        else
        {
          slog(LOG_INFO, "Read %d bytes, Error translating %s into a port\n", tRead, tFromHairtunes);
        }
      }

      int tSize;
#endif

      //  READ Ports from here?close(pConn->hairtunes_pipes[0]);
      propogateCSeq(pConn);
      tSize = 0;
      char *tTransport = getFromHeader(pConn->recv.data, "Transport", &tSize);
      addToShairBuffer(&(pConn->resp), "Transport: ");
      addNToShairBuffer(&(pConn->resp), tTransport, tSize);
      // Append server port:
      addToShairBuffer(&(pConn->resp), ";server_port=");
      addToShairBuffer(&(pConn->resp), tPort);
      addToShairBuffer(&(pConn->resp), "\r\nSession: DEADBEEF\r\n");
#ifndef BOXEE
    }
    else
    {
      slog(LOG_INFO, "Error forking process....dere' be errors round here.\n");
      return -1;
    }
#endif
  }
  else if(!strncmp(pConn->recv.data, "TEARDOWN", 8))
  {
    // Be smart?  Do more finish up stuff...
    addToShairBuffer(&(pConn->resp), "Connection: close\r\n");
    propogateCSeq(pConn);
#ifndef BOXEE
    close(pConn->hairtunes->in[1]);
    slog(LOG_DEBUG, "Tearing down connection, closing pipes\n");
#else
    hairtunes_cleanup();
#endif
    //close(pConn->hairtunes->out[0]);
    tReturn = -1;  // Close client socket, but sends an ACK/OK packet first
  }
  else if(!strncmp(pConn->recv.data, "FLUSH", 5))
  {
    // TBD FLUSH
#ifndef BOXEE
    write(pConn->hairtunes->in[1], "flush\n", 6);
#else
    hairtunes_flush();
#endif
    propogateCSeq(pConn);
  }
  else if(!strncmp(pConn->recv.data, "SET_PARAMETER", 13))
  {
    propogateCSeq(pConn);
    int tSize = 0;
    char *tVol = getFromHeader(pConn->recv.data, "volume", &tSize);
    slog(LOG_DEBUG_VV, "About to write [vol: %.*s] data to hairtunes\n", tSize, tVol);
    // TBD VOLUME
#ifndef BOXEE
    write(pConn->hairtunes->in[1], "vol: ", 5);
    write(pConn->hairtunes->in[1], tVol, tSize);
    write(pConn->hairtunes->in[1], "\n", 1);
#else
    hairtunes_setvolume(atof(tVol));
#endif
    slog(LOG_DEBUG_VV, "Finished writing data write data to hairtunes\n");
  }
  else
  {
    slog(LOG_DEBUG, "\n\nUn-Handled recv: %s\n", pConn->recv.data);
    propogateCSeq(pConn);
  }
  addToShairBuffer(&(pConn->resp), "\r\n");
  return tReturn;
}