void MainWindow::changeLanguage() { QWidget *lang_widget = new QWidget(this, Qt::Dialog); lang_widget->setWindowModality(Qt::WindowModal); lang_widget->setAttribute(Qt::WA_DeleteOnClose); #ifdef Q_OS_MAC lang_widget->setWindowTitle(tr("Change language")); #else lang_widget->setWindowTitle(tr("Change language - iTest")); #endif QGridLayout *lang_glayout = new QGridLayout(lang_widget); lang_glayout->setMargin(6); lang_glayout->setSpacing(6); QLabel *lang_label = new QLabel(lang_widget); lang_label->setText(tr("Select your preferred language")); lang_glayout->addWidget(lang_label, 0, 0); langComboBox = new QComboBox(lang_widget); QStringList langs(itest_i18n.keys()); langs.sort(); for (int i = 0; i < langs.count(); ++i) { langComboBox->addItem(langs.at(i)); if (langs.at(i) == "English") { langComboBox->setCurrentIndex(i); } } lang_glayout->addWidget(langComboBox, 1, 0); QDialogButtonBox *lang_buttonbox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, lang_widget); QObject::connect(lang_buttonbox, SIGNAL(accepted()), this, SLOT(langChanged())); QObject::connect(lang_buttonbox, SIGNAL(rejected()), lang_widget, SLOT(close())); lang_glayout->addWidget(lang_buttonbox, 2, 0); lang_widget->show(); }
int main(void) { struct lang Python; langs(&Python); // pasando un puntero a la estructura printf("lang1: %d\n", Python.lang1); // imprime "10" printf("lang2: %d\n", Python.lang2); // imprime "34" return 0; }
void IndicationHandlerService::handleEnqueue(Message* message) { if (!message) { return; } // l10n // Set the client's requested language into this service thread. // This will allow functions in this service to return messages // in the correct language. AutoPtr<CIMMessage> msg(dynamic_cast<CIMMessage *>(message)); if (msg.get() != NULL) { if (msg->thread_changed()) { AutoPtr<AcceptLanguages> langs(new AcceptLanguages(((AcceptLanguageListContainer)msg->operationContext.get(AcceptLanguageListContainer::NAME)).getLanguages())); Thread::setLanguages(langs.get()); langs.release(); } } else { Thread::clearLanguages(); } switch (message->getType()) { case CIM_HANDLE_INDICATION_REQUEST_MESSAGE: { AutoPtr<CIMHandleIndicationResponseMessage> response(_handleIndication( (CIMHandleIndicationRequestMessage*) message)); SendForget(response.get()); response.release(); break; } default: Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2, "IndicationHandlerService::handleEnqueue got unexpected " "message type '%u'", message->getType()); break; } }
void YandexTranslationService::loadLanguages(const QString &file, bool withAutodetect) { if (withAutodetect) { m_sourceLanguages << Language("", tr("Autodetect")); m_langCodeToName.insert("", tr("Autodetect")); } QFile f(file); if (f.open(QFile::Text | QFile::ReadOnly)) { const QVariant data = parseJson(f.readAll()); f.close(); if (data.isValid()) { QVariantMapIterator langs(data.toMap().value("langs").toMap()); while (langs.hasNext()) { langs.next(); const QString code = langs.key(); const QString name = langs.value().toString(); m_langCodeToName.insert(code, name); } QSet<QString> duplicates; foreach (const QString &dirs, data.toMap().value("dirs").toStringList()) { const QStringList pair = dirs.split("-"); if (!duplicates.contains(pair.at(0))) { const QString code = pair.at(0); const QString name = m_langCodeToName.value(pair.at(0)); m_sourceLanguages << Language(code, name); m_targetLanguages[""] << Language(code, name); duplicates.insert(pair.at(0)); } m_targetLanguages[pair.at(0)] << Language(pair.at(1), m_langCodeToName.value(pair.at(1))); } } }
std::vector<std::string> Thesaurus::GetLanguageList() const { if (languages.empty()) boost::set_intersection(langs("idx"), langs("dat"), back_inserter(languages)); return languages; }
void CIMOperationRequestAuthorizer::handleEnqueue(Message *request) { PEG_METHOD_ENTER(TRC_SERVER, "CIMOperationRequestAuthorizer::handleEnqueue"); if (!request) { PEG_METHOD_EXIT(); return; } AutoPtr<CIMOperationRequestMessage> req(dynamic_cast<CIMOperationRequestMessage *>(request)); PEGASUS_ASSERT(req.get()); // // Get the HTTPConnection queue id // QueueIdStack qis = req->queueIds.copyAndPop(); Uint32 queueId = qis.top(); // l10n // Set the client's requested language into this service thread. // This will allow functions in this service to return messages // in the correct language. if (req->thread_changed()) { AutoPtr<AcceptLanguages> langs(new AcceptLanguages(((AcceptLanguageListContainer)req->operationContext.get (AcceptLanguageListContainer:: NAME)).getLanguages())); Thread::setLanguages(langs.release()); } // // If CIMOM is shutting down, return "Service Unavailable" response // if (_serverTerminating) { Array<char> message; message = XmlWriter::formatHttpErrorRspMessage( HTTP_STATUS_SERVICEUNAVAILABLE, String::EMPTY, "CIM Server is shutting down."); sendResponse(queueId, message); PEG_METHOD_EXIT(); return; } String userName = String::EMPTY; String authType = String::EMPTY; CIMNamespaceName nameSpace; String cimMethodName = String::EMPTY; // Set the username and namespace. nameSpace = req->nameSpace; userName = ((IdentityContainer)(req->operationContext.get (IdentityContainer::NAME))).getUserName(); switch (req->getType()) { case CIM_GET_CLASS_REQUEST_MESSAGE: authType = ((CIMGetClassRequestMessage*)req.get())->authType; cimMethodName = "GetClass"; break; case CIM_GET_INSTANCE_REQUEST_MESSAGE: authType = ((CIMGetInstanceRequestMessage*)req.get())->authType; cimMethodName = "GetInstance"; break; case CIM_DELETE_CLASS_REQUEST_MESSAGE: authType = ((CIMDeleteClassRequestMessage*)req.get())->authType; cimMethodName = "DeleteClass"; break; case CIM_DELETE_INSTANCE_REQUEST_MESSAGE: authType = ((CIMDeleteInstanceRequestMessage*)req.get())->authType; cimMethodName = "DeleteInstance"; break; case CIM_CREATE_CLASS_REQUEST_MESSAGE: authType = ((CIMCreateClassRequestMessage*)req.get())->authType; cimMethodName = "CreateClass"; break; case CIM_CREATE_INSTANCE_REQUEST_MESSAGE: authType = ((CIMCreateInstanceRequestMessage*)req.get())->authType; cimMethodName = "CreateInstance"; break; case CIM_MODIFY_CLASS_REQUEST_MESSAGE: authType = ((CIMModifyClassRequestMessage*)req.get())->authType; cimMethodName = "ModifyClass"; break; case CIM_MODIFY_INSTANCE_REQUEST_MESSAGE: authType = ((CIMModifyInstanceRequestMessage*)req.get())->authType; cimMethodName = "ModifyInstance"; break; case CIM_ENUMERATE_CLASSES_REQUEST_MESSAGE: authType = ((CIMEnumerateClassesRequestMessage*)req.get())->authType; cimMethodName = "EnumerateClasses"; break; case CIM_ENUMERATE_CLASS_NAMES_REQUEST_MESSAGE: authType = ((CIMEnumerateClassNamesRequestMessage*)req.get())->authType; cimMethodName = "EnumerateClassNames"; break; case CIM_ENUMERATE_INSTANCES_REQUEST_MESSAGE: authType = ((CIMEnumerateInstancesRequestMessage*)req.get())->authType; cimMethodName = "EnumerateInstances"; break; case CIM_ENUMERATE_INSTANCE_NAMES_REQUEST_MESSAGE: authType = ((CIMEnumerateInstanceNamesRequestMessage*)req.get())->authType; cimMethodName = "EnumerateInstanceNames"; break; case CIM_EXEC_QUERY_REQUEST_MESSAGE: authType = ((CIMExecQueryRequestMessage*)req.get())->authType; cimMethodName = "ExecQuery"; break; case CIM_ASSOCIATORS_REQUEST_MESSAGE: authType = ((CIMAssociatorsRequestMessage*)req.get())->authType; cimMethodName = "Associators"; break; case CIM_ASSOCIATOR_NAMES_REQUEST_MESSAGE: authType = ((CIMAssociatorNamesRequestMessage*)req.get())->authType; cimMethodName = "AssociatorNames"; break; case CIM_REFERENCES_REQUEST_MESSAGE: authType = ((CIMReferencesRequestMessage*)req.get())->authType; cimMethodName = "References"; break; case CIM_REFERENCE_NAMES_REQUEST_MESSAGE: authType = ((CIMReferenceNamesRequestMessage*)req.get())->authType; cimMethodName = "ReferenceNames"; break; case CIM_GET_PROPERTY_REQUEST_MESSAGE: authType = ((CIMGetPropertyRequestMessage*)req.get())->authType; cimMethodName = "GetProperty"; break; case CIM_SET_PROPERTY_REQUEST_MESSAGE: authType = ((CIMSetPropertyRequestMessage*)req.get())->authType; cimMethodName = "SetProperty"; break; case CIM_GET_QUALIFIER_REQUEST_MESSAGE: authType = ((CIMGetQualifierRequestMessage*)req.get())->authType; cimMethodName = "GetQualifier"; break; case CIM_SET_QUALIFIER_REQUEST_MESSAGE: authType = ((CIMSetQualifierRequestMessage*)req.get())->authType; cimMethodName = "SetQualifier"; break; case CIM_DELETE_QUALIFIER_REQUEST_MESSAGE: authType = ((CIMDeleteQualifierRequestMessage*)req.get())->authType; cimMethodName = "DeleteQualifier"; break; case CIM_ENUMERATE_QUALIFIERS_REQUEST_MESSAGE: authType = ((CIMEnumerateQualifiersRequestMessage*)req.get())->authType; cimMethodName = "EnumerateQualifiers"; break; case CIM_INVOKE_METHOD_REQUEST_MESSAGE: authType = ((CIMInvokeMethodRequestMessage*)req.get())->authType; cimMethodName = "InvokeMethod"; break; default: PEGASUS_ASSERT(0); break; } #ifdef PEGASUS_ENABLE_USERGROUP_AUTHORIZATION // // If the user is not privileged and authorized user group is specified, // then perform the user group authorization check. // try { if ( ! System::isPrivilegedUser(userName) ) { Uint32 size = _authorizedUserGroups.size(); if (size > 0) { Boolean authorized = false; // // Check if the user name is in the authorized user groups. // for (Uint32 i = 0; i < size; i++) { // // Check if the user is a member of the group // if ( System::isGroupMember(userName.getCString(), _authorizedUserGroups[i].getCString()) ) { authorized = true; break; } } // // If the user is not a member of any of the authorized // user groups then generate error response. // if (!authorized) { PEG_TRACE_STRING(TRC_SERVER, Tracer::LEVEL2, "Authorization Failed: User '" + userName + "' is not a member of the authorized groups"); MessageLoaderParms msgLoaderParms( "Server.CIMOperationRequestAuthorizer.NOT_IN_AUTHORIZED_GRP", "User '$0' is not authorized to access CIM data.", userName); // // user is not in the authorized user groups, send an // error message to the requesting client. // if (cimMethodName == "InvokeMethod") { // l10n sendMethodError( queueId, req->getHttpMethod(), req->messageId, ((CIMInvokeMethodRequestMessage*)req.get())->methodName, PEGASUS_CIM_EXCEPTION_L(CIM_ERR_ACCESS_DENIED, msgLoaderParms)); PEG_METHOD_EXIT(); return; } else { // l10n sendIMethodError( queueId, req->getHttpMethod(), req->messageId, cimMethodName, PEGASUS_CIM_EXCEPTION_L(CIM_ERR_ACCESS_DENIED, msgLoaderParms)); PEG_METHOD_EXIT(); return; } } } } } catch (InternalSystemError &ise) { sendIMethodError( queueId, req->getHttpMethod(), req->messageId, cimMethodName, PEGASUS_CIM_EXCEPTION(CIM_ERR_ACCESS_DENIED, ise.getMessage())); PEG_METHOD_EXIT(); return; } #endif // #ifdef PEGASUS_ENABLE_USERGROUP_AUTHORIZATION // // Get a config manager instance // ConfigManager* configManager = ConfigManager::getInstance(); // // Do namespace authorization verification // if (String::equalNoCase( configManager->getCurrentValue("enableNamespaceAuthorization"), "true")) { // // If the user is not privileged, perform the authorization check. // #if !defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM) if ( ! System::isPrivilegedUser(userName) ) #else // On OS/400, always check authorization if remote user. // Always allow local privileged users through. // Check authorization for local non-privileged users. // (User authorization to providers are checked downstream from here). if ( ! String::equalNoCase(authType,"Local") || ! System::isPrivilegedUser(userName) ) #endif { UserManager* userManager = UserManager::getInstance(); if ( !userManager || !userManager->verifyAuthorization( userName, nameSpace, cimMethodName) ) { // l10n // String description = "Not authorized to run "; // description.append(cimMethodName); // description.append(" in the namespace "); // description.append(nameSpace.getString()); if (cimMethodName == "InvokeMethod") { // l10n sendMethodError( queueId, req->getHttpMethod(), req->messageId, ((CIMInvokeMethodRequestMessage*)req.get())->methodName, PEGASUS_CIM_EXCEPTION_L(CIM_ERR_ACCESS_DENIED, MessageLoaderParms( "Server.CIMOperationRequestAuthorizer.NOT_AUTHORIZED", "Not authorized to run $0 in the namespace $1", cimMethodName, nameSpace.getString()))); } else { // l10n sendIMethodError( queueId, req->getHttpMethod(), req->messageId, cimMethodName, PEGASUS_CIM_EXCEPTION_L(CIM_ERR_ACCESS_DENIED, MessageLoaderParms( "Server.CIMOperationRequestAuthorizer.NOT_AUTHORIZED", "Not authorized to run $0 in the namespace $1", cimMethodName, nameSpace.getString()))); } PEG_METHOD_EXIT(); return; } } } // // If the user is privileged, and remote privileged user access is not // enabled and the auth type is not Local then reject access. // if ( System::isPrivilegedUser(userName) && !String::equalNoCase(authType, "Local") && !String::equalNoCase( configManager->getCurrentValue("enableRemotePrivilegedUserAccess"), "true") ) { if (cimMethodName == "InvokeMethod") { // l10n sendMethodError( queueId, req->getHttpMethod(), req->messageId, ((CIMInvokeMethodRequestMessage*)req.get())->methodName, PEGASUS_CIM_EXCEPTION_L(CIM_ERR_ACCESS_DENIED, MessageLoaderParms( "Server.CIMOperationRequestAuthorizer.REMOTE_NOT_ENABLED", "Remote privileged user access is not enabled."))); } else { // l10n sendIMethodError( queueId, req->getHttpMethod(), req->messageId, cimMethodName, PEGASUS_CIM_EXCEPTION_L(CIM_ERR_ACCESS_DENIED, MessageLoaderParms( "Server.CIMOperationRequestAuthorizer.REMOTE_NOT_ENABLED", "Remote privileged user access is not enabled."))); } PEG_METHOD_EXIT(); return; } // // Enqueue the request // _outputQueue->enqueue(req.release()); PEG_METHOD_EXIT(); }
OptionMenu::OptionMenu() : m_background("core/menu/wood"), m_blackboard("core/menu/blackboard"), ok_button(), x_pos(), y_pos(), options(), fullscreen_box(), software_cursor_box(), autoscroll_box(), dragdrop_scroll_box(), mousegrab_box(), printfps_box(), master_volume_box(), sound_volume_box(), music_volume_box(), //defaults_label(), //defaults_box(), connections(), m_language(), m_language_map() { gui_manager->add(ok_button = new OptionMenuCloseButton(this, Display::get_width()/2 + 245, Display::get_height()/2 + 150)); x_pos = 0; y_pos = 0; ChoiceBox* resolution_box = new ChoiceBox(Rect()); { std::vector<SDL_DisplayMode> resolutions = Display::get_fullscreen_video_modes(); Size fullscreen = config_manager.get_fullscreen_resolution(); int choice = static_cast<int>(resolutions.size()) - 1; for (auto it = resolutions.begin(); it != resolutions.end(); ++it) { // add resolution to the box std::ostringstream ostr; ostr << it->w << "x" << it->h << "@" << it->refresh_rate; resolution_box->add_choice(ostr.str()); // FIXME: ignoring refresh_rate if (fullscreen.width == it->w && fullscreen.height == it->h) { choice = static_cast<int>(it - resolutions.begin()); } } resolution_box->set_current_choice(choice); } ChoiceBox* renderer_box = new ChoiceBox(Rect()); renderer_box->add_choice("sdl"); renderer_box->add_choice("delta"); renderer_box->add_choice("opengl"); switch(config_manager.get_renderer()) { case SDL_FRAMEBUFFER: renderer_box->set_current_choice(0); break; case DELTA_FRAMEBUFFER: renderer_box->set_current_choice(1); break; case OPENGL_FRAMEBUFFER: renderer_box->set_current_choice(2); break; default: assert(!"unknown renderer type"); } m_language = dictionary_manager.get_language(); ChoiceBox* language_box = new ChoiceBox(Rect()); { std::set<tinygettext::Language> languages = dictionary_manager.get_languages(); // English is the default language, thus it's not in the list of // languages returned by tinygettext and we have to add it manually languages.insert(tinygettext::Language::from_name("en")); std::vector<tinygettext::Language> langs(languages.begin(), languages.end()); std::sort(langs.begin(), langs.end(), LanguageSorter()); for (auto i = langs.begin(); i != langs.end(); ++i) { m_language_map[i->get_name()] = *i; language_box->add_choice(i->get_name()); if (m_language == *i) { language_box->set_current_choice(static_cast<int>(i - langs.begin())); } } } ChoiceBox* scroll_box = new ChoiceBox(Rect()); scroll_box->add_choice("Drag&Drop"); scroll_box->add_choice("Rubberband"); software_cursor_box = new CheckBox(Rect()); fullscreen_box = new CheckBox(Rect()); autoscroll_box = new CheckBox(Rect()); dragdrop_scroll_box = new CheckBox(Rect()); mousegrab_box = new CheckBox(Rect()); printfps_box = new CheckBox(Rect()); master_volume_box = new SliderBox(Rect(), 25); sound_volume_box = new SliderBox(Rect(), 25); music_volume_box = new SliderBox(Rect(), 25); master_volume_box->set_value(config_manager.get_master_volume()); sound_volume_box->set_value(config_manager.get_sound_volume()); music_volume_box->set_value(config_manager.get_music_volume()); C(software_cursor_box->on_change.connect(std::bind(&OptionMenu::on_software_cursor_change, this, std::placeholders::_1))); C(fullscreen_box->on_change.connect(std::bind(&OptionMenu::on_fullscreen_change, this, std::placeholders::_1))); C(autoscroll_box->on_change.connect(std::bind(&OptionMenu::on_autoscroll_change, this, std::placeholders::_1))); C(dragdrop_scroll_box->on_change.connect(std::bind(&OptionMenu::on_drag_drop_scrolling_change, this, std::placeholders::_1))); C(mousegrab_box->on_change.connect(std::bind(&OptionMenu::on_mousegrab_change, this, std::placeholders::_1))); C(printfps_box->on_change.connect(std::bind(&OptionMenu::on_printfps_change, this, std::placeholders::_1))); C(master_volume_box->on_change.connect(std::bind(&OptionMenu::on_master_volume_change, this, std::placeholders::_1))); C(sound_volume_box->on_change.connect(std::bind(&OptionMenu::on_sound_volume_change, this, std::placeholders::_1))); C(music_volume_box->on_change.connect(std::bind(&OptionMenu::on_music_volume_change, this, std::placeholders::_1))); C(language_box->on_change.connect(std::bind(&OptionMenu::on_language_change, this, std::placeholders::_1))); C(resolution_box->on_change.connect(std::bind(&OptionMenu::on_resolution_change, this, std::placeholders::_1))); C(renderer_box->on_change.connect(std::bind(&OptionMenu::on_renderer_change, this, std::placeholders::_1))); x_pos = 0; y_pos = 0; add_item(_("Fullscreen"), fullscreen_box); add_item(_("Mouse Grab"), mousegrab_box); y_pos += 1; add_item(_("Software Cursor"), software_cursor_box); add_item(_("Autoscrolling"), autoscroll_box); add_item(_("Drag&Drop Scrolling"), dragdrop_scroll_box); y_pos += 1; add_item(_("Print FPS"), printfps_box); x_pos = 1; y_pos = 0; add_item(_("Resolution:"), resolution_box); add_item(_("Renderer:"), renderer_box); y_pos += 1; add_item(_("Language:"), language_box); y_pos += 1; add_item(_("Master Volume:"), master_volume_box); add_item(_("Sound Volume:"), sound_volume_box); add_item(_("Music Volume:"), music_volume_box); // Connect with ConfigManager mousegrab_box->set_state(config_manager.get_mouse_grab(), false); C(config_manager.on_mouse_grab_change.connect(std::bind(&CheckBox::set_state, mousegrab_box, std::placeholders::_1, false))); printfps_box->set_state(config_manager.get_print_fps(), false); C(config_manager.on_print_fps_change.connect(std::bind(&CheckBox::set_state, printfps_box, std::placeholders::_1, false))); fullscreen_box->set_state(config_manager.get_fullscreen(), false); C(config_manager.on_fullscreen_change.connect(std::bind(&CheckBox::set_state, fullscreen_box, std::placeholders::_1, false))); software_cursor_box->set_state(config_manager.get_software_cursor(), false); C(config_manager.on_software_cursor_change.connect(std::bind(&CheckBox::set_state, software_cursor_box, std::placeholders::_1, false))); autoscroll_box->set_state(config_manager.get_auto_scrolling(), false); C(config_manager.on_auto_scrolling_change.connect(std::bind(&CheckBox::set_state, autoscroll_box, std::placeholders::_1, false))); dragdrop_scroll_box->set_state(config_manager.get_drag_drop_scrolling(), false); C(config_manager.on_drag_drop_scrolling_change.connect(std::bind(&CheckBox::set_state, dragdrop_scroll_box, std::placeholders::_1, false))); /* defaults_label = new Label(_("Reset to Defaults:"), Rect(Vector2i(Display::get_width()/2 - 100, Display::get_height()/2 + 160), Size(170, 32))); gui_manager->add(defaults_label); defaults_box = new CheckBox(Rect(Vector2i(Display::get_width()/2 - 100 + 170, Display::get_height()/2 + 160), Size(32, 32))); gui_manager->add(defaults_box); */ }