Krazy/EBN: qMin is better than QMIN
[kphotoalbum.git] / MainWindow / InvalidDateFinder.cpp
blobfc09477eb60b8712fe345d7bd39f90775566d3cf
1 /* Copyright (C) 2003-2006 Jesper K. Pedersen <blackie@kde.org>
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public
5 License as published by the Free Software Foundation; either
6 version 2 of the License, or (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; see the file COPYING. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #include "InvalidDateFinder.h"
20 #include <qlayout.h>
21 #include <qradiobutton.h>
22 #include <klocale.h>
23 #include "DB/ImageInfo.h"
24 #include "DB/ImageDB.h"
25 #include "DB/ImageDate.h"
26 #include "DB/FileInfo.h"
27 #include "DB/ResultId.h"
28 #include "MainWindow/Window.h"
29 #include <qapplication.h>
30 #include <qeventloop.h>
31 #include "Utilities/ShowBusyCursor.h"
32 #include <QGroupBox>
33 #include <QTextEdit>
34 #include <KProgressDialog>
35 #include <kdebug.h>
37 using namespace MainWindow;
39 InvalidDateFinder::InvalidDateFinder( QWidget* parent )
40 :KDialog( parent )
42 setWindowTitle( i18n("Search for Images and Videos with Missing Dates" ) );
43 setButtons( Cancel | Ok );
45 QWidget* top = new QWidget;
46 setMainWidget( top );
47 QVBoxLayout* lay1 = new QVBoxLayout( top );
49 QGroupBox* grp = new QGroupBox( i18n("Which Images and Videos to Display") );
50 QVBoxLayout* grpLay = new QVBoxLayout( grp );
51 lay1->addWidget( grp );
53 _dateNotTime = new QRadioButton( i18n( "Search for images and videos with a valid date but an invalid time stamp") );
54 _missingDate = new QRadioButton( i18n( "Search for images and videos missing date and time" ) );
55 _partialDate = new QRadioButton( i18n( "Search for images and videos with only partial dates (like 1971 vs. 11/7-1971)") );
56 _dateNotTime->setChecked( true );
58 grpLay->addWidget( _dateNotTime );
59 grpLay->addWidget( _missingDate );
60 grpLay->addWidget( _partialDate );
63 void InvalidDateFinder::accept()
65 KDialog::accept();
66 Utilities::ShowBusyCursor dummy;
68 // create the info dialog
69 KDialog* info = new KDialog;
70 info->setWindowTitle( i18n("Image Info" ) );
71 info->setButtons( Ok );
73 QWidget* top = new QWidget;
74 info->setMainWidget( top );
76 QVBoxLayout* lay1 = new QVBoxLayout( top );
77 QTextEdit* edit = new QTextEdit( top );
78 lay1->addWidget( edit );
79 edit->setText( i18n("<h1>Here you may see the date changes for the displayed items.</h1>") );
81 // Now search for the images.
82 DB::Result list = DB::ImageDB::instance()->images();
83 DB::Result toBeShown;
84 KProgressDialog dialog( 0, i18n("Reading file properties"),
85 i18n("Reading File Properties") );
86 dialog.progressBar()->setMaximum(list.size());
87 dialog.progressBar()->setValue(0);
88 int progress = 0;
90 Q_FOREACH(DB::ResultId id, list) {
91 DB::ImageInfoPtr info = id.fetchInfo();
92 dialog.progressBar()->setValue( ++progress );
93 qApp->processEvents( QEventLoop::AllEvents );
94 if ( dialog.wasCancelled() )
95 break;
97 DB::ImageDate date = info->date();
98 bool show = false;
99 if ( _dateNotTime->isChecked() ) {
100 DB::FileInfo fi = DB::FileInfo::read( info->fileName(DB::AbsolutePath), DB::EXIFMODE_DATE );
101 if ( fi.dateTime().date() == date.start().date() )
102 show = ( fi.dateTime().time() != date.start().time() );
103 if ( show ) {
104 edit->append( QString::fromLatin1("%1:<br/>existing = %2<br>new..... = %3" )
105 .arg(info->fileName(DB::AbsolutePath))
106 .arg(date.start().toString())
107 .arg(fi.dateTime().toString()) );
110 else if ( _missingDate->isChecked() ) {
111 show = !date.start().isValid();
113 else if ( _partialDate->isChecked() ) {
114 show = ( date.start() != date.end() );
117 if ( show )
118 toBeShown.append(id);
121 if ( _dateNotTime->isChecked() ) {
122 info->resize( 800, 600 );
123 edit->setReadOnly( true );
124 QFont f = edit->font();
125 f.setFamily( QString::fromLatin1( "fixed" ) );
126 edit->setFont( f );
127 info->show();
129 else
130 delete info;
132 Window::theMainWindow()->showThumbNails( toBeShown );
135 #include "InvalidDateFinder.moc"