From 0604978403c0e734382b709ba4d92befeedef390 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ole-Andr=C3=A9=20Rodlie?= <ole.andre.rodlie@gmail.com>
Date: Sun, 3 Jun 2018 03:24:09 +0200
Subject: [PATCH 1/6] added fallback for text files in openInApp

---
 fm/src/mimeutils.cpp | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fm/src/mimeutils.cpp b/fm/src/mimeutils.cpp
index 5a23ab9..2321666 100644
--- a/fm/src/mimeutils.cpp
+++ b/fm/src/mimeutils.cpp
@@ -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(); }

From 2e2432b42275dfab100f034bfe3cfa9e3821adf0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ole-Andr=C3=A9=20Rodlie?= <ole.andre.rodlie@gmail.com>
Date: Sun, 3 Jun 2018 03:42:41 +0200
Subject: [PATCH 2/6] settings mime types: don't load icons for mime types,
 it's slow and pointless. Also removed progressbar used when generating icons.

---
 fm/src/settingsdialog.cpp | 22 +++++++++++-----------
 fm/src/settingsdialog.h   |  4 ++--
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/fm/src/settingsdialog.cpp b/fm/src/settingsdialog.cpp
index 7aff27b..49848be 100644
--- a/fm/src/settingsdialog.cpp
+++ b/fm/src/settingsdialog.cpp
@@ -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)));
@@ -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();
@@ -270,7 +270,7 @@ QWidget* SettingsDialog::createMimeProgress() {
                                   QSizePolicy::MinimumExpanding), 3, 1);
 
   return widget;
