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

0001 /****************************************************************************************
0002  * Copyright (c) 2009 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 BROWSERCATEGORY_H
0018 #define BROWSERCATEGORY_H
0019 
0020 #include "amarok_export.h"
0021 #include "BrowserDefines.h"
0022 #include "widgets/BoxWidget.h"
0023 
0024 #include <QIcon>
0025 
0026 class BrowserBreadcrumbItem;
0027 class BrowserCategoryList;
0028 
0029 /**
0030  * The base class of browsers, services, categories or any other widget that can be inserted into a CategoryList
0031  *
0032  * @author Nikolaj Hald Nielsen <nhn@kde.org>
0033 */
0034 class AMAROK_EXPORT BrowserCategory : public BoxWidget
0035 {
0036     Q_OBJECT
0037 
0038 public:
0039 
0040     /**
0041      * Constructor.
0042      *
0043      * @param name The internal name of the category, used for generating Amarok urls. This should never be translated.
0044      * @param parent The parent widget.
0045      */
0046     explicit BrowserCategory( const QString &name, QWidget *parent = nullptr );
0047 
0048     /**
0049      * Destructor.
0050      */
0051     ~BrowserCategory() override;
0052 
0053     /**
0054      * Get the internal name of this category.
0055      *
0056      * @return The name.
0057      */
0058     QString name() const;
0059 
0060     /**
0061      * Set the user visible name of this category
0062      * @param prettyName The user visible name.
0063      */
0064     void setPrettyName( const QString &prettyName );
0065 
0066     /**
0067      * Get the user visible name of this category.
0068      * @return The name of the service.
0069      */
0070     virtual QString prettyName() const;
0071 
0072     /**
0073      * Set a short description string for this category. This string is used to describe the category in the category browser.
0074      * @param shortDescription The description.
0075      */
0076     void setShortDescription( const QString &shortDescription );
0077 
0078     /**
0079      * Get the short description of this category.
0080      * @return The short description.
0081      */
0082     QString shortDescription() const;
0083 
0084     /**
0085      * Set a long description of the category. This is for allowing users to get more detailed info a about a category.
0086      * @param longDescription The long description.
0087      */
0088     void setLongDescription( const QString &longDescription );
0089 
0090     /**
0091      * Get the long description of this category.
0092      * @return The long description.
0093      */
0094     QString longDescription() const;
0095 
0096     /**
0097      * Set the icon that will be used to identify this category.
0098      * @param icon The icon to use.
0099      */
0100     void setIcon( const QIcon &icon );
0101 
0102     /**
0103      * Get the icon of this category.
0104      * @return The icon
0105      */
0106     QIcon icon() const;
0107 
0108     /**
0109      * Set the background image of this browser widget
0110      *
0111      * \param path Fully qualified path (e.g. looked up with KStandardDirs::locate)
0112      */
0113     void setBackgroundImage( const QString &path );
0114 
0115     /**
0116      * Set the path of the imaged used in the presentation of this category.
0117      * @param path The path of the image to use.
0118      */
0119     void setImagePath( const QString &path );
0120 
0121     /**
0122      * Get the path of the image used in the presentation of this category.
0123      * @return The path of the image.
0124      */
0125     QString imagePath() const;
0126 
0127     BrowserCategoryList * parentList() const;
0128     void setParentList( BrowserCategoryList * parent );
0129 
0130     /**
0131      * Returns an item that will be added to the breadcrumb widget
0132      * if this category is selected.
0133      *
0134      * The caller will have to free the returned item.
0135      */
0136     BrowserBreadcrumbItem* breadcrumb();
0137 
0138     virtual void polish() {}
0139     virtual void setupAddItems() {}
0140 
0141     //These 2 functions are forwarded to simplify the creation of urls
0142     //even though they might not be needed in many cases.
0143     virtual QString filter() const { return QString(); }
0144     virtual QList<CategoryId::CatMenuId> levels() const { return QList<CategoryId::CatMenuId>(); }
0145 
0146     virtual void setFilter( const QString &filter ) { Q_UNUSED( filter ) };
0147     virtual void setLevels( const QList<CategoryId::CatMenuId> &levels ) { Q_UNUSED( levels ) };
0148 
0149     /**
0150      * Add an additional category-specific item to breadcrumbs. This BrowserCategory
0151      * takes ownership of the item.
0152      */
0153     void addAdditionalItem( BrowserBreadcrumbItem *item );
0154     void clearAdditionalItems();
0155 
0156     QList<BrowserBreadcrumbItem *> additionalItems();
0157 
0158 public Q_SLOTS:
0159     void activate();
0160 
0161     //Called if this category itself is re-clicked in the breadcrumb
0162     virtual void reActivate() {}
0163 
0164 private Q_SLOTS:
0165     void slotSettingsChanged();
0166 
0167 private:
0168     QString m_name;
0169     QString m_prettyName;
0170     QString m_shortDescription;
0171     QString m_longDescription;
0172     QIcon   m_icon;
0173     QString m_imagePath;
0174     BrowserCategoryList * m_parentList;
0175 
0176     QList<BrowserBreadcrumbItem *> m_additionalItems;
0177 
0178 };
0179 
0180 #endif