Commit ec809374 authored by camilo higuita's avatar camilo higuita

now working again, still missign some fixes on other views

parent 3a23f2b6
......@@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.0)
find_package(ECM 1.7.0 REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${ECM_MODULE_PATH})
set(CMAKE_CXX_STANDARD 17)
find_package(MauiKit REQUIRED)
find_package(Qt5 REQUIRED NO_MODULE COMPONENTS Qml Quick Sql Svg QuickControls2 Widgets)
......
......@@ -49,8 +49,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <MauiKit/tagging.h>
#endif
#include "./src/models/basemodel.h"
#include "./src/models/baselist.h"
#include "./src/models/gallery/gallery.h"
#include "./src/models/albums/albums.h"
//#include "./src/models/cloud/cloud.h"
......@@ -58,7 +56,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "./src/models/folders/foldermodel.h"
#include "./src/models/folders/folders.h"
QStringList getFolderImages(const QString &path)
static const QStringList getFolderImages(const QString &path)
{
QStringList urls;
......@@ -74,7 +72,7 @@ QStringList getFolderImages(const QString &path)
return urls;
}
QStringList openFiles(const QStringList &files)
static const QStringList openFiles(const QStringList &files)
{
QStringList urls;
......@@ -101,13 +99,15 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
#endif
app.setApplicationName(PIX::App);
app.setApplicationName(PIX::appName);
app.setApplicationVersion(PIX::version);
app.setApplicationDisplayName(PIX::App);
app.setApplicationDisplayName(PIX::displayName);
app.setOrganizationName(PIX::orgName);
app.setOrganizationDomain(PIX::orgDomain);
app.setWindowIcon(QIcon(":/img/assets/pix.png"));
QCommandLineParser parser;
parser.setApplicationDescription("Pix Image gallery viewer");
parser.setApplicationDescription(PIX::description);
const QCommandLineOption versionOption = parser.addVersionOption();
parser.addOption(versionOption);
parser.process(app);
......@@ -119,33 +119,41 @@ int main(int argc, char *argv[])
if(!args.isEmpty())
pics = openFiles(args);
Pix pix;
QQmlApplicationEngine engine;
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, [&]()
{
pix.refreshCollection();
if(!pics.isEmpty())
pix.openPics(pics);
// QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, [&]()
// {
// pix.refreshCollection();
// if(!pics.isEmpty())
// pix.openPics(pics);
// });
qmlRegisterSingletonType<Pix>("org.maui.pix", 1, 0, "Collection",
[](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject* {
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return new Pix;
});
auto context = engine.rootContext();
context->setContextProperty("pix", &pix);
const auto dba = DBActions::getInstance();
context->setContextProperty("tag", dba->tag);
context->setContextProperty("dba", dba);
// qmlRegisterUncreatableMetaObject(PIX::staticMetaObject, "PIX", 1, 0, "KEY", "Error");
qmlRegisterSingletonType<DBActions>("org.maui.pix", 1, 0, "DB",
[](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject* {
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return DBActions::getInstance();
});
qmlRegisterUncreatableType<BaseList>("BaseList", 1, 0, "BaseList", QStringLiteral("BaseList should not be created in QML"));
qmlRegisterSingletonType<Tagging>("org.maui.pix", 1, 0, "Tag",
[](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject* {
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return DBActions::getInstance()->tag;
});
qmlRegisterType<BaseModel>("PixModel", 1, 0, "PixModel");
qmlRegisterType<Gallery>("GalleryList", 1, 0, "GalleryList");
qmlRegisterType<Albums>("AlbumsList", 1, 0, "AlbumsList");
qmlRegisterType<FolderModel>("FolderModel", 1, 0, "FolderModel");
qmlRegisterType<Folders>("FoldersList", 1, 0, "FoldersList");
// qmlRegisterType<Cloud>("CloudList", 1, 0, "CloudList");
// qmlRegisterType<Cloud>("CloudList", 1, 0, "CloudList");
#ifdef STATIC_KIRIGAMI
KirigamiPlugin::getInstance().registerTypes();
......
......@@ -26,35 +26,30 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
DB::DB(QObject *parent) : QObject(parent)
{
this->initDB();
}
DB::~DB()
{
// this->m_db.close();
}
void DB::initDB()
{
QDir collectionDBPath_dir(PIX::CollectionDBPath);
QDir collectionDBPath_dir(PIX::CollectionDBPath.toLocalFile());
if (!collectionDBPath_dir.exists())
collectionDBPath_dir.mkpath(".");
this->name = QUuid::createUuid().toString();
if(!FMH::fileExists(PIX::CollectionDBPath + PIX::DBName))
if(!FMH::fileExists(PIX::CollectionDBPath.toLocalFile() + PIX::DBName))
{
this->openDB(this->name);
qDebug()<<"Collection doesn't exists, trying to create it" << PIX::CollectionDBPath + PIX::DBName;
qDebug()<<"Collection doesn't exists, trying to create it" << PIX::CollectionDBPath.toLocalFile() + PIX::DBName;
this->prepareCollectionDB();
}else this->openDB(this->name);
}
DB::~DB()
{
this->m_db.close();
}
void DB::openDB(const QString &name)
{
if(!QSqlDatabase::contains(name))
{
this->m_db = QSqlDatabase::addDatabase(QStringLiteral("QSQLITE"), name);
this->m_db.setDatabaseName(PIX::CollectionDBPath + PIX::DBName);
this->m_db.setDatabaseName(PIX::CollectionDBPath.toLocalFile() + PIX::DBName);
}
if (!this->m_db.isOpen())
......
......@@ -63,7 +63,6 @@ public:
QVariantList getList(const QString &queryTxt);
protected:
void initDB();
void openDB(const QString &name);
void prepareCollectionDB() const;
......
......@@ -26,27 +26,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <MauiKit/tagging.h>
#endif
DBActions::DBActions(QObject *parent) : DB(parent) {}
DBActions::~DBActions() {}
void DBActions::init()
DBActions::DBActions(QObject *parent) : DB(parent)
{
qDebug() << "Getting collectionDB info from: " << PIX::CollectionDBPath;
qDebug()<< "Starting DBActions";
this->tag = Tagging::getInstance();
}
DBActions *DBActions::instance = nullptr;
DBActions *DBActions::getInstance()
{
if(!instance)
{
instance = new DBActions();
qDebug() << "getInstance(): First DBActions instance\n";
instance->init();
instance = new DBActions();
return instance;
} else
{
......@@ -256,7 +249,7 @@ FMH::MODEL_LIST DBActions::getFolders(const QString &query)
return res;
}
FMH::MODEL_LIST DBActions::getDBData(const QString &queryTxt)
FMH::MODEL_LIST DBActions::getDBData(const QString &queryTxt, std::function<void(FMH::MODEL &item)> modifier)
{
FMH::MODEL_LIST mapList;
......@@ -267,18 +260,12 @@ FMH::MODEL_LIST DBActions::getDBData(const QString &queryTxt)
while(query.next())
{
FMH::MODEL data;
for(auto key : FMH::MODEL_NAME.keys())
for(const auto &key : FMH::MODEL_NAME.keys())
if(query.record().indexOf(FMH::MODEL_NAME[key]) > -1)
data.insert(key, query.value(FMH::MODEL_NAME[key]).toString());
const auto url = data[FMH::MODEL_KEY::URL];
if(!url.isEmpty())
{
if(FMH::fileExists(url))
mapList<< data;
else
this->removePic(data[FMH::MODEL_KEY::URL]);
}else mapList<< data;
if(modifier)
modifier(data);
mapList << data;
}
}else qDebug()<< query.lastError()<< query.lastQuery();
......
......@@ -58,7 +58,7 @@ public:
/* utils */
FMH::MODEL_LIST getFolders(const QString &query);
FMH::MODEL_LIST getDBData(const QString &queryTxt);
FMH::MODEL_LIST getDBData(const QString &queryTxt, std::function<void(FMH::MODEL &item)> modifier = nullptr);
public slots:
QVariantList get(const QString &queryTxt);
......@@ -73,8 +73,7 @@ public slots:
private:
static DBActions* instance;
explicit DBActions(QObject *parent = nullptr);
~DBActions();
void init();
signals:
void tagAdded(QString tag);
void albumAdded(QString album);
......
......@@ -24,6 +24,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QObject>
#include <QDirIterator>
#include <QFileInfo>
#include <QThread>
#include "dbactions.h"
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
......@@ -32,6 +34,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "fmh.h"
#endif
class MThread : public QThread
{
};
class FileLoader : public QObject
{
Q_OBJECT
......@@ -39,83 +46,72 @@ class FileLoader : public QObject
public:
FileLoader() : QObject()
{
this->dba = DBActions::getInstance();
qRegisterMetaType<PIX::TABLE>("PIX::TABLE");
qRegisterMetaType<QMap<PIX::TABLE, bool>>("QMap<PIX::TABLE,bool>");
// qRegisterMetaType<PIX::TABLE>("PIX::TABLE");
// qRegisterMetaType<QMap<PIX::TABLE, bool>>("QMap<PIX::TABLE,bool>");
this->moveToThread(&t);
t.start();
}
~FileLoader()
{
this->go = false;
this->t.quit();
this->t.wait();
connect(this, &FileLoader::start, this, &FileLoader::getPics);
}
void requestPath(QStringList paths)
void requestPath(const QList<QUrl> &urls)
{
qDebug()<<"FROM file loader"<< paths;
qDebug()<<"FROM file loader"<< urls;
this->go = true;
QMetaObject::invokeMethod(this, "getPics", Q_ARG(QStringList, paths));
}
void nextTrack()
{
this->wait = !this->wait;
this->t.start();
emit this->start(urls);
}
public slots:
void getPics(QStringList paths)
private slots:
void getPics(QList<QUrl> paths)
{
qDebug()<<"GETTING IMAGES";
QStringList urls;
QList<QUrl> urls;
const auto db_ = DBActions::getInstance();
for(const auto &path : paths)
if (QFileInfo(path).isDir())
{
if (QFileInfo(path.toLocalFile()).isDir() && path.isLocalFile())
{
QDirIterator it(path, FMH::FILTER_LIST[FMH::FILTER_TYPE::IMAGE], QDir::Files, QDirIterator::Subdirectories);
QDirIterator it(path.toLocalFile(), FMH::FILTER_LIST[FMH::FILTER_TYPE::IMAGE], QDir::Files, QDirIterator::Subdirectories);
while (it.hasNext())
urls << it.next();
urls << QUrl::fromLocalFile(it.next());
}else if (QFileInfo(path).isFile())
}else if (QFileInfo(path.toLocalFile()).isFile())
urls << path;
}
int newPics = 0;
uint newPics = 0;
if(urls.size() > 0)
{
for(auto url : urls)
for(const auto &url : urls)
{
if(go)
{
if(this->dba->addPic(url))
if(db_->addPic(url.toString()))
newPics++;
}else break;
}
emit collectionSize(newPics);
emit this->collectionSize(newPics);
}
this->t.msleep(100);
// this->t.msleep(100);
emit this->finished(newPics);
this->go = false;
t.quit();
}
signals:
void finished(int size);
void collectionSize(int size);
void finished(uint size);
void collectionSize(uint size);
void start(QList<QUrl> urls);
private:
DBActions * dba;
QThread t;
bool go = false;
bool wait = true;
QStringList queue;
};
......
......@@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.3
import org.kde.kirigami 2.6 as Kirigami
......@@ -44,15 +44,15 @@ import "widgets/views/Pix.js" as PIX
import "widgets/views/Viewer/Viewer.js" as VIEWER
import "db/Query.js" as Q
import PixModel 1.0
import AlbumsList 1.0
import TagsModel 1.0
import TagsList 1.0
import org.maui.pix 1.0 as Pix
//import SyncingModel 1.0
//import SyncingList 1.0
import StoreList 1.0
//import StoreList 1.0
Maui.ApplicationWindow
{
......@@ -77,7 +77,6 @@ Maui.ApplicationWindow
})
/*PROPS*/
property int currentView : views.gallery
property bool fullScreen : false
property bool selectionMode : false
......@@ -86,26 +85,26 @@ Maui.ApplicationWindow
/******************** UI COLORS *******************/
/*************************************************/
// highlightColor : "#00abaa"
// altColor : "#2e2f30" // "#545c6e"
// accentColor: altColor
// altColorText: "#fafafa"
// highlightColor : "#00abaa"
// altColor : "#2e2f30" // "#545c6e"
// accentColor: altColor
// altColorText: "#fafafa"
// colorSchemeName: "pix"
// bgColor: backgroundColor
// headBar.drawBorder: false
// headBarBGColor: backgroundColor
// headBarFGColor: currentView === views.viewer ? altColorText : Maui.Style.textColor
// backgroundColor: currentView === views.viewer ? "#3c3e3f" : viewBackgroundColor
// viewBackgroundColor: currentView === views.viewer ? backgroundColor : Maui.Style.viewBackgroundColor
// colorSchemeName: "pix"
// bgColor: backgroundColor
// headBar.drawBorder: false
// headBarBGColor: backgroundColor
// headBarFGColor: currentView === views.viewer ? altColorText : Maui.Style.textColor
// backgroundColor: currentView === views.viewer ? "#3c3e3f" : viewBackgroundColor
// viewBackgroundColor: currentView === views.viewer ? backgroundColor : Maui.Style.viewBackgroundColor
/***************************************************/
/**************************************************/
/*************************************************/
onSearchButtonClicked: currentView = views.search
// rightIcon.icon.color: currentView === views.search ? highlightColor : headBarFGColor
// rightIcon.showIndicator: currentView === views.search
// rightIcon.icon.color: currentView === views.search ? highlightColor : headBarFGColor
// rightIcon.showIndicator: currentView === views.search
// menuDrawer.bannerImageSource: "qrc:/img/assets/banner.png"
mainMenu: [
......@@ -134,17 +133,17 @@ Maui.ApplicationWindow
icon.name: "folder-add"
onTriggered:
{
dialogLoader.sourceComponent = sourcesDialogComponent;
dialog.open()
dialogLoader.sourceComponent = sourcesDialogComponent;
dialog.open()
// dialogLoader.sourceComponent= fmDialogComponent
// dialog.mode= dialog.modes.OPEN
// dialog.onlyDirs= true
// dialog.show(function(paths)
// {
// pix.addSources(paths)
// })
// dialogLoader.sourceComponent= fmDialogComponent
// dialog.mode= dialog.modes.OPEN
// dialog.onlyDirs= true
// dialog.show(function(paths)
// {
// pix.addSources(paths)
// })
}
},
......@@ -168,67 +167,46 @@ Maui.ApplicationWindow
]
headBar.visible: !fullScreen
headBar.spacing: space.big
headBar.middleContent: Kirigami.ActionToolBar
headBar.spacing: Maui.Style.space.big
headBar.middleContent: Maui.ActionGroup
{
hiddenActions: [
id: _actionGroup
Layout.fillHeight: true
Layout.minimumWidth: implicitWidth
currentIndex : swipeView.currentIndex
onCurrentIndexChanged: swipeView.currentIndex = currentIndex
Kirigami.Action
hiddenActions: [
Action
{
id: _tagsButton
text: qsTr("Tags")
onTriggered: currentView = views.tags
icon.name: "tag"
}
]
actions: [
Kirigami.Action
{
text: qsTr("Viewer")
// showIndicator: true
checked: currentView === views.viewer
checkable: false
visible: !pixViewer.holder.visible
// icon.color: checked ? highlightColor : headBarFGColor
icon.name: "image"
onTriggered: currentView = views.viewer
},
Kirigami.Action
{
text: qsTr("Gallery")
checked: currentView === views.gallery
// showIndicator: true
// icon.color: checked ? highlightColor : headBarFGColor
icon.name: "folder-image"
onTriggered: currentView = views.gallery
},
Kirigami.Action
{
text: qsTr("Folders")
checked: currentView === views.folders
checkable: false
// showIndicator: true
// icon.color: active ? highlightColor : headBarFGColor
icon.name: "folder"
onTriggered: currentView = views.folders
},
Kirigami.Action
{
text: qsTr("Albums")
checked: currentView === views.albums
checkable: false
// showIndicator: true
// icon.color: checked ? highlightColor : headBarFGColor
icon.name: "image-frames"
onTriggered: currentView = views.albums
}
]
Action
{
text: qsTr("Viewer")
icon.name: "image"
}
Action
{
text: qsTr("Gallery")
icon.name: "folder-image"
}
Action
{
text: qsTr("Folders")
icon.name: "folder"
}
Action
{
text: qsTr("Albums")
icon.name: "image-frames"
}
}
ColumnLayout
......@@ -240,51 +218,50 @@ Maui.ApplicationWindow
id: swipeView
Layout.fillHeight: true
Layout.fillWidth: true
interactive: isMobile
currentIndex: currentView
interactive: Kirigami.Settings.isMobile
currentIndex: _actionGroup.currentIndex
onCurrentIndexChanged: _actionGroup.currentIndex = currentIndex
onCurrentIndexChanged: currentView = currentIndex
PixViewer
{
id: pixViewer
}
// PixViewer
// {
// id: pixViewer
// }
GalleryView
{
id: galleryView
}
FoldersView
{
id: foldersView
}
// FoldersView
// {
// id: foldersView
// }
AlbumsView
{
id: albumsView
}
// AlbumsView
// {
// id: albumsView
// }
TagsView
{
id: tagsView
}
// TagsView
// {
// id: tagsView
// }
// Loader
// {
// id: cloudViewLoader
// }
// // Loader
// // {
// // id: cloudViewLoader
// // }
// Loader
// {
// id: storeViewLoader
// }
// // Loader
// // {
// // id: storeViewLoader
// // }
SearchView
{
id: searchView
}
// SearchView
// {
// id: searchView
// }
}
......@@ -292,10 +269,10 @@ Maui.ApplicationWindow
{
id: selectionBox
Layout.fillWidth : true
Layout.leftMargin: space.big
Layout.rightMargin: space.big
Layout.bottomMargin: space.big
Layout.topMargin: space.small
Layout.leftMargin: Maui.Style.space.big
Layout.rightMargin: Maui.Style.space.big
Layout.bottomMargin: Maui.Style.space.big
Layout.topMargin: Maui.Style.space.small
}
}
......@@ -422,7 +399,7 @@ Maui.ApplicationWindow
}
/***MODELS****/
PixModel
Maui.BaseModel
{
id: albumsModel
list: albumsList
......@@ -445,9 +422,10 @@ Maui.ApplicationWindow
id: tagsList
}
Connections
{
target: pix
target: Pix.Collection
onRefreshViews: PIX.refreshViews()
onViewPics: VIEWER.openExternalPics(pics, 0)
}
......
#include "albums.h"
#include "./src/db/dbactions.h"
Albums::Albums(QObject *parent) : BaseList(parent)
Albums::Albums(QObject *parent) : MauiList(parent)
{
qDebug()<< "CREATING GALLERY LIST";
this->dba = DBActions::getInstance();
......
......@@ -2,10 +2,17 @@
#define ALBUMS_H
#include <QObject>
#include "./src/models/baselist.h"
#ifdef STATIC_MAUIKIT
#include "fmh.h"
#include "mauilist.h"
#else
#include <MauiKit/fmh.h>
#include <MauiKit/mauilist.h>
#endif
class DBActions;
class Albums : public BaseList
class Albums : public MauiList
{
Q_OBJECT
Q_PROPERTY(QString query READ getQuery WRITE setQuery NOTIFY queryChanged())
......@@ -13,7 +20,7 @@ class Albums : public BaseList
public:
explicit Albums(QObject *parent = nullptr);
FMH::MODEL_LIST items() const override;
FMH::MODEL_LIST items() const override final;
void setQuery(const QString &query);
QString getQuery() const;
......@@ -38,12 +45,12 @@ signals:
void sortByChanged();
public slots:
QVariantMap get(const int &index) const override;
bool insert(const QVariantMap &pic) override;
bool update(const int &index, const QVariant &value, const int &role) override; //deprecrated
bool update(const QVariantMap &data, const int &index) override;
bool update(const FMH::MODEL &pic) override;
bool remove(const int &index) override;
QVariantMap get(const int &index) const;
bool insert(const QVariantMap &pic);