00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "options.h"
00029
00030 #include <qlineedit.h>
00031 #include <qcheckbox.h>
00032 #include <qtooltip.h>
00033 #include <qwhatsthis.h>
00034 #include <qbuttongroup.h>
00035 #include <qlabel.h>
00036 #include <qpushbutton.h>
00037 #include <qlayout.h>
00038
00039 #include <kmessagebox.h>
00040
00041 #include "pilotRecord.h"
00042 #include "dbRecordEditor.h"
00043
00044
00045 #ifdef USE_KHEXEDIT
00046 #include <khexedit/byteseditinterface.h>
00047 #include <khexedit/valuecolumninterface.h>
00048 #include <khexedit/charcolumninterface.h>
00049 using namespace KHE;
00050 #endif
00051
00052
00053
00054 DBRecordEditor::DBRecordEditor(PilotRecord*r, int n, QWidget *parent)
00055 : KDialogBase(parent, "RecordEditor",false,i18n("Edit Record"),
00056 Ok|Cancel), rec(r), nr(n)
00057 {
00058
00059 fWidget=new QWidget(this);
00060 setMainWidget(fWidget);
00061 fBuffer = new char[4096];
00062
00063 initWidgets();
00064 fillWidgets();
00065 }
00066
00067
00068 DBRecordEditor::~DBRecordEditor()
00069 {
00070 KPILOT_DELETE( fBuffer );
00071 }
00072
00073
00074 void DBRecordEditor::slotOk()
00075 {
00076 FUNCTIONSETUP;
00077 if (KMessageBox::questionYesNo(this, i18n("Changing the record data and flags might corrupt the whole record, or even make the database unusable. Do not change the values unless you are absolutely sure you know what you are doing.\n\nReally assign these new flags?"), i18n("Changing Record"),i18n("Assign"),KStdGuiItem::cancel())==KMessageBox::Yes)
00078 {
00079 int att=rec->attributes();
00080 #define setFlag(ctrl, flag) if (ctrl->isChecked()) att|=flag; else att &= ~flag;
00081 setFlag(fDirty, dlpRecAttrDirty);
00082 setFlag(fDeleted, dlpRecAttrDeleted);
00083 setFlag(fBusy, dlpRecAttrBusy);
00084 setFlag(fSecret, dlpRecAttrSecret);
00085 setFlag(fArchived, dlpRecAttrArchived);
00086 rec->setAttributes(att);
00087 #undef setFlag
00088
00089 #ifdef USE_KHEXEDIT
00090 if ( fRecordDataIf->isModified() )
00091 {
00092 #ifdef DEBUG
00093 DEBUGKPILOT << "record data changed, new Length of record: " <<
00094 fRecordDataIf->dataSize() << endl;
00095 #endif
00096
00097 rec->setData( fRecordDataIf->data(), fRecordDataIf->dataSize() );
00098 }
00099 #endif
00100
00101 KDialogBase::slotOk();
00102 }
00103 }
00104
00105 void DBRecordEditor::slotCancel()
00106 {
00107 KDialogBase::slotCancel();
00108 }
00109
00110 void DBRecordEditor::languageChange()
00111 {
00112 fRecordIndexLabel->setText( tr2i18n( "Record index:" ) );
00113 fRecordIDLabel->setText( tr2i18n( "Record ID:" ) );
00114 fRecordIndex->setText( tr2i18n( "1" ) );
00115 fRecordID->setText( tr2i18n( "1" ) );
00116 fFlagsGroup->setTitle( tr2i18n( "Flags" ) );
00117 fDirty->setText( tr2i18n( "&Dirty" ) );
00118 fDeleted->setText( tr2i18n( "De&leted" ) );
00119 fBusy->setText( tr2i18n( "&Busy" ) );
00120 fSecret->setText( tr2i18n( "&Secret" ) );
00121 fArchived->setText( tr2i18n( "&Archived" ) );
00122 }
00123
00124 void DBRecordEditor::initWidgets()
00125 {
00126
00127
00128 DBRecordEditorBaseLayout = new QGridLayout( fWidget, 1, 1, 11, 6, "DBRecordEditorBaseLayout");
00129
00130 fRecordIndexLabel = new QLabel( fWidget, "fRecordIndexLabel" );
00131 DBRecordEditorBaseLayout->addWidget( fRecordIndexLabel, 0, 0 );
00132
00133 fRecordIDLabel = new QLabel( fWidget, "fRecordIDLabel" );
00134 DBRecordEditorBaseLayout->addWidget( fRecordIDLabel, 0, 2 );
00135
00136 fRecordIndex = new QLineEdit( fWidget, "fRecordIndex" );
00137 fRecordIndex->setReadOnly( TRUE );
00138
00139 DBRecordEditorBaseLayout->addWidget( fRecordIndex, 0, 1 );
00140
00141 fRecordID = new QLineEdit( fWidget, "fRecordID" );
00142 fRecordID->setReadOnly( TRUE );
00143
00144 DBRecordEditorBaseLayout->addWidget( fRecordID, 0, 3 );
00145
00146 fFlagsGroup = new QButtonGroup( fWidget, "fFlagsGroup" );
00147 fFlagsGroup->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5,
00148 (QSizePolicy::SizeType)4, 0, 0, fFlagsGroup->sizePolicy().hasHeightForWidth() ) );
00149 fFlagsGroup->setColumnLayout(0, Qt::Vertical );
00150 fFlagsGroup->layout()->setSpacing( 6 );
00151 fFlagsGroup->layout()->setMargin( 11 );
00152 fFlagsGroupLayout = new QGridLayout( fFlagsGroup->layout() );
00153 fFlagsGroupLayout->setAlignment( Qt::AlignTop );
00154
00155 fDirty = new QCheckBox( fFlagsGroup, "fDirty" );
00156 fFlagsGroupLayout->addWidget( fDirty, 0, 0 );
00157
00158 fDeleted = new QCheckBox( fFlagsGroup, "fDeleted" );
00159 fFlagsGroupLayout->addWidget( fDeleted, 1, 0 );
00160
00161 fBusy = new QCheckBox( fFlagsGroup, "fBusy" );
00162 fFlagsGroupLayout->addWidget( fBusy, 0, 1 );
00163
00164 fSecret = new QCheckBox( fFlagsGroup, "fSecret" );
00165 fFlagsGroupLayout->addMultiCellWidget( fSecret, 1, 1, 1, 2 );
00166
00167 fArchived = new QCheckBox( fFlagsGroup, "fArchived" );
00168 fFlagsGroupLayout->addWidget( fArchived, 0, 2 );
00169
00170 DBRecordEditorBaseLayout->addMultiCellWidget( fFlagsGroup, 1, 1, 0, 3 );
00171
00172 #ifdef USE_KHEXEDIT
00173 fRecordData = KHE::createBytesEditWidget( fWidget, "fRecordData" );
00174 if( fRecordData )
00175 {
00176
00177 fRecordDataIf = KHE::bytesEditInterface( fRecordData );
00178 Q_ASSERT( fRecordDataIf );
00179
00180 KHE::ValueColumnInterface *ValueColumn = valueColumnInterface( fRecordData );
00181 if( ValueColumn )
00182 {
00183 ValueColumn->setNoOfBytesPerLine( 16 );
00184 ValueColumn->setResizeStyle( KHE::ValueColumnInterface::LockGrouping );
00185
00186
00187 ValueColumn->setNoOfGroupedBytes( 4 );
00188 ValueColumn->setGroupSpacingWidth( 8 );
00189 }
00190
00191 KHE::CharColumnInterface *CharColumn = charColumnInterface( fRecordData );
00192 if( CharColumn )
00193 {
00194 CharColumn->setShowUnprintable( false );
00195
00196 }
00197 }
00198 else
00199 {
00200 QLabel*tmpW = new QLabel( i18n("To view and edit the record data, please install a hex editor (e.g. kbytesedit from kdeutils)."), fWidget );
00201 tmpW->setBackgroundMode( Qt::PaletteMid );
00202 tmpW->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter | Qt::WordBreak);
00203 tmpW->setFrameShape( QFrame::Panel );
00204 tmpW->setFrameShadow( QFrame::Sunken );
00205 fRecordData = tmpW;
00206 fRecordDataIf = 0;
00207 }
00208
00209 DBRecordEditorBaseLayout->addMultiCellWidget( fRecordData, 2, 2, 0, 3 );
00210 #endif
00211
00212 languageChange();
00213 resize( QSize(600, 561).expandedTo(minimumSizeHint()) );
00214 }
00215
00216 void DBRecordEditor::fillWidgets()
00217 {
00218
00219
00220 fRecordIndex->setText(QString::number(nr));
00221 fRecordID->setText(QString::number(rec->id()));
00222
00223 int att=rec->attributes();
00224 fDirty->setChecked(att & dlpRecAttrDirty);
00225 fDeleted->setChecked(att & dlpRecAttrDeleted);
00226 fBusy->setChecked(att & dlpRecAttrBusy);
00227 fSecret->setChecked(att & dlpRecAttrSecret);
00228 fArchived->setChecked(att & dlpRecAttrArchived);
00229
00230 #ifdef USE_KHEXEDIT
00231 if( fRecordDataIf )
00232 {
00233 int len = rec->size();
00234 memcpy( fBuffer, rec->data(), len );
00235 fRecordDataIf->setData( fBuffer, len, 4096 );
00236 fRecordDataIf->setMaxDataSize( 4096 );
00237 fRecordDataIf->setReadOnly( false );
00238
00239 fRecordDataIf->setAutoDelete( false );
00240 }
00241 #endif
00242 }
00243
00244
00245 #include "dbRecordEditor.moc"