File indexing completed on 2025-01-19 03:51:26
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2012-17-04 0007 * Description : time adjust images list. 0008 * 0009 * SPDX-FileCopyrightText: 2012 by Smit Mehta <smit dot meh at gmail dot com> 0010 * SPDX-FileCopyrightText: 2012-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * SPDX-FileCopyrightText: 2018-2021 by Maik Qualmann <metzpinguin at gmail dot com> 0012 * 0013 * SPDX-License-Identifier: GPL-2.0-or-later 0014 * 0015 * ============================================================ */ 0016 0017 #include "timeadjustlist.h" 0018 0019 // Qt includes 0020 0021 #include <QLocale> 0022 #include <QHeaderView> 0023 0024 // KDE includes 0025 0026 #include <klocalizedstring.h> 0027 0028 namespace DigikamGenericTimeAdjustPlugin 0029 { 0030 0031 TimeAdjustList::TimeAdjustList(QWidget* const parent) 0032 : DItemsList(parent) 0033 { 0034 setControlButtonsPlacement(DItemsList::NoControlButtons); 0035 listView()->setColumn(static_cast<Digikam::DItemsListView::ColumnType>(TIMESTAMP_USED), 0036 i18n("Timestamp Used"), true); 0037 listView()->setColumn(static_cast<Digikam::DItemsListView::ColumnType>(TIMESTAMP_UPDATED), 0038 i18n("Timestamp Updated"), true); 0039 listView()->setColumn(static_cast<Digikam::DItemsListView::ColumnType>(STATUS), 0040 i18n("Status"), true); 0041 0042 listView()->header()->setSectionResizeMode(QHeaderView::Interactive); 0043 listView()->setSelectionMode(QAbstractItemView::SingleSelection); 0044 listView()->header()->resizeSection(0, 120); 0045 listView()->header()->resizeSection(1, 200); 0046 listView()->header()->resizeSection(2, 200); 0047 listView()->header()->resizeSection(3, 200); 0048 listView()->setUniformRowHeights(true); 0049 } 0050 0051 TimeAdjustList::~TimeAdjustList() 0052 { 0053 } 0054 0055 void TimeAdjustList::setStatus(const QUrl& url, 0056 const QDateTime& org, 0057 const QDateTime& adj, int status) 0058 { 0059 QString dateTimeFormat = QLocale().dateFormat(QLocale::ShortFormat); 0060 0061 if (!dateTimeFormat.contains(QLatin1String("yyyy"))) 0062 { 0063 dateTimeFormat.replace(QLatin1String("yy"), 0064 QLatin1String("yyyy")); 0065 } 0066 0067 dateTimeFormat.append(QLatin1String(" hh:mm:ss")); 0068 0069 DItemsListViewItem* const item = listView()->findItem(url); 0070 0071 if (item) 0072 { 0073 QStringList errors; 0074 0075 if (status & META_TIME_ERROR) 0076 { 0077 errors << i18n("Failed to update metadata timestamp"); 0078 } 0079 0080 if (status & FILE_TIME_ERROR) 0081 { 0082 errors << i18n("Failed to update file timestamp"); 0083 } 0084 0085 if (status & CLRSTATUS_ERROR) 0086 { 0087 item->setText(STATUS, QLatin1String("")); 0088 } 0089 else if (errors.isEmpty()) 0090 { 0091 // Processed without error 0092 item->setText(STATUS, i18n("Success")); 0093 } 0094 else 0095 { 0096 item->setText(STATUS, errors.join(QLatin1String(" | "))); 0097 } 0098 0099 if (org.isValid()) 0100 { 0101 item->setText(TIMESTAMP_USED, org.toString(dateTimeFormat)); 0102 } 0103 else 0104 { 0105 item->setText(TIMESTAMP_USED, i18n("not valid")); 0106 } 0107 0108 if (adj.isValid()) 0109 { 0110 item->setText(TIMESTAMP_UPDATED, adj.toString(dateTimeFormat)); 0111 } 0112 else 0113 { 0114 item->setText(TIMESTAMP_UPDATED, i18n("not valid")); 0115 } 0116 } 0117 } 0118 0119 void TimeAdjustList::setWaitStatus() 0120 { 0121 QTreeWidgetItemIterator it(listView()); 0122 0123 while (*it) 0124 { 0125 DItemsListViewItem* const item = dynamic_cast<DItemsListViewItem*>(*it); 0126 0127 if (item) 0128 { 0129 item->setText(STATUS, i18n("Please wait ...")); 0130 item->setText(TIMESTAMP_USED, QLatin1String("")); 0131 item->setText(TIMESTAMP_UPDATED, QLatin1String("")); 0132 } 0133 0134 ++it; 0135 } 0136 } 0137 0138 } // namespace DigikamGenericTimeAdjustPlugin 0139 0140 #include "moc_timeadjustlist.cpp"