示例#1
0
bool SHAMapTreeNode::setItem (SHAMapItem::ref i, TNType type)
{
    mType = type;
    mItem = i;
    assert (isLeaf ());
    return updateHash ();
}
示例#2
0
文件: hash.cpp 项目: adfin/mordor
size_t
HashStream::read(void *buffer, size_t length)
{
    size_t result = parent()->read(buffer, length);
    updateHash(buffer, result);
    return result;
}
示例#3
0
	bool ChunkDownload::load(File & file,ChunkDownloadHeader & hdr)
	{
		// read pieces
		if (hdr.num_bits != num)
			return false; 
		
		pieces = BitSet(hdr.num_bits);
		Array<Uint8> data(pieces.getNumBytes());
		file.read(data,pieces.getNumBytes());
		pieces = BitSet(data,hdr.num_bits);
		num_downloaded = pieces.numOnBits();
		if (hdr.buffered)
		{
			// if it's a buffered chunk, load the data to
			if (file.read(chunk->getData(),chunk->getSize()) != chunk->getSize())
				return false;
		}
		
		for (Uint32 i = 0;i < pieces.getNumBits();i++)
			if (pieces.get(i))
				piece_queue.remove(i);
		
		updateHash();
		return true;
	}
示例#4
0
文件: hash.cpp 项目: adfin/mordor
size_t
HashStream::write(const void *buffer, size_t length)
{
    size_t result = parent()->write(buffer, length);
    updateHash(buffer, result);
    return result;
}
void PreflateHashChainExt::updateHash(const unsigned l) {
  if (l > 0x180) {
    unsigned l_ = l;
    while (l_ > 0) {
      unsigned blk = std::min(l_, 0x180u);
      updateHash(blk);
      l_ -= blk;
    }
    return;
  }

  const unsigned char* b = _input.curChars();
  unsigned pos = _input.pos();
  if (pos - totalShift >= 0xfe08) {
    reshift();
  }
  for (unsigned i = 2; i < std::min(l + 2, _input.remaining()); ++i) {
    updateRunningHash(b[i]);
    unsigned h = runningHash & hashMask;
    unsigned p = (pos + i - 2) - totalShift;
    chainDepth[p] = chainDepth[head[h]] + 1;
    prev[p] = head[h];
    head[h] = p;
  }
  _input.advance(l);
}
 vector<string> findRepeatedDnaSequences(string s) {
     vector<string> result;
     if(s.length() < 10) {
         return result;
     }
     unordered_map <int, int> Map;
     
     string substr = s.substr(0, 10);
     int hash = stringHash(substr);
     Map[hash]++;
     
     for(int i = 10; i < s.length(); ++i) {
         int newHash = updateHash(hash, s[i]);
         Map[newHash]++;
         hash = newHash;
     }
     
     for(auto it = Map.begin(); it != Map.end(); ++it) {
         if(it->second > 1) {
             string str = hashToStr(it->first);
             result.push_back(str);
         }
     }
     return result;
 }
 void SimpleWorldState::unset(Predicates::predID pred, const paramlist &params)
 {
    if(pred < mState.size())
    {
       _unset(pred, params);
       updateHash();
    }
 }
示例#8
0
文件: hash.cpp 项目: adfin/mordor
size_t
HashStream::read(Buffer &buffer, size_t length)
{
    Buffer temp;
    size_t result = parent()->read(temp, length);
    updateHash(temp, result);
    buffer.copyIn(temp);
    return result;
}
示例#9
0
int parseConfigFile(char *filename, Config_t *conf, bool trimQuotes)
{
    FILE *fp;
    char *linebuf = NULL;
    size_t len = 0;
    ssize_t read;
    int count = 0;

    /* init config list */
    INIT_LIST_HEAD(conf);

    if (!(fp = fopen(filename, "r"))) {
	char *cwd = getcwd(NULL, 0);

	pluginlog("%s: error opening config cwd:%s file:%s\n", __func__, cwd,
		  filename);
	if (cwd) free(cwd);
	return -1;
    }

    while ((read = getline(&linebuf, &len, fp)) != -1) {
	char *line = linebuf, *key, *val, *tmp;

	if (configHashAcc && read) updateHash(configHashAcc, line);

	/* skip comments and empty lines */
	if (!read || line[0] == '\n' || line[0] == '#' || line[0] == '\0') {
	    continue;
	}

	/* remove trailing comments */
	if ((tmp = strchr(line, '#'))) *tmp = '\0';

	/* Split line into key and value */
	key = line;
	val = strchr(line,'=');

	if (val) {
	    *val = '\0';
	    val = trim(++val);
	    /* remove quotes from value if required */
	    if (trimQuotes) val = trim_quotes(val);
	    if (!strlen(val)) val = NULL;
	}

	key = trim(key);

	doAddConfigEntry(conf, key, val);
	count++;
    }

    if (linebuf) ufree(linebuf);
    fclose(fp);

    return count;
}
示例#10
0
   /// This method applies an Action to a WorldState in reverse. In effect,
   /// it determines the state of the world required that when this Action is
   /// applied to it, the result is the current state.
   /// This involves making sure that the new state's predicates match the
   /// Action's prerequisites, and clearing any predicates that the Action
   /// sets.
   void WorldState::applyReverse(const Action &ac, const objects &params)
   {
      operations::const_iterator o;
      Operation op;
      Fact f;
      for(o = ac.begin(); o != ac.end(); o++)
      {
         op = o->second;
         f = o->first;
         if(params.size())
         {
            fillOp(op, params);
            fillFact(f, params);
         }
         // If there's no condition, check the effects.
         if(op.ctype == NoCondition)
         {
            switch(op.etype)
            {
            case Set:
                //_set(f,op.eval);
               _unset(f);
               break;
            case Unset:
               _set(f,op.eval);
               break;
            case Increment:
               _set(f, op.eval - 1);
               break;
            case Decrement:
               _set(f, op.eval + 1);
               break;
            }
         }
         else
         {
            switch(op.ctype)
            {
            case IsSet:
               _set(f, 0);
               break;
            case Equals:
               _set(f, op.cval);
               break;
            case IsUnset:
               _unset(f);
               break;
            }
         }
      }

      updateHash();
   }
