Пример #1
0
void NetworkPlugin::contextMenuRequested()
{
    DeviceItem *item = qobject_cast<DeviceItem *>(sender());
    Q_ASSERT(item);

    m_proxyInter->requestContextMenu(this, item->uuid().toString());
}
bool UpdateDevModel::changeItem(void *c, int updateStatus, int updatePercent)
{
    int pos = this->getDevItemPos(c);
    if(pos == -1)
        return false;
    DeviceItem * item = this->items.at(pos);

    bool toSet = item->setUpdateStatus(updateStatus,updatePercent);
    if(toSet){
        QModelIndex left = this->createIndex(pos,3);
        QModelIndex right = this->createIndex(pos,3);
        topLeftList.append(left);
        bottomRightList.append(right);
    }
    return true;
}
bool UpdateDevModel::pushItem(DeviceItem *item)
{

    int pos = items.size();
    if (!this->insertRow(pos, QModelIndex()))
        return false;

    DeviceItem * newItem = items.value(pos);
    bool result = newItem->setData(item);
    if (result){
        QModelIndex left = this->createIndex(pos,0);
        QModelIndex right = this->createIndex(pos,headerTexts.size()-1);
        topLeftList.append(left);
        bottomRightList.append(right);
        //emit dataChanged(left, right);
    }
    return result;
}
Пример #4
0
void
MainWindow::deviceInserted(QDBusMessage message)
{
    QString devicePath;
#ifdef USEHAL
    devicePath = message.arguments().at(0).toString();
    if (devicePath.startsWith("/org/freedesktop/Hal/devices/storage_serial"))
#else
    QDBusObjectPath path = message.arguments().at(0).value<QDBusObjectPath>();
    devicePath = path.path();
    if (devicePath.startsWith("/org/freedesktop/UDisks/devices/"))
#endif
    {
        DeviceItem *device = pPlatform->getNewDevice(devicePath);
        if (device != NULL)
            if (deviceComboBox->findText(device->getDisplayString()) == -1)
                addMenuItem(device->getDisplayString());
    }
}
bool UpdateDevModel::setData(const QModelIndex &index, const QVariant &value, int role)
{

//    if(role == Qt::CheckStateRole && index.column() == 0){
//        DeviceItem *item = static_cast<DeviceItem*>(index.internalPointer());
//        if (value==Qt::Unchecked)
//        {
//            item->setCheckState(false);
//            emit dataChanged(index, index);
//            //m_checkedList.removeOne(item);
//            //emit selectedRows(m_checkedList.size());
//        }
//        else if(value==Qt::Checked)
//        {
//            item->setCheckState(true);
//            emit dataChanged(index, index);
//            if(!m_checkedList.contains(item)){
//                m_checkedList.append(item);
//                emit selectedRows(m_checkedList.size());
//            }
//        }
//        return true;
//    }

    if(role == Qt::UserRole){
        return false;
    }
    if (role != Qt::EditRole)
        return false;

    DeviceItem *item = items.value(index.row());
    bool result = item->setData(index.column(), value);

    if (result){
        topLeftList.append(index);
        bottomRightList.append(index);
    //    emit dataChanged(index, index);
    }
    return result;
}
QVariant UpdateDevModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
        return QVariant();

//    DeviceItem *item = static_cast<DeviceItem*>(index.internalPointer());

//    if ( role == Qt::CheckStateRole && index.column() == 0 )
//        return static_cast< int >( item->isChecked() ? Qt::Checked : Qt::Unchecked );

    if(role == Qt::UserRole && index.row() < items.size()){
        DeviceItem * item = items[index.row()];
        return createIndex(index.row(), index.column(),item);
    }

    if (role != Qt::DisplayRole && role != Qt::EditRole)
        return QVariant();
    if(index.row() < items.size()){
        DeviceItem * item = items[index.row()];
        return item->data(index.column());
    }

    return QVariant();
}
Пример #7
0
void
MainWindow::write()
{
    if (file.isEmpty())
    {
        QMessageBox msgBox;
        msgBox.setText(tr("Please select an image to use."));
        msgBox.exec();
        return;
    }

    DeviceItem *item = pPlatform->findDeviceInList(deviceComboBox->currentText());

    if (item != NULL)
    {
        if (pPlatform->isMounted(item->getUDI()))
        {
            // We won't let them nuke a mounted device
            QMessageBox msgBox;
            msgBox.setText(tr("This device is already mounted, and I will not write to a mounted device.  Would you like me to attempt to unmount it?"));
#if (QT_VERSION >= 0x040400)
            msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
            msgBox.setDefaultButton(QMessageBox::No);
#else
            msgBox.setButtonText(QMessageBox::Yes, tr("Yes"));
            msgBox.setButtonText(QMessageBox::No, tr("No"));
#endif

            switch (msgBox.exec())
            {
                case QMessageBox::Yes:
                {
                    if (!pPlatform->unmountDevice(item->getUDI()))
                    {
                        QMessageBox failedBox;
                        failedBox.setText(tr("Unmount failed.  I will not write to this device."));
                        failedBox.exec();
                        return;
                    }
                    break;
                }
                case QMessageBox::No:
                    return;
                default:
                    break;
            }
        }

        QMessageBox msgBox;
        QString messageString;
        if (item->isRemovable())
            messageString = tr("This will overwrite the contents of ") + item->getPath() + tr(".  Are you sure you want to continue?");
        else
            messageString = item->getPath() + tr(" is a non-removable hard drive, and this will overwrite the contents.  Are you <b>sure</b> you want to continue?");
        msgBox.setText(messageString);

#if (QT_VERSION >= 0x040400)
        msgBox.setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
        msgBox.setDefaultButton(QMessageBox::Cancel);
#else
        msgBox.setButtonText(QMessageBox::Cancel, tr("Cancel"));
        msgBox.setButtonText(QMessageBox::Ok, tr("Ok"));
#endif


        switch (msgBox.exec())
        {
            case QMessageBox::Ok:
            {
                pPlatform->writeData(item->getPath(), file, item->getSize());
                break;
            }
            default:
                break;
        }
    }
}
DeviceItem *
PlatformUdisks2::buildDevice(QVariantMap &blockProperties, QVariantMap &driveProperties) {
    DeviceItem *devItem = new DeviceItem;

    QString path = blockProperties.value("path").toString();
    devItem->setUDI(path.mid(path.lastIndexOf("/") + 1));
    qDebug() << devItem->getUDI();
    isMounted(devItem->getUDI());
    devItem->setPath(path);
    devItem->setIsRemovable(driveProperties.value("removable").toBool());
    devItem->setSize(blockProperties.value("size").toLongLong());
    devItem->setModelString(driveProperties.value("model").toString());
    QString vendor = driveProperties.value("vendor").toString();

    if (vendor == "")
    {
        if (mKioskMode)
            devItem->setVendorString("SUSE Studio USB Key");
        else
            devItem->setVendorString("Unknown Device");
    }
    else
    {
        devItem->setVendorString(vendor);
    }
    QString newDisplayString = QString("%1 %2 - %3 (%4 MB)")
                                      .arg(devItem->getVendorString())
                                      .arg(devItem->getModelString())
                                      .arg(devItem->getPath())
                                      .arg(devItem->getSize() / 1048576);
    devItem->setDisplayString(newDisplayString);

    if (mKioskMode)
    {
        if((devItem->getSize() / 1048576) > 200000)
        {
            delete devItem;
            return(NULL);
        }
    }

    // If a device is 0 megs we might as well just not list it
    if ((devItem->getSize() / 1048576) > 0)
    {
        itemList << devItem;
    }
    else
    {
        delete devItem;
        devItem = NULL;
    }

    return(devItem);
}
Пример #9
0
DeviceItem *
PlatformUdisks::getNewDevice(QString devicePath)
{
    QString path, model, vendor;

    DeviceItem *devItem = new DeviceItem;
    path = getPath(devicePath);
    if (path == "")
        return(NULL);

    if (!getIsDrive(devicePath))
        return(NULL);

    model = getModel(devicePath);
    vendor = getVendor(devicePath);

    devItem->setUDI(devicePath);
    devItem->setPath(path);
    devItem->setIsRemovable(getIsRemovable(devicePath));
    devItem->setSize(getSize(devicePath));
    devItem->setModelString(model);
    if (vendor == "")
    {
        if (mKioskMode)
            devItem->setVendorString("SUSE Studio USB Key");
        else
            devItem->setVendorString("Unknown Device");
    }
    else
    {
        devItem->setVendorString(vendor);
    }
    QString newDisplayString = QString("%1 %2 - %3 (%4 MB)")
                               .arg(devItem->getVendorString())
                               .arg(devItem->getModelString())
                               .arg(devItem->getPath())
                               .arg(devItem->getSize() / 1048576);
    devItem->setDisplayString(newDisplayString);

    if (mKioskMode)
    {
        if((devItem->getSize() / 1048576) > 200000)
        {
            delete devItem;
            return(NULL);
        }
    }

    // If a device is 0 megs we might as well just not list it
    if ((devItem->getSize() / 1048576) > 0)
    {
        itemList << devItem;
    }
    else
    {
        delete devItem;
        devItem = NULL;
    }

    return(devItem);
}