Exemple #1
0
/*
 * Use blkid to extract UUID and label from device, since it handles many
 * obscure edge cases around partition types and formats. Always broadcasts
 * updated metadata values.
 */
int Volume::extractMetadata(const char* devicePath) {
    int res = 0;

#ifdef MTK_EMULATOR_SUPPORT
        ALOGI("For emulator, give the fake uuid and label");
        setUuid("1234-ABCD");
        setUserLabel("NO NAME");
#else
        std::string cmd;
        cmd = BLKID_PATH;
        cmd += " -c /dev/null ";
        cmd += devicePath;

        FILE* fp = popen(cmd.c_str(), "r");
        if (!fp) {
            ALOGE("Failed to run %s: %s", cmd.c_str(), strerror(errno));
            res = -1;
            goto done;
        }

        char line[1024];
        char value[128];
        if (fgets(line, sizeof(line), fp) != NULL) {
            ALOGD("blkid identified as %s", line);

            char* start = strstr(line, "UUID=");
            if (start != NULL && sscanf(start + 5, "\"%127[^\"]\"", value) == 1) {
                setUuid(value);
            } else {
                setUuid(NULL);
            }

            start = strstr(line, "LABEL=");
            if (start != NULL && sscanf(start + 6, "\"%127[^\"]\"", value) == 1) {
                setUserLabel(value);
            } else {
                setUserLabel(NULL);
            }
        } else {
            ALOGW("blkid failed to identify %s", devicePath);
            res = -1;
        }

        pclose(fp);

    done:
        if (res == -1) {
            setUuid(NULL);
            setUserLabel(NULL);
        }
#endif
    return res;
}
UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent) :
    QGraphicsTextItem(parent)
    , UBGraphicsItem()
    , mMultiClickState(0)
    , mLastMousePressTime(QTime::currentTime())
{
    setDelegate(new UBGraphicsTextItemDelegate(this, 0));

    // TODO claudio remove this because in contrast with the fact the frame should be created on demand.
    Delegate()->createControls();
    Delegate()->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing);
    Delegate()->setUBFlag(GF_FLIPPABLE_ALL_AXIS, false);
    Delegate()->setUBFlag(GF_REVOLVABLE, true);

    mTypeTextHereLabel = tr("<Type Text Here>");

    setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object);
    setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly


    setFlag(QGraphicsItem::ItemIsSelectable, true);
    setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);

    setTextInteractionFlags(Qt::TextEditorInteraction);

    setUuid(QUuid::createUuid());

    connect(document(), SIGNAL(contentsChanged()), Delegate(), SLOT(contentsChanged()));
    connect(document(), SIGNAL(undoCommandAdded()), this, SLOT(undoCommandAdded()));

    connect(document()->documentLayout(), SIGNAL(documentSizeChanged(const QSizeF &)),
            this, SLOT(documentSizeChanged(const QSizeF &)));

}
void UBDocumentProxy::init()
{
    setMetaData(UBSettings::documentGroupName, "");

    QDateTime now = QDateTime::currentDateTime();
    setMetaData(UBSettings::documentName, now.toString(Qt::SystemLocaleShortDate));

    setUuid(QUuid::createUuid());

    //qDebug() << UBSettings::settings()->pageSize->get().toSize();
    setDefaultDocumentSize(UBSettings::settings()->pageSize->get().toSize());

    //teacherGuide metadata
    setMetaData(UBSettings::sessionTitle,"");
    setMetaData(UBSettings::sessionAuthors,"");
    setMetaData(UBSettings::sessionObjectives,"");
    setMetaData(UBSettings::sessionKeywords,"");
    setMetaData(UBSettings::sessionGradeLevel,"");
    setMetaData(UBSettings::sessionSubjects,"");
    setMetaData(UBSettings::sessionType,"");
    setMetaData(UBSettings::sessionLicence,"");
    // Issue 1684 - ALTI/AOU - 20131210
    setMetaData(UBSettings::documentDefaultBackgroundImage,"");
    setMetaData(UBSettings::documentDefaultBackgroundImageDisposition, "");
    // Fin Issue 1684 - ALTI/AOU - 20131210
}
void TestKeePass2Format::initTestCase()
{
    QVERIFY(Crypto::init());

    // read raw XML database
    bool hasError;
    QString errorString;
    m_xmlDb = readXml(QString(KEEPASSX_TEST_DATA_DIR).append("/NewDatabase.xml"), true, hasError, errorString);
    if (hasError) {
        QFAIL(qPrintable(QString("Error while reading XML: ").append(errorString)));
    }
    QVERIFY(m_xmlDb.data());

    // construct and write KDBX to buffer
    auto key = QSharedPointer<CompositeKey>::create();
    key->addKey(QSharedPointer<PasswordKey>::create("test"));

    m_kdbxSourceDb = QSharedPointer<Database>::create();
    m_kdbxSourceDb->setKey(key);
    m_kdbxSourceDb->metadata()->setName("TESTDB");
    Group* group = m_kdbxSourceDb->rootGroup();
    group->setUuid(QUuid::createUuid());
    group->setNotes("I'm a note!");
    auto entry = new Entry();
    entry->setPassword(QString::fromUtf8("\xc3\xa4\xa3\xb6\xc3\xbc\xe9\x9b\xbb\xe7\xb4\x85"));
    entry->setUuid(QUuid::createUuid());
    entry->attributes()->set("test", "protectedTest", true);
    QVERIFY(entry->attributes()->isProtected("test"));
    entry->attachments()->set("myattach.txt", QByteArray("this is an attachment"));
    entry->attachments()->set("aaa.txt", QByteArray("also an attachment"));
    entry->setGroup(group);
    auto groupNew = new Group();
    groupNew->setUuid(QUuid::createUuid());
    groupNew->setName("TESTGROUP");
    groupNew->setNotes("I'm a sub group note!");
    groupNew->setParent(group);

    m_kdbxTargetBuffer.open(QBuffer::ReadWrite);
    writeKdbx(&m_kdbxTargetBuffer, m_kdbxSourceDb.data(), hasError, errorString);
    if (hasError) {
        QFAIL(qPrintable(QString("Error while writing database: ").append(errorString)));
    }

    // call sub class init method
    initTestCaseImpl();
}
Exemple #5
0
/**
 * @author Rafal 'Vogel' Malinowski
 * @short Loads object from storage.
 *
 * Loads obejct from storage. Loads only uuid from uuid attribute. Superclass method
 * is not called (storage status remaining unchanged - access to each other property will
 * fire load method). You must call this method in loadStub methods of derivered class.
 */
void Shared::loadStub()
{
	if (!isValidStorage())
		return;

	setUuid(QUuid(loadAttribute<QString>("uuid")));
	setState(StateNotLoaded);
}
Exemple #6
0
/**
 * @author Rafal 'Vogel' Malinowski
 * @short Loads object from storage.
 *
 * Loads the object from storage. Loads uuid from uuid attribute. Superclass method
 * is also called. You must call this method in load methods of derivered class.
 *
 * When reimplementing this method, avoid calling any methods or emitting signals.
 * It could lead to big trouble as the object is in an unstable state where State
 * is set to StateLoaded while actually it may be not fully loaded yet.
 */
void Shared::load()
{
	if (!isValidStorage())
		return;

	UuidStorableObject::load();
	setUuid(QUuid(loadAttribute<QString>("uuid")));
}
 /**
  * Creates completely new ConnectionSettings by cloning this record.
  */
 ConnectionSettings *ConnectionSettings::clone() const
 {
     auto settings = new ConnectionSettings(true);
     settings->setUniqueId(_uniqueId);
     settings->setUuid(_uuid);
     settings->apply(this);
     return settings;
 }
Exemple #8
0
QUuid Controller::ensureHasUuid(Mlt::Properties& properties) const
{
    if (properties.get(kUuidProperty)) {
        return uuid(properties);
    } else {
        QUuid newUid = QUuid::createUuid();
        setUuid(properties, newUid);
        return newUid;
    }
}
Exemple #9
0
void PlaylistWindow::addNewTab(QUuid playlist, QString title)
{
    auto qdp = new QDrawnPlaylist();
    qdp->setDisplayParser(&displayParser);
    qdp->setUuid(playlist);
    connect(qdp, &QDrawnPlaylist::itemDesired, this, &PlaylistWindow::itemDesired);
    widgets.insert(playlist, qdp);
    ui->tabWidget->addTab(qdp, title);
    ui->tabWidget->setCurrentWidget(qdp);
}
Exemple #10
0
Store::Store(atable_ptr_t main_table) :
    _delta_size(0),
    _main_table(main_table),
    delta(main_table->copy_structure(create_concurrent_dict, create_concurrent_storage)),
    merger(createDefaultMerger()),
    _cidBeginVector(main_table->size(), 0),
    _cidEndVector(main_table->size(), tx::INF_CID),
    _tidVector(main_table->size(), tx::UNKNOWN) {
  setUuid();
}
Exemple #11
0
bool CGraphicsBank::deserialize(QDomDocument& /*doc*/, QDomNode& node, QString& errors)
{
   QDomElement element = node.toElement();

   if (element.isNull())
   {
      return false;
   }

   if (!element.hasAttribute("name"))
   {
      errors.append("Missing required attribute 'name' of element <source name='?'>\n");
      return false;
   }

   if (!element.hasAttribute("uuid"))
   {
      errors.append("Missing required attribute 'uuid' of element <source name='"+element.attribute("name")+"'>\n");
      return false;
   }

   m_name = element.attribute("name");

   setUuid(element.attribute("uuid"));

   m_bankItems.clear();

   QDomNode childNode = node.firstChild();

   if (!childNode.isNull())
   {
      do
      {
         if (childNode.nodeName() == "graphicitem")
         {
            QDomElement graphicItem = childNode.toElement();

            IProjectTreeViewItem* projectItem = findProjectItem(graphicItem.attribute("uuid"));
            IChrRomBankItem* pItem = dynamic_cast<IChrRomBankItem*>(projectItem);

            if ( pItem )
            {
               m_bankItems.append(pItem);
            }

         }
         else
         {
            return false;
         }
      } while (!(childNode = childNode.nextSibling()).isNull());
   }

   return true;
}
bool CUndoObjectInterface::setUuid(const std::string & uuid)
{
  xg::Guid UUID(uuid);

  if (!UUID.isValid())
    {
      return false;
    }

  return setUuid(UUID);
}
UBGraphicsStrokesGroup::UBGraphicsStrokesGroup(QGraphicsItem *parent):QGraphicsItemGroup(parent)
{
    mDelegate = new UBGraphicsItemDelegate(this, 0, true, true);
    mDelegate->init();
    mDelegate->setFlippable(true);
    setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object);

    setUuid(QUuid::createUuid());
    setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly
    setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
    setFlag(QGraphicsItem::ItemIsSelectable, true);
    setFlag(QGraphicsItem::ItemIsMovable, true);
}
ContextPacket::ContextPacket(IpAddress *ipAddress) :

		sg_request(0),
		sg_profile(0),
		service(SERVICE_DEFAULT),
		version(VERSION),
		channel(CHANNEL_META),
		additionalHeaderType(0),
		additionalHeaderSize(0),
		contextType(CONTEXT_TYPE_DEFAULT),
		additionalBricksSize(4),
		dataType(DATA_TYPE_DEFAULT),
		additionalDataSize(8) {

	if (DEBUG) std::cout << __FILE__ << "(" << __LINE__ << ")"  << "[" << __FUNCTION__<< "]  Constructor(IpAddress: "
			<< inet_ntoa(ipAddress->getSockAddress().sin_addr) << ":" << ntohs(ipAddress->getSockAddress().sin_port) << ")" << std::endl;

	setUuid(ipAddress->getAddressId());

//	memset(&timestamp, 0, 8);
//	timestamp = time(NULL);

	this->sockAddress = ipAddress->getSockAddress();

	// additionalHeaderData
	memset(&additionalHeaderData, 0, additionalHeaderSize);
	for (int i =0; i<additionalHeaderSize; i++) {
		additionalHeaderData[i] = '#';
	}

	// firstBrick
	firstBrick = new ContextBrick(1, 2);


	// additionalBricks
	memset(&additionalBricks, 0, additionalBricksSize);
	for (int i =0; i<additionalBricksSize; i++) {
		additionalBricks[i] = (*new ContextBrick('#', '+'));
	}

	// data
	memset(&data, '*', 140);

	// additionalData
	memset(&additionalData, 0, DATA_ADDITIONAL_SIZE);
	for (int i =0; i<additionalDataSize; i++) {
		additionalData[i] = 'x';
	}
}
UBGraphicsPixmapItem::UBGraphicsPixmapItem(QGraphicsItem* parent)
    : QGraphicsPixmapItem(parent)
{
    setDelegate(new UBGraphicsItemDelegate(this, 0, true, false, true, true));
    Delegate()->init();
    Delegate()->setFlippable(true);
    Delegate()->setRotatable(true);

    setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object);
    setTransformationMode(Qt::SmoothTransformation);

    setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly
    setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);

    setUuid(QUuid::createUuid()); //more logical solution is in creating uuid for element in element's constructor
}
ContextPacket::ContextPacket(IpAddress *ipAddress) :

		request(0),
		profile(0),
		version(VERSION),
		channel(CHANNEL_RZV),
		headerType(0),
		headerSize(0),
		ciType(CI_TYPE_RZV),
		ciSize(4),
		appDataType(APP_TYPE_RZV),
		appDataSize(8) {

	if (DEBUG) std::cout << __FILE__ << "(" << __LINE__ << ")"  << "[" << __FUNCTION__<< "]  Constructor(IpAddress: "
			<< inet_ntoa(ipAddress->getSockAddress().sin_addr) << ":" << ntohs(ipAddress->getSockAddress().sin_port) << ")" << std::endl;

	// UUID
	setUuid();

	// IP address and port
	sockAddress = ipAddress->getSockAddress();

	// Current timestamp
	setTime();

	// headerData
	memset(&headerData, 0, headerSize);
	for (int i =0; i<headerSize; i++) {
		headerData[i] = '\0';
	}

	// root-CIC
	rootCIC = new ContextBrick(0, 0);


	// additional CIC-Bricks
	memset(&ciCICBricks, 0, ciSize);
	for (int i =0; i<ciSize; i++) {
		ciCICBricks[i] = (*new ContextBrick('#', '+'));
	}

	// Application data
	memset(&appData, 0, DATA_ADDITIONAL_SIZE);
	for (int i =0; i<appDataSize; i++) {
		appData[i] = 'x';
	}
}
void UBGraphicsSvgItem::init()
{
    setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object);

    mDelegate = new UBGraphicsItemDelegate(this, 0, true, true, false);
    mDelegate->init();
    mDelegate->setFlippable(true);
    mDelegate->setRotatable(true);

    setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);

    setCacheMode(QGraphicsItem::DeviceCoordinateCache);
    setMaximumCacheSize(boundingRect().size().toSize() * UB_MAX_ZOOM);

    setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly

    setUuid(QUuid::createUuid());
}
void NetworkManager::ConnectionSettings::fromMap(const NMVariantMapMap &map)
{
    QVariantMap connectionSettings = map.value(QLatin1String(NM_SETTING_CONNECTION_SETTING_NAME));

    setId(connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_ID)).toString());
    setUuid(connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_UUID)).toString());
    setConnectionType(typeFromString(connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_TYPE)).toString()));

    if (connectionSettings.contains(QLatin1String(NM_SETTING_CONNECTION_INTERFACE_NAME))) {
        setInterfaceName(connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_INTERFACE_NAME)).toString());
    }
    if (connectionSettings.contains(QLatin1String(NM_SETTING_CONNECTION_PERMISSIONS))) {
        QStringList permissions = connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_PERMISSIONS)).toStringList();
        Q_FOREACH (const QString & permission, permissions) {
            const QStringList split = permission.split(QLatin1String(":"), QString::KeepEmptyParts);
            addToPermissions(split.at(1), split.at(2));
        }
    }
