summaryrefslogtreecommitdiffstats
path: root/kexi/main/startup/KexiStartupFileDialog.h
blob: e27f200d7d6af5516c94613966a5f63476e31c97 (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
/* This file is part of the KDE project
   Copyright (C) 2003-2005 Jaroslaw Staniek <js@iidea.pl>

   This library 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 library 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 library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#ifndef _KexiStartupFileDialog_h_
#define _KexiStartupFileDialog_h_

#include <tdefiledialog.h>

#ifdef TQ_WS_WIN
# include "KexiStartupFileDialogBase_win.h"
#else
  typedef KFileDialog KexiStartupFileDialogBase;
#endif


//! @short Widget for opening/saving files supported by Kexi
class KEXIMAIN_EXPORT KexiStartupFileDialog : public KexiStartupFileDialogBase
{
	Q_OBJECT
  
	
public:
	/*! Dialog mode:
	 - Opening opens existing database (or shortcut)
	 - SavingFileBasedDB saves file-based database file
	 - SavingServerBasedDB saves server-based (shortcut) file
	 - CustomOpening can be used for opening other files, like CSV
	*/
	typedef enum Mode { 
		Opening = 1,
		SavingFileBasedDB = 2,
		SavingServerBasedDB = 4,
		Custom = 256
	};
	
	KexiStartupFileDialog(
		const TQString& startDirOrVariable, int mode, TQWidget *parent=0, const char *name=0);

	virtual ~KexiStartupFileDialog();

	/*! Helper. Displays "The file %1 already exists. Do you want to overwrite it?" yes/no message box.
	 \a parent is used as a parent of the KMessageBox.
	 \return true if \a filePath file does not exists or user has agreed on overwriting,
	 false in user do not want to overwrite. */
	static bool askForOverwriting(const TQString& filePath, TQWidget *parent = 0);

	void setMode(int mode);

	TQStringList additionalFilters() const;

	//! Sets additional filters list, e.g. "text/x-csv"
	void setAdditionalFilters(const TQStringList &mimeTypes);

	TQStringList excludedFilters() const;

	//! Excludes filters list
	void setExcludedFilters(const TQStringList &mimeTypes);

//	KURL currentURL();
	TQString currentFileName();

//#ifndef TQ_WS_WIN
//	KURLComboBox *locationWidget() const;
//#endif
	//! just sets locationWidget()->setCurrentText(fn)
	//! (and something similar on win32)
	void setLocationText(const TQString& fn);

	//! Sets default extension which will be added after accepting
	//! if user didn't provided one. This method is usable when there is 
	//! more than one filter so there is no rule what extension should be selected
	//! (by default first one is selected).
	void setDefaultExtension(const TQString& ext) { m_defaultExtension = ext; }
	
	/*! \return true if the current URL meets requies constraints 
	 (i.e. exists or doesn't exist);
	 shows appropriate message box if needed. */
	bool checkFileName();
//	bool checkURL();

	/*! If true, user will be asked to accept overwriting existing file. 
	 This is true by default. */
	void setConfirmOverwrites(bool set) { m_confirmOverwrites = set; }

	virtual bool eventFilter ( TQObject * watched, TQEvent * e );

public slots:
	virtual void show();

	virtual void setFocus();

	// Typing a file that doesn't exist closes the file dialog, we have to
	// handle this case better here.
	virtual void accept();

signals:
	//entered file name is accepted
	void accepted();
	void rejected();
	
protected slots:
	virtual void reject();

private:
	void updateFilters();

//	KURL m_lastUrl;
	TQString m_lastFileName;
	int m_mode;
	TQStringList m_additionalMimeTypes, m_excludedMimeTypes;
	TQString m_defaultExtension;
	bool m_confirmOverwrites : 1;
	bool m_filtersUpdated : 1;
};

#endif