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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
|
/*
*
* $Id: k3bbootimageview.cpp 619556 2007-01-03 17:38:12Z trueg $
* Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
*
* This file is part of the K3b project.
* Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
*
* 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.
* See the file "COPYING" for the exact licensing terms.
*/
#include "k3bbootimageview.h"
#include "k3bdatadoc.h"
#include "k3bbootitem.h"
#include <k3bintvalidator.h>
#include <klocale.h>
#include <klistview.h>
#include <kfiledialog.h>
#include <kdebug.h>
#include <kmessagebox.h>
#include <tqpushbutton.h>
#include <tqstring.h>
#include <tqgroupbox.h>
#include <tqlineedit.h>
#include <tqcheckbox.h>
#include <tqradiobutton.h>
#include <tqbuttongroup.h>
#include <tqregexp.h>
class K3bBootImageView::PrivateBootImageViewItem : public KListViewItem
{
public:
PrivateBootImageViewItem( K3bBootItem* image, TQListView* tqparent )
: KListViewItem( tqparent ),
m_image( image ) {
}
PrivateBootImageViewItem( K3bBootItem* image, TQListView* tqparent, TQListViewItem* after )
: KListViewItem( tqparent, after ),
m_image( image ) {
}
TQString text( int col ) const {
if( col == 0 ) {
if( m_image->imageType() == K3bBootItem::FLOPPY )
return i18n("Floppy");
else if( m_image->imageType() == K3bBootItem::HARDDISK )
return i18n("Harddisk");
else
return i18n("None");
}
else if( col == 1 )
return TQString( "%1 KB" ).tqarg( m_image->size()/1024 );
else if( col == 2 )
return m_image->localPath();
else
return TQString();
}
K3bBootItem* bootImage() const { return m_image; }
private:
K3bBootItem* m_image;
};
K3bBootImageView::K3bBootImageView( K3bDataDoc* doc, TQWidget* tqparent, const char* name )
: base_K3bBootImageView( tqparent, name ),
m_doc(doc)
{
connect( m_buttonNew, TQT_SIGNAL(clicked()),
this, TQT_SLOT(slotNewBootImage()) );
connect( m_buttonDelete, TQT_SIGNAL(clicked()),
this, TQT_SLOT(slotDeleteBootImage()) );
connect( m_buttonToggleOptions, TQT_SIGNAL(clicked()),
this, TQT_SLOT(slotToggleOptions()) );
connect( m_viewImages, TQT_SIGNAL(selectionChanged()),
this, TQT_SLOT(slotSelectionChanged()) );
connect( m_radioNoEmulation, TQT_SIGNAL(toggled(bool)),
this, TQT_SLOT(slotNoEmulationToggled(bool)) );
K3bIntValidator* v = new K3bIntValidator( this );
m_editLoadSegment->setValidator( v );
m_editLoadSize->setValidator( v );
updateBootImages();
showAdvancedOptions( false );
loadBootItemSettings(0);
}
K3bBootImageView::~K3bBootImageView()
{
}
void K3bBootImageView::slotToggleOptions()
{
showAdvancedOptions( !m_groupOptions->isVisible() );
}
void K3bBootImageView::showAdvancedOptions( bool show )
{
if( show ) {
m_groupOptions->show();
m_buttonToggleOptions->setText( i18n("Hide Advanced Options") );
}
else {
m_groupOptions->hide();
m_buttonToggleOptions->setText( i18n("Show Advanced Options") );
}
}
void K3bBootImageView::slotNewBootImage()
{
TQString file = KFileDialog::getOpenFileName( TQString(), TQString(), this, i18n("Please Choose Boot Image") );
if( !file.isEmpty() ) {
KIO::filesize_t fsize = K3b::filesize( file );
int boottype = K3bBootItem::FLOPPY;
if( fsize != 1200*1024 &&
fsize != 1440*1024 &&
fsize != 2880*1024 ) {
switch( KMessageBox::warningYesNoCancel( this,
i18n("<p>The file you selected is not a floppy image (floppy images are "
"of size 1200 KB, 1440 KB, or 2880 KB). You may still use boot images "
"of other sizes by emulating a harddisk or disabling emulation completely. "
"<p>If you are not familiar with terms like 'harddisk emulation' you most "
"likely want to use a floppy image here. Floppy images can be created by "
"directly extracting them from a real floppy disk:"
"<pre>dd if=/dev/floppy of=/tmp/floppy.img</pre>"
"or by using one of the many boot floppy generators that can be found on "
"<a href=\"http://www.google.com/search?q=linux+boot+floppy&ie=UTF-8&oe=UTF-8\">the internet</a>."),
i18n("No Floppy image selected"),
i18n("Use harddisk emulation"),
i18n("Use no emulation"),
TQString(),
KMessageBox::AllowLink ) ) {
case KMessageBox::Yes:
boottype = K3bBootItem::HARDDISK;
break;
case KMessageBox::No:
boottype = K3bBootItem::NONE;
break;
default:
return;
}
}
m_doc->createBootItem( file )->setImageType( boottype );
updateBootImages();
}
}
void K3bBootImageView::slotDeleteBootImage()
{
TQListViewItem* item = m_viewImages->selectedItem();
if( item ) {
K3bBootItem* i = ((PrivateBootImageViewItem*)item)->bootImage();
delete item;
m_doc->removeItem( i );
}
}
void K3bBootImageView::slotSelectionChanged()
{
TQListViewItem* item = m_viewImages->selectedItem();
if( item )
loadBootItemSettings( ((PrivateBootImageViewItem*)item)->bootImage() );
else
loadBootItemSettings( 0 );
}
void K3bBootImageView::updateBootImages()
{
m_viewImages->clear();
for( TQPtrListIterator<K3bBootItem> it( m_doc->bootImages() ); it.current(); ++it ) {
(void)new PrivateBootImageViewItem( *it, m_viewImages,
m_viewImages->lastItem() );
}
}
void K3bBootImageView::loadBootItemSettings( K3bBootItem* item )
{
// this is needed to prevent the slots to change stuff
m_loadingItem = true;
if( item ) {
m_groupOptions->setEnabled(true);
m_groupImageType->setEnabled(true);
m_checkNoBoot->setChecked( item->noBoot() );
m_checkInfoTable->setChecked( item->bootInfoTable() );
m_editLoadSegment->setText( "0x" + TQString::number( item->loadSegment(), 16 ) );
m_editLoadSize->setText( "0x" + TQString::number( item->loadSize(), 16 ) );
if( item->imageType() == K3bBootItem::FLOPPY )
m_radioFloppy->setChecked(true);
else if( item->imageType() == K3bBootItem::HARDDISK )
m_radioHarddisk->setChecked(true);
else
m_radioNoEmulation->setChecked(true);
// force floppy size
KIO::filesize_t fsize = K3b::filesize( item->localPath() );
m_radioFloppy->setDisabled( fsize != 1200*1024 &&
fsize != 1440*1024 &&
fsize != 2880*1024 );
}
else {
m_groupOptions->setEnabled(false);
m_groupImageType->setEnabled(false);
}
m_loadingItem = false;
}
void K3bBootImageView::slotOptionsChanged()
{
if( !m_loadingItem ) {
TQListViewItem* item = m_viewImages->selectedItem();
if( item ) {
K3bBootItem* i = ((PrivateBootImageViewItem*)item)->bootImage();
i->setNoBoot( m_checkNoBoot->isChecked() );
i->setBootInfoTable( m_checkInfoTable->isChecked() );
// TODO: create some class K3bIntEdit : public TQLineEdit
bool ok = true;
i->setLoadSegment( K3bIntValidator::toInt( m_editLoadSegment->text(), &ok ) );
if( !ok )
kdDebug() << "(K3bBootImageView) parsing number failed: " << m_editLoadSegment->text().lower() << endl;
i->setLoadSize( K3bIntValidator::toInt( m_editLoadSize->text(), &ok ) );
if( !ok )
kdDebug() << "(K3bBootImageView) parsing number failed: " << m_editLoadSize->text().lower() << endl;
if( m_radioFloppy->isChecked() )
i->setImageType( K3bBootItem::FLOPPY );
else if( m_radioHarddisk->isChecked() )
i->setImageType( K3bBootItem::HARDDISK );
else
i->setImageType( K3bBootItem::NONE );
}
}
}
void K3bBootImageView::slotNoEmulationToggled( bool on )
{
// it makes no sense to combine no emulation and no boot!
// the base_widget takes care of the disabling
if( on )
m_checkNoBoot->setChecked(false);
}
#include "k3bbootimageview.moc"
|