UBGraphicsStrokesGroup::UBGraphicsStrokesGroup(QGraphicsItem *parent)
    :QGraphicsItemGroup(parent), UBGraphicsItem()
{
    setDelegate(new UBGraphicsItemDelegate(this, 0, GF_COMMON
                                           | GF_RESPECT_RATIO
                                           | GF_REVOLVABLE
                                           | GF_FLIPPABLE_ALL_AXIS));

    setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object);

    setUuid(QUuid::createUuid());
    setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly
    setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
    setFlag(QGraphicsItem::ItemIsSelectable, true);
    setFlag(QGraphicsItem::ItemIsMovable, true);

    mDebugText = NULL;
    debugTextEnabled = false; // set to true to get a graphical display of strokes' Z-levels
}
UBGraphicsGroupContainerItem::UBGraphicsGroupContainerItem(QGraphicsItem *parent)
    : QGraphicsItem(parent)
    , mCurrentItem(NULL)
{
    setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object);

   	setDelegate(new UBGraphicsGroupContainerItemDelegate(this, 0));
    Delegate()->init();

    setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
    setFlag(QGraphicsItem::ItemIsSelectable, true);
    setFlag(QGraphicsItem::ItemIsMovable, true);

    UBGraphicsGroupContainerItem::setAcceptHoverEvents(true);

    setUuid(QUuid::createUuid());

    setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly
}
//Got credentials back, store if necessary
void SkynetClient::processReady(char *data, jsmntok_t *tok)
{
	DBGCSN("Skynet Connect");

	char temp[UUIDSIZE];

	status = 1;
	
	getUuid(temp);

    //if uuid has been refreshed, save it
    if (!TOKEN_STRING(data, tok[13], temp ))
    {
      	DBGCSN("uuid refresh");
		strncpy(temp, data + tok[13].start, tok[13].end - tok[13].start);
		
      	DBGCS("new: ");
      	DBGCN(temp);
		
      	setUuid(temp);
    }else
    {
    	DBGCSN("no uuid refresh necessary");
    }

    getToken(temp);
	
    //if token has been refreshed, save it
    if (!TOKEN_STRING(data, tok[15], temp ))
    {
		DBGCSN("token refresh");
	  	strncpy(temp, data + tok[15].start, tok[15].end - tok[15].start);

        DBGCS("new: ");
      	DBGCN(temp);
      
		setToken(temp);
    }else
    {
		DBGCSN("no token refresh necessary");
    }

}
Exemple #22
0
void CoreAccount::fromVariantMap(const QVariantMap &v)
{
    setAccountId((AccountId)v.value("AccountId").toInt());
    setAccountName(v.value("AccountName").toString());
    setUuid(QUuid(v.value("Uuid").toString()));
    setInternal(v.value("Internal").toBool());
    setUser(v.value("User").toString());
    setPassword(v.value("Password").toString());
    setStorePassword(v.value("StorePassword").toBool());
    setHostName(v.value("HostName").toString());
    setPort(v.value("Port").toUInt());
    setUseSsl(v.value("UseSSL").toBool());
    setProxyType((QNetworkProxy::ProxyType)v.value("ProxyType").toInt());
    setProxyUser(v.value("ProxyUser").toString());
    setProxyPassword(v.value("ProxyPassword").toString());
    setProxyHostName(v.value("ProxyHostName").toString());
    setProxyPort(v.value("ProxyPort").toUInt());

    _storePassword = !password().isEmpty();
}
NetworkManager::ConnectionSettings::ConnectionSettings(const NetworkManager::ConnectionSettings::Ptr &other)
    : d_ptr(new ConnectionSettingsPrivate(this))
{
    Q_D(ConnectionSettings);

    setId(other->id());
    setUuid(other->uuid());
    setInterfaceName(other->interfaceName());
    setConnectionType(other->connectionType());
    setPermissions(other->permissions());
    setAutoconnect(other->autoconnect());
    setAutoconnectPriority(other->autoconnectPriority());
    setTimestamp(other->timestamp());
    setReadOnly(other->readOnly());
    setZone(other->zone());
    setMaster(other->master());
    setSlaveType(other->slaveType());
    setGatewayPingTimeout(other->gatewayPingTimeout());
    d->initSettings(other);
}
Exemple #24
0
/**
   @brief Restore a todo list from a QVariant representation
   @sa toVariant()
 */
void TodoList::fromVariant(const QVariant &todolist)
{
  m_loading = true;
  QVariantMap map = todolist.toMap();

  // Special handling for id: Only update if identify changes
  if ( m_uuid != map.value( "uuid", QUuid() ).toUuid() || !m_hasId ) {
    m_hasId = map.contains( "id" );
    if ( m_hasId ) {
      setId( map.value( "id", m_id ).toInt() );
    }
  }

  setAccount( map.value( "accountUuid", m_accountUuid ).toUuid() );
  setMetaAttributes( map.value( "metaAttributes", m_metaAttributes ).toMap() );
  setName( map.value( "name", m_name ).toString() );
  setUuid( map.value( "uuid", m_uuid ).toUuid() );
  setDirty( map.value( "dirty", m_dirty ).toInt() );
  setDisposed( map.value( "disposed", m_disposed ).toBool() );
  m_loading = false;
}
void UBDocumentProxy::init()
{
    setMetaData(UBSettings::documentGroupName, "");

    QDateTime now = QDateTime::currentDateTime();
    setMetaData(UBSettings::documentName, now.toString(Qt::SystemLocaleShortDate));

    setUuid(QUuid::createUuid());

    setDefaultDocumentSize(UBSettings::settings()->pageSize->get().toSize());

    //teacherGuide metadata
    setMetaData(UBSettings::sessionTitle,"");
    setMetaData(UBSettings::sessionAuthors,"");
    setMetaData(UBSettings::sessionObjectives,"");
    setMetaData(UBSettings::sessionKeywords,"");
    setMetaData(UBSettings::sessionGradeLevel,"");
    setMetaData(UBSettings::sessionSubjects,"");
    setMetaData(UBSettings::sessionType,"");
    setMetaData(UBSettings::sessionLicence,"");
}
Exemple #26
0
void Task::fromVariant(const QVariant &task)
{
  m_loading = true;
  QVariantMap map = task.toMap();

  // Special handling ID: Onlz override on identity change
  if ( map.value( "uuid" ).toUuid() != m_uuid || !m_hasId ) {
    if ( map.contains( "id" ) ) {
      setId( map.value( "id" ).toInt() );
    }
  }

  setDone( map.value( "done", m_done ).toBool() );
  setMetaAttributes( map.value( "metaAttributes", m_metaAttributes ).toMap() );
  setTitle( map.value( "title", m_title ).toString() );
  setTodo( map.value( "todoUuid", m_todoUuid ).toUuid() );
  setUuid( map.value( "uuid", m_uuid ).toUuid() );
  setWeight( map.value( "weight", m_weigth ).toDouble() );
  setDirty( map.value( "dirty", m_dirty ).toInt() );
  setDisposed( map.value( "disposed", m_disposed ).toBool() );

  m_loading = false;
}
UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent) :
    QGraphicsTextItem(parent)
    , UBGraphicsItem()
    , mMultiClickState(0)
    , mLastMousePressTime(QTime::currentTime())
{
    setDelegate(new UBGraphicsTextItemDelegate(this, 0));
    Delegate()->init();

    Delegate()->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing);
    Delegate()->setFlippable(false);
    Delegate()->setRotatable(true);

    mTypeTextHereLabel = tr("<Type Text Here>");


    setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object);
