示例#1
0
QList<int> RecipeActionsHandler::getAllVisibleItems()
{
	QList<int> ids;

	Q3ListViewItemIterator iterator( parentListView );
	while ( iterator.current() ) {
		if ( iterator.current() ->isVisible() ) {
			if ( iterator.current() ->rtti() == RECIPELISTITEM_RTTI ) {
				RecipeListItem * recipe_it = ( RecipeListItem* ) iterator.current();
				int recipe_id = recipe_it->recipeID();
	
				if ( ids.indexOf( recipe_id ) == -1 )
					ids.append( recipe_id );
			}
			//it is a category item and isn't populated, so get the unpopulated data from the database
			else if ( iterator.current()->rtti() == CATEGORYLISTITEM_RTTI && !iterator.current()->firstChild() ) {
				int cat_id = (( CategoryListItem* ) iterator.current())->element().id;
				ElementList list;
				database->loadRecipeList( &list, cat_id, true );
		
				for ( ElementList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it ) {
					if ( ids.indexOf( (*it).id ) == -1 )
						ids << (*it).id;
				}
			}
		}

		++iterator;
	}

	return ids;
}
示例#2
0
void KreAuthorActionsHandler::remove()
{
	int id = m_listWidget->selectedRowId();
	if ( id == -1 )
		return;

	ElementList recipeDependancies;
	m_database->findUseOfAuthorInRecipes( &recipeDependancies, id );

	//Check the current usage of the author in existing recipes, if it's used warn
	//that the recipes using that author will be modified, otherwise just say that
	//the selected author will be removed.
	if ( recipeDependancies.isEmpty() ) {
		switch ( KMessageBox::warningContinueCancel(
			m_listWidget,
			i18n( "Are you sure you want to delete this author?" ) ) ) {
			case KMessageBox::Continue:
				m_database->removeAuthor( id );
				break;
		}
		return;
	} else {
		ListInfo info;
		info.list = recipeDependancies;
		info.name = i18n("Recipes");

		QPointer<DependanciesDialog> warnDialog =
			new DependanciesDialog( m_listWidget, info, false );
		if ( warnDialog->exec() == QDialog::Accepted )
			m_database->removeAuthor( id );

		delete warnDialog;
	}
}
示例#3
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;
                }
            }
        }
    }
}
示例#4
0
void IngredientComboBox::reload()
{
	QString remember_text;
	if ( isEditable() )
		remember_text = lineEdit()->text();

	ElementList ingredientList;
	database->loadIngredients( &ingredientList );

	clear();
	ingredientComboRows.clear();

	int row = 0;
	if ( !m_specialItem.isEmpty() ) {
		insertItem( count(), m_specialItem );
		ingredientComboRows.insert( row, -1 );
		row++;
	}
	for ( ElementList::const_iterator it = ingredientList.constBegin(); it != ingredientList.constEnd(); ++it, ++row ) {
		insertItem( count(), (*it).name );
		completionObject()->addItem((*it).name);
		ingredientComboRows.insert( row, (*it).id );
	}

	if ( isEditable() )
		setEditText( remember_text );

	database->disconnect( this );
	connect( database, SIGNAL( ingredientCreated( const Element & ) ), SLOT( createIngredient( const Element & ) ) );
	connect( database, SIGNAL( ingredientRemoved( int ) ), SLOT( removeIngredient( int ) ) );
}
示例#5
0
QList<int> RecipeActionsHandler::recipeIDs( const QList<Q3ListViewItem *> &items ) const
{
	QList<int> ids;

	QListIterator<Q3ListViewItem *> it(items);
	const Q3ListViewItem *item;
	while ( it.hasNext() ) {
		item = it.next();
		if ( item->rtti() == 1000 ) { //RecipeListItem
			RecipeListItem * recipe_it = ( RecipeListItem* ) item;
			if ( ids.indexOf( recipe_it->recipeID() ) == -1 )
				ids << recipe_it->recipeID();
		}
		else if ( item->rtti() == 1001 ) {
			CategoryListItem *cat_it = ( CategoryListItem* ) item;
			ElementList list;
			database->loadRecipeList( &list, cat_it->element().id, true );
	
			for ( ElementList::const_iterator cat_it = list.constBegin(); cat_it != list.constEnd(); ++cat_it ) {
				if ( ids.indexOf( (*cat_it).id ) == -1 )
					ids << (*cat_it).id;
			}
		}
	}

	return ids;
}
示例#6
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;
}
示例#7
0
bool ContentDirectory::RefreshShareIndex()
{
  ElementList vars;
  ElementList args;
  args.push_back(ElementPtr(new Element("AlbumArtistDisplayOption", "")));
  vars = Request("RefreshShareIndex", args);
  if (!vars.empty() && vars[0]->compare("RefreshShareIndexResponse") == 0)
    return true;
  return false;
}
示例#8
0
ElementList Element::getElementsByName(string name)
{
	ElementList list;
	for(int i=0;i<(int)this->elements.size();i++)
	{
		if(this->elements.at(i).getTagName()==name)
			list.push_back(this->elements.at(i));
	}
	return list;
}
示例#9
0
bool ContentDirectory::DestroyObject(const std::string& objectID)
{
  ElementList vars;
  ElementList args;
  args.push_back(ElementPtr(new Element("ObjectID", objectID)));
  vars = Request("DestroyObject", args);
  if (!vars.empty() && vars[0]->compare("DestroyObjectResponse") == 0)
    return true;
  return false;
}
示例#10
0
string Element::renderChildren()
{
	string rend;
	ElementList elements = this->getChildElements();
	for(unsigned int i=0;i<elements.size();i++)
	{
		rend.append(elements.at(i).render());
	}
	return rend;
}
示例#11
0
void IngredientListView::load( int limit, int offset )
{
	ElementList ingredientList;
	database->loadIngredients( &ingredientList, limit, offset );

	setTotalItems(ingredientList.count());

	for ( ElementList::const_iterator ing_it = ingredientList.constBegin(); ing_it != ingredientList.constEnd(); ++ing_it )
		createIngredient( *ing_it );
}
示例#12
0
bool ContentDirectory::CreateObject(const std::string& containerID, const DigitalItemPtr& element)
{
  ElementList vars;
  ElementList args;
  args.push_back(ElementPtr(new Element("ContainerID", containerID)));
  args.push_back(ElementPtr(new Element("Elements", element->DIDL())));
  vars = Request("CreateObject", args);
  if (!vars.empty() && vars[0]->compare("CreateObjectResponse") == 0)
    return true;
  return false;
}
示例#13
0
		// 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 );
		}
