00001
00002 #include <iostream>
00003
00004
00005 #include <QDir>
00006 #include <QtPlugin>
00007
00008
00009 #include <mythcontext.h>
00010 #include <mythversion.h>
00011 #include <mythmediamonitor.h>
00012 #include <mythpluginapi.h>
00013
00014
00015 #include "config.h"
00016 #include "iconview.h"
00017 #include "gallerysettings.h"
00018 #include "dbcheck.h"
00019
00020 #ifdef DCRAW_SUPPORT
00021 Q_IMPORT_PLUGIN(dcrawplugin)
00022 #endif // DCRAW_SUPPORT
00023 void runRandomSlideshow(void);
00024
00025 static int run(MythMediaDevice *dev = NULL, bool startRandomShow = false)
00026 {
00027 QDir startdir(gCoreContext->GetSetting("GalleryDir"));
00028 if (startdir.exists() && startdir.isReadable())
00029 {
00030 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
00031
00032 IconView *iconview = new IconView(mainStack, "mythgallery",
00033 startdir.absolutePath(), dev);
00034
00035 if (iconview->Create())
00036 {
00037 if (startRandomShow)
00038 {
00039 iconview->HandleRandomShow();
00040 }
00041 else
00042 {
00043 mainStack->AddScreen(iconview);
00044 }
00045 return 0;
00046 }
00047 else
00048 delete iconview;
00049 }
00050 else
00051 {
00052 ShowOkPopup(QObject::tr("MythGallery cannot find its start directory."
00053 "\n%1\n"
00054 "Check the directory exists, is readable and "
00055 "the setting is correct on MythGallery's "
00056 "settings page.")
00057 .arg(startdir.absolutePath()));
00058 }
00059
00060 return -1;
00061 }
00062
00063 static void runGallery(void)
00064 {
00065 run();
00066 }
00067
00068 void runRandomSlideshow(void)
00069 {
00070 run(NULL, true);
00071 }
00072
00073 static void handleMedia(MythMediaDevice *dev)
00074 {
00075 if (! gCoreContext->GetNumSetting("GalleryAutoLoad", 0))
00076 return;
00077
00078 if (dev && dev->isUsable())
00079 {
00080 GetMythMainWindow()->JumpTo("Main Menu");
00081 run(dev);
00082 }
00083 }
00084
00085 static void setupKeys(void)
00086 {
00087 REG_JUMP("MythGallery", QT_TRANSLATE_NOOP("MythControls",
00088 "Image viewer / slideshow"), "", runGallery);
00089 REG_JUMP("Random Slideshow", QT_TRANSLATE_NOOP("MythControls",
00090 "Start Random Slideshow in thumbnail view"), "", runRandomSlideshow);
00091
00092 REG_KEY("Gallery", "PLAY", QT_TRANSLATE_NOOP("MythControls",
00093 "Start/Stop Slideshow"), "P");
00094 REG_KEY("Gallery", "HOME", QT_TRANSLATE_NOOP("MythControls",
00095 "Go to the first image in thumbnail view"), "Home");
00096 REG_KEY("Gallery", "END", QT_TRANSLATE_NOOP("MythControls",
00097 "Go to the last image in thumbnail view"), "End");
00098 REG_KEY("Gallery", "SLIDESHOW", QT_TRANSLATE_NOOP("MythControls",
00099 "Start Slideshow in thumbnail view"), "S");
00100 REG_KEY("Gallery", "RANDOMSHOW", QT_TRANSLATE_NOOP("MythControls",
00101 "Start Random Slideshow in thumbnail view"), "R");
00102
00103 REG_KEY("Gallery", "ROTRIGHT", QT_TRANSLATE_NOOP("MythControls",
00104 "Rotate image right 90 degrees"), "],3");
00105 REG_KEY("Gallery", "ROTLEFT", QT_TRANSLATE_NOOP("MythControls",
00106 "Rotate image left 90 degrees"), "[,1");
00107 REG_KEY("Gallery", "ZOOMOUT", QT_TRANSLATE_NOOP("MythControls",
00108 "Zoom image out"), "7");
00109 REG_KEY("Gallery", "ZOOMIN", QT_TRANSLATE_NOOP("MythControls",
00110 "Zoom image in"), "9");
00111 REG_KEY("Gallery", "SCROLLUP", QT_TRANSLATE_NOOP("MythControls",
00112 "Scroll image up"), "2");
00113 REG_KEY("Gallery", "SCROLLLEFT", QT_TRANSLATE_NOOP("MythControls",
00114 "Scroll image left"), "4");
00115 REG_KEY("Gallery", "SCROLLRIGHT", QT_TRANSLATE_NOOP("MythControls",
00116 "Scroll image right"), "6");
00117 REG_KEY("Gallery", "SCROLLDOWN", QT_TRANSLATE_NOOP("MythControls",
00118 "Scroll image down"), "8");
00119 REG_KEY("Gallery", "RECENTER", QT_TRANSLATE_NOOP("MythControls",
00120 "Recenter image"), "5");
00121 REG_KEY("Gallery", "FULLSIZE", QT_TRANSLATE_NOOP("MythControls",
00122 "Full-size (un-zoom) image"), "0");
00123 REG_KEY("Gallery", "UPLEFT", QT_TRANSLATE_NOOP("MythControls",
00124 "Go to the upper-left corner of the image"), "PgUp");
00125 REG_KEY("Gallery", "LOWRIGHT", QT_TRANSLATE_NOOP("MythControls",
00126 "Go to the lower-right corner of the image"), "PgDown");
00127 REG_KEY("Gallery", "MARK", QT_TRANSLATE_NOOP("MythControls",
00128 "Mark image"), "T");
00129 REG_KEY("Gallery", "FULLSCREEN", QT_TRANSLATE_NOOP("MythControls",
00130 "Toggle scale to fullscreen/scale to fit"), "W");
00131 REG_MEDIA_HANDLER(QT_TRANSLATE_NOOP("MythControls",
00132 "MythGallery Media Handler 1/2"), "", "", handleMedia,
00133 MEDIATYPE_DATA | MEDIATYPE_MIXED, QString::null);
00134 REG_MEDIA_HANDLER(QT_TRANSLATE_NOOP("MythControls",
00135 "MythGallery Media Handler 2/2"), "", "", handleMedia,
00136 MEDIATYPE_MGALLERY, "gif,jpg,png");
00137 }
00138
00139 int mythplugin_init(const char *libversion)
00140 {
00141 if (!gContext->TestPopupVersion("mythgallery", libversion,
00142 MYTH_BINARY_VERSION))
00143 return -1;
00144
00145 gCoreContext->ActivateSettingsCache(false);
00146 UpgradeGalleryDatabaseSchema();
00147 gCoreContext->ActivateSettingsCache(true);
00148
00149 GallerySettings settings;
00150 settings.Load();
00151 settings.Save();
00152
00153 setupKeys();
00154
00155 return 0;
00156 }
00157
00158 int mythplugin_run(void)
00159 {
00160 return run();
00161 }
00162
00163 int mythplugin_config(void)
00164 {
00165 GallerySettings settings;
00166 settings.exec();
00167
00168 return 0;
00169 }
00170