Exemplo n.º 1
0
static void
readSetting (CCSBackend *backend,
	     CCSContext *context,
	     CCSSetting *setting)
{
    Bool         status = FALSE;
    char        *keyName;
    IniPrivData *data;

    data = (IniPrivData *) ccsObjectGetPrivate (backend);
    if (!data)
	return;

    if (asprintf (&keyName, "s%d_%s", ccsContextGetScreenNum (context), ccsSettingGetName (setting)) == -1)
	return;

    switch (ccsSettingGetType (setting))
    {
    case TypeString:
	{
	    char *value;
	    if (ccsIniGetString (data->iniFile, ccsPluginGetName (ccsSettingGetParent (setting)),
 				 keyName, &value))
	    {
		ccsSetString (setting, value, TRUE);
		free (value);
		status = TRUE;
	    }
	}
	break;
    case TypeMatch:
	{
	    char *value;
	    if (ccsIniGetString (data->iniFile, ccsPluginGetName (ccsSettingGetParent (setting)),
				 keyName, &value))
	    {
		ccsSetMatch (setting, value, TRUE);
		free (value);
		status = TRUE;
	    }
	}
	break;
    case TypeInt:
	{
	    int value;
	    if (ccsIniGetInt (data->iniFile, ccsPluginGetName (ccsSettingGetParent (setting)),
			      keyName, &value))
	    {
		ccsSetInt (setting, value, TRUE);
		status = TRUE;
	    }
	}
	break;
    case TypeBool:
	{
	    Bool value;
	    if (ccsIniGetBool (data->iniFile, ccsPluginGetName (ccsSettingGetParent (setting)),
			       keyName, &value))
	    {
		ccsSetBool (setting, (value != 0), TRUE);
		status = TRUE;
	    }
	}
	break;
    case TypeFloat:
	{
	    float value;
	    if (ccsIniGetFloat (data->iniFile, ccsPluginGetName (ccsSettingGetParent (setting)),
				keyName, &value))
	    {
		ccsSetFloat (setting, value, TRUE);
		status = TRUE;
	    }
	}
	break;
    case TypeColor:
	{
	    CCSSettingColorValue color;

	    if (ccsIniGetColor (data->iniFile, ccsPluginGetName (ccsSettingGetParent (setting)),
				keyName, &color))
	    {
		ccsSetColor (setting, color, TRUE);
		status = TRUE;
	    }
	}
	break;
    case TypeKey:
	{
	    CCSSettingKeyValue key;
	    if (ccsIniGetKey (data->iniFile, ccsPluginGetName (ccsSettingGetParent (setting)),
			      keyName, &key))
	    {
		ccsSetKey (setting, key, TRUE);
		status = TRUE;
	    }
	}
	break;
    case TypeButton:
	{
	    CCSSettingButtonValue button;
	    if (ccsIniGetButton (data->iniFile, ccsPluginGetName (ccsSettingGetParent (setting)),
				 keyName, &button))
	    {
		ccsSetButton (setting, button, TRUE);
		status = TRUE;
	    }
	}
	break;
    case TypeEdge:
	{
	    unsigned int edges;
	    if (ccsIniGetEdge (data->iniFile, ccsPluginGetName (ccsSettingGetParent (setting)),
				 keyName, &edges))
	    {
		ccsSetEdge (setting, edges, TRUE);
		status = TRUE;
	    }
	}
	break;
    case TypeBell:
	{
	    Bool bell;
	    if (ccsIniGetBell (data->iniFile, ccsPluginGetName (ccsSettingGetParent (setting)),
			       keyName, &bell))
	    {
		ccsSetBell (setting, bell, TRUE);
		status = TRUE;
	    }
	}
	break;
    case TypeList:
	{
	    CCSSettingValueList value;
	    if (ccsIniGetList (data->iniFile, ccsPluginGetName (ccsSettingGetParent (setting)),
			       keyName, &value, setting))
	    {
		ccsSetList (setting, value, TRUE);
		ccsSettingValueListFree (value, TRUE);
		status = TRUE;
	    }
	}
	break;
    default:
	break;
    }

    if (!status)
    {
	/* reset setting to default if it could not be read */
	ccsResetToDefault (setting, TRUE);
    }

    if (keyName)
	free (keyName);
}
static void
readSetting (CCSContext *c,
	     CCSSetting *setting)
{
    QString key (setting->name);
    QString group (setting->parent->name);

    group += "_display";

    KConfigGroup cfg = cFiles->main->group (group);

    if (ccsGetIntegrationEnabled (c) && isIntegratedOption (setting) )
    {
	readIntegratedOption (setting, &cfg);
	return;
    }

    if (!cfg.hasKey (key) )
    {
	ccsResetToDefault (setting);
	return;
    }

    switch (setting->type)
    {

    case TypeString:
	ccsSetString (setting, cfg.readEntry (key, "").toAscii ().constData ());
	break;

    case TypeMatch:
	ccsSetMatch (setting, cfg.readEntry (key, "").toAscii ().constData ());
	break;

    case TypeFloat:
	ccsSetFloat (setting, cfg.readEntry (key, double(0.0)));
	break;

    case TypeInt:
	ccsSetInt (setting, cfg.readEntry (key, int(0)));
	break;

    case TypeBool:
	{
	    Bool val = (cfg.readEntry (key, false)) ? TRUE : FALSE;
	    ccsSetBool (setting, val);
	}
	break;

    case TypeColor:
	{
	    CCSSettingColorValue color;
	    QString value = cfg.readEntry (key, "");

	    if (ccsStringToColor (value.toAscii ().constData (), &color))
		ccsSetColor (setting, color);
	}
	break;

    case TypeList:
	{
	    switch (setting->info.forList.listType)
	    {

	    case TypeBool:
		{
		    QList<bool> list = cfg.readEntry (key, QList<bool> ());

		    Bool *array = new Bool[list.count ()];
		    int i = 0;

		    foreach (Bool val, list)
		    {
			array[i] = (val) ? TRUE : FALSE;
			i++;
		    }

		    CCSSettingValueList l =
			ccsGetValueListFromBoolArray (array, i, setting);
		    ccsSetList (setting, l);
		    ccsSettingValueListFree (l, TRUE);
		    delete array;
		}
		break;

	    case TypeInt:
		{
		    QList<int> list = cfg.readEntry (key, QList<int> ());

		    int *array = new int[list.count ()];
		    int i = 0;

		    foreach (int val, list)
		    {
			array[i] = val;
			i++;
		    }

		    CCSSettingValueList l =
			ccsGetValueListFromIntArray (array, i, setting);
		    ccsSetList (setting, l);
		    ccsSettingValueListFree (l, TRUE);
		    delete array;
		}
		break;

	    case TypeString:
		{
		    QStringList list = cfg.readEntry (key, QStringList ());

		    if (!list.count ())
			break;

		    char **array = new char *[list.count ()];

		    int i = 0;

		    foreach (QString val, list)
		    {
			array[i] = strdup (val.toAscii ().constData ());
			i++;
		    }

		    CCSSettingValueList l =
			ccsGetValueListFromStringArray (array, i, setting);
		    ccsSetList (setting, l);
		    ccsSettingValueListFree (l, TRUE);

		    for (int j = 0; j < i; j++)
			free (array[j]);

		    delete [] array;

		}
		break;

	    case TypeMatch:
		{
		    QStringList list = cfg.readEntry (key, QStringList ());

		    if (!list.count ())
			break;

		    char **array = new char *[list.count ()];

		    int i = 0;

		    foreach (QString val, list)
		    {
			array[i] = strdup (val.toAscii ().constData ());
			i++;
		    }

		    CCSSettingValueList l =
			ccsGetValueListFromStringArray (array, i, setting);
		    ccsSetList (setting, l);
		    ccsSettingValueListFree (l, TRUE);

		    for (int j = 0; j < i; j++)
			free (array[j]);

		    delete [] array;

		}
Exemplo n.º 3
0
static void
readSetting (CCSContext *context,
             CCSSetting *setting)
{
    Bool         status = FALSE;
    char        *keyName;
    IniPrivData *data;

    data = findPrivFromContext (context);
    if (!data)
        return;

    if (setting->isScreen)
        asprintf (&keyName, "s%d_%s", setting->screenNum, setting->name);
    else
        asprintf (&keyName, "as_%s", setting->name);

    switch (setting->type)
    {
    case TypeString:
    {
        char *value;
        if (ccsIniGetString (data->iniFile, setting->parent->name,
                             keyName, &value))
        {
            ccsSetString (setting, value);
            free (value);
            status = TRUE;
        }
    }
    break;
    case TypeMatch:
    {
        char *value;
        if (ccsIniGetString (data->iniFile, setting->parent->name,
                             keyName, &value))
        {
            ccsSetMatch (setting, value);
            free (value);
            status = TRUE;
        }
    }
    break;
    case TypeInt:
    {
        int value;
        if (ccsIniGetInt (data->iniFile, setting->parent->name,
                          keyName, &value))
        {
            ccsSetInt (setting, value);
            status = TRUE;
        }
    }
    break;
    case TypeBool:
    {
        Bool value;
        if (ccsIniGetBool (data->iniFile, setting->parent->name,
                           keyName, &value))
        {
            ccsSetBool (setting, (value != 0));
            status = TRUE;
        }
    }
    break;
    case TypeFloat:
    {
        float value;
        if (ccsIniGetFloat (data->iniFile, setting->parent->name,
                            keyName, &value))
        {
            ccsSetFloat (setting, value);
            status = TRUE;
        }
    }
    break;
    case TypeColor:
    {
        CCSSettingColorValue color;

        if (ccsIniGetColor (data->iniFile, setting->parent->name,
                            keyName, &color))
        {
            ccsSetColor (setting, color);
            status = TRUE;
        }
    }
    break;
    case TypeKey:
    {
        CCSSettingKeyValue key;
        if (ccsIniGetKey (data->iniFile, setting->parent->name,
                          keyName, &key))
        {
            ccsSetKey (setting, key);
            status = TRUE;
        }
    }
    break;
    case TypeButton:
    {
        CCSSettingButtonValue button;
        if (ccsIniGetButton (data->iniFile, setting->parent->name,
                             keyName, &button))
        {
            ccsSetButton (setting, button);
            status = TRUE;
        }
    }
    break;
    case TypeEdge:
    {
        unsigned int edges;
        if (ccsIniGetEdge (data->iniFile, setting->parent->name,
                           keyName, &edges))
        {
            ccsSetEdge (setting, edges);
            status = TRUE;
        }
    }
    break;
    case TypeBell:
    {
        Bool bell;
        if (ccsIniGetBell (data->iniFile, setting->parent->name,
                           keyName, &bell))
        {
            ccsSetBell (setting, bell);
            status = TRUE;
        }
    }
    break;
    case TypeList:
    {
        CCSSettingValueList value;
        if (ccsIniGetList (data->iniFile, setting->parent->name,
                           keyName, &value, setting))
        {
            ccsSetList (setting, value);
            ccsSettingValueListFree (value, TRUE);
            status = TRUE;
        }
    }
    break;
    default:
        break;
    }

    if (!status)
    {
        /* reset setting to default if it could not be read */
        ccsResetToDefault (setting);
    }

    if (keyName)
        free (keyName);
}
static void
readIntegratedOption (CCSSetting   *setting,
		      KConfigGroup *mcg)
{
    int option = 0;
    KConfigGroup g;

    for (unsigned int i = 0; i < N_SOPTIONS; i++)
    {
	if (setting->name == specialOptions[i].settingName &&
	    QString (setting->parent->name) == specialOptions[i].pluginName)
	{
	    option = i;
	    break;
	}
    }

    switch (specialOptions[option].type)
    {

    case OptionInt:
	KdeIntToCCS (setting, option);
	break;

    case OptionBool:
	KdeBoolToCCS (setting, option);
	break;

    case OptionKey:
	KdeKeyToCCS (setting, option);
	break;

    case OptionSpecial:
	if (specialOptions[option].settingName == "command11")
	{
	    ccsSetString (setting, "xkill");
	}
	else if (specialOptions[option].settingName == "unmaximize_window_key"
		 || specialOptions[option].settingName == "maximize_window_key"
		 || specialOptions[option].settingName == "maximize_window_horizontally_key"
		 || specialOptions[option].settingName == "maximize_window_vertically_key")
	{
	    CCSSettingKeyValue keyVal;

	    if (!ccsGetKey (setting, &keyVal) )
		break;

	    keyVal.keysym = 0;

	    keyVal.keyModMask = 0;

	    ccsSetKey (setting, keyVal);
	}
	else if (specialOptions[option].settingName == "click_to_focus")
	{
	    Bool val = (cFiles->kwin->group ("Windows").
		        readEntry ("FocusPolicy") == "ClickToFocus") ?
		        TRUE : FALSE;
	    ccsSetBool (setting, val);
	}
	else if (specialOptions[option].settingName == "mode" &&
		 specialOptions[option].pluginName == "resize")
	{
	    QString mode = cFiles->kwin->group ("Windows").
			   readEntry ("ResizeMode");
	    int     imode = -1;
	    int     result = 0;

	    if (mcg->hasKey (specialOptions[option].settingName +
			     " (Integrated)"))
		imode = mcg->readEntry (specialOptions[option].settingName + 
				        " (Integrated)", int (0));

	    if (mode == "Opaque")
	    {
		result = 0;

		if (imode == 3)
		    result = 3;
	    }
	    else if (mode == "Transparent")
	    {
		result = 1;

		if (imode == 2)
		    result = 2;
	    }

	    ccsSetInt (setting, result);
	}
	else if (specialOptions[option].settingName == "snap_type")
	{
	    static int intList[2] = {0, 1};
	    CCSSettingValueList list = ccsGetValueListFromIntArray (intList, 2,
								    setting);
	    ccsSetList (setting, list);
	    ccsSettingValueListFree (list, TRUE);
	}
	else if (specialOptions[option].settingName == "resistance_distance" ||
		 specialOptions[option].settingName == "attraction_distance")
	{
	    int val1 = 
		cFiles->kwin->group ("Windows").
		    readEntry ("WindowSnapZone", int (0));
	    int val2 = 
		cFiles->kwin->group ("Windows").
		    readEntry ("BorderSnapZone", int (0));
	    int result = qMax (val1, val2);

	    if (result == 0)
		result = mcg->readEntry ("snap_distance (Integrated)", int (0));

	    if (result > 0)
	    	ccsSetInt (setting, result);
	}
	else if (specialOptions[option].settingName == "edges_categories")
	{
	    int val1 = 
		cFiles->kwin->group ("Windows").
		    readEntry ("WindowSnapZone", int (0));
	    int val2 = 
		cFiles->kwin->group ("Windows").
		    readEntry ("BorderSnapZone", int (0));
	    int intList[2] = {0, 0};
	    int num = 0;

	    if (val2 > 0)
		num++;
	    if (val1 > 0)
	    {
		intList[num] = 1;
		num++;
	    }

	    CCSSettingValueList list = ccsGetValueListFromIntArray (intList,
								    num,
								    setting);
	    ccsSetList (setting, list);
	    ccsSettingValueListFree (list, TRUE);
	}
	else if (specialOptions[option].settingName == "edge_flip_window" ||
		 specialOptions[option].settingName == "edgeflip_move")
	{
	    int val = 
		cFiles->kwin->group ("Windows").
		    readEntry ("ElectricBorders", int (0));

	    if (val > 0)
		ccsSetBool (setting, TRUE);
	    else
		ccsSetBool (setting, FALSE);
	}
	else if (specialOptions[option].settingName == "edge_flip_pointer" ||
		 specialOptions[option].settingName == "edgeflip_pointer")
	{
	    int val = 
		cFiles->kwin->group ("Windows").
		    readEntry ("ElectricBorders", int (0));

	    if (val > 1)
		ccsSetBool (setting, TRUE);
	    else
		ccsSetBool (setting, FALSE);
	}
	else if (specialOptions[option].settingName == "mode" &&
		 specialOptions[option].pluginName == "place")
	{
	    QString mode = cFiles->kwin->group ("Windows").
			   readEntry ("Placement");
	    int     result = 0;

	    if (mode == "Smart")
		result = 2;
	    else if (mode == "Maximizing")
		result = 3;
	    else if (mode == "Cascade")
		result = 0;
	    else if (mode == "Random")
		result = 4;
	    else if (mode == "Centered")
		result = 1;

	    ccsSetInt (setting, result);
	}
	break;

    default:
	break;
    }
}