Added ability to fetch just icons.
This commit is contained in:
		
							parent
							
								
									835d66e94d
								
							
						
					
					
						commit
						98da617b75
					
				
					 5 changed files with 83 additions and 58 deletions
				
			
		| 
						 | 
				
			
			@ -2,6 +2,7 @@
 | 
			
		|||
<center><h2>2.4.0</h2></center>
 | 
			
		||||
Added:
 | 
			
		||||
<ul>
 | 
			
		||||
<li>Ability to fetch only new icon for feed from its online source.</li>
 | 
			
		||||
<li>Option to search highlighted text in web browser via Google, available from context menu. (issue #72)</li>
 | 
			
		||||
</ul>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -63,8 +63,6 @@ FeedsView::FeedsView(QWidget *parent)
 | 
			
		|||
 | 
			
		||||
  // Setup the timer.
 | 
			
		||||
  updateAutoUpdateStatus();
 | 
			
		||||
 | 
			
		||||
  setItemDelegateForColumn(1, new Delegate(this));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
FeedsView::~FeedsView() {
 | 
			
		||||
| 
						 | 
				
			
			@ -690,39 +688,6 @@ void FeedsView::validateItemAfterDragDrop(const QModelIndex &source_index) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Delegate::Delegate(FeedsView *view, QObject *parent) : QStyledItemDelegate(parent) {
 | 
			
		||||
  this->view = view;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
 | 
			
		||||
{
 | 
			
		||||
  QStyledItemDelegate::paint(painter, option, index);
 | 
			
		||||
 | 
			
		||||
  QSize size = sizeHint(option, index);
 | 
			
		||||
 | 
			
		||||
  int width = qMin(size.width(), option.rect.width()) - 4;
 | 
			
		||||
  int height = qMin(size.height(), option.rect.height()) - 4;
 | 
			
		||||
  int left = option.rect.left() + ((option.rect.width() - width) / 2.0);
 | 
			
		||||
  int top = option.rect.top() + ((option.rect.height() - height) / 2.0);
 | 
			
		||||
 | 
			
		||||
  QRect target_rect = QRect(left, top, width, height);
 | 
			
		||||
 | 
			
		||||
  painter->save();
 | 
			
		||||
 | 
			
		||||
  //if ((option.state & QStyle::State_MouseOver) == 0 && (option.state & QStyle::State_Selected) == 0) {
 | 
			
		||||
  painter->setPen(QPen(QColor(Qt::black)));
 | 
			
		||||
  painter->setRenderHint(QPainter::Antialiasing, false);
 | 
			
		||||
  painter->setBrush(QBrush(Qt::lightGray));
 | 
			
		||||
  /*painter->drawRoundRect(QRect(left,
 | 
			
		||||
                                   top,
 | 
			
		||||
                                   width,
 | 
			
		||||
                                   height), 15, 15);*/
 | 
			
		||||
  //}
 | 
			
		||||
 | 
			
		||||
  QString str = view->sourceModel()->data(view->model()->mapToSource(index), Qt::DisplayRole).toString();
 | 
			
		||||
 | 
			
		||||
  painter->drawRect(target_rect);
 | 
			
		||||
  painter->drawText(target_rect, str, QTextOption(Qt::AlignCenter));
 | 
			
		||||
 | 
			
		||||
  painter->restore();
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32,9 +32,6 @@ class FeedsModelFeed;
 | 
			
		|||
class FeedsModelCategory;
 | 
			
		||||
class QTimer;
 | 
			
		||||
 | 
			
		||||
#include <QPainter>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class FeedsView : public QTreeView {
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -203,13 +200,45 @@ class FeedsView : public QTreeView {
 | 
			
		|||
    int m_globalAutoUpdateRemainingInterval;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
class Delegate : public QStyledItemDelegate {
 | 
			
		||||
  public:
 | 
			
		||||
    explicit Delegate(FeedsView *view, QObject *parent = 0);
 | 
			
		||||
    explicit Delegate(FeedsView *view, QObject *parent = 0) : QStyledItemDelegate(parent) {
 | 
			
		||||
      this->view = view;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // QAbstractItemDelegate interface
 | 
			
		||||
  public:
 | 
			
		||||
    void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
 | 
			
		||||
    void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
 | 
			
		||||
    {
 | 
			
		||||
      //QStyledItemDelegate::paint(painter, option, index);
 | 
			
		||||
 | 
			
		||||
      QSize size = sizeHint(option, index);
 | 
			
		||||
 | 
			
		||||
      int width = qMin(size.width(), option.rect.width()) - 4;
 | 
			
		||||
      int height = qMin(size.height(), option.rect.height()) - 4;
 | 
			
		||||
      int left = option.rect.left() + ((option.rect.width() - width) / 2.0);
 | 
			
		||||
      int top = option.rect.top() + ((option.rect.height() - height) / 2.0);
 | 
			
		||||
 | 
			
		||||
      QRect target_rect = QRect(left, top, width, height);
 | 
			
		||||
 | 
			
		||||
      painter->save();
 | 
			
		||||
 | 
			
		||||
      //if ((option.state & QStyle::State_MouseOver) == 0 && (option.state & QStyle::State_Selected) == 0) {
 | 
			
		||||
      painter->setPen(QPen(QColor(Qt::black)));
 | 
			
		||||
      painter->setRenderHint(QPainter::Antialiasing, false);
 | 
			
		||||
      painter->setBrush(QBrush(Qt::lightGray));
 | 
			
		||||
      //}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
      QString str = view->sourceModel()->data(view->model()->mapToSource(index), Qt::DisplayRole).toString();
 | 
			
		||||
 | 
			
		||||
      painter->drawRect(target_rect);
 | 
			
		||||
      painter->drawText(target_rect, str, QTextOption(Qt::AlignCenter));
 | 
			
		||||
 | 
			
		||||
      painter->restore();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // QStyledItemDelegate interface
 | 
			
		||||
  public:
 | 
			
		||||
| 
						 | 
				
			
			@ -230,5 +259,6 @@ class Delegate : public QStyledItemDelegate {
 | 
			
		|||
  private:
 | 
			
		||||
    FeedsView *view;
 | 
			
		||||
};
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
#endif // FEEDSVIEW_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -306,28 +306,51 @@ void FormFeedDetails::guessFeed() {
 | 
			
		|||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void FormFeedDetails::guessIconOnly() {
 | 
			
		||||
  QPair<FeedsModelFeed*, QNetworkReply::NetworkError> result =  FeedsModelFeed::guessFeed(m_ui->m_txtUrl->lineEdit()->text(),
 | 
			
		||||
                                                                                          m_ui->m_txtUsername->lineEdit()->text(),
 | 
			
		||||
                                                                                          m_ui->m_txtPassword->lineEdit()->text());
 | 
			
		||||
 | 
			
		||||
  if (result.first != NULL) {
 | 
			
		||||
    // Icon or whole feed was guessed.
 | 
			
		||||
    m_ui->m_btnIcon->setIcon(result.first->icon());
 | 
			
		||||
 | 
			
		||||
    if (result.second == QNetworkReply::NoError) {
 | 
			
		||||
      m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::Ok,
 | 
			
		||||
                                          tr("Icon fetched successfully."),
 | 
			
		||||
                                          tr("Icon metadata fetched."));
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
      m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::Warning,
 | 
			
		||||
                                          tr("Result: %1.").arg(NetworkFactory::networkErrorText(result.second)),
 | 
			
		||||
                                          tr("Icon metatada not fetched."));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Remove temporary feed object.
 | 
			
		||||
    delete result.first;
 | 
			
		||||
  }
 | 
			
		||||
  else {
 | 
			
		||||
    // No feed guessed, even no icon available.
 | 
			
		||||
    m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::Error,
 | 
			
		||||
                                        tr("Error: %1.").arg(NetworkFactory::networkErrorText(result.second)),
 | 
			
		||||
                                        tr("No icon fetched."));
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void FormFeedDetails::createConnections() {
 | 
			
		||||
  // General connections.
 | 
			
		||||
  connect(m_ui->m_buttonBox, SIGNAL(accepted()),
 | 
			
		||||
          this, SLOT(apply()));
 | 
			
		||||
  connect(m_ui->m_txtTitle->lineEdit(), SIGNAL(textChanged(QString)),
 | 
			
		||||
          this, SLOT(onTitleChanged(QString)));
 | 
			
		||||
  connect(m_ui->m_txtDescription->lineEdit(), SIGNAL(textChanged(QString)),
 | 
			
		||||
          this, SLOT(onDescriptionChanged(QString)));
 | 
			
		||||
  connect(m_ui->m_txtUrl->lineEdit(), SIGNAL(textChanged(QString)),
 | 
			
		||||
          this, SLOT(onUrlChanged(QString)));
 | 
			
		||||
  connect(m_ui->m_txtUsername->lineEdit(), SIGNAL(textChanged(QString)),
 | 
			
		||||
          this, SLOT(onUsernameChanged(QString)));
 | 
			
		||||
  connect(m_ui->m_txtPassword->lineEdit(), SIGNAL(textChanged(QString)),
 | 
			
		||||
          this, SLOT(onPasswordChanged(QString)));
 | 
			
		||||
  connect(m_ui->m_gbAuthentication, SIGNAL(toggled(bool)),
 | 
			
		||||
          this, SLOT(onAuthenticationSwitched()));
 | 
			
		||||
  connect(m_ui->m_cmbAutoUpdateType, SIGNAL(currentIndexChanged(int)),
 | 
			
		||||
          this, SLOT(onAutoUpdateTypeChanged(int)));
 | 
			
		||||
  connect(m_ui->m_btnFetchMetadata, SIGNAL(clicked()),
 | 
			
		||||
          this, SLOT(guessFeed()));
 | 
			
		||||
  connect(m_ui->m_buttonBox, SIGNAL(accepted()), this, SLOT(apply()));
 | 
			
		||||
  connect(m_ui->m_txtTitle->lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(onTitleChanged(QString)));
 | 
			
		||||
  connect(m_ui->m_txtDescription->lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(onDescriptionChanged(QString)));
 | 
			
		||||
  connect(m_ui->m_txtUrl->lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(onUrlChanged(QString)));
 | 
			
		||||
  connect(m_ui->m_txtUsername->lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(onUsernameChanged(QString)));
 | 
			
		||||
  connect(m_ui->m_txtPassword->lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(onPasswordChanged(QString)));
 | 
			
		||||
  connect(m_ui->m_gbAuthentication, SIGNAL(toggled(bool)), this, SLOT(onAuthenticationSwitched()));
 | 
			
		||||
  connect(m_ui->m_cmbAutoUpdateType, SIGNAL(currentIndexChanged(int)), this, SLOT(onAutoUpdateTypeChanged(int)));
 | 
			
		||||
  connect(m_ui->m_btnFetchMetadata, SIGNAL(clicked()), this, SLOT(guessFeed()));
 | 
			
		||||
 | 
			
		||||
  // Icon connections.
 | 
			
		||||
  connect(m_actionFetchIcon, SIGNAL(triggered()), this, SLOT(guessIconOnly()));
 | 
			
		||||
  connect(m_actionLoadIconFromFile, SIGNAL(triggered()), this, SLOT(onLoadIconFromFile()));
 | 
			
		||||
  connect(m_actionNoIcon, SIGNAL(triggered()), this, SLOT(onNoIconSelected()));
 | 
			
		||||
  connect(m_actionUseDefaultIcon, SIGNAL(triggered()), this, SLOT(onUseDefaultIcon()));
 | 
			
		||||
| 
						 | 
				
			
			@ -410,6 +433,10 @@ void FormFeedDetails::initialize() {
 | 
			
		|||
  m_actionUseDefaultIcon = new QAction(qApp->icons()->fromTheme("folder-feed"),
 | 
			
		||||
                                       tr("Use default icon"),
 | 
			
		||||
                                       this);
 | 
			
		||||
  m_actionFetchIcon = new QAction(qApp->icons()->fromTheme("document-download"),
 | 
			
		||||
                                  tr("Fetch icon from feed"),
 | 
			
		||||
                                  this);
 | 
			
		||||
  m_iconMenu->addAction(m_actionFetchIcon);
 | 
			
		||||
  m_iconMenu->addAction(m_actionLoadIconFromFile);
 | 
			
		||||
  m_iconMenu->addAction(m_actionUseDefaultIcon);
 | 
			
		||||
  m_iconMenu->addAction(m_actionNoIcon);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -48,6 +48,7 @@ class FormFeedDetails : public QDialog {
 | 
			
		|||
    // Applies changes.
 | 
			
		||||
    void apply();
 | 
			
		||||
    void guessFeed();
 | 
			
		||||
    void guessIconOnly();
 | 
			
		||||
 | 
			
		||||
    // Trigerred when title/description/url/username/password changes.
 | 
			
		||||
    void onTitleChanged(const QString &new_title);
 | 
			
		||||
| 
						 | 
				
			
			@ -88,6 +89,7 @@ class FormFeedDetails : public QDialog {
 | 
			
		|||
    QMenu *m_iconMenu;
 | 
			
		||||
    QAction *m_actionLoadIconFromFile;
 | 
			
		||||
    QAction *m_actionUseDefaultIcon;
 | 
			
		||||
    QAction *m_actionFetchIcon;
 | 
			
		||||
    QAction *m_actionNoIcon;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue