1 | /* -*- c++ -*- |
2 | SPDX-FileCopyrightText: 2000 Daniel M. Duley <mosfet@kde.org> |
3 | SPDX-FileCopyrightText: 2022 Méven Car <meven.car@kdemail.net> |
4 | |
5 | SPDX-License-Identifier: BSD-2-Clause |
6 | */ |
7 | |
8 | #ifndef __KRECENTDOCUMENT_H |
9 | #define __KRECENTDOCUMENT_H |
10 | |
11 | #include "kiocore_export.h" |
12 | |
13 | #include <QString> |
14 | #include <QUrl> |
15 | |
16 | /** |
17 | * @class KRecentDocument krecentdocument.h <KRecentDocument> |
18 | * |
19 | * Manage the "Recent Document Menu" entries displayed by |
20 | * applications such as Kicker and Konqueror. |
21 | * |
22 | * These entries are automatically generated .desktop files pointing |
23 | * to the current application and document. You should call the |
24 | * static add() method whenever the user opens or saves a new |
25 | * document if you want it to show up in the menu. |
26 | * |
27 | * It also stores history following xdg specification. |
28 | * Ref: https://www.freedesktop.org/wiki/Specifications/desktop-bookmark-spec |
29 | * This allows cross-framework file history sharing. |
30 | * I.e Gtk Apps can access files recently opened by KDE Apps. |
31 | * |
32 | * You don't have to worry about this if you are using |
33 | * QFileDialog to open and save documents, as the KDE implementation |
34 | * (KFileWidget) already calls this class. User defined limits on the maximum |
35 | * number of documents to save, etc... are all automatically handled. |
36 | * |
37 | * @author Daniel M. Duley <mosfet@kde.org> |
38 | * @author Méven Car <meven.car@kdemail.net> |
39 | */ |
40 | class KIOCORE_EXPORT KRecentDocument |
41 | { |
42 | public: |
43 | /* |
44 | * Usage group for a file to bookmark in recently-used.xbel file |
45 | * |
46 | * from spec https://www.freedesktop.org/wiki/Specifications/desktop-bookmark-spec/#appendixb:registeredgroupnames |
47 | * @since 5.93 |
48 | */ |
49 | enum RecentDocumentGroup { |
50 | Development, // A bookmark related to a development environment |
51 | Office, // A bookmark related to an office type document or folder |
52 | Database, // A bookmark related to a database application; Office; relates to Development |
53 | Email, // A bookmark related to an email application relates to Office |
54 | Presentation, // A bookmark related to a presentation application relates to Office |
55 | Spreadsheet, // A bookmark related to a spreadsheet application relates to Office |
56 | WordProcessor, // A bookmark related to a word processing application relates to Office |
57 | Graphics, // A bookmark related to a graphical application |
58 | TextEditor, // A bookmark related to a text editor |
59 | Viewer, // A bookmark related to any kind of file viewer |
60 | Archive, // A bookmark related to an archive file |
61 | Multimedia, // A bookmark related to a multimedia file or application |
62 | Audio, // A bookmark related to an audio file or application relates to Multimedia |
63 | Video, // A bookmark related to a video file or application relates to Multimedia |
64 | Photo, // A bookmark related to a digital photography file or application relates to Multimedia; Graphics; Viewer |
65 | Application, // Special bookmark for application launchers |
66 | }; |
67 | |
68 | typedef QList<KRecentDocument::RecentDocumentGroup> RecentDocumentGroups; |
69 | |
70 | /** |
71 | * |
72 | * Return a list of recent URLs. This includes all the URLs from |
73 | * recentDocuments() as well as URLs from other applications conforming to |
74 | * the XDG desktop-bookmark-spec (e. g. the GTK file dialog). |
75 | * |
76 | * @since 5.93 |
77 | */ |
78 | static QList<QUrl> recentUrls(); |
79 | |
80 | /** |
81 | * Add a new item to the Recent Document menu. |
82 | * |
83 | * @param url The url to add. |
84 | */ |
85 | static void add(const QUrl &url); |
86 | /// @since 5.93 |
87 | static void add(const QUrl &url, KRecentDocument::RecentDocumentGroups groups); |
88 | |
89 | /** |
90 | * Add a new item to the Recent Document menu, specifying the application to open it with. |
91 | * The above add() method uses QCoreApplication::applicationName() for the app name, |
92 | * which isn't always flexible enough. |
93 | * This method is used when an application launches another one to open a document. |
94 | * |
95 | * @param url The url to add. |
96 | * @param desktopEntryName The desktopEntryName of the service to use for opening this document. |
97 | */ |
98 | static void add(const QUrl &url, const QString &desktopEntryName); |
99 | /// @since 5.93 |
100 | static void add(const QUrl &url, const QString &desktopEntryName, KRecentDocument::RecentDocumentGroups groups); |
101 | |
102 | static bool clearEntriesOldestEntries(int maxEntries); |
103 | |
104 | /** |
105 | * Clear the recent document menu of all entries. |
106 | */ |
107 | static void clear(); |
108 | |
109 | /** |
110 | * Returns the maximum amount of recent document entries allowed. |
111 | */ |
112 | static int maximumItems(); |
113 | }; |
114 | |
115 | #endif |
116 | |