dbhub: Respect the order of the licence list and remove "Unspecified"

Respect the suggested order of the licences as provided by the dbhub.io
server instead of sorting them alphabetically by their internal key.

Also remove the hard-coded "Unspecified" licence option because the
dbhub.io server provided its own "No licence specified" option.
This commit is contained in:
Martin Kleusberg
2019-05-03 15:28:02 +02:00
parent 5e90d90ac6
commit 16768d5474
4 changed files with 13 additions and 10 deletions

View File

@@ -199,13 +199,17 @@ void RemoteDatabase::gotReply(QNetworkReply* reply)
if(obj.is_discarded() || !obj.is_object())
break;
// Parse data and build licence map (short name -> long name)
std::map<std::string, std::string> licences;
// Parse data and build ordered licence map: order -> (short name, long name)
std::map<int, std::pair<std::string, std::string>> licences;
for(auto it=obj.cbegin();it!=obj.cend();++it)
licences.insert({it.key(), it.value()["full_name"]});
licences.insert({it.value()["order"], {it.key(), it.value()["full_name"]}});
// Send licence map to anyone who's interested
emit gotLicenceList(licences);
// Convert the map into an ordered vector and send it to anyone who's interested
std::vector<std::pair<std::string, std::string>> licence_list;
std::transform(licences.begin(), licences.end(), std::back_inserter(licence_list), [](const std::pair<int, std::pair<std::string, std::string>>& it) {
return it.second;
});
emit gotLicenceList(licence_list);
break;
}
case RequestTypeBranchList:

View File

@@ -63,7 +63,7 @@ signals:
// a directory listing or the licence list.
void gotDirList(QString json, QVariant userdata);
void gotCurrentVersion(QString version, QString url);
void gotLicenceList(std::map<std::string, std::string> licences);
void gotLicenceList(std::vector<std::pair<std::string, std::string>> licences);
void gotBranchList(std::vector<std::string> branches, std::string default_branch);
// The uploadFinished() signal is emitted when a push() call is finished, i.e. a database upload has completed.

View File

@@ -104,11 +104,10 @@ bool RemotePushDialog::forcePush() const
return ui->checkForce->isChecked();
}
void RemotePushDialog::fillInLicences(const std::map<std::string, std::string>& licences)
void RemotePushDialog::fillInLicences(const std::vector<std::pair<std::string, std::string>>& licences)
{
// Clear licence list and add default item for unspecified licence
// Clear licence list
ui->comboLicence->clear();
ui->comboLicence->addItem(tr("Unspecified"), QString());
// Parse licence list and fill combo box. Show the full name to the user and use the short name as user data.
for(const auto& it : licences)

View File

@@ -45,7 +45,7 @@ protected slots:
void reloadBranchList();
void fillInLicences(const std::map<std::string, std::string>& licences);
void fillInLicences(const std::vector<std::pair<std::string, std::string>>& licences);
void fillInBranches(const std::vector<std::string>& branches, const std::string& default_branch);
};