Skip to content

Commit fa14046

Browse files
committed
Basic implementation of a Digg input
1 parent 51e1fff commit fa14046

File tree

14 files changed

+375
-199
lines changed

14 files changed

+375
-199
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#############################################################################
22
# Makefile for building: gltrail
3-
# Generated by qmake (2.01a) (Qt 4.3.2) on: Sat Mar 15 17:33:31 2008
3+
# Generated by qmake (2.01a) (Qt 4.3.2) on: Sat Mar 15 18:26:00 2008
44
# Project: gltrail.pro
55
# Template: subdirs
66
# Command: /usr/bin/qmake -unix -o Makefile gltrail.pro

README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
3. cp gltrail.ini-example gltrail.ini
55
(and replace with your information)
66
4. ./bin/gltrail gltrail.ini
7+
./bin/gltrail --digg
78

89
Note: You'll need public-key ssh access set up to your servers,
910
as I haven't found a good/free cross-platform ssh library.

src/Makefile

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#############################################################################
22
# Makefile for building: ../bin/gltrail
3-
# Generated by qmake (2.01a) (Qt 4.3.2) on: Sat Mar 15 17:33:31 2008
3+
# Generated by qmake (2.01a) (Qt 4.3.2) on: Sat Mar 15 18:40:51 2008
44
# Project: src.pro
55
# Template: app
66
# Command: /usr/bin/qmake -unix -o Makefile src.pro
@@ -10,13 +10,13 @@
1010

1111
CC = gcc
1212
CXX = g++
13-
DEFINES = -DQT_SHARED -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB
13+
DEFINES = -DQT_SHARED -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB
1414
CFLAGS = -pipe -g -D_REENTRANT -Wall -W $(DEFINES)
1515
CXXFLAGS = -pipe -g -D_REENTRANT -Wall -W $(DEFINES)
16-
INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I/usr/X11R6/include -I. -I.
16+
INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I/usr/X11R6/include -I. -I.
1717
LINK = g++
1818
LFLAGS =
19-
LIBS = $(SUBLIBS) -L/usr/X11R6/lib -L/usr/lib -lGLU -lGL -lQtOpenGL -lQtGui -lQtCore -lpthread
19+
LIBS = $(SUBLIBS) -L/usr/lib -L/usr/X11R6/lib -lQtOpenGL -lQtGui -lQtNetwork -lQtCore -lGLU -lGL -lpthread
2020
AR = ar cqs
2121
RANLIB =
2222
QMAKE = /usr/bin/qmake
@@ -48,23 +48,27 @@ SOURCES = main.cpp \
4848
window.cpp \
4949
glwidget.cpp \
5050
background_updater.cpp \
51-
inputs/ssh.cpp moc_input.cpp \
52-
moc_window.cpp \
51+
input.cpp \
52+
inputs/ssh.cpp \
53+
inputs/digg.cpp moc_window.cpp \
5354
moc_glwidget.cpp \
5455
moc_background_updater.cpp \
55-
moc_ssh.cpp
56+
moc_ssh.cpp \
57+
moc_digg.cpp
5658
OBJECTS = main.o \
5759
activity.o \
5860
element.o \
5961
window.o \
6062
glwidget.o \
6163
background_updater.o \
64+
input.o \
6265
ssh.o \
63-
moc_input.o \
66+
digg.o \
6467
moc_window.o \
6568
moc_glwidget.o \
6669
moc_background_updater.o \
67-
moc_ssh.o
70+
moc_ssh.o \
71+
moc_digg.o
6872
DIST = /usr/share/qt4/mkspecs/common/g++.conf \
6973
/usr/share/qt4/mkspecs/common/unix.conf \
7074
/usr/share/qt4/mkspecs/common/linux.conf \
@@ -75,8 +79,8 @@ DIST = /usr/share/qt4/mkspecs/common/g++.conf \
7579
/usr/share/qt4/mkspecs/features/default_pre.prf \
7680
/usr/share/qt4/mkspecs/features/debug.prf \
7781
/usr/share/qt4/mkspecs/features/default_post.prf \
78-
/usr/share/qt4/mkspecs/features/unix/opengl.prf \
7982
/usr/share/qt4/mkspecs/features/qt.prf \
83+
/usr/share/qt4/mkspecs/features/unix/opengl.prf \
8084
/usr/share/qt4/mkspecs/features/moc.prf \
8185
/usr/share/qt4/mkspecs/features/unix/thread.prf \
8286
/usr/share/qt4/mkspecs/features/warn_on.prf \
@@ -127,8 +131,8 @@ Makefile: src.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt4/mk
127131
/usr/share/qt4/mkspecs/features/default_pre.prf \
128132
/usr/share/qt4/mkspecs/features/debug.prf \
129133
/usr/share/qt4/mkspecs/features/default_post.prf \
130-
/usr/share/qt4/mkspecs/features/unix/opengl.prf \
131134
/usr/share/qt4/mkspecs/features/qt.prf \
135+
/usr/share/qt4/mkspecs/features/unix/opengl.prf \
132136
/usr/share/qt4/mkspecs/features/moc.prf \
133137
/usr/share/qt4/mkspecs/features/unix/thread.prf \
134138
/usr/share/qt4/mkspecs/features/warn_on.prf \
@@ -147,8 +151,8 @@ Makefile: src.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt4/mk
147151
/usr/share/qt4/mkspecs/features/default_pre.prf:
148152
/usr/share/qt4/mkspecs/features/debug.prf:
149153
/usr/share/qt4/mkspecs/features/default_post.prf:
150-
/usr/share/qt4/mkspecs/features/unix/opengl.prf:
151154
/usr/share/qt4/mkspecs/features/qt.prf:
155+
/usr/share/qt4/mkspecs/features/unix/opengl.prf:
152156
/usr/share/qt4/mkspecs/features/moc.prf:
153157
/usr/share/qt4/mkspecs/features/unix/thread.prf:
154158
/usr/share/qt4/mkspecs/features/warn_on.prf:
@@ -161,7 +165,7 @@ qmake: FORCE
161165

