File indexing completed on 2024-04-21 15:42:44

0001 /***************************************************************************
0002     This class provides the interface to the libsmbclient library.
0003                              -------------------
0004     begin                : Sa Oct 20 2018
0005     copyright            : (C) 2018-2019 by Alexander Reinholdt
0006     email                : alexander.reinholdt@kdemail.net
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *   This program is free software; you can redistribute it and/or modify  *
0011  *   it under the terms of the GNU General Public License as published by  *
0012  *   the Free Software Foundation; either version 2 of the License, or     *
0013  *   (at your option) any later version.                                   *
0014  *                                                                         *
0015  *   This program is distributed in the hope that it will be useful, but   *
0016  *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
0017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
0018  *   General Public License for more details.                              *
0019  *                                                                         *
0020  *   You should have received a copy of the GNU General Public License     *
0021  *   along with this program; if not, write to the                         *
0022  *   Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,*
0023  *   MA 02110-1335, USA                                                    *
0024  ***************************************************************************/
0025 
0026 #ifndef SMB4KCLIENT_H
0027 #define SMB4KCLIENT_H
0028 
0029 // application specific includes
0030 #include "smb4kglobal.h"
0031 
0032 // Qt includes
0033 #include <QScopedPointer>
0034 
0035 // KDE includes
0036 #include <KCoreAddons/KCompositeJob>
0037 #include <KIOCore/KFileItem>
0038 
0039 // forward declarations
0040 class Smb4KClientPrivate;
0041 class Smb4KBasicNetworkItem;
0042 class Smb4KClientJob;
0043 class Smb4KPreviewDialog;
0044 class Smb4KPrintDialog;
0045 
0046 class Q_DECL_EXPORT Smb4KClient : public KCompositeJob
0047 {
0048   Q_OBJECT
0049   
0050   public:
0051     /**
0052      * The constructor
0053      */
0054     explicit Smb4KClient(QObject *parent = 0);
0055     
0056     /**
0057      * The destructor
0058      */
0059     ~Smb4KClient();
0060     
0061     /**
0062      * This function returns a static pointer to this class.
0063      *
0064      * @returns a static pointer to the Smb4KClient class.
0065      */
0066     static Smb4KClient *self();
0067     
0068     /**
0069      * This function starts the composite job
0070      */
0071     void start() override;
0072     
0073     /**
0074      * Returns TRUE, if jobs are running and FALSE otherwise
0075      * 
0076      * @returns TRUE if jobs are running
0077      */
0078     bool isRunning();
0079     
0080     /**
0081      * Aborts all subjobs
0082      */
0083     void abort();
0084     
0085     /**
0086      * This function starts the scan for all available workgroups and domains
0087      * on the network neighborhood.
0088      */
0089     void lookupDomains();
0090     
0091     /**
0092      * This function looks up all hosts in a certain domain or workgroup.
0093      * 
0094      * @param workgroup       The workgroup object
0095      */
0096     void lookupDomainMembers(const WorkgroupPtr &workgroup);
0097     
0098     /**
0099      * This function looks up all shared resources a certain @p host provides.
0100      * 
0101      * @param host            The host object
0102      */
0103     void lookupShares(const HostPtr &host);
0104     
0105     /**
0106      * This function looks up all files and directories present at the location
0107      * @p item points to. The network item must be of type Smb4KGlobal::Share or
0108      * Smb4KGlobal::Directory.
0109      * 
0110      * @param item            The network item object
0111      */
0112     void lookupFiles(const NetworkItemPtr &item);
0113     
0114     /**
0115      * This function starts the printing of a file @p file to the printer share
0116      * @p printer.
0117      *
0118      * @param share           The printer share
0119      * 
0120      * @param fileItem        The file item
0121      * 
0122      * @param copies          Number of copies
0123      */
0124     void printFile(const SharePtr &share, const KFileItem &fileItem, int copies);
0125     
0126     /**
0127      * Perform a search on the entire network neighborhood
0128      * 
0129      * @param item            The search item
0130      */
0131     void search(const QString &item);
0132     
0133     /**
0134      * This function opens the preview dialog for @p share.
0135      * 
0136      * @param share           The share object
0137      */
0138     void openPreviewDialog(const SharePtr &share);
0139     
0140     /**
0141      * This function opens the print dialog for @p share.
0142      * 
0143      * @param share           The share object (printer only)
0144      */
0145     void openPrintDialog(const SharePtr &share);
0146     
0147   Q_SIGNALS:
0148     /**
0149      * This signal is emitted when the client starts its work.
0150      * 
0151      * @param item          The network item
0152      * @param type          The type of work
0153      */
0154     void aboutToStart(const NetworkItemPtr &item, int type);
0155     
0156     /**
0157      * This signal is emitted when the client finished its work.
0158      * 
0159      * @param item          The network item
0160      * @param type          The type of work
0161      */
0162     void finished(const NetworkItemPtr &item, int type);
0163     
0164     /**
0165      * Emitted when the requested list of workgroups was acquired
0166      */
0167     void workgroups();
0168     
0169     /**
0170      * Emitted when the requested list of workgroup members was acquired
0171      * 
0172      * @param workgroup     The workgroup that was queried
0173      */
0174     void hosts(const WorkgroupPtr &workgroup);
0175     
0176     /**
0177      * Emitted when the requested list of shares was acquired
0178      * 
0179      * @param host          The host that was queried
0180      */
0181     void shares(const HostPtr &host);
0182     
0183     /**
0184      * Emitted when the requested list of files and directories was acquired
0185      * 
0186      * @param list          The list of files and directories
0187      */
0188     void files(const QList<FilePtr> &list);
0189     
0190     /**
0191      * Emitted when a search was done
0192      * 
0193      * @param list          The list of search results
0194      */
0195     void searchResults(const QList<SharePtr> &list);
0196     
0197   protected Q_SLOTS:
0198     /**
0199      * Start the composite job
0200      */
0201     void slotStartJobs();
0202     
0203     /**
0204      * Called when a job finished. Reimplemented from KCompositeJob.
0205      */
0206     void slotResult(KJob *job) override;
0207     
0208     /**
0209      * Called when the application is about to be closed
0210      */
0211     void slotAboutToQuit();
0212     
0213     /**
0214      * Start a network query
0215      */
0216     void slotStartNetworkQuery(NetworkItemPtr item);
0217     
0218     /**
0219      * Called when a preview dialog closed
0220      */
0221     void slotPreviewDialogClosed(Smb4KPreviewDialog *dialog);
0222     
0223     /**
0224      * Called when a process should be aborted
0225      */
0226     void slotAbort();
0227     
0228     /**
0229      * Called when a file is about to be printed
0230      */
0231     void slotStartPrinting(const SharePtr &printer, const KFileItem &fileItem, int copies);
0232     
0233     /**
0234      * Called when a print dialog closed
0235      */
0236     void slotPrintDialogClosed(Smb4KPrintDialog *dialog);
0237     
0238   private:
0239     /**
0240      * Process errors
0241      */
0242     void processErrors(Smb4KClientJob *job);
0243     
0244     /**
0245      * Process the domains/workgroups retrieved from the network
0246      * 
0247      * @param job             The client job
0248      */
0249     void processWorkgroups(Smb4KClientJob *job);
0250     
0251     /**
0252      * Process the domain/workgroup members
0253      * 
0254      * @param job             The client job
0255      */
0256     void processHosts(Smb4KClientJob *job);
0257     
0258     /**
0259      * Process the shares
0260      * 
0261      * @param job             The client job
0262      */
0263     void processShares(Smb4KClientJob *job);
0264     
0265     /**
0266      * Process the files and directories
0267      * 
0268      * @param job             The client job
0269      */
0270     void processFiles(Smb4KClientJob *job);
0271       
0272     /**
0273      * Pointer to the Smb4KClientPrivate class
0274      */
0275     QScopedPointer<Smb4KClientPrivate> d;
0276 };
0277 
0278 #endif
0279