1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * The source file for tone list model |
|
16 */ |
|
17 #include "tonefetchermodel.h" |
|
18 #include <QFileInfo> |
|
19 #include <QtAlgorithms> |
|
20 |
|
21 ToneFetcherModel::ToneFetcherModel(QObject *parent) |
|
22 : QStringListModel(parent) |
|
23 { |
|
24 } |
|
25 |
|
26 ToneFetcherModel::~ToneFetcherModel() |
|
27 { |
|
28 } |
|
29 |
|
30 QVariant ToneFetcherModel::data(const QModelIndex &index, int role) const |
|
31 { |
|
32 if (role == Qt::DisplayRole) { |
|
33 return QFileInfo(QStringListModel::data(index, role).toString()).baseName(); |
|
34 } else { |
|
35 return QStringListModel::data(index, role); |
|
36 } |
|
37 } |
|
38 |
|
39 QString ToneFetcherModel::getPath(const QModelIndex &index) const |
|
40 { |
|
41 return QStringListModel::data(index, Qt::DisplayRole).toString(); |
|
42 } |
|
43 |
|
44 void ToneFetcherModel::sort() |
|
45 { |
|
46 QStringList list = stringList(); |
|
47 qStableSort(list.begin(), list.end(), caseSensitiveLessThan); |
|
48 removeRows(0, rowCount()); |
|
49 setStringList(list); |
|
50 } |
|
51 void ToneFetcherModel::layoutToBeChanged() |
|
52 { |
|
53 emit layoutAboutToBeChanged(); |
|
54 } |
|
55 |
|
56 void ToneFetcherModel::layoutHasChanged() |
|
57 { |
|
58 emit layoutChanged(); |
|
59 } |
|
60 |
|
61 bool ToneFetcherModel::caseSensitiveLessThan(const QString &s1, const QString &s2) |
|
62 { |
|
63 return QFileInfo(s1).baseName().toLower() < QFileInfo(s2).baseName().toLower(); |
|
64 } |
|
65 //End of File |
|