Commit 098b227c authored by Camilo higuita's avatar Camilo higuita

remove unused source files and further usage of MauiKit fm classes and...

remove unused source files and further usage of MauiKit fm classes and controls, making Index super light weight
parent 5b22721d
......@@ -21,7 +21,6 @@ add_executable(index
src/main.cpp
src/index.cpp
src/qml.qrc
src/kde/kde.cpp
src/kde/notify.cpp
)
......
function createFolder()
{
newFolderDialog.open()
}
function createFile()
{
newFileDialog.open()
}
function bookmarkFolder()
{
browser.bookmarkFolder([browser.currentPath])
}
#include "index.h"
#include <QFileInfo>
#include <QMimeType>
#include <QDirIterator>
#include <QDesktopServices>
#include <QUrl>
#include <QDir>
#include <QDebug>
#include "inx.h"
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
#include "kde/notify.h"
#include "kde/kde.h"
#endif
Index::Index(QObject *parent) : FM(parent)
Index::Index(QObject *parent) : QObject(parent)
{
}
QVariantList Index::getCustomPathContent(const QString &path)
{
QVariantList res;
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
if(path.startsWith(INX::CUSTOMPATH_PATH[INX::CUSTOMPATH::APPS]+"/"))
return KDE::getApps(QString(path).replace(INX::CUSTOMPATH_PATH[INX::CUSTOMPATH::APPS]+"/",""));
else
return KDE::getApps();
#endif
return res;
}
bool Index::isCustom(const QString &path)
{
return path.startsWith("#");
}
bool Index::isApp(const QString &path)
{
return /*QFileInfo(path).isExecutable() ||*/ path.endsWith(".desktop");
}
/* to be called to launch index with opening different paths */
......@@ -55,27 +27,3 @@ void Index::openPaths(const QStringList &paths)
emit this->openPath(urls);
}
QVariantList Index::getCustomPaths()
{
#ifdef Q_OS_ANDROID
return QVariantList();
#endif
return QVariantList
{
QVariantMap
{
{INX::MODEL_NAME[INX::MODEL_KEY::ICON], "system-run"},
{INX::MODEL_NAME[INX::MODEL_KEY::LABEL], INX::CUSTOMPATH_NAME[INX::CUSTOMPATH::APPS]},
{INX::MODEL_NAME[INX::MODEL_KEY::PATH], INX::CUSTOMPATH_PATH[INX::CUSTOMPATH::APPS]},
{INX::MODEL_NAME[INX::MODEL_KEY::TYPE], INX::PATHTYPE_NAME[INX::PATHTYPE_KEY::PLACES]}
}
};
}
void Index::runApplication(const QString &exec, const QString &url)
{
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
return KDE::launchApp(exec);
#endif
}
......@@ -2,31 +2,15 @@
#define INDEX_H
#include <QObject>
#include <QVariantList>
#include <QStringList>
#include <QFileSystemWatcher>
#ifdef STATIC_KIRIGAMI
#include "fm.h"
#else
#include "MauiKit/fm.h"
#endif
class Index : public FM
class Index : public QObject
{
Q_OBJECT
public:
explicit Index(QObject *parent = nullptr);
Q_INVOKABLE static QVariantList getCustomPathContent(const QString &path);
Q_INVOKABLE static bool isCustom(const QString &path);
Q_INVOKABLE static bool isApp(const QString &path);
Q_INVOKABLE void openPaths(const QStringList &paths);
Q_INVOKABLE static QVariantList getCustomPaths();
/*KDE*/
Q_INVOKABLE static void runApplication(const QString &exec, const QString &url);
signals:
void openPath(QStringList paths);
......
......@@ -4,241 +4,15 @@
#include <QString>
#include <QDebug>
#include <QStandardPaths>
#include <QFileInfo>
#include <QImage>
#include <QTime>
#include <QSettings>
#include <QDirIterator>
#include <QVariantList>
#include <QMimeType>
#include <QMimeData>
#include <QMimeDatabase>
#if defined(Q_OS_ANDROID)
#include "../mauikit/src/android/mauiandroid.h"
#endif
namespace INX
{
Q_NAMESPACE
inline bool isMobile()
{
#if defined(Q_OS_ANDROID)
return true;
#elif defined(Q_OS_LINUX)
return false;
#elif defined(Q_OS_WIN32)
return false;
#elif defined(Q_OS_WIN64)
return false;
#elif defined(Q_OS_MACOS)
return false;
#elif defined(Q_OS_IOS)
return true;
#elif defined(Q_OS_HAIKU)
return false;
#endif
}
inline bool isAndroid()
{
#if defined(Q_OS_ANDROID)
return true;
#elif defined(Q_OS_LINUX)
return false;
#elif defined(Q_OS_WIN32)
return false;
#elif defined(Q_OS_WIN64)
return false;
#elif defined(Q_OS_MACOS)
return false;
#elif defined(Q_OS_IOS)
return false;
#elif defined(Q_OS_HAIKU)
return false;
#endif
}
#if defined(Q_OS_ANDROID)
const QString PicturesPath = PATHS::PicturesPath;
const QString DownloadsPath = PATHS::DownloadsPath;
const QString DocumentsPath = PATHS::DocumentsPath;
const QString HomePath = PATHS::HomePath;
const QString MusicPath = PATHS::MusicPath;
const QString VideosPath = PATHS::VideosPath;
const QStringList defaultPaths =
{
HomePath,
DocumentsPath,
PicturesPath,
MusicPath,
VideosPath,
DownloadsPath
};
const QMap<QString, QString> folderIcon
{
{PicturesPath, "folder-pictures"},
{DownloadsPath, "folder-download"},
{DocumentsPath, "folder-documents"},
{HomePath, "user-home"},
{MusicPath, "folder-music"},
{VideosPath, "folder-videos"},
};
#else
const QString PicturesPath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
const QString DownloadsPath = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
const QString DocumentsPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
const QString HomePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
const QString MusicPath = QStandardPaths::writableLocation(QStandardPaths::MusicLocation);
const QString VideosPath = QStandardPaths::writableLocation(QStandardPaths::MoviesLocation);
const QString DesktopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
const QString AppsPath = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation);
const QString RootPath = "/";
const QStringList defaultPaths =
{
HomePath,
DesktopPath,
DocumentsPath,
PicturesPath,
MusicPath,
VideosPath,
DownloadsPath
};
const QMap<QString, QString> folderIcon
{
{PicturesPath, "folder-pictures"},
{DownloadsPath, "folder-download"},
{DocumentsPath, "folder-documents"},
{HomePath, "user-home"},
{MusicPath, "folder-music"},
{VideosPath, "folder-videos"},
{DesktopPath, "user-desktop"},
{AppsPath, "system-run"},
{RootPath, "folder-root"}
};
#endif
inline QString getIconName(const QString &path)
{
if(QFileInfo(path).isDir())
{
if(folderIcon.contains(path))
return folderIcon[path];
else return "folder";
}else
{
QMimeDatabase mime;
auto type = mime.mimeTypeForFile(path);
return isAndroid() ? type.genericIconName() : type.iconName();
}
return "unkown";
}
enum class MODEL_KEY : uint_fast8_t
{
ICON,
LABEL,
PATH,
TYPE,
GROUP,
OWNER,
SUFFIX,
NAME,
DATE,
MODIFIED,
MIME,
TAGS,
PERMISSIONS
};
static const QMap<MODEL_KEY, QString> MODEL_NAME =
{
{MODEL_KEY::ICON, "icon"},
{MODEL_KEY::LABEL, "label"},
{MODEL_KEY::PATH, "path"},
{MODEL_KEY::TYPE, "type"},
{MODEL_KEY::GROUP, "group"},
{MODEL_KEY::OWNER, "owner"},
{MODEL_KEY::SUFFIX, "suffix"},
{MODEL_KEY::NAME, "name"},
{MODEL_KEY::DATE, "date"},
{MODEL_KEY::MODIFIED, "modified"},
{MODEL_KEY::MIME, "mime"},
{MODEL_KEY::TAGS, "tags"},
{MODEL_KEY::PERMISSIONS, "permissions"}
};
enum class CUSTOMPATH : uint_fast8_t
{
APPS,
TAGS,
TRASH
};
static const QMap<CUSTOMPATH, QString> CUSTOMPATH_PATH =
{
{CUSTOMPATH::APPS, "#apps"},
{CUSTOMPATH::TAGS, "#tags"},
{CUSTOMPATH::TRASH, "#trash"}
};
static const QMap<CUSTOMPATH, QString> CUSTOMPATH_NAME =
{
{CUSTOMPATH::APPS, "Apps"},
{CUSTOMPATH::TAGS, "Tags"},
{CUSTOMPATH::TRASH, "Trash"}
};
enum class PATHTYPE_KEY : uint_fast8_t
{
PLACES,
DRIVES,
BOOKMARKS,
TAGS
};
static const QMap<PATHTYPE_KEY, QString> PATHTYPE_NAME =
{
{PATHTYPE_KEY::PLACES, "Places"},
{PATHTYPE_KEY::DRIVES, "Drives"},
{PATHTYPE_KEY::BOOKMARKS, "Bookmarks"},
{PATHTYPE_KEY::TAGS, "Tags"}
};
const QString SettingPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)+"/pix/";
const QString CachePath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation)+"/pix/";
const QString NotifyDir = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
const QString app = "Index";
const QString version = "0.1.0";
const QString version = "1.0.0";
const QString description = "File manager";
inline void saveSettings(const QString &key, const QVariant &value, const QString &group)
{
QSettings setting(INX::app,INX::app);
setting.beginGroup(group);
setting.setValue(key,value);
setting.endGroup();
}
inline QVariant loadSettings(const QString &key, const QString &group, const QVariant &defaultValue)
{
QVariant variant;
QSettings setting(INX::app,INX::app);
setting.beginGroup(group);
variant = setting.value(key,defaultValue);
setting.endGroup();
return variant;
}
}
#endif // INX_H
/***
Pix Copyright (C) 2018 Camilo Higuita
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "kde.h"
#include <KService>
#include <KMimeTypeTrader>
#include <KToolInvocation>
#include <KLocalizedString>
#include <QDebug>
#include <KRun>
#include <QFileInfo>
#include <KService>
#include <KServiceGroup>
#include <QDebug>
#include "../inx.h"
KDE::KDE(QObject *parent) : QObject(parent) {}
QVariantList KDE::getApps()
{
QVariantList res;
KServiceGroup::Ptr group = KServiceGroup::root();
bool sortByGenericName = false;
KServiceGroup::List list = group->entries(true /* sorted */, true /* excludeNoDisplay */,
true /* allowSeparators */, sortByGenericName /* sortByGenericName */);
for (KServiceGroup::List::ConstIterator it = list.constBegin(); it != list.constEnd(); it++)
{
const KSycocaEntry::Ptr p = (*it);
if (p->isType(KST_KServiceGroup))
{
KServiceGroup::Ptr s(static_cast<KServiceGroup*>(p.data()));
if (!s->noDisplay() && s->childCount() > 0)
{
qDebug()<< "Getting app"<<s->icon();
res << QVariantMap
{
{INX::MODEL_NAME[INX::MODEL_KEY::ICON], s->icon()},
{INX::MODEL_NAME[INX::MODEL_KEY::LABEL], s->name()},
{INX::MODEL_NAME[INX::MODEL_KEY::PATH], INX::CUSTOMPATH_PATH[INX::CUSTOMPATH::APPS]+"/"+s->entryPath()}
};
}
}
}
return res;
}
QVariantList KDE::getApps(const QString &groupStr)
{
if(groupStr.isEmpty()) return getApps();
QVariantList res;
// const KServiceGroup::Ptr group(static_cast<KServiceGroup*>(groupStr));
auto group = new KServiceGroup(groupStr);
KServiceGroup::List list = group->entries(true /* sorted */,
true /* excludeNoDisplay */,
false /* allowSeparators */,
true /* sortByGenericName */);
for (KServiceGroup::List::ConstIterator it = list.constBegin(); it != list.constEnd(); it++)
{
const KSycocaEntry::Ptr p = (*it);
if (p->isType(KST_KService))
{
const KService::Ptr s(static_cast<KService*>(p.data()));
if (s->noDisplay())
continue;
res << QVariantMap {
{INX::MODEL_NAME[INX::MODEL_KEY::ICON], s->icon()},
{INX::MODEL_NAME[INX::MODEL_KEY::LABEL], s->name()},
{INX::MODEL_NAME[INX::MODEL_KEY::PATH], s->entryPath()}
};
} else if (p->isType(KST_KServiceSeparator))
{
qDebug()<< "separator wtf";
} else if (p->isType(KST_KServiceGroup))
{
const KServiceGroup::Ptr s(static_cast<KServiceGroup*>(p.data()));
if (s->childCount() == 0)
continue;
res << QVariantMap { {INX::MODEL_NAME[INX::MODEL_KEY::ICON], s->icon()},
{INX::MODEL_NAME[INX::MODEL_KEY::LABEL], s->name()},
{INX::MODEL_NAME[INX::MODEL_KEY::PATH], INX::CUSTOMPATH_PATH[INX::CUSTOMPATH::APPS]+"/"+s->entryPath()}
};
}
}
return res;
}
void KDE::launchApp(const QString &app)
{
KService service(app);
KRun::runApplication(service,{}, nullptr);
}
/***
Pix Copyright (C) 2018 Camilo Higuita
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef KDE_H
#define KDE_H
#include <QObject>
#include <QVariantList>
#include <KFileItem>
class KDE : public QObject
{
Q_OBJECT
public:
explicit KDE(QObject *parent = nullptr);
static QVariantList getApps();
static QVariantList getApps(const QString &groupStr);
static void launchApp(const QString &app);
signals:
public slots:
};
#endif // KDE_H
......@@ -14,7 +14,6 @@ HEADERS += \
$$PWD/notify.h
SOURCES += \
$$PWD/kde.cpp \
$$PWD/notify.cpp
LIBS += -lMauiKit
......@@ -5,14 +5,10 @@ import org.kde.kirigami 2.0 as Kirigami
import org.kde.mauikit 1.0 as Maui
import QtQuick.Window 2.0
import QtQuick.Controls.Material 2.1
import "widgets"
import "widgets/views"
import "widgets/sidebar"
import "widgets_templates"
import "Index.js" as INX
Maui.ApplicationWindow
{
......
......@@ -3,16 +3,6 @@
<file>main.qml</file>
<file>widgets/sidebar/PlacesSidebar.qml</file>
<file>widgets/views/Browser.qml</file>
<file>widgets_templates/ItemMenu.qml</file>
<file>Index.js</file>
<file>widgets/views/BrowserMenu.qml</file>
<file>widgets/views/Previewer/AudioPreview.qml</file>
<file>widgets/views/Previewer/ImagePreview.qml</file>
<file>widgets/views/Previewer/TextPreview.qml</file>
<file>widgets/views/Previewer/VideoPreview.qml</file>
<file>widgets/views/Previewer/DefaultPreview.qml</file>
<file>widgets_templates/ColorsBar.qml</file>
<file>widgets/views/Terminal.qml</file>
<file>widgets/views/Previewer.qml</file>
</qresource>
</RCC>
......@@ -2,7 +2,6 @@ import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import org.kde.mauikit 1.0 as Maui
import "../../widgets_templates"
Maui.SideBar
{
......@@ -39,11 +38,11 @@ Maui.SideBar
function populate()
{
clear()
var places = inx.getDefaultPaths()
places.push(inx.getCustomPaths())
places.push(inx.getBookmarks())
places.push(inx.getDevices())
places.push(inx.getTags())
var places = Maui.FM.getDefaultPaths()
places.push(Maui.FM.getCustomPaths())
places.push(Maui.FM.getBookmarks())
places.push(Maui.FM.getDevices())
places.push(Maui.FM.getTags())
if(places.length > 0)
for(var i in places)
......
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import "../../widgets_templates"
import "../../Index.js" as INX
import org.kde.kirigami 2.0 as Kirigami
import org.kde.mauikit 1.0 as Maui
import FMModel 1.0
......
import QtQuick 2.9
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import org.kde.mauikit 1.0 as Maui
import org.kde.kirigami 2.2 as Kirigami
import "../../Index.js" as INX
Maui.Menu
{
property int pasteFiles : 0
Maui.MenuItem
{
text: qsTr(browser.selectionMode ? "Selection OFF" : "Selection ON")
onTriggered: browser.selectionMode = !browser.selectionMode
}
MenuSeparator { }
Maui.MenuItem
{
visible: !isMobile
text: qsTr(terminalVisible ? "Hide terminal" : "Show terminal")
onTriggered:
{
terminalVisible = !terminalVisible
Maui.FM.setDirConf(browser.currentPath+"/.directory", "MAUIFM", "ShowTerminal", browser.terminalVisible)
close()
}
}
Maui.MenuItem
{
text: qsTr("Compact mode")
onTriggered: placesSidebar.isCollapsed = !placesSidebar.isCollapsed
}
Maui.MenuItem
{
text: qsTr("Show previews")
onTriggered:
{
INX.showPreviews()
close()
}
}
Maui.MenuItem
{
text: qsTr("Show hidden files")
onTriggered:
{
INX.showHiddenFiles()
close()
}
}
MenuSeparator { }
Maui.MenuItem
{
text: qsTr("New folder")
onTriggered: INX.createFolder()
}
Maui.MenuItem
{
text: qsTr("New file")
onTriggered: INX.createFile()
}
Maui.MenuItem
{
text: qsTr("Bookmark")
onTriggered: INX.bookmarkFolder()
}
MenuSeparator { }
Maui.MenuItem
{
text: qsTr("Paste ")+"["+pasteFiles+"]"
enabled: pasteFiles > 0
onTriggered: browser.paste()
}
MenuSeparator { }
Maui.MenuItem
{
width: parent.width
RowLayout
{
anchors.fill: parent
Maui.ToolButton
{
Layout.fillHeight: true
Layout.fillWidth: true
iconName: "list-add"
onClicked: zoomIn()
}
Maui.ToolButton
{
Layout.fillHeight: true
Layout.fillWidth: true
iconName: "list-remove"
onClicked: zoomOut()
}
}
}
function show()
{
if(browser.currentPathType === browser.pathType.directory
|| browser.currentPathType === browser.pathType.tags)
{
if(browser.isCopy)
pasteFiles = copyPaths.length
else if(browser.isCut)
pasteFiles = cutPaths.length
popup()
}
}
}
import QtQuick 2.9
import QtQuick.Controls 2.2