File indexing completed on 2024-03-24 05:51:17
0001 /** 0002 * SPDX-FileCopyrightText: (C) 2003 Sébastien Laoût <slaout@linux62.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef NOTEFACTORY_H 0008 #define NOTEFACTORY_H 0009 0010 #include "notecontent.h" //For NoteType::Id 0011 0012 class QColor; 0013 class QPixmap; 0014 class QString; 0015 class QStringList; 0016 0017 class QUrl; 0018 class QMimeType; 0019 0020 class BasketScene; 0021 class Note; 0022 0023 /** Factory class to create (new, drop, paste) or load BasketIem, and eventually save them (?) 0024 * @author Sébastien Laoût 0025 */ 0026 namespace NoteFactory 0027 { 0028 /** Functions to create a new note from a content item. 0029 * Content, if any, is saved to file but the note is not inserted in the basket, and the basket is not saved. 0030 * Return 0 if the note has not been successfully created. 0031 * In some cases, the returned note can be a group containing several notes or the first note of a chained list. 0032 * The method BasketScene::TODO() can insert several grouped or chained notes without problem. 0033 */ 0034 Note *createNoteText(const QString &text, BasketScene *parent, bool reallyPlainText = false); 0035 Note *createNoteHtml(const QString &html, BasketScene *parent); 0036 Note *createNoteLink(const QUrl &url, BasketScene *parent); 0037 Note *createNoteLink(const QUrl &url, const QString &title, BasketScene *parent); 0038 Note *createNoteCrossReference(const QUrl &url, BasketScene *parent); 0039 Note *createNoteCrossReference(const QUrl &url, const QString &title, BasketScene *parent); 0040 Note *createNoteCrossReference(const QUrl &url, const QString &title, const QString &icon, BasketScene *parent); 0041 Note *createNoteImage(const QPixmap &image, BasketScene *parent); 0042 Note *createNoteColor(const QColor &color, BasketScene *parent); 0043 Note *createNoteFromText(const QString &content, BasketScene *parent); // Find automatically the type from the text meaning // TODO: Return Note::List? 0044 Note *createNoteLauncher(const QUrl &url, BasketScene *parent); 0045 Note *createNoteLauncher(const QString &command, const QString &name, const QString &icon, BasketScene *parent); 0046 Note *createNoteUnknown(const QMimeData *source, BasketScene *parent); 0047 /** Functions to create derived notes from a content */ 0048 Note *createNoteLinkOrLauncher(const QUrl &url, BasketScene *parent); 0049 Note *copyFileAndLoad(const QUrl &url, BasketScene *parent); 0050 Note *moveFileAndLoad(const QUrl &url, BasketScene *parent); 0051 Note *loadFile(const QString &fileName, BasketScene *parent); /// << Determine the content of the file (the file SHOULD exists) and return a note of the good type. 0052 Note *loadFile(const QString &fileName, NoteType::Id type, BasketScene *parent); /// << Create a note of type @p type. The file is not obliged to exist. 0053 /** Functions to create a new note from a drop or paste event */ 0054 Note *dropNote(const QMimeData *source, BasketScene *parent, bool fromDrop = false, Qt::DropAction action = Qt::CopyAction, Note *noteSource = nullptr); 0055 bool movingNotesInTheSameBasket(const QMimeData *source, BasketScene *parent, Qt::DropAction action); 0056 Note *dropURLs(QList<QUrl> urls, BasketScene *parent, Qt::DropAction action, bool fromDrop); 0057 Note *decodeContent(QDataStream &stream, NoteType::Id type, BasketScene *parent); /// << Decode the @p stream to a note or return 0 if a general loadFile() is sufficient. 0058 void consumeContent(QDataStream &stream, NoteType::Id type); /// << Decode the @p stream to a note or return 0 if a general loadFile() is sufficient. 0059 /** Functions to create a note file but not load it in a note object */ 0060 QString createNoteLauncherFile(const QString &command, const QString &name, const QString &icon, BasketScene *parent); 0061 /** Other useful functions */ 0062 NoteType::Id typeForURL(const QUrl &url, BasketScene *parent); 0063 bool maybeText(const QMimeType &mimeType); 0064 bool maybeHtml(const QMimeType &mimeType); 0065 bool maybeImage(const QMimeType &mimeType); 0066 bool maybeAnimation(const QMimeType &mimeType); 0067 bool maybeSound(const QMimeType &mimeType); 0068 bool maybeLauncher(const QMimeType &mimeType); 0069 QString fileNameForNewNote(BasketScene *parent, const QString &wantedName); 0070 QString createFileForNewNote(BasketScene *parent, const QString &extension, const QString &wantedName = QString()); 0071 QUrl filteredURL(const QUrl &url); 0072 QString titleForURL(const QUrl &url); 0073 QString iconForURL(const QUrl &url); 0074 QString iconForCommand(const QString &command); 0075 bool isIconExist(const QString &icon); 0076 QStringList textToURLList(const QString &text); // @Return { url1, title1, url2, title2, url3, title3... } 0077 /** Insert GUI menu */ 0078 Note *createEmptyNote(NoteType::Id type, BasketScene *parent); // Insert empty if of type Note::Type 0079 Note *importKMenuLauncher(BasketScene *parent); 0080 Note *importIcon(BasketScene *parent); 0081 Note *importFileContent(BasketScene *parent); 0082 0083 void loadNode(const QDomElement &content, const QString &lowerTypeName, Note *parent, bool lazyLoad); 0084 } 0085 0086 #endif // NOTEFACTORY_H