File indexing completed on 2024-05-12 05:52:07
0001 /* 0002 SPDX-FileCopyrightText: 2005 Christoph Cullmann <cullmann@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "kateprivate_export.h" 0010 0011 #include <QDateTime> 0012 #include <QExplicitlySharedDataPointer> 0013 #include <QString> 0014 0015 #include <memory> 0016 0017 class KConfig; 0018 0019 class KATE_PRIVATE_EXPORT KateSession : public QSharedData 0020 { 0021 public: 0022 /** 0023 * Define a Shared-Pointer type 0024 */ 0025 typedef QExplicitlySharedDataPointer<KateSession> Ptr; 0026 0027 public: 0028 /** 0029 * session name 0030 * @return name for this session 0031 */ 0032 const QString &name() const 0033 { 0034 return m_name; 0035 } 0036 0037 /** 0038 * session config 0039 * on first access, will create the config object, delete will be done automagic 0040 * return 0 if we have no file to read config from atm 0041 * @return correct KConfig, never null 0042 * @note never delete configRead(), because the return value might be 0043 * KSharedConfig::openConfig(). Only delete the member variables directly. 0044 */ 0045 KConfig *config(); 0046 0047 /** 0048 * count of documents in this session 0049 * @return documents count 0050 */ 0051 unsigned int documents(); 0052 0053 /** 0054 * @return true if this is anonymous/new session 0055 */ 0056 bool isAnonymous() const 0057 { 0058 return m_anonymous; 0059 } 0060 0061 /** 0062 * @return path to session file 0063 */ 0064 const QString &file() const; 0065 0066 /** 0067 * returns last save time of this session 0068 */ 0069 const QDateTime ×tamp() const 0070 { 0071 return m_timestamp; 0072 } 0073 0074 /** 0075 * Factories 0076 */ 0077 public: 0078 static KateSession::Ptr create(const QString &file, const QString &name); 0079 static KateSession::Ptr createFrom(const KateSession::Ptr &session, const QString &file, const QString &name); 0080 static KateSession::Ptr createAnonymous(const QString &file); 0081 static KateSession::Ptr createAnonymousFrom(const KateSession::Ptr &session, const QString &file); 0082 0083 static bool compareByName(const KateSession::Ptr &s1, const KateSession::Ptr &s2); 0084 static bool compareByTimeDesc(const KateSession::Ptr &s1, const KateSession::Ptr &s2); 0085 0086 private: 0087 friend class KateSessionManager; 0088 friend class KateSessionTest; 0089 /** 0090 * set session name 0091 */ 0092 void setName(const QString &name); 0093 0094 /** 0095 * set's new session file to @filename 0096 */ 0097 void setFile(const QString &filename); 0098 0099 /** 0100 * create a session from given @file 0101 * @param file configuration file 0102 * @param name name of this session 0103 * @param anonymous anonymous flag 0104 * @param config if specified, the session will copy configuration from the KConfig instead of opening the file 0105 */ 0106 KateSession(const QString &file, const QString &name, const bool anonymous, const KConfig *config = nullptr); 0107 0108 private: 0109 QString m_name; 0110 QString m_file; 0111 bool m_anonymous; 0112 std::unique_ptr<KConfig> m_config; 0113 QDateTime m_timestamp; 0114 };