int main( int argc, char **argv ) { // Using QgsApplication instead of QApplication gives access to the // qgis translation files. QgsApplication a( argc, argv, true ); // Set up the QSettings environment must be done after a is created QCoreApplication::setOrganizationName( "QuantumGIS" ); QCoreApplication::setOrganizationDomain( "qgis.org" ); QCoreApplication::setApplicationName( "qgis" ); // Install translations if available. Based on the code in the Qgis // main.cpp file. // Let the user set the locale on the command line. If this program // needs to parse any more arguments, it'll be worthwhile using // something like getopt. QString translationCode; QStringList args = a.arguments(); int i = args.lastIndexOf( "-h" ); if ( i != -1 ) { std::cout << "Usage: msexport [--lang language]\n" "\t[--lang language]\tuse language for interface text (optional)\n"; exit( 0 ); } i = args.lastIndexOf( "--lang" ); if ( i != -1 ) { if ( args.count() > i + 1 ) translationCode = args[i+1]; } if ( translationCode.isEmpty() ) translationCode = QTextCodec::locale(); QString i18nPath = QgsApplication::i18nPath(); QTranslator qttor; if ( qttor.load( "qt_" + translationCode, i18nPath ) ) a.installTranslator( &qttor ); QTranslator mstor; if ( mstor.load( "qgis_" + translationCode, i18nPath ) ) a.installTranslator( &mstor ); QgsMapserverExport *mse = new QgsMapserverExport(); mse->show(); return a.exec(); }
QStringList Uninstaller::getAllSections() { QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, 0); QStringList allSections = installlog.childGroups(); allSections.removeAt(allSections.lastIndexOf("Bootloader")); return allSections; }
QWidget* PreferencesDialog::createPathTab(QWidget* parent) { QWidget* widget = new QWidget(parent); QVBoxLayout* vbox = new QVBoxLayout(widget); // QLabel* label = new QLabel(tr("&Save recorded calls here:"), widget); filesPathEdit = new QLineEdit(settings.filesDirectory(), widget); label->setBuddy(filesPathEdit); // connect(filesPathEdit, SIGNAL(textChanged(const QString &)), this, SLOT(updateAbsolutePathWarning(const QString &))); // QPushButton* button = new QPushButton("...", widget); connect(button, SIGNAL(clicked(bool)), this, SLOT(browseOutputPath())); QHBoxLayout *hbox = new QHBoxLayout; hbox->addWidget(filesPathEdit); hbox->addWidget(button); vbox->addWidget(label); vbox->addLayout(hbox); // label = new QLabel(tr("File &name:")); patternWidget = new QComboBox(widget); patternWidget->setEditable(true); patternWidget->setEditText(settings.filesNames()); label->setBuddy(patternWidget); QStringList patterns; patterns << tr("%Y-%m-%d %H:%M:%S Call with &s - %P") << tr("Call with &s, %a %b %d %Y, %H:%M:%S - %P") << tr("%Y, %B/Call with &s, %a %b %d %Y, %H:%M:%S - %P") << tr("&s/%Y-%m%d %H:%M:%S - %P") << tr("Calls with &s/Call with &s, %a %b %d %Y, %H:%M:%S - %P") << settings.filesNames(); patterns.removeDuplicates(); foreach(const QString& pattern, patterns) patternWidget->addItem(pattern); patternWidget->setCurrentIndex(patterns.lastIndexOf(settings.filesNames())); //Calls with &s/Call with &s, %Y-%m-%d, %H:%M:%S - %P connect(patternWidget, SIGNAL(editTextChanged(const QString &)), this, SLOT(updatePatternToolTip(const QString &))); connect(patternWidget, SIGNAL(editTextChanged(const QString &)), &settings, SLOT(setFilesNames(const QString &))); vbox->addWidget(label); vbox->addWidget(patternWidget); // vbox->addStretch(); // absolutePathWarningLabel = new QLabel(tr("<b>Warning:</b> The path you have entered is not an absolute path!"), widget); vbox->addWidget(absolutePathWarningLabel); // updatePatternToolTip(""); updateAbsolutePathWarning(settings.filesDirectory()); // return widget; }
QList<QSharedPointer<Icon> > Unpacker::getIcons(QString manifest, QString contents) { // Parse filenames: QStringList files; files.push_back(parse("application-icon-120:'(.+)'", manifest)); files.push_back(parse("application-icon-160:'(.+)'", manifest)); files.push_back(parse("application-icon-240:'(.+)'", manifest)); files.push_back(parse("application-icon-320:'(.+)'", manifest)); files.push_back(parse("application-icon-480:'(.+)'", manifest)); files.push_back(parse("application-icon-640:'(.+)'", manifest)); files.push_back(parse("banner='(.+)'", manifest)); qDebug() << "Icons:" << files; // Load icons: QList<QSharedPointer<Icon> > icons; for (short i = Dpi::LDPI; i < Dpi::COUNT; ++i) { QString filename = files[i]; if (!QFile::exists(contents + "/" + files[i])) { // Add "-v4" qualifier to handle Apktool behaviour: const QString V4 = files[i].section('/', 0, 1) + "-v4/" + files[i].section('/', 2); if (QFile::exists(contents + "/" + V4)) { filename = V4; } } if (filename.isEmpty()) { // Create dummy entry icons.push_back(QSharedPointer<Icon>( i != Dpi::BANNER ? new Icon : new Icon(contents + "/res/drawable-xhdpi-v4/banner.png"))); continue; } const int DUPL = files.lastIndexOf(filename, i - 1); if (i == 0 || DUPL == -1) { // Create new entry icons.push_back(QSharedPointer<Icon>(new Icon(contents + "/" + filename))); } else { // Reuse existing entry icons.push_back(icons[DUPL]); } } return icons; }
void tst_QStringList::lastIndexOf() { QStringList list; list << "harald" << "trond" << "vohi" << "harald"; QCOMPARE(list.lastIndexOf("harald"), 3); QCOMPARE(list.lastIndexOf("trond"), 1); QCOMPARE(list.lastIndexOf("vohi"), 2); QCOMPARE(list.lastIndexOf("harald", 2), 0); QCOMPARE(list.lastIndexOf("hans"), -1); QCOMPARE(list.lastIndexOf("vohi", 1), -1); QCOMPARE(list.lastIndexOf("vohi", -1), 2); QCOMPARE(list.lastIndexOf("vohi", -3), -1); }
int StringList::lastIndexOf ( lua_State * L )//( const QRegExp & rx, int from = -1 ) int { QStringList* lhs = ValueInstaller2<QStringList>::check( L, 1 ); QRegExp* rx = ValueInstaller2<QRegExp>::check( L, 2 ); int from = -1; if (Util::isNum( L, 3 ) ) { if ( Util::toInt( L, 3 ) < -1 ) { Util::error( L, "Starting No is invalid" ); } else { from = Util::toInt( L, 3 ); } } Util::push( L, lhs->lastIndexOf( *rx, from ) ); return 1; }
void tst_QStringList::lastIndexOf_regExp() { QStringList list; list << "harald" << "trond" << "vohi" << "harald"; QRegExp re(".*o.*"); QCOMPARE(list.lastIndexOf(re), 2); QCOMPARE(list.lastIndexOf(re, 2), 2); QCOMPARE(list.lastIndexOf(re, 1), 1); QCOMPARE(list.lastIndexOf(QRegExp(".*x.*")), -1); QCOMPARE(list.lastIndexOf(re, -1), 2); QCOMPARE(list.lastIndexOf(re, -3), 1); QCOMPARE(list.lastIndexOf(re, -9999), -1); QCOMPARE(list.lastIndexOf(re, 9999), 2); }
void GalleryTalker::slotResult(KJob *job) { KIO::Job *tempjob = static_cast<KIO::Job*>(job); if (tempjob->error()) { if (m_state == GE_LOGIN) { emit signalLoginFailed(tempjob->errorString()); } else { if (m_state == GE_ADDPHOTO) { emit signalAddPhotoFailed(tempjob->errorString()); } else { tempjob->ui()->setWindow(m_parent); tempjob->ui()->showErrorMessage(); } } emit signalBusy(false); return; } switch (m_state) { case(GE_LOGIN): parseResponseLogin(m_talker_buffer); break; case(GE_LISTALBUMS): parseResponseListAlbums(m_talker_buffer); break; case(GE_LISTPHOTOS): parseResponseListPhotos(m_talker_buffer); break; case(GE_CREATEALBUM): parseResponseCreateAlbum(m_talker_buffer); break; case(GE_ADDPHOTO): parseResponseAddPhoto(m_talker_buffer); break; } if (m_state == GE_LOGIN && m_loggedIn) { const QStringList cookielist = (tempjob->queryMetaData("setcookies")).split('\n'); m_cookie = "Cookie:"; if(!cookielist.isEmpty()) { QRegExp rx("^GALLERYSID=.+"); QString app; foreach(const QString &str, cookielist) { if(str.contains("Set-Cookie: ")) { const QStringList cl = str.split(' '); int n = cl.lastIndexOf(rx); if(n!= -1) { app = cl.at(n); } } } m_cookie += app; } tempjob->kill(); listAlbums(); }
bool cmdArgs(QStringList args) { bool server = false; if(args.lastIndexOf("-server")>=0) server = true; Preferences *prefsman = new Preferences(NULL); if(args.lastIndexOf("-exe")>=0) { prefsman->saveAnimeStudioPath(args.at(args.lastIndexOf("-exe")+1)); } if(args.lastIndexOf("-out")>=0) { prefsman->saveOutputDirectory(args.at(args.lastIndexOf("-out")+1)); } if(args.lastIndexOf("-format")>=0) { prefsman->saveOutputFormat(args.at(args.lastIndexOf("-format")+1).toInt()); } prefsman->saveSetFrameRange(true); if(args.lastIndexOf("-startframe")>=0) { prefsman->saveStartFrame(args.at(args.lastIndexOf("-startframe")+1).toInt()); prefsman->saveSetFrameRange(true); } else { prefsman->saveSetFrameRange(false); } if(args.lastIndexOf("-endframe")>=0) { prefsman->saveEndFrame(args.at(args.lastIndexOf("-endframe")+1).toInt()); prefsman->saveSetFrameRange(true); } else { prefsman->saveSetFrameRange(false); } if(args.lastIndexOf("-aa")>=0) { prefsman->saveAntialiasedEdges(args.at(args.lastIndexOf("-aa")+1)=="yes"?true:false); } if(args.lastIndexOf("-shapefx")>=0) { prefsman->saveApplyShapeEffects(args.at(args.lastIndexOf("-shapefx")+1)=="yes"?true:false); } if(args.lastIndexOf("-layerfx")>=0) { prefsman->saveApplyLayerEffects(args.at(args.lastIndexOf("-layerfx")+1)=="yes"?true:false); } if(args.lastIndexOf("-halfsize")>=0) { prefsman->saveRenderAtHalfDimensions(args.at(args.lastIndexOf("-halfsize")+1)=="yes"?true:false); } if(args.lastIndexOf("-halffps")>=0) { prefsman->saveRenderAtHalfFramerate(args.at(args.lastIndexOf("-halffps")+1)=="yes"?true:false); } if(args.lastIndexOf("-fewparticles")>=0) { prefsman->saveReducedParticles(args.at(args.lastIndexOf("-fewparticles")+1)=="yes"?true:false); } if(args.lastIndexOf("-extrasmooth")>=0) { prefsman->saveExtraSmoothImages(args.at(args.lastIndexOf("-extrasmooth")+1)=="yes"?true:false); } if(args.lastIndexOf("-ntscsafe")>=0) { prefsman->saveUseNTSCSafeColours(args.at(args.lastIndexOf("-ntscsafe")+1)=="yes"?true:false); } if(args.lastIndexOf("-premultiply")>=0) { // This option is weird prefsman->saveDoNotPremultiplyAlpha(args.at(args.lastIndexOf("-premultiply")+1)=="yes"?true:false); } if(args.lastIndexOf("-nopremultiply")>=0) { prefsman->saveDoNotPremultiplyAlpha(!(args.at(args.lastIndexOf("-nopremultiply")+1)=="yes"?true:false)); } if(args.lastIndexOf("-variablewidths")>=0) { prefsman->saveVariableLineWidths(args.at(args.lastIndexOf("-variablewidths")+1)=="yes"?true:false); } prefsman->deleteLater(); return server; }
QString elideText(const QString &text, const QFont &font, const QString &format, bool escapeAmpersands, int maxWidthPixels, int maxLines) { if (maxWidthPixels <= 0) maxWidthPixels = smallIconSize() * 20; QStringList lines = text.split('\n'); // Ignore empty lines at beginning. static const QRegExp reNonEmpty(".*\\S.*"); const int firstLine = qMax(0, lines.indexOf(reNonEmpty)); const int lastLine = qMax(0, lines.lastIndexOf(reNonEmpty, firstLine + maxLines - 1)); // If empty lines are at beginning, prepend triple dot. if (firstLine != 0) lines[firstLine].prepend("..."); // If there are too many lines, append triple dot. if (lastLine + 1 != lines.size()) lines[lastLine].append("..."); lines = lines.mid(firstLine, lastLine - firstLine + 1); QFontMetrics fm(font); const int formatWidth = format.isEmpty() ? 0 : fm.width(format.arg(QString())); // Remove redundant spaces from single line text. if (lines.size() == 1) lines[0] = lines[0].simplified(); // Find common indentation. int commonIndent = lines.value(0).size(); static const QRegExp reNonSpace("\\S"); for (const auto &line : lines) { const int lineIndent = line.indexOf(reNonSpace); if (lineIndent != -1 && lineIndent < commonIndent) { commonIndent = lineIndent; if (commonIndent == 0) break; } } // Remove common indentation each line and elide text if too long. for (auto &line : lines) { line = line.mid(commonIndent); // Make eliding huge text faster. if (line.size() > maxElidedTextLineLength) line = line.left(maxElidedTextLineLength) + "..."; line = fm.elidedText(line, Qt::ElideMiddle, maxWidthPixels - formatWidth); } QString result = lines.join("\n"); // Escape all ampersands. if (escapeAmpersands) result.replace( QChar('&'), QString("&&") ); return format.isEmpty() ? result : format.arg(result); }
void Application::parseArguments(QStringList args) { QFileInfo program(args.at(0)); QString programName("renderer"); if (program.exists()) programName = program.baseName(); if (args.contains("-h") || args.contains("-help") || args.contains("--help")) { std::cout << "Usage: " << programName.toLatin1().data() << " [-version]" << " [-gui]" << " [-bookjs path]" << " [-custom-css path]" << " [-output path]" << " URL" << std::endl; appQuit(0); } if (args.contains("-version")) { std::cout << applicationName().toLatin1().data() << " " << applicationVersion().toLatin1().data() #if defined(Q_PROCESSOR_X86_32) << " x86" #elif defined(Q_PROCESSOR_X86_64) << " amd64" #endif << std::endl; appQuit(0); } m_gui = args.contains("-gui"); int bookjsPathIndex = args.indexOf("-bookjs"); if (bookjsPathIndex != -1) { QString path = takeOptionValue(&args, bookjsPathIndex); QDir dir(path); if (! dir.exists()) { appQuit(1, QString("path does not point to a directory: %1").arg(path)); } m_rendererOptions.bookjsPath = dir.absolutePath(); } int cssPathIndex = args.indexOf("-custom-css"); if (cssPathIndex != -1) { QString path = takeOptionValue(&args, cssPathIndex); if (! QFileInfo(path).isReadable()) { appQuit(1, QString("file does not exist or is not readable: %1").arg(path)); } QFile file(path); if (! file.open(QFile::ReadOnly)) { appQuit(1, QString("cout not open file: %1").arg(path)); } m_rendererOptions.customCSS = QTextStream(&file).readAll(); } int outputPathIndex = args.indexOf("-output"); if (outputPathIndex != -1) m_rendererOptions.outputFilePath = takeOptionValue(&args, outputPathIndex); int lastArg = args.lastIndexOf(QRegExp("^-.*")); m_urls = (lastArg != -1) ? args.mid(++lastArg) : args.mid(1); }
void Updater::checkNewestVersion() { connect(socket, &Socket::connected, [this](){ state_ = State::CHK_VERSION; QJsonDocument doc; QJsonObject obj; obj.insert("request", QJsonValue(QString("check"))); doc.setObject(obj); socket->sendData(doc.toJson()); }); connect(socket, &Socket::error, [this](){ switch(state_){ case State::CHK_VERSION: state_ = State::CHK_ERROR; break; case State::DOWNLOAD_NEW: state_ = State::DOWNLOAD_ERROR; break; case State::OVERLAP: state_ = State::OVERLAP_ERROR; break; default: state_ = State::UNKNOWN_ERROR; } qDebug()<<socket->errorString(); }); connect(socket, &Socket::newData, [this](const QByteArray& data){ QJsonDocument doc = QJsonDocument::fromJson(data); QJsonObject obj = doc.object(); if(obj.isEmpty()){ state_ = State::CHK_ERROR; qDebug()<<"Check version error!"; quit(); } QJsonObject info = obj.value("info").toObject(); if(info.isEmpty()){ state_ = State::CHK_ERROR; qDebug()<<"Check version error!"; quit(); } QString version = info.value("version").toString().trimmed(); QString changelog = info.value("changelog").toString(); int level = info.value("level").toDouble(); QUrl url = QUrl::fromUserInput(DOWNLOAD_URL); QString fetched_url = info.value("url").toString(); if(!fetched_url.isEmpty()){ url = QUrl::fromUserInput(fetched_url); } QStringList commandList = qApp->arguments(); // --version should be considered first int index = commandList.lastIndexOf("--version"); // then we check if there is -v index = index>0?index:commandList.lastIndexOf("-v"); if(index < 0 || index >= commandList.count()){ qDebug()<<"parsing error!"<<"cannot find --version or -v"; printUsage(); quit(); } QString old_version = commandList[index+1].trimmed(); if(old_version.isEmpty()){ qDebug()<<"parsing error!"<<"version number is empty"; printUsage(); quit(); } if(version != old_version){ QMessageBox msgBox; msgBox.setText(tr("New version!")); if(level < 3) { msgBox.setIcon(QMessageBox::Information); msgBox.setText(tr("There's a new version of Mr.Paint.\n" "We suggest you download it here: %1") .arg(url.toDisplayString())); }else{ msgBox.setIcon(QMessageBox::Warning); msgBox.setText(tr("There's a critical update of Mr.Paint.\n" "You can connect to server ONLY if you've updated: %1") .arg(url.toDisplayString())); } if(!changelog.isEmpty()){ msgBox.setDetailedText(changelog); } msgBox.exec(); quit(); } }); socket->connectToHost(QHostAddress(SERVER_ADDRESS), SERVER_PORT); return; }