1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "mainpage.h"
#include "ui_mainpage.h"
#include "tvshowlistwidget.h"
#include "server.h"
#include "mainwindow.h"
MainPage::MainPage(Library& library, MainWindow* mainwindow, QWidget *parent) :
Page(parent),
ui(new Ui::MainPage),
library(library),
mainwindow(mainwindow)
{
ui->setupUi(this);
if (library.getSearchStatus() != Library::done) {
connect(&library, SIGNAL(searchFinished()), this, SLOT(setRandomWallpaperAfterSearch()));
} else {
this->setRandomWallpaper();
}
this->ui->currentlyAiringShows->set(library.filter().airing(), QString("Airing Shows"));
this->ui->allShows->set(library.filter().all(), QString("All Shows"));
connect(&library, SIGNAL(showAdded(TvShow*)), this, SLOT(onShowAdded(TvShow*)));
}
MainPage::~MainPage() {
delete ui;
}
void MainPage::initFromQuery(const QString& initString) {
if (initString.isNull()) {
this->ui->message->setVisible(false);
return;
}
this->ui->message->setVisible(true);
this->ui->message->setText(initString);
}
bool MainPage::handleApiRequest(QHttpRequest *, QHttpResponse *) {
return false;
}
void MainPage::on_settingsButton_clicked() {
mainwindow->setPage(PageFactory::settingsPageKey);
}
void MainPage::onShowAdded(TvShow *show) {
if (show->isAiring()) {
this->ui->currentlyAiringShows->add(show);
}
this->ui->allShows->add(show);
}
void MainPage::setRandomWallpaperAfterSearch() {
QString path = library.filter().getRandomWallpaper();
if (!path.isNull()) {
this->setRandomWallpaper(path);
} else {
connect(&library, SIGNAL(wallpaperDownloaded(QString)), this, SLOT(setRandomWallpaper(QString)));
}
disconnect(&library, SIGNAL(searchFinished()), this, SLOT(setRandomWallpaperAfterSearch()));
}
void MainPage::setRandomWallpaper(QString path) {
MainBackgroundWidget* mbw = mainwindow->getCentralWidget();
if (mbw) {
if (path.isNull()) {
path = library.filter().getRandomWallpaper();
}
mbw->setBackground(path);
}
disconnect(&library, SIGNAL(wallpaperDownloaded(QString)), this, SLOT(setRandomWallpaper(QString)));
}