# coding=utf-8
""" created by pbc on 2016.05.20 for init config.ini
"""
import os

from PyQt4.QtCore import QSettings
settings = QSettings("/mcos/config.ini", QSettings.IniFormat)
import common_run


def set_screen_r(value):
    if value == "":
        value = "1440x900"
    try:
        if int(value.split("x")[0]) < 1024 or int(value.split("x")[1]) < 768:
            settings.setValue("screen","1024x768")
            value = "1024x768"
            settings.setValue("screen",value)
            __c = "xrandr -s %s" % value
            os.system(__c)
    except:
        pass
    __c = "xrandr -s %s" % value
    retu = os.system(__c)
    if retu != 0:
        try:
            scrrent_list = common_run.get_screen_resolutionlist()
            first_value = "1024"
            last_value = "1024x768"
            for i in range(len(scrrent_list)):
                v = scrrent_list[i].split("x")[0]
                if int(v) > int(first_value):
                    last_value = scrrent_list[i]

            value = last_value
            settings.setValue("screen",value)
            __c = "xrandr -s %s" % value
            os.system(__c)

        except:
            value = "1024x768"
            settings.setValue("screen",value)
            __c = "xrandr -s %s" % value
            os.system(__c)


def set_ini_value(key, value):
    settings.setValue(key, value)


def get_ini_value(key):
    return settings.value(key).toString()
