コード例 #1
0
ファイル: mainwindow_news.cpp プロジェクト: nbyouri/octopkg
/*
 * This is the high level method that orquestrates the Distro RSS News printing in tabNews
 *
 * boolean parameter searchForLatestNews:
 *    controls whether this method tries to connect to the remote RSS News Feed (default is true)
 * boolean parameter gotoNewsTab:
 *    controls whether this method must set the mainwindow focus to NewsTab (default is true)
 */
void MainWindow::refreshDistroNews(bool searchForLatestNews, bool gotoNewsTab)
{
  ui->actionGetNews->setEnabled(false);
  m_gotoNewsTab = gotoNewsTab;

  if (searchForLatestNews)
  {
    BSDFlavour bsd = UnixCommand::getBSDFlavour();

    if (gotoNewsTab)
    {
      clearTabOutput();
    }

    if (gotoNewsTab && bsd == ectn_FREEBSD)
    {
      writeToTabOutputExt("<b>" +
                          StrConstants::getSearchingForBSDNews().arg("FreeBSD") + "</b>");
    }
    else if (gotoNewsTab && bsd == ectn_PCBSD)
    {
      writeToTabOutputExt("<b>" +
                          StrConstants::getSearchingForBSDNews().arg("PC-BSD") + "</b>");
    }

    /*
     * Here, we retrieve distro's latest news without
     * blocking Octopi main interface.
     */
    QFuture<QString> f;
    f = QtConcurrent::run(getLatestDistroNews);
    g_fwDistroNews.setFuture(f);
    connect(&g_fwDistroNews, SIGNAL(finished()), this, SLOT(postRefreshDistroNews()));
  }
  else
  {
    QString distroRSSXML = utils::retrieveDistroNews(searchForLatestNews);
    showDistroNews(distroRSSXML, false);
  }
}
コード例 #2
0
ファイル: mainwindow_news.cpp プロジェクト: anselmolsm/octopi
/*
 * This is the high level method that orquestrates the Distro RSS News printing in tabNews
 *
 * boolean parameter searchForLatestNews:
 *    controls whether this method tries to connect to the remote RSS News Feed (default is true)
 * boolean parameter gotoNewsTab:
 *    controls whether this method must set the mainwindow focus to NewsTab (default is true)
 */
void MainWindow::refreshDistroNews(bool searchForLatestNews, bool gotoNewsTab)
{
  qApp->processEvents();

  if (searchForLatestNews)
  {
    LinuxDistro distro = UnixCommand::getLinuxDistro();
    clearTabOutput();

    if (distro == ectn_ARCHLINUX || distro == ectn_ARCHBANGLINUX)
    {
      writeToTabOutputExt("<b>" +
                          StrConstants::getSearchingForDistroNews().arg("Arch Linux") + "</b>");
    }
    else if (distro == ectn_CHAKRA)
    {
      writeToTabOutputExt("<b>" +
                          StrConstants::getSearchingForDistroNews().arg("Chakra") + "</b>");
    }
    else if (distro == ectn_MANJAROLINUX)
    {
      writeToTabOutputExt("<b>" +
                          StrConstants::getSearchingForDistroNews().arg("Manjaro Linux") + "</b>");
    }

    qApp->processEvents();
  }

  CPUIntensiveComputing *cic = new CPUIntensiveComputing;
  QString distroRSSXML = retrieveDistroNews(searchForLatestNews);
  delete cic;

  QString html;

  if (distroRSSXML.count() >= 200)
  {
    if (distroRSSXML.at(0)=='*')
    {
      /* If this is an updated RSS, we must warn the user!
         And if the main window is hidden... */
      if (isHidden())
      {
        show();
      }

      ui->twProperties->setTabText(ctn_TABINDEX_NEWS, "** " + StrConstants::getTabNewsName() + " **");
      if (gotoNewsTab)
      {
        ui->twProperties->setCurrentIndex(ctn_TABINDEX_NEWS);
      }
    }
    else
    {
      if(searchForLatestNews)
      {
        ui->twProperties->setTabText(ctn_TABINDEX_NEWS, StrConstants::getTabNewsName());
      }
    }

    //First, we have to parse the raw RSS XML...
    html = parseDistroNews();
  }
  else
  {
    if(searchForLatestNews)
      ui->twProperties->setTabText(ctn_TABINDEX_NEWS, StrConstants::getTabNewsName());

    html = distroRSSXML;
  }

  //Now that we have the html table code, let's put it into TextBrowser's News tab
  QTextBrowser *text = ui->twProperties->widget(ctn_TABINDEX_NEWS)->findChild<QTextBrowser*>("textBrowser");
  if (text)
  {
    text->clear();
    text->setHtml(html);
  }

  clearTabOutput();
  qApp->processEvents();

  if (searchForLatestNews && gotoNewsTab)
  {
    _changeTabWidgetPropertiesIndex(ctn_TABINDEX_NEWS);
  }
}