コード例 #1
0
ファイル: model.cpp プロジェクト: kcsomisetty/cutewiki
Model::Model(HistoryModel* hm, FavModel* fm):
    m_url(""),
    m_hm(hm),
    m_fm(fm),
    m_showkeyboard(true),
    m_loadimages(true),
    m_busy(false),
    m_resultsmap(new QVariantMap()),
    m_error(""),
    m_searchString(""),
    m_fontsize(FONTSIZE),
    m_language(0),
    m_urlprefix("http://en."),
    m_favurl(false)
{
    LS("Model::Model =>>");

    m_dbhandler = new SmartboxHandler(this);

    QHash<int, QByteArray> roles;
    roles[0] = "title";

    setRoleNames(roles);
    roles.clear();

    QString fi(CONFIGFILE);
    QFile file( fi.toLower() );

    if(file.exists() && file.open( QIODevice::ReadOnly ))
    {
        QDataStream stream( &file );
        int configfileversion = 0;
        stream >> configfileversion; //version of config file
        //and then fontsize to use
        stream >> m_fontsize;

        bool var;
        stream >> var;
        setshowkeyboard(var);
        stream >> var;
        setloadimages(var);
        int lang = 0;
        stream >> lang;
        setlanguage(lang);

        if(m_hm)
            m_hm->readfromfile(stream);

        if(m_fm)
            m_fm->readfromfile(stream);
    }
コード例 #2
0
/*--------------------------------------------------------------------------*/
void setdefaultlanguage(const char * lang)
{

#ifdef _MSC_VER
    wchar_t *savedLanguage = getLanguagePreferences();
    wchar_t* pwstLang = to_wide_string(lang);
    if (wcscmp(pwstLang, savedLanguage))
    {
        if (setlanguage(pwstLang))
        {
            setLanguagePreferences();
        }
    }
#endif

}
コード例 #3
0
BOOL InitializeLocalization(void)
{
#ifdef HAVE_LIBINTL_H

    char *SCIpath = getSCIpath();
    char *pathLocales = NULL, *previousPathLocales = NULL;
    char *ret = NULL;

    /* set directory containing message catalogs */
    pathLocales = (char *)MALLOC(sizeof(char) * (strlen(SCIpath) + strlen(PATHLOCALIZATIONFILE) + 1));

    strcpy(pathLocales, SCIpath);
    strcat(pathLocales, PATHLOCALIZATIONFILE);
    if (bindtextdomain(NAMELOCALIZATIONDOMAIN, pathLocales) == NULL || !isdir(pathLocales))
    {
        /* source tree and classic build */
        previousPathLocales = strdup(pathLocales);
        if (pathLocales)
        {
            FREE(pathLocales);
            pathLocales = NULL;
        }

        pathLocales = (char *)MALLOC(sizeof(char) * (strlen(SCIpath) + strlen("/..") + strlen(PATHLOCALIZATIONFILE) + 1));
        strcpy(pathLocales, SCIpath);
        strcat(pathLocales, "/..");
        strcat(pathLocales, PATHLOCALIZATIONFILE);
        if (bindtextdomain(NAMELOCALIZATIONDOMAIN, pathLocales) == NULL || !isdir(pathLocales))
        {
            /* when it is installed on the system for example /usr/share/locale/ */
            fprintf(stderr, "Warning: Localization issue: Error while binding the domain from %s or %s: Switch to the default language (English).\n", pathLocales, previousPathLocales);

            // Set default behaviour
            textdomain(NAMELOCALIZATIONDOMAIN);
            bind_textdomain_codeset (NAMELOCALIZATIONDOMAIN, "UTF-8");
#ifndef _MSC_VER
            setlanguage("");
#else
            /* We look if registry value LANGUAGE exists */
            /* If not exists the "" means that we will try to use the language of the system.*/
            {
                char *loadLanguage = getLanguagePreferences();
                setlanguage(loadLanguage);
                if (loadLanguage)
                {
                    FREE(loadLanguage);
                    loadLanguage = NULL;
                }
            }
#endif

            if (previousPathLocales)
            {
                FREE(previousPathLocales);
                previousPathLocales = NULL;
            }
            if (pathLocales)
            {
                FREE(pathLocales);
                pathLocales = NULL;
            }
            if (SCIpath)
            {
                FREE(SCIpath);
                SCIpath = NULL;
            }
            return FALSE;
        }
        if (previousPathLocales)
        {
            FREE(previousPathLocales);
            previousPathLocales = NULL;
        }
        if (pathLocales)
        {
            FREE(pathLocales);
            pathLocales = NULL;
        }
        if (SCIpath)
        {
            FREE(SCIpath);
            SCIpath = NULL;
        }

    }

    /* set domain for future gettext() calls */
    ret = textdomain(NAMELOCALIZATIONDOMAIN);
    if (ret == NULL)
    {
        fprintf(stderr, "Localization: Error while declaring the text domain %s\n", NAMELOCALIZATIONDOMAIN);
        FREE(pathLocales);
        return FALSE;
    }
    bind_textdomain_codeset (NAMELOCALIZATIONDOMAIN, "UTF-8"); /*such that gettext and dgettext return UTF8 string*/
#ifndef _MSC_VER
    /* Here, the "" means that we will try to use the language of the system
     * first. If it doesn't work, we switch back to default (English) */
    setlanguage("");
#else
    /* We look if registry value LANGUAGE exists */
    /* If not exists the "" means that we will try to use the language of the system.*/
    {
        char *loadLanguage = getLanguagePreferences();
        setlanguage(loadLanguage);
        if (loadLanguage)
        {
            FREE(loadLanguage);
            loadLanguage = NULL;
        }
    }
#endif

    if (previousPathLocales)
    {
        FREE(previousPathLocales);
    }
    if (pathLocales)
    {
        FREE(pathLocales);
    }
    if (SCIpath)
    {
        FREE(SCIpath);
    }

    return TRUE;
#else
    fprintf(stderr, "Localization: setlocale didn't exist on the computer used to compile Scilab ! This is abnormal ! No localization will be working for this distribution of Scilab.\n");
    return FALSE;
#endif
}
コード例 #4
0
/*--------------------------------------------------------------------------*/
types::Function::ReturnValue sci_setdefaultlanguage(types::typed_list &in, int _piRetCount, types::typed_list &out)
{
    if (in.size() != 1)
    {
        Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), "setdefaultlanguage", 1);
        return types::Function::Error;
    }

    if (_piRetCount != 1)
    {
        Scierror(999, _("%s: Wrong number of output arguments: %d expected.\n"), "setdefaultlanguage", 1);
        return types::Function::Error;
    }

