Adds some right click menus, fixes bug in gopher.

This commit is contained in:
Felix (xq) Queißner 2020-06-10 00:31:56 +02:00
parent 0739bce0be
commit 656391ecc0
11 changed files with 136 additions and 31 deletions

View File

@ -24,6 +24,10 @@ Kristall Changelog
- Added help file
- Added shortcut to focus URL bar
- Added possibility to save/load/share theme presets. Make everything colorful!
- Added a lot of context menus
- Added possibility to open links into a new tab
- Added possibility to open history and favourite items into new tab or same tab
== 0.1
- Initial release

View File

@ -107,21 +107,12 @@ ln -s Kristall.desktop ~/.local/share/applications/kristall.desktop
- [ ] Will use a preview document instead of displaying the content
- [ ] Allow import of themes
- [ ] File extension is `.kthm`
- [ ] Replace Qt markdown with standalone markdown renderer
- [ ] Enable markdown theming
- [ ] Render text/plain and others with custom document creation for styles. Enable auto-link recognition
- [ ] Implement more protocols
- [ ] Gopher
- [ ] Support more media types (include uudecode and hexbin decoder)
- [ ] Read non-binary media only until `.`
- [ ] Image Zoom and Pan
- [ ] Improve Unicode/Emoji support
- Seems to need multiple font families per font?
- [ ] Rightclick with "open in new tab" and "open in this tab"
- [ ] For history
- [ ] For favourites
- [ ] For documents
### 0.3 release
- [ ] TLS Handling
- [ ] Allow user to ignore TLS errors
@ -143,6 +134,11 @@ ln -s Kristall.desktop ~/.local/share/applications/kristall.desktop
- [ ] FTP
- [ ] Search for FTP library or use self-written one?
- [ ] Improve UX
- [ ] Provide text search function
- [ ] Replace Qt markdown with standalone markdown renderer
- [ ] Enable markdown theming
- [ ] Improve Unicode/Emoji support
- Seems to need multiple font families per font?
## Bugs

View File

@ -64,6 +64,8 @@ BrowserTab::BrowserTab(MainWindow * mainWindow) :
this->ui->graphics_browser->setVisible(false);
this->ui->text_browser->setVisible(true);
this->ui->text_browser->setContextMenuPolicy(Qt::CustomContextMenu);
this->ui->graphics_browser->setScene(&graphics_scene);
}
@ -591,3 +593,37 @@ void BrowserTab::updateUI()
this->ui->fav_button->setEnabled(this->successfully_loaded);
this->ui->fav_button->setChecked(this->mainWindow->favourites.contains(this->current_location));
}
#include <QClipboard>
void BrowserTab::on_text_browser_customContextMenuRequested(const QPoint &pos)
{
QMenu menu;
QString anchor = ui->text_browser->anchorAt(pos);
if(not anchor.isEmpty()) {
QUrl real_url { anchor };
if(real_url.isRelative())
real_url = this->current_location.resolved(real_url);
connect(menu.addAction("Follow link…"), &QAction::triggered, [this,real_url]() {
this->navigateTo(real_url, PushImmediate);
});
connect(menu.addAction("Open in new tab…"), &QAction::triggered, [this,real_url]() {
mainWindow->addNewTab(false, real_url);
});
connect(menu.addAction("Copy link"), &QAction::triggered, [this,real_url]() {
global_clipboard->setText(real_url.toString(QUrl::FullyEncoded));
});
menu.addSeparator();
}
connect(menu.addAction("Select all"), &QAction::triggered, [this]() {
this->ui->text_browser->selectAll();
});
menu.exec(ui->text_browser->mapToGlobal(pos));
}

View File

@ -102,6 +102,8 @@ private slots:
void on_requestProgress(qint64 transferred);
void on_text_browser_customContextMenuRequested(const QPoint &pos);
private:
void setErrorMessage(QString const & msg);

View File

