void RecipeActionsHandler::mergeSimilar()
{
	QList<Q3ListViewItem> items = parentListView->selectedItems();
	if ( items.count() > 1 )
		KMessageBox::sorry( kapp->mainWidget(), i18nc("@info", "Please select only one category."), QString() );
	else if ( items.count() == 1 && items.at(0)->rtti() == 1001 ) {
		CategoryListItem * cat_it = ( CategoryListItem* ) items.at(0);
		QString name = cat_it->categoryName();
		const double max_allowed_distance = 0.60;
		const int length = name.length();
		ElementList categories;
		database->loadCategories( &categories );

		ElementList matches;
		for ( ElementList::const_iterator it = categories.begin(); it != categories.end(); ++it ) {
			#if 0
			if ( levenshtein_distance(name.toLatin1(),(*it).name.toLatin1())/double(qMax(length,(*it).name.length())) >= max_allowed_distance ) {
			#else
			if ( compareStrings(name,(*it).name) >= max_allowed_distance ) {
			#endif
				kDebug()<<(*it).name<<" matches";
				if ( cat_it->categoryId() != (*it).id )
					matches.append(*it);
			}
		}


		for ( ElementList::const_iterator it = categories.begin(); it != categories.end(); ++it ) {
			database->mergeCategories(cat_it->categoryId(),(*it).id);
		}

	}
	else //either nothing was selected or a recipe was selected
Exemple #2
0
DigitalItem::DigitalItem(const std::string& objectID, const std::string& parentID, bool restricted, const ElementList& vars)
    : m_type(Type_unknown)
    , m_subType(SubType_unknown)
    , m_restricted(restricted)
    , m_objectID(objectID)
    , m_parentID(parentID)
    , m_vars(vars)
{
    ElementList::const_iterator it;
    if ((it = vars.FindKey(DIDL_QNAME_UPNP "class")) != vars.end())
    {
        std::vector<std::string> tokens;
        __tokenize((*it)->c_str(), ".", tokens);
        if (tokens.size() >= 2 && tokens[0] == "object")
        {
            if (tokens[1] == TypeTable[Type_container])
                m_type = Type_container;
            else
                m_type = Type_item;
            if (tokens.size() >= 3)
            {
                for (unsigned i = 0; i < SubType_unknown; ++i)
                {
                    if (tokens[2] != SubTypeTable[i])
                        continue;
                    m_subType = (SubType_t)i;
                    break;
                }
            }
        }
    }
}
		virtual void SetValue( const String &value )
		{
			// search for <color> children, find the one with matching value
			// and "select" it
			ElementList colors;
			ElementList::iterator it;
			GetElementsByTagName( colors, "color" );
			for( it = colors.begin(); it != colors.end(); ++it )
			{
				ColorBlock *cb = dynamic_cast<ColorBlock*>( *it );
				if( cb && cb->getColor() == value )
				{
					selectColorBlock( cb );
					break;
				}
			}
			// FIXME: do i need to release the elements?

			// TODO: if no block with matching color was found, find the
			// custom colorblock and set its color to value and select it.
			if( it == colors.end() )
			{
				// DEBUG
				//Com_Printf( "ColorSelector searching for custom\n" );
				for( it = colors.begin(); it != colors.end(); ++it )
				{
					ColorBlock *cb = dynamic_cast<ColorBlock*>( *it );
					if( cb && cb->isCustom() )
					{
						cb->setColor( value );
						selectColorBlock( cb );
						// DEBUG
						//Com_Printf( "ColorSelector FOUND custom\n" );
						break;
					}
				}
				// FIXME: what if we still have no block selected?
				if( it == colors.end() )
				{
					// DEBUG
					//Com_Printf( "ColorSelector DIDNT FIND custom\n" );
				}
			}

			// this calls out onchange event i guess
			SetAttribute("value", value);
		}
		// Own methods
		void selectColorBlock( ColorBlock *element )
		{
			ElementList colors;
			GetElementsByTagName( colors, "color" );
			for( ElementList::iterator it = colors.begin(); it != colors.end(); ++it )
				(*it)->SetPseudoClass( "selected", ( /* *it == element ? true : */ false ) );

			// FIXME: do i need to release the elements?

			element->SetPseudoClass( "selected", true );
		}
		~ColorSelector()
		{
			// for 'color' children, unset parent
			ElementList colors;
			GetElementsByTagName( colors, "color" );
			for( ElementList::iterator it = colors.begin(); it != colors.end(); ++it )
			{
				ColorBlock *cb = dynamic_cast<ColorBlock*>( *it );
				if( cb )
					cb->setSelector( 0 );
			}
			// FIXME: do i need to release the elements?
		}
Exemple #6
0
bool RenderingControl::GetMute(uint8_t* value, const char* channel)
{
  ElementList args;
  args.push_back(ElementPtr(new Element("InstanceID", "0")));
  args.push_back(ElementPtr(new Element("Channel", channel)));
  ElementList vars = Request("GetMute", args);
  if (!vars.empty() && vars[0]->compare("GetMuteResponse") == 0)
  {
    ElementList::const_iterator it = vars.FindKey("CurrentMute");
    if (it != vars.end())
      return (string_to_uint8((*it)->c_str(), value) == 0);
  }
  return false;
}
		// FormControl methods
		virtual String GetValue( void ) const
		{
			// search for <color> children, find the "selected" one
			// and return its value
			ElementList colors;
			const_cast<ColorSelector*>( this )->GetElementsByTagName( colors, "color" );
			for( ElementList::const_iterator it = colors.begin(); it != colors.end(); ++it )
			{
				ColorBlock *cb = dynamic_cast<ColorBlock*>( *it );
				if( cb && cb->IsPseudoClassSet( "selected" ) )
					return cb->getColor();
			}
			// FIXME: do i need to release the elements?

			// FIXME: default value from THE CVAR??
			return "";
		}
Exemple #8
0
void SelectAuthorsDialog::loadAuthors( const ElementList &currentAuthors )
{

	// Load the combo
	reloadAuthorsCombo();

	// Load the ListView with the authors of this recipe
	//authorListModel->clear();
	for ( ElementList::const_iterator author_it = currentAuthors.begin(); author_it != currentAuthors.end(); ++author_it ) {
		QStandardItem *itemId = new QStandardItem;
		itemId->setData( QVariant(author_it->id), Qt::EditRole );
		itemId->setEditable( false ); 
		QStandardItem *itemAuthor = new QStandardItem( author_it->name );
		itemAuthor->setEditable( false );
		QList<QStandardItem*> items;
		items << itemId << itemAuthor;
		authorListModel->appendRow( items );
	}
	
	authorListView->setSortingEnabled( true );
	authorListView->sortByColumn( 1, Qt::AscendingOrder);
}
void Card::loadFromXML(XMLElement *cardData)
{
    // Load card ID, if this card was saved.
    if (std::string(cardData->attributes["id"]) != "") {
        ID = std::string(cardData->attributes["id"]);
    }

    // Build card from xml
    // Title
    XMLElement *titleXML = cardData->getChildByTag("title");
    title = std::string(titleXML->text);
    // Icon
    XMLElement *iconXML = cardData->getChildByTag("icon");
    iconAtlas = AtlasManager::instance()->get(iconXML->attributes["atlas"]);
    iconAtlasKey = std::string(iconXML->attributes["key"]);
    if (iconAtlasKey == "") {
        Log::message("Card", "Missing icon atlas key in \"%s\"",filename.c_str(), Log::WARN);
    }
    // Image
    XMLElement *imageXML = cardData->getChildByTag("image");
    imageAtlas = AtlasManager::instance()->get(imageXML->attributes["atlas"]);
    imageAtlasKey = std::string(imageXML->attributes["key"]);
    if (imageAtlasKey == std::string("")) {
        Log::message("Card", "Missing image atlas key in \"%s\"",filename.c_str(), Log::WARN);
    }
    // Text
    XMLElement *textXML = cardData->getChildByTag("text");
    text = std::string(textXML->text);
    // Tags
    ElementList tagsXML = cardData->getChildByTag("tags")->children;
    for(ElementList::iterator iter = tagsXML.begin(); iter != tagsXML.end(); iter++) {
        // Create a tag (name + attributes) from XML
        XMLElement *tagXML = *iter;
        Tag *tag = new Tag(tagXML->name);
        if (tagXML->hasText) {
            tag->setText(tagXML->text);
        }
        for(AttributeMap::iterator iter = tagXML->attributes.begin(); iter != tagXML->attributes.end(); iter++) {
            tag->set(iter->first, iter->second);
        }

        tags.push_back(tag);
    }

    // Load list of attached cards, if present
    XMLElement *attachedXML = cardData->getChildByTag("attached");
    if (attachedXML != NULL) {
        for(ElementList::iterator iter = attachedXML->children.begin(); iter != attachedXML->children.end(); iter++) {
            XMLElement *attachment = *iter;
            attachedIDs.push_back(std::string(attachment->attributes["id"]));
        }
    }

    // Load list of linked cards, if present
    XMLElement *linksXML = cardData->getChildByTag("links");
    if (linksXML != NULL) {
        for(ElementList::iterator iter = linksXML->children.begin(); iter != linksXML->children.end(); iter++) {
            XMLElement *link = *iter;
            linksIDs.push_back(std::string(link->attributes["id"]));
        }
    }

    // Filter out redundant links -- ensure that we can only have one link to a given card.
    linksIDs.sort();
    linksIDs.unique();

    // Load owner ID, if present
    ownerID = -1;
    XMLElement *ownerXML = cardData->getChildByTag("owner");
    if (ownerXML != NULL) {
        std::string ownerString(ownerXML->attributes["index"]);
        ownerID = atoi(ownerString.c_str());
    }

    parent = NULL;
    isFromFile = true;

    owner = NULL;

    scriptHost = new ScriptHost();
    scriptHost->setEnvironment(filename);
}
Exemple #10
0
bool ContentBrowser::BrowseContent(unsigned startingIndex, unsigned count, Table::iterator position)
{
  DBG(DBG_PROTO, "%s: browse %u from %u\n", __FUNCTION__, count, startingIndex);
  ElementList vars;
  ElementList::const_iterator it;
  if (m_service.Browse(m_root, startingIndex, count, vars) && (it = vars.FindKey("Result")) != vars.end())
  {
    uint32_t updateID = 0;
    if (string_to_uint32(vars.GetValue("UpdateID").c_str(), &updateID) == 0)
      m_lastUpdateID = updateID; // set update ID for this chunk of data
    uint32_t totalcount = 0;
    if (string_to_uint32(vars.GetValue("TotalMatches").c_str(), &totalcount) == 0)
      m_totalCount = totalcount; // reset total count
    uint32_t count = 0;
    string_to_uint32(vars.GetValue("NumberReturned").c_str(), &count);
    DIDLParser didl((*it)->c_str(), count);
    if (didl.IsValid())
    {
      m_table.insert(position, didl.GetItems().begin(), didl.GetItems().end());
      DBG(DBG_PROTO, "%s: count %u\n", __FUNCTION__, didl.GetItems().size());
      return true;
    }
  }
  return false;
}
Result_t
ASDCP::TimedText::DCSubtitleParser::h__SubtitleParser::OpenRead()
{
  if ( ! m_Root.ParseString(m_XMLDoc.c_str()) )
    return RESULT_FORMAT;

  m_TDesc.EncodingName = "UTF-8"; // the XML parser demands UTF-8
  m_TDesc.ResourceList.clear();
  m_TDesc.ContainerDuration = 0;
  const XMLNamespace* ns = m_Root.Namespace();

  if ( ns == 0 )
    {
      DefaultLogSink(). Warn("Document has no namespace name, assuming %s\n", c_dcst_namespace_name);
      m_TDesc.NamespaceName = c_dcst_namespace_name;
    }
  else
    {
      m_TDesc.NamespaceName = ns->Name();
    }

  UUID DocID;
  if ( ! get_UUID_from_child_element("Id", &m_Root, DocID) )
    {
      DefaultLogSink(). Error("Id element missing from input document\n");
      return RESULT_FORMAT;
    }

  memcpy(m_TDesc.AssetID, DocID.Value(), DocID.Size());
  XMLElement* EditRate = m_Root.GetChildWithName("EditRate");

  if ( EditRate == 0 )
    {
      DefaultLogSink(). Error("EditRate element missing from input document\n");
      return RESULT_FORMAT;
    }

  m_TDesc.EditRate = decode_rational(EditRate->GetBody().c_str());

  if ( m_TDesc.EditRate != EditRate_23_98
       && m_TDesc.EditRate != EditRate_24
       && m_TDesc.EditRate != EditRate_25
       && m_TDesc.EditRate != EditRate_30
       && m_TDesc.EditRate != EditRate_48
       && m_TDesc.EditRate != EditRate_50
       && m_TDesc.EditRate != EditRate_60 )
    {
      DefaultLogSink(). Error("Unexpected EditRate: %d/%d\n",
			      m_TDesc.EditRate.Numerator, m_TDesc.EditRate.Denominator);
      return RESULT_FORMAT;
    }

  // list of fonts
  ElementList FontList;
  m_Root.GetChildrenWithName("LoadFont", FontList);

  for ( Elem_i i = FontList.begin(); i != FontList.end(); i++ )
    {
      UUID AssetID;
      if ( ! get_UUID_from_element(*i, AssetID) )
	{
	  DefaultLogSink(). Error("LoadFont element does not contain a urn:uuid value as expected.\n");
	  return RESULT_FORMAT;
	}

      TimedTextResourceDescriptor TmpResource;
      memcpy(TmpResource.ResourceID, AssetID.Value(), UUIDlen);
      TmpResource.Type = MT_OPENTYPE;
      m_TDesc.ResourceList.push_back(TmpResource);
      m_ResourceTypes.insert(ResourceTypeMap_t::value_type(UUID(TmpResource.ResourceID), MT_OPENTYPE));
    }

  // list of images
  ElementList ImageList;
  m_Root.GetChildrenWithName("Image", ImageList);
  std::set<Kumu::UUID> visited_items;

  for ( Elem_i i = ImageList.begin(); i != ImageList.end(); i++ )
    {
      UUID AssetID;
      if ( ! get_UUID_from_element(*i, AssetID) )
	{
	  DefaultLogSink(). Error("Image element does not contain a urn:uuid value as expected.\n");
	  return RESULT_FORMAT;
	}

      if ( visited_items.find(AssetID) == visited_items.end() )
	{
	  TimedTextResourceDescriptor TmpResource;
	  memcpy(TmpResource.ResourceID, AssetID.Value(), UUIDlen);
	  TmpResource.Type = MT_PNG;
	  m_TDesc.ResourceList.push_back(TmpResource);
	  m_ResourceTypes.insert(ResourceTypeMap_t::value_type(UUID(TmpResource.ResourceID), MT_PNG));
	  visited_items.insert(AssetID);
	}
    }

  // Calculate the timeline duration.
  // This is a little ugly because the last element in the file is not necessarily
  // the last instance to be displayed, e.g., element n and element n-1 may have the
  // same start time but n-1 may have a greater duration making it the last to be seen.
  // We must scan the list to accumulate the latest TimeOut value.
  ElementList InstanceList;
  ElementList::const_iterator ei;
  ui32_t end_count = 0;
  
  m_Root.GetChildrenWithName("Subtitle", InstanceList);

  if ( InstanceList.empty() )
    {
      DefaultLogSink(). Error("XML document contains no Subtitle elements.\n");
      return RESULT_FORMAT;
    }

  // assumes edit rate is constrained above
  ui32_t TCFrameRate = ( m_TDesc.EditRate == EditRate_23_98  ) ? 24 : m_TDesc.EditRate.Numerator;

  S12MTimecode beginTC;
  beginTC.SetFPS(TCFrameRate);
  XMLElement* StartTime = m_Root.GetChildWithName("StartTime");

  if ( StartTime != 0 )
    beginTC.DecodeString(StartTime->GetBody());

  for ( ei = InstanceList.begin(); ei != InstanceList.end(); ei++ )
    {
      S12MTimecode tmpTC((*ei)->GetAttrWithName("TimeOut"), TCFrameRate);
      if ( end_count < tmpTC.GetFrames() )
	end_count = tmpTC.GetFrames();
    }

  if ( end_count <= beginTC.GetFrames() )
    {
      DefaultLogSink(). Error("Timed Text file has zero-length timeline.\n");
      return RESULT_FORMAT;
    }

  m_TDesc.ContainerDuration = end_count - beginTC.GetFrames();

  return RESULT_OK;
}