示例#14
0
/**
 * Add a new group definition to the ELSTABLE. Returns 0 if OK, -1 if parsing FORMULA
 * fails. Assumes the syntax of grpname is correct.
 */
QString KMolCalc::defineGroup (const QString& grpname, const QString& formula) {
  ElementList* els = new ElementList(grpname);
  QString error = readGroup(formula, els);
  if (error != "OK")
    return error;

  if (els->contains(grpname))
    return QString("Can't define a group recursively!\n");

  elstable->replace(grpname, els);
  return QString("OK");
}
示例#15
0
文件: View.cpp 项目: GYGit/ffead-cpp
void View::traverseElement(string *ss, Element* element)
{
	ss->append(generateStartOpenTag(element->getTagName()));
	ss->append(generateAttributes(element->getAttributes()));
	ss->append(generateEndOpenTag());
	ss->append(element->getText());
	ElementList elements = element->getChildElements();
	for(unsigned int i=0;i<elements.size();i++)
	{
		traverseElement(ss, elements.at(i));
	}
	ss->append(generateCloseTag(element->getTagName()));
}
示例#16
0
		~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?
		}
示例#17
0
bool RenderingControl::SetMute(uint8_t value, const char* channel)
{
  char buf[4];
  memset(buf, 0, sizeof (buf));
  uint8_to_string(value, buf);
  ElementList args;
  args.push_back(ElementPtr(new Element("InstanceID", "0")));
  args.push_back(ElementPtr(new Element("Channel", channel)));
  args.push_back(ElementPtr(new Element("DesiredMute", buf)));
  ElementList vars = Request("SetMute", args);
  if (!vars.empty() && vars[0]->compare("SetMuteResponse") == 0)
    return true;
  return false;
}
示例#18
0
bool DietWizardDialog::checkCategories( Recipe &rec, int meal, int dish )
{

	// Check if the recipe is among the categories chosen
	ElementList categoryList;
	loadEnabledCategories( meal, dish, &categoryList );


	for ( ElementList::const_iterator cat_it = rec.categoryList.constBegin(); cat_it != rec.categoryList.constEnd(); ++cat_it ) {
		if ( categoryList.containsId( ( *cat_it ).id ) )
			return true;
	}

	return false;
}
示例#19
0
std::string Document::render()
{
	std::string rend = this->docType;
	rend.append(generateStartOpenTag(this->root.getTagName()));
	rend.append(generateAttributes(this->root.getAttributes()));
	rend.append(generateEndOpenTag());
	rend.append(this->root.getText());
	ElementList elements = this->root.getChildElements();
	for(unsigned int i=0;i<elements.size();i++)
	{
		rend.append(elements.at(i)->render());
	}
	rend.append(generateCloseTag(this->root.getTagName()));
	return rend;
}
示例#20
0
void Element::validateNs()
{
	if(nameSpace=="" || isValidNamespace(this, nameSpace))
	{
		ElementList elements = this->getChildElements();
		for(unsigned int i=0;i<elements.size();i++)
		{
			elements.at(i).parent = this;
			elements.at(i).validateNs();
		}
	}
	else
	{
		throw ("No namespace definition found - xmlns:" + nameSpace);
	}
}
示例#21
0
string Element::render()
{
	string rend;
	rend.append(generateStartOpenTag(this->getTagName()));
	rend.append(generateAttributes(this->getAttributes()));
	//rend.append(generateAttributes(this->namespaces));
	rend.append(generateEndOpenTag());
	rend.append(this->getText());
	ElementList elements = this->getChildElements();
	for(unsigned int i=0;i<elements.size();i++)
	{
		rend.append(elements.at(i).render());
	}
	rend.append(generateCloseTag(this->getTagName()));
	return rend;
}
示例#22
0
void IngredientComboBox::loadMore()
{
	if ( loading_at >= ing_count-1 ) {
		endLoad();
		return;
	}

	ElementList ingredientList;
	database->loadIngredients( &ingredientList, load_limit, loading_at );

	for ( ElementList::const_iterator it = ingredientList.constBegin(); it != ingredientList.constEnd(); ++it, ++loading_at ) {
		insertItem( count(), (*it).name );
		completionObject()->addItem((*it).name);
		ingredientComboRows.insert( loading_at, (*it).id );
	}
}
示例#23
0
string Element::renderSerialization()
{
	string rend;
	rend.append(generateStartOpenTag(this->getTagName()));
	rend.append(generateAttributes(this->getAttributes()));
	//rend.append(" namespace=\""+getNameSpcValue()+"\"");
	rend.append(generateEndOpenTag());
	rend.append(this->getText());
	ElementList elements = this->getChildElements();
	for(unsigned int i=0;i<elements.size();i++)
	{
		rend.append(elements.at(i)->renderSerialization());
	}
	rend.append(generateCloseTag(this->getTagName()));
	return rend;
}
示例#24
0
		// 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 "";
		}
