void Updater::analyzeXmlResponse(QNetworkReply *reply) { layout->setCurrentIndex(1); QByteArray xml = reply->readAll(); QDomDocument doc; QString errorMsg; int errorLine, errorColumn; if (doc.setContent(xml, false, &errorMsg, &errorLine, &errorColumn) == false) { QMessageBox::critical(this, "XML Error", errorMsg + " at line " + QString::number(errorLine) + " column " + QString::number(errorColumn)); reject(); } QDomElement rootEl = doc.documentElement(); for (QDomElement el = rootEl.firstChildElement(); !el.isNull(); el = el.nextSiblingElement()) { if (el.tagName() == "version") { if (versionCompare(QCoreApplication::applicationVersion(), el.text()) == 1) { QMessageBox::information(this, tr("Updates avaible"), tr("A new version of Fado is avaible. Go and download it now.")); } } else if (el.tagName() == "machines") { for (QDomElement elMachine = el.firstChildElement("machine"); !elMachine.isNull(); elMachine = elMachine.nextSiblingElement("machine")) { Machine::MachineType type = Machine::MachineNull; QIcon icon; if (elMachine.attribute("type") == "generator") { type = Machine::MachineGenerator; icon = QIcon(":/icons/gear-small.png"); } else if (elMachine.attribute("type") == "effect") { type = Machine::MachineEffect; icon = QIcon(":/icons/funnel-small.png"); } if (type != Machine::MachineNull and searchMachine(elMachine.attribute("member"), elMachine.attribute("code")) == false) { QListWidgetItem *item = new QListWidgetItem(icon, elMachine.attribute("author")+" / "+elMachine.attribute("name"), listListWidget); item->setFlags(item->flags() | Qt::ItemIsUserCheckable); item->setCheckState(Qt::Checked); item->setData(Qt::UserRole+1, elMachine.attribute("member")); item->setData(Qt::UserRole+2, elMachine.attribute("code")); item->setData(Qt::UserRole+3, elMachine.attribute("author")); item->setData(Qt::UserRole+4, elMachine.attribute("name")); } } if (listListWidget->count() == 0) { QMessageBox::information(this, tr("No updates"), tr("There are no updatable machines")); this->reject(); } } } reply->deleteLater(); }
void DefinitionUpdater::checkVersion() { // parse reply data for version information const QByteArray data(reply->readAll()); reply->deleteLater(); QString remoteversion = parseVersion(data); // check for newer version if (versionCompare(remoteversion,version)>0) { version = remoteversion; save = new QFile(filename); save->open(QIODevice::WriteOnly | QIODevice::Truncate); if (save) { save->write(data); save->flush(); save->close(); delete save; save = NULL; } } }
void UpdateChecker::parseData(const QByteArray &data) { QDomDocument domDocument; if (domDocument.setContent(data)){ QDomElement root = domDocument.documentElement(); if (root.tagName() != "versions") { if (!silent) txsWarning(tr("Update check failed (invalid update file format).")); return; } QDomNodeList nodes = root.elementsByTagName("stable"); if (nodes.count() == 1) { QDomElement latestRelease = nodes.at(0).toElement(); m_latestVersion = latestRelease.attribute("value"); VersionCompareResult res = versionCompare(m_latestVersion, TXSVERSION); if (res == Invalid) { if (!silent) txsWarning(tr("Update check failed (invalid update file format).")); return; } if (res == Higher) { QString text = QString(tr( "A new version of TeXstudio is available.<br><br>" "Current version: %1<br>" "Latest version: %2<br><br>" "You can download it from the <a href='%3'>TeXstudio website</a>." )).arg(TXSVERSION).arg(m_latestVersion).arg("http://texstudio.sourceforge.net"); QMessageBox msgBox; msgBox.setWindowTitle(tr("TeXstudio Update")); msgBox.setTextFormat(Qt::RichText); msgBox.setText(text); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.exec(); } else { if (!silent) txsInformation(tr("TeXstudio is up-to-date.")); } ConfigManager::getInstance()->setOption("Update/LastCheck", QDateTime::currentDateTime()); emit checkCompleted(); } } }
void UpdateCheck::replyFinished(QNetworkReply *reply) { // Read in all the data if (!reply->isReadable()) { QMessageBox::warning(qobject_cast<QWidget*>(parent()), tr("Network Update Check Failed"), tr("Network timeout or other error.")); reply->deleteLater(); return; } QString version, releaseNotes; bool newVersionAvailable = false; // reply->canReadLine() always returns false, so this seems to best approach QStringList lines = QString(reply->readAll()).split('\n'); for(int i = 0; i < lines.size(); ++i) { if (lines[i] == "[Version]" && lines.size() > ++i) { version = lines[i]; if (versionCompare(version)) newVersionAvailable = true; } if (lines[i] == "[Release Notes]" && lines.size() > ++i) { // Right now just reading in the rest of the file as release notes for (int j = i-1; j >=0; --j) lines.removeAt(j); releaseNotes = lines.join("\n"); } } if (newVersionAvailable) { QPointer<UpdateDialog> info = new UpdateDialog(qobject_cast<QWidget *>(parent()), releaseNotes); info->exec(); delete info; } // Now we have warned the user, set this version as the prompted version *m_versionPrompted = version; // We are responsible for deleting the reply object reply->deleteLater(); }
void DefinitionUpdater::checkReadyRead() { // get all data received at the moment (more may follow) const QByteArray data(reply->readAll()); if (save) { // consecutive data received // -> append it to current file save->write(data); } else { // no file open -> first data for our request // -> parse reply data for version information QString remoteversion = parseVersion(data); // check for newer version if (versionCompare(remoteversion,version)>0) { version = remoteversion; save = new QFile(filename); save->open(QIODevice::WriteOnly | QIODevice::Truncate); if (save) { save->write(data); } } } }
void AppUpdater::finishedRead( int id, bool errors ) { (void)errors; // we'll get called here alternately by the setHost( ) request and the actual GET request // we don't care about setHost, so just return and wait for the GET response if( id != httpGetID ) return; QDomDocument doc; QString err; int line, col; if (!doc.setContent(http.readAll(), true, &err, &line, &col)) { headline.setText( "<font size=4>Couldn't contact the update server...</font>" ); details.setText( QString( "Make sure you're connected to the internet." ) ); acceptButton.setText( tr("OK") ); acceptButton.disconnect( ); // make sure it wasn't connected by anything else previously connect( &acceptButton, SIGNAL( clicked() ), this, SLOT( accept() ) ); removeBrowserAndIgnoreButton( ); if(!checkingOnStartup) this->show( ); return; } QDomElement channel = doc.documentElement().firstChild().toElement(); QDomNodeList items = channel.elementsByTagName("item"); QPair<QString, QString> latest(MCBUILDER_VERSION, ""); bool updateAvailable = false; for (int i=0, j=items.size(); i<j; i++) { QDomElement item = items.item(i).toElement(); if( item.isNull() ) continue; QDomNodeList enclosures = item.elementsByTagName("enclosure"); for (int k=0, l=enclosures.size(); k<l; k++) { QDomElement enclosure = enclosures.item(k).toElement(); if (enclosure.isNull()) continue; QString version = enclosure.attributeNS( "http://www.andymatuschak.org/xml-namespaces/sparkle", "version", "not-found" ); // each item can have multiple enclosures, of which at least one // should have a version field if (version == "not-found") continue; if( versionCompare(version, latest.first) > 0 ) { latest.first = version; QDomNodeList descs = item.elementsByTagName("description"); //I(descs.size() == 1); QDomElement desc = descs.item(0).toElement(); //I(!desc.isNull()); latest.second = desc.text(); updateAvailable = true; } } } // add the appropriate elements/info depending on whether an update is available if( updateAvailable ) { headline.setText( "<font size=4>A new version of mcbuilder is available!</font>" ); QString d = QString( "mcbuilder %1 is now available (you have %2). Would you like to download it?" ) .arg(latest.first).arg( MCBUILDER_VERSION ); details.setText( d ); browser.setHtml( latest.second ); acceptButton.setText( tr("Visit Download Page") ); acceptButton.disconnect( ); ignoreButton.disconnect( ); connect( &acceptButton, SIGNAL( clicked() ), this, SLOT( visitDownloadsPage() ) ); connect( &ignoreButton, SIGNAL( clicked() ), this, SLOT( accept() ) ); if( textLayout.indexOf( &browser ) < 0 ) // if the browser's not in the layout, then insert it after the details line textLayout.insertWidget( textLayout.indexOf( &details ) + 1, &browser ); if( buttonLayout.indexOf( &ignoreButton ) < 0 ) // put the ignore button on the left buttonLayout.insertWidget( 0, &ignoreButton ); this->show( ); } else { headline.setText( "<font size=4>You're up to date!</font>" ); details.setText( QString( "You're running the latest version of mcbuilder, version %1." ).arg( MCBUILDER_VERSION ) ); acceptButton.setText( tr("OK") ); acceptButton.disconnect( ); connect( &acceptButton, SIGNAL( clicked() ), this, SLOT( accept() ) ); removeBrowserAndIgnoreButton( ); if(!checkingOnStartup) this->show( ); } }
void UpdateChecker::resultReceiver(QString data) { QDomDocument xml; qDebug() << data; xml.setContent(data); QDomElement productxml = xml.firstChildElement("product"); if (productxml.isNull()) { QMessageBox::critical(NULL, tr("Error"), tr("Could not check for updates. Wrong server response.")); inProgress = false; return; } QDomElement urlxml = productxml.firstChildElement("url"); QString url = urlxml.text(); QDomNodeList versionsx = xml.elementsByTagName("version"); if (versionsx.length()==0) { QMessageBox::critical(NULL, tr("Error"), tr("Could not check for updates. No versions found.")); inProgress = false; return; } QString platform; #ifdef Q_OS_WIN platform = "WIN"; #endif #ifdef Q_OS_MAC platform = "MAC"; #endif if (platform.isEmpty()) platform = "UNIX"; QStringList versions; QMap<QString, QUrl> urls; for(unsigned int i=0; i<versionsx.length(); i++) { QDomNode version = versionsx.at(i); QDomNode platformx = version.attributes().namedItem("platform"); if (platformx.isNull()) continue; QString vpl = platformx.nodeValue(); if ((vpl != platform) && (vpl != "ALL")) continue; QString ver = version.attributes().namedItem("id").nodeValue(); versions.append(ver); QDomElement xurl = version.toElement().firstChildElement("url"); urls[ver] = QUrl(xurl.text()); } if (!versions.size()) { if (!workSilent) QMessageBox::information(NULL, tr("No updates available"), tr("You have the latest version of this application.")); inProgress = false; return; } qSort( versions.begin(), versions.end(), versionCompare); // I should write Version class with right compare QString version = versions.first(); // operator and use QMap's auto sorting. if (versionCompare(version, QApplication::applicationVersion())) { QMessageBox msg; msg.addButton(tr("Yes"), QMessageBox::YesRole); msg.addButton(tr("No"), QMessageBox::NoRole); msg.setText(tr("Lastest version is %1. Do you want to update?").arg(version)); msg.setWindowTitle(tr("Update available")); msg.exec(); if (msg.buttonRole(msg.clickedButton()) == QMessageBox::YesRole) { QDesktopServices().openUrl(urls[version]); } } else { if (!workSilent) { QMessageBox::information(NULL, tr("No updates available"), tr("You have the latest version of this application.")); } } inProgress = false; }