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.
331 lines
8.7 KiB
331 lines
8.7 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.
|
||
|
*
|
||
|
*/
|
||
|
|
||
14 years ago
|
#include <tqheader.h>
|
||
|
#include <tqlabel.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdeglobalsettings.h>
|
||
|
#include <tdeglobal.h>
|
||
|
#include <tdelocale.h>
|
||
15 years ago
|
|
||
|
#include "fileinfodialog.h"
|
||
|
#include "listview.h"
|
||
|
|
||
|
// quick'n'dirty hack to have the occurrence column sorted correctly
|
||
14 years ago
|
class CStatisticListViewItem : public TQListViewItem
|
||
15 years ago
|
{
|
||
|
public:
|
||
13 years ago
|
CStatisticListViewItem( TQListView * parent, TQListViewItem * after,
|
||
14 years ago
|
TQString label1, TQString label2, TQString label3, TQString label4,
|
||
|
TQString label5, TQString label6, TQString label7, int i, int o)
|
||
13 years ago
|
: TQListViewItem( parent, after, label1, label2, label3, label4, label5, label6, label7),
|
||
15 years ago
|
item( i ),
|
||
|
occurrence( o )
|
||
|
{}
|
||
|
|
||
14 years ago
|
virtual int compare( TQListViewItem *i, int col, bool ascending/*TQt doc says: ignore this one*/ ) const
|
||
15 years ago
|
{
|
||
|
// occurrence column (or the percent one)?
|
||
|
if( col == 5 || col == 6 )
|
||
|
{
|
||
|
const int otherOccurrence = ((CStatisticListViewItem*)i)->occurrence;
|
||
|
return occurrence < otherOccurrence ? -1 : occurrence == otherOccurrence ? 0 : 1;
|
||
|
}
|
||
|
// char column?
|
||
|
else if( col == 4 )
|
||
|
{
|
||
|
const int otherItem = ((CStatisticListViewItem*)i)->item;
|
||
|
return item < otherItem ? -1 : item == otherItem ? 0 : 1;
|
||
|
}
|
||
|
// default
|
||
|
else
|
||
14 years ago
|
return TQListViewItem::compare(i,col,ascending);
|
||
15 years ago
|
}
|
||
|
|
||
|
protected:
|
||
|
// no of byte
|
||
|
int item;
|
||
|
// number of the byte's occurrence
|
||
|
int occurrence;
|
||
|
};
|
||
|
|
||
|
|
||
|
|
||
13 years ago
|
CFileInfoDialog::CFileInfoDialog( TQWidget *parent,const char *name,bool modal)
|
||
15 years ago
|
:KDialogBase( Plain, i18n("Statistics"), Help|User1|Cancel, User1,
|
||
13 years ago
|
parent, name, modal, true, i18n("&Update") ),
|
||
15 years ago
|
mBusy(false), mDirty(false)
|
||
|
{
|
||
14 years ago
|
setHelp( "khexedit/khexedit.html", TQString() );
|
||
15 years ago
|
|
||
14 years ago
|
TQString text;
|
||
|
TQVBoxLayout *topLayout = new TQVBoxLayout( plainPage(), 0, spacingHint() );
|
||
15 years ago
|
if( topLayout == 0 ) { return; }
|
||
|
|
||
|
|
||
14 years ago
|
TQGridLayout *gbox = new TQGridLayout( 2, 2, spacingHint() );
|
||
15 years ago
|
if( gbox == 0 ) { return; }
|
||
|
topLayout->addLayout( gbox );
|
||
|
gbox->setColStretch( 1, 10 );
|
||
|
|
||
|
text = i18n("File name: ");
|
||
14 years ago
|
TQLabel *label = new TQLabel( text, plainPage() );
|
||
15 years ago
|
gbox->addWidget( label, 0, 0 );
|
||
|
|
||
|
text = i18n("Size [bytes]: ");
|
||
14 years ago
|
label = new TQLabel( text, plainPage() );
|
||
15 years ago
|
gbox->addWidget( label, 1, 0 );
|
||
|
|
||
14 years ago
|
mFileNameLabel = new TQLabel( plainPage() );
|
||
|
mFileSizeLabel = new TQLabel( plainPage() );
|
||
15 years ago
|
gbox->addWidget( mFileNameLabel, 0, 1 );
|
||
|
gbox->addWidget( mFileSizeLabel, 1, 1 );
|
||
|
|
||
|
mFrequencyList = new CListView( plainPage(), "stringList" );
|
||
12 years ago
|
mFrequencyList->setFont( TDEGlobalSettings::fixedFont() );
|
||
15 years ago
|
|
||
|
mFrequencyList->addColumn( i18n("Hexadecimal") );
|
||
|
mFrequencyList->addColumn( i18n("Decimal") );
|
||
|
mFrequencyList->addColumn( i18n("Octal") );
|
||
|
mFrequencyList->addColumn( i18n("Binary") );
|
||
|
mFrequencyList->addColumn( i18n("Text") );
|
||
|
mFrequencyList->addColumn( i18n("Occurrence") );
|
||
|
mFrequencyList->addColumn( i18n("Percent") );
|
||
|
mFrequencyList->setAllColumnsShowFocus( true );
|
||
14 years ago
|
mFrequencyList->setFrameStyle( TQFrame::WinPanel + TQFrame::Sunken );
|
||
15 years ago
|
topLayout->addWidget( mFrequencyList, 10 );
|
||
|
|
||
14 years ago
|
mDirtyLabel = new TQLabel( plainPage() );
|
||
15 years ago
|
mDirtyLabel->setFixedHeight( fontMetrics().height() );
|
||
|
topLayout->addWidget( mDirtyLabel );
|
||
|
|
||
|
setStatistics();
|
||
|
setColumnWidth();
|
||
|
mFrequencyList->setVisibleItem( 15 );
|
||
|
|
||
|
//
|
||
|
// Load the first set of data when this timer expires. I do it this
|
||
|
// way so that the dialog will be visible when the load operation starts.
|
||
|
//
|
||
|
startTimer( 0 );
|
||
|
}
|
||
|
|
||
|
|
||
|
CFileInfoDialog::~CFileInfoDialog( void )
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
void CFileInfoDialog::slotUser1( void ) // Update
|
||
|
{
|
||
|
if( mBusy )
|
||
|
return;
|
||
|
|
||
|
SStatisticControl *sc = new SStatisticControl;
|
||
|
if( sc == 0 ) { return; }
|
||
|
|
||
|
mBusy = true;
|
||
|
emit collectStatistic( *sc );
|
||
|
mBusy = false;
|
||
|
|
||
|
delete sc;
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
void CFileInfoDialog::setDirty( void )
|
||
|
{
|
||
|
if( mDirty )
|
||
|
return;
|
||
|
|
||
|
mDirtyLabel->setText(
|
||
|
i18n("Warning: Document has been modified since last update"));
|
||
|
mDirty = true;
|
||
|
}
|
||
|
|
||
|
|
||
|
void CFileInfoDialog::setClean( void )
|
||
|
{
|
||
|
if( !mDirty )
|
||
|
return;
|
||
|
|
||
|
mDirtyLabel->setText("");
|
||
|
mDirty = false;
|
||
|
}
|
||
|
|
||
|
|
||
|
const char *printBin( uint val )
|
||
|
{
|
||
|
static char buf[9];
|
||
|
for( int i = 0; i < 8; i++ )
|
||
|
buf[7-i] = (val&(1<<i)) ? '1' : '0';
|
||
|
buf[8] = 0;
|
||
|
return( buf );
|
||
|
}
|
||
|
|
||
|
|
||
|
void CFileInfoDialog::setStatistics() // Default
|
||
|
{
|
||
|
setClean();
|
||
|
mFrequencyList->clear();
|
||
|
mFileNameLabel->clear();
|
||
|
mFileSizeLabel->clear();
|
||
|
|
||
14 years ago
|
static const TQString u("?");
|
||
|
TQString d, h, o, b, c;
|
||
|
TQListViewItem *item = 0;
|
||
15 years ago
|
|
||
|
char buf[10];
|
||
|
memset( buf, 0, sizeof( buf ) );
|
||
|
|
||
|
for( uint i=0; i<256; i++ )
|
||
|
{
|
||
|
h.sprintf("0x%02x", i );
|
||
|
d.sprintf("%03d", i );
|
||
|
o.sprintf("%03o", i );
|
||
|
b.sprintf("%s", printBin(i) );
|
||
|
|
||
14 years ago
|
const TQChar _i((char)i);
|
||
|
c = _i.isPrint() ? _i : TQChar('.');
|
||
15 years ago
|
|
||
|
item = new CStatisticListViewItem( mFrequencyList, item, h, d, o, b, c, u, u, i, -1 );
|
||
|
if( i == 0 )
|
||
|
mFrequencyList->setSelected( item, true );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
void CFileInfoDialog::setStatistics( SStatisticControl &sc )
|
||
|
{
|
||
|
setClean();
|
||
|
mFrequencyList->clear();
|
||
|
mFileNameLabel->setText( sc.documentName );
|
||
12 years ago
|
mFileSizeLabel->setText( TDEGlobal::locale()->formatNumber(sc.documentSize, 0) );
|
||
15 years ago
|
|
||
14 years ago
|
TQString d, h, o, b, c, n, p;
|
||
|
TQListViewItem *item = 0;
|
||
15 years ago
|
|
||
|
uint size, pre, i;
|
||
|
// find width of occurrence
|
||
|
for( i=size=0; i<256; i++ )
|
||
|
if( sc.occurrence[i] > size )
|
||
|
size = sc.occurrence[i];
|
||
|
for( pre = 1; size > 0 ; pre++ )
|
||
|
size /= 10;
|
||
|
|
||
|
for( i=0; i<256; i++ )
|
||
|
{
|
||
|
h.sprintf("0x%02x", i );
|
||
|
d.sprintf("%03d", i );
|
||
|
o.sprintf("%03o", i );
|
||
|
b.sprintf("%s", printBin(i) );
|
||
|
|
||
13 years ago
|
n = TQString("%1").arg( sc.occurrence[i], pre );
|
||
15 years ago
|
if( sc.documentSize == 0 )
|
||
|
p = "0.00";
|
||
|
else
|
||
|
{
|
||
|
double val = 100.0*((double)sc.occurrence[i]/(double)sc.documentSize);
|
||
13 years ago
|
p = TQString("%1").arg( val, 6, 'f', 2 );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
const TQChar _i((char)i);
|
||
|
c = _i.isPrint() ? _i : TQChar('.');
|
||
15 years ago
|
|
||
|
item = new CStatisticListViewItem( mFrequencyList, item, h, d, o, b, c, n, p, i, sc.occurrence[i] );
|
||
|
if( i == 0 )
|
||
|
mFrequencyList->setSelected( item, true );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
void CFileInfoDialog::setColumnWidth( void )
|
||
|
{
|
||
14 years ago
|
const TQFontMetrics &fm = mFrequencyList->fontMetrics();
|
||
15 years ago
|
int w0, w1, w2, w3, w4;
|
||
|
|
||
|
w0 = -fm.minLeftBearing() - fm.minRightBearing() + 8 + fm.maxWidth();
|
||
|
w3 = 0;
|
||
|
|
||
|
w1 = fm.width( mFrequencyList->header()->label(0) ) + w0;
|
||
|
w2 = fm.width('0')*6;
|
||
|
w3 += w1 > w2 ? w1 : w2;
|
||
|
mFrequencyList->setColumnWidth( 0, w1 > w2 ? w1 : w2 );
|
||
|
|
||
|
w1 = fm.boundingRect( mFrequencyList->header()->label(1) ).width() + w0;
|
||
|
w2 = fm.width('0')*5;
|
||
|
w3 += w1 > w2 ? w1 : w2;
|
||
|
mFrequencyList->setColumnWidth( 1, w1 > w2 ? w1 : w2 );
|
||
|
|
||
|
w1 = fm.boundingRect( mFrequencyList->header()->label(2) ).width() + w0;
|
||
|
w2 = fm.width('0')*5;
|
||
|
w3 += w1 > w2 ? w1 : w2;
|
||
|
mFrequencyList->setColumnWidth( 2, w1 > w2 ? w1 : w2 );
|
||
|
|
||
|
w1 = fm.boundingRect( mFrequencyList->header()->label(3) ).width() + w0;
|
||
|
w2 = fm.width('0')*10;
|
||
|
w3 += w1 > w2 ? w1 : w2;
|
||
|
mFrequencyList->setColumnWidth( 3, w1 > w2 ? w1 : w2 );
|
||
|
|
||
|
w1 = fm.boundingRect( mFrequencyList->header()->label(4) ).width() + w0;
|
||
|
w2 = fm.width('0')*3;
|
||
|
w3 += w1 > w2 ? w1 : w2;
|
||
|
mFrequencyList->setColumnWidth( 4, w1 > w2 ? w1 : w2 );
|
||
|
|
||
|
w1 = fm.boundingRect( mFrequencyList->header()->label(5) ).width() + w0;
|
||
|
w2 = fm.width('0')*10;
|
||
|
w3 += w1 > w2 ? w1 : w2;
|
||
|
mFrequencyList->setColumnWidth( 5, w1 > w2 ? w1 : w2 );
|
||
|
|
||
|
w4 = mFrequencyList->viewport()->width() - w3;
|
||
|
w1 = fm.boundingRect( mFrequencyList->header()->label(6) ).width() + w0;
|
||
|
w2 = fm.width('0')*3;
|
||
|
w1 = w1 > w2 ? w1 : w2;
|
||
|
mFrequencyList->setColumnWidth( 6, w1 > w4 ? w1 : w4 );
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void CFileInfoDialog::resizeEvent( TQResizeEvent * )
|
||
15 years ago
|
{
|
||
|
setColumnWidth();
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void CFileInfoDialog::showEvent( TQShowEvent *e )
|
||
15 years ago
|
{
|
||
|
KDialogBase::showEvent(e);
|
||
|
setColumnWidth();
|
||
|
mFrequencyList->setFocus();
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void CFileInfoDialog::timerEvent( TQTimerEvent * )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQT_TQOBJECT(this)->killTimers();
|
||
15 years ago
|
slotUser1();
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
#include "fileinfodialog.moc"
|