2 #include <QXmlSimpleReader>
4 #include "w_timeline.h"
5 #include "timelinehandler.h"
7 w_Timeline::w_Timeline(QString usr
, QString pass
, QWidget
*parent
)
10 le_message
->setFocus();
12 timeline
= new Timeline();
13 tv_timeline
->setModel(timeline
);
21 // Send message button (Squawk!)
22 QObject::connect(pb_update
, SIGNAL(clicked()), this, SLOT(sendUpdate()));
24 //Refresh the timeline ever so often...
25 timer
= new QTimer(this);
26 QObject::connect(timer
, SIGNAL(timeout()), this, SLOT(refresh()));
32 void w_Timeline::sendUpdate()
34 pb_update
->setEnabled(false);
35 le_message
->setEnabled(false);
37 TwitterSocket
*tmp
= new TwitterSocket(user
,password
);
38 QObject::connect( tmp
, SIGNAL( result(bool,QString
,QString
) ), this, SLOT( updateResult(bool, QString
) ) );
39 tmp
->update(le_message
->text());
42 void w_Timeline::updateResult(bool error
, QString errorstring
)
46 le_message
->setEnabled(true);
47 pb_update
->setEnabled(true);
52 qDebug() << "An error occured in updateResult: " << errorstring
;
55 void w_Timeline::refresh()
57 TwitterSocket
*tmp
= new TwitterSocket(user
,password
);
58 QObject::connect( tmp
, SIGNAL( result(bool,QString
,QString
) ), this, SLOT( refreshResult(bool, QString
, QString
) ) );
62 void w_Timeline::refreshResult(bool error
, QString errorstring
, QString contents
)
66 QXmlSimpleReader xmlReader
;
67 QXmlInputSource
*source
= new QXmlInputSource();
68 source
->setData(contents
);
70 handler
= new TimelineHandler
;
71 xmlReader
.setContentHandler(handler
);
72 xmlReader
.setErrorHandler(handler
);
74 QObject::connect(handler
,SIGNAL(result(QList
<Status
*>)),this, SLOT(updateTimeline(QList
<Status
*>)));
76 if (xmlReader
.parse(source
));
77 qDebug() << "Parsed timeline XML successfully";
80 qDebug() << "An error occured in refreshResult: " << errorstring
;
82 //qDebug() << "Refresh result:" << error;
83 //qDebug() << "Contents:" << contents;
86 void w_Timeline::updateTimeline(QList
<Status
*> statuses
)
88 qDebug() << "Updating with size:" << statuses
.size();
89 for (int i
=0; i
< statuses
.size();++i
)
90 if (!timeline
->hasItem(statuses
.at(i
)->id
))
91 timeline
->appendRow(new QStandardItem(statuses
.at(i
)->text
));