示例#1
0
std::pair<uint64_t, uint64_t> block_queue::reserve_span(uint64_t first_block_height, uint64_t last_block_height, uint64_t max_blocks, const boost::uuids::uuid &connection_id, const std::list<crypto::hash> &block_hashes, boost::posix_time::ptime time)
{
  boost::unique_lock<boost::recursive_mutex> lock(mutex);

  if (last_block_height < first_block_height || max_blocks == 0)
  {
    MDEBUG("reserve_span: early out: first_block_height " << first_block_height << ", last_block_height " << last_block_height << ", max_blocks " << max_blocks);
    return std::make_pair(0, 0);
  }

  uint64_t span_start_height = last_block_height - block_hashes.size() + 1;
  std::list<crypto::hash>::const_iterator i = block_hashes.begin();
  while (i != block_hashes.end() && requested(*i))
  {
    ++i;
    ++span_start_height;
  }
  uint64_t span_length = 0;
  std::list<crypto::hash> hashes;
  while (i != block_hashes.end() && span_length < max_blocks)
  {
    hashes.push_back(*i);
    ++i;
    ++span_length;
  }
  if (span_length == 0)
    return std::make_pair(0, 0);
  MDEBUG("Reserving span " << span_start_height << " - " << (span_start_height + span_length - 1) << " for " << connection_id);
  add_blocks(span_start_height, span_length, connection_id, time);
  set_span_hashes(span_start_height, connection_id, hashes);
  return std::make_pair(span_start_height, span_length);
}
示例#2
0
void TextTool::release(const KTInputDeviceInformation *input, KTBrushManager *brushManager, KTGraphicsScene *scene)
{
    Q_UNUSED(input);
    Q_UNUSED(brushManager);

    if (m_configurator->text().isEmpty()) {
        delete m_item;
        return;
    }

    if (m_configurator->isHtml())
        m_item->setHtml(m_configurator->text());
    else
        m_item->setPlainText(m_configurator->text());

    m_item->setFont(m_configurator->textFont());

    //scene->addItem(m_item);
    scene->includeObject(m_item);

    QDomDocument doc;
    doc.appendChild(m_item->toXml(doc));

    KTProjectRequest event = KTRequestBuilder::createItemRequest(scene->currentSceneIndex(), scene->currentLayerIndex(), 
                             scene->currentFrameIndex(), scene->currentFrame()->graphics().count(), QPointF(),
                             KTLibraryObject::Item, KTProjectRequest::Add, doc.toString()); // Adds to end

    emit requested(&event);
}
示例#3
0
void PencilTool::release(const TupInputDeviceInformation *input, TupBrushManager *brushManager, TupGraphicsScene *scene)
{
    Q_UNUSED(brushManager);

    if (!k->item)
        return;

    double smoothness = k->configurator->exactness();

    if (k->firstPoint == input->pos() && k->path.elementCount() == 1) {
        smoothness = 0;
        qreal radius = ((qreal) brushManager->pen().width()) / ((qreal) 2);
        k->path.addEllipse(input->pos().x(), input->pos().y(), radius, radius);
    } 

    smoothPath(k->path, smoothness);

    k->item->setBrush(brushManager->brush());
    k->item->setPath(k->path);

    QDomDocument doc;
    doc.appendChild(k->item->toXml(doc));

    TupProjectRequest request = TupRequestBuilder::createItemRequest(scene->currentSceneIndex(), scene->currentLayerIndex(), scene->currentFrameIndex(), 
                                                                     0, QPoint(), scene->spaceContext(), TupLibraryObject::Item, TupProjectRequest::Add, 
                                                                     doc.toString());

    emit requested(&request);
}
示例#4
0
void PencilTool::release(const TupInputDeviceInformation *input, TupBrushManager *brushManager, TupGraphicsScene *scene)
{
    Q_UNUSED(brushManager);

    if (!k->resize) {
        if (!k->item)
            return;

        if (k->firstPoint == input->pos() && k->path.elementCount() == 1) {
            QPointF currentPoint = input->pos();
            scene->removeItem(k->item);
 
            qreal radius = brushManager->pen().width();
            QPointF distance((radius + 2)/2, (radius + 2)/2);
            QPen inkPen(brushManager->penColor(), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
            TupEllipseItem *blackEllipse = new TupEllipseItem(QRectF(currentPoint - distance, QSize(radius + 2, radius + 2)));
            blackEllipse->setPen(inkPen);
            blackEllipse->setBrush(inkPen.brush());
            scene->includeObject(blackEllipse);

            QDomDocument doc;
            doc.appendChild(blackEllipse->toXml(doc));
            TupProjectRequest request = TupRequestBuilder::createItemRequest(scene->currentSceneIndex(), scene->currentLayerIndex(), scene->currentFrameIndex(),
                                                                             0, currentPoint, scene->spaceContext(), TupLibraryObject::Item, TupProjectRequest::Add,
                                                                             doc.toString());
            emit requested(&request);
            return;
        } else {
            double smoothness = k->configurator->smoothness();
            if (smoothness > 0)
                smoothPath(k->path, smoothness);
        }

        k->item->setBrush(brushManager->brush());
        k->item->setPath(k->path);

        QDomDocument doc;
        doc.appendChild(k->item->toXml(doc));

        TupProjectRequest request = TupRequestBuilder::createItemRequest(scene->currentSceneIndex(), scene->currentLayerIndex(), scene->currentFrameIndex(), 
                                                                         0, QPoint(), scene->spaceContext(), TupLibraryObject::Item, TupProjectRequest::Add, 
                                                                         doc.toString());
        emit requested(&request);
    }
}
	FileTransferManager::FileTransferManager (ToxAccount *acc)
	: QObject { acc }
	, Acc_ { acc }
	{
		connect (this,
				SIGNAL (requested (int32_t, QByteArray, uint8_t, uint64_t, QString)),
				this,
				SLOT (handleRequest (int32_t, QByteArray, uint8_t, uint64_t, QString)));
	}
示例#6
0
  ShutterSpeedChoice TimeLapseCapture::getShutterSpeed(QString optStr, QList<ShutterSpeedChoice> choices, ErrorMessageHelper *die) {
    try {
      ShutterSpeedChoice requested(optStr);
      // check if this option is available
      bool found = false;
      for (ShutterSpeedChoice ch : choices) {
        if ((ch.toString() == requested.toString()) || (ch.isBulb() && requested.isBulb())) {
          found = true;
          break;
        }
      }
      if (!found)
        *die << QString("Camera don't support requested shutterspeed \"%1\".").arg(optStr);
      return requested;
    } catch (std::exception &e) {
      *die << QString("Can't parse shutterspeed option \"%1\": %2").arg(optStr).arg(e.what());
    }

    throw std::logic_error("Unreachable statement - should not happen!");
  }
示例#7
0
void VideoCapture::request()
{
    emit requested();
}
示例#8
0
int
main(int argc, char *argv[])
{
	char *p;
	struct acct ab;
	struct stat sb;
	FILE *fp;
	off_t size = 0;
	time_t t;
	int ch;
	const char *acctfile;
	int flags = 0;

	acctfile = _PATH_ACCT;
	while ((ch = getopt(argc, argv, "f:usecSE")) != -1)
		switch((char)ch) {
		case 'f':
			acctfile = optarg;
			break;

		case 'u': 
			flags |= AC_UTIME; /* user time */
			break;
		case 's':
			flags |= AC_STIME; /* system time */
			break;
		case 'e':
			flags |= AC_ETIME; /* elapsed time */
			break;
		case 'c':
                        flags |= AC_CTIME; /* user + system time */
			break;

		case 'S':
                        flags |= AC_BTIME; /* starting time */
			break;
		case 'E':
			/* exit time (starting time + elapsed time )*/
                        flags |= AC_FTIME; 
			break;

		case '?':
		default:
			usage();
		}

	/* default user + system time and starting time */
	if (!flags) {
	    flags = AC_CTIME | AC_BTIME;
	}

	argc -= optind;
	argv += optind;

	if (strcmp(acctfile, "-") == 0)
		fp = stdin;
	else {
		/* Open the file. */
		if ((fp = fopen(acctfile, "r")) == NULL ||
		    fstat(fileno(fp), &sb))
			err(1, "could not open %s", acctfile);

		/*
		 * Round off to integral number of accounting records,
		 * probably not necessary, but it doesn't hurt.
		 */
		size = sb.st_size - sb.st_size % sizeof(struct acct);

		/* Check if any records to display. */
		if ((unsigned)size < sizeof(struct acct))
			exit(0);
	}

	do {
		int rv;

		if (fp != stdin) {
			size -= sizeof(struct acct);
			if (fseeko(fp, size, SEEK_SET) == -1)
				err(1, "seek %s failed", acctfile);
		}

		if ((rv = fread(&ab, sizeof(struct acct), 1, fp)) != 1) {
			if (feof(fp))
				break;
			else
				err(1, "read %s returned %d", acctfile, rv);
		}

		if (ab.ac_comm[0] == '\0') {
			ab.ac_comm[0] = '?';
			ab.ac_comm[1] = '\0';
		} else
			for (p = &ab.ac_comm[0];
			    p < &ab.ac_comm[AC_COMM_LEN] && *p; ++p)
				if (!isprint(*p))
					*p = '?';
		if (*argv && !requested(argv, &ab))
			continue;

		(void)printf("%-*.*s %-7s %-*s %-*s",
			     AC_COMM_LEN, AC_COMM_LEN, ab.ac_comm,
			     flagbits(ab.ac_flag),
			     UT_NAMESIZE, user_from_uid(ab.ac_uid, 0),
			     UT_LINESIZE, getdev(ab.ac_tty));
		
		
		/* user + system time */
		if (flags & AC_CTIME) {
			(void)printf(" %6.2f secs", 
				     (expand(ab.ac_utime) + 
				      expand(ab.ac_stime))/AC_HZ);
		}
		
		/* usr time */
		if (flags & AC_UTIME) {
			(void)printf(" %6.2f us", expand(ab.ac_utime)/AC_HZ);
		}
		
		/* system time */
		if (flags & AC_STIME) {
			(void)printf(" %6.2f sy", expand(ab.ac_stime)/AC_HZ);
		}
		
		/* elapsed time */
		if (flags & AC_ETIME) {
			(void)printf(" %8.2f es", expand(ab.ac_etime)/AC_HZ);
		}
		
		/* starting time */
		if (flags & AC_BTIME) {
			(void)printf(" %.16s", ctime(&ab.ac_btime));
		}
		
		/* exit time (starting time + elapsed time )*/
		if (flags & AC_FTIME) {
			t = ab.ac_btime;
			t += (time_t)(expand(ab.ac_etime)/AC_HZ);
			(void)printf(" %.16s", ctime(&t));
		}
		printf("\n");

	} while (size > 0);
	exit(0);
}
示例#9
0
void NodesTool::release(const TupInputDeviceInformation *input, TupBrushManager *brushManager, TupGraphicsScene *scene)
{
    #ifdef K_DEBUG
        #ifdef Q_OS_WIN
            qDebug() << "[NodesTool::release()]";
        #else
            T_FUNCINFOX("tools");
        #endif
    #endif

    Q_UNUSED(brushManager);

    QList<QGraphicsItem *> currentSelection = scene->selectedItems();
    if (!currentSelection.isEmpty()) {
        QGraphicsItem *selectedItem = currentSelection.at(0);
        TupFrame *frame = currentFrame();
        int itemIndex = frame->indexOf(selectedItem);

        if (qgraphicsitem_cast<TupSvgItem *>(selectedItem)) {
            TOsd::self()->display(tr("Error"), tr("SVG objects cannot be edited!"), TOsd::Error);
            return;
        }

        if (TupGraphicLibraryItem *libraryItem = qgraphicsitem_cast<TupGraphicLibraryItem *>(selectedItem)) {
            if (libraryItem->itemType() == TupLibraryObject::Image) {
                TOsd::self()->display(tr("Error"), tr("Images have no nodes!"), TOsd::Error);
                return;
            }
        }

        if (qgraphicsitem_cast<TupItemGroup *>(selectedItem)) {
            if (k->activeSelection)
                k->nodeGroup->clear();
            QPointF coord = input->pos();

            if (itemIndex >= 0) {
                TupProjectRequest event = TupRequestBuilder::createItemRequest(
                                          scene->currentSceneIndex(),
                                          k->currentLayer, k->currentFrame,
                                          itemIndex, coord,
                                          scene->spaceContext(), TupLibraryObject::Item,
                                          TupProjectRequest::Ungroup);
                emit requested(&event);
            }
            return;
        }

        if (!qgraphicsitem_cast<TControlNode*>(selectedItem)) {
            if (!qgraphicsitem_cast<TupPathItem *>(selectedItem)) {
                TOsd::self()->display(tr("Error"), tr("Only pencil/ink lines can be edited!"), TOsd::Error);
                return;
            }
        }

        if (itemIndex == -1) {
            if (qgraphicsitem_cast<TControlNode*>(selectedItem)) {
                QGraphicsItem *item = k->nodeGroup->parentItem();
                int position = frame->indexOf(item);
                if (position >= 0) {
                    // if (qgraphicsitem_cast<QGraphicsPathItem *>(item)) {
                        QString path = qgraphicsitem_cast<TupPathItem *>(item)->pathToString();
                        TupProjectRequest event = TupRequestBuilder::createItemRequest(scene->currentSceneIndex(),
                                                  k->currentLayer, k->currentFrame, position,
                                                  QPointF(), scene->spaceContext(), TupLibraryObject::Item,
                                                  TupProjectRequest::EditNodes, path);
                        emit requested(&event);
                        k->nodeGroup->clearChangedNodes();
                    // }
                } else {
                    #ifdef K_DEBUG
                        QString msg = "NodesTool::release() - Fatal Error: Invalid position [ " + QString::number(position) + " ]";
                        #ifdef Q_OS_WIN
                            qDebug() << msg;
                        #else
                            tError() << msg;
                        #endif
                    #endif
                }
            } else {
                #ifdef K_DEBUG
                    QString msg = "NodesTool::release() - Invalid selected item index: " + QString::number(itemIndex);
                    #ifdef Q_OS_WIN
                       qDebug() << msg;
                    #else
                       tWarning() << msg;
                    #endif
                #endif
            }

            return;
        }

        // Avoiding to select the same item twice 
        if (k->activeSelection) { 
            TupFrame *frame = currentFrame();
            int oldIndex = frame->indexOf(k->nodeGroup->parentItem());
            if (oldIndex != itemIndex) {
                k->nodeGroup->clear();
                k->nodeGroup = new TNodeGroup(selectedItem, scene, TNodeGroup::LineSelection, k->baseZValue);
                k->nodeGroup->show();
                k->nodeGroup->resizeNodes(k->realFactor);
                if (TupPathItem *path = qgraphicsitem_cast<TupPathItem *>(selectedItem)) {
                    if (path->isNotEdited()) 
                        path->saveOriginalPath();
                }
            } else {
                if (k->nodeGroup->hasChangedNodes()) {
                    QGraphicsItem *item = k->nodeGroup->parentItem();
                    int position = frame->indexOf(item);
                    if (position >= 0) {
                        QString path = qgraphicsitem_cast<TupPathItem *>(item)->pathToString();
                        TupProjectRequest event = TupRequestBuilder::createItemRequest(scene->currentSceneIndex(),
                                                  k->currentLayer, k->currentFrame, position,
                                                  QPointF(), scene->spaceContext(), TupLibraryObject::Item,
                                                  TupProjectRequest::EditNodes, path);
                        emit requested(&event);
                        k->nodeGroup->clearChangedNodes();
                    } else {
                        #ifdef K_DEBUG
                            QString msg = "NodesTool::release() - Fatal Error: Invalid position [ " + QString::number(position) + " ]";
                            #ifdef Q_OS_WIN
                                qDebug() << msg;
                            #else
                                tError() << msg;
                            #endif
                        #endif
                    }
                } else {
                    #ifdef K_DEBUG
                        QString msg = "NodesTool::release() - Node group has NO changes!";
                        #ifdef Q_OS_WIN
                            qDebug() << msg;
                        #else
                            tWarning() << msg;
                        #endif
                    #endif
                }
            }
        } else {
            k->nodeGroup = new TNodeGroup(selectedItem, scene, TNodeGroup::LineSelection, k->baseZValue);
            k->nodeGroup->show();
            k->activeSelection = true;

            k->nodeGroup->resizeNodes(k->realFactor);
            if (TupPathItem *path = qgraphicsitem_cast<TupPathItem *>(selectedItem)) {
                if (path->isNotEdited())
                    path->saveOriginalPath();
            }
        }
    } else {
        if (k->activeSelection) {
            #ifdef K_DEBUG
                QString msg = "NodesTool::release() - Empty selection! Removing nodes...";
                #ifdef Q_OS_WIN
                    qDebug() << msg;
                #else
                    tWarning() << msg;
                #endif
            #endif
            k->nodeGroup->clear();
            k->nodeGroup = 0;
            k->activeSelection = false;
        }
    } 
}