//#include #include #include #include #include #include "mv_common.h" #include "mythprogressdialog.h" #include "installationtype.h" #include "mythsystemlegacy.h" int mythinstalltype (QString tmp_install_drive) { QString line; QString disksize; QString rootsize; QString homesize; QString sqlsize; QString useswap; QString swapsize; QString datasize; QString usealldata; int neededsize; int disksizeMB; int retc = 1; while ( retc != 0 ) { Mythinstalltype setting; //FINDME this is needed to populate the default values and have the triggered config work setting.Load(); setting.Save(); if ( setting.exec() == QDialog::Accepted ) { //get users sizes rootsize = gCoreContext->GetSetting("HOSTOSsize"); homesize = gCoreContext->GetSetting("HOSTHOMEsize"); sqlsize = gCoreContext->GetSetting("HOSTDatabasesize"); useswap = gCoreContext->GetSetting("HostUseSWAP"); swapsize = gCoreContext->GetSetting("HOSTSWAPsize"); usealldata = gCoreContext->GetSetting("HostUseALLdata"); datasize = gCoreContext->GetSetting("HOSTDATAsize"); //check if using swap if ( useswap == "0" ) swapsize = "0"; //calculate size of all partitions; neededsize = rootsize.toInt() * 1024 + homesize.toInt() *1024 + sqlsize.toInt() * 1024 + swapsize.toInt(); //add 300 MB to neededsize if usealldata is enabled if ( usealldata == "1" ) neededsize = neededsize + 300; else neededsize = neededsize + datasize.toInt() * 1024; //get selected drive size //using myth_system as QFile wouldn't read /proc/partitions directly myth_system("cat /proc/partitions > /tmp/proc.partitions"); QFile file("/tmp/proc.partitions"); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream t( &file ); while (!t.atEnd()) { line = t.readLine(); line = line.simplified(); if ( line.endsWith(tmp_install_drive) ) { disksize = line.section( " ", 2, 2 ); //QTextStream(stdout) << "disksize:" + disksize << endl; break; } } } file.close(); //convert to MB and match calulation in installdialog.cpp disksizeMB = qRound(disksize.toFloat() * 1024 / 1000000); if (neededsize > disksizeMB) { DialogCode val = MythPopupBox::Show2ButtonPopup( GetMythMainWindow(), "Error", "The total partition sizes (" + QString::number(neededsize) + " MB) are too large for the selected drive (" + QString::number(disksizeMB) + " MB). Continuing may result in a failed install.", QObject::tr("Continue"), QObject::tr("Try Again"), kDialogCodeButton1); if ( val == kDialogCodeButton0 ) { retc = 0; } else { retc = 1; } } else { retc = 0; } } else { retc = 0; } } return retc; }; static HostComboBox *HOSTinstallationtype() { HostComboBox *gc = new HostComboBox("HOSTinstallationtype"); gc->setLabel(QObject::tr("Installation Type")); gc->addSelection("Full/Auto") ; gc->addSelection("Upgrade"); //gc->setValue("Full/Auto"); gc->setHelpText(QObject::tr("Full install will erase the entire drive and repartition. Upgrade will format only the first parition of the drive. Only LinHES R8.0 or newer can use Upgrade.")); return gc; } static HostSpinBox *HOSTOSsize() { #ifdef __MVAPP__ HostSpinBox *gc = new HostSpinBox("HOSTOSsize", 2, 15, 1, true); #else HostSpinBox *gc = new HostSpinBox("HOSTOSsize", 3, 25, 1, true); #endif gc->setLabel(QObject::tr("OS size (GB)")); gc->setValue(2); gc->setHelpText(QObject::tr("Amount of space allocated for the root OS." )); return gc; } static HostSpinBox *HOSTDATAsize() { HostSpinBox *gc = new HostSpinBox("HOSTDATAsize", 2, 1500, 1, true); gc->setLabel(QObject::tr("Data size (GB)")); gc->setValue(3); gc->setHelpText(QObject::tr("" )); return gc; } static HostSpinBox *HOSTHOMEsize() { HostSpinBox *gc = new HostSpinBox("HOSTHOMEsize", 1, 1500, 1, true); gc->setLabel(QObject::tr("Home dir size (GB)")); gc->setValue(3); gc->setHelpText(QObject::tr("Amount of space allocated for the home directories partition. Three to five GB will be sufficient for most people. The home partition will be the same filesystem as the root OS." )); return gc; } static HostSpinBox *HOSTDatabasesize() { HostSpinBox *gc = new HostSpinBox("HOSTDatabasesize", 1, 20, 1, true); gc->setLabel(QObject::tr("Database partition size (GB)")); gc->setValue(4); gc->setHelpText(QObject::tr("Amount of space allocated for the database partition. Two GB is more then enough for most people. The database partition space will be formatted with the ext3 filesystem." )); return gc; } static HostSpinBox *HOSTSWAPsize() { QString currentitem; QString line; QFile file("/proc/meminfo"); if ( file.open(QIODevice::ReadOnly | QIODevice::Text) ) { QTextStream t( &file ); // use a text stream line = t.readLine(); if ( line.startsWith("MemTotal:") ) { currentitem = line.simplified(); currentitem = currentitem.section( " ", 1, 1 ); } } file.close(); bool ok; int mem = currentitem.toInt( &ok, 10 ); // dec == 0, ok == FALSE //QTextStream(stdout) << mem << endl; mem = mem / 1024 + 16; //QTextStream(stdout) << mem << endl; if ( ! ok ) mem = 257 ; //QTextStream(stdout) << mem << endl; HostSpinBox *gc = new HostSpinBox("HOSTSWAPsize", 256, 256000, 256, true); gc->setLabel(QObject::tr("Swapspace size (MB)")); gc->setValue(mem); gc->setHelpText(QObject::tr("Amount of space allocated for the swap partition." )); return gc; } static HostCheckBox *HostUseSWAP() { HostCheckBox *gc = new HostCheckBox("HostUseSWAP"); gc->setLabel(QObject::tr("Use swap partition")); gc->setValue(true); gc->setHelpText(QObject::tr("Enable or disable the swap partition.")); return gc; }; static HostCheckBox *HostUseALLdata() { HostCheckBox *gc = new HostCheckBox("HostUseALLdata"); gc->setLabel(QObject::tr("Use all remaining space for data")); gc->setValue(true); gc->setHelpText(QObject::tr("If checked the remaining space on the drive will be used for storage. Otherwise you can set the size of the partition.")); return gc; }; static HostComboBox *HOSTdatafstype() { HostComboBox *gc = new HostComboBox("HOSTdatafstype"); gc->setLabel(QObject::tr("Data filesystem")); gc->addSelection("ext3") ; gc->addSelection("ext4") ; // gc->addSelection("reiserfs"); gc->addSelection("jfs"); gc->addSelection("xfs"); //gc->addSelection("btrfs"); gc->setHelpText(QObject::tr("Filesystem type for data storage.")); return gc; } static HostComboBox *HOSTuprootfstype() { HostComboBox *gc = new HostComboBox("HOSTuprootfstype"); gc->setLabel(QObject::tr("OS file system")); gc->addSelection("ext3") ; gc->addSelection("ext4") ; gc->addSelection("reiserfs"); gc->addSelection("jfs"); //gc->addSelection("xfs"); //gc->addSelection("btrfs"); gc->addSelection("Do_not_format"); gc->setHelpText(QObject::tr("Filesystem type for OS. ")); return gc; } static HostComboBox *HOSTrootfstype() { HostComboBox *gc = new HostComboBox("HOSTrootfstype"); gc->setLabel(QObject::tr("Root filesystem format")); gc->addSelection("ext3") ; gc->addSelection("ext4") ; gc->addSelection("reiserfs"); gc->addSelection("jfs"); //gc->addSelection("btrfs"); //gc->addSelection("xfs"); gc->setHelpText(QObject::tr("Filesystem type for root OS.")); return gc; } class USESwap: public TriggeredConfigurationGroup { public: USESwap(): TriggeredConfigurationGroup(true,false,true,true,false,false,false,true) { SetVertical(false); Setting* useswap = HostUseSWAP(); addChild(useswap); setTrigger(useswap); ConfigurationGroup* swapyes = new VerticalConfigurationGroup(false); swapyes->addChild(HOSTSWAPsize()); addTarget("1", swapyes ); addTarget("0", new VerticalConfigurationGroup(true)); }; }; class DATAsize: public TriggeredConfigurationGroup { public: DATAsize(): TriggeredConfigurationGroup(true,false,true,true,false,false,false,true) { SetVertical(false); Setting* datasize = HostUseALLdata(); addChild(datasize); setTrigger(datasize); ConfigurationGroup* alldatano = new VerticalConfigurationGroup(false); alldatano->addChild(HOSTDATAsize()); alldatano->addChild(HOSTdatafstype()); ConfigurationGroup* alldatayes = new VerticalConfigurationGroup(false); alldatayes->addChild(HOSTdatafstype()); addTarget("1", alldatayes); addTarget("0", alldatano); }; }; class Installationtype: public TriggeredConfigurationGroup { public: Installationtype(): TriggeredConfigurationGroup(true,false,true,true,false,false,false,true) { setLabel(QObject::tr("LinHES Install")); Setting *Mtemplate = HOSTinstallationtype(); addChild(Mtemplate); setTrigger(Mtemplate); ConfigurationGroup *ospartition = new GridConfigurationGroup(2,false); ospartition->addChild(HOSTOSsize()); ospartition->addChild(HOSTrootfstype()); ospartition->addChild(HOSTHOMEsize()); ospartition->addChild(HOSTDatabasesize()); ConfigurationGroup *tupgrade = new VerticalConfigurationGroup(false); tupgrade->addChild(HOSTuprootfstype()); ConfigurationGroup *tfull = new VerticalConfigurationGroup(false); // tfull->addChild(HOSTOSsize()); // tfull->addChild(HOSTrootfstype()); tfull->addChild(ospartition); tfull->addChild(new USESwap); tfull->addChild(new DATAsize); addTarget("Upgrade",tupgrade ); addTarget("Full/Auto", tfull); }; }; Mythinstalltype::Mythinstalltype() { //Reseting the install type to remove "NET" if ( gCoreContext->GetSetting("Hostinstallationtype") == "NET") gCoreContext->SaveSetting("HOSTinstallationtype","Full/Auto"); Installationtype *installationtype = new Installationtype(); addChild(installationtype); };