File indexing completed on 2024-12-22 04:41:07

0001 /* ============================================================
0002 * Falkon - Qt web browser
0003 * Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
0004 *
0005 * This program is free software: you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, either version 3 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 * ============================================================ */
0018 #ifndef LOCATIONCOMPLETER_H
0019 #define LOCATIONCOMPLETER_H
0020 
0021 #include <QObject>
0022 
0023 #include "qzcommon.h"
0024 
0025 class QUrl;
0026 class QModelIndex;
0027 
0028 class LocationBar;
0029 class LoadRequest;
0030 class BrowserWindow;
0031 class OpenSearchEngine;
0032 class LocationCompleterModel;
0033 class LocationCompleterView;
0034 
0035 class FALKON_EXPORT LocationCompleter : public QObject
0036 {
0037     Q_OBJECT
0038 public:
0039     explicit LocationCompleter(QObject* parent = nullptr);
0040 
0041     void setMainWindow(BrowserWindow* window);
0042     void setLocationBar(LocationBar* locationBar);
0043 
0044     bool isVisible() const;
0045     void closePopup();
0046 
0047 public Q_SLOTS:
0048     void complete(const QString &string);
0049     void showMostVisited();
0050 
0051 Q_SIGNALS:
0052     void showCompletion(const QString &completion, bool completeDomain);
0053     void showDomainCompletion(const QString &completion);
0054     void clearCompletion();
0055     void popupClosed();
0056     void cancelRefreshJob();
0057     void loadRequested(const LoadRequest &request);
0058 
0059 private Q_SLOTS:
0060     void refreshJobFinished();
0061     void slotPopupClosed();
0062     void addSuggestions(const QStringList &suggestions);
0063 
0064     void currentChanged(const QModelIndex &index);
0065     void indexActivated(const QModelIndex &index);
0066     void indexCtrlActivated(const QModelIndex &index);
0067     void indexShiftActivated(const QModelIndex &index);
0068     void indexDeleteRequested(const QModelIndex &index);
0069 
0070 private:
0071     LoadRequest createLoadRequest(const QModelIndex &index);
0072     void switchToTab(BrowserWindow* window, int tab);
0073     void loadRequest(const LoadRequest &reqeust);
0074     void openSearchEnginesDialog();
0075 
0076     void showPopup();
0077     void adjustPopupSize();
0078 
0079     BrowserWindow* m_window;
0080     LocationBar* m_locationBar;
0081     qint64 m_lastRefreshTimestamp;
0082     bool m_popupClosed;
0083     bool m_ignoreCurrentChanged = false;
0084     OpenSearchEngine* m_openSearchEngine = nullptr;
0085     QStringList m_oldSuggestions;
0086     QString m_suggestionsTerm;
0087 
0088     static LocationCompleterView* s_view;
0089     static LocationCompleterModel* s_model;
0090 };
0091 
0092 #endif // LOCATIONCOMPLETER_H