Big cleanup.

Now searches all volumes for people groups.
The only thing left is to make "URL:" and "E-mail:" clickable.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13136 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2005-06-15 03:18:00 +00:00
parent f32d9ec555
commit 779f323d92
7 changed files with 399 additions and 791 deletions

View File

@ -26,43 +26,52 @@
#include "PeopleWindow.h" #include "PeopleWindow.h"
#include "PersonIcons.h" #include "PersonIcons.h"
//====================================================================
struct people_field gFields[] = {
{ "META:name", 120, "Contact Name" },
{ "META:nickname", 120, "Nickname" },
{ "META:company", 120, "Company" },
{ "META:address", 120, "Address" },
{ "META:city", 90, "City" },
{ "META:state", 50, "State" },
{ "META:zip", 50, "Zip" },
{ "META:country", 120, "Country" },
{ "META:hphone", 90, "Home Phone" },
{ "META:wphone", 90, "Work Phone" },
{ "META:fax", 90, "Fax" },
{ "META:email", 120, "E-mail" },
{ "META:url", 120, "URL" },
{ "META:group", 120, "Group" },
{ NULL, NULL }
};
TPeopleApp::TPeopleApp(void) TPeopleApp::TPeopleApp(void)
:BApplication(APP_SIG) : BApplication(APP_SIG)
{ {
bool valid = FALSE;
const char *str; const char *str;
int32 index = 0; int32 index = 0;
BBitmap large_icon(BRect(0, 0, B_LARGE_ICON - 1, B_LARGE_ICON - 1), B_COLOR_8_BIT);
BBitmap mini_icon(BRect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1), B_COLOR_8_BIT);
BDirectory dir; BDirectory dir;
BEntry entry; BEntry entry;
BMessage msg; BMessage msg;
BMessage info; BMessage info;
BMimeType mime;
BPath path; BPath path;
BPoint pos;
BVolume vol;
BVolumeRoster roster;
// TPeopleWindow *window;
fHaveWindow = FALSE; fHaveWindow = false;
fPosition.Set(6, TITLE_BAR_HEIGHT, 6 + WIND_WIDTH, TITLE_BAR_HEIGHT + WIND_HEIGHT); fPosition.Set(6, TITLE_BAR_HEIGHT, 6 + WIND_WIDTH, TITLE_BAR_HEIGHT + WIND_HEIGHT);
pos = fPosition.LeftTop(); BPoint pos = fPosition.LeftTop();
find_directory(B_USER_SETTINGS_DIRECTORY, &path, true); find_directory(B_USER_SETTINGS_DIRECTORY, &path, true);
dir.SetTo(path.Path()); dir.SetTo(path.Path());
if (dir.FindEntry("People_data", &entry) == B_NO_ERROR) { if (dir.FindEntry("People_data", &entry) == B_NO_ERROR) {
fPrefs = new BFile(&entry, O_RDWR); fPrefs = new BFile(&entry, B_READ_WRITE);
if (fPrefs->InitCheck() == B_NO_ERROR) { if (fPrefs->InitCheck() == B_NO_ERROR) {
fPrefs->Read(&pos, sizeof(BPoint)); fPrefs->Read(&pos, sizeof(BPoint));
if (BScreen(B_MAIN_SCREEN_ID).Frame().Contains(pos)) if (BScreen(B_MAIN_SCREEN_ID).Frame().Contains(pos))
fPosition.OffsetTo(pos); fPosition.OffsetTo(pos);
} }
} } else {
else {
fPrefs = new BFile(); fPrefs = new BFile();
if (dir.CreateFile("People_data", fPrefs) != B_NO_ERROR) { if (dir.CreateFile("People_data", fPrefs) != B_NO_ERROR) {
delete fPrefs; delete fPrefs;
@ -70,29 +79,28 @@ TPeopleApp::TPeopleApp(void)
} }
} }
roster.GetBootVolume(&vol); // create indices on the boot volume
fs_create_index(vol.Device(), P_NAME, B_STRING_TYPE, 0); // ToDo: on other volumes as well?
fs_create_index(vol.Device(), P_COMPANY, B_STRING_TYPE, 0);
fs_create_index(vol.Device(), P_ADDRESS, B_STRING_TYPE, 0); BVolumeRoster roster;
fs_create_index(vol.Device(), P_CITY, B_STRING_TYPE, 0); BVolume volume;
fs_create_index(vol.Device(), P_STATE, B_STRING_TYPE, 0); roster.GetBootVolume(&volume);
fs_create_index(vol.Device(), P_ZIP, B_STRING_TYPE, 0);
fs_create_index(vol.Device(), P_COUNTRY, B_STRING_TYPE, 0); for (int32 i = 0; gFields[i].attribute; i++) {
fs_create_index(vol.Device(), P_HPHONE, B_STRING_TYPE, 0); fs_create_index(volume.Device(), gFields[i].attribute, B_STRING_TYPE, 0);
fs_create_index(vol.Device(), P_WPHONE, B_STRING_TYPE, 0); }
fs_create_index(vol.Device(), P_FAX, B_STRING_TYPE, 0);
fs_create_index(vol.Device(), P_EMAIL, B_STRING_TYPE, 0);
fs_create_index(vol.Device(), P_URL, B_STRING_TYPE, 0);
fs_create_index(vol.Device(), P_GROUP, B_STRING_TYPE, 0);
fs_create_index(vol.Device(), P_NICKNAME, B_STRING_TYPE, 0);
// install person mime type // install person mime type
bool valid = false;
BMimeType mime;
mime.SetType(B_PERSON_MIMETYPE); mime.SetType(B_PERSON_MIMETYPE);
if (mime.IsInstalled()) { if (mime.IsInstalled()) {
if (mime.GetAttrInfo(&info) == B_NO_ERROR) { if (mime.GetAttrInfo(&info) == B_NO_ERROR) {
while (info.FindString("attr:name", index++, &str) == B_NO_ERROR) { while (info.FindString("attr:name", index++, &str) == B_NO_ERROR) {
if (!strcmp(str, P_NAME)) { if (!strcmp(str, gFields[0].attribute)) {
valid = TRUE; valid = true;
break; break;
} }
} }
@ -101,207 +109,67 @@ TPeopleApp::TPeopleApp(void)
} }
} }
if (!valid) { if (!valid) {
BBitmap largeIcon(BRect(0, 0, B_LARGE_ICON - 1, B_LARGE_ICON - 1), B_COLOR_8_BIT);
BBitmap miniIcon(BRect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1), B_COLOR_8_BIT);
mime.Install(); mime.Install();
large_icon.SetBits(kLargePersonIcon, large_icon.BitsLength(), 0, B_COLOR_8_BIT); largeIcon.SetBits(kLargePersonIcon, largeIcon.BitsLength(), 0, B_COLOR_8_BIT);
mini_icon.SetBits(kSmallPersonIcon, mini_icon.BitsLength(), 0, B_COLOR_8_BIT); miniIcon.SetBits(kSmallPersonIcon, miniIcon.BitsLength(), 0, B_COLOR_8_BIT);
mime.SetShortDescription("Person"); mime.SetShortDescription("Person");
mime.SetLongDescription("Contact information for a person."); mime.SetLongDescription("Contact information for a person.");
mime.SetIcon(&large_icon, B_LARGE_ICON); mime.SetIcon(&largeIcon, B_LARGE_ICON);
mime.SetIcon(&mini_icon, B_MINI_ICON); mime.SetIcon(&miniIcon, B_MINI_ICON);
mime.SetPreferredApp(APP_SIG); mime.SetPreferredApp(APP_SIG);
// add relevant person fields to meta-mime type // add relevant person fields to meta-mime type
msg.AddString("attr:public_name", "Contact Name");
msg.AddString("attr:name", P_NAME);
msg.AddInt32("attr:type", B_STRING_TYPE);
msg.AddBool("attr:viewable", true);
msg.AddBool("attr:editable", true);
msg.AddInt32("attr:width", 120);
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
msg.AddBool("attr:extra", false);
msg.AddString("attr:public_name", "Company"); for (int32 i = 0; gFields[i].attribute; i++) {
msg.AddString("attr:name", P_COMPANY); msg.AddString("attr:public_name", gFields[i].name);
msg.AddInt32("attr:type", B_STRING_TYPE); msg.AddString("attr:name", gFields[i].attribute);
msg.AddBool("attr:viewable", true); msg.AddInt32("attr:type", B_STRING_TYPE);
msg.AddBool("attr:editable", true); msg.AddBool("attr:viewable", true);
msg.AddInt32("attr:width", 120); msg.AddBool("attr:editable", true);
msg.AddInt32("attr:alignment", B_ALIGN_LEFT); msg.AddInt32("attr:width", gFields[i].width);
msg.AddBool("attr:extra", false); msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
msg.AddBool("attr:extra", false);
msg.AddString("attr:public_name", "Address"); }
msg.AddString("attr:name", P_ADDRESS);
msg.AddInt32("attr:type", B_STRING_TYPE);
msg.AddBool("attr:viewable", true);
msg.AddBool("attr:editable", true);
msg.AddInt32("attr:width", 120);
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
msg.AddBool("attr:extra", false);
msg.AddString("attr:public_name", "City");
msg.AddString("attr:name", P_CITY);
msg.AddInt32("attr:type", B_STRING_TYPE);
msg.AddBool("attr:viewable", true);
msg.AddBool("attr:editable", true);
msg.AddInt32("attr:width", 90);
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
msg.AddBool("attr:extra", false);
msg.AddString("attr:public_name", "State");
msg.AddString("attr:name", P_STATE);
msg.AddInt32("attr:type", B_STRING_TYPE);
msg.AddBool("attr:viewable", true);
msg.AddBool("attr:editable", true);
msg.AddInt32("attr:width", 50);
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
msg.AddBool("attr:extra", false);
msg.AddString("attr:public_name", "Zip");
msg.AddString("attr:name", P_ZIP);
msg.AddInt32("attr:type", B_STRING_TYPE);
msg.AddBool("attr:viewable", true);
msg.AddBool("attr:editable", true);
msg.AddInt32("attr:width", 50);
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
msg.AddBool("attr:extra", false);
msg.AddString("attr:public_name", "Country");
msg.AddString("attr:name", P_COUNTRY);
msg.AddInt32("attr:type", B_STRING_TYPE);
msg.AddBool("attr:viewable", true);
msg.AddBool("attr:editable", true);
msg.AddInt32("attr:width", 120);
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
msg.AddBool("attr:extra", false);
msg.AddString("attr:public_name", "Home Phone");
msg.AddString("attr:name", P_HPHONE);
msg.AddInt32("attr:type", B_STRING_TYPE);
msg.AddBool("attr:viewable", true);
msg.AddBool("attr:editable", true);
msg.AddInt32("attr:width", 90);
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
msg.AddBool("attr:extra", false);
msg.AddString("attr:public_name", "Work Phone");
msg.AddString("attr:name", P_WPHONE);
msg.AddInt32("attr:type", B_STRING_TYPE);
msg.AddBool("attr:viewable", true);
msg.AddBool("attr:editable", true);
msg.AddInt32("attr:width", 90);
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
msg.AddBool("attr:extra", false);
msg.AddString("attr:public_name", "Fax");
msg.AddString("attr:name", P_FAX);
msg.AddInt32("attr:type", B_STRING_TYPE);
msg.AddBool("attr:viewable", true);
msg.AddBool("attr:editable", true);
msg.AddInt32("attr:width", 90);
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
msg.AddBool("attr:extra", false);
msg.AddString("attr:public_name", "E-mail");
msg.AddString("attr:name", P_EMAIL);
msg.AddInt32("attr:type", B_STRING_TYPE);
msg.AddBool("attr:viewable", true);
msg.AddBool("attr:editable", true);
msg.AddInt32("attr:width", 120);
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
msg.AddBool("attr:extra", false);
msg.AddString("attr:public_name", "URL");
msg.AddString("attr:name", P_URL);
msg.AddInt32("attr:type", B_STRING_TYPE);
msg.AddBool("attr:viewable", true);
msg.AddBool("attr:editable", true);
msg.AddInt32("attr:width", 120);
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
msg.AddBool("attr:extra", false);
msg.AddString("attr:public_name", "Group");
msg.AddString("attr:name", P_GROUP);
msg.AddInt32("attr:type", B_STRING_TYPE);
msg.AddBool("attr:viewable", true);
msg.AddBool("attr:editable", true);
msg.AddInt32("attr:width", 120);
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
msg.AddBool("attr:extra", false);
msg.AddString("attr:public_name", "Nickname");
msg.AddString("attr:name", P_NICKNAME);
msg.AddInt32("attr:type", B_STRING_TYPE);
msg.AddBool("attr:viewable", true);
msg.AddBool("attr:editable", true);
msg.AddInt32("attr:width", 120);
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
msg.AddBool("attr:extra", false);
mime.SetAttrInfo(&msg); mime.SetAttrInfo(&msg);
} }
} }
//--------------------------------------------------------------------
TPeopleApp::~TPeopleApp(void) TPeopleApp::~TPeopleApp(void)
{ {
if (fPrefs) delete fPrefs;
delete fPrefs;
} }
//--------------------------------------------------------------------
void TPeopleApp::AboutRequested(void) void
TPeopleApp::AboutRequested(void)
{ {
(new BAlert("", "...by Robert Polic", "Big Deal"))->Go(); (new BAlert("", "...by Robert Polic", "Big Deal"))->Go();
} }
//--------------------------------------------------------------------
void TPeopleApp::ArgvReceived(int32 argc, char **argv) void
TPeopleApp::ArgvReceived(int32 argc, char **argv)
{ {
char *arg; TPeopleWindow* window = NULL;
int32 index;
int32 loop;
TPeopleWindow *window = NULL;
for (loop = 1; loop < argc; loop++) { for (int32 loop = 1; loop < argc; loop++) {
arg = argv[loop]; char* arg = argv[loop];
if (!strncmp(P_NAME, arg, strlen(P_NAME)))
index = F_NAME;
else if (!strncmp(P_COMPANY, arg, strlen(P_COMPANY)))
index = F_COMPANY;
else if (!strncmp(P_ADDRESS, arg, strlen(P_ADDRESS)))
index = F_ADDRESS;
else if (!strncmp(P_CITY, arg, strlen(P_CITY)))
index = F_CITY;
else if (!strncmp(P_STATE, arg, strlen(P_STATE)))
index = F_STATE;
else if (!strncmp(P_ZIP, arg, strlen(P_ZIP)))
index = F_ZIP;
else if (!strncmp(P_COUNTRY, arg, strlen(P_COUNTRY)))
index = F_COUNTRY;
else if (!strncmp(P_HPHONE, arg, strlen(P_HPHONE)))
index = F_HPHONE;
else if (!strncmp(P_WPHONE, arg, strlen(P_WPHONE)))
index = F_WPHONE;
else if (!strncmp(P_FAX, arg, strlen(P_FAX)))
index = F_FAX;
else if (!strncmp(P_EMAIL, arg, strlen(P_EMAIL)))
index = F_EMAIL;
else if (!strncmp(P_URL, arg, strlen(P_URL)))
index = F_URL;
else if (!strncmp(P_GROUP, arg, strlen(P_GROUP)))
index = F_GROUP;
else if (!strncmp(P_NICKNAME, arg, strlen(P_NICKNAME)))
index = F_NICKNAME;
else
index = F_END;
if (index != F_END) { int32 index;
for (index = 0; gFields[index].attribute; index++) {
if (!strncmp(gFields[index].attribute, arg, strlen(gFields[index].attribute)))
break;
}
if (gFields[index].attribute != NULL) {
if (!window) if (!window)
window = NewWindow(); window = NewWindow();
while(*arg != ' ') while (*arg != ' ')
arg++; arg++;
arg++; arg++;
window->SetField(index, arg); window->SetField(index, arg);
@ -309,9 +177,9 @@ void TPeopleApp::ArgvReceived(int32 argc, char **argv)
} }
} }
//--------------------------------------------------------------------
void TPeopleApp::MessageReceived(BMessage *msg) void
TPeopleApp::MessageReceived(BMessage *msg)
{ {
switch (msg->what) { switch (msg->what) {
case M_NEW: case M_NEW:
@ -323,44 +191,44 @@ void TPeopleApp::MessageReceived(BMessage *msg)
} }
} }
//--------------------------------------------------------------------
void TPeopleApp::RefsReceived(BMessage *msg) void
TPeopleApp::RefsReceived(BMessage *message)
{ {
int32 item = 0; int32 index = 0;
BFile file;
entry_ref ref;
TPeopleWindow *window;
while (msg->HasRef("refs", item)) { while (message->HasRef("refs", index)) {
msg->FindRef("refs", item++, &ref); entry_ref ref;
if ((window = FindWindow(ref))) message->FindRef("refs", index++, &ref);
window->Activate(TRUE);
TPeopleWindow* window = FindWindow(ref);
if (window != NULL)
window->Activate(true);
else { else {
file.SetTo(&ref, O_RDONLY); BFile file(&ref, B_READ_ONLY);
if (file.InitCheck() == B_NO_ERROR) if (file.InitCheck() == B_OK)
NewWindow(&ref); NewWindow(&ref);
} }
} }
} }
//--------------------------------------------------------------------
void TPeopleApp::ReadyToRun(void) void
TPeopleApp::ReadyToRun(void)
{ {
if (!fHaveWindow) if (!fHaveWindow)
NewWindow(); NewWindow();
} }
//--------------------------------------------------------------------
TPeopleWindow* TPeopleApp::NewWindow(entry_ref *ref) TPeopleWindow*
TPeopleApp::NewWindow(entry_ref *ref)
{ {
TPeopleWindow *window; TPeopleWindow *window;
window = new TPeopleWindow(fPosition, "New Person", ref); window = new TPeopleWindow(fPosition, "New Person", ref);
window->Show(); window->Show();
fHaveWindow = TRUE; fHaveWindow = true;
fPosition.OffsetBy(20, 20); fPosition.OffsetBy(20, 20);
if (fPosition.bottom > BScreen(B_MAIN_SCREEN_ID).Frame().bottom) if (fPosition.bottom > BScreen(B_MAIN_SCREEN_ID).Frame().bottom)
@ -371,15 +239,15 @@ TPeopleWindow* TPeopleApp::NewWindow(entry_ref *ref)
return window; return window;
} }
//--------------------------------------------------------------------
TPeopleWindow* TPeopleApp::FindWindow(entry_ref ref) TPeopleWindow*
TPeopleApp::FindWindow(entry_ref ref)
{ {
int32 index = 0; TPeopleWindow* window;
TPeopleWindow *window; int32 index = 0;
while ((window = (TPeopleWindow *)WindowAt(index++))) { while ((window = (TPeopleWindow *)WindowAt(index++))) {
if ((window->FindView("PeopleView")) && (window->fRef) && (*(window->fRef) == ref)) if (window->FindView("PeopleView") != NULL && window->fRef && *window->fRef == ref)
return window; return window;
} }
return NULL; return NULL;

View File

@ -13,61 +13,56 @@
#ifndef PEOPLEAPP_H #ifndef PEOPLEAPP_H
#define PEOPLEAPP_H #define PEOPLEAPP_H
#define B_PERSON_MIMETYPE "application/x-person"
#define APP_SIG "application/x-vnd.Be-PEPL"
#define P_NAME "META:name"
#define P_NICKNAME "META:nickname"
#define P_COMPANY "META:company"
#define P_ADDRESS "META:address"
#define P_CITY "META:city"
#define P_STATE "META:state"
#define P_ZIP "META:zip"
#define P_COUNTRY "META:country"
#define P_HPHONE "META:hphone"
#define P_WPHONE "META:wphone"
#define P_FAX "META:fax"
#define P_EMAIL "META:email"
#define P_URL "META:url"
#define P_GROUP "META:group"
enum MESSAGES {M_NEW = 128, M_SAVE, M_SAVE_AS, M_REVERT,
M_UNDO, M_SELECT, M_GROUP_MENU, M_DIRTY,
M_NAME, M_NICKNAME, M_COMPANY, M_ADDRESS,
M_CITY, M_STATE, M_ZIP, M_COUNTRY, M_HPHONE,
M_WPHONE, M_FAX, M_EMAIL, M_URL, M_GROUP};
enum FIELDS {F_NAME = 0, F_NICKNAME, F_COMPANY, F_ADDRESS,
F_CITY, F_STATE, F_ZIP, F_COUNTRY, F_HPHONE,
F_WPHONE, F_FAX, F_EMAIL, F_URL, F_GROUP, F_END};
class TPeopleWindow;
//====================================================================
#include <Application.h> #include <Application.h>
#define B_PERSON_MIMETYPE "application/x-person"
#define APP_SIG "application/x-vnd.Be-PEPL"
struct people_field {
const char* attribute;
int32 width;
const char* name;
};
extern people_field gFields[];
enum messages{
M_NEW = 128, M_SAVE, M_SAVE_AS, M_REVERT,
M_UNDO, M_SELECT, M_GROUP_MENU, M_DIRTY,
M_NAME, M_NICKNAME, M_COMPANY, M_ADDRESS,
M_CITY, M_STATE, M_ZIP, M_COUNTRY, M_HPHONE,
M_WPHONE, M_FAX, M_EMAIL, M_URL, M_GROUP
};
enum fields {
F_NAME = 0, F_NICKNAME, F_COMPANY, F_ADDRESS,
F_CITY, F_STATE, F_ZIP, F_COUNTRY, F_HPHONE,
F_WPHONE, F_FAX, F_EMAIL, F_URL, F_GROUP, F_END
};
class TPeopleWindow;
//====================================================================
class TPeopleApp : public BApplication { class TPeopleApp : public BApplication {
public:
TPeopleApp(void);
virtual ~TPeopleApp(void);
private: virtual void AboutRequested(void);
virtual void ArgvReceived(int32, char**);
virtual void MessageReceived(BMessage*);
virtual void RefsReceived(BMessage*);
virtual void ReadyToRun(void);
TPeopleWindow *FindWindow(entry_ref);
TPeopleWindow *NewWindow(entry_ref* = NULL);
bool fHaveWindow; BFile *fPrefs;
BRect fPosition;
public: private:
bool fHaveWindow;
BFile *fPrefs; BRect fPosition;
TPeopleApp(void);
~TPeopleApp(void);
virtual void AboutRequested(void);
virtual void ArgvReceived(int32, char**);
virtual void MessageReceived(BMessage*);
virtual void RefsReceived(BMessage*);
virtual void ReadyToRun(void);
TPeopleWindow *FindWindow(entry_ref);
TPeopleWindow *NewWindow(entry_ref* = NULL);
}; };
#endif /* PEOPLEAPP_H */ #endif /* PEOPLEAPP_H */

View File

@ -18,14 +18,14 @@
#include <PopUpMenu.h> #include <PopUpMenu.h>
#include <Query.h> #include <Query.h>
#include <VolumeRoster.h> #include <VolumeRoster.h>
#include <malloc.h>
#include <string.h>
#include <stdio.h>
#include "PeopleView.h" #include "PeopleView.h"
#include "TTextControl.h" #include "TTextControl.h"
//==================================================================== #include <stdlib.h>
#include <string.h>
#include <stdio.h>
TPeopleView::TPeopleView(BRect rect, char *title, entry_ref *ref) TPeopleView::TPeopleView(BRect rect, char *title, entry_ref *ref)
:BView(rect, title, B_FOLLOW_ALL, B_WILL_DRAW) :BView(rect, title, B_FOLLOW_ALL, B_WILL_DRAW)
@ -36,280 +36,93 @@ TPeopleView::TPeopleView(BRect rect, char *title, entry_ref *ref)
fFile = NULL; fFile = NULL;
} }
//--------------------------------------------------------------------
TPeopleView::~TPeopleView(void) TPeopleView::~TPeopleView(void)
{ {
if (fFile) delete fFile;
delete fFile;
} }
//--------------------------------------------------------------------
void TPeopleView::AttachedToWindow(void) void
TPeopleView::AttachedToWindow(void)
{ {
char *text;
float offset;
BBox *box;
BFont font = *be_plain_font;
BMenuField *field;
BRect r;
attr_info info;
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
r = Bounds(); BRect bounds = Bounds();
r.InsetBy(-1, -1);
box = new BBox(r);
AddChild(box);
offset = font.StringWidth(HPHONE_TEXT) + 18; BFont font = *be_plain_font;
int32 offset = int32(font.StringWidth(HPHONE_TEXT) + 10.5);
BRect rect;
int32 row = 0;
text = (char *)malloc(1); for (int32 i = 0; gFields[i].attribute; i++, row++) {
text[0] = 0; const char *name = gFields[i].name;
r.Set(offset - font.StringWidth(NAME_TEXT) - 11, NAME_V,
NAME_H + NAME_WIDTH, NAME_V + TEXT_HEIGHT); rect.Set(NAME_H, NAME_V + row * 25,
if (fFile) { bounds.right - NAME_H, NAME_V + (row + 1) * 25);
if (fFile->GetAttrInfo(P_NAME, &info) == B_NO_ERROR) { int32 labelOffset = offset;
text = (char *)realloc(text, info.size);
fFile->ReadAttr(P_NAME, B_STRING_TYPE, 0, text, info.size); if (i == F_NAME)
name = "Name";
else if (i == F_GROUP) {
name = "";
rect.left += offset;
labelOffset = 0;
} else if (i == F_STATE) {
rect.right = rect.left + STATE_WIDTH;
row--;
} else if (i == F_ZIP) {
rect.left += STATE_WIDTH + 10;
labelOffset = int32(font.StringWidth(gFields[i].name) + 10.5);
} }
}
fField[F_NAME] = new TTextControl(r, NAME_TEXT, 256,
text, M_DIRTY, M_NAME);
fField[F_NAME]->SetTarget(this);
box->AddChild(fField[F_NAME]);
text = (char *)realloc(text, 1); char *text = NULL;
text[0] = 0; attr_info info;
r.Set(offset - font.StringWidth(NICKNAME_TEXT) - 11, NICKNAME_V, if (fFile && fFile->GetAttrInfo(gFields[i].attribute, &info) == B_OK) {
NICKNAME_H + NICKNAME_WIDTH, NICKNAME_V + TEXT_HEIGHT); text = (char *)calloc(info.size, 1);
if (fFile) { fFile->ReadAttr(gFields[i].attribute, B_STRING_TYPE, 0, text, info.size);
if (fFile->GetAttrInfo(P_NICKNAME, &info) == B_NO_ERROR) {
text = (char *)realloc(text, info.size);
fFile->ReadAttr(P_NICKNAME, B_STRING_TYPE, 0, text, info.size);
} }
}
fField[F_NICKNAME] = new TTextControl(r, NICKNAME_TEXT, 256,
text, M_DIRTY, M_NICKNAME);
fField[F_NICKNAME]->SetTarget(this);
box->AddChild(fField[F_NICKNAME]);
text = (char *)realloc(text, 1); fField[i] = new TTextControl(rect, name, labelOffset, text, M_DIRTY, M_NAME);
text[0] = 0; fField[i]->SetTarget(this);
r.Set(offset - font.StringWidth(COMPANY_TEXT) - 11, COMPANY_V, AddChild(fField[i]);
COMPANY_H + COMPANY_WIDTH, COMPANY_V + TEXT_HEIGHT);
if (fFile) {
if (fFile->GetAttrInfo(P_COMPANY, &info) == B_NO_ERROR) {
text = (char *)realloc(text, info.size);
fFile->ReadAttr(P_COMPANY, B_STRING_TYPE, 0, text, info.size);
}
}
fField[F_COMPANY] = new TTextControl(r, COMPANY_TEXT, 256,
text, M_DIRTY, M_COMPANY);
fField[F_COMPANY]->SetTarget(this);
box->AddChild(fField[F_COMPANY]);
text = (char *)realloc(text, 1); free(text);
text[0] = 0;
r.Set(offset - font.StringWidth(ADDRESS_TEXT) - 11, ADDRESS_V,
ADDRESS_H + ADDRESS_WIDTH, ADDRESS_V + TEXT_HEIGHT);
if (fFile) {
if (fFile->GetAttrInfo(P_ADDRESS, &info) == B_NO_ERROR) {
text = (char *)realloc(text, info.size);
fFile->ReadAttr(P_ADDRESS, B_STRING_TYPE, 0, text, info.size);
}
} }
fField[F_ADDRESS] = new TTextControl(r, ADDRESS_TEXT, 256,
text, M_DIRTY, M_ADDRESS);
fField[F_ADDRESS]->SetTarget(this);
box->AddChild(fField[F_ADDRESS]);
text = (char *)realloc(text, 1); rect.right = NAME_H + offset;
text[0] = 0; rect.left = rect.right - font.StringWidth(gFields[F_GROUP].name) - 32;
r.Set(offset - font.StringWidth(CITY_TEXT) - 11, CITY_V, rect.top -= 1;
CITY_H + CITY_WIDTH, CITY_V + TEXT_HEIGHT);
if (fFile) {
if (fFile->GetAttrInfo(P_CITY, &info) == B_NO_ERROR) {
text = (char *)realloc(text, info.size);
fFile->ReadAttr(P_CITY, B_STRING_TYPE, 0, text, info.size);
}
}
fField[F_CITY] = new TTextControl(r, CITY_TEXT, 256,
text, M_DIRTY, M_CITY);
fField[F_CITY]->SetTarget(this);
box->AddChild(fField[F_CITY]);
text = (char *)realloc(text, 1); fGroups = new BPopUpMenu(gFields[F_GROUP].name);
text[0] = 0; fGroups->SetRadioMode(false);
r.Set(offset - font.StringWidth(STATE_TEXT) - 11, STATE_V, BMenuField *field = new BMenuField(rect, "", "", fGroups);
STATE_H + STATE_WIDTH, STATE_V + TEXT_HEIGHT);
if (fFile) {
if (fFile->GetAttrInfo(P_STATE, &info) == B_NO_ERROR) {
text = (char *)realloc(text, info.size);
fFile->ReadAttr(P_STATE, B_STRING_TYPE, 0, text, info.size);
}
}
fField[F_STATE] = new TTextControl(r, STATE_TEXT, 256,
text, M_DIRTY, M_STATE);
fField[F_STATE]->SetTarget(this);
box->AddChild(fField[F_STATE]);
text = (char *)realloc(text, 1);
text[0] = 0;
r.Set(ZIP_H + 11, ZIP_V,
ZIP_H + ZIP_WIDTH, ZIP_V + TEXT_HEIGHT);
if (fFile) {
if (fFile->GetAttrInfo(P_ZIP, &info) == B_NO_ERROR) {
text = (char *)realloc(text, info.size);
fFile->ReadAttr(P_ZIP, B_STRING_TYPE, 0, text, info.size);
}
}
fField[F_ZIP] = new TTextControl(r, ZIP_TEXT, 256,
text, M_DIRTY, M_ZIP);
fField[F_ZIP]->SetTarget(this);
box->AddChild(fField[F_ZIP]);
text = (char *)realloc(text, 1);
text[0] = 0;
r.Set(offset - font.StringWidth(COUNTRY_TEXT) - 11, COUNTRY_V,
COUNTRY_H + COUNTRY_WIDTH, COUNTRY_V + TEXT_HEIGHT);
if (fFile) {
if (fFile->GetAttrInfo(P_COUNTRY, &info) == B_NO_ERROR) {
text = (char *)realloc(text, info.size);
fFile->ReadAttr(P_COUNTRY, B_STRING_TYPE, 0, text, info.size);
}
}
fField[F_COUNTRY] = new TTextControl(r, COUNTRY_TEXT, 256,
text, M_DIRTY, M_COUNTRY);
fField[F_COUNTRY]->SetTarget(this);
box->AddChild(fField[F_COUNTRY]);
text = (char *)realloc(text, 1);
text[0] = 0;
r.Set(offset - font.StringWidth(HPHONE_TEXT) - 11, HPHONE_V,
HPHONE_H + HPHONE_WIDTH, HPHONE_V + TEXT_HEIGHT);
if (fFile) {
if (fFile->GetAttrInfo(P_HPHONE, &info) == B_NO_ERROR) {
text = (char *)realloc(text, info.size);
fFile->ReadAttr(P_HPHONE, B_STRING_TYPE, 0, text, info.size);
}
}
fField[F_HPHONE] = new TTextControl(r, HPHONE_TEXT, 256,
text, M_DIRTY, M_HPHONE);
fField[F_HPHONE]->SetTarget(this);
box->AddChild(fField[F_HPHONE]);
text = (char *)realloc(text, 1);
text[0] = 0;
r.Set(offset - font.StringWidth(WPHONE_TEXT) - 11, WPHONE_V,
WPHONE_H + WPHONE_WIDTH, WPHONE_V + TEXT_HEIGHT);
if (fFile) {
if (fFile->GetAttrInfo(P_WPHONE, &info) == B_NO_ERROR) {
text = (char *)realloc(text, info.size);
fFile->ReadAttr(P_WPHONE, B_STRING_TYPE, 0, text, info.size);
}
}
fField[F_WPHONE] = new TTextControl(r, WPHONE_TEXT, 256,
text, M_DIRTY, M_WPHONE);
fField[F_WPHONE]->SetTarget(this);
box->AddChild(fField[F_WPHONE]);
text = (char *)realloc(text, 1);
text[0] = 0;
r.Set(offset - font.StringWidth(FAX_TEXT) - 11, FAX_V,
FAX_H + FAX_WIDTH, FAX_V + TEXT_HEIGHT);
if (fFile) {
if (fFile->GetAttrInfo(P_FAX, &info) == B_NO_ERROR) {
text = (char *)realloc(text, info.size);
fFile->ReadAttr(P_FAX, B_STRING_TYPE, 0, text, info.size);
}
}
fField[F_FAX] = new TTextControl(r, FAX_TEXT, 256,
text, M_DIRTY, M_FAX);
fField[F_FAX]->SetTarget(this);
box->AddChild(fField[F_FAX]);
text = (char *)realloc(text, 1);
text[0] = 0;
r.Set(offset - font.StringWidth(EMAIL_TEXT) - 11, EMAIL_V,
EMAIL_H + EMAIL_WIDTH, EMAIL_V + TEXT_HEIGHT);
if (fFile) {
if (fFile->GetAttrInfo(P_EMAIL, &info) == B_NO_ERROR) {
text = (char *)realloc(text, info.size);
fFile->ReadAttr(P_EMAIL, B_STRING_TYPE, 0, text, info.size);
}
}
fField[F_EMAIL] = new TTextControl(r, EMAIL_TEXT, 256,
text, M_DIRTY, M_EMAIL);
fField[F_EMAIL]->SetTarget(this);
box->AddChild(fField[F_EMAIL]);
text = (char *)realloc(text, 1);
text[0] = 0;
r.Set(offset - font.StringWidth(URL_TEXT) - 11, URL_V,
URL_H + URL_WIDTH, URL_V + TEXT_HEIGHT);
if (fFile) {
if (fFile->GetAttrInfo(P_URL, &info) == B_NO_ERROR) {
text = (char *)realloc(text, info.size);
fFile->ReadAttr(P_URL, B_STRING_TYPE, 0, text, info.size);
}
}
fField[F_URL] = new TTextControl(r, URL_TEXT, 256,
text, M_DIRTY, M_URL);
fField[F_URL]->SetTarget(this);
box->AddChild(fField[F_URL]);
text = (char *)realloc(text, 1);
text[0] = 0;
r.Set(offset - 11, GROUP_V,
GROUP_H + GROUP_WIDTH, GROUP_V + TEXT_HEIGHT);
if (fFile) {
if (fFile->GetAttrInfo(P_GROUP, &info) == B_NO_ERROR) {
text = (char *)realloc(text, info.size);
fFile->ReadAttr(P_GROUP, B_STRING_TYPE, 0, text, info.size);
}
}
fField[F_GROUP] = new TTextControl(r, "", 256,
text, M_DIRTY, M_GROUP);
fField[F_GROUP]->SetTarget(this);
box->AddChild(fField[F_GROUP]);
free(text);
r.right = r.left + 3;
r.left = r.right - font.StringWidth(GROUP_TEXT) - 20;
r.top -= 1;
fGroups = new BPopUpMenu("Group");
fGroups->SetRadioMode(FALSE);
field = new BMenuField(r, "", "", fGroups);
field->SetDivider(0.0); field->SetDivider(0.0);
field->SetFont(&font); field->SetFont(&font);
field->SetEnabled(TRUE); field->SetEnabled(true);
box->AddChild(field); AddChild(field);
fField[F_NAME]->MakeFocus(); fField[F_NAME]->MakeFocus();
ResizeTo(bounds.right, rect.bottom + NAME_V);
} }
//--------------------------------------------------------------------
void TPeopleView::MessageReceived(BMessage* msg) void
TPeopleView::MessageReceived(BMessage* msg)
{ {
int32 loop;
BTextView *text;
switch (msg->what) { switch (msg->what) {
case M_SAVE: case M_SAVE:
Save(); Save();
break; break;
case M_REVERT: case M_REVERT:
for (loop = 0; loop < F_END; loop++) for (int32 loop = 0; loop < F_END; loop++)
fField[loop]->Revert(); fField[loop]->Revert();
break; break;
case M_SELECT: case M_SELECT:
for (loop = 0; loop < F_END; loop++) { for (int32 loop = 0; loop < F_END; loop++) {
text = (BTextView *)fField[loop]->ChildAt(0); BTextView* text = (BTextView *)fField[loop]->ChildAt(0);
if (text->IsFocus()) { if (text->IsFocus()) {
text->Select(0, text->TextLength()); text->Select(0, text->TextLength());
break; break;
@ -319,218 +132,162 @@ void TPeopleView::MessageReceived(BMessage* msg)
} }
} }
//--------------------------------------------------------------------
void TPeopleView::BuildGroupMenu(void) void
TPeopleView::BuildGroupMenu(void)
{ {
char *offset; BMenuItem* item;
char str[256]; while ((item = fGroups->ItemAt(0)) != NULL) {
char *text;
char *text1;
int32 count = 0;
int32 index;
BEntry entry;
BFile file;
BMessage *msg;
BMenuItem *item;
BQuery query;
BVolume vol;
BVolumeRoster volume;
attr_info info;
while ((item = fGroups->ItemAt(0))) {
fGroups->RemoveItem(item); fGroups->RemoveItem(item);
delete item; delete item;
} }
volume.GetBootVolume(&vol); const char *groupAttribute = gFields[F_GROUP].attribute;
query.SetVolume(&vol); int32 count = 0;
sprintf(str, "%s=*", P_GROUP);
query.SetPredicate(str);
query.Fetch();
while (query.GetNextEntry(&entry) == B_NO_ERROR) { BVolumeRoster volumeRoster;
file.SetTo(&entry, O_RDONLY); BVolume volume;
if ((file.InitCheck() == B_NO_ERROR) && while (volumeRoster.GetNextVolume(&volume) == B_OK) {
(file.GetAttrInfo(P_GROUP, &info) == B_NO_ERROR) && BQuery query;
(info.size > 1)) { query.SetVolume(&volume);
text = (char *)malloc(info.size);
text1 = text; char buffer[256];
file.ReadAttr(P_GROUP, B_STRING_TYPE, 0, text, info.size); sprintf(buffer, "%s=*", groupAttribute);
while (1) { query.SetPredicate(buffer);
if ((offset = strstr(text, ","))) query.Fetch();
*offset = 0;
if (!fGroups->FindItem(text)) { BEntry entry;
index = 0; while (query.GetNextEntry(&entry) == B_OK) {
while ((item = fGroups->ItemAt(index))) { BFile file(&entry, B_READ_ONLY);
if (strcmp(text, item->Label()) < 0) attr_info info;
break;
index++; if (file.InitCheck() == B_OK
&& file.GetAttrInfo(groupAttribute, &info) == B_OK
&& info.size > 1) {
if (info.size > sizeof(buffer))
info.size = sizeof(buffer);
if (file.ReadAttr(groupAttribute, B_STRING_TYPE, 0, buffer, info.size) < B_OK)
continue;
const char *text = buffer;
while (true) {
char* offset = strstr(text, ",");
if (offset != NULL)
offset[0] = '\0';
if (!fGroups->FindItem(text)) {
int32 index = 0;
while ((item = fGroups->ItemAt(index)) != NULL) {
if (strcmp(text, item->Label()) < 0)
break;
index++;
}
BMessage* message = new BMessage(M_GROUP_MENU);
message->AddString("group", text);
fGroups->AddItem(new BMenuItem(text, message), index);
count++;
} }
msg = new BMessage(M_GROUP_MENU); if (offset) {
msg->AddString("group", text); text = offset + 1;
fGroups->AddItem(new BMenuItem(text, msg), index); while (*text == ' ')
count++; text++;
}
else
break;
} }
if (offset) {
text = offset + 1;
while (*text == ' ')
text++;
}
else
break;
} }
free(text1);
} }
} }
if (!count) { if (!count) {
fGroups->AddItem(item = new BMenuItem("none", new BMessage(M_GROUP_MENU))); fGroups->AddItem(item = new BMenuItem("none", new BMessage(M_GROUP_MENU)));
item->SetEnabled(FALSE); item->SetEnabled(false);
} }
} }
//--------------------------------------------------------------------
bool TPeopleView::CheckSave(void) bool
TPeopleView::CheckSave(void)
{ {
int32 loop; for (int32 loop = 0; loop < F_END; loop++) {
for (loop = 0; loop < F_END; loop++)
if (fField[loop]->Changed()) if (fField[loop]->Changed())
return TRUE; return true;
return FALSE; }
return false;
} }
//--------------------------------------------------------------------
const char* TPeopleView::GetField(int32 index) const char*
TPeopleView::GetField(int32 index)
{ {
if (index < F_END) if (index < F_END)
return fField[index]->Text(); return fField[index]->Text();
else
return NULL; return NULL;
} }
//--------------------------------------------------------------------
void TPeopleView::NewFile(entry_ref *ref) void
TPeopleView::NewFile(entry_ref *ref)
{ {
if (fFile) delete fFile;
delete fFile; fFile = new BFile(ref, B_READ_WRITE);
fFile = new BFile(ref, O_RDWR);
Save(); Save();
} }
//--------------------------------------------------------------------
void TPeopleView::Save(void) void
TPeopleView::Save(void)
{ {
const char *text; for (int32 i = 0; gFields[i].attribute; i++) {
const char *text = fField[i]->Text();
text = fField[F_NAME]->Text(); fFile->WriteAttr(gFields[i].attribute, B_STRING_TYPE, 0, text, strlen(text) + 1);
fFile->WriteAttr(P_NAME, B_STRING_TYPE, 0, text, strlen(text) + 1); fField[i]->Update();
fField[F_NAME]->Update(); }
text = fField[F_COMPANY]->Text();
fFile->WriteAttr(P_COMPANY, B_STRING_TYPE, 0, text, strlen(text) + 1);
fField[F_COMPANY]->Update();
text = fField[F_ADDRESS]->Text();
fFile->WriteAttr(P_ADDRESS, B_STRING_TYPE, 0, text, strlen(text) + 1);
fField[F_ADDRESS]->Update();
text = fField[F_CITY]->Text();
fFile->WriteAttr(P_CITY, B_STRING_TYPE, 0, text, strlen(text) + 1);
fField[F_CITY]->Update();
text = fField[F_STATE]->Text();
fFile->WriteAttr(P_STATE, B_STRING_TYPE, 0, text, strlen(text) + 1);
fField[F_STATE]->Update();
text = fField[F_ZIP]->Text();
fFile->WriteAttr(P_ZIP, B_STRING_TYPE, 0, text, strlen(text) + 1);
fField[F_ZIP]->Update();
text = fField[F_COUNTRY]->Text();
fFile->WriteAttr(P_COUNTRY, B_STRING_TYPE, 0, text, strlen(text) + 1);
fField[F_COUNTRY]->Update();
text = fField[F_HPHONE]->Text();
fFile->WriteAttr(P_HPHONE, B_STRING_TYPE, 0, text, strlen(text) + 1);
fField[F_HPHONE]->Update();
text = fField[F_WPHONE]->Text();
fFile->WriteAttr(P_WPHONE, B_STRING_TYPE, 0, text, strlen(text) + 1);
fField[F_WPHONE]->Update();
text = fField[F_FAX]->Text();
fFile->WriteAttr(P_FAX, B_STRING_TYPE, 0, text, strlen(text) + 1);
fField[F_FAX]->Update();
text = fField[F_EMAIL]->Text();
fFile->WriteAttr(P_EMAIL, B_STRING_TYPE, 0, text, strlen(text) + 1);
fField[F_EMAIL]->Update();
text = fField[F_URL]->Text();
fFile->WriteAttr(P_URL, B_STRING_TYPE, 0, text, strlen(text) + 1);
fField[F_URL]->Update();
text = fField[F_GROUP]->Text();
fFile->WriteAttr(P_GROUP, B_STRING_TYPE, 0, text, strlen(text) + 1);
fField[F_GROUP]->Update();
text = fField[F_NICKNAME]->Text();
fFile->WriteAttr(P_NICKNAME, B_STRING_TYPE, 0, text, strlen(text) + 1);
fField[F_NICKNAME]->Update();
} }
//--------------------------------------------------------------------
void TPeopleView::SetField(int32 index, char *data, bool update) void
TPeopleView::SetField(int32 index, char *data, bool update)
{ {
int32 end;
int32 start;
BTextView *text;
Window()->Lock(); Window()->Lock();
if (update) { if (update) {
fField[index]->SetText(data); fField[index]->SetText(data);
fField[index]->Update(); fField[index]->Update();
} } else {
else { BTextView* text = (BTextView *)fField[index]->ChildAt(0);
text = (BTextView *)fField[index]->ChildAt(0);
int32 start, end;
text->GetSelection(&start, &end); text->GetSelection(&start, &end);
if (start != end) { if (start != end) {
text->Delete(); text->Delete();
text->Insert(data); text->Insert(data);
} } else if ((end = text->TextLength())) {
else if ((end = text->TextLength())) {
text->Select(end, end); text->Select(end, end);
text->Insert(","); text->Insert(",");
text->Insert(data); text->Insert(data);
text->Select(text->TextLength(), text->TextLength()); text->Select(text->TextLength(), text->TextLength());
} } else
else
fField[index]->SetText(data); fField[index]->SetText(data);
} }
Window()->Unlock(); Window()->Unlock();
} }
//--------------------------------------------------------------------
bool TPeopleView::TextSelected(void) bool
TPeopleView::TextSelected(void)
{ {
int32 end; for (int32 loop = 0; loop < F_END; loop++) {
int32 loop; BTextView* text = (BTextView*)fField[loop]->ChildAt(0);
int32 start;
BTextView *text;
for (loop = 0; loop < F_END; loop++) { int32 start, end;
text = (BTextView *)fField[loop]->ChildAt(0);
text->GetSelection(&start, &end); text->GetSelection(&start, &end);
if (start != end) if (start != end)
return TRUE; return true;
} }
return FALSE; return false;
} }

View File

@ -19,86 +19,83 @@
#define NAME_H 10 #define NAME_H 10
#define NAME_V 10 #define NAME_V 10
#define NAME_WIDTH 300 #define NAME_WIDTH 300
#define NAME_TEXT "Name" #define NAME_TEXT "Name:"
#define NICKNAME_H 10 #define NICKNAME_H 10
#define NICKNAME_V (NAME_V + 25) #define NICKNAME_V (NAME_V + 25)
#define NICKNAME_WIDTH 300 #define NICKNAME_WIDTH 300
#define NICKNAME_TEXT "Nickname" #define NICKNAME_TEXT "Nickname:"
#define COMPANY_H 10 #define COMPANY_H 10
#define COMPANY_V (NICKNAME_V + 25) #define COMPANY_V (NICKNAME_V + 25)
#define COMPANY_WIDTH 300 #define COMPANY_WIDTH 300
#define COMPANY_TEXT "Company" #define COMPANY_TEXT "Company:"
#define ADDRESS_H 10 #define ADDRESS_H 10
#define ADDRESS_V (COMPANY_V + 25) #define ADDRESS_V (COMPANY_V + 25)
#define ADDRESS_WIDTH 300 #define ADDRESS_WIDTH 300
#define ADDRESS_TEXT "Address" #define ADDRESS_TEXT "Address:"
#define CITY_H 10 #define CITY_H 10
#define CITY_V (ADDRESS_V + 25) #define CITY_V (ADDRESS_V + 25)
#define CITY_WIDTH 300 #define CITY_WIDTH 300
#define CITY_TEXT "City" #define CITY_TEXT "City:"
#define STATE_H 10 #define STATE_H 10
#define STATE_V (CITY_V + 25) #define STATE_V (CITY_V + 25)
#define STATE_WIDTH 175 #define STATE_WIDTH 175
#define STATE_TEXT "State" #define STATE_TEXT "State:"
#define ZIP_H (STATE_H + STATE_WIDTH) #define ZIP_H (STATE_H + STATE_WIDTH)
#define ZIP_V (CITY_V + 25) #define ZIP_V (CITY_V + 25)
#define ZIP_WIDTH 125 #define ZIP_WIDTH 125
#define ZIP_TEXT "Zip" #define ZIP_TEXT "Zip:"
#define COUNTRY_H 10 #define COUNTRY_H 10
#define COUNTRY_V (ZIP_V + 25) #define COUNTRY_V (ZIP_V + 25)
#define COUNTRY_WIDTH 300 #define COUNTRY_WIDTH 300
#define COUNTRY_TEXT "Country" #define COUNTRY_TEXT "Country:"
#define HPHONE_H 10 #define HPHONE_H 10
#define HPHONE_V (COUNTRY_V + 25) #define HPHONE_V (COUNTRY_V + 25)
#define HPHONE_WIDTH 300 #define HPHONE_WIDTH 300
#define HPHONE_TEXT "Home Phone" #define HPHONE_TEXT "Home Phone:"
#define WPHONE_H 10 #define WPHONE_H 10
#define WPHONE_V (HPHONE_V + 25) #define WPHONE_V (HPHONE_V + 25)
#define WPHONE_WIDTH 300 #define WPHONE_WIDTH 300
#define WPHONE_TEXT "Work Phone" #define WPHONE_TEXT "Work Phone:"
#define FAX_H 10 #define FAX_H 10
#define FAX_V (WPHONE_V + 25) #define FAX_V (WPHONE_V + 25)
#define FAX_WIDTH 300 #define FAX_WIDTH 300
#define FAX_TEXT "Fax" #define FAX_TEXT "Fax:"
#define EMAIL_H 10 #define EMAIL_H 10
#define EMAIL_V (FAX_V + 25) #define EMAIL_V (FAX_V + 25)
#define EMAIL_WIDTH 300 #define EMAIL_WIDTH 300
#define EMAIL_TEXT "E-mail" #define EMAIL_TEXT "E-mail:"
#define URL_H 10 #define URL_H 10
#define URL_V (EMAIL_V + 25) #define URL_V (EMAIL_V + 25)
#define URL_WIDTH 300 #define URL_WIDTH 300
#define URL_TEXT "URL" #define URL_TEXT "URL:"
#define GROUP_H 10 #define GROUP_H 10
#define GROUP_V (URL_V + 25) #define GROUP_V (URL_V + 25)
#define GROUP_WIDTH 300 #define GROUP_WIDTH 300
#define GROUP_TEXT "Group" #define GROUP_TEXT "Group:"
class TTextControl; class TTextControl;
//====================================================================
class TPeopleView : public BView { class TPeopleView : public BView {
public:
TPeopleView(BRect rect, char* title, entry_ref* ref);
~TPeopleView(void);
private: virtual void AttachedToWindow(void);
virtual void MessageReceived(BMessage*);
void BuildGroupMenu(void);
bool CheckSave(void);
const char* GetField(int32);
void NewFile(entry_ref*);
void Save(void);
void SetField(int32, char*, bool);
bool TextSelected(void);
BFile *fFile; private:
BPopUpMenu *fGroups; BFile *fFile;
TTextControl *fField[F_END]; BPopUpMenu *fGroups;
TTextControl *fField[F_END];
public:
TPeopleView(BRect, char*, entry_ref*);
~TPeopleView(void);
virtual void AttachedToWindow(void);
virtual void MessageReceived(BMessage*);
void BuildGroupMenu(void);
bool CheckSave(void);
const char* GetField(int32);
void NewFile(entry_ref*);
void Save(void);
void SetField(int32, char*, bool);
bool TextSelected(void);
}; };
#endif /* PEOPLEVIEW_H */ #endif /* PEOPLEVIEW_H */

View File

@ -14,33 +14,29 @@
#include <MenuItem.h> #include <MenuItem.h>
#include <FilePanel.h> #include <FilePanel.h>
#include <NodeInfo.h> #include <NodeInfo.h>
#include <stdio.h>
#include <Alert.h> #include <Alert.h>
#include <Path.h> #include <Path.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <Font.h> #include <Font.h>
#include <Clipboard.h> #include <Clipboard.h>
#include <string.h>
#include "PeopleApp.h" #include "PeopleApp.h"
#include "PeopleView.h" #include "PeopleView.h"
#include "PeopleWindow.h" #include "PeopleWindow.h"
//==================================================================== #include <stdio.h>
#include <string.h>
TPeopleWindow::TPeopleWindow(BRect rect, char *title, entry_ref *ref)
:BWindow(rect, title, B_TITLED_WINDOW, B_NOT_RESIZABLE | TPeopleWindow::TPeopleWindow(BRect frame, char *title, entry_ref *ref)
B_NOT_ZOOMABLE) : BWindow(frame, title, B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE),
fPanel(NULL)
{ {
BMenu *menu; BMenu* menu;
BMenuBar *menu_bar; BMenuItem* item;
BMenuItem *item;
BRect r;
fPanel = NULL; BRect rect(0, 0, 32767, 15);
BMenuBar* menuBar = new BMenuBar(rect, "");
r.Set(0, 0, 32767, 15);
menu_bar = new BMenuBar(r, "");
menu = new BMenu("File"); menu = new BMenu("File");
menu->AddItem(item = new BMenuItem("New Person", new BMessage(M_NEW), 'N')); menu->AddItem(item = new BMenuItem("New Person", new BMessage(M_NEW), 'N'));
item->SetTarget(NULL, be_app); item->SetTarget(NULL, be_app);
@ -53,7 +49,7 @@ TPeopleWindow::TPeopleWindow(BRect rect, char *title, entry_ref *ref)
fRevert->SetEnabled(FALSE); fRevert->SetEnabled(FALSE);
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q')); menu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q'));
menu_bar->AddItem(menu); menuBar->AddItem(menu);
menu = new BMenu("Edit"); menu = new BMenu("Edit");
menu->AddItem(fUndo = new BMenuItem("Undo", new BMessage(M_UNDO), 'Z')); menu->AddItem(fUndo = new BMenuItem("Undo", new BMessage(M_UNDO), 'Z'));
@ -66,47 +62,41 @@ TPeopleWindow::TPeopleWindow(BRect rect, char *title, entry_ref *ref)
fPaste->SetTarget(NULL, this); fPaste->SetTarget(NULL, this);
menu->AddItem(item = new BMenuItem("Select All", new BMessage(M_SELECT), 'A')); menu->AddItem(item = new BMenuItem("Select All", new BMessage(M_SELECT), 'A'));
item->SetTarget(NULL, this); item->SetTarget(NULL, this);
menu_bar->AddItem(menu); menuBar->AddItem(menu);
AddChild(menu_bar); AddChild(menuBar);
if (ref) { if (ref) {
fRef = new entry_ref(*ref); fRef = new entry_ref(*ref);
SetTitle(ref->name); SetTitle(ref->name);
} } else
else
fRef = NULL; fRef = NULL;
r = Frame(); rect = Frame();
r.OffsetTo(0, menu_bar->Bounds().bottom + 1); rect.OffsetTo(0, menuBar->Bounds().bottom + 1);
fView = new TPeopleView(r, "PeopleView", fRef); fView = new TPeopleView(rect, "PeopleView", fRef);
ResizeBy(0, menu_bar->Bounds().bottom + 1); ResizeTo(frame.Width(), fView->Frame().bottom);
Lock();
AddChild(fView); AddChild(fView);
Unlock();
} }
//--------------------------------------------------------------------
TPeopleWindow::~TPeopleWindow(void) TPeopleWindow::~TPeopleWindow(void)
{ {
if (fRef) delete fRef;
delete fRef; delete fPanel;
if (fPanel)
delete fPanel;
} }
//--------------------------------------------------------------------
void TPeopleWindow::MenusBeginning(void) void
TPeopleWindow::MenusBeginning(void)
{ {
bool enabled; bool enabled;
enabled = fView->CheckSave(); enabled = fView->CheckSave();
fSave->SetEnabled(enabled); fSave->SetEnabled(enabled);
fRevert->SetEnabled(enabled); fRevert->SetEnabled(enabled);
fUndo->SetEnabled(FALSE); fUndo->SetEnabled(false);
enabled = fView->TextSelected(); enabled = fView->TextSelected();
fCut->SetEnabled(enabled); fCut->SetEnabled(enabled);
fCopy->SetEnabled(enabled); fCopy->SetEnabled(enabled);
@ -118,9 +108,9 @@ void TPeopleWindow::MenusBeginning(void)
fView->BuildGroupMenu(); fView->BuildGroupMenu();
} }
//--------------------------------------------------------------------
void TPeopleWindow::MessageReceived(BMessage* msg) void
TPeopleWindow::MessageReceived(BMessage* msg)
{ {
char str[256]; char str[256];
entry_ref dir; entry_ref dir;
@ -129,7 +119,7 @@ void TPeopleWindow::MessageReceived(BMessage* msg)
BFile file; BFile file;
BNodeInfo *node; BNodeInfo *node;
switch(msg->what) { switch (msg->what) {
case M_SAVE: case M_SAVE:
if (!fRef) { if (!fRef) {
SaveAs(); SaveAs();
@ -184,9 +174,9 @@ void TPeopleWindow::MessageReceived(BMessage* msg)
} }
} }
//--------------------------------------------------------------------
bool TPeopleWindow::QuitRequested(void) bool
TPeopleWindow::QuitRequested(void)
{ {
int32 count = 0; int32 count = 0;
int32 index = 0; int32 index = 0;
@ -203,11 +193,10 @@ bool TPeopleWindow::QuitRequested(void)
fView->Save(); fView->Save();
else { else {
SaveAs(); SaveAs();
return FALSE; return false;
} }
} } else if (result == 0)
else if (result == 0) return false;
return FALSE;
} }
while ((window = (TPeopleWindow *)be_app->WindowAt(index++))) { while ((window = (TPeopleWindow *)be_app->WindowAt(index++))) {
@ -224,12 +213,12 @@ bool TPeopleWindow::QuitRequested(void)
} }
be_app->PostMessage(B_QUIT_REQUESTED); be_app->PostMessage(B_QUIT_REQUESTED);
} }
return TRUE; return true;
} }
//--------------------------------------------------------------------
void TPeopleWindow::DefaultName(char *name) void
TPeopleWindow::DefaultName(char *name)
{ {
strncpy(name, fView->GetField(F_NAME), B_FILE_NAME_LENGTH); strncpy(name, fView->GetField(F_NAME), B_FILE_NAME_LENGTH);
while (*name) { while (*name) {
@ -239,16 +228,16 @@ void TPeopleWindow::DefaultName(char *name)
} }
} }
//--------------------------------------------------------------------
void TPeopleWindow::SetField(int32 index, char *text) void
TPeopleWindow::SetField(int32 index, char *text)
{ {
fView->SetField(index, text, TRUE); fView->SetField(index, text, true);
} }
//--------------------------------------------------------------------
void TPeopleWindow::SaveAs(void) void
TPeopleWindow::SaveAs(void)
{ {
char name[B_FILE_NAME_LENGTH]; char name[B_FILE_NAME_LENGTH];
BDirectory dir; BDirectory dir;

View File

@ -16,60 +16,64 @@
#include "TTextControl.h" #include "TTextControl.h"
//====================================================================
TTextControl::TTextControl(BRect r, char *label, int32 length, TTextControl::TTextControl(BRect r, const char *label, int32 offset,
char *text, int32 mod_msg, int32 msg) const char *text, int32 modificationMessage, int32 msg)
:BTextControl(r, "", label, text, new BMessage(msg)) : BTextControl(r, "", "", text, new BMessage(msg))
{ {
SetModificationMessage(new BMessage(mod_msg)); SetModificationMessage(new BMessage(modificationMessage));
fLabel = (char *)malloc(strlen(label) + 1); if (label[0]) {
strcpy(fLabel, label); char newLabel[B_FILE_NAME_LENGTH];
fOriginal = (char *)malloc(strlen(text) + 1); int32 length = strlen(label);
strcpy(fOriginal, text); memcpy(newLabel, label, length);
fLength = length; newLabel[length] = ':';
newLabel[length + 1] = '\0';
SetLabel(newLabel);
}
SetDivider(offset);
SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
if (text == NULL)
text = "";
fOriginal = strdup(text);
} }
//--------------------------------------------------------------------
TTextControl::~TTextControl(void) TTextControl::~TTextControl(void)
{ {
free(fLabel);
free(fOriginal); free(fOriginal);
} }
//--------------------------------------------------------------------
void TTextControl::AttachedToWindow(void) void
TTextControl::AttachedToWindow(void)
{ {
BTextView *text;
BTextControl::AttachedToWindow(); BTextControl::AttachedToWindow();
SetDivider(StringWidth(fLabel) + 7); BTextView* text = (BTextView *)ChildAt(0);
text = (BTextView *)ChildAt(0); text->SetMaxBytes(255);
text->SetMaxBytes(fLength - 1);
} }
//--------------------------------------------------------------------
bool TTextControl::Changed(void) bool
TTextControl::Changed(void)
{ {
return strcmp(fOriginal, Text()); return strcmp(fOriginal, Text());
} }
//--------------------------------------------------------------------
void TTextControl::Revert(void) void
TTextControl::Revert(void)
{ {
if (Changed()) if (Changed())
SetText(fOriginal); SetText(fOriginal);
} }
//--------------------------------------------------------------------
void TTextControl::Update(void) void
TTextControl::Update(void)
{ {
fOriginal = (char *)realloc(fOriginal, strlen(Text()) + 1); fOriginal = (char *)realloc(fOriginal, strlen(Text()) + 1);
strcpy(fOriginal, Text()); strcpy(fOriginal, Text());

View File

@ -16,21 +16,19 @@
#include <TextControl.h> #include <TextControl.h>
class TTextControl : public BTextControl { class TTextControl : public BTextControl {
public:
TTextControl(BRect rect, const char* label, int32 length, const char* text,
int32 modificationMessage, int32 invokationMessage);
~TTextControl();
private: virtual void AttachedToWindow(void);
char *fLabel; bool Changed(void);
char *fOriginal; void Revert(void);
int32 fLength; void Update(void);
public: private:
char *fOriginal;
TTextControl(BRect, char*, int32, char*, int32, int32);
~TTextControl(void);
virtual void AttachedToWindow(void);
bool Changed(void);
void Revert(void);
void Update(void);
}; };
#endif /* TEXTCONTROL_H */ #endif /* TEXTCONTROL_H */