void MainWindow::onProfileYarpNetwork() { if(mainGraph.nodesCount()) { QMessageBox::StandardButton reply; reply = QMessageBox::question(this, "Profiling: clear current project", "Running profiler will clear the current project.\n Are you sure?", QMessageBox::Yes|QMessageBox::No); if (reply == QMessageBox::No) return; } mainGraph.clear(); QInputDialog* inputDialog = new QInputDialog(this); inputDialog->setOptions(QInputDialog::NoButtons); bool ok=false; float timeout = inputDialog->getDouble(nullptr ,"Profiling: yarp clean", "Do you want to run yarp clean before profiling?\n\n" "Be aware that yarp clean with a little timetout could\n" "unregister ports that are actually open.\n\n" "Timeout(seconds):", 0.3, 0, 2147483647, 1, &ok); if (ok) { messages.append("Cleaning death ports..."); NetworkProfiler::yarpClean(timeout); } messages.append("Getting the ports list..."); NetworkProfiler::ports_name_set ports; NetworkProfiler::yarpNameList(ports); messages.append("Getting the ports details..."); NetworkProfiler::ports_detail_set portsInfo; progressDlg = new QProgressDialog("...", "Cancel", 0, 100, this); progressDlg->setLabelText("Getting the ports details..."); progressDlg->reset(); progressDlg->setRange(0, ports.size()); progressDlg->setValue(0); progressDlg->setWindowModality(Qt::WindowModal); progressDlg->show(); for(size_t i=0; i<ports.size(); i++) { NetworkProfiler::PortDetails info; std::string portname = ports[i].find("name").asString(); std::string msg = string("Cheking ") + portname + "..."; messages.append(QString(msg.c_str())); if(NetworkProfiler::getPortDetails(portname, info)) portsInfo.push_back(info); progressDlg->setValue(i); if (progressDlg->wasCanceled()) return; } //progressDlg->setValue(ports.size()); stringModel.setStringList(messages); ui->messageView->update(); NetworkProfiler::setProgressCallback(this); progressDlg->setLabelText("Generating the graph..."); progressDlg->setRange(0, 100); progressDlg->setValue(0); NetworkProfiler::creatNetworkGraph(portsInfo, mainGraph); progressDlg->close(); delete progressDlg; progressDlg = nullptr; // update QoS NetworkProfiler::updateConnectionQosStatus(mainGraph); moduleParentItem->setExpanded(true); portParentItem->setExpanded(true); machinesParentItem->setExpanded(true); currentGraph = &mainGraph; // add process and port nodes to the tree populateTreeWidget(); drawGraph(*currentGraph); ui->actionHighlight_Loops->setEnabled(true); ui->actionHidePorts->setEnabled(true); ui->actionHideDisconnectedPorts->setEnabled(true); ui->actionHideConnectionsLable->setEnabled(true); ui->actionDebugMode->setEnabled(true); ui->actionUpdateConnectionQosStatus->setEnabled(true); ui->actionProfilePortsRate->setEnabled(true); }
QString GUI::_passwordDialog(const QString& cancel, const QString& body) { // we use a hack. It is considered that closing the dialog without explicitly clicking // disable history is confusing. But we can't distinguish between clicking the cancel // button and closing the dialog. So instead, we reverse the Ok and Cancel roles, // so that nothing but explicitly clicking disable history closes the dialog QString ret; QInputDialog dialog; dialog.setWindowTitle(tr("Enter your password")); dialog.setOkButtonText(cancel); dialog.setCancelButtonText(tr("Decrypt")); dialog.setInputMode(QInputDialog::TextInput); dialog.setTextEchoMode(QLineEdit::Password); dialog.setLabelText(body); // problem with previous hack: the default button is disable history, not decrypt. // use another hack to reverse the default buttons. // http://www.qtcentre.org/threads/49924-Change-property-of-QInputDialog-button QList<QDialogButtonBox*> l = dialog.findChildren<QDialogButtonBox*>(); if (!l.isEmpty()) { QPushButton* ok = l.first()->button(QDialogButtonBox::Ok); QPushButton* cancel = l.first()->button(QDialogButtonBox::Cancel); if (ok && cancel) { ok->setAutoDefault(false); ok->setDefault(false); cancel->setAutoDefault(true); cancel->setDefault(true); } else qWarning() << "PasswordDialog: Missing button!"; } else qWarning() << "PasswordDialog: No QDialogButtonBox!"; // using similar code, set QLabels to wrap for (auto* label : dialog.findChildren<QLabel*>()) label->setWordWrap(true); while (true) { int val = dialog.exec(); if (val == QDialog::Accepted) return QString(); else { ret = dialog.textValue(); if (!ret.isEmpty()) return ret; } dialog.setTextValue(""); dialog.setLabelText(body + "\n\n" + tr("You must enter a non-empty password:")); } }
int FileListModel::importFromCsv(QWidget *parent, const QString &inFile) { QFile file(inFile); if(!file.open(QIODevice::ReadOnly)) { return CsvError_FileOpen; } QTextCodec *codec = NULL; QByteArray bomCheck = file.peek(16); if((!bomCheck.isEmpty()) && bomCheck.startsWith("\xef\xbb\xbf")) { codec = QTextCodec::codecForName("UTF-8"); } else if((!bomCheck.isEmpty()) && bomCheck.startsWith("\xff\xfe")) { codec = QTextCodec::codecForName("UTF-16LE"); } else if((!bomCheck.isEmpty()) && bomCheck.startsWith("\xfe\xff")) { codec = QTextCodec::codecForName("UTF-16BE"); } else { const QString systemDefault = tr("(System Default)"); QStringList codecList; codecList.append(systemDefault); codecList.append(lamexp_available_codepages()); QInputDialog *input = new QInputDialog(parent); input->setLabelText(EXPAND(tr("Select ANSI Codepage for CSV file:"))); input->setOkButtonText(tr("OK")); input->setCancelButtonText(tr("Cancel")); input->setTextEchoMode(QLineEdit::Normal); input->setComboBoxItems(codecList); if(input->exec() < 1) { LAMEXP_DELETE(input); return CsvError_Aborted; } if(input->textValue().compare(systemDefault, Qt::CaseInsensitive)) { qDebug("User-selected codec is: %s", input->textValue().toLatin1().constData()); codec = QTextCodec::codecForName(input->textValue().toLatin1().constData()); } else { qDebug("Going to use the system's default codec!"); codec = QTextCodec::codecForName("System"); } LAMEXP_DELETE(input); } bomCheck.clear(); //----------------------// QTextStream stream(&file); stream.setAutoDetectUnicode(false); stream.setCodec(codec); QString headerLine = stream.readLine().simplified(); while(headerLine.isEmpty()) { if(stream.atEnd()) { qWarning("The file appears to be empty!"); return CsvError_FileRead; } qWarning("Skipping a blank line at beginning of CSV file!"); headerLine = stream.readLine().simplified(); } QStringList header = headerLine.split(";", QString::KeepEmptyParts); const int nCols = header.count(); const int nFiles = m_fileList.count(); if(nCols < 1) { qWarning("Header appears to be empty!"); return CsvError_FileRead; } bool *ignore = new bool[nCols]; memset(ignore, 0, sizeof(bool) * nCols); for(int i = 0; i < nCols; i++) { if((header[i] = header[i].trimmed()).isEmpty()) { ignore[i] = true; } } //----------------------// for(int i = 0; i < nFiles; i++) { if(stream.atEnd()) { LAMEXP_DELETE_ARRAY(ignore); return CsvError_Incomplete; } QString line = stream.readLine().simplified(); if(line.isEmpty()) { qWarning("Skipping a blank line in CSV file!"); continue; } QStringList data = line.split(";", QString::KeepEmptyParts); if(data.count() < header.count()) { qWarning("Skipping an incomplete line in CSV file!"); continue; } const QString key = m_fileList[i]; for(int j = 0; j < nCols; j++) { if(ignore[j]) { continue; } else if(CHECK_HDR(header.at(j), "POSITION")) { bool ok = false; unsigned int temp = data.at(j).trimmed().toUInt(&ok); if(ok) m_fileStore[key].metaInfo().setPosition(temp); } else if(CHECK_HDR(header.at(j), "TITLE")) { QString temp = data.at(j).trimmed(); if(!temp.isEmpty()) m_fileStore[key].metaInfo().setTitle(temp); } else if(CHECK_HDR(header.at(j), "ARTIST")) { QString temp = data.at(j).trimmed(); if(!temp.isEmpty()) m_fileStore[key].metaInfo().setArtist(temp); } else if(CHECK_HDR(header.at(j), "ALBUM")) { QString temp = data.at(j).trimmed(); if(!temp.isEmpty()) m_fileStore[key].metaInfo().setAlbum(temp); } else if(CHECK_HDR(header.at(j), "GENRE")) { QString temp = data.at(j).trimmed(); if(!temp.isEmpty()) m_fileStore[key].metaInfo().setGenre(temp); } else if(CHECK_HDR(header.at(j), "YEAR")) { bool ok = false; unsigned int temp = data.at(j).trimmed().toUInt(&ok); if(ok) m_fileStore[key].metaInfo().setYear(temp); } else if(CHECK_HDR(header.at(j), "COMMENT")) { QString temp = data.at(j).trimmed(); if(!temp.isEmpty()) m_fileStore[key].metaInfo().setComment(temp); } else { qWarning("Unkonw field '%s' will be ignored!", QUTF8(header.at(j))); ignore[j] = true; if(!checkArray(ignore, false, nCols)) { qWarning("No known fields left, aborting!"); return CsvError_NoTags; } } } } //----------------------// LAMEXP_DELETE_ARRAY(ignore); return CsvError_OK; }
void vkUploadImagesForm::on_toolButton_clicked() { QInputDialog dialog; QString newfolder = dialog.getText(this,tr("Title of new album"),tr("Please input title of new album")); if (!newfolder.isEmpty()) emit addNewAlbum(newfolder); }