void PreflateCompLevelEstimatorState::checkDump(bool early_out) {
  for (unsigned i = 0, n = blocks.size(); i < n; ++i) {
    const PreflateTokenBlock& b = blocks[i];
    if (b.type == PreflateTokenBlock::STORED) {
      updateHash(b.uncompressedLen);
      continue;
    }
    for (unsigned j = 0, m = b.tokens.size(); j < m; ++j) {
      const PreflateToken& t = b.tokens[j];
      if (t.len == 1) {
        updateHash(1);
      } else {
        checkMatch(t);
        updateOrSkipHash(t.len);
      }
      if (early_out && (info.possibleCompressionLevels & (info.possibleCompressionLevels - 1)) == 0) {
        return;
      }
    }
  }
}
示例#12
0
Q_UINT32 KStandardDirs::calcResourceHash(const char *type, const QString &filename, bool deep) const
{
    Q_UINT32 hash = 0;

    if(!QDir::isRelativePath(filename))
    {
        // absolute dirs are absolute dirs, right? :-/
        return updateHash(filename, hash);
    }
    if(d && d->restrictionsActive && (strcmp(type, "data") == 0))
        applyDataRestrictions(filename);
    QStringList candidates = resourceDirs(type);
    QString fullPath;

    for(QStringList::ConstIterator it = candidates.begin(); it != candidates.end(); ++it)
    {
        hash = updateHash(*it + filename, hash);
        if(!deep && hash)
            return hash;
    }
    return hash;
}
示例#13
0
文件: mainUI.cpp 项目: KdeOs/pcbsd
void mainUI::setupUI(){
  //Initialize the Hash (make sure it is not run too frequently - causes kernel panics)
  if(lastUpdate.isNull() || lastUpdate.addSecs(15) < QTime::currentTime() ){
    lastUpdate = QTime::currentTime();	  
    qDebug() << "Updating the database";
    updateHash();
  }else{
    freqTimer->start();
  }
  //Update the display
  updateUI();
  updateMenus();
}
void QFSEventsFileSystemWatcherEngine::updateFiles()
{
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
    QMutexLocker locker(&mutex);
    updateHash(filePathInfoHash);
    updateHash(dirPathInfoHash);
    if (filePathInfoHash.isEmpty() && dirPathInfoHash.isEmpty()) {
        // Everything disappeared before we got to start, don't bother.
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
        // Code duplicated from stop(), with the exception that we
        // don't wait on waitForStop here. Doing this will lead to
        // a deadlock since this function is called from the worker
        // thread. (waitForStop.wakeAll() is only called from the
        // end of run()).
        stopFSStream(fsStream);
        if (threadsRunLoop)
            CFRunLoopStop(threadsRunLoop);
#endif
        cleanupFSStream(fsStream);
    }
    waitCondition.wakeAll();
#endif
}
示例#15
0
bool match(char* P, char* T) {
    size_t m = strlen(P), n = strlen(T);
    HashCode Dm, hashP = 0, hashT = 0;
    Dm = prepareDm(m);
    for (size_t i = 0; i < m; i++) {
        hashP = (hashP*R + DIGIT(P, i)) % M;
        hashT = (hashT*R + DIGIT(T, i)) % M;
    }
    for (size_t k = 0;;) {
        if (hashT == hashP && check1by1(P, T, k)) return true;
        if (++k>n - m) return false;
        else updateHash(hashT, T, m, k, Dm);
    }
}
void TabDeckEditor::setDeck(DeckLoader *_deck)
{
    deckModel->setDeckList(_deck);

    nameEdit->setText(deckModel->getDeckList()->getName());
    commentsEdit->setText(deckModel->getDeckList()->getComments());
    updateHash();
    deckModel->sort(deckView->header()->sortIndicatorSection(), deckView->header()->sortIndicatorOrder());
    deckView->expandAll();
    setModified(false);

    db->cacheCardPixmaps(deckModel->getDeckList()->getCardList());
    deckView->expandAll();
    setModified(false);
}
示例#17
0
void NDirWatcherThread::run()
{
    logMessage("Server", "Looking for files modification...");
    parseSharedDirs();

    if (isStopping())
        return;

    updateHash();

    if (isStopping())
        return;

    emit hash(m_hash.toHex(), m_dirs);

    logMessage("Server", "Looking for files modification finished.");
}
示例#18
0
bool SHAMapTreeNode::setChildHash (int m, uint256 const& hash)
{
    assert ((m >= 0) && (m < 16));
    assert (mType == tnINNER);

    if (mHashes[m] == hash)
        return false;

    mHashes[m] = hash;

    if (hash.isNonZero ())
        mIsBranch |= (1 << m);
    else
        mIsBranch &= ~ (1 << m);

    return updateHash ();
}
PreflateCompLevelEstimatorState::PreflateCompLevelEstimatorState(
    const int wbits,
    const int mbits,
    const std::vector<unsigned char>& unpacked_output_,
    const size_t off0_,
    const std::vector<PreflateTokenBlock>& blocks_)
  : slowHash(unpacked_output_, mbits)
  , fastL1Hash(unpacked_output_, mbits)
  , fastL2Hash(unpacked_output_, mbits)
  , fastL3Hash(unpacked_output_, mbits)
  , blocks(blocks_)
  , wsize(1 << wbits)
  , off0(off0_)
{
  memset(&info, 0, sizeof(info));
  info.possibleCompressionLevels = (1 << 10) - (1 << 1);
  updateHash(off0);
}
示例#20
0
bool Archive::remove( const WidgetKey & key )
{
	ASSERT( m_Open && m_Access == READ_WRITE );
	lock();

	// you cannot remove a file while it's open
	if ( fileOpen( key ) )
	{
		unlock();
		return false;
	}

	int fileIndex = file( key );
	if ( fileIndex < 0 )
	{
		unlock();
		return false;
	}

	File & removeFile = m_Files[ fileIndex ];

	// deallocate the sectors for this file
	dword sector = removeFile.sector;
	while( sector != SECTOR_LAST )
	{
		dword next = m_SectorMap[ sector ];
		m_SectorMap[ sector ] = SECTOR_FREE;

		sector = next;
	}
	
	// remove from file table
	m_Files.remove( fileIndex );
	// rebuild the hash
	updateHash();
	// write the new table
	writeTable();

	unlock();

	// file removed
	return true;
}
	bool ChunkDownload::piece(const Piece & p,bool & ok)
	{
		ok = false;
		timer.update();
			
		Uint32 pp = p.getOffset() / MAX_PIECE_LEN;
		Uint32 len = pp == num - 1 ? last_size : MAX_PIECE_LEN;
		if (pp >= num || pieces.get(pp) || p.getLength() != len)
			return false;

	
		DownloadStatus* ds = dstatus.find(p.getPieceDownloader());
		if (ds)
			ds->remove(pp);
		
		PieceData::Ptr buf = chunk->getPiece(p.getOffset(),p.getLength(),false);
		if (buf && buf->write(p.getData(),p.getLength()) == p.getLength())
		{
			piece_data[pp] = buf;
			ok = true;
			pieces.set(pp,true);
			piece_providers.insert(p.getPieceDownloader());
			num_downloaded++;
			if (pdown.count() > 1)
			{
				endgameCancel(p);
			}
			
			updateHash();
			
			if (num_downloaded >= num)
			{
				// finalize hash
				hash_gen.end();
				releaseAllPDs();
				return true;
			}
		}
		
		sendRequests();
		return false;
	}
示例#22
0
bool Archive::readTable()
{
	if ( m_pFile->size() == 0 )
	{
		// really bad news if the following exception get's thrown
		if ( m_SectorMap.size() != 0 )
			throw Failure();
		// new archive file, initialize the header
		if ( m_Access == READ )
			return false;
		
		// write a pristine table to disk
		writeTable();

		return true;
	}


	// read in the header
	ArchiveHeader header;
	m_pFile->setPosition( 0 );
	m_pFile->read( &header, sizeof(header) );

	if (header.id != ARCHIVE_ID )
		return false;

	// read in the table
	m_pFile->setPosition( sizeof(ArchiveHeader) + header.sectors * ARCHIVE_SECTOR_SIZE );

	InStream input( m_pFile );
	input >> m_Files;
	input >> m_SectorMap;

	// build the file hash
	updateHash();

	return true;
}
示例#23
0
EditUserDialog::EditUserDialog(int userIndex, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::EditUserDialog)
{
    ui->setupUi(this);
    connect(ui->selectFolderButton,SIGNAL(clicked()),SLOT(openFolderDialog()));
    connect(ui->passwordEdt, SIGNAL(textEdited(QString)),SLOT(updateHash(QString)));
    if ( userIndex >= 0)
    {
        User user = Settings::getInstance()->listUsers().at(userIndex);
        ui->usernameEdt->setText(user.getName());
        passHash = user.getPasswordHash();
        if (passHash.isEmpty())
            ui->emptypassRB->setChecked(true);
        else
            ui->enterpassRB->setChecked(true);
        ui->folderEdt->setText(user.getFolder());
        FileAccess fileAccess = user.getFileAccess();
        ui->freadCb->setChecked(fileAccess.aread);
        ui->fwriteCb->setChecked(fileAccess.awrite);
        ui->fdeleteCb->setChecked(fileAccess.adelete);
        ui->fappendCb->setChecked(fileAccess.aappend);
    }
}
示例#24
0
 void WorldState::unset(const Fact &fact)
 {
    _unset(fact);
    updateHash();
 }
TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent)
    : Tab(_tabSupervisor, parent), modified(false)
{
    aClearFilterAll = new QAction(QString(), this);
    aClearFilterAll->setIcon(QIcon(":/resources/icon_clearsearch.svg"));
    connect(aClearFilterAll, SIGNAL(triggered()), this, SLOT(actClearFilterAll()));

    aClearFilterOne = new QAction(QString(), this);
    aClearFilterOne->setIcon(QIcon(":/resources/decrement.svg"));
    connect(aClearFilterOne, SIGNAL(triggered()), this, SLOT(actClearFilterOne()));

    searchEdit = new SearchLineEdit;
#if QT_VERSION >= 0x050300
    searchEdit->addAction(QIcon(":/resources/icon_search_black.svg"), QLineEdit::LeadingPosition);
#endif
    searchEdit->setObjectName("searchEdit");
    
    setFocusProxy(searchEdit);
    setFocusPolicy(Qt::ClickFocus);

    searchEdit->installEventFilter(&searchKeySignals);
    connect(searchEdit, SIGNAL(textChanged(const QString &)), this, SLOT(updateSearch(const QString &)));
    connect(&searchKeySignals, SIGNAL(onEnter()), this, SLOT(actAddCard()));
    connect(&searchKeySignals, SIGNAL(onCtrlAltEqual()), this, SLOT(actAddCard()));
    connect(&searchKeySignals, SIGNAL(onCtrlAltRBracket()), this, SLOT(actAddCardToSideboard()));
    connect(&searchKeySignals, SIGNAL(onCtrlAltMinus()), this, SLOT(actDecrementCard()));
    connect(&searchKeySignals, SIGNAL(onCtrlAltLBracket()), this, SLOT(actDecrementCardFromSideboard()));
    connect(&searchKeySignals, SIGNAL(onCtrlAltEnter()), this, SLOT(actAddCardToSideboard()));
    connect(&searchKeySignals, SIGNAL(onCtrlEnter()), this, SLOT(actAddCardToSideboard()));

    QToolBar *deckEditToolBar = new QToolBar;
    deckEditToolBar->setOrientation(Qt::Horizontal);
    deckEditToolBar->setIconSize(QSize(24, 24));

    QHBoxLayout *searchLayout = new QHBoxLayout;
    searchLayout->addWidget(deckEditToolBar);
    searchLayout->addWidget(searchEdit);

    databaseModel = new CardDatabaseModel(db, this);
    databaseDisplayModel = new CardDatabaseDisplayModel(this);
    databaseDisplayModel->setSourceModel(databaseModel);
    databaseDisplayModel->setFilterKeyColumn(0);
    databaseDisplayModel->sort(0, Qt::AscendingOrder);

    databaseView = new QTreeView();
    databaseView->setFocusProxy(searchEdit);
    databaseView->setModel(databaseDisplayModel);
    databaseView->setUniformRowHeights(true);
    databaseView->setRootIsDecorated(false);
    databaseView->setAlternatingRowColors(true);
    databaseView->setSortingEnabled(true);
    databaseView->sortByColumn(0, Qt::AscendingOrder);
    databaseView->resizeColumnToContents(0);
    connect(databaseView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(updateCardInfoLeft(const QModelIndex &, const QModelIndex &)));
    connect(databaseView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(actAddCard()));
    searchEdit->setTreeView(databaseView);

    QVBoxLayout *leftFrame = new QVBoxLayout;
    leftFrame->addLayout(searchLayout);
    leftFrame->addWidget(databaseView);

    cardInfo = new CardFrame(250, 372);

    filterModel = new FilterTreeModel();
    databaseDisplayModel->setFilterTree(filterModel->filterTree());
    filterView = new QTreeView;
    filterView->setModel(filterModel);
    filterView->setMaximumWidth(250);
    filterView->setUniformRowHeights(true);
    filterView->setHeaderHidden(true);
    filterView->setContextMenuPolicy(Qt::CustomContextMenu);
    connect(filterModel, SIGNAL(layoutChanged()), filterView, SLOT(expandAll()));
    connect(filterView, SIGNAL(customContextMenuRequested(const QPoint &)),
            this, SLOT(filterViewCustomContextMenu(const QPoint &)));
    FilterBuilder *filterBuilder = new FilterBuilder;
    connect(filterBuilder, SIGNAL(add(const CardFilter *)), filterModel, SLOT(addFilter(const CardFilter *)));

    QToolButton *filterDelOne = new QToolButton();
    filterDelOne->setDefaultAction(aClearFilterOne);
    filterDelOne->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);

    QToolButton *filterDelAll = new QToolButton();
    filterDelAll->setDefaultAction(aClearFilterAll);
    filterDelAll->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);

    QGridLayout *filterLayout = new QGridLayout;
    filterLayout->addWidget(filterBuilder, 0, 0, 1, 2);
    filterLayout->addWidget(filterView, 1, 0, 1, 2);
    filterLayout->addWidget(filterDelOne, 2, 0);
    filterLayout->addWidget(filterDelAll, 2, 1);

    filterBox = new QGroupBox();
    filterBox->setMaximumWidth(250);
    filterBox->setLayout(filterLayout);

    QVBoxLayout *middleFrame = new QVBoxLayout;
    middleFrame->addWidget(cardInfo, 1, Qt::AlignTop);
    middleFrame->addWidget(filterBox, 0);

    deckModel = new DeckListModel(this);
    connect(deckModel, SIGNAL(deckHashChanged()), this, SLOT(updateHash()));
    deckView = new QTreeView();
    deckView->setModel(deckModel);
    deckView->setUniformRowHeights(true);
    deckView->setSortingEnabled(true);
    deckView->sortByColumn(1, Qt::AscendingOrder);
#if QT_VERSION < 0x050000
    deckView->header()->setResizeMode(QHeaderView::ResizeToContents);
#else
    deckView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
