Label advancements.
This commit is contained in:
		
							parent
							
								
									26e4431d3b
								
							
						
					
					
						commit
						205c32735f
					
				
					 6 changed files with 34 additions and 6 deletions
				
			
		|  | @ -31,6 +31,29 @@ | ||||||
| #include <QUrl> | #include <QUrl> | ||||||
| #include <QVariant> | #include <QVariant> | ||||||
| 
 | 
 | ||||||
|  | QList<Label*> DatabaseQueries::getLabels(const QSqlDatabase& db, int account_id) { | ||||||
|  |   QList<Label*> labels; | ||||||
|  |   QSqlQuery q(db); | ||||||
|  | 
 | ||||||
|  |   q.setForwardOnly(true); | ||||||
|  |   q.prepare("SELECT * FROM Labels WHERE account_id = :account_id;"); | ||||||
|  | 
 | ||||||
|  |   q.bindValue(QSL(":account_id"), account_id); | ||||||
|  | 
 | ||||||
|  |   if (q.exec()) { | ||||||
|  |     while (q.next()) { | ||||||
|  |       Label* lbl = new Label(q.value(QSL("name")).toString(), QColor(q.value(QSL("color")).toString())); | ||||||
|  | 
 | ||||||
|  |       lbl->setId(q.value(QSL("id")).toInt()); | ||||||
|  |       lbl->setCustomId(q.value(QSL("custom_id")).toString()); | ||||||
|  | 
 | ||||||
|  |       labels << lbl; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   return labels; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| bool DatabaseQueries::createLabel(const QSqlDatabase& db, Label* label, int account_id) { | bool DatabaseQueries::createLabel(const QSqlDatabase& db, Label* label, int account_id) { | ||||||
|   QSqlQuery q(db); |   QSqlQuery q(db); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -19,6 +19,7 @@ class DatabaseQueries { | ||||||
|   public: |   public: | ||||||
| 
 | 
 | ||||||
|     // Label operators.
 |     // Label operators.
 | ||||||
|  |     static QList<Label*> getLabels(const QSqlDatabase& db, int account_id); | ||||||
|     static bool createLabel(const QSqlDatabase& db, Label* label, int account_id); |     static bool createLabel(const QSqlDatabase& db, Label* label, int account_id); | ||||||
| 
 | 
 | ||||||
|     // Message operators.
 |     // Message operators.
 | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| #include <QPainter> | #include <QPainter> | ||||||
| #include <QPainterPath> | #include <QPainterPath> | ||||||
| 
 | 
 | ||||||
| Label::Label(const QString& name, const QColor& color, RootItem* parent_item) : RootItem(parent_item) { | Label::Label(const QString& name, const QColor& color, RootItem* parent_item) : Label(parent_item) { | ||||||
|   setColor(color); |   setColor(color); | ||||||
|   setTitle(name); |   setTitle(name); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -9,13 +9,17 @@ | ||||||
| #include "miscellaneous/iconfactory.h" | #include "miscellaneous/iconfactory.h" | ||||||
| #include "services/abstract/serviceroot.h" | #include "services/abstract/serviceroot.h" | ||||||
| 
 | 
 | ||||||
| LabelsNode::LabelsNode(RootItem* parent_item) : RootItem(parent_item), m_actLabelNew(nullptr) { | LabelsNode::LabelsNode(const QList<Label*>& labels, RootItem* parent_item) : RootItem(parent_item), m_actLabelNew(nullptr) { | ||||||
|   setKind(RootItem::Kind::Labels); |   setKind(RootItem::Kind::Labels); | ||||||
|   setId(ID_LABELS); |   setId(ID_LABELS); | ||||||
|   setIcon(qApp->icons()->fromTheme(QSL("mail-mark-important"))); |   setIcon(qApp->icons()->fromTheme(QSL("mail-mark-important"))); | ||||||
|   setTitle(tr("Labels")); |   setTitle(tr("Labels")); | ||||||
|   setDescription(tr("You can see all your labels (tags) here.")); |   setDescription(tr("You can see all your labels (tags) here.")); | ||||||
|   setCreationDate(QDateTime::currentDateTime()); |   setCreationDate(QDateTime::currentDateTime()); | ||||||
|  | 
 | ||||||
|  |   for (Label* lbl : labels) { | ||||||
|  |     appendChild(lbl); | ||||||
|  |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| QList<QAction*> LabelsNode::contextMenuFeedsList() { | QList<QAction*> LabelsNode::contextMenuFeedsList() { | ||||||
|  |  | ||||||
|  | @ -5,11 +5,13 @@ | ||||||
| 
 | 
 | ||||||
| #include "services/abstract/rootitem.h" | #include "services/abstract/rootitem.h" | ||||||
| 
 | 
 | ||||||
|  | #include "services/abstract/label.h" | ||||||
|  | 
 | ||||||
| class LabelsNode : public RootItem { | class LabelsNode : public RootItem { | ||||||
|   Q_OBJECT |   Q_OBJECT | ||||||
| 
 | 
 | ||||||
|   public: |   public: | ||||||
|     explicit LabelsNode(RootItem* parent_item = nullptr); |     explicit LabelsNode(const QList<Label*>& labels, RootItem* parent_item = nullptr); | ||||||
| 
 | 
 | ||||||
|     virtual QList<QAction*> contextMenuFeedsList(); |     virtual QList<QAction*> contextMenuFeedsList(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -142,9 +142,7 @@ void StandardServiceRoot::loadFromDatabase() { | ||||||
|   // As the last item, add recycle bin, which is needed.
 |   // As the last item, add recycle bin, which is needed.
 | ||||||
|   appendChild(recycleBin()); |   appendChild(recycleBin()); | ||||||
|   appendChild(importantNode()); |   appendChild(importantNode()); | ||||||
|   appendChild(new LabelsNode(this)); |   appendChild(new LabelsNode(DatabaseQueries::getLabels(database, accountId()), this)); | ||||||
| 
 |  | ||||||
|   // TODO: Load all labels and append.
 |  | ||||||
| 
 | 
 | ||||||
|   updateCounts(true); |   updateCounts(true); | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue