Changeset View
Changeset View
Standalone View
Standalone View
src/KDbTableSchemaChangeListener.h
1 | /* This file is part of the KDE project | 1 | /* This file is part of the KDE project | ||
---|---|---|---|---|---|
2 | Copyright (C) 2003-2016 Jarosław Staniek <staniek@kde.org> | 2 | Copyright (C) 2003-2017 Jarosław Staniek <staniek@kde.org> | ||
3 | 3 | | |||
4 | This program is free software; you can redistribute it and/or | 4 | This program is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Library General Public | 5 | modify it under the terms of the GNU Library General Public | ||
6 | License as published by the Free Software Foundation; either | 6 | License as published by the Free Software Foundation; either | ||
7 | version 2 of the License, or (at your option) any later version. | 7 | version 2 of the License, or (at your option) any later version. | ||
8 | 8 | | |||
9 | This program is distributed in the hope that it will be useful, | 9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Library General Public License for more details. | 12 | Library General Public License for more details. | ||
13 | 13 | | |||
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this program; see the file COPYING. If not, write to | 15 | along with this program; see the file COPYING. If not, write to | ||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | * Boston, MA 02110-1301, USA. | 17 | * Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #ifndef KDB_KDBTABLESCHEMACHANGELISTENER_H | 20 | #ifndef KDB_KDBTABLESCHEMACHANGELISTENER_H | ||
21 | 21 | | |||
22 | #include <kdb_export.h> | 22 | #include <kdb_export.h> | ||
23 | #include <KDbTristate> | 23 | #include <KDbTristate> | ||
24 | 24 | | |||
25 | class KDbConnection; | 25 | class KDbConnection; | ||
26 | class KDbQuerySchema; | ||||
26 | class KDbTableSchema; | 27 | class KDbTableSchema; | ||
28 | class KDbTableSchemaChangeListenerPrivate; | ||||
27 | 29 | | |||
28 | //! @short An interface allowing to listen for table schema changes | 30 | //! @short An interface allowing to listen for table schema changes | ||
29 | /** | 31 | /** | ||
30 | * The KDbTableSchemaChangeListener class can be used to listen for changes in table schema. | 32 | * The KDbTableSchemaChangeListener class can be used to listen for changes in table schema. | ||
31 | * For example query designer window that uses given table schema can be informed about | 33 | * For example query designer window that uses given table schema can be informed about | ||
32 | * planned changes and it can be decided about closing the window prior to changes in the schema. | 34 | * planned changes and it can be decided about closing the window prior to changes in the schema. | ||
33 | */ | 35 | */ | ||
34 | class KDB_EXPORT KDbTableSchemaChangeListener | 36 | class KDB_EXPORT KDbTableSchemaChangeListener | ||
Show All 27 Lines | 38 | public: | |||
62 | /** | 64 | /** | ||
63 | * @return translated string that clearly identifies object that listens for changes | 65 | * @return translated string that clearly identifies object that listens for changes | ||
64 | * in a given table schema. | 66 | * in a given table schema. | ||
65 | * | 67 | * | ||
66 | * @see name() | 68 | * @see name() | ||
67 | */ | 69 | */ | ||
68 | void setName(const QString &name); | 70 | void setName(const QString &name); | ||
69 | 71 | | |||
70 | //! @todo will be more generic | 72 | /** Registers @a listener for receiving (listening) information about changes in table schema | ||
71 | /** Registers @a listener for receiving (listening) information about changes | 73 | * @a table and all tables related to lookup fields. Changes can be related to altering and | ||
72 | in table schema @a table. Changes could be related to altering and removing. */ | 74 | * removing. | ||
75 | */ | ||||
73 | static void registerForChanges(KDbConnection *conn, | 76 | static void registerForChanges(KDbConnection *conn, | ||
74 | KDbTableSchemaChangeListener* listener, | 77 | KDbTableSchemaChangeListener* listener, | ||
75 | const KDbTableSchema* table); | 78 | const KDbTableSchema* table); | ||
76 | 79 | | |||
77 | /** | 80 | /** | ||
81 | * Registers @a listener for receiving (listening) information about changes in query schema | ||||
82 | * @a query and all tables that the query uses. | ||||
83 | * | ||||
84 | * All tables related to lookup fields of these tables are also checked. | ||||
85 | * Changes can be related to table altering and removing. | ||||
86 | */ | ||||
87 | static void registerForChanges(KDbConnection *conn, | ||||
88 | KDbTableSchemaChangeListener* listener, | ||||
89 | const KDbQuerySchema* query); | ||||
90 | | ||||
91 | /** | ||||
78 | * Unregisters @a listener for receiving (listening) information about changes | 92 | * Unregisters @a listener for receiving (listening) information about changes | ||
79 | * in table schema @a table. | 93 | * in table schema @a table. | ||
80 | */ | 94 | */ | ||
81 | static void unregisterForChanges(KDbConnection *conn, | 95 | static void unregisterForChanges(KDbConnection *conn, | ||
82 | KDbTableSchemaChangeListener* listener, | 96 | KDbTableSchemaChangeListener* listener, | ||
83 | const KDbTableSchema* table); | 97 | const KDbTableSchema* table); | ||
84 | 98 | | |||
85 | /** | 99 | /** | ||
100 | * Unregisters all listeners for receiving (listening) information about changes | ||||
101 | * in table schema @a table. | ||||
102 | */ | ||||
103 | static void unregisterForChanges(KDbConnection *conn, | ||||
104 | const KDbTableSchema* table); | ||||
105 | | ||||
106 | /** | ||||
86 | * Unregisters @a listener for receiving (listening) information about changes | 107 | * Unregisters @a listener for receiving (listening) information about changes | ||
87 | * in any table schema. | 108 | * in any table or query schema. | ||
88 | */ | 109 | */ | ||
89 | static void unregisterForChanges(KDbConnection *conn, | 110 | static void unregisterForChanges(KDbConnection *conn, | ||
90 | KDbTableSchemaChangeListener* listener); | 111 | KDbTableSchemaChangeListener* listener); | ||
91 | 112 | | |||
92 | /** | 113 | /** | ||
114 | * Unregisters @a listener for receiving (listening) information about changes | ||||
115 | * in query schema @a query. | ||||
116 | */ | ||||
117 | static void unregisterForChanges(KDbConnection *conn, | ||||
118 | KDbTableSchemaChangeListener* listener, | ||||
119 | const KDbQuerySchema* query); | ||||
120 | | ||||
121 | /** | ||||
122 | * Unregisters all listeners for receiving (listening) information about changes | ||||
123 | * in query schema @a query. | ||||
124 | */ | ||||
125 | static void unregisterForChanges(KDbConnection *conn, | ||||
126 | const KDbQuerySchema* query); | ||||
127 | | ||||
128 | /** | ||||
129 | * @return list of all table schema listeners registered for receiving (listening) | ||||
130 | * information about changes in table schema @a table and other tables or queries depending | ||||
131 | * on @a table. | ||||
132 | */ | ||||
133 | static QList<KDbTableSchemaChangeListener *> listeners(KDbConnection *conn, | ||||
134 | const KDbTableSchema *table); | ||||
135 | | ||||
136 | /** | ||||
93 | * @return list of all table schema listeners registered for receiving (listening) | 137 | * @return list of all table schema listeners registered for receiving (listening) | ||
94 | * information about changes in table schema @a table. | 138 | * information about changes in query @a query and other tables or queries depending on @a query. | ||
95 | */ | 139 | */ | ||
96 | static QList<KDbTableSchemaChangeListener*> listeners( | 140 | static QList<KDbTableSchemaChangeListener *> listeners(KDbConnection *conn, | ||
97 | const KDbConnection *conn, const KDbTableSchema* table); | 141 | const KDbQuerySchema *query); | ||
98 | 142 | | |||
99 | /** | 143 | /** | ||
100 | * Closes all table schema listeners for table schema @a table. | 144 | * Closes all table schema listeners for table schema @a table except for the ones from | ||
101 | * See KDbTableSchemaChangeListener::closeListener() for explanation | 145 | * the @a except list. | ||
102 | * of the operation of closing listener. | 146 | * | ||
147 | * See KDbTableSchemaChangeListener::closeListener() for explanation of the operation | ||||
148 | * of closing listener. | ||||
149 | * | ||||
150 | * @return true if all listenters for the table schema @a table have been successfully closed | ||||
151 | * (returned true) or @c false or @c cancelled if at least one listener returned | ||||
152 | * @c false or @c cancelled, respectively. | ||||
153 | * Regardless of returned value, closeListener() is called on all listeners for @a table. | ||||
154 | */ | ||||
155 | static tristate closeListeners(KDbConnection *conn, const KDbTableSchema* table, | ||||
156 | const QList<KDbTableSchemaChangeListener*> &except | ||||
157 | = QList<KDbTableSchemaChangeListener*>()); | ||||
158 | | ||||
159 | /** | ||||
160 | * Closes all table schema listeners for query schema @a query except for the ones from | ||||
161 | * the @a except list. | ||||
162 | * | ||||
163 | * See KDbTableSchemaChangeListener::closeListener() for explanation of the operation | ||||
164 | * of closing listener. | ||||
165 | * | ||||
103 | * @return true if all listenters for the table schema @a table have been successfully closed | 166 | * @return true if all listenters for the table schema @a table have been successfully closed | ||
104 | * (returned true) or @c false or @c cancelled if at least one listener returned | 167 | * (returned true) or @c false or @c cancelled if at least one listener returned | ||
105 | * @c false or @c cancelled, respectively. | 168 | * @c false or @c cancelled, respectively. | ||
106 | * Regardless of returned value, closeListener() is called on all listeners for @a table. | 169 | * Regardless of returned value, closeListener() is called on all listeners for @a table. | ||
107 | */ | 170 | */ | ||
108 | static tristate closeListeners(KDbConnection *conn, const KDbTableSchema* table); | 171 | static tristate closeListeners(KDbConnection *conn, const KDbQuerySchema* query, | ||
172 | const QList<KDbTableSchemaChangeListener*> &except | ||||
173 | = QList<KDbTableSchemaChangeListener*>()); | ||||
109 | 174 | | |||
110 | private: | 175 | private: | ||
111 | Q_DISABLE_COPY(KDbTableSchemaChangeListener) | 176 | Q_DISABLE_COPY(KDbTableSchemaChangeListener) | ||
112 | class Private; | 177 | KDbTableSchemaChangeListenerPrivate * const d; | ||
113 | Private * const d; | | |||
114 | }; | 178 | }; | ||
115 | 179 | | |||
116 | #endif | 180 | #endif |