162166
dist:
163167
@$(CHK_DIR_EXISTS) .tmp/gltrail1.0.0 || $(MKDIR) .tmp/gltrail1.0.0
164-
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/gltrail1.0.0/ && $(COPY_FILE) --parents input.h element.h activity.h relation.h window.h glwidget.h background_updater.h inputs/ssh.h .tmp/gltrail1.0.0/ && $(COPY_FILE) --parents main.cpp activity.cpp element.cpp window.cpp glwidget.cpp background_updater.cpp inputs/ssh.cpp .tmp/gltrail1.0.0/ && (cd `dirname .tmp/gltrail1.0.0` && $(TAR) gltrail1.0.0.tar gltrail1.0.0 && $(COMPRESS) gltrail1.0.0.tar) && $(MOVE) `dirname .tmp/gltrail1.0.0`/gltrail1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/gltrail1.0.0
168+
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/gltrail1.0.0/ && $(COPY_FILE) --parents input.h element.h activity.h relation.h window.h glwidget.h background_updater.h inputs/ssh.h inputs/digg.h .tmp/gltrail1.0.0/ && $(COPY_FILE) --parents main.cpp activity.cpp element.cpp window.cpp glwidget.cpp background_updater.cpp input.cpp inputs/ssh.cpp inputs/digg.cpp .tmp/gltrail1.0.0/ && (cd `dirname .tmp/gltrail1.0.0` && $(TAR) gltrail1.0.0.tar gltrail1.0.0 && $(COMPRESS) gltrail1.0.0.tar) && $(MOVE) `dirname .tmp/gltrail1.0.0`/gltrail1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/gltrail1.0.0
165169

166170

167171
clean:compiler_clean
@@ -180,12 +184,9 @@ mocclean: compiler_moc_header_clean compiler_moc_source_clean
180184

181185
mocables: compiler_moc_header_make_all compiler_moc_source_make_all
182186

183-
compiler_moc_header_make_all: moc_input.cpp moc_window.cpp moc_glwidget.cpp moc_background_updater.cpp moc_ssh.cpp
187+
compiler_moc_header_make_all: moc_window.cpp moc_glwidget.cpp moc_background_updater.cpp moc_ssh.cpp moc_digg.cpp
184188
compiler_moc_header_clean:
185-
-$(DEL_FILE) moc_input.cpp moc_window.cpp moc_glwidget.cpp moc_background_updater.cpp moc_ssh.cpp
186-
moc_input.cpp: input.h
187-
/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) input.h -o moc_input.cpp
188-
189+
-$(DEL_FILE) moc_window.cpp moc_glwidget.cpp moc_background_updater.cpp moc_ssh.cpp moc_digg.cpp
189190
moc_window.cpp: glwidget.h \
190191
input.h \
191192
window.h
@@ -207,6 +208,10 @@ moc_ssh.cpp: input.h \
207208
inputs/ssh.h
208209
/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) inputs/ssh.h -o moc_ssh.cpp
209210

