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  else
51  delete iconview;
52  }
53  else
54  {
55  ShowOkPopup(QCoreApplication::translate("(MythGalleryMain)",
56  "MythGallery cannot find its start directory.\n"
57  "%1\n"
58  "Check the directory exists, is readable and the setting is "
59  "correct on MythGallery's settings page.")
60  .arg(startdir.absolutePath()));
61  }
62 
63  return -1;
64 }
65 
66 static void runGallery(void)
67 {
68  run();
69 }
70 
72 {
73  run(nullptr, true);
74 }
75 
76 static void handleMedia(MythMediaDevice *dev)
77 {
78  if (! gCoreContext->GetBoolSetting("GalleryAutoLoad", false))
79  return;
80 
81  if (dev && dev->isUsable())
82  run(dev);
83 }
84 
85 static void setupKeys(void)
86 {
87  REG_JUMP("MythGallery", QT_TRANSLATE_NOOP("MythControls",
88  "Image viewer / slideshow"), "", runGallery);
89  REG_JUMP("Random Slideshow", QT_TRANSLATE_NOOP("MythControls",
90  "Start Random Slideshow in thumbnail view"), "", runRandomSlideshow);
91 
92  REG_KEY("Gallery", "PLAY", QT_TRANSLATE_NOOP("MythControls",
93  "Start/Stop Slideshow"), "P");
94  REG_KEY("Gallery", "HOME", QT_TRANSLATE_NOOP("MythControls",
95  "Go to the first image in thumbnail view"), "Home");
96  REG_KEY("Gallery", "END", QT_TRANSLATE_NOOP("MythControls",
97  "Go to the last image in thumbnail view"), "End");
98  REG_KEY("Gallery", "SLIDESHOW", QT_TRANSLATE_NOOP("MythControls",
99  "Start slideshow in thumbnail view"), "S");
100  REG_KEY("Gallery", "RANDOMSHOW", QT_TRANSLATE_NOOP("MythControls",
101  "Start random slideshow in thumbnail view"), "R");
102 #ifdef EXIF_SUPPORT
103  REG_KEY("Gallery", "SEASONALSHOW", QT_TRANSLATE_NOOP("MythControls",
104  "Start random slideshow with seasonal theme in thumbnail view"), "");
105 #endif // EXIF_SUPPORT
106 
107  REG_KEY("Gallery", "ROTRIGHT", QT_TRANSLATE_NOOP("MythControls",
108  "Rotate image right 90 degrees"), "],3");
109  REG_KEY("Gallery", "ROTLEFT", QT_TRANSLATE_NOOP("MythControls",
110  "Rotate image left 90 degrees"), "[,1");
111  REG_KEY("Gallery", "ZOOMOUT", QT_TRANSLATE_NOOP("MythControls",
112  "Zoom image out"), "7");
113  REG_KEY("Gallery", "ZOOMIN", QT_TRANSLATE_NOOP("MythControls",
114  "Zoom image in"), "9");
115  REG_KEY("Gallery", "SCROLLUP", QT_TRANSLATE_NOOP("MythControls",
116  "Scroll image up"), "2");
117  REG_KEY("Gallery", "SCROLLLEFT", QT_TRANSLATE_NOOP("MythControls",
118  "Scroll image left"), "4");
119  REG_KEY("Gallery", "SCROLLRIGHT", QT_TRANSLATE_NOOP("MythControls",
120  "Scroll image right"), "6");
121  REG_KEY("Gallery", "SCROLLDOWN", QT_TRANSLATE_NOOP("MythControls",
122  "Scroll image down"), "8");
123  REG_KEY("Gallery", "RECENTER", QT_TRANSLATE_NOOP("MythControls",
124  "Recenter image"), "5");
125  REG_KEY("Gallery", "FULLSIZE", QT_TRANSLATE_NOOP("MythControls",
126  "Full-size (un-zoom) image"), "0");
127  REG_KEY("Gallery", "UPLEFT", QT_TRANSLATE_NOOP("MythControls",
128  "Go to the upper-left corner of the image"), "PgUp");
129  REG_KEY("Gallery", "LOWRIGHT", QT_TRANSLATE_NOOP("MythControls",
130  "Go to the lower-right corner of the image"), "PgDown");
131  REG_KEY("Gallery", "MARK", QT_TRANSLATE_NOOP("MythControls",
132  "Mark image"), "T");
133  REG_KEY("Gallery", "FULLSCREEN", QT_TRANSLATE_NOOP("MythControls",
134  "Toggle scale to fullscreen/scale to fit"), "W");
135  REG_MEDIA_HANDLER(QT_TRANSLATE_NOOP("MythControls",
136  "MythGallery Media Handler 1/3"), "", handleMedia,
137  MEDIATYPE_DATA | MEDIATYPE_MIXED, QString());
138  QString filt;
139  Q_FOREACH(QString format, GalleryUtil::GetImageFilter())
140  {
141  format.remove(0,2); // Remoce "*."
142  if (filt.isEmpty())
143  filt = format;
144  else
145  filt += "," + format;
146  }
147  REG_MEDIA_HANDLER(QT_TRANSLATE_NOOP("MythControls",
148  "MythGallery Media Handler 2/3"), "", handleMedia,
149  MEDIATYPE_MGALLERY, filt);
150  filt.clear();
151  Q_FOREACH(QString format, GalleryUtil::GetMovieFilter())
152  {
153  format.remove(0,2); // Remoce "*."
154  if (filt.isEmpty())
155  filt = format;
156  else
157  filt += "," + format;
158  }
159  REG_MEDIA_HANDLER(QT_TRANSLATE_NOOP("MythControls",
160  "MythGallery Media Handler 3/3"), "", handleMedia,
161  MEDIATYPE_MVIDEO, filt);
162 }
163 
164 int mythplugin_init(const char *libversion)
165 {
166  if (!gCoreContext->TestPluginVersion("mythgallery", libversion,
168  return -1;
169 
173 
174  GallerySettings settings;
175  settings.Load();
176  settings.Save();
177 
178  setupKeys();
179 
180  return 0;
181 }
182 
183 int mythplugin_run(void)
184 {
185  return run();
186 }
187 
189 {
191  StandardSettingDialog *ssd =
192  new StandardSettingDialog(mainStack, "gallerysettings",
193  new GallerySettings());
194 
195  if (ssd->Create())
196  {
197  mainStack->AddScreen(ssd);
198  }
199  else
200  delete ssd;
201 
202  return 0;
203 }
204 
#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:174
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:582
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)