File indexing completed on 2025-01-19 03:53:33

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2010-04-02
0007  * Description : Database engine low level error handler
0008  *
0009  * SPDX-FileCopyrightText: 2009-2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0010  * SPDX-FileCopyrightText: 2010-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #ifndef DIGIKAM_DB_ENGINE_ERROR_HANDLER_H
0017 #define DIGIKAM_DB_ENGINE_ERROR_HANDLER_H
0018 
0019 // Qt includes
0020 
0021 #include <QObject>
0022 #include <QMetaType>
0023 #include <QSqlError>
0024 
0025 // Local includes
0026 
0027 #include "digikam_export.h"
0028 
0029 namespace Digikam
0030 {
0031 
0032 class DIGIKAM_EXPORT DbEngineErrorAnswer
0033 {
0034 
0035 public:
0036 
0037     DbEngineErrorAnswer()                         = default;
0038     virtual ~DbEngineErrorAnswer()                = default;
0039 
0040     virtual void connectionErrorContinueQueries() = 0;
0041     virtual void connectionErrorAbortQueries()    = 0;
0042 
0043 private:
0044 
0045     Q_DISABLE_COPY(DbEngineErrorAnswer)
0046 };
0047 
0048 // -----------------------------------------------------------------
0049 
0050 class DIGIKAM_EXPORT DbEngineErrorHandler : public QObject
0051 {
0052     Q_OBJECT
0053 
0054 public:
0055 
0056     explicit DbEngineErrorHandler();
0057     ~DbEngineErrorHandler()                                     override;
0058 
0059 public Q_SLOTS:
0060 
0061     // NOTE: These all need to be slots, possibly called by queued connection
0062 
0063     /**
0064      *  In the situation of a connection error,
0065      *  all threads will be waiting with their queries
0066      *  and this method is called.
0067      *  This method can display an error dialog and try to repair
0068      *  the connection.
0069      *  It must then call either connectionErrorContinueQueries()
0070      *  or connectionErrorAbortQueries().
0071      *  The method is guaranteed to be invoked in the UI thread.
0072      */
0073     virtual void connectionError(DbEngineErrorAnswer* answer,
0074                                  const QSqlError& error,
0075                                  const QString& query)          = 0;
0076 
0077     /**
0078      *  In the situation of an error requiring user intervention or information,
0079      *  all threads will be waiting with their queries
0080      *  and this method is called.
0081      *  This method can display an error dialog.
0082      *  It must then call either connectionErrorContinueQueries()
0083      *  or connectionErrorAbortQueries().
0084      *  The method is guaranteed to be invoked in the UI thread.
0085      */
0086     virtual void consultUserForError(DbEngineErrorAnswer* answer,
0087                                      const QSqlError& error,
0088                                      const QString& query)      = 0;
0089 
0090 private:
0091 
0092     // Disable
0093     DbEngineErrorHandler(QObject*) = delete;
0094 };
0095 
0096 } // namespace Digikam
0097 
0098 Q_DECLARE_METATYPE(Digikam::DbEngineErrorAnswer*)
0099 
0100 #endif // DIGIKAM_DB_ENGINE_ERROR_HANDLER_H