1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you want to add, delete, or rename functions or slots, use
** Qt Designer to update this file, preserving your code.
**
** You should not define a constructor or destructor in this file.
** Instead, write your code in functions called init() and destroy().
** These will automatically be called by the form's constructor and
** destructor.
*****************************************************************************/
#define BEGIN_CALLSIGN "<b class=\"bbigblue\">"
#define END_CALLSIGN "</span><p>"
#define NOT_FOUND "The callsign <span class=\"red\">"
void Form1::init()
{
connect(&http, SIGNAL(done(bool)), this, SLOT(httpDone(bool)));
}
void Form1::getit()
{
result_TE->setText("...Working...");
website = "www.qrz.com";
callsign = callsign_LE->text().upper();
gohere = "/callsign/" + callsign;
if (callsign_LE->text() == "") {
QMessageBox::critical(this, "Empty query",
"Please type a callsign.",
QMessageBox::Ok, QMessageBox::NoButton);
}else{
file.setName("result.html");
if (!file.open(IO_WriteOnly)) {
QMessageBox::warning(this, tr("HTTP Get"),
tr("Cannot write to file. %1\n%2")
.arg(file.name())
.arg(file.errorString()));
return;
}
http.setHost(website);
http.get(gohere, &file);
http.closeConnection();
}
file.close();
}
void Form1::httpDone( bool error)
{
if (error)
QMessageBox::warning(this, tr("HTTP Get"),
tr("Error while fetching file with HTTP: %1")
.arg(http.errorString()));
file.close();
parseit();
}
void Form1::parseit()
{
result_TE->setText("...Checking Received HTML...");
if (!file.open(IO_ReadOnly | IO_Translate)) {
QMessageBox::warning(this, tr("Parser"),
tr("Cannot open file. %1\n%2")
.arg(file.name())
.arg(file.errorString()));
return;
}
flag = FALSE;
QString str = "";
int len;
QTextStream in (&file);
// Main parser loop
while (!in.atEnd()){
lineOdata = in.readLine();
if (lineOdata.find(NOT_FOUND, 0) >= 0){
// Callsign not found
flag = TRUE;
result_TE->setText("...Callsign not found...");
}
if (lineOdata.find(BEGIN_CALLSIGN, 0) >= 0) {
// Found the callsign stuff
flag = TRUE;
result_TE->setText("...Found callsign...");
}
if ( flag && (lineOdata.find(END_CALLSIGN, 0) >= 0)) {
flag = FALSE;
}
if (flag && (lineOdata.find("<img src=", 0) >= 0)){
// Pull out the map image info
snip1 = lineOdata.find("<img src=", 0) + 10; // Offset of 9 to remove html crap
snip2 = lineOdata.find("gif", snip1) +4;
len = (snip2 - 1) - snip1;
QString resultstr = lineOdata.mid(snip1, len);
// Now get rid of image in web page data
snip1 = snip1 -10;
snip2 = lineOdata.find(">", snip1);
len = snip2 - snip1 + 1;
QString junk = lineOdata.remove(snip1, len);
}
// Save the line if its good
if (flag) {
str = str + lineOdata;
}
}
file.close();
// Print result to main window
result_TE->setText(str);
}
void Form1::saveit()
{
saved_TE->setText(result_TE->text());
}
|