示例#25
0
bool DeviceProperties::GetZoneAttributes(ElementList& vars)
{
  ElementList args;
  vars = Request("GetZoneAttributes", args);
  if (!vars.empty() && vars[0]->compare("GetZoneAttributesResponse") == 0)
    return true;
  return false;
}
示例#26
0
bool DeviceProperties::GetHouseholdID(ElementList& vars)
{
  ElementList args;
  vars = Request("GetHouseholdID", args);
  if (!vars.empty() && vars[0]->compare("GetHouseholdIDResponse") == 0)
    return true;
  return false;
}
示例#27
0
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
示例#28
0
Element* Document::getElementByName(const std::string& name, Element* ele)
{
	if(ele->getTagName()==name)
		return ele;
	else
	{
		ElementList chi = ele->getChildElements();
		for(unsigned int i=0;i<chi.size();i++)
		{
			Element* ele1 = getElementByName(name, chi.at(i));
			if(ele1!=NULL)
			{
				return ele1;
			}
		}
	}
	return NULL;
}
示例#29
0
void AppClient::decode(const ElementList& el)
{
    while ( el.forth() )
    {
        const ElementEntry& ee = el.getEntry();

        cout << "Name: " << ee.getName() << " DataType: " << DataType( ee.getLoad().getDataType() ) << " Value: ";

        if ( ee.getCode() == Data::BlankEnum )
            cout << " blank" << endl;
        else
            switch ( ee.getLoadType() )
            {
            case DataType::RealEnum:
                cout << ee.getReal().getAsDouble() << endl;
                break;
            case DataType::DateEnum:
                cout << (UInt64)ee.getDate().getDay() << " / " << (UInt64)ee.getDate().getMonth() << " / " << (UInt64)ee.getDate().getYear() << endl;
                break;
            case DataType::TimeEnum:
                cout << (UInt64)ee.getTime().getHour() << ":" << (UInt64)ee.getTime().getMinute() << ":" << (UInt64)ee.getTime().getSecond() << ":" << (UInt64)ee.getTime().getMillisecond() << endl;
                break;
            case DataType::IntEnum:
                cout << ee.getInt() << endl;
                break;
            case DataType::UIntEnum:
                cout << ee.getUInt() << endl;
                break;
            case DataType::AsciiEnum:
                cout << ee.getAscii() << endl;
                break;
            case DataType::ErrorEnum:
                cout << ee.getError().getErrorCode() << "( " << ee.getError().getErrorCodeAsString() << " )" << endl;
                break;
            case DataType::EnumEnum:
                cout << ee.getEnum() << endl;
                break;
            default:
                cout << endl;
                break;
            }
    }
}
示例#30
0
void createProgramaticConfig( Map& configDb )
{
	Map elementMap;
	ElementList elementList;

	elementMap.addKeyAscii( "Consumer_1", MapEntry::AddEnum,
		ElementList().addAscii( "Channel", "Channel_1" ).complete() ).complete();

	elementList.addMap( "ConsumerList", elementMap );

	elementList.complete();
	elementMap.clear();

	configDb.addKeyAscii( "ConsumerGroup", MapEntry::AddEnum, elementList );
	elementList.clear();

	elementMap.addKeyAscii( "Channel_1", MapEntry::AddEnum,
		ElementList()
		.addEnum( "ChannelType", 1 ) // Use the RSSL_CONN_TYPE_ENCRYPTED connection
		.addAscii( "Host", host )
		.addAscii( "Port", port )
		.addUInt( "EnableSessionManagement", 1 )
		.addEnum( "EncryptedProtocolType", 0 ) // Use the standard TCP transport protocol and OpenSSL for encryption on Windows
		.complete() ).complete();

	elementList.addMap( "ChannelList", elementMap );

	elementList.complete();
	elementMap.clear();

	configDb.addKeyAscii( "ChannelGroup", MapEntry::AddEnum, elementList );
	configDb.complete();
}