File indexing completed on 2024-10-13 04:31:35

0001 /*
0002     This class provides the network search toolbar.
0003 
0004     SPDX-FileCopyrightText: 2018-2023 Alexander Reinholdt <alexander.reinholdt@kdemail.net>
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef SMB4KNETWORKSEARCHTOOLBAR_H
0009 #define SMB4KNETWORKSEARCHTOOLBAR_H
0010 
0011 // application specific includes
0012 #include "core/smb4kglobal.h"
0013 
0014 // Qt includes
0015 #include <QList>
0016 #include <QListIterator>
0017 #include <QToolBar>
0018 
0019 // KDE includes
0020 #include <KComboBox>
0021 #include <KDualAction>
0022 
0023 class Smb4KNetworkSearchToolBar : public QToolBar
0024 {
0025     Q_OBJECT
0026 
0027 public:
0028     /**
0029      * Constructor
0030      */
0031     Smb4KNetworkSearchToolBar(QWidget *parent = nullptr);
0032 
0033     /**
0034      * Destructor
0035      */
0036     ~Smb4KNetworkSearchToolBar();
0037 
0038     /**
0039      * Sets the focus to the search combo box
0040      */
0041     void prepareInput();
0042 
0043     /**
0044      * Set the active state
0045      *
0046      * @param active          The state
0047      */
0048     void setActiveState(bool active);
0049 
0050     /**
0051      * Set the search result
0052      *
0053      * @param list            The list of search results
0054      */
0055     void setSearchResults(const QList<SharePtr> &list);
0056 
0057     /**
0058      * Clear the search
0059      */
0060     void clearSearch();
0061 
0062     /**
0063      * Set the completion items. This function should be invoked before the
0064      * search toolbar is shown.
0065      *
0066      * @param items         The list of completion strings
0067      */
0068     void setCompletionItems(const QStringList &items);
0069 
0070     /**
0071      * Get the completion strings.
0072      *
0073      * @returns the completion strings
0074      */
0075     QStringList completionItems() const;
0076 
0077 Q_SIGNALS:
0078     /**
0079      * Emitted when the search toolbar is to be closed (should be hidden)
0080      */
0081     void closeSearchBar();
0082 
0083     /**
0084      * Emitted when a search should be done
0085      */
0086     void search(const QString &item);
0087 
0088     /**
0089      * Emitted when a search should be stopped
0090      */
0091     void abort();
0092 
0093     /**
0094      * Emitted when either the up or down action was clicked
0095      */
0096     void jumpToResult(const QString &url);
0097 
0098     /**
0099      * Emitted when the search is cleared
0100      */
0101     void clearSearchResults();
0102 
0103 protected Q_SLOTS:
0104     /**
0105      * Called when the return key was pressed
0106      */
0107     void slotReturnKeyPressed(const QString &text);
0108 
0109     /**
0110      * Called when the search dual action is toggled
0111      */
0112     void slotSearchActionTriggered();
0113 
0114     /**
0115      * Called when the close button was pressed
0116      */
0117     void slotCloseButtonPressed();
0118 
0119     /**
0120      * Called when the down action was triggered
0121      */
0122     void slotDownActionTriggered();
0123 
0124     /**
0125      * Called when the up action was triggered
0126      */
0127     void slotUpActionTriggered();
0128 
0129     /**
0130      * Called when the search is cleared
0131      */
0132     void slotClearSearch();
0133 
0134 private:
0135     QStringList m_searchResults;
0136     QStringListIterator m_iterator;
0137     KComboBox *m_searchComboBox;
0138     KDualAction *m_searchAction;
0139     QAction *m_downAction;
0140     QAction *m_upAction;
0141     QAction *m_clearAction;
0142 };
0143 
0144 #endif