Commit 099b003e authored by Camilo higuita's avatar Camilo higuita

continue port to new model

parent df2674c5
...@@ -49,10 +49,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ...@@ -49,10 +49,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <MauiKit/tagging.h> #include <MauiKit/tagging.h>
#endif #endif
#include "src/models/basemodel.h" #include "./src/models/basemodel.h"
#include "src/models/baselist.h" #include "./src/models/baselist.h"
#include "src/models/gallery/gallery.h" #include "./src/models/gallery/gallery.h"
#include "src/models/albums/albums.h" #include "./src/models/albums/albums.h"
#include "./src/models/folders/foldermodel.h"
#include "./src/models/folders/folders.h"
QStringList getFolderImages(const QString &path) QStringList getFolderImages(const QString &path)
{ {
...@@ -127,7 +130,10 @@ int main(int argc, char *argv[]) ...@@ -127,7 +130,10 @@ int main(int argc, char *argv[])
auto context = engine.rootContext(); auto context = engine.rootContext();
context->setContextProperty("pix", &pix); context->setContextProperty("pix", &pix);
context->setContextProperty("tag", pix.tag);
const auto dba = DBActions::getInstance();
context->setContextProperty("tag", dba->tag);
context->setContextProperty("dba", dba);
qmlRegisterUncreatableMetaObject(PIX::staticMetaObject, "PIX", 1, 0, "KEY", "Error"); qmlRegisterUncreatableMetaObject(PIX::staticMetaObject, "PIX", 1, 0, "KEY", "Error");
...@@ -136,6 +142,8 @@ int main(int argc, char *argv[]) ...@@ -136,6 +142,8 @@ int main(int argc, char *argv[])
qmlRegisterType<BaseModel>("PixModel", 1, 0, "PixModel"); qmlRegisterType<BaseModel>("PixModel", 1, 0, "PixModel");
qmlRegisterType<Gallery>("GalleryList", 1, 0, "GalleryList"); qmlRegisterType<Gallery>("GalleryList", 1, 0, "GalleryList");
qmlRegisterType<Albums>("AlbumsList", 1, 0, "AlbumsList"); qmlRegisterType<Albums>("AlbumsList", 1, 0, "AlbumsList");
qmlRegisterType<FolderModel>("FolderModel", 1, 0, "FolderModel");
qmlRegisterType<Folders>("FoldersList", 1, 0, "FoldersList");
#ifdef STATIC_KIRIGAMI #ifdef STATIC_KIRIGAMI
KirigamiPlugin::getInstance().registerTypes(); KirigamiPlugin::getInstance().registerTypes();
......
...@@ -48,7 +48,9 @@ SOURCES += main.cpp \ ...@@ -48,7 +48,9 @@ SOURCES += main.cpp \
src/models/basemodel.cpp \ src/models/basemodel.cpp \
src/models/baselist.cpp \ src/models/baselist.cpp \
src/models/gallery/gallery.cpp \ src/models/gallery/gallery.cpp \
src/models/albums/albums.cpp src/models/albums/albums.cpp \
src/models/folders/folders.cpp \
src/models/folders/foldermodel.cpp \
# Additional import path used to resolve QML modules in Qt Creator's code model # Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH = QML_IMPORT_PATH =
...@@ -75,7 +77,9 @@ HEADERS += \ ...@@ -75,7 +77,9 @@ HEADERS += \
src/models/basemodel.h \ src/models/basemodel.h \
src/models/baselist.h \ src/models/baselist.h \
src/models/gallery/gallery.h \ src/models/gallery/gallery.h \
src/models/albums/albums.h src/models/albums/albums.h \
src/models/folders/folders.h \
src/models/folders/foldermodel.h
include(install.pri) include(install.pri)
......
...@@ -22,15 +22,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ...@@ -22,15 +22,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "db.h" #include "db.h"
#ifdef STATIC_MAUIKIT #ifdef STATIC_MAUIKIT
#include "fmh.h"
#include "tagging.h" #include "tagging.h"
#else #else
#include <MauiKit/fmh.h>
#include <MauiKit/tagging.h> #include <MauiKit/tagging.h>
#endif #endif
DBActions::DBActions(QObject *parent) : QObject(parent) {}
DBActions::DBActions(QObject *parent) : QObject(parent) DBActions::~DBActions() {}
void DBActions::init()
{ {
qDebug() << "Getting collectionDB info from: " << PIX::CollectionDBPath; qDebug() << "Getting collectionDB info from: " << PIX::CollectionDBPath;
...@@ -40,8 +41,22 @@ DBActions::DBActions(QObject *parent) : QObject(parent) ...@@ -40,8 +41,22 @@ DBActions::DBActions(QObject *parent) : QObject(parent)
this->tag = Tagging::getInstance(PIX::App, PIX::version, "org.kde.pix", PIX::comment); this->tag = Tagging::getInstance(PIX::App, PIX::version, "org.kde.pix", PIX::comment);
} }
DBActions::~DBActions() {} DBActions *DBActions::instance = nullptr;
DBActions *DBActions::getInstance()
{
if(!instance)
{
instance = new DBActions();
qDebug() << "getInstance(): First DBActions instance\n";
instance->init();
return instance;
} else
{
qDebug()<< "getInstance(): previous DBActions instance\n";
return instance;
}
}
bool DBActions::execQuery(const QString &queryTxt) bool DBActions::execQuery(const QString &queryTxt)
{ {
...@@ -131,6 +146,10 @@ bool DBActions::removePic(const QString &url) ...@@ -131,6 +146,10 @@ bool DBActions::removePic(const QString &url)
bool DBActions::favPic(const QString &url, const bool &fav ) bool DBActions::favPic(const QString &url, const bool &fav )
{ {
if(!this->db->checkExistance("images", "url", url))
if(!this->addPic(url))
return false;
PIX::DB favedPic = {{PIX::KEY::FAV, fav ? "1" : "0"}}; PIX::DB favedPic = {{PIX::KEY::FAV, fav ? "1" : "0"}};
return this->db->update(PIX::TABLEMAP[PIX::TABLE::IMAGES], favedPic, QVariantMap({{PIX::KEYMAP[PIX::KEY::URL], url}}) ); return this->db->update(PIX::TABLEMAP[PIX::TABLE::IMAGES], favedPic, QVariantMap({{PIX::KEYMAP[PIX::KEY::URL], url}}) );
} }
...@@ -179,6 +198,17 @@ bool DBActions::cleanTags() ...@@ -179,6 +198,17 @@ bool DBActions::cleanTags()
return false; return false;
} }
bool DBActions::addAlbum(const QString &album)
{
QVariantMap albumMap
{
{PIX::KEYMAP[PIX::KEY::ALBUM], album},
{PIX::KEYMAP[PIX::KEY::ADD_DATE], QDateTime::currentDateTime()}
};
return this->db->insert(PIX::TABLEMAP[PIX::TABLE::ALBUMS], albumMap);
}
bool DBActions::picAlbum(const QString &album, const QString &url) bool DBActions::picAlbum(const QString &album, const QString &url)
{ {
qDebug()<<"Trying to add to album"<<album<<url; qDebug()<<"Trying to add to album"<<album<<url;
...@@ -201,14 +231,19 @@ QVariantList DBActions::searchFor(const QStringList &queries, const QString &que ...@@ -201,14 +231,19 @@ QVariantList DBActions::searchFor(const QStringList &queries, const QString &que
return res; return res;
} }
QVariantList DBActions::getFolders(const QString &query) FMH::MODEL_LIST DBActions::getFolders(const QString &query)
{ {
QVariantList res; FMH::MODEL_LIST res;
auto data = this->db->getDBData(query); auto data = this->db->getDBData(query);
/*Data model keys for to be used on MauiKit Icondelegate component */ /*Data model keys for to be used on MauiKit Icondelegate component */
for(auto i : data) for(auto i : data)
res << FMH::getFileInfo(i[PIX::KEY::URL]); res << FMH::getFileInfoModel(i[PIX::KEY::URL]);
return res; return res;
} }
PIX::DB_LIST DBActions::getDBData(const QString &query)
{
return this->db->getDBData(query);
}
...@@ -24,41 +24,55 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ...@@ -24,41 +24,55 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QObject> #include <QObject>
#include "../utils/pic.h" #include "../utils/pic.h"
#ifdef STATIC_MAUIKIT
#include "fmh.h"
#else
#include <MauiKit/fmh.h>
#endif
class DB; class DB;
class Tagging; class Tagging;
class DBActions : public QObject class DBActions : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DBActions(QObject *parent = nullptr);
~DBActions();
static DBActions *getInstance();
Tagging *tag; Tagging *tag;
bool execQuery(const QString &queryTxt); bool execQuery(const QString &queryTxt);
bool insertPic(const PIX::DB &img); bool insertPic(const PIX::DB &img);
Q_INVOKABLE bool addPic(const QString &url); bool addPic(const QString &url);
Q_INVOKABLE bool removePic(const QString &url); bool removePic(const QString &url);
/* actions on model */ /* actions on model */
Q_INVOKABLE bool favPic(const QString &url, const bool &fav); bool addTag(const QString &tag);
Q_INVOKABLE bool isFav(const QString &url); bool albumTag(const QString &tag, const QString &album);
bool removePicTag(const QString &tag, const QString &url);
bool removeAlbumTag(const QString &tag, const QString &album);
bool cleanTags();
Q_INVOKABLE bool addTag(const QString &tag); bool addAlbum(const QString &album);
Q_INVOKABLE bool albumTag(const QString &tag, const QString &album); bool picAlbum(const QString &album, const QString &url);
Q_INVOKABLE bool removePicTag(const QString &tag, const QString &url);
Q_INVOKABLE bool removeAlbumTag(const QString &tag, const QString &album);
Q_INVOKABLE bool cleanTags();
Q_INVOKABLE bool picAlbum(const QString &album, const QString &url); QVariantList searchFor(const QStringList &queries, const QString &queryTxt);
Q_INVOKABLE QVariantList searchFor(const QStringList &queries, const QString &queryTxt);
/* utils */ /* utils */
Q_INVOKABLE QVariantList getFolders(const QString &query); FMH::MODEL_LIST getFolders(const QString &query);
PIX::DB_LIST getDBData(const QString &query);
public slots:
bool favPic(const QString &url, const bool &fav);
bool isFav(const QString &url);
private: private:
DB *db; DB *db;
static DBActions* instance;
explicit DBActions(QObject *parent = nullptr);
~DBActions();
void init();
signals: signals:
void tagAdded(QString tag); void tagAdded(QString tag);
}; };
......
...@@ -32,13 +32,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ...@@ -32,13 +32,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "fmh.h" #include "fmh.h"
#endif #endif
class FileLoader : public DBActions class FileLoader : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
FileLoader() : DBActions() FileLoader() : QObject()
{ {
this->dba = DBActions::getInstance();
qRegisterMetaType<PIX::DB>("PIX::DB"); qRegisterMetaType<PIX::DB>("PIX::DB");
qRegisterMetaType<PIX::TABLE>("PIX::TABLE"); qRegisterMetaType<PIX::TABLE>("PIX::TABLE");
qRegisterMetaType<QMap<PIX::TABLE, bool>>("QMap<PIX::TABLE,bool>"); qRegisterMetaType<QMap<PIX::TABLE, bool>>("QMap<PIX::TABLE,bool>");
...@@ -93,7 +94,7 @@ public slots: ...@@ -93,7 +94,7 @@ public slots:
{ {
if(go) if(go)
{ {
if(this->addPic(url)) if(this->dba->addPic(url))
newPics++; newPics++;
}else break; }else break;
} }
...@@ -107,11 +108,11 @@ public slots: ...@@ -107,11 +108,11 @@ public slots:
} }
signals: signals:
void trackReady(PIX::DB track);
void finished(int size); void finished(int size);
void collectionSize(int size); void collectionSize(int size);
private: private:
DBActions * dba;
QThread t; QThread t;
bool go = false; bool go = false;
bool wait = true; bool wait = true;
......
...@@ -150,6 +150,7 @@ Maui.ApplicationWindow ...@@ -150,6 +150,7 @@ Maui.ApplicationWindow
} }
] ]
content: ColumnLayout content: ColumnLayout
{ {
id: mainPage id: mainPage
...@@ -286,8 +287,9 @@ Maui.ApplicationWindow ...@@ -286,8 +287,9 @@ Maui.ApplicationWindow
Connections Connections
{ {
target: pix target: pix
// onRefreshViews: PIX.refreshViews() onRefreshViews: PIX.refreshViews()
onViewPics: VIEWER.openExternalPics(pics, 0) onViewPics: VIEWER.openExternalPics(pics, 0)
onNewPic: console.log(pic.url)
} }
Connections Connections
......
#include "albums.h" #include "albums.h"
#include "./src/db/db.h" #include "./src/db/dbactions.h"
#ifdef STATIC_MAUIKIT #ifdef STATIC_MAUIKIT
#include "fmh.h" #include "fmh.h"
#include "tagging.h"
#else #else
#include <MauiKit/fmh.h> #include <MauiKit/fmh.h>
#include <MauiKit/tagging.h>
#endif #endif
Albums::Albums(QObject *parent) : BaseList(parent) Albums::Albums(QObject *parent) : BaseList(parent)
{ {
qDebug()<< "CREATING GALLERY LIST"; qDebug()<< "CREATING GALLERY LIST";
this->db = DB::getInstance(); this->dba = DBActions::getInstance();
this->tag = Tagging::getInstance(PIX::App, PIX::version, "org.kde.pix", PIX::comment);
this->tag = Tagging::getInstance(PIX::App, PIX::version, "org.kde.pix", PIX::comment);
this->sortList(); this->sortList();
connect(this, &Albums::sortByChanged, this, &Albums::sortList); connect(this, &Albums::sortByChanged, this, &Albums::sortList);
...@@ -106,24 +101,13 @@ void Albums::setList() ...@@ -106,24 +101,13 @@ void Albums::setList()
{ {
emit this->preListChanged(); emit this->preListChanged();
this->list = this->db->getDBData(this->query); this->list = this->dba->getDBData(this->query);
qDebug()<< "ALBUMS LIST READY"<< list; qDebug()<< "ALBUMS LIST READY"<< list;
this->sortList(); this->sortList();
emit this->postListChanged(); emit this->postListChanged();
} }
bool Albums::addAlbum(const QString &album)
{
QVariantMap albumMap
{
{PIX::KEYMAP[PIX::KEY::ALBUM], album},
{PIX::KEYMAP[PIX::KEY::ADD_DATE], QDateTime::currentDateTime()}
};
return this->db->insert(PIX::TABLEMAP[PIX::TABLE::ALBUMS], albumMap);
}
QVariantMap Albums::get(const int &index) const QVariantMap Albums::get(const int &index) const
{ {
if(index >= this->list.size() || index < 0) if(index >= this->list.size() || index < 0)
...@@ -142,7 +126,7 @@ bool Albums::insert(const QVariantMap &pic) ...@@ -142,7 +126,7 @@ bool Albums::insert(const QVariantMap &pic)
{ {
emit this->preItemAppended(); emit this->preItemAppended();
if(this->addAlbum(pic[PIX::KEYMAP[PIX::KEY::ALBUM]].toString())) if(this->dba->addAlbum(pic[PIX::KEYMAP[PIX::KEY::ALBUM]].toString()))
{ {
emit postItemAppended(); emit postItemAppended();
return true; return true;
......
...@@ -5,8 +5,7 @@ ...@@ -5,8 +5,7 @@
#include "./src/models/baselist.h" #include "./src/models/baselist.h"
#include "./src/utils/pic.h" #include "./src/utils/pic.h"
class DB; class DBActions;
class Tagging;
class Albums : public BaseList class Albums : public BaseList
{ {
Q_OBJECT Q_OBJECT
...@@ -24,8 +23,7 @@ public: ...@@ -24,8 +23,7 @@ public:
uint getSortBy() const; uint getSortBy() const;
private: private:
DB *db; DBActions *dba;
Tagging *tag;
PIX::DB_LIST list; PIX::DB_LIST list;
void sortList(); void sortList();
void setList(); void setList();
...@@ -34,7 +32,6 @@ private: ...@@ -34,7 +32,6 @@ private:
uint sort = PIX::KEY::ADD_DATE; uint sort = PIX::KEY::ADD_DATE;
protected: protected:
bool addAlbum(const QString &album);
signals: signals:
void queryChanged(); void queryChanged();
......
...@@ -46,7 +46,7 @@ Qt::ItemFlags BaseModel::flags(const QModelIndex &index) const ...@@ -46,7 +46,7 @@ Qt::ItemFlags BaseModel::flags(const QModelIndex &index) const
QHash<int, QByteArray> BaseModel::roleNames() const QHash<int, QByteArray> BaseModel::roleNames() const
{ {
QHash<int, QByteArray> names; QHash<int, QByteArray> names;
for(auto key : PIX::KEYMAP.keys()) for(auto key : PIX::KEYMAP.keys())
names[key] = QString(PIX::KEYMAP[key]).toUtf8(); names[key] = QString(PIX::KEYMAP[key]).toUtf8();
return names; return names;
...@@ -107,3 +107,8 @@ void BaseModel::setList(BaseList *value) ...@@ -107,3 +107,8 @@ void BaseModel::setList(BaseList *value)
endResetModel(); endResetModel();
} }
QVariantMap BaseModel::get(const int &index) const
{
return this->mList->get(index);
}
...@@ -32,6 +32,9 @@ private: ...@@ -32,6 +32,9 @@ private:
BaseList *mList; BaseList *mList;
signals: signals:
void listChanged(); void listChanged();
public slots:
QVariantMap get(const int &index) const;
}; };
#endif // NOTESMODEL_H #endif // NOTESMODEL_H
#include "foldermodel.h"
#include "folders.h"
#ifdef STATIC_MAUIKIT
#include "fmh.h"
#else
#include <MauiKit/fmh.h>
#endif
FolderModel::FolderModel(QObject *parent)
: QAbstractListModel(parent),
mList(nullptr)
{}
int FolderModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid() || !mList)
return 0;
return mList->items().size();
}
QVariant FolderModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || !mList)
return QVariant();
return mList->items().at(index.row())[static_cast<FMH::MODEL_KEY>(role)];
}
bool FolderModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
return false;
}
Qt::ItemFlags FolderModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return Qt::NoItemFlags;
return Qt::ItemIsEditable; // FIXME: Implement me!
}
QHash<int, QByteArray> FolderModel::roleNames() const
{
QHash<int, QByteArray> names;
for(auto key : FMH::MODEL_NAME.keys())
names[key] = QString(FMH::MODEL_NAME[key]).toUtf8();
return names;
}
Folders *FolderModel::getList() const
{
return this->mList;
}
void FolderModel::setList(Folders *value)
{
beginResetModel();
if(mList)
mList->disconnect(this);
mList = value;
if(mList)
{
connect(this->mList, &Folders::preItemAppended, this, [=]()
{
const int index = mList->items().size();
beginInsertRows(QModelIndex(), index, index);
});
connect(this->mList, &Folders::postItemAppended, this, [=]()
{
endInsertRows();
});
connect(this->mList, &Folders::preItemRemoved, this, [=](int index)
{
beginRemoveRows(QModelIndex(), index, index);
});
connect(this->mList, &Folders::postItemRemoved, this, [=]()
{
endRemoveRows();
});
connect(this->mList, &Folders::updateModel, this, [=](int index, QVector<int> roles)
{
emit this->dataChanged(this->index(index), this->index(index), roles);
});
connect(this->mList, &Folders::preListChanged, this, [=]()
{
beginResetModel();
});
connect(this->mList, &Folders::postListChanged, this, [=]()
{
endResetModel();
});
}
endResetModel();
}
#ifndef FOLDERMODEL_H
#define FOLDERMODEL_H
#include <QAbstractListModel>
#include <QList>
class Folders;
class FolderModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(Folders *list READ getList WRITE setList)
public:
explicit FolderModel(QObject *parent = nullptr);
// Basic functionality:
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;