Changeset View
Changeset View
Standalone View
Standalone View
containments/desktop/plugins/folder/placesmodel.cpp
Show All 13 Lines | |||||
14 | * You should have received a copy of the GNU General Public License * | 14 | * You should have received a copy of the GNU General Public License * | ||
15 | * along with this program; if not, write to the * | 15 | * along with this program; if not, write to the * | ||
16 | * Free Software Foundation, Inc., * | 16 | * Free Software Foundation, Inc., * | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * | ||
18 | ***************************************************************************/ | 18 | ***************************************************************************/ | ||
19 | 19 | | |||
20 | #include "placesmodel.h" | 20 | #include "placesmodel.h" | ||
21 | 21 | | |||
22 | #include <QStandardPaths> | ||||
23 | | ||||
22 | #include <KFilePlacesModel> | 24 | #include <KFilePlacesModel> | ||
23 | #include <KService> | 25 | #include <KService> | ||
24 | #include <KServiceTypeTrader> | 26 | #include <KServiceTypeTrader> | ||
25 | 27 | | |||
26 | PlacesModel::PlacesModel(QObject *parent) : QSortFilterProxyModel(parent) | 28 | PlacesModel::PlacesModel(QObject *parent) : QSortFilterProxyModel(parent) | ||
27 | { | 29 | { | ||
28 | m_sourceModel = new KFilePlacesModel(this); | 30 | m_sourceModel = new KFilePlacesModel(this); | ||
29 | 31 | | |||
Show All 24 Lines | 53 | { | |||
54 | 56 | | |||
55 | if (services.isEmpty()) { | 57 | if (services.isEmpty()) { | ||
56 | return false; | 58 | return false; | ||
57 | } | 59 | } | ||
58 | 60 | | |||
59 | return !services.at(0).data()->noDisplay(); | 61 | return !services.at(0).data()->noDisplay(); | ||
60 | } | 62 | } | ||
61 | 63 | | |||
64 | bool PlacesModel::showDesktopEntry() const | ||||
65 | { | ||||
66 | return m_showDesktopEntry; | ||||
67 | } | ||||
68 | | ||||
69 | void PlacesModel::setShowDesktopEntry(bool showDesktopEntry) | ||||
70 | { | ||||
71 | if (m_showDesktopEntry != showDesktopEntry) { | ||||
72 | m_showDesktopEntry = showDesktopEntry; | ||||
73 | | ||||
74 | invalidateFilter(); | ||||
75 | | ||||
76 | emit showDesktopEntryChanged(); | ||||
77 | } | ||||
78 | } | ||||
79 | | ||||
62 | QString PlacesModel::urlForIndex(int idx) const | 80 | QString PlacesModel::urlForIndex(int idx) const | ||
63 | { | 81 | { | ||
64 | return m_sourceModel->url(mapToSource(index(idx, 0))).toString(); | 82 | return m_sourceModel->url(mapToSource(index(idx, 0))).toString(); | ||
65 | } | 83 | } | ||
66 | 84 | | |||
67 | 85 | | |||
68 | int PlacesModel::indexForUrl(const QString& url) const | 86 | int PlacesModel::indexForUrl(const QString& url) const | ||
69 | { | 87 | { | ||
Show All 13 Lines | |||||
83 | 101 | | |||
84 | return -1; | 102 | return -1; | ||
85 | } | 103 | } | ||
86 | 104 | | |||
87 | bool PlacesModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const | 105 | bool PlacesModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const | ||
88 | { | 106 | { | ||
89 | const QModelIndex index = m_sourceModel->index(sourceRow, 0, sourceParent); | 107 | const QModelIndex index = m_sourceModel->index(sourceRow, 0, sourceParent); | ||
90 | 108 | | |||
109 | if (!m_showDesktopEntry) { | ||||
110 | const QUrl url = index.data(KFilePlacesModel::UrlRole).toUrl(); | ||||
111 | const QUrl desktopUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)); | ||||
112 | if (url == desktopUrl) { | ||||
113 | return false; | ||||
114 | } | ||||
115 | } | ||||
116 | | ||||
91 | return !m_sourceModel->isHidden(index); | 117 | return !m_sourceModel->isHidden(index); | ||
92 | } | 118 | } |