Skip to content

Commit

Permalink
fix fallback icon theme
Browse files Browse the repository at this point in the history
  • Loading branch information
rodlie committed May 18, 2018
1 parent d4dda41 commit b613444
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
30 changes: 30 additions & 0 deletions fm/src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <QTextStream>
#include <QMap>
#include <QMapIterator>
#include <QDirIterator>

#define FM_MAJOR 6

Expand Down Expand Up @@ -268,6 +269,35 @@ class Common
}
return result;
}
static QStringList getIconThemes()
{
QStringList result;
for (int i=0;i<iconLocations().size();++i) {
QDirIterator it(iconLocations().at(i), QDir::Dirs | QDir::NoDotAndDotDot);
while (it.hasNext()) {
it.next();
//qDebug() << it.fileName() << it.filePath();
if (QFile::exists(it.filePath()+"/index.theme")) { result.append(it.fileName()); }
}
}
return result;
}
static bool removeFileCache()
{
QFile cache(QString("%1/file.cache").arg(Common::configDir()));
if (cache.exists()) {
return cache.remove();
}
return false;
}
static bool removeFolderCache()
{
QFile cache(QString("%1/folder.cache").arg(Common::configDir()));
if (cache.exists()) {
return cache.remove();
}
return false;
}
};

#endif // COMMON_H
9 changes: 8 additions & 1 deletion fm/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,15 @@ MainWindow::MainWindow()

settings = new QSettings();

if (settings->value("clearCache").toBool()) {
qDebug() << "clear cache";
Common::removeFileCache();
Common::removeFolderCache();
settings->setValue("clearCache", false);
}

QString temp = QIcon::themeName();
if (temp.isEmpty()) { temp = settings->value("fallbackTheme").toString(); }
if (temp.isEmpty() || temp == "hicolor") { temp = settings->value("fallbackTheme").toString(); }
if(temp.isEmpty() || temp == "hicolor") {
if(QFile::exists(QDir::homePath() + "/" + ".gtkrc-2.0")) { // try gtk-2.0
QSettings gtkFile(QDir::homePath() + "/.gtkrc-2.0",QSettings::IniFormat,this);
Expand Down
22 changes: 14 additions & 8 deletions fm/src/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ QWidget *SettingsDialog::createGeneralSettings() {
checkThumbs = new QCheckBox(grpAppear);
checkHidden = new QCheckBox(grpAppear);
checkTabs = new QCheckBox(grpAppear);
//cmbIconTheme = new QComboBox(grpAppear);
//layoutAppear->addRow(tr("Icon theme:"), cmbIconTheme);
cmbIconTheme = new QComboBox(grpAppear);
layoutAppear->addRow(tr("Fallback Icon theme:"), cmbIconTheme);
layoutAppear->addRow(tr("Show thumbnails: "), checkThumbs);
layoutAppear->addRow(tr("Show hidden files: "), checkHidden);
layoutAppear->addRow(tr("Tabs on top: "), checkTabs);
Expand Down Expand Up @@ -518,15 +518,16 @@ void SettingsDialog::readSettings() {
mimeUtilsPtr->setDefaultsFileName(cmbDefaultMimeApps->currentText());

// Load icon themes
/*QString currentTheme = settingsPtr->value("forceTheme").toString();
QDirIterator it("/usr/share/icons", QDir::Dirs | QDir::NoDotAndDotDot);
QString currentTheme = settingsPtr->value("fallbackTheme").toString();
//QDirIterator it("/usr/share/icons", QDir::Dirs | QDir::NoDotAndDotDot);
QStringList iconThemes;
while (it.hasNext()) {
iconThemes << Common::getIconThemes();
/*while (it.hasNext()) {
it.next();
iconThemes.append(it.fileName());
}
}*/
cmbIconTheme->addItems(iconThemes);
cmbIconTheme->setCurrentIndex(iconThemes.indexOf(currentTheme));*/
cmbIconTheme->setCurrentIndex(iconThemes.indexOf(currentTheme));

// Read custom actions
checkOutput->setChecked(settingsPtr->value("showActionOutput", true).toBool());
Expand Down Expand Up @@ -733,7 +734,12 @@ bool SettingsDialog::saveSettings() {
settingsPtr->setValue("hiddenMode", checkHidden->isChecked());
settingsPtr->setValue("confirmDelete", checkDelete->isChecked());
//settingsPtr->setValue("term", editTerm->text());
//settingsPtr->setValue("forceTheme", cmbIconTheme->currentText());
if (cmbIconTheme->currentText() != settingsPtr->value("fallbackTheme").toString()) {
//QIcon::setThemeName(cmbIconTheme->currentText());
settingsPtr->setValue("clearCache", true);
QMessageBox::warning(this, tr("Restart to apply settings"), tr("You must restart to apply theme settings"));
}
settingsPtr->setValue("fallbackTheme", cmbIconTheme->currentText());
settingsPtr->setValue("defMimeAppsFile", cmbDefaultMimeApps->currentText());

// Custom actions
Expand Down
2 changes: 1 addition & 1 deletion fm/src/settingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected slots:
QCheckBox* checkTabs;
QCheckBox* checkDelete;
//QLineEdit* editTerm;
//QComboBox* cmbIconTheme;
QComboBox* cmbIconTheme;
QComboBox* cmbDefaultMimeApps;

QTreeWidget *actionsWidget;
Expand Down

0 comments on commit b613444

Please sign in to comment.