Changeset View
Changeset View
Standalone View
Standalone View
containments/desktop/plugins/folder/foldermodel.cpp
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | |||||
52 | #include <KIO/DeleteJob> | 52 | #include <KIO/DeleteJob> | ||
53 | #include <KIO/EmptyTrashJob> | 53 | #include <KIO/EmptyTrashJob> | ||
54 | #include <KIO/FileUndoManager> | 54 | #include <KIO/FileUndoManager> | ||
55 | #include <KIO/JobUiDelegate> | 55 | #include <KIO/JobUiDelegate> | ||
56 | #include <KIO/Paste> | 56 | #include <KIO/Paste> | ||
57 | #include <KIO/PasteJob> | 57 | #include <KIO/PasteJob> | ||
58 | #include <KIO/RestoreJob> | 58 | #include <KIO/RestoreJob> | ||
59 | #include <KLocalizedString> | 59 | #include <KLocalizedString> | ||
60 | #include <KUrlMimeData> | ||||
60 | #include <KPropertiesDialog> | 61 | #include <KPropertiesDialog> | ||
61 | #include <KSharedConfig> | 62 | #include <KSharedConfig> | ||
62 | #include <KShell> | 63 | #include <KShell> | ||
63 | #include <kio_version.h> | 64 | #include <kio_version.h> | ||
64 | 65 | | |||
65 | #include <KCoreDirLister> | 66 | #include <KCoreDirLister> | ||
66 | #include <KDirLister> | 67 | #include <KDirLister> | ||
67 | #include <KDesktopFile> | 68 | #include <KDesktopFile> | ||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | 115 | { | |||
139 | setFilterCaseSensitivity(Qt::CaseInsensitive); | 140 | setFilterCaseSensitivity(Qt::CaseInsensitive); | ||
140 | setDynamicSortFilter(true); | 141 | setDynamicSortFilter(true); | ||
141 | 142 | | |||
142 | sort(m_sortMode, m_sortDesc ? Qt::DescendingOrder : Qt::AscendingOrder); | 143 | sort(m_sortMode, m_sortDesc ? Qt::DescendingOrder : Qt::AscendingOrder); | ||
143 | 144 | | |||
144 | setSupportedDragActions(Qt::CopyAction | Qt::MoveAction | Qt::LinkAction); | 145 | setSupportedDragActions(Qt::CopyAction | Qt::MoveAction | Qt::LinkAction); | ||
145 | 146 | | |||
146 | createActions(); | 147 | createActions(); | ||
148 | | ||||
149 | connect(QApplication::clipboard(), &QClipboard::dataChanged, | ||||
150 | this, &FolderModel::updateCutUrls); | ||||
151 | updateCutUrls(); | ||||
147 | } | 152 | } | ||
148 | 153 | | |||
149 | FolderModel::~FolderModel() | 154 | FolderModel::~FolderModel() | ||
150 | { | 155 | { | ||
151 | } | 156 | } | ||
152 | 157 | | |||
153 | QHash< int, QByteArray > FolderModel::roleNames() const | 158 | QHash< int, QByteArray > FolderModel::roleNames() const | ||
154 | { | 159 | { | ||
155 | return staticRoleNames(); | 160 | return staticRoleNames(); | ||
156 | } | 161 | } | ||
157 | 162 | | |||
158 | QHash< int, QByteArray > FolderModel::staticRoleNames() | 163 | QHash< int, QByteArray > FolderModel::staticRoleNames() | ||
159 | { | 164 | { | ||
160 | QHash<int, QByteArray> roleNames; | 165 | QHash<int, QByteArray> roleNames; | ||
161 | roleNames[Qt::DisplayRole] = "display"; | 166 | roleNames[Qt::DisplayRole] = "display"; | ||
162 | roleNames[Qt::DecorationRole] = "decoration"; | 167 | roleNames[Qt::DecorationRole] = "decoration"; | ||
163 | roleNames[BlankRole] = "blank"; | 168 | roleNames[BlankRole] = "blank"; | ||
164 | roleNames[OverlaysRole] = "overlays"; | 169 | roleNames[OverlaysRole] = "overlays"; | ||
165 | roleNames[SelectedRole] = "selected"; | 170 | roleNames[SelectedRole] = "selected"; | ||
166 | roleNames[IsDirRole] = "isDir"; | 171 | roleNames[IsDirRole] = "isDir"; | ||
167 | roleNames[IsLinkRole] = "isLink"; | 172 | roleNames[IsLinkRole] = "isLink"; | ||
168 | roleNames[IsHiddenRole] = "isHidden"; | 173 | roleNames[IsHiddenRole] = "isHidden"; | ||
174 | roleNames[IsCutRole] = "isCut"; | ||||
169 | roleNames[UrlRole] = "url"; | 175 | roleNames[UrlRole] = "url"; | ||
170 | roleNames[LinkDestinationUrl] = "linkDestinationUrl"; | 176 | roleNames[LinkDestinationUrl] = "linkDestinationUrl"; | ||
171 | roleNames[SizeRole] = "size"; | 177 | roleNames[SizeRole] = "size"; | ||
172 | roleNames[TypeRole] = "type"; | 178 | roleNames[TypeRole] = "type"; | ||
173 | 179 | | |||
174 | return roleNames; | 180 | return roleNames; | ||
175 | } | 181 | } | ||
176 | 182 | | |||
▲ Show 20 Lines • Show All 878 Lines • ▼ Show 20 Line(s) | 1060 | } else { | |||
1055 | return isDir(mapToSource(index), m_dirModel); | 1061 | return isDir(mapToSource(index), m_dirModel); | ||
1056 | } | 1062 | } | ||
1057 | } else if (role == IsLinkRole) { | 1063 | } else if (role == IsLinkRole) { | ||
1058 | const KFileItem item = itemForIndex(index); | 1064 | const KFileItem item = itemForIndex(index); | ||
1059 | return item.isLink(); | 1065 | return item.isLink(); | ||
1060 | } else if (role == IsHiddenRole) { | 1066 | } else if (role == IsHiddenRole) { | ||
1061 | const KFileItem item = itemForIndex(index); | 1067 | const KFileItem item = itemForIndex(index); | ||
1062 | return item.isHidden(); | 1068 | return item.isHidden(); | ||
1069 | } else if (role == IsCutRole) { | ||||
1070 | const QUrl &url = data(index, UrlRole).value<QUrl>(); | ||||
1071 | return m_cutUrls.contains(url); | ||||
1063 | } else if (role == UrlRole) { | 1072 | } else if (role == UrlRole) { | ||
1064 | return itemForIndex(index).url(); | 1073 | return itemForIndex(index).url(); | ||
1065 | } else if (role == LinkDestinationUrl) { | 1074 | } else if (role == LinkDestinationUrl) { | ||
1066 | const KFileItem item = itemForIndex(index); | 1075 | const KFileItem item = itemForIndex(index); | ||
1067 | 1076 | | |||
1068 | if (m_parseDesktopFiles && item.isDesktopFile()) { | 1077 | if (m_parseDesktopFiles && item.isDesktopFile()) { | ||
1069 | const KDesktopFile file(item.targetUrl().path()); | 1078 | const KDesktopFile file(item.targetUrl().path()); | ||
1070 | 1079 | | |||
▲ Show 20 Lines • Show All 604 Lines • ▼ Show 20 Line(s) | |||||
1675 | } | 1684 | } | ||
1676 | 1685 | | |||
1677 | void FolderModel::undoTextChanged(const QString &text) | 1686 | void FolderModel::undoTextChanged(const QString &text) | ||
1678 | { | 1687 | { | ||
1679 | if (QAction *action = m_actionCollection.action(QStringLiteral("undo"))) { | 1688 | if (QAction *action = m_actionCollection.action(QStringLiteral("undo"))) { | ||
1680 | action->setText(text); | 1689 | action->setText(text); | ||
1681 | } | 1690 | } | ||
1682 | } | 1691 | } | ||
1692 | | ||||
1693 | void FolderModel::updateCutUrls() | ||||
1694 | { | ||||
1695 | QSet<QUrl> newCutUrls; | ||||
1696 | | ||||
1697 | const QMimeData *mimeData = QApplication::clipboard()->mimeData(); | ||||
1698 | | ||||
1699 | if (mimeData) { | ||||
1700 | const QByteArray data = mimeData->data(QStringLiteral("application/x-kde-cutselection")); | ||||
1701 | const bool isCutSelection = (!data.isEmpty() && data.at(0) == QLatin1Char('1')); | ||||
1702 | if (isCutSelection) { | ||||
1703 | newCutUrls = KUrlMimeData::urlsFromMimeData(mimeData).toSet(); | ||||
1704 | } | ||||
1705 | } | ||||
1706 | | ||||
1707 | // Now store both the old and newly cut items, so we can emit a change for both sets. | ||||
1708 | const QSet<QUrl> combinedCutUrls = m_cutUrls + newCutUrls; | ||||
1709 | | ||||
1710 | m_cutUrls = newCutUrls; | ||||
1711 | | ||||
1712 | for (const QUrl &url : combinedCutUrls) { | ||||
1713 | const QModelIndex &idx = index(indexForUrl(url), 0); | ||||
1714 | if (idx.isValid()) { | ||||
broulik: I think this check down here is wrong/not working properly | |||||
hein: Can you elaborate? | |||||
1715 | emit dataChanged(idx, idx, {IsCutRole}); | ||||
1716 | } | ||||
1717 | } | ||||
1718 | } |
I think this check down here is wrong/not working properly