MythTV  master
thumbview.cpp
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 
3 // Qt headers
4 #include <QPixmap>
5 #include <QFileInfo>
6 #include <QDir>
7 
8 // MythTV plugin headers
9 #include <mythdb.h>
10 
11 // MythGallery headers
12 #include "thumbview.h"
13 #include "galleryutil.h"
14 
16 {
17  if (m_pixmap)
18  {
19  delete m_pixmap;
20  m_pixmap = nullptr;
21  }
22 }
23 
25 {
26  if (!QFile::exists(m_path) || !QFile::remove(m_path))
27  return false;
28 
30  query.prepare(
31  "DELETE FROM gallerymetadata "
32  "WHERE image = :PATH");
33  query.bindValue(":PATH", m_path);
34 
35  if (!query.exec())
36  {
37  MythDB::DBError("thumb_item_remove", query);
38  return false;
39  }
40 
41  return true;
42 }
43 
44 void ThumbItem::InitCaption(bool get_caption)
45 {
46  if (!HasCaption() && get_caption)
48  if (!HasCaption())
50 }
51 
53 {
54  if (!HasTimestamp())
56 }
57 
59 {
61  query.prepare(
62  "REPLACE INTO gallerymetadata "
63  "SET image = :IMAGE, "
64  " angle = :ANGLE");
65  query.bindValue(":IMAGE", m_path);
66  query.bindValue(":ANGLE", angle);
67 
68  if (!query.exec())
69  MythDB::DBError("set_rotation_angle", query);
70 
71  SetPixmap(nullptr);
72 }
73 
74 void ThumbItem::SetPixmap(QPixmap *pixmap)
75 {
76  if (m_pixmap)
77  delete m_pixmap;
78  m_pixmap = pixmap;
79 }
80 
82 {
84 
85  // first try to find the exact file
86  query.prepare(
87  "SELECT angle "
88  "FROM gallerymetadata "
89  "WHERE image = :PATH");
90  query.bindValue(":PATH", m_path);
91 
92  if (!query.exec() || !query.isActive())
93  MythDB::DBError("get_rotation_angle", query);
94  else if (query.next())
95  return query.value(0).toInt();
96 
97  // second try to find the first image in the same directory
98  query.prepare(
99  "SELECT angle, image "
100  "FROM gallerymetadata "
101  "WHERE image LIKE :PATH "
102  "ORDER BY image");
103  query.bindValue(":PATH", m_path + '%');
104 
105  if (!query.exec() || !query.isActive())
106  MythDB::DBError("get_rotation_angle", query);
107  else if (query.next())
108  return query.value(0).toInt();
109 
111 }
112 
113 QString ThumbItem::GetDescription(const QString &status,
114  const QSize &sz, int angle) const
115 {
116  QFileInfo fi(GetPath());
117 
118  QString info = GetName();
119 
120  if (!status.isEmpty())
121  info += status;
122 
123  info += "\n\n" + tr("Folder: %1").arg(fi.dir().dirName());
124  //: %1 is the creation date
125 #if QT_VERSION < QT_VERSION_CHECK(5,10,0)
126  info += "\n" + tr("Created: %1").arg(fi.created().toString());
127 #else
128  info += "\n" + tr("Created: %1").arg(fi.birthTime().toString());
129 #endif
130  //: %1 is the modification date
131  info += "\n" + tr("Modified: %1").arg(fi.lastModified().toString());
132  info += "\n" + tr("Size: %n byte(s)", "", fi.size());
133  info += "\n" + tr("Width: %n pixel(s)", "", sz.width());
134  info += "\n" + tr("Height: %n pixel(s)", "", sz.height());
135  info += "\n" + tr("Pixel Count: %1 megapixels")
136  .arg((float) sz.width() * sz.height() * (1.0f/1000000.0f), 0, 'f', 2);
137  info += "\n" + tr("Rotation Angle: %n degree(s)", "", angle);
138 
139  return info;
140 }
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:794
static long GetNaturalRotation(const unsigned char *buffer, int size)
void bindValue(const QString &placeholder, const QVariant &val)
Definition: mythdbcon.cpp:875
bool HasCaption(void) const
Definition: thumbview.h:56
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:125
QString GetDescription(const QString &status, const QSize &sz, int angle) const
Definition: thumbview.cpp:113
QString m_name
Definition: thumbview.h:71
void SetPixmap(QPixmap *pixmap)
Definition: thumbview.cpp:74
void SetTimestamp(const QDateTime &timestamp)
Definition: thumbview.h:43
QVariant value(int i) const
Definition: mythdbcon.h:182
QString GetName(void) const
Definition: thumbview.h:55
long GetRotationAngle(void)
Definition: thumbview.cpp:81
static QDateTime GetTimestamp(const QString &filePath)
bool isActive(void) const
Definition: mythdbcon.h:188
static QString GetCaption(const QString &filePath)
bool HasTimestamp(void) const
Definition: thumbview.h:58
static MSqlQueryInfo InitCon(ConnectionReuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:547
QString m_path
Definition: thumbview.h:74
QString GetPath(void) const
Definition: thumbview.h:61
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:819
void InitCaption(bool get_caption)
Definition: thumbview.cpp:44
void SetCaption(const QString &caption)
Definition: thumbview.h:41
void SetRotationAngle(int angle)
Definition: thumbview.cpp:58
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:615
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:179
QPixmap * m_pixmap
Definition: thumbview.h:77
bool Remove(void)
Definition: thumbview.cpp:24
void InitTimestamp()
Definition: thumbview.cpp:52