Author: stippi Date: 2011-02-12 18:40:58 +0100 (Sat, 12 Feb 2011) New Revision: 40462 Changeset: http://dev.haiku-os.org/changeset/40462 Added: haiku/trunk/src/apps/people/PersonView.cpp haiku/trunk/src/apps/people/PersonView.h haiku/trunk/src/apps/people/PersonWindow.cpp haiku/trunk/src/apps/people/PersonWindow.h Removed: haiku/trunk/src/apps/people/PeopleView.cpp haiku/trunk/src/apps/people/PeopleView.h haiku/trunk/src/apps/people/PeopleWindow.cpp haiku/trunk/src/apps/people/PeopleWindow.h haiku/trunk/src/apps/people/README Modified: haiku/trunk/src/apps/people/Jamfile haiku/trunk/src/apps/people/People.rdef haiku/trunk/src/apps/people/PeopleApp.cpp haiku/trunk/src/apps/people/PeopleApp.h Log: Renamed PeopleWindow/View to PersonWindow/View, since they only show one person at a time. Modified: haiku/trunk/src/apps/people/Jamfile =================================================================== --- haiku/trunk/src/apps/people/Jamfile 2011-02-12 16:46:54 UTC (rev 40461) +++ haiku/trunk/src/apps/people/Jamfile 2011-02-12 17:40:58 UTC (rev 40462) @@ -5,8 +5,8 @@ Application People : main.cpp AttributeTextControl.cpp PeopleApp.cpp - PeopleView.cpp - PeopleWindow.cpp + PersonView.cpp + PersonWindow.cpp : libbe.so libtracker.so $(TARGET_LIBSUPC++) $(HAIKU_LOCALE_LIBS) : People.rdef ; @@ -15,6 +15,6 @@ x-vnd.Be-PEPL : PeopleApp.cpp - PeopleView.cpp - PeopleWindow.cpp + PersonView.cpp + PersonWindow.cpp ; Modified: haiku/trunk/src/apps/people/People.rdef =================================================================== --- haiku/trunk/src/apps/people/People.rdef 2011-02-12 16:46:54 UTC (rev 40461) +++ haiku/trunk/src/apps/people/People.rdef 2011-02-12 17:40:58 UTC (rev 40462) @@ -10,7 +10,7 @@ internal = 0, short_info = "People", - long_info = "People ©1999 Be, Inc. ©2005-2009 Haiku, Inc." + long_info = "People ©1999 Be, Inc. ©2005-2011 Haiku, Inc." }; resource app_flags B_SINGLE_LAUNCH; Modified: haiku/trunk/src/apps/people/PeopleApp.cpp =================================================================== --- haiku/trunk/src/apps/people/PeopleApp.cpp 2011-02-12 16:46:54 UTC (rev 40461) +++ haiku/trunk/src/apps/people/PeopleApp.cpp 2011-02-12 17:40:58 UTC (rev 40462) @@ -12,6 +12,8 @@ */ +#include "PeopleApp.h" + #include <Alert.h> #include <AutoDeleter.h> #include <Bitmap.h> @@ -25,8 +27,7 @@ #include <Volume.h> #include <VolumeRoster.h> -#include "PeopleApp.h" -#include "PeopleWindow.h" +#include "PersonWindow.h" #include "PersonIcons.h" #include <string.h> @@ -250,7 +251,7 @@ entry_ref ref; message->FindRef("refs", index++, &ref); - TPeopleWindow* window = _FindWindow(ref); + PersonWindow* window = _FindWindow(ref); if (window != NULL) window->Activate(true); else { @@ -273,10 +274,10 @@ // #pragma mark - -TPeopleWindow* +PersonWindow* TPeopleApp::_NewWindow(entry_ref* ref) { - TPeopleWindow* window = new TPeopleWindow(fPosition, + PersonWindow* window = new PersonWindow(fPosition, B_TRANSLATE("New person"), kNameAttribute, kCategoryAttribute, ref); @@ -300,7 +301,7 @@ void -TPeopleApp::_AddAttributes(TPeopleWindow* window) const +TPeopleApp::_AddAttributes(PersonWindow* window) const { int32 count = fAttributes.CountItems(); for (int32 i = 0; i < count; i++) { @@ -314,11 +315,11 @@ } -TPeopleWindow* +PersonWindow* TPeopleApp::_FindWindow(const entry_ref& ref) const { for (int32 i = 0; BWindow* window = WindowAt(i); i++) { - TPeopleWindow* personWindow = dynamic_cast<TPeopleWindow*>(window); + PersonWindow* personWindow = dynamic_cast<PersonWindow*>(window); if (personWindow == NULL) continue; if (personWindow->RefersPersonFile(ref)) Modified: haiku/trunk/src/apps/people/PeopleApp.h =================================================================== --- haiku/trunk/src/apps/people/PeopleApp.h 2011-02-12 16:46:54 UTC (rev 40461) +++ haiku/trunk/src/apps/people/PeopleApp.h 2011-02-12 17:40:58 UTC (rev 40462) @@ -30,7 +30,7 @@ M_WINDOW_QUITS = 'wndq' }; -class TPeopleWindow; +class PersonWindow; class TPeopleApp : public BApplication { public: @@ -44,9 +44,9 @@ virtual void ReadyToRun(); private: - TPeopleWindow* _FindWindow(const entry_ref&) const; - TPeopleWindow* _NewWindow(entry_ref* = NULL); - void _AddAttributes(TPeopleWindow* window) const; + PersonWindow* _FindWindow(const entry_ref&) const; + PersonWindow* _NewWindow(entry_ref* = NULL); + void _AddAttributes(PersonWindow* window) const; void _SavePreferences(BMessage* message) const; private: Copied: haiku/trunk/src/apps/people/PersonView.cpp (from rev 40461, haiku/trunk/src/apps/people/PeopleView.cpp) =================================================================== --- haiku/trunk/src/apps/people/PersonView.cpp (rev 0) +++ haiku/trunk/src/apps/people/PersonView.cpp 2011-02-12 17:40:58 UTC (rev 40462) @@ -0,0 +1,338 @@ +/* + * Copyright 2010, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT license. + * + * Authors: + * Robert Polic + * Stephan Aßmus <superstippi@xxxxxx> + * + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + */ + + +#include "PersonView.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <Catalog.h> +#include <fs_attr.h> +#include <Box.h> +#include <ControlLook.h> +#include <GridLayout.h> +#include <Locale.h> +#include <MenuField.h> +#include <MenuItem.h> +#include <PopUpMenu.h> +#include <Query.h> +#include <VolumeRoster.h> +#include <Window.h> + +#include "AttributeTextControl.h" + + +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "People" + + +PersonView::PersonView(const char* name, const char* categoryAttribute, + const entry_ref *ref) + : + BGridView(), + fControls(20, false), + fCategoryAttribute(categoryAttribute) +{ + SetName(name); + if (ref) + fFile = new BFile(ref, O_RDWR); + else + fFile = NULL; + + float spacing = be_control_look->DefaultItemSpacing(); + GridLayout()->SetInsets(spacing, spacing, spacing, spacing); +} + + +PersonView::~PersonView() +{ + delete fFile; +} + + +void +PersonView::AddAttribute(const char* label, const char* attribute) +{ + // TODO: We could check if this attribute has already been added. + + AttributeTextControl* control = new AttributeTextControl(label, attribute); + fControls.AddItem(control); + + BGridLayout* layout = GridLayout(); + int32 row = layout->CountRows(); + + if (fCategoryAttribute == attribute) { + // Special case the category attribute. The Group popup field will + // be added as the label instead. + fGroups = new BPopUpMenu(label); + fGroups->SetRadioMode(false); + BuildGroupMenu(); + + BMenuField* field = new BMenuField("", "", fGroups); + field->SetEnabled(true); + layout->AddView(field, 0, row); + + control->SetLabel(""); + layout->AddView(control, 1, row); + } else { + layout->AddItem(control->CreateLabelLayoutItem(), 0, row); + layout->AddItem(control->CreateTextViewLayoutItem(), 1, row); + } + + SetAttribute(attribute, true); +} + + +void +PersonView::MakeFocus(bool focus) +{ + if (focus && fControls.CountItems() > 0) + fControls.ItemAt(0)->MakeFocus(); + else + BView::MakeFocus(focus); +} + + +void +PersonView::MessageReceived(BMessage* msg) +{ + switch (msg->what) { + case M_SAVE: + Save(); + break; + + case M_REVERT: + for (int32 i = fControls.CountItems() - 1; i >= 0; i--) + fControls.ItemAt(i)->Revert(); + break; + + case M_SELECT: + for (int32 i = fControls.CountItems() - 1; i >= 0; i--) { + BTextView* text = fControls.ItemAt(i)->TextView(); + if (text->IsFocus()) { + text->Select(0, text->TextLength()); + break; + } + } + break; + + case M_GROUP_MENU: + { + const char* name = NULL; + if (msg->FindString("group", &name) == B_OK) + SetAttribute(fCategoryAttribute, name, false); + break; + } + + } +} + + +void +PersonView::BuildGroupMenu() +{ + BMenuItem* item; + while ((item = fGroups->ItemAt(0)) != NULL) { + fGroups->RemoveItem(item); + delete item; + } + + int32 count = 0; + + BVolumeRoster volumeRoster; + BVolume volume; + while (volumeRoster.GetNextVolume(&volume) == B_OK) { + BQuery query; + query.SetVolume(&volume); + + char buffer[256]; + snprintf(buffer, sizeof(buffer), "%s=*", fCategoryAttribute.String()); + query.SetPredicate(buffer); + query.Fetch(); + + BEntry entry; + while (query.GetNextEntry(&entry) == B_OK) { + BFile file(&entry, B_READ_ONLY); + attr_info info; + + if (file.InitCheck() == B_OK + && file.GetAttrInfo(fCategoryAttribute, &info) == B_OK + && info.size > 1) { + if (info.size > sizeof(buffer)) + info.size = sizeof(buffer); + + if (file.ReadAttr(fCategoryAttribute.String(), B_STRING_TYPE, + 0, buffer, info.size) < 0) { + 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++; + } + if (offset) { + text = offset + 1; + while (*text == ' ') + text++; + } + else + break; + } + } + } + } + + if (count == 0) { + fGroups->AddItem(item = new BMenuItem( + B_TRANSLATE_WITH_CONTEXT("none", "Groups list"), + new BMessage(M_GROUP_MENU))); + item->SetEnabled(false); + } + + fGroups->SetTargetForItems(this); +} + + +void +PersonView::CreateFile(const entry_ref* ref) +{ + delete fFile; + fFile = new BFile(ref, B_READ_WRITE); + Save(); +} + + +bool +PersonView::IsSaved() const +{ + for (int32 i = fControls.CountItems() - 1; i >= 0; i--) { + if (fControls.ItemAt(i)->HasChanged()) + return false; + } + + return true; +} + + +void +PersonView::Save() +{ + int32 count = fControls.CountItems(); + for (int32 i = 0; i < count; i++) { + AttributeTextControl* control = fControls.ItemAt(i); + const char* value = control->Text(); + fFile->WriteAttr(control->Attribute().String(), B_STRING_TYPE, 0, + value, strlen(value) + 1); + control->Update(); + } +} + + +const char* +PersonView::AttributeValue(const char* attribute) const +{ + for (int32 i = fControls.CountItems() - 1; i >= 0; i--) { + if (fControls.ItemAt(i)->Attribute() == attribute) + return fControls.ItemAt(i)->Text(); + } + + return ""; +} + + +void +PersonView::SetAttribute(const char* attribute, bool update) +{ + char* value = NULL; + attr_info info; + if (fFile != NULL && fFile->GetAttrInfo(attribute, &info) == B_OK) { + value = (char*)calloc(info.size, 1); + fFile->ReadAttr(attribute, B_STRING_TYPE, 0, value, info.size); + } + + SetAttribute(attribute, value, update); + + free(value); +} + + +void +PersonView::SetAttribute(const char* attribute, const char* value, + bool update) +{ + if (!LockLooper()) + return; + + AttributeTextControl* control = NULL; + for (int32 i = fControls.CountItems() - 1; i >= 0; i--) { + if (fControls.ItemAt(i)->Attribute() == attribute) { + control = fControls.ItemAt(i); + break; + } + } + + if (control == NULL) + return; + + if (update) { + control->SetText(value); + control->Update(); + } else { + BTextView* text = control->TextView(); + + int32 start, end; + text->GetSelection(&start, &end); + if (start != end) { + text->Delete(); + text->Insert(value); + } else if ((end = text->TextLength())) { + text->Select(end, end); + text->Insert(","); + text->Insert(value); + text->Select(text->TextLength(), text->TextLength()); + } else + control->SetText(value); + } + + UnlockLooper(); +} + + +bool +PersonView::IsTextSelected() const +{ + for (int32 i = fControls.CountItems() - 1; i >= 0; i--) { + BTextView* text = fControls.ItemAt(i)->TextView(); + + int32 start, end; + text->GetSelection(&start, &end); + if (start != end) + return true; + } + return false; +} Copied: haiku/trunk/src/apps/people/PersonView.h (from rev 40461, haiku/trunk/src/apps/people/PeopleView.h) =================================================================== --- haiku/trunk/src/apps/people/PersonView.h (rev 0) +++ haiku/trunk/src/apps/people/PersonView.h 2011-02-12 17:40:58 UTC (rev 40462) @@ -0,0 +1,69 @@ +/* + * Copyright 2010, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT license. + * + * Authors: + * Robert Polic + * Stephan Aßmus <superstippi@xxxxxx> + * + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + */ +#ifndef PERSON_VIEW_H +#define PERSON_VIEW_H + + +#include <GridView.h> +#include <ObjectList.h> +#include <String.h> + + +class AttributeTextControl; +class BFile; +class BPopUpMenu; + +enum { + M_SAVE = 'save', + M_REVERT = 'rvrt', + M_SELECT = 'slct', + M_GROUP_MENU = 'grmn', +}; + + +class PersonView : public BGridView { +public: + PersonView(const char* name, + const char* categoryAttribute, + const entry_ref* ref); + virtual ~PersonView(); + + virtual void MakeFocus(bool focus = true); + virtual void MessageReceived(BMessage* message); + + void AddAttribute(const char* label, + const char* attribute); + + void BuildGroupMenu(); + + void CreateFile(const entry_ref* ref); + + bool IsSaved() const; + void Save(); + + const char* AttributeValue(const char* attribute) const; + void SetAttribute(const char* attribute, bool update); + void SetAttribute(const char* attribute, + const char* value, bool update); + + bool IsTextSelected() const; + +private: + BFile* fFile; + BPopUpMenu* fGroups; + typedef BObjectList<AttributeTextControl> AttributeList; + AttributeList fControls; + + BString fCategoryAttribute; +}; + +#endif // PERSON_VIEW_H Copied: haiku/trunk/src/apps/people/PersonWindow.cpp (from rev 40461, haiku/trunk/src/apps/people/PeopleWindow.cpp) =================================================================== --- haiku/trunk/src/apps/people/PersonWindow.cpp (rev 0) +++ haiku/trunk/src/apps/people/PersonWindow.cpp 2011-02-12 17:40:58 UTC (rev 40462) @@ -0,0 +1,410 @@ +/* + * Copyright 2005-2010, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT license. + * + * Authors: + * Robert Polic + * Stephan Aßmus <superstippi@xxxxxx> + * + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + */ + +#include "PersonWindow.h" + +#include <stdio.h> +#include <string.h> + +#include <Alert.h> +#include <Catalog.h> +#include <Clipboard.h> +#include <ControlLook.h> +#include <FilePanel.h> +#include <FindDirectory.h> +#include <Font.h> +#include <LayoutBuilder.h> +#include <Locale.h> +#include <MenuBar.h> +#include <MenuItem.h> +#include <NodeInfo.h> +#include <NodeMonitor.h> +#include <Path.h> +#include <String.h> +#include <TextView.h> +#include <Volume.h> + +#include "PeopleApp.h" +#include "PersonView.h" + + +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "People" + + +PersonWindow::PersonWindow(BRect frame, const char* title, + const char* nameAttribute, const char* categoryAttribute, + const entry_ref* ref) + : + BWindow(frame, title, B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE + | B_AUTO_UPDATE_SIZE_LIMITS), + fPanel(NULL), + fNameAttribute(nameAttribute) +{ + BMenu* menu; + BMenuItem* item; + + BMenuBar* menuBar = new BMenuBar(""); + menu = new BMenu(B_TRANSLATE("File")); + menu->AddItem(item = new BMenuItem( + B_TRANSLATE("New person" B_UTF8_ELLIPSIS), + new BMessage(M_NEW), 'N')); + item->SetTarget(be_app); + menu->AddItem(new BMenuItem(B_TRANSLATE("Close"), + new BMessage(B_QUIT_REQUESTED), 'W')); + menu->AddSeparatorItem(); + menu->AddItem(fSave = new BMenuItem(B_TRANSLATE("Save"), + new BMessage(M_SAVE), 'S')); + fSave->SetEnabled(FALSE); + menu->AddItem(new BMenuItem( + B_TRANSLATE("Save as"B_UTF8_ELLIPSIS), + new BMessage(M_SAVE_AS))); + menu->AddItem(fRevert = new BMenuItem(B_TRANSLATE("Revert"), + new BMessage(M_REVERT), 'R')); + fRevert->SetEnabled(FALSE); + menu->AddSeparatorItem(); + item = new BMenuItem(B_TRANSLATE("Quit"), + new BMessage(B_QUIT_REQUESTED), 'Q'); + item->SetTarget(be_app); + menu->AddItem(item); + menuBar->AddItem(menu); + + menu = new BMenu(B_TRANSLATE("Edit")); + menu->AddItem(fUndo = new BMenuItem(B_TRANSLATE("Undo"), + new BMessage(B_UNDO), 'Z')); + fUndo->SetEnabled(false); + menu->AddSeparatorItem(); + menu->AddItem(fCut = new BMenuItem(B_TRANSLATE("Cut"), + new BMessage(B_CUT), 'X')); + menu->AddItem(fCopy = new BMenuItem(B_TRANSLATE("Copy"), + new BMessage(B_COPY), 'C')); + menu->AddItem(fPaste = new BMenuItem(B_TRANSLATE("Paste"), + new BMessage(B_PASTE), 'V')); + BMenuItem* selectAllItem = new BMenuItem(B_TRANSLATE("Select all"), + new BMessage(M_SELECT), 'A'); + menu->AddItem(selectAllItem); + menuBar->AddItem(menu); + + if (ref != NULL) { + SetTitle(ref->name); + _SetToRef(new entry_ref(*ref)); + } else + _SetToRef(NULL); + + fView = new PersonView("PeopleView", categoryAttribute, fRef); + + BLayoutBuilder::Group<>(this, B_VERTICAL, 0) + .SetInsets(0, 0, 0, 0) + .Add(menuBar) + .Add(fView); + + fRevert->SetTarget(fView); + selectAllItem->SetTarget(fView); +} + + +PersonWindow::~PersonWindow() +{ + _SetToRef(NULL); +} + + +void +PersonWindow::MenusBeginning() +{ + bool enabled = !fView->IsSaved(); + fSave->SetEnabled(enabled); + fRevert->SetEnabled(enabled); + + bool isRedo = false; + undo_state state = ((BTextView*)CurrentFocus())->UndoState(&isRedo); + fUndo->SetEnabled(state != B_UNDO_UNAVAILABLE); + + if (isRedo) + fUndo->SetLabel(B_TRANSLATE("Redo")); + else + fUndo->SetLabel(B_TRANSLATE("Undo")); + + enabled = fView->IsTextSelected(); + fCut->SetEnabled(enabled); + fCopy->SetEnabled(enabled); + + be_clipboard->Lock(); + fPaste->SetEnabled(be_clipboard->Data()->HasData("text/plain", B_MIME_TYPE)); + be_clipboard->Unlock(); + + fView->BuildGroupMenu(); +} + + +void +PersonWindow::MessageReceived(BMessage* msg) +{ + char str[256]; + BDirectory directory; + BEntry entry; + BFile file; + BNodeInfo *node; + + switch (msg->what) { + case M_SAVE: + if (!fRef) { + SaveAs(); + break; + } + // supposed to fall through + case M_REVERT: + case M_SELECT: + fView->MessageReceived(msg); + break; + + case M_SAVE_AS: + SaveAs(); + break; + + case B_SAVE_REQUESTED: + { + entry_ref dir; + if (msg->FindRef("directory", &dir) == B_OK) { + const char* name = NULL; + msg->FindString("name", &name); + directory.SetTo(&dir); + if (directory.InitCheck() == B_NO_ERROR) { + directory.CreateFile(name, &file); + if (file.InitCheck() == B_NO_ERROR) { + node = new BNodeInfo(&file); + node->SetType("application/x-person"); + delete node; + + directory.FindEntry(name, &entry); + entry.GetRef(&dir); + _SetToRef(new entry_ref(dir)); + SetTitle(fRef->name); + fView->CreateFile(fRef); + } + else { + sprintf(str, B_TRANSLATE("Could not create %s."), name); + (new BAlert("", str, B_TRANSLATE("Sorry")))->Go(); + } + } + } + break; + } + + case B_NODE_MONITOR: + { + int32 opcode; + if (msg->FindInt32("opcode", &opcode) == B_OK) { + switch (opcode) { + case B_ENTRY_REMOVED: + // We lost our file. Close the window. + PostMessage(B_QUIT_REQUESTED); + break; + + case B_ENTRY_MOVED: + { + // We may have renamed our entry. Obtain relevant data + // from message. + BString name; + msg->FindString("name", &name); + + int64 directory; + msg->FindInt64("to directory", &directory); + + int32 device; + msg->FindInt32("device", &device); + + // Update our ref. + delete fRef; + fRef = new entry_ref(device, directory, name.String()); + + // And our window title. + SetTitle(name); + + // If moved to Trash, close window. + BVolume volume(device); + BPath trash; + find_directory(B_TRASH_DIRECTORY, &trash, false, + &volume); + BPath folder(fRef); + folder.GetParent(&folder); + if (folder == trash) + PostMessage(B_QUIT_REQUESTED); + + break; + } + + case B_ATTR_CHANGED: + { + // An attribute was updated. + BString attr; + if (msg->FindString("attr", &attr) == B_OK) + fView->SetAttribute(attr.String(), true); + break; + } + } + } + break; + } + + default: + BWindow::MessageReceived(msg); + } +} + + +bool +PersonWindow::QuitRequested() +{ + status_t result; + + if (!fView->IsSaved()) { + result = (new BAlert("", B_TRANSLATE("Save changes before quitting?"), + B_TRANSLATE("Cancel"), B_TRANSLATE("Quit"), + B_TRANSLATE("Save")))->Go(); + if (result == 2) { + if (fRef) + fView->Save(); + else { + SaveAs(); + return false; + } + } else if (result == 0) + return false; + } + + delete fPanel; + + BMessage message(M_WINDOW_QUITS); + message.AddRect("frame", Frame()); + if (be_app->Lock()) { + be_app->PostMessage(&message); + be_app->Unlock(); + } + + return true; +} + + +void +PersonWindow::Show() +{ + fView->MakeFocus(); + BWindow::Show(); +} + + +void +PersonWindow::AddAttribute(const char* label, const char* attribute) +{ + fView->AddAttribute(label, attribute); +} + + +void +PersonWindow::SaveAs() +{ + char name[B_FILE_NAME_LENGTH]; + _GetDefaultFileName(name); + + if (fPanel == NULL) { + BMessenger target(this); + fPanel = new BFilePanel(B_SAVE_PANEL, &target); + + BPath path; + find_directory(B_USER_DIRECTORY, &path, true); + + BDirectory dir; + dir.SetTo(path.Path()); + + BEntry entry; + if (dir.FindEntry("people", &entry) == B_OK + || (dir.CreateDirectory("people", &dir) == B_OK + && dir.GetEntry(&entry) == B_OK)) { + fPanel->SetPanelDirectory(&entry); + } + } + + if (fPanel->Window()->Lock()) { + fPanel->SetSaveText(name); + if (fPanel->Window()->IsHidden()) + fPanel->Window()->Show(); + else + fPanel->Window()->Activate(); + fPanel->Window()->Unlock(); + } +} + + +bool +PersonWindow::RefersPersonFile(const entry_ref& ref) const +{ + if (fRef == NULL) + return false; + return *fRef == ref; +} + + +void +PersonWindow::_GetDefaultFileName(char* name) +{ + strncpy(name, fView->AttributeValue(fNameAttribute), B_FILE_NAME_LENGTH); + while (*name) { + if (*name == '/') + *name = '-'; + name++; + } +} + + +void +PersonWindow::_SetToRef(entry_ref* ref) +{ + if (fRef != NULL) { + _WatchChanges(false); + delete fRef; + } + + fRef = ref; + + _WatchChanges(true); +} + + +void +PersonWindow::_WatchChanges(bool enable) +{ + if (fRef == NULL) + return; + + node_ref nodeRef; + + BNode node(fRef); + node.GetNodeRef(&nodeRef); + + uint32 flags; + BString action; + + if (enable) { + // Start watching. + flags = B_WATCH_ALL; + action = "starting"; + } else { + // Stop watching. + flags = B_STOP_WATCHING; + action = "stoping"; + } + + if (watch_node(&nodeRef, flags, this) != B_OK) { + printf("Error %s node monitor.\n", action.String()); + } +} Copied: haiku/trunk/src/apps/people/PersonWindow.h (from rev 40461, haiku/trunk/src/apps/people/PeopleWindow.h) =================================================================== --- haiku/trunk/src/apps/people/PersonWindow.h (rev 0) +++ haiku/trunk/src/apps/people/PersonWindow.h 2011-02-12 17:40:58 UTC (rev 40462) @@ -0,0 +1,71 @@ +/* + * Copyright 2010, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT license. + * + * Authors: + * Robert Polic + * + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + */ +#ifndef PERSON_WINDOW_H +#define PERSON_WINDOW_H + + +#include <String.h> +#include <Window.h> + + +#define TITLE_BAR_HEIGHT 25 +#define WIND_WIDTH 321 +#define WIND_HEIGHT 340 + + +class PersonView; +class BFilePanel; [... truncated: 47 lines follow ...]