Commit b7bb6278 authored by camilo higuita's avatar camilo higuita

work on albums dialog to create album and add pics to albums #4

parent 6d9672fb
......@@ -6,5 +6,6 @@ var Query = {
picTags_ : "select * from images_tags where url = \"%1\"",
allTags : "select * from tags",
allAlbums : "select * from albums"
allAlbums : "select * from albums order by strftime(\"%s\", addDate) desc",
albumPics_ : "select i.* from images_albums ia inner join images i on i.url = ia.url where ia.album = \"%1\" order by strftime(\"%s\", ia.addDate) desc"
}
......@@ -122,11 +122,6 @@ bool DBActions::isFav(const QString &url)
}
bool DBActions::addTag(const QString &tag)
{
}
bool DBActions::picTag(const QString &tag, const QString &url)
{
QVariantMap tagMap
{
......@@ -134,7 +129,11 @@ bool DBActions::picTag(const QString &tag, const QString &url)
};
this->insert(PIX::TABLEMAP[PIX::TABLE::TAGS], tagMap);
}
bool DBActions::picTag(const QString &tag, const QString &url)
{
this->addTag(tag);
QVariantMap taggedPic
{
{PIX::KEYMAP[PIX::KEY::URL], url},
......@@ -160,6 +159,19 @@ bool DBActions::addAlbum(const QString &album)
this->insert(PIX::TABLEMAP[PIX::TABLE::ALBUMS], albumMap);
}
bool DBActions::picAlbum(const QString &album, const QString &url)
{
qDebug()<<"Trying to add to album"<<album<<url;
this->addAlbum(album);
QVariantMap albumPic
{
{PIX::KEYMAP[PIX::KEY::URL], url},
{PIX::KEYMAP[PIX::KEY::ALBUM], album},
{PIX::KEYMAP[PIX::KEY::ADD_DATE], QDateTime::currentDateTime()}
};
return this->insert(PIX::TABLEMAP[PIX::TABLE::IMAGES_ALBUMS], albumPic);
}
QVariantList DBActions::getFolders()
{
QVariantList res;
......
......@@ -26,6 +26,8 @@ class DBActions : public DB
Q_INVOKABLE bool removePicTag(const QString &tag, const QString &url);
Q_INVOKABLE bool addAlbum(const QString &album);
Q_INVOKABLE bool picAlbum(const QString &album, const QString &url);
/* utils */
......
......@@ -119,7 +119,7 @@ Kirigami.ApplicationWindow
AlbumsView
{
id: albumsView
}
TagsView
......
......@@ -27,86 +27,43 @@ PixPopup
Layout.fillWidth: true
width: parent.width
height: parent.height
onTagClicked:
{
tagListComposer.model.insert(0, {tag: albumsList.model.get(index).album})
}
}
TextField
{
id: tagText
id: albumText
Layout.fillWidth: true
placeholderText: "Tags..."
placeholderText: "New album..."
onAccepted:
{
var tags = tagText.text.split(",")
for(var i in tags)
{
var tag = tags[i].trim()
if(!pix.checkExistance("tags", "tag", tag))
{
albumsList.model.insert(0, {tag: tag})
tagListComposer.model.insert(0, {tag: tag})
}
}
albumsList.model.insert(0, {album: albumText.text})
clear()
}
}
TagList
{
id: tagListComposer
Layout.fillWidth: true
height: 64
width: parent.width
onTagRemoved:
{
pix.removePicTag(model.get(index).tag, pixViewer.currentPic.url)
tagListComposer.model.remove(index)
}
}
Button
{
text: qsTr("Add")
Layout.alignment: Qt.AlignRight
onClicked: addTags(picUrl)
onClicked: addToAlbum(albumsList.model.get(albumsList.currentIndex).album)
}
}
function addTags(url)
function addToAlbum(album)
{
var tags = []
for(var i = 0; i < tagListComposer.model.count; i++)
tags.push(tagListComposer.model.get(i))
if(tags.length > 0)
for(i in tags)
{
if(PIX.addTag(tags[i].tag, picUrl))
picTagged(tags[i].tag)
}
if(pix.picAlbum(album, picUrl))
albumsView.albumsGrid.model.append({album : album})
close()
}
function populate()
{
tagsList.model.clear()
var tags = pix.get(Q.Query.allTags)
if(tags.length > 0)
for(var i in tags)
tagsList.model.append(tags[i])
albumsList.model.clear()
var albums = pix.get(Q.Query.allAlbums)
tagListComposer.populate(picUrl)
if(albums.length > 0)
for(var i in albums)
albumsList.model.append(albums[i])
}
}
......@@ -4,14 +4,14 @@ import "../../../view_models"
ListView
{
id: tagListRoot
id: albumsListRoot
signal tagClicked(int index)
signal albumClicked(int index)
highlight: Rectangle
{
width: tagListRoot.width
height: tagListRoot.currentItem.height
width: albumsListRoot.width
height: albumsListRoot.currentItem.height
color: highlightColor
}
......@@ -23,15 +23,15 @@ ListView
delegate: PixDelegate
{
id: delegate
label: tag
label: album
Connections
{
target: delegate
onClicked:
{
tagListRoot.currentIndex = index
tagClicked(index)
albumsListRoot.currentIndex = index
albumClicked(index)
}
}
}
......
......@@ -30,9 +30,6 @@ GridView
ListElement{album: "Favs"}
ListElement{album: "Recent"}
ListElement{album: "albums"}
ListElement{album: "albums"}
ListElement{album: "albums"}
}
highlightFollowsCurrentItem: true
......
......@@ -6,11 +6,17 @@ import "../../dialogs/Albums"
PixPage
{
property alias albumsGrid : albumGrid
headerbarExit: stackView.currentItem === picsView
headerbarExitIcon: "go-previous"
headerbarTitle: albumGrid.count+qsTr(" Albums")
onExit: stackView.pop(albumGrid)
onExit:
{
stackView.pop(albumGrid)
headerbarTitle: albumGrid.count+qsTr(" Albums")
}
headerBarRight: [
......@@ -26,6 +32,7 @@ PixPage
PixButton
{
iconName: "list-add"
visible: stackView.currentItem === albumGrid
onClicked: newAlbumDialog.open()
}
]
......@@ -46,14 +53,7 @@ PixPage
{
id: albumGrid
onAlbumClicked:
{
headerbarTitle = model.get(index).album
picsView.clear()
// picsView.populate(model.get(index).url)
// if(stackView.currentItem === folderGrid)
// stackView.push(picsView)
}
onAlbumClicked: populateAlbum(model.get(index).album)
}
PixGrid
......@@ -66,7 +66,7 @@ PixPage
function populate()
{
var albums = pix.get(Q.Query.allAlbums())
var albums = pix.get(Q.Query.allAlbums)
if(albums.length > 0)
for(var i in albums)
albumGrid.model.append(albums[i])
......@@ -78,9 +78,19 @@ PixPage
albumGrid.model.clear()
}
function addAlbum()
function populateAlbum(album)
{
headerbarTitle = album
picsView.clear()
var pics = pix.get(Q.Query.albumPics_.arg(album))
if(pics.length > 0)
for(var i in pics)
picsView.grid.model.append(pics[i])
if(stackView.currentItem === albumGrid)
stackView.push(picsView)
}
}
......@@ -5,6 +5,7 @@ function refreshViews()
galleryView.populate()
foldersView.populate()
albumsView.populate()
}
function addTag(tag, url)
......
......@@ -6,6 +6,7 @@ import "../../../widgets/views/Viewer/Viewer.js" as VIEWER
import "../../../widgets/custom/TagBar"
import "../../dialogs/share"
import "../../dialogs/Tags"
import "../../dialogs/Albums"
PixPage
{
......@@ -27,6 +28,7 @@ PixPage
PixButton
{
iconName: "edit-rename"
},
PixButton
......@@ -38,6 +40,16 @@ PixPage
headerBarLeft: [
PixButton
{
iconName: "document-save-as"
onClicked:
{
albumsDialog.picUrl = currentPic.url
albumsDialog.open()
}
},
PixButton
{
iconName: "draw-text"
......@@ -62,6 +74,11 @@ PixPage
onPicTagged: tagBar.tagsList.model.insert(0, {"tag": tag})
}
AlbumsDialog
{
id: albumsDialog
}
PixHolder
{
id: holder
......
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