kpilot Library API Documentation

dbRecordEditor.cc

00001 /* dbRecordEditor.cc                KPilot
00002 **
00003 ** Copyright (C) 2003 by Dan Pilone
00004 ** Written 2003 by Reinhold Kainhofer
00005 **
00006 **/
00007 
00008 /*
00009 ** This program is free software; you can redistribute it and/or modify
00010 ** it under the terms of the GNU General Public License as published by
00011 ** the Free Software Foundation; either version 2 of the License, or
00012 ** (at your option) any later version.
00013 **
00014 ** This program is distributed in the hope that it will be useful,
00015 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00017 ** GNU General Public License for more details.
00018 **
00019 ** You should have received a copy of the GNU General Public License
00020 ** along with this program in a file called COPYING; if not, write to
00021 ** the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00022 ** MA 02111-1307, USA.
00023 */
00024 
00025 /*
00026 ** Bug reports and questions can be sent to kde-pim@kde.org
00027 */
00028 
00029 #include "options.h"
00030 
00031 #include <qlineedit.h>
00032 #include <qcheckbox.h>
00033 #include <qtooltip.h>
00034 #include <qwhatsthis.h>
00035 #include <qbuttongroup.h>
00036 #include <qcheckbox.h>
00037 #include <qlabel.h>
00038 #include <qlineedit.h>
00039 #include <qpushbutton.h>
00040 #include <qlayout.h>
00041 
00042 #include <kmessagebox.h>
00043 
00044 #include "pilotRecord.h"
00045 #include "dbRecordEditor.h"
00046 //#include "dbRecordEditor_base.h"
00047 
00048 #ifdef USE_KHEXEDIT
00049 #include <khexedit/byteseditinterface.h>
00050 #include <khexedit/valuecolumninterface.h>
00051 #include <khexedit/charcolumninterface.h>
00052 using namespace KHE;
00053 #endif
00054 
00055 
00056 
00057 DBRecordEditor::DBRecordEditor(PilotRecord*r, int n, QWidget *parent)
00058     : KDialogBase(parent, "RecordEditor",false,i18n("Edit Record..."),
00059                 Ok|Cancel), rec(r), nr(n)
00060 {
00061 //  fWidget=new DBRecordEditorBase(this);
00062     fWidget=new QWidget(this);
00063     setMainWidget(fWidget);
00064     fBuffer = new char[4096];
00065 
00066     initWidgets();
00067     fillWidgets();
00068 }
00069 
00070  
00071 DBRecordEditor::~DBRecordEditor()
00072 {
00073     KPILOT_DELETE( fBuffer );
00074 }
00075 
00076 
00077 void DBRecordEditor::slotOk()
00078 {
00079     FUNCTIONSETUP;
00080     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"))==KMessageBox::Yes)
00081     {
00082         int att=rec->getAttrib();
00083 #define setFlag(ctrl, flag) if (ctrl->isChecked()) att|=flag; else att &= ~flag;
00084         setFlag(fDirty, dlpRecAttrDirty);
00085         setFlag(fDeleted, dlpRecAttrDeleted);
00086         setFlag(fBusy, dlpRecAttrBusy);
00087         setFlag(fSecret, dlpRecAttrSecret);
00088         setFlag(fArchived, dlpRecAttrArchived);
00089         rec->setAttrib(att);
00090 #undef setFlag
00091 
00092 #ifdef USE_KHEXEDIT
00093         if ( fRecordDataIf->isModified() )
00094         {
00095 #ifdef DEBUG
00096             DEBUGKPILOT << "record data changed, new Length of record: " << 
00097                 fRecordDataIf->dataSize() << endl;
00098 #endif
00099             // take over data
00100             rec->setData( fRecordDataIf->data(), fRecordDataIf->dataSize() );
00101         }
00102 #endif
00103 
00104         KDialogBase::slotOk();
00105     }
00106 }
00107 
00108 void DBRecordEditor::slotCancel()
00109 {
00110     KDialogBase::slotCancel();
00111 }
00112 
00113 void DBRecordEditor::languageChange()
00114 {
00115     fRecordIndexLabel->setText( tr2i18n( "Record index:" ) );
00116     fRecordIDLabel->setText( tr2i18n( "Record ID:" ) );
00117     fRecordIndex->setText( tr2i18n( "1" ) );
00118     fRecordID->setText( tr2i18n( "1" ) );
00119     fFlagsGroup->setTitle( tr2i18n( "Flags" ) );
00120     fDirty->setText( tr2i18n( "&Dirty" ) );
00121     fDeleted->setText( tr2i18n( "De&leted" ) );
00122     fBusy->setText( tr2i18n( "&Busy" ) );
00123     fSecret->setText( tr2i18n( "&Secret" ) );
00124     fArchived->setText( tr2i18n( "&Archived" ) );
00125 }
00126 
00127 void DBRecordEditor::initWidgets()
00128 {
00129     // FUNCTIONSETUP
00130 
00131     DBRecordEditorBaseLayout = new QGridLayout( fWidget, 1, 1, 11, 6, "DBRecordEditorBaseLayout");
00132 
00133     fRecordIndexLabel = new QLabel( fWidget, "fRecordIndexLabel" );
00134     DBRecordEditorBaseLayout->addWidget( fRecordIndexLabel, 0, 0 );
00135 
00136     fRecordIDLabel = new QLabel( fWidget, "fRecordIDLabel" );
00137     DBRecordEditorBaseLayout->addWidget( fRecordIDLabel, 0, 2 );
00138 
00139     fRecordIndex = new QLineEdit( fWidget, "fRecordIndex" );
00140     fRecordIndex->setReadOnly( TRUE );
00141 
00142     DBRecordEditorBaseLayout->addWidget( fRecordIndex, 0, 1 );
00143 
00144     fRecordID = new QLineEdit( fWidget, "fRecordID" );
00145     fRecordID->setReadOnly( TRUE );
00146 
00147     DBRecordEditorBaseLayout->addWidget( fRecordID, 0, 3 );
00148 
00149     fFlagsGroup = new QButtonGroup( fWidget, "fFlagsGroup" );
00150     fFlagsGroup->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5,
00151         (QSizePolicy::SizeType)4, 0, 0, fFlagsGroup->sizePolicy().hasHeightForWidth() ) );
00152     fFlagsGroup->setColumnLayout(0, Qt::Vertical );
00153     fFlagsGroup->layout()->setSpacing( 6 );
00154     fFlagsGroup->layout()->setMargin( 11 );
00155     fFlagsGroupLayout = new QGridLayout( fFlagsGroup->layout() );
00156     fFlagsGroupLayout->setAlignment( Qt::AlignTop );
00157 
00158     fDirty = new QCheckBox( fFlagsGroup, "fDirty" );
00159     fFlagsGroupLayout->addWidget( fDirty, 0, 0 );
00160 
00161     fDeleted = new QCheckBox( fFlagsGroup, "fDeleted" );
00162     fFlagsGroupLayout->addWidget( fDeleted, 1, 0 );
00163 
00164     fBusy = new QCheckBox( fFlagsGroup, "fBusy" );
00165     fFlagsGroupLayout->addWidget( fBusy, 0, 1 );
00166 
00167     fSecret = new QCheckBox( fFlagsGroup, "fSecret" );
00168     fFlagsGroupLayout->addMultiCellWidget( fSecret, 1, 1, 1, 2 );
00169 
00170     fArchived = new QCheckBox( fFlagsGroup, "fArchived" );
00171     fFlagsGroupLayout->addWidget( fArchived, 0, 2 );
00172 
00173     DBRecordEditorBaseLayout->addMultiCellWidget( fFlagsGroup, 1, 1, 0, 3 );
00174 
00175 #ifdef USE_KHEXEDIT
00176     fRecordData = KHE::createBytesEditWidget( fWidget, "fRecordData" );
00177     if( fRecordData )
00178     {
00179         // fetch the editor interface
00180         fRecordDataIf = KHE::bytesEditInterface( fRecordData );
00181         Q_ASSERT( fRecordDataIf ); // This should not fail!
00182 
00183         KHE::ValueColumnInterface *ValueColumn = valueColumnInterface( fRecordData );
00184         if( ValueColumn )
00185         {
00186             ValueColumn->setNoOfBytesPerLine( 16 );
00187             ValueColumn->setResizeStyle( KHE::ValueColumnInterface::LockGrouping );
00188 //          ValueColumn->setCoding( ValueColumnInterface::HexadecimalCoding );
00189 //          ValueColumn->setByteSpacingWidth( 2 );
00190             ValueColumn->setNoOfGroupedBytes( 4 );
00191             ValueColumn->setGroupSpacingWidth( 8 );
00192         }
00193 
00194         KHE::CharColumnInterface *CharColumn = charColumnInterface( fRecordData );
00195         if( CharColumn )
00196         {
00197             CharColumn->setShowUnprintable( false );
00198 //          CharColumn->setSubstituteChar( '*' );
00199         }
00200     }
00201     else
00202     {
00203         QLabel*tmpW = new QLabel( i18n("To view and edit the record data, please install a hex editor (e.g. kbytesedit from kdeutils)."), fWidget );
00204         tmpW->setBackgroundMode( Qt::PaletteMid );
00205         tmpW->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter | Qt::WordBreak);
00206         tmpW->setFrameShape( QFrame::Panel );
00207         tmpW->setFrameShadow( QFrame::Sunken );
00208         fRecordData = tmpW;
00209         fRecordDataIf = 0;
00210     }
00211  
00212     DBRecordEditorBaseLayout->addMultiCellWidget( fRecordData, 2, 2, 0, 3 );
00213 #endif
00214 
00215     languageChange();
00216     resize( QSize(600, 561).expandedTo(minimumSizeHint()) );
00217 }
00218 
00219 void DBRecordEditor::fillWidgets()
00220 {
00221     // FUNCTIONSETUP
00222 
00223     fRecordIndex->setText(QString::number(nr));
00224     fRecordID->setText(QString::number(rec->getID()));
00225 
00226     int att=rec->getAttrib();
00227     fDirty->setChecked(att & dlpRecAttrDirty);
00228     fDeleted->setChecked(att & dlpRecAttrDeleted);
00229     fBusy->setChecked(att & dlpRecAttrBusy);
00230     fSecret->setChecked(att & dlpRecAttrSecret);
00231     fArchived->setChecked(att & dlpRecAttrArchived);
00232 
00233 #ifdef USE_KHEXEDIT
00234     if( fRecordDataIf )
00235     {
00236         int len = rec->getLen();
00237         memcpy( fBuffer, rec->getData(), len );
00238         fRecordDataIf->setData( fBuffer, len, 4096 );
00239         fRecordDataIf->setMaxDataSize( 4096 );
00240         fRecordDataIf->setReadOnly( false );
00241         // We are managing the buffer ourselves:
00242         fRecordDataIf->setAutoDelete( false ); 
00243     }
00244 #endif
00245 }
00246 
00247 
00248 #include "dbRecordEditor.moc"
KDE Logo
This file is part of the documentation for kpilot Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:36:46 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003