aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-01-16 14:01:01 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2017-01-16 14:01:01 +0100
commita58c58148db61107497fbdf7fa98ceee96c99c4d (patch)
tree6b9837916015635be06c87b4e69c63844f8c831e
parentDownload manager (diff)
downloadsmolbote-a58c58148db61107497fbdf7fa98ceee96c99c4d.tar.xz
Added license headers
-rw-r--r--header-gpl3.txt20
-rwxr-xr-xscripts/licensecheck.py59
-rw-r--r--src/browser.cpp114
-rw-r--r--src/browser.h72
-rw-r--r--src/forms/downloaddialog.cpp20
-rw-r--r--src/forms/downloaddialog.h20
-rw-r--r--src/forms/profiledialog.cpp20
-rw-r--r--src/forms/profiledialog.h20
-rw-r--r--src/main.cpp96
-rw-r--r--src/mainwindow.cpp332
-rw-r--r--src/mainwindow.h136
-rw-r--r--src/settings.cpp20
-rw-r--r--src/settings.h20
-rw-r--r--src/webengine/downloaditemform.cpp20
-rw-r--r--src/webengine/downloaditemform.h20
-rw-r--r--src/webengine/webengineprofile.cpp20
-rw-r--r--src/webengine/webengineprofile.h20
-rw-r--r--src/widgets/webviewtabbar.cpp20
-rw-r--r--src/widgets/webviewtabbar.h20
19 files changed, 744 insertions, 325 deletions
diff --git a/header-gpl3.txt b/header-gpl3.txt
new file mode 100644
index 0000000..939e526
--- /dev/null
+++ b/header-gpl3.txt
@@ -0,0 +1,20 @@
+/** LICENSE ********************************************************************
+ **
+ ** smolbote: yet another qute browser
+ ** Copyright (C) $CURRENTYEAR$ $AUTHOR$
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **
+ ******************************************************************************/
+
diff --git a/scripts/licensecheck.py b/scripts/licensecheck.py
new file mode 100755
index 0000000..be6de9a
--- /dev/null
+++ b/scripts/licensecheck.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python3
+
+# TODO: username argument
+# TODO: updating licenses
+
+import argparse
+import datetime
+
+def getLicense(licenseFile):
+ with open(licenseFile) as rawlicense:
+ licensetext = rawlicense.read()
+
+ # fill in name and year
+ licensetext = licensetext.replace('$AUTHOR$', 'Xian Nox')
+ licensetext = licensetext.replace('$CURRENTYEAR$', str(datetime.datetime.now().year))
+
+ return licensetext
+
+def hasLicense(sourceFile):
+ with open(sourceFile) as source:
+ if source.readline().startswith('/** LICENSE **'):
+ return True
+ else:
+ return False
+
+def fix(sourceFile, licenseText):
+ with open(sourceFile, 'r') as source:
+ origData = source.read()
+ with open(sourceFile, 'w') as source:
+ source.write(licenseText + origData)
+
+def main(license, src, verbose=False):
+ if verbose is True:
+ print("Using license header {0}".format(license))
+ print("Going through {0}".format(src))
+
+ # read license file
+ licensetext = getLicense(license)
+ #print(licensetext)
+
+ # open source file and check for license
+ for filename in src:
+ if hasLicense(filename):
+ print("{0} has license".format(filename))
+ else:
+ fix(filename, licensetext)
+ print("{0} license added".format(filename))
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser(description='Check source files for license')
+ parser.add_argument('-l', '--license', required=True)
+ parser.add_argument('-v', '--verbose', action='store_true')
+ parser.add_argument('src', nargs='*')
+ args = parser.parse_args()
+
+ main(args.license, args.src, args.verbose)
+else:
+ print('Do not use this as an import!')
+ sys.exit(-1)
diff --git a/src/browser.cpp b/src/browser.cpp
index e6be694..654c020 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -1,47 +1,67 @@
-#include "browser.h"
-#include "mainwindow.h"
-#include "settings.h"
-#include <QtWebEngine>
-
-Browser::Browser(QString configPath, QObject *parent) : QObject(parent)
-{
- if(configPath.isEmpty()) {
- // set default config path
- Settings::setFilepath(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini");
- } else {
- // set custom config path
- Settings::setFilepath(configPath);
- }
-
- // TODO Restore previous session
-
- QtWebEngine::initialize();
-}
-
-Browser::~Browser()
-{
- // TODO Save session
-
- // cleanup
- qDeleteAll(m_windows);
- m_windows.clear();
-}
-
-void Browser::addWindow(MainWindow *window)
-{
- if(m_windows.contains(window)) {
- return;
- }
-
- m_windows.append(window);
- connect(window, &QObject::destroyed, [this, window]() {
- this->removeWindow(window);
- });
-
- window->show();
-}
-
-void Browser::removeWindow(MainWindow *window)
-{
- m_windows.removeOne(window);
-}
+/** LICENSE ********************************************************************
+ **
+ ** smolbote: yet another qute browser
+ ** Copyright (C) 2017 Xian Nox
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **
+ ******************************************************************************/
+
+#include "browser.h"
+#include "mainwindow.h"
+#include "settings.h"
+#include <QtWebEngine>
+
+Browser::Browser(QString configPath, QObject *parent) : QObject(parent)
+{
+ if(configPath.isEmpty()) {
+ // set default config path
+ Settings::setFilepath(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini");
+ } else {
+ // set custom config path
+ Settings::setFilepath(configPath);
+ }
+
+ // TODO Restore previous session
+
+ QtWebEngine::initialize();
+}
+
+Browser::~Browser()
+{
+ // TODO Save session
+
+ // cleanup
+ qDeleteAll(m_windows);
+ m_windows.clear();
+}
+
+void Browser::addWindow(MainWindow *window)
+{
+ if(m_windows.contains(window)) {
+ return;
+ }
+
+ m_windows.append(window);
+ connect(window, &QObject::destroyed, [this, window]() {
+ this->removeWindow(window);
+ });
+
+ window->show();
+}
+
+void Browser::removeWindow(MainWindow *window)
+{
+ m_windows.removeOne(window);
+}
diff --git a/src/browser.h b/src/browser.h
index 38826f0..14ef771 100644
--- a/src/browser.h
+++ b/src/browser.h
@@ -1,26 +1,46 @@
-#ifndef BROWSER_H
-#define BROWSER_H
-
-#include <QObject>
-#include <QVector>
-
-class MainWindow;
-class Browser : public QObject
-{
- Q_OBJECT
-
-public:
- explicit Browser(QString configPath, QObject *parent = 0);
- ~Browser();
-
- void addWindow(MainWindow* window);
-
-public slots:
- void removeWindow(MainWindow* window);
-
-private:
- QVector<MainWindow*> m_windows;
-
-};
-
-#endif // BROWSER_H
+/** LICENSE ********************************************************************
+ **
+ ** smolbote: yet another qute browser
+ ** Copyright (C) 2017 Xian Nox
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **
+ ******************************************************************************/
+
+#ifndef BROWSER_H
+#define BROWSER_H
+
+#include <QObject>
+#include <QVector>
+
+class MainWindow;
+class Browser : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit Browser(QString configPath, QObject *parent = 0);
+ ~Browser();
+
+ void addWindow(MainWindow* window);
+
+public slots:
+ void removeWindow(MainWindow* window);
+
+private:
+ QVector<MainWindow*> m_windows;
+
+};
+
+#endif // BROWSER_H
diff --git a/src/forms/downloaddialog.cpp b/src/forms/downloaddialog.cpp
index 4943fcc..bb92a0f 100644
--- a/src/forms/downloaddialog.cpp
+++ b/src/forms/downloaddialog.cpp
@@ -1,3 +1,23 @@
+/** LICENSE ********************************************************************
+ **
+ ** smolbote: yet another qute browser
+ ** Copyright (C) 2017 Xian Nox
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **
+ ******************************************************************************/
+
#include "downloaddialog.h"
#include "ui_downloaddialog.h"
diff --git a/src/forms/downloaddialog.h b/src/forms/downloaddialog.h
index bec0037..cadc2b5 100644
--- a/src/forms/downloaddialog.h
+++ b/src/forms/downloaddialog.h
@@ -1,3 +1,23 @@
+/** LICENSE ********************************************************************
+ **
+ ** smolbote: yet another qute browser
+ ** Copyright (C) 2017 Xian Nox
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **
+ ******************************************************************************/
+
#ifndef DOWNLOADDIALOG_H
#define DOWNLOADDIALOG_H
diff --git a/src/forms/profiledialog.cpp b/src/forms/profiledialog.cpp
index 286d85c..3d93dd0 100644
--- a/src/forms/profiledialog.cpp
+++ b/src/forms/profiledialog.cpp
@@ -1,3 +1,23 @@
+/** LICENSE ********************************************************************
+ **
+ ** smolbote: yet another qute browser
+ ** Copyright (C) 2017 Xian Nox
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **
+ ******************************************************************************/
+
#include "profiledialog.h"
#include "ui_profiledialog.h"
diff --git a/src/forms/profiledialog.h b/src/forms/profiledialog.h
index c78f892..59c2d5a 100644
--- a/src/forms/profiledialog.h
+++ b/src/forms/profiledialog.h
@@ -1,3 +1,23 @@
+/** LICENSE ********************************************************************
+ **
+ ** smolbote: yet another qute browser
+ ** Copyright (C) 2017 Xian Nox
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **
+ ******************************************************************************/
+
#ifndef PROFILEDIALOG_H
#define PROFILEDIALOG_H
diff --git a/src/main.cpp b/src/main.cpp
index ef6a5e1..698a4a4 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,38 +1,58 @@
-#include "browser.h"
-#include "mainwindow.h"
-#include <QApplication>
-#include <QCommandLineParser>
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- app.setApplicationName("smolbote");
- app.setApplicationVersion("0.0.0");
-
- QCommandLineParser parser;
- parser.setApplicationDescription("Test browser using QtWebEngine");
- parser.addHelpOption();
- parser.addVersionOption();
-
- parser.addPositionalArgument("URL", "URL to open");
-
- QCommandLineOption configOption(QStringList() << "c" << "config", "Set configuration file.", "PATH");
- parser.addOption(configOption);
-
- parser.process(app);
-
- Browser instance(parser.value(configOption));
-
- if(parser.positionalArguments().length() > 0) {
- QUrl url = QUrl::fromUserInput(parser.positionalArguments().at(0));
- if(url.isValid()) {
- instance.addWindow(new MainWindow(&instance, url));
- } else {
- instance.addWindow(new MainWindow(&instance));
- }
- } else {
- instance.addWindow(new MainWindow(&instance));
- }
-
- return app.exec();
-}
+/** LICENSE ********************************************************************
+ **
+ ** smolbote: yet another qute browser
+ ** Copyright (C) 2017 Xian Nox
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **
+ ******************************************************************************/
+
+#include "browser.h"
+#include "mainwindow.h"
+#include <QApplication>
+#include <QCommandLineParser>
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ app.setApplicationName("smolbote");
+ app.setApplicationVersion("0.0.0");
+
+ QCommandLineParser parser;
+ parser.setApplicationDescription("Test browser using QtWebEngine");
+ parser.addHelpOption();
+ parser.addVersionOption();
+
+ parser.addPositionalArgument("URL", "URL to open");
+
+ QCommandLineOption configOption(QStringList() << "c" << "config", "Set configuration file.", "PATH");
+ parser.addOption(configOption);
+
+ parser.process(app);
+
+ Browser instance(parser.value(configOption));
+
+ if(parser.positionalArguments().length() > 0) {
+ QUrl url = QUrl::fromUserInput(parser.positionalArguments().at(0));
+ if(url.isValid()) {
+ instance.addWindow(new MainWindow(&instance, url));
+ } else {
+ instance.addWindow(new MainWindow(&instance));
+ }
+ } else {
+ instance.addWindow(new MainWindow(&instance));
+ }
+
+ return app.exec();
+}
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 9e028e4..1a52ee2 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1,156 +1,176 @@
-#include "mainwindow.h"
-#include "ui_mainwindow.h"
-#include "settings.h"
-#include <QMenu>
-#include <QMenuBar>
-#include <QCloseEvent>
-#include <QMessageBox>
-#include "browser.h"
-#include "forms/profiledialog.h"
-#include <QApplication>
-#include <QInputDialog>
-#include <QWebEngineDownloadItem>
-
-MainWindow::MainWindow(Browser *instance, QUrl defaultUrl, QWidget *parent) :
- QMainWindow(parent),
- downloadManager(new DownloadDialog(this)),
- ui(new Ui::MainWindow),
- navigationToolBar(new QToolBar(this)),
- tabToolBar(new QToolBar(this)),
- tabBar(new WebViewTabBar(this)),
- urlLineEdit(new QLineEdit(navigationToolBar))
-{
- browserInstance = instance;
- Settings settings;
-
- // Load profile and connect its signals
- loadProfile(settings.value("defaults/profile").toString());
-
- ui->setupUi(this);
- resize(settings.value("window/width", 800).toInt(), settings.value("window/height", 600).toInt());
-
- // Browser menu
- browserMenu = new QMenu(qApp->applicationName(), ui->menuBar);
- ui->menuBar->addMenu(browserMenu);
- browserMenu->addAction(tr("New Window"), this, SLOT(handleNewWindow()), QKeySequence(tr("Ctrl+N")));
- browserMenu->addAction(tr("New Tab"), this, SLOT(createNewTab()), QKeySequence(tr("Ctrl+T")));
- browserMenu->addSeparator();
- browserMenu->addAction(tr("About Qt"), qApp, SLOT(aboutQt()));
- browserMenu->addAction(tr("Quit"), qApp, SLOT(quit()), QKeySequence(tr("Ctrl+Q")));
-
- // Profile menu
- QMenuBar *rightBar = new QMenuBar(ui->menuBar);
- profileMenu = new QMenu(tr("Profile: ") + profileName);
- rightBar->addMenu(profileMenu);
- ui->menuBar->setCornerWidget(rightBar);
- profileMenu->addAction(tr("Edit profile"), this, SLOT(createProfileDialog()));
- profileMenu->addAction(tr("Load profile"), this, SLOT(handleLoadProfile()));
- profileMenu->addAction(tr("Downloads"), downloadManager, SLOT(show()));
- //profileMenu->addAction(tr("Settings"));
- //profileMenu->addAction(tr("Cookies"));
-
- this->addToolBar(Qt::TopToolBarArea, navigationToolBar);
- this->addToolBarBreak(Qt::TopToolBarArea);
- this->addToolBar(Qt::TopToolBarArea, tabToolBar);
-
- navigationToolBar->addWidget(urlLineEdit);
- connect(urlLineEdit, SIGNAL(returnPressed()), this, SLOT(handleUrlChanged()));
-
- tabToolBar->addWidget(tabBar);
- connect(tabBar, SIGNAL(currentTabChanged(QWebEngineView*)), this, SLOT(handleTabChanged(QWebEngineView*)));
-
- if(!defaultUrl.isEmpty())
- createNewTab(defaultUrl);
- else
- createNewTab(settings.value("defaults/url", QUrl("http://duckduckgo.com")).toUrl());
-}
-
-MainWindow::~MainWindow()
-{
- delete ui;
-}
-
-void MainWindow::createNewTab(const QUrl &url)
-{
- tabBar->addTab(profile, url);
-}
-
-void MainWindow::closeEvent(QCloseEvent *event)
-{
- if(tabBar->count() > 1) {
- int ret = QMessageBox::warning(this, tr("Close window?"), tr("Close multiple tabs?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
- if(ret == QMessageBox::No) {
- event->ignore();
- return;
- }
- }
- QMainWindow::closeEvent(event);
-}
-
-void MainWindow::loadProfile(const QString &name)
-{
- if(profile) {
- profile->deleteLater();
- }
-
- if(name.isEmpty()) {
- qDebug("Creating off-the-record profile");
- profileName = tr("Off the record");
- profile = new WebEngineProfile(this);
- } else {
- profileName = name;
- qDebug("Using profile: %s", qUtf8Printable(profileName));
- profile = new WebEngineProfile(profileName, this);
- }
-
- connect(profile, SIGNAL(downloadRequested(QWebEngineDownloadItem*)), downloadManager, SLOT(addDownload(QWebEngineDownloadItem*)));
-}
-
-void MainWindow::handleLoadProfile()
-{
- bool ok;
- QString name = QInputDialog::getText(this, tr("Load Profile"), tr("Enter Profile name"), QLineEdit::Normal, QString(""), &ok);
- if(ok) {
- loadProfile(name);
- profileMenu->setTitle(tr("Profile: ") + profileName);
- tabBar->setProfile(profile);
- }
-}
-
-void MainWindow::handleNewWindow(const QUrl &url)
-{
- browserInstance->addWindow(new MainWindow(browserInstance, url));
-}
-
-void MainWindow::handleTabChanged(QWebEngineView *view)
-{
- centralWidget()->setParent(0);
- disconnect(centralWidget());
- setCentralWidget(view);
- connect(view, SIGNAL(urlChanged(QUrl)), this, SLOT(handleUrlUpdated(QUrl)));
- connect(view, SIGNAL(titleChanged(QString)), this, SLOT(handleTitleUpdated(QString)));
- this->handleUrlUpdated(view->url());
- this->handleTitleUpdated(view->title());
-}
-
-void MainWindow::handleUrlChanged()
-{
- tabBar->currentView()->load(QUrl::fromUserInput(urlLineEdit->text()));
-}
-
-void MainWindow::handleUrlUpdated(const QUrl &url)
-{
- urlLineEdit->setText(url.toString());
-}
-
-void MainWindow::handleTitleUpdated(const QString &title)
-{
- Settings settings;
- setWindowTitle(title + settings.value("window/title").toString());
-}
-
-void MainWindow::createProfileDialog()
-{
- ProfileDialog *dialog = new ProfileDialog(profile, this);
- dialog->exec();
-}
+/** LICENSE ********************************************************************
+ **
+ ** smolbote: yet another qute browser
+ ** Copyright (C) 2017 Xian Nox
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **
+ ******************************************************************************/
+
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+#include "settings.h"
+#include <QMenu>
+#include <QMenuBar>
+#include <QCloseEvent>
+#include <QMessageBox>
+#include "browser.h"
+#include "forms/profiledialog.h"
+#include <QApplication>
+#include <QInputDialog>
+#include <QWebEngineDownloadItem>
+
+MainWindow::MainWindow(Browser *instance, QUrl defaultUrl, QWidget *parent) :
+ QMainWindow(parent),
+ downloadManager(new DownloadDialog(this)),
+ ui(new Ui::MainWindow),
+ navigationToolBar(new QToolBar(this)),
+ tabToolBar(new QToolBar(this)),
+ tabBar(new WebViewTabBar(this)),
+ urlLineEdit(new QLineEdit(navigationToolBar))
+{
+ browserInstance = instance;
+ Settings settings;
+
+ // Load profile and connect its signals
+ loadProfile(settings.value("defaults/profile").toString());
+
+ ui->setupUi(this);
+ resize(settings.value("window/width", 800).toInt(), settings.value("window/height", 600).toInt());
+
+ // Browser menu
+ browserMenu = new QMenu(qApp->applicationName(), ui->menuBar);
+ ui->menuBar->addMenu(browserMenu);
+ browserMenu->addAction(tr("New Window"), this, SLOT(handleNewWindow()), QKeySequence(tr("Ctrl+N")));
+ browserMenu->addAction(tr("New Tab"), this, SLOT(createNewTab()), QKeySequence(tr("Ctrl+T")));
+ browserMenu->addSeparator();
+ browserMenu->addAction(tr("About Qt"), qApp, SLOT(aboutQt()));
+ browserMenu->addAction(tr("Quit"), qApp, SLOT(quit()), QKeySequence(tr("Ctrl+Q")));
+
+ // Profile menu
+ QMenuBar *rightBar = new QMenuBar(ui->menuBar);
+ profileMenu = new QMenu(tr("Profile: ") + profileName);
+ rightBar->addMenu(profileMenu);
+ ui->menuBar->setCornerWidget(rightBar);
+ profileMenu->addAction(tr("Edit profile"), this, SLOT(createProfileDialog()));
+ profileMenu->addAction(tr("Load profile"), this, SLOT(handleLoadProfile()));
+ profileMenu->addAction(tr("Downloads"), downloadManager, SLOT(show()));
+ //profileMenu->addAction(tr("Settings"));
+ //profileMenu->addAction(tr("Cookies"));
+
+ this->addToolBar(Qt::TopToolBarArea, navigationToolBar);
+ this->addToolBarBreak(Qt::TopToolBarArea);
+ this->addToolBar(Qt::TopToolBarArea, tabToolBar);
+
+ navigationToolBar->addWidget(urlLineEdit);
+ connect(urlLineEdit, SIGNAL(returnPressed()), this, SLOT(handleUrlChanged()));
+
+ tabToolBar->addWidget(tabBar);
+ connect(tabBar, SIGNAL(currentTabChanged(QWebEngineView*)), this, SLOT(handleTabChanged(QWebEngineView*)));
+
+ if(!defaultUrl.isEmpty())
+ createNewTab(defaultUrl);
+ else
+ createNewTab(settings.value("defaults/url", QUrl("http://duckduckgo.com")).toUrl());
+}
+
+MainWindow::~MainWindow()
+{
+ delete ui;
+}
+
+void MainWindow::createNewTab(const QUrl &url)
+{
+ tabBar->addTab(profile, url);
+}
+
+void MainWindow::closeEvent(QCloseEvent *event)
+{
+ if(tabBar->count() > 1) {
+ int ret = QMessageBox::warning(this, tr("Close window?"), tr("Close multiple tabs?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
+ if(ret == QMessageBox::No) {
+ event->ignore();
+ return;
+ }
+ }
+ QMainWindow::closeEvent(event);
+}
+
+void MainWindow::loadProfile(const QString &name)
+{
+ if(profile) {
+ profile->deleteLater();
+ }
+
+ if(name.isEmpty()) {
+ qDebug("Creating off-the-record profile");
+ profileName = tr("Off the record");
+ profile = new WebEngineProfile(this);
+ } else {
+ profileName = name;
+ qDebug("Using profile: %s", qUtf8Printable(profileName));
+ profile = new WebEngineProfile(profileName, this);
+ }
+
+ connect(profile, SIGNAL(downloadRequested(QWebEngineDownloadItem*)), downloadManager, SLOT(addDownload(QWebEngineDownloadItem*)));
+}
+
+void MainWindow::handleLoadProfile()
+{
+ bool ok;
+ QString name = QInputDialog::getText(this, tr("Load Profile"), tr("Enter Profile name"), QLineEdit::Normal, QString(""), &ok);
+ if(ok) {
+ loadProfile(name);
+ profileMenu->setTitle(tr("Profile: ") + profileName);
+ tabBar->setProfile(profile);
+ }
+}
+
+void MainWindow::handleNewWindow(const QUrl &url)
+{
+ browserInstance->addWindow(new MainWindow(browserInstance, url));
+}
+
+void MainWindow::handleTabChanged(QWebEngineView *view)
+{
+ centralWidget()->setParent(0);
+ disconnect(centralWidget());
+ setCentralWidget(view);
+ connect(view, SIGNAL(urlChanged(QUrl)), this, SLOT(handleUrlUpdated(QUrl)));
+ connect(view, SIGNAL(titleChanged(QString)), this, SLOT(handleTitleUpdated(QString)));
+ this->handleUrlUpdated(view->url());
+ this->handleTitleUpdated(view->title());
+}
+
+void MainWindow::handleUrlChanged()
+{
+ tabBar->currentView()->load(QUrl::fromUserInput(urlLineEdit->text()));
+}
+
+void MainWindow::handleUrlUpdated(const QUrl &url)
+{
+ urlLineEdit->setText(url.toString());
+}
+
+void MainWindow::handleTitleUpdated(const QString &title)
+{
+ Settings settings;
+ setWindowTitle(title + settings.value("window/title").toString());
+}
+
+void MainWindow::createProfileDialog()
+{
+ ProfileDialog *dialog = new ProfileDialog(profile, this);
+ dialog->exec();
+}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 2ad88b8..f084b95 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -1,58 +1,78 @@
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QMainWindow>
-#include <QToolBar>
-#include <QLineEdit>
-#include <QWebEngineView>
-#include "webengine/webengineprofile.h"
-#include <QUrl>
-#include "widgets/webviewtabbar.h"
-#include "forms/downloaddialog.h"
-
-namespace Ui {
-class MainWindow;
-}
-
-class Browser;
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-
-public:
- explicit MainWindow(Browser *instance, QUrl defaultUrl = QUrl(""), QWidget *parent = 0);
- ~MainWindow();
-
-public slots:
- void createNewTab(const QUrl &url = QUrl(""));
-
-protected:
- void closeEvent(QCloseEvent *event) override;
-
-private slots:
- void loadProfile(const QString &name);
- void handleLoadProfile();
-
- void handleNewWindow(const QUrl &url = QUrl(""));
- void handleTabChanged(QWebEngineView *view);
- void handleUrlChanged();
- void handleUrlUpdated(const QUrl &url);
- void handleTitleUpdated(const QString &title);
-
- void createProfileDialog();
-
-private:
- Browser *browserInstance;
- DownloadDialog *downloadManager;
- QString profileName;
- WebEngineProfile *profile = nullptr;
-
- // ui
- Ui::MainWindow *ui;
- QMenu *browserMenu, *profileMenu;
- QToolBar *navigationToolBar, *tabToolBar;
- WebViewTabBar *tabBar;
- QLineEdit *urlLineEdit;
-};
-
-#endif // MAINWINDOW_H
+/** LICENSE ********************************************************************
+ **
+ ** smolbote: yet another qute browser
+ ** Copyright (C) 2017 Xian Nox
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **
+ ******************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <QToolBar>
+#include <QLineEdit>
+#include <QWebEngineView>
+#include "webengine/webengineprofile.h"
+#include <QUrl>
+#include "widgets/webviewtabbar.h"
+#include "forms/downloaddialog.h"
+
+namespace Ui {
+class MainWindow;
+}
+
+class Browser;
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ explicit MainWindow(Browser *instance, QUrl defaultUrl = QUrl(""), QWidget *parent = 0);
+ ~MainWindow();
+
+public slots:
+ void createNewTab(const QUrl &url = QUrl(""));
+
+protected:
+ void closeEvent(QCloseEvent *event) override;
+
+private slots:
+ void loadProfile(const QString &name);
+ void handleLoadProfile();
+
+ void handleNewWindow(const QUrl &url = QUrl(""));
+ void handleTabChanged(QWebEngineView *view);
+ void handleUrlChanged();
+ void handleUrlUpdated(const QUrl &url);
+ void handleTitleUpdated(const QString &title);
+
+ void createProfileDialog();
+
+private:
+ Browser *browserInstance;
+ DownloadDialog *downloadManager;
+ QString profileName;
+ WebEngineProfile *profile = nullptr;
+
+ // ui
+ Ui::MainWindow *ui;
+ QMenu *browserMenu, *profileMenu;
+ QToolBar *navigationToolBar, *tabToolBar;
+ WebViewTabBar *tabBar;
+ QLineEdit *urlLineEdit;
+};
+
+#endif // MAINWINDOW_H
diff --git a/src/settings.cpp b/src/settings.cpp
index 4dbc7c8..ad5cdb0 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -1,3 +1,23 @@
+/** LICENSE ********************************************************************
+ **
+ ** smolbote: yet another qute browser
+ ** Copyright (C) 2017 Xian Nox
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **
+ ******************************************************************************/
+
#include "settings.h"
QString Settings::_path = QString("");
diff --git a/src/settings.h b/src/settings.h
index 146bfa1..e073ceb 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -1,3 +1,23 @@
+/** LICENSE ********************************************************************
+ **
+ ** smolbote: yet another qute browser
+ ** Copyright (C) 2017 Xian Nox
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **
+ ******************************************************************************/
+
#ifndef SETTINGS_H
#define SETTINGS_H
diff --git a/src/webengine/downloaditemform.cpp b/src/webengine/downloaditemform.cpp
index 717a41d..39661f9 100644
--- a/src/webengine/downloaditemform.cpp
+++ b/src/webengine/downloaditemform.cpp
@@ -1,3 +1,23 @@
+/** LICENSE ********************************************************************
+ **
+ ** smolbote: yet another qute browser
+ ** Copyright (C) 2017 Xian Nox
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **
+ ******************************************************************************/
+
#include "downloaditemform.h"
#include "ui_downloaditemform.h"
diff --git a/src/webengine/downloaditemform.h b/src/webengine/downloaditemform.h
index 996b876..963d7c5 100644
--- a/src/webengine/downloaditemform.h
+++ b/src/webengine/downloaditemform.h
@@ -1,3 +1,23 @@
+/** LICENSE ********************************************************************
+ **
+ ** smolbote: yet another qute browser
+ ** Copyright (C) 2017 Xian Nox
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **
+ ******************************************************************************/
+
#ifndef DOWNLOADITEMFORM_H
#define DOWNLOADITEMFORM_H
diff --git a/src/webengine/webengineprofile.cpp b/src/webengine/webengineprofile.cpp
index 1eb1112..532250c 100644
--- a/src/webengine/webengineprofile.cpp
+++ b/src/webengine/webengineprofile.cpp
@@ -1,3 +1,23 @@
+/** LICENSE ********************************************************************
+ **
+ ** smolbote: yet another qute browser
+ ** Copyright (C) 2017 Xian Nox
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **
+ ******************************************************************************/
+
#include "webengineprofile.h"
#include <QSettings>
diff --git a/src/webengine/webengineprofile.h b/src/webengine/webengineprofile.h
index ca2fd08..51fb739 100644
--- a/src/webengine/webengineprofile.h
+++ b/src/webengine/webengineprofile.h
@@ -1,3 +1,23 @@
+/** LICENSE ********************************************************************
+ **
+ ** smolbote: yet another qute browser
+ ** Copyright (C) 2017 Xian Nox
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **
+ ******************************************************************************/
+
#ifndef WEBENGINEPROFILE_H
#define WEBENGINEPROFILE_H
diff --git a/src/widgets/webviewtabbar.cpp b/src/widgets/webviewtabbar.cpp
index 666c610..d3747cc 100644
--- a/src/widgets/webviewtabbar.cpp
+++ b/src/widgets/webviewtabbar.cpp
@@ -1,3 +1,23 @@
+/** LICENSE ********************************************************************
+ **
+ ** smolbote: yet another qute browser
+ ** Copyright (C) 2017 Xian Nox
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **
+ ******************************************************************************/
+
#include "webviewtabbar.h"
WebViewTabBar::WebViewTabBar(QWidget *parent) :
diff --git a/src/widgets/webviewtabbar.h b/src/widgets/webviewtabbar.h
index f4fc6e4..58d85a8 100644
--- a/src/widgets/webviewtabbar.h
+++ b/src/widgets/webviewtabbar.h
@@ -1,3 +1,23 @@
+/** LICENSE ********************************************************************
+ **
+ ** smolbote: yet another qute browser
+ ** Copyright (C) 2017 Xian Nox
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **
+ ******************************************************************************/
+
#ifndef WEBVIEWTABBAR_H
#define WEBVIEWTABBAR_H