00001
00002
00003
00004 #include <qpixmap.h>
00005 #include <qfileinfo.h>
00006 #include <qdir.h>
00007
00008
00009 #include <mythtv/mythcontext.h>
00010 #include <mythtv/mythdbcon.h>
00011
00012
00013 #include "thumbview.h"
00014 #include "galleryutil.h"
00015
00016 ThumbItem::~ThumbItem()
00017 {
00018 if (m_pixmap)
00019 {
00020 delete m_pixmap;
00021 m_pixmap = NULL;
00022 }
00023 }
00024
00025 bool ThumbItem::Remove(void)
00026 {
00027 if (!QFile::exists(m_path) || !QFile::remove(m_path))
00028 return false;
00029
00030 MSqlQuery query(MSqlQuery::InitCon());
00031 query.prepare(
00032 "DELETE FROM gallerymetadata "
00033 "WHERE image = :PATH");
00034 query.bindValue(":PATH", m_path.utf8());
00035
00036 if (!query.exec())
00037 {
00038 MythContext::DBError("thumb_item_remove", query);
00039 return false;
00040 }
00041
00042 return true;
00043 }
00044
00045 void ThumbItem::InitCaption(bool get_caption)
00046 {
00047 if (!HasCaption() && get_caption)
00048 SetCaption(GalleryUtil::GetCaption(m_path));
00049 if (!HasCaption())
00050 SetCaption(m_name);
00051 }
00052
00053 void ThumbItem::SetRotationAngle(int angle)
00054 {
00055 MSqlQuery query(MSqlQuery::InitCon());
00056 query.prepare(
00057 "REPLACE INTO gallerymetadata "
00058 "SET image = :IMAGE, "
00059 " angle = :ANGLE");
00060 query.bindValue(":IMAGE", m_path.utf8());
00061 query.bindValue(":ANGLE", angle);
00062
00063 if (!query.exec())
00064 MythContext::DBError("set_rotation_angle", query);
00065
00066 SetPixmap(NULL);
00067 }
00068
00069 void ThumbItem::SetPixmap(QPixmap *pixmap)
00070 {
00071 if (m_pixmap)
00072 delete m_pixmap;
00073 m_pixmap = pixmap;
00074 }
00075
00076 long ThumbItem::GetRotationAngle(void)
00077 {
00078 MSqlQuery query(MSqlQuery::InitCon());
00079
00080
00081 query.prepare(
00082 "SELECT angle "
00083 "FROM gallerymetadata "
00084 "WHERE image = :PATH");
00085 query.bindValue(":PATH", m_path.utf8());
00086
00087 if (!query.exec() || !query.isActive())
00088 MythContext::DBError("get_rotation_angle", query);
00089 else if (query.next())
00090 return query.value(0).toInt();
00091
00092
00093 query.prepare(
00094 "SELECT angle, image "
00095 "FROM gallerymetadata "
00096 "WHERE image LIKE :PATH "
00097 "ORDER BY image");
00098 query.bindValue(":PATH", m_path.utf8() + '%');
00099
00100 if (!query.exec() || !query.isActive())
00101 MythContext::DBError("get_rotation_angle", query);
00102 else if (query.next())
00103 return query.value(0).toInt();
00104
00105 return GalleryUtil::GetNaturalRotation(m_path);
00106 }
00107
00108 QString ThumbItem::GetDescription(const QString &status,
00109 const QSize &sz, int angle) const
00110 {
00111 QFileInfo fi(GetPath());
00112
00113 QString info = GetName();
00114
00115 if (!status.isEmpty())
00116 info += status;
00117
00118 info += "\n\n" + QObject::tr("Folder: ") + fi.dir().dirName();
00119 info += "\n" + QObject::tr("Created: ") + fi.created().toString();
00120 info += "\n" + QObject::tr("Modified: ") +
00121 fi.lastModified().toString();
00122 info += "\n" + QString(QObject::tr("Bytes") + ": %1").arg(fi.size());
00123 info += "\n" + QString(QObject::tr("Width") + ": %1 " +
00124 QObject::tr("pixels")).arg(sz.width());
00125 info += "\n" + QString(QObject::tr("Height") + ": %1 " +
00126 QObject::tr("pixels")).arg(sz.height());
00127 info += "\n" + QString(QObject::tr("Pixel Count") + ": %1 " +
00128 QObject::tr("megapixels"))
00129 .arg((float) sz.width() * sz.height() * (1.0f/1000000.0f), 0, 'f', 2);
00130 info += "\n" + QString(QObject::tr("Rotation Angle") + ": %1 " +
00131 QObject::tr("degrees")).arg(angle);
00132
00133 return info;
00134 }