Changeset View
Changeset View
Standalone View
Standalone View
src/panels/places/placesitem.cpp
Show All 15 Lines | |||||
16 | * * | 16 | * * | ||
17 | * You should have received a copy of the GNU General Public License * | 17 | * You should have received a copy of the GNU General Public License * | ||
18 | * along with this program; if not, write to the * | 18 | * along with this program; if not, write to the * | ||
19 | * Free Software Foundation, Inc., * | 19 | * Free Software Foundation, Inc., * | ||
20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * | 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * | ||
21 | ***************************************************************************/ | 21 | ***************************************************************************/ | ||
22 | 22 | | |||
23 | #include "placesitem.h" | 23 | #include "placesitem.h" | ||
24 | #include "placesitemsignalhandler.h" | ||||
elvisangelaccio: Not needed, please remove. | |||||
25 | #include "trash/dolphintrash.h" | ||||
24 | 26 | | |||
25 | #include "dolphindebug.h" | 27 | #include "dolphindebug.h" | ||
26 | #include "placesitemsignalhandler.h" | 28 | #include "placesitemsignalhandler.h" | ||
27 | 29 | | |||
28 | #include <KDirLister> | 30 | #include <KDirLister> | ||
29 | #include <KLocalizedString> | 31 | #include <KLocalizedString> | ||
30 | #include <Solid/Block> | 32 | #include <Solid/Block> | ||
31 | 33 | | |||
Show All 23 Lines | 56 | { | |||
55 | // The default check in KStandardItem::setDataValue() | 57 | // The default check in KStandardItem::setDataValue() | ||
56 | // for equal values does not work with a custom value | 58 | // for equal values does not work with a custom value | ||
57 | // like QUrl. Hence do a manual check to prevent that | 59 | // like QUrl. Hence do a manual check to prevent that | ||
58 | // setting an equal URL results in an itemsChanged() | 60 | // setting an equal URL results in an itemsChanged() | ||
59 | // signal. | 61 | // signal. | ||
60 | if (dataValue("url").toUrl() != url) { | 62 | if (dataValue("url").toUrl() != url) { | ||
61 | delete m_trashDirLister; | 63 | delete m_trashDirLister; | ||
62 | if (url.scheme() == QLatin1String("trash")) { | 64 | if (url.scheme() == QLatin1String("trash")) { | ||
63 | // The trash icon must always be updated dependent on whether | 65 | QObject::connect(&Trash::instance(), &Trash::emptinessChanged, [this](bool isTrashEmpty){ | ||
64 | // the trash is empty or not. We use a KDirLister that automatically | 66 | setIcon(isTrashEmpty ? QStringLiteral("user-trash") : QStringLiteral("user-trash-full")); | ||
65 | // watches for changes if the number of items has been changed. | 67 | }); | ||
66 | // The update of the icon is handled in onTrashDirListerCompleted(). | | |||
67 | m_trashDirLister = new KDirLister(); | | |||
68 | m_trashDirLister->setAutoErrorHandlingEnabled(false, nullptr); | | |||
69 | m_trashDirLister->setDelayedMimeTypes(true); | | |||
70 | QObject::connect(m_trashDirLister.data(), static_cast<void(KDirLister::*)()>(&KDirLister::completed), | | |||
71 | m_signalHandler.data(), &PlacesItemSignalHandler::onTrashDirListerCompleted); | | |||
72 | m_trashDirLister->openUrl(url); | | |||
73 | } | 68 | } | ||
74 | 69 | | |||
75 | setDataValue("url", url); | 70 | setDataValue("url", url); | ||
76 | } | 71 | } | ||
77 | } | 72 | } | ||
78 | 73 | | |||
79 | QUrl PlacesItem::url() const | 74 | QUrl PlacesItem::url() const | ||
80 | { | 75 | { | ||
▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Line(s) | |||||
234 | } | 229 | } | ||
235 | 230 | | |||
236 | void PlacesItem::onAccessibilityChanged() | 231 | void PlacesItem::onAccessibilityChanged() | ||
237 | { | 232 | { | ||
238 | setIconOverlays(m_device.emblems()); | 233 | setIconOverlays(m_device.emblems()); | ||
239 | setUrl(QUrl::fromLocalFile(m_access->filePath())); | 234 | setUrl(QUrl::fromLocalFile(m_access->filePath())); | ||
240 | } | 235 | } | ||
241 | 236 | | |||
242 | void PlacesItem::onTrashDirListerCompleted() | | |||
243 | { | | |||
244 | Q_ASSERT(url().scheme() == QLatin1String("trash")); | | |||
245 | | ||||
246 | const bool isTrashEmpty = m_trashDirLister->items().isEmpty(); | | |||
247 | setIcon(isTrashEmpty ? QStringLiteral("user-trash") : QStringLiteral("user-trash-full")); | | |||
248 | } | | |||
249 | | ||||
250 | void PlacesItem::updateBookmarkForRole(const QByteArray& role) | 237 | void PlacesItem::updateBookmarkForRole(const QByteArray& role) | ||
251 | { | 238 | { | ||
252 | Q_ASSERT(!m_bookmark.isNull()); | 239 | Q_ASSERT(!m_bookmark.isNull()); | ||
253 | if (role == "iconName") { | 240 | if (role == "iconName") { | ||
254 | m_bookmark.setIcon(icon()); | 241 | m_bookmark.setIcon(icon()); | ||
255 | } else if (role == "text") { | 242 | } else if (role == "text") { | ||
256 | // Only store the text in the KBookmark if it is not the translation of | 243 | // Only store the text in the KBookmark if it is not the translation of | ||
257 | // the current text. This makes sure that the text is re-translated if | 244 | // the current text. This makes sure that the text is re-translated if | ||
Show All 33 Lines |
Not needed, please remove.