[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: extragear/pim/ksig
From: Pino Toscano <pino () kde ! org>
Date: 2012-09-21 14:13:47
Message-ID: 20120921141347.A3881AC7E8 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1317180 by pino:
covert SigGenerator to use an item model for the data
instead of reading the signatures on its own, query the specified model using the \
specified data role
in main:
- create a new SigModel and pass it to the generator already created there
- output a new line, since now signatures produced by SigGenerator do not have an \
extra new line (added while reading them)
M +4 -1 main.cpp
M +16 -24 siggenerator.cpp
M +5 -4 siggenerator.h
--- trunk/extragear/pim/ksig/main.cpp #1317179:1317180
@@ -23,6 +23,7 @@
#include "ksig.h"
#include "siggenerator.h"
+#include "sigmodel.h"
//Added by qt3to4:
#include <QTextStream>
@@ -47,13 +48,15 @@
if(args->isSet("random") || args->isSet("daily")) {
KApplication a(false);
- SigGenerator generator;
+ SigModel model;
+ SigGenerator generator(&model, SigModel::SignatureRole);
QTextStream output(stdout, QIODevice::WriteOnly);
if(args->isSet("random"))
output << generator.random();
else if(args->isSet("daily"))
output << generator.daily();
+ output << endl;
return(0);
}
--- trunk/extragear/pim/ksig/siggenerator.cpp #1317179:1317180
@@ -16,27 +16,19 @@
***************************************************************************/
#include "siggenerator.h"
-#include "siglistviewitem.h"
-#include <kstandarddirs.h>
-#include <ksharedconfig.h>
-#include <kdebug.h>
-
-#include <qfile.h>
+#include <qabstractitemmodel.h>
#include <qdatetime.h>
-#include <krandom.h>
+
#include <kconfiggroup.h>
+#include <kglobal.h>
+#include <krandom.h>
+#include <ksharedconfig.h>
-SigGenerator::SigGenerator()
+SigGenerator::SigGenerator(QAbstractItemModel *model, int role)
+ : m_model(model)
+ , m_role(role)
{
- QString dir = KGlobal::dirs()->saveLocation("appdata");
- QFile file(dir + "sigs.sigml");
-
- if(file.open(QIODevice::ReadOnly) && doc.setContent(&file)) {
- signatures = doc.elementsByTagName("signature");
- file.close();
- }
-
KSharedConfig::Ptr config = KGlobal::config();
{
KConfigGroup group(config, "Settings");
@@ -53,25 +45,25 @@
QString SigGenerator::random() const
{
- if(signatures.count() <= 0)
+ const int count = m_model->rowCount();
+ if(count <= 0)
return(QString::null); //krazy:exclude=nullstrassign for old broken gcc
- int i = KRandom::random() % signatures.count();
- QString text;
- SigListViewItem::nodeToText(signatures.item(i), text);
+ const int i = KRandom::random() % count;
+ const QString text = m_model->data(m_model->index(i, 0), m_role).toString();
return attachStandard(text);
}
QString SigGenerator::daily() const
{
- if(signatures.count() <= 0)
+ const int count = m_model->rowCount();
+ if(count <= 0)
return(QString::null); //krazy:exclude=nullstrassign for old broken gcc
QDate date;
- int i = date.dayOfYear() % signatures.count();
- QString text;
- SigListViewItem::nodeToText(signatures.item(i), text);
+ const int i = date.dayOfYear() % count;
+ const QString text = m_model->data(m_model->index(i, 0), m_role).toString();
return attachStandard(text);
}
--- trunk/extragear/pim/ksig/siggenerator.h #1317179:1317180
@@ -19,12 +19,13 @@
#define SIGGENERATOR_H
#include <qstring.h>
-#include <qdom.h>
+class QAbstractItemModel;
+
class SigGenerator
{
public:
- SigGenerator();
+ SigGenerator(QAbstractItemModel *model, int role);
~SigGenerator();
QString random() const;
@@ -34,8 +35,8 @@
QString attachStandard(const QString &text) const;
- QDomDocument doc;
- QDomNodeList signatures;
+ QAbstractItemModel *m_model;
+ int m_role;
QString header;
QString footer;
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic