Added support for web icon and title fetching.
This commit is contained in:
parent
6ef18d1477
commit
08b3b60d33
@ -26,7 +26,9 @@
|
||||
#define APP_USERAGENT QString("@APP_NAME@/@APP_VERSION@ (@APP_URL@) on @CMAKE_SYSTEM@;")
|
||||
#endif
|
||||
|
||||
#define APP_CFG_PATH "data/config/config.ini"
|
||||
#define APP_CFG_PATH "data/config"
|
||||
#define APP_CFG_WEB_PATH "data/web"
|
||||
#define APP_CFG_FILE "config.ini"
|
||||
#define APP_CFG_GUI "gui"
|
||||
#define APP_CFG_GEN "main"
|
||||
#define APP_CFG_PROXY "proxy"
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QPointer>
|
||||
#include <QWebSettings>
|
||||
|
||||
#include "core/settings.h"
|
||||
#include "core/defs.h"
|
||||
@ -68,20 +69,23 @@ QSettings::Status Settings::setupSettings() {
|
||||
// then use it (portable settings).
|
||||
// Otherwise use settings file stored in homePath();
|
||||
QString home_path = QDir::homePath() + QDir::separator() +
|
||||
APP_LOW_H_NAME + QDir::separator() +
|
||||
APP_CFG_PATH;
|
||||
QString app_path = qApp->applicationDirPath() + QDir::separator() +
|
||||
APP_CFG_PATH;
|
||||
APP_LOW_H_NAME;
|
||||
QString home_path_file = home_path + QDir::separator() +
|
||||
APP_CFG_PATH + QDir::separator() + APP_CFG_FILE;
|
||||
QString app_path = qApp->applicationDirPath();
|
||||
QString app_path_file = app_path + QDir::separator() + APP_CFG_FILE;
|
||||
|
||||
if (QFile(app_path).exists()) {
|
||||
if (QFile(app_path_file).exists()) {
|
||||
s_instance = new Settings(app_path, QSettings::IniFormat, qApp);
|
||||
QWebSettings::setIconDatabasePath(app_path + QDir::separator() + APP_CFG_WEB_PATH);
|
||||
qDebug("Initializing settings in %s.",
|
||||
qPrintable(QDir::toNativeSeparators(app_path)));
|
||||
}
|
||||
else {
|
||||
s_instance = new Settings(home_path, QSettings::IniFormat, qApp);
|
||||
s_instance = new Settings(home_path_file, QSettings::IniFormat, qApp);
|
||||
QWebSettings::setIconDatabasePath(home_path + QDir::separator() + APP_CFG_WEB_PATH);
|
||||
qDebug("Initializing settings in %s.",
|
||||
qPrintable(QDir::toNativeSeparators(home_path)));
|
||||
qPrintable(QDir::toNativeSeparators(home_path_file)));
|
||||
}
|
||||
|
||||
return (*s_instance).checkSettings();
|
||||
|
@ -42,7 +42,7 @@ IconThemeFactory::IconThemeFactory(QObject *parent)
|
||||
}
|
||||
|
||||
IconThemeFactory::~IconThemeFactory() {
|
||||
qDebug("Destroying ThemeFactory instance.");
|
||||
qDebug("Destroying IconThemeFactory instance.");
|
||||
}
|
||||
|
||||
IconThemeFactory *IconThemeFactory::getInstance() {
|
||||
|
@ -31,8 +31,9 @@ void TabWidget::setupCornerButton() {
|
||||
void TabWidget::createConnections() {
|
||||
connect(m_cornerButton, SIGNAL(clicked()), this, SLOT(addEmptyBrowser()));
|
||||
connect(tabBar(), SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
|
||||
connect(tabBar(), SIGNAL(emptySpaceDoubleClicked()),
|
||||
this, SLOT(addEmptyBrowser()));
|
||||
connect(tabBar(), SIGNAL(emptySpaceDoubleClicked()), this, SLOT(addEmptyBrowser()));
|
||||
connect(tabBar(), SIGNAL(tabMoved(int,int)), this, SLOT(fixContentsAfterMove(int,int)));
|
||||
connect(tabBar(), SIGNAL(currentChanged(int)), this, SLOT(fixContentAfterIndexChange(int)));
|
||||
}
|
||||
|
||||
TabBar *TabWidget::tabBar() {
|
||||
@ -128,6 +129,14 @@ int TabWidget::addLinkedBrowser(const QUrl &initial_url) {
|
||||
initial_url);
|
||||
}
|
||||
|
||||
void TabWidget::changeIcon(int column, const QIcon &new_icon) {
|
||||
setTabIcon(column, new_icon);
|
||||
}
|
||||
|
||||
void TabWidget::changeTitle(int column, const QString &new_title) {
|
||||
setTabText(column, new_title);
|
||||
}
|
||||
|
||||
int TabWidget::addBrowser(bool move_after_current,
|
||||
bool make_active,
|
||||
const QUrl &initial_url) {
|
||||
@ -151,6 +160,15 @@ int TabWidget::addBrowser(bool move_after_current,
|
||||
TabBar::Closable);
|
||||
}
|
||||
|
||||
// Make connections.
|
||||
connect(browser, SIGNAL(titleChanged(int,QString)),
|
||||
this, SLOT(changeTitle(int,QString)));
|
||||
connect(browser, SIGNAL(iconChanged(int,QIcon)),
|
||||
this, SLOT(changeIcon(int,QIcon)));
|
||||
|
||||
// Setup the tab index.
|
||||
browser->setTabIndex(final_index);
|
||||
|
||||
// Load initial web page if desired.
|
||||
if (initial_url.isValid()) {
|
||||
browser->navigateToUrl(initial_url);
|
||||
@ -164,3 +182,18 @@ int TabWidget::addBrowser(bool move_after_current,
|
||||
|
||||
return final_index;
|
||||
}
|
||||
|
||||
void TabWidget::fixContentAfterIndexChange(int from) {
|
||||
fixContentsIndexes(from, count() - 1);
|
||||
}
|
||||
|
||||
void TabWidget::fixContentsAfterMove(int from, int to) {
|
||||
fixContentsIndexes(qMin(from, to), qMax(from, to));
|
||||
}
|
||||
|
||||
void TabWidget::fixContentsIndexes(int starting_index, int ending_index) {
|
||||
for ( ; starting_index <= ending_index; starting_index++) {
|
||||
TabContent *content = static_cast<TabContent*>(widget(starting_index));
|
||||
content->webBrowser()->setTabIndex(starting_index);
|
||||
}
|
||||
}
|
||||
|
@ -48,6 +48,16 @@ class TabWidget : public QTabWidget {
|
||||
void setupCornerButton();
|
||||
|
||||
public slots:
|
||||
void fixContentAfterIndexChange(int from);
|
||||
void fixContentsAfterMove(int from, int to);
|
||||
|
||||
// Fixes indexes of tab contents.
|
||||
void fixContentsIndexes(int starting_index, int ending_index);
|
||||
|
||||
// Changes icon/text of the tab.
|
||||
void changeTitle(int column, const QString &new_title);
|
||||
void changeIcon(int column, const QIcon &new_icon);
|
||||
|
||||
// Closes tab with given index and deletes contained widget.
|
||||
void closeTab(int index);
|
||||
|
||||
|
@ -25,6 +25,7 @@ WebBrowser::WebBrowser(QWidget *parent)
|
||||
m_toolBar(new QToolBar(tr("Navigation panel"), this)),
|
||||
m_webView(new BaseWebView(this)),
|
||||
m_txtLocation(new LocationLineEdit(this)),
|
||||
m_tabIndex(-1),
|
||||
m_actionBack(m_webView->pageAction(QWebPage::Back)),
|
||||
m_actionForward(m_webView->pageAction(QWebPage::Forward)),
|
||||
m_actionReload(m_webView->pageAction(QWebPage::Reload)),
|
||||
@ -86,12 +87,40 @@ void WebBrowser::createConnections() {
|
||||
// Change location textbox status according to webpage status.
|
||||
connect(m_webView, SIGNAL(loadProgress(int)), m_txtLocation, SLOT(setProgress(int)));
|
||||
connect(m_webView, SIGNAL(loadFinished(bool)), m_txtLocation, SLOT(clearProgress()));
|
||||
|
||||
// Forward title/icon changes.
|
||||
connect(m_webView, SIGNAL(titleChanged(QString)), this, SLOT(onTitleChanged(QString)));
|
||||
connect(m_webView, SIGNAL(iconChanged()), this, SLOT(onIconChanged()));
|
||||
}
|
||||
|
||||
void WebBrowser::onIconChanged() {
|
||||
emit iconChanged(m_tabIndex, m_webView->icon());
|
||||
}
|
||||
|
||||
void WebBrowser::onTitleChanged(const QString &new_title) {
|
||||
if (new_title.isEmpty()) {
|
||||
emit titleChanged(m_tabIndex, tr("No title"));
|
||||
}
|
||||
else {
|
||||
emit titleChanged(m_tabIndex, new_title);
|
||||
}
|
||||
|
||||
emit iconChanged(m_tabIndex, QIcon());
|
||||
}
|
||||
|
||||
void WebBrowser::updateUrl(const QUrl &url) {
|
||||
m_txtLocation->setText(url.toString());
|
||||
}
|
||||
|
||||
int WebBrowser::tabIndex() const {
|
||||
return m_tabIndex;
|
||||
}
|
||||
|
||||
void WebBrowser::setTabIndex(int tab_index) {
|
||||
m_tabIndex = tab_index;
|
||||
}
|
||||
|
||||
|
||||
void WebBrowser::navigateToUrl(const QUrl &url) {
|
||||
if (url.isValid()) {
|
||||
m_webView->load(url);
|
||||
|
@ -49,6 +49,10 @@ class WebBrowser : public TabContent {
|
||||
// Returns list of all running web browsers.
|
||||
static QList<WebBrowser*> runningWebBrowsers();
|
||||
|
||||
// Tab index getter/setter.
|
||||
int tabIndex() const;
|
||||
void setTabIndex(int tab_index);
|
||||
|
||||
public slots:
|
||||
// Switches visibility of navigation bar.
|
||||
void setNavigationBarVisible(bool visible);
|
||||
@ -65,16 +69,22 @@ class WebBrowser : public TabContent {
|
||||
// Updates url (for example on location text box).
|
||||
void updateUrl(const QUrl &url);
|
||||
|
||||
void onTitleChanged(const QString &new_title);
|
||||
void onIconChanged();
|
||||
|
||||
signals:
|
||||
void newTabRequested();
|
||||
void linkMiddleClicked(const QUrl &link_url);
|
||||
|
||||
void iconChanged(int index, const QIcon &icon);
|
||||
void titleChanged(int index, const QString &title);
|
||||
|
||||
private:
|
||||
QVBoxLayout *m_layout;
|
||||
QToolBar *m_toolBar;
|
||||
BaseWebView *m_webView;
|
||||
LocationLineEdit *m_txtLocation;
|
||||
int m_tabIndex;
|
||||
|
||||
QAction *m_actionBack;
|
||||
QAction *m_actionForward;
|
||||
|
Loading…
x
Reference in New Issue
Block a user