diff --git a/src/apps/haikudepot/ui/FilterView.cpp b/src/apps/haikudepot/ui/FilterView.cpp index ef52e08f21..11c2c1bb41 100644 --- a/src/apps/haikudepot/ui/FilterView.cpp +++ b/src/apps/haikudepot/ui/FilterView.cpp @@ -15,10 +15,10 @@ #include #include #include -#include #include #include "Model.h" +#include "support.h" #undef B_TRANSLATION_CONTEXT @@ -38,16 +38,6 @@ add_categories_to_menu(const CategoryList& categories, BMenu* menu) } -static void -set_small_font(BView* view) -{ - BFont font; - view->GetFont(&font); - font.SetSize(ceilf(font.Size() * 0.8)); - view->SetFont(&font); -} - - static BCheckBox* create_check_box(const char* label, const char* name) { @@ -98,11 +88,6 @@ FilterView::FilterView() fSourceCodeCheckBox = create_check_box( B_TRANSLATE("Source code"), "source code"); - // Logged in user label - fUsername = new BStringView("logged in user", ""); - set_small_font(fUsername); - fUsername->SetHighColor(80, 80, 80); - // Build layout BLayoutBuilder::Group<>(this) .AddGroup(B_HORIZONTAL) @@ -119,8 +104,7 @@ FilterView::FilterView() .Add(fInstalledCheckBox) .Add(fDevelopmentCheckBox) .Add(fSourceCodeCheckBox) - .AddGlue(0.5f) - .Add(fUsername) + .AddGlue() .End() .SetInsets(B_USE_DEFAULT_SPACING) @@ -214,17 +198,3 @@ FilterView::AdoptCheckmarks(const Model& model) fSourceCodeCheckBox->SetValue(model.ShowSourcePackages()); } - -void -FilterView::SetUsername(const BString& username) -{ - BString label; - if (username.Length() == 0) { - label = B_TRANSLATE("Not logged in"); - } else { - label = B_TRANSLATE("Logged in as %User%"); - label.ReplaceAll("%User%", username); - } - fUsername->SetText(label); -} - diff --git a/src/apps/haikudepot/ui/FilterView.h b/src/apps/haikudepot/ui/FilterView.h index 81e6a6bae7..056d889b55 100644 --- a/src/apps/haikudepot/ui/FilterView.h +++ b/src/apps/haikudepot/ui/FilterView.h @@ -10,7 +10,6 @@ class BCheckBox; class BMenuField; -class BStringView; class BTextControl; class Model; @@ -34,8 +33,6 @@ public: void AdoptModel(const Model& model); void AdoptCheckmarks(const Model& model); - void SetUsername(const BString& username); - private: BMenuField* fShowField; BMenuField* fRepositoryField; @@ -45,8 +42,6 @@ private: BCheckBox* fInstalledCheckBox; BCheckBox* fDevelopmentCheckBox; BCheckBox* fSourceCodeCheckBox; - - BStringView* fUsername; }; #endif // FILTER_VIEW_H diff --git a/src/apps/haikudepot/ui/MainWindow.cpp b/src/apps/haikudepot/ui/MainWindow.cpp index a997992f40..e1dddea2e7 100644 --- a/src/apps/haikudepot/ui/MainWindow.cpp +++ b/src/apps/haikudepot/ui/MainWindow.cpp @@ -45,6 +45,7 @@ #include "PackageListView.h" #include "PackageManager.h" #include "RatePackageWindow.h" +#include "support.h" #include "UserLoginWindow.h" @@ -109,6 +110,9 @@ MainWindow::MainWindow(BRect frame, const BMessage& settings) BWindow(frame, B_TRANSLATE_SYSTEM_NAME("HaikuDepot"), B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS), + fUserMenu(NULL), + fLogInItem(NULL), + fLogOutItem(NULL), fModelListener(new MessageModelListener(BMessenger(this)), true), fTerminating(false), fSinglePackageMode(false), @@ -117,6 +121,12 @@ MainWindow::MainWindow(BRect frame, const BMessage& settings) BMenuBar* menuBar = new BMenuBar(B_TRANSLATE("Main Menu")); _BuildMenu(menuBar); + BMenuBar* userMenuBar = new BMenuBar(B_TRANSLATE("User Menu")); + _BuildUserMenu(userMenuBar); + set_small_font(userMenuBar); + userMenuBar->SetExplicitMaxSize(BSize(B_SIZE_UNSET, + menuBar->MaxSize().height)); + fFilterView = new FilterView(); fPackageListView = new PackageListView(fModel.Lock()); fPackageInfoView = new PackageInfoView(fModel.Lock(), this); @@ -124,7 +134,10 @@ MainWindow::MainWindow(BRect frame, const BMessage& settings) fSplitView = new BSplitView(B_VERTICAL, 5.0f); BLayoutBuilder::Group<>(this, B_VERTICAL, 0.0f) - .Add(menuBar) + .AddGroup(B_HORIZONTAL, 0.0f) + .Add(menuBar, 1.0f) + .Add(userMenuBar, 0.0f) + .End() .Add(fFilterView) .AddSplit(fSplitView) .AddGroup(B_VERTICAL) @@ -175,6 +188,8 @@ MainWindow::MainWindow(BRect frame, const BMessage& settings, BWindow(frame, B_TRANSLATE_SYSTEM_NAME("HaikuDepot"), B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS), + fUserMenu(NULL), + fLogInItem(NULL), fLogOutItem(NULL), fModelListener(new MessageModelListener(BMessenger(this)), true), fTerminating(false), @@ -463,11 +478,7 @@ MainWindow::_BuildMenu(BMenuBar* menuBar) menu->AddItem(new BMenuItem(B_TRANSLATE("Refresh depots"), new BMessage(MSG_REFRESH_DEPOTS))); menu->AddSeparatorItem(); - menu->AddItem(new BMenuItem(B_TRANSLATE("Log in" B_UTF8_ELLIPSIS), - new BMessage(MSG_LOG_IN))); - fLogOutItem = new BMenuItem(B_TRANSLATE("Log out"), - new BMessage(MSG_LOG_OUT)); - menu->AddItem(fLogOutItem); + menuBar->AddItem(menu); // menu = new BMenu(B_TRANSLATE("Options")); @@ -485,6 +496,23 @@ MainWindow::_BuildMenu(BMenuBar* menuBar) } +void +MainWindow::_BuildUserMenu(BMenuBar* menuBar) +{ + fUserMenu = new BMenu(B_TRANSLATE("Not logged in")); + + fLogInItem = new BMenuItem(B_TRANSLATE("Log in" B_UTF8_ELLIPSIS), + new BMessage(MSG_LOG_IN)); + fUserMenu->AddItem(fLogInItem); + + fLogOutItem = new BMenuItem(B_TRANSLATE("Log out"), + new BMessage(MSG_LOG_OUT)); + fUserMenu->AddItem(fLogOutItem); + + menuBar->AddItem(fUserMenu); +} + + void MainWindow::_InitWorkerThreads() { @@ -939,9 +967,27 @@ void MainWindow::_UpdateAuthorization() { BString username(fModel.Username()); + bool hasUser = !username.IsEmpty(); + if (fLogOutItem != NULL) - fLogOutItem->SetEnabled(username.Length() > 0); - fFilterView->SetUsername(username); + fLogOutItem->SetEnabled(hasUser); + if (fLogInItem != NULL) { + if (hasUser) + fLogInItem->SetLabel(B_TRANSLATE("Switch account" B_UTF8_ELLIPSIS)); + else + fLogInItem->SetLabel(B_TRANSLATE("Log in" B_UTF8_ELLIPSIS)); + } + + if (fUserMenu != NULL) { + BString label; + if (username.Length() == 0) { + label = B_TRANSLATE("Not logged in"); + } else { + label = B_TRANSLATE("Logged in as %User%"); + label.ReplaceAll("%User%", username); + } + fUserMenu->Superitem()->SetLabel(label); + } } diff --git a/src/apps/haikudepot/ui/MainWindow.h b/src/apps/haikudepot/ui/MainWindow.h index 18a494dc64..9805fe6165 100644 --- a/src/apps/haikudepot/ui/MainWindow.h +++ b/src/apps/haikudepot/ui/MainWindow.h @@ -14,6 +14,8 @@ #include "PackageInfoListener.h" +class BMenu; +class BMenuItem; class BSplitView; class FilterView; class PackageActionsView; @@ -55,6 +57,8 @@ private: private: void _BuildMenu(BMenuBar* menuBar); + void _BuildUserMenu(BMenuBar* menuBar); + void _InitWorkerThreads(); void _AdoptModel(); @@ -65,11 +69,8 @@ private: void _RefreshPackageList(); void _StartRefreshWorker(bool force = false); - static status_t _RefreshModelThreadWorker(void* arg); - static status_t _PackageActionWorker(void* arg); - static status_t _PopulatePackageWorker(void* arg); void _NotifyUser(const char* title, @@ -85,7 +86,13 @@ private: PackageListView* fPackageListView; PackageInfoView* fPackageInfoView; BSplitView* fSplitView; + + BMenu* fUserMenu; + BMenuItem* fLogInItem; BMenuItem* fLogOutItem; + + BMenuItem* fShowAvailablePackagesItem; + BMenuItem* fShowInstalledPackagesItem; BMenuItem* fShowDevelopPackagesItem; BMenuItem* fShowSourcePackagesItem; diff --git a/src/apps/haikudepot/ui_generic/support.cpp b/src/apps/haikudepot/ui_generic/support.cpp index 9287cd8696..d508769d00 100644 --- a/src/apps/haikudepot/ui_generic/support.cpp +++ b/src/apps/haikudepot/ui_generic/support.cpp @@ -13,10 +13,12 @@ #include #include #include +#include #include #include #include #include +#include status_t @@ -145,3 +147,16 @@ get_app_resources(BResources& resources) return resources.SetTo(&info.ref); } + +void +set_small_font(BView* view) +{ + BFont font; + view->GetFont(&font); + font.SetSize(ceilf(font.Size() * 0.8)); + view->SetFont(&font); +} + + + + diff --git a/src/apps/haikudepot/ui_generic/support.h b/src/apps/haikudepot/ui_generic/support.h index 1f45eb3019..31ec2c4108 100644 --- a/src/apps/haikudepot/ui_generic/support.h +++ b/src/apps/haikudepot/ui_generic/support.h @@ -11,6 +11,7 @@ class BMessage; class BResources; +class BView; class BWindow; @@ -25,5 +26,6 @@ bool make_sure_frame_is_on_screen(BRect& frame, float borderWidth = 5.0f, status_t get_app_resources(BResources& resources); +void set_small_font(BView* view); #endif // SUPPORT_H