mirror of
https://invent.kde.org/system/dolphin
synced 2024-08-22 01:40:02 +00:00
Show button to open knetattach inline with URL nav on Remote:// view
In conjunction with https://invent.kde.org/frameworks/kio/-/merge_requests/260, the net result is to hide the knetattach launcher in the view, and show it inline with Dolphin's URL navigator toolbar when viewing the remote:// view, just like how we add an "Empty Trash" button when viewing trash://. CCBUG: 430211
This commit is contained in:
parent
e9f5525696
commit
b1cadeba93
|
@ -10,9 +10,13 @@
|
|||
#include "trash/dolphintrash.h"
|
||||
|
||||
#include <KLocalizedString>
|
||||
#include <KNotificationJobUiDelegate>
|
||||
#include <KService>
|
||||
#include <KXMLGUIFactory>
|
||||
#include <KXmlGuiWindow>
|
||||
|
||||
#include <KIO/ApplicationLauncherJob>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDomDocument>
|
||||
#include <QHBoxLayout>
|
||||
|
@ -56,7 +60,9 @@ void DolphinNavigatorsWidgetAction::adjustSpacing()
|
|||
}
|
||||
int trailingSpacing = (viewGeometries.globalXOfNavigatorsWidget + m_splitter->width())
|
||||
- (viewGeometries.globalXOfPrimary + viewGeometries.widthOfPrimary);
|
||||
if (trailingSpacing < 0 || emptyTrashButton(Primary)->isVisible()) {
|
||||
if (trailingSpacing < 0 || emptyTrashButton(Primary)->isVisible()
|
||||
|| networkFolderButton(Primary)->isVisible()
|
||||
) {
|
||||
trailingSpacing = 0;
|
||||
}
|
||||
const int widthLeftForUrlNavigator = m_splitter->widget(0)->width() - leadingSpacing - trailingSpacing;
|
||||
|
@ -83,7 +89,9 @@ void DolphinNavigatorsWidgetAction::adjustSpacing()
|
|||
|
||||
trailingSpacing = (viewGeometries.globalXOfNavigatorsWidget + m_splitter->width())
|
||||
- (viewGeometries.globalXOfSecondary + viewGeometries.widthOfSecondary);
|
||||
if (trailingSpacing < 0 || emptyTrashButton(Secondary)->isVisible()) {
|
||||
if (trailingSpacing < 0 || emptyTrashButton(Secondary)->isVisible()
|
||||
|| networkFolderButton(Secondary)->isVisible()
|
||||
) {
|
||||
trailingSpacing = 0;
|
||||
} else {
|
||||
const int widthLeftForUrlNavigator2 = m_splitter->widget(1)->width() - trailingSpacing;
|
||||
|
@ -185,6 +193,9 @@ QWidget *DolphinNavigatorsWidgetAction::createNavigatorWidget(Side side) const
|
|||
auto emptyTrashButton = newEmptyTrashButton(urlNavigator, navigatorWidget);
|
||||
layout->addWidget(emptyTrashButton);
|
||||
|
||||
auto networkFolderButton = newNetworkFolderButton(urlNavigator, navigatorWidget);
|
||||
layout->addWidget(networkFolderButton);
|
||||
|
||||
connect(urlNavigator, &KUrlNavigator::urlChanged, this, [urlNavigator, this]() {
|
||||
// Update URL navigator to show a server URL entry placeholder text if we
|
||||
// just loaded the remote:/ page, to make it easier for users to figure out
|
||||
|
@ -235,6 +246,36 @@ QPushButton *DolphinNavigatorsWidgetAction::newEmptyTrashButton(const DolphinUrl
|
|||
return emptyTrashButton;
|
||||
}
|
||||
|
||||
QPushButton *DolphinNavigatorsWidgetAction::networkFolderButton(DolphinNavigatorsWidgetAction::Side side)
|
||||
{
|
||||
int sideIndex = (side == Primary ? 0 : 1);
|
||||
if (side == Primary) {
|
||||
return static_cast<QPushButton *>(m_splitter->widget(sideIndex)->layout()->itemAt(3)->widget());
|
||||
}
|
||||
return static_cast<QPushButton *>(m_splitter->widget(sideIndex)->layout()->itemAt(2)->widget());
|
||||
}
|
||||
|
||||
QPushButton *DolphinNavigatorsWidgetAction::newNetworkFolderButton(const DolphinUrlNavigator *urlNavigator, QWidget *parent) const
|
||||
{
|
||||
auto networkFolderButton = new QPushButton(QIcon::fromTheme(QStringLiteral("folder-add")),
|
||||
i18nc("@action:button", "Add Network Folder"), parent);
|
||||
networkFolderButton->setFlat(true);
|
||||
connect(networkFolderButton, &QPushButton::clicked,
|
||||
this, [networkFolderButton]() {
|
||||
KService::Ptr service = KService::serviceByDesktopName(QStringLiteral("org.kde.knetattach"));
|
||||
auto *job = new KIO::ApplicationLauncherJob(service, networkFolderButton);
|
||||
auto *delegate = new KNotificationJobUiDelegate;
|
||||
delegate->setAutoErrorHandlingEnabled(true);
|
||||
job->setUiDelegate(delegate);
|
||||
job->start();
|
||||
});
|
||||
networkFolderButton->hide();
|
||||
connect(urlNavigator, &KUrlNavigator::urlChanged, this, [networkFolderButton, urlNavigator]() {
|
||||
networkFolderButton->setVisible(urlNavigator->locationUrl().scheme() == QLatin1String("remote"));
|
||||
});
|
||||
return networkFolderButton;
|
||||
}
|
||||
|
||||
QWidget *DolphinNavigatorsWidgetAction::spacing(Side side, Position position) const
|
||||
{
|
||||
int sideIndex = (side == Primary ? 0 : 1);
|
||||
|
@ -243,9 +284,9 @@ QWidget *DolphinNavigatorsWidgetAction::spacing(Side side, Position position) co
|
|||
return m_splitter->widget(sideIndex)->layout()->itemAt(0)->widget();
|
||||
}
|
||||
if (side == Primary) {
|
||||
return m_splitter->widget(sideIndex)->layout()->itemAt(3)->widget();
|
||||
return m_splitter->widget(sideIndex)->layout()->itemAt(4)->widget();
|
||||
}
|
||||
return m_splitter->widget(sideIndex)->layout()->itemAt(2)->widget();
|
||||
return m_splitter->widget(sideIndex)->layout()->itemAt(3)->widget();
|
||||
}
|
||||
|
||||
void DolphinNavigatorsWidgetAction::updateText()
|
||||
|
|
|
@ -31,7 +31,8 @@ class QPushButton;
|
|||
* The secondary side only exists for split view and is created by
|
||||
* createSecondaryUrlNavigator() when necessary.
|
||||
* - Each side is a QWidget which I call NavigatorWidget with a QHBoxLayout.
|
||||
* - Each NavigatorWidget consists an UrlNavigator, an emptyTrashButton and spacing.
|
||||
* - Each NavigatorWidget consists an UrlNavigator, an emptyTrashButton, a
|
||||
* networkFolderButton, and spacing.
|
||||
* - Only the primary navigatorWidget has leading spacing. Both have trailing spacing.
|
||||
* The spacing is there to align the UrlNavigator with its DolphinViewContainer.
|
||||
*/
|
||||
|
@ -127,6 +128,20 @@ private:
|
|||
*/
|
||||
QPushButton *newEmptyTrashButton(const DolphinUrlNavigator *urlNavigator, QWidget *parent) const;
|
||||
|
||||
/**
|
||||
* Used to retrieve the networkFolderButtons for the navigatorWidgets on
|
||||
* both sides.
|
||||
*/
|
||||
QPushButton *networkFolderButton(Side side);
|
||||
|
||||
/**
|
||||
* Creates a new add "network folder" button.
|
||||
* @param urlNavigator Only when this UrlNavigator shows the remote directory
|
||||
* will the button be visible.
|
||||
* @param parent The object that should be the button's parent.
|
||||
*/
|
||||
QPushButton *newNetworkFolderButton(const DolphinUrlNavigator *urlNavigator, QWidget *parent) const;
|
||||
|
||||
enum Position {
|
||||
Leading,
|
||||
Trailing
|
||||
|
|
Loading…
Reference in a new issue