People: Accept initial values

Besides the entry_ref to an existing Person file as argv, also
accept a BMessage containing values for attributes and set those
in the new window.

The specifier name in the BMessage needs to be the same as the
attribute name used by the People app, e.g. "META:email".

Needed to let the Mail app create a new Person file with the email
address already filled in.

Fixes #14766

Change-Id: I637200b08d5c1b7cf52d7cf3f56dab93ce1a6ec5
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7085
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
This commit is contained in:
Humdinger 2023-10-30 08:05:35 +01:00 committed by Adrien Destugues
parent a7ee73c8eb
commit 964b6e8090
6 changed files with 30 additions and 10 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2005-2010, Haiku, Inc. All rights reserved.
* Copyright 2005-2023, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
@ -223,7 +223,7 @@ TPeopleApp::MessageReceived(BMessage* message)
switch (message->what) {
case M_NEW:
case B_SILENT_RELAUNCH:
_NewWindow();
_NewWindow(NULL, message);
break;
case M_WINDOW_QUITS:
@ -274,7 +274,7 @@ TPeopleApp::RefsReceived(BMessage* message)
else {
BFile file(&ref, B_READ_ONLY);
if (file.InitCheck() == B_OK)
_NewWindow(&ref);
_NewWindow(&ref, NULL);
}
}
}
@ -292,13 +292,15 @@ TPeopleApp::ReadyToRun()
PersonWindow*
TPeopleApp::_NewWindow(entry_ref* ref)
TPeopleApp::_NewWindow(entry_ref* ref, BMessage* message)
{
PersonWindow* window = new PersonWindow(fPosition,
B_TRANSLATE("New person"), kNameAttribute,
kCategoryAttribute, ref);
_AddAttributes(window);
if (message != NULL)
window->SetInitialValues(message);
window->Show();

View File

@ -28,7 +28,7 @@ enum {
M_NEW = 'newp',
M_SAVE_AS = 'svas',
M_WINDOW_QUITS = 'wndq',
M_CONFIGURE_ATTRIBUTES = 'catr'
M_CONFIGURE_ATTRIBUTES = 'catr',
};
class PersonWindow;
@ -45,7 +45,7 @@ public:
private:
PersonWindow* _FindWindow(const entry_ref&) const;
PersonWindow* _NewWindow(entry_ref* = NULL);
PersonWindow* _NewWindow(entry_ref* = NULL, BMessage* = NULL);
void _AddAttributes(PersonWindow* window) const;
void _SavePreferences(BMessage* message) const;

View File

@ -386,8 +386,10 @@ PersonView::SetAttribute(const char* attribute, const char* value,
}
}
if (control == NULL)
if (control == NULL) {
UnlockLooper();
return;
}
if (update) {
control->SetText(value);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2005-2010, Haiku, Inc. All rights reserved.
* Copyright 2005-2023, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
@ -351,6 +351,21 @@ PersonWindow::AddAttribute(const char* label, const char* attribute)
}
void
PersonWindow::SetInitialValues(BMessage* message)
{
char* attribute;
uint32 type;
int32 count;
for (int32 i = 0; message->GetInfo(B_STRING_TYPE, i, &attribute, &type, &count) == B_OK; i++) {
BString text = "";
if (message->FindString(attribute, &text) == B_OK)
fView->SetAttribute(attribute, text.String(), true);
}
}
void
PersonWindow::SaveAs()
{

View File

@ -1,5 +1,5 @@
/*
* Copyright 2010, Haiku, Inc. All rights reserved.
* Copyright 2010-2023, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
@ -42,6 +42,7 @@ public:
void AddAttribute(const char* label,
const char* attribute);
void SetInitialValues(BMessage* message);
void SaveAs();