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
|
/****************************************************************************
**
** Copyright (C) 2009-2010 Andrey Rijov <ANDron142@yandex.ru>
**
** This file is part of AQEMU.
**
** 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.
**
** 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 <QCheckBox>
#include "Boot_Device_Window.h"
#include "Utils.h"
Boot_Device_Window::Boot_Device_Window( QWidget *parent )
: QDialog( parent )
{
ui.setupUi( this );
}
QList<VM::Boot_Order> Boot_Device_Window::data() const
{
QList<VM::Boot_Order> list;
for( int ix = 0; ix < ui.Boot_Devices_List->topLevelItemCount(); ix++ )
{
QTreeWidgetItem *item = ui.Boot_Devices_List->topLevelItem( ix );
if( item != NULL )
{
VM::Boot_Order tmpDev;
if( item->checkState(0) == Qt::Checked ) tmpDev.Enabled = true;
else tmpDev.Enabled = false;
QString typeStr = item->data( 0, Qt::UserRole ).toString();
if( typeStr == "FDA" ) tmpDev.Type = VM::Boot_From_FDA;
else if( typeStr == "FDB" ) tmpDev.Type = VM::Boot_From_FDB;
else if( typeStr == "CDROM" ) tmpDev.Type = VM::Boot_From_CDROM;
else if( typeStr == "HDD" ) tmpDev.Type = VM::Boot_From_HDD;
else if( typeStr == "Network1" ) tmpDev.Type = VM::Boot_From_Network1;
else if( typeStr == "Network2" ) tmpDev.Type = VM::Boot_From_Network2;
else if( typeStr == "Network3" ) tmpDev.Type = VM::Boot_From_Network3;
else if( typeStr == "Network4" ) tmpDev.Type = VM::Boot_From_Network4;
else
{
AQError( "QList<VM::Boot_Order> Boot_Device_Window::data() const",
"Incorrent boot device type \"" + typeStr + "\"!" );
}
list << tmpDev;
}
}
return list;
}
void Boot_Device_Window::setData( const QList<VM::Boot_Order> &list )
{
ui.Boot_Devices_List->clear();
ui.Boot_Devices_List->resizeColumnToContents( 0 );
for( int ix = 0; ix < list.count(); ix++ )
{
QTreeWidgetItem *item = new QTreeWidgetItem( ui.Boot_Devices_List );
if( list[ix].Enabled ) item->setCheckState( 0, Qt::Checked );
else item->setCheckState( 0, Qt::Unchecked );
switch( list[ix].Type )
{
case VM::Boot_From_FDA:
item->setText( 0, tr("Floppy A") );
item->setData( 0, Qt::UserRole, "FDA" );
break;
case VM::Boot_From_FDB:
item->setText( 0, tr("Floppy B") );
item->setData( 0, Qt::UserRole, "FDB" );
break;
case VM::Boot_From_CDROM:
item->setText( 0, tr("CD-ROM") );
item->setData( 0, Qt::UserRole, "CDROM" );
break;
case VM::Boot_From_HDD:
item->setText( 0, tr("Hard Drive") );
item->setData( 0, Qt::UserRole, "HDD" );
break;
case VM::Boot_From_Network1:
item->setText( 0, tr("Network 1") );
item->setData( 0, Qt::UserRole, "Network1" );
break;
case VM::Boot_From_Network2:
item->setText( 0, tr("Network 2") );
item->setData( 0, Qt::UserRole, "Network2" );
break;
case VM::Boot_From_Network3:
item->setText( 0, tr("Network 3") );
item->setData( 0, Qt::UserRole, "Network3" );
break;
case VM::Boot_From_Network4:
item->setText( 0, tr("Network 4") );
item->setData( 0, Qt::UserRole, "Network4" );
break;
default:
AQWarning( "void Boot_Device_Window::setData( QList<VM::Boot_Order> &list )",
"Incorrect boot device type!" );
break;
}
}
}
bool Boot_Device_Window::useBootMenu() const
{
return ui.CH_Boot_Menu->isChecked();
}
void Boot_Device_Window::setUseBootMenu( bool use )
{
ui.CH_Boot_Menu->setChecked( use );
}
void Boot_Device_Window::on_TB_Up_clicked()
{
int index = Get_Current_Index();
if( index < 1 ||
index > ui.Boot_Devices_List->topLevelItemCount() ) return;
QTreeWidgetItem *item = ui.Boot_Devices_List->takeTopLevelItem( index );
ui.Boot_Devices_List->insertTopLevelItem( index - 1, item );
ui.Boot_Devices_List->setCurrentItem( item );
}
void Boot_Device_Window::on_TB_Down_clicked()
{
int index = Get_Current_Index();
if( index < 0 ||
index > ui.Boot_Devices_List->topLevelItemCount()-2 ) return;
QTreeWidgetItem *item = ui.Boot_Devices_List->takeTopLevelItem( index );
ui.Boot_Devices_List->insertTopLevelItem( index + 1, item );
ui.Boot_Devices_List->setCurrentItem( item );
}
int Boot_Device_Window::Get_Current_Index()
{
QTreeWidgetItem *currentItem = ui.Boot_Devices_List->currentItem();
if( ! currentItem ) return -1;
for( int ix = 0; ix < ui.Boot_Devices_List->topLevelItemCount(); ++ix )
{
if( ui.Boot_Devices_List->topLevelItem(ix) == currentItem ) return ix;
}
return -1; // not finded
}
|