Beispiel #1
0
void *ConfigureDialog::processEvent(Event *e)
{
    if (e->type() == EventLanguageChanged)
        bLanguageChanged = true;
    if (e->type() == EventPluginChanged){
        pluginInfo *info = (pluginInfo*)(e->param());
        if (info->plugin == NULL){
            for (QListViewItem *i = lstBox->firstChild(); i; i = i->nextSibling()){
                ConfigItem *item = static_cast<ConfigItem*>(i);
                if (item->type() != PLUGIN_ITEM)
                    continue;
                if (static_cast<PluginItem*>(item)->info() == info){
                    item->deleteWidget();
                    break;
                }
            }
        }
    }
    if (e->type() == EventClientsChanged){
        unsigned id = 0;
        if (lstBox->currentItem())
            id = static_cast<ConfigItem*>(lstBox->currentItem())->id();
        fill(id);
    }
    if (e->type() == EventClientChanged){
        if (m_nUpdates){
            if (--m_nUpdates == 0){
                setTitle();
                btnUpdate->setEnabled(true);
            }
        }
    }
    return NULL;
}
Beispiel #2
0
/**
 * Set a "key = value" to config items
 *
 * @param key The name of the key to set
 * @param value The value to set
 */
int Settings::set(QString key, QString value)
{
	QPtrListIterator<ConfigItem> it(m_items);
	
	// Search for existing key
	while (it.current() != NULL)
	{
		if (it.current()->key() == key)
		{
			// Replace existing
			it.current()->setText(value);
			
			return m_items.count();
		}
		else
		{
			++it;
		}
	}
	
	//
	// If we come here, it means the key was not found so we must create new
	ConfigItem* item = new ConfigItem;
	item->setKey(key);
	item->setText(value);
	m_items.append(item);
	
	return m_items.count();
}
void Configuration::itemChanged(QTreeWidgetItem* item, int column) {
    if (column == 1) {
        ConfigItem* ci = configItem(item);
        if (ci) {
            ci->setValue(item->text(1));
        }
    }
}
Beispiel #4
0
void BasicConfig::AddBasicConfig(const std::string& name, ConfigItem::ConfigItemType type, const std::string& value)
{
    ConfigItem *pConfigItem;


    pConfigItem = new xPL::ConfigItem(name, type);
	pConfigItem->AddValue(value);
	AddConfigItem(pConfigItem);
}
Beispiel #5
0
 static ConfigItem parseConfigItemFromYamlNode(const YAML::Node &n) {
   ConfigItem item;
   if(n.Type() == YAML::NodeType::Scalar) {
     std::string s;
     n.GetScalar(s);
     item.setUnparsedString(s);
   }
   return item;
 }
Beispiel #6
0
  inline ConfigItem* Configuration::find(const char* key) {
    for(Items::iterator i = items_.begin();
        i != items_.end();
        ++i) {
      ConfigItem* item = *i;
      if(item->equal_p(key)) return item;
    }

    return 0;
  }
Beispiel #7
0
  inline bool Configuration::import(const char* key, const char* val) {
    for(Items::iterator i = items_.begin();
        i != items_.end();
        ++i) {
      ConfigItem* item = *i;
      if(item->set_maybe(key, val)) return true;
    }

    return false;
  }
Beispiel #8
0
 inline void Configuration::print(bool desc) {
   for(Items::iterator i = items_.begin();
       i != items_.end();
       ++i) {
     ConfigItem* item = *i;
     std::cout << item->name() << ": ";
     item->print_value(std::cout);
     std::cout << "\n";
     if(desc) {
       if(const char* desc = item->description()) {
         std::cout << "  " << desc << "\n";
       }
       std::cout << "\n";
     }
   }
 }
Beispiel #9
0
void
ConfigScope::dump(
	StringBuffer &			buf,
	bool					wantExpandedUidNames,
	int						indentLevel) const
{
	int						i;
	int						len;
	StringVector			nameVec;
	ConfigItem *			item;
	
	//--------
	// First pass. Dump the variables
	//--------
	listLocalNames(Configuration::CFG_VARIABLES, nameVec);
	nameVec.sort();
	len = nameVec.length();
	for (i = 0; i < len; i++) {
		item = findItem(nameVec[i]);
		assert(item->type() & Configuration::CFG_VARIABLES);
		item->dump(buf, item->name(), wantExpandedUidNames, indentLevel);
	}

	//--------
	// Second pass. Dump the nested scopes
	//--------
	listLocalNames(Configuration::CFG_SCOPE, nameVec);
	nameVec.sort();
	len = nameVec.length();
	for (i = 0; i < len; i++) {
		item = findItem(nameVec[i]);
		assert(item->type() == Configuration::CFG_SCOPE);
		item->dump(buf, item->name(), wantExpandedUidNames, indentLevel);
	}
}
Beispiel #10
0
    static void dumpConfigItemToYaml(YAML::Emitter &emitter,
                                     const ConfigItem &item) {
      std::string s = item.toString();

      if(!s.empty() && item.children.size()) {
        fprintf(stderr, "%s: To dump to yaml file it is not allowed to have a item value and map at the same time.\n",
                item.getParentName().c_str());
        assert(false);
      }
      else {
        if(s.empty() && item.children.size() == 0) {
          emitter << "";
        }
      }

      if(!s.empty())
        emitter << s;
      if(item.children.size())
        dumpConfigMapToYaml(emitter, item.children);
    }
