Topbar: Implement Auth menu

This commit is contained in:
YuSanka 2023-12-11 11:20:29 +01:00 committed by David Kocik
parent 78c9aa668c
commit 55ba9f2351
9 changed files with 130 additions and 33 deletions

18
resources/icons/login.svg Normal file
View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg height="800px" width="800px" version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 499.1 499.1" xml:space="preserve">
<g>
<g>
<g>
<path fill="#ED6B21" d="M0,249.6c0,9.5,7.7,17.2,17.2,17.2h327.6l-63.9,63.8c-6.7,6.7-6.7,17.6,0,24.3c3.3,3.3,7.7,5,12.1,5s8.8-1.7,12.1-5
l93.1-93.1c6.7-6.7,6.7-17.6,0-24.3l-93.1-93.1c-6.7-6.7-17.6-6.7-24.3,0c-6.7,6.7-6.7,17.6,0,24.3l63.8,63.8H17.2
C7.7,232.5,0,240.1,0,249.6z"/>
<path fill="#808080" d="M396.4,494.2c56.7,0,102.7-46.1,102.7-102.8V107.7C499.1,51,453,4.9,396.4,4.9H112.7C56,4.9,10,51,10,107.7V166
c0,9.5,7.7,17.1,17.1,17.1c9.5,0,17.2-7.7,17.2-17.1v-58.3c0-37.7,30.7-68.5,68.4-68.5h283.7c37.7,0,68.4,30.7,68.4,68.5v283.7
c0,37.7-30.7,68.5-68.4,68.5H112.7c-37.7,0-68.4-30.7-68.4-68.5v-57.6c0-9.5-7.7-17.2-17.2-17.2S10,324.3,10,333.8v57.6
c0,56.7,46.1,102.8,102.7,102.8H396.4L396.4,494.2z"/>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg height="800px" width="800px" version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 490.3 490.3" xml:space="preserve">
<g>
<g>
<path fill="#808080" d="M0,121.05v248.2c0,34.2,27.9,62.1,62.1,62.1h200.6c34.2,0,62.1-27.9,62.1-62.1v-40.2c0-6.8-5.5-12.3-12.3-12.3
s-12.3,5.5-12.3,12.3v40.2c0,20.7-16.9,37.6-37.6,37.6H62.1c-20.7,0-37.6-16.9-37.6-37.6v-248.2c0-20.7,16.9-37.6,37.6-37.6h200.6
c20.7,0,37.6,16.9,37.6,37.6v40.2c0,6.8,5.5,12.3,12.3,12.3s12.3-5.5,12.3-12.3v-40.2c0-34.2-27.9-62.1-62.1-62.1H62.1
C27.9,58.95,0,86.75,0,121.05z"/>
<path fill="#ED6B21" d="M385.4,337.65c2.4,2.4,5.5,3.6,8.7,3.6s6.3-1.2,8.7-3.6l83.9-83.9c4.8-4.8,4.8-12.5,0-17.3l-83.9-83.9
c-4.8-4.8-12.5-4.8-17.3,0s-4.8,12.5,0,17.3l63,63H218.6c-6.8,0-12.3,5.5-12.3,12.3c0,6.8,5.5,12.3,12.3,12.3h229.8l-63,63
C380.6,325.15,380.6,332.95,385.4,337.65z"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

18
resources/icons/user.svg Normal file
View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Written by Treer (gitlab.com/Treer) -->
<svg
version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="600"
height="600"
stroke="grey"
stroke-width="30"
fill="none">
<title>Abstract user icon</title>
<circle cx="300" cy="300" r="265" />
<circle cx="300" cy="230" r="115" />
<path d="M106.81863443903,481.4 a205,205 1 0,1 386.36273112194,0" stroke-linecap="butt" />
</svg>

After

Width:  |  Height:  |  Size: 497 B

View File

