コード例 #1
0
ファイル: mainwindow.cpp プロジェクト: msys2/octopi
/*
 * This SLOT is called whenever user clicks a url inside output's textBrowser
 */
void MainWindow::outputTextBrowserAnchorClicked(const QUrl &link)
{
  if (link.toString().contains("goto:"))
  {
    QString pkgName = link.toString().mid(5);

    QModelIndex columnIndex = m_packageModel->index(0, PackageModel::ctn_PACKAGE_NAME_COLUMN,
                                                    QModelIndex());

    QModelIndexList foundItems = m_packageModel->match(columnIndex, Qt::DisplayRole, pkgName, -1, Qt::MatchExactly);
    QModelIndex proxyIndex;

    if (foundItems.count() == 1)
    {
      proxyIndex = foundItems.first();
      if(proxyIndex.isValid())
      {
        ui->tvPackages->scrollTo(proxyIndex, QAbstractItemView::PositionAtCenter);
        ui->tvPackages->setCurrentIndex(proxyIndex);
        _changeTabWidgetPropertiesIndex(ctn_TABINDEX_INFORMATION);
      }
    }
    if (foundItems.count() == 0 || !proxyIndex.isValid())
    {
      refreshTabInfo(pkgName);
      disconnect(ui->twProperties, SIGNAL(currentChanged(int)), this, SLOT(changedTabIndex()));
      _ensureTabVisible(ctn_TABINDEX_INFORMATION);
      connect(ui->twProperties, SIGNAL(currentChanged(int)), this, SLOT(changedTabIndex()));
    }
コード例 #2
0
ファイル: mainwindow.cpp プロジェクト: gcala/octopi
/*
 * This SLOT is called whenever user clicks a url inside output's textBrowser
 */
void MainWindow::outputTextBrowserAnchorClicked(const QUrl &link)
{
  if (link.toString().contains("goto:"))
  {
    QString pkgName = link.toString().mid(5);

    QStandardItemModel * sim = _getCurrentSelectedModel();
    QList<QStandardItem*> foundItems =
        sim->findItems(pkgName, Qt::MatchExactly, ctn_PACKAGE_NAME_COLUMN);

    if (foundItems.count() > 0)
    {
      /*QStandardItem * si = foundItems.first();
      QModelIndex indexIcon = sim->index(si->row(), ctn_PACKAGE_ICON_COLUMN);
      QModelIndex proxyIndex = m_proxyModelPackages->mapFromSource(indexIcon);
      ui->tvPackages->scrollTo(proxyIndex, QAbstractItemView::PositionAtCenter);
      ui->tvPackages->setCurrentIndex(proxyIndex);
      _changeTabWidgetPropertiesIndex(ctn_TABINDEX_INFORMATION);*/

      QStandardItem * si = foundItems.first();
      QModelIndex indexIcon = sim->index(si->row(), ctn_PACKAGE_ICON_COLUMN);
      QModelIndex proxyIndex = m_proxyModelPackages->mapFromSource(indexIcon);
      if(proxyIndex.isValid())
      {
        ui->tvPackages->scrollTo(proxyIndex, QAbstractItemView::PositionAtCenter);
        ui->tvPackages->setCurrentIndex(proxyIndex);
        _changeTabWidgetPropertiesIndex(ctn_TABINDEX_INFORMATION);
      }
      else
      {
        refreshTabInfo(pkgName);
        disconnect(ui->twProperties, SIGNAL(currentChanged(int)), this, SLOT(changedTabIndex()));
        _ensureTabVisible(ctn_TABINDEX_INFORMATION);
        connect(ui->twProperties, SIGNAL(currentChanged(int)), this, SLOT(changedTabIndex()));
      }
    }
コード例 #3
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);
  }
}