Beispiel #11
0
void ConfigureDialog::fill(unsigned id)
{
    lstBox->clear();
    lstBox->setSorting(1);

    ConfigItem *parentItem = new MainInfoItem(lstBox, 0);
    for (unsigned i = 0; i < getContacts()->nClients(); i++){
        Client *client = getContacts()->getClient(i);
        CommandDef *cmds = client->configWindows();
        if (cmds){
            parentItem = NULL;
            for (; cmds->text; cmds++){
                if (parentItem){
                    new ClientItem(parentItem, client, cmds);
                }else{
                    parentItem = new ClientItem(lstBox, client, cmds);
                    parentItem->setOpen(true);
                }
            }
        }
    }

    unsigned long n;
    parentItem = NULL;
    list<unsigned> st;
    for (n = 0; n < getContacts()->nClients(); n++){
        Protocol *protocol = getContacts()->getClient(n)->protocol();
        if ((protocol->description()->flags & (PROTOCOL_AR | PROTOCOL_AR_USER)) == 0)
            continue;
        if (parentItem == NULL){
            parentItem = new ConfigItem(lstBox, 0);
            parentItem->setText(0, i18n("Autoreply"));
            parentItem->setOpen(true);
        }
        for (const CommandDef *d = protocol->statusList(); d->text; d++){
            if (((protocol->description()->flags & PROTOCOL_AR_OFFLINE) == 0) &&
                    ((d->id == STATUS_ONLINE) || (d->id == STATUS_OFFLINE)))
                continue;
            list<unsigned>::iterator it;
            for (it = st.begin(); it != st.end(); ++it)
                if ((*it) == d->id)
                    break;
            if (it != st.end())
                continue;
            st.push_back(d->id);
            new ARItem(parentItem, d);
        }
    }

    parentItem = new ConfigItem(lstBox, 0);
    parentItem->setText(0, i18n("Plugins"));
    parentItem->setPixmap(0, Pict("run", lstBox->colorGroup().base()));
    parentItem->setOpen(true);

    for ( n = 0;; n++){
        Event e(EventPluginGetInfo, (void*)n);
        pluginInfo *info = (pluginInfo*)e.process();
        if (info == NULL) break;
        if (info->info == NULL){
            Event e(EventLoadPlugin, (char*)info->name.c_str());
            e.process();
        }
        if ((info->info == NULL) || (info->info->title == NULL)) continue;
        QString title = i18n(info->info->title);
        new PluginItem(parentItem, title, info, n);
    }

    QFontMetrics fm(lstBox->font());
    unsigned w = 0;
    for (QListViewItem *item = lstBox->firstChild(); item; item = item->nextSibling()){
        w = QMAX(w, itemWidth(item, fm));
    }
    lstBox->setFixedWidth(w);
    lstBox->setColumnWidth(0, w - 2);

    if (id){
        for (QListViewItem *item = lstBox->firstChild(); item; item = item->nextSibling()){
            if (setCurrentItem(item, id))
                return;
        }
    }
    lstBox->setCurrentItem(lstBox->firstChild());
}
Beispiel #12
0
bool BasicConfig::MsgAnswer(SchemaObject& msg)
{
    if(msg.GetMsgType() != SchemaObject::cmnd)
    {
        LOG_VERBOSE(m_Log) << "Not a command message.";
        LOG_EXIT_OK;
        return false;
    }

    if(msg.GetClass() != "config")
    {
        LOG_VERBOSE(m_Log) << "Not a config class.";
        LOG_EXIT_OK;
        return false;
    }

    if(msg.GetType() == "current")
    {
        LOG_VERBOSE(m_Log) << "current type...";
        if(msg.GetValue("command") != "request")
        {
            LOG_VERBOSE(m_Log) << "but not command request";
            LOG_EXIT_OK;
            return false;
        }
        LOG_VERBOSE(m_Log) << "send config.current message";
        SchemaConfigCurrent configCurrent;
        configCurrent = ToConfigCurrent();
        m_xPLDevice->SendMessage(&configCurrent, msg.GetSource());
        LOG_EXIT_OK;
        return true;
    }

    if(msg.GetType() == "list")
    {
        LOG_VERBOSE(m_Log) << "list type...";
        if(msg.GetValue("command") != "request")
        {
            LOG_VERBOSE(m_Log) << "but not command request";
            LOG_EXIT_OK;
            return false;
        }
        LOG_VERBOSE(m_Log) << "send config.list message";
        SchemaConfigList configList;
        configList = ToConfigList();
        m_xPLDevice->SendMessage(&configList, msg.GetSource());
        LOG_EXIT_OK;
        return true;
    }

    if(msg.GetType() == "response")
    {
        LOG_VERBOSE(m_Log) << "response type";
        size_t i;
        SchemaObject::SchemaItem* pSchemaItem;
        ConfigItem* pConfigItem;
        SchemaObject::SchemaItem::Iterator itValue;

        for(i=0; i<m_ConfigItems.size(); i++)
        {
            pConfigItem = m_ConfigItems[i];

            pSchemaItem = msg.GetItem(pConfigItem->GetName());
            if(pSchemaItem==nullptr) continue;

            pConfigItem->ClearValues();

            for(itValue=pSchemaItem->begin(); itValue!=pSchemaItem->end(); ++itValue)
                pConfigItem->AddValue(*itValue);
        }

        if(m_CallBackConfig != nullptr) m_CallBackConfig->Configure();
        m_xPLDevice->SaveConfig();
        LOG_EXIT_OK;
        return true;
    }

    LOG_VERBOSE(m_Log) << "Not a current|list|response type.";
    LOG_EXIT_OK;
    return false;
}