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