Changeset View
Changeset View
Standalone View
Standalone View
src/panels/places/placesitem.cpp
Show All 14 Lines | |||||
15 | * GNU General Public License for more details. * | 15 | * GNU General Public License for more details. * | ||
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 "dolphindebug.h" | ||||
23 | #include "placesitem.h" | 24 | #include "placesitem.h" | ||
25 | #include "placesitemsignalhandler.h" | ||||
26 | #include "trash/dolphintrash.h" | ||||
24 | 27 | | |||
25 | #include "dolphindebug.h" | 28 | #include <KBookmarkManager> | ||
26 | #include <KDirLister> | 29 | #include <KDirLister> | ||
27 | #include <KLocalizedString> | 30 | #include <KLocalizedString> | ||
28 | #include "placesitemsignalhandler.h" | 31 | #include <QDateTime> | ||
markg: This is unrelated. I get that you don't like them not being order, but lets keep it focused on… | |||||
29 | #include <Solid/Block> | 32 | #include <Solid/Block> | ||
30 | 33 | | |||
31 | PlacesItem::PlacesItem(const KBookmark& bookmark, PlacesItem* parent) : | 34 | PlacesItem::PlacesItem(const KBookmark& bookmark, PlacesItem* parent) : | ||
32 | KStandardItem(parent), | 35 | KStandardItem(parent), | ||
33 | m_device(), | 36 | m_device(), | ||
34 | m_access(), | 37 | m_access(), | ||
35 | m_volume(), | 38 | m_volume(), | ||
36 | m_disc(), | 39 | m_disc(), | ||
Show All 17 Lines | 56 | { | |||
54 | // The default check in KStandardItem::setDataValue() | 57 | // The default check in KStandardItem::setDataValue() | ||
55 | // for equal values does not work with a custom value | 58 | // for equal values does not work with a custom value | ||
56 | // like QUrl. Hence do a manual check to prevent that | 59 | // like QUrl. Hence do a manual check to prevent that | ||
57 | // setting an equal URL results in an itemsChanged() | 60 | // setting an equal URL results in an itemsChanged() | ||
58 | // signal. | 61 | // signal. | ||
59 | if (dataValue("url").toUrl() != url) { | 62 | if (dataValue("url").toUrl() != url) { | ||
60 | delete m_trashDirLister; | 63 | delete m_trashDirLister; | ||
61 | if (url.scheme() == QLatin1String("trash")) { | 64 | if (url.scheme() == QLatin1String("trash")) { | ||
62 | // The trash icon must always be updated dependent on whether | 65 | QObject::connect(&Trash::instance(), &Trash::emptinessChanged, [this](bool isTrashEmpty){ | ||
63 | // the trash is empty or not. We use a KDirLister that automatically | 66 | setIcon(isTrashEmpty ? QStringLiteral("user-trash") : QStringLiteral("user-trash-full")); | ||
64 | // watches for changes if the number of items has been changed. | 67 | }); | ||
65 | // The update of the icon is handled in onTrashDirListerCompleted(). | | |||
66 | m_trashDirLister = new KDirLister(); | | |||
67 | m_trashDirLister->setAutoErrorHandlingEnabled(false, nullptr); | | |||
68 | m_trashDirLister->setDelayedMimeTypes(true); | | |||
69 | QObject::connect(m_trashDirLister.data(), static_cast<void(KDirLister::*)()>(&KDirLister::completed), | | |||
70 | m_signalHandler.data(), &PlacesItemSignalHandler::onTrashDirListerCompleted); | | |||
71 | m_trashDirLister->openUrl(url); | | |||
72 | } | 68 | } | ||
73 | 69 | | |||
74 | setDataValue("url", url); | 70 | setDataValue("url", url); | ||
75 | } | 71 | } | ||
76 | } | 72 | } | ||
77 | 73 | | |||
78 | QUrl PlacesItem::url() const | 74 | QUrl PlacesItem::url() const | ||
79 | { | 75 | { | ||
▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Line(s) | |||||
233 | } | 229 | } | ||
234 | 230 | | |||
235 | void PlacesItem::onAccessibilityChanged() | 231 | void PlacesItem::onAccessibilityChanged() | ||
236 | { | 232 | { | ||
237 | setIconOverlays(m_device.emblems()); | 233 | setIconOverlays(m_device.emblems()); | ||
238 | setUrl(QUrl::fromLocalFile(m_access->filePath())); | 234 | setUrl(QUrl::fromLocalFile(m_access->filePath())); | ||
239 | } | 235 | } | ||
240 | 236 | | |||
241 | void PlacesItem::onTrashDirListerCompleted() | | |||
242 | { | | |||
243 | Q_ASSERT(url().scheme() == QLatin1String("trash")); | | |||
244 | | ||||
245 | const bool isTrashEmpty = m_trashDirLister->items().isEmpty(); | | |||
246 | setIcon(isTrashEmpty ? QStringLiteral("user-trash") : QStringLiteral("user-trash-full")); | | |||
247 | } | | |||
248 | | ||||
249 | void PlacesItem::updateBookmarkForRole(const QByteArray& role) | 237 | void PlacesItem::updateBookmarkForRole(const QByteArray& role) | ||
250 | { | 238 | { | ||
251 | Q_ASSERT(!m_bookmark.isNull()); | 239 | Q_ASSERT(!m_bookmark.isNull()); | ||
252 | if (role == "iconName") { | 240 | if (role == "iconName") { | ||
253 | m_bookmark.setIcon(icon()); | 241 | m_bookmark.setIcon(icon()); | ||
254 | } else if (role == "text") { | 242 | } else if (role == "text") { | ||
255 | // 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 | ||
256 | // 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 |
This is unrelated. I get that you don't like them not being order, but lets keep it focused on the actual thing you implement in this commit :)