On 15.4.2005, at 22:20, Eggert Thorlacius wrote:
This small patch adds a checkbox to the MythGallery Settings page
where the user can choose between the current functionality of
storing .thumbcache directories inside the image directory or storing
them in ~/.mythtv/mythgallery/
This makes it possible to use MythGallery to browse a read-only
directory
I'm not sure if there was a reason why this patch never made it to CVS,
but it works really nicely for me (I mount my photos share read-only for
safety...).
I have modified it so that actually the settings flag acts as an
over-ride, but actually it also uses the local home dir if it finds that
the gallery dir is read-only for any reason. This means that you can
eithe force it locally or let it auto-detect. Perhaps this removes one
of the main objections from before?
Ed W
Index: mythgallery/gallerysettings.cpp
===================================================================
RCS file:
/var/lib/mythcvs/mythplugins/mythgallery/mythgallery/gallerysettings.cpp,v
retrieving revision 1.12
diff -u -r1.12 gallerysettings.cpp
--- mythgallery/gallerysettings.cpp 30 Jan 2005 16:11:49 -0000 1.12
+++ mythgallery/gallerysettings.cpp 23 May 2005 14:12:18 -0000
@@ -21,6 +21,15 @@
return gc;
};
+static HostCheckBox *MythGalleryThumbnailLocation()
+{
+ HostCheckBox *gc = new HostCheckBox("GalleryThumbnailLocation");
+ gc->setLabel(QObject::tr("Store thumbnails in image directory"));
+ gc->setValue(1);
+ gc->setHelpText(QObject::tr("If set, thumbnails are stored in
'.thumbcache' directories within the above directory. If cleared, they are
stored in your home directory."));
+ return gc;
+};
+
static HostLineEdit *MythGalleryMoviePlayerCmd()
{
HostLineEdit *gc = new HostLineEdit("GalleryMoviePlayerCmd");
@@ -132,6 +141,7 @@
setUseLabel(false);
addChild(MythGalleryDir());
+ addChild(MythGalleryThumbnailLocation());
addChild(MythGalleryImportDirs());
addChild(MythGalleryMoviePlayerCmd());
Index: mythgallery/iconview.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythplugins/mythgallery/mythgallery/iconview.cpp,v
retrieving revision 1.39
diff -u -r1.39 iconview.cpp
--- mythgallery/iconview.cpp 24 Feb 2005 21:21:35 -0000 1.39
+++ mythgallery/iconview.cpp 23 May 2005 14:12:19 -0000
@@ -602,9 +602,8 @@
else
m_isGallery = false;
- QFileInfo cdir(d.absPath() + "/.thumbcache");
- if (!cdir.exists())
- d.mkdir(".thumbcache");
+ // Create .thumbcache dir if neccesary
+ m_thumbGen->getThumbcacheDir(m_currDir);
d.setNameFilter(MEDIA_FILENAMES);
d.setSorting(QDir::Name | QDir::DirsFirst | QDir::IgnoreCase);
@@ -686,8 +685,7 @@
}
if (!canLoadGallery) {
- QString cachePath = m_currDir + QString("/.thumbcache/") +
- item->name;
+ QString cachePath = m_thumbGen->getThumbcacheDir(m_currDir) +
item->name;
image.load(cachePath);
}
Index: mythgallery/thumbgenerator.cpp
===================================================================
RCS file:
/var/lib/mythcvs/mythplugins/mythgallery/mythgallery/thumbgenerator.cpp,v
retrieving revision 1.6
diff -u -r1.6 thumbgenerator.cpp
--- mythgallery/thumbgenerator.cpp 31 Jan 2005 06:27:43 -0000 1.6
+++ mythgallery/thumbgenerator.cpp 23 May 2005 14:12:20 -0000
@@ -103,7 +103,7 @@
if (!isGallery) {
- QString cachePath = dir + QString("/.thumbcache/") + file;
+ QString cachePath = getThumbcacheDir(dir) + file;
QFileInfo cacheInfo(cachePath);
if (cacheInfo.exists() &&
@@ -275,3 +275,33 @@
image.load(fi.absFilePath());
}
}
+
+QString ThumbGenerator::getThumbcacheDir(const QString& inDir)
+{
+ // For directory "/my/images/january", this function either returns
+ // "/my/images/january/.thumbcache" or
"~/.mythtv/mythgallery/january/.thumbcache"
+ QString aPath = inDir + QString("/.thumbcache/");
+ if ( gContext->GetNumSetting("GalleryThumbnailLocation")
+ && ! QDir(aPath).exists() )
+ {
+ QString cmd = "mkdir -p '" + aPath + "'"; // create dir and all its
parents
+ system(cmd);
+ }
+ if ( ! gContext->GetNumSetting("GalleryThumbnailLocation") || !
QDir(aPath).exists() )
+ {
+ // Arrive here if storing thumbs in home dir,
+ // OR failed to create thumb dir in gallery pics location
+ int prefixLen = gContext->GetSetting("GalleryDir").length();
+ aPath = gContext->GetConfDir() + "/MythGallery";
+ aPath += inDir.right(inDir.length() - prefixLen);
+ aPath += QString("/.thumbcache/");
+
+ if ( ! QDir(aPath).exists() )
+ {
+ QString cmd = "mkdir -p '" + aPath + "'"; // create dir and all
its parents
+ system(cmd);
+ }
+ }
+
+ return aPath;
+}
Index: mythgallery/thumbgenerator.h
===================================================================
RCS file:
/var/lib/mythcvs/mythplugins/mythgallery/mythgallery/thumbgenerator.h,v
retrieving revision 1.2
diff -u -r1.2 thumbgenerator.h
--- mythgallery/thumbgenerator.h 17 Jan 2004 18:10:22 -0000 1.2
+++ mythgallery/thumbgenerator.h 23 May 2005 14:12:20 -0000
@@ -45,6 +45,8 @@
void setDirectory(const QString& directory, bool isGallery=false);
void addFile(const QString& fileName);
void cancel();
+
+ QString getThumbcacheDir(const QString& inDir);
protected:
_______________________________________________
mythtv-dev mailing list
[email protected]
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev