2 #include <QDialogButtonBox>
6 #include <QListWidgetItem>
10 #include "tagcompletion.h"
12 #include "tagsdialog.h"
14 TagsDialog::TagsDialog(const QHash<QString, QString> &tags, QWidget *parent)
17 qDebug() << __PRETTY_FUNCTION__;
19 setWindowTitle(tr("Edit tags"));
22 setAttribute(Qt::WA_Maemo5StackedWindow);
23 setWindowFlags(Qt::Window);
26 QVBoxLayout *mainLayout = new QVBoxLayout;
27 QHBoxLayout *lineEditLayout = new QHBoxLayout;
28 QGridLayout *listLayout = new QGridLayout;
29 QVBoxLayout *buttonLayout = new QVBoxLayout;
31 m_addTagEdit = new QLineEdit("");
32 QPushButton *addButton = new QPushButton(tr("Add"));
33 lineEditLayout->addWidget(m_addTagEdit);
34 lineEditLayout->addWidget(addButton);
36 QPushButton *deleteButton = new QPushButton(tr("Delete"));
37 QPushButton *okButton = new QPushButton(tr("Update"));
38 buttonLayout->addWidget(deleteButton, 0, Qt::AlignBottom);
39 buttonLayout->addWidget(okButton, 0, Qt::AlignBottom);
41 QLabel *yourTagsLabel = new QLabel(tr("Your tags:"));
42 yourTagsLabel->setAlignment(Qt::AlignCenter);
43 QLabel *popularTagsLabel = new QLabel(tr("Popular tags:"));
44 popularTagsLabel->setAlignment(Qt::AlignCenter);
45 m_userTagsView = new QListWidget();
46 m_popularTagsView = new QListWidget();
47 m_popularTagsView->setSelectionMode(QAbstractItemView::NoSelection);
49 listLayout->addWidget(yourTagsLabel, 0, 0);
50 listLayout->addWidget(popularTagsLabel, 0, 1);
51 listLayout->addWidget(m_userTagsView, 1, 0);
52 listLayout->addWidget(m_popularTagsView, 1, 1);
53 listLayout->addLayout(buttonLayout, 0, 2, -1, 1);
55 mainLayout->addLayout(lineEditLayout);
56 mainLayout->addLayout(listLayout);
58 setLayout(mainLayout);
60 connect(okButton, SIGNAL(clicked()),
61 this, SLOT(accept()));
63 connect(addButton, SIGNAL(clicked()),
64 this, SLOT(addTagToList()));
66 connect(deleteButton, SIGNAL(clicked()),
67 this, SLOT(deleteTagFromList()));
69 populateUserTags(tags);
72 void TagsDialog::addTagToList()
74 qDebug() << __PRETTY_FUNCTION__;
76 QList<QListWidgetItem *> findItems = m_userTagsView->findItems(m_addTagEdit->text(),
79 if (findItems.isEmpty()) {
80 m_userTagsView->insertItem(0, m_addTagEdit->text());
81 m_newTags.append(m_addTagEdit->text());
84 m_addTagEdit->setText("");
87 void TagsDialog::deleteTagFromList()
89 qDebug() << __PRETTY_FUNCTION__;
91 QList<QListWidgetItem *> selectedItems = m_userTagsView->selectedItems();
93 if (!selectedItems.isEmpty()) {
94 QListWidgetItem *selectedItem = selectedItems.at(0);
95 m_userTagsView->takeItem(m_userTagsView->row(selectedItem));
97 if (m_newTags.contains(selectedItem->text()))
98 m_newTags.removeOne(selectedItem->text());
100 m_removedTags.append(selectedItem->text());
104 QStringList TagsDialog::newTags()
106 qDebug() << __PRETTY_FUNCTION__;
111 QStringList TagsDialog::removedTags()
113 qDebug() << __PRETTY_FUNCTION__;
115 return m_removedTags;
118 void TagsDialog::populatePopularTags(const QHash<QString, QString> &popularTags)
120 qDebug() << __PRETTY_FUNCTION__;
122 m_popularTagsView->clear();
124 foreach (QString tag, popularTags)
125 m_popularTagsView->addItem(tag);
128 void TagsDialog::populateUserTags(const QHash<QString, QString> &userTags)
130 qDebug() << __PRETTY_FUNCTION__;
132 m_userTagsView->clear();
134 foreach (QString tag, m_newTags) {
135 if (!userTags.values().contains(tag))
136 m_userTagsView->addItem(tag);
139 foreach (QString tag, userTags)
140 m_userTagsView->addItem(tag);