[haiku-commits] Change in haiku[master]: DataTranslations: sort by supertype before name

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 13 Jul 2020 13:44:06 +0000

From Adrien Destugues <pulkomandy@xxxxxxxxx>:

Adrien Destugues has uploaded this change for review. ( 
https://review.haiku-os.org/c/haiku/+/3030 ;)


Change subject: DataTranslations: sort by supertype before name
......................................................................

DataTranslations: sort by supertype before name

Fixes #9618 (which suggested using a tree view, but I think that's not
useful, just proper sorting of the items seems fine to me)

Comments welcome, as the French localization results in the same order
in either case (because it translates as "Images PNG", etc)
---
M src/preferences/datatranslations/TranslatorListView.cpp
1 file changed, 29 insertions(+), 4 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/30/3030/1

diff --git a/src/preferences/datatranslations/TranslatorListView.cpp 
b/src/preferences/datatranslations/TranslatorListView.cpp
index d7cf40a..1f6ebe3 100644
--- a/src/preferences/datatranslations/TranslatorListView.cpp
+++ b/src/preferences/datatranslations/TranslatorListView.cpp
@@ -14,15 +14,40 @@
 #include <string.h>

 #include <Application.h>
-
+#include <String.h>
+#include <TranslatorRoster.h>

 static int
 compare_items(const void* a, const void* b)
 {
-       const BStringItem* stringA = *(const BStringItem**)a;
-       const BStringItem* stringB = *(const BStringItem**)b;
+       const TranslatorItem* itemA = *(const TranslatorItem**)a;
+       const TranslatorItem* itemB = *(const TranslatorItem**)b;

-       return strcmp(stringA->Text(), stringB->Text());
+       // Get the first input MIME type
+       const translation_format* formatA;
+       const translation_format* formatB;
+       int32 numA;
+       int32 numB;
+
+       static BTranslatorRoster* roster = BTranslatorRoster::Default();
+       roster->GetInputFormats(itemA->ID(), &formatA, &numA);
+       roster->GetInputFormats(itemB->ID(), &formatB, &numB);
+
+       // Get the MIME supertype
+       BString typeA(formatA->MIME);
+       int32 slashA = typeA.FindFirst('/');
+       typeA.Truncate(slashA);
+
+       BString typeB(formatB->MIME);
+       int32 slashB = typeB.FindFirst('/');
+       typeB.Truncate(slashB);
+
+       // Compare by supertype, then by name
+       int typeDiff = typeA.Compare(typeB);
+       if (typeDiff != 0)
+               return typeDiff;
+
+       return strcmp(itemA->Text(), itemB->Text());
 }



--
To view, visit https://review.haiku-os.org/c/haiku/+/3030
To unsubscribe, or for help writing mail filters, visit 
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: Ie1298eec048f9cb42528b8420a91e807e8f00eab
Gerrit-Change-Number: 3030
Gerrit-PatchSet: 1
Gerrit-Owner: Adrien Destugues <pulkomandy@xxxxxxxxx>
Gerrit-MessageType: newchange

Other related posts:

  • » [haiku-commits] Change in haiku[master]: DataTranslations: sort by supertype before name - Gerrit