@ -2498,11 +2498,6 @@ wxMenu* GUI_App::get_config_menu()
local_menu->Append(config_id_base + ConfigMenuUpdateConf, _L("Check for Configuration Updates"), _L("Check for configuration updates"));
local_menu->Append(config_id_base + ConfigMenuUpdateApp, _L("Check for Application Updates"), _L("Check for new version of application"));
local_menu->AppendSeparator();
wxMenuItem* updatable_item = local_menu->Append(config_id_base + ConfigMenuAuthLogin, _L("PrusaAuth Log in"), _L(""));
m_config_menu_updatable_items.emplace(ConfigMenuIDs::ConfigMenuAuthLogin, updatable_item);
updatable_item = local_menu->Append(config_id_base + ConfigMenuConnectDummy, _L("PrusaConnect Printers"), _L(""));
updatable_item->Enable(false);
m_config_menu_updatable_items.emplace(ConfigMenuIDs::ConfigMenuConnectDummy, updatable_item);
local_menu->Append(config_id_base + ConfigMenuConnectDialog, _L("Connect Dialog"), _L("Connect Dialog"));
local_menu->Append(config_id_base + ConfigMenuMediaDialog, _L("Media Dialog"), _L("Media Dialog"));
#if defined(__linux__) && defined(SLIC3R_DESKTOP_INTEGRATION)
@ -2540,19 +2535,6 @@ wxMenu* GUI_App::get_config_menu()
case ConfigMenuUpdateApp:
app_version_check(true);
break;
case ConfigMenuAuthLogin:
{
if (this->plater()->get_user_account()->is_logged())
this->plater()->get_user_account()->do_logout();
else
this->plater()->get_user_account()->do_login();
}
break;
case ConfigMenuConnectDummy:
{
this->plater()->get_user_account()->enqueue_connect_printers_action();
}
break;
#ifdef __linux__
case ConfigMenuDesktopIntegration:
show_desktop_integration_dialog();
@ -2666,11 +2648,7 @@ wxMenu* GUI_App::get_config_menu()
return local_menu;
}
void GUI_App::update_config_menu()
{
m_config_menu_updatable_items[ConfigMenuIDs::ConfigMenuAuthLogin]->SetItemLabel(this->plater()->get_user_account()->is_logged() ? _L("PrusaAuth Log out") : _L("PrusaAuth Log in"));
m_config_menu_updatable_items[ConfigMenuIDs::ConfigMenuConnectDummy]->Enable(this->plater()->get_user_account()->is_logged());
}
void GUI_App::open_preferences(const std::string& highlight_option /*= std::string()*/, const std::string& tab_name/*= std::string()*/)
{
mainframe->preferences_dialog->show(highlight_option, tab_name);

View File

@ -99,8 +99,6 @@ enum ConfigMenuIDs {
ConfigMenuUpdateConf,
ConfigMenuUpdateApp,
ConfigMenuMediaDialog,
ConfigMenuAuthLogin,
ConfigMenuConnectDummy,
ConfigMenuConnectDialog,
ConfigMenuDesktopIntegration,
ConfigMenuPreferences,
@ -299,7 +297,6 @@ public:
void update_mode();
wxMenu* get_config_menu();
void update_config_menu();
bool has_unsaved_preset_changes() const;
bool has_current_preset_changes() const;
void update_saved_preset_from_current_preset();

View File

@ -836,10 +836,10 @@ void MainFrame::create_preset_tabs()
add_created_tab(new TabPrinter(m_tabpanel), wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() == ptFFF ? "printer" : "sla_printer");
m_webview = new WebViewPanel(m_tabpanel);
m_tabpanel->AddPage(m_webview, "PrusaConnect");
dynamic_cast<TopBar*>(m_tabpanel)->AddPage(m_webview, "PrusaConnect", "");
/*
m_media = new MediaMainPanel(this);
m_tabpanel->AddPage(m_media, "Media");
dynamic_cast<TopBar*>(m_tabpanel)->AddPage(m_media, "Media");
*/
}

View File

@ -887,7 +887,6 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
std::string text = _u8L("Logged out.");
this->notification_manager->close_notification_of_type(NotificationType::PrusaAuthUserID);
this->notification_manager->push_notification(NotificationType::PrusaAuthUserID, NotificationManager::NotificationLevel::ImportantNotificationLevel, text);
wxGetApp().update_config_menu();
});
this->q->Bind(EVT_PA_ID_USER_SUCCESS, [this](PrusaAuthSuccessEvent& evt) {
@ -897,7 +896,6 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
std::string text = format(_u8L("Logged as %1%."), username);
this->notification_manager->close_notification_of_type(NotificationType::PrusaAuthUserID);
this->notification_manager->push_notification(NotificationType::PrusaAuthUserID, NotificationManager::NotificationLevel::ImportantNotificationLevel, text);
wxGetApp().update_config_menu();
} else {
// TODO
}

View File

@ -2,6 +2,7 @@
#include "GUI_App.hpp"
#include "Plater.hpp"
#include "UserAccount.hpp"
//#include "wxExtensions.hpp"
#include "format.hpp"
#include "I18N.hpp"
@ -27,6 +28,10 @@ TopBarItemsCtrl::Button::Button(wxWindow* parent, const wxString& label, const s
wxSize size = GetTextExtent(label) + wxSize(6 * btn_margin, int(1.5 * btn_margin));
if (icon_name.empty())
this->SetMinSize(size);
if (label.IsEmpty()) {
const int btn_side = px_cnt + btn_margin;
this->SetMinSize(wxSize(btn_side, btn_side));
}
else
this->SetMinSize(wxSize(-1, size.y));
}
@ -62,6 +67,11 @@ TopBarItemsCtrl::ButtonWithPopup::ButtonWithPopup(wxWindow* parent, const wxStri
this->SetLabel(label);
}
TopBarItemsCtrl::ButtonWithPopup::ButtonWithPopup(wxWindow* parent, const std::string& icon_name, int icon_width/* = 20*/, int icon_height/* = 20*/)
:TopBarItemsCtrl::Button(parent, "", icon_name, icon_width)
{
}
void TopBarItemsCtrl::ButtonWithPopup::SetLabel(const wxString& label)
{
wxString full_label = " " + label + " " + down_arrow;
@ -97,6 +107,42 @@ void TopBarItemsCtrl::ApplyWorkspacesMenu()
}
}
void TopBarItemsCtrl::CreateAuthMenu()
{
m_user_menu_item = append_menu_item(&m_auth_menu, wxID_ANY, "", "",
[this](wxCommandEvent& e) {
m_auth_btn->set_selected(true);
wxGetApp().plater()->PopupMenu(&m_auth_menu, m_auth_btn->GetPosition());
}, get_bmp_bundle("user", 16), nullptr, []() { return true; }, this);
m_auth_menu.AppendSeparator();
m_connect_dummy_menu_item = append_menu_item(&m_auth_menu, wxID_ANY, _L("PrusaConnect Printers"), "",
[this](wxCommandEvent&) { wxGetApp().plater()->get_user_account()->enqueue_connect_printers_action(); },
"", nullptr, []() { return wxGetApp().plater()->get_user_account()->is_logged(); }, this->GetParent());
m_login_menu_item = append_menu_item(&m_auth_menu, wxID_ANY, "", "",
[this](wxCommandEvent&) {
auto user_account = wxGetApp().plater()->get_user_account();
if (user_account->is_logged())
user_account->do_logout();
else
user_account->do_login();
}, get_bmp_bundle("login", 16), nullptr, []() { return true; }, this);
}
void TopBarItemsCtrl::UpdateAuthMenu()
{
auto user_account = wxGetApp().plater()->get_user_account();
if (m_login_menu_item) {
m_login_menu_item->SetItemLabel(user_account->is_logged() ? _L("PrusaAuth Log out") : _L("PrusaAuth Log in"));
m_login_menu_item->SetBitmap(user_account->is_logged() ? *get_bmp_bundle("logout", 16) : *get_bmp_bundle("login", 16));
}
if (m_user_menu_item)
m_user_menu_item->SetItemLabel(user_account->is_logged() ? from_u8(user_account->get_username()) : _L("Anonymus"));
}
TopBarItemsCtrl::TopBarItemsCtrl(wxWindow *parent) :
wxControl(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE | wxTAB_TRAVERSAL)
{
@ -134,7 +180,7 @@ TopBarItemsCtrl::TopBarItemsCtrl(wxWindow *parent) :
m_workspace_btn = new ButtonWithPopup(this, _L("Workspace"), "mode_simple");
m_sizer->AddStretchSpacer(20);
m_sizer->Add(m_workspace_btn, 1, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxRIGHT, 2 * m_btn_margin);
m_sizer->Add(m_workspace_btn, 1, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT);
m_workspace_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent& event) {
m_workspace_btn->set_selected(true);
@ -143,6 +189,20 @@ TopBarItemsCtrl::TopBarItemsCtrl(wxWindow *parent) :
});
m_workspaces_menu.Bind(wxEVT_MENU_CLOSE, [this](wxMenuEvent&) { m_workspace_btn->set_selected(false); });
// create Auth menu
CreateAuthMenu();
m_auth_btn = new ButtonWithPopup(this, "user", 35);
m_sizer->Add(m_auth_btn, 1, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxRIGHT | wxLEFT, m_btn_margin);
m_auth_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent& event) {
UpdateAuthMenu();
m_auth_btn->set_selected(true);
wxPoint pos = m_auth_btn->GetPosition();
wxGetApp().plater()->PopupMenu(&m_auth_menu, pos);
});
m_auth_menu.Bind(wxEVT_MENU_CLOSE, [this](wxMenuEvent&) { m_auth_btn->set_selected(false); });
this->Bind(wxEVT_PAINT, &TopBarItemsCtrl::OnPaint, this);
}

