Changeset View
Changeset View
Standalone View
Standalone View
src/kitemviews/kfileitemmodelrolesupdater.cpp
Show All 38 Lines | |||||
39 | #include <Baloo/FileMonitor> | 39 | #include <Baloo/FileMonitor> | ||
40 | #endif | 40 | #endif | ||
41 | 41 | | |||
42 | #include <QApplication> | 42 | #include <QApplication> | ||
43 | #include <QPainter> | 43 | #include <QPainter> | ||
44 | #include <QElapsedTimer> | 44 | #include <QElapsedTimer> | ||
45 | #include <QTimer> | 45 | #include <QTimer> | ||
46 | 46 | | |||
47 | | ||||
48 | // #define KFILEITEMMODELROLESUPDATER_DEBUG | 47 | // #define KFILEITEMMODELROLESUPDATER_DEBUG | ||
49 | 48 | | |||
50 | namespace { | 49 | namespace { | ||
51 | // Maximum time in ms that the KFileItemModelRolesUpdater | 50 | // Maximum time in ms that the KFileItemModelRolesUpdater | ||
52 | // may perform a blocking operation | 51 | // may perform a blocking operation | ||
53 | const int MaxBlockTimeout = 200; | 52 | const int MaxBlockTimeout = 200; | ||
54 | 53 | | |||
55 | // If the number of items is smaller than ResolveAllItemsLimit, | 54 | // If the number of items is smaller than ResolveAllItemsLimit, | ||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 92 | { | |||
103 | connect(m_model, &KFileItemModel::itemsChanged, | 102 | connect(m_model, &KFileItemModel::itemsChanged, | ||
104 | this, &KFileItemModelRolesUpdater::slotItemsChanged); | 103 | this, &KFileItemModelRolesUpdater::slotItemsChanged); | ||
105 | connect(m_model, &KFileItemModel::itemsMoved, | 104 | connect(m_model, &KFileItemModel::itemsMoved, | ||
106 | this, &KFileItemModelRolesUpdater::slotItemsMoved); | 105 | this, &KFileItemModelRolesUpdater::slotItemsMoved); | ||
107 | connect(m_model, &KFileItemModel::sortRoleChanged, | 106 | connect(m_model, &KFileItemModel::sortRoleChanged, | ||
108 | this, &KFileItemModelRolesUpdater::slotSortRoleChanged); | 107 | this, &KFileItemModelRolesUpdater::slotSortRoleChanged); | ||
109 | 108 | | |||
110 | // Use a timer to prevent that each call of slotItemsChanged() results in a synchronous | 109 | // Use a timer to prevent that each call of slotItemsChanged() results in a synchronous | ||
111 | // resolving of the roles. Postpone the resolving until no update has been done for 1 second. | 110 | // resolving of the roles. Postpone the resolving until no update has been done for 100 ms. | ||
112 | m_recentlyChangedItemsTimer = new QTimer(this); | 111 | m_recentlyChangedItemsTimer = new QTimer(this); | ||
113 | m_recentlyChangedItemsTimer->setInterval(1000); | 112 | m_recentlyChangedItemsTimer->setInterval(100); | ||
114 | m_recentlyChangedItemsTimer->setSingleShot(true); | 113 | m_recentlyChangedItemsTimer->setSingleShot(true); | ||
115 | connect(m_recentlyChangedItemsTimer, &QTimer::timeout, this, &KFileItemModelRolesUpdater::resolveRecentlyChangedItems); | 114 | connect(m_recentlyChangedItemsTimer, &QTimer::timeout, this, &KFileItemModelRolesUpdater::resolveRecentlyChangedItems); | ||
116 | 115 | | |||
117 | m_resolvableRoles.insert("size"); | 116 | m_resolvableRoles.insert("size"); | ||
118 | m_resolvableRoles.insert("type"); | 117 | m_resolvableRoles.insert("type"); | ||
119 | m_resolvableRoles.insert("isExpandable"); | 118 | m_resolvableRoles.insert("isExpandable"); | ||
120 | #ifdef HAVE_BALOO | 119 | #ifdef HAVE_BALOO | ||
121 | m_resolvableRoles += KBalooRolesProvider::instance().roles(); | 120 | m_resolvableRoles += KBalooRolesProvider::instance().roles(); | ||
▲ Show 20 Lines • Show All 623 Lines • ▼ Show 20 Line(s) | 743 | connect(m_model, &KFileItemModel::itemsChanged, | |||
745 | this, &KFileItemModelRolesUpdater::slotItemsChanged); | 744 | this, &KFileItemModelRolesUpdater::slotItemsChanged); | ||
746 | #else | 745 | #else | ||
747 | #ifndef Q_CC_MSVC | 746 | #ifndef Q_CC_MSVC | ||
748 | Q_UNUSED(item) | 747 | Q_UNUSED(item) | ||
749 | #endif | 748 | #endif | ||
750 | #endif | 749 | #endif | ||
751 | } | 750 | } | ||
752 | 751 | | |||
753 | void KFileItemModelRolesUpdater::slotDirectoryContentsCountReceived(const QString& path, int count) | 752 | void KFileItemModelRolesUpdater::slotDirectoryContentsCountReceived(const QString& path, int count, long size) | ||
754 | { | 753 | { | ||
755 | const bool getSizeRole = m_roles.contains("size"); | 754 | const bool getSizeRole = m_roles.contains("size"); | ||
756 | const bool getIsExpandableRole = m_roles.contains("isExpandable"); | 755 | const bool getIsExpandableRole = m_roles.contains("isExpandable"); | ||
757 | 756 | | |||
758 | if (getSizeRole || getIsExpandableRole) { | 757 | if (getSizeRole || getIsExpandableRole) { | ||
759 | const int index = m_model->index(QUrl::fromLocalFile(path)); | 758 | const int index = m_model->index(QUrl::fromLocalFile(path)); | ||
760 | if (index >= 0) { | 759 | if (index >= 0) { | ||
761 | QHash<QByteArray, QVariant> data; | 760 | QHash<QByteArray, QVariant> data; | ||
762 | 761 | | |||
763 | if (getSizeRole) { | 762 | if (getSizeRole) { | ||
764 | data.insert("size", count); | 763 | data.insert("count", count); | ||
764 | if (size != -1) { | ||||
765 | data.insert("size", QVariant::fromValue(size)); | ||||
766 | } | ||||
765 | } | 767 | } | ||
766 | if (getIsExpandableRole) { | 768 | if (getIsExpandableRole) { | ||
767 | data.insert("isExpandable", count > 0); | 769 | data.insert("isExpandable", count > 0); | ||
768 | } | 770 | } | ||
769 | 771 | | |||
770 | disconnect(m_model, &KFileItemModel::itemsChanged, | | |||
771 | this, &KFileItemModelRolesUpdater::slotItemsChanged); | | |||
772 | m_model->setData(index, data); | 772 | m_model->setData(index, data); | ||
773 | connect(m_model, &KFileItemModel::itemsChanged, | | |||
774 | this, &KFileItemModelRolesUpdater::slotItemsChanged); | | |||
elvisangelaccio: Why remove these? | |||||
To allow the slotItemsChanged to be called when new data about fileSize arrives. meven: To allow the slotItemsChanged to be called when new data about fileSize arrives.
It is needed… | |||||
I see. Please do mention this "progressive ordering" in the commit message. elvisangelaccio: I see. Please do mention this "progressive ordering" in the commit message. | |||||
775 | } | 773 | } | ||
776 | } | 774 | } | ||
777 | } | 775 | } | ||
778 | 776 | | |||
779 | void KFileItemModelRolesUpdater::startUpdating() | 777 | void KFileItemModelRolesUpdater::startUpdating() | ||
780 | { | 778 | { | ||
781 | if (m_state == Paused) { | 779 | if (m_state == Paused) { | ||
782 | return; | 780 | return; | ||
▲ Show 20 Lines • Show All 209 Lines • ▼ Show 20 Line(s) | 986 | { | |||
992 | if (m_model->sortRole() == "type") { | 990 | if (m_model->sortRole() == "type") { | ||
993 | if (!item.isMimeTypeKnown()) { | 991 | if (!item.isMimeTypeKnown()) { | ||
994 | item.determineMimeType(); | 992 | item.determineMimeType(); | ||
995 | } | 993 | } | ||
996 | 994 | | |||
997 | data.insert("type", item.mimeComment()); | 995 | data.insert("type", item.mimeComment()); | ||
998 | } else if (m_model->sortRole() == "size" && item.isLocalFile() && item.isDir()) { | 996 | } else if (m_model->sortRole() == "size" && item.isLocalFile() && item.isDir()) { | ||
999 | const QString path = item.localPath(); | 997 | const QString path = item.localPath(); | ||
1000 | data.insert("size", m_directoryContentsCounter->countDirectoryContentsSynchronously(path)); | 998 | m_directoryContentsCounter->scanDirectory(path); | ||
1001 | } else { | 999 | } else { | ||
1002 | // Probably the sort role is a baloo role - just determine all roles. | 1000 | // Probably the sort role is a baloo role - just determine all roles. | ||
1003 | data = rolesData(item); | 1001 | data = rolesData(item); | ||
1004 | } | 1002 | } | ||
1005 | 1003 | | |||
1006 | disconnect(m_model, &KFileItemModel::itemsChanged, | 1004 | disconnect(m_model, &KFileItemModel::itemsChanged, | ||
1007 | this, &KFileItemModelRolesUpdater::slotItemsChanged); | 1005 | this, &KFileItemModelRolesUpdater::slotItemsChanged); | ||
1008 | m_model->setData(index, data); | 1006 | m_model->setData(index, data); | ||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | 1060 | { | |||
1065 | const bool getSizeRole = m_roles.contains("size"); | 1063 | const bool getSizeRole = m_roles.contains("size"); | ||
1066 | const bool getIsExpandableRole = m_roles.contains("isExpandable"); | 1064 | const bool getIsExpandableRole = m_roles.contains("isExpandable"); | ||
1067 | 1065 | | |||
1068 | if ((getSizeRole || getIsExpandableRole) && item.isDir()) { | 1066 | if ((getSizeRole || getIsExpandableRole) && item.isDir()) { | ||
1069 | if (item.isLocalFile()) { | 1067 | if (item.isLocalFile()) { | ||
1070 | // Tell m_directoryContentsCounter that we want to count the items | 1068 | // Tell m_directoryContentsCounter that we want to count the items | ||
1071 | // inside the directory. The result will be received in slotDirectoryContentsCountReceived. | 1069 | // inside the directory. The result will be received in slotDirectoryContentsCountReceived. | ||
1072 | const QString path = item.localPath(); | 1070 | const QString path = item.localPath(); | ||
1073 | m_directoryContentsCounter->addDirectory(path); | 1071 | m_directoryContentsCounter->scanDirectory(path); | ||
1074 | } else if (getSizeRole) { | 1072 | } else if (getSizeRole) { | ||
1075 | data.insert("size", -1); // -1 indicates an unknown number of items | 1073 | data.insert("size", -1); // -1 indicates an unknown number of items | ||
1076 | } | 1074 | } | ||
1077 | } | 1075 | } | ||
1078 | 1076 | | |||
1079 | if (m_roles.contains("type")) { | 1077 | if (m_roles.contains("type")) { | ||
1080 | data.insert("type", item.mimeComment()); | 1078 | data.insert("type", item.mimeComment()); | ||
1081 | } | 1079 | } | ||
▲ Show 20 Lines • Show All 114 Lines • Show Last 20 Lines |
Why remove these?