File indexing completed on 2024-05-05 04:48:22
0001 /**************************************************************************************** 0002 * Copyright (c) 2004 Mark Kretschmann <kretschmann@kde.org> * 0003 * Copyright (c) 2004 Stefan Bogner <bochi@online.ms> * 0004 * Copyright (c) 2007 Dan Meltzer <parallelgrapefruit@gmail.com> * 0005 * Copyright (c) 2009 Martin Sandsmark <sandsmark@samfundet.no> * 0006 * * 0007 * This program is free software; you can redistribute it and/or modify it under * 0008 * the terms of the GNU General Public License as published by the Free Software * 0009 * Foundation; either version 2 of the License, or (at your option) any later * 0010 * version. * 0011 * * 0012 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0013 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0014 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0015 * * 0016 * You should have received a copy of the GNU General Public License along with * 0017 * this program. If not, see <http://www.gnu.org/licenses/>. * 0018 ****************************************************************************************/ 0019 0020 #ifndef AMAROK_COVERFOUNDDIALOG_H 0021 #define AMAROK_COVERFOUNDDIALOG_H 0022 0023 #include "core/meta/forward_declarations.h" 0024 #include "covermanager/CoverFetchUnit.h" 0025 #include "network/NetworkAccessManagerProxy.h" 0026 #include "widgets/BoxWidget.h" 0027 0028 #include <QProgressDialog> 0029 0030 #include <QLabel> 0031 #include <QList> 0032 #include <QListWidgetItem> 0033 #include <QObject> 0034 #include <QPointer> 0035 0036 class CoverFoundItem; 0037 class CoverFoundSideBar; 0038 class QDialog; 0039 class KJob; 0040 class KComboBox; 0041 class QListWidget; 0042 class QPushButton; 0043 class BoxWidget; 0044 class QTabWidget; 0045 0046 class CoverFoundDialog : public QDialog 0047 { 0048 Q_OBJECT 0049 0050 public: 0051 explicit CoverFoundDialog( const CoverFetchUnit::Ptr &unit, 0052 const CoverFetch::Metadata &data = CoverFetch::Metadata(), 0053 QWidget *parent = nullptr ); 0054 ~CoverFoundDialog() override; 0055 0056 /** 0057 * @returns the currently selected cover image 0058 */ 0059 const QImage image() const { return m_image; } 0060 0061 void setQueryPage( int page ); 0062 0063 const CoverFetchUnit::Ptr unit() const { return m_unit; } 0064 0065 Q_SIGNALS: 0066 void newCustomQuery( Meta::AlbumPtr album, const QString &query, int page ); 0067 0068 public Q_SLOTS: 0069 void add( const QImage &cover, 0070 const CoverFetch::Metadata &metadata, 0071 const CoverFetch::ImageSize imageSize = CoverFetch::NormalSize ); 0072 0073 protected: 0074 void hideEvent( QHideEvent *event ) override; 0075 0076 protected Q_SLOTS: 0077 void slotButtonClicked( int button ); 0078 0079 private Q_SLOTS: 0080 void addToCustomSearch( const QString &text ); 0081 void clearQueryButtonClicked(); 0082 void clearView(); 0083 void downloadProgressed( qint64 bytesReceived, qint64 bytesTotal ); 0084 void fetchRequestRedirected( QNetworkReply *oldReply, QNetworkReply *newReply ); 0085 void handleFetchResult( const QUrl &url, const QByteArray &data, const NetworkAccessManagerProxy::Error &e ); 0086 void insertComboText( const QString &text ); 0087 void currentItemChanged( QListWidgetItem *current, QListWidgetItem *previous ); 0088 void itemDoubleClicked( QListWidgetItem *item ); 0089 void itemMenuRequested( const QPoint &pos ); 0090 void processCurrentQuery(); // Same as processQuery( QString() ) 0091 void display(); ///< Opens a pixmap viewer 0092 void processQuery( const QString &input = QString() ); 0093 void saveAs(); 0094 void selectDiscogs(); 0095 void selectLastFm(); 0096 void selectGoogle(); 0097 void sortingTriggered( bool checked ); 0098 void updateSearchButton( const QString &text ); 0099 0100 private: 0101 void addToView( CoverFoundItem *item ); 0102 bool contains( const CoverFetch::Metadata &metadata ) const; 0103 bool fetchBigPix(); ///< returns true if full-size image is fetched successfully 0104 void sortCoversBySize(); 0105 void updateGui(); 0106 void updateTitle(); 0107 0108 CoverFoundSideBar *m_sideBar; //!< View of selected cover and its metadata 0109 KComboBox *m_search; //!< Custom search input 0110 QListWidget *m_view; //!< View of retrieved covers 0111 QPushButton *m_save; //!< Save Button 0112 QPushButton *m_searchButton; //!< Button to start search or get more results for last query 0113 Meta::AlbumPtr m_album; //!< Album associated with @ref m_unit; 0114 QAction *m_sortAction; //!< Action to sort covers by size 0115 QList< int > m_sortSizes; //!< List of sorted cover sizes used for indexing 0116 QImage m_image; //!< Currently selected cover image 0117 QString m_query; //!< Cache for the last entered custom query 0118 bool m_isSorted; //!< Are the covers sorted in the view? 0119 bool m_sortEnabled; //!< Sort covers by size 0120 const CoverFetchUnit::Ptr m_unit; //!< Cover fetch unit that initiated this dialog 0121 int m_queryPage; //!< Cache for the page number associated with @ref m_query 0122 QHash<QUrl, CoverFoundItem*> m_urls; //!< Urls hash for network access manager proxy 0123 QPointer<QProgressDialog> m_dialog; //!< Progress dialog for fetching big pix 0124 0125 Q_DISABLE_COPY( CoverFoundDialog ) 0126 }; 0127 0128 class CoverFoundSideBar : public BoxWidget 0129 { 0130 Q_OBJECT 0131 0132 public: 0133 explicit CoverFoundSideBar( const Meta::AlbumPtr &album, QWidget *parent = nullptr ); 0134 ~CoverFoundSideBar() override; 0135 0136 public Q_SLOTS: 0137 void clear(); 0138 void setPixmap( const QPixmap &pixmap, const CoverFetch::Metadata &metadata ); 0139 void setPixmap( const QPixmap &pixmap ); 0140 0141 private: 0142 Meta::AlbumPtr m_album; 0143 QLabel *m_notes; 0144 QLabel *m_cover; 0145 QPixmap m_pixmap; 0146 QTabWidget *m_tabs; 0147 QWidget *m_metaTable; 0148 CoverFetch::Metadata m_metadata; 0149 0150 void updateNotes(); 0151 void updateMetaTable(); 0152 void clearMetaTable(); 0153 0154 Q_DISABLE_COPY( CoverFoundSideBar ) 0155 }; 0156 0157 class CoverFoundItem : public QListWidgetItem 0158 { 0159 public: 0160 explicit CoverFoundItem( const QImage &cover, 0161 const CoverFetch::Metadata &data, 0162 const CoverFetch::ImageSize imageSize = CoverFetch::NormalSize, 0163 QListWidget *parent = nullptr ); 0164 ~CoverFoundItem() override; 0165 0166 const CoverFetch::Metadata metadata() const { return m_metadata; } 0167 const QImage bigPix() const { return m_bigPix; } 0168 const QImage thumb() const { return m_thumb; } 0169 0170 bool hasBigPix() const { return !m_bigPix.isNull(); } 0171 0172 void setBigPix( const QImage &image ) { m_bigPix = image; } 0173 0174 bool operator==( const CoverFoundItem &other ) const; 0175 bool operator!=( const CoverFoundItem &other ) const; 0176 0177 private: 0178 void setCaption(); 0179 0180 CoverFetch::Metadata m_metadata; 0181 QImage m_thumb; 0182 QImage m_bigPix; 0183 0184 Q_DISABLE_COPY( CoverFoundItem ) 0185 }; 0186 0187 #endif /* AMAROK_COVERFOUNDDIALOG_H */