211+
moc_digg.cpp: input.h \
212+
inputs/digg.h
213+
/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) inputs/digg.h -o moc_digg.cpp
214+
210215
compiler_rcc_make_all:
211216
compiler_rcc_clean:
212217
compiler_image_collection_make_all: qmake_image_collection.cpp
@@ -248,7 +253,8 @@ element.o: element.cpp element.h \
248253
window.o: window.cpp window.h \
249254
glwidget.h \
250255
input.h \
251-
inputs/ssh.h
256+
inputs/ssh.h \
257+
inputs/digg.h
252258
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o window.o window.cpp
253259

254260
glwidget.o: glwidget.cpp glwidget.h \
@@ -267,13 +273,19 @@ background_updater.o: background_updater.cpp background_updater.h \
267273
relation.h
268274
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o background_updater.o background_updater.cpp
269275

276+
input.o: input.cpp input.h \
277+
glwidget.h
278+
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o input.o input.cpp
279+
270280
ssh.o: inputs/ssh.cpp inputs/ssh.h \
271281
input.h \
272282
glwidget.h
273283
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o ssh.o inputs/ssh.cpp
274284

275-
moc_input.o: moc_input.cpp
276-
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_input.o moc_input.cpp
285+
digg.o: inputs/digg.cpp inputs/digg.h \
286+
input.h \
287+
glwidget.h
288+
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o digg.o inputs/digg.cpp
277289

278290
moc_window.o: moc_window.cpp
279291
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_window.o moc_window.cpp
@@ -287,6 +299,9 @@ moc_background_updater.o: moc_background_updater.cpp
287299
moc_ssh.o: moc_ssh.cpp
288300
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_ssh.o moc_ssh.cpp
289301

302+
moc_digg.o: moc_digg.cpp
303+
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_digg.o moc_digg.cpp
304+
290305
####### Install
291306

292307
install: FORCE

src/background_updater.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ class BackgroundUpdater : public QThread
2121
protected:
2222
void run();
2323

24-
25-
2624
private:
2725
Inputs *hosts;
2826
Elements *elements;

