summaryrefslogtreecommitdiffstats
path: root/src/stylesheetdialog.cpp
blob: a54cce113b0aecb0b5171439b9ded512e769b428 (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
/***************************************************************************
 *                                                                         *
 *   Copyright (C) 2005, 2006 by Kevin Gilbert                             *
 *   kev.gilbert@cdu.edu.au                                                *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   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 General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 *                                                                         *
 ***************************************************************************/

#include <tqiconset.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqlineedit.h>
#include <tqlistbox.h>
#include <tqpushbutton.h>
#include <tqstring.h>
#include <tqstringlist.h>

#include <kdebug.h>
#include <tdefiledialog.h>
#include <tdeglobalsettings.h>
#include <kiconloader.h>
#include <tdelocale.h>
#include <tdemessagebox.h>

#include "stylesheetdialog.h"

//	constructor
//	===========

StylesheetDialog::StylesheetDialog( const TQString&     currentStylesheetURL,
									const TQStringList& stylesheetURLs,
									TQWidget*           parent,
									const char*        name )
: KDialogBase( Plain, "'man' stylesheet location", Ok | Cancel, Ok, parent, name ),
  m_currentStylesheetURL( currentStylesheetURL ),
  m_stylesheetURLs( stylesheetURLs )
{	TQGridLayout* layout          = new TQGridLayout( plainPage( ));
	TDEIconLoader* iconLoader      = TDEGlobal::iconLoader( );
	TQIconSet     fileOpenIconSet = iconLoader->loadIconSet( "document-open",   TDEIcon::Small );
	TQPushButton* urlButton       = new TQPushButton( fileOpenIconSet, NULL, plainPage( ), "stylesheet url button" );
	m_urlLineEdit                = new TQLineEdit( plainPage( ), "stylesheet url line edit" );
	m_urlListBox                 = new TQListBox( plainPage( ), "stylesheet url list box" );

	m_urlListBox->insertStringList( stylesheetURLs );
	m_urlLineEdit->setMinimumWidth( int( 1.1 * m_urlListBox->maxItemWidth( )));
	m_urlLineEdit->setText( currentStylesheetURL );

	layout->addWidget( new TQLabel( "Stylesheet URL: ", plainPage( ), "url label" ), 1, 1, TQt::AlignRight );
	layout->addWidget( m_urlLineEdit, 1, 2 );
	layout->addWidget( urlButton,     1, 3 );
	layout->addWidget( new TQLabel( "Known URLs: ", plainPage( ), "url label" ), 3, 1, TQt::AlignRight | TQt::AlignTop );
	layout->addWidget( m_urlListBox,  3, 2 );

	layout->setColStretch( 0,  1 );
	layout->setColStretch( 2, 20 );
	layout->setColStretch( 4,  1 );

	layout->setRowStretch( 0,  2 );
	layout->setRowStretch( 2,  1 );
	layout->setRowStretch( 3, 10 );
	layout->setRowStretch( 4,  2 );

	connect( urlButton,    TQ_SIGNAL( clicked( )),                     TQ_SLOT( slotURLButtonClicked( )));
	connect( m_urlListBox, TQ_SIGNAL( doubleClicked( TQListBoxItem* )), TQ_SLOT( slotURLListBoxDoubleClicked( TQListBoxItem* )));
}

//	slotOk
//	======

void StylesheetDialog::slotOk( )
{	TQString currentStylesheetURL = m_urlLineEdit->text( );
	TQStringList::Iterator it = m_stylesheetURLs.find( currentStylesheetURL );

	if( it != m_stylesheetURLs.end( ))
		m_stylesheetURLs.remove( it );

	if( !TQFile::exists( currentStylesheetURL ))
	{	KMessageBox::sorry( this, TQString( i18n( "The stylesheet \"%1\" does not exist" )).arg( currentStylesheetURL ), i18n( "Nonexistant stylesheet" ));
		TQListBoxItem* item = m_urlListBox->findItem( currentStylesheetURL, TQt::ExactMatch );

		if( item != NULL )
		{	m_urlListBox->removeItem( m_urlListBox->index( item ));
			emit( stylesheetRemoved( ));
		}

		m_urlLineEdit->clear( );
		return;
	}

	m_stylesheetURLs.push_front( currentStylesheetURL );
	KDialogBase::slotOk( );
}

//	slotURLButtonClicked
//	====================

void StylesheetDialog::slotURLButtonClicked( )
{	TQString filter        = "*.css|CSS files\n*.*|All files";
	TQString startDir      = (m_currentStylesheetURL.isEmpty( )) ? TDEGlobalSettings::documentPath( ) : m_currentStylesheetURL;
	TQString stylesheetURL = KFileDialog::getOpenFileName( startDir, filter, this, "url path dlg" );

	if( stylesheetURL.isEmpty( ))
		return;

	m_urlLineEdit->setText( stylesheetURL );
}

//	slotURLListBoxDoubleClicked
//	===========================

void StylesheetDialog::slotURLListBoxDoubleClicked( TQListBoxItem* item )
{	m_urlLineEdit->setText( item->text( ));
	slotOk( );
}

#include "stylesheetdialog.moc"