Commit 57e8ad12 authored by camilo higuita's avatar camilo higuita

not more albums and instead use tagging features

parent 08f59df1
......@@ -23,7 +23,6 @@ set(pix_SRCS
src/db/db.cpp
src/db/dbactions.cpp
src/models/gallery/gallery.cpp
src/models/albums/albums.cpp
src/models/folders/folders.cpp
)
......@@ -34,7 +33,6 @@ set(pix_HDRS
src/db/dbactions.h
src/utils/pic.h
src/models/gallery/gallery.h
src/models/albums/albums.h
src/models/folders/folders.h
)
......
......@@ -50,7 +50,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#endif
#include "./src/models/gallery/gallery.h"
#include "./src/models/albums/albums.h"
//#include "./src/models/cloud/cloud.h"
#include "./src/models/folders/foldermodel.h"
......@@ -146,11 +145,10 @@ int main(int argc, char *argv[])
[](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject* {
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return DBActions::getInstance()->tag;
return Tagging::getInstance();
});
qmlRegisterType<Gallery>("GalleryList", 1, 0, "GalleryList");
qmlRegisterType<Albums>("AlbumsList", 1, 0, "AlbumsList");
qmlRegisterType<Folders>("FoldersList", 1, 0, "FoldersList");
// qmlRegisterType<Cloud>("CloudList", 1, 0, "CloudList");
......
......@@ -20,17 +20,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "dbactions.h"
#ifdef STATIC_MAUIKIT
#include "tagging.h"
#else
#include <MauiKit/tagging.h>
#endif
DBActions::DBActions(QObject *parent) : DB(parent)
{
qDebug() << "Getting collectionDB info from: " << PIX::CollectionDBPath;
qDebug()<< "Starting DBActions";
this->tag = Tagging::getInstance();
}
DBActions *DBActions::instance = nullptr;
......@@ -56,55 +49,27 @@ bool DBActions::execQuery(const QString &queryTxt)
bool DBActions::insertPic(const FMH::MODEL &img)
{
auto url = img[FMH::MODEL_KEY::URL];
auto title = img[FMH::MODEL_KEY::TITLE];
auto rate = img[FMH::MODEL_KEY::RATE];
auto fav = img[FMH::MODEL_KEY::FAV];
auto color = img[FMH::MODEL_KEY::COLOR];
auto sourceUrl = img[FMH::MODEL_KEY::SOURCE];
auto picDate = img[FMH::MODEL_KEY::DATE];
auto format = img[FMH::MODEL_KEY::FORMAT];
qDebug()<< "writting to db: "<<title<<url;
/* first needs to insert album and artist*/
QVariantMap sourceMap {{FMH::MODEL_NAME[FMH::MODEL_KEY::URL], sourceUrl}};
QVariantMap sourceMap {{FMH::MODEL_NAME[FMH::MODEL_KEY::URL], img[FMH::MODEL_KEY::SOURCE]}};
this->insert(PIX::TABLEMAP[PIX::TABLE::SOURCES], sourceMap);
QVariantMap imgMap {{FMH::MODEL_NAME[FMH::MODEL_KEY::URL], url},
{FMH::MODEL_NAME[FMH::MODEL_KEY::SOURCE], sourceUrl},
{FMH::MODEL_NAME[FMH::MODEL_KEY::TITLE], title},
{FMH::MODEL_NAME[FMH::MODEL_KEY::RATE], rate},
{FMH::MODEL_NAME[FMH::MODEL_KEY::FAV], fav},
{FMH::MODEL_NAME[FMH::MODEL_KEY::COLOR], color},
{FMH::MODEL_NAME[FMH::MODEL_KEY::FORMAT], format},
{FMH::MODEL_NAME[FMH::MODEL_KEY::DATE], picDate},
{FMH::MODEL_NAME[FMH::MODEL_KEY::PLACE], QString()},
{FMH::MODEL_NAME[FMH::MODEL_KEY::ADDDATE], QDateTime::currentDateTime().toString(Qt::TextDate)}};
return this->insert(PIX::TABLEMAP[PIX::TABLE::IMAGES], imgMap);
return this->insert(PIX::TABLEMAP[PIX::TABLE::IMAGES], FMH::toMap(img));
}
bool DBActions::addPic(const QString &url)
bool DBActions::addPic(const QUrl &url)
{
if(!this->checkExistance(PIX::TABLEMAP[PIX::TABLE::IMAGES], FMH::MODEL_NAME[FMH::MODEL_KEY::URL], url))
if(!this->checkExistance(PIX::TABLEMAP[PIX::TABLE::IMAGES], FMH::MODEL_NAME[FMH::MODEL_KEY::URL], url.toString()))
{
QFileInfo info(url);
auto title = info.baseName();
auto format = info.suffix();
auto sourceUrl = info.dir().path();
const QFileInfo info(url.toLocalFile());
FMH::MODEL picMap =
{
{FMH::MODEL_KEY::URL, url},
{FMH::MODEL_KEY::TITLE, title},
{FMH::MODEL_KEY::FAV, "0"},
{FMH::MODEL_KEY::URL, url.toString()},
{FMH::MODEL_KEY::TITLE, info.baseName()},
{FMH::MODEL_KEY::RATE, "0"},
{FMH::MODEL_KEY::COLOR, ""},
{FMH::MODEL_KEY::SOURCE, sourceUrl},
{FMH::MODEL_KEY::SIZE, QString::number(info.size())},
{FMH::MODEL_KEY::SOURCE, FMH::fileDir(url)},
{FMH::MODEL_KEY::DATE, info.birthTime().toString(Qt::TextDate)},
{FMH::MODEL_KEY::FORMAT, format}
{FMH::MODEL_KEY::ADDDATE, QDateTime::currentDateTime().toString(Qt::TextDate)},
{FMH::MODEL_KEY::FORMAT, info.suffix()}
};
return this->insertPic(picMap);
......@@ -119,12 +84,6 @@ bool DBActions::removePic(const QString &url)
auto query = this->getQuery(queryTxt);
if(query.exec())
{
queryTxt = QString("DELETE FROM images_tags WHERE url = \"%1\"").arg(url);
this->getQuery(queryTxt).exec();
queryTxt = QString("DELETE FROM images_albums WHERE url = \"%1\"").arg(url);
this->getQuery(queryTxt).exec();
queryTxt = QString("DELETE FROM images_notes WHERE url = \"%1\"").arg(url);
this->getQuery(queryTxt).exec();
......@@ -144,90 +103,6 @@ bool DBActions::deletePic(const QString &url)
return false;
}
bool DBActions::favPic(const QString &url, const bool &fav )
{
if(!this->checkExistance("images", "url", url))
if(!this->addPic(url))
return false;
FMH::MODEL favedPic = {{FMH::MODEL_KEY::FAV, fav ? "1" : "0"}};
return this->update(PIX::TABLEMAP[PIX::TABLE::IMAGES], favedPic, QVariantMap({{FMH::MODEL_NAME[FMH::MODEL_KEY::URL], url}}) );
}
bool DBActions::isFav(const QString &url)
{
const auto data = this->getDBData(QString("select * from images where url = '%1'").arg(url));
if (data.isEmpty()) return false;
return data.first()[FMH::MODEL_KEY::FAV] == "1" ? true : false;
}
bool DBActions::addTag(const QString &tag)
{
if (this->tag->tag(tag))
{
emit tagAdded(tag);
return true;
}
return false;
}
bool DBActions::albumTag(const QString &tag, const QString &album)
{
this->addTag(tag);
return this->tag->tagAbstract(tag, FMH::MODEL_NAME[FMH::MODEL_KEY::ALBUM], album);
}
bool DBActions::removePicTag(const QString &tag, const QString &url)
{
FMH::MODEL tagMap {{FMH::MODEL_KEY::URL, url}, {FMH::MODEL_KEY::TAG, tag}};
return this->remove(PIX::TABLEMAP[PIX::TABLE::IMAGES_TAGS], tagMap);
}
bool DBActions::removeAlbumTag(const QString &tag, const QString &album)
{
FMH::MODEL tagMap {{FMH::MODEL_KEY::TAG, tag}, {FMH::MODEL_KEY::ALBUM, album}};
return this->remove(PIX::TABLEMAP[PIX::TABLE::ALBUMS_TAGS], tagMap);
}
bool DBActions::cleanTags()
{
return false;
}
bool DBActions::addAlbum(const QString &album)
{
QVariantMap albumMap
{
{FMH::MODEL_NAME[FMH::MODEL_KEY::ALBUM], album},
{FMH::MODEL_NAME[FMH::MODEL_KEY::ADDDATE], QDateTime::currentDateTime()}
};
if(this->insert(PIX::TABLEMAP[PIX::TABLE::ALBUMS], albumMap))
{
emit this->albumAdded(album);
return true;
}
return false;
}
bool DBActions::picAlbum(const QString &album, const QString &url)
{
qDebug()<<"Trying to add to album"<<album<<url;
this->addAlbum(album);
QVariantMap albumPic
{
{FMH::MODEL_NAME[FMH::MODEL_KEY::URL], url},
{FMH::MODEL_NAME[FMH::MODEL_KEY::ALBUM], album},
{FMH::MODEL_NAME[FMH::MODEL_KEY::ADDDATE], QDateTime::currentDateTime()}
};
return this->insert(PIX::TABLEMAP[PIX::TABLE::IMAGES_ALBUMS], albumPic);
}
QVariantList DBActions::searchFor(const QStringList &queries, const QString &queryTxt)
{
QVariantList res;
......@@ -246,7 +121,7 @@ FMH::MODEL_LIST DBActions::getFolders(const QString &query)
});
}
FMH::MODEL_LIST DBActions::getDBData(const QString &queryTxt, std::function<void(FMH::MODEL &item)> modifier)
FMH::MODEL_LIST DBActions::getDBData(const QString &queryTxt, std::function<bool(FMH::MODEL &item)> modifier)
{
FMH::MODEL_LIST mapList;
......@@ -260,8 +135,13 @@ FMH::MODEL_LIST DBActions::getDBData(const QString &queryTxt, std::function<void
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());
if(modifier)
modifier(data);
{
if(!modifier(data))
continue;
}
mapList << data;
}
......
......@@ -43,31 +43,20 @@ public:
bool execQuery(const QString &queryTxt);
bool insertPic(const FMH::MODEL &img);
bool addPic(const QString &url);
bool addPic(const QUrl &url);
bool removePic(const QString &url);
/* actions on model */
bool addTag(const QString &tag);
bool removePicTag(const QString &tag, const QString &url);
bool cleanTags();
bool addAlbum(const QString &album);
bool picAlbum(const QString &album, const QString &url);
QVariantList searchFor(const QStringList &queries, const QString &queryTxt);
/* utils */
FMH::MODEL_LIST getFolders(const QString &query);
FMH::MODEL_LIST getDBData(const QString &queryTxt, std::function<void(FMH::MODEL &item)> modifier = nullptr);
FMH::MODEL_LIST getDBData(const QString &queryTxt, std::function<bool (FMH::MODEL &)> modifier = nullptr);
public slots:
QVariantList get(const QString &queryTxt);
bool albumTag(const QString &tag, const QString &album);
bool removeAlbumTag(const QString &tag, const QString &album);
bool favPic(const QString &url, const bool &fav);
bool isFav(const QString &url);
bool deletePic(const QString &url);
private:
......@@ -75,8 +64,6 @@ private:
explicit DBActions(QObject *parent = nullptr);
signals:
void tagAdded(QString tag);
void albumAdded(QString album);
void picRemoved();
};
......
......@@ -2,21 +2,12 @@ CREATE TABLE IF NOT EXISTS SOURCES (
url TEXT PRIMARY KEY
);
CREATE TABLE IF NOT EXISTS ALBUMS (
album TEXT PRIMARY KEY,
adddate DATE
);
CREATE TABLE IF NOT EXISTS TAGS (
tag TEXT PRIMARY KEY
);
CREATE TABLE IF NOT EXISTS IMAGES (
url TEXT PRIMARY KEY,
source TEXT NOT NULL,
title TEXT NOT NULL,
rate INTEGER NOT NULL,
fav INTEGER NOT NULL,
size INTEGER,
color TEXT,
adddate DATE,
date DATE,
......@@ -26,23 +17,6 @@ format TEXT,
FOREIGN KEY(source) REFERENCES SOURCES(url)
);
CREATE TABLE IF NOT EXISTS IMAGES_TAGS (
tag TEXT NOT NULL,
url TEXT NOT NULL,
PRIMARY KEY (tag, url),
FOREIGN KEY(tag) REFERENCES TAGS(tag),
FOREIGN KEY(url) REFERENCES IMAGES(url)
);
CREATE TABLE IF NOT EXISTS IMAGES_ALBUMS (
album TEXT NOT NULL,
url TEXT NOT NULL,
adddate DATE,
PRIMARY KEY (album, url),
FOREIGN KEY(album) REFERENCES ALBUMS(album),
FOREIGN KEY(url) REFERENCES IMAGES(url)
);
CREATE TABLE IF NOT EXISTS IMAGES_NOTES (
note TEXT NOT NULL,
url TEXT NOT NULL,
......@@ -51,15 +25,6 @@ PRIMARY KEY (note, url),
FOREIGN KEY(url) REFERENCES IMAGES(url)
);
CREATE TABLE IF NOT EXISTS ALBUMS_TAGS (
tag TEXT NOT NULL,
album TEXT NOT NULL,
PRIMARY KEY (tag, album),
FOREIGN KEY(tag) REFERENCES TAGS(tag),
FOREIGN KEY(album) REFERENCES ALBUMS(album)
);
CREATE TABLE IF NOT EXISTS ALBUMS_NOTES (
note TEXT NOT NULL,
album TEXT NOT NULL,
......@@ -67,7 +32,3 @@ album TEXT NOT NULL,
PRIMARY KEY (note, album),
FOREIGN KEY(album) REFERENCES ALBUMS(album)
);
INSERT INTO ALBUMS VALUES ("Favs", CURRENT_TIME);
INSERT INTO ALBUMS VALUES ("Recent", CURRENT_TIME);
COMMIT;
This diff is collapsed.
#include "albums.h"
#include "./src/db/dbactions.h"
Albums::Albums(QObject *parent) : MauiList(parent)
{
qDebug()<< "CREATING GALLERY LIST";
this->dba = DBActions::getInstance();
this->sortList();
connect(this, &Albums::sortByChanged, this, &Albums::sortList);
connect(this, &Albums::orderChanged, this, &Albums::sortList);
connect(this, &Albums::queryChanged, this, &Albums::setList);
connect(this, &Albums::sortByChanged, this, &Albums::setList);
}
void Albums::setSortBy(const FMH::MODEL_KEY &sort)
{
if(this->sort == sort)
return;
this->sort = sort;
emit this->sortByChanged();
}
FMH::MODEL_KEY Albums::getSortBy() const
{
return this->sort;
}
FMH::MODEL_LIST Albums::items() const
{
return this->list;
}
void Albums::setQuery(const QString &query)
{
if(this->query == query)
return;
this->query = query;
qDebug()<< "setting ALBUMS query"<< this->query;
emit this->queryChanged();
}
QString Albums::getQuery() const
{
return this->query;
}
void Albums::sortList()
{
const auto key = static_cast<FMH::MODEL_KEY>(this->sort);
qSort(this->list.begin(), this->list.end(), [key](const FMH::MODEL &e1, const FMH::MODEL &e2) -> bool
{
auto role = key;
switch(role)
{
case FMH::MODEL_KEY::ADDDATE:
{
auto currentTime = QDateTime::currentDateTime();
auto date1 = QDateTime::fromString(e1[role], Qt::TextDate);
auto date2 = QDateTime::fromString(e2[role], Qt::TextDate);
if(date1.secsTo(currentTime) < date2.secsTo(currentTime))
return true;
break;
}
case FMH::MODEL_KEY::ALBUM:
{
const auto str1 = QString(e1[role]).toLower();
const auto str2 = QString(e2[role]).toLower();
if(str1 < str2)
return true;
break;
}
default:
if(e1[role] < e2[role])
return true;
}
return false;
});
}
void Albums::setList()
{
emit this->preListChanged();
this->list = this->dba->getDBData(this->query);
// qDebug()<< "ALBUMS LIST READY"<< list;
this->sortList();
emit this->postListChanged();
}
QVariantMap Albums::get(const int &index) const
{
if(index >= this->list.size() || index < 0)
return QVariantMap();
QVariantMap res;
const auto pic = this->list.at(index);
for(auto key : pic.keys())
res.insert(FMH::MODEL_NAME[key], pic[key]);
return res;
}
bool Albums::insert(const QVariantMap &pic)
{
const auto album = pic[FMH::MODEL_NAME[FMH::MODEL_KEY::ALBUM]].toString();
if(this->dba->addAlbum(album))
{
emit this->preItemAppended();
this->list << FMH::MODEL {{FMH::MODEL_KEY::ALBUM, album}};
emit postItemAppended();
return true;
}
qDebug()<< "COUDLDNT ADD ALBUM" << album;
return false;
}
bool Albums::update(const int &index, const QVariant &value, const int &role)
{
return false;
}
bool Albums::update(const QVariantMap &data, const int &index)
{
return false;
}
bool Albums::update(const FMH::MODEL &pic)
{
return false;
}
bool Albums::remove(const int &index)
{
return false;
}
void Albums::insertPic(const QString &album, const QString &url)
{
//this->insert({{FMH::MODEL_NAME[FMH::MODEL_KEY::ALBUM], album}});
this->dba->picAlbum(album, url);
}
#ifndef ALBUMS_H
#define ALBUMS_H
#include <QObject>
#ifdef STATIC_MAUIKIT
#include "fmh.h"
#include "mauilist.h"
#else
#include <MauiKit/fmh.h>
#include <MauiKit/mauilist.h>
#endif
class DBActions;
class Albums : public MauiList
{
Q_OBJECT
Q_PROPERTY(QString query READ getQuery WRITE setQuery NOTIFY queryChanged())
Q_PROPERTY(FMH::MODEL_KEY sortBy READ getSortBy WRITE setSortBy NOTIFY sortByChanged)
public:
explicit Albums(QObject *parent = nullptr);
FMH::MODEL_LIST items() const override final;
void setQuery(const QString &query);
QString getQuery() const;
void setSortBy(const FMH::MODEL_KEY &sort);
FMH::MODEL_KEY getSortBy() const;
private:
DBActions *dba;
FMH::MODEL_LIST list;
void sortList();
void setList();
QString query;
FMH::MODEL_KEY sort = FMH::MODEL_KEY::ADDDATE;
protected:
signals:
void queryChanged();
void orderChanged();
void sortByChanged();
public slots:
QVariantMap get(const int &index) const;
bool insert(const QVariantMap &pic);
bool update(const int &index, const QVariant &value, const int &role); //deprecrated
bool update(const QVariantMap &data, const int &index);
bool update(const FMH::MODEL &pic);
bool remove(const int &index);
void insertPic(const QString &album, const QString &url);
};
#endif // ALBUMS_H
#include "baselist.h"
BaseList::BaseList(QObject *parent) : QObject(parent)
{
}
#ifndef BASELIST_H
#define BASELIST_H
#ifdef STATIC_MAUIKIT
#include "fm.h"
#include "fmh.h"
#else
#include <MauiKit/fm.h>
#include <MauiKit/fmh.h>
#endif
class BaseList : public QObject
{
Q_OBJECT
public:
explicit BaseList(QObject *parent = nullptr);
//* To be overrided *//
virtual FMH::MODEL_LIST items() const {return FMH::MODEL_LIST({{}});}
protected:
signals:
void preItemAppended();
void postItemAppended();
void preItemRemoved(int index);
void postItemRemoved();
void updateModel(int index, QVector<int> roles);
void preListChanged();
void postListChanged();
public slots:
virtual QVariantMap get(const int &index) const
{
Q_UNUSED(index);
return QVariantMap();
}
virtual bool update(const int &index, const QVariant &value, const int &role)
{
Q_UNUSED(index);
Q_UNUSED(value);
Q_UNUSED(role);
return false;
}
virtual bool update(const QVariantMap &data, const int &index)
{
Q_UNUSED(index);
Q_UNUSED(data);
return false;
}
virtual bool update(const FMH::MODEL &data)
{
Q_UNUSED(data);
return false;
}
virtual bool insert(const QVariantMap &map)
{
Q_UNUSED(map);
return false;
}
virtual bool remove(const int &index)
{
Q_UNUSED(index);
return false;
}
};
#endif // BASELIST_H
#include "basemodel.h"
#include "baselist.h"
#include "src/utils/pic.h"
BaseModel::BaseModel(QObject *parent)
: QAbstractListModel(parent),
mList(nullptr)
{}
int BaseModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid() || !mList)
return 0;
return mList->items().size();
}
QVariant BaseModel::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 BaseModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!mList)
return false;
if (mList->update(index.row(), value, role))
{
emit dataChanged(index, index, QVector<int>() << role);
return true;
}
return false;
}
Qt::ItemFlags BaseModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return Qt::NoItemFlags;
return Qt::ItemIsEditable; // FIXME: Implement me!
}
QHash<int, QByteArray> BaseModel::roleNames() const
{
QHash<int, QByteArray> names;
for(auto key : FMH::MODEL_NAME.keys())
names[key] = QString(FMH::MODEL_NAME[key]).toUtf8();
return names;
}
BaseList *BaseModel::getList() const
{