File: InfoTagPicture.cpp

package info (click to toggle)
kodi 2%3A20.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 143,820 kB
  • sloc: cpp: 664,925; xml: 68,398; ansic: 37,223; python: 6,903; sh: 4,209; javascript: 2,325; makefile: 1,754; perl: 969; java: 513; cs: 390; objc: 340
file content (98 lines) | stat: -rw-r--r-- 2,802 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 *  Copyright (C) 2021 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#include "InfoTagPicture.h"

#include "AddonUtils.h"
#include "guilib/guiinfo/GUIInfoLabels.h"
#include "interfaces/legacy/Exception.h"
#include "pictures/PictureInfoTag.h"
#include "utils/StringUtils.h"

using namespace XBMCAddonUtils;

namespace XBMCAddon
{
namespace xbmc
{

InfoTagPicture::InfoTagPicture(bool offscreen /* = false */)
  : infoTag(new CPictureInfoTag), offscreen(offscreen), owned(true)
{
}

InfoTagPicture::InfoTagPicture(const CPictureInfoTag* tag)
  : infoTag(new CPictureInfoTag(*tag)), offscreen(true), owned(true)
{
}

InfoTagPicture::InfoTagPicture(CPictureInfoTag* tag, bool offscreen /* = false */)
  : infoTag(tag), offscreen(offscreen), owned(false)
{
}

InfoTagPicture::~InfoTagPicture()
{
  if (owned)
    delete infoTag;
}

String InfoTagPicture::getResolution()
{
  return infoTag->GetInfo(SLIDESHOW_RESOLUTION);
}

String InfoTagPicture::getDateTimeTaken()
{
  return infoTag->GetDateTimeTaken().GetAsW3CDateTime();
}

void InfoTagPicture::setResolution(int width, int height)
{
  XBMCAddonUtils::GuiLock lock(languageHook, offscreen);
  setResolutionRaw(infoTag, width, height);
}

void InfoTagPicture::setDateTimeTaken(const String& datetimetaken)
{
  XBMCAddonUtils::GuiLock lock(languageHook, offscreen);
  setDateTimeTakenRaw(infoTag, datetimetaken);
}

void InfoTagPicture::setResolutionRaw(CPictureInfoTag* infoTag, const String& resolution)
{
  infoTag->SetInfo("resolution", resolution);
}

void InfoTagPicture::setResolutionRaw(CPictureInfoTag* infoTag, int width, int height)
{
  if (width <= 0)
    throw WrongTypeException("InfoTagPicture.setResolution: width must be greater than zero (0)");
  if (height <= 0)
    throw WrongTypeException("InfoTagPicture.setResolution: height must be greater than zero (0)");

  setResolutionRaw(infoTag, StringUtils::Format("{:d},{:d}", width, height));
}

void InfoTagPicture::setDateTimeTakenRaw(CPictureInfoTag* infoTag, String datetimetaken)
{
  // try to parse the datetimetaken as from W3C format and adjust it to the EXIF datetime format YYYY:MM:DD HH:MM:SS
  CDateTime w3cDateTimeTaken;
  if (w3cDateTimeTaken.SetFromW3CDateTime(datetimetaken))
  {
    datetimetaken = StringUtils::Format("{:4d}:{:2d}:{:2d} {:2d}:{:2d}:{:2d}",
                                        w3cDateTimeTaken.GetYear(), w3cDateTimeTaken.GetMonth(),
                                        w3cDateTimeTaken.GetDay(), w3cDateTimeTaken.GetHour(),
                                        w3cDateTimeTaken.GetMinute(), w3cDateTimeTaken.GetSecond());
  }

  infoTag->SetInfo("exiftime", datetimetaken);
}

} // namespace xbmc
} // namespace XBMCAddon