File indexing completed on 2024-05-12 16:40:53

0001 /* This file is part of the KDE project
0002    Copyright (C) 2005 Jarosław Staniek <staniek@kde.org>
0003    Copyright (C) 2014 Roman Shtemberko <shtemberko@gmail.com>
0004 
0005    This program is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 
0010    This program is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this program; see the file COPYING.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019  */
0020 
0021 #ifndef KEXIDBCONNECTIONWIDGET_H
0022 #define KEXIDBCONNECTIONWIDGET_H
0023 
0024 #include "kexiextwidgets_export.h"
0025 #include "ui_kexidbconnectionwidget.h"
0026 #include "ui_kexidbconnectionwidgetdetails.h"
0027 
0028 #include <kexiprojectdata.h>
0029 
0030 #include <KGuiItem>
0031 
0032 #include <QTabWidget>
0033 #include <QDialog>
0034 
0035 class QPushButton;
0036 class KexiDBDriverComboBox;
0037 class KexiDBConnectionTabWidget;
0038 
0039 class KEXIEXTWIDGETS_EXPORT KexiDBConnectionWidget
0040             : public QWidget, protected Ui::KexiDBConnectionWidget
0041 {
0042     Q_OBJECT
0043 
0044 public:
0045     explicit KexiDBConnectionWidget(QWidget* parent = 0);
0046     virtual ~KexiDBConnectionWidget();
0047 
0048     /*! Sets project data \a data.
0049      \a shortcutFileName is only used to check if the file is writable
0050      (if no, "save changes" button will be disabled). */
0051     void setData(const KexiProjectData& data, const QString& shortcutFileName = QString());
0052 
0053     /*! Sets connection data \a data.
0054      \a shortcutFileName is only used to check if the file is writable
0055      (if no, "save changes" button will be disabled). */
0056     void setData(const KDbConnectionData& data,
0057                  const QString& shortcutFileName = QString());
0058 
0059     KexiProjectData data();
0060 
0061     //! \return a pointer to 'save changes' button. You can call hide() for this to hide it.
0062     QPushButton* saveChangesButton() const;
0063 
0064     //! \return a pointer to 'test connection' button. You can call hide() for this to hide it.
0065     QPushButton* testConnectionButton() const;
0066 
0067     KexiDBDriverComboBox *driversCombo() const;
0068 
0069     //! \return true if only connection data is managed by this widget
0070     bool connectionOnly() const;
0071 
0072 Q_SIGNALS:
0073     //! emitted when data saving is needed
0074     void saveChanges();
0075 
0076     void loadDBList();
0077 
0078 protected Q_SLOTS:
0079     void slotLocationRadioClicked();
0080     void slotCBToggled(bool on);
0081     void slotShowSavePasswordHelp();
0082 
0083 protected:
0084     void setDataInternal(const KexiProjectData& data, bool connectionOnly,
0085                          const QString& shortcutFileName);
0086 
0087 private:
0088     class Private;
0089     Private * const d;
0090 
0091     friend class KexiDBConnectionTabWidget;
0092     friend class KexiDBConnectionDialog;
0093 };
0094 
0095 class KEXIEXTWIDGETS_EXPORT KexiDBConnectionWidgetDetails
0096             : public QWidget, public Ui::KexiDBConnectionWidgetDetails
0097 {
0098     Q_OBJECT
0099 public:
0100     explicit KexiDBConnectionWidgetDetails(QWidget* parent = 0);
0101     ~KexiDBConnectionWidgetDetails();
0102 };
0103 
0104 class KEXIEXTWIDGETS_EXPORT KexiDBConnectionTabWidget : public QTabWidget
0105 {
0106     Q_OBJECT
0107 public:
0108     explicit KexiDBConnectionTabWidget(QWidget* parent = 0);
0109     virtual ~KexiDBConnectionTabWidget();
0110 
0111     /*! Sets connection data \a data.
0112      \a shortcutFileName is only used to check if the file is writable
0113      (if no, "save changes" button will be disabled). */
0114     void setData(const KexiProjectData& data, const QString& shortcutFileName = QString());
0115 
0116     void setData(const KDbConnectionData& data,
0117                  const QString& shortcutFileName = QString());
0118 
0119     KexiProjectData currentProjectData();
0120 
0121     //! \return true if 'save password' option is selected
0122     bool savePasswordOptionSelected() const;
0123 
0124 Q_SIGNALS:
0125     //! emitted when test connection is needed
0126     void testConnection();
0127 
0128 protected Q_SLOTS:
0129     void slotTestConnection();
0130     void slotSocketComboboxToggled(bool on);
0131 
0132 protected:
0133     KexiDBConnectionWidget *mainWidget;
0134     KexiDBConnectionWidgetDetails* detailsWidget;
0135 
0136     friend class KexiDBConnectionDialog;
0137 };
0138 
0139 
0140 class KEXIEXTWIDGETS_EXPORT KexiDBConnectionDialog : public QDialog
0141 {
0142     Q_OBJECT
0143 
0144 public:
0145     /*! Creates a new connection dialog for project data \a data.
0146      Not only connection data is visible but also database name and title.
0147      \a shortcutFileName is only used to check if the shortcut file is writable
0148      (if no, "save changes" button will be disabled).
0149      The shortcut file is in .KEXIS format.
0150      Connect to saveChanges() signal to react on saving changes.
0151      If \a shortcutFileName is empty, the button will be hidden.
0152      \a acceptButtonGuiItem allows to override default "Open" button's appearance. */
0153     KexiDBConnectionDialog(QWidget* parent, const KexiProjectData& data,
0154                            const QString& shortcutFileName = QString(),
0155                            const KGuiItem& acceptButtonGuiItem = KGuiItem());
0156 
0157     /*! Creates a new connection dialog for connection data \a data.
0158      Only connection data is visible: database name and title fields are hidden.
0159      \a shortcutFileName is only used to check if the shortcut file is writable
0160      (if no, "save changes" button will be disabled).
0161      The shortcut file is in .KEXIC format.
0162      See above constructor for more details. */
0163     KexiDBConnectionDialog(QWidget* parent, const KDbConnectionData& data,
0164                            const QString& shortcutFileName = QString(),
0165                            const KGuiItem& acceptButtonGuiItem = KGuiItem());
0166 
0167     ~KexiDBConnectionDialog();
0168 
0169     /*! \return project data displayed within the dialog.
0170      Information about database name and title can be empty if the dialog
0171      contain only a connection data (if second constructor was used). */
0172     KexiProjectData currentProjectData();
0173 
0174     //! \return true if 'save password' option is selected
0175     bool savePasswordOptionSelected() const;
0176 
0177     KexiDBConnectionWidget *mainWidget() const;
0178     KexiDBConnectionWidgetDetails* detailsWidget() const;
0179 
0180 Q_SIGNALS:
0181     //! emitted when data saving is needed
0182     void saveChanges();
0183 
0184     //! emitted when test connection is needed
0185     void testConnection();
0186 
0187     void loadDBList();
0188 
0189 private:
0190     void init(const KGuiItem& acceptButtonGuiItem);
0191 
0192     class Private;
0193     Private * const d;
0194 };
0195 
0196 #endif // KEXIDBCONNECTIONWIDGET_H