File indexing completed on 2025-01-19 03:53:22

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2014-05-17
0007  * Description : Album Labels Search Tree View.
0008  *
0009  * SPDX-FileCopyrightText: 2014-2015 by Mohamed_Anwer <m_dot_anwer at gmx dot com>
0010  * SPDX-FileCopyrightText: 2014-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #ifndef DIGIKAM_ALBUM_LABELS_SEARCH_HANDLER_H
0017 #define DIGIKAM_ALBUM_LABELS_SEARCH_HANDLER_H
0018 
0019 #include "labelstreeview.h"
0020 
0021 namespace Digikam
0022 {
0023 
0024 class AlbumLabelsSearchHandler : public QObject
0025 {
0026     Q_OBJECT
0027 
0028 public:
0029 
0030     explicit AlbumLabelsSearchHandler(LabelsTreeView* const treeWidget);
0031     ~AlbumLabelsSearchHandler() override;
0032 
0033     /**
0034      * @return Album pointer of the currently selected labels
0035      */
0036     Album* albumForSelectedItems()         const;
0037 
0038     /**
0039      * @brief Gets the list of images generated, for exporting
0040      *
0041      * @return QUrl List of images Urls
0042      */
0043     QList<QUrl> imagesUrls()               const;
0044 
0045     /**
0046      * @return A string for a name generated by @see
0047      *         generateAlbumNameForExporting()
0048      */
0049     QString generatedName()                const;
0050 
0051     /**
0052      * @brief Restores the selection of the tree-view from history
0053      *
0054      * @param neededLabels a hash to restore selection from it
0055      */
0056     void restoreSelectionFromHistory(const QHash<LabelsTreeView::Labels,
0057                                      QList<int> >& neededLabels);
0058 
0059     /**
0060      * @return true if the tree-view is restoring the selection state
0061      *         from history to block searching until the restoring
0062      *         is done
0063      */
0064     bool isRestoringSelectionFromHistory() const;
0065 
0066 private:
0067 
0068     /**
0069      * @brief Create XML for currently selected labels
0070      *
0071      * @param selectedLabels to generate XML for it
0072      * @return XML generated
0073      */
0074     QString createXMLForCurrentSelection(const QHash<LabelsTreeView::Labels, QList<int> >& selectedLabels);
0075 
0076     /**
0077      * @brief Passes the generated XML to CoreDB class
0078      *        search methods
0079      *
0080      * @param xml generated from @see createXMLForCurrentSelection
0081      * @return A pointer of the search album created by the CoreDB
0082      */
0083     SAlbum* search(const QString& xml)     const;
0084 
0085     /**
0086      * @brief Generates album name based on the selected labels for
0087      *        example if rating 2 and 5 are selected then the name is
0088      *        "Rating: 2, 5", If there are any selected picks for example
0089      *        Pending, then the generated name is "Rating: 2, 5 | Picks: Pending"
0090      */
0091     void generateAlbumNameForExporting(const QList<int>& ratings,
0092                                        const QList<int>& colorsList,
0093                                        const QList<int>& picksList);
0094 
0095     /**
0096      * @brief Passes the current album DB url to a DBJobsManager
0097      *        to get images urls in this album
0098      */
0099     void imagesUrlsForCurrentAlbum();
0100 
0101     /**
0102      * @return "Labels Album" if the tree-widget is not checkable
0103      *         and returns "Exporting Album" if it was checkable
0104      */
0105     QString getDefaultTitle()              const;
0106 
0107 private Q_SLOTS:
0108 
0109     void slotSelectionChanged();
0110     void slotCheckStateChanged();
0111     void slotSetCurrentAlbum();
0112     void slotResult();
0113     void slotData(const QList<ItemListerRecord>& data);
0114 
0115 Q_SIGNALS:
0116 
0117     void checkStateChanged(Album* album, Qt::CheckState checkState);
0118 
0119 private:
0120 
0121     class Private;
0122     Private* const d;
0123 };
0124 
0125 } // namespace Digikam
0126 
0127 #endif // DIGIKAM_ALBUM_LABELS_SEARCH_HANDLER_H