2 #include <QXmlSimpleReader>
4 #include "w_timeline.h"
5 #include "timelinehandler.h"
7 w_Timeline::w_Timeline(QString usr
, QString pass
, QWidget
*parent
) : QDialog(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(QStandardItem
*)),this, SLOT(updateTimeline(QStandardItem
*)));
76 xmlReader
.parse(source
);
79 qDebug() << "An error occured in refreshResult: " << errorstring
;
83 void w_Timeline::updateTimeline(QStandardItem
*item
)
85 if (!timeline
->hasItem(item
))
86 timeline
->appendRow(item
);