コード例 #1
0
IMessageStyleOptions SimpleMessageStyleEngine::styleOptions(const OptionsNode &AEngineNode, const QString &AStyleId) const
{
	IMessageStyleOptions options;
	if (AStyleId.isEmpty() || FStylePaths.contains(AStyleId))
	{
		QString styleId = AStyleId.isEmpty() ? AEngineNode.value("style-id").toString() : AStyleId;

		// Select default style
		if (!FStylePaths.isEmpty() && !FStylePaths.contains(styleId))
		{
			int mtype = AEngineNode.parentNSpaces().value(1).toInt();
			switch (mtype)
			{
			case Message::Normal:
			case Message::Headline:
			case Message::Error:
				styleId = "Message Style";
				AEngineNode.node("style",styleId).setValue(QString("Default"),"variant");
				break;
			default:
				styleId = "Chat Style";
				AEngineNode.node("style",styleId).setValue(QString("Default"),"variant");
			}
			styleId = !FStylePaths.contains(styleId) ? FStylePaths.keys().first() : styleId;
		}

		if (FStylePaths.contains(styleId))
		{
			options.engineId = engineId();
			options.styleId = styleId;

			OptionsNode styleNode = AEngineNode.node("style",styleId);
			options.extended.insert(MSO_VARIANT,styleNode.value("variant"));
			options.extended.insert(MSO_FONT_FAMILY,styleNode.value("font-family"));
			options.extended.insert(MSO_FONT_SIZE,styleNode.value("font-size"));
			options.extended.insert(MSO_SELF_COLOR,styleNode.value("self-color"));
			options.extended.insert(MSO_CONTACT_COLOR,styleNode.value("contact-color"));
			options.extended.insert(MSO_BG_COLOR,styleNode.value("bg-color"));
			options.extended.insert(MSO_BG_IMAGE_FILE,styleNode.value("bg-image-file"));

			QList<QString> variants = styleVariants(styleId);
			QMap<QString,QVariant> info = styleInfo(styleId);

			if (!variants.contains(options.extended.value(MSO_VARIANT).toString()))
				options.extended.insert(MSO_VARIANT,info.value(MSIV_DEFAULT_VARIANT, variants.value(0)));

			if (info.value(MSIV_DISABLE_CUSTOM_BACKGROUND,false).toBool())
			{
				options.extended.remove(MSO_BG_IMAGE_FILE);
				options.extended.insert(MSO_BG_COLOR,info.value(MSIV_DEFAULT_BACKGROUND_COLOR));
			}
			else if (options.extended.value(MSO_BG_COLOR).toString().isEmpty())
			{
				options.extended.insert(MSO_BG_COLOR,info.value(MSIV_DEFAULT_BACKGROUND_COLOR));
			}

			if (options.extended.value(MSO_FONT_FAMILY).toString().isEmpty())
				options.extended.insert(MSO_FONT_FAMILY,info.value(MSIV_DEFAULT_FONT_FAMILY));
			if (options.extended.value(MSO_FONT_SIZE).toInt() == 0)
				options.extended.insert(MSO_FONT_SIZE,info.value(MSIV_DEFAULT_FONT_SIZE));

			if (options.extended.value(MSO_SELF_COLOR).toString().isEmpty())
				options.extended.insert(MSO_SELF_COLOR,info.value(MSIV_DEFAULT_SELF_COLOR,QColor(Qt::red).name()));
			if (options.extended.value(MSO_CONTACT_COLOR).toString().isEmpty())
				options.extended.insert(MSO_CONTACT_COLOR,info.value(MSIV_DEFAULT_CONTACT_COLOR,QColor(Qt::blue).name()));
		}
		else
		{
			REPORT_ERROR("Failed to find any suitable simple message style");
		}
	}
	else
	{
		REPORT_ERROR(QString("Failed to get adium style options for style=%1: Style not found").arg(AStyleId));
	}

	return options;
}
コード例 #2
0
ファイル: agent.cpp プロジェクト: rehsack/smart-snmpd
Agent::Agent()
    : mMib( 0 )
    , mReqList( 0 )
    , mSnmp( 0 )
    , mv3mp( 0 )
    , mSignal(0)
    , mRunning( false )
    , mMibModules()
{
    for( size_t i = 0; i < (lengthof(moduleInfoFuncs) - 1); ++i )
    {
        MibModule *modInfo = moduleInfoFuncs[i]();
        mMibModules.push_back( modInfo );

        if( !modInfo->InitModule() )
        {
            LOG_BEGIN(loggerModuleName, ERROR_LOG | 0);
            LOG("Agent::Init(): mibs module initialization failed at (index)");
            LOG(i);
            LOG_END;

            exit(1);
        }
    }

    int status;

    Snmp::socket_startup();  // Initialize socket subsystem
    if( Config::getInstance().getListenOn().empty() )
        mSnmp = new Snmpx(status, Config::getInstance().getPort());
    else
        mSnmp = new Snmpx(status, UdpAddress( Config::getInstance().getListenOn().c_str() ) );
    if( !mSnmp )
    {
        LOG_BEGIN(loggerModuleName, ERROR_LOG | 0);
        LOG("Agent::Init(): Error allocating Snmpx");
        LOG(status);
        LOG_END;

        exit(1);
    }

    if (status == SNMP_CLASS_SUCCESS)
    {
        LOG_BEGIN(loggerModuleName, EVENT_LOG | 1);
        LOG("Agent::Init(): SNMP listen port");
        LOG(Config::getInstance().getPort());
        LOG_END;
    }
    else
    {
        LOG_BEGIN(loggerModuleName, ERROR_LOG | 0);
        LOG("Agent::Init(): SNMP port init failed");
        LOG(status);
        LOG_END;

        delete mSnmp;

        mSnmp = 0;

        exit(1);
    }

    unsigned int snmpEngineBoots = 0;
    OctetStr engineId(SnmpEngineID::create_engine_id(Config::getInstance().getPort()));

    LOG_BEGIN(loggerModuleName,  DEBUG_LOG | 1 );
    LOG("status file name");
    LOG(Config::getInstance().getStatusFileName().c_str());
    LOG_END;

    // you may use your own methods to load/store this counter
    status = getBootCounter(Config::getInstance().getStatusFileName().c_str(), engineId, snmpEngineBoots);
    if ((status != SNMPv3_OK) && (status < SNMPv3_FILEOPEN_ERROR))
    {
        LOG_BEGIN(loggerModuleName, ERROR_LOG | 0);
        LOG("Agent::Init(): Error loading snmpEngineBoots counter (status)");
        LOG(status);
        LOG_END;
        exit(1);
    }

    snmpEngineBoots++;
    status = saveBootCounter(Config::getInstance().getStatusFileName().c_str(), engineId, snmpEngineBoots);
    if (status != SNMPv3_OK)
    {
        LOG_BEGIN(loggerModuleName, ERROR_LOG | 0);
        LOG("Agent::Init(): Error saving snmpEngineBoots counter (status)");
        LOG(status);
        LOG_END;
        exit(1);
    }

    int stat;
    mv3mp = new v3MP(engineId, snmpEngineBoots, stat);
    if( !mv3mp )
    {
        LOG_BEGIN(loggerModuleName, ERROR_LOG | 0);
        LOG("Agent::Init(): Error allocating v3MP");
        LOG(status);
        LOG_END;

        delete mSnmp;
        mSnmp = 0;

        exit(1);
    }

    mMib = new Mib();
    if( !mMib )
    {
        LOG_BEGIN(loggerModuleName, ERROR_LOG | 0);
        LOG("Agent::Init(): Error allocating Mib");
        LOG(status);
        LOG_END;

        delete mSnmp;
        mSnmp = 0;

        delete mv3mp;
        mv3mp = 0;

        exit(1);
    }

    mReqList = new RequestList();
    if( !mMib )
    {
        LOG_BEGIN(loggerModuleName, ERROR_LOG | 0);
        LOG("Agent::Init(): Error allocating RequestList");
        LOG(status);
        LOG_END;

        delete mMib;
        mMib = 0;

        delete mSnmp;
        mSnmp = 0;

        delete mv3mp;
        mv3mp = 0;

        exit(1);
    }

    // register v3MP
    mReqList->set_v3mp(mv3mp);

    // register requestList for outgoing requests
    mMib->set_request_list(mReqList);
}