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 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
|
/****************************************************************************
**
** Copyright (C) 2008-2009 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 <QDir>
#include <QDialog>
#include <QMessageBox>
#include <QFileDialog>
#include <QInputDialog>
#include "Utils.h"
#include "Settings_Window.h"
#include "Create_Template_Window.h"
#include "QEMU_Binary_Window.h"
Settings_Window::Settings_Window( QWidget *parent )
: QDialog( parent )
{
ui.setupUi( this );
First_Show = false;
// Minimum Size
resize( width(), minimumSizeHint().height() );
// Load Settings
Settings = new QSettings();
// Emulator Control
bool emul_show = Settings->value( "Show_Emulator_Control_Window", "yes" ).toString() == "yes";
bool emul_vnc = Settings->value( "Use_VNC_Display", "no" ).toString() == "yes";
bool emul_include = Settings->value( "Include_Emulator_Control", "yes" ).toString() == "yes";
if( emul_show == true && emul_vnc == false && emul_include == false )
{
ui.RB_Emul_Show_Window->setChecked( true );
}
else if( emul_show == true && emul_vnc == true && emul_include == false )
{
ui.RB_Emul_Show_VNC->setChecked( true );
}
else if( emul_show == true && emul_vnc == false && emul_include == true )
{
ui.RB_Emul_Show_In_Main_Window->setChecked( true );
}
else if( emul_show == true && emul_vnc == true && emul_include == true )
{
ui.RB_Emul_Show_VNC_In_Main_Window->setChecked( true );
}
else if( emul_show == false && emul_vnc == false && emul_include == false )
{
ui.RB_Emul_No_Show->setChecked( true );
}
#ifndef VNC_DISPLAY
ui.RB_Emul_Show_VNC->setEnabled( false );
ui.RB_Emul_Show_VNC_In_Main_Window->setEnabled( false );
if( ui.RB_Emul_Show_VNC->isChecked() ) ui.RB_Emul_Show_Window->setChecked( true );
else if( ui.RB_Emul_Show_VNC_In_Main_Window->isChecked() ) ui.RB_Emul_Show_In_Main_Window->setChecked( true );
#endif
// Virtual Machines Folder
ui.Edit_VM_Folder->setText( Settings->value("VM_Directory", QDir::homePath() + "/.aqemu/").toString() );
// Use Device Manager
ui.CH_Use_Device_Manager->setChecked( Settings->value("Use_Device_Manager", "no").toString() == "yes" );
// Find All Language Files (*.qm)
QDir data_dir( Settings->value("AQEMU_Data_Folder", "/usr/share/aqemu/").toString() );
QFileInfoList lang_files = data_dir.entryInfoList( QStringList("*.qm"), QDir::Files, QDir::Name );
if( lang_files.count() > 0 )
{
// Add Languages to List
for( int dd = 0; dd < lang_files.count(); ++dd )
{
ui.CB_Language->addItem( lang_files[dd].completeBaseName() );
if( lang_files[dd].completeBaseName() == Settings->value( "Language", "en" ).toString() )
{
ui.CB_Language->setCurrentIndex( dd + 1 ); // First Item 'English'
}
}
}
// 64x64 Icons
ui.CH_64_Icons->setChecked( Settings->value("64x64_Icons", "yes").toString() == "yes" );
// Screenshot for OS Logo
ui.CH_Screenshot_for_OS_Logo->setChecked( Settings->value("Use_Screenshot_for_OS_Logo", "yes").toString() == "yes" );
// Use USB
#ifdef Q_OS_LINUX
ui.CH_Use_USB->setEnabled( true );
ui.CH_Use_USB->setChecked( Settings->value("Use_USB", "yes").toString() == "yes" );
#else
ui.CH_Use_USB->setEnabled( false );
ui.CH_Use_USB->setChecked( false );
#endif
Load_Templates();
First_Show = true;
connect( ui.RB_Emul_Show_VNC, SIGNAL(toggled(bool)),
this, SLOT(VNC_Warning(bool)) );
connect( ui.RB_Emul_Show_VNC_In_Main_Window, SIGNAL(toggled(bool)),
this, SLOT(VNC_Warning(bool)) );
}
Settings_Window::~Settings_Window()
{
if( Settings != NULL ) delete Settings;
}
void Settings_Window::Load_Templates()
{
QList<QString> all_templates = Get_Templates_List();
ui.CB_Default_VM_Template->clear();
for( int ix = 0; ix < all_templates.count(); ++ix )
{
QFileInfo tmp_info = QFileInfo( all_templates[ix] );
ui.CB_Default_VM_Template->addItem( tmp_info.completeBaseName() );
}
// no items found
if( ui.CB_Default_VM_Template->count() < 1 )
{
AQGraphic_Warning( tr("Warning"), tr("AQEMU VM Templates Not Found!") );
}
else
{
// Find default template
for( int ix = 0; ix < ui.CB_Default_VM_Template->count(); ++ix )
{
if( ui.CB_Default_VM_Template->itemText(ix) == Settings->value("Default_VM_Template", "Linux_2_6").toString() )
{
ui.CB_Default_VM_Template->setCurrentIndex( ix );
}
}
}
}
void Settings_Window::on_Button_Create_Template_from_VM_clicked()
{
Create_Template_Window *templ_win = new Create_Template_Window();
if( templ_win->exec() == QDialog::Accepted )
{
Load_Templates();
QMessageBox::information( this, tr("Information"), tr("New Template Created!") );
}
delete templ_win;
}
void Settings_Window::on_TB_VM_Folder_clicked()
{
QString folder = QFileDialog::getExistingDirectory( this, tr("Set Folder for you VM's"),
Settings->value("VM_Directory", "~").toString() );
if( ! (folder.isNull() || folder.isEmpty()) )
{
if( ! folder.endsWith("/") || folder.endsWith("\\") )
{
#ifdef Q_OS_WIN32
folder += "\\";
#else
folder += "/";
#endif
}
ui.Edit_VM_Folder->setText( folder );
}
}
void Settings_Window::on_CB_Language_currentIndexChanged( int index )
{
if( First_Show && Settings->value("Show_Language_Warning", "yes").toString() == "yes" )
{
if( QMessageBox::information(this, tr("Information"),
tr("Language be set after restart AQEMU\nShow this message in future?"),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::No )
{
Settings->setValue( "Show_Language_Warning", "no" );
}
First_Show = false;
}
}
void Settings_Window::on_Button_OK_clicked()
{
QDir dir; // For Check on valid
Settings->setValue( "Default_VM_Template", ui.CB_Default_VM_Template->currentText() );
// VM Folder
if( ! ui.Edit_VM_Folder->text().endsWith("/") ) ui.Edit_VM_Folder->setText( ui.Edit_VM_Folder->text() + "/" );
if( dir.exists(ui.Edit_VM_Folder->text()) )
{
if( ! dir.exists(ui.Edit_VM_Folder->text() + "os_templates/") ) dir.mkdir( ui.Edit_VM_Folder->text() + "os_templates/" );
Settings->setValue( "VM_Directory", ui.Edit_VM_Folder->text() );
}
else
{
int mes_res = QMessageBox::question( this, tr("Invalid Value!"),
tr("Folder for AQEMU VM is Not Exists! Create It?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes );
if( mes_res == QMessageBox::Yes )
{
if( ! (dir.mkdir(ui.Edit_VM_Folder->text()) &&
dir.mkdir(ui.Edit_VM_Folder->text() + "os_templates/")) )
{
AQGraphic_Warning( tr("Error!"), tr("Cannot Create New Folder!") );
return;
}
else Settings->setValue( "VM_Directory", ui.Edit_VM_Folder->text() );
}
else return;
}
// Check Log
if( Settings->value("Use_Log", "yes").toString() == "yes" )
{
if( Settings->value("Log_Path", "aqemu.log").toString() == "aqemu.log" )
{
Settings->setValue( "Log_Path", Settings->value("VM_Directory", "").toString() + "aqemu.log" );
}
}
// Use Device Manager
if( ui.CH_Use_Device_Manager->isChecked() ) Settings->setValue( "Use_Device_Manager", "yes" );
else Settings->setValue( "Use_Device_Manager", "no" );
// Interface Language
if( ui.CB_Language->currentIndex() == 0 ) Settings->setValue( "Language", "en" );
else Settings->setValue( "Language", ui.CB_Language->itemText(ui.CB_Language->currentIndex()) );
// USB Support
if( ui.CH_Use_USB->isChecked() ) Settings->setValue( "Use_USB", "yes" );
else Settings->setValue( "Use_USB", "no" );
// Screenshot for OS Logo
if( ui.CH_Screenshot_for_OS_Logo->isChecked() ) Settings->setValue( "Use_Screenshot_for_OS_Logo", "yes" );
else Settings->setValue( "Use_Screenshot_for_OS_Logo", "no" );
// 64x64 Icons
if( ui.CH_64_Icons->isChecked() ) Settings->setValue( "64x64_Icons", "yes" );
else Settings->setValue( "64x64_Icons", "no" );
Settings->sync();
if( Settings->status() != QSettings::NoError )
{
AQError( "void Settings_Window::on_Button_Box_clicked( QAbstractButton* button )",
"QSettings Error!" );
}
// Emulator Control
if( ui.RB_Emul_Show_Window->isChecked() )
{
Settings->setValue( "Show_Emulator_Control_Window", "yes" );
Settings->setValue( "Use_VNC_Display", "no" );
Settings->setValue( "Include_Emulator_Control", "no" );
}
else if( ui.RB_Emul_Show_VNC->isChecked() )
{
Settings->setValue( "Show_Emulator_Control_Window", "yes" );
Settings->setValue( "Use_VNC_Display", "yes" );
Settings->setValue( "Include_Emulator_Control", "no" );
}
else if( ui.RB_Emul_Show_In_Main_Window->isChecked() )
{
Settings->setValue( "Show_Emulator_Control_Window", "yes" );
Settings->setValue( "Use_VNC_Display", "no" );
Settings->setValue( "Include_Emulator_Control", "yes" );
}
else if( ui.RB_Emul_Show_VNC_In_Main_Window->isChecked() )
{
Settings->setValue( "Show_Emulator_Control_Window", "yes" );
Settings->setValue( "Use_VNC_Display", "yes" );
Settings->setValue( "Include_Emulator_Control", "yes" );
}
else if( ui.RB_Emul_No_Show->isChecked() )
{
Settings->setValue( "Show_Emulator_Control_Window", "no" );
Settings->setValue( "Use_VNC_Display", "no" );
Settings->setValue( "Include_Emulator_Control", "no" );
}
accept();
}
void Settings_Window::VNC_Warning( bool state )
{
if( ! state ) return;
if( Settings->value("Show_VNC_Warning", "yes").toString() == "yes" )
{
if( QMessageBox::information(this, tr("Information"),
tr("Support for this feature is not complete! If there is no picture, click \"View->Reinit VNC\"\nShow This Message Again?"),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::No )
{
Settings->setValue( "Show_VNC_Warning", "no" );
}
}
}
|