- Add the ability to parse the RSS feeds from reddit groups (in particular the image feed groups like EarthPorn) and display them
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QApplication>
|
||||
#include <QScreen>
|
||||
#include <QNetworkReply>
|
||||
#include <sstream>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
@@ -165,15 +166,46 @@ void MainWindow::checkWindowSize()
|
||||
void MainWindow::setImage(const ImageDetails &imageDetails)
|
||||
{
|
||||
currentImage = imageDetails;
|
||||
downloadedData.clear();
|
||||
if (pendingReply)
|
||||
{
|
||||
pendingReply->abort();
|
||||
}
|
||||
updateImage(false);
|
||||
}
|
||||
|
||||
void MainWindow::fileDownloaded(QNetworkReply* netReply)
|
||||
{
|
||||
if (netReply == pendingReply)
|
||||
{
|
||||
pendingReply = nullptr;
|
||||
QNetworkReply::NetworkError err = netReply->error();
|
||||
if (err == QNetworkReply::NoError)
|
||||
{
|
||||
downloadedData = netReply->readAll();
|
||||
netReply->deleteLater();
|
||||
updateImage(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::updateImage(bool immediately)
|
||||
{
|
||||
checkWindowSize();
|
||||
if (currentImage.filename == "")
|
||||
return;
|
||||
|
||||
if (currentImage.filename.find("https://") != std::string::npos && downloadedData.isNull())
|
||||
{
|
||||
if (pendingReply == nullptr)
|
||||
{
|
||||
QNetworkRequest request(QUrl(currentImage.filename.c_str()));
|
||||
pendingReply = networkManager->get(request);
|
||||
connect( networkManager, SIGNAL (finished(QNetworkReply*)), this, SLOT (fileDownloaded(QNetworkReply*)));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
QLabel *label = this->findChild<QLabel*>("image");
|
||||
const QPixmap* oldImage = label->pixmap();
|
||||
if (oldImage != NULL && !immediately)
|
||||
@@ -183,7 +215,28 @@ void MainWindow::updateImage(bool immediately)
|
||||
this->setPalette(palette);
|
||||
}
|
||||
|
||||
QPixmap p( currentImage.filename.c_str() );
|
||||
QPixmap p;
|
||||
if (!downloadedData.isNull())
|
||||
{
|
||||
p.loadFromData(downloadedData);
|
||||
// BUG BUG have the selector update this?
|
||||
currentImage.width = p.width();
|
||||
currentImage.height = p.height();
|
||||
currentImage.rotation = 0;
|
||||
if (currentImage.width > currentImage.height) {
|
||||
currentImage.aspect = ImageAspect_Landscape;
|
||||
} else if (currentImage.height > currentImage.width) {
|
||||
currentImage.aspect = ImageAspect_Portrait;
|
||||
} else {
|
||||
currentImage.aspect = ImageAspect_Any;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
p.load( currentImage.filename.c_str() );
|
||||
}
|
||||
|
||||
if(debugMode)
|
||||
{
|
||||
std::cout << "size:" << p.width() << "x" << p.height() << "(window:" << width() << "," << height() << ")" << std::endl;
|
||||
@@ -382,3 +435,8 @@ const ImageDisplayOptions &MainWindow::getBaseOptions()
|
||||
{
|
||||
return baseImageOptions;
|
||||
}
|
||||
|
||||
void MainWindow::setNetworkManager(QNetworkAccessManager *networkManagerIn)
|
||||
{
|
||||
networkManager = networkManagerIn;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user