File indexing completed on 2024-04-21 03:55:09

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 recent URLs. This includes all the URLs from
0073      * recentDocuments() as well as URLs from other applications conforming to
0074      * the XDG desktop-bookmark-spec (e. g. the GTK file dialog).
0075      *
0076      * @since 5.93
0077      */
0078     static QList<QUrl> recentUrls();
0079 
0080     /**
0081      * Add a new item to the Recent Document menu.
0082      *
0083      * @param url The url to add.
0084      */
0085     static void add(const QUrl &url);
0086     /// @since 5.93
0087     static void add(const QUrl &url, KRecentDocument::RecentDocumentGroups groups);
0088 
0089     /**
0090      * Add a new item to the Recent Document menu, specifying the application to open it with.
0091      * The above add() method uses QCoreApplication::applicationName() for the app name,
0092      * which isn't always flexible enough.
0093      * This method is used when an application launches another one to open a document.
0094      *
0095      * @param url The url to add.
0096      * @param desktopEntryName The desktopEntryName of the service to use for opening this document.
0097      */
0098     static void add(const QUrl &url, const QString &desktopEntryName);
0099     /// @since 5.93
0100     static void add(const QUrl &url, const QString &desktopEntryName, KRecentDocument::RecentDocumentGroups groups);
0101 
0102     static bool clearEntriesOldestEntries(int maxEntries);
0103 
0104     /**
0105      * Clear the recent document menu of all entries.
0106      */
0107     static void clear();
0108 
0109     /**
0110      * Returns the maximum amount of recent document entries allowed.
0111      */
0112     static int maximumItems();
0113 };
0114 
0115 #endif