File indexing completed on 2024-10-06 12:21:30
0001 /* -*- c++ -*- 0002 SPDX-FileCopyrightText: 2000 Daniel M. Duley <mosfet@kde.org> 0003 SPDX-FileCopyrightText: 2022 Méven Car <meven.car@kdemail.net> 0004 0005 SPDX-License-Identifier: BSD-2-Clause 0006 */ 0007 0008 #ifndef __KRECENTDOCUMENT_H 0009 #define __KRECENTDOCUMENT_H 0010 0011 #include "kiocore_export.h" 0012 0013 #include <QString> 0014 #include <QUrl> 0015 0016 /** 0017 * @class KRecentDocument krecentdocument.h <KRecentDocument> 0018 * 0019 * Manage the "Recent Document Menu" entries displayed by 0020 * applications such as Kicker and Konqueror. 0021 * 0022 * These entries are automatically generated .desktop files pointing 0023 * to the current application and document. You should call the 0024 * static add() method whenever the user opens or saves a new 0025 * document if you want it to show up in the menu. 0026 * 0027 * It also stores history following xdg specification. 0028 * Ref: https://www.freedesktop.org/wiki/Specifications/desktop-bookmark-spec 0029 * This allows cross-framework file history sharing. 0030 * I.e Gtk Apps can access files recently opened by KDE Apps. 0031 * 0032 * You don't have to worry about this if you are using 0033 * QFileDialog to open and save documents, as the KDE implementation 0034 * (KFileWidget) already calls this class. User defined limits on the maximum 0035 * number of documents to save, etc... are all automatically handled. 0036 * 0037 * @author Daniel M. Duley <mosfet@kde.org> 0038 * @author Méven Car <meven.car@kdemail.net> 0039 */ 0040 class KIOCORE_EXPORT KRecentDocument 0041 { 0042 public: 0043 /* 0044 * Usage group for a file to bookmark in recently-used.xbel file 0045 * 0046 * from spec https://www.freedesktop.org/wiki/Specifications/desktop-bookmark-spec/#appendixb:registeredgroupnames 0047 * @since 5.93 0048 */ 0049 enum RecentDocumentGroup { 0050 Development, // A bookmark related to a development environment 0051 Office, // A bookmark related to an office type document or folder 0052 Database, // A bookmark related to a database application; Office; relates to Development 0053 Email, // A bookmark related to an email application relates to Office 0054 Presentation, // A bookmark related to a presentation application relates to Office 0055 Spreadsheet, // A bookmark related to a spreadsheet application relates to Office 0056 WordProcessor, // A bookmark related to a word processing application relates to Office 0057 Graphics, // A bookmark related to a graphical application 0058 TextEditor, // A bookmark related to a text editor 0059 Viewer, // A bookmark related to any kind of file viewer 0060 Archive, // A bookmark related to an archive file 0061 Multimedia, // A bookmark related to a multimedia file or application 0062 Audio, // A bookmark related to an audio file or application relates to Multimedia 0063 Video, // A bookmark related to a video file or application relates to Multimedia 0064 Photo, // A bookmark related to a digital photography file or application relates to Multimedia; Graphics; Viewer 0065 Application, // Special bookmark for application launchers 0066 }; 0067 0068 typedef QList<KRecentDocument::RecentDocumentGroup> RecentDocumentGroups; 0069 0070 /** 0071 * 0072 * Return a list of absolute paths to recent document .desktop files, 0073 * sorted by date. 0074 * 0075 */ 0076 static QStringList recentDocuments(); 0077 0078 /** 0079 * 0080 * Return a list of recent URLs. This includes all the URLs from 0081 * recentDocuments() as well as URLs from other applications conforming to 0082 * the XDG desktop-bookmark-spec (e. g. the GTK file dialog). 0083 * 0084 * @since 5.93 0085 */ 0086 static QList<QUrl> recentUrls(); 0087 0088 /** 0089 * Add a new item to the Recent Document menu. 0090 * 0091 * @param url The url to add. 0092 */ 0093 static void add(const QUrl &url); 0094 /// @since 5.93 0095 static void add(const QUrl &url, KRecentDocument::RecentDocumentGroups groups); 0096 0097 /** 0098 * Add a new item to the Recent Document menu, specifying the application to open it with. 0099 * The above add() method uses QCoreApplication::applicationName() for the app name, 0100 * which isn't always flexible enough. 0101 * This method is used when an application launches another one to open a document. 0102 * 0103 * @param url The url to add. 0104 * @param desktopEntryName The desktopEntryName of the service to use for opening this document. 0105 */ 0106 static void add(const QUrl &url, const QString &desktopEntryName); 0107 /// @since 5.93 0108 static void add(const QUrl &url, const QString &desktopEntryName, KRecentDocument::RecentDocumentGroups groups); 0109 0110 #if KIOCORE_ENABLE_DEPRECATED_SINCE(5, 0) 0111 /** 0112 * 0113 * Add a new item to the Recent Document menu. Calls add( url ). 0114 * 0115 * @param documentStr The full path to the document or URL to add. 0116 * @param isURL Set to @p true if @p documentStr is an URL and not a local file path. 0117 * @deprecated Since 5.0, call add(QUrl(str)) if isURL=true, and add(QUrl::fromLocalFile(str)) if isURL=false. 0118 */ 0119 KIOCORE_DEPRECATED_VERSION(5, 0, "Use KRecentDocument::add(const QUrl &)") 0120 static void add(const QString &documentStr, bool isUrl = false) 0121 { 0122 if (isUrl) { 0123 add(QUrl(documentStr)); 0124 } else { 0125 add(QUrl::fromLocalFile(documentStr)); 0126 } 0127 } 0128 #endif 0129 0130 /** 0131 * Clear the recent document menu of all entries. 0132 */ 0133 static void clear(); 0134 0135 /** 0136 * Returns the maximum amount of recent document entries allowed. 0137 */ 0138 static int maximumItems(); 0139 0140 /** 0141 * Returns the path to the directory where recent document .desktop files 0142 * are stored. 0143 */ 0144 static QString recentDocumentDirectory(); 0145 }; 0146 0147 #endif