Index: mythgallery/mythgallery/gallerysettings.cpp
===================================================================
--- mythgallery/mythgallery/gallerysettings.cpp	(revision 6764)
+++ mythgallery/mythgallery/gallerysettings.cpp	(working copy)
@@ -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/mythgallery/iconview.cpp
===================================================================
--- mythgallery/mythgallery/iconview.cpp	(revision 6764)
+++ mythgallery/mythgallery/iconview.cpp	(working copy)
@@ -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/mythgallery/thumbgenerator.cpp
===================================================================
--- mythgallery/mythgallery/thumbgenerator.cpp	(revision 6764)
+++ mythgallery/mythgallery/thumbgenerator.cpp	(working copy)
@@ -104,7 +104,7 @@
 
         if (!isGallery) {
         
-            QString cachePath = dir + QString("/.thumbcache/") + file;
+            QString cachePath = getThumbcacheDir(dir) + file;
             QFileInfo cacheInfo(cachePath);
 
             if (cacheInfo.exists() &&
@@ -276,3 +276,49 @@
       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() )
+    {
+        mkpath(aPath);
+    }
+    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/");
+        mkpath(aPath);
+    }
+    
+    return aPath;
+}
+
+bool ThumbGenerator::mkpath(const QString& inPath)
+{
+    // The function will create all parent directories necessary to create the directory.
+    // We can replace this function with QDir::mkpath() when uprading to Qt 4.0
+    int i = 0;
+    QString absPath = QDir(inPath).absPath() + "/";
+    QDir parent("/");
+    do {
+        i = absPath.find('/', i + 1);
+        if (i == -1) {
+            return true;
+        }
+        QString subPath(absPath.left(i));
+        if (! QDir(subPath).exists()) {
+            if (! parent.mkdir(subPath.right(subPath.length() - parent.absPath().length() - 1))) {
+                return false;
+            }
+        }
+        parent = QDir(subPath);
+    } while(true);
+}
Index: mythgallery/mythgallery/thumbgenerator.h
===================================================================
--- mythgallery/mythgallery/thumbgenerator.h	(revision 6764)
+++ mythgallery/mythgallery/thumbgenerator.h	(working copy)
@@ -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:
 
@@ -57,6 +59,8 @@
     bool checkGalleryFile(const QFileInfo& fi);
     void loadDir(QImage& image, const QFileInfo& fi);
     void loadFile(QImage& image, const QFileInfo& fi);
+    
+    bool mkpath(const QString& inPath);
 
     QObject     *m_parent;
     QString      m_directory;
