| | 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 | } |
| | 247 | |
| | 248 | m_listIcons->clearSelections(); |
| | 249 | m_editName->setValue(""); |
| | 250 | m_iter = m_listEntries.begin(); |
| | 251 | |
| | 252 | MythProgressDialog *progressDialog = new MythProgressDialog("Downloading, please wait...", |
| | 253 | m_listEntries.size()+1, true, this, SLOT(cancelPressed())); |
| | 254 | while (!m_cancelled && (m_iter != m_listEntries.end())) |
| | 255 | { |
| | 256 | progressDialog->setLabel(QString("Downloading %1 / %2 : ").arg(m_nCount+1) |
| | 257 | .arg(m_listEntries.size()+1) + (*m_iter).strName + |
| | 258 | QString("\nCould not find %1 icons.").arg(m_missingEntries.size()+1)); |
| | 259 | if (!findmissing((*m_iter).strIconCSV)) |
| | 260 | m_missingEntries.append((*m_iter)); |
| | 261 | m_nCount++; |
| | 262 | m_iter++; |
| | 263 | m_missingMaxCount++; |
| | 264 | progressDialog->setProgress(m_nCount); |
| | 265 | } |
| | 266 | progressDialog->Close(); |
| | 267 | |
| | 268 | //Comment below for debugging - cancel button will continue to dialog |
| | 269 | if (m_cancelled) |
| | 270 | m_nMaxCount=0; |
| | 271 | return m_nMaxCount; |
| | 272 | } |
| | 273 | |
| | 274 | bool ImportIconsWizard::doLoad() |
| | 275 | { |
| | 276 | VERBOSE(VB_CHANNEL, QString("%1 / %2").arg(m_missingCount).arg(m_missingMaxCount)); |
| | 277 | if (m_missingCount >= m_missingMaxCount) |
| | 278 | { |
| | 279 | VERBOSE(VB_CHANNEL, "doLoad Icon search complete"); |
| | 280 | if (!m_strMatches.isEmpty()) |
| | 281 | { |
| | 282 | int nVal = MythPopupBox::showOkCancelPopup( |
| | 283 | gContext->GetMainWindow(), |
| | 284 | QObject::tr("Submit information"), |
| | 285 | QObject::tr("You now have the opportunity to " |
| | 286 | "transmit your choices back to " |
| | 287 | "mythtv.org so that others can " |
| | 288 | "benefit from your selections."), |
| | 289 | true); |
| | 290 | if (nVal == 1) |
| | 291 | submit(m_strMatches); |
| | 292 | } |
| | 293 | //FIXME: Exit dialog here |
| | 294 | return false; |
| | 295 | } |
| | 296 | else |
| | 297 | { |
| | 298 | // Look for the next missing icon |
| | 299 | m_editName->setValue((*m_missingIter).strName); |
| | 300 | m_buttonSelect->setEnabled(search((*m_missingIter).strNameCSV)); |
| | 301 | return true; |
| | 302 | } |
| | 303 | } |
| | 304 | |
| | 305 | QString ImportIconsWizard::escape_csv(const QString& str) |
| | 306 | { |
| | 307 | VERBOSE(VB_CHANNEL, "escape_csv"); |
| | 308 | QRegExp rxDblForEscape("\""); |
| | 309 | QString str2 = str; |
| | 310 | str2.replace(rxDblForEscape,"\\\""); |
| | 311 | return "\""+str2+"\""; |
| | 312 | } |
| | 313 | |
| | 314 | QStringList ImportIconsWizard::extract_csv(const QString& strLine) |
| | 315 | { |
| | 316 | VERBOSE(VB_CHANNEL, "extract_csv"); |
| | 317 | QStringList ret; |
| | 318 | //Clean up the line and split out the fields |
| | 319 | QString str = strLine; |
| | 320 | |
| | 321 | unsigned int pos = 0; |
| | 322 | bool fFinish = false; |
| | 323 | while(!fFinish) |
| | 324 | { |
| | 325 | str=str.stripWhiteSpace(); |
| | 326 | while(!fFinish) |
| | 327 | { |
| | 328 | QString strLeft; |
| | 329 | switch (str.at(pos).unicode()) |
| | 330 | { |
| | 331 | case '\\': |
| | 332 | if (pos>=1) |
| | 333 | str.left(pos-1)+str.mid(pos+1); |
| | 334 | else |
| | 335 | str=str.mid(pos+1); |
| | 336 | pos+=2; |
| | 337 | if (pos > str.length()) |
| | 338 | { |
| | 339 | strLeft = str.left(pos); |
| | 340 | if (strLeft.startsWith("\"") && strLeft.endsWith("\"")) |
| | 341 | strLeft=strLeft.mid(1,strLeft.length()-2); |
| | 342 | ret.append(strLeft); |
| | 343 | fFinish = true; |
| | 344 | } |
| | 345 | break; |
| | 346 | case ',': |
| | 347 | strLeft = str.left(pos); |
| | 348 | if (strLeft.startsWith("\"") && strLeft.endsWith("\"")) |
| | 349 | strLeft=strLeft.mid(1,strLeft.length()-2); |
| | 350 | ret.append(strLeft); |
| | 351 | if ((pos+1) > str.length()) |
| | 352 | fFinish = true; |
| | 353 | str=str.mid(pos+1); |
| | 354 | pos=0; |
| | 355 | break; |
| | 356 | default: |
| | 357 | pos++; |
| | 358 | if (pos > str.length()) |
| | 359 | { |
| | 360 | strLeft = str.left(pos); |
| | 361 | if (strLeft.startsWith("\"") && strLeft.endsWith("\"")) |
| | 362 | strLeft=strLeft.mid(1,strLeft.length()-2); |
| | 363 | ret.append(strLeft); |
| | 364 | fFinish = true; |
| | 365 | } |
| | 366 | } |
| | 367 | } |
| | 368 | } |
| | 369 | return ret; |
| | 370 | } |
| | 371 | |
| | 372 | |
| | 373 | QString ImportIconsWizard::wget(QUrl& url,const QString& strParam ) |
| | 374 | { |
| | 375 | VERBOSE(VB_CHANNEL, "wget"); |
| | 376 | QByteArray raw; |
| | 377 | QTextStream rawStream(raw,IO_WriteOnly); |
| | 378 | rawStream << strParam; |
| | 379 | |
| | 380 | QBuffer data(raw); |
| | 381 | QHttpRequestHeader header; |
| | 382 | |
| | 383 | header.setContentType(QString("application/x-www-form-urlencoded")); |
| | 384 | header.setContentLength(raw.size()); |
| | 385 | |
| | 386 | header.setValue("User-Agent", "MythTV Channel Icon lookup bot"); |
| | 387 | |
| | 388 | QString str = HttpComms::postHttp(url,&header,&data); |
| | 389 | |
| | 390 | return str; |
| | 391 | } |
| | 392 | |
| | 393 | bool ImportIconsWizard::checkAndDownload(const QString& str) |
| | 394 | { |
| | 395 | VERBOSE(VB_CHANNEL, "checkAndDownload"); |
| | 396 | int iIndex = str.findRev('/'); |
| | 397 | QString str2; |
| | 398 | if (iIndex < 0) |
| | 399 | str2=str; |
| | 400 | else |
| | 401 | str2=str.mid(iIndex+1); |
| | 402 | |
| | 403 | QString str3 = str; |
| | 404 | QFileInfo file(m_strChannelDir+str2); |
| | 405 | |
| | 406 | bool fRet; |
| | 407 | if (!file.exists()) |
| | 408 | fRet = HttpComms::getHttpFile(m_strChannelDir+str2,str3); |
| | 409 | else |
| | 410 | fRet = true; |
| | 411 | |
| | 412 | if (fRet) |
| | 413 | { |
| | 414 | MSqlQuery query(MSqlQuery::InitCon()); |
| | 415 | QString qstr = "UPDATE channel SET icon = :ICON " |
| | 416 | "WHERE chanid = :CHANID"; |
| | 417 | |
| | 418 | query.prepare(qstr); |
| | 419 | query.bindValue(":ICON", m_strChannelDir+str2); |
| | 420 | query.bindValue(":CHANID", (*m_iter).strChanId); |
| | 421 | |
| | 422 | if (!query.exec()) |
| | 423 | { |
| | 424 | MythContext::DBError("Error inserting channel icon", query); |
| | 425 | return false; |
| | 426 | } |
| | 427 | |
| | 428 | } |
| | 429 | return fRet; |
| | 430 | } |
| | 431 | |
| | 432 | bool ImportIconsWizard::isBlocked(const QString& strParam) |
| | 433 | { |
| | 434 | VERBOSE(VB_CHANNEL, "isBlocked"); |
| | 435 | QString strParam1 = strParam; |
| | 436 | QUrl::encode(strParam1); |
| | 437 | QUrl url(ImportIconsWizard::url+"/checkblock"); |
| | 438 | QString str = wget(url,"csv="+strParam1); |
| | 439 | if (str.startsWith("Error",false)) |
| | 440 | { |
| | 441 | VERBOSE(VB_IMPORTANT, QString("Error from isBlocked : %1").arg(str)); |
| | 442 | return true; |
| | 443 | } |
| | 444 | else if (str.isEmpty() || str.startsWith("\r\n")) |
| | 445 | return false; |
| | 446 | else |
| | 447 | { |
| | 448 | VERBOSE(VB_IMPORTANT, QString("Working isBlocked")); |
| | 449 | int nVal = MythPopupBox::showOkCancelPopup(gContext->GetMainWindow(), |
| | 450 | QObject::tr("Icon is blocked"), |
| | 451 | QObject::tr("This combination of channel and icon " |
| | 452 | "has been blocked by the MythTV " |
| | 453 | "admins. The most common reason for " |
| | 454 | "this is that there is a better match " |
| | 455 | "available.\n " |
| | 456 | "Are you still sure that you want to " |
| | 457 | "use this icon?"), |
| | 458 | true); |
| | 459 | if (nVal == 0) |
| | 460 | return false; |
| | 461 | else |
| | 462 | return true; |
| | 463 | } |
| | 464 | } |
| | 465 | |
| | 466 | |
| | 467 | bool ImportIconsWizard::lookup(const QString& strParam) |
| | 468 | { |
| | 469 | QString strParam1 = "callsign="+strParam; |
| | 470 | QUrl::encode(strParam1); |
| | 471 | QUrl url(ImportIconsWizard::url+"/lookup"); |
| | 472 | |
| | 473 | QString str = wget(url,strParam1); |
| | 474 | if (str.isEmpty() || str.startsWith("Error",false)) |
| | 475 | { |
| | 476 | VERBOSE(VB_IMPORTANT, QString("Error from lookup : %1").arg(str)); |
| | 477 | return true; |
| | 478 | } |
| | 479 | else |
| | 480 | { |
| | 481 | VERBOSE(VB_IMPORTANT, QString("Working lookup : %1").arg(str)); |
| | 482 | return false; |
| | 483 | } |
| | 484 | } |
| | 485 | |
| | 486 | bool ImportIconsWizard::search(const QString& strParam) |
| | 487 | { |
| | 488 | QString strParam1 = strParam; |
| | 489 | QUrl::encode(strParam1); |
| | 490 | QUrl url(ImportIconsWizard::url+"/search"); |
| | 491 | |
| | 492 | QString str = wget(url,"s="+strParam1); |
| | 493 | |
| | 494 | m_listSearch.clear(); |
| | 495 | m_listIcons->clearSelections(); |
| | 496 | |
| | 497 | if (str.isEmpty() || str.startsWith("#") || str.startsWith("Error",false)) |
| | 498 | { |
| | 499 | VERBOSE(VB_IMPORTANT, QString("Error from search : %1").arg(str)); |
| | 500 | return false; |
| | 501 | } |
| | 502 | else |
| | 503 | { |
| | 504 | VERBOSE(VB_IMPORTANT, QString("Working search : %1").arg(str)); |
| | 505 | QStringList strSplit=QStringList::split("\n",str); |
| | 506 | |
| | 507 | for (QStringList::iterator begin=strSplit.begin(); |
| | 508 | begin!=strSplit.end();begin++) |
| | 509 | { |
| | 510 | if (*begin != "#" ) |
| | 511 | { |
| | 512 | QStringList ret = extract_csv(*begin); |
| | 513 | VERBOSE(VB_IMPORTANT, QString(" search : %1 %2 %3").arg(ret[0]).arg(ret[1]).arg(ret[2])); |
| | 514 | SearchEntry entry; |
| | 515 | entry.strID=ret[0]; |
| | 516 | entry.strName=ret[1]; |
| | 517 | entry.strLogo=ret[2]; |
| | 518 | m_listSearch.append(entry); |
| | 519 | m_listIcons->addSelection(entry.strName); |
| | 520 | } |
| | 521 | } |
| | 522 | |
| | 523 | return true; |
| | 524 | } |
| | 525 | } |
| | 526 | |
| | 527 | bool ImportIconsWizard::findmissing(const QString& strParam) |
| | 528 | { |
| | 529 | QString strParam1 = strParam; |
| | 530 | QUrl::encode(strParam1); |
| | 531 | QUrl url(ImportIconsWizard::url+"/findmissing"); |
| | 532 | |
| | 533 | QString str = wget(url,"csv="+strParam1); |
| | 534 | VERBOSE(VB_IMPORTANT, QString("findmissing : strParam1 = %1. str = %2").arg(strParam1).arg(str)); |
| | 535 | if (str.isEmpty() || str.startsWith("#") || str.startsWith("Error",false)) |
| | 536 | { |
| | 537 | VERBOSE(VB_IMPORTANT, QString("Error from findmissing : %1").arg(str)); |
| | 538 | return false; |
| | 539 | } |
| | 540 | else |
| | 541 | { |
| | 542 | VERBOSE(VB_IMPORTANT, QString("Working findmissing : %1").arg(str)); |
| | 543 | QStringList strSplit=QStringList::split("\n",str); |
| | 544 | for (QStringList::iterator begin=strSplit.begin(); |
| | 545 | begin!=strSplit.end();begin++) |
| | 546 | { |
| | 547 | if (*begin != "#" ) |
| | 548 | { |
| | 549 | QStringList ret = extract_csv(*begin); |
| | 550 | 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])); |
| | 551 | checkAndDownload(ret[4]); |
| | 552 | } |
| | 553 | } |
| | 554 | return true; |
| | 555 | } |
| | 556 | } |
| | 557 | |
| | 558 | bool ImportIconsWizard::submit(const QString& strParam) |
| | 559 | { |
| | 560 | QString strParam1 = strParam; |
| | 561 | QUrl::encode(strParam1); |
| | 562 | QUrl url(ImportIconsWizard::url+"/submit"); |
| | 563 | |
| | 564 | QString str = wget(url,"csv="+strParam1); |
| | 565 | if (str.isEmpty() || str.startsWith("#") || str.startsWith("Error",false)) |
| | 566 | { |
| | 567 | VERBOSE(VB_IMPORTANT, QString("Error from submit : %1").arg(str)); |
| | 568 | return false; |
| | 569 | } |
| | 570 | else |
| | 571 | { |
| | 572 | VERBOSE(VB_IMPORTANT, QString("Working submit : %1").arg(str)); |
| | 573 | QStringList strSplit=QStringList::split("\n",str); |
| | 574 | unsigned atsc =0, dvb =0, callsign =0, tv =0, xmltvid=0; |
| | 575 | for (QStringList::iterator begin=strSplit.begin(); |
| | 576 | begin!=strSplit.end();begin++) |
| | 577 | { |
| | 578 | if (*begin != "#" ) |
| | 579 | { |
| | 580 | QStringList strSplit2=QStringList::split(":",*begin); |
| | 581 | QString s=strSplit2[0].stripWhiteSpace(); |
| | 582 | if (s=="a") |
| | 583 | atsc=strSplit2[1].toUInt(); |
| | 584 | else if (s=="c") |
| | 585 | callsign=strSplit2[1].toUInt(); |
| | 586 | else if (s=="d") |
| | 587 | dvb=strSplit2[1].toUInt(); |
| | 588 | else if (s=="t") |
| | 589 | tv=strSplit2[1].toUInt(); |
| | 590 | else if (s=="x") |
| | 591 | xmltvid=strSplit2[1].toUInt(); |
| | 592 | } |
| | 593 | } |
| | 594 | 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)); |
| | 595 | return true; |
| | 596 | } |
| | 597 | } |
| | 598 | |
| | 599 | void ImportIconsWizard::cancelPressed() |
| | 600 | { |
| | 601 | m_cancelled=true; |
| | 602 | } |