Skip to content

Commit

Permalink
HaikuDepot: Centralized user account features in the UI
Browse files Browse the repository at this point in the history
There is now a right-aligned second menu bar for the account management.
The menu label is what was previously shown underneath the search terms field.
The menu items have moved from the Tools menu into the new user menu. This
means the login/logout functionality is directly available where the login
info is shown in the UI when you click it.
  • Loading branch information
stippi committed Oct 25, 2014
1 parent 9303787 commit e0a26dc
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 48 deletions.
34 changes: 2 additions & 32 deletions src/apps/haikudepot/ui/FilterView.cpp
Expand Up @@ -15,10 +15,10 @@
#include <MenuItem.h>
#include <Messenger.h>
#include <PopUpMenu.h>
#include <StringView.h>
#include <TextControl.h>

#include "Model.h"
#include "support.h"


#undef B_TRANSLATION_CONTEXT
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
Expand All @@ -119,8 +104,7 @@ FilterView::FilterView()
.Add(fInstalledCheckBox)
.Add(fDevelopmentCheckBox)
.Add(fSourceCodeCheckBox)
.AddGlue(0.5f)
.Add(fUsername)
.AddGlue()
.End()

.SetInsets(B_USE_DEFAULT_SPACING)
Expand Down Expand Up @@ -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);
}

5 changes: 0 additions & 5 deletions src/apps/haikudepot/ui/FilterView.h
Expand Up @@ -10,7 +10,6 @@

class BCheckBox;
class BMenuField;
class BStringView;
class BTextControl;
class Model;

Expand All @@ -34,8 +33,6 @@ class FilterView : public BGroupView {
void AdoptModel(const Model& model);
void AdoptCheckmarks(const Model& model);

void SetUsername(const BString& username);

private:
BMenuField* fShowField;
BMenuField* fRepositoryField;
Expand All @@ -45,8 +42,6 @@ class FilterView : public BGroupView {
BCheckBox* fInstalledCheckBox;
BCheckBox* fDevelopmentCheckBox;
BCheckBox* fSourceCodeCheckBox;

BStringView* fUsername;
};

#endif // FILTER_VIEW_H
62 changes: 54 additions & 8 deletions src/apps/haikudepot/ui/MainWindow.cpp
Expand Up @@ -45,6 +45,7 @@
#include "PackageListView.h"
#include "PackageManager.h"
#include "RatePackageWindow.h"
#include "support.h"
#include "UserLoginWindow.h"


Expand Down Expand Up @@ -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),
Expand All @@ -117,14 +121,23 @@ 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);

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)
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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"));
Expand All @@ -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()
{
Expand Down Expand Up @@ -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);
}
}


Expand Down
13 changes: 10 additions & 3 deletions src/apps/haikudepot/ui/MainWindow.h
Expand Up @@ -14,6 +14,8 @@
#include "PackageInfoListener.h"


class BMenu;
class BMenuItem;
class BSplitView;
class FilterView;
class PackageActionsView;
Expand Down Expand Up @@ -55,6 +57,8 @@ class MainWindow : public BWindow, private PackageInfoListener,

private:
void _BuildMenu(BMenuBar* menuBar);
void _BuildUserMenu(BMenuBar* menuBar);

void _InitWorkerThreads();
void _AdoptModel();

Expand All @@ -65,11 +69,8 @@ class MainWindow : public BWindow, private PackageInfoListener,
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,
Expand All @@ -85,7 +86,13 @@ class MainWindow : public BWindow, private PackageInfoListener,
PackageListView* fPackageListView;
PackageInfoView* fPackageInfoView;
BSplitView* fSplitView;

BMenu* fUserMenu;
BMenuItem* fLogInItem;
BMenuItem* fLogOutItem;

BMenuItem* fShowAvailablePackagesItem;
BMenuItem* fShowInstalledPackagesItem;
BMenuItem* fShowDevelopPackagesItem;
BMenuItem* fShowSourcePackagesItem;

Expand Down
15 changes: 15 additions & 0 deletions src/apps/haikudepot/ui_generic/support.cpp
Expand Up @@ -13,10 +13,12 @@
#include <Directory.h>
#include <File.h>
#include <FindDirectory.h>
#include <Font.h>
#include <Path.h>
#include <Resources.h>
#include <Roster.h>
#include <Screen.h>
#include <View.h>


status_t
Expand Down Expand Up @@ -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);
}




2 changes: 2 additions & 0 deletions src/apps/haikudepot/ui_generic/support.h
Expand Up @@ -11,6 +11,7 @@

class BMessage;
class BResources;
class BView;
class BWindow;


Expand All @@ -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

0 comments on commit e0a26dc

Please sign in to comment.