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 @@
#include <KMimeTypeTrader>
#include <KLocalizedString>
#include <QDebug>
#include <KRun>
KDE::KDE(QObject *parent) : QObject(parent)
{
......@@ -44,6 +45,7 @@ QVariantList KDE::mimeApps(const QUrl &url)
const QString text = service->name().replace('&', "&&");
QVariantMap item = createActionItem(text, "_kicker_fileItem_openWith", service->entryPath());
item["serviceIcon"] = service->icon();
item["serviceExec"] = service->exec();
list << item;
}
......@@ -54,3 +56,9 @@ QVariantList KDE::mimeApps(const QUrl &url)
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
public:
explicit KDE(QObject *parent = nullptr);
static QVariantList mimeApps(const QUrl &url);
static void openWithApp(const QString &exec, const QString &url);
signals:
public slots:
......
......@@ -24,10 +24,16 @@ int main(int argc, char *argv[])
// QQuickStyle::setStyle("nomad");
#endif
Pix pix;
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);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
......
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
void requestPath(QStringList paths)
{
qDebug()<<"FROM file loader"<< paths;
this->queue << paths;
for(auto url : this->queue)
{
if(!go)
{
this->go = true;
QMetaObject::invokeMethod(this, "getPics", Q_ARG(QString, url));
this->queue.removeOne(url);
}
}
this->go = true;
QMetaObject::invokeMethod(this, "getPics", Q_ARG(QStringList, paths));
}
void nextTrack()
......@@ -50,23 +44,23 @@ class FileLoader : public DBActions
public slots:
void getPics(QString path)
void getPics(QStringList paths)
{
qDebug()<<"GETTING TRACKS FROM SETTINGS";
QStringList urls;
if (QFileInfo(path).isDir())
{
QDirIterator it(path, PIX::formats, QDir::Files, QDirIterator::Subdirectories);
while (it.hasNext()) urls<<it.next();
} else if (QFileInfo(path).isFile()) urls<<path;
for(auto path : paths)
if (QFileInfo(path).isDir())
{
QDirIterator it(path, PIX::formats, QDir::Files, QDirIterator::Subdirectories);
while (it.hasNext()) urls<<it.next();
} else if (QFileInfo(path).isFile()) urls<<path;
int newPics = 0;
if(urls.size()>0)
{
int newTracks = 0;
for(auto url : urls)
{
if(go)
......@@ -87,27 +81,27 @@ class FileLoader : public DBActions
{PIX::KEY::RATE, "0"},
{PIX::KEY::COLOR, ""},
{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);
newTracks++;
newPics++;
}
}else break;
}
emit collectionSize(newTracks);
emit collectionSize(newPics);
}
this->t.msleep(100);
emit this->finished();
emit this->finished(newPics);
this->go = false;
}
signals:
void trackReady(PIX::DB track);
void finished();
void finished(int size);
void collectionSize(int size);
private:
......
......@@ -13,6 +13,8 @@ import "widgets/views/Viewer"
import "view_models"
import "widgets/views/Pix.js" as PIX
Kirigami.ApplicationWindow
{
id: root
......@@ -104,7 +106,7 @@ Kirigami.ApplicationWindow
GalleryView
{
id: galleryView
}
FoldersView
......@@ -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)
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},
{PIX::TABLEMAP[TABLE::TAGS], true},
{PIX::TABLEMAP[TABLE::IMAGES], true}});
emit refreshViews({{PIX::TABLEMAP[TABLE::ALBUMS], true},
{PIX::TABLEMAP[TABLE::TAGS], true},
{PIX::TABLEMAP[TABLE::IMAGES], true}});
});
this->populateDB({PIX::PicturesPath, PIX::DownloadsPath});
}
Pix::~Pix()
......@@ -49,6 +48,11 @@ Pix::~Pix()
delete this->fileLoader;
}
void Pix::refreshCollection()
{
this->populateDB({PIX::PicturesPath, PIX::DownloadsPath});
}
QVariantList Pix::getList(const QStringList &urls)
{
QVariantList mapList;
......@@ -76,12 +80,15 @@ void Pix::populateDB(const QStringList &paths)
<< "new path for database action: " << paths;
QStringList newPaths;
for(auto &path : newPaths)
for(auto path : paths)
{
if(path.startsWith("file://"))
path.replace("file://", "");
newPaths<<path;
newPaths << path.replace("file://", "");
else
newPaths<<path;
qDebug()<<"paths to scan"<<newPaths;
}
fileLoader->requestPath(newPaths);
......@@ -167,5 +174,13 @@ QVariantList Pix::openWith(const QString &url)
#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
explicit Pix(QObject* parent = nullptr);
~Pix();
Q_INVOKABLE void refreshCollection();
Q_INVOKABLE QVariantList getList(const QStringList &urls);
Q_INVOKABLE bool run(const QString &query);
......@@ -40,6 +42,7 @@ class Pix : public DBActions
Q_INVOKABLE static QVariantMap getParentDir(const QString &path);
Q_INVOKABLE static QVariantList openWith(const QString &url);
Q_INVOKABLE static void runApplication(const QString &exec, const QString &url);
private:
FileLoader *fileLoader;
......@@ -47,7 +50,7 @@ class Pix : public DBActions
void populateDB(const QStringList &paths);
signals:
void refreshTables(QVariantMap tables);
void refreshViews(QVariantMap tables);
};
......
......@@ -29,5 +29,6 @@
<file>widgets/dialogs/share/ShareDialog.qml</file>
<file>widgets/dialogs/share/ShareGrid.qml</file>
<file>widgets/dialogs/share/ShareDelegate.qml</file>
<file>widgets/views/Pix.js</file>
</qresource>
</RCC>
......@@ -29,10 +29,8 @@ PixPage
{
id: grid
clip: true
// width: Math.min(model.count, Math.floor(parent.width/cellWidth))*cellWidth
width: parent.width
height: parent.height
// anchors.horizontalCenter: parent.horizontalCenter
cellWidth: picSize + picSpacing
cellHeight: picSize + picSpacing
......@@ -88,10 +86,10 @@ PixPage
}
}
ScrollBar.vertical: ScrollBar{ visible: !isMobile}
ScrollBar.vertical: ScrollBar{ visible: true}
}
function clearGrid()
function clear()
{
gridModel.clear()
}
......
......@@ -103,8 +103,6 @@ Page
}
Column
{
id: pageContent
......
......@@ -5,6 +5,9 @@ import "../../../view_models"
PixPopup
{
property string picUrl : ""
padding: contentMargins
width: 260
height: 230
......
......@@ -5,7 +5,6 @@ import QtQuick.Layouts 1.3
GridView
{
property int gridSize : 64
clip: true
width: Math.min(model.count, Math.floor(parent.width/cellWidth))*cellWidth
......@@ -42,6 +41,9 @@ GridView
onClicked:
{
currentIndex = index
var obj = gridModel.get(index)
pix.runApplication(obj.actionArgument, picUrl)
shareDialog.close()
}
}
}
......
......@@ -2,6 +2,7 @@ import QtQuick 2.0
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
GridView
{
id: folderGridRoot
......@@ -10,9 +11,11 @@ GridView
signal folderClicked(int index)
clip: true
height: parent.height
width: parent.width
cellHeight: gridSize+contentMargins
height: parent.height
cellHeight: gridSize+(contentMargins*2)
cellWidth: gridSize+contentMargins
focus: true
......@@ -36,5 +39,6 @@ GridView
}
}
ScrollBar.vertical: ScrollBar{ visible: true}
}
......@@ -4,20 +4,37 @@ import "../../../view_models"
PixPage
{
headerbarExit: false
headerbarExit: stackView.currentItem === picsView
headerbarExitIcon: "go-previous"
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()
{
......@@ -27,4 +44,10 @@ PixPage
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"
PixGrid
{
id: galleryViewRoot
headerbarExit: false
visible: true
picSize: Math.sqrt(root.width*root.height)*0.25
picRadius: 2
Component.onCompleted: populate()
function populate()
{
......
function refreshViews()
{
galleryView.clear()
foldersView.clear()
galleryView.populate()
foldersView.populate()
}
......@@ -72,7 +72,11 @@ PixPage
ToolTip.visible: hovered
ToolTip.text: qsTr("Share")
onClicked: shareDialog.open()
onClicked:
{
shareDialog.picUrl = currentPic.url
shareDialog.open()
}
}
}
......@@ -121,7 +125,6 @@ PixPage
onClicked: currentPicFav = VIEWER.fav(currentPic.url)
}
}
......@@ -189,9 +192,9 @@ PixPage
Rectangle
{
id: shadow
width: parent.width
height: parent.height - headerBar.height
y: headerBar.height
width: parent.width
height: parent.height - headerBar.height
y: headerBar.height
color: textColor
opacity: 0.6
visible: shareDialog.opened
......
......@@ -7,5 +7,4 @@ Image {
width: parent.width
source: "file://"+currentPic.url
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