diff options
author | Nils Schwabe | 2014-04-04 16:08:35 +0200 |
---|---|---|
committer | Nils Schwabe | 2014-04-04 16:08:35 +0200 |
commit | 4f2acaa4896cd68699938aa954b337fea480115d (patch) | |
tree | 5241d896175dc299492220d97650b96f0bf3bf2e /src/dialog.cpp | |
parent | fixed some sorting issues (diff) | |
download | vmchooser2-4f2acaa4896cd68699938aa954b337fea480115d.tar.gz vmchooser2-4f2acaa4896cd68699938aa954b337fea480115d.tar.xz vmchooser2-4f2acaa4896cd68699938aa954b337fea480115d.zip |
added cache to news and help, fixed filter bug
Diffstat (limited to 'src/dialog.cpp')
-rw-r--r-- | src/dialog.cpp | 77 |
1 files changed, 75 insertions, 2 deletions
diff --git a/src/dialog.cpp b/src/dialog.cpp index 8db4a4b..233ca32 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -426,6 +426,11 @@ void Dialog::onTabButtonChanged(int tab) { ui->filterEdit->setEnabled(true); } + // clear filter if necessary + if (activeTab != tab) { + this->ui->filterEdit->setText(""); + } + // load the new list setListModel(model_[tab]); this->activeTab = tab; @@ -474,8 +479,23 @@ void Dialog::on_helpNewsButton_clicked() { void Dialog::addNewsAfterDownload(QNetworkReply* reply) { if (reply->error() != QNetworkReply::NoError) { if (debugMode) { - qDebug() << "Could not get news."; + qDebug() << "Could not get news. Try to get cached news."; + } + + // try to get cached news + QFile backup_file(news_backup_filename); + + if (!backup_file.open(QIODevice::ReadOnly)) { + if (debugMode) { + qDebug() << "Cannot read backup file " << news_backup_filename << " either"; + } + this->ui->newsTextBrowser->setText(QCoreApplication::instance()->translate("Dialog", "Could not get news.")); + return; + } + if (debugMode) { + qDebug() << "Used backup file " << news_backup_filename; } + backup_file.close(); return; } QByteArray data = reply->readAll(); @@ -500,13 +520,47 @@ void Dialog::addNewsAfterDownload(QNetworkReply* reply) { // update ini ChooserSettings::setSetting("last-news", QString::number(timestamp.toTime_t())); + + // make backup + QFile file(news_backup_filename); + if (!file.open(QIODevice::WriteOnly)) { + if (debugMode) { + qDebug() << "Could not write XML to " << xml_filename; + } + return; + } + + if (file.write(data) != data.length()) { + return; + } + if (!file.setPermissions(QFile::ReadUser | QFile::ReadGroup | QFile::ReadOther | QFile::WriteUser | QFile::WriteGroup | QFile::WriteOther)) { + if (debugMode) { + qDebug() << "Could not change permissions of file: " << news_backup_filename; + } + } + file.close(); } void Dialog::addHelpAfterDownload(QNetworkReply* reply) { if (reply->error() != QNetworkReply::NoError) { if (debugMode) { - qDebug() << "Could not get news."; + qDebug() << "Could not get help xml. Try to get cached help..."; } + + // try to get cached news + QFile backup_file(help_backup_filename); + + if (!backup_file.open(QIODevice::ReadOnly)) { + if (debugMode) { + qDebug() << "Cannot read backup file " << help_backup_filename << " either"; + } + this->ui->helpTextBrowser->setText(QCoreApplication::instance()->translate("Dialog", "Could not get help.")); + return; + } + if (debugMode) { + qDebug() << "Used backup file " << help_backup_filename; + } + backup_file.close(); return; } @@ -521,6 +575,25 @@ void Dialog::addHelpAfterDownload(QNetworkReply* reply) { } ui->helpTextBrowser->setText(QString(data)); + + // make backup + QFile file(help_backup_filename); + if (!file.open(QIODevice::WriteOnly)) { + if (debugMode) { + qDebug() << "Could not write XML to " << xml_filename; + } + return; + } + + if (file.write(data) != data.length()) { + return; + } + if (!file.setPermissions(QFile::ReadUser | QFile::ReadGroup | QFile::ReadOther | QFile::WriteUser | QFile::WriteGroup | QFile::WriteOther)) { + if (debugMode) { + qDebug() << "Could not change permissions of file: " << help_backup_filename; + } + } + file.close(); } void Dialog::keyPressEvent(QKeyEvent* event) { |