#endif
    deckView->installEventFilter(&deckViewKeySignals);
    connect(deckView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(updateCardInfoRight(const QModelIndex &, const QModelIndex &)));
    connect(deckView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(actSwapCard()));
    connect(&deckViewKeySignals, SIGNAL(onS()), this, SLOT(actSwapCard()));
    connect(&deckViewKeySignals, SIGNAL(onEnter()), this, SLOT(actIncrement()));
    connect(&deckViewKeySignals, SIGNAL(onCtrlAltEqual()), this, SLOT(actIncrement()));
    connect(&deckViewKeySignals, SIGNAL(onCtrlAltMinus()), this, SLOT(actDecrement()));
    connect(&deckViewKeySignals, SIGNAL(onRight()), this, SLOT(actIncrement()));
    connect(&deckViewKeySignals, SIGNAL(onLeft()), this, SLOT(actDecrement()));
    connect(&deckViewKeySignals, SIGNAL(onDelete()), this, SLOT(actRemoveCard()));

    nameLabel = new QLabel();
    nameEdit = new QLineEdit;
    nameLabel->setBuddy(nameEdit);
    connect(nameEdit, SIGNAL(textChanged(const QString &)), this, SLOT(updateName(const QString &)));
    commentsLabel = new QLabel();
    commentsEdit = new QTextEdit;
    commentsEdit->setMaximumHeight(70);
    commentsLabel->setBuddy(commentsEdit);
    connect(commentsEdit, SIGNAL(textChanged()), this, SLOT(updateComments()));
    hashLabel1 = new QLabel();
    hashLabel = new QLabel;

    QGridLayout *grid = new QGridLayout;
    grid->addWidget(nameLabel, 0, 0);
    grid->addWidget(nameEdit, 0, 1);

    grid->addWidget(commentsLabel, 1, 0);
    grid->addWidget(commentsEdit, 1, 1);

    grid->addWidget(hashLabel1, 2, 0);
    grid->addWidget(hashLabel, 2, 1);

    /* Update price
    aUpdatePrices = new QAction(QString(), this);
    aUpdatePrices->setIcon(QIcon(":/resources/icon_update.png"));
    connect(aUpdatePrices, SIGNAL(triggered()), this, SLOT(actUpdatePrices()));
    if (!settingsCache->getPriceTagFeature())
        aUpdatePrices->setVisible(false);
    connect(settingsCache, SIGNAL(priceTagFeatureChanged(int)), this, SLOT(setPriceTagFeatureEnabled(int)));
    */

    QToolBar *deckToolBar = new QToolBar;
    deckToolBar->setOrientation(Qt::Vertical);
    deckToolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
    deckToolBar->setIconSize(QSize(24, 24));
    //deckToolBar->addAction(aUpdatePrices);
    QHBoxLayout *deckToolbarLayout = new QHBoxLayout;
    deckToolbarLayout->addStretch();
    deckToolbarLayout->addWidget(deckToolBar);
    deckToolbarLayout->addStretch();

    QVBoxLayout *rightFrame = new QVBoxLayout;
    rightFrame->addLayout(grid);
    rightFrame->addWidget(deckView, 10);
    rightFrame->addLayout(deckToolbarLayout);

    QHBoxLayout *mainLayout = new QHBoxLayout;
    mainLayout->addLayout(leftFrame, 10);
    mainLayout->addLayout(middleFrame);
    mainLayout->addLayout(rightFrame);
    setLayout(mainLayout);

    aNewDeck = new QAction(QString(), this);
    aNewDeck->setShortcuts(QKeySequence::New);
    connect(aNewDeck, SIGNAL(triggered()), this, SLOT(actNewDeck()));
    aLoadDeck = new QAction(QString(), this);
    aLoadDeck->setShortcuts(QKeySequence::Open);
    connect(aLoadDeck, SIGNAL(triggered()), this, SLOT(actLoadDeck()));
    aSaveDeck = new QAction(QString(), this);
    aSaveDeck->setShortcuts(QKeySequence::Save);
    connect(aSaveDeck, SIGNAL(triggered()), this, SLOT(actSaveDeck()));
    aSaveDeckAs = new QAction(QString(), this);
//    aSaveDeckAs->setShortcuts(QKeySequence::SaveAs);
    connect(aSaveDeckAs, SIGNAL(triggered()), this, SLOT(actSaveDeckAs()));
    aLoadDeckFromClipboard = new QAction(QString(), this);
    connect(aLoadDeckFromClipboard, SIGNAL(triggered()), this, SLOT(actLoadDeckFromClipboard()));
    aLoadDeckFromClipboard->setShortcuts(QKeySequence::Paste);
    aSaveDeckToClipboard = new QAction(QString(), this);
    connect(aSaveDeckToClipboard, SIGNAL(triggered()), this, SLOT(actSaveDeckToClipboard()));
    aSaveDeckToClipboard->setShortcuts(QKeySequence::Copy);
    aPrintDeck = new QAction(QString(), this);
    aPrintDeck->setShortcuts(QKeySequence::Print);
    connect(aPrintDeck, SIGNAL(triggered()), this, SLOT(actPrintDeck()));
    aAnalyzeDeck = new QAction(QString(), this);
    connect(aAnalyzeDeck, SIGNAL(triggered()), this, SLOT(actAnalyzeDeck()));
    aClose = new QAction(QString(), this);
    connect(aClose, SIGNAL(triggered()), this, SLOT(closeRequest()));
    aOpenCustomFolder = new QAction(QString(), this);
    connect(aOpenCustomFolder, SIGNAL(triggered()), this, SLOT(actOpenCustomFolder()));

    aEditSets = new QAction(QString(), this);
    connect(aEditSets, SIGNAL(triggered()), this, SLOT(actEditSets()));
    aEditTokens = new QAction(QString(), this);
    connect(aEditTokens, SIGNAL(triggered()), this, SLOT(actEditTokens()));

    deckMenu = new QMenu(this);
    deckMenu->addAction(aNewDeck);
    deckMenu->addAction(aLoadDeck);
    deckMenu->addAction(aSaveDeck);
    deckMenu->addAction(aSaveDeckAs);
    deckMenu->addSeparator();
    deckMenu->addAction(aLoadDeckFromClipboard);
    deckMenu->addAction(aSaveDeckToClipboard);
    deckMenu->addSeparator();
    deckMenu->addAction(aPrintDeck);
    deckMenu->addSeparator();
    deckMenu->addAction(aAnalyzeDeck);
    deckMenu->addSeparator();
    deckMenu->addAction(aClose);
    addTabMenu(deckMenu);

    dbMenu = new QMenu(this);
    dbMenu->addAction(aEditSets);
    dbMenu->addAction(aEditTokens);
    dbMenu->addSeparator();
    dbMenu->addAction(aClearFilterAll);
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
    dbMenu->addSeparator();
    dbMenu->addAction(aOpenCustomFolder);
