File indexing completed on 2024-04-28 15:40:12

0001 /* SPDX-FileCopyrightText: 2003-2020 Jesper K. Pedersen <blackie@kde.org>
0002 
0003    SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "InvalidDateFinder.h"
0007 
0008 #include "Window.h"
0009 
0010 #include <DB/FileInfo.h>
0011 #include <DB/ImageDB.h>
0012 #include <DB/ImageDate.h>
0013 #include <DB/ImageInfo.h>
0014 #include <Utilities/ShowBusyCursor.h>
0015 
0016 #include <KLocalizedString>
0017 #include <KTextEdit>
0018 #include <QDialogButtonBox>
0019 #include <QGroupBox>
0020 #include <QProgressDialog>
0021 #include <QPushButton>
0022 #include <QVBoxLayout>
0023 #include <qapplication.h>
0024 #include <qeventloop.h>
0025 #include <qlayout.h>
0026 #include <qradiobutton.h>
0027 
0028 using namespace MainWindow;
0029 
0030 InvalidDateFinder::InvalidDateFinder(QWidget *parent)
0031     : QDialog(parent)
0032 {
0033     setWindowTitle(i18nc("@title:window", "Search for Images and Videos with Missing Dates"));
0034     QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
0035     QWidget *mainWidget = new QWidget(this);
0036     QVBoxLayout *mainLayout = new QVBoxLayout;
0037     setLayout(mainLayout);
0038     mainLayout->addWidget(mainWidget);
0039 
0040     QGroupBox *grp = new QGroupBox(i18n("Which Images and Videos to Display"));
0041     QVBoxLayout *grpLay = new QVBoxLayout(grp);
0042     mainLayout->addWidget(grp);
0043 
0044     m_dateNotTime = new QRadioButton(i18n("Search for images and videos with a valid date but an invalid time stamp"));
0045     m_missingDate = new QRadioButton(i18n("Search for images and videos missing date and time"));
0046     m_partialDate = new QRadioButton(i18n("Search for images and videos with only partial dates (like 1971 vs. 11/7-1971)"));
0047     m_dateNotTime->setChecked(true);
0048 
0049     grpLay->addWidget(m_dateNotTime);
0050     grpLay->addWidget(m_missingDate);
0051     grpLay->addWidget(m_partialDate);
0052 
0053     QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
0054     okButton->setDefault(true);
0055     okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0056     connect(buttonBox, &QDialogButtonBox::accepted, this, &InvalidDateFinder::accept);
0057     connect(buttonBox, &QDialogButtonBox::rejected, this, &InvalidDateFinder::reject);
0058     mainLayout->addWidget(buttonBox);
0059 }
0060 
0061 void InvalidDateFinder::accept()
0062 {
0063     QDialog::accept();
0064     Utilities::ShowBusyCursor dummy;
0065 
0066     // create the info dialog
0067     QDialog *info = new QDialog;
0068     QVBoxLayout *mainLayout = new QVBoxLayout;
0069     info->setLayout(mainLayout);
0070     info->setWindowTitle(i18nc("@title:window", "Image Info"));
0071 
0072     KTextEdit *edit = new KTextEdit(info);
0073     mainLayout->addWidget(edit);
0074     edit->setText(i18n("<h1>Here you may see the date changes for the displayed items.</h1>"));
0075 
0076     QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
0077     QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
0078     okButton->setDefault(true);
0079     okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0080     info->connect(buttonBox, &QDialogButtonBox::accepted, info, &QDialog::accept);
0081     info->connect(buttonBox, &QDialogButtonBox::rejected, info, &QDialog::reject);
0082     mainLayout->addWidget(buttonBox);
0083 
0084     // Now search for the images.
0085     const auto images = DB::ImageDB::instance()->images();
0086     DB::FileNameList toBeShown;
0087     QProgressDialog dialog(nullptr);
0088     dialog.setWindowTitle(i18nc("@title:window", "Reading File Properties"));
0089     dialog.setMaximum(images.size());
0090     dialog.setValue(0);
0091     int progress = 0;
0092 
0093     for (const auto &info : images) {
0094         dialog.setValue(++progress);
0095         qApp->processEvents(QEventLoop::AllEvents);
0096         if (dialog.wasCanceled())
0097             break;
0098         if (info->isNull())
0099             continue;
0100 
0101         DB::ImageDate date = info->date();
0102         bool show = false;
0103         if (m_dateNotTime->isChecked()) {
0104             DB::FileInfo fi = DB::FileInfo::read(info->fileName(), DB::EXIFMODE_DATE);
0105             if (fi.dateTime().date() == date.start().date())
0106                 show = (fi.dateTime().time() != date.start().time());
0107             if (show) {
0108                 edit->append(QString::fromLatin1("%1:<br/>existing = %2<br>new..... = %3").arg(info->fileName().relative(), date.start().toString(), fi.dateTime().toString()));
0109             }
0110         } else if (m_missingDate->isChecked()) {
0111             show = !date.start().isValid();
0112         } else if (m_partialDate->isChecked()) {
0113             show = (date.start() != date.end());
0114         }
0115 
0116         if (show)
0117             toBeShown.append(info->fileName());
0118     }
0119 
0120     if (m_dateNotTime->isChecked()) {
0121         info->resize(800, 600);
0122         edit->setReadOnly(true);
0123         QFont f = edit->font();
0124         f.setFamily(QString::fromLatin1("fixed"));
0125         edit->setFont(f);
0126         info->show();
0127     } else
0128         delete info;
0129 
0130     Window::theMainWindow()->showThumbNails(toBeShown);
0131 }
0132 
0133 // vi:expandtab:tabstop=4 shiftwidth=4:
0134 
0135 #include "moc_InvalidDateFinder.cpp"