refactor: remove ReleaseChannel keeping track of its own indexes (#5366)

This commit is contained in:
RickyRister 2024-12-28 15:51:37 -08:00 committed by GitHub
parent c8d49b5bf9
commit 25d21a3da6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 13 additions and 18 deletions

View file

@ -21,11 +21,8 @@
#define GIT_SHORT_HASH_LEN 7 #define GIT_SHORT_HASH_LEN 7
int ReleaseChannel::sharedIndex = 0;
ReleaseChannel::ReleaseChannel() : netMan(new QNetworkAccessManager(this)), response(nullptr), lastRelease(nullptr) ReleaseChannel::ReleaseChannel() : netMan(new QNetworkAccessManager(this)), response(nullptr), lastRelease(nullptr)
{ {
index = sharedIndex++;
} }
ReleaseChannel::~ReleaseChannel() ReleaseChannel::~ReleaseChannel()

View file

@ -82,9 +82,6 @@ public:
~ReleaseChannel() override; ~ReleaseChannel() override;
protected: protected:
// shared by all instances
static int sharedIndex;
int index;
QNetworkAccessManager *netMan; QNetworkAccessManager *netMan;
QNetworkReply *response; QNetworkReply *response;
Release *lastRelease; Release *lastRelease;
@ -94,10 +91,6 @@ protected:
virtual QString getReleaseChannelUrl() const = 0; virtual QString getReleaseChannelUrl() const = 0;
public: public:
int getIndex() const
{
return index;
}
Release *getLastRelease() Release *getLastRelease()
{ {
return lastRelease; return lastRelease;

View file

@ -174,8 +174,9 @@ GeneralSettingsPage::GeneralSettingsPage()
GeneralSettingsPage::retranslateUi(); GeneralSettingsPage::retranslateUi();
// connect the ReleaseChannel combo box only after the entries are inserted in retranslateUi // connect the ReleaseChannel combo box only after the entries are inserted in retranslateUi
connect(&updateReleaseChannelBox, SIGNAL(currentIndexChanged(int)), &settings, SLOT(setUpdateReleaseChannel(int))); connect(&updateReleaseChannelBox, SIGNAL(currentIndexChanged(int)), &settings,
updateReleaseChannelBox.setCurrentIndex(settings.getUpdateReleaseChannel()->getIndex()); SLOT(setUpdateReleaseChannelIndex(int)));
updateReleaseChannelBox.setCurrentIndex(settings.getUpdateReleaseChannelIndex());
setLayout(mainLayout); setLayout(mainLayout);
} }
@ -309,7 +310,7 @@ void GeneralSettingsPage::retranslateUi()
int oldIndex = updateReleaseChannelBox.currentIndex(); int oldIndex = updateReleaseChannelBox.currentIndex();
updateReleaseChannelBox.clear(); updateReleaseChannelBox.clear();
for (ReleaseChannel *chan : settings.getUpdateReleaseChannels()) { for (ReleaseChannel *chan : settings.getUpdateReleaseChannels()) {
updateReleaseChannelBox.insertItem(chan->getIndex(), tr(chan->getName().toUtf8())); updateReleaseChannelBox.addItem(tr(chan->getName().toUtf8()));
} }
updateReleaseChannelBox.setCurrentIndex(oldIndex); updateReleaseChannelBox.setCurrentIndex(oldIndex);
} }

View file

@ -1139,9 +1139,9 @@ void SettingsCache::setDownloadSpoilerStatus(bool _spoilerStatus)
emit downloadSpoilerStatusChanged(); emit downloadSpoilerStatusChanged();
} }
void SettingsCache::setUpdateReleaseChannel(int _updateReleaseChannel) void SettingsCache::setUpdateReleaseChannelIndex(int value)
{ {
updateReleaseChannel = _updateReleaseChannel; updateReleaseChannel = value;
settings->setValue("personal/updatereleasechannel", updateReleaseChannel); settings->setValue("personal/updatereleasechannel", updateReleaseChannel);
} }

View file

@ -290,6 +290,10 @@ public:
{ {
return seenTips; return seenTips;
} }
int getUpdateReleaseChannelIndex() const
{
return updateReleaseChannel;
}
ReleaseChannel *getUpdateReleaseChannel() const ReleaseChannel *getUpdateReleaseChannel() const
{ {
return releaseChannels.at(qMax(0, updateReleaseChannel)); return releaseChannels.at(qMax(0, updateReleaseChannel));
@ -712,7 +716,7 @@ public slots:
void setCheckUpdatesOnStartup(QT_STATE_CHANGED_T value); void setCheckUpdatesOnStartup(QT_STATE_CHANGED_T value);
void setNotifyAboutUpdate(QT_STATE_CHANGED_T _notifyaboutupdate); void setNotifyAboutUpdate(QT_STATE_CHANGED_T _notifyaboutupdate);
void setNotifyAboutNewVersion(QT_STATE_CHANGED_T _notifyaboutnewversion); void setNotifyAboutNewVersion(QT_STATE_CHANGED_T _notifyaboutnewversion);
void setUpdateReleaseChannel(int _updateReleaseChannel); void setUpdateReleaseChannelIndex(int value);
void setMaxFontSize(int _max); void setMaxFontSize(int _max);
}; };

View file

@ -321,7 +321,7 @@ void SettingsCache::setNotifyAboutNewVersion(QT_STATE_CHANGED_T /* _notifyaboutn
void SettingsCache::setDownloadSpoilerStatus(bool /* _spoilerStatus */) void SettingsCache::setDownloadSpoilerStatus(bool /* _spoilerStatus */)
{ {
} }
void SettingsCache::setUpdateReleaseChannel(int /* _updateReleaseChannel */) void SettingsCache::setUpdateReleaseChannelIndex(int /* value */)
{ {
} }
void SettingsCache::setMaxFontSize(int /* _max */) void SettingsCache::setMaxFontSize(int /* _max */)

View file

@ -325,7 +325,7 @@ void SettingsCache::setNotifyAboutNewVersion(QT_STATE_CHANGED_T /* _notifyaboutn
void SettingsCache::setDownloadSpoilerStatus(bool /* _spoilerStatus */) void SettingsCache::setDownloadSpoilerStatus(bool /* _spoilerStatus */)
{ {
} }
void SettingsCache::setUpdateReleaseChannel(int /* _updateReleaseChannel */) void SettingsCache::setUpdateReleaseChannelIndex(int /* value */)
{ {
} }
void SettingsCache::setMaxFontSize(int /* _max */) void SettingsCache::setMaxFontSize(int /* _max */)