@ -11,25 +11,6 @@
#include "kristall.hpp"
//Canonical Types
//0 Text File
//1 Gopher submenu or link to another gopher server
//2 CCSO Nameserver
//3 Error code returned by a Gopher server to indicate failure
//4 BinHex-encoded file (primarily for Macintosh computers)
//5 DOS file
//6 uuencoded file
//7 Gopher full-text search
//8 Telnet
//9 Binary file
//+ Mirror or alternate server (for load balancing or in case of primary server downtime)
//g GIF file
//I Image file
//T Telnet 3270
//Non-Canonical Types
//h HTML file
//i Informational message
//s Sound file
std::unique_ptr<QTextDocument> GophermapRenderer::render(const QByteArray &input, const QUrl &root_url, const DocumentStyle &themed_style)
{
@ -84,6 +65,7 @@ std::unique_ptr<QTextDocument> GophermapRenderer::render(const QByteArray &input
continue;
QString icon;
QString scheme = "gopher";
switch (line.at(0))
{
case '0': // Text File
@ -112,6 +94,7 @@ std::unique_ptr<QTextDocument> GophermapRenderer::render(const QByteArray &input
break;
case '8': // Telnet
icon = "telnet";
scheme = "telnet";
break;
case '9': // Binary file
icon = "binary";
@ -127,6 +110,7 @@ std::unique_ptr<QTextDocument> GophermapRenderer::render(const QByteArray &input
break;
case 'T': // Telnet 3270
icon = "telnet";
scheme = "telnet";
break;
//Non-Canonical Types
case 'h': // HTML file
@ -163,10 +147,10 @@ std::unique_ptr<QTextDocument> GophermapRenderer::render(const QByteArray &input
dst_url = root_url.resolved(QUrl(items.at(1))).toString();
break;
case 3:
dst_url = "gopher://" + items.at(2) + "/" + line.mid(0, 1) + items.at(1);
dst_url = scheme + "://" + items.at(2) + "/" + line.mid(0, 1) + items.at(1);
break;
default:
dst_url = "gopher://" + items.at(2) + ":" + items.at(3) + "/" + line.mid(0, 1) + items.at(1);
dst_url = scheme + "://" + items.at(2) + ":" + items.at(3) + "/" + line.mid(0, 1) + items.at(1);
break;
}

21
src/gophertypes.txt Normal file
View File

@ -0,0 +1,21 @@
Canonical Types
0 Text File
1 Gopher submenu or link to another gopher server
2 CCSO Nameserver
3 Error code returned by a Gopher server to indicate failure
4 BinHex-encoded file (primarily for Macintosh computers)
5 DOS file
6 uuencoded file
7 Gopher full-text search
8 Telnet
9 Binary file
+ Mirror or alternate server (for load balancing or in case of primary server downtime)
g GIF file
I Image file
T Telnet 3270
Non-Canonical Types
h HTML file
i Informational message
s Sound file
d Document file

View File

@ -2,7 +2,9 @@
#define KRISTALL_HPP
#include <QSettings>
#include <QClipboard>
extern QSettings global_settings;
extern QClipboard * global_clipboard;
#endif // KRISTALL_HPP

View File

@ -75,3 +75,6 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
RESOURCES += \
../lib/BreezeStyleSheets/breeze.qrc \
icons.qrc
DISTFILES += \
gophertypes.txt

View File

@ -1,4 +1,5 @@
#include "mainwindow.hpp"
#include "kristall.hpp"
#include <QApplication>
#include <QUrl>
@ -7,11 +8,14 @@
#include <QDebug>
QSettings global_settings { "xqTechnologies", "Kristall" };
QClipboard * global_clipboard;
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
global_clipboard = app.clipboard();
QCommandLineParser cli_parser;
cli_parser.parse(app.arguments());

View File

@ -84,6 +84,9 @@ MainWindow::MainWindow(QApplication * app, QWidget *parent) :
global_settings.endGroup();
}
this->ui->favourites_view->setContextMenuPolicy(Qt::CustomContextMenu);
this->ui->history_view->setContextMenuPolicy(Qt::CustomContextMenu);
reloadTheme();
}
@ -402,3 +405,49 @@ void MainWindow::on_actionHelp_triggered()
{
this->addNewTab(true, QUrl("about:help"));
}
void MainWindow::on_history_view_customContextMenuRequested(const QPoint &pos)
{
if(auto idx = this->ui->history_view->indexAt(pos); idx.isValid()) {
BrowserTab * tab = qobject_cast<BrowserTab*>(this->ui->browser_tabs->currentWidget());
if(tab != nullptr) {
if(QUrl url = tab->history.get(idx); url.isValid()) {
QMenu menu;
connect(menu.addAction("Open here"), &QAction::triggered, [tab, idx]() {
// We do the same thing as a double click here
tab->navigateBack(idx);
});
connect(menu.addAction("Open in new tab"), &QAction::triggered, [this, url]() {
addNewTab(true, url);
});
menu.exec(this->ui->history_view->mapToGlobal(pos));
}
}
}
}
void MainWindow::on_favourites_view_customContextMenuRequested(const QPoint &pos)
{
if(auto idx = this->ui->favourites_view->indexAt(pos); idx.isValid()) {
if(QUrl url = favourites.get(idx); url.isValid()) {
QMenu menu;
BrowserTab * tab = qobject_cast<BrowserTab*>(this->ui->browser_tabs->currentWidget());
if(tab != nullptr) {
connect(menu.addAction("Open here"), &QAction::triggered, [tab, url]() {
tab->navigateTo(url, BrowserTab::PushImmediate);
});
}
connect(menu.addAction("Open in new tab"), &QAction::triggered, [this, url]() {
addNewTab(true, url);
});
menu.exec(this->ui->favourites_view->mapToGlobal(pos));
}
}
}

View File

@ -79,6 +79,10 @@ private slots:
void on_actionHelp_triggered();
void on_history_view_customContextMenuRequested(const QPoint &pos);
void on_favourites_view_customContextMenuRequested(const QPoint &pos);
private:
void reloadTheme();