koPictureKey.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qdatetime.h>
00022 #include <qfileinfo.h>
00023 #include <qdom.h>
00024
00025 #include <kdebug.h>
00026
00027 #include "koPictureKey.h"
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 static void resetDateTimeToEpoch(QDateTime& dt)
00042 {
00043
00044 dt.setDate(QDate(1970,1,1));
00045 dt.setTime(QTime(0,0));
00046
00047 }
00048
00049 KoPictureKey::KoPictureKey()
00050 {
00051 resetDateTimeToEpoch(m_lastModified);
00052 }
00053
00054 KoPictureKey::KoPictureKey( const QString &fn, const QDateTime &mod )
00055 : m_filename( fn ), m_lastModified( mod )
00056 {
00057 if (!m_lastModified.isValid())
00058 {
00059
00060 resetDateTimeToEpoch(m_lastModified);
00061 }
00062 }
00063
00064 KoPictureKey::KoPictureKey( const QString &fn )
00065 : m_filename( fn )
00066 {
00067 resetDateTimeToEpoch(m_lastModified);
00068 }
00069
00070 KoPictureKey::KoPictureKey( const KoPictureKey &key )
00071 : m_filename( key.m_filename ), m_lastModified( key.m_lastModified )
00072 {
00073 }
00074
00075 KoPictureKey& KoPictureKey::operator=( const KoPictureKey &key )
00076 {
00077 m_filename = key.m_filename;
00078 m_lastModified = key.m_lastModified;
00079 return *this;
00080 }
00081
00082 bool KoPictureKey::operator==( const KoPictureKey &key ) const
00083 {
00084 return ( key.m_filename == m_filename &&
00085 key.m_lastModified == m_lastModified );
00086 }
00087
00088 bool KoPictureKey::operator<( const KoPictureKey &key ) const
00089 {
00090 return key.toString() < toString();
00091 }
00092
00093 void KoPictureKey::saveAttributes( QDomElement &elem ) const
00094 {
00095 QDate date = m_lastModified.date();
00096 QTime time = m_lastModified.time();
00097 elem.setAttribute( "filename", m_filename );
00098 elem.setAttribute( "year", date.year() );
00099 elem.setAttribute( "month", date.month() );
00100 elem.setAttribute( "day", date.day() );
00101 elem.setAttribute( "hour", time.hour() );
00102 elem.setAttribute( "minute", time.minute() );
00103 elem.setAttribute( "second", time.second() );
00104 elem.setAttribute( "msec", time.msec() );
00105 }
00106
00107 void KoPictureKey::loadAttributes( const QDomElement &elem )
00108 {
00109
00110 int year=1970, month=1, day=1;
00111 int hour=0, minute=0, second=0, msec=0;
00112
00113 if( elem.hasAttribute( "key" ) )
00114 {
00115
00116 m_filename=elem.attribute( "key" );
00117 }
00118 else
00119 {
00120
00121 m_filename=elem.attribute( "filename" );
00122 }
00123
00124 if( elem.hasAttribute( "year" ) )
00125 year=elem.attribute( "year" ).toInt();
00126 if( elem.hasAttribute( "month" ) )
00127 month=elem.attribute( "month" ).toInt();
00128 if( elem.hasAttribute( "day" ) )
00129 day=elem.attribute( "day" ).toInt();
00130 if( elem.hasAttribute( "hour" ) )
00131 hour=elem.attribute( "hour" ).toInt();
00132 if( elem.hasAttribute( "minute" ) )
00133 minute=elem.attribute( "minute" ).toInt();
00134 if( elem.hasAttribute( "second" ) )
00135 second=elem.attribute( "second" ).toInt();
00136 if( elem.hasAttribute( "msec" ) )
00137 msec=elem.attribute( "msec" ).toInt();
00138
00139 m_lastModified.setDate( QDate( year, month, day ) );
00140 m_lastModified.setTime( QTime( hour, minute, second, msec ) );
00141
00142 if (!m_lastModified.isValid())
00143 {
00144
00145 kdWarning(30003) << "Correcting invalid date/time: " << toString() << " (in KoPictureKey::loadAttributes)" << endl;
00146 resetDateTimeToEpoch(m_lastModified);
00147 }
00148 }
00149
00150 QString KoPictureKey::toString() const
00151 {
00152
00153
00154 return QString::fromLatin1("%2 %1")
00155 .arg(m_lastModified.toString("yyyy-MM-dd hh:mm:ss.zzz")).arg(m_filename);
00156 }
00157
00158 void KoPictureKey::setKeyFromFile (const QString& filename)
00159 {
00160 QFileInfo inf(filename);
00161 m_filename = filename;
00162 m_lastModified = inf.lastModified();
00163 }
This file is part of the documentation for lib Library Version 1.3.5.