MythTV  master
image.cpp
Go to the documentation of this file.
1 // Program Name: image.cpp
3 // Created : Jul. 27, 2012
4 //
5 // Copyright (c) 2012 Robert Siebert <trebor_s@web.de>
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 //
25 
26 //#include "libmythbase/mythcorecontext.h"
27 
28 #include "image.h"
29 
30 #define LOC QString("ImageService: ")
31 
40 QString Image::GetImageInfo( int /*id*/, const QString &/*tag*/ )
41 {
42 // ImageManagerBe *mgr = ImageManagerBe::getInstance();
43 
44 // // Find image in DB
45 // ImageList images;
46 // if (mgr->GetFiles(images, QString::number(id)) != 1)
47 // {
48 // qDeleteAll(images);
49 // LOG(VB_FILE, LOG_NOTICE, LOC + QString("Image %1 not found").arg(id));
50 // return QString();
51 // }
52 
53 // // Read all metadata tags
54 // ImageAdapterBase::TagMap tags;
55 // tags.insert(tag, qMakePair(QString(), QString()));
56 
57 // ImageItem *im = images[0];
58 // bool found = mgr->HandleGetMetadata(id, tags);
59 // delete im;
60 
61 // if (found)
62 // return tags[tag].first;
63 
64 // LOG(VB_FILE, LOG_DEBUG, LOC + QString("Tag %1 not found for %2").arg(tag).arg(id));
65  return {};
66 }
67 
68 
69 
76 {
77  // This holds the xml data structure from
78  // the returned stringlist with the exif data
79  auto *imInfoList = new DTC::ImageMetadataInfoList();
80 
81  // Read all metadata tags
82 // ImageManagerBe *mgr = ImageManagerBe::getInstance();
83  QStringList tags; // = mgr->HandleGetMetadata(QString::number(id));
84 
85  if (tags.size() < 2 || tags[0] != "OK")
86  {
87  LOG(VB_FILE, LOG_NOTICE, LOC +
88  QString("Image %1 - %2").arg(id).arg(tags.join(",")));
89  return imInfoList;
90  }
91  tags.removeFirst();
92 
93  // Set the general information of the image
94  imInfoList->setCount(tags.size());
95 // imInfoList->setFile(im->m_filePath);
96 // imInfoList->setPath(im->m_path);
97 // imInfoList->setSize(im->m_size);
98 // imInfoList->setExtension(im->m_extension);
99 
100  // Each string contains a Name<seperator>Label<seperator>Value.
101  QString seperator = tags.takeFirst();
102  int index = 0;
103  for (const QString & token : std::as_const(tags))
104  {
105  QStringList parts = token.split(seperator);
106  if (parts.size() != 3)
107  {
108  LOG(VB_GENERAL, LOG_ERR, LOC +
109  QString("Bad Metadata received: '%1' (%2)").arg(token, seperator));
110  continue;
111  }
112  DTC::ImageMetadataInfo *imInfo = imInfoList->AddNewImageMetadataInfo();
113 
114  imInfo->setNumber(index++);
115  imInfo->setTag(parts[0]);
116  imInfo->setLabel(parts[1]);
117  imInfo->setValue(parts[2]);
118 
119 #if defined(DUMP_METADATA_TAGS) && DUMP_METADATA_TAGS
120  LOG(VB_FILE, LOG_DEBUG, LOC +
121  QString("Metadata %1 : %2 : '%3'").arg(parts[0], parts[1], parts[2]));
122 #endif
123  }
124  return imInfoList;
125 }
126 
127 
128 
134 bool Image::RemoveImage( int id )
135 {
136  QStringList result = ImageManagerBe::getInstance()->
137  HandleDelete(QString::number(id));
138  return result[0] == "OK";
139 }
140 
141 
148 bool Image::RenameImage( int id, const QString &newName)
149 {
150  QStringList result = ImageManagerBe::getInstance()->
151  HandleRename(QString::number(id), newName);
152  return result[0] == "OK";
153 }
154 
155 
160 bool Image::StartSync( void )
161 {
162  QStringList result = ImageManagerBe::getInstance()->HandleScanRequest("START");
163  return result.size() >= 2 && !result[1].isEmpty();
164 }
165 
166 
167 
172 bool Image::StopSync( void )
173 {
174  QStringList result = ImageManagerBe::getInstance()->HandleScanRequest("STOP");
175  return result.size() >= 2 && !result[1].isEmpty();
176 }
177 
178 
179 
187 {
188  // Default to No Scan
189  bool running = false;
190  int current = 0;
191  int total = 0;
192 
193  // Expects OK, scanner id, current#, total#
194  QStringList result = ImageManagerBe::getInstance()->HandleScanRequest("QUERY");
195  if (result.size() == 4 && result[0] == "OK")
196  {
197  current = result[2].toInt();
198  total = result[3].toInt();
199  running = (current != total);
200  }
201 
202  LOG(VB_GENERAL, LOG_DEBUG,
203  QString("Image: Sync status is running: %1, current: %2, total: %3")
204  .arg(running).arg(current).arg(total));
205 
206  auto *syncInfo = new DTC::ImageSyncInfo();
207  syncInfo->setRunning(running);
208  syncInfo->setCurrent(current);
209  syncInfo->setTotal(total);
210 
211  return syncInfo;
212 }
213 
220 {
221  QStringList mesg("0");
222  mesg << QString::number(id);
224  return true;
225 }
DTC::ImageSyncInfo
Definition: imageSyncInfo.h:14
Image::RenameImage
bool RenameImage(int id, const QString &newName) override
Renames the file to the new name.
Definition: image.cpp:148
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
LOC
#define LOC
Definition: image.cpp:30
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:14
Image::GetImageInfoList
DTC::ImageMetadataInfoList * GetImageInfoList(int id) override
Returns all values from all available exif tags.
Definition: image.cpp:75
DTC::ImageMetadataInfo
Definition: imageMetadataInfo.h:14
Image::CreateThumbnail
bool CreateThumbnail(int id) override
Request creation of a thumbnail.
Definition: image.cpp:219
Image::StopSync
bool StopSync(void) override
Stops the image synchronization if its running.
Definition: image.cpp:172
image.h
DTC::ImageMetadataInfoList
Definition: imageMetadataInfoList.h:15
ImageHandler::HandleScanRequest
QStringList HandleScanRequest(const QString &command, int devId=DEVICE_INVALID) const
Process scan requests.
Definition: imagemanager.cpp:1622
Image::GetImageInfo
QString GetImageInfo(int id, const QString &tag) override
Returns the value of the specified exif tag from the image file.
Definition: image.cpp:40
Image::RemoveImage
bool RemoveImage(int id) override
Deletes an image file or dir subtree from filesystem and database.
Definition: image.cpp:134
Image::GetSyncStatus
DTC::ImageSyncInfo * GetSyncStatus(void) override
Returns a list with information if the synchronization is currently running, the already synchronized...
Definition: image.cpp:186
ImageManagerBe::getInstance
static ImageManagerBe * getInstance()
Get Backend Gallery.
Definition: imagemanager.cpp:1942
Image::StartSync
bool StartSync(void) override
Starts the synchronization of the images with the database.
Definition: image.cpp:160
ImageHandler::HandleCreateThumbnails
QStringList HandleCreateThumbnails(const QStringList &message) const
Creates thumbnails on-demand.
Definition: imagemanager.cpp:1668