1 /* This file is part of the KDE project 2 Copyright (C) 2003-2017 Jarosław Staniek <staniek@kde.org> 3 Copyright (C) 2012 Dimitrios T. Tanis <dimitrios.tanis@kdemail.net> 4 5 This program is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Library General Public 7 License as published by the Free Software Foundation; either 8 version 2 of the License, or (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Library General Public License for more details. 14 15 You should have received a copy of the GNU Library General Public License 16 along with this program; see the file COPYING. If not, write to 17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 */ 20 21 #ifndef KEXICONNECTIONSELECTORWIDGET_H 22 #define KEXICONNECTIONSELECTORWIDGET_H 23 24 #include <core/kexidbconnectionset.h> 25 #include <KexiFileFilters.h> 26 #include "kexiextwidgets_export.h" 27 28 #include <QTreeWidgetItem> 29 30 class QAbstractButton; 31 class KDbDriverMetaData; 32 33 //! An item for a single database connection 34 class KEXIEXTWIDGETS_EXPORT ConnectionDataLVItem : public QTreeWidgetItem 35 { 36 public: 37 ConnectionDataLVItem(KDbConnectionData *data, 38 const KDbDriverMetaData &driverMetaData, QTreeWidget* list); 39 ~ConnectionDataLVItem(); 40 41 void update(const KDbDriverMetaData& driverMetaData); 42 43 using QTreeWidgetItem::data; data()44 KDbConnectionData *data() const { 45 return m_data; 46 } 47 48 protected: 49 KDbConnectionData *m_data; 50 }; 51 52 //! @short Widget that allows to select a database connection (file- or server-based) 53 /*! The widget allows to select database connection without choosing database itself. 54 */ 55 class KEXIEXTWIDGETS_EXPORT KexiConnectionSelectorWidget : public QWidget 56 { 57 Q_OBJECT 58 59 public: 60 //! Defines connection type 61 enum ConnectionType { 62 FileBased = 1, //!< the widget displays file-based connection 63 ServerBased = 2 //!< the widget displays server-based connection 64 }; 65 66 //! Defines operation mode 67 enum OperationMode { 68 Opening = 1, 69 Saving = 2 70 }; 71 72 /*! Constructs a new widget which contains \a conn_set as connection set. 73 \a conn_set can be altered, because Add/Edit/Remove buttons are available 74 to users. \a startDirOrVariable can be provided to specify a start dir for file browser 75 (it can also contain a configuration variable name with "kfiledialog:///" prefix 76 as described in KRecentDirs documentation). */ 77 //! @todo KEXI3 add equivalent of kfiledialog:/// for startDirOrVariable 78 KexiConnectionSelectorWidget(KexiDBConnectionSet *conn_set, 79 const QUrl& startDirOrVariable, 80 OperationMode mode, 81 QWidget* parent = 0); 82 83 virtual ~KexiConnectionSelectorWidget(); 84 85 /*! After accepting this dialog this method returns wherher user selected 86 file- or server-based connection. */ 87 ConnectionType selectedConnectionType() const; 88 89 /*! \return data of selected connection, if server-based connection was selected. 90 Returns NULL if no selection has been made or file-based connection 91 has been selected. 92 @see selectedConnectionType() 93 */ 94 KDbConnectionData* selectedConnectionData() const; 95 96 /*! \return the name of database file, if file-based connection was selected. 97 Returns empty string if no selection has been made or server-based connection 98 has been selected. 99 //! @note Call checkSelectedFile() first 100 @see selectedConnectionType() 101 */ 102 QString selectedFile() const; 103 104 QTreeWidget* connectionsList() const; 105 106 bool confirmOverwrites() const; 107 108 bool hasSelectedConnection() const; 109 110 /*! @return true if the current file URL meets requied constraints (i.e. the file exists) 111 Shows appropriate message box if needed. */ 112 bool checkSelectedFile(); 113 114 //! @return highlighted file 115 QString highlightedFile() const; 116 117 Q_SIGNALS: 118 void connectionItemExecuted(ConnectionDataLVItem *item); 119 void connectionItemHighlighted(ConnectionDataLVItem *item); 120 void connectionSelected(bool hasSelected); 121 void fileSelected(const QString &name); 122 123 public Q_SLOTS: 124 void showSimpleConnection(); 125 void showAdvancedConnection(); 126 virtual void setFocus(); 127 128 /*! Hides helpers on the server based connection page 129 (sometimes it's convenient not to have these): 130 - "Select existing database server's connection..." (label at the top) 131 - "Click "Back" button" (label at the bottom) 132 - "Back" button itself */ 133 void hideHelpers(); 134 void hideConnectonIcon(); 135 void hideDescription(); 136 137 /*! Sets selected filename to @a name. 138 Only works when selectedConnectionType()==FileBased. */ 139 void setSelectedFile(const QString &name); 140 141 /*! If true, user will be asked to accept overwriting existing project. 142 This is true by default. */ 143 void setConfirmOverwrites(bool set); 144 145 void setFileMode(KexiFileFilters::Mode mode); 146 147 void setAdditionalMimeTypes(const QStringList &mimeTypes); 148 149 //! Sets excluded mime types 150 void setExcludedMimeTypes(const QStringList& mimeTypes); 151 152 void setFileWidgetFrameVisible(bool set); 153 154 protected Q_SLOTS: 155 void slotConnectionItemExecuted(QTreeWidgetItem *item); 156 void slotConnectionItemExecuted(); 157 void slotRemoteAddBtnClicked(); 158 void slotRemoteEditBtnClicked(); 159 void slotRemoteRemoveBtnClicked(); 160 void slotConnectionSelectionChanged(); 161 void slotPrjTypeSelected(QAbstractButton *btn); 162 void slotFileConnectionSelected(const QString &name); 163 void slotConnectionSelected(); 164 165 protected: 166 virtual bool eventFilter(QObject* watched, QEvent* event); 167 168 private: 169 ConnectionDataLVItem* addConnectionData(KDbConnectionData* data); 170 ConnectionDataLVItem* selectedConnectionDataItem() const; 171 172 class Private; 173 Private * const d; 174 }; 175 176 #endif // KEXICONNECTIONSELECTORWIDGET_H 177