| 1 | #include <sys/stat.h> |
| 2 | #include <qapplication.h> |
| 3 | #include <qregexp.h> |
| 4 | #include <qbuffer.h> |
| 5 | #include <qfileinfo.h> |
| 6 | |
| 7 | #include "httpcomms.h" |
| 8 | #include "importicons.h" |
| 9 | #include "util.h" |
| 10 | |
| 11 | ImportIconsWizard::ImportIconsWizard(bool fRefresh) |
| 12 | { |
| 13 | m_fRefresh = fRefresh; |
| 14 | |
| 15 | VerticalConfigurationGroup *manSearch = |
| 16 | new VerticalConfigurationGroup(false,false,true,true); |
| 17 | |
| 18 | manSearch->addChild(m_editName = new TransLineEditSetting(false)); |
| 19 | m_editName->setLabel(QObject::tr("Name")); |
| 20 | m_editName->setHelpText(QObject::tr("Name of the icon file")); |
| 21 | |
| 22 | manSearch->addChild(m_listIcons = new TransListBoxSetting()); |
| 23 | m_listIcons->setHelpText(QObject::tr("List of possible icon files")); |
| 24 | |
| 25 | m_editManual = new TransLineEditSetting(); |
| 26 | m_editManual->setHelpText(QObject::tr("Enter text here for the manual search")); |
| 27 | |
| 28 | m_buttonManual = new TransButtonSetting(); |
| 29 | m_buttonManual->setLabel(QObject::tr("&Search")); |
| 30 | m_buttonManual->setHelpText(QObject::tr("Manually search for the text")); |
| 31 | |
| 32 | m_buttonSkip = new TransButtonSetting(); |
| 33 | m_buttonSkip->setLabel(QObject::tr("S&kip")); |
| 34 | m_buttonSkip->setHelpText(QObject::tr("Skip this icon")); |
| 35 | |
| 36 | m_buttonSelect = new TransButtonSetting(); |
| 37 | m_buttonSelect->setLabel(QObject::tr("S&elect")); |
| 38 | m_buttonSelect->setHelpText(QObject::tr("Select this icon")); |
| 39 | |
| 40 | HorizontalConfigurationGroup *hrz1 = |
| 41 | new HorizontalConfigurationGroup(false, false, true, true); |
| 42 | |
| 43 | hrz1->addChild(m_editManual); |
| 44 | hrz1->addChild(m_buttonManual); |
| 45 | hrz1->addChild(m_buttonSkip); |
| 46 | hrz1->addChild(m_buttonSelect); |
| 47 | manSearch->addChild(hrz1); |
| 48 | |
| 49 | addChild(manSearch); |
| 50 | |
| 51 | connect(m_editManual, SIGNAL(valueChanged( const QString&)), |
| 52 | this, SLOT( enableControls())); |
| 53 | connect(m_buttonManual, SIGNAL(pressed()), this, SLOT(manualSearch())); |
| 54 | connect(m_buttonSkip, SIGNAL(pressed()), this, SLOT(skip())); |
| 55 | connect(m_listIcons,SIGNAL(accepted(int)),this, |
| 56 | SLOT(menuSelection(int))); |
| 57 | connect(m_buttonSelect,SIGNAL(pressed()),this, |
| 58 | SLOT(menuSelect())); |
| 59 | |
| 60 | enableControls(); |
| 61 | |
| 62 | |
| 63 | m_strChannelDir = MythContext::GetConfDir()+ "/channels"; |
| 64 | mkdir(MythContext::GetConfDir(),0776); |
| 65 | mkdir(m_strChannelDir,0776); |
| 66 | m_strChannelDir+="/"; |
| 67 | m_cancelled=false; |
| 68 | |
| 69 | if (initialLoad() > 0) |
| 70 | { |
| 71 | m_missingIter=m_missingEntries.begin(); |
| 72 | m_missingCount=0; |
| 73 | enableControls(); |
| 74 | doLoad(); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | const QString ImportIconsWizard::url="http://services.mythtv.org/channel-icon/"; |
| 79 | |
| 80 | void ImportIconsWizard::enableControls(dialogState state) |
| 81 | { |
| 82 | switch (state) |
| 83 | { |
| 84 | case STATE_NORMAL: |
| 85 | if (m_editManual->getValue()) |
| 86 | m_buttonManual->setEnabled(true); |
| 87 | else |
| 88 | m_buttonManual->setEnabled(false); |
| 89 | if (m_missingCount < m_missingMaxCount) |
| 90 | { |
| 91 | m_buttonSkip->setEnabled(true); |
| 92 | m_editName->setEnabled(true); |
| 93 | m_listIcons->setEnabled(true); |
| 94 | m_editManual->setEnabled(true); |
| 95 | m_buttonSelect->setEnabled(true); |
| 96 | // m_editManual->setValue(""); |
| 97 | } |
| 98 | else |
| 99 | { |
| 100 | m_buttonSkip->setEnabled(false); |
| 101 | m_editName->setEnabled(false); |
| 102 | m_listIcons->setEnabled(false); |
| 103 | m_editManual->setEnabled(false); |
| 104 | m_buttonManual->setEnabled(false); |
| 105 | m_buttonSelect->setEnabled(false); |
| 106 | } |
| 107 | break; |
| 108 | case STATE_SEARCHING: |
| 109 | m_buttonSkip->setEnabled(false); |
| 110 | m_buttonSelect->setEnabled(false); |
| 111 | m_buttonManual->setEnabled(false); |
| 112 | m_listIcons->setEnabled(false); |
| 113 | m_listIcons->clearSelections(); |
| 114 | m_listIcons->addSelection("Please wait..."); |
| 115 | break; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | void ImportIconsWizard::manualSearch() |
| 120 | { |
| 121 | enableControls(STATE_SEARCHING); |
| 122 | QString str = m_editManual->getValue(); |
| 123 | search(escape_csv(str)); |
| 124 | enableControls(STATE_NORMAL); |
| 125 | } |
| 126 | |
| 127 | void ImportIconsWizard::skip() |
| 128 | { |
| 129 | enableControls(STATE_SEARCHING); |
| 130 | m_missingCount++; |
| 131 | m_missingIter++; |
| 132 | doLoad(); |
| 133 | enableControls(STATE_NORMAL); |
| 134 | } |
| 135 | |
| 136 | void ImportIconsWizard::menuSelect() |
| 137 | { |
| 138 | menuSelection(m_listIcons->currentItem()); |
| 139 | } |
| 140 | |
| 141 | void ImportIconsWizard::menuSelection(int nIndex) |
| 142 | { |
| 143 | enableControls(STATE_SEARCHING); |
| 144 | SearchEntry entry = *(m_listSearch.at(nIndex)); |
| 145 | if (!isBlocked((*m_iter).strIconCSV) && |
| 146 | checkAndDownload(entry.strLogo)) |
| 147 | { |
| 148 | CSVEntry entry2 = (*m_iter); |
| 149 | m_strMatches += QString("%1,%2,%3,%4,%5,%6,%7,%8,%9\n"). |
| 150 | arg(escape_csv(entry.strID)). |
| 151 | arg(escape_csv(entry2.strName)). |
| 152 | arg(escape_csv(entry2.strXmlTvId)). |
| 153 | arg(escape_csv(entry2.strCallsign)). |
| 154 | arg(escape_csv(entry2.strTransportId)). |
| 155 | arg(escape_csv(entry2.strAtscMajorChan)). |
| 156 | arg(escape_csv(entry2.strAtscMinorChan)). |
| 157 | arg(escape_csv(entry2.strNetworkId)). |
| 158 | arg(escape_csv(entry2.strServiceId)); |
| 159 | m_missingCount++; |
| 160 | m_missingIter++; |
| 161 | doLoad(); |
| 162 | enableControls(STATE_NORMAL); |
| 163 | } |
| 164 | else |
| 165 | { |
| 166 | MythPopupBox::showOkPopup(gContext->GetMainWindow(), |
| 167 | QObject::tr("Error downloading"), |
| 168 | QObject::tr("Failed to download the icon file")); |
| 169 | enableControls(STATE_NORMAL); |
| 170 | } |
| 171 | |
| 172 | } |
| 173 | |
| 174 | unsigned ImportIconsWizard::initialLoad() |
| 175 | { |
| 176 | VERBOSE(VB_CHANNEL, "initialLoad"); |
| 177 | MSqlQuery query(MSqlQuery::InitCon()); |
| 178 | query.prepare("SELECT chanid,name,xmltvid,callsign," |
| 179 | "dtv_multiplex.transportid, " |
| 180 | "atsc_major_chan,atsc_minor_chan,dtv_multiplex.networkid," |
| 181 | "channel.serviceid, " |
| 182 | "channel.mplexid, dtv_multiplex.mplexid," |
| 183 | "channel.icon, channel.visible FROM " |
| 184 | "channel, dtv_multiplex WHERE " |
| 185 | "channel.visible && " |
| 186 | "channel.mplexid=dtv_multiplex.mplexid ORDER BY name"); |
| 187 | |
| 188 | m_listEntries.clear(); |
| 189 | m_nCount=0; |
| 190 | m_nMaxCount=0; |
| 191 | m_missingMaxCount=0; |
| 192 | |
| 193 | if (query.exec() && query.isActive() && query.size() > 0) |
| 194 | { |
| 195 | MythProgressDialog *progressDialog = new MythProgressDialog("Initialising, please wait...", query.size()); |
| 196 | |
| 197 | sleep(2); // Ensures dialog is drawn before ping freezes execution |
| 198 | |
| 199 | if (!ping("services.mythtv.org", 3)) |
| 200 | { |
| 201 | progressDialog->Close(); |
| 202 | MythPopupBox::showOkPopup(gContext->GetMainWindow(), |
| 203 | tr("Bad Host"), |
| 204 | tr("Failed to connect to the remote server")); |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | while(query.next()) |
| 209 | { |
| 210 | CSVEntry entry; |
| 211 | |
| 212 | if (m_fRefresh) |
| 213 | { |
| 214 | QFileInfo file(query.value(11).toString()); |
| 215 | if (file.exists()) |
| 216 | continue; |
| 217 | } |
| 218 | |
| 219 | entry.strChanId=query.value(0).toString(); |
| 220 | entry.strName=query.value(1).toString(); |
| 221 | entry.strXmlTvId=query.value(2).toString(); |
| 222 | entry.strCallsign=query.value(3).toString(); |
| 223 | entry.strTransportId=query.value(4).toString(); |
| 224 | entry.strAtscMajorChan=query.value(5).toString(); |
| 225 | entry.strAtscMinorChan=query.value(6).toString(); |
| 226 | entry.strNetworkId=query.value(7).toString(); |
| 227 | entry.strServiceId=query.value(8).toString(); |
| 228 | entry.strIconCSV= QString("%1,%2,%3,%4,%5,%6,%7,%8,%9\n"). |
| 229 | arg(escape_csv(entry.strChanId)). |
| 230 | arg(escape_csv(entry.strName)). |
| 231 | arg(escape_csv(entry.strXmlTvId)). |
| 232 | arg(escape_csv(entry.strCallsign)). |
| 233 | arg(escape_csv(entry.strTransportId)). |
| 234 | arg(escape_csv(entry.strAtscMajorChan)). |
| 235 | arg(escape_csv(entry.strAtscMinorChan)). |
| 236 | arg(escape_csv(entry.strNetworkId)). |
| 237 | arg(escape_csv(entry.strServiceId)); |
| 238 | entry.strNameCSV=escape_csv(entry.strName); |
| 239 | VERBOSE(VB_IMPORTANT,QString("chanid %1").arg(entry.strIconCSV)); |
| 240 | |
| 241 | m_listEntries.append(entry); |
| 242 | m_nMaxCount++; |
| 243 | progressDialog->setProgress(m_nMaxCount); |
| 244 | } |
| 245 | progressDialog->Close(); |
| 246 | progressDialog->deleteLater(); |
| 247 | } |
| 248 | |
| 249 | m_listIcons->clearSelections(); |
| 250 | m_editName->setValue(""); |
| 251 | m_iter = m_listEntries.begin(); |
| 252 | |
| 253 | MythProgressDialog *progressDialog = new MythProgressDialog("Downloading, please wait...", |
| 254 | m_listEntries.size()+1, true, this, SLOT(cancelPressed())); |
| 255 | while (!m_cancelled && (m_iter != m_listEntries.end())) |
| 256 | { |
| 257 | progressDialog->setLabel(QString("Downloading %1 / %2 : ").arg(m_nCount+1) |
| 258 | .arg(m_listEntries.size()+1) + (*m_iter).strName + |
| 259 | QString("\nCould not find %1 icons.").arg(m_missingEntries.size()+1)); |
| 260 | if (!findmissing((*m_iter).strIconCSV)) |
| 261 | m_missingEntries.append((*m_iter)); |
| 262 | m_nCount++; |
| 263 | m_iter++; |
| 264 | m_missingMaxCount++; |
| 265 | progressDialog->setProgress(m_nCount); |
| 266 | } |
| 267 | progressDialog->Close(); |
| 268 | progressDialog->deleteLater(); |
| 269 | |
| 270 | //Comment below for debugging - cancel button will continue to dialog |
| 271 | if (m_cancelled) |
| 272 | m_nMaxCount=0; |
| 273 | return m_nMaxCount; |
| 274 | } |
| 275 | |
| 276 | bool ImportIconsWizard::doLoad() |
| 277 | { |
| 278 | VERBOSE(VB_CHANNEL, QString("%1 / %2").arg(m_missingCount).arg(m_missingMaxCount)); |
| 279 | if (m_missingCount >= m_missingMaxCount) |
| 280 | { |
| 281 | VERBOSE(VB_CHANNEL, "doLoad Icon search complete"); |
| 282 | if (!m_strMatches.isEmpty()) |
| 283 | { |
| 284 | int nVal = MythPopupBox::showOkCancelPopup( |
| 285 | gContext->GetMainWindow(), |
| 286 | QObject::tr("Submit information"), |
| 287 | QObject::tr("You now have the opportunity to " |
| 288 | "transmit your choices back to " |
| 289 | "mythtv.org so that others can " |
| 290 | "benefit from your selections."), |
| 291 | true); |
| 292 | if (nVal == 1) |
| 293 | submit(m_strMatches); |
| 294 | } |
| 295 | return false; |
| 296 | } |
| 297 | else |
| 298 | { |
| 299 | // Look for the next missing icon |
| 300 | m_editName->setValue((*m_missingIter).strName); |
| 301 | m_buttonSelect->setEnabled(search((*m_missingIter).strNameCSV)); |
| 302 | return true; |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | QString ImportIconsWizard::escape_csv(const QString& str) |
| 307 | { |
| 308 | VERBOSE(VB_CHANNEL, "escape_csv"); |
| 309 | QRegExp rxDblForEscape("\""); |
| 310 | QString str2 = str; |
| 311 | str2.replace(rxDblForEscape,"\\\""); |
| 312 | return "\""+str2+"\""; |
| 313 | } |
| 314 | |
| 315 | QStringList ImportIconsWizard::extract_csv(const QString& strLine) |
| 316 | { |
| 317 | VERBOSE(VB_CHANNEL, "extract_csv"); |
| 318 | QStringList ret; |
| 319 | //Clean up the line and split out the fields |
| 320 | QString str = strLine; |
| 321 | |
| 322 | unsigned int pos = 0; |
| 323 | bool fFinish = false; |
| 324 | while(!fFinish) |
| 325 | { |
| 326 | str=str.stripWhiteSpace(); |
| 327 | while(!fFinish) |
| 328 | { |
| 329 | QString strLeft; |
| 330 | switch (str.at(pos).unicode()) |
| 331 | { |
| 332 | case '\\': |
| 333 | if (pos>=1) |
| 334 | str.left(pos-1)+str.mid(pos+1); |
| 335 | else |
| 336 | str=str.mid(pos+1); |
| 337 | pos+=2; |
| 338 | if (pos > str.length()) |
| 339 | { |
| 340 | strLeft = str.left(pos); |
| 341 | if (strLeft.startsWith("\"") && strLeft.endsWith("\"")) |
| 342 | strLeft=strLeft.mid(1,strLeft.length()-2); |
| 343 | ret.append(strLeft); |
| 344 | fFinish = true; |
| 345 | } |
| 346 | break; |
| 347 | case ',': |
| 348 | strLeft = str.left(pos); |
| 349 | if (strLeft.startsWith("\"") && strLeft.endsWith("\"")) |
| 350 | strLeft=strLeft.mid(1,strLeft.length()-2); |
| 351 | ret.append(strLeft); |
| 352 | if ((pos+1) > str.length()) |
| 353 | fFinish = true; |
| 354 | str=str.mid(pos+1); |
| 355 | pos=0; |
| 356 | break; |
| 357 | default: |
| 358 | pos++; |
| 359 | if (pos > str.length()) |
| 360 | { |
| 361 | strLeft = str.left(pos); |
| 362 | if (strLeft.startsWith("\"") && strLeft.endsWith("\"")) |
| 363 | strLeft=strLeft.mid(1,strLeft.length()-2); |
| 364 | ret.append(strLeft); |
| 365 | fFinish = true; |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | return ret; |
| 371 | } |
| 372 | |
| 373 | |
| 374 | QString ImportIconsWizard::wget(QUrl& url,const QString& strParam ) |
| 375 | { |
| 376 | VERBOSE(VB_CHANNEL, "wget"); |
| 377 | QByteArray raw; |
| 378 | QTextStream rawStream(raw,IO_WriteOnly); |
| 379 | rawStream << strParam; |
| 380 | |
| 381 | QBuffer data(raw); |
| 382 | QHttpRequestHeader header; |
| 383 | |
| 384 | header.setContentType(QString("application/x-www-form-urlencoded")); |
| 385 | header.setContentLength(raw.size()); |
| 386 | |
| 387 | header.setValue("User-Agent", "MythTV Channel Icon lookup bot"); |
| 388 | |
| 389 | QString str = HttpComms::postHttp(url,&header,&data); |
| 390 | |
| 391 | return str; |
| 392 | } |
| 393 | |
| 394 | bool ImportIconsWizard::checkAndDownload(const QString& str) |
| 395 | { |
| 396 | VERBOSE(VB_CHANNEL, "checkAndDownload"); |
| 397 | int iIndex = str.findRev('/'); |
| 398 | QString str2; |
| 399 | if (iIndex < 0) |
| 400 | str2=str; |
| 401 | else |
| 402 | str2=str.mid(iIndex+1); |
| 403 | |
| 404 | QString str3 = str; |
| 405 | QFileInfo file(m_strChannelDir+str2); |
| 406 | |
| 407 | bool fRet; |
| 408 | if (!file.exists()) |
| 409 | fRet = HttpComms::getHttpFile(m_strChannelDir+str2,str3); |
| 410 | else |
| 411 | fRet = true; |
| 412 | |
| 413 | if (fRet) |
| 414 | { |
| 415 | MSqlQuery query(MSqlQuery::InitCon()); |
| 416 | QString qstr = "UPDATE channel SET icon = :ICON " |
| 417 | "WHERE chanid = :CHANID"; |
| 418 | |
| 419 | query.prepare(qstr); |
| 420 | query.bindValue(":ICON", m_strChannelDir+str2); |
| 421 | query.bindValue(":CHANID", (*m_iter).strChanId); |
| 422 | |
| 423 | if (!query.exec()) |
| 424 | { |
| 425 | MythContext::DBError("Error inserting channel icon", query); |
| 426 | return false; |
| 427 | } |
| 428 | |
| 429 | } |
| 430 | return fRet; |
| 431 | } |
| 432 | |
| 433 | bool ImportIconsWizard::isBlocked(const QString& strParam) |
| 434 | { |
| 435 | VERBOSE(VB_CHANNEL, "isBlocked"); |
| 436 | QString strParam1 = strParam; |
| 437 | QUrl::encode(strParam1); |
| 438 | QUrl url(ImportIconsWizard::url+"/checkblock"); |
| 439 | QString str = wget(url,"csv="+strParam1); |
| 440 | if (str.startsWith("Error",false)) |
| 441 | { |
| 442 | VERBOSE(VB_IMPORTANT, QString("Error from isBlocked : %1").arg(str)); |
| 443 | return true; |
| 444 | } |
| 445 | else if (str.isEmpty() || str.startsWith("\r\n")) |
| 446 | return false; |
| 447 | else |
| 448 | { |
| 449 | VERBOSE(VB_IMPORTANT, QString("Working isBlocked")); |
| 450 | int nVal = MythPopupBox::showOkCancelPopup(gContext->GetMainWindow(), |
| 451 | QObject::tr("Icon is blocked"), |
| 452 | QObject::tr("This combination of channel and icon " |
| 453 | "has been blocked by the MythTV " |
| 454 | "admins. The most common reason for " |
| 455 | "this is that there is a better match " |
| 456 | "available.\n " |
| 457 | "Are you still sure that you want to " |
| 458 | "use this icon?"), |
| 459 | true); |
| 460 | if (nVal == 0) |
| 461 | return false; |
| 462 | else |
| 463 | return true; |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | |
| 468 | bool ImportIconsWizard::lookup(const QString& strParam) |
| 469 | { |
| 470 | QString strParam1 = "callsign="+strParam; |
| 471 | QUrl::encode(strParam1); |
| 472 | QUrl url(ImportIconsWizard::url+"/lookup"); |
| 473 | |
| 474 | QString str = wget(url,strParam1); |
| 475 | if (str.isEmpty() || str.startsWith("Error",false)) |
| 476 | { |
| 477 | VERBOSE(VB_IMPORTANT, QString("Error from lookup : %1").arg(str)); |
| 478 | return true; |
| 479 | } |
| 480 | else |
| 481 | { |
| 482 | VERBOSE(VB_IMPORTANT, QString("Working lookup : %1").arg(str)); |
| 483 | return false; |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | bool ImportIconsWizard::search(const QString& strParam) |
| 488 | { |
| 489 | QString strParam1 = strParam; |
| 490 | QUrl::encode(strParam1); |
| 491 | QUrl url(ImportIconsWizard::url+"/search"); |
| 492 | |
| 493 | QString str = wget(url,"s="+strParam1); |
| 494 | |
| 495 | m_listSearch.clear(); |
| 496 | m_listIcons->clearSelections(); |
| 497 | |
| 498 | if (str.isEmpty() || str.startsWith("#") || str.startsWith("Error",false)) |
| 499 | { |
| 500 | VERBOSE(VB_IMPORTANT, QString("Error from search : %1").arg(str)); |
| 501 | return false; |
| 502 | } |
| 503 | else |
| 504 | { |
| 505 | VERBOSE(VB_IMPORTANT, QString("Working search : %1").arg(str)); |
| 506 | QStringList strSplit=QStringList::split("\n",str); |
| 507 | |
| 508 | for (QStringList::iterator begin=strSplit.begin(); |
| 509 | begin!=strSplit.end();begin++) |
| 510 | { |
| 511 | if (*begin != "#" ) |
| 512 | { |
| 513 | QStringList ret = extract_csv(*begin); |
| 514 | VERBOSE(VB_IMPORTANT, QString(" search : %1 %2 %3").arg(ret[0]).arg(ret[1]).arg(ret[2])); |
| 515 | SearchEntry entry; |
| 516 | entry.strID=ret[0]; |
| 517 | entry.strName=ret[1]; |
| 518 | entry.strLogo=ret[2]; |
| 519 | m_listSearch.append(entry); |
| 520 | m_listIcons->addSelection(entry.strName); |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | return true; |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | bool ImportIconsWizard::findmissing(const QString& strParam) |
| 529 | { |
| 530 | QString strParam1 = strParam; |
| 531 | QUrl::encode(strParam1); |
| 532 | QUrl url(ImportIconsWizard::url+"/findmissing"); |
| 533 | |
| 534 | QString str = wget(url,"csv="+strParam1); |
| 535 | VERBOSE(VB_IMPORTANT, QString("findmissing : strParam1 = %1. str = %2").arg(strParam1).arg(str)); |
| 536 | if (str.isEmpty() || str.startsWith("#") || str.startsWith("Error",false)) |
| 537 | { |
| 538 | VERBOSE(VB_IMPORTANT, QString("Error from findmissing : %1").arg(str)); |
| 539 | return false; |
| 540 | } |
| 541 | else |
| 542 | { |
| 543 | VERBOSE(VB_IMPORTANT, QString("Working findmissing : %1").arg(str)); |
| 544 | QStringList strSplit=QStringList::split("\n",str); |
| 545 | for (QStringList::iterator begin=strSplit.begin(); |
| 546 | begin!=strSplit.end();begin++) |
| 547 | { |
| 548 | if (*begin != "#" ) |
| 549 | { |
| 550 | QStringList ret = extract_csv(*begin); |
| 551 | VERBOSE(VB_IMPORTANT, QString(" findmissing : %1 %2 %3 %4 %5").arg(ret[0]).arg(ret[1]).arg(ret[2]).arg(ret[3]).arg(ret[4])); |
| 552 | checkAndDownload(ret[4]); |
| 553 | } |
| 554 | } |
| 555 | return true; |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | bool ImportIconsWizard::submit(const QString& strParam) |
| 560 | { |
| 561 | QString strParam1 = strParam; |
| 562 | QUrl::encode(strParam1); |
| 563 | QUrl url(ImportIconsWizard::url+"/submit"); |
| 564 | |
| 565 | QString str = wget(url,"csv="+strParam1); |
| 566 | if (str.isEmpty() || str.startsWith("#") || str.startsWith("Error",false)) |
| 567 | { |
| 568 | VERBOSE(VB_IMPORTANT, QString("Error from submit : %1").arg(str)); |
| 569 | return false; |
| 570 | } |
| 571 | else |
| 572 | { |
| 573 | VERBOSE(VB_IMPORTANT, QString("Working submit : %1").arg(str)); |
| 574 | QStringList strSplit=QStringList::split("\n",str); |
| 575 | unsigned atsc =0, dvb =0, callsign =0, tv =0, xmltvid=0; |
| 576 | for (QStringList::iterator begin=strSplit.begin(); |
| 577 | begin!=strSplit.end();begin++) |
| 578 | { |
| 579 | if (*begin != "#" ) |
| 580 | { |
| 581 | QStringList strSplit2=QStringList::split(":",*begin); |
| 582 | QString s=strSplit2[0].stripWhiteSpace(); |
| 583 | if (s=="a") |
| 584 | atsc=strSplit2[1].toUInt(); |
| 585 | else if (s=="c") |
| 586 | callsign=strSplit2[1].toUInt(); |
| 587 | else if (s=="d") |
| 588 | dvb=strSplit2[1].toUInt(); |
| 589 | else if (s=="t") |
| 590 | tv=strSplit2[1].toUInt(); |
| 591 | else if (s=="x") |
| 592 | xmltvid=strSplit2[1].toUInt(); |
| 593 | } |
| 594 | } |
| 595 | VERBOSE(VB_IMPORTANT, QString("working submit : atsc=%1 callsign=%2 dvb=%3 tv=%4 xmltvid=%5").arg(atsc).arg(callsign).arg(dvb).arg(tv).arg(xmltvid)); |
| 596 | return true; |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | void ImportIconsWizard::cancelPressed() |
| 601 | { |
| 602 | m_cancelled=true; |
| 603 | } |