Exemplo n.º 1
0
BootSelectionDialog::BootSelectionDialog(const QString &defaultPartition, QWidget *parent) :
    QDialog(parent),
    _countdown(OS_SELECTION_TIMEOUT+1),
    ui(new Ui::BootSelectionDialog)
{
    setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
    ui->setupUi(this);
    QRect s = QApplication::desktop()->screenGeometry();
    if (s.height() < 500)
        resize(s.width()-10, s.height()-100);

    QDir dir;
    dir.mkdir("/settings");

    if (QProcess::execute("mount -o remount,ro /settings") != 0
        && QProcess::execute("mount -t ext4 -o ro " SETTINGS_PARTITION " /settings") != 0)
    {
        QMessageBox::critical(this, tr("Cannot display boot menu"), tr("Error mounting settings partition"));
        return;
    }

    /* Also mount /dev/mmcblk0p1 as it may contain icons we need */
    if (QProcess::execute("mount -t vfat -o ro /dev/mmcblk0p1 /mnt") != 0)
    {
        /* Not fatal if this fails */
    }

    QVariantList installed_os = Json::loadFromFile("/settings/installed_os.json").toList();
    QSize currentsize = ui->list->iconSize();

    foreach (QVariant v, installed_os)
    {
        QVariantMap m = v.toMap();
        QString iconfilename = m.value("icon").toString();
        QIcon icon;

        if (!iconfilename.isEmpty() && QFile::exists(iconfilename))
        {
            icon = QIcon(iconfilename);
            QList<QSize> avs = icon.availableSizes();
            if (avs.isEmpty())
            {
                /* Icon file corrupt */
                icon = QIcon();
            }
            else
            {
                QSize iconsize = avs.first();

                if (iconsize.width() > currentsize.width() || iconsize.height() > currentsize.height())
                {
                    /* Make all icons as large as the largest icon we have */
                    currentsize = QSize(qMax(iconsize.width(), currentsize.width()),qMax(iconsize.height(), currentsize.height()));
                    ui->list->setIconSize(currentsize);
                }
            }
        }
        if (canBootOs(m.value("name").toString(), m))
        {
            QListWidgetItem *item = new QListWidgetItem(icon, m.value("name").toString()+"\n"+m.value("description").toString(), ui->list);
            item->setData(Qt::UserRole, m);
        }
    }
Exemplo n.º 2
0
BootSelectionDialog::BootSelectionDialog(
        const QString &drive,               //PINN drive where boot partitions are stored for DSI mod
        const QString &defaultPartition,    //Could be provided on cmdline. Only used if no previoous OS had been used.
        bool stickyBoot,                    //Use Stickyboot i.e. when NOT going through recovery menu
        bool dsi,                           //Adapt config.txt according to fitted monitor
        QWidget *parent) :
    QDialog(parent),
    _countdown(11),
    _dsi(dsi),
    ui(new Ui::BootSelectionDialog),
    _inSelection(false),
    _drive(drive.toAscii())
{
    setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
    ui->setupUi(this);
    QRect s = QApplication::desktop()->screenGeometry();
    if (s.height() < 500)
        resize(s.width()-10, s.height()-100);
    QDir dir;
    dir.mkdir("/settings");
    if (QProcess::execute("mount -o remount,ro /settings") != 0
        && QProcess::execute("mount -t ext4 -o ro "+partdev(drive, SETTINGS_PARTNR)+" /settings") != 0)
    {
        QMessageBox::critical(this, tr("Cannot display boot menu"), tr("Error mounting settings partition"));
        return;
    }

    _altered=false;

    cec->setWindow("bootSelection");
    cec->setMenu("any");
    connect(cec, SIGNAL(keyPress(int)), this, SLOT(onKeyPress(int)));

    /* Also mount recovery partition as it may contain icons we need */
    if (QProcess::execute("mount -t vfat -o ro "+partdev(drive, 1)+" /mnt") != 0)
    {
        /* Not fatal if this fails */
    }
    installed_os = Json::loadFromFile("/settings/installed_os.json").toList();
    QSize currentsize = ui->list->iconSize();

    QSettings settings("/settings/noobs.conf", QSettings::IniFormat, this);
    int oldSticky = settings.value("sticky_boot", 800).toInt();

    foreach (QVariant v, installed_os)
    {
        QVariantMap m = v.toMap();
        QString iconfilename = m.value("icon").toString();
        QIcon icon;

        if (!iconfilename.isEmpty() && QFile::exists(iconfilename))
        {
            icon = QIcon(iconfilename);
            QList<QSize> avs = icon.availableSizes();
            if (avs.isEmpty())
            {
                /* Icon file corrupt */
                icon = QIcon();
            }
            else
            {
                QSize iconsize = avs.first();

                if (iconsize.width() > currentsize.width() || iconsize.height() > currentsize.height())
                {
                    /* Make all icons as large as the largest icon we have */
                    currentsize = QSize(qMax(iconsize.width(), currentsize.width()),qMax(iconsize.height(), currentsize.height()));
                    ui->list->setIconSize(currentsize);
                }
            }
        }
        QString name = CORE(m.value("name").toString());
        if (canBootOs(name, m))
        {
            name=NICKNAME(m.value("name").toString());
            QListWidgetItem *item = new QListWidgetItem(icon, name+"\n"+m.value("description").toString(), ui->list);
            item->setData(Qt::UserRole, m);
            item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
            item->setCheckState(Qt::Unchecked);
         }
    }