File indexing completed on 2024-12-15 04:54:44

0001 /******************************************************************************
0002  *
0003  *  SPDX-FileCopyrightText: 2008 Szymon Tomasz Stefanek <pragma@kvirc.net>
0004  *
0005  *  SPDX-License-Identifier: GPL-2.0-or-later
0006  *
0007  *******************************************************************************/
0008 
0009 #pragma once
0010 
0011 #include <QString>
0012 #include <QWidget>
0013 
0014 #include <MessageList/Enums>
0015 #include <MessageList/QuickSearchLine>
0016 
0017 class QLineEdit;
0018 class QActionGroup;
0019 class QMenu;
0020 
0021 namespace Akonadi
0022 {
0023 class Collection;
0024 class MessageStatus;
0025 }
0026 
0027 namespace MessageList
0028 {
0029 namespace Core
0030 {
0031 class GroupHeaderItem;
0032 class MessageItem;
0033 class StorageModel;
0034 class View;
0035 class Filter;
0036 /**
0037  * Provides a widget which has the messagelist and the most important helper widgets,
0038  * like the search line and the comboboxes for changing status filtering, aggregation etc.
0039  */
0040 class Widget : public QWidget
0041 {
0042     friend class View;
0043 
0044     Q_OBJECT
0045 public:
0046     explicit Widget(QWidget *parent);
0047     ~Widget() override;
0048 
0049     /**
0050      * Sets the storage model for this Widget.
0051      *
0052      * Pre-selection is the action of automatically selecting a message just after the folder
0053      * has finished loading. See Model::setStorageModel() for more information.
0054      */
0055     void setStorageModel(StorageModel *storageModel, PreSelectionMode preSelectionMode = PreSelectLastSelected);
0056 
0057     /**
0058      * Returns the StorageModel currently set. May be nullptr.
0059      */
0060     StorageModel *storageModel() const;
0061 
0062     /**
0063      * Returns the search line of this widget. Can be nullptr if the quick search
0064      * is disabled in the global configuration.
0065      */
0066     QLineEdit *quickSearch() const;
0067 
0068     /**
0069      * Returns the View attached to this Widget. Never nullptr.
0070      */
0071     View *view() const;
0072 
0073     /**
0074      * Returns the current MessageItem in the current folder.
0075      * May return nullptr if there is no current message or no current folder.
0076      */
0077     Core::MessageItem *currentMessageItem() const;
0078 
0079     /**
0080      * Returns the Akonadi::MessageStatus in the current quicksearch field.
0081      */
0082     [[nodiscard]] QList<Akonadi::MessageStatus> currentFilterStatus() const;
0083 
0084     /**
0085      * Returns the search term in the current quicksearch field.
0086      */
0087     [[nodiscard]] QString currentFilterSearchString() const;
0088 
0089     /**
0090      * Returns the id of the MessageItem::Tag currently set in the quicksearch field.
0091      */
0092     [[nodiscard]] QString currentFilterTagId() const;
0093 
0094     /**
0095      * Sets the focus on the quick search line of the currently active tab.
0096      */
0097     void focusQuickSearch(const QString &selectedText);
0098 
0099     /**
0100      * Returns true if the current Aggregation is threaded, false otherwise
0101      * (or if there is no current Aggregation).
0102      */
0103     [[nodiscard]] bool isThreaded() const;
0104     /**
0105      * Fast function that determines if the selection is empty
0106      */
0107     [[nodiscard]] bool selectionEmpty() const;
0108 
0109     /**
0110      * Sets the current folder.
0111      */
0112     void setCurrentFolder(const Akonadi::Collection &collection);
0113     [[nodiscard]] Akonadi::Collection currentFolder() const;
0114 
0115     void saveCurrentSelection();
0116 
0117     [[nodiscard]] bool searchEditHasFocus() const;
0118 
0119     void sortOrderMenuAboutToShow(QMenu *menu);
0120     void themeMenuAboutToShow(QMenu *menu);
0121     void aggregationMenuAboutToShow(QMenu *menu);
0122 
0123     [[nodiscard]] MessageList::Core::QuickSearchLine::SearchOptions currentOptions() const;
0124     void setFilter(Filter *filter);
0125 public Q_SLOTS:
0126 
0127     /**
0128      * This is called to setup the status filter's QComboBox.
0129      */
0130     void populateStatusFilterCombo();
0131 
0132     /**
0133      * Shows or hides the quicksearch field, the filter combobox and the toolbutton for advanced search.
0134      */
0135     void changeQuicksearchVisibility(bool);
0136 
0137     void setLockTab(bool lock);
0138     [[nodiscard]] bool isLocked() const;
0139 
0140 protected:
0141     /**
0142      * Called when the "Message Status/Tag" filter menu is opened by the user.
0143      * You may override this function in order to add some "custom tag" entries
0144      * to the menu. The entries should be placed in a QActionGroup which should be returned
0145      * to the caller. The QAction objects associated to the entries should have
0146      * the string id of the tag set as data() and the tag icon set as icon().
0147      * The default implementation does nothing.
0148      *
0149      * Once the tag retrieval is complete call setCurrentStatusFilterItem()
0150      */
0151     virtual void fillMessageTagCombo();
0152 
0153     void addMessageTagItem(const QPixmap &, const QString &, const QVariant &);
0154 
0155     /**
0156      * Must be called by fillMessageTagCombo()
0157      */
0158     void setCurrentStatusFilterItem();
0159 
0160     /**
0161      * This is called by View when a message is single-clicked (thus selected and made current)
0162      */
0163     virtual void viewMessageSelected(MessageItem *msg);
0164 
0165     /**
0166      * This is called by View when a message is double-clicked or activated by other input means
0167      */
0168     virtual void viewMessageActivated(MessageItem *msg);
0169 
0170     /**
0171      * This is called by View when selection changes.
0172      */
0173     virtual void viewSelectionChanged();
0174 
0175     /**
0176      * This is called by View when a message is right clicked.
0177      */
0178     virtual void viewMessageListContextPopupRequest(const QList<MessageItem *> &selectedItems, const QPoint &globalPos);
0179 
0180     /**
0181      * This is called by View when a group header is right clicked.
0182      */
0183     virtual void viewGroupHeaderContextPopupRequest(GroupHeaderItem *group, const QPoint &globalPos);
0184 
0185     /**
0186      * This is called by View when a drag enter event is received
0187      */
0188     virtual void viewDragEnterEvent(QDragEnterEvent *e);
0189 
0190     /**
0191      * This is called by View when a drag move event is received
0192      */
0193     virtual void viewDragMoveEvent(QDragMoveEvent *e);
0194 
0195     /**
0196      * This is called by View when a drop event is received
0197      */
0198     virtual void viewDropEvent(QDropEvent *e);
0199 
0200     /**
0201      * This is called by View when a drag can possibly be started
0202      */
0203     virtual void viewStartDragRequest();
0204 
0205     /**
0206      * This is called by View when a message item is manipulated by the user
0207      * in a way that it's status should change. (e.g, by clicking on a status icon, for example).
0208      */
0209     virtual void viewMessageStatusChangeRequest(MessageItem *msg, Akonadi::MessageStatus set, Akonadi::MessageStatus clear);
0210 
0211     void tagIdSelected(const QVariant &data);
0212 
0213 Q_SIGNALS:
0214     /**
0215      * Notify the outside when updating the status bar with a message
0216      * could be useful
0217      */
0218     void statusMessage(const QString &message);
0219     void forceLostFocus();
0220     void unlockTabRequested();
0221 
0222 protected Q_SLOTS:
0223     /**
0224      * This is called by Manager when the option sets stored within have changed.
0225      */
0226     void aggregationsChanged();
0227 
0228     /**
0229      * This is called by Manager when the option sets stored within have changed.
0230      */
0231     void themesChanged();
0232 
0233     void themeMenuAboutToShow();
0234     void aggregationMenuAboutToShow();
0235     void themeSelected(bool);
0236     void configureThemes();
0237     void setPrivateSortOrderForStorage();
0238     void aggregationSelected(bool);
0239     void statusSelected(int index);
0240     void searchEditTextEdited();
0241     void searchTimerFired();
0242     void searchEditClearButtonClicked();
0243     void sortOrderMenuAboutToShow();
0244     void messageSortingSelected(QAction *action);
0245     void messageSortDirectionSelected(QAction *action);
0246     void groupSortingSelected(QAction *action);
0247     void groupSortDirectionSelected(QAction *action);
0248     void resetFilter();
0249 
0250     /**
0251      * Handles header section clicks switching the Aggregation MessageSorting on-the-fly.
0252      */
0253     void slotViewHeaderSectionClicked(int logicalIndex);
0254     void slotStatusButtonsClicked();
0255     void slotSaveFilter();
0256 
0257 private:
0258     void slotActivateFilter(Filter *f);
0259     class WidgetPrivate;
0260     std::unique_ptr<WidgetPrivate> const d;
0261 };
0262 } // namespace Core
0263 } // namespace MessageList