Skip to content

Commit

Permalink
screen selection
Browse files Browse the repository at this point in the history
  • Loading branch information
akdor1154 committed Mar 6, 2015
1 parent 425d913 commit be7577c
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ bool launch(AnyOption *cmdopts)

cmdopts->setOption("config", 'c');
cmdopts->setOption("uri", 'u');
cmdopts->setOption("monitors", 'm');

cmdopts->setVersion(VERSION);

Expand Down
27 changes: 22 additions & 5 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ MainWindow::MainWindow() : QMainWindow()
mainSettings = NULL;

isUrlRealyChanged = false;

handler = new UnixSignals();
connect(handler, SIGNAL(sigBREAK()), SLOT(unixSignalQuit()));
connect(handler, SIGNAL(sigTERM()), SLOT(unixSignalQuit()));
Expand All @@ -83,7 +82,8 @@ MainWindow::MainWindow() : QMainWindow()
void MainWindow::init(AnyOption *opts)
{
cmdopts = opts;

nam = new QNetworkAccessManager(this);
manualScreen = 0;
if (cmdopts->getValue("config") || cmdopts->getValue('c')) {
qDebug(">> Config option in command prompt...");
QString cfgPath = cmdopts->getValue('c');
Expand All @@ -95,6 +95,23 @@ void MainWindow::init(AnyOption *opts)
loadSettings(QString(""));
}

if (cmdopts->getValue('m')) {
qDebug("setting monitor");
QString monitorString = cmdopts->getValue('m');
bool ok;
int monitorNum = monitorString.toInt(&ok);
if (ok) {
const QList<QScreen*> screens = qApp->screens();
int numScreens = screens.size();
if (false && monitorNum >= numScreens) {
qDebug() << "invalid monitor" << monitorNum << ", you only have " << numScreens << "screens.";
} else {
qDebug() << "setting screen" << monitorNum << "/" << numScreens;
manualScreen = monitorNum;
}
}
}

if (mainSettings->value("signals/enable").toBool()) {
connect(handler, SIGNAL(sigUSR1()), SLOT(unixSignalUsr1()));
connect(handler, SIGNAL(sigUSR2()), SLOT(unixSignalUsr2()));
Expand Down Expand Up @@ -214,7 +231,6 @@ void MainWindow::init(AnyOption *opts)
connect(desktop, SIGNAL(resized(int)), SLOT(desktopResized(int)));

show();

view->page()->view()->setFocusPolicy(Qt::StrongFocus);
view->setFocusPolicy(Qt::StrongFocus);

Expand All @@ -234,6 +250,8 @@ void MainWindow::init(AnyOption *opts)

void MainWindow::delayedWindowResize()
{

this->windowHandle()->setScreen(qApp->screens()[manualScreen]);
if (mainSettings->value("view/fullscreen").toBool()) {
showFullScreen();
} else if (mainSettings->value("view/maximized").toBool()) {
Expand Down Expand Up @@ -734,8 +752,7 @@ void MainWindow::attachStyles()

void MainWindow::pageIconLoaded()
{
//TODO: fix;
//setWindowIcon(view->icon());
setWindowIcon(view->icon());
}

// ----------------------- SIGNALS -----------------------------
Expand Down
8 changes: 8 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
#include "anyoption.h"
#include "unixsignals.h"

#ifndef MAIN_WINDOW_H
#define MAIN_WINDOW_H

class MainWindow : public QMainWindow
{
Q_OBJECT
Expand All @@ -68,6 +71,8 @@ class MainWindow : public QMainWindow
void clearCache();
void clearCacheOnExit();

QNetworkAccessManager *nam;

protected slots:

void cleanupSlot();
Expand Down Expand Up @@ -114,6 +119,7 @@ protected slots:

AnyOption *cmdopts;
UnixSignals *handler;
int manualScreen;

#ifdef USE_TESTLIB
QTestEventList *simulateClick;
Expand All @@ -129,3 +135,5 @@ protected slots:
QTimer *delayedResize;
QTimer *delayedLoad;
};

#endif
46 changes: 35 additions & 11 deletions src/webview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
#include <QNetworkReply>
#include <QSslError>

#include "mainwindow.h"

WebView::WebView(QWidget* parent): QWebEngineView(parent)
{
player = NULL;
loader = NULL;
pageIcon = QIcon();
}

/**
Expand All @@ -34,6 +36,11 @@ void WebView::initSignals()
SIGNAL(printRequested(QWebEnginePage*)),
this,
SLOT(handlePrintRequested(QWebEnginePage*)));

connect(page(),
SIGNAL(iconUrlChanged(QUrl)),
this,
SLOT(onIconUrlChanged(QUrl)));
}

void WebView::setPage(QWebEnginePage *page)
Expand Down Expand Up @@ -97,22 +104,39 @@ void WebView::loadCustomPage(QString uri)
}
}


void WebView::handleSslErrors(QNetworkReply* reply, const QList<QSslError> &errors)
{
qDebug() << "handleSslErrors: ";
foreach (QSslError e, errors)
{
qDebug() << "ssl error: " << e;
QIcon WebView::icon() {
if (!pageIcon.isNull()) {
return pageIcon;
}
return static_cast<MainWindow*>(this->parent())->windowIcon();
}

if (mainSettings->value("browser/ignore_ssl_errors").toBool()) {
reply->ignoreSslErrors();
} else {
reply->abort();
void WebView::onIconUrlChanged(const QUrl &url) {
qDebug() << "icon changed";
QNetworkRequest iconRequest(url);
iconRequest.setSslConfiguration(QSslConfiguration::defaultConfiguration());
QNetworkAccessManager* nam = static_cast<MainWindow*>(this->parent())->nam;
pageIconReply = nam->get(iconRequest);
pageIconReply->setParent(this);

connect(pageIconReply, SIGNAL(finished()), this, SLOT(onIconLoaded()));

}

void WebView::onIconLoaded() {
pageIcon = QIcon();
if (pageIconReply) {
QByteArray data = pageIconReply->readAll();
QPixmap pixmap;
pixmap.loadFromData(data);
pageIcon.addPixmap(pixmap);
pageIconReply->deleteLater();
pageIconReply = 0;
}
emit iconChanged();
}


void WebView::handleWindowCloseRequested()
{
qDebug() << "Handle windowCloseRequested:" << mainSettings->value("browser/show_homepage_on_window_close").toString();
Expand Down
10 changes: 9 additions & 1 deletion src/webview.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ class WebView : public QWebEngineView

void playSound(QString soundSetting);

QIcon icon();


public slots:
void handlePrintRequested(QWebEnginePage *);
void handleUrlChanged(const QUrl &);

signals:
void iconChanged();

protected:
void mousePressEvent(QMouseEvent *event);
QPlayer *getPlayer();
Expand All @@ -47,9 +51,13 @@ public slots:
FakeWebView *loader;
QPrinter *printer;

QIcon pageIcon;
QNetworkReply* pageIconReply;

private slots:
void handleSslErrors(QNetworkReply* reply, const QList<QSslError> &errors);
void handleWindowCloseRequested();
void onIconLoaded();
void onIconUrlChanged(const QUrl&);

};

Expand Down

0 comments on commit be7577c

Please sign in to comment.