/* * Cantata * * Copyright (c) 2011-2012 Craig Drummond * */ /* This file is part of Clementine. Copyright 2010, David Sansome Clementine is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Clementine is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Clementine. If not, see . */ #include "cachesettings.h" #include "localize.h" #include "lyricspage.h" #include "covers.h" #include "musiclibrarymodel.h" #include "utils.h" #include "messagebox.h" #include #include #include #include #include #include #include #include static const int constMaxRecurseLevel=4; static void calculate(const QString &d, const QStringList &types, int &items, int &space, int level=0) { if (levelstart(); } CacheItemCounter::~CacheItemCounter() { if (thread) { Utils::stopThread(thread); } } void CacheItemCounter::getCount() { int items=0; int space=0; calculate(dir, types, items, space); emit count(items, space); } void CacheItemCounter::deleteAll() { ::deleteAll(dir, types); getCount(); } CacheItem::CacheItem(const QString &title, const QString &d, const QStringList &t, QWidget *p) : QGroupBox(p) , calculated(false) , counter(new CacheItemCounter(d, t)) { setTitle(title); QFormLayout *layout=new QFormLayout(this); button=new QPushButton(i18n("Delete All"), this); button->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); button->setEnabled(false); connect(this, SIGNAL(getCount()), counter, SLOT(getCount()), Qt::QueuedConnection); connect(this, SIGNAL(deleteAll()), counter, SLOT(deleteAll()), Qt::QueuedConnection); connect(counter, SIGNAL(count(int, int)), this, SLOT(update(int, int)), Qt::QueuedConnection); connect(button, SIGNAL(clicked(bool)), this, SLOT(deleteAllItems())); numItems=new QLabel(this); spaceUsed=new QLabel(this); layout->addRow(i18n("Number of items:"), numItems); layout->addRow(i18n("Space used:"), spaceUsed); layout->setWidget(2, QFormLayout::FieldRole, button); numItems->setText(i18n("Calculating...")); spaceUsed->setText(i18n("Calculating...")); } CacheItem::~CacheItem() { } void CacheItem::showEvent(QShowEvent *e) { if (!calculated) { emit getCount(); calculated=true; } QGroupBox::showEvent(e); } void CacheItem::deleteAllItems() { if (MessageBox::Yes==MessageBox::warningYesNo(this, i18n("Delete all cached items?"), title())) { emit deleteAll(); } } void CacheItem::update(int itemCount, int space) { numItems->setText(QString::number(itemCount)); spaceUsed->setText(Utils::formatByteSize(space)); button->setEnabled(itemCount>0); } CacheSettings::CacheSettings(QWidget *parent) : QWidget(parent) { int spacing=style()->layoutSpacing(QSizePolicy::DefaultType, QSizePolicy::DefaultType, Qt::Vertical); if (spacing<0) { spacing=4; } QVBoxLayout *layout=new QVBoxLayout(this); layout->setMargin(0); QLabel *label=new QLabel(i18n("To speed up loading of the music library, Cantata caches a local copy of the MPD listing. Cantata might also have cached " "covers, or lyrics, if these have been downloaded and could not be saved into the MPD folder (because Cantata cannot access it, " "or you have configured Cantata to not save these items there). Below is a summary of Cantata's cache usage."), this); label->setWordWrap(true); layout->addWidget(label); layout->addSpacing(spacing); layout->addWidget(new CacheItem(i18n("Covers"), Utils::cacheDir(Covers::constCoverDir, false), QStringList() << "*.jpg" << "*.png", this)); layout->addWidget(new CacheItem(i18n("Lyrics"), Utils::cacheDir(LyricsPage::constLyricsDir, false), QStringList() << "*"+LyricsPage::constExtension, this)); layout->addWidget(new CacheItem(i18n("Music Library List"), Utils::cacheDir(MusicLibraryModel::constLibraryCache, false), QStringList() << "*"+MusicLibraryModel::constLibraryExt << "*"+MusicLibraryModel::constLibraryCompressedExt, this)); layout->addSpacerItem(new QSpacerItem(0, 8, QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); } CacheSettings::~CacheSettings() { }