summaryrefslogtreecommitdiffstats
path: root/part/kxenewfilesettings.cpp
blob: cc9a4fc4b8473e23d47ecdbb0e327a6daad4c6b1 (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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/***************************************************************************
                           kxenewfilesettings.cpp
                           ----------------------
    begin                : Tue Dec 02 2003
    copyright            : (C) 2003 by The KXMLEditor Team
    email                : hartig@users.sourceforge.net
 ***************************************************************************/

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

#include "kxenewfilesettings.h"
#include "kxenewfilesettingspage.h"

#include <klocale.h>
#include <kconfig.h>
#include <kdebug.h>

#include <tqframe.h>
#include <tqlineedit.h>
#include <tqcombobox.h>
#include <tqbuttongroup.h>
#include <tqradiobutton.h>

#define CONF_ENTRY_NAME_DFLT_VERSION "Default version"
#define DFLT_VALUE_DFLT_VERSION "1.0"

#define CONF_ENTRY_NAME_DFLT_ENCODING "Default encoding"
#define DFLT_VALUE_DFLT_ENCODING "UTF-8"

#define CONF_ENTRY_NAME_DFLT_NEWFILE_CREAT_BEHAVIOUR "Default behaviour"
#define DFLT_VALUE_NEWFILE_CREAT_BEHAVIOUR UseDefaults


KXENewFileSettings::KXENewFileSettings( TQObject * pParent, const char * pszName )
 : KXESettings( "New File Settings", pParent, pszName ),
   m_strDfltVersion( DFLT_VALUE_DFLT_VERSION ),
   m_strDfltEncoding( DFLT_VALUE_DFLT_ENCODING ),
   m_enmNewFileCreaBehav( DFLT_VALUE_NEWFILE_CREAT_BEHAVIOUR ),
   m_pDialogPage(0)
{
}


void KXENewFileSettings::write( KConfig * pConfig ) const
{
	pConfig->writeEntry( CONF_ENTRY_NAME_DFLT_VERSION, m_strDfltVersion );
	pConfig->writeEntry( CONF_ENTRY_NAME_DFLT_ENCODING, m_strDfltEncoding );
	pConfig->writeEntry( CONF_ENTRY_NAME_DFLT_NEWFILE_CREAT_BEHAVIOUR, m_enmNewFileCreaBehav );
}


void KXENewFileSettings::read( const KConfig * pConfig )
{
	m_strDfltVersion = pConfig->readEntry( CONF_ENTRY_NAME_DFLT_VERSION, DFLT_VALUE_DFLT_VERSION );
	m_strDfltEncoding = pConfig->readEntry( CONF_ENTRY_NAME_DFLT_ENCODING, DFLT_VALUE_DFLT_ENCODING );
	m_enmNewFileCreaBehav = static_cast<NewFileCreationBehaviour> ( pConfig->readNumEntry( CONF_ENTRY_NAME_DFLT_NEWFILE_CREAT_BEHAVIOUR, DFLT_VALUE_NEWFILE_CREAT_BEHAVIOUR ) );
}


TQString KXENewFileSettings::dialogPageName() const
{
	return i18n( "New Files" );
}

TQString KXENewFileSettings::dialogPageHeader() const
{
	return i18n( "New File Settings" );
}

TQString KXENewFileSettings::dialogPageIcon() const
{
	return "files";
}


TQWidget * KXENewFileSettings::dialogPage( TQFrame * pParent )
{

	if ( ! m_pDialogPage )
	{
		// create the page if necessary
		m_pDialogPage = new KXENewFileSettingsPage( pParent, "new files config.dialog page" );

		// and fill its widgets with the corresponding values
		m_pDialogPage->m_pDfltEncoding->insertStringList( encodings() );
		updatePage();

		connect( m_pDialogPage->m_pDfltVersion, SIGNAL(textChanged(const TQString&)), this, SIGNAL(sigDialogPageChanged()) );
		connect( m_pDialogPage->m_pDfltEncoding, SIGNAL(activated(int)), this, SIGNAL(sigDialogPageChanged()) );
		connect( m_pDialogPage->m_pNewFileCreatBehav1, SIGNAL(toggled(bool)), this, SIGNAL(sigDialogPageChanged()) );
		connect( m_pDialogPage->m_pNewFileCreatBehav2, SIGNAL(toggled(bool)), this, SIGNAL(sigDialogPageChanged()) );
		connect( m_pDialogPage->m_pNewFileCreatBehav3, SIGNAL(toggled(bool)), this, SIGNAL(sigDialogPageChanged()) );
	}

	return m_pDialogPage;
}

void KXENewFileSettings::setFromPage()
{
	if ( m_pDialogPage )
	{
		m_strDfltVersion = m_pDialogPage->m_pDfltVersion->text();
		m_strDfltEncoding = m_pDialogPage->m_pDfltEncoding->currentText();

		if ( m_pDialogPage->m_pNewFileCreatBehav1->isChecked() )
			m_enmNewFileCreaBehav = CreateEmptyFile;
		else if ( m_pDialogPage->m_pNewFileCreatBehav2->isChecked() )
			m_enmNewFileCreaBehav = CreateWithAssistance;
		else if ( m_pDialogPage->m_pNewFileCreatBehav3->isChecked() )
			m_enmNewFileCreaBehav = UseDefaults;
	}
}

void KXENewFileSettings::updatePage() const
{
	if ( m_pDialogPage )
	{
		m_pDialogPage->m_pDfltVersion->setText( m_strDfltVersion );
		m_pDialogPage->m_pDfltEncoding->setCurrentText( m_strDfltEncoding );

		switch ( m_enmNewFileCreaBehav )
		{
			case CreateEmptyFile:
				m_pDialogPage->m_pNewFileCreatBehav->setButton( m_pDialogPage->m_pNewFileCreatBehav->id( m_pDialogPage->m_pNewFileCreatBehav1 ) );
				break;
			case CreateWithAssistance:
				m_pDialogPage->m_pNewFileCreatBehav->setButton( m_pDialogPage->m_pNewFileCreatBehav->id( m_pDialogPage->m_pNewFileCreatBehav2 ) );
				break;
			case UseDefaults:
				m_pDialogPage->m_pNewFileCreatBehav->setButton( m_pDialogPage->m_pNewFileCreatBehav->id( m_pDialogPage->m_pNewFileCreatBehav3 ) );
				break;
			default:
				kdError() << "KXENewFileSettings::updatePage: unknown creation behavior" << endl;
		}
	}
}

TQStringList KXENewFileSettings::encodings()
{
	static TQStringList lstEncs;
	if ( lstEncs.empty() )
	{
		lstEncs.append("UTF-8");
		lstEncs.append("ISO-8859-1");
		lstEncs.append("ISO-8859-2");
		lstEncs.append("ISO-8859-3");
		lstEncs.append("ISO-8859-4");
		lstEncs.append("ISO-8859-5");
		lstEncs.append("ISO-8859-6");
		lstEncs.append("ISO-8859-7");
		lstEncs.append("ISO-8859-8");
		lstEncs.append("ISO-8859-9");
	}
	return lstEncs;
}


/////////////////////////////////////////////////
// function(s) to set this settings group data //
/////////////////////////////////////////////////

void KXENewFileSettings::setNewFileCreaBehav( NewFileCreationBehaviour enmNewFileCreaBehav, KConfig * pConfig )
{
	// if the data really has been changed
	if ( m_enmNewFileCreaBehav != enmNewFileCreaBehav )
	{
		// set this object's data to the new one given
		m_enmNewFileCreaBehav = enmNewFileCreaBehav;

		// update the corresponding widget in the config.dialog page, if necessary
		if ( m_pDialogPage )
		{
			blockSignals( true );

			switch ( enmNewFileCreaBehav )
			{
				case CreateEmptyFile:
					m_pDialogPage->m_pNewFileCreatBehav->setButton( m_pDialogPage->m_pNewFileCreatBehav->id( m_pDialogPage->m_pNewFileCreatBehav1 ) );
					break;
				case CreateWithAssistance:
					m_pDialogPage->m_pNewFileCreatBehav->setButton( m_pDialogPage->m_pNewFileCreatBehav->id( m_pDialogPage->m_pNewFileCreatBehav2 ) );
					break;
				case UseDefaults:
					m_pDialogPage->m_pNewFileCreatBehav->setButton( m_pDialogPage->m_pNewFileCreatBehav->id( m_pDialogPage->m_pNewFileCreatBehav3 ) );
					break;
				default:
					kdError() << "KXENewFileSettings::dialogPage: unknown creation behavior" << endl;
			}

			blockSignals( false );
		}

		// store the new data (only the given one) to the given config file
		setConfigGroup( pConfig );
		pConfig->writeEntry( CONF_ENTRY_NAME_DFLT_NEWFILE_CREAT_BEHAVIOUR, m_enmNewFileCreaBehav );

		// and inform everyone about the changing of our data
		emit sigChanged();
	}
}