Exemple #1
0
PartitionNode*
_findRootForPartition( PartitionNode* partition )
{
    if ( partition->isRoot() ||
         !partition->parent() )
        return partition;

    return _findRootForPartition( partition->parent() );
}
Exemple #2
0
QColor
colorForPartition( Partition* partition )
{
    if ( KPMHelpers::isPartitionFreeSpace( partition ) )
        return FREE_SPACE_COLOR;
    if ( partition->roles().has( PartitionRole::Extended ) )
        return EXTENDED_COLOR;
    if ( s_partitionColorsCache.contains( partition->partitionPath() ) )
        return s_partitionColorsCache[ partition->partitionPath() ];

    // No partition-specific color needed, pick one from our list, but skip
    // free space: we don't want a partition to change colors if space before
    // it is inserted or removed
    PartitionNode* parent = _findRootForPartition( partition );
    PartitionTable* table = dynamic_cast< PartitionTable* >( parent );
    Q_ASSERT( table );
    int colorIdx = 0;
    int newColorIdx = 0;
    for ( PartitionIterator it = PartitionIterator::begin( table );
          it != PartitionIterator::end( table );
          ++it )
    {
        Partition* child = *it;
        if ( child == partition )
            break;
        if ( !KPMHelpers::isPartitionFreeSpace( child ) &&
             !child->hasChildren() )
        {
            if ( KPMHelpers::isPartitionNew( child ) )
                ++newColorIdx;
            else
                ++colorIdx;
        }
    }

    if ( KPMHelpers::isPartitionNew( partition ) )
        return NEW_PARTITION_COLORS[ newColorIdx % NUM_NEW_PARTITION_COLORS ];

    s_partitionColorsCache.insert( partition->partitionPath(),
                                   PARTITION_COLORS[ colorIdx % NUM_PARTITION_COLORS ] );
    return PARTITION_COLORS[ colorIdx % NUM_PARTITION_COLORS ];
}
Exemple #3
0
QColor
colorForPartitionInFreeSpace( Partition* partition )
{
    PartitionNode* parent = _findRootForPartition( partition );
    PartitionTable* table = dynamic_cast< PartitionTable* >( parent );
    Q_ASSERT( table );
    int newColorIdx = 0;
    for ( PartitionIterator it = PartitionIterator::begin( table );
          it != PartitionIterator::end( table );
          ++it )
    {
        Partition* child = *it;
        if ( child == partition )
            break;
        if ( !KPMHelpers::isPartitionFreeSpace( child ) &&
             !child->hasChildren() &&
             KPMHelpers::isPartitionNew( child ) )
            ++newColorIdx;
    }
    return NEW_PARTITION_COLORS[ newColorIdx % NUM_NEW_PARTITION_COLORS ];
}
Exemple #4
0
QColor
colorForPartition( Partition* partition )
{
    if ( !partition )
    {
        cWarning() << "NULL partition";
        return FREE_SPACE_COLOR;
    }

    if ( KPMHelpers::isPartitionFreeSpace( partition ) )
        return FREE_SPACE_COLOR;
    if ( partition->roles().has( PartitionRole::Extended ) )
        return EXTENDED_COLOR;

    if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone &&
         !partition->fileSystem().uuid().isEmpty() )
    {
        if ( partition->fileSystem().type() == FileSystem::Luks )
        {
            FS::luks& luksFs = dynamic_cast< FS::luks& >( partition->fileSystem() );
            if ( !luksFs.outerUuid().isEmpty() &&
                 s_partitionColorsCache.contains( luksFs.outerUuid() ) )
                return s_partitionColorsCache[ luksFs.outerUuid() ];
        }

        if ( s_partitionColorsCache.contains( partition->fileSystem().uuid() ) )
            return s_partitionColorsCache[ partition->fileSystem().uuid() ];
    }

    // No partition-specific color needed, pick one from our list, but skip
    // free space: we don't want a partition to change colors if space before
    // it is inserted or removed
    PartitionNode* parent = _findRootForPartition( partition );
    PartitionTable* table = dynamic_cast< PartitionTable* >( parent );
    Q_ASSERT( table );
    int colorIdx = 0;
    int newColorIdx = 0;
    for ( PartitionIterator it = PartitionIterator::begin( table );
          it != PartitionIterator::end( table );
          ++it )
    {
        Partition* child = *it;
        if ( child == partition )
            break;
        if ( !KPMHelpers::isPartitionFreeSpace( child ) &&
             !child->hasChildren() )
        {
            if ( KPMHelpers::isPartitionNew( child ) )
                ++newColorIdx;
            ++colorIdx;
        }
    }

    if ( KPMHelpers::isPartitionNew( partition ) )
        return NEW_PARTITION_COLORS[ newColorIdx % NUM_NEW_PARTITION_COLORS ];

    if ( partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone &&
         !partition->fileSystem().uuid().isEmpty() )
    {
        if ( partition->fileSystem().type() == FileSystem::Luks )
        {
            FS::luks& luksFs = dynamic_cast< FS::luks& >( partition->fileSystem() );
            if ( !luksFs.outerUuid().isEmpty() )
            {
                s_partitionColorsCache.insert( luksFs.outerUuid(),
                                               PARTITION_COLORS[ colorIdx % NUM_PARTITION_COLORS ] );
            }
        }
        else
            s_partitionColorsCache.insert( partition->fileSystem().uuid(),
                                           PARTITION_COLORS[ colorIdx % NUM_PARTITION_COLORS ] );
    }
    return PARTITION_COLORS[ colorIdx % NUM_PARTITION_COLORS ];
}