Exemplo n.º 1
0
InstallDialog::InstallDialog(QWidget *parent, Qt::WindowFlags flags) : QDialog(parent, flags)
{
    QWidget *widget = new QWidget(this);
    KFormat format;
    ui = new Ui::InstallDialog;
    ui->setupUi(widget);
    QVBoxLayout *mainLayout = new QVBoxLayout;
    setLayout(mainLayout);
    mainLayout->addWidget(widget);
    QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
    mainLayout->addWidget(buttonBox);
    buttonBox->button(QDialogButtonBox::Ok)->setIcon(QApplication::style()->standardIcon(QStyle::SP_DialogOkButton));
    buttonBox->button(QDialogButtonBox::Cancel)->setIcon(QApplication::style()->standardIcon(QStyle::SP_DialogCancelButton));
    connect(buttonBox, SIGNAL(accepted()), this, SLOT(SlotOkButtonClicked()));
    connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
    buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
    setWindowTitle(i18nc("@title:window", "Install/Recover Bootloader"));
    setWindowIcon(QIcon::fromTheme(QStringLiteral("system-software-update")));
    if (parent) {
        resize(parent->size());
    }

    ui->treeWidget_recover->headerItem()->setText(0, QString());
    ui->treeWidget_recover->header()->setSectionResizeMode(QHeaderView::Stretch);
    ui->treeWidget_recover->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
    Q_FOREACH(const Solid::Device &device, Solid::Device::listFromType(Solid::DeviceInterface::StorageAccess)) {
        if (!device.is<Solid::StorageAccess>() || !device.is<Solid::StorageVolume>()) {
            continue;
        }
        const Solid::StorageAccess *partition = device.as<Solid::StorageAccess>();
        if (!partition) {
            continue;
        }
        const Solid::StorageVolume *volume = device.as<Solid::StorageVolume>();
        if (!volume || volume->usage() != Solid::StorageVolume::FileSystem) {
            continue;
        }

        QString uuidDir = "/dev/disk/by-uuid/", uuid = volume->uuid(), name;
        name = (QFile::exists((name = uuidDir + uuid)) || QFile::exists((name = uuidDir + uuid.toLower())) || QFile::exists((name = uuidDir + uuid.toUpper())) ? QFile::symLinkTarget(name) : QString());
        QTreeWidgetItem *item = new QTreeWidgetItem(ui->treeWidget_recover, QStringList() << QString() << name << partition->filePath() << volume->label() << volume->fsType() << format.formatByteSize(volume->size())); //KGlobal::locale()->
        item->setIcon(1, QIcon::fromTheme(device.icon()));
        item->setTextAlignment(5, Qt::AlignRight | Qt::AlignVCenter);
        ui->treeWidget_recover->addTopLevelItem(item);
        QRadioButton *radio = new QRadioButton(ui->treeWidget_recover);
        connect(radio, SIGNAL(clicked(bool)), buttonBox->button(QDialogButtonBox::Ok), SLOT(setEnabled(bool)));
        ui->treeWidget_recover->setItemWidget(item, 0, radio);
    }
}
Exemplo n.º 2
0
QString KBalooRolesProvider::bitrateFromValue(int value) const
{
    KFormat form;
    QString bitrate = i18nc("@label bitrate (per second)", "%1/s", form.formatByteSize(value, 1, KFormat::MetricBinaryDialect));
    return bitrate;
}
Exemplo n.º 3
0
QVariant TreeModel::data(const QModelIndex& index, int role) const
{
    if (index.row() < 0 || index.column() < 0 || index.column() > NUM_COLUMNS) {
        return {};
    }

    const auto row = (role == MaxCostRole) ? &m_maxCost : toRow(index);

    if (role == Qt::DisplayRole || role == SortRole || role == MaxCostRole) {
        switch (static_cast<Columns>(index.column())) {
        case AllocatedColumn:
            if (role == SortRole || role == MaxCostRole) {
                return static_cast<qint64>(abs(row->cost.allocated));
            }
            return m_format.formatByteSize(row->cost.allocated);
        case AllocationsColumn:
            if (role == SortRole || role == MaxCostRole) {
                return static_cast<qint64>(abs(row->cost.allocations));
            }
            return static_cast<qint64>(row->cost.allocations);
        case TemporaryColumn:
            if (role == SortRole || role == MaxCostRole) {
                return static_cast<qint64>(abs(row->cost.temporary));
            }
            return static_cast<qint64>(row->cost.temporary);
        case PeakColumn:
            if (role == SortRole || role == MaxCostRole) {
                return static_cast<qint64>(abs(row->cost.peak));
            } else {
                return m_format.formatByteSize(row->cost.peak);
            }
        case LeakedColumn:
            if (role == SortRole || role == MaxCostRole) {
                return static_cast<qint64>(abs(row->cost.leaked));
            } else {
                return m_format.formatByteSize(row->cost.leaked);
            }
        case FunctionColumn:
            return row->location->function;
        case ModuleColumn:
            return row->location->module;
        case FileColumn:
            return row->location->file;
        case LineColumn:
            return row->location->line;
        case LocationColumn:
            if (row->location->file.isEmpty()) {
                return i18n("%1 in ?? (%2)",
                            basename(row->location->function),
                            basename(row->location->module));
            } else {
                return i18n("%1 in %2:%3 (%4)", row->location->function,
                            basename(row->location->file), row->location->line,
                            basename(row->location->module));
            }
        case NUM_COLUMNS:
            break;
        }
    } else if (role == Qt::ToolTipRole) {
        QString tooltip;
        QTextStream stream(&tooltip);
        stream << "<qt><pre style='font-family:monospace;'>";
        if (row->location->line > 0) {
            stream << i18nc("1: function, 2: file, 3: line, 4: module", "%1\n  at %2:%3\n  in %4",
                            row->location->function.toHtmlEscaped(),
                            row->location->file.toHtmlEscaped(), row->location->line, row->location->module.toHtmlEscaped());
        } else {
            stream << i18nc("1: function, 2: module", "%1\n  in %2",
                            row->location->function.toHtmlEscaped(), row->location->module.toHtmlEscaped());
        }
        stream << '\n';
        stream << '\n';
        KFormat format;
        const auto allocatedFraction = QString::number(double(row->cost.allocated)  * 100. / m_maxCost.cost.allocated, 'g', 3);
        const auto peakFraction = QString::number(double(row->cost.peak)  * 100. / m_maxCost.cost.peak, 'g', 3);
        const auto leakedFraction = QString::number(double(row->cost.leaked)  * 100. / m_maxCost.cost.leaked, 'g', 3);
        const auto allocationsFraction = QString::number(double(row->cost.allocations)  * 100. / m_maxCost.cost.allocations, 'g', 3);
        const auto temporaryFraction = QString::number(double(row->cost.temporary)  * 100. / row->cost.allocations, 'g', 3);
        const auto temporaryFractionTotal = QString::number(double(row->cost.temporary)  * 100. / m_maxCost.cost.temporary, 'g', 3);
        stream << i18n("allocated: %1 (%2% of total)\n",
                       format.formatByteSize(row->cost.allocated), allocatedFraction);
        stream << i18n("peak: %1 (%2% of total)\n", format.formatByteSize(row->cost.peak), peakFraction);
        stream << i18n("leaked: %1 (%2% of total)\n", format.formatByteSize(row->cost.leaked), leakedFraction);
        stream << i18n("allocations: %1 (%2% of total)\n", row->cost.allocations, allocationsFraction);
        stream << i18n("temporary: %1 (%2% of allocations, %3% of total)\n",
                       row->cost.temporary, temporaryFraction, temporaryFractionTotal);
        if (!row->children.isEmpty()) {
            auto child = row;
            int max = 5;
            if (child->children.count() == 1) {
                stream << '\n' << i18n("backtrace:") << '\n';
            }
            while (child->children.count() == 1 && max-- > 0) {
                stream << "\n";
                if (child->location->line > 0) {
                    stream << i18nc("1: function, 2: file, 3: line, 4: module", "%1\n  at %2:%3\n  in %4",
                                    child->location->function.toHtmlEscaped(),
                                    child->location->file.toHtmlEscaped(), child->location->line,
                                    child->location->module.toHtmlEscaped());
                } else {
                    stream << i18nc("1: function, 2: module", "%1\n  in %2",
                                    child->location->function.toHtmlEscaped(), child->location->module.toHtmlEscaped());
                }
                child = child->children.data();
            }
            if (child->children.count() > 1) {
                stream << "\n";
                stream << i18np("called from one location", "called from %1 locations", child->children.count());
            }
        }
        stream << "</pre></qt>";
        return tooltip;
    }
    return {};
}
Exemplo n.º 4
0
QVariant ChartModel::data(const QModelIndex& index, int role) const
{
    if (!index.isValid()) {
        return {};
    }
    Q_ASSERT(index.row() >= 0 && index.row() < rowCount(index.parent()));
    Q_ASSERT(index.column() >= 0 && index.column() < columnCount(index.parent()));
    Q_ASSERT(!index.parent().isValid());

    if ( role == KChart::LineAttributesRole ) {
        KChart::LineAttributes attributes;
        attributes.setDisplayArea(true);
        if (index.column() > 1) {
            attributes.setTransparency(127);
        } else {
            attributes.setTransparency(50);
        }
        return QVariant::fromValue(attributes);
    }


    if ( role == KChart::DatasetPenRole ) {
        return QVariant::fromValue(m_columnDataSetPens.at(index.column()));
    } else if ( role == KChart::DatasetBrushRole ) {
        return QVariant::fromValue(m_columnDataSetBrushes.at(index.column()));
    }

    if ( role != Qt::DisplayRole && role != Qt::ToolTipRole ) {
        return {};
    }

    const auto& data = m_data.rows.at(index.row());

    int column = index.column();
    if (role != Qt::ToolTipRole && column % 2 == 0) {
        return data.timeStamp;
    }
    column = column / 2;
    Q_ASSERT(column < ChartRows::MAX_NUM_COST);

    const auto cost = data.cost[column];
    if (role == Qt::ToolTipRole) {
        const QString time = QString::number(double(data.timeStamp) / 1000, 'g', 3) + QLatin1Char('s');
        const auto label = m_data.labels.value(column).toHtmlEscaped();
        KFormat format;
        switch (m_type) {
            case Allocations:
                return i18n("<qt>%2 allocations after %3 from:<p style='margin-left:10px;'>%1</p></qt>",
                            label, cost, time);
            case Temporary:
                return i18n("<qt>%2 temporary allocations after %3 from:<p style='margin-left:10px'>%1</p></qt>",
                            label, cost, time);
            case Consumed:
                return i18n("<qt>%2 consumed after %3 from:<p style='margin-left:10px'>%1</p></qt>",
                            label, format.formatByteSize(cost, 1, KFormat::MetricBinaryDialect), time);
            case Allocated:
                return i18n("<qt>%2 allocated after %3 from:<p style='margin-left:10px'>%1</p></qt>",
                            label, format.formatByteSize(cost, 1, KFormat::MetricBinaryDialect), time);
        }
        return {};
    }

    return cost;
}