Minor cleanups in model and connect
[squawker.git] / w_timeline.cpp
bloba4f28a0c9dae24aaafc3b5369bbe8fa809681b5d
1 #include <QtGui>
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)
9 setupUi(this);
10 le_message->setFocus();
12 timeline = new Timeline();
13 tv_timeline->setModel(timeline);
15 user = usr;
16 password = pass;
18 //Load the timeline
19 refresh();
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()));
27 //30 seconds
28 timer->start(30000);
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)
44 if (!error)
46 le_message->setEnabled(true);
47 pb_update->setEnabled(true);
48 le_message->clear();
49 refresh();
51 else
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) ) );
59 tmp->timeline();
62 void w_Timeline::refreshResult(bool error, QString errorstring, QString contents)
64 if (!error)
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);
78 else
79 qDebug() << "An error occured in refreshResult: " << errorstring;
83 void w_Timeline::updateTimeline(QStandardItem *item)
85 if (!timeline->hasItem(item))
86 timeline->appendRow(item);