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

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2009-11-14
0007  * Description : database settings widget
0008  *
0009  * SPDX-FileCopyrightText: 2009-2010 by Holger Foerster <Hamsi2k at freenet 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_SETTINGS_WIDGET_H
0017 #define DIGIKAM_DB_SETTINGS_WIDGET_H
0018 
0019 // Qt includes
0020 
0021 #include <QWidget>
0022 #include <QString>
0023 
0024 // Local includes
0025 
0026 #include "digikam_export.h"
0027 
0028 namespace Digikam
0029 {
0030 
0031 class ApplicationSettings;
0032 class DbEngineParameters;
0033 
0034 class DIGIKAM_GUI_EXPORT DatabaseSettingsWidget : public QWidget
0035 {
0036     Q_OBJECT
0037 
0038 public:
0039 
0040     enum DatabaseType
0041     {
0042         SQlite          = 0,
0043         MysqlInternal   = 1,
0044         MysqlServer     = 2
0045     };
0046 
0047 public:
0048 
0049     explicit DatabaseSettingsWidget(QWidget* const parent = nullptr);
0050     ~DatabaseSettingsWidget() override;
0051 
0052 public:
0053 
0054     void setParametersFromSettings(const ApplicationSettings* const settings,
0055                                    const bool& migration = false);
0056     DbEngineParameters getDbEngineParameters()  const;
0057 
0058     void    setDatabaseType(int type);
0059     int     databaseType()                      const;
0060 
0061     QString databaseBackend()                   const;
0062 
0063     void setDatabasePath(const QString& path);
0064     QString databasePath()                      const;
0065 
0066     DbEngineParameters orgDatabasePrm()         const;
0067 
0068     /**
0069      * For Sqlite or MysqlInternal, check properties of local path to store database files.
0070      * For MysqlServer, check the network connection and database names.
0071      */
0072     bool checkDatabaseSettings();
0073 
0074 private:
0075 
0076     void setupMainArea();
0077     void handleInternalServer(int index);
0078     void setDatabaseInputFields(int index);
0079     bool isNotEqualToThumbName(const QString& name);
0080     bool checkMysqlServerConnection(QString& error);
0081     bool checkMysqlServerConnectionConfig(QString& error);
0082     bool checkMysqlServerDbNamesConfig(QString& error);
0083     bool checkDatabasePath();
0084 
0085 private Q_SLOTS:
0086 
0087     void slotHandleDBTypeIndexChanged(int index);
0088     void slotDatabasePathEditedDelayed();
0089     void slotDatabasePathEdited();
0090     void slotUpdateSqlInit();
0091     void slotCheckMysqlServerConnection();
0092     void slotResetMysqlServerDBNames();
0093 
0094 private:
0095 
0096     class Private;
0097     Private* const d;
0098 };
0099 
0100 } // namespace Digikam
0101 
0102 #endif // DIGIKAM_DB_SETTINGS_WIDGET_H