#endif
    addTabMenu(dbMenu);

    aAddCard = new QAction(QString(), this);
    aAddCard->setIcon(QIcon(":/resources/arrow_right_green.svg"));
    connect(aAddCard, SIGNAL(triggered()), this, SLOT(actAddCard()));
    aAddCardToSideboard = new QAction(QString(), this);
    aAddCardToSideboard->setIcon(QIcon(":/resources/add_to_sideboard.svg"));
    connect(aAddCardToSideboard, SIGNAL(triggered()), this, SLOT(actAddCardToSideboard()));
    aRemoveCard = new QAction(QString(), this);
    aRemoveCard->setIcon(QIcon(":/resources/remove_row.svg"));
    connect(aRemoveCard, SIGNAL(triggered()), this, SLOT(actRemoveCard()));
    aIncrement = new QAction(QString(), this);
    aIncrement->setIcon(QIcon(":/resources/increment.svg"));
    connect(aIncrement, SIGNAL(triggered()), this, SLOT(actIncrement()));
    aDecrement = new QAction(QString(), this);
    aDecrement->setIcon(QIcon(":/resources/decrement.svg"));
    connect(aDecrement, SIGNAL(triggered()), this, SLOT(actDecrement()));

    deckEditToolBar->addAction(aAddCard);
    deckEditToolBar->addAction(aAddCardToSideboard);
    deckEditToolBar->addAction(aRemoveCard);
    deckEditToolBar->addAction(aDecrement);
    deckEditToolBar->addAction(aIncrement);
    deckEditToolBar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);

    retranslateUi();
    
    resize(950, 700);

    QTimer::singleShot(0, this, SLOT(checkFirstRunDetected()));
}
示例#26
0
void TabDeckEditor::createDeckDock()
{
    deckModel = new DeckListModel(this);
    deckModel->setObjectName("deckModel");
    connect(deckModel, SIGNAL(deckHashChanged()), this, SLOT(updateHash()));
    deckView = new QTreeView();
    deckView->setObjectName("deckView");
    deckView->setModel(deckModel);
    deckView->setUniformRowHeights(true);
    deckView->setSortingEnabled(true);
    deckView->sortByColumn(1, Qt::AscendingOrder);
#if QT_VERSION < 0x050000
    deckView->header()->setResizeMode(QHeaderView::ResizeToContents);
#else
    deckView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
#endif
    deckView->installEventFilter(&deckViewKeySignals);
    connect(deckView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(updateCardInfoRight(const QModelIndex &, const QModelIndex &)));
    connect(deckView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(actSwapCard()));
    connect(&deckViewKeySignals, SIGNAL(onS()), this, SLOT(actSwapCard()));
    connect(&deckViewKeySignals, SIGNAL(onEnter()), this, SLOT(actIncrement()));
    connect(&deckViewKeySignals, SIGNAL(onCtrlAltEqual()), this, SLOT(actIncrement()));
    connect(&deckViewKeySignals, SIGNAL(onCtrlAltMinus()), this, SLOT(actDecrement()));
    connect(&deckViewKeySignals, SIGNAL(onRight()), this, SLOT(actIncrement()));
    connect(&deckViewKeySignals, SIGNAL(onLeft()), this, SLOT(actDecrement()));
    connect(&deckViewKeySignals, SIGNAL(onDelete()), this, SLOT(actRemoveCard()));

    nameLabel = new QLabel();
    nameLabel->setObjectName("nameLabel");
    nameEdit = new QLineEdit;
    nameEdit->setObjectName("nameEdit");
    nameLabel->setBuddy(nameEdit);
    connect(nameEdit, SIGNAL(textChanged(const QString &)), this, SLOT(updateName(const QString &)));
    commentsLabel = new QLabel();
    commentsLabel->setObjectName("commentsLabel");
    commentsEdit = new QTextEdit;
    commentsEdit->setObjectName("commentsEdit");
    commentsEdit->setMaximumHeight(70);
    commentsLabel->setBuddy(commentsEdit);
    connect(commentsEdit, SIGNAL(textChanged()), this, SLOT(updateComments()));

    hashLabel1 = new QLabel();
    hashLabel1->setObjectName("hashLabel1");
    hashLabel = new QLabel;
    hashLabel->setObjectName("hashLabel");

    QGridLayout *grid = new QGridLayout;
    grid->setObjectName("grid");
    grid->addWidget(nameLabel, 0, 0);
    grid->addWidget(nameEdit, 0, 1);

    grid->addWidget(commentsLabel, 1, 0);
    grid->addWidget(commentsEdit, 1, 1);

    grid->addWidget(hashLabel1, 2, 0);
    grid->addWidget(hashLabel, 2, 1);

    /* Update price
    aUpdatePrices = new QAction(QString(), this);
    aUpdatePrices->setIcon(QPixmap("theme:icons/update"));
    connect(aUpdatePrices, SIGNAL(triggered()), this, SLOT(actUpdatePrices()));
    if (!settingsCache->getPriceTagFeature())
        aUpdatePrices->setVisible(false);
    connect(settingsCache, SIGNAL(priceTagFeatureChanged(int)), this, SLOT(setPriceTagFeatureEnabled(int)));
    */

    QToolBar *deckToolBar = new QToolBar;
    deckToolBar->setObjectName("deckToolBar");
    deckToolBar->setOrientation(Qt::Vertical);
    deckToolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
    deckToolBar->setIconSize(QSize(24, 24));
    //deckToolBar->addAction(aUpdatePrices);
    QHBoxLayout *deckToolbarLayout = new QHBoxLayout;
    deckToolbarLayout->setObjectName("deckToolbarLayout");
    deckToolbarLayout->addStretch();
    deckToolbarLayout->addWidget(deckToolBar);
    deckToolbarLayout->addStretch();

    QVBoxLayout *rightFrame = new QVBoxLayout;
    rightFrame->setObjectName("rightFrame");
    rightFrame->addLayout(grid);
    rightFrame->addWidget(deckView, 10);
    rightFrame->addLayout(deckToolbarLayout);

    deckDock = new QDockWidget(MainWindow);
    deckDock->setObjectName("deckDock");

    deckDock->setMinimumSize(QSize(200, 41));
    deckDock->setAllowedAreas(Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea);
    deckDock->setFeatures(QDockWidget::DockWidgetClosable|QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable);
    QWidget *deckDockContents = new QWidget();
    deckDockContents->setObjectName("deckDockContents");
    deckDockContents->setLayout(rightFrame);
    deckDock->setWidget(deckDockContents);

    connect(btnDeck,SIGNAL(toggled(bool)),deckDock,SLOT(setVisible(bool)));
    deckDock->installEventFilter(this);
}
示例#27
0
 // decode a bitstream @bitstream and compute 
 // the SHA1 hash of the reconstruction YUV file
 void DecodeHash(const char* bitstream, unsigned char* md) {
  FILE* pH264File	  = NULL;
  int64_t iStart = 0, iEnd = 0, iTotal = 0;
  int32_t iSliceSize;
  int32_t iSliceIndex = 0;
  uint8_t* pBuf = NULL;
  uint8_t uiStartCode[4] = {0, 0, 0, 1};
  int iWidth, iHeight;
  void* pData[3] = {NULL};
  uint8_t* pDst[3] = {NULL};
  SBufferInfo sDstBufInfo;
  CryptoPP::SHA1 hash;
  int32_t iBufPos = 0;
  int32_t iFileSize;
  int32_t i = 0;
  int32_t iLastWidth = 0, iLastHeight = 0;
  int32_t iFrameCount = 0;
  int32_t iEndOfStreamFlag = 0;
  int iYStride, iUVStride;
  static int32_t iFrameNum = 0;

  EDecodeMode     eDecoderMode    = AUTO_MODE;
  EBufferProperty	eOutputProperty = BUFFER_DEVICE;
  double dElapsed = 0;
  pH264File = fopen(bitstream, "rb");
  ASSERT_TRUE(pH264File);
  fseek (pH264File, 0L, SEEK_END);
  iFileSize = ftell (pH264File);
  if (iFileSize <= 0) {
    fprintf (stderr, "Current Bit Stream File is too small, read error!!!!\n");
    goto label_exit;
  }
  fseek (pH264File, 0L, SEEK_SET);

  pBuf = new uint8_t[iFileSize + 4];
  if (pBuf == NULL) {
    fprintf (stderr, "new buffer failed!\n");
    goto label_exit;
  }

  fread (pBuf, 1, iFileSize, pH264File);
  memcpy (pBuf + iFileSize, &uiStartCode[0], 4); //confirmed_safe_unsafe_usage

  while (true) {

    if (iBufPos >= iFileSize) {
      iEndOfStreamFlag = true;
      break;
    }

    for (i = 0; i < iFileSize; i++) {
      if (pBuf[iBufPos + i] == 0 && pBuf[iBufPos + i + 1] == 0 && pBuf[iBufPos + i + 2] == 0 &&
          pBuf[iBufPos + i + 3] == 1 && i > 0) {
        break;
      }
    }
    iSliceSize = i;

    pData[0] = NULL;
    pData[1] = NULL;
    pData[2] = NULL;
    memset (&sDstBufInfo, 0, sizeof (SBufferInfo));

    decoder_->DecodeFrame (pBuf + iBufPos, iSliceSize, pData, &sDstBufInfo);

    if (sDstBufInfo.iBufferStatus == 1) {
      pDst[0] = (uint8_t*)pData[0];
      pDst[1] = (uint8_t*)pData[1];
      pDst[2] = (uint8_t*)pData[2];
    }
    iTotal	+= iEnd - iStart;
    if (sDstBufInfo.iBufferStatus == 1) {
      iFrameNum++;
      if (sDstBufInfo.eBufferProperty == BUFFER_HOST) {
        iWidth  = sDstBufInfo.UsrData.sSystemBuffer.iWidth;
        iHeight = sDstBufInfo.UsrData.sSystemBuffer.iHeight;
        iYStride = sDstBufInfo.UsrData.sSystemBuffer.iStride[0];
        iUVStride = sDstBufInfo.UsrData.sSystemBuffer.iStride[1];
      } else {
        iWidth  = sDstBufInfo.UsrData.sVideoBuffer.iSurfaceWidth;
        iHeight = sDstBufInfo.UsrData.sVideoBuffer.iSurfaceHeight;
      }
      updateHash(hash, pDst[0], iWidth, iHeight, iYStride);
      updateHash(hash, pDst[1], iWidth >> 1, iHeight >> 1, iUVStride);
      updateHash(hash, pDst[2], iWidth >> 1, iHeight >> 1, iUVStride);
      ++ iFrameCount;
    }

    iBufPos += iSliceSize;
    ++ iSliceIndex;
  }
示例#28
0
SHAMapTreeNode::SHAMapTreeNode (const SHAMapNode& id, Blob const& rawNode, uint32 seq,
                                SHANodeFormat format, uint256 const& hash, bool hashValid) :
    SHAMapNode (id), mSeq (seq), mType (tnERROR), mIsBranch (0), mFullBelow (false)
{
    if (format == snfWIRE)
    {
        Serializer s (rawNode);
        int type = s.removeLastByte ();
        int len = s.getLength ();

        if ((type < 0) || (type > 4))
        {
#ifdef BEAST_DEBUG
            Log::out() << "Invalid wire format node";
            Log::out() << strHex (rawNode);
            assert (false);
#endif
            throw std::runtime_error ("invalid node AW type");
        }

        if (type == 0)
        {
            // transaction
            mItem = boost::make_shared<SHAMapItem> (s.getPrefixHash (HashPrefix::transactionID), s.peekData ());
            mType = tnTRANSACTION_NM;
        }
        else if (type == 1)
        {
            // account state
            if (len < (256 / 8))
                throw std::runtime_error ("short AS node");

            uint256 u;
            s.get256 (u, len - (256 / 8));
            s.chop (256 / 8);

            if (u.isZero ()) throw std::runtime_error ("invalid AS node");

            mItem = boost::make_shared<SHAMapItem> (u, s.peekData ());
            mType = tnACCOUNT_STATE;
        }
        else if (type == 2)
        {
            // full inner
            if (len != 512)
                throw std::runtime_error ("invalid FI node");

            for (int i = 0; i < 16; ++i)
            {
                s.get256 (mHashes[i], i * 32);

                if (mHashes[i].isNonZero ())
                    mIsBranch |= (1 << i);
            }

            mType = tnINNER;
        }
        else if (type == 3)
        {
            // compressed inner
            for (int i = 0; i < (len / 33); ++i)
            {
                int pos;
                s.get8 (pos, 32 + (i * 33));

                if ((pos < 0) || (pos >= 16)) throw std::runtime_error ("invalid CI node");

                s.get256 (mHashes[pos], i * 33);

                if (mHashes[pos].isNonZero ())
                    mIsBranch |= (1 << pos);
            }

            mType = tnINNER;
        }
        else if (type == 4)
        {
            // transaction with metadata
            if (len < (256 / 8))
                throw std::runtime_error ("short TM node");

            uint256 u;
            s.get256 (u, len - (256 / 8));
            s.chop (256 / 8);

            if (u.isZero ())
                throw std::runtime_error ("invalid TM node");

            mItem = boost::make_shared<SHAMapItem> (u, s.peekData ());
            mType = tnTRANSACTION_MD;
        }
    }

    else if (format == snfPREFIX)
    {
        if (rawNode.size () < 4)
        {
            WriteLog (lsINFO, SHAMapNode) << "size < 4";
            throw std::runtime_error ("invalid P node");
        }

        uint32 prefix = rawNode[0];
        prefix <<= 8;
        prefix |= rawNode[1];
        prefix <<= 8;
        prefix |= rawNode[2];
        prefix <<= 8;
        prefix |= rawNode[3];
        Serializer s (rawNode.begin () + 4, rawNode.end ());

        if (prefix == HashPrefix::transactionID)
        {
            mItem = boost::make_shared<SHAMapItem> (Serializer::getSHA512Half (rawNode), s.peekData ());
            mType = tnTRANSACTION_NM;
        }
        else if (prefix == HashPrefix::leafNode)
        {
            if (s.getLength () < 32)
                throw std::runtime_error ("short PLN node");

            uint256 u;
            s.get256 (u, s.getLength () - 32);
            s.chop (32);

            if (u.isZero ())
            {
                WriteLog (lsINFO, SHAMapNode) << "invalid PLN node";
                throw std::runtime_error ("invalid PLN node");
            }

            mItem = boost::make_shared<SHAMapItem> (u, s.peekData ());
            mType = tnACCOUNT_STATE;
        }
        else if (prefix == HashPrefix::innerNode)
        {
            if (s.getLength () != 512)
                throw std::runtime_error ("invalid PIN node");

            for (int i = 0; i < 16; ++i)
            {
                s.get256 (mHashes[i], i * 32);

                if (mHashes[i].isNonZero ())
                    mIsBranch |= (1 << i);
            }

            mType = tnINNER;
        }
        else if (prefix == HashPrefix::txNode)
        {
            // transaction with metadata
            if (s.getLength () < 32)
                throw std::runtime_error ("short TXN node");

            uint256 txID;
            s.get256 (txID, s.getLength () - 32);
            s.chop (32);
            mItem = boost::make_shared<SHAMapItem> (txID, s.peekData ());
            mType = tnTRANSACTION_MD;
        }
        else
        {
            WriteLog (lsINFO, SHAMapNode) << "Unknown node prefix " << std::hex << prefix << std::dec;
            throw std::runtime_error ("invalid node prefix");
        }
    }

    else
    {
        assert (false);
        throw std::runtime_error ("Unknown format");
    }

    if (hashValid)
    {
        mHash = hash;
#if RIPPLE_VERIFY_NODEOBJECT_KEYS
        updateHash ();
        assert (mHash == hash);
#endif
    }
    else
        updateHash ();
}
示例#29
0
SHAMapTreeNode::SHAMapTreeNode (const SHAMapNode& node, SHAMapItem::ref item, TNType type, uint32 seq) :
    SHAMapNode (node), mItem (item), mSeq (seq), mType (type), mIsBranch (0), mFullBelow (false)
{
    assert (item->peekData ().size () >= 12);
    updateHash ();
}
示例#30
0
 void WorldState::set(const Fact &fact, PVal val)
 {
    _set(fact, val);
    updateHash();
 }