forked from organicmaps/organicmaps
Cleaned up unused update check code
This commit is contained in:
parent
fcb35bbceb
commit
f2b82e4dd0
4 changed files with 4 additions and 171 deletions
|
@ -61,15 +61,6 @@ namespace qt
|
|||
{
|
||||
setWindowModality(Qt::WindowModal);
|
||||
|
||||
string timeString;
|
||||
if (!Settings::Get(LAST_CHECK_TIME_KEY, timeString))
|
||||
timeString = "Never checked";
|
||||
m_label = new QLabel(QString(QObject::tr(LAST_UPDATE_CHECK)) + QString::fromUtf8(timeString.c_str()), this);
|
||||
|
||||
m_updateButton = new QPushButton(QObject::tr(CHECK_FOR_UPDATE), this);
|
||||
m_updateButton->setDefault(false);
|
||||
connect(m_updateButton, SIGNAL(clicked()), this, SLOT(OnUpdateClick()));
|
||||
|
||||
QPushButton * closeButton = new QPushButton(QObject::tr("Close"), this);
|
||||
closeButton->setDefault(true);
|
||||
connect(closeButton, SIGNAL(clicked()), this, SLOT(OnCloseClick()));
|
||||
|
@ -82,8 +73,7 @@ namespace qt
|
|||
connect(m_tree, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(OnItemClick(QTreeWidgetItem *, int)));
|
||||
|
||||
QHBoxLayout * horizontalLayout = new QHBoxLayout();
|
||||
horizontalLayout->addWidget(m_label);
|
||||
horizontalLayout->addWidget(m_updateButton);
|
||||
horizontalLayout->addStretch();
|
||||
horizontalLayout->addWidget(closeButton);
|
||||
|
||||
QVBoxLayout * verticalLayout = new QVBoxLayout();
|
||||
|
@ -96,8 +86,7 @@ namespace qt
|
|||
|
||||
// we want to receive all download progress and result events
|
||||
m_storage.Subscribe(bind(&UpdateDialog::OnCountryChanged, this, _1),
|
||||
bind(&UpdateDialog::OnCountryDownloadProgress, this, _1, _2),
|
||||
bind(&UpdateDialog::OnUpdateRequest, this, _1, _2));
|
||||
bind(&UpdateDialog::OnCountryDownloadProgress, this, _1, _2));
|
||||
}
|
||||
|
||||
UpdateDialog::~UpdateDialog()
|
||||
|
@ -190,13 +179,6 @@ namespace qt
|
|||
return item;
|
||||
}
|
||||
|
||||
void UpdateDialog::OnUpdateClick()
|
||||
{
|
||||
m_updateButton->setText(QObject::tr("Checking for update..."));
|
||||
m_updateButton->setDisabled(true);
|
||||
m_storage.CheckForUpdate();
|
||||
}
|
||||
|
||||
void UpdateDialog::OnCloseClick()
|
||||
{
|
||||
done(0);
|
||||
|
@ -209,63 +191,6 @@ namespace qt
|
|||
item.setTextColor(column, color);
|
||||
}
|
||||
|
||||
void UpdateDialog::OnUpdateRequest(storage::TUpdateResult res, string const & description)
|
||||
{
|
||||
switch (res)
|
||||
{
|
||||
case ENoAnyUpdateAvailable:
|
||||
{
|
||||
// @TODO do not show it for automatic update checks
|
||||
InfoDialog dlg(tr("No update is available"),
|
||||
tr("At this moment, no new version is available. Please, try again later or "
|
||||
"visit our web site <a href=\"http://www.mapswithme.com\">www.mapswithme.com</a> "
|
||||
"for latest news."),
|
||||
this, QStringList(tr("Ok")));
|
||||
dlg.exec();
|
||||
}
|
||||
break;
|
||||
case ENewBinaryAvailable:
|
||||
{
|
||||
InfoDialog dlg(tr("New version is available!"), description.c_str(), this,
|
||||
QStringList(tr("Postpone update")));
|
||||
dlg.exec();
|
||||
}
|
||||
break;
|
||||
case storage::EBinaryCheckFailed:
|
||||
{
|
||||
InfoDialog dlg(tr("Update check failed"), description.c_str(), this, QStringList(tr("Ok")));
|
||||
dlg.exec();
|
||||
}
|
||||
break;
|
||||
default: /// @TODO handle all other cases
|
||||
break;
|
||||
}
|
||||
// if (updateSize < 0)
|
||||
// ;//m_label->setText(QObject::tr("No update is available"));
|
||||
// else
|
||||
// {
|
||||
// QString title(QObject::tr("Update is available"));
|
||||
// QString text(readme ? readme : "");
|
||||
// if (updateSize / (1000 * 1000 * 1000) > 0)
|
||||
// text.append(QObject::tr("\n\nDo you want to perform update and download %1 GB?").arg(
|
||||
// uint(updateSize / (1000 * 1000 * 1000))));
|
||||
// else if (updateSize / (1000 * 1000) > 0)
|
||||
// text.append(QObject::tr("\n\nDo you want to perform update and download %1 MB?").arg(
|
||||
// uint(updateSize / (1000 * 1000))));
|
||||
// else
|
||||
// text.append(QObject::tr("\n\nDo you want to perform update and download %1 kB?").arg(
|
||||
// uint((updateSize + 999) / 1000)));
|
||||
// if (QMessageBox::Yes == QMessageBox::question(this, title, text, QMessageBox::Yes, QMessageBox::No))
|
||||
// m_storage.PerformUpdate();
|
||||
// }
|
||||
QString labelText(LAST_UPDATE_CHECK);
|
||||
QString const textDate = QDateTime::currentDateTime().toString();
|
||||
Settings::Set(LAST_CHECK_TIME_KEY, string(textDate.toUtf8().data()));
|
||||
m_label->setText(labelText.append(textDate));
|
||||
m_updateButton->setText(CHECK_FOR_UPDATE);
|
||||
m_updateButton->setDisabled(false);
|
||||
}
|
||||
|
||||
void UpdateDialog::UpdateRowWithCountryInfo(TIndex const & index)
|
||||
{
|
||||
QTreeWidgetItem * item = GetTreeItemByIndex(*m_tree, index);
|
||||
|
|
|
@ -24,14 +24,12 @@ namespace qt
|
|||
void OnCountryChanged(storage::TIndex const & index);
|
||||
void OnCountryDownloadProgress(storage::TIndex const & index,
|
||||
HttpProgressT const & progress);
|
||||
void OnUpdateRequest(storage::TUpdateResult result, string const & description);
|
||||
//@}
|
||||
|
||||
void ShowDialog();
|
||||
|
||||
private slots:
|
||||
void OnItemClick(QTreeWidgetItem * item, int column);
|
||||
void OnUpdateClick();
|
||||
void OnCloseClick();
|
||||
|
||||
private:
|
||||
|
@ -40,8 +38,6 @@ namespace qt
|
|||
|
||||
private:
|
||||
QTreeWidget * m_tree;
|
||||
QLabel * m_label;
|
||||
QPushButton * m_updateButton;
|
||||
storage::Storage & m_storage;
|
||||
};
|
||||
} // namespace qt
|
||||
|
|
|
@ -307,12 +307,10 @@ namespace storage
|
|||
}
|
||||
}
|
||||
|
||||
void Storage::Subscribe(TObserverChangeCountryFunction change, TObserverProgressFunction progress,
|
||||
TUpdateRequestFunction updateRequest)
|
||||
void Storage::Subscribe(TObserverChangeCountryFunction change, TObserverProgressFunction progress)
|
||||
{
|
||||
m_observerChange = change;
|
||||
m_observerProgress = progress;
|
||||
m_observerUpdateRequest = updateRequest;
|
||||
|
||||
ReInitCountries(false);
|
||||
}
|
||||
|
@ -321,7 +319,6 @@ namespace storage
|
|||
{
|
||||
m_observerChange.clear();
|
||||
m_observerProgress.clear();
|
||||
m_observerUpdateRequest.clear();
|
||||
}
|
||||
|
||||
void Storage::OnMapDownloadFinished(HttpFinishedParams const & result)
|
||||
|
@ -383,84 +380,4 @@ namespace storage
|
|||
m_observerProgress(m_queue.front(), p);
|
||||
}
|
||||
}
|
||||
|
||||
void Storage::CheckForUpdate()
|
||||
{
|
||||
// at this moment we support only binary update checks
|
||||
string const update = UpdateBaseUrl() + BINARY_UPDATE_FILE/*DATA_UPDATE_FILE*/;
|
||||
GetDownloadManager().CancelDownload(update);
|
||||
HttpStartParams params;
|
||||
params.m_url = update;
|
||||
params.m_fileToSave = GetPlatform().WritablePathForFile(DATA_UPDATE_FILE);
|
||||
params.m_finish = bind(&Storage::OnBinaryUpdateCheckFinished, this, _1);
|
||||
params.m_useResume = false;
|
||||
GetDownloadManager().HttpRequest(params);
|
||||
}
|
||||
|
||||
void Storage::OnDataUpdateCheckFinished(HttpFinishedParams const & params)
|
||||
{
|
||||
if (params.m_error != EHttpDownloadOk)
|
||||
{
|
||||
LOG(LWARNING, ("Update check failed for url:", params.m_url));
|
||||
if (m_observerUpdateRequest)
|
||||
m_observerUpdateRequest(EDataCheckFailed, ErrorString(params.m_error));
|
||||
}
|
||||
else
|
||||
{ // @TODO parse update file and notify GUI
|
||||
}
|
||||
|
||||
// parse update file
|
||||
// TCountriesContainer tempCountries;
|
||||
// if (!LoadCountries(tempCountries, GetPlatform().WritablePathForFile(DATA_UPDATE_FILE)))
|
||||
// {
|
||||
// LOG(LWARNING, ("New application version should be downloaded, "
|
||||
// "update file format can't be parsed"));
|
||||
// // @TODO: report to GUI
|
||||
// return;
|
||||
// }
|
||||
// // stop any active download, clear the queue, replace countries and notify GUI
|
||||
// if (!m_queue.empty())
|
||||
// {
|
||||
// CancelCountryDownload(CountryByIndex(m_queue.front()));
|
||||
// m_queue.clear();
|
||||
// }
|
||||
// m_countries.swap(tempCountries);
|
||||
// // @TODO report to GUI about reloading all countries
|
||||
// LOG(LINFO, ("Update check complete"));
|
||||
}
|
||||
|
||||
void Storage::OnBinaryUpdateCheckFinished(HttpFinishedParams const & params)
|
||||
{
|
||||
if (params.m_error == EHttpDownloadFileNotFound)
|
||||
{
|
||||
// no binary update is available
|
||||
if (m_observerUpdateRequest)
|
||||
m_observerUpdateRequest(ENoAnyUpdateAvailable, "No update is available");
|
||||
}
|
||||
else if (params.m_error == EHttpDownloadOk)
|
||||
{
|
||||
// update is available!
|
||||
try
|
||||
{
|
||||
if (m_observerUpdateRequest)
|
||||
{
|
||||
string buffer;
|
||||
ReaderPtr<Reader>(GetPlatform().GetReader(params.m_file)).ReadAsString(buffer);
|
||||
m_observerUpdateRequest(ENewBinaryAvailable, buffer);
|
||||
}
|
||||
}
|
||||
catch (std::exception const & e)
|
||||
{
|
||||
if (m_observerUpdateRequest)
|
||||
m_observerUpdateRequest(EBinaryCheckFailed,
|
||||
string("Error loading b-update text file ") + e.what());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// connection error
|
||||
if (m_observerUpdateRequest)
|
||||
m_observerUpdateRequest(EBinaryCheckFailed, ErrorString(params.m_error));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,10 +80,8 @@ namespace storage
|
|||
//@{
|
||||
typedef function<void (TIndex const &)> TObserverChangeCountryFunction;
|
||||
typedef function<void (TIndex const &, HttpProgressT const &)> TObserverProgressFunction;
|
||||
typedef function<void (TUpdateResult, string const &)> TUpdateRequestFunction;
|
||||
TObserverChangeCountryFunction m_observerChange;
|
||||
TObserverProgressFunction m_observerProgress;
|
||||
TUpdateRequestFunction m_observerUpdateRequest;
|
||||
//@}
|
||||
|
||||
/// @name Communicate with Framework
|
||||
|
@ -117,15 +115,12 @@ namespace storage
|
|||
//@{
|
||||
void OnMapDownloadFinished(HttpFinishedParams const & params);
|
||||
void OnMapDownloadProgress(HttpProgressT const & progress);
|
||||
void OnDataUpdateCheckFinished(HttpFinishedParams const & params);
|
||||
void OnBinaryUpdateCheckFinished(HttpFinishedParams const & params);
|
||||
//@}
|
||||
|
||||
/// @name Current impl supports only one observer
|
||||
//@{
|
||||
void Subscribe(TObserverChangeCountryFunction change,
|
||||
TObserverProgressFunction progress,
|
||||
TUpdateRequestFunction dataCheck);
|
||||
TObserverProgressFunction progress);
|
||||
void Unsubscribe();
|
||||
//@}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue