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 <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) { | ||||
|   QSqlQuery q(db); | ||||
| 
 | ||||
|  |  | |||
|  | @ -19,6 +19,7 @@ class DatabaseQueries { | |||
|   public: | ||||
| 
 | ||||
|     // Label operators.
 | ||||
|     static QList<Label*> getLabels(const QSqlDatabase& db, int account_id); | ||||
|     static bool createLabel(const QSqlDatabase& db, Label* label, int account_id); | ||||
| 
 | ||||
|     // Message operators.
 | ||||
|  |  | |||
|  | @ -5,7 +5,7 @@ | |||
| #include <QPainter> | ||||
| #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); | ||||
|   setTitle(name); | ||||
| } | ||||
|  |  | |||
|  | @ -9,13 +9,17 @@ | |||
| #include "miscellaneous/iconfactory.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); | ||||
|   setId(ID_LABELS); | ||||
|   setIcon(qApp->icons()->fromTheme(QSL("mail-mark-important"))); | ||||
|   setTitle(tr("Labels")); | ||||
|   setDescription(tr("You can see all your labels (tags) here.")); | ||||
|   setCreationDate(QDateTime::currentDateTime()); | ||||
| 
 | ||||
|   for (Label* lbl : labels) { | ||||
|     appendChild(lbl); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| QList<QAction*> LabelsNode::contextMenuFeedsList() { | ||||
|  |  | |||
|  | @ -5,11 +5,13 @@ | |||
| 
 | ||||
| #include "services/abstract/rootitem.h" | ||||
| 
 | ||||
| #include "services/abstract/label.h" | ||||
| 
 | ||||
| class LabelsNode : public RootItem { | ||||
|   Q_OBJECT | ||||
| 
 | ||||
|   public: | ||||
|     explicit LabelsNode(RootItem* parent_item = nullptr); | ||||
|     explicit LabelsNode(const QList<Label*>& labels, RootItem* parent_item = nullptr); | ||||
| 
 | ||||
|     virtual QList<QAction*> contextMenuFeedsList(); | ||||
| 
 | ||||
|  |  | |||
|  | @ -142,9 +142,7 @@ void StandardServiceRoot::loadFromDatabase() { | |||
|   // As the last item, add recycle bin, which is needed.
 | ||||
|   appendChild(recycleBin()); | ||||
|   appendChild(importantNode()); | ||||
|   appendChild(new LabelsNode(this)); | ||||
| 
 | ||||
|   // TODO: Load all labels and append.
 | ||||
|   appendChild(new LabelsNode(DatabaseQueries::getLabels(database, accountId()), this)); | ||||
| 
 | ||||
|   updateCounts(true); | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue