filebrowser/ui/src/fbdrivemodel.cpp
author hgs
Tue, 27 Jul 2010 14:45:43 +0300
changeset 39 a5449825eaf3
parent 31 e7a04a6385be
child 48 da3ec8478e66
permissions -rw-r--r--
201029_1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include "fbdrivemodel.h"
hgs
parents:
diff changeset
    19
#include "enginewrapper.h"
hgs
parents:
diff changeset
    20
#include "driveentry.h"
hgs
parents:
diff changeset
    21
#include "settingsview.h"
hgs
parents:
diff changeset
    22
#include "filebrowsersettings.h"
hgs
parents:
diff changeset
    23
#include "FB.hrh"
hgs
parents:
diff changeset
    24
hgs
parents:
diff changeset
    25
#include <QModelIndex>
hgs
parents:
diff changeset
    26
#include <QFileIconProvider>
hgs
parents:
diff changeset
    27
hgs
parents:
diff changeset
    28
/**
hgs
parents:
diff changeset
    29
  Constructs a file browser custom system model with the given \a engineWrapper and \a parent.
hgs
parents:
diff changeset
    30
  */
hgs
parents:
diff changeset
    31
FbDriveModel::FbDriveModel(EngineWrapper *engineWrapper, QObject *parent) :
hgs
parents:
diff changeset
    32
    QAbstractListModel(parent),
hgs
parents:
diff changeset
    33
    mEngineWrapper(engineWrapper),
hgs
parents:
diff changeset
    34
    mFileIconProvider(0)
hgs
parents:
diff changeset
    35
{
hgs
parents:
diff changeset
    36
    mFileIconProvider = new QFileIconProvider();
hgs
parents:
diff changeset
    37
}
hgs
parents:
diff changeset
    38
hgs
parents:
diff changeset
    39
/**
hgs
parents:
diff changeset
    40
  Destroys this file browser custom system model.
hgs
parents:
diff changeset
    41
  */
hgs
parents:
diff changeset
    42
FbDriveModel::~FbDriveModel()
hgs
parents:
diff changeset
    43
{  
hgs
parents:
diff changeset
    44
    if (mFileIconProvider) {
hgs
parents:
diff changeset
    45
        delete mFileIconProvider;
hgs
parents:
diff changeset
    46
    }
hgs
parents:
diff changeset
    47
}
hgs
parents:
diff changeset
    48
hgs
parents:
diff changeset
    49
/**
hgs
parents:
diff changeset
    50
  \reimp
hgs
parents:
diff changeset
    51
  */
hgs
parents:
diff changeset
    52
int FbDriveModel::rowCount(const QModelIndex &parent) const
hgs
parents:
diff changeset
    53
{
hgs
parents:
diff changeset
    54
    Q_UNUSED(parent);
hgs
parents:
diff changeset
    55
    return mEngineWrapper->itemCount();
hgs
parents:
diff changeset
    56
}
hgs
parents:
diff changeset
    57
hgs
parents:
diff changeset
    58
/**
hgs
parents:
diff changeset
    59
  \reimp
hgs
parents:
diff changeset
    60
  */
hgs
parents:
diff changeset
    61
QVariant FbDriveModel::data(const QModelIndex &index, int role) const
hgs
parents:
diff changeset
    62
{
hgs
parents:
diff changeset
    63
    if (!index.isValid() || index.model() != this)
hgs
parents:
diff changeset
    64
        return QVariant();
hgs
parents:
diff changeset
    65
hgs
parents:
diff changeset
    66
    switch (role) {
hgs
parents:
diff changeset
    67
    case Qt::EditRole:
hgs
parents:
diff changeset
    68
    case Qt::DisplayRole: {
hgs
parents:
diff changeset
    69
            QStringList listItem;
hgs
parents:
diff changeset
    70
            DriveEntry driveEntry(mEngineWrapper->getDriveEntry(index));
hgs
parents:
diff changeset
    71
            if (mEngineWrapper->settings().fileViewMode() == EFileViewModeSimple)
hgs
parents:
diff changeset
    72
            {
hgs
parents:
diff changeset
    73
                const QString SimpleDriveEntry("%1: <%2>");
hgs
parents:
diff changeset
    74
                listItem /*<< driveEntry.IconId() */
hgs
parents:
diff changeset
    75
                        << SimpleDriveEntry.arg(driveEntry.driveLetter())
hgs
parents:
diff changeset
    76
                                           .arg(driveEntry.mediaTypeString());
hgs
parents:
diff changeset
    77
            } else if (mEngineWrapper->settings().fileViewMode() == EFileViewModeExtended) {
hgs
parents:
diff changeset
    78
                const QString SimpleDriveEntry("%1: <%2>");
hgs
parents:
diff changeset
    79
                const QString ExtendedDriveEntry("%1/%2 kB");
hgs
parents:
diff changeset
    80
                listItem /*<< driveEntry.IconId()*/
hgs
parents:
diff changeset
    81
                        << SimpleDriveEntry.arg(driveEntry.driveLetter())
hgs
parents:
diff changeset
    82
                                           .arg(driveEntry.mediaTypeString())
hgs
parents:
diff changeset
    83
                        << ExtendedDriveEntry.arg(QString::number(driveEntry.volumeInfoFree()/1024))
hgs
parents:
diff changeset
    84
                                             .arg(QString::number(driveEntry.volumeInfoSize()/1024));
hgs
parents:
diff changeset
    85
hgs
parents:
diff changeset
    86
            }
hgs
parents:
diff changeset
    87
            return listItem;
hgs
parents:
diff changeset
    88
        }
hgs
parents:
diff changeset
    89
    case Qt::DecorationRole: {
hgs
parents:
diff changeset
    90
            if (mEngineWrapper) {
hgs
parents:
diff changeset
    91
                QIcon icon;
hgs
parents:
diff changeset
    92
                //TODO Drive ico has to be provided, for some reason it is not visible
hgs
parents:
diff changeset
    93
                icon = mFileIconProvider->icon(QFileIconProvider::Drive);
hgs
parents:
diff changeset
    94
                return QVariant(icon);
hgs
parents:
diff changeset
    95
            }
hgs
parents:
diff changeset
    96
        }
hgs
parents:
diff changeset
    97
    }
hgs
parents:
diff changeset
    98
    return QVariant();
hgs
parents:
diff changeset
    99
}
hgs
parents:
diff changeset
   100
hgs
parents:
diff changeset
   101
/**
hgs
parents:
diff changeset
   102
  \reimp
hgs
parents:
diff changeset
   103
  */
hgs
parents:
diff changeset
   104
QVariant FbDriveModel::headerData(int section, Qt::Orientation orientation, int role) const
hgs
parents:
diff changeset
   105
{
hgs
parents:
diff changeset
   106
    Q_UNUSED(section);
hgs
parents:
diff changeset
   107
    Q_UNUSED(orientation);
hgs
parents:
diff changeset
   108
    Q_UNUSED(role);
hgs
parents:
diff changeset
   109
hgs
parents:
diff changeset
   110
    // TODO, implement or remove
hgs
parents:
diff changeset
   111
    return QVariant();
hgs
parents:
diff changeset
   112
}
hgs
parents:
diff changeset
   113
hgs
parents:
diff changeset
   114
hgs
parents:
diff changeset
   115
DriveEntry FbDriveModel::driveEntry(const QModelIndex &index) const
hgs
parents:
diff changeset
   116
{
hgs
parents:
diff changeset
   117
    return mEngineWrapper->getDriveEntry(index);
hgs
parents:
diff changeset
   118
}
hgs
parents:
diff changeset
   119
hgs
parents:
diff changeset
   120
QString FbDriveModel::driveLetter(const QModelIndex &index) const
hgs
parents:
diff changeset
   121
{
hgs
parents:
diff changeset
   122
    QString diskLetter;
hgs
parents:
diff changeset
   123
    if (index.row() >= 0 && index.row() < mEngineWrapper->itemCount()) {
hgs
parents:
diff changeset
   124
        DriveEntry driveEntry(mEngineWrapper->getDriveEntry(index));
hgs
parents:
diff changeset
   125
        diskLetter = driveEntry.driveLetter();
hgs
parents:
diff changeset
   126
    }
hgs
parents:
diff changeset
   127
    return diskLetter;
hgs
parents:
diff changeset
   128
}
hgs
parents:
diff changeset
   129
hgs
parents:
diff changeset
   130
QString FbDriveModel::mediaTypeString(const QModelIndex &index) const
hgs
parents:
diff changeset
   131
{
hgs
parents:
diff changeset
   132
    QString mediaTypeString;
hgs
parents:
diff changeset
   133
    if (index.row() >= 0 && index.row() < mEngineWrapper->itemCount()) {
hgs
parents:
diff changeset
   134
        DriveEntry driveEntry(mEngineWrapper->getDriveEntry(index));
hgs
parents:
diff changeset
   135
        mediaTypeString = driveEntry.mediaTypeString();
hgs
parents:
diff changeset
   136
    }
hgs
parents:
diff changeset
   137
    return mediaTypeString;
hgs
parents:
diff changeset
   138
}
hgs
parents:
diff changeset
   139
hgs
parents:
diff changeset
   140
// ---------------------------------------------------------------------------