//    setData(UBGraphicsItemData::ItemEditable, QVariant(true));
    setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly


    setFlag(QGraphicsItem::ItemIsSelectable, true);
//    setFlag(QGraphicsItem::ItemIsMovable, true);
    setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);

    setTextInteractionFlags(Qt::TextEditorInteraction);

    setUuid(QUuid::createUuid());

    connect(document(), SIGNAL(contentsChanged()), Delegate(), SLOT(contentsChanged()));
    connect(document(), SIGNAL(undoCommandAdded()), this, SLOT(undoCommandAdded()));

    connect(document()->documentLayout(), SIGNAL(documentSizeChanged(const QSizeF &)),
            this, SLOT(documentSizeChanged(const QSizeF &)));

}
void BeetleInternal::init() {
	std::lock_guard<std::recursive_mutex> lg(handlesMutex);
	uint16_t handleAlloc = 1; // 0 is special

	/*
	 * Setup GAP service with name characteristic
	 */
	auto gapServiceHandle = std::make_shared<PrimaryService>();
	gapServiceHandle->setHandle(handleAlloc++);
	auto gapHandleUUID = boost::shared_array<uint8_t>(new uint8_t[2]);
	*(uint16_t *) gapHandleUUID.get() = btohs(GATT_GAP_SERVICE_UUID);
	gapServiceHandle->cache.set(gapHandleUUID, 2);
	handles[gapServiceHandle->getHandle()] = gapServiceHandle;

	auto gapDeviceNameCharHandle = std::make_shared<Characteristic>();
	gapDeviceNameCharHandle->setHandle(handleAlloc++);
	gapDeviceNameCharHandle->setServiceHandle(gapServiceHandle->getHandle());
	auto gapDeviceNameCharHandleValue = boost::shared_array<uint8_t>(new uint8_t[5]);
	gapDeviceNameCharHandleValue[0] = GATT_CHARAC_PROP_READ;
	*(uint16_t *) (gapDeviceNameCharHandleValue.get() + 3) = htobs(GATT_GAP_CHARAC_DEVICE_NAME_UUID);
	gapDeviceNameCharHandle->cache.set(gapDeviceNameCharHandleValue, 5);
	handles[gapDeviceNameCharHandle->getHandle()] = gapDeviceNameCharHandle;

	auto gapDeviceNameAttrHandle = std::make_shared<CharacteristicValue>(true, true);
	gapDeviceNameAttrHandle->setHandle(handleAlloc++);
	gapDeviceNameAttrHandle->setUuid(UUID(GATT_GAP_CHARAC_DEVICE_NAME_UUID));
	gapDeviceNameAttrHandle->setServiceHandle(gapServiceHandle->getHandle());
	gapDeviceNameAttrHandle->setCharHandle(gapDeviceNameCharHandle->getHandle());
	auto gapDeviceNameAttrHandleValue = boost::shared_array<uint8_t>(new uint8_t[name.length()]);
	memcpy(gapDeviceNameAttrHandleValue.get(), name.c_str(), name.length());
	gapDeviceNameAttrHandle->cache.set(gapDeviceNameAttrHandleValue, name.length());
	handles[gapDeviceNameAttrHandle->getHandle()] = gapDeviceNameAttrHandle;

	// fill in attr handle for characteristic
	gapDeviceNameCharHandle->setCharHandle(gapDeviceNameAttrHandle->getHandle());
	*(uint16_t *) (gapDeviceNameCharHandleValue.get() + 1) = htobs(gapDeviceNameAttrHandle->getHandle());

	// end the characteristic
	gapDeviceNameCharHandle->setEndGroupHandle(gapDeviceNameAttrHandle->getHandle());

	// end the service
	gapServiceHandle->setEndGroupHandle(gapDeviceNameAttrHandle->getHandle());

	/*
	 * Setup GATT service with service changed characteristic
	 */
	auto gattServiceHandle = std::make_shared<PrimaryService>();
	gattServiceHandle->setHandle(handleAlloc++);
	auto gattHandleUUID = boost::shared_array<uint8_t>(new uint8_t[2]);
	*(uint16_t *) gattHandleUUID.get() = btohs(GATT_GATT_SERVICE_UUID);
	gattServiceHandle->cache.set(gattHandleUUID, 2);
	handles[gattServiceHandle->getHandle()] = gattServiceHandle;

	auto gattServiceChangedCharHandle = std::make_shared<Characteristic>();
	gattServiceChangedCharHandle->setHandle(handleAlloc++);
	gattServiceChangedCharHandle->setServiceHandle(gattServiceHandle->getHandle());
	auto gattServiceChangedCharHandleValue = boost::shared_array<uint8_t>(new uint8_t[5]);
	gattServiceChangedCharHandleValue[0] = GATT_CHARAC_PROP_NOTIFY;
	*(uint16_t *) (gattServiceChangedCharHandleValue.get() + 3) = htobs(GATT_GATT_CHARAC_SERVICE_CHANGED_UUID);
	gattServiceChangedCharHandle->cache.set(gattServiceChangedCharHandleValue, 5);
	handles[gattServiceChangedCharHandle->getHandle()] = gattServiceChangedCharHandle;

	auto gattServiceChangedAttrHandle = std::make_shared<CharacteristicValue>(false, false);
	gattServiceChangedAttrHandle->setHandle(handleAlloc++);
	gattServiceChangedAttrHandle->setUuid(UUID(GATT_GATT_CHARAC_SERVICE_CHANGED_UUID));
	gattServiceChangedAttrHandle->setServiceHandle(gattServiceHandle->getHandle());
	gattServiceChangedAttrHandle->setCharHandle(gattServiceChangedCharHandle->getHandle());
	gattServiceChangedAttrHandle->cache.clear();
	handles[gattServiceChangedAttrHandle->getHandle()] = gattServiceChangedAttrHandle;

	// fill in attr handle for characteristic
	gattServiceChangedCharHandle->setCharHandle(gattServiceChangedAttrHandle->getHandle());
	*(uint16_t *) (gattServiceChangedCharHandleValue.get() + 1) = htobs(gattServiceChangedAttrHandle->getHandle());

	auto gattServiceChangedCfgHandle = std::make_shared<ClientCharCfg>();
	gattServiceChangedCfgHandle->setHandle(handleAlloc++);
	gattServiceChangedCfgHandle->setServiceHandle(gattServiceHandle->getHandle());
	gattServiceChangedCfgHandle->setCharHandle(gattServiceChangedCharHandle->getHandle());
	gattServiceChangedCfgHandle->cache.clear();
	handles[gattServiceChangedCfgHandle->getHandle()] = gattServiceChangedCfgHandle;

	// end the characteristic
	gattServiceChangedCharHandle->setEndGroupHandle(gattServiceChangedCfgHandle->getHandle());
	// end the service
	gattServiceHandle->setEndGroupHandle(gattServiceChangedCfgHandle->getHandle());

	// save the service changed attr handle
	serviceChangedAttr = gattServiceChangedAttrHandle;
}
Exemple #29
0
Store::Store() :
  merger(createDefaultMerger()) {
  setUuid();
}
Exemple #30
0
void QShaderGraphLoader::load()
{
    if (m_status == Error)
        return;

    auto error = QJsonParseError();
    const auto document = QJsonDocument::fromJson(m_device->readAll(), &error);

    if (error.error != QJsonParseError::NoError) {
        qWarning() << "Invalid JSON document:" << error.errorString();
        m_status = Error;
        return;
    }

    if (document.isEmpty() || !document.isObject()) {
        qWarning() << "Invalid JSON document, root should be an object";
        m_status = Error;
        return;
    }

    const auto root = document.object();

    const auto nodesValue = root.value(QStringLiteral("nodes"));
    if (!nodesValue.isArray()) {
        qWarning() << "Invalid nodes property, should be an array";
        m_status = Error;
        return;
    }

    const auto edgesValue = root.value(QStringLiteral("edges"));
    if (!edgesValue.isArray()) {
        qWarning() << "Invalid edges property, should be an array";
        m_status = Error;
        return;
    }

    bool hasError = false;

    const auto nodes = nodesValue.toArray();
    for (const auto &nodeValue : nodes) {
        if (!nodeValue.isObject()) {
            qWarning() << "Invalid node found";
            hasError = true;
            continue;
        }

        const auto nodeObject = nodeValue.toObject();

        const auto uuidString = nodeObject.value(QStringLiteral("uuid")).toString();
        const auto uuid = QUuid(uuidString);
        if (uuid.isNull()) {
            qWarning() << "Invalid UUID found in node:" << uuidString;
            hasError = true;
            continue;
        }

        const auto type = nodeObject.value(QStringLiteral("type")).toString();
        if (!m_prototypes.contains(type)) {
            qWarning() << "Unsupported node type found:" << type;
            hasError = true;
            continue;
        }

        const auto layersArray = nodeObject.value(QStringLiteral("layers")).toArray();
        auto layers = QStringList();
        for (const auto &layerValue : layersArray) {
            layers.append(layerValue.toString());
        }

        auto node = m_prototypes.value(type);
        node.setUuid(uuid);
        node.setLayers(layers);

        const auto parametersValue = nodeObject.value(QStringLiteral("parameters"));
        if (parametersValue.isObject()) {
            const auto parametersObject = parametersValue.toObject();
            for (const auto &parameterName : parametersObject.keys()) {
                const auto parameterValue = parametersObject.value(parameterName);
                if (parameterValue.isObject()) {
                    const auto parameterObject = parameterValue.toObject();
                    const auto type = parameterObject.value(QStringLiteral("type")).toString();
                    const auto typeId = QMetaType::type(type.toUtf8());

                    const auto value = parameterObject.value(QStringLiteral("value")).toString();
                    auto variant = QVariant(value);

                    if (QMetaType::typeFlags(typeId) & QMetaType::IsEnumeration) {
                        const auto metaObject = QMetaType::metaObjectForType(typeId);
                        const auto className = metaObject->className();
                        const auto enumName = type.mid(static_cast<int>(qstrlen(className)) + 2).toUtf8();
                        const auto metaEnum = metaObject->enumerator(metaObject->indexOfEnumerator(enumName));
                        const auto enumValue = metaEnum.keyToValue(value.toUtf8());
                        variant = QVariant(enumValue);
                        variant.convert(typeId);
                    } else {
                        variant.convert(typeId);
                    }
                    node.setParameter(parameterName, variant);
                } else {
                    node.setParameter(parameterName, parameterValue.toVariant());
                }
            }
        }

        m_graph.addNode(node);
    }

    const auto edges = edgesValue.toArray();
    for (const auto &edgeValue : edges) {
        if (!edgeValue.isObject()) {
            qWarning() << "Invalid edge found";
            hasError = true;
            continue;
        }

        const auto edgeObject = edgeValue.toObject();

        const auto sourceUuidString = edgeObject.value(QStringLiteral("sourceUuid")).toString();
        const auto sourceUuid = QUuid(sourceUuidString);
        if (sourceUuid.isNull()) {
            qWarning() << "Invalid source UUID found in edge:" << sourceUuidString;
            hasError = true;
            continue;
        }

        const auto sourcePort = edgeObject.value(QStringLiteral("sourcePort")).toString();

        const auto targetUuidString = edgeObject.value(QStringLiteral("targetUuid")).toString();
        const auto targetUuid = QUuid(targetUuidString);
        if (targetUuid.isNull()) {
            qWarning() << "Invalid target UUID found in edge:" << targetUuidString;
            hasError = true;
            continue;
        }

        const auto targetPort = edgeObject.value(QStringLiteral("targetPort")).toString();

        const auto layersArray = edgeObject.value(QStringLiteral("layers")).toArray();
        auto layers = QStringList();
        for (const auto &layerValue : layersArray) {
            layers.append(layerValue.toString());
        }

        auto edge = QShaderGraph::Edge();
        edge.sourceNodeUuid = sourceUuid;
        edge.sourcePortName = sourcePort;
        edge.targetNodeUuid = targetUuid;
        edge.targetPortName = targetPort;
        edge.layers = layers;
        m_graph.addEdge(edge);
    }

    if (hasError) {
        m_status = Error;
        m_graph = QShaderGraph();
    } else {
        m_status = Ready;
    }
}