File indexing completed on 2024-05-12 04:58:18

0001 /* ============================================================
0002 * Falkon - Qt web browser
0003 * Copyright (C) 2010-2014  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 SPEEDDIAL_H
0019 #define SPEEDDIAL_H
0020 
0021 #include <QObject>
0022 #include <QPointer>
0023 #include <QWebEnginePage>
0024 
0025 #include "qzcommon.h"
0026 
0027 class QUrl;
0028 class QPixmap;
0029 
0030 class AutoSaver;
0031 class PageThumbnailer;
0032 
0033 class FALKON_EXPORT SpeedDial : public QObject
0034 {
0035     Q_OBJECT
0036 public:
0037     struct Page {
0038         QString title;
0039         QString url;
0040 
0041         bool isValid() const {
0042             return !url.isEmpty();
0043         }
0044 
0045         bool operator==(const Page &other) const {
0046             return (this->title == other.title &&
0047                     this->url == other.url);
0048         }
0049     };
0050 
0051     explicit SpeedDial(QObject* parent = nullptr);
0052     ~SpeedDial();
0053 
0054     void loadSettings();
0055 
0056     Page pageForUrl(const QUrl &url);
0057     QUrl urlForShortcut(int key);
0058 
0059     void addPage(const QUrl &url, const QString &title);
0060     void removePage(const Page &page);
0061 
0062     int pagesInRow();
0063     int sdSize();
0064     bool sdCenter();
0065     bool lockDials();
0066 
0067     QString backgroundImage();
0068     QString backgroundImageUrl();
0069     QString backgroundImageSize();
0070     QString initialScript();
0071     QList<Page> pages();
0072 
0073 Q_SIGNALS:
0074     void pagesChanged();
0075     void thumbnailLoaded(const QString &url, const QString &src);
0076     void pageTitleLoaded(const QString &url, const QString &title);
0077 
0078 public Q_SLOTS:
0079     void changed(const QString &allPages);
0080     void loadThumbnail(const QString &url, bool loadTitle);
0081     void removeImageForUrl(const QString &url);
0082 
0083     QStringList getOpenFileName();
0084     QString urlFromUserInput(const QString &url);
0085     void setBackgroundImage(const QString &image);
0086     void setBackgroundImageSize(const QString &size);
0087     void setPagesInRow(int count);
0088     void setSdSize(int count);
0089     void setSdCentered(bool centered);
0090     void setLockDials(bool lockDials);
0091 
0092 private Q_SLOTS:
0093     void thumbnailCreated(const QPixmap &pixmap);
0094     void saveSettings();
0095 
0096 private:
0097     QString escapeTitle(QString string) const;
0098     QString escapeUrl(QString url) const;
0099 
0100     QString generateAllPages();
0101 
0102     QString m_initialScript;
0103     QString m_thumbnailsDir;
0104     QString m_backgroundImage;
0105     QString m_backgroundImageUrl;
0106     QString m_backgroundImageSize;
0107     int m_maxPagesInRow;
0108     int m_sizeOfSpeedDials;
0109     bool m_sdcentered;
0110     bool m_lockDials;
0111 
0112     QList<Page> m_pages;
0113     AutoSaver* m_autoSaver;
0114 
0115     bool m_loaded;
0116     bool m_regenerateScript;
0117 };
0118 
0119 #endif // SPEEDDIAL_H