File indexing completed on 2024-04-21 15:42:45
0001 /*************************************************************************** 0002 Private classes for the SMB client 0003 ------------------- 0004 begin : So Oct 21 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_P_H 0027 #define SMB4KCLIENT_P_H 0028 0029 // application specific includes 0030 #include "smb4kclient.h" 0031 #include "smb4kglobal.h" 0032 #include "smb4kworkgroup.h" 0033 #include "smb4khost.h" 0034 #include "smb4kshare.h" 0035 #include "smb4kfile.h" 0036 0037 // Samba includes 0038 #include <libsmbclient.h> 0039 0040 // Qt includes 0041 #include <QUrl> 0042 #include <QHostAddress> 0043 #include <QDialog> 0044 #include <QListWidgetItem> 0045 0046 // KDE includes 0047 #include <KCoreAddons/KJob> 0048 #include <KIOCore/KFileItem> 0049 0050 0051 class Smb4KClientJob : public KJob 0052 { 0053 Q_OBJECT 0054 0055 public: 0056 /** 0057 * Constructor 0058 */ 0059 explicit Smb4KClientJob(QObject *parent = 0); 0060 0061 /** 0062 * Destructor 0063 */ 0064 ~Smb4KClientJob(); 0065 0066 /** 0067 * Error enumeration 0068 * 0069 * @enum OutOfMemoryError Out of memory 0070 * @enum NullContextError The passed SMBCCTX context was a null pointer 0071 * @enum SmbConfError The smb.conf file could not be read 0072 * @enum AccessDeniedError Permission denied 0073 * @enum InvalidUrlError The URL that was passed is invalid 0074 * @enum NonExistentUrlError The URL does not exist 0075 * @enum NoDirectoryError The name is not a directory 0076 * @enum NetPermittedError The operation is not permitted 0077 * @enum NotFoundError The network item was not found 0078 * @enum FileAccessError The file could not be read 0079 * @enum OpenPrintJobError The printer share could not be opened 0080 * @enum PrintFileError The file could not be printed 0081 * @enum UnknownError Unknown error 0082 */ 0083 enum { 0084 OutOfMemoryError = UserDefinedError, 0085 NullContextError, 0086 SmbConfError, 0087 AccessDeniedError, 0088 InvalidUrlError, 0089 NonExistentUrlError, 0090 NoDirectoryError, 0091 NotPermittedError, 0092 NotFoundError, 0093 FileAccessError, 0094 OpenPrintJobError, 0095 PrintFileError, 0096 UnknownError 0097 }; 0098 0099 /** 0100 * Starts the job. 0101 */ 0102 void start() override; 0103 0104 /** 0105 * Set the basic network item 0106 */ 0107 void setNetworkItem(NetworkItemPtr item); 0108 0109 /** 0110 * Return the basic network item 0111 */ 0112 NetworkItemPtr networkItem() const; 0113 0114 /** 0115 * Set the process 0116 */ 0117 void setProcess(Smb4KGlobal::Process process); 0118 0119 /** 0120 * Return the process 0121 */ 0122 Smb4KGlobal::Process process() const; 0123 0124 /** 0125 * Set the file that is to be printed 0126 */ 0127 void setPrintFileItem(const KFileItem &item); 0128 0129 /** 0130 * Get the file that is to be printed 0131 */ 0132 KFileItem printFileItem() const; 0133 0134 /** 0135 * Set the number of copies that are to be printed 0136 */ 0137 void setPrintCopies(int copies); 0138 0139 /** 0140 * Get the number of copies that are to be printed 0141 */ 0142 int printCopies() const; 0143 0144 /** 0145 * The authentication function for libsmbclient 0146 */ 0147 void get_auth_data_fn(const char *server, 0148 const char *share, 0149 char *workgroup, 0150 int maxLenWorkgroup, 0151 char *username, 0152 int maxLenUsername, 0153 char *password, 0154 int maxLenPassword); 0155 /** 0156 * The list of workgroups that was discovered. 0157 */ 0158 QList<WorkgroupPtr> workgroups(); 0159 0160 /** 0161 * The list of hosts that was discovered. 0162 */ 0163 QList<HostPtr> hosts(); 0164 0165 /** 0166 * The list shares that was discovered. 0167 */ 0168 QList<SharePtr> shares(); 0169 0170 /** 0171 * The ist of files and directories that were discovered. 0172 */ 0173 QList<FilePtr> files(); 0174 0175 /** 0176 * The workgroup 0177 */ 0178 QString workgroup(); 0179 0180 protected Q_SLOTS: 0181 void slotStartJob(); 0182 0183 private: 0184 void doLookups(); 0185 void doPrinting(); 0186 QHostAddress lookupIpAddress(const QString &name); 0187 Smb4KGlobal::Process m_process; 0188 SMBCCTX *m_context; 0189 NetworkItemPtr m_item; 0190 QList<WorkgroupPtr> m_workgroups; 0191 QList<HostPtr> m_hosts; 0192 QList<SharePtr> m_shares; 0193 QList<FilePtr> m_files; 0194 KFileItem m_fileItem; 0195 int m_copies; 0196 }; 0197 0198 0199 class Smb4KPreviewDialog : public QDialog 0200 { 0201 Q_OBJECT 0202 0203 public: 0204 /** 0205 * Constructor 0206 */ 0207 Smb4KPreviewDialog(const SharePtr &share, QWidget *parent = 0); 0208 0209 /** 0210 * Destructor 0211 */ 0212 ~Smb4KPreviewDialog(); 0213 0214 /** 0215 * Returns the share that is previewed 0216 * 0217 * @returns the share 0218 */ 0219 SharePtr share() const; 0220 0221 Q_SIGNALS: 0222 /** 0223 * Request a preview 0224 */ 0225 void requestPreview(NetworkItemPtr item); 0226 0227 /** 0228 * Emitted when the dialog is about to close. 0229 */ 0230 void aboutToClose(Smb4KPreviewDialog *dialog); 0231 0232 /** 0233 * Emitted when the process should be aborted 0234 */ 0235 void requestAbort(); 0236 0237 protected Q_SLOTS: 0238 /** 0239 * Do last things before the dialog is closed 0240 */ 0241 void slotClosingDialog(); 0242 0243 /** 0244 * Reload 0245 */ 0246 void slotReloadActionTriggered(); 0247 0248 /** 0249 * Go up 0250 */ 0251 void slotUpActionTriggered(); 0252 0253 /** 0254 * An URL was activated in the combo box 0255 * 0256 * @param url The activated URL 0257 */ 0258 void slotUrlActivated(const QUrl &url); 0259 0260 /** 0261 * Process the selected item 0262 * 0263 * @param item The activated item 0264 */ 0265 void slotItemActivated(QListWidgetItem *item); 0266 0267 /** 0268 * Initialize the preview 0269 */ 0270 void slotInitializePreview(); 0271 0272 /** 0273 * Get the preview results and process them 0274 * 0275 * @param list The list of the preview results 0276 */ 0277 void slotPreviewResults(const QList<FilePtr> &list); 0278 0279 /** 0280 * Change the reload/abort dual action 0281 */ 0282 void slotAboutToStart(const NetworkItemPtr &item, int type); 0283 0284 /** 0285 * Change the reload/abort dual action back 0286 */ 0287 void slotFinished(const NetworkItemPtr &item, int type); 0288 0289 private: 0290 SharePtr m_share; 0291 NetworkItemPtr m_currentItem; 0292 QList<FilePtr> m_listing; 0293 }; 0294 0295 0296 class Smb4KPrintDialog : public QDialog 0297 { 0298 Q_OBJECT 0299 0300 public: 0301 /** 0302 * Constructor 0303 */ 0304 Smb4KPrintDialog(const SharePtr &share, QWidget *parent = 0); 0305 0306 /** 0307 * Destructor 0308 */ 0309 ~Smb4KPrintDialog(); 0310 0311 /** 0312 * Returns the share that is printed to 0313 * 0314 * @returns the share 0315 */ 0316 SharePtr share() const; 0317 0318 /** 0319 * Returns the file item that is to be printed 0320 * 0321 * @returns the file 0322 */ 0323 KFileItem fileItem() const; 0324 0325 Q_SIGNALS: 0326 /** 0327 * Emitted when a file is to be printed 0328 */ 0329 void printFile(const SharePtr &printer, const KFileItem &file, int copies); 0330 0331 /** 0332 * Emitted when the dialog is about to close 0333 */ 0334 void aboutToClose(Smb4KPrintDialog *dialog); 0335 0336 protected Q_SLOTS: 0337 /** 0338 * Print button was clicked 0339 */ 0340 void slotPrintButtonClicked(); 0341 0342 /** 0343 * Cancel button clicked 0344 */ 0345 void slotCancelButtonClicked(); 0346 0347 /** 0348 * Called when the URL was changed 0349 */ 0350 void slotUrlChanged(); 0351 0352 private: 0353 SharePtr m_share; 0354 KFileItem m_fileItem; 0355 }; 0356 0357 0358 class Smb4KClientPrivate 0359 { 0360 public: 0361 QList<Smb4KPreviewDialog *> previewDialogs; 0362 QList<Smb4KPrintDialog *> printDialogs; 0363 }; 0364 0365 0366 class Smb4KClientStatic 0367 { 0368 public: 0369 Smb4KClient instance; 0370 }; 0371 0372 #endif 0373 0374 0375