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