MythTV  master
mythplugins/mythgallery/mythgallery/main.cpp
Go to the documentation of this file.
1 // c++
2 #include <iostream>
3 
4 // qt
5 #include <QDir>
6 #include <QtPlugin>
7 #include <QImageReader>
8 #include <QCoreApplication>
9 
10 // myth
11 #include <mythcontext.h>
12 #include <mythversion.h>
13 #include <mythmediamonitor.h>
14 #include <mythpluginapi.h>
15 
16 // mythgallery
17 #include "config.h"
18 #include "iconview.h"
19 #include "gallerysettings.h"
20 #include "galleryutil.h"
21 #include "dbcheck.h"
22 
23 #ifdef DCRAW_SUPPORT
24 Q_IMPORT_PLUGIN(DcrawPlugin)
25 #endif // DCRAW_SUPPORT
26 void runRandomSlideshow(void);
27 
28 static int run(MythMediaDevice *dev = nullptr, bool startRandomShow = false)
29 {
30  QDir startdir(gCoreContext->GetSetting("GalleryDir"));
31  if (startdir.exists() && startdir.isReadable())
32  {
34 
35  IconView *iconview = new IconView(mainStack, "mythgallery",
36  startdir.absolutePath(), dev);
37 
38  if (iconview->Create())
39  {
40  if (startRandomShow)
41  {
42  iconview->HandleRandomShow();
43  }
44  else
45  {
46  mainStack->AddScreen(iconview);
47  }
48  return 0;
49  }
50  delete iconview;
51  }
52  else
53  {
54  ShowOkPopup(QCoreApplication::translate("(MythGalleryMain)",
55  "MythGallery cannot find its start directory.\n"
56  "%1\n"
57  "Check the directory exists, is readable and the setting is "
58  "correct on MythGallery's settings page.")
59  .arg(startdir.absolutePath()));
60  }
61 
62  return -1;
63 }
64 
65 static void runGallery(void)
66 {
67  run();
68 }
69 
71 {
72  run(nullptr, true);
73 }
74 
75 static void handleMedia(MythMediaDevice *dev)
76 {
77  if (! gCoreContext->GetBoolSetting("GalleryAutoLoad", false))
78  return;
79 
80  if (dev && dev->isUsable())
81  run(dev);
82 }
83 
84 static void setupKeys(void)
85 {
86  REG_JUMP("MythGallery", QT_TRANSLATE_NOOP("MythControls",
87  "Image viewer / slideshow"), "", runGallery);
88  REG_JUMP("Random Slideshow", QT_TRANSLATE_NOOP("MythControls",
89  "Start Random Slideshow in thumbnail view"), "", runRandomSlideshow);
90 
91  REG_KEY("Gallery", "PLAY", QT_TRANSLATE_NOOP("MythControls",
92  "Start/Stop Slideshow"), "P");
93  REG_KEY("Gallery", "HOME", QT_TRANSLATE_NOOP("MythControls",
94  "Go to the first image in thumbnail view"), "Home");
95  REG_KEY("Gallery", "END", QT_TRANSLATE_NOOP("MythControls",
96  "Go to the last image in thumbnail view"), "End");
97  REG_KEY("Gallery", "SLIDESHOW", QT_TRANSLATE_NOOP("MythControls",
98  "Start slideshow in thumbnail view"), "S");
99  REG_KEY("Gallery", "RANDOMSHOW", QT_TRANSLATE_NOOP("MythControls",
100  "Start random slideshow in thumbnail view"), "R");
101 #ifdef EXIF_SUPPORT
102  REG_KEY("Gallery", "SEASONALSHOW", QT_TRANSLATE_NOOP("MythControls",
103  "Start random slideshow with seasonal theme in thumbnail view"), "");
104 #endif // EXIF_SUPPORT
105 
106  REG_KEY("Gallery", "ROTRIGHT", QT_TRANSLATE_NOOP("MythControls",
107  "Rotate image right 90 degrees"), "],3");
108  REG_KEY("Gallery", "ROTLEFT", QT_TRANSLATE_NOOP("MythControls",
109  "Rotate image left 90 degrees"), "[,1");
110  REG_KEY("Gallery", "ZOOMOUT", QT_TRANSLATE_NOOP("MythControls",
111  "Zoom image out"), "7");
112  REG_KEY("Gallery", "ZOOMIN", QT_TRANSLATE_NOOP("MythControls",
113  "Zoom image in"), "9");
114  REG_KEY("Gallery", "SCROLLUP", QT_TRANSLATE_NOOP("MythControls",
115  "Scroll image up"), "2");
116  REG_KEY("Gallery", "SCROLLLEFT", QT_TRANSLATE_NOOP("MythControls",
117  "Scroll image left"), "4");
118  REG_KEY("Gallery", "SCROLLRIGHT", QT_TRANSLATE_NOOP("MythControls",
119  "Scroll image right"), "6");
120  REG_KEY("Gallery", "SCROLLDOWN", QT_TRANSLATE_NOOP("MythControls",
121  "Scroll image down"), "8");
122  REG_KEY("Gallery", "RECENTER", QT_TRANSLATE_NOOP("MythControls",
123  "Recenter image"), "5");
124  REG_KEY("Gallery", "FULLSIZE", QT_TRANSLATE_NOOP("MythControls",
125  "Full-size (un-zoom) image"), "0");
126  REG_KEY("Gallery", "UPLEFT", QT_TRANSLATE_NOOP("MythControls",
127  "Go to the upper-left corner of the image"), "PgUp");
128  REG_KEY("Gallery", "LOWRIGHT", QT_TRANSLATE_NOOP("MythControls",
129  "Go to the lower-right corner of the image"), "PgDown");
130  REG_KEY("Gallery", "MARK", QT_TRANSLATE_NOOP("MythControls",
131  "Mark image"), "T");
132  REG_KEY("Gallery", "FULLSCREEN", QT_TRANSLATE_NOOP("MythControls",
133  "Toggle scale to fullscreen/scale to fit"), "W");
134  REG_MEDIA_HANDLER(QT_TRANSLATE_NOOP("MythControls",
135  "MythGallery Media Handler 1/3"), "", handleMedia,
136  MEDIATYPE_DATA | MEDIATYPE_MIXED, QString());
137  QString filt;
138  Q_FOREACH(QString format, GalleryUtil::GetImageFilter())
139  {
140  format.remove(0,2); // Remoce "*."
141  if (filt.isEmpty())
142  filt = format;
143  else
144  filt += "," + format;
145  }
146  REG_MEDIA_HANDLER(QT_TRANSLATE_NOOP("MythControls",
147  "MythGallery Media Handler 2/3"), "", handleMedia,
148  MEDIATYPE_MGALLERY, filt);
149  filt.clear();
150  Q_FOREACH(QString format, GalleryUtil::GetMovieFilter())
151  {
152  format.remove(0,2); // Remoce "*."
153  if (filt.isEmpty())
154  filt = format;
155  else
156  filt += "," + format;
157  }
158  REG_MEDIA_HANDLER(QT_TRANSLATE_NOOP("MythControls",
159  "MythGallery Media Handler 3/3"), "", handleMedia,
160  MEDIATYPE_MVIDEO, filt);
161 }
162 
163 int mythplugin_init(const char *libversion)
164 {
165  if (!gCoreContext->TestPluginVersion("mythgallery", libversion,
167  return -1;
168 
172 
173  GallerySettings settings;
174  settings.Load();
175  settings.Save();
176 
177  setupKeys();
178 
179  return 0;
180 }
181 
182 int mythplugin_run(void)
183 {
184  return run();
185 }
186 
188 {
190  StandardSettingDialog *ssd =
191  new StandardSettingDialog(mainStack, "gallerysettings",
192  new GallerySettings());
193 
194  if (ssd->Create())
195  {
196  mainStack->AddScreen(ssd);
197  }
198  else
199  delete ssd;
200 
201  return 0;
202 }
203 
#define REG_JUMP(a, b, c, d)
#define REG_MEDIA_HANDLER(a, b, c, d, e)
MythConfirmationDialog * ShowOkPopup(const QString &message, QObject *parent, const char *slot, bool showCancel)
Non-blocking version of MythPopupBox::showOkPopup()
bool Create(void) override
Definition: iconview.cpp:163
virtual void Load(void)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
MythScreenStack * GetMainStack()
#define REG_KEY(a, b, c, d)
bool TestPluginVersion(const QString &name, const QString &libversion, const QString &pluginversion)
static int run(MythMediaDevice *dev=nullptr, bool startRandomShow=false)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
QString GetSetting(const QString &key, const QString &defaultval="")
static void runGallery(void)
MythMainWindow * GetMythMainWindow(void)
static void handleMedia(MythMediaDevice *dev)
virtual void Save(void)
static void setupKeys(void)
void HandleRandomShow(void)
Definition: iconview.cpp:569
static QStringList GetMovieFilter(void)
Definition: galleryutil.cpp:74
bool Create(void) override
bool GetBoolSetting(const QString &key, bool defaultval=false)
int mythplugin_init(const char *libversion)
#define MYTH_BINARY_VERSION
Update this whenever the plug-in ABI changes.
Definition: mythversion.h:16
bool isUsable() const
Is this device "ready", for a plugin to access?
Definition: mythmedia.h:84
static QStringList GetImageFilter(void)
Definition: galleryutil.cpp:58
void ActivateSettingsCache(bool activate=true)