QStringList TikzCommandInserter::getCommandWords() { QStringList words; QString word; QRegExp rx1("^([^a-z\\\\<>]*<[^>]*>)*"); QRegExp rx2("^[^a-z\\\\]*"); QString allowedLetters = "abcdefghijklmnopqrstuvwxyz\\"; for (int i = 0; i < m_tikzCommandsList.size(); ++i) { word = m_tikzCommandsList.at(i).description; // remove all special characters and <options> at the beginning of the word if (!word.isEmpty() && !allowedLetters.contains(word.at(0))) // minimize the number of uses of QRegExp { word.remove(rx1); word.remove(rx2); } if (!word.isEmpty()) words.append(word); else { word = m_tikzCommandsList.at(i).command; // remove all special characters and <options> at the beginning of the word if (!word.isEmpty() && !allowedLetters.contains(word.at(0))) // minimize the number of uses of QRegExp { word.remove(rx1); word.remove(rx2); } if (!word.isEmpty()) words.append(word); } } return words; }
DiscData DiscName::split(const QString & disc_url, bool * ok) { qDebug("DiscName::split: disc_url: '%s'", disc_url.toUtf8().constData()); QRegExp rx1("^(dvd|dvdnav|vcd|cdda)://(\\d+)/(.*)"); QRegExp rx2("^(dvd|dvdnav|vcd|cdda)://(\\d+)"); QRegExp rx3("^(dvd|dvdnav|vcd|cdda):///(.*)"); QRegExp rx4("^(dvd|dvdnav|vcd|cdda):(.*)"); DiscData d; bool success = false; if (rx1.indexIn(disc_url) != -1) { d.protocol = rx1.cap(1); d.title = rx1.cap(2).toInt(); d.device = rx1.cap(3); success = true; } else if (rx2.indexIn(disc_url) != -1) { d.protocol = rx2.cap(1); d.title = rx2.cap(2).toInt(); d.device = ""; success = true; } else if (rx3.indexIn(disc_url) != -1) { d.protocol = rx3.cap(1); d.title = 0; d.device = rx3.cap(2); success = true; } else if (rx4.indexIn(disc_url) != -1) { d.protocol = rx4.cap(1); d.title = 0; d.device =""; success = true; } if (!d.device.isEmpty()) d.device = removeTrailingSlash(d.device); if (success) { qDebug("DiscName::split: protocol: '%s'", d.protocol.toUtf8().constData()); qDebug("DiscName::split: title: '%d'", d.title); qDebug("DiscName::split: device: '%s'", d.device.toUtf8().constData()); } else { qWarning("DiscName::split: no match in regular expression"); } if (ok != 0) (*ok) = success; return d; }
void searchhandler::perform_search(QString searchtxt, bool exactmatch, sqlquery::en_queryType qrytyp, int selectitem, bool updSearchMemory) { if (sq->isDBOpen() == false) return; if (searchtxt.isEmpty()) return; sqlqueryresultlist sqlresultlist; QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); if (m_autocompBusy) { m_autocompBusy = false; m_autocompFutureWatcher.waitForFinished(); } sqlquery::en_queryType querytype = qrytyp; if (querytype == sqlquery::sqlresultDEFAULT) querytype = (sqlquery::en_queryType)m_comboBoxQueryType->itemData(m_comboBoxQueryType->currentIndex()).toInt(); sqlresultlist = sq->search(searchtxt.toAscii().data(), querytype, exactmatch); QApplication::restoreOverrideCursor(); if (sqlresultlist.result_type == sqlqueryresultlist::sqlresultERROR) { QMessageBox msgBox((QWidget*)mw); msgBox.setText(str2qt(sqlresultlist.sqlerrmsg)); msgBox.exec(); } else { m_pushButtonGraph->setEnabled((querytype == sqlquery::sqlresultFUNC_MACRO)|| (querytype == sqlquery::sqlresultCLASS_STRUCT)); if (m_checkBoxHeaderFilesOnly->isChecked()) { QRegExp rx1("\\.h([xp]{0,2})$", Qt::CaseInsensitive); unsigned int n = sqlresultlist.resultlist.size(); int pos; sqlqueryresultlist oldlist(sqlresultlist); sqlresultlist.resultlist.clear(); for(unsigned int i=0; i<n; i++) { pos = rx1.indexIn(str2qt(oldlist.resultlist[i].filename)); if (pos != -1) sqlresultlist.resultlist.push_back(oldlist.resultlist[i]); } } updateSearchHistory(searchtxt); if (updSearchMemory) addToSearchMemory(searchtxt); emit searchresults(sqlresultlist, selectitem); QString str; str = QString("%1").arg(sqlresultlist.resultlist.size()); str += " "; str += tr("results found"); emit updateStatus(str, 5000); } }
void NewProjectWizard::accept() { int type = field("projectType").toInt(); QString projectName = field("projectName").toString(); QString projectLocation = field("projectLocation").toString(); QString projectPath = field("projectPath").toString(); valid = false; QString projectType; switch (type) { case 0: projectType = "C"; break; case 1: projectType = "C++"; break; default: projectType = "C++"; break; } QRegExp rx1("^\\s*"); QRegExp rx2("\\s*$"); QRegExp rx3("/$"); projectName.remove(rx1); projectName.remove(rx2); projectLocation.remove(rx1); projectLocation.remove(rx2); projectLocation.remove(rx3); FileTools fileTools; if (!fileTools.mkdir(projectPath)) { QMessageBox::warning(0, QObject::tr("创建目录失败"), QObject::tr("%1") .arg(fileTools.errorString())); return; } if (!QFile::copy(Global::projectConfigTemplate(), projectPath + "/project.small")) { QMessageBox::warning(0, QObject::tr("创建项目配置文件失败"), QObject::tr("copy from:%1 \ncopy to:%2") .arg(Global::projectConfigTemplate()) .arg(projectPath + "/project.small")); return; } QSettings *settings = new QSettings(projectPath + "/project.small", QSettings::IniFormat); settings->setValue("Type", projectType); settings->setValue("Name", projectName); settings->sync(); delete settings; valid = true; path = projectPath; QDialog::accept(); }
void fileviewer::updateTextEdit(void) { if (m_iter == m_fileDataList.end()) return; QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); m_textEditSource->clear(); QFile file(m_iter->filename); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { QApplication::restoreOverrideCursor(); return; } QTextStream in(&file); int lang = enHighlightCPP; // default QRegExp rx1("\\.py$", Qt::CaseInsensitive); int pos = rx1.indexIn(m_iter->filename); if (pos != -1) lang = enHighlightPython; QRegExp rx2("\\.java$", Qt::CaseInsensitive); pos = rx2.indexIn(m_iter->filename); if (pos != -1) lang = enHighlightJava; QRegExp rx3("\\.rb$", Qt::CaseInsensitive); pos = rx3.indexIn(m_iter->filename); if (pos != -1) lang = enHighlightRuby; QRegExp rx4("\\.js$", Qt::CaseInsensitive); pos = rx4.indexIn(m_iter->filename); if (pos != -1) lang = enHighlightJavascript; m_currentlang = lang; setLexer(lang); QString alltext; while (!in.atEnd()) { alltext = in.readAll(); } m_textEditSource->setText(alltext); m_textEditSource->setMarginWidth(0, QString::number(m_textEditSource->lines() * 10)); highlightLine(m_iter->linenum.toInt()); updateFilePathLabel(); m_pushButtonGoToLine->setEnabled(true); m_pushButtonOpenInEditor->setEnabled(true); m_pushButtonTextShrink->setEnabled(true); m_pushButtonTextEnlarge->setEnabled(true); m_listWidgetFunc->clear(); if (m_iter->fileid < 0) {emit requestFuncList_filename(m_iter->filename);} else {emit requestFuncList_fileid(m_iter->fileid);} QApplication::restoreOverrideCursor(); }
/* * Given a QString, this method searches for a link pattern and inserts an URL html/ftp link tag * Returns the modified (or not) QString */ QString Package::makeURLClickable( const QString &s ) { QString sb = s; QRegExp rx("((ht|f)tp(s?))://(\\S)+[^\"|)|(|.|\\s|\\n]"); QRegExp rx1("^|[\\s]+(www\\.)(\\S)+[^\"|)|(|.|\\s|\\n]"); rx.setCaseSensitivity( Qt::CaseInsensitive ); rx1.setCaseSensitivity( Qt::CaseInsensitive ); int search = 0; int ini = 0; //First we search for the 1st pattern: rx while ( (ini = rx.indexIn( sb, search )) != -1 ){ QString s1 = rx.cap(); QString ns; if (UnixCommand::getLinuxDistro() == ectn_MANJAROLINUX) ns = "<a style=\"color:\'#425823\'\" href=\"" + s1 + "\">" + s1 + "</a>"; else ns = "<a href=\"" + s1 + "\">" + s1 + "</a>"; sb.replace( ini, s1.length(), ns); search = ini + (2*s1.length()) + 15; } search = 0; ini = 0; //Now, we search for the 2nd pattern: rx1 while ( (ini = rx1.indexIn( sb, search )) != -1 ){ QString s1 = rx1.cap(); QString ns; if (s1[0] == '\n') ns += "\n"; int blanks = s1.count( QRegExp("^|[\\s]+") ); for (int i=0; i<blanks; i++) ns += " "; if (UnixCommand::getLinuxDistro() == ectn_MANJAROLINUX) { ns += "<a style=\"color:\'#425823\'\" href=\"http://" + s1.trimmed() + "\">" + s1.trimmed() + "</a>"; } else ns += "<a href=\"http://" + s1.trimmed() + "\">" + s1.trimmed() + "</a>"; sb.replace( ini, s1.length(), ns); search = ini + (2*s1.length()) + 15; } return sb; }
void AuthManager::replyFinished(QNetworkReply* reply) { QVariant cooks = reply->header(QNetworkRequest::SetCookieHeader); if (!cooks.isNull()) { bool found = false; foreach (const QNetworkCookie& netcook, qVariantValue< QList<QNetworkCookie> >(cooks)) { if (netcook.name() == "yandex_login" && !netcook.value().isEmpty()) { found = true; break; } } if (!found) { QRegExp rx("<input type=\"?submit\"?[^>]+name=\"no\""); QString page = reply->readAll(); if (rx.indexIn(page) > 0) { QRegExp rx1("<input type=\"hidden\" name=\"idkey\" value=\"(\\S+)\"[^>]*>"); if (rx1.indexIn(page) > 0) { QByteArray post = "idkey=" + rx1.cap(1).toAscii() + "&filled=yes"; QNetworkRequest nr = newRequest(); nr.setUrl(authUrl); nr.setHeader(QNetworkRequest::ContentLengthHeader, post.length()); nr.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); manager_->post(nr, post); reply->deleteLater(); return; } } else { rx.setPattern("<input type=\"hidden\" name=\"idkey\" value=\"(\\S+)\" />"); if (rx.indexIn(page) > 0) { timer_->stop(); go(narodLogin, narodPass, rx.cap(1)); reply->deleteLater(); return; } else { authorized_ = false; loop_->exit(); reply->deleteLater(); return; } } } else { authorized_ = true; loop_->exit(); reply->deleteLater(); return; } }
int BtTextFilter::rewriteHref(int i, const QString& part) { QRegExp rx1("<a\\s(\\w+)=\"([\\s\\S]*)\"\\s(\\w+)=\"([\\s\\S]*)\""); rx1.setMinimal(false); int pos1 = rx1.indexIn(part); if (pos1 >= 0 && rx1.captureCount() == 4) { QString newEntry; if (rx1.cap(1) == "href") newEntry = "<a " + rx1.cap(1) + "=\"" + rx1.cap(2) + "||" + rx1.cap(3) + "=" + rx1.cap(4) + "\" name=\"crossref\">"; else newEntry = "<a " + rx1.cap(3) + "=\"" + rx1.cap(4) + "||" + rx1.cap(1) + "=" + rx1.cap(2) + "\" name=\"crossref\">"; m_parts[i] = newEntry; } return 1; }
void DashcoinWallet::init_ui() { ui->panel_generate->hide(); ui->panel_send_confirm->hide(); show_wallet(false); syncLabel = new QLabel(this); messageLabel = new QLabel(this); syncLabel->setContentsMargins(9,0,9,0); messageLabel->setContentsMargins(9,0,9,0); ui->bar_status->addPermanentWidget(syncLabel); ui->bar_status->addPermanentWidget(messageLabel, 1); QRegularExpression rx1("[a-zA-Z0-9]*"); QValidator *alphaNum = new QRegularExpressionValidator(rx1, this); ui->txt_send_address->setValidator(alphaNum); QRegularExpression rx2("[a-fA-F0-9]*"); QValidator *hexOnly = new QRegularExpressionValidator(rx2, this); ui->txt_send_paymentid->setValidator(hexOnly); }
int MemSensor::getCached() { #ifdef Q_OS_FREEBSD static int mem = 0; size_t size = sizeof(mem); sysctlbyname("vm.stats.vm.v_cache_count", &mem, &size, NULL, 0); return (pagetok(mem)); #elif defined(Q_OS_NETBSD) return 0; #else QRegExp rx1( "Cached:\\s*(\\d+)" ); QRegExp rx2( "SwapCached:\\s*(\\d+)" ); rx1.search( meminfo ); rx2.search( meminfo ); return ( rx1.cap(1).toInt() + rx2.cap(1).toInt() ); #endif }
void principal::on_pushButton_7_clicked(){ QFile archivo("/home/jossy/proyecto/base09.txt"); archivo.open(QIODevice::ReadOnly | QIODevice::Text); QTextStream escribir(&archivo); QString line; while (!escribir.atEnd()){ line = escribir.readLine(); qDebug() << "linea: "<<line; QRegExp rx(","); QStringList query = line.split(rx); Carros* car = new Carros(query[2].toInt(0,10),query[0],query[1],""); lista.push_back(car); } QFile archivo1("/home/jossy/proyecto/llenados.txt"); archivo1.open(QIODevice::ReadOnly | QIODevice::Text); QTextStream escribir1(&archivo1); QString line1; while (!escribir1.atEnd()){ line1 = escribir1.readLine(); QRegExp rx1(":"); QStringList query1 = line1.split(rx1); for(int q=0;q<lista.size();q++){ if(lista[q]->getplaca()==query1[0]){ for(int o=0;o<query1.size();o++){ if(o>0){ QRegExp rx2(","); QStringList query2 = query1[o].split(rx2); qDebug() << "sub listas"<<query2; llenado n (query2[0],query2[1].toDouble(0),query2[2].toDouble(0),query2[3].toDouble(0)); lista[q]->setLista(n); } } } } } }
void BpdeMainWindow::filterFile() { QFile infile(tempfile); infile.open(QFile::ReadOnly); QFile outfile(svgfile); outfile.open(QFile::WriteOnly | QFile::Truncate); QTextStream in(&infile); QTextStream out(&outfile); QRegExp rx1("<symbol"); QRegExp rx2("</symbol"); while (!in.atEnd()) { QString line = in.readLine(); line.replace(rx1, "<g"); line.replace(rx2, "</g"); out << line << "\n"; } infile.close(); outfile.close(); }
/** \param menu El menu sobre el que pintar la opcion **/ void EQToolButtonMail::pintaMenu ( QMenu *menu ) { BL_FUNC_DEBUG QMenu *ajust = menu->addMenu ( _ ( "Inf. personales por e-mail" ) ); /// Buscamos ficheros que tengan el nombre de la tabla QDir dir ( g_confpr->value( CONF_DIR_OPENREPORTS ) ); dir.setFilter ( QDir::Files | QDir::NoSymLinks ); dir.setSorting ( QDir::Size | QDir::Reversed ); /// Hacemos un filtrado de busqueda QStringList filters; filters << "*impers_" + m_BlForm->tableName() + "*.rml"; dir.setNameFilters ( filters ); QFileInfoList list = dir.entryInfoList(); for ( int i = 0; i < list.size(); ++i ) { QFileInfo fileInfo = list.at ( i ); QFile file; file.setFileName ( g_confpr->value( CONF_DIR_OPENREPORTS ) + fileInfo.fileName() ); file.open ( QIODevice::ReadOnly ); QTextStream stream ( &file ); QString buff = stream.readAll(); file.close(); /// Buscamos Query's por tratar QString titulo = fileInfo.fileName(); QRegExp rx1 ( "title\\s*=\\s*\"(.*)\"" ); rx1.setMinimal ( true ); if ( rx1.indexIn ( buff, 0 ) != -1 ) { titulo = rx1.cap ( 1 ); } // end while QAction * action = ajust->addAction ( titulo ); action->setObjectName ( "em_" + fileInfo.fileName() ); } }
void QtDensity::filterFile() { // cairoDevice creates richer SVG than Qt can display // but per Michaele Lawrence, a simple trick is to s/symbol/g/ which we do here QFile infile(m_tempfile); infile.open(QFile::ReadOnly); QFile outfile(m_svgfile); outfile.open(QFile::WriteOnly | QFile::Truncate); QTextStream in(&infile); QTextStream out(&outfile); QRegExp rx1("<symbol"); QRegExp rx2("</symbol"); while (!in.atEnd()) { QString line = in.readLine(); line.replace(rx1, "<g"); // so '<symbol' becomes '<g ...' line.replace(rx2, "</g");// and '</symbol becomes '</g' out << line << "\n"; } infile.close(); outfile.close(); }
void fileviewer::updateTextEdit(void) { if (!m_iter) return; QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); m_textEditSource->clear(); m_highlighter->m_intAddlRulesMode = 0; //reset additional rules mode QFile file(m_iter->filename); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { QApplication::restoreOverrideCursor(); return; } QTextStream in(&file); int lang = enHighlightCPP; QRegExp rx1("\\.py$", Qt::CaseInsensitive); int pos = rx1.indexIn(m_iter->filename); if (pos != -1) lang = enHighlightPython; QRegExp rx2("\\.java$", Qt::CaseInsensitive); pos = rx2.indexIn(m_iter->filename); if (pos != -1) lang = enHighlightJava; m_highlighter->m_intLanguage = lang; while (!in.atEnd()) { m_textEditSource->insertPlainText(in.readAll()); } m_textEditSource->highlightLine(m_iter->linenum.toInt()); updateFilePathLabel(); m_pushButtonGoToLine->setEnabled(true); m_pushButtonOpenInEditor->setEnabled(true); m_pushButtonTextShrink->setEnabled(true); m_pushButtonTextEnlarge->setEnabled(true); QApplication::restoreOverrideCursor(); }
sqlqueryresultlist searchhandler::doGrep(const QString &fp) { sqlqueryresultlist reslist; sqlqueryresult res; QString str, fp2; tStr fpstr, fn; int pos, linenumber=0; char numtext[10]; QRegExp rx1(*m_grepRegExp); reslist.result_type = sqlqueryresultlist::sqlresultFILE_LINE; fp2 = fp; fp2.replace(QString("$HOME"), QDir::homePath()); #ifdef _WIN32 fp2.replace("/", "\\"); #endif fpstr = qt2str(fp2); fn = extract_filename(fpstr.c_str()); QFile file(fp2); QTextStream in(&file); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { return reslist; } while (!in.atEnd()) { linenumber++; str = in.readLine(); pos = rx1.indexIn(str); if (pos != -1) { res.filepath = fpstr; res.filename = fn; sprintf(numtext, "%d", linenumber); res.linenum = numtext; res.linetext = qt2str(str.trimmed().left(80)); reslist.resultlist.push_back(res); } } return reslist; }
void QtDialog::on_doubleSpinBox_valueChanged(double arg1) { const auto m_tempfile = QString::fromStdString(Rcpp::as<std::string>(m_r_inside->parseEval("tfile <- tempfile()"))); const auto m_svgfile = QString::fromStdString(Rcpp::as<std::string>(m_r_inside->parseEval("sfile <- tempfile()"))); (*m_r_inside)["a"] = arg1; std::string cmd0 = "svg(width=6,height=6,pointsize=10,filename=tfile); "; std::string cmd1 = "x <- seq(0,2*pi,0.01);"; std::string cmd2 = "y <- sin(x * a);"; std::string cmd3 = "plot(x,y,t='line',main=\"CppRinsideExample4\");"; std::string cmd4 = "dev.off();"; std::string cmd = cmd0 + cmd1 + cmd2 + cmd3 + cmd4; m_r_inside->parseEvalQ(cmd); { // cairoDevice creates richer SVG than Qt can display // but per Michaele Lawrence, a simple trick is to s/symbol/g/ which we do here QFile infile(m_tempfile); infile.open(QFile::ReadOnly); QFile outfile(m_svgfile); outfile.open(QFile::WriteOnly | QFile::Truncate); QTextStream in(&infile); QTextStream out(&outfile); QRegExp rx1("<symbol"); QRegExp rx2("</symbol"); while (!in.atEnd()) { QString line = in.readLine(); line.replace(rx1, "<g"); // so '<symbol' becomes '<g ...' line.replace(rx2, "</g");// and '</symbol becomes '</g' out << line << "\n"; } infile.close(); outfile.close(); } m_svg_widget->load(m_svgfile); }
// Typical input: <span lemma="H07225">God</span> // Output: "<a href="sword://lemmamorph/lemma=H0430||/God" style="color: black">" int BtTextFilter::rewriteLemmaOrMorphAsLink(int i, const QString& part) { QString value; QRegExp rx1("lemma=\"([^\"]*)*"); int pos1 = rx1.indexIn(part); if (pos1 > -1) value = "lemma=" + rx1.cap(1); QRegExp rx2("morph=\"([^\"]*)(\){0,1}"); int pos2 = rx2.indexIn(part); if (pos2 > -1) { if (!value.isEmpty()) value += "||"; value += "morph=" + rx2.cap(1); } QString refText = m_parts.at(i+1); QString url = "sword://lemmamorph/" + value + "/" + refText; QString newEntry; newEntry = "<a href=\"" + url + "\">"; m_parts[i] = newEntry; m_parts[i+2] = "</a>"; return 3; }
KLF_EXPORT int klfVersionCompare(const QString& v1, const QString& v2) { qDebug("klfVersionCompare(): Comparing versions %s and %s", qPrintable(v1), qPrintable(v2)); if (v1 == v2) return 0; if (v1.isEmpty()) // v1 is empty, but v2 is not empty because of test above return -1; if (v2.isEmpty()) // v2 is empty, but not v1 because of test above return 1; // *1 2 *3 4 *5 *6 QRegExp rx1("^(\\d+)(\\.(\\d+)(\\.(\\d+)([a-zA-Z]+\\d*)?)?)?$"); QRegExp rx2(rx1); if (!rx1.exactMatch(v1)) { qWarning("klfVersionLessThan: Invalid version number format: %s", qPrintable(v1)); return -200; } if (!rx2.exactMatch(v2)) { qWarning("klfVersionLessThan: Invalid version number format: %s", qPrintable(v2)); return -200; } int maj1 = rx1.cap(1).toInt(); int maj2 = rx2.cap(1).toInt(); if (maj1 != maj2) return maj1 - maj2; bool hasmin1 = !rx1.cap(2).isEmpty(); bool hasmin2 = !rx2.cap(2).isEmpty(); if ( ! hasmin1 && ! hasmin2 ) return 0; // equal if ( ! hasmin1 && hasmin2 ) return -1; // 3 < 3.x if ( hasmin1 && ! hasmin2 ) return +1; // 3.x > 3 int min1 = rx1.cap(3).toInt(); int min2 = rx2.cap(3).toInt(); if ( min1 != min2 ) return min1 - min2; bool hasrel1 = !rx1.cap(4).isEmpty(); bool hasrel2 = !rx2.cap(4).isEmpty(); if ( ! hasrel1 && ! hasrel2 ) return 0; // equal if ( ! hasrel1 && hasrel2 ) return -1; // 3.x < 3.x.y if ( hasrel1 && ! hasrel2 ) return +1; // 3.x.y > 3.x int rel1 = rx1.cap(5).toInt(); int rel2 = rx2.cap(5).toInt(); if ( rel1 != rel2 ) return rel1 - rel2; QString suffix1 = rx1.cap(6); QString suffix2 = rx2.cap(6); // qDebug("Suffix1=%s, suffix2=%s", qPrintable(suffix1), qPrintable(suffix2)); if (suffix1 == suffix2) return 0; // equal // 1 2 QRegExp rxs1("^([a-zA-Z]*)(\\d*)$"); QRegExp rxs2(rxs1); rxs1.exactMatch(suffix1); // must necessarily match, already matched global regex rxs2.exactMatch(suffix2); QString w1 = rxs1.cap(1); QString w2 = rxs2.cap(1); QString ns1 = rxs1.cap(2); QString ns2 = rxs2.cap(2); int cmp = __klf_version_compare_suffix_words(w1, w2); if (cmp != 0) return cmp; // words are enough to make the difference // the words are the same -> compare ns1<->ns2 if (ns1.isEmpty()) { if (ns2.isEmpty()) return 0; // equal // with suffix number compares greater than without return -1; } if (ns2.isEmpty()) { return +1; } int n1 = ns1.toInt(); int n2 = ns2.toInt(); return n1 - n2; }
void Videoner_Handler::populateWebViewMenu(QMenu* menu, WebView* view, const QWebHitTestResult &r) { m_view = view; if (m_pageyt) { QRegExp rx1("v=([^&]+)|youtu.be/([^&]+)|y2u.be/([^&]+)|youtube.com/embed/([^&]+)"); QString videoId1; rx1.indexIn(r.linkUrl().toString()); for (int i = 1; i < 4; ++i) { if (!rx1.cap(i).isEmpty()) { videoId1 = rx1.cap(i); break; } } if (videoId1.isEmpty()) { rx1.indexIn(view->url().toString()); for (int i = 1; i < 4; ++i) { if (!rx1.cap(i).isEmpty()) { videoId1 = rx1.cap(i); break; } } } if (!videoId1.isEmpty()) { QString videoPage1; videoPage1 = "http://www.youtube.com/watch?v=" + videoId1; menu->addAction(QIcon(":/videoner/data/videoner.png"), tr("Videonize!"), this, (m_sepyth ? SLOT(startExternalHandlerYt()) : SLOT(startExternalHandler())))->setData(videoPage1); } } if (m_pagevm) { QRegExp rx2("://vimeo.com/([^d]{8})"); QString videoId2; rx2.indexIn(r.linkUrl().toString()); for (int i = 1; i < 4; ++i) { if (!rx2.cap(i).isEmpty()) { videoId2 = rx2.cap(i); break; } } if (videoId2.isEmpty()) { rx2.indexIn(view->url().toString()); for (int i = 1; i < 4; ++i) { if (!rx2.cap(i).isEmpty()) { videoId2 = rx2.cap(i); break; } } } if (!videoId2.isEmpty()) { QString videoPage2; videoPage2 = "http://vimeo.com/" + videoId2; menu->addAction(QIcon(":/videoner/data/videoner.png"), tr("Videonize!"), this, SLOT(startExternalHandler()))->setData(videoPage2); } } if (m_pagell) { QRegExp rx3("www.liveleak.com/view?i=([a-z0-9]{3})_([^&]+)"); QString videoId3; rx3.indexIn(r.linkUrl().toString()); for (int i = 1; i < 4; ++i) { if (!rx3.cap(i).isEmpty()) { videoId3 = rx3.cap(i); break; } } if (videoId3.isEmpty()) { rx3.indexIn(view->url().toString()); for (int i = 1; i < 4; ++i) { if (!rx3.cap(i).isEmpty()) { videoId3 = rx3.cap(i); break; } } } if (!videoId3.isEmpty()) { QString videoPage3; videoPage3 = "http://www.liveleak.com/view?i=" + videoId3; menu->addAction(QIcon(":/videoner/data/videoner.png"), tr("Videonize!"), this, SLOT(startExternalHandler()))->setData(videoPage3); } } if (m_pagemc) { QRegExp rx4("www.metacafe.com/watch/([^d]+)/([^&]+)"); QString videoId4; rx4.indexIn(r.linkUrl().toString()); for (int i = 1; i < 4; ++i) { if (!rx4.cap(i).isEmpty()) { videoId4 = rx4.cap(i); break; } } if (videoId4.isEmpty()) { rx4.indexIn(view->url().toString()); for (int i = 1; i < 4; ++i) { if (!rx4.cap(i).isEmpty()) { videoId4 = rx4.cap(i); break; } } } if (!videoId4.isEmpty()) { QString videoPage4; videoPage4 = "http://www.metacafe.com/watch/" + videoId4; menu->addAction(QIcon(":/videoner/data/videoner.png"), tr("Videonize!"), this, SLOT(startExternalHandler()))->setData(videoPage4); } } if (m_pagedm) { QRegExp rx5("dailymotion.com/video/([a-z0-9]+_[^&]+)"); QString videoId5; rx5.indexIn(r.linkUrl().toString()); for (int i = 1; i < 4; ++i) { if (!rx5.cap(i).isEmpty()) { videoId5 = rx5.cap(i); break; } } if (videoId5.isEmpty()) { rx5.indexIn(view->url().toString()); for (int i = 1; i < 4; ++i) { if (!rx5.cap(i).isEmpty()) { videoId5 = rx5.cap(i); break; } } } if (!videoId5.isEmpty()) { QString videoPage5; videoPage5 = "http://www.dailymotion.com/video/" + videoId5; menu->addAction(QIcon(":/videoner/data/videoner.png"), tr("Videonize!"), this, SLOT(startExternalHandler()))->setData(videoPage5); } } if (m_pagebr) { QRegExp rx6("www.break.com/video/([^&]+)"); QString videoId6; rx6.indexIn(r.linkUrl().toString()); for (int i = 1; i < 4; ++i) { if (!rx6.cap(i).isEmpty()) { videoId6 = rx6.cap(i); break; } } if (videoId6.isEmpty()) { rx6.indexIn(view->url().toString()); for (int i = 1; i < 4; ++i) { if (!rx6.cap(i).isEmpty()) { videoId6 = rx6.cap(i); break; } } } if (!videoId6.isEmpty()) { QString videoPage6; videoPage6 = "www.break.com/video/" + videoId6; menu->addAction(QIcon(":/videoner/data/videoner.png"), tr("Videonize!"), this, SLOT(startExternalHandler()))->setData(videoPage6); } } if (m_pagehu) { QRegExp rx7("www.hulu.com/watch/([^d]+)"); QString videoId7; rx7.indexIn(r.linkUrl().toString()); for (int i = 1; i < 4; ++i) { if (!rx7.cap(i).isEmpty()) { videoId7 = rx7.cap(i); break; } } if (videoId7.isEmpty()) { rx7.indexIn(view->url().toString()); for (int i = 1; i < 4; ++i) { if (!rx7.cap(i).isEmpty()) { videoId7 = rx7.cap(i); break; } } } if (!videoId7.isEmpty()) { QString videoPage7; videoPage7 = "http://www.hulu.com/watch/" + videoId7; menu->addAction(QIcon(":/videoner/data/videoner.png"), tr("Videonize!"), this, SLOT(startExternalHandler()))->setData(videoPage7); } } if (m_medel) { if (r.element().tagName().toLower() == QLatin1String("video") || r.element().tagName().toLower() == QLatin1String("audio")) { QUrl mediaLink = r.element().evaluateJavaScript("this.currentSrc").toUrl(); menu->addAction(QIcon(":/videoner/data/videoner.png"), tr("Videonize!"), this, (m_sepmedel ? SLOT(startExternalHandlerMed()) : SLOT(startExternalHandler())))->setData(mediaLink); } } }
int init ( ) { BL_FUNC_DEBUG /// Inicializa el sistema de traducciones 'gettext'. setlocale ( LC_ALL, "" ); blBindTextDomain ( "pluginbl_report2ods", g_confpr->value( CONF_DIR_TRADUCCION ).toLatin1().constData() ); PluginBl_Report2ODS *mcont = new PluginBl_Report2ODS; QMenu *pPluginMenu = NULL; /// Buscamos ficheros que tengan el nombre de la tabla QDir dir ( g_confpr->value( CONF_DIR_OPENREPORTS ) ); dir.setFilter ( QDir::Files | QDir::NoSymLinks ); dir.setSorting ( QDir::Size | QDir::Reversed ); /// Hacemos un filtrado de busqueda QStringList filters; filters << "inf_*.pys"; dir.setNameFilters ( filters ); QFileInfoList list = dir.entryInfoList(); for ( int i = 0; i < list.size(); ++i ) { QFileInfo fileInfo = list.at ( i ); QFile file; file.setFileName ( g_confpr->value( CONF_DIR_OPENREPORTS ) + fileInfo.fileName() ); file.open ( QIODevice::ReadOnly ); QTextStream stream ( &file ); QString buff = stream.readAll(); file.close(); /// Buscamos el titulo QString titulo = fileInfo.fileName(); QRegExp rx3 ( "title\\s*=\\s*\"(.*)\"" ); rx3.setMinimal ( true ); if ( rx3.indexIn ( buff, 0 ) != -1 ) { titulo = rx3.cap ( 1 ); } // end if QString pathtitulo = fileInfo.fileName(); QRegExp rx1 ( "pathtitle\\s*=\\s*\"(.*)\"" ); rx1.setMinimal ( true ); if ( rx1.indexIn ( buff, 0 ) != -1 ) { pathtitulo = rx1.cap ( 1 ); } else { pathtitulo = titulo; } // end if /// Buscamos el icono QString icon = ":/Images/template2ods.png"; QRegExp rx4 ( " icon\\s*=\\s*\"(.*)\"" ); rx4.setMinimal ( true ); if ( rx4.indexIn ( buff, 0 ) != -1 ) { icon = rx4.cap ( 1 ); } // end if QMenuBar *menubar =g_pluginbl_report2ods->menuBar(); QMenu *menu = NULL; QStringList path = pathtitulo.split("\\"); if (path.size() > 1) { QList<QMenu *> allPButtons = menubar->findChildren<QMenu *>(); bool encontrado = false; for (int j = 0; j < allPButtons.size(); ++j) { if (allPButtons.at(j)->title() == path[0]) { encontrado = true; menu = allPButtons.at(j); } // end if } // end for if (!encontrado) { //QMenu *pPluginMenu1 = new QMenu ( path[0] , menubar ); //menubar->insertMenu ( pPluginVer->menuAction(), pPluginMenu1 ); /// Miramos si existe un menu Herramientas menu = g_pluginbl_report2ods->newMenu ( path[0], "", "menuHerramientas" ); } // end if } else { if (!pPluginMenu) { pPluginMenu = g_pluginbl_report2ods->newMenu ( _("Informes &ODS"), "menuInfODS", "menuHerramientas" ); } // end if menu = pPluginMenu; } // end if for (int i = 1; i < path.size()-1; ++i) { QList<QMenu *> allPButtons = menu->findChildren<QMenu *>(); bool encontrado = false; for (int j = 0; j < allPButtons.size(); ++j) { if (allPButtons.at(j)->title() == path[i]) { encontrado = true; menu = allPButtons.at(j); } // end if } // end for if (!encontrado) { QMenu *pPluginMenu1 = new QMenu ( path[i] , menu ); menu->addMenu ( pPluginMenu1 ); menu = pPluginMenu1; } // end if } // end for /// Creamos el menú. QAction *accion = new QAction ( path[path.size()-1], 0 ); accion->setIcon(QIcon(icon)); accion->setObjectName ( fileInfo.fileName() ); accion->setStatusTip ( titulo); accion->setWhatsThis ( titulo ); mcont->connect ( accion, SIGNAL ( activated() ), mcont, SLOT ( elslot1() ) ); menu->addAction ( accion ); } // end for return 0; }
bool CCustomBindStatusCallBack::_GetFileName() { HRESULT hr = S_OK; CComQIPtr<IWinInetHttpInfo> spInfo = m_spBinding; if (spInfo) { char buff[1024]; DWORD dwBuffSize = 1024; hr = spInfo->QueryInfo(HTTP_QUERY_CONTENT_DISPOSITION, (LPVOID)buff, &dwBuffSize, 0, NULL); if (hr == S_OK) { // CONTENT_DISPOSITIONからファイル名を取得する std::string strbuff = buff; std::regex rx("filename\\*=(?: |)UTF-8''(.+)"); std::regex rx1("filename=(?:\"|)([^\";]+)"); std::smatch result; if (std::regex_search(strbuff, result, rx)) { CString strtemp = result.str(1).c_str(); vector<char> strurldecoded = Misc::urlstr_decode(strtemp); m_pDLItem->strFileName = Misc::utf8_to_CString(strurldecoded); // } else if (std::regex_search(strbuff, result, rx1)) { std::string strtemp1 = result.str(1); int nPerCount = 0; std::for_each(strtemp1.begin(), strtemp1.end(), [&nPerCount](char c) { if (c == '%') ++nPerCount; }); vector<char> strUrlDecoded; bool bShiftJis = false; if (nPerCount != 0) { double dRate = double(strtemp1.length()) / double(nPerCount); if (dRate >= 2.4) { // '%'が多いならURLDecode char tempdecoded[INTERNET_MAX_PATH_LENGTH] = "\0"; DWORD dwBufferLength = INTERNET_MAX_PATH_LENGTH; hr = ::UrlUnescapeA(const_cast<LPSTR>(strtemp1.c_str()), tempdecoded, &dwBufferLength, 0); if (FAILED(hr)) { TRACEIN(_T("UrlUnescapeA 失敗 : Error「%s」\n (%s)"), (LPCTSTR)GetLastErrorString(hr), (LPCTSTR)CString(strtemp1.c_str())); ::strcpy_s(tempdecoded, strtemp1.c_str()); // 失敗したので元に戻しておく } else { strtemp1 = tempdecoded; for (auto it = strtemp1.begin(); it != strtemp1.end(); ++it) { // '+'を空白に置換する if (*it == '+') *it = ' '; } } } } else { if (Misc::IsShiftJIS(strtemp1.c_str(), (int)strtemp1.length())) { bShiftJis = true; m_pDLItem->strFileName = strtemp1.c_str(); TRACEIN(_T("Shift-JIS文字列でした : %s"), (LPCTSTR)m_pDLItem->strFileName); } } if (bShiftJis == false) { strUrlDecoded.resize(strtemp1.length() + 1, '\0'); ::strcpy_s(strUrlDecoded.data(), strtemp1.length() + 1, strtemp1.c_str()); m_pDLItem->strFileName = Misc::utf8_to_CString(strUrlDecoded); } } else { TRACEIN(_T("CONTENT_DISPOSITIONが見つからない? 内容: %s"), (LPCTSTR)CString(buff)); } } if (m_pDLItem->strFileName.IsEmpty()) { dwBuffSize = 1024; hr = spInfo->QueryOption(INTERNET_OPTION_DATAFILE_NAME, (LPVOID)buff, &dwBuffSize); if (hr == S_OK) { // ファイル名の部分を取得する([?]部分を除く) CString strBaseName = Misc::GetFileBaseName(buff); int nIndex = strBaseName.ReverseFind(_T('[')); if (nIndex != -1) { m_pDLItem->strFileName = strBaseName.Left(nIndex); CString strExt = Misc::GetFileExt(strBaseName); if (strExt.IsEmpty() == FALSE) { m_pDLItem->strFileName += _T('.') + strExt; } } else { m_pDLItem->strFileName = strBaseName; } } } } else { ATLASSERT(m_strDLFolder.IsEmpty() == FALSE); // これ以外で失敗すると困る m_pDLItem->strFileName = Misc::GetFileBaseName(m_pDLItem->strURL); // [?]がつくかも int nQIndex = m_pDLItem->strFileName.ReverseFind(_T('?')); if (nQIndex != -1) { m_pDLItem->strFileName = m_pDLItem->strFileName.Left(nQIndex); } if (m_pDLItem->strFileName.IsEmpty()) m_pDLItem->strFileName = _T("index"); // めったにないと思うけど一応 if (m_pDLItem->strFileName.Find(_T('%')) != -1) { // URLデコードする //vector<char> filename = Misc::urlstr_decode(m_pDLItem->strFileName); m_pDLItem->strFileName = Misc::urlstr_decodeJpn(m_pDLItem->strFileName, 3);//Misc::UnknownToCString(filename); } } // リンク抽出ダイアログより(画像を保存も) if (m_strDLFolder.IsEmpty() == FALSE) { // 拡張子がなければ Content-Type から拡張子を得る if (Misc::GetFileExt(m_pDLItem->strFileName).IsEmpty() && m_pDLItem->strExtention.GetLength() > 0) m_pDLItem->strFileName += _T(".") + m_pDLItem->strExtention; m_pDLItem->strFilePath = m_strDLFolder + m_pDLItem->strFileName; if (::PathFileExists(m_pDLItem->strFilePath)) { if (m_dwDLOption & DLO_OVERWRITEPROMPT) { CString strMessage; strMessage.Format(_T("%s は既に存在します。\n上書きしますか?\n"), (LPCTSTR)m_pDLItem->strFileName);; if (MessageBox(NULL, strMessage, _T("確認"), MB_OKCANCEL | MB_ICONWARNING) == IDCANCEL) { return false; } } else if (m_dwDLOption & DLO_USEUNIQUENUMBER) { // 連番を付ける int nCount = 0; CString strOriginalFileName = m_pDLItem->strFileName; while (TRUE) { CString strAppend; strAppend.Format(_T("_[%d]"), nCount); int nExt = m_pDLItem->strFileName.Find(_T('.')); if (nExt != -1) { m_pDLItem->strFileName.Insert(nExt, strAppend); } else { m_pDLItem->strFileName += strAppend; } m_pDLItem->strFilePath = m_strDLFolder + m_pDLItem->strFileName; if (::PathFileExists(m_pDLItem->strFilePath) == FALSE) break; m_pDLItem->strFileName = strOriginalFileName; ++nCount; } } } m_pDLItem->strIncompleteFilePath = m_pDLItem->strFilePath + _T(".incomplete"); return true; } return GetFileName(m_pDLItem); }
/** \param parent **/ EQToolButton::EQToolButton ( QWidget *parent ) : QToolButton ( parent ) { BL_FUNC_DEBUG /// Buscamos alguna otra instancia y si la hay nos quitamos de enmedio EQToolButton *tool = parent->findChild<EQToolButton *>("EQToolButtonN"); if (tool) { hide(); return; } // end if setObjectName("EQToolButtonN"); connect ( parent, SIGNAL ( pintaMenu ( QMenu * ) ), this, SLOT ( pintaMenu ( QMenu * ) ) ); connect ( parent, SIGNAL ( trataMenu ( QAction * ) ), this, SLOT ( trataMenu ( QAction * ) ) ); m_BlForm = ( BlForm * ) parent; QFrame *plugbotones = m_BlForm->findChild<QFrame *>("mui_plugbotones"); if (plugbotones) { QHBoxLayout *m_hboxLayout1 = plugbotones->findChild<QHBoxLayout *> ( "hboxLayout1" ); if ( !m_hboxLayout1 ) { m_hboxLayout1 = new QHBoxLayout ( plugbotones ); m_hboxLayout1->setSpacing ( 5 ); m_hboxLayout1->setMargin ( 0 ); m_hboxLayout1->setObjectName ( QString::fromUtf8 ( "hboxLayout1" ) ); } // end if m_hboxLayout1->addWidget ( this ); setMinimumSize ( QSize ( 32, 32 ) ); setMaximumSize ( QSize ( 32, 32 ) ); setIcon ( QIcon ( ":/Images/template2ods.png" ) ); setIconSize ( QSize ( 32, 32 ) ); setPopupMode(QToolButton::InstantPopup); /// Creamos el menu QMenu *menu = new QMenu(this); /// Buscamos ficheros que tengan el nombre de la tabla QDir dir ( g_confpr->value( CONF_DIR_OPENREPORTS ) ); dir.setFilter ( QDir::Files | QDir::NoSymLinks ); dir.setSorting ( QDir::Size | QDir::Reversed ); /// Hacemos un filtrado de busqueda QStringList filters; filters << "*impers_" + m_BlForm->tableName() + "*.pys"; dir.setNameFilters ( filters ); QFileInfoList list = dir.entryInfoList(); // Si no hay elementos que mostrar entonces ocultamos el boton ya que no lleva a ninguna parte. if (list.size() == 0) { hide(); return; } // end if for ( int i = 0; i < list.size(); ++i ) { QFileInfo fileInfo = list.at ( i ); QFile file; file.setFileName ( g_confpr->value( CONF_DIR_OPENREPORTS ) + fileInfo.fileName() ); file.open ( QIODevice::ReadOnly ); QTextStream stream ( &file ); QString buff = stream.readAll(); file.close(); /// Buscamos Query's por tratar QString titulo = fileInfo.fileName(); QRegExp rx1 ( " title\\s*=\\s*\"(.*)\"" ); rx1.setMinimal ( true ); if ( rx1.indexIn ( buff, 0 ) != -1 ) { titulo = rx1.cap ( 1 ); } // end while /// Buscamos Query's por tratar QString icon = ":/Images/template2ods.png"; QRegExp rx2 ( " icon\\s*=\\s*\"(.*)\"" ); rx2.setMinimal ( true ); if ( rx2.indexIn ( buff, 0 ) != -1 ) { icon = rx2.cap ( 1 ); } // end if QAction *accion = menu->addAction ( titulo ); accion->setObjectName ( fileInfo.fileName() ); accion->setIcon(QIcon(icon)); connect ( accion, SIGNAL ( triggered ( bool ) ), this, SLOT ( trataMenu ( ) ) ); } setMenu(menu); } else {
static void GeomTest() { PointD ptD(12.4, -13.6); utassert(ptD.x == 12.4 && ptD.y == -13.6); PointI ptI = ptD.ToInt(); utassert(ptI.x == 12 && ptI.y == -14); ptD = ptI.Convert<double>(); utassert(PointD(12, -14) == ptD); utassert(PointD(12.4, -13.6) != ptD); SizeD szD(7.7, -3.3); utassert(szD.dx == 7.7 && szD.dy == -3.3); SizeI szI = szD.ToInt(); utassert(szI.dx == 8 && szI.dy == -3); szD = szI.Convert<double>(); utassert(SizeD(8, -3) == szD); utassert(!szD.IsEmpty() && !szI.IsEmpty()); utassert(SizeI().IsEmpty() && SizeD().IsEmpty()); struct SRIData { int x1s, x1e, y1s, y1e; int x2s, x2e, y2s, y2e; bool intersect; int i_xs, i_xe, i_ys, i_ye; int u_xs, u_xe, u_ys, u_ye; } testData[] = { { 0,10, 0,10, 0,10, 0,10, true, 0,10, 0,10, 0,10, 0,10 }, /* complete intersect */ { 0,10, 0,10, 20,30,20,30, false, 0, 0, 0, 0, 0,30, 0,30 }, /* no intersect */ { 0,10, 0,10, 5,15, 0,10, true, 5,10, 0,10, 0,15, 0,10 }, /* { | } | */ { 0,10, 0,10, 5, 7, 0,10, true, 5, 7, 0,10, 0,10, 0,10 }, /* { | | } */ { 0,10, 0,10, 5, 7, 5, 7, true, 5, 7, 5, 7, 0,10, 0,10 }, { 0,10, 0,10, 5, 15,5,15, true, 5,10, 5,10, 0,15, 0,15 }, }; for (size_t i = 0; i < dimof(testData); i++) { struct SRIData *curr = &testData[i]; RectI rx1(curr->x1s, curr->y1s, curr->x1e - curr->x1s, curr->y1e - curr->y1s); RectI rx2 = RectI::FromXY(curr->x2s, curr->y2s, curr->x2e, curr->y2e); RectI isect = rx1.Intersect(rx2); if (curr->intersect) { utassert(!isect.IsEmpty()); utassert(isect.x == curr->i_xs && isect.y == curr->i_ys); utassert(isect.x + isect.dx == curr->i_xe && isect.y + isect.dy == curr->i_ye); } else { utassert(isect.IsEmpty()); } RectI urect = rx1.Union(rx2); utassert(urect.x == curr->u_xs && urect.y == curr->u_ys); utassert(urect.x + urect.dx == curr->u_xe && urect.y + urect.dy == curr->u_ye); /* if we swap rectangles, the results should be the same */ std::swap(rx1, rx2); isect = rx1.Intersect(rx2); if (curr->intersect) { utassert(!isect.IsEmpty()); utassert(isect.x == curr->i_xs && isect.y == curr->i_ys); utassert(isect.x + isect.dx == curr->i_xe && isect.y + isect.dy == curr->i_ye); } else { utassert(isect.IsEmpty()); } urect = rx1.Union(rx2); utassert(RectI::FromXY(curr->u_xs, curr->u_ys, curr->u_xe, curr->u_ye) == urect); utassert(!rx1.Contains(PointI(-2, -2))); utassert(rx1.Contains(rx1.TL())); utassert(!rx1.Contains(PointI(rx1.x, INT_MAX))); utassert(!rx1.Contains(PointI(INT_MIN, rx1.y))); } }
ClientUI::ClientUI(QWidget *parent) : QDialog(parent), ui(new Ui::ClientUI) { ui->setupUi(this); int port = 11111; QString ip = "127.0.0.1"; QFile *fp = new QFile("config"); if(fp->exists()) { QTextStream config(fp); fp->open(QIODevice::ReadOnly); ip = config.readLine(); port = config.readLine().toInt(); fp->close(); } tcpSocket=new Client; tcpSocket->link(ip, port); QRegExp rx1("^[A-Za-z][A-Za-z0-9_]{4,12}"); ui->regLoginName->setValidator(new QRegExpValidator(rx1, this)); ui->editLoginName->setValidator(new QRegExpValidator(rx1, this)); QRegExp rx2("[\u4e00-\u9fa5A-Za-z0-9_]{2,10}"); ui->regNickname->setValidator(new QRegExpValidator(rx2, this)); QRegExp rx3("[A-Za-z0-9_]{6,12}"); ui->regPassword->setValidator(new QRegExpValidator(rx3, this)); ui->regPasswordAgain->setValidator(new QRegExpValidator(rx3, this)); ui->editPassword->setValidator(new QRegExpValidator(rx3, this)); fp=new QFile("account"); if(fp->exists()) { QTextStream account(fp); int pos; fp->open(QIODevice::ReadOnly); QString userName = account.readLine(); if (QValidator::State::Acceptable == ui->editLoginName->validator()->validate(userName, pos)){ ui->editLoginName->setText(userName); ui->chkSaveUser->setChecked(true); } QString password = account.readLine(); if (QValidator::State::Acceptable == ui->editPassword->validator()->validate(password, pos)){ ui->editPassword->setText(password); ui->chkSavePwd->setChecked(true); } fp->close(); } connect(tcpSocket,SIGNAL(error(QAbstractSocket::SocketError)), this,SLOT(displayError(QAbstractSocket::SocketError))); connect(tcpSocket,SIGNAL(getMessage(unsigned short, google::protobuf::Message*)), this,SLOT(showMessage(unsigned short, google::protobuf::Message*))); connect(ui->btnLogin, SIGNAL(clicked()), this, SLOT(UserLogin())); connect(ui->btnGuest, SIGNAL(clicked()), this, SLOT(GuestLogin())); connect(ui->btnRegist, SIGNAL(clicked()), this, SLOT(UserRegistShow())); connect(ui->btnRegistCommit, SIGNAL(clicked()), this, SLOT(UserRegist())); connect(ui->btnBackLogin, SIGNAL(clicked()), this, SLOT(UserBackLogin())); connect(ui->chkSaveUser, SIGNAL(clicked()), this, SLOT(CheckSaveUser())); connect(ui->chkSavePwd, SIGNAL(clicked()), this, SLOT(CheckSavePwd())); ui->frameRegist->hide(); ui->frameLogin->show(); ui->editPassword->setEchoMode(QLineEdit::Password); ui->regPassword->setEchoMode(QLineEdit::Password); ui->regPasswordAgain->setEchoMode(QLineEdit::Password); ui->btnRegist->setEnabled(true); }
// ======================================================== int init1 ( ) { BL_FUNC_DEBUG PluginBl_Report *mcont = new PluginBl_Report; QMenu *pPluginMenu = NULL; /// Miramos si existe un menu Informes pPluginMenu = g_pluginbl_report->menuBar()->findChild<QMenu *> ( "menuInformes" ); QMenu *pPluginVer = g_pluginbl_report->menuBar()->findChild<QMenu *> ( "menuVentana" ); /// Buscamos ficheros adecuados QDir dir ( g_confpr->value( CONF_DIR_OPENREPORTS ) ); dir.setFilter ( QDir::Files | QDir::NoSymLinks ); dir.setSorting ( QDir::Size | QDir::Reversed ); /// Hacemos un filtrado de busqueda QStringList filters; filters << "inf_*.txt"; dir.setNameFilters ( filters ); QFileInfoList list = dir.entryInfoList(); for ( int i = 0; i < list.size(); ++i ) { QFileInfo fileInfo = list.at ( i ); QFile file; file.setFileName ( g_confpr->value( CONF_DIR_OPENREPORTS ) + fileInfo.fileName() ); file.open ( QIODevice::ReadOnly ); QTextStream stream ( &file ); QString buff = stream.readAll(); file.close(); /// Buscamos el titulo QString titulo = fileInfo.fileName(); QRegExp rx3 ( " title\\s*=\\s*\"(.*)\"" ); rx3.setMinimal ( true ); if ( rx3.indexIn ( buff, 0 ) != -1 ) { titulo = rx3.cap ( 1 ); } // end while QString pathtitulo = fileInfo.fileName(); QRegExp rx1 ( "pathtitle\\s*=\\s*\"(.*)\"" ); rx1.setMinimal ( true ); if ( rx1.indexIn ( buff, 0 ) != -1 ) { pathtitulo = rx1.cap ( 1 ); } else { pathtitulo = titulo; } // end while /// Buscamos el icono QString icon = ":/Images/template2rml.png"; QRegExp rx6 ( " icon\\s*=\\s*\"(.*)\"" ); rx6.setMinimal ( true ); if ( rx6.indexIn ( buff, 0 ) != -1 ) { icon = rx6.cap ( 1 ); } // end while QMenuBar *menubar =g_pluginbl_report->menuBar(); QMenu *menu = NULL; QStringList path = pathtitulo.split("\\"); if (path.size() > 1) { QList<QMenu *> allPButtons = menubar->findChildren<QMenu *>(); bool encontrado = false; for (int j = 0; j < allPButtons.size(); ++j) { if (allPButtons.at(j)->title() == path[0]) { encontrado = true; menu = allPButtons.at(j); } // end if } // end for if (!encontrado) { QMenu *pPluginMenu1 = new QMenu (path[0] , menubar ); menubar->insertMenu ( pPluginVer->menuAction(), pPluginMenu1 ); menu = pPluginMenu1; } // end if } else { if (!pPluginMenu) { pPluginMenu = new QMenu ( _ ( "Informes" ), g_pluginbl_report->menuBar() ); pPluginMenu->setObjectName ( QString::fromUtf8 ( "menuInformes" ) ); g_pluginbl_report->menuBar()->insertMenu ( pPluginVer->menuAction(), pPluginMenu ); } // end if menu = pPluginMenu; } // end if for (int i = 1; i < path.size()-1; ++i) { QList<QMenu *> allPButtons = menu->findChildren<QMenu *>(); bool encontrado = false; for (int j = 0; j < allPButtons.size(); ++j) { if (allPButtons.at(j)->title() == path[i]) { encontrado = true; menu = allPButtons.at(j); } // end if } // end for if (!encontrado) { QMenu *pPluginMenu1 = new QMenu ( path[i] , menu ); menu->addMenu ( pPluginMenu1 ); menu = pPluginMenu1; } // end if } // end for /// Creamos el menú. QAction *accion = new QAction ( path[path.size()-1], 0 ); accion->setIcon(QIcon(icon)); accion->setObjectName ( fileInfo.fileName() ); accion->setStatusTip ( titulo); accion->setWhatsThis ( titulo ); mcont->connect ( accion, SIGNAL ( activated() ), mcont, SLOT ( elslot2() ) ); menu->addAction ( accion ); } // end for return 0; }