Commit 0bb11925 authored by Harald Sitter's avatar Harald Sitter
Browse files

smb: list printers

using a vendor specific mimetype and 0x0 access (the thing can't be
edited!) and with explicit erroring when trying to stat (which should
for the most part prevent KIO from opening the file by doing a mimetype
test on it)

this facilitates smb browsing of printers in printer-manager as it can
simply filter for the vendor mimetype now
parent d13fd7fc
Pipeline #112346 passed with stage
in 2 minutes and 27 seconds
......@@ -102,5 +102,15 @@ install(TARGETS kio_smb DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/kio)
install(FILES smb-network.desktop DESTINATION ${KDE_INSTALL_DATADIR}/konqueror/dirtree/remote)
install(FILES smb-network.desktop DESTINATION ${KDE_INSTALL_DATADIR}/remoteview)
option(WITH_SHAREDMIMEINFO "Build with shared shared-mime-info and update mimetype database on install" ON)
if(WITH_SHAREDMIMEINFO)
install(FILES org.kde.kio.smb.xml DESTINATION ${KDE_INSTALL_MIMEDIR})
find_package(SharedMimeInfo 1.3)
set_package_properties(SharedMimeInfo PROPERTIES
TYPE REQUIRED
PURPOSE "Used to update the mimetype database")
update_xdg_mimetypes(${KDE_INSTALL_MIMEDIR})
endif()
add_subdirectory(autotests)
add_subdirectory(kded)
......@@ -143,6 +143,12 @@ private Q_SLOTS:
// Clearly not a file should not work
QCOMPARE(QUrl(), SMBUrl(QUrl("file:///")).partUrl());
}
void testPrinter()
{
// We tag printers as such cause otherwise we have no way of knowing it was a printer.
QCOMPARE(SMBUrl(QUrl("smb://host/printer?kio-printer=true")).getType(), SMBURLTYPE_PRINTER);
}
};
QTEST_GUILESS_MAIN(SMBUrlTest)
......
/*
SPDX-License-Identifier: GPL-2.0-or-later
SPDX-FileCopyrightText: 2000 Caldera Systems Inc.
SPDX-FileCopyrightText: 2018-2020 Harald Sitter <sitter@kde.org>
SPDX-FileCopyrightText: 2018-2021 Harald Sitter <sitter@kde.org>
SPDX-FileContributor: Matthew Peterson <mpeterson@caldera.com>
*/
......@@ -141,6 +141,10 @@ void SMBSlave::stat(const QUrl &kurl)
error(ERR_MALFORMED_URL, url.toDisplayString());
return;
case SMBURLTYPE_PRINTER:
error(ERR_UNSUPPORTED_ACTION, url.toDisplayString());
return;
case SMBURLTYPE_ENTIRE_NETWORK:
case SMBURLTYPE_WORKGROUP_OR_SERVER:
udsentry.fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR);
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
SPDX-License-Identifier: CC0-1.0
SPDX-FileCopyrightText: 2021 Harald Sitter <sitter@kde.org>
-->
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="inode/vnd.kde.kio.smb.printer">
<comment>Shared Network Printer (SMB)</comment>
<icon name="printer"/>
</mime-type>
</mime-info>
/*
SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
SPDX-FileCopyrightText: 2020 Harald Sitter <sitter@kde.org>
SPDX-FileCopyrightText: 2020-2021 Harald Sitter <sitter@kde.org>
*/
#include <QCoreApplication>
......@@ -73,6 +73,20 @@ public:
}
};
class SMBCPrinterDiscovery : public SMBCDiscovery
{
public:
SMBCPrinterDiscovery(const UDSEntry &entry)
: SMBCDiscovery(entry)
{
m_entry.fastInsert(KIO::UDSEntry::UDS_ACCESS, 0x0);
m_entry.fastInsert(KIO::UDSEntry::UDS_MIME_TYPE, QStringLiteral("inode/vnd.kde.kio.smb.printer"));
// Relative to parent, but need to set it so we can append a marker. Subsequent stat calls wouldn't know that this is a printer
// because libsmbc doesn't reflect that in the stat output.
m_entry.fastInsert(KIO::UDSEntry::UDS_URL, udsName() + QStringLiteral("?kio-printer=true"));
}
};
SMBCDiscovery::SMBCDiscovery(const UDSEntry &entry)
: m_entry(entry)
// cache the name, it may get accessed more than once
......@@ -167,7 +181,9 @@ void SMBCDiscoverer::discoverNext()
return;
}
if (discoverNextFileInfo()) {
static bool printersOnly = qEnvironmentVariableIntValue("KIO_SMB_PRINTERS") > 0;
if (!printersOnly && discoverNextFileInfo()) {
return;
}
......@@ -201,6 +217,13 @@ void SMBCDiscoverer::discoverNext()
entry.fastInsert(KIO::UDSEntry::UDS_HIDDEN, 1);
}
if (printersOnly) {
if (dirp->smbc_type == SMBC_PRINTER_SHARE) {
Q_EMIT newDiscovery(Discovery::Ptr(new SMBCPrinterDiscovery(entry)));
}
return;
}
#if !defined(HAVE_READDIRPLUS2)
// . and .. are always of the dir type so they are of no consequence outside
// actual dir listing and that'd be done by readdirplus2 already
......
......@@ -163,6 +163,10 @@ SMBUrlType SMBUrl::getType() const
return m_type;
}
if (QUrlQuery query(*this); query.queryItemValue("kio-printer") == "true") {
return m_type = SMBURLTYPE_PRINTER;
}
if (path().isEmpty() || path(QUrl::FullyDecoded) == "/") {
if (host().isEmpty() && !query().contains("kio-workgroup"))
m_type = SMBURLTYPE_ENTIRE_NETWORK;
......
......@@ -39,11 +39,15 @@
* SMBURLTYPE_UNKNOWN - Type could not be determined. Bad SMB Url.
* SMBURLTYPE_ENTIRE_NETWORK - "smb:/" is entire network
* SMBURLTYPE_WORKGROUP_OR_SERVER - "smb:/mygroup" or "smb:/myserver"
* URLTYPE_SHARE_OR_PATH - "smb:/mygroupe/mymachine/myshare/mydir"
* SMBURLTYPE_SHARE_OR_PATH - "smb:/mygroupe/mymachine/myshare/mydir"
* SMBURLTYPE_PRINTER - "smb://host/printer?kio-printer=true"
*/
enum SMBUrlType {
SMBURLTYPE_UNKNOWN = 0, SMBURLTYPE_ENTIRE_NETWORK = 1,
SMBURLTYPE_WORKGROUP_OR_SERVER = 2, SMBURLTYPE_SHARE_OR_PATH = 3
SMBURLTYPE_UNKNOWN = 0,
SMBURLTYPE_ENTIRE_NETWORK = 1,
SMBURLTYPE_WORKGROUP_OR_SERVER = 2,
SMBURLTYPE_SHARE_OR_PATH = 3,
SMBURLTYPE_PRINTER,
};
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment