#include "trash/dolphintrash.h"
#include <KLocalizedString>
+#include <KNotificationJobUiDelegate>
+#include <KService>
#include <KXMLGUIFactory>
#include <KXmlGuiWindow>
+#include <KIO/ApplicationLauncherJob>
+
#include <QApplication>
#include <QDomDocument>
#include <QHBoxLayout>
}
int trailingSpacing = (m_globalXOfSplitter + m_splitter->width())
- (m_globalXOfPrimary + m_widthOfPrimary);
+#if KIO_VERSION < QT_VERSION_CHECK(5, 78, 0)
if (trailingSpacing < 0 || emptyTrashButton(Primary)->isVisible()) {
+#else
+ if (trailingSpacing < 0 || emptyTrashButton(Primary)->isVisible()
+ || networkFolderButton(Primary)->isVisible()
+ ) {
+#endif
trailingSpacing = 0;
}
const int widthLeftForUrlNavigator = m_splitter->widget(0)->width() - leadingSpacing - trailingSpacing;
trailingSpacing = (m_globalXOfSplitter + m_splitter->width())
- (m_globalXOfSecondary + m_widthOfSecondary);
+#if KIO_VERSION < QT_VERSION_CHECK(5, 78, 0)
if (trailingSpacing < 0 || emptyTrashButton(Secondary)->isVisible()) {
+#else
+ if (trailingSpacing < 0 || emptyTrashButton(Secondary)->isVisible()
+ || networkFolderButton(Secondary)->isVisible()
+ ) {
+#endif
trailingSpacing = 0;
} else {
const int widthLeftForUrlNavigator2 = m_splitter->widget(1)->width() - trailingSpacing;
auto emptyTrashButton = newEmptyTrashButton(urlNavigator, navigatorWidget);
layout->addWidget(emptyTrashButton);
+#if !(KIO_VERSION < QT_VERSION_CHECK(5, 78, 0))
+ auto networkFolderButton = newNetworkFolderButton(urlNavigator, navigatorWidget);
+ layout->addWidget(networkFolderButton);
+#endif
+
connect(urlNavigator, &KUrlNavigator::urlChanged, this, [this]() {
// We have to wait for DolphinUrlNavigator::sizeHint() to update which
// happens a little bit later than when urlChanged is emitted.
return emptyTrashButton;
}
+#if !(KIO_VERSION < QT_VERSION_CHECK(5, 78, 0))
+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;
+}
+#endif
+
QWidget *DolphinNavigatorsWidgetAction::spacing(Side side, Position position) const
{
int sideIndex = (side == Primary ? 0 : 1);
return m_splitter->widget(sideIndex)->layout()->itemAt(0)->widget();
}
if (side == Primary) {
+#if KIO_VERSION < QT_VERSION_CHECK(5, 78, 0)
return m_splitter->widget(sideIndex)->layout()->itemAt(3)->widget();
+#else
+ return m_splitter->widget(sideIndex)->layout()->itemAt(4)->widget();
+#endif
}
+#if KIO_VERSION < QT_VERSION_CHECK(5, 78, 0)
return m_splitter->widget(sideIndex)->layout()->itemAt(2)->widget();
+#else
+ return m_splitter->widget(sideIndex)->layout()->itemAt(3)->widget();
+#endif
}
void DolphinNavigatorsWidgetAction::updateText()
#include "dolphinurlnavigator.h"
+#include <kio_version.h>
#include <QSplitter>
#include <QTimer>
#include <QWidgetAction>
* 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 (for frameworks >= 5.78), and spacing.
* - Only the primary navigatorWidget has leading spacing. Both have trailing spacing.
* The spacing is there to align the UrlNavigator with its DolphinViewContainer.
*/
*/
QPushButton *newEmptyTrashButton(const DolphinUrlNavigator *urlNavigator, QWidget *parent) const;
+#if !(KIO_VERSION < QT_VERSION_CHECK(5, 78, 0))
+ /**
+ * 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;
+#endif
+
enum Position {
Leading,
Trailing