File indexing completed on 2024-05-12 15:27:46

0001 /***************************************************************************
0002     File                 : DatabaseManagerWidget.h
0003     Project              : LabPlot
0004     Description          : widget for managing database connections
0005     --------------------------------------------------------------------
0006     Copyright            : (C) 2017 Alexander Semke (alexander.semke@web.de)
0007 
0008  ***************************************************************************/
0009 
0010 /***************************************************************************
0011  *                                                                         *
0012  *  This program is free software; you can redistribute it and/or modify   *
0013  *  it under the terms of the GNU General Public License as published by   *
0014  *  the Free Software Foundation; either version 2 of the License, or      *
0015  *  (at your option) any later version.                                    *
0016  *                                                                         *
0017  *  This program is distributed in the hope that it will be useful,        *
0018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
0019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
0020  *  GNU General Public License for more details.                           *
0021  *                                                                         *
0022  *   You should have received a copy of the GNU General Public License     *
0023  *   along with this program; if not, write to the Free Software           *
0024  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
0025  *   Boston, MA  02110-1301  USA                                           *
0026  *                                                                         *
0027  ***************************************************************************/
0028 #ifndef DATABASEMANAGERWIDGET_H
0029 #define DATABASEMANAGERWIDGET_H
0030 
0031 #include "ui_databasemanagerwidget.h"
0032 
0033 #ifdef HAVE_KF5_SYNTAX_HIGHLIGHTING
0034 #include <repository.h>
0035 namespace KSyntaxHighlighting {
0036     class SyntaxHighlighter;
0037 }
0038 #endif
0039 
0040 class DatabaseManagerWidget : public QWidget {
0041     Q_OBJECT
0042 
0043 public:
0044     explicit DatabaseManagerWidget(QWidget*, QString);
0045 
0046     struct SQLConnection {
0047         int port;
0048         QString name;
0049         QString driver;
0050         QString hostName;
0051         QString dbName;
0052         QString userName;
0053         QString password;
0054         bool customConnectionEnabled{false};
0055         QString customConnectionString;
0056     };
0057 
0058     QString connection() const;
0059     void setCurrentConnection(const QString&);
0060     void saveConnections();
0061     static bool isFileDB(const QString&);
0062     static bool isODBC(const QString&);
0063 
0064 private:
0065     Ui::DatabaseManagerWidget ui;
0066     QList<SQLConnection> m_connections;
0067     SQLConnection* m_current_connection = nullptr;
0068     bool m_initializing{false};
0069     QString m_configPath;
0070     QString m_initConnName;
0071 #ifdef HAVE_KF5_SYNTAX_HIGHLIGHTING
0072     KSyntaxHighlighting::SyntaxHighlighter* m_highlighter{nullptr};
0073     KSyntaxHighlighting::Repository m_repository;
0074 #endif
0075 
0076     QString uniqueName();
0077     void loadConnection();
0078     int defaultPort(const QString&) const;
0079     void dataChanged();
0080 
0081 private slots:
0082     void loadConnections();
0083     void addConnection();
0084     void deleteConnection();
0085     void testConnection();
0086     void connectionChanged(int);
0087 
0088     void nameChanged(const QString&);
0089     void driverChanged();
0090     void selectFile();
0091     void hostChanged();
0092     void portChanged();
0093     void databaseNameChanged();
0094     void customConnectionEnabledChanged(int);
0095     void customConnectionChanged();
0096     void userNameChanged();
0097     void passwordChanged();
0098 
0099 signals:
0100     void changed();
0101 };
0102 
0103 #endif