src/glwidget.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ int last_time = 0;
4141
GLWidget::GLWidget(QWidget *parent, Inputs *h)
4242
: QGLWidget(QGLFormat(QGL::DoubleBuffer | QGL::Rgba | QGL::DirectRendering | QGL::AlphaChannel), parent)
4343
{
44-
// startTimer(1);
4544
startTimer(16);
4645
setFocusPolicy(Qt::StrongFocus);
4746
setMouseTracking(true);
@@ -75,7 +74,7 @@ GLWidget::~GLWidget()
7574
{
7675
if( hosts != NULL ) {
7776
for(Inputs::iterator it = hosts->begin(); it != hosts->end(); ++it)
78-
(*it)->end();
77+
(*it)->endProcessing();
7978
}
8079
}
8180

@@ -342,7 +341,7 @@ void GLWidget::resizeGL(int width, int height) {
342341
void GLWidget::keyPressEvent(QKeyEvent *event) {
343342
if( event->key() == Qt::Key_Escape ) {
344343
for(Inputs::iterator it = hosts->begin(); it != hosts->end(); ++it)
345-
(*it)->end();
344+
(*it)->endProcessing();
346345
hosts = NULL;
347346
QApplication::exit(1);
348347
} else if( event->key() == Qt::Key_Space ) {

src/glwidget.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ class GLWidget : public QGLWidget
7878
bool showStats() const { return statsMode; };
7979
bool useRecoil() const { return recoil; };
8080

81+
void setShowLines(int mode) { linesMode = mode; };
82+
void setShowSize(int mode) { sizeMode = mode; };
83+
8184
float getX() const { return x; };
8285
float getY() const { return y; };
8386

src/input.cpp

Lines changed: 3 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,16 @@
1-
#include "host.h"
1+
#include "input.h"
22

33
#include <QStringList>
44
#include <iostream>
55
#include "glwidget.h"
66

77
using namespace std;
88

9-
void Input::start(void) {
10-
proc = new QProcess( this );
9+
void Input::startProcessing() {
1110

12-
proc->setProcessChannelMode(QProcess::SeparateChannels);
13-
14-
connect( proc, SIGNAL(readyReadStandardOutput()), this, SLOT(readFromStdout()) );
15-
connect( proc, SIGNAL(readyReadStandardError()), this, SLOT(readFromStderr()) );
16-
QString cmd = getCommandString();
17-
std::cout << "[" << domain.toStdString() << "] exec[" << cmd.toStdString() << "]" << std::endl;
18-
proc->start( getCommandString() );
19-
proc->waitForStarted();
2011
}
2112

13+
void Input::endProcessing() {
2214

23-
void Input::end( void ) {
24-
cout << "Terminating[" << domain.toStdString() << "]" << endl;
25-
proc->terminate();
26-
proc->waitForFinished(2000);
27-
if( proc->state() == QProcess::Running ) {
28-
cout << "Killing[" << domain.toStdString() << "]" << endl;
29-
proc->kill();
30-
}
31-
32-
}
33-
34-
QString Input::getCommandString() {
35-
QStringList cmd;
36-
cmd << "ssh";
37-
cmd << user + "@" + host;
38-
39-
if( !port.isEmpty() )
40-
cmd << "-p" << port;
41-
42-
cmd << command << args;
43-
44-
return cmd.join(" ");
4515
}
4616

47-
void Input::readFromStdout(void ) {
48-
char buf[2048];
49-
50-
proc->setReadChannel(QProcess::StandardOutput);
51-
52-
while( proc->canReadLine() ) {
53-
qint64 len = proc->readLine(buf, sizeof(buf));
54-
if( len != -1 ) {
55-
56-
// QString apache_pattern("([\\d\\S.]+) (\\S+) (\\S+) \\[([^\\]]+)\\] \"([^\"]*)\" (\\d+) ([\\S]+) \"([^\"]+)\" \"([^\"]+)\"");
57-
QRegExp rx(pattern);
58-
59-
if( rx.indexIn(buf) > -1 ) {
60-
QString url = rx.cap(1);
61-
62-
if( url.contains(" ") ) {
63-
url = url.split(" ")[1];
64-
}
65-
66-
QString referrer = rx.cap(2);
67-
68-
if( ignoreQueryParameters() )
69-
url = url.split("?")[0];
70-
71-
if( !ignore.isEmpty() && url.contains( QRegExp(ignore, Qt::CaseInsensitive) ) ) {
72-
continue;
73-
}
74-
75-
for( int i = 0; i < replacementPatterns.size(); i++ ) {
76-
url.replace( QRegExp(replacementPatterns[i]), replacementStrings[i] );
77-
}
78-
79-
url.replace( QRegExp("/index\\.vsp$"), "/" );
80-
81-
if( referrer.contains( QRegExp("http://(.*\\.)?" + domain) ) || referrer.startsWith("/") ) {
82-
referrer = referrer.split("?")[0];
83-
84-
for( int i = 0; i < replacementPatterns.size(); i++ ) {
85-
referrer.replace( QRegExp(replacementPatterns[i]), replacementStrings[i] );
86-
}
87-
}
88-
89-
referrer.replace( QRegExp("^http://(.*\\.)?" + domain), "");
90-
bool external = false;
91-
if( referrer.contains("http://") ) {
92-
external = true;
93-
referrer.replace("http://", "");
94-
}
95-
// std::cout << "[" << domain.toStdString() << "] " << url.toStdString() << " <- " << (const char*) referrer.toLatin1() << std::endl;
96-
97-
if( url == referrer ) {
98-
referrer = "";
99-
}
100-
101-
gl->addRelation(this, url, referrer, external);
102-
103-
} else {
104-
std::cout << "[" << domain.toStdString() << "] UNKNOWN [" << buf << "]" << std::endl;
105-
}
106-
// glWidget->addRandomElement();
107-
}
108-
}
109-
}
110-
111-
void Input::readFromStderr(void) {
112-
char buf[2048];
113-
std::cout << "STDERR!\n";
114-
proc->setReadChannel(QProcess::StandardError);
115-
116-
while( proc->canReadLine() ) {
117-
qint64 len = proc->readLine(buf, sizeof(buf));
118-
if( len != -1 ) {
119-
std::cout << "[" << domain.toStdString() << "] STDERR [" << buf << "]" << std::endl;
120-
}
121-
}
122-
}

src/input.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99

1010
class GLWidget;
1111

12-
class Input : public QObject {
13-
14-
Q_OBJECT
12+
class Input {
1513

1614
public:
1715

18-
Input(QObject *parent) : QObject(parent) {};
19-
~Input() {};
16+
Input() {};
17+
virtual ~Input() {};
2018

2119
void setDomain(const QString &d) { domain = d; };
2220
void setColor(const QString &c) { color = QColor(c); };
@@ -27,10 +25,11 @@ class Input : public QObject {
2725
void setGLWidget(GLWidget *glw) { gl = glw; };
2826
GLWidget *getGLWidget() const { return gl; };
2927

28+
void setAutoPurge(bool p) {autoPurge = p; };
3029
bool doPurge( void ) const { return autoPurge; };
3130

32-
virtual void start() {};
33-
virtual void end() {};
31+
virtual void startProcessing();
32+
virtual void endProcessing();
3433
protected:
3534
GLWidget *gl;
3635
QString domain;

0 commit comments

Comments
 (0)