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  delete m_pixmap;
77  m_pixmap = pixmap;
78 }
79 
81 {
83 
84  // first try to find the exact file
85  query.prepare(
86  "SELECT angle "
87  "FROM gallerymetadata "
88  "WHERE image = :PATH");
89  query.bindValue(":PATH", m_path);
90 
91  if (!query.exec() || !query.isActive())
92  MythDB::DBError("get_rotation_angle", query);
93  else if (query.next())
94  return query.value(0).toInt();
95 
96  // second try to find the first image in the same directory
97  query.prepare(
98  "SELECT angle, image "
99  "FROM gallerymetadata "
100  "WHERE image LIKE :PATH "
101  "ORDER BY image");
102  query.bindValue(":PATH", m_path + '%');
103 
104  if (!query.exec() || !query.isActive())
105  MythDB::DBError("get_rotation_angle", query);
106  else if (query.next())
107  return query.value(0).toInt();
108 
110 }
111 
112 QString ThumbItem::GetDescription(const QString &status,
113  const QSize &sz, int angle) const
114 {
115  QFileInfo fi(GetPath());
116 
117  QString info = GetName();
118 
119  if (!status.isEmpty())
120  info += status;
121 
122  info += "\n\n" + tr("Folder: %1").arg(fi.dir().dirName());
123  //: %1 is the creation date
124 #if QT_VERSION < QT_VERSION_CHECK(5,10,0)
125  info += "\n" + tr("Created: %1").arg(fi.created().toString());
126 #else
127  info += "\n" + tr("Created: %1").arg(fi.birthTime().toString());
128 #endif
129  //: %1 is the modification date
130  info += "\n" + tr("Modified: %1").arg(fi.lastModified().toString());
131  info += "\n" + tr("Size: %n byte(s)", "", fi.size());
132  info += "\n" + tr("Width: %n pixel(s)", "", sz.width());
133  info += "\n" + tr("Height: %n pixel(s)", "", sz.height());
134  info += "\n" + tr("Pixel Count: %1 megapixels")
135  .arg((float) sz.width() * sz.height() * (1.0F/1000000.0F), 0, 'f', 2);
136  info += "\n" + tr("Rotation Angle: %n degree(s)", "", angle);
137 
138  return info;
139 }
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:782
static long GetNaturalRotation(const unsigned char *buffer, int size)
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:863
bool HasCaption(void) const
Definition: thumbview.h:54
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:112
QString m_name
Definition: thumbview.h:69
void SetPixmap(QPixmap *pixmap)
Definition: thumbview.cpp:74
void SetTimestamp(const QDateTime &timestamp)
Definition: thumbview.h:41
QVariant value(int i) const
Definition: mythdbcon.h:198
QString GetName(void) const
Definition: thumbview.h:53
long GetRotationAngle(void)
Definition: thumbview.cpp:80
static QDateTime GetTimestamp(const QString &filePath)
bool isActive(void) const
Definition: mythdbcon.h:204
static QString GetCaption(const QString &filePath)
bool HasTimestamp(void) const
Definition: thumbview.h:56
static MSqlQueryInfo InitCon(ConnectionReuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:535
QString m_path
Definition: thumbview.h:72
QString GetPath(void) const
Definition: thumbview.h:59
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:807
void InitCaption(bool get_caption)
Definition: thumbview.cpp:44
void SetCaption(const QString &caption)
Definition: thumbview.h:39
void SetRotationAngle(int angle)
Definition: thumbview.cpp:58
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:603
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:179
QPixmap * m_pixmap
Definition: thumbview.h:75
bool Remove(void)
Definition: thumbview.cpp:24
void InitTimestamp()
Definition: thumbview.cpp:52