View File

@ -36,14 +36,23 @@ class TopBarItemsCtrl : public wxControl
ButtonWithPopup(wxWindow* parent,
const wxString& label,
const std::string& icon_name = "");
ButtonWithPopup(wxWindow* parent,
const std::string& icon_name,
int icon_width = 20,
int icon_height = 20);
~ButtonWithPopup() {}
void SetLabel(const wxString& label) override;
};
wxMenu m_main_menu;
wxMenu m_workspaces_menu;
wxMenu m_main_menu;
wxMenu m_workspaces_menu;
wxMenu m_auth_menu;
wxMenuItem* m_user_menu_item{ nullptr };
wxMenuItem* m_login_menu_item{ nullptr };
wxMenuItem* m_connect_dummy_menu_item{ nullptr };
public:
TopBarItemsCtrl(wxWindow* parent);
@ -64,6 +73,8 @@ public:
void AppendMenuItem(wxMenu* menu, const wxString& title);
void AppendMenuSeparaorItem();
void ApplyWorkspacesMenu();
void CreateAuthMenu();
void UpdateAuthMenu();
private:
wxWindow* m_parent;
@ -71,6 +82,7 @@ private:
wxBoxSizer* m_sizer;
ButtonWithPopup* m_menu_btn {nullptr};
ButtonWithPopup* m_workspace_btn {nullptr};
ButtonWithPopup* m_auth_btn {nullptr};
std::vector<Button*> m_pageButtons;
int m_selection {-1};
int m_btn_margin;