bool PumpSpreadsheet::saveDataInPump2000Format(const QString &fileName) { QFile file(fileName); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { showWarning(tr("Cannot write file %1:\n%2.") .arg(file.fileName()) .arg(file.errorString())); return false; } QTextStream out(&file); for (int row = 0; row < rowCount(); ++row) { for (int column = 0; column < ColumnCount; ++column) { out << text(row, column); if (column < ColumnCount - 1) { out << "\t"; } else { out << endl; } } } file.close(); if (file.error() != QFile::NoError) { showWarning(tr("Error when writing to %1:\n%2.") .arg(file.fileName()) .arg(file.errorString())); return false; } return true; }
void AccountSettingsDialog::onSubmitBtnClicked() { if (!validateInputs()) { return; } QString url = mServerAddr->text().trimmed(); if (url != account_.serverUrl.toString()) { Account new_account(account_); new_account.serverUrl = url; if (seafApplet->accountManager()->replaceAccount(account_, new_account) < 0) { showWarning(tr("Failed to save account information")); return; } QString error; QUrl new_server_url = new_account.serverUrl; new_server_url.setPath("/"); if (seafApplet->rpcClient()->updateReposServerHost(account_.serverUrl.host(), new_account.serverUrl.host(), new_server_url.toString(), &error) < 0) { showWarning(tr("Failed to save the changes: %1").arg(error)); return; } } seafApplet->messageBox(tr("Successfully updated current account information"), this); accept(); }
QByteArray ToxDNS::fetchLastTextRecord(const QString& record, bool silent) { QByteArray result; QDnsLookup dns; dns.setType(QDnsLookup::TXT); dns.setName(record); dns.lookup(); int timeout; for (timeout = 0; timeout<30 && !dns.isFinished(); ++timeout) { qApp->processEvents(); QThread::msleep(100); } if (timeout >= 30) { dns.abort(); if (!silent) showWarning(tr("The connection timed out","The DNS gives the Tox ID associated to toxme.se addresses")); return result; } if (dns.error() == QDnsLookup::NotFoundError) { if (!silent) showWarning(tr("This address does not exist","The DNS gives the Tox ID associated to toxme.se addresses")); return result; } else if (dns.error() != QDnsLookup::NoError) { if (!silent) showWarning(tr("Error while looking up DNS","The DNS gives the Tox ID associated to toxme.se addresses")); return result; } const QList<QDnsTextRecord> textRecords = dns.textRecords(); if (textRecords.isEmpty()) { if (!silent) showWarning(tr("No text record found", "Error with the DNS")); return result; } const QList<QByteArray> textRecordValues = textRecords.last().values(); if (textRecordValues.length() != 1) { if (!silent) showWarning(tr("Unexpected number of values in text record", "Error with the DNS")); return result; } result = textRecordValues.first(); return result; }
bool PumpSpreadsheet::addDataInPump2000Format(const QString &fileName) { QFile file(fileName); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { showWarning(tr("Cannot read file %1:\n%2.") .arg(file.fileName()) .arg(file.errorString())); return false; } QTextStream in(&file); while (!in.atEnd()) { QString line = in.readLine().simplified(); QStringList fields = line.split(' '); if (fields.count() == 7) addItem(fields); } file.close(); if (file.error() != QFile::NoError) { showWarning(tr("Error when reading from %1:\n%2.") .arg(file.fileName()) .arg(file.errorString())); return false; } return true; }
bool PumpSpreadsheet::addDataInGasPumpXmlFormat(const QString &fileName) { QFile file(fileName); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { showWarning(tr("Cannot read file %1:\n%2.") .arg(file.fileName()) .arg(file.errorString())); return false; } QXmlStreamReader reader(&file); reader.readNext(); while (!reader.atEnd()) { if (reader.isStartElement()) { if (reader.name() == "gpx") { readGpxElement(reader); } else { reader.raiseError(tr("Not a Gas Pump XML file")); } } else { reader.readNext(); } } file.close(); if (file.error() != QFile::NoError) { showWarning(tr("Error when writing to %1:\n%2.") .arg(file.fileName()) .arg(file.errorString())); return false; } return true; }
QString ToxDNS::queryTox1(const QString& record, bool silent) { QString realRecord = record, toxId; realRecord.replace("@", "._tox."); const QString entry = fetchLastTextRecord(realRecord, silent); if (entry.isEmpty()) return toxId; // Check toxdns protocol version int verx = entry.indexOf("v="); if (verx) { verx += 2; int verend = entry.indexOf(';', verx); if (verend) { QString ver = entry.mid(verx, verend-verx); if (ver != "tox1") { if (!silent) showWarning(tr("The version of Tox DNS used by this server is not supported", "Error with the DNS")); return toxId; } } } // Get the tox id int idx = entry.indexOf("id="); if (idx < 0) { if (!silent) showWarning(tr("The DNS lookup does not contain any Tox ID", "Error with the DNS")); return toxId; } idx += 3; if (entry.length() < idx + static_cast<int>(TOX_HEX_ID_LENGTH)) { if (!silent) showWarning(tr("The DNS lookup does not contain a valid Tox ID", "Error with the DNS")); return toxId; } toxId = entry.mid(idx, TOX_HEX_ID_LENGTH); if (!ToxId::isToxId(toxId)) { if (!silent) showWarning(tr("The DNS lookup does not contain a valid Tox ID", "Error with the DNS")); return toxId; } return toxId; }
TERMINAL_ACT_INFO* GetNextNameClass::GetName(const FN_STATE_ACT_LIST* period_info, TERMINAL_ACT_LIST* act_list,int ¤t_pos,int time_pos) { FNDWORD k = 0;// if (period_info == NULL) { showWarning("时间表为空,请检查时间表\n"); return NULL; } if (act_list == NULL) { showWarning("节目表为空,请检查节目表\n"); return NULL; } if(period_info->dwSectionCnt == 0) { showWarning("节目表时段数量为0\n"); return NULL; } if(time_pos >= (int)period_info->dwSectionCnt && time_pos < 0) { showWarning("当前时间在时间表时段内越界\n"); return NULL; } current_pos = current_pos + 1; if(current_pos >= (int)period_info->SectionList[time_pos].dwActCnt)//循环播放 { current_pos=0; } showDebug("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-40\n"); //获取到一个播放的节目号,还要通过这个号码在节目表中找到具体的节目 k = period_info->SectionList[time_pos].dwActList[current_pos]; for(FNDWORD i=0;i<act_list->dwActNum;i++) { if(act_list->ActList[i].sActInfo.dwActID == k) { act_endtime = period_info->SectionList[time_pos].dwEndTime; return &act_list->ActList[i]; } } showWarning("获取节目%u失败,当前时段为%u\n",k,time_pos ); act_endtime = 0; return NULL; }
void InsertLinkOrPictureDialog::checkAndAccept() { QString text = ui->textLineEdit->text(); if(text.isEmpty() && text.trimmed().isEmpty()){ showWarning(tr("Alt Text can't be empty!"), tr("Link Text cann't be empty!")); return; } QString url = ui->urlLineEdit->text(); if(url.isEmpty() && url.trimmed().isEmpty()){ showWarning(tr("Picture Url can't be empty!"), tr("Link Url cann't be empty!")); return; } accept(); }
bool QgsOfflineEditing::createSpatialiteDB( const QString& offlineDbPath ) { int ret; sqlite3 *sqlite_handle; char *errMsg = NULL; QFile newDb( offlineDbPath ); if ( newDb.exists() ) { QFile::remove( offlineDbPath ); } // see also QgsNewSpatialiteLayerDialog::createDb() QFileInfo fullPath = QFileInfo( offlineDbPath ); QDir path = fullPath.dir(); // Must be sure there is destination directory ~/.qgis QDir().mkpath( path.absolutePath( ) ); // creating/opening the new database QString dbPath = newDb.fileName(); spatialite_init( 0 ); ret = sqlite3_open_v2( dbPath.toUtf8().constData(), &sqlite_handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL ); if ( ret ) { // an error occurred QString errCause = tr( "Could not create a new database\n" ); errCause += QString::fromUtf8( sqlite3_errmsg( sqlite_handle ) ); sqlite3_close( sqlite_handle ); showWarning( errCause ); return false; } // activating Foreign Key constraints ret = sqlite3_exec( sqlite_handle, "PRAGMA foreign_keys = 1", NULL, 0, &errMsg ); if ( ret != SQLITE_OK ) { showWarning( tr( "Unable to activate FOREIGN_KEY constraints" ) ); sqlite3_free( errMsg ); sqlite3_close( sqlite_handle ); return false; } initializeSpatialMetadata( sqlite_handle ); // all done: closing the DB connection sqlite3_close( sqlite_handle ); return true; }
void LoginDialog::onNetworkError(const QNetworkReply::NetworkError& error, const QString& error_string) { showWarning(tr("Network Error:\n %1").arg(error_string)); enableInputs(); mStatusText->setText(""); }
QgsOfflineEditing::AttributeValueChanges QgsOfflineEditing::sqlQueryAttributeValueChanges( sqlite3* db, const QString& sql ) { AttributeValueChanges values; sqlite3_stmt* stmt = NULL; if ( sqlite3_prepare_v2( db, sql.toUtf8().constData(), -1, &stmt, NULL ) != SQLITE_OK ) { showWarning( sqlite3_errmsg( db ) ); return values; } int ret = sqlite3_step( stmt ); while ( ret == SQLITE_ROW ) { AttributeValueChange change; change.fid = sqlite3_column_int( stmt, 0 ); change.attr = sqlite3_column_int( stmt, 1 ); change.value = QString(( const char* )sqlite3_column_text( stmt, 2 ) ); values << change; ret = sqlite3_step( stmt ); } sqlite3_finalize( stmt ); return values; }
QList<QgsField> QgsOfflineEditing::sqlQueryAttributesAdded( sqlite3* db, const QString& sql ) { QList<QgsField> values; sqlite3_stmt* stmt = NULL; if ( sqlite3_prepare_v2( db, sql.toUtf8().constData(), -1, &stmt, NULL ) != SQLITE_OK ) { showWarning( sqlite3_errmsg( db ) ); return values; } int ret = sqlite3_step( stmt ); while ( ret == SQLITE_ROW ) { QgsField field( QString(( const char* )sqlite3_column_text( stmt, 0 ) ), ( QVariant::Type )sqlite3_column_int( stmt, 1 ), "", // typeName sqlite3_column_int( stmt, 2 ), sqlite3_column_int( stmt, 3 ), QString(( const char* )sqlite3_column_text( stmt, 4 ) ) ); values << field; ret = sqlite3_step( stmt ); } sqlite3_finalize( stmt ); return values; }
void CMainFrame::OnFileOpen(int id) { TextView *view = getActiveTextView(); if(view == NULL) { showWarning(_T("No active view")); return; } CFileDialog dlg(TRUE); dlg.m_ofn.lpstrFilter = getFileDialogExtension().cstr(); dlg.m_ofn.lpstrTitle = _T("Open files"); dlg.m_ofn.nFilterIndex = getOptions().m_defaultExtensionIndex; dlg.m_ofn.Flags |= OFN_ALLOWMULTISELECT | OFN_FILEMUSTEXIST; TCHAR fileNames[1024]; fileNames[0] = 0; dlg.m_ofn.lpstrFile = fileNames; dlg.m_ofn.nMaxFile = ARRAYSIZE(fileNames); if((dlg.DoModal() != IDOK) || (_tcsclen(fileNames) == 0)) { return; } getOptions().m_defaultExtensionIndex = dlg.m_ofn.nFilterIndex; TCHAR *files[3]; getFileNames(files,fileNames); CWinDiffDoc *doc = view->getDocument(); if(_tcsclen(files[1]) == 0) { // only one selected doc->setDoc(id, DIFFDOC_FILE, files[0]); } else { const String f1 = FileNameSplitter::getChildName(files[0],files[1]); const String f2 = FileNameSplitter::getChildName(files[0],files[2]); doc->setDocs(f1, f2); } Invalidate(FALSE); }
ccShiftAndScaleCloudDlg::ccShiftAndScaleCloudDlg( const CCVector3d& Pl, double Dl, const CCVector3d& Pg, double Dg, QWidget* parent/*=0*/) : QDialog(parent) , m_ui(0) , m_applyAll(false) , m_cancel(false) , m_activeInfoIndex(-1) , m_originalPoint(Pg) , m_originalDiagonal(Dg) , m_localPoint(Pl) , m_localDiagonal(Dl) , m_reversedMode(true) { init(); showWarning(false); showTitle(false); showKeepGlobalPosCheckbox(true); showScaleItems(m_originalDiagonal > 0.0 && m_localDiagonal > 0.0); showCancelButton(true); //to update the GUI accordingly onGlobalPosCheckBoxToggled(m_ui->keepGlobalPosCheckBox->isChecked()); }
void CEnterOptionsNameDlg::OnOK() { UpdateData(); m_name.TrimLeft(); m_name.TrimRight(); if(m_name.GetLength() == 0) { getNameCombo()->SetFocus(); showWarning(_T("Please enter a name")); return; } const StringArray names = Options::getExistingNames(); if(names.size() >= 9 && !names.contains((LPCTSTR)m_name)) { getNameCombo()->SetFocus(); showWarning(_T("Max 9 different settings can be saved")); return; } __super::OnOK(); }
String getWindowText(const CWnd *wnd, int id) { CWnd *ctrl = wnd->GetDlgItem(id); if(ctrl == NULL) { showWarning(_T("No dlgItem %d in window"), id); return EMPTYSTRING; } return getWindowText(ctrl); }
void setWindowText(CWnd *wnd, int id, const String &str) { CWnd *ctrl = wnd->GetDlgItem(id); if(ctrl == NULL) { showWarning(_T("No dlgItem %d in window"), id); return; } setWindowText(ctrl, str); }
void CPasswordDlg::OnOK() { UpdateData(); if(m_password != m_expectedPassword) { showWarning(_T("Forkert kodeord")); OnCancel(); } else { __super::OnOK(); } }
bool CHexViewView::dropAnchor(unsigned __int64 index) { if(index > m_docSize) { showWarning(_T("dropAnchor:index=%I64u, docSize=%I64d"), index, m_docSize); return false; } const bool ret = index != m_anchor; m_anchor = index; return ret; }
int QgsOfflineEditing::sqlExec( sqlite3* db, const QString& sql ) { char * errmsg; int rc = sqlite3_exec( db, sql.toUtf8(), NULL, NULL, &errmsg ); if ( rc != SQLITE_OK ) { showWarning( errmsg ); } return rc; }
void AddFriendForm::onSendTriggered() { QString id = toxId.text().trimmed(); if (id.isEmpty()) { showWarning(tr("Please fill in a valid Tox ID","Tox ID of the friend you're sending a friend request to")); } else if (isToxId(id)) { if (id.toUpper() == Core::getInstance()->getSelfId().toString().toUpper()) showWarning(tr("You can't add yourself as a friend!","When trying to add your own Tox ID as friend")); else emit friendRequested(id, getMessage()); this->toxId.setText(""); this->message.setText(""); } else { id = id.replace("@", "._tox."); dns.setName(id); dns.lookup(); } }
void PkInstallProvideFiles::notFound() { if (m_alreadyInstalled.size()) { if (showWarning()) { setInfo(i18n("Failed to install file"), i18n("The %1 package already provides this file", m_alreadyInstalled)); } sendErrorFinished(Failed, "already provided"); } else { if (showWarning()) { setInfo(i18n("Failed to find package"), i18np("The file could not be found in any packages", "The files could not be found in any packages", m_args.size())); } sendErrorFinished(NoPackagesFound, "no files found"); } }
void PrecisionDlg::OnOK() { if(!UpdateData()) { return; } if(m_precision < 1 || m_precision > MAXPRECISION) { OnGotoPrecision(); showWarning(_T("Please enter an integer between 1 and %d"), MAXPRECISION); return; } __super::OnOK(); }
void DishInfoDialog::on_lineEditId_textChanged(const QString &arg1) { if (isIDConflict(arg1)) { showWarning("输入菜品的ID已经存在!"); } else { clearWarning(); } }
bool PumpSpreadsheet::saveDataInGasPumpXmlFormat( const QString &fileName) { QFile file(fileName); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { showWarning(tr("Cannot write file %1:\n%2.") .arg(file.fileName()) .arg(file.errorString())); return false; } QXmlStreamWriter writer(&file); writer.setAutoFormatting(true); writer.writeStartDocument(); writer.writeStartElement("gpx"); for (int row = 0; row < rowCount(); ++row) { writer.writeStartElement("transaction"); writer.writeTextElement("date", text(row, Date)); writer.writeTextElement("time", text(row, Time)); writer.writeTextElement("pump", text(row, Pump)); writer.writeTextElement("company", text(row, Company)); writer.writeTextElement("user", text(row, User)); writer.writeTextElement("quantity", text(row, Quantity)); writer.writeTextElement("status", text(row, Status)); writer.writeEndElement(); } writer.writeEndElement(); writer.writeEndDocument(); file.close(); if (file.error() != QFile::NoError) { showWarning(tr("Error when writing to %1:\n%2.") .arg(file.fileName()) .arg(file.errorString())); return false; } return true; }
bool LoginDialog::getShibLoginUrl(const QString& last_shib_url, QUrl *url_out) { QString server_addr = last_shib_url; QUrl url; while (true) { bool ok; server_addr = seafApplet->getText(this, tr("Single Sign On"), tr("%1 Server Address").arg(getBrand()), QLineEdit::Normal, server_addr, &ok); server_addr = server_addr.trimmed(); // exit when user hits cancel button if (!ok) { return false; } if (server_addr.isEmpty()) { showWarning(tr("Server address must not be empty").arg(server_addr)); continue; } if (!server_addr.startsWith("https://")) { showWarning(tr("%1 is not a valid server address. It has to start with 'https://'").arg(server_addr)); continue; } url = QUrl(server_addr, QUrl::StrictMode); if (!url.isValid()) { showWarning(tr("%1 is not a valid server address").arg(server_addr)); continue; } *url_out = url; return true; } }
void XtgScanner::xtgParse() { /* Enter the default mode as textMode */ enterState(textMode); writer->setCharStyle(""); writer->setStyle(""); currentCharStyle = writer->getCurrentCharStyle(); currentParagraphStyle = writer->getCurrentStyle(); while (input_Buffer.at(top) != '\0') { token = getToken(); QHash<QString,void (XtgScanner::*)(void)> *temp = NULL; if (Mode == tagMode) temp = &tagModeHash; if (Mode == nameMode) temp = &nameModeHash; if (Mode == textMode) temp = &textModeHash; if (temp->contains(token) ) { funPointer = temp->value(token); (this->*funPointer)(); } /** Various character Style Applications <@stylesheetname>. We cannot hash this since stylesheetname is not constant */ else if ( (currentState() == tagMode ) && token.startsWith('@') && token.endsWith('>') ) { /*here we receive a token @stylesheetname>, hence we have to slice of token to get the name of character stylesheet to be applied */ define = 0; sfcName = token.remove(0,1); sfcName = sfcName.remove(sfcName.size()-1,1); flushText(); if (styleStatus(definedCStyles,sfcName)) writer->setCharStyle(sfcName); else { showWarning(sfcName); writer->setCharStyle(""); } currentCharStyle = writer->getCurrentCharStyle(); } if (top == input_Buffer.length()) break; } writer->appendText(textToAppend); qDebug()<<"Unsupported : "<<unSupported; }
void action(const gcn::ActionEvent& actionEvent) { int selected_item; selected_item = savestatelistBox->getSelected(); BuildBaseDir(savestate_filename); strcat(savestate_filename, "/"); strcat(savestate_filename, savestateList.getElementAt(selected_item).c_str()); if(unlink(savestate_filename)) { showWarning("Failed to delete savestate."); } else { BuildBaseDir(savestate_filename); savestateList = savestate_filename; } }
void MainWindow::openFile(const QString &mml_file_name) { m_mml_widget->clear(); m_compare_image->clear(); QFile file(mml_file_name); if (!file.open(QIODevice::ReadOnly)) { showWarning("File error: Could not open \"" + mml_file_name + "\": " + file.errorString()); return; } QTextStream stream(&file); // stream.setEncoding(QTextStream::UnicodeUTF8); QString text = stream.readAll(); file.close(); QString error_msg; int error_line, error_column; bool result = m_mml_widget->setContent(text, &error_msg, &error_line, &error_column); if (!result) { showWarning("Parse error: line " + QString::number(error_line) + ", col " + QString::number(error_column) + ": " + error_msg); return; } QPixmap pm; int idx = mml_file_name.lastIndexOf('.'); if (idx != -1) { QString image_file_name = mml_file_name.mid(0, idx + 1) + "png"; if (pm.load(image_file_name)) m_compare_image->setPixmap(pm); } }
void XtgScanner::defineCStyle() { //token [St QString s4; top = top+10; s4 = getToken(); if (styleStatus(definedCStyles,s4)) defCharStyle.setParent(s4); else { showWarning(s4); defCharStyle.setParent("Default Character Style"); } }