void UpdateChecker::onNetworkReply(QNetworkReply *reply) { qWarning() << "Received network reply"; if (reply->error() != QNetworkReply::NoError) { qWarning() << reply->errorString(); //output some meaningful error msg return; } availVersion = QString(reply->readAll()); availVersion = availVersion.trimmed(); QStringList curVersionParts = currentVer.split("."); QStringList availVersionParts = availVersion.split("."); if (availVersionParts.size() != 3 || curVersionParts.size() != 3) { qWarning() << "Got invalid version info from server"; return; } int availMajor = availVersionParts.at(0).toInt(); int availMinor = availVersionParts.at(1).toInt(); int availRevis = availVersionParts.at(2).toInt(); int curMajor = curVersionParts.at(0).toInt(); int curMinor = curVersionParts.at(1).toInt(); int curRevis = curVersionParts.at(2).toInt(); if (availMajor > curMajor) emit newVersionAvailable(availVersion); else if (availMajor == curMajor && availMinor > curMinor) emit newVersionAvailable(availVersion); else if (availMajor == curMajor && availMinor == curMinor && availRevis > curRevis) emit newVersionAvailable(availVersion); qWarning() << "Received version: " << availVersion << " Current version: " << currentVer; reply->deleteLater(); }
BluecherryApp::BluecherryApp() : nam(new QNetworkAccessManager(this)), liveView(new LiveViewManager(this)), globalRate(new TransferRateCalculator(this)), m_updateChecker(0), m_livePaused(false), m_inPauseQuery(false), m_screensaverInhibited(false), m_screensaveValue(0) { Q_ASSERT(!bcApp); bcApp = this; m_serverRepository = new DVRServerRepository(this); connect(qApp, SIGNAL(aboutToQuit()), SLOT(aboutToQuit())); appIcon.addFile(QLatin1String(":/icons/icon16.png")); appIcon.addFile(QLatin1String(":/icons/icon32.png")); appIcon.addFile(QLatin1String(":/icons/icon64.png")); appIcon.addFile(QLatin1String(":/icons/bluecherry-client.png")); qApp->setWindowIcon(appIcon); connect(nam, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), SLOT(sslErrors(QNetworkReply*,QList<QSslError>))); /* Don't use the system CAs to verify certificates */ QSslConfiguration sslConfig = QSslConfiguration::defaultConfiguration(); sslConfig.setCaCertificates(QList<QSslCertificate>()); #if QT_VERSION >= 0x040800 /* SNI breaks connections (before sslError, even) when the hostname does * not match the server. */ sslConfig.setSslOption(QSsl::SslOptionDisableServerNameIndication, true); #endif QSslConfiguration::setDefaultConfiguration(sslConfig); loadServers(); if (shouldAddLocalServer()) addLocalServer(); autoConnectServers(); sendSettingsChanged(); m_updateChecker = new UpdateChecker(nam, this); connect(m_updateChecker, SIGNAL(newVersionAvailable(Version)), this, SLOT(newVersionAvailable(Version))); QSettings settings; if (!settings.value(QLatin1String("ui/disableUpdateNotifications"), false).toBool()) { startUpdateChecker(); } m_mediaDownloadManager = new MediaDownloadManager(this); m_mediaDownloadManager->setCookieJar(nam->cookieJar()); m_eventDownloadManager = new EventDownloadManager(this); connect(m_serverRepository, SIGNAL(serverRemoved(DVRServer*)), m_eventDownloadManager, SLOT(serverRemoved(DVRServer*))); registerVideoPlayerFactory(); connect(qApp, SIGNAL(commitDataRequest(QSessionManager&)), this, SLOT(commitDataRequest(QSessionManager&))); connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(saveSettings())); }
void cUpdater::processDisconnected() { if (m_Data.isEmpty()){ qCritical() << "cUpdater: check failed. no response"; return; } int pos = m_Data.indexOf("HTTP/1.1"); if (pos==-1) pos = m_Data.indexOf("HTTP/1.0"); if (pos==-1){ qCritical() << "cUpdater: check failed. no response"; return; } pos = m_Data.indexOf(" ",pos); int pos2 = m_Data.indexOf("\r",pos); QString Status = m_Data.mid(pos+1,pos2-(pos+1)); if (Status!="200 OK"){ qCritical() << "cUpdater: check failed. response:" << Status; return; } m_AvailableVersion = m_Data.split("\n").last(); cSettings settings; QString lastAvailableVersion = settings.db()->value(cDataManager::CONF_LAST_AVAILABLE_VERSION_ID,CURRENT_VERSION).toString(); if (m_AvailableVersion!=lastAvailableVersion) emit newVersionAvailable(m_AvailableVersion); }
void Updater::replyFinished(QNetworkReply *reply) { QString replyText = reply->readAll(); if(reply->error() != QNetworkReply::NoError) { //Parse servers response QDomDocument doc("error"); if (!doc.setContent(replyText)) { //No XML to parse, user is probably disconnected return; }else { QDomElement docElem = doc.documentElement(); QDomElement message = docElem.firstChildElement("message"); if(!message.text().isEmpty()) { QMessageBox msgBox; msgBox.setWindowTitle("Failed to check for updates"); msgBox.setIcon(QMessageBox::Warning); msgBox.setText("Failed to check for updates.\nError was: " + message.text()); msgBox.exec(); } } }else { //No error in request QDomDocument doc("reply"); if (!doc.setContent(replyText)) { return; } QDomElement docElem = doc.documentElement(); QDomElement versionElem = docElem.firstChildElement("current_version"); QDomElement outdatedElem = docElem.firstChildElement("outdated"); latestVersion = versionElem.text(); bool outdated = QVariant(outdatedElem.text()).toBool(); if(outdated && notifyUpdates) { emit newVersionAvailable(latestVersion); showUpdateNotification(); } emit versionNumberRecieved(latestVersion, outdated); } }
LTWindow::LTWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::LTWindow), eventData(EventData::getInstance()) { ui->setupUi(this); currDriver = -1; streamReader = new DataStreamReader(this); prefs = new PreferencesDialog(this); settings = new QSettings(F1LTCore::iniFile(), QSettings::IniFormat, this); loginDialog = new LoginDialog(this); ltFilesManagerDialog = new LTFilesManagerDialog(this); trackRecordsDialog = new TrackRecordsDialog(this); saw = new SessionAnalysisWidget(); stw = new SessionTimesWidget(); driverTrackerWidget = new DriverTrackerWidget(); aboutDialog = new AboutDialog(this); updatesCheckerDialog = new UpdatesCheckerDialog(this); // ui->trackStatusWidget->setupItems(); connect(streamReader, SIGNAL(tryAuthorize()), this, SLOT(tryAuthorize())); connect(streamReader, SIGNAL(authorized(QString)), this, SLOT(authorized(QString))); connect(streamReader, SIGNAL(eventDataChanged(const DataUpdates&)), this, SLOT(eventDataChanged(const DataUpdates&))); connect(streamReader, SIGNAL(driverDataChanged(int, const DataUpdates&)), this, SLOT(driverDataChanged(int, const DataUpdates&))); connect(streamReader, SIGNAL(dataChanged(const DataUpdates&)), this, SLOT(dataChanged(const DataUpdates&))); connect(streamReader, SIGNAL(sessionStarted()), this, SLOT(sessionStarted())); connect(streamReader, SIGNAL(authorizationError()), this, SLOT(authorizationError())); connect(streamReader, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error(QAbstractSocket::SocketError))); connect(streamReader, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(error(QNetworkReply::NetworkError))); connect(streamReader, SIGNAL(noLiveSession(bool, QString)), this, SLOT(showNoSessionBoard(bool, QString))); connect(updatesCheckerDialog, SIGNAL(newVersionAvailable()), this, SLOT(onNewVersionAvailable())); sessionTimer = new SessionTimer(this); connect(sessionTimer, SIGNAL(updateWeather()), this, SLOT(updateWeather())); connect(&SeasonData::getInstance(), SIGNAL(seasonDataChanged()), &ImagesFactory::getInstance(), SLOT(reloadGraphics())); connect(&SeasonData::getInstance(), SIGNAL(seasonDataChanged()), &ColorsManager::getInstance(), SLOT(calculateDefaultDriverColors())); connect(&SeasonData::getInstance(), SIGNAL(seasonDataChanged()), saw, SLOT(setupColors())); connect(prefs, SIGNAL(driversColorsChanged()), saw, SLOT(setupColors())); eventRecorder = new EventRecorder(sessionTimer, this); eventPlayer = new EventPlayer(this); delayWidget = new DelayWidget(this); connect(delayWidget, SIGNAL(delayChanged(int, int)), streamReader, SLOT(setDelay(int, int))); connect(delayWidget, SIGNAL(delayChanged(int, int)), sessionTimer, SLOT(setDelay(int, int))); connect(sessionTimer, SIGNAL(synchronizingTimer(bool)), delayWidget, SLOT(synchronizingTimer(bool))); connect(sessionTimer, SIGNAL(synchronizingTimer(bool)), driverTrackerWidget, SLOT(pauseTimer(bool))); connect(ui->messageBoardWidget, SIGNAL(connectClicked()), this, SLOT(on_actionConnect_triggered())); connect(ui->messageBoardWidget, SIGNAL(playClicked()), this, SLOT(on_actionOpen_triggered())); connect(ui->messageBoardWidget, SIGNAL(loadClicked()), this, SLOT(on_actionLT_files_data_base_triggered())); loadSettings(); ColorsManager::getInstance().calculateDefaultDriverColors(); saw->setupColors(); delayWidgetAction = ui->mainToolBar->addWidget(delayWidget); delayWidgetAction->setVisible(true); eventPlayerAction = ui->mainToolBar->addWidget(eventPlayer); eventPlayerAction->setVisible(false); recording = false; playing = false; connectionProgress = new QProgressDialog(this); connect(sessionTimer, SIGNAL(timeout()), this, SLOT(timeout())); connect(eventRecorder, SIGNAL(recordingStopped()), this, SLOT(autoStopRecording())); connect(eventPlayer, SIGNAL(playClicked(int)), this, SLOT(eventPlayerPlayClicked(int))); connect(eventPlayer, SIGNAL(pauseClicked()), this, SLOT(eventPlayerPauseClicked())); connect(eventPlayer, SIGNAL(rewindToStartClicked()), this, SLOT(eventPlayerRewindToStartClicked())); connect(eventPlayer, SIGNAL(forwardToEndClicked()), this, SLOT(eventPlayerForwardToEndClicked())); connect(eventPlayer, SIGNAL(rewindClicked()), this, SLOT(eventPlayerRewindClicked())); connect(eventPlayer, SIGNAL(stopClicked()), this, SLOT(eventPlayerStopClicked())); connect(eventPlayer, SIGNAL(nextPackets(QVector<Packet>)), streamReader, SLOT(parsePackets(QVector<Packet>))); connect(ui->ltWidget, SIGNAL(driverSelected(int)), ui->driverDataWidget, SLOT(printDriverData(int))); connect(ui->ltWidget, SIGNAL(driverDoubleClicked(int)), this, SLOT(ltWidgetDriverSelected(int))); ui->messageBoardWidget->setVisible(false); QStringList args = qApp->arguments(); if (args.size() > 1) { if (eventPlayer->loadFromFile(args.at(1)) == false) { QMessageBox::critical(this, "Error opening file!", "Could not open specified file, or the file is corrupted."); connectToServer(); return; } setWindowTitle("FILT - " + args.at(1)); ui->actionRecord->setVisible(false); ui->actionStop_recording->setVisible(false); eventPlayerAction->setVisible(true); delayWidgetAction->setVisible(false); playing = true; eventPlayer->startPlaying(); } else { if (settings->value("ui/auto_connect").toBool()) connectToServer(); else { ui->messageBoardWidget->showStartupBoard(); showSessionBoard(true); } } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow (parent) { QString serverApp = QCoreApplication::applicationDirPath(); Updater *updater = new Updater(); #ifdef Q_OS_MAC // applicationDirPath() does not return bundle, but executable inside bundle serverApp.replace("Ostinato.app", "drone.app"); #endif #ifdef Q_OS_WIN32 serverApp.append("/drone.exe"); #else serverApp.append("/drone"); #endif localServer_ = new QProcess(this); localServer_->setProcessChannelMode(QProcess::ForwardedChannels); localServer_->start(serverApp, QStringList()); pgl = new PortGroupList; portsWindow = new PortsWindow(pgl, this); statsWindow = new PortStatsWindow(pgl, this); portsDock = new QDockWidget(tr("Ports and Streams"), this); portsDock->setObjectName("portsDock"); portsDock->setFeatures( portsDock->features() & ~QDockWidget::DockWidgetClosable); statsDock = new QDockWidget(tr("Statistics"), this); statsDock->setObjectName("statsDock"); statsDock->setFeatures( statsDock->features() & ~QDockWidget::DockWidgetClosable); setupUi(this); menuFile->insertActions(menuFile->actions().at(0), portsWindow->actions()); statsDock->setWidget(statsWindow); addDockWidget(Qt::BottomDockWidgetArea, statsDock); portsDock->setWidget(portsWindow); addDockWidget(Qt::TopDockWidgetArea, portsDock); QRect geom = appSettings->value(kApplicationWindowGeometryKey).toRect(); if (!geom.isNull()) setGeometry(geom); QByteArray layout = appSettings->value(kApplicationWindowLayout) .toByteArray(); if (layout.size()) restoreState(layout, 0); connect(actionFileExit, SIGNAL(triggered()), this, SLOT(close())); connect(actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt())); connect(updater, SIGNAL(newVersionAvailable(QString)), this, SLOT(onNewVersion(QString))); updater->checkForNewVersion(); #if 0 { DbgThread *dbg = new DbgThread(pgl); dbg->start(); } #endif }
int main(int argc, char *argv[]) { QCoreApplication::setOrganizationName("SRFGames"); QCoreApplication::setOrganizationDomain("sol-online.org"), QCoreApplication::setApplicationName("TrackYourTime"); #ifdef Q_OS_MAC QDir dir(argv[0]); dir.cdUp(); QString currentDir = dir.absolutePath(); dir.cdUp(); dir.cd("PlugIns"); QCoreApplication::setLibraryPaths(QStringList(dir.absolutePath())); #endif QApplication a(argc, argv); QApplication::setQuitOnLastWindowClosed(false); #ifdef Q_OS_MAC QDir::setCurrent(currentDir); #endif qDebug() << "application start\n"; cSettings settings; QString Language = QLocale::system().name(); Language.truncate(Language.lastIndexOf('_')); Language = settings.db()->value(cDataManager::CONF_LANGUAGE_ID,Language).toString(); if (settings.db()->value(cDataManager::CONF_FIRST_LAUNCH_ID,true).toBool()){ settings.db()->setValue(cDataManager::CONF_FIRST_LAUNCH_ID,false); settings.db()->setValue(cDataManager::CONF_LANGUAGE_ID,Language); settings.db()->setValue(cDataManager::CONF_AUTORUN_ID,true); setAutorun(); settings.db()->sync(); } qDebug() << "laod translation\n"; QTranslator translator; translator.load("lang_" + Language,QDir::currentPath()+"/data/languages"); QApplication::installTranslator(&translator); qDebug() << "init datamanager\n"; cDataManager datamanager; qDebug() << "init schedule\n"; cSchedule schedule(&datamanager); qDebug() << "init updater\n"; cUpdater updater; QObject::connect(&schedule,SIGNAL(checkUpdates()),&updater,SLOT(checkUpdates())); qDebug() << "init tray icon\n"; cTrayIcon trIcon(&datamanager); QObject::connect(&datamanager, SIGNAL(trayActive()), &trIcon, SLOT(setActive())); QObject::connect(&datamanager, SIGNAL(traySleep()), &trIcon, SLOT(setInactive())); QObject::connect(&datamanager, SIGNAL(trayShowHint(QString)), &trIcon, SLOT(showHint(QString))); QObject::connect(&datamanager, SIGNAL(profilesChanged()), &trIcon, SLOT(onProfilesChange())); qDebug() << "init applications window\n"; ApplicationsWindow applicationsWindow(&datamanager); QObject::connect(&trIcon, SIGNAL(showApplications()), &applicationsWindow, SLOT(showNormal())); QObject::connect(&datamanager, SIGNAL(profilesChanged()), &applicationsWindow, SLOT(onProfilesChange())); QObject::connect(&datamanager, SIGNAL(applicationsChanged()), &applicationsWindow, SLOT(onApplicationsChange())); qDebug() << "init profiles window\n"; ProfilesWindow profilesWindow(&datamanager); QObject::connect(&applicationsWindow, SIGNAL(showProfiles()), &profilesWindow, SLOT(showNormal())); qDebug() << "init app settings window\n"; App_SettingsWindow app_settingsWindow(&datamanager); QObject::connect(&applicationsWindow, SIGNAL(showAppSettings(int)), &app_settingsWindow, SLOT(showApp(int))); QObject::connect(&datamanager, SIGNAL(debugScriptResult(QString,sSysInfo)), &app_settingsWindow, SLOT(onScriptResult(QString,sSysInfo))); qDebug() << "init settings window\n"; SettingsWindow settingsWindow(&datamanager); QObject::connect(&trIcon, SIGNAL(showSettings()), &settingsWindow, SLOT(showNormal())); QObject::connect(&settingsWindow, SIGNAL(preferencesChange()), &datamanager, SLOT(onPreferencesChanged())); qDebug() << "init schedule window\n"; ScheduleWindow scheduleWindow(&datamanager,&schedule); QObject::connect(&datamanager, SIGNAL(profilesChanged()), &scheduleWindow, SLOT(rebuild())); QObject::connect(&trIcon, SIGNAL(showSchedule()), &scheduleWindow, SLOT(showNormal())); qDebug() << "init statistic window\n"; StatisticWindow statisticWindow(&datamanager); QObject::connect(&trIcon, SIGNAL(showStatistic()), &statisticWindow, SLOT(showNormal())); qDebug() << "init about window\n"; AboutWindow aboutWindow; QObject::connect(&trIcon, SIGNAL(showAbout()), &aboutWindow, SLOT(showNormal())); qDebug() << "init update window\n"; UpdateAvailableWindow updateAvailableWindow; QObject::connect(&updater, SIGNAL(newVersionAvailable(QString)), &updateAvailableWindow, SLOT(showUpdate(QString))); QObject::connect(&updateAvailableWindow, SIGNAL(ignoreUpdate()), &updater, SLOT(ignoreNewVersion())); qDebug() << "init notification window\n"; NotificationWindow notificationWindow(&datamanager); QObject::connect(&settingsWindow, SIGNAL(preferencesChange()), ¬ificationWindow, SLOT(onPreferencesChanged())); QObject::connect(&datamanager, SIGNAL(showNotification()), ¬ificationWindow, SLOT(onShow())); qDebug() << "start schedule\n"; schedule.start(); qDebug() << "start app loop\n"; int result = a.exec(); qDebug() << "application close\n"; return result; }