Ticket #48: gallery.thumbnaillocation.patch
File gallery.thumbnaillocation.patch, 4.8 KB (added by , 19 years ago) |
---|
-
mythgallery/mythgallery/gallerysettings.cpp
21 21 return gc; 22 22 }; 23 23 24 static HostCheckBox *MythGalleryThumbnailLocation() 25 { 26 HostCheckBox *gc = new HostCheckBox("GalleryThumbnailLocation"); 27 gc->setLabel(QObject::tr("Store thumbnails in image directory")); 28 gc->setValue(1); 29 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.")); 30 return gc; 31 }; 32 24 33 static HostLineEdit *MythGalleryMoviePlayerCmd() 25 34 { 26 35 HostLineEdit *gc = new HostLineEdit("GalleryMoviePlayerCmd"); … … 132 141 setUseLabel(false); 133 142 134 143 addChild(MythGalleryDir()); 144 addChild(MythGalleryThumbnailLocation()); 135 145 addChild(MythGalleryImportDirs()); 136 146 addChild(MythGalleryMoviePlayerCmd()); 137 147 -
mythgallery/mythgallery/iconview.cpp
602 602 else 603 603 m_isGallery = false; 604 604 605 QFileInfo cdir(d.absPath() + "/.thumbcache"); 606 if (!cdir.exists()) 607 d.mkdir(".thumbcache"); 605 // Create .thumbcache dir if neccesary 606 m_thumbGen->getThumbcacheDir(m_currDir); 608 607 609 608 d.setNameFilter(MEDIA_FILENAMES); 610 609 d.setSorting(QDir::Name | QDir::DirsFirst | QDir::IgnoreCase); … … 686 685 } 687 686 688 687 if (!canLoadGallery) { 689 QString cachePath = m_currDir + QString("/.thumbcache/") + 690 item->name; 688 QString cachePath = m_thumbGen->getThumbcacheDir(m_currDir) + item->name; 691 689 image.load(cachePath); 692 690 } 693 691 -
mythgallery/mythgallery/thumbgenerator.cpp
104 104 105 105 if (!isGallery) { 106 106 107 QString cachePath = dir + QString("/.thumbcache/") + file;107 QString cachePath = getThumbcacheDir(dir) + file; 108 108 QFileInfo cacheInfo(cachePath); 109 109 110 110 if (cacheInfo.exists() && … … 276 276 image.load(fi.absFilePath()); 277 277 } 278 278 } 279 280 QString ThumbGenerator::getThumbcacheDir(const QString& inDir) 281 { 282 // For directory "/my/images/january", this function either returns 283 // "/my/images/january/.thumbcache" or "~/.mythtv/mythgallery/january/.thumbcache" 284 QString aPath = inDir + QString("/.thumbcache/"); 285 if ( gContext->GetNumSetting("GalleryThumbnailLocation") 286 && ! QDir(aPath).exists() ) 287 { 288 mkpath(aPath); 289 } 290 if ( ! gContext->GetNumSetting("GalleryThumbnailLocation") || ! QDir(aPath).exists() ) 291 { 292 // Arrive here if storing thumbs in home dir, 293 // OR failed to create thumb dir in gallery pics location 294 int prefixLen = gContext->GetSetting("GalleryDir").length(); 295 aPath = gContext->GetConfDir() + "/MythGallery"; 296 aPath += inDir.right(inDir.length() - prefixLen); 297 aPath += QString("/.thumbcache/"); 298 mkpath(aPath); 299 } 300 301 return aPath; 302 } 303 304 bool ThumbGenerator::mkpath(const QString& inPath) 305 { 306 // The function will create all parent directories necessary to create the directory. 307 // We can replace this function with QDir::mkpath() when uprading to Qt 4.0 308 int i = 0; 309 QString absPath = QDir(inPath).absPath() + "/"; 310 QDir parent("/"); 311 do { 312 i = absPath.find('/', i + 1); 313 if (i == -1) { 314 return true; 315 } 316 QString subPath(absPath.left(i)); 317 if (! QDir(subPath).exists()) { 318 if (! parent.mkdir(subPath.right(subPath.length() - parent.absPath().length() - 1))) { 319 return false; 320 } 321 } 322 parent = QDir(subPath); 323 } while(true); 324 } -
mythgallery/mythgallery/thumbgenerator.h
45 45 void setDirectory(const QString& directory, bool isGallery=false); 46 46 void addFile(const QString& fileName); 47 47 void cancel(); 48 49 QString getThumbcacheDir(const QString& inDir); 48 50 49 51 protected: 50 52 … … 57 59 bool checkGalleryFile(const QFileInfo& fi); 58 60 void loadDir(QImage& image, const QFileInfo& fi); 59 61 void loadFile(QImage& image, const QFileInfo& fi); 62 63 bool mkpath(const QString& inPath); 60 64 61 65 QObject *m_parent; 62 66 QString m_directory;