Skip to content

Commit

Permalink
Merge pull request #24 from rodlie/master
Browse files Browse the repository at this point in the history
Last batch of fixes
  • Loading branch information
rodlie authored Jun 3, 2018
2 parents 6ab715e + c2b7c8f commit ea40cba
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 18 deletions.
17 changes: 16 additions & 1 deletion fm/src/actiondefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void MainWindow::createActionIcons() {
out >> *actionIcons;
icons.close();*/

if (actionIcons->count() < 28) {
if (actionIcons->count() < 29) {
actionIcons->append(QIcon::fromTheme("folder-new",QIcon(":/images/folder-new.png")));
actionIcons->append(QIcon::fromTheme("document-new",QIcon(":/images/document-new.png")));
actionIcons->append(QIcon::fromTheme("edit-cut",QIcon(":/images/cut.png")));
Expand Down Expand Up @@ -66,6 +66,7 @@ void MainWindow::createActionIcons() {
actionIcons->append(QIcon::fromTheme("window-close",QIcon(":/images/window-close.png")));
actionIcons->append(QIcon::fromTheme("tab-new",QIcon(":/images/folder-new.png"))); //26
actionIcons->append(QIcon::fromTheme("user-trash",QIcon(":/images/user-trash.png"))); //27
actionIcons->append(QIcon::fromTheme("document-new",QIcon(":/images/document-new.png"))); //28
/*icons.open(QIODevice::WriteOnly);
QDataStream out(&icons);
out << *actionIcons;
Expand All @@ -90,6 +91,11 @@ void MainWindow::createActions() {
newFileAct->setIcon(actionIcons->at(1));
actionList->append(newFileAct);

newWinAct = new QAction(tr("New window"), this);
connect(newWinAct, SIGNAL(triggered()), this, SLOT(newWindow()));
newWinAct->setIcon(actionIcons->at(28));
actionList->append(newWinAct);

openTabAct = new QAction(tr("New tab"), this);
openTabAct->setStatusTip(tr("Middle-click things to open tab"));
connect(openTabAct, SIGNAL(triggered()), this, SLOT(openTab()));
Expand Down Expand Up @@ -349,6 +355,10 @@ void MainWindow::createActions() {
mediaEjectAct->setIcon(QIcon::fromTheme("media-eject"));
connect(mediaEjectAct, SIGNAL(triggered(bool)), this, SLOT(handleMediaEject()));

clearCacheAct = new QAction(tr("Clear cache"), this);
clearCacheAct->setIcon(QIcon::fromTheme("edit-clear"));
connect(clearCacheAct, SIGNAL(triggered()), this, SLOT(clearCache()));

// We don't need the icon list anymore
delete actionIcons;
}
Expand All @@ -371,6 +381,7 @@ void MainWindow::readShortcuts() {

// Default shortcuts
if (shortcuts.count() == 0) {
shortcuts.insert(newWinAct->text(),"ctrl+n");
shortcuts.insert(openTabAct->text(),"ctrl+t");
shortcuts.insert(closeTabAct->text(),"ctrl+w");
shortcuts.insert(cutAct->text(),"ctrl+x");
Expand Down Expand Up @@ -454,6 +465,8 @@ void MainWindow::createMenus() {
QMenu *fileMenu = new QMenu(tr("File"));
fileMenu->addAction(newDirAct);
fileMenu->addAction(newFileAct);
fileMenu->addSeparator();
fileMenu->addAction(newWinAct);
fileMenu->addAction(openTabAct);
fileMenu->addSeparator();
fileMenu->addAction(closeAct);
Expand Down Expand Up @@ -511,6 +524,8 @@ void MainWindow::createMenus() {
// ----------------------------------------------------------------------
QMenu* helpMenu = new QMenu(tr("Help"));
helpMenu->addAction(aboutAct);
helpMenu->addSeparator();
helpMenu->addAction(clearCacheAct);

// Place all menus on menu bar
// ----------------------------------------------------------------------
Expand Down
30 changes: 28 additions & 2 deletions fm/src/fileutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,47 @@ QString FileUtils::getRealSuffix(const QString &name) {
* @return icon
*/
QIcon FileUtils::searchMimeIcon(QString mime, const QIcon &defaultIcon) {
//qDebug() << "search mime icon" << mime << QIcon::themeName();
qDebug() << "search mime icon" << mime << QIcon::themeName();
QIcon icon = QIcon::fromTheme(mime.replace("/", "-"));
if (icon.isNull()) {
if (mime.startsWith("image")) {
icon = QIcon::fromTheme("image-x-generic");
} else if(mime.startsWith("audio")) {
icon = QIcon::fromTheme("audio-x-generic");
} else if(mime.startsWith("video")) {
icon = QIcon::fromTheme("video-x-generic");
} else if (mime.contains("-tar") ||
mime.contains("compressed") ||
mime.contains("xz") ||
mime.contains("bz2") ||
mime.contains("gz") ||
mime.contains("rar") ||
mime.contains("zip")) {
icon = QIcon::fromTheme("package-x-generic");
} else if (mime.contains("office")) {
if (mime.contains("document")) {
icon = QIcon::fromTheme("x-office-document");
}
else if (mime.contains("drawing")) {
icon = QIcon::fromTheme("x-office-drawing");
}
else if (mime.contains("presentation")) {
icon = QIcon::fromTheme("x-office-presentation");
}
else if (mime.contains("spreadsheet")) {
icon = QIcon::fromTheme("x-office-spreadsheet");
}
} else if (mime.startsWith("text")) {
if (mime.contains("python") || mime.contains("perl") || mime.contains("script")) {
if (mime.contains("python") ||
mime.contains("perl") ||
mime.contains("php") ||
mime.contains("ruby") ||
mime.contains("script") ||
mime.contains("shell"))
{
icon = QIcon::fromTheme("text-x-script");
} else if(mime.contains("html")) {
icon = QIcon::fromTheme("text-html");
} else {
icon = QIcon::fromTheme("text-x-generic");
}
Expand Down
19 changes: 18 additions & 1 deletion fm/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ MainWindow::MainWindow()
settings = new QSettings();

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

Expand Down Expand Up @@ -863,6 +864,15 @@ void MainWindow::tabChanged(int index)
tree->setCurrentIndex(modelTree->mapFromSource(modelList->index(tabs->tabData(index).toString())));
}

void MainWindow::newWindow()
{
if (settings->value("clearCache").toBool()) {
settings->setValue("clearCache", false); // we don't want the new window to clear our existing cache
}
writeSettings();
QProcess::startDetached(qApp->applicationFilePath());
}


//---------------------------------------------------------------------------

Expand Down Expand Up @@ -1399,6 +1409,7 @@ void MainWindow::contextMenuEvent(QContextMenuEvent * event) {
bookmarksList->clearSelection();
popup->addAction(newDirAct);
popup->addAction(newFileAct);
popup->addAction(newWinAct);
popup->addAction(openTabAct);
popup->addSeparator();
popup->addAction(cutAct);
Expand Down Expand Up @@ -1609,6 +1620,12 @@ void MainWindow::handleMediaEject()
if (path.isEmpty()) { return; }
disks->devices[path]->eject();
}

void MainWindow::clearCache()
{
settings->setValue("clearCache", true);
QMessageBox::information(this, tr("Close window"), tr("Please close window to apply action."));
}
//---------------------------------------------------------------------------

void MainWindow::actionMapper(QString cmd)
Expand Down
4 changes: 4 additions & 0 deletions fm/src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public slots:

void listItemPressed(QModelIndex);
void tabChanged(int index);
void newWindow();
void openTab();
void tabsOnTop();
int addTab(QString path);
Expand Down Expand Up @@ -173,6 +174,7 @@ private slots:
void handleMediaChanged(QString path, bool present);
void handleMediaUnmount();
void handleMediaEject();
void clearCache();
private:
void createActions();
void createActionIcons();
Expand Down Expand Up @@ -285,13 +287,15 @@ private slots:
QAction *focusBookmarksAct;
QAction *focusListAct;
QAction *openFolderAct;
QAction *newWinAct;
QAction *openTabAct;
QAction *closeTabAct;
QAction *tabsOnTopAct;
QAction *aboutAct;
QAction *mediaUnmountAct;
QAction *mediaEjectAct;
QAction *trashAct;
QAction *clearCacheAct;

// libdisks
Disks *disks;
Expand Down
7 changes: 6 additions & 1 deletion fm/src/mimeutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,14 @@ QStringList MimeUtils::getMimeTypes() const {
* @param processOwner
*/
void MimeUtils::openInApp(const QFileInfo &file, QString termCmd) {
QString mime = getMimeType(file.filePath());
QString mime = getMimeType(file.absoluteFilePath());
QString app = defaults->value(mime).toString().split(";").first();
if (app.isEmpty() && mime.startsWith("text/") && mime != "text/plain") {
// fallback for text
app = defaults->value("text/plain").toString().split(";").first();
}
QString desktop = Common::findApplication(app);
qDebug() << "openInApp" << file.absoluteFilePath() << termCmd << mime << app << desktop;
if (!desktop.isEmpty()) {
DesktopFile df = DesktopFile(desktop);
if (!df.isTerminal()) { termCmd.clear(); }
Expand Down
22 changes: 11 additions & 11 deletions fm/src/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ SettingsDialog::SettingsDialog(QList<QAction *> *actionList,
stack->addWidget(createGeneralSettings());
stack->addWidget(createActionsSettings());
stack->addWidget(createShortcutSettings());
stack->addWidget(createMimeProgress());
//stack->addWidget(createMimeProgress());
stack->addWidget(createMimeSettings());
connect(selector, SIGNAL(currentRowChanged(int)), stack,
SLOT(setCurrentIndex(int)));
Expand Down Expand Up @@ -250,7 +250,7 @@ QWidget* SettingsDialog::createShortcutSettings() {
* @brief Creates widget with mime progress bar
* @return widget
*/
QWidget* SettingsDialog::createMimeProgress() {
/*QWidget* SettingsDialog::createMimeProgress() {
// Widget and its layout
QWidget* widget = new QWidget();
Expand All @@ -270,7 +270,7 @@ QWidget* SettingsDialog::createMimeProgress() {
QSizePolicy::MinimumExpanding), 3, 1);
return widget;
}
}*/
//---------------------------------------------------------------------------

/**
Expand Down Expand Up @@ -666,10 +666,10 @@ void SettingsDialog::loadMimes(int section) {
//qDebug() << "mimes" << mimes;

// Init process
progressMime->setRange(1, mimes.size());
//progressMime->setRange(1, mimes.size());

// Default icon
QIcon defaultIcon = QIcon::fromTheme("unknown");
QIcon defaultIcon = QIcon::fromTheme("text-x-generic");

// Mime cathegories and their icons
QMap<QString, QTreeWidgetItem*> categories;
Expand All @@ -680,7 +680,7 @@ void SettingsDialog::loadMimes(int section) {

QApplication::processEvents();
// Updates progress
progressMime->setValue(progressMime->value() + 1);
//progressMime->setValue(progressMime->value() + 1);

// Skip all 'inode' nodes including 'inode/directory'
if (mime.startsWith("inode")) {
Expand All @@ -696,23 +696,23 @@ void SettingsDialog::loadMimes(int section) {
QStringList splitMime = mime.split("/");

// Retrieve cathegory
QIcon icon;
QIcon icon = defaultIcon;
QString categoryName = splitMime.first();
QTreeWidgetItem* category = categories.value(categoryName, NULL);
if (!category) {
category = new QTreeWidgetItem(mimesWidget);
category->setText(0, categoryName);
category->setFlags(Qt::ItemIsEnabled);
categories.insert(categoryName, category);
icon = FileUtils::searchGenericIcon(categoryName, defaultIcon);
//icon = FileUtils::searchGenericIcon(categoryName, defaultIcon);
genericIcons.insert(category, icon);
} else {
} /*else {
icon = genericIcons.value(category);
}
}*/

// Load icon and default application for current mime
// NOTE: if icon is not found generic icon is used
icon = FileUtils::searchMimeIcon(mime, icon);
//icon = FileUtils::searchMimeIcon(mime, icon);
QString appNames = mimeUtilsPtr->getDefault(mime).join(";");

// Create item from current mime
Expand Down
4 changes: 2 additions & 2 deletions fm/src/settingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <QTreeWidget>
#include <QToolButton>
#include <QSettings>
#include <QProgressBar>
//#include <QProgressBar>
#include <QComboBox>
#include <QGroupBox>

Expand Down Expand Up @@ -75,7 +75,7 @@ protected slots:
QTreeWidget* shortsWidget;

QGroupBox* grpAssoc;
QProgressBar* progressMime;
//QProgressBar* progressMime;
QTreeWidget* mimesWidget;
QListWidget* listAssoc;
};
Expand Down
8 changes: 8 additions & 0 deletions libfm/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,14 @@ class Common
}
return false;
}
static bool removeThumbsCache()
{
QFile cache(QString("%1/thumbs.cache").arg(Common::configDir()));
if (cache.exists()) {
return cache.remove();
}
return false;
}
};

#endif // COMMON_H

0 comments on commit ea40cba

Please sign in to comment.