You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
697 lines
20 KiB
697 lines
20 KiB
15 years ago
|
/*
|
||
|
* khexedit - Versatile hex editor
|
||
|
* Copyright (C) 1999 Espen Sand, espensa@online.no
|
||
|
*
|
||
|
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
#include <limits.h>
|
||
15 years ago
|
#include <tqbuttongroup.h>
|
||
|
#include <tqlineedit.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdefiledialog.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
|
#include <tdemessagebox.h>
|
||
15 years ago
|
|
||
|
#include "dialog.h"
|
||
|
#include "exportdialog.h"
|
||
15 years ago
|
#include <tqpushbutton.h>
|
||
15 years ago
|
|
||
|
|
||
13 years ago
|
CExportDialog::CExportDialog( TQWidget *parent, char *name, bool modal )
|
||
15 years ago
|
:KDialogBase( Tabbed, i18n("Export Document"), Help|Ok|Cancel, Ok,
|
||
13 years ago
|
parent, name, modal )
|
||
15 years ago
|
{
|
||
14 years ago
|
setHelp( "khexedit/khexedit.html", TQString() );
|
||
15 years ago
|
|
||
|
mFrame[ page_destination ] = addPage( i18n("Destination") );
|
||
|
mFrame[ page_option ] = addPage( i18n("Options") );
|
||
|
|
||
|
setupDestinationPage();
|
||
|
setupOptionPage();
|
||
|
|
||
|
mConfig = 0;
|
||
|
readConfiguration();
|
||
|
|
||
15 years ago
|
TQString path = mDestination.fileInput->text();
|
||
13 years ago
|
int index = path.findRev( '/' );
|
||
15 years ago
|
if( index != -1 ) { mWorkDir = path.left( index+1 ); }
|
||
|
}
|
||
|
|
||
|
|
||
|
CExportDialog::~CExportDialog( void )
|
||
|
{
|
||
|
writeConfiguration();
|
||
|
delete mConfig; mConfig = 0;
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void CExportDialog::showEvent( TQShowEvent *e )
|
||
15 years ago
|
{
|
||
|
KDialogBase::showEvent(e);
|
||
|
showPage(0);
|
||
|
mDestination.fileInput->setFocus();
|
||
|
}
|
||
|
|
||
|
|
||
|
void CExportDialog::readConfiguration( void )
|
||
|
{
|
||
|
if( mConfig != 0 ) { return; }
|
||
|
|
||
15 years ago
|
mConfig = new KSimpleConfig( TQString("hexexport") );
|
||
15 years ago
|
if( mConfig == 0 ) { return; }
|
||
|
|
||
|
mConfig->setGroup( "Destination" );
|
||
|
|
||
|
int val = mConfig->readNumEntry( "Format", 0 );
|
||
|
mDestination.formatCombo->setCurrentItem( val );
|
||
|
formatChanged( val < 0 || val > option_html ? 0 : val );
|
||
|
|
||
|
mConfig->setGroup( "Option" );
|
||
|
val = mConfig->readNumEntry( "HtmlLine", 80 );
|
||
|
mHtml.lineSpin->setValue( val );
|
||
15 years ago
|
TQString text = mConfig->readEntry( "HtmlPrefix", "table" );
|
||
15 years ago
|
mHtml.prefixInput->setText( text );
|
||
|
val = mConfig->readNumEntry( "HtmlHeader", 1 );
|
||
|
mHtml.topCombo->setCurrentItem( val < 0 || val >= 4 ? 0 : val );
|
||
|
val = mConfig->readNumEntry( "HtmlFooter", 3 );
|
||
|
mHtml.bottomCombo->setCurrentItem( val < 0 || val >= 4 ? 0 : val );
|
||
|
|
||
|
bool state = mConfig->readBoolEntry( "HtmlSymlink", true );
|
||
|
mHtml.symlinkCheck->setChecked( state );
|
||
|
state = mConfig->readBoolEntry( "HtmlNavigatorBar", true );
|
||
|
mHtml.navigatorCheck->setChecked( state );
|
||
|
state = mConfig->readBoolEntry( "HtmlBlackWhite", false );
|
||
|
mHtml.bwCheck->setChecked( state );
|
||
|
|
||
|
text = mConfig->readEntry( "ArrayName", "buffer" );
|
||
|
mArray.nameInput->setText( text );
|
||
|
text = mConfig->readEntry( "ArrayElementType", "char" );
|
||
|
for( int i=0; i < mArray.typeCombo->count(); i++ )
|
||
|
{
|
||
|
if( mArray.typeCombo->text(i) == text )
|
||
|
{
|
||
|
mArray.typeCombo->setCurrentItem(i);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
val = mConfig->readNumEntry( "ArrayElementPerLine", 20 );
|
||
14 years ago
|
val = TQMAX( val, mArray.lineSizeSpin->minValue() );
|
||
|
val = TQMIN( val, mArray.lineSizeSpin->maxValue() );
|
||
15 years ago
|
mArray.lineSizeSpin->setValue( val );
|
||
|
state = mConfig->readBoolEntry( "ArrayUnsignedAsHex", true );
|
||
|
mArray.hexadecimalCheck->setChecked( state );
|
||
|
}
|
||
|
|
||
|
|
||
|
void CExportDialog::writeConfiguration( void )
|
||
|
{
|
||
|
if( mConfig == 0 )
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
mConfig->setGroup( "Destination" );
|
||
|
mConfig->writeEntry( "Format", mDestination.formatCombo->currentItem() );
|
||
|
|
||
|
mConfig->setGroup( "Option" );
|
||
|
mConfig->writeEntry( "HtmlLine", mHtml.lineSpin->value() );
|
||
|
mConfig->writeEntry( "HtmlPrefix", mHtml.prefixInput->text() );
|
||
|
mConfig->writeEntry( "HtmlHeader", mHtml.topCombo->currentItem() );
|
||
|
mConfig->writeEntry( "HtmlFooter", mHtml.bottomCombo->currentItem() );
|
||
|
mConfig->writeEntry( "HtmlSymlink", mHtml.symlinkCheck->isChecked());
|
||
|
mConfig->writeEntry( "HtmlNavigatorBar",mHtml.navigatorCheck->isChecked());
|
||
|
mConfig->writeEntry( "HtmlBlackWhite", mHtml.bwCheck->isChecked() );
|
||
|
|
||
|
|
||
|
mConfig->writeEntry( "ArrayName", mArray.nameInput->text() );
|
||
|
mConfig->writeEntry( "ArrayElementType", mArray.typeCombo->currentText() );
|
||
|
mConfig->writeEntry( "ArrayElementPerLine", mArray.lineSizeSpin->value() );
|
||
|
mConfig->writeEntry( "ArrayUnsignedAsHex",
|
||
|
mArray.hexadecimalCheck->isChecked() );
|
||
|
mConfig->sync();
|
||
|
}
|
||
|
|
||
|
|
||
|
void CExportDialog::setupDestinationPage( void )
|
||
|
{
|
||
15 years ago
|
TQString text;
|
||
|
TQFrame *page = mFrame[ page_destination ];
|
||
15 years ago
|
|
||
15 years ago
|
TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
|
||
15 years ago
|
if( topLayout == 0 ) { return; }
|
||
|
|
||
15 years ago
|
TQStringList formatList;
|
||
15 years ago
|
formatList.append( i18n("Plain Text") );
|
||
|
formatList.append( i18n("HTML Tables") );
|
||
|
formatList.append( i18n("Rich Text (RTF)") );
|
||
|
formatList.append( i18n("C Array") );
|
||
|
|
||
15 years ago
|
mDestination.formatCombo = new TQComboBox( false, page );
|
||
15 years ago
|
mDestination.formatCombo->insertStringList( formatList );
|
||
|
mDestination.formatCombo->setMinimumWidth( fontMetrics().maxWidth()*10 );
|
||
15 years ago
|
connect( mDestination.formatCombo, TQT_SIGNAL(activated(int)),
|
||
|
TQT_SLOT(formatChanged(int)) );
|
||
15 years ago
|
|
||
|
text = i18n("&Format:");
|
||
15 years ago
|
TQLabel *label = new TQLabel( mDestination.formatCombo, text, page );
|
||
15 years ago
|
topLayout->addWidget( label );
|
||
|
topLayout->addWidget( mDestination.formatCombo );
|
||
|
|
||
15 years ago
|
TQHBoxLayout *hbox = new TQHBoxLayout();
|
||
15 years ago
|
topLayout->addLayout( hbox );
|
||
|
|
||
|
text = i18n("&Destination:");
|
||
15 years ago
|
label = new TQLabel( text, page );
|
||
15 years ago
|
hbox->addWidget( label );
|
||
|
|
||
|
text = i18n("(Package folder)");
|
||
15 years ago
|
mDestination.fileExtraLabel = new TQLabel( text, page );
|
||
15 years ago
|
hbox->addWidget( mDestination.fileExtraLabel, 10, AlignLeft|AlignVCenter );
|
||
|
|
||
15 years ago
|
hbox = new TQHBoxLayout();
|
||
15 years ago
|
topLayout->addLayout( hbox );
|
||
|
|
||
15 years ago
|
mDestination.fileInput = new TQLineEdit( page );
|
||
15 years ago
|
hbox->addWidget( mDestination.fileInput );
|
||
15 years ago
|
connect(mDestination.fileInput, TQT_SIGNAL(textChanged ( const TQString & )),this,TQT_SLOT(destinationChanged(const TQString &)));
|
||
15 years ago
|
text = i18n("Choose...");
|
||
15 years ago
|
TQPushButton *browseButton = new TQPushButton( text, page, "browse" );
|
||
15 years ago
|
hbox->addWidget( browseButton );
|
||
15 years ago
|
connect( browseButton, TQT_SIGNAL(clicked()), TQT_SLOT(browserClicked()) );
|
||
15 years ago
|
mDestination.fileInput->setMinimumWidth( fontMetrics().maxWidth()*15 );
|
||
|
|
||
|
label->setBuddy(mDestination.fileInput);
|
||
|
|
||
15 years ago
|
hbox = new TQHBoxLayout();
|
||
15 years ago
|
topLayout->addLayout( hbox, 10 );
|
||
|
|
||
15 years ago
|
mDestination.rangeBox = new TQButtonGroup( i18n("Export Range"), page );
|
||
15 years ago
|
hbox->addWidget( mDestination.rangeBox );
|
||
|
|
||
15 years ago
|
TQButtonGroup *group = mDestination.rangeBox; // convenience
|
||
15 years ago
|
|
||
15 years ago
|
TQVBoxLayout *vbox = new TQVBoxLayout( group, spacingHint() );
|
||
15 years ago
|
vbox->addSpacing( fontMetrics().lineSpacing() );
|
||
|
|
||
15 years ago
|
TQRadioButton *radio1 = new TQRadioButton( i18n("&Everything"), group );
|
||
13 years ago
|
radio1->setFixedSize( radio1->sizeHint() );
|
||
15 years ago
|
mDestination.rangeBox->insert( radio1, 0 );
|
||
|
vbox->addWidget( radio1, 0, AlignLeft );
|
||
|
|
||
15 years ago
|
TQRadioButton *radio2 = new TQRadioButton( i18n("&Selection"), group );
|
||
13 years ago
|
radio2->setFixedSize( radio2->sizeHint() );
|
||
15 years ago
|
mDestination.rangeBox->insert( radio2, 1 );
|
||
|
vbox->addWidget( radio2, 0, AlignLeft );
|
||
|
|
||
15 years ago
|
TQRadioButton *radio3 = new TQRadioButton( i18n("&Range"), group );
|
||
13 years ago
|
radio3->setFixedSize( radio3->sizeHint() );
|
||
15 years ago
|
mDestination.rangeBox->insert( radio3, 2 );
|
||
|
vbox->addWidget( radio3, 0, AlignLeft );
|
||
|
|
||
15 years ago
|
TQGridLayout *gbox = new TQGridLayout( 2, 2, spacingHint() );
|
||
15 years ago
|
vbox->addLayout( gbox );
|
||
|
|
||
15 years ago
|
mDestination.fromInput = new TQLineEdit( group );
|
||
15 years ago
|
text = i18n("&From offset:");
|
||
15 years ago
|
mDestination.fromLabel = new TQLabel( mDestination.fromInput, text, group );
|
||
15 years ago
|
gbox->addWidget( mDestination.fromLabel, 0, 0 );
|
||
|
gbox->addWidget( mDestination.fromInput, 0, 1 );
|
||
|
|
||
15 years ago
|
mDestination.toInput = new TQLineEdit( group );
|
||
15 years ago
|
text = i18n("&To offset:");
|
||
15 years ago
|
mDestination.toLabel = new TQLabel( mDestination.toInput, text, group );
|
||
15 years ago
|
gbox->addWidget( mDestination.toLabel, 1, 0 );
|
||
|
gbox->addWidget( mDestination.toInput, 1, 1 );
|
||
|
|
||
15 years ago
|
connect( group, TQT_SIGNAL(clicked(int)), TQT_SLOT(rangeChanged(int)) );
|
||
15 years ago
|
group->setButton(0);
|
||
|
rangeChanged(0);
|
||
|
enableButtonOK( !mDestination.fileInput->text().isEmpty() );
|
||
|
}
|
||
|
|
||
15 years ago
|
void CExportDialog::destinationChanged(const TQString &_text)
|
||
15 years ago
|
{
|
||
|
enableButtonOK( !_text.isEmpty() );
|
||
|
}
|
||
|
|
||
|
void CExportDialog::setupOptionPage( void )
|
||
|
{
|
||
15 years ago
|
TQFrame *page = mFrame[ page_option ];
|
||
|
TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
|
||
15 years ago
|
if( topLayout == 0 ) { return; }
|
||
|
|
||
15 years ago
|
mOptionStack = new TQWidgetStack( page, "stack" );
|
||
15 years ago
|
if( mOptionStack == 0 ) { return; }
|
||
|
topLayout->addWidget( mOptionStack );
|
||
|
|
||
|
makeTextOption();
|
||
|
makeHtmlOption();
|
||
|
makeRtfOption();
|
||
|
makeCArrayOption();
|
||
|
mOptionStack->raiseWidget( (int)option_text );
|
||
|
|
||
13 years ago
|
TQSize size = mOptionStack->sizeHint();
|
||
15 years ago
|
size += TQSize(spacingHint()*2, spacingHint()*2);
|
||
15 years ago
|
page->setMinimumSize( size );
|
||
|
}
|
||
|
|
||
|
|
||
|
void CExportDialog::makeTextOption( void )
|
||
|
{
|
||
15 years ago
|
TQFrame *page = new TQFrame( mFrame[ page_option ] );
|
||
15 years ago
|
if( page == 0 ) { return; }
|
||
|
mOptionStack->addWidget( page, option_text );
|
||
|
|
||
15 years ago
|
TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
|
||
|
TQString text = i18n("No options for this format.");
|
||
|
TQLabel *label = new TQLabel( text, page );
|
||
15 years ago
|
topLayout->addWidget( label, 0, AlignCenter );
|
||
|
}
|
||
|
|
||
|
|
||
|
void CExportDialog::makeHtmlOption( void )
|
||
|
{
|
||
15 years ago
|
TQFrame *page = new TQFrame( mFrame[ page_option ] );
|
||
15 years ago
|
if( page == 0 ) { return; }
|
||
|
mOptionStack->addWidget( page, option_html );
|
||
|
|
||
15 years ago
|
TQString text;
|
||
|
TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
|
||
15 years ago
|
if( topLayout == 0 ) { return; }
|
||
|
|
||
|
text = i18n("HTML Options (one table per page)");
|
||
15 years ago
|
TQLabel *label = new TQLabel( text, page );
|
||
15 years ago
|
topLayout->addWidget( label );
|
||
|
|
||
15 years ago
|
TQFrame *hline = new TQFrame( page );
|
||
|
hline->setFrameStyle( TQFrame::Sunken | TQFrame::HLine );
|
||
15 years ago
|
topLayout->addWidget( hline );
|
||
|
|
||
15 years ago
|
TQFrame *frame = new TQFrame( page );
|
||
15 years ago
|
if( frame == 0 ) { return; }
|
||
|
topLayout->addWidget( frame );
|
||
|
|
||
15 years ago
|
TQGridLayout *gbox = new TQGridLayout( frame, 4, 2, 0, spacingHint() );
|
||
15 years ago
|
if( gbox == 0 ) { return; }
|
||
|
gbox->setColStretch( 1, 10 );
|
||
|
|
||
15 years ago
|
mHtml.lineSpin = new TQSpinBox( frame );
|
||
15 years ago
|
mHtml.lineSpin->setMinimumWidth( fontMetrics().maxWidth()*10 );
|
||
|
mHtml.lineSpin->setRange( 5, INT_MAX );
|
||
|
gbox->addWidget( mHtml.lineSpin, 0, 1 );
|
||
|
|
||
|
text = i18n("&Lines per table:");
|
||
15 years ago
|
label = new TQLabel( mHtml.lineSpin, text, frame );
|
||
15 years ago
|
gbox->addWidget( label, 0, 0 );
|
||
|
|
||
15 years ago
|
mHtml.prefixInput = new TQLineEdit( frame, "prefix" );
|
||
15 years ago
|
mHtml.prefixInput->setMinimumWidth( fontMetrics().maxWidth()*10 );
|
||
|
gbox->addWidget( mHtml.prefixInput, 1, 1 );
|
||
|
|
||
|
text = i18n("Filename &prefix (in package):");
|
||
15 years ago
|
label = new TQLabel( mHtml.prefixInput, text, frame );
|
||
15 years ago
|
gbox->addWidget( label, 1, 0 );
|
||
|
|
||
15 years ago
|
TQStringList headerList;
|
||
15 years ago
|
headerList.append( i18n("None") );
|
||
|
headerList.append( i18n("Filename with Path") );
|
||
|
headerList.append( i18n("Filename") );
|
||
|
headerList.append( i18n("Page Number") );
|
||
|
|
||
15 years ago
|
mHtml.topCombo = new TQComboBox( false, frame );
|
||
15 years ago
|
mHtml.topCombo->insertStringList( headerList );
|
||
|
gbox->addWidget( mHtml.topCombo, 2, 1 );
|
||
|
|
||
|
text = i18n("Header &above text:");
|
||
15 years ago
|
label = new TQLabel( mHtml.topCombo, text, frame );
|
||
15 years ago
|
gbox->addWidget( label, 2, 0 );
|
||
|
|
||
15 years ago
|
mHtml.bottomCombo = new TQComboBox( false, frame );
|
||
15 years ago
|
mHtml.bottomCombo->insertStringList( headerList );
|
||
|
gbox->addWidget( mHtml.bottomCombo, 3, 1 );
|
||
|
|
||
|
text = i18n("&Footer below text:");
|
||
15 years ago
|
label = new TQLabel( mHtml.bottomCombo, text, frame );
|
||
15 years ago
|
gbox->addWidget( label, 3, 0 );
|
||
|
|
||
|
text = i18n("Link \"index.html\" to &table of contents file");
|
||
15 years ago
|
mHtml.symlinkCheck = new TQCheckBox( text, page );
|
||
15 years ago
|
topLayout->addWidget( mHtml.symlinkCheck );
|
||
|
|
||
|
text = i18n("&Include navigator bar");
|
||
15 years ago
|
mHtml.navigatorCheck = new TQCheckBox( text, page );
|
||
15 years ago
|
topLayout->addWidget( mHtml.navigatorCheck );
|
||
|
|
||
|
text = i18n("&Use black and white only");
|
||
15 years ago
|
mHtml.bwCheck = new TQCheckBox( text, page );
|
||
15 years ago
|
topLayout->addWidget( mHtml.bwCheck );
|
||
|
|
||
|
topLayout->addStretch(10);
|
||
|
}
|
||
|
|
||
|
|
||
|
void CExportDialog::makeRtfOption( void )
|
||
|
{
|
||
15 years ago
|
TQFrame *page = new TQFrame( mFrame[ page_option ] );
|
||
15 years ago
|
if( page == 0 ) { return; }
|
||
|
mOptionStack->addWidget( page, option_rtf );
|
||
|
|
||
15 years ago
|
TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
|
||
|
TQString text = i18n("No options for this format.");
|
||
|
TQLabel *label = new TQLabel( text, page );
|
||
15 years ago
|
topLayout->addWidget( label, 0, AlignCenter );
|
||
|
}
|
||
|
|
||
|
|
||
|
void CExportDialog::makeCArrayOption( void )
|
||
|
{
|
||
15 years ago
|
TQFrame *page = new TQFrame( mFrame[ page_option ] );
|
||
15 years ago
|
mOptionStack->addWidget( page, option_carray );
|
||
|
|
||
15 years ago
|
TQString text;
|
||
|
TQVBoxLayout *topLayout = new TQVBoxLayout( page, 0, spacingHint() );
|
||
15 years ago
|
|
||
|
text = i18n("C Array Options");
|
||
15 years ago
|
TQLabel *label = new TQLabel( text, page );
|
||
15 years ago
|
topLayout->addWidget( label, 0, AlignLeft );
|
||
|
|
||
15 years ago
|
TQFrame *hline = new TQFrame( page );
|
||
|
hline->setFrameStyle( TQFrame::Sunken | TQFrame::HLine );
|
||
15 years ago
|
topLayout->addWidget( hline );
|
||
|
|
||
15 years ago
|
TQGridLayout *gbox = new TQGridLayout( 3, 2, spacingHint() );
|
||
15 years ago
|
topLayout->addLayout( gbox );
|
||
|
gbox->setColStretch( 1, 10 );
|
||
|
|
||
15 years ago
|
mArray.nameInput = new TQLineEdit( page );
|
||
15 years ago
|
gbox->addWidget( mArray.nameInput, 0, 1 );
|
||
|
text = i18n("Array name:");
|
||
15 years ago
|
label = new TQLabel( mArray.nameInput, text, page );
|
||
15 years ago
|
gbox->addWidget( label, 0, 0 );
|
||
|
|
||
15 years ago
|
TQStringList typeList;
|
||
15 years ago
|
typeList.append( i18n("char") );
|
||
|
typeList.append( i18n("unsigned char") );
|
||
|
typeList.append( i18n("short") );
|
||
|
typeList.append( i18n("unsigned short") );
|
||
|
typeList.append( i18n("int") );
|
||
|
typeList.append( i18n("unsigned int") );
|
||
|
typeList.append( i18n("float") );
|
||
|
typeList.append( i18n("double") );
|
||
15 years ago
|
mArray.typeCombo = new TQComboBox( false, page );
|
||
15 years ago
|
mArray.typeCombo->insertStringList( typeList );
|
||
|
mArray.typeCombo->setMinimumWidth( fontMetrics().maxWidth()*10 );
|
||
|
gbox->addWidget( mArray.typeCombo, 1, 1 );
|
||
|
text = i18n("Element type:");
|
||
15 years ago
|
label = new TQLabel( mArray.typeCombo, text, page );
|
||
15 years ago
|
gbox->addWidget( label, 1, 0 );
|
||
|
|
||
15 years ago
|
mArray.lineSizeSpin = new TQSpinBox( page );
|
||
15 years ago
|
mArray.lineSizeSpin->setMinimumWidth( fontMetrics().maxWidth()*10 );
|
||
|
mArray.lineSizeSpin->setRange( 1, INT_MAX );
|
||
|
gbox->addWidget( mArray.lineSizeSpin, 2, 1 );
|
||
|
text = i18n("Elements per line:");
|
||
15 years ago
|
label = new TQLabel( mArray.lineSizeSpin, text, page );
|
||
15 years ago
|
gbox->addWidget( label, 2, 0 );
|
||
|
|
||
|
text = i18n("Print unsigned values as hexadecimal");
|
||
15 years ago
|
mArray.hexadecimalCheck = new TQCheckBox( text, page );
|
||
15 years ago
|
topLayout->addWidget( mArray.hexadecimalCheck );
|
||
|
|
||
|
topLayout->addStretch(10);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
void CExportDialog::formatChanged( int index )
|
||
|
{
|
||
|
mDestination.formatCombo->setCurrentItem(index);
|
||
|
mDestination.fileExtraLabel->setEnabled( index == option_html );
|
||
|
mOptionStack->raiseWidget( index );
|
||
|
}
|
||
|
|
||
|
|
||
|
void CExportDialog::rangeChanged( int id )
|
||
|
{
|
||
|
bool state = id == 2 ? true : false;
|
||
|
mDestination.toLabel->setEnabled( state );
|
||
|
mDestination.fromLabel->setEnabled( state );
|
||
|
mDestination.toInput->setEnabled( state );
|
||
|
mDestination.fromInput->setEnabled( state );
|
||
|
}
|
||
|
|
||
|
|
||
|
void CExportDialog::browserClicked( void )
|
||
|
{
|
||
15 years ago
|
TQString url;
|
||
15 years ago
|
if( mDestination.formatCombo->currentItem() == option_html )
|
||
|
{
|
||
13 years ago
|
url = KFileDialog::getExistingDirectory( mWorkDir, topLevelWidget() );
|
||
15 years ago
|
}
|
||
|
else
|
||
|
{
|
||
13 years ago
|
url = KFileDialog::getSaveFileName( mWorkDir, "*", topLevelWidget() );
|
||
15 years ago
|
}
|
||
|
|
||
|
if( url.isEmpty() )
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
13 years ago
|
int index = url.findRev( '/' );
|
||
15 years ago
|
if( index != -1 )
|
||
|
{
|
||
|
mWorkDir = url.left( index+1 );
|
||
|
}
|
||
|
mDestination.fileInput->setText( url );
|
||
|
}
|
||
|
|
||
|
|
||
|
void CExportDialog::slotOk( void )
|
||
|
{
|
||
15 years ago
|
TQString path( mDestination.fileInput->text() );
|
||
15 years ago
|
|
||
|
int format = mDestination.formatCombo->currentItem();
|
||
|
if( format == option_text )
|
||
|
{
|
||
|
if( verifyFileDestnation( this, i18n("Export Document"), path ) == false )
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
SExportText e;
|
||
|
uint mode;
|
||
|
if( collectRange( mode, e.range.start, e.range.stop ) == false )
|
||
|
{
|
||
15 years ago
|
showEntryFailure( this, TQString("") );
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
e.range.mode = (SExportRange::EMode)mode; // FIXME
|
||
|
e.destFile = path;
|
||
|
|
||
|
hide();
|
||
|
emit exportText(e);
|
||
|
}
|
||
|
else if( format == option_html )
|
||
|
{
|
||
|
SExportHtml e;
|
||
|
uint mode;
|
||
|
if( collectRange( mode, e.range.start, e.range.stop ) == false )
|
||
|
{
|
||
15 years ago
|
showEntryFailure( this, TQString("") );
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
e.range.mode = (SExportRange::EMode)mode; // FIXME
|
||
|
|
||
15 years ago
|
const TQString str = mHtml.prefixInput->text().stripWhiteSpace();
|
||
15 years ago
|
mHtml.prefixInput->setText( str );
|
||
|
if( mHtml.prefixInput->text().isEmpty() == true )
|
||
|
{
|
||
|
mHtml.prefixInput->setText( "table" );
|
||
|
}
|
||
|
|
||
15 years ago
|
const TQString prefix = mHtml.prefixInput->text();
|
||
15 years ago
|
for( uint i=0; i<prefix.length(); i++ )
|
||
|
{
|
||
15 years ago
|
TQChar c = prefix[i];
|
||
15 years ago
|
if( c.isSpace() == true || c.isPunct() == true )
|
||
|
{
|
||
15 years ago
|
TQString msg = i18n("The filename prefix can not contain empty letters "
|
||
15 years ago
|
"or punctuation marks.");
|
||
|
KMessageBox::sorry( this, msg, i18n("Export Document") );
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if( verifyPackage( path ) == false )
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
e.package = path;
|
||
|
e.prefix = prefix;
|
||
|
e.linePerPage = mHtml.lineSpin->value();
|
||
|
e.topCaption = mHtml.topCombo->currentItem();
|
||
|
e.bottomCaption = mHtml.bottomCombo->currentItem();
|
||
|
e.symLink = mHtml.symlinkCheck->isChecked();
|
||
|
e.navigator = mHtml.navigatorCheck->isChecked();
|
||
|
e.blackWhite = mHtml.bwCheck->isChecked();
|
||
|
|
||
|
hide();
|
||
|
emit exportHtml(e);
|
||
|
}
|
||
|
else if( format == option_rtf )
|
||
|
{
|
||
15 years ago
|
TQString msg = i18n("This format is not yet supported.");
|
||
15 years ago
|
KMessageBox::sorry( this, msg );
|
||
|
}
|
||
|
else if( format == option_carray )
|
||
|
{
|
||
|
if( verifyFileDestnation( this, i18n("Export Document"), path ) == false )
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
SExportCArray e;
|
||
|
uint mode;
|
||
|
if( collectRange( mode, e.range.start, e.range.stop ) == false )
|
||
|
{
|
||
15 years ago
|
showEntryFailure( this, TQString("") );
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
e.range.mode = (SExportRange::EMode)mode; // FIXME
|
||
|
e.destFile = path;
|
||
|
e.arrayName = mArray.nameInput->text();
|
||
|
e.elementType = mArray.typeCombo->currentItem();
|
||
|
e.elementPerLine = mArray.lineSizeSpin->value();
|
||
|
e.unsignedAsHexadecimal = mArray.hexadecimalCheck->isChecked();
|
||
|
|
||
|
emit exportCArray( e );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
bool CExportDialog::collectRange( uint &mode, uint &start, uint &stop )
|
||
|
{
|
||
15 years ago
|
TQButton *b = mDestination.rangeBox->selected();
|
||
15 years ago
|
if( b == 0 )
|
||
|
{
|
||
|
return( false );
|
||
|
}
|
||
|
|
||
|
int id = mDestination.rangeBox->id( b );
|
||
|
if( id == 0 )
|
||
|
{
|
||
|
mode = SExportRange::All;
|
||
|
}
|
||
|
else if( id == 1 )
|
||
|
{
|
||
|
mode = SExportRange::Selection;
|
||
|
}
|
||
|
else if( id == 2 )
|
||
|
{
|
||
|
mode = SExportRange::Range;
|
||
|
bool ok1 = stringToOffset( mDestination.fromInput->text(), start );
|
||
|
bool ok2 = stringToOffset( mDestination.toInput->text(), stop );
|
||
|
if( ok1 == false || ok2 == false || start >= stop )
|
||
|
{
|
||
|
return( false );
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return( false );
|
||
|
}
|
||
|
|
||
|
return( true );
|
||
|
}
|
||
|
|
||
|
|
||
|
//
|
||
|
// This one will attempt to create a directory if 'path'
|
||
|
// specifies a nonexistent name.
|
||
|
//
|
||
15 years ago
|
bool CExportDialog::verifyPackage( const TQString &path )
|
||
15 years ago
|
{
|
||
15 years ago
|
const TQString title = i18n("Export Document");
|
||
15 years ago
|
|
||
|
if( path.isEmpty() == true )
|
||
|
{
|
||
15 years ago
|
TQString msg = i18n("You must specify a destination.");
|
||
15 years ago
|
KMessageBox::sorry( this, msg, title );
|
||
|
return( false );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQFileInfo info( path );
|
||
15 years ago
|
if( info.exists() == false )
|
||
|
{
|
||
15 years ago
|
TQDir directory;
|
||
15 years ago
|
if( directory.mkdir( path ) == false )
|
||
|
{
|
||
15 years ago
|
TQString msg;
|
||
15 years ago
|
msg += i18n("Unable to create a new folder");
|
||
|
msg += "\n";
|
||
|
msg += path;
|
||
|
KMessageBox::sorry( this, msg, title );
|
||
|
return( false );
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if( info.isDir() == false )
|
||
|
{
|
||
15 years ago
|
TQString msg = i18n("You have specified an existing file");
|
||
15 years ago
|
KMessageBox::sorry( this, msg, title );
|
||
|
return( false );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if( info.isWritable() == false )
|
||
|
{
|
||
15 years ago
|
TQString msg = i18n( ""
|
||
15 years ago
|
"You do not have write permission to this folder.");
|
||
|
KMessageBox::sorry( this, msg, title );
|
||
|
return( false );
|
||
|
}
|
||
|
|
||
15 years ago
|
const TQString prefix = mHtml.prefixInput->text();
|
||
13 years ago
|
TQString f1 = TQString("%1%2.html").arg(prefix).arg("00000000");
|
||
|
TQString f2 = TQString("%1%2.html").arg(prefix).arg("99999999");
|
||
15 years ago
|
|
||
15 years ago
|
TQString msg = i18n( ""
|
||
15 years ago
|
"You have specified an existing folder.\n"
|
||
|
"If you continue, any existing file in the range "
|
||
|
"\"%1\" to \"%2\" can be lost.\n"
|
||
13 years ago
|
"Continue?").arg(f1).arg(f2);
|
||
15 years ago
|
int reply = KMessageBox::warningContinueCancel( this, msg, title );
|
||
|
if( reply != KMessageBox::Continue )
|
||
|
{
|
||
|
return( false );
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return( true );
|
||
|
}
|
||
|
|
||
|
#include "exportdialog.moc"
|