HaikuDepot: Title versus Name distinction

* The name is the static package name. The title is either that name,
   or a translated pretty version of the name.
 * Adjust package info retrieval to server API changes. Unbreaks package
   translations.
This commit is contained in:
Stephan Aßmus 2015-04-04 22:14:45 +02:00
parent 5a7c64f90a
commit 72992391bb
14 changed files with 120 additions and 79 deletions

View File

@ -174,7 +174,7 @@ public:
if (package.Get()==NULL)
return false;
printf("TEST %s\n", package->Title().String());
printf("TEST %s\n", package->Name().String());
for (int32 i = 0; i < fPackageLists.CountItems(); i++) {
if (fPackageLists.ItemAtFast(i)->Contains(package)) {
@ -235,7 +235,8 @@ public:
// Every search term must be found in one of the package texts
for (int32 i = fSearchTerms.CountItems() - 1; i >= 0; i--) {
const BString& term = fSearchTerms.ItemAtFast(i);
if (!_TextContains(package->Title(), term)
if (!_TextContains(package->Name(), term)
&& !_TextContains(package->Title(), term)
&& !_TextContains(package->Publisher().Name(), term)
&& !_TextContains(package->ShortDescription(), term)
&& !_TextContains(package->FullDescription(), term)) {
@ -288,7 +289,7 @@ public:
static inline bool
is_source_package(const PackageInfoRef& package)
{
const BString& packageName = package->Title();
const BString& packageName = package->Name();
return packageName.EndsWith("_source");
}
@ -296,7 +297,7 @@ is_source_package(const PackageInfoRef& package)
static inline bool
is_develop_package(const PackageInfoRef& package)
{
const BString& packageName = package->Title();
const BString& packageName = package->Name();
return packageName.EndsWith("_devel");
}
@ -662,7 +663,7 @@ Model::PopulatePackage(const PackageInfoRef& package, uint32 flags)
BString architecture;
{
BAutolock locker(&fLock);
packageName = package->Title();
packageName = package->Name();
architecture = package->Architecture();
}
@ -903,7 +904,7 @@ Model::_PopulateAllPackagesThread(bool fromCacheOnly)
break;
const PackageInfoRef& package = packagesWithIconsList.ItemAtFast(i);
printf("Getting/Updating native icon for %s\n",
package->Title().String());
package->Name().String());
_PopulatePackageIcon(package, fromCacheOnly);
}
}
@ -963,7 +964,7 @@ Model::_PopulatePackageInfos(PackageList& packages, bool fromCacheOnly,
BFile file;
BPath path;
BString name(package->Title());
BString name(package->Name());
name << ".info";
if (_GetCacheFile(path, file, B_USER_CACHE_DIRECTORY,
"HaikuDepot", name, fromCacheOnly, 60 * 60)) {
@ -988,7 +989,7 @@ Model::_PopulatePackageInfos(PackageList& packages, bool fromCacheOnly,
StringList packageArchitectures;
for (int i = 0; i < packages.CountItems(); i++) {
const PackageInfoRef& package = packages.ItemAtFast(i);
packageNames.Add(package->Title());
packageNames.Add(package->Name());
packageArchitectures.Add(package->Architecture());
}
@ -1019,7 +1020,7 @@ Model::_PopulatePackageInfos(PackageList& packages, bool fromCacheOnly,
bool found = false;
for (int i = 0; i < packages.CountItems(); i++) {
const PackageInfoRef& package = packages.ItemAtFast(i);
if (pkgName == package->Title()) {
if (pkgName == package->Name()) {
_PopulatePackageInfo(package, pkgInfo);
if (_HasNativeIcon(pkgInfo))
packagesWithIcons.Add(package);
@ -1027,7 +1028,7 @@ Model::_PopulatePackageInfos(PackageList& packages, bool fromCacheOnly,
// Store in cache
BFile file;
BPath path;
BString fileName(package->Title());
BString fileName(package->Name());
fileName << ".info";
if (_GetCacheFile(path, file, B_USER_CACHE_DIRECTORY,
"HaikuDepot", fileName,
@ -1070,7 +1071,7 @@ Model::_PopulatePackageInfos(PackageList& packages, bool fromCacheOnly,
if (packages.CountItems() > 0) {
for (int i = 0; i < packages.CountItems(); i++) {
const PackageInfoRef& package = packages.ItemAtFast(i);
printf("No package info for %s\n", package->Title().String());
printf("No package info for %s\n", package->Name().String());
}
}
}
@ -1085,7 +1086,7 @@ Model::_PopulatePackageInfo(const PackageInfoRef& package, bool fromCacheOnly)
// Retrieve info from web-app
BMessage info;
status_t status = fWebAppInterface.RetrievePackageInfo(package->Title(),
status_t status = fWebAppInterface.RetrievePackageInfo(package->Name(),
package->Architecture(), info);
if (status == B_OK) {
// Parse message
@ -1112,6 +1113,7 @@ Model::_PopulatePackageInfo(const PackageInfoRef& package, const BMessage& data)
BAutolock locker(&fLock);
BString foundInfo;
data.PrintToStream();
BMessage versions;
if (data.FindMessage("versions", &versions) == B_OK) {
@ -1123,13 +1125,12 @@ Model::_PopulatePackageInfo(const PackageInfoRef& package, const BMessage& data)
BMessage version;
if (versions.FindMessage(name, &version) != B_OK)
break;
BString languageCode;
if (version.FindString("naturalLanguageCode",
&languageCode) != B_OK
|| languageCode != fPreferredLanguage) {
continue;
}
BString title;
if (version.FindString("title", &title) == B_OK) {
package->SetTitle(title);
append_word_list(foundInfo, "title");
}
BString summary;
if (version.FindString("summary", &summary) == B_OK) {
package->SetShortDescription(summary);
@ -1217,7 +1218,7 @@ Model::_PopulatePackageInfo(const PackageInfoRef& package, const BMessage& data)
if (foundInfo.Length() > 0) {
printf("Populated package info for %s: %s\n",
package->Title().String(), foundInfo.String());
package->Name().String(), foundInfo.String());
}
// If the user already clicked this package, remove it from the
@ -1234,7 +1235,7 @@ Model::_PopulatePackageIcon(const PackageInfoRef& package, bool fromCacheOnly)
// See if there is a cached icon file
BFile iconFile;
BPath iconCachePath;
BString iconName(package->Title());
BString iconName(package->Name());
iconName << ".hvif";
if (_GetCacheFile(iconCachePath, iconFile, B_USER_CACHE_DIRECTORY,
"HaikuDepot", iconName, fromCacheOnly, 60 * 60)) {
@ -1251,7 +1252,7 @@ Model::_PopulatePackageIcon(const PackageInfoRef& package, bool fromCacheOnly)
// Retrieve icon from web-app
BMallocIO buffer;
status_t status = fWebAppInterface.RetrievePackageIcon(package->Title(),
status_t status = fWebAppInterface.RetrievePackageIcon(package->Name(),
&buffer);
if (status == B_OK) {
BitmapRef bitmapRef(new(std::nothrow)SharedBitmap(buffer), true);

View File

@ -49,7 +49,7 @@ PackageAction::FindPackageByName(const BString& name)
const PackageList& packages = depot.Packages();
for (int32 j = 0; j < packages.CountItems(); j++) {
PackageInfoRef info = packages.ItemAtFast(j);
if (info->Title() == name)
if (info->Name() == name)
return info;
}
}

View File

@ -455,6 +455,7 @@ PackageInfo::sDefaultIcon(new(std::nothrow) SharedBitmap(
PackageInfo::PackageInfo()
:
fIcon(sDefaultIcon),
fName(),
fTitle(),
fVersion(),
fPublisher(),
@ -480,7 +481,8 @@ PackageInfo::PackageInfo()
PackageInfo::PackageInfo(const BPackageInfo& info)
:
fIcon(sDefaultIcon),
fTitle(info.Name()),
fName(info.Name()),
fTitle(),
fVersion(info.Version()),
fPublisher(),
fShortDescription(info.Summary()),
@ -514,13 +516,14 @@ PackageInfo::PackageInfo(const BPackageInfo& info)
}
PackageInfo::PackageInfo(const BString& title,
PackageInfo::PackageInfo(const BString& name,
const BPackageVersion& version, const PublisherInfo& publisher,
const BString& shortDescription, const BString& fullDescription,
int32 flags, const char* architecture)
:
fIcon(sDefaultIcon),
fTitle(title),
fName(name),
fTitle(),
fVersion(version),
fPublisher(publisher),
fShortDescription(shortDescription),
@ -546,6 +549,7 @@ PackageInfo::PackageInfo(const BString& title,
PackageInfo::PackageInfo(const PackageInfo& other)
:
fIcon(other.fIcon),
fName(other.fName),
fTitle(other.fTitle),
fVersion(other.fVersion),
fPublisher(other.fPublisher),
@ -574,6 +578,7 @@ PackageInfo&
PackageInfo::operator=(const PackageInfo& other)
{
fIcon = other.fIcon;
fName = other.fName;
fTitle = other.fTitle;
fVersion = other.fVersion;
fPublisher = other.fPublisher;
@ -603,6 +608,7 @@ bool
PackageInfo::operator==(const PackageInfo& other) const
{
return fIcon == other.fIcon
&& fName == other.fName
&& fTitle == other.fTitle
&& fVersion == other.fVersion
&& fPublisher == other.fPublisher
@ -632,6 +638,23 @@ PackageInfo::operator!=(const PackageInfo& other) const
}
void
PackageInfo::SetTitle(const BString& title)
{
if (fTitle != title) {
fTitle = title;
_NotifyListeners(PKG_CHANGED_TITLE);
}
}
const BString&
PackageInfo::Title() const
{
return fTitle.Length() > 0 ? fTitle : fName;
}
void
PackageInfo::SetShortDescription(const BString& description)
{
@ -1005,9 +1028,9 @@ DepotInfo::SyncPackages(const PackageList& otherPackages)
bool found = false;
for (int32 j = packages.CountItems() - 1; j >= 0; j--) {
const PackageInfoRef& package = packages.ItemAtFast(j);
if (package->Title() == otherPackage->Title()) {
if (package->Name() == otherPackage->Name()) {
// printf("%s: found package: '%s'\n", fName.String(),
// package->Title().String());
// package->Name().String());
package->SetState(otherPackage->State());
package->SetLocalFilePath(otherPackage->LocalFilePath());
package->SetSystemDependency(
@ -1019,7 +1042,7 @@ DepotInfo::SyncPackages(const PackageList& otherPackages)
}
if (!found) {
printf("%s: new package: '%s'\n", fName.String(),
otherPackage->Title().String());
otherPackage->Name().String());
fPackages.Add(otherPackage);
}
}
@ -1027,7 +1050,7 @@ DepotInfo::SyncPackages(const PackageList& otherPackages)
for (int32 i = packages.CountItems() - 1; i >= 0; i--) {
const PackageInfoRef& package = packages.ItemAtFast(i);
printf("%s: removing package: '%s'\n", fName.String(),
package->Title().String());
package->Name().String());
fPackages.Remove(package);
}
}

View File

@ -241,7 +241,7 @@ public:
PackageInfo();
PackageInfo(const BPackageInfo& info);
PackageInfo(
const BString& title,
const BString& name,
const BPackageVersion& version,
const PublisherInfo& publisher,
const BString& shortDescription,
@ -254,8 +254,10 @@ public:
bool operator==(const PackageInfo& other) const;
bool operator!=(const PackageInfo& other) const;
const BString& Title() const
{ return fTitle; }
const BString& Name() const
{ return fName; }
void SetTitle(const BString& title);
const BString& Title() const;
const BPackageVersion& Version() const
{ return fVersion; }
void SetShortDescription(const BString& description);
@ -346,6 +348,7 @@ private:
private:
BitmapRef fIcon;
BString fName;
BString fTitle;
BPackageVersion fVersion;
PublisherInfo fPublisher;

View File

@ -10,15 +10,16 @@
enum {
PKG_CHANGED_SUMMARY = 1 << 0,
PKG_CHANGED_DESCRIPTION = 1 << 1,
PKG_CHANGED_RATINGS = 1 << 2,
PKG_CHANGED_SCREENSHOTS = 1 << 3,
PKG_CHANGED_STATE = 1 << 4,
PKG_CHANGED_ICON = 1 << 5,
PKG_CHANGED_CHANGELOG = 1 << 6,
PKG_CHANGED_CATEGORIES = 1 << 7,
PKG_CHANGED_PROMINENCE = 1 << 8
PKG_CHANGED_TITLE = 1 << 0,
PKG_CHANGED_SUMMARY = 1 << 1,
PKG_CHANGED_DESCRIPTION = 1 << 2,
PKG_CHANGED_RATINGS = 1 << 3,
PKG_CHANGED_SCREENSHOTS = 1 << 4,
PKG_CHANGED_STATE = 1 << 5,
PKG_CHANGED_ICON = 1 << 6,
PKG_CHANGED_CHANGELOG = 1 << 7,
PKG_CHANGED_CATEGORIES = 1 << 8,
PKG_CHANGED_PROMINENCE = 1 << 9
// ...
};

View File

@ -134,7 +134,7 @@ public:
if (ref->IsLocalFile())
packageName = ref->LocalFilePath();
else
packageName = ref->Title();
packageName = ref->Name();
const char* packageNameString = packageName.String();
try {
@ -242,7 +242,7 @@ public:
PackageInfoRef ref(Package());
fPackageManager->SetCurrentActionPackage(ref, false);
fPackageManager->AddProgressListener(this);
const char* packageName = ref->Title().String();
const char* packageName = ref->Name().String();
try {
fPackageManager->Uninstall(&packageName, 1);
} catch (BFatalErrorException ex) {
@ -813,12 +813,11 @@ PackageManager::_GetSolverPackage(PackageInfoRef package)
flags |= BSolver::B_FIND_INSTALLED_ONLY;
BObjectList<BSolverPackage> packages;
status_t result = Solver()->FindPackages(package->Title(),
flags, packages);
status_t result = Solver()->FindPackages(package->Name(), flags, packages);
if (result == B_OK) {
for (int32 i = 0; i < packages.CountItems(); i++) {
BSolverPackage* solverPackage = packages.ItemAt(i);
if (solverPackage->Name() != package->Title())
if (solverPackage->Name() != package->Name())
continue;
else if (package->State() == NONE
&& dynamic_cast<BPackageManager::RemoteRepository*>(

View File

@ -141,7 +141,7 @@ public:
if (bounds.Contains(where) && Window()->IsActive()) {
BMessage message(MSG_PACKAGE_SELECTED);
message.AddString("title", PackageTitle());
message.AddString("name", PackageName());
Window()->PostMessage(&message);
}
}
@ -214,6 +214,14 @@ public:
return fTitleView->Text();
}
const char* PackageName() const
{
if (fPackageListener->Package().Get() != NULL)
return fPackageListener->Package()->Name();
else
return "";
}
void SetSelected(bool selected)
{
if (fSelected == selected)
@ -264,6 +272,7 @@ private:
bool fSelected;
BString fPackageName;
};
@ -310,12 +319,13 @@ FeaturedPackagesView::AddPackage(const PackageInfoRef& package)
if (view == NULL)
break;
BString title = view->PackageTitle();
if (title == package->Title()) {
BString name = view->PackageName();
if (name == package->Name()) {
// Don't add packages more than once
return;
}
BString title = view->PackageTitle();
if (title.Compare(package->Title()) < 0)
index++;
}
@ -336,8 +346,8 @@ FeaturedPackagesView::RemovePackage(const PackageInfoRef& package)
if (view == NULL)
break;
BString title = view->PackageTitle();
if (title == package->Title()) {
BString name = view->PackageName();
if (name == package->Name()) {
view->RemoveSelf();
delete view;
break;
@ -363,17 +373,17 @@ FeaturedPackagesView::Clear()
void
FeaturedPackagesView::SelectPackage(const PackageInfoRef& package)
{
BString selectedTitle;
BString selectedName;
if (package.Get() != NULL)
selectedTitle = package->Title();
selectedName = package->Name();
for (int32 i = 0; BLayoutItem* item = fPackageListLayout->ItemAt(i); i++) {
PackageView* view = dynamic_cast<PackageView*>(item->View());
if (view == NULL)
break;
BString title = view->PackageTitle();
view->SetSelected(title == selectedTitle);
BString name = view->PackageName();
view->SetSelected(name == selectedName);
}
}

View File

@ -380,14 +380,14 @@ MainWindow::MessageReceived(BMessage* message)
case MSG_PACKAGE_SELECTED:
{
BString title;
if (message->FindString("title", &title) == B_OK) {
BString name;
if (message->FindString("name", &name) == B_OK) {
BAutolock locker(fModel.Lock());
int count = fVisiblePackages.CountItems();
for (int i = 0; i < count; i++) {
const PackageInfoRef& package
= fVisiblePackages.ItemAtFast(i);
if (package.Get() != NULL && package->Title() == title) {
if (package.Get() != NULL && package->Name() == name) {
locker.Unlock();
_AdoptPackage(package);
break;
@ -864,7 +864,7 @@ MainWindow::_RefreshPackageList(bool force)
if (dynamic_cast<BPackageManager::RemoteRepository*>(repository)
!= NULL) {
depots[repository->Name()].AddPackage(modelInfo);
remotePackages[modelInfo->Title()] = modelInfo;
remotePackages[modelInfo->Name()] = modelInfo;
} else {
if (repository == static_cast<const BSolverRepository*>(
manager.SystemRepository())) {

View File

@ -39,7 +39,7 @@ MessagePackageListener::PackageChanged(const PackageInfoEvent& event)
return;
BMessage message(MSG_UPDATE_PACKAGE);
message.AddString("title", event.Package()->Title());
message.AddString("name", event.Package()->Name());
message.AddUInt32("changes", event.Changes());
messenger.SendMessage(&message);

View File

@ -287,7 +287,7 @@ PackageContentsView::SetPackage(const PackageInfoRef& package)
return;
// printf("PackageContentsView::SetPackage(%s)\n",
// package.Get() != NULL ? package->Title().String() : "NULL");
// package.Get() != NULL ? package->Name().String() : "NULL");
Clear();

View File

@ -621,7 +621,7 @@ private:
if (result != B_OK) {
fprintf(stderr, "Failed to schedule action: "
"%s '%s': %s\n", action->Label(),
action->Package()->Title().String(),
action->Package()->Name().String(),
strerror(result));
BString message(B_TRANSLATE("The package action "
"could not be scheduled: %Error%"));
@ -1397,25 +1397,27 @@ PackageInfoView::MessageReceived(BMessage* message)
if (fPackageListener->Package().Get() == NULL)
break;
BString title;
BString name;
uint32 changes;
if (message->FindString("title", &title) != B_OK
if (message->FindString("name", &name) != B_OK
|| message->FindUInt32("changes", &changes) != B_OK) {
break;
}
const PackageInfoRef& package = fPackageListener->Package();
if (package->Title() != title)
if (package->Name() != name)
break;
BAutolock _(fModelLock);
if ((changes & PKG_CHANGED_DESCRIPTION) != 0
if ((changes & PKG_CHANGED_SUMMARY) != 0
|| (changes & PKG_CHANGED_DESCRIPTION) != 0
|| (changes & PKG_CHANGED_SCREENSHOTS) != 0) {
fPagesView->SetPackage(package, false);
}
if ((changes & PKG_CHANGED_RATINGS) != 0) {
if ((changes & PKG_CHANGED_TITLE) != 0
|| (changes & PKG_CHANGED_RATINGS) != 0) {
fPagesView->SetPackage(package, false);
fTitleView->SetPackage(*package.Get());
}
@ -1449,7 +1451,7 @@ PackageInfoView::SetPackage(const PackageInfoRef& packageRef)
// don't switch to the default tab.
switchToDefaultTab = false;
} else if (fPackage.Get() != NULL && packageRef.Get() != NULL
&& fPackage->Title() == packageRef->Title()) {
&& fPackage->Name() == packageRef->Name()) {
// When asked to display a different PackageInfo instance,
// but it has the same package title as the already showing
// instance, this probably means there was a repository

View File

@ -163,7 +163,7 @@ public:
const PackageInfo& package = *event.Package().Get();
BMessage message(MSG_UPDATE_PACKAGE);
message.AddString("title", package.Title());
message.AddString("name", package.Name());
message.AddUInt32("changes", event.Changes());
messenger.SendMessage(&message);
@ -682,16 +682,18 @@ PackageListView::MessageReceived(BMessage* message)
switch (message->what) {
case MSG_UPDATE_PACKAGE:
{
BString title;
BString name;
uint32 changes;
if (message->FindString("title", &title) != B_OK
if (message->FindString("name", &name) != B_OK
|| message->FindUInt32("changes", &changes) != B_OK) {
break;
}
BAutolock _(fModelLock);
PackageRow* row = _FindRow(title);
PackageRow* row = _FindRow(name);
if (row != NULL) {
if ((changes & PKG_CHANGED_TITLE) != 0)
row->UpdateTitle();
if ((changes & PKG_CHANGED_SUMMARY) != 0)
row->UpdateSummary();
if ((changes & PKG_CHANGED_RATINGS) != 0)
@ -720,7 +722,7 @@ PackageListView::SelectionChanged()
PackageRow* selected = dynamic_cast<PackageRow*>(CurrentSelection());
if (selected != NULL)
message.AddString("title", selected->Package()->Title());
message.AddString("name", selected->Package()->Name());
Window()->PostMessage(&message);
}
@ -807,17 +809,17 @@ PackageListView::_FindRow(const PackageInfoRef& package, PackageRow* parent)
PackageRow*
PackageListView::_FindRow(const BString& packageTitle, PackageRow* parent)
PackageListView::_FindRow(const BString& packageName, PackageRow* parent)
{
for (int32 i = CountRows(parent) - 1; i >= 0; i--) {
PackageRow* row = dynamic_cast<PackageRow*>(RowAt(i, parent));
if (row != NULL && row->Package().Get() != NULL
&& row->Package()->Title() == packageTitle) {
&& row->Package()->Name() == packageName) {
return row;
}
if (CountRows(row) > 0) {
// recurse into child rows
row = _FindRow(packageTitle, row);
row = _FindRow(packageName, row);
if (row != NULL)
return row;
}

View File

@ -38,7 +38,7 @@ public:
private:
PackageRow* _FindRow(const PackageInfoRef& package,
PackageRow* parent = NULL);
PackageRow* _FindRow(const BString& packageTitle,
PackageRow* _FindRow(const BString& packageName,
PackageRow* parent = NULL);
private:

View File

@ -410,7 +410,7 @@ RatePackageWindow::_QueryRatingThread()
BMessage info;
status_t status = interface.RetrieveUserRating(
package->Title(), package->Version(), package->Architecture(),
package->Name(), package->Version(), package->Architecture(),
username, info);
// info.PrintToStream();
@ -489,7 +489,7 @@ RatePackageWindow::_SendRatingThread()
return;
}
BString package = fPackage->Title();
BString package = fPackage->Name();
BString architecture = fPackage->Architecture();
int rating = (int)fRating;
BString stability = fStability;