Skip to content

Commit

Permalink
Remove home shelves and add prefer lists option
Browse files Browse the repository at this point in the history
Home shelves will come back if/when I implement a proper shelves layout
as seen on the actual YouTube website, as mentioned in issue #10.
  • Loading branch information
BowDown097 committed Sep 6, 2023
1 parent eb30f07 commit 9414d58
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/stores/settingsstore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void SettingsStore::initializeFromSettingsFile()
condensedViews = settings.value("condensedViews", false).toBool();
darkTheme = settings.value("darkTheme", false).toBool();
fullSubs = settings.value("fullSubs", false).toBool();
homeShelves = settings.value("homeShelves", false).toBool();
preferLists = settings.value("preferLists", false).toBool();
returnDislikes = settings.value("returnDislikes", true).toBool();
// player
disable60Fps = settings.value("player/disable60Fps", false).toBool();
Expand Down Expand Up @@ -65,7 +65,7 @@ void SettingsStore::saveToSettingsFile()
settings.setValue("condensedViews", condensedViews);
settings.setValue("darkTheme", darkTheme);
settings.setValue("fullSubs", fullSubs);
settings.setValue("homeShelves", homeShelves);
settings.setValue("preferLists", preferLists);
settings.setValue("returnDislikes", returnDislikes);
// player
settings.setValue("player/disable60Fps", disable60Fps);
Expand Down
6 changes: 3 additions & 3 deletions src/stores/settingsstore.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class SettingsStore : public QObject
Q_PROPERTY(bool h264Only MEMBER h264Only NOTIFY h264OnlyChanged)
Q_PROPERTY(bool hideShorts MEMBER hideShorts NOTIFY hideShortsChanged)
Q_PROPERTY(bool hideStreams MEMBER hideStreams NOTIFY hideStreamsChanged)
Q_PROPERTY(bool homeShelves MEMBER homeShelves NOTIFY homeShelvesChanged)
Q_PROPERTY(bool playbackTracking MEMBER playbackTracking NOTIFY playbackTrackingChanged)
Q_PROPERTY(bool preferLists MEMBER preferLists NOTIFY preferListsChanged)
Q_PROPERTY(PlayerQuality preferredQuality MEMBER preferredQuality NOTIFY preferredQualityChanged)
Q_PROPERTY(int preferredVolume MEMBER preferredVolume NOTIFY preferredVolumeChanged)
Q_PROPERTY(bool restoreAnnotations MEMBER restoreAnnotations NOTIFY restoreAnnotationsChanged)
Expand Down Expand Up @@ -58,8 +58,8 @@ class SettingsStore : public QObject
bool h264Only;
bool hideShorts;
bool hideStreams;
bool homeShelves;
bool playbackTracking;
bool preferLists;
PlayerQuality preferredQuality;
int preferredVolume;
bool restoreAnnotations;
Expand Down Expand Up @@ -97,8 +97,8 @@ class SettingsStore : public QObject
void h264OnlyChanged(bool);
void hideShortsChanged(bool);
void hideStreamsChanged(bool);
void homeShelvesChanged(bool);
void playbackTrackingChanged(bool);
void preferListsChanged(bool);
void preferredQualityChanged(SettingsStore::PlayerQuality);
void preferredVolumeChanged(int);
void restoreAnnotationsChanged(bool);
Expand Down
21 changes: 2 additions & 19 deletions src/ui/browsehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "channelbrowser.h"
#include "http.h"
#include "protobuf/simpleprotobuf.h"
#include "stores/settingsstore.h"
#include "ui/forms/mainwindow.h"
#include "ui/widgets/renderers/browsenotificationrenderer.h"
#include "utils/uiutils.h"
Expand Down Expand Up @@ -69,28 +68,12 @@ void BrowseHelper::browseHistory(QListWidget* historyWidget, const QString& quer

void BrowseHelper::browseHome(QListWidget* homeWidget)
{
const QString clientNameTemp = InnerTube::instance().context()->client.clientName;
const QString clientVerTemp = InnerTube::instance().context()->client.clientVersion;

if (SettingsStore::instance()->homeShelves)
{
InnerTube::instance().context()->client.clientName = "ANDROID";
InnerTube::instance().context()->client.clientVersion = "17.01";
}

InnertubeReply* reply = InnerTube::instance().get<InnertubeEndpoints::BrowseHome>();
connect(reply, &InnertubeReply::exception, this, [this, clientNameTemp, clientVerTemp](const InnertubeException& ie)
{
browseFailed(ie, "Failed to get home data");
InnerTube::instance().context()->client.clientName = clientNameTemp;
InnerTube::instance().context()->client.clientVersion = clientVerTemp;
});
connect(reply, qOverload<const InnertubeEndpoints::BrowseHome&>(&InnertubeReply::finished), this, [this, clientNameTemp, clientVerTemp, homeWidget](const InnertubeEndpoints::BrowseHome& endpoint)
connect(reply, &InnertubeReply::exception, this, std::bind(&BrowseHelper::browseFailed, this, std::placeholders::_1, "Failed to get home data"));
connect(reply, qOverload<const InnertubeEndpoints::BrowseHome&>(&InnertubeReply::finished), this, [this, homeWidget](const InnertubeEndpoints::BrowseHome& endpoint)
{
setupVideoList(endpoint.response.videos, homeWidget);
continuationToken = endpoint.continuationToken;
InnerTube::instance().context()->client.clientName = clientNameTemp;
InnerTube::instance().context()->client.clientVersion = clientVerTemp;
});
}

Expand Down
23 changes: 23 additions & 0 deletions src/ui/forms/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@ void MainWindow::browse()
switch (ui->tabWidget->currentIndex())
{
case 0:
trySwitchGridStatus(ui->homeWidget);
BrowseHelper::instance()->browseHome(ui->homeWidget);
break;
case 1:
BrowseHelper::instance()->browseTrending(ui->trendingWidget);
break;
case 2:
trySwitchGridStatus(ui->subscriptionsWidget);
BrowseHelper::instance()->browseSubscriptions(ui->subscriptionsWidget);
break;
case 3:
Expand Down Expand Up @@ -394,6 +396,27 @@ void MainWindow::tryRestoreData()
}
}

void MainWindow::trySwitchGridStatus(QListWidget* listWidget)
{
bool preferLists = SettingsStore::instance()->preferLists;
if (preferLists && listWidget->flow() == QListWidget::LeftToRight)
{
listWidget->setFlow(QListWidget::TopToBottom);
listWidget->setResizeMode(QListWidget::Fixed);
listWidget->setSpacing(0);
listWidget->setStyleSheet(QString());
listWidget->setWrapping(false);
}
else if (!preferLists && listWidget->flow() == QListWidget::TopToBottom)
{
listWidget->setFlow(QListWidget::LeftToRight);
listWidget->setResizeMode(QListWidget::Adjust);
listWidget->setSpacing(3);
listWidget->setStyleSheet("QListWidget::item { background: transparent; }");
listWidget->setWrapping(true);
}
}

MainWindow::~MainWindow()
{
delete ui;
Expand Down
1 change: 1 addition & 0 deletions src/ui/forms/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ private slots:
void searchByLink(const QString& link);
void searchByQuery(const QString& query);
void tryRestoreData();
void trySwitchGridStatus(QListWidget* listWidget);

static inline QStackedWidget* m_centralWidget;
static inline QSize m_size;
Expand Down
4 changes: 2 additions & 2 deletions src/ui/forms/settings/settingsform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SettingsForm::SettingsForm(QWidget *parent) : QWidget(parent), ui(new Ui::Settin
// general
ui->condensedViews->setChecked(store->condensedViews);
ui->fullSubs->setChecked(store->fullSubs);
ui->homeShelves->setChecked(store->homeShelves);
ui->preferLists->setChecked(store->preferLists);
ui->returnDislikes->setChecked(store->returnDislikes);
// player
ui->disable60Fps->setChecked(store->disable60Fps);
Expand Down Expand Up @@ -84,7 +84,7 @@ void SettingsForm::saveSettings()
store->condensedViews = ui->condensedViews->isChecked();
store->darkTheme = ui->darkTheme->isChecked();
store->fullSubs = ui->fullSubs->isChecked();
store->homeShelves = ui->homeShelves->isChecked();
store->preferLists = ui->preferLists->isChecked();
store->returnDislikes = ui->returnDislikes->isChecked();
// player
store->disable60Fps = ui->disable60Fps->isChecked();
Expand Down
4 changes: 2 additions & 2 deletions src/ui/forms/settings/settingsform.ui
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<string>Use condensed view counts</string>
</property>
</widget>
<widget class="QCheckBox" name="homeShelves">
<widget class="QCheckBox" name="preferLists">
<property name="geometry">
<rect>
<x>10</x>
Expand All @@ -56,7 +56,7 @@
</rect>
</property>
<property name="text">
<string>Use shelves homepage layout</string>
<string>Prefer list layouts over grid layouts</string>
</property>
</widget>
<widget class="QCheckBox" name="returnDislikes">
Expand Down
2 changes: 1 addition & 1 deletion src/ui/widgets/labels/elidedtubelabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void ElidedTubeLabel::leaveEvent(QEvent*)
if (m_clickable)
setCursor(QCursor());
if (m_underline)
setStyleSheet("");
setStyleSheet(QString());
}

void ElidedTubeLabel::mousePressEvent(QMouseEvent* event)
Expand Down
2 changes: 1 addition & 1 deletion src/ui/widgets/labels/tubelabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void TubeLabel::leaveEvent(QEvent*)
if (clickable)
setCursor(QCursor());
if (underline)
setStyleSheet("");
setStyleSheet(QString());
}

void TubeLabel::mousePressEvent(QMouseEvent* event)
Expand Down

0 comments on commit 9414d58

Please sign in to comment.