-}
+}*/
 //---------------------------------------------------------------------------
 
 /**
@@ -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;
@@ -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")) {
@@ -696,7 +696,7 @@ 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) {
@@ -704,15 +704,15 @@ void SettingsDialog::loadMimes(int section) {
       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
diff --git a/fm/src/settingsdialog.h b/fm/src/settingsdialog.h
index 9dc6841..472aa00 100644
--- a/fm/src/settingsdialog.h
+++ b/fm/src/settingsdialog.h
@@ -10,7 +10,7 @@
 #include <QTreeWidget>
 #include <QToolButton>
 #include <QSettings>
-#include <QProgressBar>
+//#include <QProgressBar>
 #include <QComboBox>
 #include <QGroupBox>
 
@@ -75,7 +75,7 @@ protected slots:
   QTreeWidget* shortsWidget;
 
   QGroupBox* grpAssoc;
-  QProgressBar* progressMime;
+  //QProgressBar* progressMime;
   QTreeWidget* mimesWidget;
   QListWidget* listAssoc;
 };

From fab5da49308cf88bd665d39a8d2e148bdb39fe5c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ole-Andr=C3=A9=20Rodlie?= <ole.andre.rodlie@gmail.com>
Date: Sun, 3 Jun 2018 22:40:12 +0200
Subject: [PATCH 3/6] add more mime fallback

---
 fm/src/fileutils.cpp | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/fm/src/fileutils.cpp b/fm/src/fileutils.cpp
index f04e685..7795796 100644
--- a/fm/src/fileutils.cpp
+++ b/fm/src/fileutils.cpp
@@ -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");
           }

From 7092001b8a6693af7499ece68f3cd896e8abb4e9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ole-Andr=C3=A9=20Rodlie?= <ole.andre.rodlie@gmail.com>
Date: Sun, 3 Jun 2018 22:57:55 +0200
Subject: [PATCH 4/6] add "new window" action

---
 fm/src/actiondefs.cpp | 11 ++++++++++-
 fm/src/mainwindow.cpp |  6 ++++++
 fm/src/mainwindow.h   |  2 ++
 libfm/common.h        |  8 ++++++++
 4 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/fm/src/actiondefs.cpp b/fm/src/actiondefs.cpp
index 0f93710..0849fcd 100644
--- a/fm/src/actiondefs.cpp
+++ b/fm/src/actiondefs.cpp
@@ -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")));
@@ -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;
@@ -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()));
@@ -371,6 +377,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");
@@ -454,6 +461,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);
diff --git a/fm/src/mainwindow.cpp b/fm/src/mainwindow.cpp
index 4f766d3..2fc5e36 100644
--- a/fm/src/mainwindow.cpp
+++ b/fm/src/mainwindow.cpp
@@ -863,6 +863,11 @@ void MainWindow::tabChanged(int index)
         tree->setCurrentIndex(modelTree->mapFromSource(modelList->index(tabs->tabData(index).toString())));
 }
 
+void MainWindow::newWindow()
+{
+    QProcess::startDetached(qApp->applicationFilePath());
+}
+
 
 //---------------------------------------------------------------------------
 
@@ -1399,6 +1404,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);
diff --git a/fm/src/mainwindow.h b/fm/src/mainwindow.h
index 9b3b542..f71b95f 100644
--- a/fm/src/mainwindow.h
+++ b/fm/src/mainwindow.h
@@ -130,6 +130,7 @@ public slots:
 
     void listItemPressed(QModelIndex);
     void tabChanged(int index);
+    void newWindow();
     void openTab();
     void tabsOnTop();
     int addTab(QString path);
@@ -285,6 +286,7 @@ private slots:
     QAction *focusBookmarksAct;
     QAction *focusListAct;
     QAction *openFolderAct;
+    QAction *newWinAct;
     QAction *openTabAct;
     QAction *closeTabAct;
     QAction *tabsOnTopAct;
diff --git a/libfm/common.h b/libfm/common.h
index 3f19ed1..79f6412 100644
--- a/libfm/common.h
+++ b/libfm/common.h
@@ -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

From af1b9e492afd5dd6dbb95c25b15d975acd1216d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ole-Andr=C3=A9=20Rodlie?= <ole.andre.rodlie@gmail.com>
Date: Sun, 3 Jun 2018 23:12:15 +0200
Subject: [PATCH 5/6] added "clear cache" action

---
 fm/src/actiondefs.cpp |  6 ++++++
 fm/src/mainwindow.cpp | 10 +++++++++-
 fm/src/mainwindow.h   |  2 ++
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/fm/src/actiondefs.cpp b/fm/src/actiondefs.cpp
index 0849fcd..8ea0903 100644
--- a/fm/src/actiondefs.cpp
+++ b/fm/src/actiondefs.cpp
@@ -355,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;
 }
@@ -520,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
   // ----------------------------------------------------------------------
diff --git a/fm/src/mainwindow.cpp b/fm/src/mainwindow.cpp
index 2fc5e36..eaa460a 100644
--- a/fm/src/mainwindow.cpp
+++ b/fm/src/mainwindow.cpp
@@ -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);
     }
 
@@ -865,6 +866,7 @@ void MainWindow::tabChanged(int index)
 
 void MainWindow::newWindow()
 {
+    writeSettings();
     QProcess::startDetached(qApp->applicationFilePath());
 }
 
@@ -1615,6 +1617,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)
diff --git a/fm/src/mainwindow.h b/fm/src/mainwindow.h
index f71b95f..1ed5bc4 100644
--- a/fm/src/mainwindow.h
+++ b/fm/src/mainwindow.h
@@ -174,6 +174,7 @@ private slots:
     void handleMediaChanged(QString path, bool present);
     void handleMediaUnmount();
     void handleMediaEject();
+    void clearCache();
 private:
     void createActions();
     void createActionIcons();
@@ -294,6 +295,7 @@ private slots:
     QAction *mediaUnmountAct;
     QAction *mediaEjectAct;
     QAction *trashAct;
+    QAction *clearCacheAct;
 
     // libdisks
     Disks *disks;

From c2b7c8fb82b119966cffe78a57eb236603f62ad6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ole-Andr=C3=A9=20Rodlie?= <ole.andre.rodlie@gmail.com>
Date: Sun, 3 Jun 2018 23:15:56 +0200
Subject: [PATCH 6/6] minor

---
 fm/src/mainwindow.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fm/src/mainwindow.cpp b/fm/src/mainwindow.cpp
index eaa460a..c567ca1 100644
--- a/fm/src/mainwindow.cpp
+++ b/fm/src/mainwindow.cpp
@@ -866,6 +866,9 @@ void MainWindow::tabChanged(int index)
 
 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());
 }