/*
- * Copyright 2022-2023 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2022-2024 Soren Stoutner <soren@stoutner.com>.
*
* This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
*
qTabWidgetPointer->currentWidget()->setFocus();
}
-PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const bool backgroundTab, const QString urlString)
+PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const bool adjacent, const bool backgroundTab, const QString urlString)
{
// Create a splitter widget.
QSplitter *splitterPointer = new QSplitter();
splitterPointer->addWidget(privacyWebEngineViewPointer);
splitterPointer->addWidget(devToolsWebEngineViewPointer);
+ // Initialize the new tab index.
+ int newTabIndex = 0;
+
// Add a new tab.
- int newTabIndex = qTabWidgetPointer->addTab(splitterPointer, i18nc("New tab label.", "New Tab"));
+ if (adjacent) // Add the new tab adjacent to the current tab.
+ newTabIndex = qTabWidgetPointer->insertTab((qTabWidgetPointer->currentIndex() + 1), splitterPointer, i18nc("New tab label.", "New Tab"));
+ else // Add the new tab at the end of the list.
+ newTabIndex = qTabWidgetPointer->addTab(splitterPointer, i18nc("New tab label.", "New Tab"));
// Set the default tab icon.
qTabWidgetPointer->setTabIcon(newTabIndex, defaultFavoriteIcon);
currentPrivacyWebEngineViewPointer->reload();
}
-void TabWidget::applyOnTheFlyZoomFactor(const double &zoomFactor) const
+void TabWidget::applyOnTheFlyZoomFactor(const double zoomFactorDouble) const
{
// Set the zoom factor.
- currentPrivacyWebEngineViewPointer->setZoomFactor(zoomFactor);
+ currentPrivacyWebEngineViewPointer->setZoomFactor(zoomFactorDouble);
}
void TabWidget::applySpellCheckLanguages() const
return currentPrivacyWebEngineViewPointer->url().toString();
}
+QString TabWidget::getCurrentUserAgent() const
+{
+ // Return the current WebEngine user agent.
+ return currentWebEngineProfilePointer->httpUserAgent();
+}
+
QString& TabWidget::getDomainSettingsName() const
{
// Return the domain settings name.
void TabWidget::saveArchive()
{
// Get the suggested file name.
- QString suggestedFileName = currentPrivacyWebEngineViewPointer->url().host() + ".mht";
+ QString suggestedFileName = currentPrivacyWebEngineViewPointer->title() + ".mht";
// Get the download directory.
- QString downloadDirectory = Settings::downloadLocation();
+ QString downloadDirectory = Settings::downloadDirectory();
// Resolve the system download directory if specified.
if (downloadDirectory == QLatin1String("System Download Directory"))
// Save the webpage as an archive if the file save path is populated.
if (!saveFilePath.isEmpty())
{
+ // Update the download directory if specified.
+ if (Settings::autoUpateDownloadDirectory())
+ updateDownloadDirectory(saveFilePath);
+
// Set the saving archive flag. Otherwise, a second download tries to run.
savingArchive = true;
if (saveDialogResult == QDialog::Accepted) // Save was selected.
{
// Get the download directory.
- QString downloadDirectory = Settings::downloadLocation();
+ QString downloadDirectory = Settings::downloadDirectory();
// Resolve the system download directory if specified.
if (downloadDirectory == QLatin1String("System Download Directory"))
// Process the save file path.
if (!saveFilePath.isEmpty()) // The file save path is populated.
{
+ // Update the download directory if specified.
+ if (Settings::autoUpateDownloadDirectory())
+ updateDownloadDirectory(saveFilePath);
+
// Create a save file path file info.
QFileInfo saveFilePathFileInfo = QFileInfo(saveFilePath);
currentPrivacyWebEngineViewPointer->reload();
}
+void TabWidget::updateDownloadDirectory(QString newDownloadDirectory) const
+{
+ // Remove the file name from the save file path.
+ newDownloadDirectory.truncate(newDownloadDirectory.lastIndexOf(QLatin1Char('/')));
+
+ // Update the download location.
+ Settings::setDownloadDirectory(newDownloadDirectory);
+
+ // Get a handle for the KConfig skeleton.
+ KConfigSkeleton *kConfigSkeletonPointer = Settings::self();
+
+ // Write the settings to disk.
+ kConfigSkeletonPointer->save();
+}
+
void TabWidget::updateUiFromWebEngineView(const PrivacyWebEngineView *privacyWebEngineViewPointer) const
{
// Only update the UI if the signal was emitted from the current privacy WebEngine.
void TabWidget::useNativeKdeDownloader(QUrl &downloadUrl, QString &suggestedFileName)
{
// Get the download directory.
- QString downloadDirectory = Settings::downloadLocation();
+ QString downloadDirectory = Settings::downloadDirectory();
// Resolve the system download directory if specified.
if (downloadDirectory == QLatin1String("System Download Directory"))
saveFileDialogPointer->setWindowModality(Qt::WindowModal);
// Process the saving of the file. The save file dialog pointer must be captured directly instead of by reference or nasty crashes occur.
- auto saveFile = [saveFileDialogPointer, downloadUrl] ()
+ auto saveFile = [saveFileDialogPointer, downloadUrl, this] ()
{
// Get the save location. The dialog box should only allow the selecting of one file location.
QUrl saveLocation = saveFileDialogPointer->selectedUrls().value(0);
+ // Update the download directory if specified.
+ if (Settings::autoUpateDownloadDirectory())
+ updateDownloadDirectory(saveLocation.toLocalFile());
+
// Create a file copy job. `-1` creates the file with default permissions.
KIO::FileCopyJob *fileCopyJobPointer = KIO::file_copy(downloadUrl, saveLocation, -1, KIO::Overwrite);