Skip to content

Commit

Permalink
v0.1.5 Update - Hardware acceleration, icon, and cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCiubuc committed Jul 7, 2022
1 parent 3845a1a commit b59ab85
Show file tree
Hide file tree
Showing 16 changed files with 195 additions and 207 deletions.
4 changes: 4 additions & 0 deletions DiscordTabbed.pro
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CONFIG += c++17
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
RC_ICONS = resources/icon.ico

SOURCES += \
src/PreferencesForm.cpp \
Expand All @@ -30,3 +31,6 @@ FORMS += \
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

RESOURCES += \
resources.qrc
12 changes: 5 additions & 7 deletions patch-notes/updates.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
1. Added buttons under views that:
* Move view left
* Move view right
* Close view
2. Preferences window can open up GPU settings now
3. Fixed memory leak bug on closing embeds
4. Doesn't require sign in if it's 2 views. If it's 3 or more, it does
1. Enabled hardware acceleration
2. Fixed QWebEnginePage not being destroyed on exit
3. Added icon to app
4. Saved last channel that will be loaded when app opens
5. Removed the 'remove last view' shortcut
6 changes: 6 additions & 0 deletions resources.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<RCC>
<qresource prefix="/icons">
<file>resources/icon.ico</file>
<file>resources/icon.png</file>
</qresource>
</RCC>
Binary file added resources/icon.ico
Binary file not shown.
Binary file added resources/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 16 additions & 68 deletions src/DiscordTabbed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ DiscordTabbed::DiscordTabbed(QWidget *parent)
, ui(new Ui::DiscordTabbed)
{
ui->setupUi(this);
// ui->menubar->hide();
_profile = new QWebEngineProfile(QString::fromLatin1("DiscordTabbed")); // unique profile store per qtwbengine version
_profile->setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies);

QSettings settings("DiscordTabbed");
this->setGeometry(settings.value("geometry", this->geometry()).toRect());

this->installEventFilter(this);
_Preferences = new PreferencesForm();
connect(_Preferences, &PreferencesForm::preferencesUpdated, this, &DiscordTabbed::preferencesUpdated);

Expand All @@ -28,31 +24,32 @@ DiscordTabbed::DiscordTabbed(QWidget *parent)
_split = new QSplitter();
ui->horizontalLayout->addWidget(_split);

_lastDiscordChannel = QUrl("https://discord.com/login?redirect_to=%2Fchannels%2F%40me");
// _lastDiscordChannel = QUrl("chrome://gpu");
_lastDiscordChannel = settings.value("last-channel", QUrl("https://discord.com/login?redirect_to=%2Fchannels%2F%40me")).toUrl();
generateNewView();

// Shortcuts
connect(new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_D), this), &QShortcut::activated,
this, &DiscordTabbed::generateNewView);
connect(new QShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_D), this), &QShortcut::activated,
this, &DiscordTabbed::removeLastView);
// connect(new QShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_D), this), &QShortcut::activated,
// this, &DiscordTabbed::removeLastView);
}

DiscordTabbed::~DiscordTabbed()
{
for (auto view : _views)
{
view->setPage(new QWebEnginePage());
// view->deleteLater();
}
// for (auto view : _views)
// {
// view->setPage(new QWebEnginePage());
//// view->deleteLater();
// }
// for (int i = 0; i < _split->count(); ++i)
// {
// auto w = _split->widget(i);
// dynamic_cast<ViewForm*>(w)->getView()->deleteLater();
//// dynamic_cast<ViewForm*>(w)->deleteLater();
// w->deleteLater();
// }
QSettings settings("DiscordTabbed");
settings.setValue("geometry", this->geometry());
settings.setValue("last-channel", _lastDiscordChannel);
delete ui;
}

Expand All @@ -77,37 +74,14 @@ void DiscordTabbed::urlChanged(QUrl url)

