void MonoIcon::ensureLoaded() const { if (_size.isValid()) { return; } const uchar *data = _mask->data(); int size = _mask->size(); auto generateTag = qstr("GENERATE:"); if (size > generateTag.size() && !memcmp(data, generateTag.data(), generateTag.size())) { size -= generateTag.size(); data += generateTag.size(); auto sizeTag = qstr("SIZE:"); if (size > sizeTag.size() && !memcmp(data, sizeTag.data(), sizeTag.size())) { size -= sizeTag.size(); data += sizeTag.size(); QByteArray baForStream(reinterpret_cast<const char*>(data), size); QBuffer buffer(&baForStream); buffer.open(QIODevice::ReadOnly); QDataStream stream(&buffer); stream.setVersion(QDataStream::Qt_5_1); qint32 width = 0, height = 0; stream >> width >> height; t_assert(stream.status() == QDataStream::Ok); switch (cScale()) { case dbisOne: _size = QSize(width, height); break; case dbisOneAndQuarter: _size = QSize(pxAdjust(width, 5), pxAdjust(height, 5)); break; case dbisOneAndHalf: _size = QSize(pxAdjust(width, 6), pxAdjust(height, 6)); break; case dbisTwo: _size = QSize(width * 2, height * 2); break; } } else {
//This is intended to write the information of save data to QTableView. void save_data_info_dialog::UpdateData() { m_list->clearContents(); int num_entries = 4; // set this to number of members in struct m_list->setRowCount(num_entries); //Maybe there should be more details of save data. m_list->setItem(0, 0, new QTableWidgetItem(tr("User ID"))); m_list->setItem(0, 1, new QTableWidgetItem("00000001 (Default)")); m_list->setItem(1, 0, new QTableWidgetItem(tr("Title"))); m_list->setItem(1, 1, new QTableWidgetItem(qstr(m_entry.title))); m_list->setItem(2, 0, new QTableWidgetItem(tr("Subtitle"))); m_list->setItem(2, 1, new QTableWidgetItem(qstr(m_entry.subtitle))); m_list->setItem(3, 0, new QTableWidgetItem(tr("Detail"))); m_list->setItem(3, 1, new QTableWidgetItem(qstr(m_entry.details))); QImage img; if (m_entry.iconBuf.size() > 0 && img.loadFromData((uchar*)&m_entry.iconBuf[0], m_entry.iconBuf.size(), "PNG")) { m_list->insertRow(0); QTableWidgetItem* img_item = new QTableWidgetItem(); img_item->setData(Qt::DecorationRole, QPixmap::fromImage(img)); m_list->setItem(0, 0, new QTableWidgetItem(tr("Icon"))); m_list->setItem(0, 1, img_item); } }
bool UsernameBox::onUpdateFail(const RPCError &error) { if (MTP::isDefaultHandledError(error)) return false; _saveRequestId = 0; QString err(error.type()); if (err == qstr("USERNAME_NOT_MODIFIED") || _sentUsername == App::self()->username) { App::self()->setName(TextUtilities::SingleLine(App::self()->firstName), TextUtilities::SingleLine(App::self()->lastName), TextUtilities::SingleLine(App::self()->nameOrPhone), TextUtilities::SingleLine(_sentUsername)); closeBox(); return true; } else if (err == qstr("USERNAME_INVALID")) { _username->setFocus(); _username->showError(); _errorText = lang(lng_username_invalid); update(); return true; } else if (err == qstr("USERNAME_OCCUPIED") || err == qstr("USERNAMES_UNAVAILABLE")) { _username->setFocus(); _username->showError(); _errorText = lang(lng_username_occupied); update(); return true; } _username->setFocus(); return true; }
void filedialogInit() { if (cDialogLastPath().isEmpty()) { #ifdef Q_OS_WIN // hack to restore previous dir without hurting performance QSettings settings(QSettings::UserScope, qstr("QtProject")); settings.beginGroup(qstr("Qt")); QByteArray sd = settings.value(qstr("filedialog")).toByteArray(); QDataStream stream(&sd, QIODevice::ReadOnly); if (!stream.atEnd()) { int version = 3, _QFileDialogMagic = 190; QByteArray splitterState; QByteArray headerData; QList<QUrl> bookmarks; QStringList history; QString currentDirectory; qint32 marker; qint32 v; qint32 viewMode; stream >> marker; stream >> v; if (marker == _QFileDialogMagic && v == version) { stream >> splitterState >> bookmarks >> history >> currentDirectory >> headerData >> viewMode; cSetDialogLastPath(currentDirectory); }
bool PhoneWidget::phoneSubmitFail(const RPCError &error) { if (MTP::isFloodError(error)) { stopCheck(); _sentRequest = 0; showPhoneError(langFactory(lng_flood_error)); return true; } if (MTP::isDefaultHandledError(error)) return false; stopCheck(); _sentRequest = 0; auto &err = error.type(); if (err == qstr("PHONE_NUMBER_FLOOD")) { Ui::show(Box<InformBox>(lang(lng_error_phone_flood))); return true; } else if (err == qstr("PHONE_NUMBER_INVALID")) { // show error showPhoneError(langFactory(lng_bad_phone)); return true; } if (cDebug()) { // internal server error auto text = err + ": " + error.description(); showPhoneError([text] { return text; }); } else { showPhoneError(langFactory(lng_server_error)); } return false; }
bool IntroPwdCheck::pwdSubmitFail(const RPCError &error) { if (MTP::isFloodError(error)) { sentRequest = 0; stopCheck(); _codeField.setDisabled(false); showError(lang(lng_flood_error)); _pwdField.setDisabled(false); _pwdField.notaBene(); return true; } if (MTP::isDefaultHandledError(error)) return false; sentRequest = 0; stopCheck(); _pwdField.setDisabled(false); _codeField.setDisabled(false); const QString &err = error.type(); if (err == qstr("PASSWORD_HASH_INVALID")) { showError(lang(lng_signin_bad_password)); _pwdField.selectAll(); _pwdField.notaBene(); return true; } else if (err == qstr("PASSWORD_EMPTY")) { intro()->onBack(); } if (cDebug()) { // internal server error showError(err + ": " + error.description()); } else { showError(lang(lng_server_error)); } _pwdField.setFocus(); return false; }
void msg_dialog_frame::ProgressBarSetMsg(u32 index, const std::string& msg) { if (m_dialog) { if (index == 0 && m_text1) m_text1->setText(qstr(msg)); if (index == 1 && m_text2) m_text2->setText(qstr(msg)); } }
/** * Returns false if the game should be hidden because it doesn't match search term in toolbar. */ bool game_list_frame::SearchMatchesApp(const std::string& name, const std::string& serial) { if (m_Search_Bar->text() != "") { QString searchText = m_Search_Bar->text().toLower(); return qstr(name).toLower().contains(searchText) || qstr(serial).toLower().contains(searchText); } return true; }
void memory_viewer_panel::ShowMemory() { QString t_mem_addr_str; QString t_mem_hex_str; QString t_mem_ascii_str; for(u32 addr = m_addr; addr != m_addr + m_rowcount * m_colcount; addr += m_colcount) { t_mem_addr_str += qstr(fmt::format("%08x", addr)); if (addr != m_addr + m_rowcount * m_colcount - m_colcount) t_mem_addr_str += "\r\n"; } for (u32 row = 0; row < m_rowcount; row++) { for (u32 col = 0; col < m_colcount; col++) { u32 addr = m_addr + row * m_colcount + col; if (vm::check_addr(addr)) { const u8 rmem = vm::read8(addr); t_mem_hex_str += qstr(fmt::format("%02x ", rmem)); const bool isPrintable = rmem >= 32 && rmem <= 126; t_mem_ascii_str += qstr(isPrintable ? std::string(1, rmem) : "."); } else { t_mem_hex_str += "??"; t_mem_ascii_str += "?"; if (col != m_colcount - 1) t_mem_hex_str += " "; } } if (row != m_rowcount - 1) { t_mem_hex_str += "\r\n"; t_mem_ascii_str += "\r\n"; } } t_mem_addr->setText(t_mem_addr_str); t_mem_hex->setText(t_mem_hex_str); t_mem_ascii->setText(t_mem_ascii_str); // Adjust Text Boxes textSize = fontMetrics->size(0, t_mem_addr->text()); t_mem_addr->setFixedSize(textSize.width() + 10, textSize.height() + 10); textSize = fontMetrics->size(0, t_mem_hex->text()); t_mem_hex->setFixedSize(textSize.width() + 10, textSize.height() + 10); textSize = fontMetrics->size(0, t_mem_ascii->text()); t_mem_ascii->setFixedSize(textSize.width() + 10, textSize.height() + 10); }
QString telegramFaqLink() { QString result = qsl("https://telegram.org/faq"); if (cLang() > languageDefault && cLang() < languageCount) { const char *code = LanguageCodes[cLang()].c_str(); if (qstr("de") == code || qstr("es") == code || qstr("it") == code || qstr("ko") == code) { result += qsl("/") + code; } else if (qstr("pt_BR") == code) { result += qsl("/br"); } } return result; }
void cg_disasm_window::ShowDisasm() { if (QFileInfo(m_path_last).isFile()) { CgBinaryDisasm disasm(sstr(m_path_last)); disasm.BuildShaderBody(); m_disasm_text->setText(qstr(disasm.GetArbShader())); m_glsl_text->setText(qstr(disasm.GetGlslShader())); } else if (!m_path_last.isEmpty()) { LOG_ERROR(LOADER, "CgDisasm: Failed to open %s", sstr(m_path_last)); } }
bool DcOptions::loadFromFile(const QString &path) { QVector<MTPDcOption> options; QFile f(path); if (!f.open(QIODevice::ReadOnly)) { LOG(("MTP Error: could not read '%1'").arg(path)); return false; } QTextStream stream(&f); stream.setCodec("UTF-8"); while (!stream.atEnd()) { auto line = stream.readLine(); auto components = line.split(QRegularExpression(R"(\s)"), QString::SkipEmptyParts); if (components.isEmpty() || components[0].startsWith('#')) { continue; } auto error = [line] { LOG(("MTP Error: in .tdesktop-endpoints expected 'dcId host port [tcpo_only] [media_only]', got '%1'").arg(line)); return false; }; if (components.size() < 3) { return error(); } auto dcId = components[0].toInt(); auto ip = components[1]; auto port = components[2].toInt(); auto host = QHostAddress(); if (dcId <= 0 || dcId >= internal::kDcShift || !host.setAddress(ip) || port <= 0) { return error(); } auto flags = MTPDdcOption::Flags(0); if (host.protocol() == QAbstractSocket::IPv6Protocol) { flags |= MTPDdcOption::Flag::f_ipv6; } for (auto &option : components.mid(3)) { if (option.startsWith('#')) { break; } else if (option == qstr("tcpo_only")) { flags |= MTPDdcOption::Flag::f_tcpo_only; } else if (option == qstr("media_only")) { flags |= MTPDdcOption::Flag::f_media_only; } else { return error(); } } options.push_back(MTP_dcOption(MTP_flags(flags), MTP_int(dcId), MTP_string(ip), MTP_int(port))); }
bool MultiPropertySelector_accessor::set_value( const std::string& str ) { QString qstr( str.c_str() ); // str is just an element of an xml file, hence can not be parsed // by QDomDocument. We need to add a root element. qstr = "<root>" + qstr + "</root>"; QDomDocument doc; bool parsed = doc.setContent( qstr ); appli_assert( parsed ); QDomElement root_element = doc.documentElement(); QDomElement elem = root_element.firstChild().toElement(); QString count_str = elem.attribute( "count" ); int count = count_str.toInt(); QString prop_string = elem.attribute( "value" ); QStringList prop_list = QStringList::split( ";", prop_string ); for( int i = 0 ; i < prop_list.size() ; i++ ) { QString name = prop_list[i]; int id = 0; for( ; id < selector_->count() ; id++ ) { if( selector_->text( id ) == name ) { selector_->setCurrentItem( id ); break; } } } return true; }
void ChessWidget::onPutFEN() const { char fen[Board::FENsize]; cpos_.toFEN(fen); QString qstr(fen); QApplication::clipboard()->setText(qstr); }
bool EllipsoidInput_accessor::set_value( const std::string& str ) { QString qstr( str.c_str() ); // str is just an element of an xml file, hence can not be parsed // by QDomDocument. We need to add a root element. qstr = "<root>" + qstr + "</root>"; QDomDocument doc; bool parsed = doc.setContent( qstr ); appli_assert( parsed ); QDomElement root_element = doc.documentElement(); QDomElement elem = root_element.firstChild().toElement(); QString val = elem.attribute( "value" ); String_Op::string_pair rows = String_Op::split_string( val.ascii(), "\n", false ); std::vector<double> ranges = String_Op::to_numbers<double>( rows.first ); std::vector<double> angles = String_Op::to_numbers<double>( rows.second ); for( int i=ranges.size(); i < 3; i++ ) ranges.push_back( 0 ); for( int i=angles.size(); i < 3; i++ ) angles.push_back( 0 ); input_->set_ranges( ranges[0], ranges[1], ranges[2] ); input_->set_angles( angles[0], angles[1], angles[2] ); return true; }
bool GridSelector_accessor::set_value( const std::string& str ) { QString qstr( str.c_str() ); // str is just an element of an xml file, hence can not be parsed // by QDomDocument. We need to add a root element. qstr = "<root>" + qstr + "</root>"; QDomDocument doc; bool parsed = doc.setContent( qstr ); appli_assert( parsed ); QDomElement root_element = doc.documentElement(); QDomElement elem = root_element.firstChild().toElement(); QString value = elem.attribute( "value" ); // search if "value" is in the list of possible grids. If yes, select it int id = 0; for( ; id < selector_->count() ; id++ ) { if( selector_->text( id ) == value ) { selector_->setCurrentText( selector_->text(id) ); break; } } return true; }
Csv_input_mgrid_dialog::Csv_input_mgrid_dialog(std::ifstream& infile, QWidget* parent, const char* name ) : QWidget( parent ) { setupUi(this); std::streampos mark = infile.tellg(); std::string str; std::getline(infile, str); QString qstr(str.c_str()); QStringList property_names = qstr.split(","); X_col_name_->addItems(property_names); X_col_name_->addItem("None"); Y_col_name_->addItems(property_names); Y_col_name_->addItem("None"); Z_col_name_->addItems(property_names); Z_col_name_->addItem("None"); //Set default selection X_col_name_->setCurrentIndex(0); Y_col_name_->setCurrentIndex(std::min(1,property_names.size())); Z_col_name_->setCurrentIndex(std::min(2,property_names.size())); mask_col_name_->addItems(property_names); name_->setFocus(); }
void trophy_manager_dialog::ShowContextMenu(const QPoint& loc) { QPoint globalPos = m_trophy_tree->mapToGlobal(loc); QMenu* menu = new QMenu(); QTreeWidgetItem* item = m_trophy_tree->currentItem(); if (!item) { return; } QAction* show_trophy_dir = new QAction(tr("Open Trophy Dir"), menu); // Only two levels in this tree (ignoring root). So getting the index as such works. int db_ind; bool is_game_node = m_trophy_tree->indexOfTopLevelItem(item) != -1; if (is_game_node) { db_ind = item->data(1, Qt::UserRole).toInt(); } else { db_ind = item->parent()->data(1, Qt::UserRole).toInt(); } connect(show_trophy_dir, &QAction::triggered, [=]() { QString path = qstr(m_trophies_db[db_ind]->path); QDesktopServices::openUrl(QUrl("file:///" + path)); }); menu->addAction(show_trophy_dir); menu->exec(globalPos); }
void TempSensorManager::onTempData() { string output = QString(tempProcess->readAllStandardOutput()).toStdString(); // No data if (output.find("Temp =") == string::npos) { double now = time(NULL); double timeSince = now - lastTempUpdateAt; if (timeSince > resetThreshold) resetSensor(); return; } int index = output.find("Temp =") + 6; QString qstr(output.substr(index, output.find(" *C") - index).c_str()); double temp = qstr.toDouble(); temp = ((9.0/5.0) * temp) + 32; // filter bad data if (Temperature == -1 || abs(int(temp - Temperature)) < 10) Temperature = temp; index = output.find("Hum =") + 5; qstr = QString(output.substr(index, output.find(" %") - index).c_str()); double hum = qstr.toDouble(); if (Humidity == -1 || abs(int(hum - Humidity)) < 10) Humidity = hum; lastTempUpdateAt = time(NULL); emit TempUpdated(); }
void HiddenUrlClickHandler::Open(QString url, QVariant context) { url = tryConvertUrlToLocal(url); if (Core::InternalPassportLink(url)) { return; } const auto open = [=] { UrlClickHandler::Open(url, context); }; if (url.startsWith(qstr("tg://"), Qt::CaseInsensitive)) { open(); } else { const auto parsedUrl = QUrl::fromUserInput(url); if (UrlRequiresConfirmation(url)) { Core::App().hideMediaView(); const auto displayUrl = parsedUrl.isValid() ? parsedUrl.toDisplayString() : url; Ui::show( Box<ConfirmBox>( lang(lng_open_this_link) + qsl("\n\n") + displayUrl, lang(lng_open_link), [=] { Ui::hideLayer(); open(); }), LayerOption::KeepOther); } else { open(); } } }
void BotGameUrlClickHandler::onClick(ClickContext context) const { const auto url = tryConvertUrlToLocal(this->url()); if (Core::InternalPassportLink(url)) { return; } const auto open = [=] { UrlClickHandler::Open(url, context.other); }; if (url.startsWith(qstr("tg://"), Qt::CaseInsensitive)) { open(); } else if (!_bot || _bot->isVerified() || Local::isBotTrusted(_bot)) { open(); } else { const auto callback = [=, bot = _bot] { Ui::hideLayer(); Local::makeBotTrusted(bot); open(); }; Ui::show(Box<ConfirmBox>( lng_allow_bot_pass(lt_bot_name, _bot->name), lang(lng_allow_bot), callback)); } }
bool IntroPhone::phoneSubmitFail(const RPCError &error) { if (MTP::isFloodError(error)) { stopCheck(); sentRequest = 0; showError(lang(lng_flood_error)); enableAll(true); return true; } if (MTP::isDefaultHandledError(error)) return false; stopCheck(); sentRequest = 0; const QString &err = error.type(); if (err == qstr("PHONE_NUMBER_INVALID")) { // show error showError(lang(lng_bad_phone)); enableAll(true); return true; } if (cDebug()) { // internal server error showError(err + ": " + error.description()); } else { showError(lang(lng_server_error)); } enableAll(true); return false; }
/*! * \todo Implement */ quint32 languagesList(QStringList &opList) { QString qstr(""); return objectNamesList(qstr, opList); }
QString _getCrashReportFile(const QMimeData *m) { if (!m || m->urls().size() != 1 || !m->urls().at(0).isLocalFile()) return QString(); auto file = psConvertFileUrl(m->urls().at(0)); return file.endsWith(qstr(".telegramcrash"), Qt::CaseInsensitive) ? file : QString(); }
/* #<pydoc> def str2user(str): """ Insert C-style escape characters to string @return: new string with escape characters inserted """ pass #</pydoc> */ PyObject *py_str2user(const char *str) { qstring qstr(str); qstring retstr; qstr2user(&retstr, qstr); return PyString_FromString(retstr.c_str()); }
void emu_settings::EnhanceComboBox(QComboBox* combobox, SettingsType type, bool is_ranged, bool use_max, int max) { if (!combobox) { LOG_FATAL(GENERAL, "EnhanceComboBox '%s' was used with an invalid object", GetSettingName(type)); return; } if (is_ranged) { QStringList range = GetSettingOptions(type); int max_item = use_max ? max : range.last().toInt(); for (int i = range.first().toInt(); i <= max_item; i++) { combobox->addItem(QString::number(i), QVariant(QString::number(i))); } } else { for (QString setting : GetSettingOptions(type)) { combobox->addItem(tr(setting.toStdString().c_str()), QVariant(setting)); } } std::string selected = GetSetting(type); int index = combobox->findData(qstr(selected)); if (index == -1) { std::string def = GetSettingDefault(type); LOG_ERROR(GENERAL, "EnhanceComboBox '%s' tried to set an invalid value: %s. Setting to default: %s", GetSettingName(type), selected, def); combobox->setCurrentIndex(combobox->findData(qstr(def))); m_broken_types.insert(type); } else { combobox->setCurrentIndex(index); } connect(combobox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [=](int index) { SetSetting(type, sstr(combobox->itemData(index))); }); }
/** Do an HTTP GET of the directory on the server that has the * available traceroute sets. The directory listing is parsed * for links, and these are appended to the trsets vector. */ bool ServerComm::getTrSets(QStringList& trsets, bool popupOnError) { static bool in_progress = false; if ( in_progress ) return false; //in theory, a race condition is here. in_progress = true; trsets.clear(); QBuffer buf; buf.open(QBuffer::WriteOnly); QUrl url("http://trgen.ixmaps.ca/trsets/"); HttpGet hget(url, &buf); qDebug() << "HttpGet error " << hget.error(); QHttp::Error err = hget.error(); if ( err != QHttp::NoError ) { msgConnFailure(err, popupOnError); in_progress = false; return false; } // scan the Apache directory listing. This makes it easy to change deployment // of batch trace files. // To see what this is parsing, fetch the link in a browser and view source. char prefix_str[] = "<a href=\""; qDebug() << "prefix_str len is " << sizeof(prefix_str); QByteArray ba = buf.buffer(); char *s = ba.data(); qDebug() << "from server got: " << s; char *e = s + ba.count() - (sizeof(prefix_str)+2); // guard against read past buffer end while ( s < e ) { // look for <a href="something.trset" if ( strncmp(s, prefix_str, sizeof(prefix_str)-1) == 0 ) { // found a likely URL char *token = s+sizeof(prefix_str)-1; char *p; for ( p = token; *p != '"'; p++ ) { if ( p >= e ) goto end_buffer; } *p = '\0'; // stomp the closing quote -> string terminator if ( token[0] == '.' && token[1] == '/' ) token += 2; // ignore superfluous ./ in ./something.trset // Apache directory listing contains a few unwanted URLs beginning with ? or / // restrict filenames to those ending with ".trset" if ( token[0] != '?' && token[0] != '/' && strcmp(p-6, ".trset") == 0 ) { QString qstr(token); trsets << qstr; qDebug() << "getTrSets got " << qstr.toAscii().data(); } s = p+1; } else s++; } end_buffer: in_progress = false; return true; }
bool ChangePhoneBox::EnterPhone::sendPhoneFail(const QString &phoneNumber, const RPCError &error) { auto errorText = Lang::Hard::ServerError(); if (MTP::isFloodError(error)) { errorText = lang(lng_flood_error); } else if (MTP::isDefaultHandledError(error)) { return false; } else if (error.type() == qstr("PHONE_NUMBER_INVALID")) { errorText = lang(lng_bad_phone); } else if (error.type() == qstr("PHONE_NUMBER_OCCUPIED")) { Ui::show(Box<InformBox>(lng_change_phone_occupied(lt_phone, App::formatPhone(phoneNumber)), lang(lng_box_ok))); _requestId = 0; return true; } showError(errorText); _requestId = 0; return true; }
bool ApiWrap::gotSelfParticipantFail(ChannelData *channel, const RPCError &error) { if (mtpIsFlood(error)) return false; if (error.type() == qstr("USER_NOT_PARTICIPANT")) { channel->inviter = -1; } _selfParticipantRequests.remove(channel); return true; }
bool ConfirmPhoneBox::confirmFail(const RPCError &error) { auto errorText = lang(lng_server_error); if (MTP::isFloodError(error)) { errorText = lang(lng_flood_error); } else if (MTP::isDefaultHandledError(error)) { return false; } else { auto &errorType = error.type(); if (errorType == qstr("PHONE_CODE_EMPTY") || errorType == qstr("PHONE_CODE_INVALID")) { errorText = lang(lng_bad_code); } } _sendCodeRequestId = 0; _code->setDisabled(false); _code->setFocus(); showError(errorText); return true; }