File indexing completed on 2024-04-21 05:01:41
0001 /* 0002 This class provides the interface for Plasma and QtQuick 0003 0004 SPDX-FileCopyrightText: 2013-2023 Alexander Reinholdt <alexander.reinholdt@kdemail.net> 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef SMB4KDECLARATIVE_H 0009 #define SMB4KDECLARATIVE_H 0010 0011 // application specific includes 0012 #include "core/smb4kglobal.h" 0013 0014 // Qt includes 0015 #include <QObject> 0016 #include <QQmlListProperty> 0017 #include <QQmlListReference> 0018 #include <QUrl> 0019 0020 // forward declarations 0021 class Smb4KDeclarativePrivate; 0022 class Smb4KNetworkObject; 0023 class Smb4KBookmarkObject; 0024 class Smb4KProfileObject; 0025 0026 /** 0027 * This class provides the interface for programs written in QML to the core 0028 * classes of Smb4K. 0029 * 0030 * @author Alexander Reinholdt <alexander.reinholdt@kdemail.net> 0031 * @since 1.1.0 0032 */ 0033 0034 class Q_DECL_EXPORT Smb4KDeclarative : public QObject 0035 { 0036 Q_OBJECT 0037 0038 Q_PROPERTY(QQmlListProperty<Smb4KNetworkObject> workgroups READ workgroups NOTIFY workgroupsListChanged) 0039 Q_PROPERTY(QQmlListProperty<Smb4KNetworkObject> hosts READ hosts NOTIFY hostsListChanged) 0040 Q_PROPERTY(QQmlListProperty<Smb4KNetworkObject> shares READ shares NOTIFY sharesListChanged) 0041 Q_PROPERTY(QQmlListProperty<Smb4KNetworkObject> mountedShares READ mountedShares NOTIFY mountedSharesListChanged) 0042 Q_PROPERTY(QQmlListProperty<Smb4KBookmarkObject> bookmarks READ bookmarks NOTIFY bookmarksListChanged) 0043 Q_PROPERTY(QQmlListProperty<Smb4KBookmarkObject> bookmarkCategories READ bookmarkCategories NOTIFY bookmarksListChanged) 0044 Q_PROPERTY(QQmlListProperty<Smb4KProfileObject> profiles READ profiles NOTIFY profilesListChanged) 0045 Q_PROPERTY(QString activeProfile READ activeProfile WRITE setActiveProfile NOTIFY activeProfileChanged) 0046 Q_PROPERTY(bool profileUsage READ profileUsage NOTIFY profileUsageChanged) 0047 0048 friend class Smb4KDeclarativePrivate; 0049 0050 public: 0051 /** 0052 * Constructor 0053 */ 0054 explicit Smb4KDeclarative(QObject *parent = nullptr); 0055 0056 /** 0057 * Destructor 0058 */ 0059 virtual ~Smb4KDeclarative(); 0060 0061 /** 0062 * This function returns the list of workgroups. Basically, this is the 0063 * Smb4KGlobal::workgroupsList() list converted into a list of Smb4KNetworkItem 0064 * objects. 0065 * 0066 * @returns the list of discovered workgroups. 0067 */ 0068 QQmlListProperty<Smb4KNetworkObject> workgroups(); 0069 0070 /** 0071 * This function returns the list of hosts. Basically, this is the 0072 * Smb4KGlobal::hostsList() list converted into a list of Smb4KNetworkItem 0073 * objects. 0074 * 0075 * @returns the list of discovered hosts. 0076 */ 0077 QQmlListProperty<Smb4KNetworkObject> hosts(); 0078 0079 /** 0080 * This function returns the list of shares. Basically, this is the 0081 * Smb4KGlobal::sharesList() list converted into a list of Smb4KNetworkItem 0082 * objects. 0083 * 0084 * @returns the list of discovered shares. 0085 */ 0086 QQmlListProperty<Smb4KNetworkObject> shares(); 0087 0088 /** 0089 * This function returns the list of mounted shares. Basically, this is the 0090 * Smb4KGlobal::mountedSharesList() list converted into a list of Smb4KNetworkItem 0091 * objects. 0092 * 0093 * @returns the list of the mounted shares. 0094 */ 0095 QQmlListProperty<Smb4KNetworkObject> mountedShares(); 0096 0097 /** 0098 * This function returns the list of bookmarks. Basically, this is the 0099 * the list returned by Smb4KBookmarkHandler::bookmarksList() function 0100 * converted into a list of Smb4KBookmarkObject objects. 0101 * 0102 * @returns the list of bookmarks 0103 */ 0104 QQmlListProperty<Smb4KBookmarkObject> bookmarks(); 0105 0106 /** 0107 * This function returns the list of bookmark categories. Basically, this is the 0108 * the list returned by the Smb4KBookmarkHandler::categoryList() function 0109 * converted into a list of Smb4KBookmarkObject objects. 0110 * 0111 * @returns the list of bookmarks 0112 */ 0113 QQmlListProperty<Smb4KBookmarkObject> bookmarkCategories(); 0114 0115 /** 0116 * This function returns the list of profiles. Basically, this is the list 0117 * returned by the Smb4KProfileManager::profilesList() converted into a list 0118 * of Smb4KProfileObject objects. 0119 * 0120 * @returns the list of profiles 0121 */ 0122 QQmlListProperty<Smb4KProfileObject> profiles(); 0123 0124 /** 0125 * This function takes a Smb4KNetworkObject object and initiates a network 0126 * scan. If you pass a NULL pointer, a network scan will be performed. 0127 * 0128 * Please note that this function only works with network objects that are 0129 * already known. All others will be ignored. 0130 * 0131 * @param object The network object 0132 */ 0133 Q_INVOKABLE void lookup(Smb4KNetworkObject *object = nullptr); 0134 0135 /** 0136 * This function takes a QUrl object, looks up the respective network object 0137 * and returns it. If there is not such an object, NULL is returned. 0138 * 0139 * Please note that this function only works with network objects that are 0140 * already known. All others will be ignored. 0141 * 0142 * @param url The URL of the network item 0143 * 0144 * @param type The type of the network item 0145 * 0146 * @returns The network item or NULL if it was not found. 0147 */ 0148 Q_INVOKABLE Smb4KNetworkObject *findNetworkItem(const QUrl &url, int type); 0149 0150 /** 0151 * Open the mount dialog to mount a share. 0152 */ 0153 Q_INVOKABLE void openMountDialog(); 0154 0155 /** 0156 * This function takes a network object and initiates the mounting of 0157 * the remote share. 0158 * 0159 * Please note that this function only works with network objects that 0160 * represent a share and that are already known, i.e. it must either be 0161 * a share that was already looked up during program run or one that was 0162 * bookmarked. 0163 * 0164 * @param object The network object 0165 */ 0166 Q_INVOKABLE void mountShare(Smb4KNetworkObject *object); 0167 0168 /** 0169 * This function takes a bookmark object and initiates the mounting of 0170 * the respective remote share. 0171 * 0172 * @param object The bookmark object 0173 */ 0174 Q_INVOKABLE void mountBookmark(Smb4KBookmarkObject *object); 0175 0176 /** 0177 * This function takes a network object and initiates the unmounting of 0178 * the mounted share. 0179 * 0180 * Please note that this function only works with network objects that 0181 * represent a share and that are already known. 0182 * 0183 * @param object The network object 0184 */ 0185 Q_INVOKABLE void unmount(Smb4KNetworkObject *object); 0186 0187 /** 0188 * This function is a convenience function. It unmounts all currently mounted 0189 * shares by invoking @see unmountAllShares(0). 0190 */ 0191 Q_INVOKABLE void unmountAll(); 0192 0193 /** 0194 * This function takes a QUrl object and checks if a share with this URL 0195 * is mounted. Returns nullptr if there is no such share. 0196 * 0197 * @param url The URL to check 0198 */ 0199 Q_INVOKABLE bool isShareMounted(const QUrl &url); 0200 0201 /** 0202 * This function takes a network object representing a remote printer and 0203 * initiates the printing of a file. 0204 * 0205 * Please note that this function only works with share objects that are 0206 * already known. All others will be ignored. 0207 * 0208 * @param object The network object representing a remote printer 0209 */ 0210 Q_INVOKABLE void print(Smb4KNetworkObject *object); 0211 0212 /** 0213 * This function adds a new bookmark. 0214 * 0215 * @param object The network object that is to be bookmarked 0216 */ 0217 Q_INVOKABLE void addBookmark(Smb4KNetworkObject *object); 0218 0219 /** 0220 * This function removes a bookmark. 0221 * 0222 * @param url The bookmark object that is to be removed 0223 */ 0224 Q_INVOKABLE void removeBookmark(Smb4KBookmarkObject *object); 0225 0226 /** 0227 * This function opens the bookmark editor. 0228 */ 0229 Q_INVOKABLE void editBookmarks(); 0230 0231 /** 0232 * This function starts the synchronization of a local and a 0233 * remote folder. 0234 */ 0235 Q_INVOKABLE void synchronize(Smb4KNetworkObject *object); 0236 0237 /** 0238 * This function opens the custom options dialog. 0239 * 0240 * @param object The network object 0241 */ 0242 Q_INVOKABLE void openCustomOptionsDialog(Smb4KNetworkObject *object); 0243 0244 /** 0245 * This function starts the client 0246 */ 0247 Q_INVOKABLE void startClient(); 0248 0249 /** 0250 * This function stops the client 0251 */ 0252 Q_INVOKABLE void abortClient(); 0253 0254 /** 0255 * This function starts the mounter. 0256 */ 0257 Q_INVOKABLE void startMounter(); 0258 0259 /** 0260 * This function stops any action of the mounter. 0261 */ 0262 Q_INVOKABLE void abortMounter(); 0263 0264 /** 0265 * Return the currently active profile or an empty string if 0266 * the use of profiles is disabled. 0267 * 0268 * @returns the active profile. 0269 */ 0270 QString activeProfile() const; 0271 0272 /** 0273 * Set the active profile. 0274 * @param profile The name of the active profile 0275 */ 0276 void setActiveProfile(const QString &profile); 0277 0278 /** 0279 * Return the current setting of the profile usage. 0280 * 0281 * @returns the profile usage. 0282 */ 0283 bool profileUsage() const; 0284 0285 /** 0286 * Open the preview dialog with the contents of the passed network 0287 * item. 0288 * @param object The network object 0289 */ 0290 Q_INVOKABLE void preview(Smb4KNetworkObject *object); 0291 0292 /** 0293 * Open the configuration dialog of the main application 0294 */ 0295 Q_INVOKABLE void openConfigurationDialog(); 0296 0297 protected: 0298 /** 0299 * Reimplemented from QObject 0300 */ 0301 void timerEvent(QTimerEvent *event) override; 0302 0303 Q_SIGNALS: 0304 /** 0305 * This signal is emitted when the list of workgroups changed. 0306 */ 0307 void workgroupsListChanged(); 0308 0309 /** 0310 * This signal is emitted when the list of hosts changed. 0311 */ 0312 void hostsListChanged(); 0313 0314 /** 0315 * This signal is emitted when the list of shares changed. 0316 */ 0317 void sharesListChanged(); 0318 0319 /** 0320 * This signal is emitted when the list of mounted shares changed. 0321 */ 0322 void mountedSharesListChanged(); 0323 0324 /** 0325 * This signal is emitted when the list of bookmarks changed. 0326 */ 0327 void bookmarksListChanged(); 0328 0329 /** 0330 * This signal is emitted when the list of profiles changed. 0331 */ 0332 void profilesListChanged(); 0333 0334 /** 0335 * This signal is emitted when the active profile changed. 0336 */ 0337 void activeProfileChanged(); 0338 0339 /** 0340 * This signal is emitted when the profile usage changed. 0341 */ 0342 void profileUsageChanged(); 0343 0344 /** 0345 * This signal is emitted, when one of the core classes becomes 0346 * busy. 0347 */ 0348 void busy(); 0349 0350 /** 0351 * This signal is emitted, when one of the core signals becomes 0352 * idle. 0353 */ 0354 void idle(); 0355 0356 protected Q_SLOTS: 0357 /** 0358 * This slot is invoked, when the list of workgroups was changed by 0359 * the scanner. It rebuilds the workgroups() list and emits the 0360 * worgroupsListChanged() signal. 0361 */ 0362 void slotWorkgroupsListChanged(); 0363 0364 /** 0365 * This slot is invoked, when the list of hosts was changed by the 0366 * scanner. It rebuilds the hosts() list and emits the hostsListChanged() 0367 * signal. 0368 */ 0369 void slotHostsListChanged(); 0370 0371 /** 0372 * This slot is invoked, when the list of shares was changed by the 0373 * scanner. It rebuilds the shares() list and emits the sharesListChanged() 0374 * signal. 0375 */ 0376 void slotSharesListChanged(); 0377 0378 /** 0379 * This slot is invoked, when the list of mounted shares was changed 0380 * by the mounter. It rebuilds the mountedShares() list and emits the 0381 * mountedSharesListChanged() signal. 0382 */ 0383 void slotMountedSharesListChanged(); 0384 0385 /** 0386 * This slot is invoked when the list of bookmarks was changed. It 0387 * rebuilds the bookmarks and bookmark groups lists and emits the 0388 * bookmarksListChanged() signal. 0389 */ 0390 void slotBookmarksListChanged(); 0391 0392 /** 0393 * This slot is invoked when the list of profiles changed. It rebuils 0394 * the list of profiles and emits the profilesListChanged() signal. 0395 */ 0396 void slotProfilesListChanged(const QStringList &profiles); 0397 0398 /** 0399 * This slot is invoked when the active profile changed. It resets 0400 * the value for the active profile and emits the activeProfileChanged() 0401 * signal. 0402 */ 0403 void slotActiveProfileChanged(const QString &activeProfile); 0404 0405 /** 0406 * This slot is invoked when the profile usage changed. It resets 0407 * the value for the profile usage and emits the profileUsageChanged() 0408 * signal. 0409 */ 0410 void slotProfileUsageChanged(bool use); 0411 0412 /** 0413 * This slot is called when credentials are requested. 0414 * 0415 * @param networkItem The network item 0416 */ 0417 void slotCredentialsRequested(const NetworkItemPtr &networkItem); 0418 0419 private: 0420 const QScopedPointer<Smb4KDeclarativePrivate> d; 0421 }; 0422 0423 #endif