void DiscordTabbed::generateNewView()
{
// Create new view, set minimal width for splitter
{
// auto profile = QWebEngineProfile::defaultProfile();
// profile->setPersistentCookiesPolicy(QWebEngineProfile::AllowPersistentCookies);
// _ctrlD = 0;
// _views << new QWebEngineView();
// _views.last()->setMinimumWidth(200);
// _views.last()->setAttribute(Qt::WA_DeleteOnClose);

// // Create page
// DiscordTabbedPage * page = new DiscordTabbedPage(profile, _views.last());
//// page->profile()-
// page->setEmbedLinks(_Preferences->getEmbedLinks());

// connect(page, &DiscordTabbedPage::generateViewWithURL, this, &DiscordTabbed::generateViewWithURL);
// _views.last()->setPage(page);

// ViewForm * w = new ViewForm();
// w->setViewWidget(_views.last());
// w->updateIndex(_split->count());
// // Add view to splitter
// _split->addWidget(w);
// _views.last()->load(QUrl("https://youtu.be/Qjh1EBktSuU"));
}
auto profile = QWebEngineProfile::defaultProfile();
profile->setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies);
_ctrlD = 0;

_views << new QWebEngineView();
_views.last()->setMinimumWidth(200);
_views.last()->settings()->setAttribute(QWebEngineSettings::WebGLEnabled, true);
_views.last()->setAttribute(Qt::WA_DeleteOnClose);
// _views.last()->page()->createWindow(1);

// If this is the first view, its the one with channels
if (_views.size() == MINIMAL_VIEWS)
connect(_views.last(), &QWebEngineView::urlChanged, this, &DiscordTabbed::urlChanged);
Expand Down Expand Up @@ -169,40 +143,14 @@ void DiscordTabbed::generateNewView()
_views.last()->load(_lastDiscordChannel);
}

void DiscordTabbed::removeLastView()
{
return;
_ctrlD = 0;
if (_views.size() < MINIMAL_VIEWS) return;
_views.last()->hide();
auto view = _views.takeLast();

QWidget * w = new QWidget;
view->setParent(w);
view->page()->deleteLater();
view->deleteLater();
w->deleteLater();

// dynamic_cast<DiscordTabbedPage*>(view->page())->requestDelete();
// delete view->page()->profile();
// delete view->page();
// delete view;

}

void DiscordTabbed::on_actionReload_Far_Left_View_triggered()
{

_lastDiscordChannel = QUrl("https://discord.com/login?redirect_to=%2Fchannels%2F%40me");
QSettings settings("DiscordTabbed");
_lastDiscordChannel = settings.value("last-channel", QUrl("https://discord.com/login?redirect_to=%2Fchannels%2F%40me")).toUrl();;
_views.first()->load(_lastDiscordChannel);
}


void DiscordTabbed::on_actionExpand_Retract_Left_View_triggered()
{
removeLastView();
}

void DiscordTabbed::generateViewWithURL(QUrl url)
{
auto old = _lastDiscordChannel;
Expand Down
4 changes: 0 additions & 4 deletions src/DiscordTabbed.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ class DiscordTabbed : public QMainWindow
private slots:
void urlChanged(QUrl url);
void generateNewView();
void removeLastView();
void on_actionReload_Far_Left_View_triggered();

void on_actionExpand_Retract_Left_View_triggered();
void generateViewWithURL(QUrl url);
void on_actionOpen_Preferences_triggered();
void preferencesUpdated();
Expand All @@ -54,8 +52,6 @@ private slots:
QMap<QWebEngineView*, QWidget*> _viewMaps;
QSplitter * _split;
PreferencesForm * _Preferences;
int _ctrlD = 0;
QWebEngineProfile * _profile;

};
#endif // DISCORDTABBED_H
2 changes: 1 addition & 1 deletion src/DiscordTabbed.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<string>DiscordTabbed</string>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(54, 57, 63);
<string notr="true">background-color:rgb(47, 49, 54);
color: rgb(246, 245, 244);</string>
</property>
<widget class="QWidget" name="centralwidget">
Expand Down
6 changes: 3 additions & 3 deletions src/DiscordTabbedPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ DiscordTabbedPage::DiscordTabbedPage(QWebEngineProfile * profile,QObject *parent
: QWebEnginePage{profile,
parent}
{
interp = new WebUrlRequestInterceptor;
this->setUrlRequestInterceptor(interp);
// interp = new WebUrlRequestInterceptor;
// this->setUrlRequestInterceptor(interp);

}

void DiscordTabbedPage::setEmbedLinks(QStringList list)
{
_embedLinks = list;
db _embedLinks;
interp->setEmbedLinks(_embedLinks);
// interp->setEmbedLinks(_embedLinks);
}
bool DiscordTabbedPage::acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame)
{
Expand Down
58 changes: 29 additions & 29 deletions src/DiscordTabbedPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@
#include <QDebug>
#define db qDebug() << this <<

class WebUrlRequestInterceptor : public QWebEngineUrlRequestInterceptor
{
Q_OBJECT
//class WebUrlRequestInterceptor : public QWebEngineUrlRequestInterceptor
//{
// Q_OBJECT

public:
void setEmbedLinks(QStringList list)
{
_embedLinks = list;
}
WebUrlRequestInterceptor(QObject *p = Q_NULLPTR)
{
//public:
// void setEmbedLinks(QStringList list)
// {
// _embedLinks = list;
// }
// WebUrlRequestInterceptor(QObject *p = Q_NULLPTR)
// {

}
void interceptRequest(QWebEngineUrlRequestInfo &info)
{
// db info.requestUrl();
// QString urlString = info.requestUrl().toString();
// for (auto link : _embedLinks)
// {
// if(urlString.contains(link))
// {
// db "BLOCKING";
// info.block(true);
// return;
// }
// }
}
private:
QStringList _embedLinks;
};
// }
// void interceptRequest(QWebEngineUrlRequestInfo &info)
// {
//// db info.requestUrl();
//// QString urlString = info.requestUrl().toString();
//// for (auto link : _embedLinks)
//// {
//// if(urlString.contains(link))
//// {
//// db "BLOCKING";
//// info.block(true);
//// return;
//// }
//// }
// }
//private:
// QStringList _embedLinks;
//};


class FakePage : public QWebEnginePage
Expand Down Expand Up @@ -76,7 +76,7 @@ private slots:
bool _bYoutubeEmbed;
bool _bTwitchEmbed;
QStringList _embedLinks;
WebUrlRequestInterceptor * interp;
// WebUrlRequestInterceptor * interp;
protected:

QWebEnginePage *createWindow(WebWindowType type)
Expand Down
40 changes: 11 additions & 29 deletions src/PreferencesForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,6 @@ PreferencesForm::~PreferencesForm()
delete ui;
}

//bool PreferencesForm::getYoutubeEmbed()
//{
// return ui->checkBox->isChecked();
//}

//bool PreferencesForm::getTwitchEmbed()
//{
// return ui->checkBox_2->isChecked();
//}


void PreferencesForm::on_checkBox_clicked(bool checked)
{
QSettings settings("DiscordTabbed");
settings.setValue("youtube-embed", checked);
emit preferencesUpdated();
}


void PreferencesForm::on_checkBox_2_clicked(bool checked)
{

QSettings settings("DiscordTabbed");
settings.setValue("twitch-embed", checked);
emit preferencesUpdated();
}

void PreferencesForm::loadSettings()
{

Expand All @@ -52,8 +25,9 @@ void PreferencesForm::loadSettings()
ui->plainTextEdit->setPlainText(_embedLinks.join('\n'));
else
_embedLinks = ui->plainTextEdit->toPlainText().split('\n');
// ui->checkBox->setChecked(settings.value("youtube-embed", true).toBool());
// ui->checkBox_2->setChecked(settings.value("twitch-embed", true).toBool());


ui->checkBox_SS->setChecked(settings.value("smooth-scroll", true).toBool());
}


Expand All @@ -73,3 +47,11 @@ void PreferencesForm::on_pushButton_clicked()
emit embedGPUView();
}


void PreferencesForm::on_checkBox_SS_clicked(bool checked)
{
QSettings settings("DiscordTabbed");
settings.setValue("smooth-scroll", checked);
emit preferencesUpdated();
}

8 changes: 2 additions & 6 deletions src/PreferencesForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,14 @@ class PreferencesForm : public QWidget
{
return _embedLinks;
}
// bool getYoutubeEmbed();
// bool getTwitchEmbed();
private slots:

void on_checkBox_clicked(bool checked);

void on_checkBox_2_clicked(bool checked);

void on_plainTextEdit_textChanged();

void on_pushButton_clicked();

void on_checkBox_SS_clicked(bool checked);

private:
void loadSettings();
Ui::PreferencesForm *ui;
Expand Down
Loading

0 comments on commit b59ab85

Please sign in to comment.