ukui-menu/extension/recent-file/recent-file-extension.h

77 lines
2.0 KiB
C++

/*
* Copyright (C) 2022, KylinSoft Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#ifndef UKUI_MENU_RECENT_FILE_EXTENSION_H
#define UKUI_MENU_RECENT_FILE_EXTENSION_H
#include <QMenu>
#include <QPointer>
class QThread;
#include "menu-extension-iface.h"
namespace UkuiMenu {
class RecentFilesModel;
class RecentFileProvider;
class RecentFile
{
public:
quint64 accessTime{0};
QString uri;
QString name;
QString icon;
QString infoId;
};
class RecentFileExtension : public MenuExtensionIFace
{
Q_OBJECT
Q_PLUGIN_METADATA(IID UKUI_MENU_EXTENSION_IFACE_IID FILE "metadata.json")
Q_INTERFACES(UkuiMenu::MenuExtensionIFace)
public:
explicit RecentFileExtension(QObject *parent = nullptr);
~RecentFileExtension() override;
int index() override;
QString name() override;
QUrl url() override;
QVariantMap data() override;
void receive(QVariantMap data) override;
private:
QPointer<QMenu> m_contextMenu;
QVector<RecentFile> m_recentFile;
QVariantMap m_data;
RecentFilesModel *m_recentFilesModel = nullptr;
QThread *m_recentFilesProviderThread = nullptr;
RecentFileProvider *m_recentFileProvider = nullptr;
void openFile(const QString& fileUrl);
void creatMenu(const QString &path, const int &index);
Q_SIGNALS:
void loadRecentFiles();
void openFileASync(const QString &path);
};
} // UkuiMenu
#endif //UKUI_MENU_RECENT_FILE_EXTENSION_H