Moves all globals into a structure that can be deleted before the app exists. Fixes #193.
This commit is contained in:
parent
21c821c49e
commit
0396fdb01d
|
@ -63,7 +63,7 @@ BrowserTab::BrowserTab(MainWindow *mainWindow) : QWidget(nullptr),
|
|||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
this->setUiDensity(kristall::options.ui_density);
|
||||
this->setUiDensity(kristall::globals().options.ui_density);
|
||||
|
||||
addProtocolHandler<GeminiClient>();
|
||||
addProtocolHandler<FingerClient>();
|
||||
|
@ -124,7 +124,7 @@ BrowserTab::BrowserTab(MainWindow *mainWindow) : QWidget(nullptr),
|
|||
FavouritePopup * popup = new FavouritePopup(this->ui->fav_button, this);
|
||||
connect(popup, &FavouritePopup::unfavourited, this, [this]() {
|
||||
this->ui->fav_button->setChecked(false);
|
||||
kristall::favourites.removeUrl(this->current_location);
|
||||
kristall::globals().favourites.removeUrl(this->current_location);
|
||||
});
|
||||
this->ui->fav_button->setPopupMode(QToolButton::DelayedPopup);
|
||||
this->ui->fav_button->setMenu(popup);
|
||||
|
@ -135,7 +135,7 @@ BrowserTab::BrowserTab(MainWindow *mainWindow) : QWidget(nullptr),
|
|||
|
||||
// Update combobox
|
||||
popup->fav_group->clear();
|
||||
QStringList groups = kristall::favourites.groups();
|
||||
QStringList groups = kristall::globals().favourites.groups();
|
||||
for (int i = 0; i < groups.length(); ++i)
|
||||
{
|
||||
popup->fav_group->addItem(groups[i]);
|
||||
|
@ -157,7 +157,7 @@ BrowserTab::BrowserTab(MainWindow *mainWindow) : QWidget(nullptr),
|
|||
if (!popup->is_ready || index == -1) return;
|
||||
|
||||
// Change favourite's current group
|
||||
kristall::favourites.editFavouriteGroup(this->current_location,
|
||||
kristall::globals().favourites.editFavouriteGroup(this->current_location,
|
||||
popup->fav_group->currentText());
|
||||
});
|
||||
|
||||
|
@ -172,7 +172,7 @@ BrowserTab::~BrowserTab()
|
|||
|
||||
void BrowserTab::navigateTo(const QUrl &url, PushToHistory mode, RequestFlags flags)
|
||||
{
|
||||
if (kristall::protocols.isSchemeSupported(url.scheme()) != ProtocolSetup::Enabled)
|
||||
if (kristall::globals().protocols.isSchemeSupported(url.scheme()) != ProtocolSetup::Enabled)
|
||||
{
|
||||
QMessageBox::warning(this, tr("Kristall"), tr("URI scheme not supported or disabled: ") + url.scheme());
|
||||
return;
|
||||
|
@ -185,7 +185,7 @@ void BrowserTab::navigateTo(const QUrl &url, PushToHistory mode, RequestFlags fl
|
|||
}
|
||||
|
||||
// If this page is in cache, store the scroll position
|
||||
if (auto pg = kristall::cache.find(this->current_location); pg != nullptr)
|
||||
if (auto pg = kristall::globals().cache.find(this->current_location); pg != nullptr)
|
||||
{
|
||||
pg->scroll_pos = this->ui->text_browser->verticalScrollBar()->value();
|
||||
}
|
||||
|
@ -339,8 +339,8 @@ void BrowserTab::on_url_bar_returnPressed()
|
|||
else
|
||||
{
|
||||
// Use the text as a search query.
|
||||
if (kristall::options.search_engine.isEmpty() ||
|
||||
!kristall::options.search_engine.contains("%1"))
|
||||
if (kristall::globals().options.search_engine.isEmpty() ||
|
||||
!kristall::globals().options.search_engine.contains("%1"))
|
||||
{
|
||||
QMessageBox::warning(this,
|
||||
tr("Kristall"),
|
||||
|
@ -350,7 +350,7 @@ void BrowserTab::on_url_bar_returnPressed()
|
|||
);
|
||||
return;
|
||||
}
|
||||
url = QUrl{QString(kristall::options.search_engine)
|
||||
url = QUrl{QString(kristall::globals().options.search_engine)
|
||||
.arg(this->ui->url_bar->text())};
|
||||
}
|
||||
}
|
||||
|
@ -615,11 +615,11 @@ void BrowserTab::renderPage(const QByteArray &data, const MimeType &mime)
|
|||
|
||||
this->outline.clear();
|
||||
|
||||
auto doc_style = kristall::document_style.derive(this->current_location);
|
||||
auto doc_style = kristall::globals().document_style.derive(this->current_location);
|
||||
|
||||
this->ui->text_browser->setStyleSheet(QString("QTextBrowser { background-color: %1; color: %2; }").arg(doc_style.background_color.name(), doc_style.standard_color.name()));
|
||||
|
||||
bool plaintext_only = (kristall::options.text_display == GenericSettings::PlainText);
|
||||
bool plaintext_only = (kristall::globals().options.text_display == GenericSettings::PlainText);
|
||||
|
||||
// Only cache text pages
|
||||
bool will_cache = true;
|
||||
|
@ -663,7 +663,7 @@ void BrowserTab::renderPage(const QByteArray &data, const MimeType &mime)
|
|||
else if (not plaintext_only and mime.is("text","x-kristall-theme"))
|
||||
{
|
||||
// ugly workaround for QSettings needing a file
|
||||
QFile temp_file { kristall::dirs::cache_root.absoluteFilePath("preview-theme.kthm") };
|
||||
QFile temp_file { kristall::globals().dirs.cache_root.absoluteFilePath("preview-theme.kthm") };
|
||||
|
||||
if(temp_file.open(QFile::WriteOnly)) {
|
||||
IoUtil::writeAll(temp_file, data);
|
||||
|
@ -820,7 +820,7 @@ void BrowserTab::renderPage(const QByteArray &data, const MimeType &mime)
|
|||
!this->was_read_from_cache &&
|
||||
!this->current_identity.isValid())
|
||||
{
|
||||
kristall::cache.push(this->current_location, data, mime);
|
||||
kristall::globals().cache.push(this->current_location, data, mime);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -908,7 +908,7 @@ void BrowserTab::on_redirected(QUrl uri, bool is_permanent)
|
|||
uri.setHost(current_location.host());
|
||||
}
|
||||
|
||||
if (redirection_count >= kristall::options.max_redirections)
|
||||
if (redirection_count >= kristall::globals().options.max_redirections)
|
||||
{
|
||||
setErrorMessage(QString(tr("Too many consecutive redirections. The last redirection would have redirected you to:\r\n%1")).arg(uri.toString(QUrl::FullyEncoded)));
|
||||
return;
|
||||
|
@ -919,7 +919,7 @@ void BrowserTab::on_redirected(QUrl uri, bool is_permanent)
|
|||
bool is_cross_host = (this->current_location.host() != uri.host());
|
||||
|
||||
QString question;
|
||||
if(kristall::options.redirection_policy == GenericSettings::WarnAlways)
|
||||
if(kristall::globals().options.redirection_policy == GenericSettings::WarnAlways)
|
||||
{
|
||||
question = QString(
|
||||
tr("The location you visited wants to redirect you to another location:\r\n"
|
||||
|
@ -927,7 +927,7 @@ void BrowserTab::on_redirected(QUrl uri, bool is_permanent)
|
|||
"Do you want to allow the redirection?")
|
||||
).arg(uri.toString(QUrl::FullyEncoded));
|
||||
}
|
||||
else if((kristall::options.redirection_policy & (GenericSettings::WarnOnHostChange | GenericSettings::WarnOnSchemeChange)) and is_cross_protocol and is_cross_host)
|
||||
else if((kristall::globals().options.redirection_policy & (GenericSettings::WarnOnHostChange | GenericSettings::WarnOnSchemeChange)) and is_cross_protocol and is_cross_host)
|
||||
{
|
||||
question = QString(
|
||||
tr("The location you visited wants to redirect you to another host and switch the protocol.\r\n"
|
||||
|
@ -936,7 +936,7 @@ void BrowserTab::on_redirected(QUrl uri, bool is_permanent)
|
|||
"Do you want to allow the redirection?")
|
||||
).arg(uri.scheme()).arg(uri.host());
|
||||
}
|
||||
else if((kristall::options.redirection_policy & GenericSettings::WarnOnSchemeChange) and is_cross_protocol)
|
||||
else if((kristall::globals().options.redirection_policy & GenericSettings::WarnOnSchemeChange) and is_cross_protocol)
|
||||
{
|
||||
question = QString(
|
||||
tr("The location you visited wants to switch the protocol.\r\n"
|
||||
|
@ -944,7 +944,7 @@ void BrowserTab::on_redirected(QUrl uri, bool is_permanent)
|
|||
"Do you want to allow the redirection?")
|
||||
).arg(uri.scheme());
|
||||
}
|
||||
else if((kristall::options.redirection_policy & GenericSettings::WarnOnHostChange) and is_cross_host)
|
||||
else if((kristall::globals().options.redirection_policy & GenericSettings::WarnOnHostChange) and is_cross_host)
|
||||
{
|
||||
question = QString(
|
||||
tr("The location you visited wants to redirect you to another host.\r\n"
|
||||
|
@ -999,9 +999,9 @@ void BrowserTab::pushToHistory(const QUrl &url)
|
|||
void BrowserTab::showFavouritesPopup()
|
||||
{
|
||||
// We add it to favourites immediately.
|
||||
kristall::favourites.addUnsorted(this->current_location, this->page_title);
|
||||
kristall::globals().favourites.addUnsorted(this->current_location, this->page_title);
|
||||
|
||||
const Favourite fav = kristall::favourites.getFavourite(this->current_location);
|
||||
const Favourite fav = kristall::globals().favourites.getFavourite(this->current_location);
|
||||
|
||||
this->ui->fav_button->setChecked(true);
|
||||
FavouritePopup *popup = static_cast<FavouritePopup*>(this->ui->fav_button->menu());
|
||||
|
@ -1013,13 +1013,13 @@ void BrowserTab::showFavouritesPopup()
|
|||
// Setup the group combobox
|
||||
popup->fav_group->setCurrentIndex(-1);
|
||||
popup->fav_group->clear();
|
||||
QStringList groups = kristall::favourites.groups();
|
||||
QStringList groups = kristall::globals().favourites.groups();
|
||||
for (int i = 0; i < groups.length(); ++i)
|
||||
{
|
||||
popup->fav_group->addItem(groups[i]);
|
||||
|
||||
// Set combobox index to current group
|
||||
if (groups[i] == kristall::favourites.groupForFavourite(fav.destination))
|
||||
if (groups[i] == kristall::globals().favourites.groupForFavourite(fav.destination))
|
||||
{
|
||||
popup->fav_group->setCurrentIndex(i);
|
||||
}
|
||||
|
@ -1038,7 +1038,7 @@ void BrowserTab::showFavouritesPopup()
|
|||
this->ui->fav_button->showMenu();
|
||||
|
||||
// Update the favourites entry with what user inputted into menu
|
||||
kristall::favourites.editFavouriteTitle(this->current_location, popup->fav_title->text());
|
||||
kristall::globals().favourites.editFavouriteTitle(this->current_location, popup->fav_title->text());
|
||||
}
|
||||
|
||||
void BrowserTab::on_fav_button_clicked()
|
||||
|
@ -1090,10 +1090,10 @@ void BrowserTab::on_text_browser_anchorClicked(const QUrl &url, bool open_in_new
|
|||
}
|
||||
|
||||
if(this->current_location.scheme() == "gemini") {
|
||||
kristall::trust::gemini.addTrust(this->current_location, this->current_server_certificate);
|
||||
kristall::globals().trust.gemini.addTrust(this->current_location, this->current_server_certificate);
|
||||
}
|
||||
else if(this->current_location.scheme() == "https") {
|
||||
kristall::trust::https.addTrust(this->current_location, this->current_server_certificate);
|
||||
kristall::globals().trust.https.addTrust(this->current_location, this->current_server_certificate);
|
||||
}
|
||||
else {
|
||||
assert(false and "missing protocol implementation!");
|
||||
|
@ -1106,7 +1106,7 @@ void BrowserTab::on_text_browser_anchorClicked(const QUrl &url, bool open_in_new
|
|||
if(is_theme_preview)
|
||||
{
|
||||
// ugly workaround for QSettings needing a file
|
||||
QFile temp_file { kristall::dirs::cache_root.absoluteFilePath("preview-theme.kthm") };
|
||||
QFile temp_file { kristall::globals().dirs.cache_root.absoluteFilePath("preview-theme.kthm") };
|
||||
|
||||
if(temp_file.open(QFile::WriteOnly)) {
|
||||
IoUtil::writeAll(temp_file, this->current_buffer);
|
||||
|
@ -1151,9 +1151,9 @@ void BrowserTab::on_text_browser_anchorClicked(const QUrl &url, bool open_in_new
|
|||
{
|
||||
fileName = DocumentStyle::createFileNameFromName(name, index);
|
||||
index += 1;
|
||||
} while(kristall::dirs::styles.exists(fileName));
|
||||
} while(kristall::globals().dirs.styles.exists(fileName));
|
||||
|
||||
QFile target_file { kristall::dirs::styles.absoluteFilePath(fileName) };
|
||||
QFile target_file { kristall::globals().dirs.styles.absoluteFilePath(fileName) };
|
||||
|
||||
if(target_file.open(QFile::WriteOnly)) {
|
||||
IoUtil::writeAll(target_file, this->current_buffer);
|
||||
|
@ -1192,7 +1192,7 @@ void BrowserTab::on_text_browser_anchorClicked(const QUrl &url, bool open_in_new
|
|||
if (real_url.isRelative())
|
||||
real_url = this->current_location.resolved(url);
|
||||
|
||||
auto support = kristall::protocols.isSchemeSupported(real_url.scheme());
|
||||
auto support = kristall::globals().protocols.isSchemeSupported(real_url.scheme());
|
||||
|
||||
if (support == ProtocolSetup::Enabled)
|
||||
{
|
||||
|
@ -1204,7 +1204,7 @@ void BrowserTab::on_text_browser_anchorClicked(const QUrl &url, bool open_in_new
|
|||
}
|
||||
else
|
||||
{
|
||||
if (kristall::options.use_os_scheme_handler)
|
||||
if (kristall::globals().options.use_os_scheme_handler)
|
||||
{
|
||||
if (not QDesktopServices::openUrl(url))
|
||||
{
|
||||
|
@ -1247,7 +1247,7 @@ void BrowserTab::on_stop_button_clicked()
|
|||
|
||||
void BrowserTab::on_home_button_clicked()
|
||||
{
|
||||
this->navigateTo(QUrl(kristall::options.start_page), BrowserTab::PushImmediate);
|
||||
this->navigateTo(QUrl(kristall::globals().options.start_page), BrowserTab::PushImmediate);
|
||||
}
|
||||
|
||||
void BrowserTab::on_requestProgress(qint64 transferred)
|
||||
|
@ -1259,7 +1259,7 @@ void BrowserTab::on_requestProgress(qint64 transferred)
|
|||
emit this->fileLoaded(this->current_stats);
|
||||
|
||||
this->network_timeout_timer.stop();
|
||||
this->network_timeout_timer.start(kristall::options.network_timeout);
|
||||
this->network_timeout_timer.start(kristall::globals().options.network_timeout);
|
||||
}
|
||||
|
||||
void BrowserTab::on_back_button_clicked()
|
||||
|
@ -1288,7 +1288,7 @@ void BrowserTab::updateUI()
|
|||
void BrowserTab::refreshFavButton()
|
||||
{
|
||||
this->ui->fav_button->setEnabled(this->successfully_loaded);
|
||||
this->ui->fav_button->setChecked(kristall::favourites.containsUrl(this->current_location));
|
||||
this->ui->fav_button->setChecked(kristall::globals().favourites.containsUrl(this->current_location));
|
||||
}
|
||||
|
||||
void BrowserTab::setUrlBarText(const QString & text)
|
||||
|
@ -1323,7 +1323,7 @@ void BrowserTab::updateUrlBarStyle()
|
|||
// Set all text to default colour if url bar
|
||||
// is focused, is at an about: location,
|
||||
// or has an invalid URL.
|
||||
if (!kristall::options.fancy_urlbar ||
|
||||
if (!kristall::globals().options.fancy_urlbar ||
|
||||
this->ui->url_bar->hasFocus() ||
|
||||
!url.isValid() ||
|
||||
this->current_location.scheme() == "about")
|
||||
|
@ -1359,7 +1359,7 @@ void BrowserTab::updateUrlBarStyle()
|
|||
// non-authority colour text (grey-ish, determined by theme in kristall:setTheme)
|
||||
// The rest of the text is in default theme foreground colour.
|
||||
QTextCharFormat f;
|
||||
f.setForeground(kristall::options.fancy_urlbar_dim_colour);
|
||||
f.setForeground(kristall::globals().options.fancy_urlbar_dim_colour);
|
||||
|
||||
// Create format range for left-side of URL
|
||||
QTextLayout::FormatRange fr_left;
|
||||
|
@ -1419,9 +1419,9 @@ void BrowserTab::updatePageMargins()
|
|||
|
||||
void BrowserTab::refreshOptionalToolbarItems()
|
||||
{
|
||||
this->ui->home_button->setVisible(kristall::options.enable_home_btn);
|
||||
this->ui->root_button->setVisible(kristall::options.enable_root_btn);
|
||||
this->ui->parent_button->setVisible(kristall::options.enable_parent_btn);
|
||||
this->ui->home_button->setVisible(kristall::globals().options.enable_home_btn);
|
||||
this->ui->root_button->setVisible(kristall::globals().options.enable_root_btn);
|
||||
this->ui->parent_button->setVisible(kristall::globals().options.enable_parent_btn);
|
||||
}
|
||||
|
||||
void BrowserTab::refreshToolbarIcons()
|
||||
|
@ -1431,7 +1431,7 @@ void BrowserTab::refreshToolbarIcons()
|
|||
"dark"
|
||||
};
|
||||
|
||||
QString ico_name = ICO_NAMES[(int)kristall::options.explicit_icon_theme];
|
||||
QString ico_name = ICO_NAMES[(int)kristall::globals().options.explicit_icon_theme];
|
||||
|
||||
// Favourites button icons
|
||||
QIcon ico_fav;
|
||||
|
@ -1566,7 +1566,7 @@ bool BrowserTab::startRequest(const QUrl &url, ProtocolHandler::RequestOptions o
|
|||
}
|
||||
}
|
||||
else if(not this->current_identity.isValid()) {
|
||||
for(auto ident_ptr : kristall::identities.allIdentities())
|
||||
for(auto ident_ptr : kristall::globals().identities.allIdentities())
|
||||
{
|
||||
if(ident_ptr->isAutomaticallyEnabledOn(url)) {
|
||||
|
||||
|
@ -1598,7 +1598,7 @@ bool BrowserTab::startRequest(const QUrl &url, ProtocolHandler::RequestOptions o
|
|||
this->current_location = url;
|
||||
this->setUrlBarText(urlstr);
|
||||
|
||||
this->network_timeout_timer.start(kristall::options.network_timeout);
|
||||
this->network_timeout_timer.start(kristall::globals().options.network_timeout);
|
||||
|
||||
const auto req = [this, &url, &options]()
|
||||
{
|
||||
|
@ -1612,8 +1612,8 @@ bool BrowserTab::startRequest(const QUrl &url, ProtocolHandler::RequestOptions o
|
|||
}
|
||||
|
||||
// Check if we have the page in our cache.
|
||||
kristall::cache.clean();
|
||||
if (auto pg = kristall::cache.find(url); pg != nullptr)
|
||||
kristall::globals().cache.clean();
|
||||
if (auto pg = kristall::globals().cache.find(url); pg != nullptr)
|
||||
{
|
||||
qDebug() << "Reading page from cache";
|
||||
this->was_read_from_cache = true;
|
||||
|
@ -1717,7 +1717,7 @@ void BrowserTab::on_text_browser_customContextMenuRequested(const QPoint pos)
|
|||
});
|
||||
|
||||
connect(menu.addAction(tr("Copy link")), &QAction::triggered, [real_url]() {
|
||||
kristall::clipboard->setText(real_url.toString(QUrl::FullyEncoded));
|
||||
qApp->clipboard()->setText(real_url.toString(QUrl::FullyEncoded));
|
||||
});
|
||||
|
||||
menu.addSeparator();
|
||||
|
|
|
@ -8,14 +8,14 @@ void CacheHandler::push(const QUrl &url, const QByteArray &body, const MimeType
|
|||
{
|
||||
// Skip if this item is above the cached item size threshold
|
||||
int bodysize = body.size();
|
||||
if (bodysize > (kristall::options.cache_threshold * 1024))
|
||||
if (bodysize > (kristall::globals().options.cache_threshold * 1024))
|
||||
{
|
||||
qDebug() << "cache: item exceeds threshold (" << IoUtil::size_human(body.size()) << ")";
|
||||
return;
|
||||
}
|
||||
|
||||
// Pop cached items until we are below the cache limit
|
||||
while ((bodysize + this->size()) > (kristall::options.cache_limit * 1024))
|
||||
while ((bodysize + this->size()) > (kristall::globals().options.cache_limit * 1024))
|
||||
{
|
||||
this->popOldest();
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ int CacheHandler::size()
|
|||
void CacheHandler::clean()
|
||||
{
|
||||
// Don't clean anything if we have unlimited item life.
|
||||
if (kristall::options.cache_unlimited_life) return;
|
||||
if (kristall::globals().options.cache_unlimited_life) return;
|
||||
|
||||
// Find list of keys to delete
|
||||
std::vector<QString> vec;
|
||||
|
@ -86,7 +86,7 @@ void CacheHandler::clean()
|
|||
{
|
||||
// Check if this cache item is expired.
|
||||
if (QDateTime::currentDateTime() > i.second->time_cached
|
||||
.addSecs(kristall::options.cache_life * 60))
|
||||
.addSecs(kristall::globals().options.cache_life * 60))
|
||||
{
|
||||
vec.emplace_back(std::move(i.first));
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ CertificateSelectionDialog::CertificateSelectionDialog(QWidget *parent) :
|
|||
ui->setupUi(this);
|
||||
this->ui->server_request->setVisible(false);
|
||||
|
||||
this->ui->certificates->setModel(&kristall::identities);
|
||||
this->ui->certificates->setModel(&kristall::globals().identities);
|
||||
this->ui->certificates->expandAll();
|
||||
|
||||
connect(this->ui->certificates->selectionModel(), &QItemSelectionModel::currentChanged, this, &CertificateSelectionDialog::on_currentChanged);
|
||||
|
@ -86,7 +86,7 @@ void CertificateSelectionDialog::on_currentChanged(const QModelIndex ¤t, c
|
|||
{
|
||||
Q_UNUSED(current)
|
||||
Q_UNUSED(previous)
|
||||
auto id = kristall::identities.getIdentity(current);
|
||||
auto id = kristall::globals().identities.getIdentity(current);
|
||||
|
||||
this->ui->use_selected_cert->setEnabled(id.isValid());
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ void CertificateSelectionDialog::on_create_new_cert_clicked()
|
|||
return;
|
||||
id.is_persistent = true;
|
||||
|
||||
kristall::identities.addCertificate(
|
||||
kristall::globals().identities.addCertificate(
|
||||
dialog.groupName(),
|
||||
id);
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ void CertificateSelectionDialog::on_create_new_cert_clicked()
|
|||
void CertificateSelectionDialog::on_use_selected_cert_clicked()
|
||||
{
|
||||
auto sel = this->ui->certificates->selectionModel()->currentIndex();
|
||||
this->cryto_identity = kristall::identities.getIdentity(sel);
|
||||
this->cryto_identity = kristall::globals().identities.getIdentity(sel);
|
||||
if(this->cryto_identity.isValid()) {
|
||||
this->accept();
|
||||
} else {
|
||||
|
@ -121,7 +121,7 @@ void CertificateSelectionDialog::on_use_selected_cert_clicked()
|
|||
|
||||
void CertificateSelectionDialog::on_certificates_doubleClicked(const QModelIndex &index)
|
||||
{
|
||||
this->cryto_identity = kristall::identities.getIdentity(index);
|
||||
this->cryto_identity = kristall::globals().identities.getIdentity(index);
|
||||
if(this->cryto_identity.isValid()) {
|
||||
this->accept();
|
||||
} else {
|
||||
|
|
|
@ -19,7 +19,7 @@ NewIdentitiyDialog::NewIdentitiyDialog(QWidget *parent) :
|
|||
ui->expiration_date->setTime(QTime(12, 00));
|
||||
|
||||
ui->group->clear();
|
||||
for(const auto &group_name : kristall::identities.groups())
|
||||
for(const auto &group_name : kristall::globals().identities.groups())
|
||||
{
|
||||
ui->group->addItem(group_name);
|
||||
}
|
||||
|
|
|
@ -52,10 +52,10 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
|
|||
setGeminiStyle(DocumentStyle { });
|
||||
|
||||
this->predefined_styles.clear();
|
||||
for(auto const & fileName : kristall::dirs::styles.entryList())
|
||||
for(auto const & fileName : kristall::globals().dirs.styles.entryList())
|
||||
{
|
||||
QSettings style_sheet {
|
||||
kristall::dirs::styles.absoluteFilePath(fileName),
|
||||
kristall::globals().dirs.styles.absoluteFilePath(fileName),
|
||||
QSettings::IniFormat
|
||||
};
|
||||
|
||||
|
@ -670,7 +670,7 @@ void SettingsDialog::on_preset_load_clicked()
|
|||
|
||||
void SettingsDialog::on_SettingsDialog_accepted()
|
||||
{
|
||||
QStringList files = kristall::dirs::styles.entryList();
|
||||
QStringList files = kristall::globals().dirs.styles.entryList();
|
||||
|
||||
for(auto const & style_name : this->predefined_styles.keys())
|
||||
{
|
||||
|
@ -678,7 +678,7 @@ void SettingsDialog::on_SettingsDialog_accepted()
|
|||
files.removeAll(fileName);
|
||||
|
||||
QSettings style_sheet {
|
||||
kristall::dirs::styles.absoluteFilePath(fileName),
|
||||
kristall::globals().dirs.styles.absoluteFilePath(fileName),
|
||||
QSettings::IniFormat
|
||||
};
|
||||
|
||||
|
@ -690,7 +690,7 @@ void SettingsDialog::on_SettingsDialog_accepted()
|
|||
|
||||
for(auto const & fileName : files)
|
||||
{
|
||||
kristall::dirs::styles.remove(fileName);
|
||||
kristall::globals().dirs.styles.remove(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QFontDatabase>
|
||||
#include <QFontInfo>
|
||||
|
||||
#include <QCryptographicHash>
|
||||
#include <QDebug>
|
||||
|
@ -13,6 +14,20 @@
|
|||
#include <array>
|
||||
#include <cmath>
|
||||
|
||||
DocumentStyle::DefaultFonts::DefaultFonts()
|
||||
{
|
||||
// Initialise default fonts
|
||||
#ifdef Q_OS_WIN32
|
||||
// Windows default fonts are ugly, so we use standard ones.
|
||||
family = "Segoe UI";
|
||||
fixed = "Consolas";
|
||||
#else
|
||||
// *nix
|
||||
regular = QFontDatabase::systemFont(QFontDatabase::GeneralFont).family();
|
||||
fixed = QFontInfo(QFont("monospace")).family();
|
||||
#endif
|
||||
}
|
||||
|
||||
static QString encodeCssFont (const QFont& refFont)
|
||||
{
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -117,7 +132,7 @@ static QString encodeCssFont (const QFont& refFont)
|
|||
return cssFontStr;
|
||||
}
|
||||
|
||||
DocumentStyle::DocumentStyle(bool do_init) : theme(Fixed),
|
||||
DocumentStyle::DocumentStyle() : theme(Fixed),
|
||||
standard_font(),
|
||||
h1_font(),
|
||||
h2_font(),
|
||||
|
@ -153,30 +168,32 @@ DocumentStyle::DocumentStyle(bool do_init) : theme(Fixed),
|
|||
indent_size(15.0),
|
||||
list_symbol(QTextListFormat::ListDisc)
|
||||
{
|
||||
if (do_init) this->initialiseDefaultFonts();
|
||||
this->initialiseDefaultFonts();
|
||||
}
|
||||
|
||||
void DocumentStyle::initialiseDefaultFonts()
|
||||
{
|
||||
preformatted_font.setFamily(kristall::default_font_family_fixed);
|
||||
DefaultFonts default_fonts;
|
||||
|
||||
preformatted_font.setFamily(default_fonts.fixed);
|
||||
preformatted_font.setPointSizeF(12.0);
|
||||
|
||||
standard_font.setFamily(kristall::default_font_family);
|
||||
standard_font.setFamily(default_fonts.regular);
|
||||
standard_font.setPointSizeF(12.0);
|
||||
|
||||
h1_font.setFamily(kristall::default_font_family);
|
||||
h1_font.setFamily(default_fonts.regular);
|
||||
h1_font.setBold(true);
|
||||
h1_font.setPointSizeF(22.0);
|
||||
|
||||
h2_font.setFamily(kristall::default_font_family);
|
||||
h2_font.setFamily(default_fonts.regular);
|
||||
h2_font.setBold(true);
|
||||
h2_font.setPointSizeF(17.0);
|
||||
|
||||
h3_font.setFamily(kristall::default_font_family);
|
||||
h3_font.setFamily(default_fonts.regular);
|
||||
h3_font.setBold(true);
|
||||
h3_font.setPointSizeF(14.0);
|
||||
|
||||
blockquote_font.setFamily(kristall::default_font_family);
|
||||
blockquote_font.setFamily(default_fonts.regular);
|
||||
blockquote_font.setItalic(true);
|
||||
blockquote_font.setPointSizeF(12.0);
|
||||
}
|
||||
|
@ -430,15 +447,17 @@ DocumentStyle DocumentStyle::derive(const QUrl &url) const
|
|||
"JoyPixels",
|
||||
};
|
||||
|
||||
auto const patchup_font = [](QFont & font, bool fixed=false)
|
||||
DefaultFonts default_fonts;
|
||||
|
||||
auto const patchup_font = [&default_fonts](QFont & font, bool fixed=false)
|
||||
{
|
||||
// Set the "fallback" font, just to be absolutely sure.
|
||||
// Note the main purpose of this is to avoid emoji fonts
|
||||
// from taking precedence over text fonts.
|
||||
// (fixes *nix default font issues)
|
||||
emojiFonts[1] = fixed
|
||||
? kristall::default_font_family_fixed
|
||||
: kristall::default_font_family;
|
||||
? default_fonts.fixed
|
||||
: default_fonts.regular;
|
||||
|
||||
// Set the primary font as the preferred font.
|
||||
// We ensure that the font family is available first,
|
||||
|
@ -448,8 +467,8 @@ DocumentStyle DocumentStyle::derive(const QUrl &url) const
|
|||
if (!db.families().contains(font.family()))
|
||||
{
|
||||
emojiFonts.front() = fixed
|
||||
? kristall::default_font_family_fixed
|
||||
: kristall::default_font_family;
|
||||
? default_fonts.fixed
|
||||
: default_fonts.regular;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -458,7 +477,7 @@ DocumentStyle DocumentStyle::derive(const QUrl &url) const
|
|||
|
||||
// Set emoji fonts if supported and enabled.
|
||||
if (kristall::EMOJIS_SUPPORTED &&
|
||||
kristall::options.emojis_enabled)
|
||||
kristall::globals().options.emojis_enabled)
|
||||
{
|
||||
// Redundant check to make compiler happy...
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
|
||||
|
|
|
@ -15,7 +15,14 @@ struct DocumentStyle
|
|||
AutoLightTheme = 2
|
||||
};
|
||||
|
||||
DocumentStyle(bool do_init = true);
|
||||
struct DefaultFonts
|
||||
{
|
||||
QString regular, fixed;
|
||||
|
||||
DefaultFonts();
|
||||
};
|
||||
|
||||
DocumentStyle();
|
||||
|
||||
void initialiseDefaultFonts();
|
||||
|
||||
|
|
|
@ -39,6 +39,17 @@ FavouriteCollection::FavouriteCollection(const FavouriteCollection &other)
|
|||
relayout();
|
||||
}
|
||||
|
||||
FavouriteCollection::FavouriteCollection(FavouriteCollection &&other)
|
||||
{
|
||||
this->root.children = std::move(other.root.children);
|
||||
}
|
||||
|
||||
|
||||
FavouriteCollection::~FavouriteCollection()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
FavouriteCollection &FavouriteCollection::operator=(const FavouriteCollection & other)
|
||||
{
|
||||
beginResetModel();
|
||||
|
|
|
@ -34,6 +34,8 @@ class FavouriteCollection : public QAbstractItemModel
|
|||
std::vector<std::unique_ptr<Node>> children;
|
||||
Type type;
|
||||
explicit Node(Type t) : type(t) { }
|
||||
Node(Node const &) = delete;
|
||||
Node(Node &&) = delete;
|
||||
virtual ~Node() = default;
|
||||
|
||||
template<typename T>
|
||||
|
@ -46,17 +48,23 @@ class FavouriteCollection : public QAbstractItemModel
|
|||
struct FavouriteNode : Node {
|
||||
::Favourite favourite;
|
||||
FavouriteNode() : Node(Favourite) { }
|
||||
FavouriteNode(FavouriteNode const &) = delete;
|
||||
FavouriteNode(FavouriteNode &&) = delete;
|
||||
~FavouriteNode() override = default;
|
||||
};
|
||||
|
||||
struct GroupNode : Node {
|
||||
QString title;
|
||||
GroupNode() : Node(Group) { }
|
||||
GroupNode(GroupNode const &) = delete;
|
||||
GroupNode(GroupNode &&) = delete;
|
||||
~GroupNode() override = default;
|
||||
};
|
||||
|
||||
struct RootNode : Node {
|
||||
RootNode() : Node(Root) { }
|
||||
RootNode(RootNode const &) = delete;
|
||||
RootNode(RootNode &&) = delete;
|
||||
~RootNode() override = default;
|
||||
};
|
||||
|
||||
|
@ -65,6 +73,10 @@ public:
|
|||
|
||||
FavouriteCollection(FavouriteCollection const & other);
|
||||
|
||||
FavouriteCollection(FavouriteCollection && other);
|
||||
|
||||
~FavouriteCollection();
|
||||
|
||||
FavouriteCollection & operator=(FavouriteCollection const &);
|
||||
FavouriteCollection & operator=(FavouriteCollection &&);
|
||||
|
||||
|
|
|
@ -117,36 +117,53 @@ class MainWindow;
|
|||
///
|
||||
namespace kristall
|
||||
{
|
||||
extern ProtocolSetup protocols;
|
||||
//! Whether emojis are supprted in current build configuration
|
||||
extern const bool EMOJIS_SUPPORTED;
|
||||
|
||||
extern QSettings * settings;
|
||||
extern IdentityCollection identities;
|
||||
extern QClipboard * clipboard;
|
||||
extern FavouriteCollection favourites;
|
||||
extern GenericSettings options;
|
||||
struct Trust
|
||||
{
|
||||
SslTrust gemini;
|
||||
SslTrust https;
|
||||
};
|
||||
|
||||
extern DocumentStyle document_style;
|
||||
struct Dirs
|
||||
{
|
||||
|
||||
extern CacheHandler cache;
|
||||
|
||||
namespace trust {
|
||||
extern SslTrust gemini;
|
||||
extern SslTrust https;
|
||||
}
|
||||
|
||||
namespace dirs {
|
||||
extern QDir config_root;
|
||||
extern QDir cache_root;
|
||||
QDir config_root;
|
||||
QDir cache_root;
|
||||
|
||||
//! Contains files per host
|
||||
extern QDir offline_pages;
|
||||
QDir offline_pages;
|
||||
|
||||
//! Contains custom UI themes for kristall
|
||||
extern QDir themes;
|
||||
QDir themes;
|
||||
|
||||
//! Contains custom document styles / presets
|
||||
extern QDir styles;
|
||||
}
|
||||
QDir styles;
|
||||
};
|
||||
|
||||
struct Globals
|
||||
{
|
||||
|
||||
ProtocolSetup protocols;
|
||||
|
||||
QSettings * settings;
|
||||
IdentityCollection identities;
|
||||
QClipboard * clipboard;
|
||||
FavouriteCollection favourites;
|
||||
GenericSettings options;
|
||||
|
||||
DocumentStyle document_style;
|
||||
|
||||
CacheHandler cache;
|
||||
|
||||
Trust trust;
|
||||
|
||||
Dirs dirs;
|
||||
};
|
||||
|
||||
//! returns the instance of the globals structure
|
||||
Globals & globals();
|
||||
|
||||
//! Forwards the current settings to all windows
|
||||
void applySettings();
|
||||
|
@ -176,11 +193,6 @@ namespace kristall
|
|||
//! Opens a new window with the given list of urls.
|
||||
//! If the list is empty, no new tab will spawned.
|
||||
MainWindow * openNewWindow(QVector<QUrl> const & urls);
|
||||
|
||||
extern QString default_font_family, default_font_family_fixed;
|
||||
|
||||
//! Whether emojis are supprted in current build configuration
|
||||
extern const bool EMOJIS_SUPPORTED;
|
||||
}
|
||||
|
||||
#endif // KRISTALL_HPP
|
||||
|
|
122
src/main.cpp
122
src/main.cpp
|
@ -14,24 +14,21 @@
|
|||
#include <QLibraryInfo>
|
||||
#include <cassert>
|
||||
|
||||
ProtocolSetup kristall::protocols;
|
||||
IdentityCollection kristall::identities;
|
||||
QSettings * kristall::settings;
|
||||
QClipboard * kristall::clipboard;
|
||||
SslTrust kristall::trust::gemini;
|
||||
SslTrust kristall::trust::https;
|
||||
FavouriteCollection kristall::favourites;
|
||||
GenericSettings kristall::options;
|
||||
DocumentStyle kristall::document_style(false);
|
||||
CacheHandler kristall::cache;
|
||||
QString kristall::default_font_family;
|
||||
QString kristall::default_font_family_fixed;
|
||||
static std::unique_ptr<kristall::Globals> main_globals;
|
||||
|
||||
QDir kristall::dirs::config_root;
|
||||
QDir kristall::dirs::cache_root;
|
||||
QDir kristall::dirs::offline_pages;
|
||||
QDir kristall::dirs::themes;
|
||||
QDir kristall::dirs::styles;
|
||||
struct EnsureGlobalsReset
|
||||
{
|
||||
~EnsureGlobalsReset()
|
||||
{
|
||||
main_globals.reset();
|
||||
}
|
||||
};
|
||||
|
||||
kristall::Globals & kristall::globals()
|
||||
{
|
||||
assert(main_globals != nullptr);
|
||||
return *main_globals;
|
||||
}
|
||||
|
||||
// We need QFont::setFamilies for emojis to work properly,
|
||||
// Qt versions below 5.13 don't support this.
|
||||
|
@ -364,6 +361,11 @@ int main(int argc, char *argv[])
|
|||
QApplication app(argc, argv);
|
||||
app.setApplicationVersion(SSTR(KRISTALL_VERSION));
|
||||
|
||||
main_globals = std::make_unique<kristall::Globals>( );
|
||||
|
||||
// this is relevant to delete kristall::Globals before the application itself.
|
||||
EnsureGlobalsReset ensure_globals_reset;
|
||||
|
||||
QObject::connect(&app, &QApplication::focusChanged, [](QWidget *old, QWidget *now) {
|
||||
// Determine the window for both, we're only interested in window focus changes.
|
||||
if(old != nullptr) old = old->window();
|
||||
|
@ -392,22 +394,6 @@ int main(int argc, char *argv[])
|
|||
app.installTranslator(&qttrans);
|
||||
app.installTranslator(&trans);
|
||||
|
||||
{
|
||||
// Initialise default fonts
|
||||
#ifdef Q_OS_WIN32
|
||||
// Windows default fonts are ugly, so we use standard ones.
|
||||
kristall::default_font_family = "Segoe UI";
|
||||
kristall::default_font_family_fixed = "Consolas";
|
||||
#else
|
||||
// *nix
|
||||
kristall::default_font_family = QFontDatabase::systemFont(QFontDatabase::GeneralFont).family();
|
||||
kristall::default_font_family_fixed = QFontInfo(QFont("monospace")).family();
|
||||
#endif
|
||||
kristall::document_style.initialiseDefaultFonts();
|
||||
}
|
||||
|
||||
kristall::clipboard = app.clipboard();
|
||||
|
||||
addEmojiSubstitutions();
|
||||
|
||||
QCommandLineParser cli_parser;
|
||||
|
@ -503,18 +489,18 @@ int main(int argc, char *argv[])
|
|||
QString cache_root = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
|
||||
QString config_root = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
|
||||
|
||||
kristall::dirs::config_root = QDir { config_root };
|
||||
kristall::dirs::cache_root = QDir { cache_root };
|
||||
kristall::globals().dirs.config_root = QDir { config_root };
|
||||
kristall::globals().dirs.cache_root = QDir { cache_root };
|
||||
|
||||
kristall::dirs::offline_pages = derive_dir(kristall::dirs::cache_root, "offline-pages");
|
||||
kristall::dirs::themes = derive_dir(kristall::dirs::config_root, "themes");
|
||||
kristall::globals().dirs.offline_pages = derive_dir(kristall::globals().dirs.cache_root, "offline-pages");
|
||||
kristall::globals().dirs.themes = derive_dir(kristall::globals().dirs.config_root, "themes");
|
||||
|
||||
kristall::dirs::styles = derive_dir(kristall::dirs::config_root, "styles");
|
||||
kristall::dirs::styles.setNameFilters(QStringList { "*.kthm" });
|
||||
kristall::dirs::styles.setFilter(QDir::Files);
|
||||
kristall::globals().dirs.styles = derive_dir(kristall::globals().dirs.config_root, "styles");
|
||||
kristall::globals().dirs.styles.setNameFilters(QStringList { "*.kthm" });
|
||||
kristall::globals().dirs.styles.setFilter(QDir::Files);
|
||||
|
||||
QSettings app_settings {
|
||||
kristall::dirs::config_root.absoluteFilePath("config.ini"),
|
||||
kristall::globals().dirs.config_root.absoluteFilePath("config.ini"),
|
||||
QSettings::IniFormat
|
||||
};
|
||||
app_settings_ptr = &app_settings;
|
||||
|
@ -549,10 +535,10 @@ int main(int argc, char *argv[])
|
|||
do {
|
||||
fileName = DocumentStyle::createFileNameFromName(name, index);
|
||||
index += 1;
|
||||
} while(kristall::dirs::styles.exists(fileName));
|
||||
} while(kristall::globals().dirs.styles.exists(fileName));
|
||||
|
||||
QSettings style_sheet {
|
||||
kristall::dirs::styles.absoluteFilePath(fileName),
|
||||
kristall::globals().dirs.styles.absoluteFilePath(fileName),
|
||||
QSettings::IniFormat
|
||||
};
|
||||
style_sheet.setValue("name", name);
|
||||
|
@ -637,35 +623,35 @@ int main(int argc, char *argv[])
|
|||
app_settings.endArray();
|
||||
}
|
||||
|
||||
kristall::settings = &app_settings;
|
||||
kristall::globals().settings = &app_settings;
|
||||
|
||||
kristall::options.load(app_settings);
|
||||
kristall::globals().options.load(app_settings);
|
||||
|
||||
app_settings.beginGroup("Protocols");
|
||||
kristall::protocols.load(app_settings);
|
||||
kristall::globals().protocols.load(app_settings);
|
||||
app_settings.endGroup();
|
||||
|
||||
app_settings.beginGroup("Client Identities");
|
||||
kristall::identities.load(app_settings);
|
||||
kristall::globals().identities.load(app_settings);
|
||||
app_settings.endGroup();
|
||||
|
||||
app_settings.beginGroup("Trusted Servers");
|
||||
kristall::trust::gemini.load(app_settings);
|
||||
kristall::globals().trust.gemini.load(app_settings);
|
||||
app_settings.endGroup();
|
||||
|
||||
app_settings.beginGroup("Trusted HTTPS Servers");
|
||||
kristall::trust::https.load(app_settings);
|
||||
kristall::globals().trust.https.load(app_settings);
|
||||
app_settings.endGroup();
|
||||
|
||||
app_settings.beginGroup("Theme");
|
||||
kristall::document_style.load(app_settings);
|
||||
kristall::globals().document_style.load(app_settings);
|
||||
app_settings.endGroup();
|
||||
|
||||
app_settings.beginGroup("Favourites");
|
||||
kristall::favourites.load(app_settings);
|
||||
kristall::globals().favourites.load(app_settings);
|
||||
app_settings.endGroup();
|
||||
|
||||
kristall::setTheme(kristall::options.theme);
|
||||
kristall::setTheme(kristall::globals().options.theme);
|
||||
|
||||
if(ipc_server != nullptr) {
|
||||
QObject::connect(ipc_server.get(), &QLocalServer::newConnection, [&ipc_server]() {
|
||||
|
@ -830,8 +816,8 @@ void GenericSettings::save(QSettings &settings) const
|
|||
|
||||
void kristall::applySettings()
|
||||
{
|
||||
kristall::setTheme(kristall::options.theme);
|
||||
kristall::setUiDensity(kristall::options.ui_density, false);
|
||||
kristall::setTheme(kristall::globals().options.theme);
|
||||
kristall::setUiDensity(kristall::globals().options.ui_density, false);
|
||||
|
||||
forAllAppWindows([](MainWindow * window)
|
||||
{
|
||||
|
@ -845,30 +831,30 @@ void kristall::saveSettings()
|
|||
QSettings & app_settings = *app_settings_ptr;
|
||||
|
||||
app_settings.beginGroup("Favourites");
|
||||
kristall::favourites.save(app_settings);
|
||||
kristall::globals().favourites.save(app_settings);
|
||||
app_settings.endGroup();
|
||||
|
||||
app_settings.beginGroup("Protocols");
|
||||
kristall::protocols.save(app_settings);
|
||||
kristall::globals().protocols.save(app_settings);
|
||||
app_settings.endGroup();
|
||||
|
||||
app_settings.beginGroup("Client Identities");
|
||||
kristall::identities.save(app_settings);
|
||||
kristall::globals().identities.save(app_settings);
|
||||
app_settings.endGroup();
|
||||
|
||||
app_settings.beginGroup("Trusted Servers");
|
||||
kristall::trust::gemini.save(app_settings);
|
||||
kristall::globals().trust.gemini.save(app_settings);
|
||||
app_settings.endGroup();
|
||||
|
||||
app_settings.beginGroup("Trusted HTTPS Servers");
|
||||
kristall::trust::https.save(app_settings);
|
||||
kristall::globals().trust.https.save(app_settings);
|
||||
app_settings.endGroup();
|
||||
|
||||
app_settings.beginGroup("Theme");
|
||||
kristall::document_style.save(app_settings);
|
||||
kristall::globals().document_style.save(app_settings);
|
||||
app_settings.endGroup();
|
||||
|
||||
kristall::options.save(app_settings);
|
||||
kristall::globals().options.save(app_settings);
|
||||
|
||||
app_settings.sync();
|
||||
}
|
||||
|
@ -884,7 +870,7 @@ void kristall::setTheme(Theme theme)
|
|||
// Use "mid" colour for our URL bar dim colour:
|
||||
QColor col = qApp->palette().color(QPalette::WindowText);
|
||||
col.setAlpha(150);
|
||||
kristall::options.fancy_urlbar_dim_colour = std::move(col);
|
||||
kristall::globals().options.fancy_urlbar_dim_colour = std::move(col);
|
||||
}
|
||||
else if(theme == Theme::light)
|
||||
{
|
||||
|
@ -893,7 +879,7 @@ void kristall::setTheme(Theme theme)
|
|||
QTextStream stream(&file);
|
||||
qApp->setStyleSheet(stream.readAll());
|
||||
|
||||
kristall::options.fancy_urlbar_dim_colour = QColor(128, 128, 128, 255);
|
||||
kristall::globals().options.fancy_urlbar_dim_colour = QColor(128, 128, 128, 255);
|
||||
}
|
||||
else if(theme == Theme::dark)
|
||||
{
|
||||
|
@ -902,10 +888,10 @@ void kristall::setTheme(Theme theme)
|
|||
QTextStream stream(&file);
|
||||
qApp->setStyleSheet(stream.readAll());
|
||||
|
||||
kristall::options.fancy_urlbar_dim_colour = QColor(150, 150, 150, 255);
|
||||
kristall::globals().options.fancy_urlbar_dim_colour = QColor(150, 150, 150, 255);
|
||||
}
|
||||
|
||||
kristall::setIconTheme(kristall::options.icon_theme, theme);
|
||||
kristall::setIconTheme(kristall::globals().options.icon_theme, theme);
|
||||
|
||||
forAllAppWindows([](MainWindow * main_window) {
|
||||
if (main_window && main_window->curTab())
|
||||
|
@ -941,7 +927,7 @@ void kristall::setIconTheme(IconTheme icotheme, Theme uitheme)
|
|||
QIcon::setThemeName("");
|
||||
#endif
|
||||
|
||||
kristall::options.explicit_icon_theme = IconTheme::dark;
|
||||
kristall::globals().options.explicit_icon_theme = IconTheme::dark;
|
||||
|
||||
ret();
|
||||
return;
|
||||
|
@ -949,14 +935,14 @@ void kristall::setIconTheme(IconTheme icotheme, Theme uitheme)
|
|||
|
||||
// Use icon theme based on UI theme
|
||||
QIcon::setThemeName(icothemes[(int)uitheme]);
|
||||
kristall::options.explicit_icon_theme = (IconTheme)uitheme;
|
||||
kristall::globals().options.explicit_icon_theme = (IconTheme)uitheme;
|
||||
ret();
|
||||
return;
|
||||
}
|
||||
|
||||
// Use icon specified by user
|
||||
QIcon::setThemeName(icothemes[(int)icotheme]);
|
||||
kristall::options.explicit_icon_theme = (IconTheme)icotheme;
|
||||
kristall::globals().options.explicit_icon_theme = (IconTheme)icotheme;
|
||||
ret();
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ MainWindow::MainWindow(QApplication * app, QWidget *parent) :
|
|||
this->statusBar()->addPermanentWidget(this->file_size);
|
||||
this->statusBar()->addPermanentWidget(this->load_time);
|
||||
|
||||
ui->favourites_view->setModel(&kristall::favourites);
|
||||
ui->favourites_view->setModel(&kristall::globals().favourites);
|
||||
|
||||
this->ui->outline_window->setVisible(false);
|
||||
this->ui->history_window->setVisible(false);
|
||||
|
@ -56,7 +56,7 @@ MainWindow::MainWindow(QApplication * app, QWidget *parent) :
|
|||
connect(this->ui->menuNavigation, &QMenu::aboutToShow, [this]() {
|
||||
BrowserTab * tab = this->curTab();
|
||||
if(tab != nullptr) {
|
||||
ui->actionAdd_to_favourites->setChecked(kristall::favourites.containsUrl(tab->current_location));
|
||||
ui->actionAdd_to_favourites->setChecked(kristall::globals().favourites.containsUrl(tab->current_location));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -149,7 +149,7 @@ BrowserTab * MainWindow::addEmptyTab(bool focus_new, bool load_default)
|
|||
}
|
||||
|
||||
if(load_default) {
|
||||
tab->navigateTo(QUrl(kristall::options.start_page), BrowserTab::PushImmediate);
|
||||
tab->navigateTo(QUrl(kristall::globals().options.start_page), BrowserTab::PushImmediate);
|
||||
tab->focusUrlBar();
|
||||
} else {
|
||||
tab->navigateTo(QUrl("about:blank"), BrowserTab::DontPush);
|
||||
|
@ -274,7 +274,7 @@ QString MainWindow::newGroupDialog()
|
|||
if(dialog.exec() != QDialog::Accepted)
|
||||
return QString { };
|
||||
|
||||
kristall::favourites.addGroup(dialog.textValue());
|
||||
kristall::globals().favourites.addGroup(dialog.textValue());
|
||||
|
||||
return dialog.textValue();
|
||||
}
|
||||
|
@ -297,7 +297,7 @@ void MainWindow::applySettings()
|
|||
tab->rerenderPage();
|
||||
|
||||
// Update new-tab button visibility.
|
||||
this->ui->browser_tabs->tab_bar->new_tab_btn->setVisible(kristall::options.enable_newtab_btn);
|
||||
this->ui->browser_tabs->tab_bar->new_tab_btn->setVisible(kristall::globals().options.enable_newtab_btn);
|
||||
}
|
||||
|
||||
void MainWindow::mousePressEvent(QMouseEvent *event)
|
||||
|
@ -427,24 +427,24 @@ void MainWindow::on_actionSettings_triggered()
|
|||
{
|
||||
SettingsDialog dialog;
|
||||
|
||||
dialog.setGeminiStyle(kristall::document_style);
|
||||
dialog.setProtocols(kristall::protocols);
|
||||
dialog.setOptions(kristall::options);
|
||||
dialog.setGeminiSslTrust(kristall::trust::gemini);
|
||||
dialog.setHttpsSslTrust(kristall::trust::https);
|
||||
dialog.setGeminiStyle(kristall::globals().document_style);
|
||||
dialog.setProtocols(kristall::globals().protocols);
|
||||
dialog.setOptions(kristall::globals().options);
|
||||
dialog.setGeminiSslTrust(kristall::globals().trust.gemini);
|
||||
dialog.setHttpsSslTrust(kristall::globals().trust.https);
|
||||
|
||||
if(dialog.exec() != QDialog::Accepted) {
|
||||
kristall::setTheme(kristall::options.theme);
|
||||
this->setUiDensity(kristall::options.ui_density, false);
|
||||
kristall::setTheme(kristall::globals().options.theme);
|
||||
this->setUiDensity(kristall::globals().options.ui_density, false);
|
||||
return;
|
||||
}
|
||||
|
||||
kristall::trust::gemini = dialog.geminiSslTrust();
|
||||
kristall::trust::https = dialog.httpsSslTrust();
|
||||
kristall::options = dialog.options();
|
||||
kristall::globals().trust.gemini = dialog.geminiSslTrust();
|
||||
kristall::globals().trust.https = dialog.httpsSslTrust();
|
||||
kristall::globals().options = dialog.options();
|
||||
|
||||
kristall::protocols = dialog.protocols();
|
||||
kristall::document_style = dialog.geminiStyle();
|
||||
kristall::globals().protocols = dialog.protocols();
|
||||
kristall::globals().document_style = dialog.geminiStyle();
|
||||
|
||||
kristall::applySettings();
|
||||
|
||||
|
@ -571,7 +571,7 @@ void MainWindow::on_actionGo_to_home_triggered()
|
|||
{
|
||||
BrowserTab * tab = this->curTab();
|
||||
if(tab != nullptr) {
|
||||
tab->navigateTo(QUrl(kristall::options.start_page), BrowserTab::PushImmediate);
|
||||
tab->navigateTo(QUrl(kristall::globals().options.start_page), BrowserTab::PushImmediate);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -647,7 +647,7 @@ void MainWindow::on_history_view_customContextMenuRequested(const QPoint pos)
|
|||
void MainWindow::on_favourites_view_customContextMenuRequested(const QPoint pos)
|
||||
{
|
||||
if(auto idx = this->ui->favourites_view->indexAt(pos); idx.isValid()) {
|
||||
if(QUrl url = kristall::favourites.getFavourite(idx).destination; url.isValid()) {
|
||||
if(QUrl url = kristall::globals().favourites.getFavourite(idx).destination; url.isValid()) {
|
||||
QMenu menu;
|
||||
|
||||
BrowserTab * tab = this->curTab();
|
||||
|
@ -668,12 +668,12 @@ void MainWindow::on_favourites_view_customContextMenuRequested(const QPoint pos)
|
|||
|
||||
dialog.setInputMode(QInputDialog::TextInput);
|
||||
dialog.setLabelText(tr("Enter new location of this favourite:"));
|
||||
dialog.setTextValue(kristall::favourites.getFavourite(idx).destination.toString(QUrl::FullyEncoded));
|
||||
dialog.setTextValue(kristall::globals().favourites.getFavourite(idx).destination.toString(QUrl::FullyEncoded));
|
||||
|
||||
if (dialog.exec() != QDialog::Accepted)
|
||||
return;
|
||||
|
||||
kristall::favourites.editFavouriteDest(idx, QUrl(dialog.textValue()));
|
||||
kristall::globals().favourites.editFavouriteDest(idx, QUrl(dialog.textValue()));
|
||||
});
|
||||
|
||||
connect(menu.addAction(tr("Rename")), &QAction::triggered, [this, idx]() {
|
||||
|
@ -681,23 +681,23 @@ void MainWindow::on_favourites_view_customContextMenuRequested(const QPoint pos)
|
|||
|
||||
dialog.setInputMode(QInputDialog::TextInput);
|
||||
dialog.setLabelText(tr("New name of this favourite:"));
|
||||
dialog.setTextValue(kristall::favourites.getFavourite(idx).getTitle());
|
||||
dialog.setTextValue(kristall::globals().favourites.getFavourite(idx).getTitle());
|
||||
|
||||
if (dialog.exec() != QDialog::Accepted)
|
||||
return;
|
||||
|
||||
kristall::favourites.editFavouriteTitle(idx, dialog.textValue());
|
||||
kristall::globals().favourites.editFavouriteTitle(idx, dialog.textValue());
|
||||
});
|
||||
|
||||
menu.addSeparator();
|
||||
|
||||
connect(menu.addAction(tr("Delete")), &QAction::triggered, [idx]() {
|
||||
kristall::favourites.destroyFavourite(idx);
|
||||
kristall::globals().favourites.destroyFavourite(idx);
|
||||
});
|
||||
|
||||
menu.exec(this->ui->favourites_view->mapToGlobal(pos));
|
||||
}
|
||||
else if(QString group = kristall::favourites.group(idx); not group.isEmpty()) {
|
||||
else if(QString group = kristall::globals().favourites.group(idx); not group.isEmpty()) {
|
||||
QMenu menu;
|
||||
|
||||
connect(menu.addAction(tr("Rename group")), &QAction::triggered, [this, group]() {
|
||||
|
@ -710,7 +710,7 @@ void MainWindow::on_favourites_view_customContextMenuRequested(const QPoint pos)
|
|||
if (dialog.exec() != QDialog::Accepted)
|
||||
return;
|
||||
|
||||
if (!kristall::favourites.renameGroup(group, dialog.textValue()))
|
||||
if (!kristall::globals().favourites.renameGroup(group, dialog.textValue()))
|
||||
QMessageBox::information(this, tr("Kristall"), tr("Rename failed: group name already in use."));
|
||||
});
|
||||
|
||||
|
@ -727,7 +727,7 @@ void MainWindow::on_favourites_view_customContextMenuRequested(const QPoint pos)
|
|||
{
|
||||
return;
|
||||
}
|
||||
kristall::favourites.deleteGroupRecursive(kristall::favourites.group(idx));
|
||||
kristall::globals().favourites.deleteGroupRecursive(kristall::globals().favourites.group(idx));
|
||||
});
|
||||
|
||||
menu.exec(this->ui->favourites_view->mapToGlobal(pos));
|
||||
|
@ -753,11 +753,11 @@ void MainWindow::on_actionManage_Certificates_triggered()
|
|||
{
|
||||
CertificateManagementDialog dialog { this };
|
||||
|
||||
dialog.setIdentitySet(kristall::identities);
|
||||
dialog.setIdentitySet(kristall::globals().identities);
|
||||
if(dialog.exec() != QDialog::Accepted)
|
||||
return;
|
||||
|
||||
kristall::identities = dialog.identitySet();
|
||||
kristall::globals().identities = dialog.identitySet();
|
||||
|
||||
kristall::saveSettings();
|
||||
}
|
||||
|
@ -779,7 +779,7 @@ void MainWindow::on_actionClose_Window_triggered()
|
|||
|
||||
void MainWindow::on_favourites_view_activated(const QModelIndex &index)
|
||||
{
|
||||
if(auto url = kristall::favourites.getFavourite(index).destination; url.isValid()) {
|
||||
if(auto url = kristall::globals().favourites.getFavourite(index).destination; url.isValid()) {
|
||||
this->addNewTab(true, url);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ bool AboutHandler::startRequest(const QUrl &url, ProtocolHandler::RequestOptions
|
|||
|
||||
QString current_group;
|
||||
|
||||
for (auto const &fav : kristall::favourites.allFavourites())
|
||||
for (auto const &fav : kristall::globals().favourites.allFavourites())
|
||||
{
|
||||
if(current_group != fav.first) {
|
||||
|
||||
|
@ -54,7 +54,7 @@ bool AboutHandler::startRequest(const QUrl &url, ProtocolHandler::RequestOptions
|
|||
QByteArray document;
|
||||
document.append("# Cache information\n");
|
||||
|
||||
auto& cache = kristall::cache.getPages();
|
||||
auto& cache = kristall::globals().cache.getPages();
|
||||
long unsigned cache_usage = 0;
|
||||
int cached_count = 0;
|
||||
for (auto it = cache.begin(); it != cache.end(); ++it, ++cached_count)
|
||||
|
|
|
@ -38,7 +38,7 @@ bool FileHandler::startRequest(const QUrl &url, RequestOptions options)
|
|||
page += QString("# Index of %1\n").arg(url.path());
|
||||
|
||||
auto filters = QDir::Dirs | QDir::Files | QDir::NoDot;
|
||||
if (kristall::options.show_hidden_files_in_dirs) filters |= QDir::Hidden;
|
||||
if (kristall::globals().options.show_hidden_files_in_dirs) filters |= QDir::Hidden;
|
||||
dir.setFilter(filters);
|
||||
|
||||
// Iterate over files in the directory, and add links to each.
|
||||
|
|
|
@ -65,7 +65,7 @@ bool GeminiClient::startRequest(const QUrl &url, RequestOptions options)
|
|||
|
||||
QSslConfiguration ssl_config = socket.sslConfiguration();
|
||||
ssl_config.setProtocol(QSsl::TlsV1_2);
|
||||
if(not kristall::trust::gemini.enable_ca)
|
||||
if(not kristall::globals().trust.gemini.enable_ca)
|
||||
ssl_config.setCaCertificates(QList<QSslCertificate> { });
|
||||
else
|
||||
ssl_config.setCaCertificates(QSslConfiguration::systemCaCertificates());
|
||||
|
@ -341,7 +341,7 @@ void GeminiClient::sslErrors(QList<QSslError> const & errors)
|
|||
bool ignore = false;
|
||||
if(SslTrust::isTrustRelated(err.error()))
|
||||
{
|
||||
switch(kristall::trust::gemini.getTrust(target_url, socket.peerCertificate()))
|
||||
switch(kristall::globals().trust.gemini.getTrust(target_url, socket.peerCertificate()))
|
||||
{
|
||||
case SslTrust::Trusted:
|
||||
ignore = true;
|
||||
|
|
|
@ -40,7 +40,7 @@ bool WebClient::startRequest(const QUrl &url, RequestOptions options)
|
|||
|
||||
auto ssl_config = request.sslConfiguration();
|
||||
// ssl_config.setProtocol(QSsl::TlsV1_2);
|
||||
if(kristall::trust::https.enable_ca)
|
||||
if(kristall::globals().trust.https.enable_ca)
|
||||
ssl_config.setCaCertificates(QSslConfiguration::systemCaCertificates());
|
||||
else
|
||||
ssl_config.setCaCertificates(QList<QSslCertificate> { });
|
||||
|
@ -188,7 +188,7 @@ void WebClient::on_sslErrors(const QList<QSslError> &errors)
|
|||
if(SslTrust::isTrustRelated(err.error()))
|
||||
{
|
||||
auto cert = this->current_reply->sslConfiguration().peerCertificate();
|
||||
switch(kristall::trust::https.getTrust(this->current_reply->url(), cert))
|
||||
switch(kristall::globals().trust.https.getTrust(this->current_reply->url(), cert))
|
||||
{
|
||||
case SslTrust::Trusted:
|
||||
ignore = true;
|
||||
|
|
|
@ -43,7 +43,7 @@ std::unique_ptr<GeminiDocument> GeminiRenderer::render(
|
|||
renderhelpers::setPageMargins(result.get(), themed_style.margin_h, themed_style.margin_v);
|
||||
result->setIndentWidth(themed_style.indent_size);
|
||||
|
||||
bool emit_fancy_text = kristall::options.enable_text_decoration;
|
||||
bool emit_fancy_text = kristall::globals().options.enable_text_decoration;
|
||||
|
||||
QTextCursor cursor{result.get()};
|
||||
|
||||
|
@ -472,7 +472,7 @@ GeminiDocument::~GeminiDocument()
|
|||
*/
|
||||
static QByteArray replace_quotes(QByteArray &line)
|
||||
{
|
||||
if (!kristall::options.fancy_quotes)
|
||||
if (!kristall::globals().options.fancy_quotes)
|
||||
return line;
|
||||
|
||||
int last_d = -1,
|
||||
|
|
|
@ -27,7 +27,7 @@ std::unique_ptr<QTextDocument> GophermapRenderer::render(const QByteArray &input
|
|||
external_link.setFont(themed_style.standard_font);
|
||||
external_link.setForeground(QBrush(themed_style.external_link_color));
|
||||
|
||||
bool emit_text_only = (kristall::options.gophermap_display == GenericSettings::PlainText);
|
||||
bool emit_text_only = (kristall::globals().options.gophermap_display == GenericSettings::PlainText);
|
||||
|
||||
std::unique_ptr<QTextDocument> result = std::make_unique<QTextDocument>();
|
||||
renderhelpers::setPageMargins(result.get(), themed_style.margin_h, themed_style.margin_v);
|
||||
|
|
|
@ -30,7 +30,7 @@ static void setColor(QTextCharFormat& format, unsigned char n, bool bg=false)
|
|||
if (n < 16)
|
||||
{
|
||||
// The normal pre-defined typical 16 colors.
|
||||
color = QColor(kristall::document_style.ansi_colors[n]);
|
||||
color = QColor(kristall::globals().document_style.ansi_colors[n]);
|
||||
}
|
||||
else if (n < 232)
|
||||
{
|
||||
|
|
|
@ -13,7 +13,7 @@ BrowserTabBar::BrowserTabBar(QWidget *parent) :
|
|||
new_tab_btn = new QPushButton("+", this);
|
||||
new_tab_btn->setFixedSize(NEWTAB_BTN_SIZE, NEWTAB_BTN_SIZE);
|
||||
connect(new_tab_btn, &QPushButton::clicked, this, &BrowserTabBar::on_newTabClicked);
|
||||
this->new_tab_btn->setVisible(kristall::options.enable_newtab_btn);
|
||||
this->new_tab_btn->setVisible(kristall::globals().options.enable_newtab_btn);
|
||||
}
|
||||
|
||||
void BrowserTabBar::mouseReleaseEvent(QMouseEvent *event)
|
||||
|
@ -27,7 +27,7 @@ void BrowserTabBar::mouseReleaseEvent(QMouseEvent *event)
|
|||
|
||||
void BrowserTabBar::moveNewTabButton()
|
||||
{
|
||||
if (!kristall::options.enable_newtab_btn)
|
||||
if (!kristall::globals().options.enable_newtab_btn)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <QTouchDevice>
|
||||
#include <QRegularExpression>
|
||||
#include <QLineEdit>
|
||||
#include <QApplication>
|
||||
|
||||
const Qt::CursorShape KristallTextBrowser::NORMAL_CURSOR = Qt::IBeamCursor;
|
||||
|
||||
|
@ -133,7 +134,7 @@ void KristallTextBrowser::betterCopy()
|
|||
if (text.contains(REGEX_ONLY_QUOTES))
|
||||
{
|
||||
// Copy the original text.
|
||||
kristall::clipboard->setText(text);
|
||||
qApp->clipboard()->setText(text);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -151,5 +152,5 @@ void KristallTextBrowser::betterCopy()
|
|||
text.replace(QChar(0x2029), "\n");
|
||||
#endif
|
||||
|
||||
kristall::clipboard->setText(text);
|
||||
qApp->clipboard()->setText(text);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
SearchBar::SearchBar(QWidget *parent) : QLineEdit(parent)
|
||||
{
|
||||
QCompleter *completer = new QCompleter(this);
|
||||
completer->setModel(&kristall::favourites);
|
||||
completer->setModel(&kristall::globals().favourites);
|
||||
completer->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
completer->setCompletionRole(Qt::DisplayRole);
|
||||
this->setCompleter(completer);
|
||||
|
|
Loading…
Reference in New Issue