Browse Source

Don't display Country option in PeerListWidget header menu when country resolution is disabled.

adaptive-webui-19844
sledgehammer999 9 years ago
parent
commit
d39d40c064
  1. 22
      src/gui/properties/peerlistwidget.cpp
  2. 3
      src/gui/properties/peerlistwidget.h

22
src/gui/properties/peerlistwidget.cpp

@ -57,7 +57,7 @@
PeerListWidget::PeerListWidget(PropertiesWidget *parent) PeerListWidget::PeerListWidget(PropertiesWidget *parent)
: QTreeView(parent) : QTreeView(parent)
, m_properties(parent) , m_properties(parent)
, m_displayFlags(false) , m_resolveCountries(false)
{ {
// Load settings // Load settings
loadSettings(); loadSettings();
@ -70,7 +70,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent)
header()->setStretchLastSection(false); header()->setStretchLastSection(false);
// List Model // List Model
m_listModel = new QStandardItemModel(0, PeerListDelegate::COL_COUNT); m_listModel = new QStandardItemModel(0, PeerListDelegate::COL_COUNT);
m_listModel->setHeaderData(PeerListDelegate::COUNTRY, Qt::Horizontal, QVariant()); // Country flag column m_listModel->setHeaderData(PeerListDelegate::COUNTRY, Qt::Horizontal, tr("Country")); // Country flag column
m_listModel->setHeaderData(PeerListDelegate::IP, Qt::Horizontal, tr("IP")); m_listModel->setHeaderData(PeerListDelegate::IP, Qt::Horizontal, tr("IP"));
m_listModel->setHeaderData(PeerListDelegate::PORT, Qt::Horizontal, tr("Port")); m_listModel->setHeaderData(PeerListDelegate::PORT, Qt::Horizontal, tr("Port"));
m_listModel->setHeaderData(PeerListDelegate::FLAGS, Qt::Horizontal, tr("Flags")); m_listModel->setHeaderData(PeerListDelegate::FLAGS, Qt::Horizontal, tr("Flags"));
@ -92,6 +92,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent)
hideColumn(PeerListDelegate::COL_COUNT); hideColumn(PeerListDelegate::COL_COUNT);
if (!Preferences::instance()->resolvePeerCountries()) if (!Preferences::instance()->resolvePeerCountries())
hideColumn(PeerListDelegate::COUNTRY); hideColumn(PeerListDelegate::COUNTRY);
m_wasCountryColHidden = isColumnHidden(PeerListDelegate::COUNTRY);
//Ensure that at least one column is visible at all times //Ensure that at least one column is visible at all times
bool atLeastOne = false; bool atLeastOne = false;
for (unsigned int i = 0; i < PeerListDelegate::IP_HIDDEN; i++) { for (unsigned int i = 0; i < PeerListDelegate::IP_HIDDEN; i++) {
@ -152,6 +153,10 @@ void PeerListWidget::displayToggleColumnsMenu(const QPoint&)
hideshowColumn.setTitle(tr("Column visibility")); hideshowColumn.setTitle(tr("Column visibility"));
QList<QAction*> actions; QList<QAction*> actions;
for (int i = 0; i < PeerListDelegate::IP_HIDDEN; ++i) { for (int i = 0; i < PeerListDelegate::IP_HIDDEN; ++i) {
if ((i == PeerListDelegate::COUNTRY) && !Preferences::instance()->resolvePeerCountries()) {
actions.append(nullptr); // keep the index in sync
continue;
}
QAction *myAct = hideshowColumn.addAction(m_listModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); QAction *myAct = hideshowColumn.addAction(m_listModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString());
myAct->setCheckable(true); myAct->setCheckable(true);
myAct->setChecked(!isColumnHidden(i)); myAct->setChecked(!isColumnHidden(i));
@ -198,15 +203,18 @@ void PeerListWidget::updatePeerHostNameResolutionState()
void PeerListWidget::updatePeerCountryResolutionState() void PeerListWidget::updatePeerCountryResolutionState()
{ {
if (Preferences::instance()->resolvePeerCountries() != m_displayFlags) { if (Preferences::instance()->resolvePeerCountries() != m_resolveCountries) {
m_displayFlags = !m_displayFlags; m_resolveCountries = !m_resolveCountries;
if (m_displayFlags) { if (m_resolveCountries) {
loadPeers(m_properties->getCurrentTorrent()); loadPeers(m_properties->getCurrentTorrent());
if (!m_wasCountryColHidden) {
showColumn(PeerListDelegate::COUNTRY); showColumn(PeerListDelegate::COUNTRY);
resizeColumnToContents(PeerListDelegate::COUNTRY); resizeColumnToContents(PeerListDelegate::COUNTRY);
} }
}
else { else {
hideColumn(PeerListDelegate::COUNTRY); hideColumn(PeerListDelegate::COUNTRY);
m_wasCountryColHidden = false; // to forcefully enable that column if the user decides to resolve countries again
} }
} }
} }
@ -372,7 +380,7 @@ QStandardItem* PeerListWidget::addPeer(const QString &ip, const BitTorrent::Peer
m_listModel->setData(m_listModel->index(row, PeerListDelegate::IP), ip, Qt::ToolTipRole); m_listModel->setData(m_listModel->index(row, PeerListDelegate::IP), ip, Qt::ToolTipRole);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::PORT), peer.address().port); m_listModel->setData(m_listModel->index(row, PeerListDelegate::PORT), peer.address().port);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::IP_HIDDEN), ip); m_listModel->setData(m_listModel->index(row, PeerListDelegate::IP_HIDDEN), ip);
if (m_displayFlags) { if (m_resolveCountries) {
const QIcon ico = GuiIconProvider::instance()->getFlagIcon(peer.country()); const QIcon ico = GuiIconProvider::instance()->getFlagIcon(peer.country());
if (!ico.isNull()) { if (!ico.isNull()) {
m_listModel->setData(m_listModel->index(row, PeerListDelegate::COUNTRY), ico, Qt::DecorationRole); m_listModel->setData(m_listModel->index(row, PeerListDelegate::COUNTRY), ico, Qt::DecorationRole);
@ -400,7 +408,7 @@ void PeerListWidget::updatePeer(const QString &ip, const BitTorrent::PeerInfo &p
{ {
QStandardItem *item = m_peerItems.value(ip); QStandardItem *item = m_peerItems.value(ip);
int row = item->row(); int row = item->row();
if (m_displayFlags) { if (m_resolveCountries) {
const QIcon ico = GuiIconProvider::instance()->getFlagIcon(peer.country()); const QIcon ico = GuiIconProvider::instance()->getFlagIcon(peer.country());
if (!ico.isNull()) { if (!ico.isNull()) {
m_listModel->setData(m_listModel->index(row, PeerListDelegate::COUNTRY), ico, Qt::DecorationRole); m_listModel->setData(m_listModel->index(row, PeerListDelegate::COUNTRY), ico, Qt::DecorationRole);

3
src/gui/properties/peerlistwidget.h

@ -93,7 +93,8 @@ private:
QSet<QString> m_missingFlags; QSet<QString> m_missingFlags;
QPointer<Net::ReverseResolution> m_resolver; QPointer<Net::ReverseResolution> m_resolver;
PropertiesWidget *m_properties; PropertiesWidget *m_properties;
bool m_displayFlags; bool m_resolveCountries;
bool m_wasCountryColHidden;
QShortcut *m_copyHotkey; QShortcut *m_copyHotkey;
}; };

Loading…
Cancel
Save