File indexing completed on 2024-05-05 04:47:21

0001 /****************************************************************************************
0002  * Copyright (c) 2008 Nikolaj Hald Nielsen <nhn@kde.org>                                *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #ifndef BOOKMARKGROUP_H
0018 #define BOOKMARKGROUP_H
0019 
0020 #include "AmarokUrl.h"
0021 #include "BookmarkViewItem.h"
0022 
0023 #include <QObject>
0024 #include <QString>
0025 #include <QStringList>
0026 
0027 #include "AmarokSharedPointer.h"
0028 
0029 class BookmarkGroup;
0030 class AmarokUrl;
0031 
0032 typedef AmarokSharedPointer<AmarokUrl> AmarokUrlPtr;
0033 typedef AmarokSharedPointer<BookmarkGroup> BookmarkGroupPtr;
0034 typedef QList<AmarokUrlPtr> BookmarkList;
0035 typedef QList<BookmarkGroupPtr> BookmarkGroupList;
0036 
0037 
0038 /**
0039 A class for allowing a "folder structure" in the bookmark browser and the database. Takes care of reading and writing  itself to the database.
0040 */
0041 class BookmarkGroup : public BookmarkViewItem
0042 {
0043     public:
0044         BookmarkGroup( const QStringList &dbResultRow, const BookmarkGroupPtr &parent );
0045         explicit BookmarkGroup( const QString &name, const BookmarkGroupPtr &parent = BookmarkGroupPtr() );
0046 
0047         BookmarkGroup( const QString &name, const QString &customType );
0048 
0049         ~BookmarkGroup() override;
0050 
0051         int id() const;
0052         QString name() const override;
0053         QString description() const override;
0054 
0055         int childCount() const override;
0056 
0057         BookmarkGroupPtr parent() const override { return m_parent; }
0058 
0059         void rename( const QString &name ) override;
0060         void setDescription( const QString &description ) override;
0061 
0062         void save();
0063         BookmarkGroupList childGroups() const;
0064         BookmarkList childBookmarks() const;
0065 
0066         void reparent( const BookmarkGroupPtr &parent );
0067 
0068         void clear();
0069 
0070         void deleteChild( const BookmarkViewItemPtr &item );
0071         void removeFromDb() override;
0072 
0073     private:
0074         int m_dbId;
0075         BookmarkGroupPtr m_parent;
0076         QString m_name;
0077         QString m_description;
0078         QString m_customType;
0079 
0080         mutable BookmarkGroupList m_childGroups;
0081         mutable BookmarkList m_childBookmarks;
0082 
0083         mutable bool m_hasFetchedChildGroups;
0084         mutable bool m_hasFetchedChildPlaylists;
0085 };
0086 
0087 Q_DECLARE_METATYPE( BookmarkGroupPtr )
0088 Q_DECLARE_METATYPE( AmarokUrlPtr )
0089 Q_DECLARE_METATYPE( BookmarkList )
0090 Q_DECLARE_METATYPE( BookmarkGroupList )
0091 
0092 #endif