summaryrefslogtreecommitdiffstats
path: root/kompare/libdialogpages/filespage.cpp
blob: 0bbc87fe3fce244e8f68f429360988504409472a (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
/***************************************************************************
                                filespage.cpp
                                -------------------
        begin                   : Sun Apr 18 2004
        copyright               : (C) 2004 Otto Bruggeman
        email                   : [email protected]

****************************************************************************/

/***************************************************************************
**
**   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 <tqlayout.h>
#include <tqgroupbox.h>

#include <kapplication.h>
#include <kcharsets.h>
#include <kconfig.h>
#include <kdebug.h>
#include <kdialog.h>
#include <klocale.h>
#include <kurlcombobox.h>
#include <kurlrequester.h>

#include "filessettings.h"
#include "filespage.h"

FilesPage::FilesPage( TQWidget* parent ) : PageBase( parent ), m_URLChanged( false )
{
	TQWidget* page = new TQWidget( this );
	TQVBoxLayout* tqlayout = new TQVBoxLayout( page );
	tqlayout->setSpacing( KDialog::spacingHint() );
	tqlayout->setMargin( KDialog::marginHint() );

	m_firstGB = new TQGroupBox( 1, Qt::Vertical, "You have to set this moron :)", page );
	m_firstURLComboBox = new KURLComboBox( KURLComboBox::Both, true, m_firstGB, "SourceURLComboBox" );
	m_firstURLRequester = new KURLRequester( m_firstURLComboBox, m_firstGB );
	m_firstURLRequester->setFocus();

	m_secondGB = new TQGroupBox( 1, Qt::Vertical, "This too moron !", page );
	m_secondURLComboBox = new KURLComboBox( KURLComboBox::Both, true, m_secondGB, "DestURLComboBox" );
	m_secondURLRequester = new KURLRequester( m_secondURLComboBox, m_secondGB );

	connect( m_firstURLRequester, TQT_SIGNAL( urlSelected( const TQString & ) ), TQT_SLOT( setSecondURL( const TQString & ) ) );
	connect( m_secondURLRequester, TQT_SIGNAL( urlSelected( const TQString & ) ), TQT_SLOT( setFirstURL( const TQString & ) ) );

	m_thirdGB = new TQGroupBox( 1, Qt::Vertical, i18n( "Encoding" ), page );
	m_encodingComboBox = new TQComboBox( false, m_thirdGB, "encoding_combobox" );
	m_encodingComboBox->insertStringList( KGlobal::charsets()->availableEncodingNames() );

	tqlayout->addWidget( m_firstGB );
	tqlayout->addWidget( m_secondGB );
	tqlayout->addWidget( m_thirdGB );

	tqlayout->addStretch( 1 );
	page->setMinimumSize( sizeHintForWidget( page ) );

	addTab( page, i18n( "&Files" ) );
}

FilesPage::~FilesPage()
{
	m_settings = 0;
}

KURLRequester* FilesPage::firstURLRequester() const
{
	return m_firstURLRequester;
}

KURLRequester* FilesPage::secondURLRequester() const
{
	return m_secondURLRequester;
}

TQString FilesPage::encoding() const
{
	return m_encodingComboBox->currentText();
}

void FilesPage::setFirstGroupBoxTitle( const TQString& title )
{
	m_firstGB->setTitle( title );
}

void FilesPage::setSecondGroupBoxTitle( const TQString& title )
{
	m_secondGB->setTitle( title );
}

void FilesPage::setURLsInComboBoxes()
{
//	kdDebug() << "first : " << m_firstURLComboBox->currentText() << endl;
//	kdDebug() << "second: " << m_secondURLComboBox->currentText() << endl;
	m_firstURLComboBox->setURL( KURL( m_firstURLComboBox->currentText() ) );
	m_secondURLComboBox->setURL( KURL( m_secondURLComboBox->currentText() ) );
}


void FilesPage::setFirstURLRequesterMode( unsigned int mode )
{
	m_firstURLRequester->setMode( mode );
}

void FilesPage::setSecondURLRequesterMode( unsigned int mode )
{
	m_secondURLRequester->setMode( mode );
}

void FilesPage::setSettings( FilesSettings* settings )
{
	m_settings = settings;

	m_firstURLComboBox->setURLs( m_settings->m_recentSources );
	m_firstURLComboBox->setURL( KURL( m_settings->m_lastChosenSourceURL ) );
	m_secondURLComboBox->setURLs( m_settings->m_recentDestinations );
	m_secondURLComboBox->setURL( KURL( m_settings->m_lastChosenDestinationURL ) );
	m_encodingComboBox->setCurrentText( m_settings->m_encoding );
}

void FilesPage::restore()
{
	// this shouldn't do a thing...
}

void FilesPage::apply()
{
	m_settings->m_recentSources            = m_firstURLComboBox->urls();
	m_settings->m_lastChosenSourceURL      = m_firstURLComboBox->currentText();
	m_settings->m_recentDestinations       = m_secondURLComboBox->urls();
	m_settings->m_lastChosenDestinationURL = m_secondURLComboBox->currentText();
	m_settings->m_encoding                 = m_encodingComboBox->currentText();
}

void FilesPage::setDefaults()
{
	m_firstURLComboBox->setURLs( "" );
	m_firstURLComboBox->setURL( KURL( "" ) );
	m_secondURLComboBox->setURLs( "" );
	m_secondURLComboBox->setURL( KURL( "" ) );
	m_encodingComboBox->setCurrentText( "Default" );
}

void FilesPage::setFirstURL( const TQString &url )
{
	TQString _url = url;
	if ( !m_URLChanged )
	{
		m_firstURLRequester->setURL( _url.remove( url.section( '/', -1 ) ) );
		m_URLChanged = true;
	}
}

void FilesPage::setSecondURL( const TQString &url )
{
	TQString _url = url;
	if ( !m_URLChanged )
	{
		m_secondURLRequester->setURL( _url.remove( url.section( '/', -1 ) ) );
		m_URLChanged = true;
	}
}

#include "filespage.moc"