Split account preferences into dedicated window

Found in the new "Accounts" menubar option.
This commit is contained in:
Jaidyn Ann 2021-08-06 12:21:17 -05:00
parent a9022755ca
commit 2e746a975a
6 changed files with 43 additions and 32 deletions

View File

@ -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';

View File

@ -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 \

View File

@ -8,6 +8,8 @@
* Jaidyn Levesque, jadedctrl@teknik.io
*/
#include "AccountsWindow.h"
#include <Button.h>
#include <Catalog.h>
#include <ControlLook.h>
@ -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 =

View File

@ -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 <View.h>
#include <Window.h>
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

View File

@ -18,6 +18,7 @@
#include <TranslationUtils.h>
#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);

View File

@ -14,7 +14,6 @@
#include <LayoutBuilder.h>
#include <TabView.h>
#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());