Commit 0b8160a3 authored by Camilo Higuita's avatar Camilo Higuita

also scan download folder, actually make open with dialog function and work on...

also scan download folder, actually make open with dialog function and work on folders view #4 #10 close #6
parent 9812414c
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <KMimeTypeTrader> #include <KMimeTypeTrader>
#include <KLocalizedString> #include <KLocalizedString>
#include <QDebug> #include <QDebug>
#include <KRun>
KDE::KDE(QObject *parent) : QObject(parent) KDE::KDE(QObject *parent) : QObject(parent)
{ {
...@@ -44,6 +45,7 @@ QVariantList KDE::mimeApps(const QUrl &url) ...@@ -44,6 +45,7 @@ QVariantList KDE::mimeApps(const QUrl &url)
const QString text = service->name().replace('&', "&&"); const QString text = service->name().replace('&', "&&");
QVariantMap item = createActionItem(text, "_kicker_fileItem_openWith", service->entryPath()); QVariantMap item = createActionItem(text, "_kicker_fileItem_openWith", service->entryPath());
item["serviceIcon"] = service->icon(); item["serviceIcon"] = service->icon();
item["serviceExec"] = service->exec();
list << item; list << item;
} }
...@@ -54,3 +56,9 @@ QVariantList KDE::mimeApps(const QUrl &url) ...@@ -54,3 +56,9 @@ QVariantList KDE::mimeApps(const QUrl &url)
return list; return list;
} else return list; } else return list;
} }
void KDE::openWithApp(const QString &exec, const QString &url)
{
KService service(exec);
KRun::runApplication(service,{url}, nullptr);
}
...@@ -11,6 +11,7 @@ class KDE : public QObject ...@@ -11,6 +11,7 @@ class KDE : public QObject
public: public:
explicit KDE(QObject *parent = nullptr); explicit KDE(QObject *parent = nullptr);
static QVariantList mimeApps(const QUrl &url); static QVariantList mimeApps(const QUrl &url);
static void openWithApp(const QString &exec, const QString &url);
signals: signals:
public slots: public slots:
......
...@@ -24,10 +24,16 @@ int main(int argc, char *argv[]) ...@@ -24,10 +24,16 @@ int main(int argc, char *argv[])
// QQuickStyle::setStyle("nomad"); // QQuickStyle::setStyle("nomad");
#endif #endif
Pix pix;
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
auto context = engine.rootContext(); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, [&]()
{
qDebug()<<"FINISHED LOADING QML APP";
pix.refreshCollection();
});
Pix pix; auto context = engine.rootContext();
context->setContextProperty("pix", &pix); context->setContextProperty("pix", &pix);
engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
......
var Query = { var Query = {
allPics : "select * from images order by addDate desc" allPics : "select * from images order by strftime(\"%s\", addDate) desc",
picLikeUrl_ : "select * from images where url like \"%1%\" "
} }
...@@ -31,16 +31,10 @@ class FileLoader : public DBActions ...@@ -31,16 +31,10 @@ class FileLoader : public DBActions
void requestPath(QStringList paths) void requestPath(QStringList paths)
{ {
qDebug()<<"FROM file loader"<< paths; qDebug()<<"FROM file loader"<< paths;
this->queue << paths;
for(auto url : this->queue) this->go = true;
{ QMetaObject::invokeMethod(this, "getPics", Q_ARG(QStringList, paths));
if(!go)
{
this->go = true;
QMetaObject::invokeMethod(this, "getPics", Q_ARG(QString, url));
this->queue.removeOne(url);
}
}
} }
void nextTrack() void nextTrack()
...@@ -50,23 +44,23 @@ class FileLoader : public DBActions ...@@ -50,23 +44,23 @@ class FileLoader : public DBActions
public slots: public slots:
void getPics(QString path) void getPics(QStringList paths)
{ {
qDebug()<<"GETTING TRACKS FROM SETTINGS"; qDebug()<<"GETTING TRACKS FROM SETTINGS";
QStringList urls; QStringList urls;
if (QFileInfo(path).isDir()) for(auto path : paths)
{ if (QFileInfo(path).isDir())
QDirIterator it(path, PIX::formats, QDir::Files, QDirIterator::Subdirectories); {
while (it.hasNext()) urls<<it.next(); QDirIterator it(path, PIX::formats, QDir::Files, QDirIterator::Subdirectories);
while (it.hasNext()) urls<<it.next();
} else if (QFileInfo(path).isFile()) urls<<path;
} else if (QFileInfo(path).isFile()) urls<<path;
int newPics = 0;
if(urls.size()>0) if(urls.size()>0)
{ {
int newTracks = 0;
for(auto url : urls) for(auto url : urls)
{ {
if(go) if(go)
...@@ -87,27 +81,27 @@ class FileLoader : public DBActions ...@@ -87,27 +81,27 @@ class FileLoader : public DBActions
{PIX::KEY::RATE, "0"}, {PIX::KEY::RATE, "0"},
{PIX::KEY::COLOR, ""}, {PIX::KEY::COLOR, ""},
{PIX::KEY::SOURCES_URL, sourceUrl}, {PIX::KEY::SOURCES_URL, sourceUrl},
{PIX::KEY::PIC_DATE, info.created().toString()} {PIX::KEY::PIC_DATE, info.created().toString()},
{PIX::KEY::FORMAT, format}
}; };
this->addPic(trackMap); this->addPic(trackMap);
newTracks++; newPics++;
} }
}else break; }else break;
} }
emit collectionSize(newTracks); emit collectionSize(newPics);
} }
this->t.msleep(100); this->t.msleep(100);
emit this->finished(); emit this->finished(newPics);
this->go = false; this->go = false;
} }
signals: signals:
void trackReady(PIX::DB track); void trackReady(PIX::DB track);
void finished(); void finished(int size);
void collectionSize(int size); void collectionSize(int size);
private: private:
......
...@@ -13,6 +13,8 @@ import "widgets/views/Viewer" ...@@ -13,6 +13,8 @@ import "widgets/views/Viewer"
import "view_models" import "view_models"
import "widgets/views/Pix.js" as PIX
Kirigami.ApplicationWindow Kirigami.ApplicationWindow
{ {
id: root id: root
...@@ -104,7 +106,7 @@ Kirigami.ApplicationWindow ...@@ -104,7 +106,7 @@ Kirigami.ApplicationWindow
GalleryView GalleryView
{ {
id: galleryView
} }
FoldersView FoldersView
...@@ -129,6 +131,11 @@ Kirigami.ApplicationWindow ...@@ -129,6 +131,11 @@ Kirigami.ApplicationWindow
} }
Component.onCompleted: foldersView.populate() Connections
{
target: pix
onRefreshViews: PIX.refreshViews()
}
} }
...@@ -34,14 +34,13 @@ Pix::Pix(QObject *parent) : DBActions(parent) ...@@ -34,14 +34,13 @@ Pix::Pix(QObject *parent) : DBActions(parent)
this->fileLoader = new FileLoader; this->fileLoader = new FileLoader;
connect(this->fileLoader, &FileLoader::finished,[this]() connect(this->fileLoader, &FileLoader::finished,[this](int size)
{ {
emit refreshTables({{PIX::TABLEMAP[TABLE::ALBUMS], true}, emit refreshViews({{PIX::TABLEMAP[TABLE::ALBUMS], true},
{PIX::TABLEMAP[TABLE::TAGS], true}, {PIX::TABLEMAP[TABLE::TAGS], true},
{PIX::TABLEMAP[TABLE::IMAGES], true}}); {PIX::TABLEMAP[TABLE::IMAGES], true}});
}); });
this->populateDB({PIX::PicturesPath, PIX::DownloadsPath});
} }
Pix::~Pix() Pix::~Pix()
...@@ -49,6 +48,11 @@ Pix::~Pix() ...@@ -49,6 +48,11 @@ Pix::~Pix()
delete this->fileLoader; delete this->fileLoader;
} }
void Pix::refreshCollection()
{
this->populateDB({PIX::PicturesPath, PIX::DownloadsPath});
}
QVariantList Pix::getList(const QStringList &urls) QVariantList Pix::getList(const QStringList &urls)
{ {
QVariantList mapList; QVariantList mapList;
...@@ -76,12 +80,15 @@ void Pix::populateDB(const QStringList &paths) ...@@ -76,12 +80,15 @@ void Pix::populateDB(const QStringList &paths)
<< "new path for database action: " << paths; << "new path for database action: " << paths;
QStringList newPaths; QStringList newPaths;
for(auto &path : newPaths) for(auto path : paths)
{ {
if(path.startsWith("file://")) if(path.startsWith("file://"))
path.replace("file://", "");
newPaths<<path; newPaths << path.replace("file://", "");
else
newPaths<<path;
qDebug()<<"paths to scan"<<newPaths;
} }
fileLoader->requestPath(newPaths); fileLoader->requestPath(newPaths);
...@@ -167,5 +174,13 @@ QVariantList Pix::openWith(const QString &url) ...@@ -167,5 +174,13 @@ QVariantList Pix::openWith(const QString &url)
#endif #endif
} }
void Pix::runApplication(const QString &exec, const QString &url)
{
qDebug()<<"RUN:"<<exec<<url;
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
return KDE::openWithApp(exec, url);
#endif
}
...@@ -26,6 +26,8 @@ class Pix : public DBActions ...@@ -26,6 +26,8 @@ class Pix : public DBActions
explicit Pix(QObject* parent = nullptr); explicit Pix(QObject* parent = nullptr);
~Pix(); ~Pix();
Q_INVOKABLE void refreshCollection();
Q_INVOKABLE QVariantList getList(const QStringList &urls); Q_INVOKABLE QVariantList getList(const QStringList &urls);
Q_INVOKABLE bool run(const QString &query); Q_INVOKABLE bool run(const QString &query);
...@@ -40,6 +42,7 @@ class Pix : public DBActions ...@@ -40,6 +42,7 @@ class Pix : public DBActions
Q_INVOKABLE static QVariantMap getParentDir(const QString &path); Q_INVOKABLE static QVariantMap getParentDir(const QString &path);
Q_INVOKABLE static QVariantList openWith(const QString &url); Q_INVOKABLE static QVariantList openWith(const QString &url);
Q_INVOKABLE static void runApplication(const QString &exec, const QString &url);
private: private:
FileLoader *fileLoader; FileLoader *fileLoader;
...@@ -47,7 +50,7 @@ class Pix : public DBActions ...@@ -47,7 +50,7 @@ class Pix : public DBActions
void populateDB(const QStringList &paths); void populateDB(const QStringList &paths);
signals: signals:
void refreshTables(QVariantMap tables); void refreshViews(QVariantMap tables);
}; };
......
...@@ -29,5 +29,6 @@ ...@@ -29,5 +29,6 @@
<file>widgets/dialogs/share/ShareDialog.qml</file> <file>widgets/dialogs/share/ShareDialog.qml</file>
<file>widgets/dialogs/share/ShareGrid.qml</file> <file>widgets/dialogs/share/ShareGrid.qml</file>
<file>widgets/dialogs/share/ShareDelegate.qml</file> <file>widgets/dialogs/share/ShareDelegate.qml</file>
<file>widgets/views/Pix.js</file>
</qresource> </qresource>
</RCC> </RCC>
...@@ -29,10 +29,8 @@ PixPage ...@@ -29,10 +29,8 @@ PixPage
{ {
id: grid id: grid
clip: true clip: true
// width: Math.min(model.count, Math.floor(parent.width/cellWidth))*cellWidth
width: parent.width width: parent.width
height: parent.height height: parent.height
// anchors.horizontalCenter: parent.horizontalCenter
cellWidth: picSize + picSpacing cellWidth: picSize + picSpacing
cellHeight: picSize + picSpacing cellHeight: picSize + picSpacing
...@@ -88,10 +86,10 @@ PixPage ...@@ -88,10 +86,10 @@ PixPage
} }
} }
ScrollBar.vertical: ScrollBar{ visible: !isMobile} ScrollBar.vertical: ScrollBar{ visible: true}
} }
function clearGrid() function clear()
{ {
gridModel.clear() gridModel.clear()
} }
......
...@@ -103,8 +103,6 @@ Page ...@@ -103,8 +103,6 @@ Page
} }
Column Column
{ {
id: pageContent id: pageContent
......
...@@ -5,6 +5,9 @@ import "../../../view_models" ...@@ -5,6 +5,9 @@ import "../../../view_models"
PixPopup PixPopup
{ {
property string picUrl : ""
padding: contentMargins padding: contentMargins
width: 260 width: 260
height: 230 height: 230
......
...@@ -5,7 +5,6 @@ import QtQuick.Layouts 1.3 ...@@ -5,7 +5,6 @@ import QtQuick.Layouts 1.3
GridView GridView
{ {
property int gridSize : 64 property int gridSize : 64
clip: true clip: true
width: Math.min(model.count, Math.floor(parent.width/cellWidth))*cellWidth width: Math.min(model.count, Math.floor(parent.width/cellWidth))*cellWidth
...@@ -42,6 +41,9 @@ GridView ...@@ -42,6 +41,9 @@ GridView
onClicked: onClicked:
{ {
currentIndex = index currentIndex = index
var obj = gridModel.get(index)
pix.runApplication(obj.actionArgument, picUrl)
shareDialog.close()
} }
} }
} }
......
...@@ -2,6 +2,7 @@ import QtQuick 2.0 ...@@ -2,6 +2,7 @@ import QtQuick 2.0
import QtQuick.Controls 2.2 import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
GridView GridView
{ {
id: folderGridRoot id: folderGridRoot
...@@ -10,9 +11,11 @@ GridView ...@@ -10,9 +11,11 @@ GridView
signal folderClicked(int index) signal folderClicked(int index)
clip: true clip: true
height: parent.height
width: parent.width width: parent.width
cellHeight: gridSize+contentMargins height: parent.height
cellHeight: gridSize+(contentMargins*2)
cellWidth: gridSize+contentMargins cellWidth: gridSize+contentMargins
focus: true focus: true
...@@ -36,5 +39,6 @@ GridView ...@@ -36,5 +39,6 @@ GridView
} }
} }
ScrollBar.vertical: ScrollBar{ visible: true}
} }
...@@ -4,20 +4,37 @@ import "../../../view_models" ...@@ -4,20 +4,37 @@ import "../../../view_models"
PixPage PixPage
{ {
headerbarExit: false headerbarExit: stackView.currentItem === picsView
headerbarExitIcon: "go-previous"
headerbarTitle: qsTr("Folders") headerbarTitle: qsTr("Folders")
content: FoldersGrid onExit: stackView.pop(folderGrid)
content: StackView
{ {
id: folderGrid id: stackView
onFolderClicked: initialItem: FoldersGrid
{ {
headerbarTitle = folderGrid.model.get(index).folder id: folderGrid
onFolderClicked:
{
headerbarTitle = folderGrid.model.get(index).folder
picsView.clear()
picsView.populate(folderGrid.model.get(index).url)
if(stackView.currentItem === folderGrid)
stackView.push(picsView)
}
} }
}
PicsView
{
id: picsView
headerbarVisible: false
}
}
function populate() function populate()
{ {
...@@ -27,4 +44,10 @@ PixPage ...@@ -27,4 +44,10 @@ PixPage
folderGrid.model.append(folders[i]) folderGrid.model.append(folders[i])
} }
function clear()
{
folderGrid.model.clear()
}
} }
import QtQuick 2.0 import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import "../../../db/Query.js" as Q
import "../../../widgets/views/Viewer/Viewer.js" as VIEWER
import "../../../view_models"
Item { PixGrid
{
picSize: Math.sqrt(root.width*root.height)*0.25
picRadius: 2
function populate(url)
{
var map = pix.get(Q.Query.picLikeUrl_.arg(url))
for(var i in map)
grid.model.append(map[i])
}
onPicClicked: openPic(index)
function openPic(index)
{
var data = []
for(var i = 0; i < grid.model.count; i++)
data.push(grid.model.get(i))
VIEWER.open(data, index)
}
} }
...@@ -8,10 +8,11 @@ import "../../../view_models" ...@@ -8,10 +8,11 @@ import "../../../view_models"
PixGrid PixGrid
{ {
id: galleryViewRoot id: galleryViewRoot
headerbarExit: false
visible: true visible: true
picSize: Math.sqrt(root.width*root.height)*0.25 picSize: Math.sqrt(root.width*root.height)*0.25
picRadius: 2 picRadius: 2
Component.onCompleted: populate()
function populate() function populate()
{ {
......
function refreshViews()
{
galleryView.clear()
foldersView.clear()
galleryView.populate()
foldersView.populate()
}
...@@ -72,7 +72,11 @@ PixPage ...@@ -72,7 +72,11 @@ PixPage
ToolTip.visible: hovered ToolTip.visible: hovered
ToolTip.text: qsTr("Share") ToolTip.text: qsTr("Share")
onClicked: shareDialog.open() onClicked:
{
shareDialog.picUrl = currentPic.url
shareDialog.open()
}
} }
} }
...@@ -121,7 +125,6 @@ PixPage ...@@ -121,7 +125,6 @@ PixPage
onClicked: currentPicFav = VIEWER.fav(currentPic.url) onClicked: currentPicFav = VIEWER.fav(currentPic.url)
} }
} }
...@@ -189,9 +192,9 @@ PixPage ...@@ -189,9 +192,9 @@ PixPage
Rectangle Rectangle
{ {
id: shadow id: shadow
width: parent.width width: parent.width
height: parent.height - headerBar.height height: parent.height - headerBar.height
y: headerBar.height y: headerBar.height
color: textColor color: textColor
opacity: 0.6 opacity: 0.6
visible: shareDialog.opened visible: shareDialog.opened
......
...@@ -7,5 +7,4 @@ Image { ...@@ -7,5 +7,4 @@ Image {
width: parent.width width: parent.width
source: "file://"+currentPic.url source: "file://"+currentPic.url
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment