Changeset View
Changeset View
Standalone View
Standalone View
kate/session/katesessionmanager.h
Show All 26 Lines | |||||
27 | #include <QHash> | 27 | #include <QHash> | ||
28 | 28 | | |||
29 | typedef QList<KateSession::Ptr> KateSessionList; | 29 | typedef QList<KateSession::Ptr> KateSessionList; | ||
30 | 30 | | |||
31 | class KATE_TESTS_EXPORT KateSessionManager : public QObject | 31 | class KATE_TESTS_EXPORT KateSessionManager : public QObject | ||
32 | { | 32 | { | ||
33 | Q_OBJECT | 33 | Q_OBJECT | ||
34 | 34 | | |||
35 | friend class KateSessionManageDialog; | ||||
36 | | ||||
35 | public: | 37 | public: | ||
36 | KateSessionManager(QObject *parent = nullptr, const QString &sessionsDir = QString()); | 38 | KateSessionManager(QObject *parent = nullptr, const QString &sessionsDir = QString()); | ||
37 | ~KateSessionManager() override; | 39 | ~KateSessionManager() override; | ||
38 | 40 | | |||
39 | /** | 41 | /** | ||
40 | * allow access to the session list | 42 | * allow access to the session list | ||
41 | * kept up to date by watching the dir | 43 | * kept up to date by watching the dir | ||
42 | */ | 44 | */ | ||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | |||||
91 | public Q_SLOTS: | 93 | public Q_SLOTS: | ||
92 | /** | 94 | /** | ||
93 | * try to start a new session | 95 | * try to start a new session | ||
94 | * asks user first for name | 96 | * asks user first for name | ||
95 | */ | 97 | */ | ||
96 | void sessionNew(); | 98 | void sessionNew(); | ||
97 | 99 | | |||
98 | /** | 100 | /** | ||
99 | * try to open a existing session | | |||
100 | */ | | |||
101 | void sessionOpen(); | | |||
102 | | ||||
103 | /** | | |||
104 | * try to save current session | 101 | * try to save current session | ||
105 | */ | 102 | */ | ||
106 | void sessionSave(); | 103 | void sessionSave(); | ||
107 | 104 | | |||
108 | /** | 105 | /** | ||
109 | * try to save as current session | 106 | * try to save as current session | ||
110 | */ | 107 | */ | ||
111 | void sessionSaveAs(); | 108 | void sessionSaveAs(); | ||
112 | 109 | | |||
113 | /** | 110 | /** | ||
114 | * show dialog to manage our sessions | 111 | * show dialog to manage our sessions | ||
115 | */ | 112 | */ | ||
116 | void sessionManage(); | 113 | void sessionManage(); | ||
117 | 114 | | |||
118 | Q_SIGNALS: | 115 | Q_SIGNALS: | ||
119 | /** | 116 | /** | ||
120 | * Emitted, whenever the session changes, e.g. when it was renamed. | 117 | * Emitted, whenever the session changes, e.g. when it was renamed. | ||
121 | */ | 118 | */ | ||
122 | void sessionChanged(); | 119 | void sessionChanged(); | ||
123 | 120 | | |||
124 | /** | 121 | /** | ||
122 | * Emitted whenever the session list has changed. | ||||
123 | * @see sessionList() | ||||
124 | */ | ||||
125 | void sessionListChanged(); | ||||
126 | | ||||
127 | /** | ||||
125 | * module internal APIs | 128 | * module internal APIs | ||
126 | */ | 129 | */ | ||
127 | public: | 130 | public: | ||
128 | /** | 131 | /** | ||
129 | * return session with given name | 132 | * return session with given name | ||
130 | * if no existing session matches, create new one with this name | 133 | * if no existing session matches, create new one with this name | ||
131 | * @param name session name | 134 | * @param name session name | ||
132 | */ | 135 | */ | ||
133 | KateSession::Ptr giveSession(const QString &name); | 136 | KateSession::Ptr giveSession(const QString &name); | ||
134 | 137 | | |||
135 | /** | 138 | /** | ||
136 | * deletes session file and removes the session from sessions list | 139 | * Try to delete the @p session and removes the session from sessions list | ||
140 | * @param the session to delete | ||||
141 | * @return true on success, false if @p session is currently in use | ||||
142 | */ | ||||
143 | bool deleteSession(KateSession::Ptr session); | ||||
144 | | ||||
145 | /** | ||||
146 | * Try to copy the @p session to a new session @p newName. | ||||
147 | * Will ask by @c askForNewSessionName() for a differend name when @p newName is already in use or is an | ||||
148 | * empty string. | ||||
149 | * @param newName is wished name of the new session | ||||
150 | * @return the new session name on success, otherwise an empty string | ||||
151 | * @see askForNewSessionName() | ||||
137 | */ | 152 | */ | ||
138 | void deleteSession(KateSession::Ptr session); | 153 | QString copySession(KateSession::Ptr session, const QString &newName = QString()); | ||
139 | 154 | | |||
140 | /** | 155 | /** | ||
141 | * renames the session to \p newName | 156 | * Try to rename the @p session to @p newName. | ||
142 | * @param session pointer to the session | 157 | * Will ask by @c askForNewSessionName() for a differend name when @p newName is already in use or is an | ||
143 | * @param newName new name of the session | 158 | * empty string. | ||
144 | * @return true if successful | 159 | * @param newName is wished new name of the session | ||
160 | * @return the new session name on success, otherwise an empty string | ||||
161 | * @see askForNewSessionName() | ||||
145 | */ | 162 | */ | ||
146 | bool renameSession(KateSession::Ptr session, const QString &newName); | 163 | QString renameSession(KateSession::Ptr session, const QString &newName = QString()); | ||
147 | 164 | | |||
148 | /** | 165 | /** | ||
149 | * activate a session | 166 | * activate a session | ||
150 | * first, it will look if a session with this name exists in list | 167 | * first, it will look if a session with this name exists in list | ||
151 | * if yes, it will use this session, else it will create a new session file | 168 | * if yes, it will use this session, else it will create a new session file | ||
152 | * @param session session to activate | 169 | * @param session session to activate | ||
153 | * @param closeAndSaveLast try to close and save last session or not? | 170 | * @param closeAndSaveLast try to close and save last session or not? | ||
154 | * @param loadNew load new session stuff? | 171 | * @param loadNew load new session stuff? | ||
155 | * @return false==session has been delegated, true==session has been activated in this distance | 172 | * @return false==session has been delegated, true==session has been activated in this distance | ||
156 | */ | 173 | */ | ||
157 | bool activateSession(KateSession::Ptr session, const bool closeAndSaveLast = true, const bool loadNew = true); | 174 | bool activateSession(KateSession::Ptr session, const bool closeAndSaveLast = true, const bool loadNew = true); | ||
158 | 175 | | |||
159 | private Q_SLOTS: | 176 | private Q_SLOTS: | ||
160 | /** | 177 | /** | ||
161 | * trigger update of session list | 178 | * trigger update of session list | ||
162 | */ | 179 | */ | ||
163 | void updateSessionList(); | 180 | void updateSessionList(); | ||
164 | 181 | | |||
165 | private: | 182 | private: | ||
166 | /** | 183 | /** | ||
167 | * Asks the user for a new session name. Used by save as for example. | 184 | * Ask the user for a new session name, when needed. | ||
185 | * @param session is the session to rename or copy | ||||
186 | * @param newName is a preset value. Is @p newName not already in use is nothing asked | ||||
187 | * @return a (currently) not used new session name or an empty string when | ||||
188 | * user aborted or when @p newName is the current session name. | ||||
189 | */ | ||||
190 | QString askForNewSessionName(KateSession::Ptr session, const QString &newName = QString()); | ||||
191 | | ||||
192 | /** | ||||
193 | * Try to generate a new session name from @p target by a number suffix. | ||||
194 | * @param target is the base name | ||||
195 | * @return a (currently) not used session name or an empty string | ||||
168 | */ | 196 | */ | ||
169 | bool newSessionName(); | 197 | QString suggestNewSessionName(const QString &target); | ||
170 | 198 | | |||
171 | /** | 199 | /** | ||
172 | * returns session config file according to policy | 200 | * returns session config file according to policy | ||
173 | */ | 201 | */ | ||
174 | QString sessionFileForName(const QString &name) const; | 202 | QString sessionFileForName(const QString &name) const; | ||
175 | 203 | | |||
176 | /** | 204 | /** | ||
205 | * @return true when @p session is active in any Kate instance, otherwise false | ||||
206 | */ | ||||
207 | bool sessionIsActive(const QString &session); | ||||
208 | | ||||
209 | /** | ||||
177 | * returns session file for anonymous session | 210 | * returns session file for anonymous session | ||
178 | */ | 211 | */ | ||
179 | QString anonymousSessionFile() const; | 212 | QString anonymousSessionFile() const; | ||
180 | 213 | | |||
181 | /** | 214 | /** | ||
182 | * helper function to save the session to a given config object | 215 | * helper function to save the session to a given config object | ||
183 | */ | 216 | */ | ||
184 | void saveSessionTo(KConfig *sc) const; | 217 | void saveSessionTo(KConfig *sc) const; | ||
Show All 32 Lines |