diff --git a/core/smb4kglobal.cpp b/core/smb4kglobal.cpp index bd17ea9..43323f0 100644 --- a/core/smb4kglobal.cpp +++ b/core/smb4kglobal.cpp @@ -1,1335 +1,1323 @@ /*************************************************************************** This is the global namespace for Smb4K. ------------------- begin : Sa Apr 2 2005 - copyright : (C) 2005-2017 by Alexander Reinholdt + copyright : (C) 2005-2019 by Alexander Reinholdt email : alexander.reinholdt@kdemail.net ***************************************************************************/ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* * MA 02110-1335, USA * ***************************************************************************/ #ifdef HAVE_CONFIG_H #include #endif // application specific includes #include "smb4kglobal.h" #include "smb4kglobal_p.h" #include "smb4knotification.h" #include "smb4kmounter.h" #include "smb4ksynchronizer.h" #include "smb4kclient.h" // Qt includes #include #include #include #include // KDE includes #include #include Q_GLOBAL_STATIC(Smb4KGlobalPrivate, p); QMutex mutex(QMutex::Recursive /* needed to avoid dead-locks */); void Smb4KGlobal::initCore(bool modifyCursor, bool initClasses) { if (!p->coreInitialized) { // // Busy cursor // p->modifyCursor = modifyCursor; - // - // Set default values - // - p->setDefaultSettings(); - // // Initialize the necessary core classes // if (initClasses) { Smb4KClient::self()->start(); Smb4KMounter::self()->start(); } else { // Do nothing } - p->makeConnections(); p->coreInitialized = true; } else { // Do nothing } } void Smb4KGlobal::abortCore() { Smb4KClient::self()->abort(); Smb4KMounter::self()->abortAll(); Smb4KSynchronizer::self()->abortAll(); } bool Smb4KGlobal::coreIsRunning() { return (Smb4KClient::self()->isRunning() || Smb4KMounter::self()->isRunning() || Smb4KSynchronizer::self()->isRunning()); } -void Smb4KGlobal::setDefaultSettings() -{ - p->setDefaultSettings(); -} - - bool Smb4KGlobal::coreIsInitialized() { return p->coreInitialized; } const QList &Smb4KGlobal::workgroupsList() { return p->workgroupsList; } WorkgroupPtr Smb4KGlobal::findWorkgroup(const QString &name) { WorkgroupPtr workgroup; mutex.lock(); for (const WorkgroupPtr &w : p->workgroupsList) { if (QString::compare(w->workgroupName(), name, Qt::CaseInsensitive) == 0) { workgroup = w; break; } else { // Do nothing } } mutex.unlock(); return workgroup; } bool Smb4KGlobal::addWorkgroup(WorkgroupPtr workgroup) { Q_ASSERT(workgroup); bool added = false; if (workgroup) { mutex.lock(); if (!findWorkgroup(workgroup->workgroupName())) { p->workgroupsList.append(workgroup); added = true; } else { // Do nothing } mutex.unlock(); } else { // Do nothing } return added; } bool Smb4KGlobal::updateWorkgroup(WorkgroupPtr workgroup) { Q_ASSERT(workgroup); bool updated = false; if (workgroup) { mutex.lock(); WorkgroupPtr existingWorkgroup = findWorkgroup(workgroup->workgroupName()); if (existingWorkgroup) { existingWorkgroup->update(workgroup.data()); updated = true; } else { // Do nothing } mutex.unlock(); } else { // Do nothing } return updated; } bool Smb4KGlobal::removeWorkgroup(WorkgroupPtr workgroup) { Q_ASSERT(workgroup); bool removed = false; if (workgroup) { mutex.lock(); int index = p->workgroupsList.indexOf(workgroup); if (index != -1) { // The workgroup was found. Remove it. p->workgroupsList.takeAt(index).clear(); removed = true; } else { // Try harder to find the workgroup. WorkgroupPtr wg = findWorkgroup(workgroup->workgroupName()); if (wg) { index = p->workgroupsList.indexOf(wg); if (index != -1) { p->workgroupsList.takeAt(index).clear(); removed = true; } else { // Do nothing } } else { // Do nothing } workgroup.clear(); } mutex.unlock(); } else { // Do nothing } return removed; } void Smb4KGlobal::clearWorkgroupsList() { mutex.lock(); while (!p->workgroupsList.isEmpty()) { p->workgroupsList.takeFirst().clear(); } mutex.unlock(); } const QList &Smb4KGlobal::hostsList() { return p->hostsList; } HostPtr Smb4KGlobal::findHost(const QString &name, const QString &workgroup) { HostPtr host; mutex.lock(); for (const HostPtr &h : p->hostsList) { if ((workgroup.isEmpty() || QString::compare(h->workgroupName(), workgroup, Qt::CaseInsensitive) == 0) && QString::compare(h->hostName(), name, Qt::CaseInsensitive) == 0) { host = h; break; } else { // Do nothing } } mutex.unlock(); return host; } bool Smb4KGlobal::addHost(HostPtr host) { Q_ASSERT(host); bool added = false; if (host) { mutex.lock(); if (!findHost(host->hostName(), host->workgroupName())) { p->hostsList.append(host); added = true; } else { // Do nothing } mutex.unlock(); } else { // Do nothing } return added; } bool Smb4KGlobal::updateHost(HostPtr host) { Q_ASSERT(host); bool updated = false; if (host) { mutex.lock(); HostPtr existingHost = findHost(host->hostName(), host->workgroupName()); if (existingHost) { existingHost->update(host.data()); updated = true; } else { // Do nothing } mutex.unlock(); } else { // Do nothing } return updated; } bool Smb4KGlobal::removeHost(HostPtr host) { Q_ASSERT(host); bool removed = false; if (host) { mutex.lock(); int index = p->hostsList.indexOf(host); if (index != -1) { // The host was found. Remove it. p->hostsList.takeAt(index).clear(); removed = true; } else { // Try harder to find the host. HostPtr h = findHost(host->hostName(), host->workgroupName()); if (h) { index = p->hostsList.indexOf(h); if (index != -1) { p->hostsList.takeAt(index).clear(); removed = true; } else { // Do nothing } } else { // Do nothing } host.clear(); } mutex.unlock(); } else { // Do nothing } return removed; } void Smb4KGlobal::clearHostsList() { mutex.lock(); while (!p->hostsList.isEmpty()) { p->hostsList.takeFirst().clear(); } mutex.unlock(); } QList Smb4KGlobal::workgroupMembers(WorkgroupPtr workgroup) { QList hosts; mutex.lock(); for (const HostPtr &h : p->hostsList) { if (QString::compare(h->workgroupName(), workgroup->workgroupName(), Qt::CaseInsensitive) == 0) { hosts << h; } else { // Do nothing } } mutex.unlock(); return hosts; } const QList &Smb4KGlobal::sharesList() { return p->sharesList; } SharePtr Smb4KGlobal::findShare(const QUrl& url, const QString& workgroup) { SharePtr share; mutex.lock(); for (const SharePtr &s : p->sharesList) { if (s->url().matches(url, QUrl::RemoveUserInfo|QUrl::RemovePort) && (workgroup.isEmpty() || QString::compare(s->workgroupName(), workgroup, Qt::CaseInsensitive) == 0)) { share = s; break; } else { // Do nothing } } mutex.unlock(); return share; } bool Smb4KGlobal::addShare(SharePtr share) { Q_ASSERT(share); bool added = false; if (share) { mutex.lock(); // // Add the share // if (!findShare(share->url(), share->workgroupName())) { // // Set the share mounted // Only honor shares that are owned by the user // QList mountedShares = findShareByUrl(share->url()); if (!mountedShares.isEmpty()) { for (const SharePtr &s : mountedShares) { if (!s->isForeign()) { share->setMountData(s.data()); break; } else { continue; } } } else { // Do nothing } // // Add it // p->sharesList.append(share); added = true; } else { // Do nothing } } else { // Do nothing } mutex.unlock(); return added; } bool Smb4KGlobal::updateShare(SharePtr share) { Q_ASSERT(share); bool updated = false; if (share) { mutex.lock(); // // Updated the share // SharePtr existingShare = findShare(share->url(), share->workgroupName()); if (existingShare) { // // Set the share mounted // Only honor shares that are owned by the user // QList mountedShares = findShareByUrl(share->url()); if (!mountedShares.isEmpty()) { for (const SharePtr &s : mountedShares) { if (!s->isForeign()) { share->setMountData(s.data()); break; } else { continue; } } } else { // Do nothing } // // Update it // existingShare->update(share.data()); updated = true; } else { // Do nothing } mutex.unlock(); } else { // Do nothing } return updated; } bool Smb4KGlobal::removeShare(SharePtr share) { Q_ASSERT(share); bool removed = false; if (share) { mutex.lock(); int index = p->sharesList.indexOf(share); if (index != -1) { // The share was found. Remove it. p->sharesList.takeAt(index).clear(); removed = true; } else { // Try harder to find the share. SharePtr s = findShare(share->url(), share->workgroupName()); if (s) { index = p->sharesList.indexOf(s); if (index != -1) { p->sharesList.takeAt(index).clear(); removed = true; } else { // Do nothing } } else { // Do nothing } share.clear(); } mutex.unlock(); } else { // Do nothing } return removed; } void Smb4KGlobal::clearSharesList() { mutex.lock(); while (!p->sharesList.isEmpty()) { p->sharesList.takeFirst().clear(); } mutex.unlock(); } QList Smb4KGlobal::sharedResources(HostPtr host) { QList shares; mutex.lock(); for (const SharePtr &s : p->sharesList) { if (QString::compare(s->hostName(), host->hostName(), Qt::CaseInsensitive) == 0 && QString::compare(s->workgroupName(), host->workgroupName(), Qt::CaseInsensitive) == 0) { shares += s; } else { // Do nothing } } mutex.unlock(); return shares; } const QList &Smb4KGlobal::mountedSharesList() { return p->mountedSharesList; } SharePtr Smb4KGlobal::findShareByPath(const QString &path) { SharePtr share; mutex.lock(); if (!path.isEmpty() && !p->mountedSharesList.isEmpty()) { for (const SharePtr &s : p->mountedSharesList) { if (QString::compare(s->path(), path, Qt::CaseInsensitive) == 0 || QString::compare(s->canonicalPath(), path, Qt::CaseInsensitive) == 0) { share = s; break; } else { // Do nothing } } } else { // Do nothing } mutex.unlock(); return share; } QList Smb4KGlobal::findShareByUrl(const QUrl &url) { QList shares; mutex.lock(); if (!url.isEmpty() && url.isValid() && !p->mountedSharesList.isEmpty()) { for (const SharePtr &s : p->mountedSharesList) { if (s->url().matches(url, QUrl::RemoveUserInfo|QUrl::RemovePort)) { shares << s; } else { // Do nothing } } } else { // Do nothing } mutex.unlock(); return shares; } QList Smb4KGlobal::findInaccessibleShares() { QList inaccessibleShares; mutex.lock(); for (const SharePtr &s : p->mountedSharesList) { if (s->isInaccessible()) { inaccessibleShares += s; } else { // Do nothing } } mutex.unlock(); return inaccessibleShares; } bool Smb4KGlobal::addMountedShare(SharePtr share) { Q_ASSERT(share); bool added = false; if (share) { mutex.lock(); // // Copy the mount data to the network share and the search results. // Only honor shares that were mounted by the user. // if (!share->isForeign()) { // Network shares SharePtr networkShare = findShare(share->url(), share->workgroupName()); if (networkShare) { networkShare->setMountData(share.data()); } else { // Do nothing } // Search results for (SharePtr s : p->searchResults) { if (share->url().matches(s->url(), QUrl::RemoveUserInfo|QUrl::RemovePort)) { s->setMountData(share.data()); } else { // Do nothing } } } else { // Do nothing } if (!findShareByPath(share->path())) { // // Check if we have to add a workgroup name and/or IP address // HostPtr networkHost = findHost(share->hostName(), share->workgroupName()); if (networkHost) { // Set the IP address if (!share->hasHostIpAddress() || networkHost->ipAddress() != share->hostIpAddress()) { share->setHostIpAddress(networkHost->ipAddress()); } else { // Do nothing } // Set the workgroup name if (share->workgroupName().isEmpty()) { share->setWorkgroupName(networkHost->workgroupName()); } else { // Do nothing } } else { // Do nothing } p->mountedSharesList.append(share); added = true; p->onlyForeignShares = true; for (const SharePtr &s : p->mountedSharesList) { if (!s->isForeign()) { p->onlyForeignShares = false; break; } else { // Do nothing } } } else { // Do nothing } mutex.unlock(); } else { // Do nothing } return added; } bool Smb4KGlobal::updateMountedShare(SharePtr share) { Q_ASSERT(share); bool updated = false; if (share) { mutex.lock(); // // Copy the mount data to the network share (needed for unmounting from the network browser) // Only honor shares that were mounted by the user. // if (!share->isForeign()) { SharePtr networkShare = findShare(share->url(), share->workgroupName()); if (networkShare) { networkShare->setMountData(share.data()); } else { // Do nothing } } else { // Do nothing } SharePtr mountedShare = findShareByPath(share->path()); if (mountedShare) { // // Check if we have to add a workgroup name and/or IP address // HostPtr networkHost = findHost(share->hostName(), share->workgroupName()); if (networkHost) { // Set the IP address if (!share->hasHostIpAddress() || networkHost->ipAddress() != share->hostIpAddress()) { share->setHostIpAddress(networkHost->ipAddress()); } else { // Do nothing } // Set the workgroup name if (share->workgroupName().isEmpty()) { share->setWorkgroupName(networkHost->workgroupName()); } else { // Do nothing } } else { // Do nothing } // // Update share // mountedShare->setMountData(share.data()); updated = true; } else { // Do nothing } mutex.unlock(); } else { // Do nothing } return updated; } bool Smb4KGlobal::removeMountedShare(SharePtr share) { Q_ASSERT(share); bool removed = false; if (share) { mutex.lock(); // // Reset the mount data for the network share and the // search result // if (!share->isForeign()) { // Network share SharePtr networkShare = findShare(share->url(), share->workgroupName()); if (networkShare) { networkShare->resetMountData(); } else { // Do nothing } // Search result for (SharePtr searchResult : searchResults()) { if (searchResult->url().matches(share->url(), QUrl::RemoveUserInfo|QUrl::RemovePort)) { searchResult->resetMountData(); break; } else { // Do nothing } } } else { // Do nothing } // // Remove the mounted share // int index = p->mountedSharesList.indexOf(share); if (index != -1) { // The share was found. Remove it. p->mountedSharesList.takeAt(index).clear(); removed = true; } else { // Try harder to find the share. SharePtr s = findShareByPath(share->isInaccessible() ? share->path() : share->canonicalPath()); if (s) { index = p->mountedSharesList.indexOf(s); if (index != -1) { p->mountedSharesList.takeAt(index).clear(); removed = true; } else { // Do nothing } } else { // Do nothing } share.clear(); } for (const SharePtr &s : p->mountedSharesList) { if (!s->isForeign()) { p->onlyForeignShares = false; break; } else { // Do nothing } } mutex.unlock(); } else { // Do nothing } return removed; } bool Smb4KGlobal::onlyForeignMountedShares() { return p->onlyForeignShares; } bool Smb4KGlobal::addSearchResult(SharePtr share) { bool added = false; if (share) { mutex.lock(); // // Check if the share is already mounted. Ignore foreign shares // for that. // QList mountedShares = findShareByUrl(share->url()); if (!mountedShares.isEmpty()) { for (const SharePtr &mountedShare : mountedShares) { if (!mountedShare->isForeign()) { share->setMountData(mountedShare.data()); break; } else { // Do nothing } } } else { // Do nothing } // // Add the search result. // p->searchResults.append(share); added = true; mutex.unlock(); } else { // Do nothing } return added; } void Smb4KGlobal::clearSearchResults() { mutex.lock(); while (!p->searchResults.isEmpty()) { p->searchResults.takeFirst().clear(); } mutex.unlock(); } QList Smb4KGlobal::searchResults() { return p->searchResults; } void Smb4KGlobal::openShare(SharePtr share, OpenWith openWith) { if (!share || share->isInaccessible()) { return; } switch (openWith) { case FileManager: { QUrl url = QUrl::fromLocalFile(share->canonicalPath()); (void) new KRun(url, 0); break; } case Konsole: { QString konsole = QStandardPaths::findExecutable("konsole"); if (konsole.isEmpty()) { Smb4KNotification::commandNotFound("konsole"); } else { KRun::runCommand(konsole+" --workdir "+KShell::quoteArg(share->canonicalPath()), 0); } break; } default: { break; } } } -const QMap &Smb4KGlobal::globalSambaOptions(bool read) +const QMap &Smb4KGlobal::globalSambaOptions() { - return p->globalSambaOptions(read); + return p->globalSambaOptions(); } const QString Smb4KGlobal::winsServer() { QMap global_opts = p->globalSambaOptions(false); QString wins_server; if (global_opts.contains("wins server")) { wins_server = global_opts.value("wins server"); } else { if (global_opts.contains("wins support") && (QString::compare(global_opts.value("wins support"), "yes", Qt::CaseInsensitive) == 0 || QString::compare(global_opts.value("wins support"), "true", Qt::CaseInsensitive) == 0)) { wins_server = "127.0.0.1"; } else { // Do nothing } } return wins_server; } bool Smb4KGlobal::modifyCursor() { return p->modifyCursor; } #if defined(Q_OS_LINUX) QStringList Smb4KGlobal::whitelistedMountArguments() { return p->whitelistedMountArguments; } #endif const QString Smb4KGlobal::findMountExecutable() { QStringList paths; paths << "/bin"; paths << "/sbin"; paths << "/usr/bin"; paths << "/usr/sbin"; paths << "/usr/local/bin"; paths << "/usr/local/sbin"; #if defined(Q_OS_LINUX) return QStandardPaths::findExecutable("mount.cifs", paths); #elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) return QStandardPaths::findExecutable("mount_smbfs", paths); #else return QString(); #endif } const QString Smb4KGlobal::findUmountExecutable() { QStringList paths; paths << "/bin"; paths << "/sbin"; paths << "/usr/bin"; paths << "/usr/sbin"; paths << "/usr/local/bin"; paths << "/usr/local/sbin"; return QStandardPaths::findExecutable("umount", paths); } const QString Smb4KGlobal::dataLocation() { return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)+QDir::separator()+"smb4k"; } diff --git a/core/smb4kglobal.h b/core/smb4kglobal.h index 8307e5c..398e4db 100644 --- a/core/smb4kglobal.h +++ b/core/smb4kglobal.h @@ -1,561 +1,552 @@ /*************************************************************************** This is the global namespace for Smb4K. ------------------- begin : Sa Apr 2 2005 - copyright : (C) 2005-2017 by Alexander Reinholdt + copyright : (C) 2005-2019 by Alexander Reinholdt email : alexander.reinholdt@kdemail.net ***************************************************************************/ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* * MA 02110-1335, USA * ***************************************************************************/ #ifndef SMB4KGLOBAL_H #define SMB4KGLOBAL_H // Qt includes #include #include #include #include #include #include // forward declarations class Smb4KBasicNetworkItem; class Smb4KWorkgroup; class Smb4KHost; class Smb4KShare; class Smb4KFile; class Smb4KBookmark; class Smb4KCustomOptions; // type definitions typedef QSharedPointer NetworkItemPtr; typedef QSharedPointer WorkgroupPtr; typedef QSharedPointer HostPtr; typedef QSharedPointer SharePtr; typedef QSharedPointer FilePtr; typedef QSharedPointer BookmarkPtr; typedef QSharedPointer OptionsPtr; // Other definitions #ifndef SMB4K_DEPRECATED #define SMB4K_DEPRECATED __attribute__ ((__deprecated__)) #endif #if !defined(Q_OS_LINUX) && !defined(Q_OS_FREEBSD) && !defined(Q_OS_NETBSD) #warning Defining SMB4K_UNSUPPORTED_PLATFORM #define SMB4K_UNSUPPORTED_PLATFORM #endif /** * This is the global namespace. It provides access to the global lists * of workgroups, hosts and shares, to the global settings of the Samba * configuration and much more. * * @author Alexander Reinholdt */ namespace Smb4KGlobal { /** * The Process enumeration. * * @enum LookupDomains Look up domains * @enum LookupDomainMembers Look up those servers that belong to a domain/workgroup * @enum LookupShares Look up shares on a server * @enum LookupFiles Look up files and directories within a share * @enum WakeUp Send magic Wake-On-LAN packages * @enum PrintFile Print a file * @enum NetworkSearch Network search * @enum MountShare Mount a share * @enum UnmountShare Unmount a share * @enum NoProcess No process */ enum Process { LookupDomains, LookupDomainMembers, LookupShares, LookupFiles, WakeUp, PrintFile, NetworkSearch, MountShare, UnmountShare, NoProcess }; /** * The enumeration to determine the type of a network item. * * @enum Network The network * @enum Workgroup A workgroup * @enum Host A host * @enum Share A share * @enum Directory A directory in a shared folder * @enum File A file in a shared folder * @enum UnknownNetworkItem An unknown network item */ enum NetworkItem { Network, Workgroup, Host, Share, Directory, File, UnknownNetworkItem }; /** * The enumeration that determines the share type * * @enum FileShare a file share * @enum PrinterShare a printer share * @enum IpcShare an IPC share */ enum ShareType { FileShare, PrinterShare, IpcShare, }; /** * Use this function to initialize the core classes. Besides starting several * core classes such as the scanner (for an initial browse list) and the mounter * (for the import of all externally mounted shares), it also sets some default * values for some of the settings used to browse the network. * * By setting the @p modifyCursor parameter to TRUE, you force the core classes * to set a busy cursor when they do something. Default is FALSE. * * Setting @p initClasses to FALSE will avoid starting the core classes. This * should only the used if you are starting the core classes in a different * way (e. g. if you are starting them in the plasmoid via the Smb4KDeclarative * class). * * You should execute this function before starting your main application. */ Q_DECL_EXPORT void initCore(bool modifyCursor = false, bool initClasses = true); /** * Aborts all actions that are run by the core classes and that can be aborted. */ Q_DECL_EXPORT void abortCore(); /** * Check if at least one of the core classes that use KJobs (scanner, mounter, etc.) * is running. * * @returns TRUE if at least one of the core classes is doing something. */ Q_DECL_EXPORT bool coreIsRunning(); - /** - * Set the necessary default values. - * - * You only need to run this function if you do not use the initCore() function. - * Check if the core has been initialized by the coreIsInitialized() function. - */ - Q_DECL_EXPORT void setDefaultSettings(); - /** * Check if the core has been initialized through the initCore() function. * * @returns TRUE if the core has already been initialized. */ Q_DECL_EXPORT bool coreIsInitialized(); /** * This function returns the global list of workgroups that were discovered by * Smb4K. Use this if you want to access and modify the list with your code. * * @returns the global list of known workgroups. */ Q_DECL_EXPORT const QList &workgroupsList(); /** * This function returns the workgroup or domain that matches the name @p name or * NULL if there is no such workgroup. * * @returns a pointer to the workgroup with name @p name. */ Q_DECL_EXPORT WorkgroupPtr findWorkgroup(const QString &name); /** * This function takes a workgroup @p workgroup, checks whether it is already * in the list of domains and adds it to the list if necessary. It returns TRUE * if the workgroup was added and FALSE otherwise. * * Please prefer this function over per class solutions. * * @param workgroup The workgroup item * * @returns TRUE if the workgroup was added and FALSE otherwise. */ Q_DECL_EXPORT bool addWorkgroup(WorkgroupPtr workgroup); /** * This function takes a workgroup @p workgroup, and updates the respective workgroup * in the global list, if it exists. It returns TRUE on success and FALSE otherwise. * If you want to add a workgroup to the global list, use @see addWorkgroup(). * * Please prefer this function over per class solutions. * * @returns TRUE if the workgroup was updated and FALSE otherwise */ Q_DECL_EXPORT bool updateWorkgroup(WorkgroupPtr workgroup); /** * This function removes a workgroup @p workgroup from the list of domains. The * pointer that is passed to this function will be deleted. You won't be able * to use it afterwards. This function returns TRUE if the workgroup was removed * and FALSE otherwise. * * Please prefer this function over per class solutions. * * @param workgroup The workgroup item * * @returns TRUE if the workgroup was removed and FALSE otherwise. */ Q_DECL_EXPORT bool removeWorkgroup(WorkgroupPtr workgroup); /** * This function clears the global list of workgroups. */ Q_DECL_EXPORT void clearWorkgroupsList(); /** * This function returns the global list of hosts that were discovered by * Smb4K. Use this if you want to access and modify the list with your code. * * @returns the global list of known hosts. */ Q_DECL_EXPORT const QList &hostsList(); /** * This function returns the host matching the name @p name or NULL if there is no * such host. The name of the host is mandatory. The workgroup may be empty, but * should be given, because this will speed up the search process. * * @param name The name of the host * * @param workgroup The workgroup where the host is located * * @returns an Smb4KHost item of NULL if none was found that matches @p name. */ Q_DECL_EXPORT HostPtr findHost(const QString &name, const QString &workgroup = QString()); /** * This function takes a host @p host, checks whether it is already * in the list of hosts and adds it to the list if necessary. It returns TRUE * if the host was added and FALSE otherwise. * * Please prefer this function over per class solutions. * * @param host The host item * * @returns TRUE if the host was added and FALSE otherwise. */ Q_DECL_EXPORT bool addHost(HostPtr host); /** * This function takes an host @p host, and updates the respective host * in the global list, if it exists. It returns TRUE on success and FALSE otherwise. * If you want to add an host to the global list, use @see addHost(). * * Please prefer this function over per class solutions. * * @returns TRUE if the host was updated and FALSE otherwise */ Q_DECL_EXPORT bool updateHost(HostPtr host); /** * This function removes a host @p host from the list of hosts. The * pointer that is passed to this function will be deleted. You won't * be able to use it afterwards. This function returns TRUE if the host was removed * and FALSE otherwise. * * Please prefer this function over per class solutions. * * @param host The host item * * @returns TRUE if the host was removed and FALSE otherwise. */ Q_DECL_EXPORT bool removeHost(HostPtr host); /** * This function clears the global list of hosts. */ Q_DECL_EXPORT void clearHostsList(); /** * This function returns all hosts that belong to the workgroup or domain * @p workgroup. * * Please favor this function over per class solutions. * * @param workgroup The workgroup for that the list should be returned. * * @returns the list of hosts belonging to the workgroup or domain @param workgroup. */ Q_DECL_EXPORT QList workgroupMembers(WorkgroupPtr workgroup); /** * This function returns the list of shares that were discovered by Smb4K. * Use this if you want to access and modify the list with your code. * * @returns the global list of known shares. */ Q_DECL_EXPORT const QList &sharesList(); /** * This function returns the share with URL @p url located in the workgroup or * domain @p workgroup. If there is no such share, 0 is returned. The workgroup * entry may be empty. * * @param url The URL of the share * * @param workgroup The workgroup * * @returns the share that matches @p url and optionally @p workgroup or 0. */ Q_DECL_EXPORT SharePtr findShare(const QUrl &url, const QString &workgroup = QString()); /** * This function takes a share @p share, checks whether it is already * in the list of shares and adds it to the list if necessary. It returns TRUE * if the share was added and FALSE otherwise. * * Please prefer this function over per class solutions. * * @param share The share item * * @returns TRUE if the share was added and FALSE otherwise. */ Q_DECL_EXPORT bool addShare(SharePtr share); /** * This function takes a share @p share, and updates the respective share * in the global list, if it exists. It returns TRUE on success and FALSE otherwise. * If you want to add a share to the global list, use @see addShare(). * * Please prefer this function over per class solutions. * * @returns TRUE if the share was updated and FALSE otherwise */ Q_DECL_EXPORT bool updateShare(SharePtr share); /** * This function removes a share @p share from the list of shares. The * pointer that is passed to this function will be deleted. You won't * be able to use it afterwards. This function returns TRUE if the share was removed * and FALSE otherwise. * * Please prefer this function over per class solutions. * * @param share The share item * * @returns TRUE if the share was removed and FALSE otherwise. */ Q_DECL_EXPORT bool removeShare(SharePtr share); /** * This function clears the global list of shares. */ Q_DECL_EXPORT void clearSharesList(); /** * This function returns the list of shares that is provided by one specific host * @p host. * * Please favor this function over per class solutions. * * @param host The host where the shares are located * * @returns the list of shares that are provided by the host @p host. */ Q_DECL_EXPORT QList sharedResources(HostPtr host); /** * This function returns the global list of mounted shares that were discovered by * Smb4K. Use this if you want to access and modify the list with your code. * * @returns the global list of known mounted shares. */ Q_DECL_EXPORT const QList &mountedSharesList(); /** * Find a mounted share by its path (i.e. mount point). * * @returns the share that is mounted to @p path. */ Q_DECL_EXPORT SharePtr findShareByPath(const QString &path); /** * Find all mounts of a particular share with URL @p url on the system. * * This function will compare the incoming URL with the URL of each * mounted share to find all shares with the same URL. For the comparison * the user info and the port will be stripped. * * @param url The URL of the share * * @returns the complete list of mounts with the URL @p url. */ Q_DECL_EXPORT QList findShareByUrl(const QUrl &url); /** * This function returns the list of inaccessible shares. * * @returns the list of inaccessible shares. */ Q_DECL_EXPORT QList findInaccessibleShares(); /** * This function takes a mounted share @p share, checks whether it is * already in the list of mounted shares and adds it to the list if * necessary. It returns TRUE if the share was added and FALSE otherwise. * * Please prefer this function over per class solutions. * * @param share The share item * * @returns TRUE if the share was added and FALSE otherwise. */ Q_DECL_EXPORT bool addMountedShare(SharePtr share); /** * This function takes a mounted share @p share and updates the share that * is already present in the internal list. * * @param share The share item * @returns TRUE if a share was found and updated. Returns FALSE otherwise. */ Q_DECL_EXPORT bool updateMountedShare(SharePtr share); /** * This function removes a mounted share @p share from the list of mounted * shares. The pointer that is passed to this function will be deleted. * You won't be able to use it afterwards. This function returns TRUE if * the share was removed and FALSE otherwise. * * Please prefer this function over per class solutions. * * @param share The share item * * @returns TRUE if the share was removed and FALSE otherwise. */ Q_DECL_EXPORT bool removeMountedShare(SharePtr share); /** * This function returns TRUE if only shares are present that are owned by * other users and FALSE otherwise. * * @returns TRUE if there are only shares that are owned by other users. */ Q_DECL_EXPORT bool onlyForeignMountedShares(); /** * This functions adds a share to the search results. * * @param share The share item */ Q_DECL_EXPORT bool addSearchResult(SharePtr share); /** * This function clears the list of search results. */ Q_DECL_EXPORT void clearSearchResults(); /** * This function returns the list of all search results * * @returns the list of search results */ Q_DECL_EXPORT QList searchResults(); /** * This enumeration determines with which application the mount point * of the current mounted share is to be opened. */ enum OpenWith { FileManager, Konsole }; /** * Open the mount point of a share. Which application is used is determined by * the value of @p openWith and - maybe - by settings that were defined by the * user. * * @param share The share that is to be opened. * * @param openWith Integer of type Smb4KCore::OpenWith. Determines with which * application the share should be opened. */ Q_DECL_EXPORT void openShare(SharePtr share, OpenWith openWith = FileManager); /** - * Get the entries of the [global] section of the smb.conf file. By setting @p read - * to TRUE you can force the smb.conf file to be reread. + * Get the entries of the [global] section of the smb.conf file. * * @returns the entries of the [global] section of the smb.conf file */ - Q_DECL_EXPORT const QMap &globalSambaOptions(bool read = false); + Q_DECL_EXPORT const QMap &globalSambaOptions(); /** * Get the WINS server's name or IP address. Returns an empty string if there is no * WINS server is defined. * * @returns the WINS server */ Q_DECL_EXPORT const QString winsServer(); /** * This function returns TRUE if the core classes should set a busy cursor when * they are doing something. * * @returns TRUE in case a busy cursor should be set. */ Q_DECL_EXPORT bool modifyCursor(); #if defined(Q_OS_LINUX) /** * This list contains all whitelisted arguments for the mount.cifs binary and * is only present under the Linux operating system. */ Q_DECL_EXPORT QStringList whitelistedMountArguments(); #endif /** * Find the mount executable on the system. * * @returns the path of the mount executable. */ Q_DECL_EXPORT const QString findMountExecutable(); /** * Find the umount executable on the system. * * @returns the path of the umount executable. */ Q_DECL_EXPORT const QString findUmountExecutable(); /** * This function returns the directory where data is to be placed. * @returns the data location */ Q_DECL_EXPORT const QString dataLocation(); }; #endif