Ticket #48: gallery.thumbnaillocation.patch

File gallery.thumbnaillocation.patch, 4.8 KB (added by anonymous, 19 years ago)
  • mythgallery/mythgallery/gallerysettings.cpp

     
    2121    return gc;
    2222};
    2323
     24static 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
    2433static HostLineEdit *MythGalleryMoviePlayerCmd()
    2534{
    2635    HostLineEdit *gc = new HostLineEdit("GalleryMoviePlayerCmd");
     
    132141        setUseLabel(false);
    133142
    134143        addChild(MythGalleryDir());
     144        addChild(MythGalleryThumbnailLocation());
    135145        addChild(MythGalleryImportDirs());
    136146        addChild(MythGalleryMoviePlayerCmd());
    137147
  • mythgallery/mythgallery/iconview.cpp

     
    602602    else
    603603        m_isGallery = false;
    604604
    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);
    608607
    609608    d.setNameFilter(MEDIA_FILENAMES);
    610609    d.setSorting(QDir::Name | QDir::DirsFirst | QDir::IgnoreCase);
     
    686685    }
    687686
    688687    if (!canLoadGallery) {
    689         QString cachePath = m_currDir + QString("/.thumbcache/") +
    690                             item->name;
     688        QString cachePath = m_thumbGen->getThumbcacheDir(m_currDir) + item->name;
    691689        image.load(cachePath);
    692690    }
    693691
  • mythgallery/mythgallery/thumbgenerator.cpp

     
    104104
    105105        if (!isGallery) {
    106106       
    107             QString cachePath = dir + QString("/.thumbcache/") + file;
     107            QString cachePath = getThumbcacheDir(dir) + file;
    108108            QFileInfo cacheInfo(cachePath);
    109109
    110110            if (cacheInfo.exists() &&
     
    276276      image.load(fi.absFilePath());
    277277  }
    278278}
     279
     280QString 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
     304bool 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

     
    4545    void setDirectory(const QString& directory, bool isGallery=false);
    4646    void addFile(const QString& fileName);
    4747    void cancel();
     48   
     49    QString getThumbcacheDir(const QString& inDir);
    4850
    4951protected:
    5052
     
    5759    bool checkGalleryFile(const QFileInfo& fi);
    5860    void loadDir(QImage& image, const QFileInfo& fi);
    5961    void loadFile(QImage& image, const QFileInfo& fi);
     62   
     63    bool mkpath(const QString& inPath);
    6064
    6165    QObject     *m_parent;
    6266    QString      m_directory;