File indexing completed on 2024-04-28 05:10:59

0001 /*
0002     This file is part of Akregator.
0003 
0004     SPDX-FileCopyrightText: 2004 Stanislav Karchebny <Stanislav.Karchebny@kdemail.net>
0005     SPDX-FileCopyrightText: 2005 Frank Osterfeld <osterfeld@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
0008 */
0009 
0010 #pragma once
0011 
0012 #include <KSharedConfig>
0013 #include <QList>
0014 #include <QPointer>
0015 
0016 #include <QUrl>
0017 #include <kparts/part.h>
0018 
0019 #include "crashwidget/crashwidget.h"
0020 
0021 class KConfigGroup;
0022 class KCMultiDialog;
0023 
0024 class QTimer;
0025 
0026 namespace Akregator
0027 {
0028 namespace Backend
0029 {
0030 class Storage;
0031 }
0032 class Article;
0033 class ActionManagerImpl;
0034 class Feed;
0035 class FeedList;
0036 class LoadFeedListCommand;
0037 class MainWidget;
0038 class Part;
0039 class TrayIcon;
0040 class AkregatorCentralWidget;
0041 
0042 /**
0043     This is a RSS Aggregator "Part". It does all the real work.
0044     It is also embeddable into other applications (e.g. for use in Kontact).
0045     */
0046 class Part : public KParts::Part
0047 {
0048     Q_OBJECT
0049 public:
0050     /** Default constructor.*/
0051     explicit Part(QWidget *parentWidget, QObject *parent, const KPluginMetaData &data, const QVariantList &);
0052 
0053     /** Destructor. */
0054     ~Part() override;
0055 
0056     /** Opens standard feedlist */
0057     void openStandardFeedList();
0058 
0059     void fetchFeedUrl(const QString &);
0060 
0061     /** Fetch all feeds in the feed tree */
0062     void fetchAllFeeds();
0063 
0064     /**
0065         Add a feed to a group.
0066         @param urls The URLs of the feeds to add.
0067         @param group The name of the folder into which the feed is added.
0068         If the group does not exist, it is created.  The feed is added as the last member
0069         of the group.
0070         */
0071     void addFeedsToGroup(const QStringList &urls, const QString &group);
0072 
0073     void addFeed();
0074 
0075     /**
0076         This method is called when this app is restored.  The KConfig
0077         object points to the session management config file that was saved
0078         with @ref saveProperties
0079         Calls Akregator MainWidget's readProperties.
0080         */
0081     virtual void readProperties(const KConfigGroup &config);
0082 
0083     /** This method is called when it is time for the app to save its
0084         properties for session management purposes.
0085         Calls Akregator MainWidget's saveProperties. */
0086     virtual void saveProperties(KConfigGroup &config);
0087 
0088     void exportFile(const QString &str); /* for the DBus adaptor */
0089     void exportFile(const QUrl &url);
0090 
0091     bool handleCommandLine(const QStringList &args);
0092 
0093     KSharedConfig::Ptr config();
0094     void updateQuickSearchLineText();
0095 public Q_SLOTS:
0096     /** Used to save settings after changing them from configuration dialog. Calls AkregatorPart's saveSettings. */
0097     void saveSettings();
0098 
0099     /** Saves the standard feed list to it's default location */
0100     void slotSaveFeedList();
0101 
0102     void fileImport();
0103     void fileExport();
0104 
0105     /** Shows configuration dialog */
0106     void showOptions();
0107     void showNotificationOptions();
0108 
0109     /** Call to auto save */
0110     void slotAutoSave();
0111 
0112 Q_SIGNALS:
0113     void signalSettingsChanged();
0114     void signalArticlesSelected(const QList<Akregator::Article> &);
0115 
0116 private:
0117     /** @return Whether the tray icon is enabled or not */
0118     bool isTrayIconEnabled() const;
0119 
0120     void importFile(const QUrl &url);
0121 
0122     void openFile(const QString &filePath);
0123 
0124 private Q_SLOTS:
0125     void slotOnShutdown();
0126     void slotSettingsChanged();
0127     void slotSetStatusText(const QString &statusText);
0128 
0129     void feedListLoaded(const QSharedPointer<Akregator::FeedList> &list);
0130 
0131     void flushAddFeedRequests();
0132 
0133     void slotRestoreSession(Akregator::CrashWidget::CrashAction type);
0134 
0135 private: // methods
0136     /** fills the font settings with system fonts, if fonts are not set */
0137     void initFonts();
0138 
0139     bool writeToTextFile(const QString &data, const QString &fname) const;
0140 
0141     /**
0142      * This function ist called by the MainWindow upon restore
0143      */
0144     void autoReadProperties();
0145 
0146     /**
0147      * This is called when exiting akregator in order to be able to restore
0148      * its state next time it starts.
0149      */
0150     void autoSaveProperties();
0151 
0152     /**
0153      * Saves the session in a special file, so akregator can restore the session in
0154      * case of a crash.
0155      */
0156     void saveCrashProperties();
0157 
0158     /**
0159      * Clears the crash data.
0160      */
0161     void clearCrashProperties();
0162 
0163 private: // attributes
0164     void initializeTrayIcon();
0165 
0166     class ApplyFiltersInterceptor;
0167     ApplyFiltersInterceptor *m_applyFiltersInterceptor = nullptr;
0168     QString m_standardFeedList;
0169     bool m_standardListLoaded = false;
0170     bool m_shuttingDown = false;
0171     bool m_doCrashSave = false;
0172 
0173     QTimer *m_autosaveTimer = nullptr;
0174     /** did we backup the feed list already? */
0175     bool m_backedUpList = false;
0176     Akregator::AkregatorCentralWidget *mCentralWidget = nullptr;
0177     QPointer<MainWidget> m_mainWidget;
0178     Backend::Storage *m_storage = nullptr;
0179     ActionManagerImpl *m_actionManager = nullptr;
0180     KCMultiDialog *m_dialog = nullptr;
0181     struct AddFeedRequest {
0182         QStringList urls;
0183         QString group;
0184     };
0185     QPointer<LoadFeedListCommand> m_loadFeedListCommand;
0186     QList<AddFeedRequest> m_requests;
0187     KSharedConfig::Ptr mConfig;
0188 };
0189 } // namespace Akregator