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

0001 /***************************************************************************
0002     This class handles the bookmarks.
0003                              -------------------
0004     begin                : Fr Jan 9 2004
0005     copyright            : (C) 2004-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 SMB4KBOOKMARKHANDLER_H
0027 #define SMB4KBOOKMARKHANDLER_H
0028 
0029 // application specific includes
0030 #include "smb4kglobal.h"
0031 
0032 // Qt includes
0033 #include <QObject>
0034 #include <QList>
0035 #include <QScopedPointer>
0036 #include <QUrl>
0037 
0038 // forward declarations
0039 class Smb4KBookmark;
0040 class Smb4KBookmarkHandlerPrivate;
0041 class Smb4KBookmarkDialog;
0042 class Smb4KBookmarkEditor;
0043 class Smb4KProfileManager;
0044 
0045 
0046 /**
0047  * This class belongs the to core classes of Smb4K and manages the
0048  * bookmarks.
0049  *
0050  * @author         Alexander Reinholdt <alexander.reinholdt@kdemail.net>
0051  */
0052 
0053 class Q_DECL_EXPORT Smb4KBookmarkHandler : public QObject
0054 {
0055   Q_OBJECT  
0056   
0057   friend class Smb4KBookmarkHandlerPrivate;
0058   friend class Smb4KProfileManager;
0059 
0060   public:
0061     /**
0062      * The constructor.
0063      */
0064     explicit Smb4KBookmarkHandler(QObject *parent = 0);
0065 
0066     /**
0067      * The destructor.
0068      */
0069     ~Smb4KBookmarkHandler();
0070     
0071     /**
0072      * This function returns a static pointer to this class.
0073      *
0074      * @returns a static pointer to the Smb4KSynchronizer class.
0075      */
0076     static Smb4KBookmarkHandler *self();
0077     
0078     /**
0079      * This function adds a new bookmark.
0080      *
0081      * @param share         The share that is to be bookmarked.
0082      */
0083     void addBookmark(const SharePtr &share);
0084 
0085     /**
0086      * This function adds several bookmarks at once. It takes a list of 
0087      * shares and converts them internally to bookmark items.
0088      *
0089      * @param list          The list of shares that are to be bookmarked
0090      */
0091     void addBookmarks(const QList<SharePtr> &list);
0092     
0093     /**
0094      * This function adds several bookmarks at once. It takes a list of
0095      * Smb4KBookmark items.
0096      * 
0097      * @param list          The list of bookmarks that are to be bookmarked
0098      * 
0099      * @param replace       If TRUE the old list of bookmarks is replaced by
0100      *                      @p list.
0101      */
0102     void addBookmarks(const QList<BookmarkPtr> &list, bool replace = false);
0103     
0104     /**
0105      * Remove a bookmark.
0106      * 
0107      * @param bookmark      The bookmark that is to be removed
0108      */
0109     void removeBookmark(const BookmarkPtr &bookmark);
0110     
0111     /**
0112      * This function removes a group and all the bookmarks it contains.
0113      * 
0114      * @param name          The group name
0115      */
0116     void removeGroup(const QString &name);
0117 
0118     /**
0119      * Get the list of bookmarks.
0120      *
0121      * @returns             The current list of bookmarks stored in the
0122      *                      bookmark file.
0123      */
0124     QList<BookmarkPtr> bookmarksList() const;
0125     
0126     /**
0127      * Get the list of bookmarks belonging to a certain group.
0128      *
0129      * @param group         The name of the group the bookmarks are organized in
0130      *
0131      * @returns a list of bookmarks belonging to a certain group
0132      */
0133     QList<BookmarkPtr> bookmarksList(const QString &group) const;
0134     
0135     /**
0136      * This function searches for a bookmark using its URL and returns a pointer
0137      * to it if it is present or NULL.
0138      *
0139      * @param url           The URL of the bookmark that is searched.
0140      *
0141      * @returns the bookmark object that was searched for or NULL if it was not
0142      * found.
0143      */
0144     BookmarkPtr findBookmarkByUrl(const QUrl &url);
0145 
0146     /**
0147      * This function searches for a bookmark using its label and returns a pointer
0148      * to it if it is present or NULL.
0149      *
0150      * @param label         The label that is searched.
0151      *
0152      * @returns             The bookmark object that was searched for or NULL if it
0153      *                      wasn't found.
0154      */
0155     BookmarkPtr findBookmarkByLabel(const QString &label);
0156 
0157     /**
0158      * Returns the sorted list of bookmark groups.
0159      *
0160      * @returns the list of groups
0161      */
0162     QStringList groupsList() const;  
0163     
0164     /**
0165      * Reset the bookmarks by reloading them from the file.              
0166      */
0167     void resetBookmarks();
0168     
0169     /**
0170      * This function checks if the @p share is already bookmarked or not.
0171      * @param share         The share item
0172      * @returns TRUE if the share is bookmarked and FALSE otherwise.
0173      */
0174     bool isBookmarked(const SharePtr &share);
0175     
0176     /**
0177      * This function opens the bookmark editor.
0178      */
0179     void editBookmarks();
0180 
0181   Q_SIGNALS:
0182     /**
0183      * Signal emitted when the list of bookmarks has been updated.
0184      */
0185     void updated();
0186     
0187   private:
0188     /**
0189      * This function reads the list of bookmarks from the bookmarks file.
0190      */
0191     void readBookmarkList();
0192 
0193     /**
0194      * This function updates the data of the bookmarks, i.e. is searches for
0195      * the host provided by m_hosts and sets the appropriate data, if
0196      * necessary.
0197      */
0198     void update() const;
0199 
0200     /**
0201      * This function writes the bookmarks to the disk. 
0202      */
0203     void writeBookmarkList();
0204 
0205     /**
0206      * Migrates one profile to another.
0207      * 
0208      * This function is meant to be used by the profile manager.
0209      * 
0210      * @param from        The name of the old profile.
0211      * @param to          The name of the new profile.
0212      */
0213     void migrateProfile(const QString &from, const QString &to);
0214     
0215     /**
0216      * Removes a profile from the list of profiles.
0217      * 
0218      * This function is meant to be used by the profile manager.
0219      * 
0220      * @param name        The name of the profile.
0221      */
0222     void removeProfile(const QString &name);
0223     
0224     /**
0225      * Pointer to Smb4KBookmarkHandlerPrivate class
0226      */
0227     const QScopedPointer<Smb4KBookmarkHandlerPrivate> d;
0228 };
0229 
0230 #endif