From 2e746a975a9d4cd8218b78206bdc24ad754c9fe8 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Fri, 6 Aug 2021 12:21:17 -0500 Subject: [PATCH] Split account preferences into dedicated window Found in the new "Accounts" menubar option. --- application/AppMessages.h | 3 ++ application/Makefile | 2 +- .../AccountsWindow.cpp} | 39 ++++++++----------- .../AccountsWindow.h} | 14 +++---- application/windows/MainWindow.cpp | 15 +++++++ application/windows/PreferencesWindow.cpp | 2 - 6 files changed, 43 insertions(+), 32 deletions(-) rename application/{preferences/PreferencesAccounts.cpp => windows/AccountsWindow.cpp} (91%) rename application/{preferences/PreferencesAccounts.h => windows/AccountsWindow.h} (74%) diff --git a/application/AppMessages.h b/application/AppMessages.h index 47ff093..fce3ee3 100644 --- a/application/AppMessages.h +++ b/application/AppMessages.h @@ -8,6 +8,9 @@ //! Show settings window const uint32 APP_SHOW_SETTINGS = 'RPST'; +//! Show accounts window +const uint32 APP_SHOW_ACCOUNTS = 'RPac'; + //! Chat messages const uint32 APP_CHAT = 'CYch'; diff --git a/application/Makefile b/application/Makefile index 6b06179..58e6f7b 100644 --- a/application/Makefile +++ b/application/Makefile @@ -52,7 +52,6 @@ SRCS = \ application/preferences/AccountListItem.cpp \ application/preferences/AppPreferences.cpp \ application/preferences/PreferencesChatWindow.cpp \ - application/preferences/PreferencesAccounts.cpp \ application/preferences/PreferencesBehavior.cpp \ application/preferences/PreferencesReplicant.cpp \ application/views/AccountsMenu.cpp \ @@ -76,6 +75,7 @@ SRCS = \ application/views/UserListView.cpp \ application/views/UserPopUp.cpp \ application/windows/AboutWindow.cpp \ + application/windows/AccountsWindow.cpp \ application/windows/ConversationInfoWindow.cpp \ application/windows/MainWindow.cpp \ application/windows/PreferencesWindow.cpp \ diff --git a/application/preferences/PreferencesAccounts.cpp b/application/windows/AccountsWindow.cpp similarity index 91% rename from application/preferences/PreferencesAccounts.cpp rename to application/windows/AccountsWindow.cpp index ac4634e..2067838 100644 --- a/application/preferences/PreferencesAccounts.cpp +++ b/application/windows/AccountsWindow.cpp @@ -8,6 +8,8 @@ * Jaidyn Levesque, jadedctrl@teknik.io */ +#include "AccountsWindow.h" + #include #include #include @@ -23,7 +25,6 @@ #include "AccountListItem.h" #include "ChatProtocol.h" #include "ChatProtocolMessages.h" -#include "PreferencesAccounts.h" #include "ProtocolManager.h" #include "ProtocolSettings.h" #include "MainWindow.h" @@ -32,7 +33,7 @@ #undef B_TRANSLATION_CONTEXT -#define B_TRANSLATION_CONTEXT "PreferencesAccounts" +#define B_TRANSLATION_CONTEXT "AccountsWindow" const uint32 kAddAccount = 'adac'; @@ -52,12 +53,16 @@ compare_by_name(const void* _item1, const void* _item2) } -PreferencesAccounts::PreferencesAccounts() - : BView("Accounts", B_WILL_DRAW) +AccountsWindow::AccountsWindow() + : + BWindow(BRect(200, 200, 300, 400), + B_TRANSLATE("Accounts"), B_TITLED_WINDOW, + B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS) { fListView = new BListView("accountsListView"); fListView->SetInvocationMessage(new BMessage(kEditAccount)); fListView->SetSelectionMessage(new BMessage(kSelect)); + fListView->SetExplicitMinSize(BSize(B_SIZE_UNSET, BFont().Size() * 20)); BScrollView* scrollView = new BScrollView("scrollView", fListView, B_WILL_DRAW, false, true); @@ -80,6 +85,7 @@ PreferencesAccounts::PreferencesAccounts() addOn->ProtoFriendlySignature(), msg, addOn->ProtoIcon()); fProtosMenu->AddItem(item); } + fProtosMenu->SetTargetForItems(this); MenuButton* proto = new MenuButton("addButton", B_TRANSLATE("Add"), NULL); proto->SetMenu(fProtosMenu); @@ -94,9 +100,9 @@ PreferencesAccounts::PreferencesAccounts() fToggleButton->SetEnabled(false); BLayoutBuilder::Group<>(this, B_VERTICAL) + .SetInsets(B_USE_DEFAULT_SPACING) .Add(scrollView) .AddGroup(B_HORIZONTAL) - .SetInsets(B_USE_HALF_ITEM_SPACING) .Add(proto) .Add(fDelButton) .AddGlue() @@ -108,18 +114,7 @@ PreferencesAccounts::PreferencesAccounts() void -PreferencesAccounts::AttachedToWindow() -{ - fListView->SetTarget(this); - fProtosMenu->SetTargetForItems(this); - fDelButton->SetTarget(this); - fEditButton->SetTarget(this); - fToggleButton->SetTarget(this); -} - - -void -PreferencesAccounts::MessageReceived(BMessage* msg) +AccountsWindow::MessageReceived(BMessage* msg) { switch (msg->what) { case kSelect: { @@ -254,13 +249,13 @@ PreferencesAccounts::MessageReceived(BMessage* msg) break; } default: - BView::MessageReceived(msg); + BWindow::MessageReceived(msg); } } void -PreferencesAccounts::_LoadListView(ProtocolSettings* settings) +AccountsWindow::_LoadListView(ProtocolSettings* settings) { if (!settings) return; @@ -278,7 +273,7 @@ PreferencesAccounts::_LoadListView(ProtocolSettings* settings) void -PreferencesAccounts::_DisableAccount(const char* account, int64 instance) +AccountsWindow::_DisableAccount(const char* account, int64 instance) { BMessage* remove = new BMessage(IM_MESSAGE); remove->AddInt32("im_what", IM_PROTOCOL_DISABLE); @@ -291,7 +286,7 @@ PreferencesAccounts::_DisableAccount(const char* account, int64 instance) void -PreferencesAccounts::_EnableAccount(const char* account, +AccountsWindow::_EnableAccount(const char* account, ProtocolSettings* settings) { ProtocolManager::Get()->AddAccount(settings->AddOn(), account, @@ -300,7 +295,7 @@ PreferencesAccounts::_EnableAccount(const char* account, int64 -PreferencesAccounts::_AccountInstance(const char* account) +AccountsWindow::_AccountInstance(const char* account) { bool found = false; AccountInstances accs = diff --git a/application/preferences/PreferencesAccounts.h b/application/windows/AccountsWindow.h similarity index 74% rename from application/preferences/PreferencesAccounts.h rename to application/windows/AccountsWindow.h index 1c3be07..aef715f 100644 --- a/application/preferences/PreferencesAccounts.h +++ b/application/windows/AccountsWindow.h @@ -1,11 +1,12 @@ /* * Copyright 2009-2010, Pier Luigi Fiorini. All rights reserved. + * Copyright 2021, Jaidyn Levesque. All rights reserved. * Distributed under the terms of the MIT License. */ -#ifndef _PREFERENCES_ACCOUNTS_H -#define _PREFERENCES_ACCOUNTS_H +#ifndef _ACCOUNTS_WINDOW_H +#define _ACCOUNTS_WINDOW_H -#include +#include class BButton; class BListView; @@ -14,11 +15,10 @@ class BPopUpMenu; class ProtocolSettings; -class PreferencesAccounts : public BView { +class AccountsWindow : public BWindow { public: - PreferencesAccounts(); + AccountsWindow(); - virtual void AttachedToWindow(); virtual void MessageReceived(BMessage* msg); private: @@ -37,4 +37,4 @@ private: int64 _AccountInstance(const char* account); }; -#endif // _PREFERENCES_ACCOUNTS_H +#endif // _ACCOUNTS_WINDOW_H diff --git a/application/windows/MainWindow.cpp b/application/windows/MainWindow.cpp index b32eba1..91a289c 100644 --- a/application/windows/MainWindow.cpp +++ b/application/windows/MainWindow.cpp @@ -18,6 +18,7 @@ #include #include "AccountManager.h" +#include "AccountsWindow.h" #include "AppMessages.h" #include "AppPreferences.h" #include "Cardie.h" @@ -110,6 +111,12 @@ MainWindow::MessageReceived(BMessage* message) win->Show(); break; } + case APP_SHOW_ACCOUNTS: + { + AccountsWindow* win = new AccountsWindow(); + win->Show(); + break; + } case APP_NEW_CHAT: { BMessage* newMsg = new BMessage(IM_MESSAGE); @@ -449,6 +456,13 @@ MainWindow::_CreateMenuBar() new BMessage(B_QUIT_REQUESTED), 'Q', B_COMMAND_KEY)); programMenu->SetTargetForItems(this); + // Accounts + BMenu* accountsMenu = new BMenu(B_TRANSLATE("Accounts")); + accountsMenu->AddItem( + new BMenuItem(B_TRANSLATE("Manage accounts" B_UTF8_ELLIPSIS), + new BMessage(APP_SHOW_ACCOUNTS), '.', B_COMMAND_KEY)); + accountsMenu->SetTargetForItems(this); + // Chat BMenu* chatMenu = new BMenu(B_TRANSLATE("Chat")); chatMenu->AddItem(new BMenuItem(B_TRANSLATE("Join room" B_UTF8_ELLIPSIS), @@ -478,6 +492,7 @@ MainWindow::_CreateMenuBar() windowMenu->SetTargetForItems(this); menuBar->AddItem(programMenu); + menuBar->AddItem(accountsMenu); menuBar->AddItem(chatMenu); menuBar->AddItem(rosterMenu); menuBar->AddItem(windowMenu); diff --git a/application/windows/PreferencesWindow.cpp b/application/windows/PreferencesWindow.cpp index 34e8135..0c82dfd 100644 --- a/application/windows/PreferencesWindow.cpp +++ b/application/windows/PreferencesWindow.cpp @@ -14,7 +14,6 @@ #include #include -#include "PreferencesAccounts.h" #include "PreferencesBehavior.h" #include "PreferencesChatWindow.h" #include "PreferencesReplicant.h" @@ -33,7 +32,6 @@ PreferencesWindow::PreferencesWindow() | B_NOT_ZOOMABLE | B_CLOSE_ON_ESCAPE) { BTabView* tabView = new BTabView("tabView", B_WIDTH_AS_USUAL); - tabView->AddTab(new PreferencesAccounts()); tabView->AddTab(new PreferencesBehavior()); tabView->AddTab(new PreferencesChatWindow()); tabView->AddTab(new PreferencesReplicant());