BiblioteQ

biblioteq_misc_functions.h
1 /*
2 ** Copyright (c) 2006 - present, Alexis Megas.
3 ** All rights reserved.
4 **
5 ** Redistribution and use in source and binary forms, with or without
6 ** modification, are permitted provided that the following conditions
7 ** are met:
8 ** 1. Redistributions of source code must retain the above copyright
9 ** notice, this list of conditions and the following disclaimer.
10 ** 2. Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
13 ** 3. The name of the author may not be used to endorse or promote products
14 ** derived from BiblioteQ without specific prior written permission.
15 **
16 ** BIBLIOTEQ IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 ** BIBLIOTEQ, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #ifndef _BIBLIOTEQ_MISC_FUNCTIONS_H_
29 #define _BIBLIOTEQ_MISC_FUNCTIONS_H_
30
31 #include <QGraphicsItem>
32 #include <QSqlDatabase>
33 #include <QSqlError>
34 #include <QSqlQuery>
35 #include <QTableWidget>
36
37 class QComboBox;
38 class QMainWindow;
39 class biblioteq;
40
41 class biblioteq_misc_functions
42 {
43 public:
44 static const int CREATE_USER = 100;
45 static const int DELETE_USER = 200;
46 static const int UPDATE_USER = 300;
47 static QImage getImage(const QString &,
48 const QString &,
49 const QString &,
50 const QSqlDatabase &);
51 static QList<QPair<QString, QString> > getLocations(const QSqlDatabase &,
52 QString &);
53 static QList<int> selectedRows(QTableWidget *);
54 static QMap<QString, qint64> getItemsReservedCounts(const QSqlDatabase &,
55 const QString &,
56 QString &);
57 static QString accessionNumberAsSpecialText(const qint64 integer);
58 static QString categories(QHash<QString, QString> &hash,
59 const QSqlDatabase &db,
60 const QString &id);
61 static QString getAbstractInfo(const QString &,
62 const QString &,
63 const QSqlDatabase &);
64 static QString getAvailability(const QString &,
65 const QSqlDatabase &,
66 const QString &,
67 QString &);
68 static QString getColumnString(const QTableWidget *,
69 const int,
70 const QString &);
71 static QString getColumnString(const QTableWidget *, const int, const int);
72 static QString getMemberName(const QSqlDatabase &,
73 const QString &,
74 QString &);
75 static QString getNextCopy(QString &field,
76 bool &ok,
77 const QSqlDatabase &db,
78 const QString &id,
79 const QString &type);
80 static QString getOID(const QString &,
81 const QString &,
82 const QSqlDatabase &,
83 QString &);
84 static QString getRoles(const QSqlDatabase &, const QString &, QString &);
85 static QString getTotalReserved(const QSqlDatabase &,
86 const QString &,
87 const QString &);
88 static QString imageFormatGuess(const QByteArray &bytes);
89 static QString isbn10to13(const QString &text);
90 static QString isbn13to10(const QString &text);
91 static QString linearizeString(const QString &text);
92 static QStringList getBookBindingTypes(const QSqlDatabase &, QString &);
93 static QStringList getBookConditions(const QSqlDatabase &, QString &);
94 static QStringList getBookOriginality(const QSqlDatabase &, QString &);
95 static QStringList getBookTargetAudiences(const QSqlDatabase &, QString &);
96 static QStringList getCDFormats(const QSqlDatabase &, QString &);
97 static QStringList getDVDAspectRatios(const QSqlDatabase &, QString &);
98 static QStringList getDVDRatings(const QSqlDatabase &, QString &);
99 static QStringList getDVDRegions(const QSqlDatabase &, QString &);
100 static QStringList getGreyLiteratureTypes(const QSqlDatabase &db,
101 QString &errorstr);
102 static QStringList getLanguages(const QSqlDatabase &, QString &);
103 static QStringList getLocations(const QSqlDatabase &,
104 const QString &,
105 QString &);
106 static QStringList getMinimumDays(const QSqlDatabase &, QString &);
107 static QStringList getMonetaryUnits(const QSqlDatabase &, QString &);
108 static QStringList getReservedItems(const QString &,
109 const QSqlDatabase &,
110 QString &);
111 static QStringList getVideoGamePlatforms(const QSqlDatabase &, QString &);
112 static QStringList getVideoGameRatings(const QSqlDatabase &, QString &);
113 static bool dnt(const QSqlDatabase &, const QString &, QString &);
114 static bool getMemberMatch(const QString &,
115 const QString &,
116 const QSqlDatabase &,
117 QString &);
118 static bool hasMemberExpired(const QSqlDatabase &,
119 const QString &,
120 QString &);
121 static bool hasUnaccentExtension(const QSqlDatabase &);
122
123 static bool isBookRead(const QSqlDatabase &db, const quint64 myoid)
124 {
125 if(db.driverName() != "QSQLITE")
126 return false;
127
128 QSqlQuery query(db);
129
130 query.setForwardOnly(true);
131 query.prepare("SELECT book_read FROM book WHERE myoid = ?");
132 query.addBindValue(myoid);
133
134 if(query.exec() && query.next())
135 return query.value(0).toBool();
136
137 return false;
138 }
139
140 static bool isCheckedOut(const QSqlDatabase &,
141 const QString &,
142 const QString &,
143 QString &);
144 static bool isCopyAvailable(const QSqlDatabase &,
145 const QString &,
146 const QString &,
147 const QString &,
148 QString &);
149 static bool isCopyCheckedOut(const QSqlDatabase &,
150 const QString &,
151 const QString &,
152 const QString &,
153 QString &);
154 static bool isGnome(void);
155 static bool isItemAvailable
156 (QString &error,
157 const QSqlDatabase &db,
158 const QString &id,
159 const QString &copyId,
160 const QString &t,
161 const bool emptyCopyIdAllowed = false);
162 static bool isRequested(const QSqlDatabase &,
163 const QString &,
164 const QString &,
165 QString &);
166 static bool userExists(const QString &, const QSqlDatabase &, QString &);
167 static int getColumnNumber(const QTableWidget *, const QString &);
168 static int getCopyNumber(const QSqlDatabase &db,
169 const QString &copyId,
170 const QString &itemOid,
171 const QString &itemTypeArg,
172 QString &errorstr);
173 static int getMaxCopyNumber(const QSqlDatabase &,
174 const QString &,
175 const QString &,
176 QString &);
177 static int getMinimumDays(const QSqlDatabase &, const QString &, QString &);
178 static int maximumReserved(const QSqlDatabase &,
179 const QString &,
180 const QString &);
181 static int quantity
182 (const QSqlDatabase &db, const QString &oid, const QString &t);
183 static int sqliteQuerySize(const QString &,
184 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
185 const QMap<QString, QVariant> &,
186 #else
187 const QVariantList &,
188 #endif
189 const QSqlDatabase &,
190 const char *,
191 const int,
192 biblioteq *);
193 static int sqliteQuerySize(const QString &,
194 const QSqlDatabase &,
195 const char *,
196 const int,
197 biblioteq *);
198 static qint64 bookAccessionNumber(const QSqlDatabase &);
199 static qint64 getSqliteUniqueId(const QSqlDatabase &, QString &);
200 static void DBAccount(const QString &,
201 const QSqlDatabase &,
202 const int,
203 QString &,
204 const QString & = "");
205 static void center(QWidget *, QMainWindow *);
206 static void createBookCopy(const QString &idArg,
207 const int copyNumber,
208 const QSqlDatabase &db,
209 QString &errorstr);
210 static void createInitialCopies(QString const &,
211 const int,
212 const QSqlDatabase &,
213 const QString &,
214 QString &);
215 static void exportPhotographs(const QSqlDatabase &,
216 const QString &,
217 const QString &,
218 const QList<QGraphicsItem *> &,
219 QWidget *);
220 static void exportPhotographs(const QSqlDatabase &,
221 const QString &,
222 const int,
223 const int,
224 const QString &,
225 QWidget *);
226 static void grantPrivs(const QString &,
227 const QString &,
228 const QSqlDatabase &,
229 QString &);
230 static void hideAdminFields(QMainWindow *, const QString &);
231 static void highlightWidget(QWidget *, const QColor &);
232 static void revokeAll(const QString &, const QSqlDatabase &, QString &);
233 static void savePassword(const QString &,
234 const QSqlDatabase &,
235 const QString &,
236 QString &);
237 static void saveQuantity(const QSqlDatabase &,
238 const QString &,
239 const int,
240 const QString &,
241 QString &);
242 static void setBookRead(const QSqlDatabase &, const bool, const quint64);
243 static void setRole(const QSqlDatabase &, QString &, const QString &);
244 static void sortCombinationBox(QComboBox *comboBox);
245 static void updateColumn(QTableWidget *,
246 const int,
247 const int,
248 const QString &);
249 static void updateColumnColor(QTableWidget *,
250 const int,
251 const int,
252 const QColor &);
253
254 private:
255 biblioteq_misc_functions(void);
256 ~biblioteq_misc_functions();
257 };
258
259 #endif
biblioteq_misc_functions
Definition: biblioteq_misc_functions.h:42
biblioteq
Definition: biblioteq.h:274