summaryrefslogtreecommitdiffstats
path: root/kexi/widget/kexidbconnectionwidget.h
blob: 72c49c894a243c4bfa903bd92dd993772377c67e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/* This file is part of the KDE project
   Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifndef KEXIDBCONNECTIONWIDGET_H
#define KEXIDBCONNECTIONWIDGET_H

#include "kexidbconnectionwidgetbase.h"

#include <kexiprojectdata.h>

#include <ktabwidget.h>
#include <kdialogbase.h>

class KTextEdit;
class KPushButton;
class KexiDBDriverComboBox;
class KexiDBConnectionWidgetDetailsBase;
class KexiDBConnectionTabWidget;

class KEXIEXTWIDGETS_EXPORT KexiDBConnectionWidget : public KexiDBConnectionWidgetBase
{
	Q_OBJECT
  TQ_OBJECT

	public:
		KexiDBConnectionWidget( TQWidget* tqparent = 0, const char* name = 0 );
		virtual ~KexiDBConnectionWidget();

		/*! Sets project data \a data.
		 \a shortcutFileName is only used to check if the file is writable 
		 (if no, "save changes" button will be disabled). */
		void setData(const KexiProjectData& data, const TQString& shortcutFileName = TQString());

		/*! Sets connection data \a data.
		 \a shortcutFileName is only used to check if the file is writable 
		 (if no, "save changes" button will be disabled). */
		void setData(const KexiDB::ConnectionData& data, const TQString& shortcutFileName = TQString());

		KexiProjectData data();

		//! \return a pointer to 'save changes' button. You can call hide() for this to hide it.
		KPushButton* saveChangesButton() const;

		//! \return a pointer to 'test connection' button. You can call hide() for this to hide it.
		KPushButton* testConnectionButton() const;

		KexiDBDriverComboBox *driversCombo() const { return m_driversCombo; }

		//! \return true if only connection data is managed by this widget
		bool connectionOnly() const;

	signals:
		//! emitted when data saving is needed
		void saveChanges();

		void loadDBList();

	protected slots:
		void slotLocationBGrpClicked(int id);
		void slotCBToggled(bool on);
		virtual void languageChange() { KexiDBConnectionWidgetBase::languageChange(); }

	protected:
		void setDataInternal(const KexiProjectData& data, bool connectionOnly, 
			const TQString& shortcutFileName);

		KexiProjectData m_data;
		KexiDBDriverComboBox *m_driversCombo;

		class Private;
		Private *d;

//		friend class KexiDBConnectionTabWidget;
};

class KEXIEXTWIDGETS_EXPORT KexiDBConnectionTabWidget : public KTabWidget
{
	Q_OBJECT
  TQ_OBJECT

	public:
		KexiDBConnectionTabWidget( TQWidget* tqparent = 0, const char* name = 0 );
		virtual ~KexiDBConnectionTabWidget();

		/*! Sets connection data \a data.
		 \a shortcutFileName is only used to check if the file is writable 
		 (if no, "save changes" button will be disabled). */
		void setData(const KexiProjectData& data, const TQString& shortcutFileName = TQString());
		void setData(const KexiDB::ConnectionData& data, const TQString& shortcutFileName = TQString());
		KexiProjectData currentProjectData();

		//! \return true if 'save password' option is selected
		bool savePasswordOptionSelected() const;

	signals:
		//! emitted when test connection is needed
		void testConnection();

	protected slots:
		void slotTestConnection();

	protected:
		KexiDBConnectionWidget *mainWidget;
		KexiDBConnectionWidgetDetailsBase* detailsWidget;

	friend class KexiDBConnectionDialog;
};

class KEXIEXTWIDGETS_EXPORT KexiDBConnectionDialog : public KDialogBase
{
	Q_OBJECT
  TQ_OBJECT

	public:
		/*! Creates a new connection dialog for project data \a data.
		 Not only connection data is visible but also database name and and title.
		 \a shortcutFileName is only used to check if the shortcut file is writable 
		 (if no, "save changes" button will be disabled).
		 The shortcut file is in .KEXIS format.
		 Connect to saveChanges() signal to react on saving changes.
		 If \a shortcutFileName is empty, the button will be hidden. 
		 \a acceptButtonGuiItem allows to override default "Open" button's appearance. */
		KexiDBConnectionDialog(const KexiProjectData& data, 
			const TQString& shortcutFileName = TQString(), 
			const KGuiItem& acceptButtonGuiItem = KGuiItem(""));

		/*! Creates a new connection dialog for connection data \a data.
		 Only connection data is visible: database name and and title fields are hidden.
		 \a shortcutFileName is only used to check if the shortcut file is writable 
		 (if no, "save changes" button will be disabled).
		 The shortcut file is in .KEXIC format. 
		 See above constructor for more details. */
		KexiDBConnectionDialog(const KexiDB::ConnectionData& data, 
			const TQString& shortcutFileName = TQString(),
			const KGuiItem& acceptButtonGuiItem = KGuiItem(""));

		~KexiDBConnectionDialog();

		/*! \return project data displayed within the dialog.
		 Information about database name and title can be empty if the dialog 
		 contain only a connection data (if second constructor was used). */
		KexiProjectData currentProjectData();

		//! \return true if 'save password' option is selected
		bool savePasswordOptionSelected() const;

		KexiDBConnectionWidget *mainWidget() const;
		KexiDBConnectionWidgetDetailsBase* detailsWidget() const;

	signals:
		//! emitted when data saving is needed
		void saveChanges();

		//! emitted when test connection is needed
		void testConnection();

		void loadDBList();

	protected:
		KexiDBConnectionTabWidget *tabWidget;
	
	private:
		void init();
};

#endif // KEXIDBCONNECTIONWIDGET_H