#ifndef _MSC_VER
    /*
    ** No need to set default language except under Windows.
    ** Will return FALSE
    */
    if (getWarningMode())
    {
        sciprint(_("%ls: This feature is only supported on Windows.\n"), L"setdefaultlanguage");
    }

    types::Bool* pbOut = new types::Bool(FALSE);
    out.push_back(pbOut);
    return types::Function::OK;
#else
    if (in[0]->isString() == false || in[0]->getAs<types::String>()->getSize() != 1)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), "setdefaultlanguage" , 1);
        return types::Function::Error;
    }
    wchar_t *newlang = getLanguageFromAlias(in[0]->getAs<types::String>()->get(0));

    if ( !isValidLanguage(newlang) )
    {
        if ( getWarningMode() )
        {
            sciprint(_("Unsupported language '%ls'.\n"), newlang);
        }
        out.push_back(new types::Bool(FALSE));

        return types::Function::OK;
    }
    else
    {
        wchar_t *savedLanguage = getLanguagePreferences();
        if ( wcscmp(newlang, savedLanguage) == 0 )
        {
            /* do nothing */
            out.push_back(new types::Bool(TRUE));

            return types::Function::OK;
        }
        else
        {
            // ??                if (savedLanguage) { FREE(savedLanguage); savedLanguage = NULL; }
            if ( !setlanguage(newlang) ) /* */
            {
                out.push_back(new types::Bool(FALSE));
                return types::Function::OK;
            }
            else
            {
                if ( getWarningMode() )
                {
                    sciprint("\n");
                    sciprint(_("The language for menus cannot be changed on a running console.\n"));
                    sciprint(_("Restart Scilab to apply to menus.\n"));
                }
                if ( setLanguagePreferences() )
                {
                    out.push_back(new types::Bool(TRUE));
                }
                else
                {
                    out.push_back(new types::Bool(FALSE));
                }
                return types::Function::OK;
            }
        }
    }

#endif
}