Add a new feature to People app: a picture can now be stored in Person file,

besides attributes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40647 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin
2011-02-23 19:31:28 +00:00
parent 7a9ea6df3b
commit 84627497fb
5 changed files with 115 additions and 39 deletions
+11 -6
View File
@@ -1,20 +1,25 @@
SubDir HAIKU_TOP src apps people ; SubDir HAIKU_TOP src apps people ;
UseLibraryHeaders icon ;
UsePrivateHeaders shared ; UsePrivateHeaders shared ;
Application People : main.cpp Application People :
main.cpp
AttributeTextControl.cpp AttributeTextControl.cpp
PeopleApp.cpp PeopleApp.cpp
PersonView.cpp PersonView.cpp
PersonWindow.cpp PersonWindow.cpp
: libbe.so libtracker.so $(TARGET_LIBSUPC++) $(HAIKU_LOCALE_LIBS) PictureView.cpp
: libicon.a be tracker translation
$(TARGET_LIBSUPC++) $(HAIKU_LOCALE_LIBS)
: People.rdef : People.rdef
; ;
DoCatalogs People : DoCatalogs People :
x-vnd.Be-PEPL x-vnd.Be-PEPL
: :
PeopleApp.cpp PeopleApp.cpp
PersonView.cpp PersonView.cpp
PersonWindow.cpp PersonWindow.cpp
# PictureView.cpp
; ;
+74 -11
View File
@@ -17,6 +17,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <BitmapStream.h>
#include <Catalog.h> #include <Catalog.h>
#include <fs_attr.h> #include <fs_attr.h>
#include <Box.h> #include <Box.h>
@@ -27,10 +28,13 @@
#include <MenuItem.h> #include <MenuItem.h>
#include <PopUpMenu.h> #include <PopUpMenu.h>
#include <Query.h> #include <Query.h>
#include <TranslationUtils.h>
#include <Translator.h>
#include <VolumeRoster.h> #include <VolumeRoster.h>
#include <Window.h> #include <Window.h>
#include "AttributeTextControl.h" #include "AttributeTextControl.h"
#include "PictureView.h"
#undef B_TRANSLATE_CONTEXT #undef B_TRANSLATE_CONTEXT
@@ -43,16 +47,27 @@ PersonView::PersonView(const char* name, const char* categoryAttribute,
BGridView(), BGridView(),
fGroups(NULL), fGroups(NULL),
fControls(20, false), fControls(20, false),
fCategoryAttribute(categoryAttribute) fCategoryAttribute(categoryAttribute),
fPictureView(NULL)
{ {
SetName(name); SetName(name);
SetFlags(Flags() | B_WILL_DRAW);
if (ref) if (ref)
fFile = new BFile(ref, O_RDWR); fFile = new BFile(ref, O_RDWR);
else else
fFile = NULL; fFile = NULL;
float spacing = be_control_look->DefaultItemSpacing(); float spacing = be_control_look->DefaultItemSpacing();
GridLayout()->SetInsets(spacing, spacing, spacing, spacing); BGridLayout* layout = GridLayout();
layout->SetInsets(spacing, spacing, spacing, spacing);
// Add picture "field"
fPictureView = new PictureView(96, 112, ref);
layout->AddView(fPictureView, 0, 0, 1, 5);
layout->ItemAt(0, 0)->SetExplicitAlignment(
BAlignment(B_ALIGN_CENTER, B_ALIGN_TOP));
} }
@@ -65,13 +80,19 @@ PersonView::~PersonView()
void void
PersonView::AddAttribute(const char* label, const char* attribute) PersonView::AddAttribute(const char* label, const char* attribute)
{ {
// TODO: We could check if this attribute has already been added. // Check if this attribute has already been added.
AttributeTextControl* control = NULL;
for (int32 i = fControls.CountItems() - 1; i >= 0; i--) {
if (fControls.ItemAt(i)->Attribute() == attribute) {
return;
}
}
AttributeTextControl* control = new AttributeTextControl(label, attribute); control = new AttributeTextControl(label, attribute);
fControls.AddItem(control); fControls.AddItem(control);
BGridLayout* layout = GridLayout(); BGridLayout* layout = GridLayout();
int32 row = layout->CountRows(); int32 row = fControls.CountItems();
if (fCategoryAttribute == attribute) { if (fCategoryAttribute == attribute) {
// Special case the category attribute. The Group popup field will // Special case the category attribute. The Group popup field will
@@ -82,13 +103,13 @@ PersonView::AddAttribute(const char* label, const char* attribute)
BMenuField* field = new BMenuField("", "", fGroups); BMenuField* field = new BMenuField("", "", fGroups);
field->SetEnabled(true); field->SetEnabled(true);
layout->AddView(field, 0, row); layout->AddView(field, 1, row);
control->SetLabel(""); control->SetLabel("");
layout->AddView(control, 1, row); layout->AddView(control, 2, row);
} else { } else {
layout->AddItem(control->CreateLabelLayoutItem(), 0, row); layout->AddItem(control->CreateLabelLayoutItem(), 1, row);
layout->AddItem(control->CreateTextViewLayoutItem(), 1, row); layout->AddItem(control->CreateTextViewLayoutItem(), 2, row);
} }
SetAttribute(attribute, true); SetAttribute(attribute, true);
@@ -114,6 +135,9 @@ PersonView::MessageReceived(BMessage* msg)
break; break;
case M_REVERT: case M_REVERT:
if (fPictureView)
fPictureView->Revert();
for (int32 i = fControls.CountItems() - 1; i >= 0; i--) for (int32 i = fControls.CountItems() - 1; i >= 0; i--)
fControls.ItemAt(i)->Revert(); fControls.ItemAt(i)->Revert();
break; break;
@@ -140,6 +164,21 @@ PersonView::MessageReceived(BMessage* msg)
} }
void
PersonView::Draw(BRect updateRect)
{
if (!fPictureView)
return;
// Draw a alert/get info-like strip
BRect stripeRect = Bounds();
float pictureWidth = /*fPictureView->Bounds().Width() */ 96;
stripeRect.right = 10 + pictureWidth / 2;
SetHighColor(tint_color(ViewColor(), B_DARKEN_1_TINT));
FillRect(stripeRect);
}
void void
PersonView::BuildGroupMenu() PersonView::BuildGroupMenu()
{ {
@@ -213,7 +252,7 @@ PersonView::BuildGroupMenu()
if (count == 0) { if (count == 0) {
fGroups->AddItem(item = new BMenuItem( fGroups->AddItem(item = new BMenuItem(
B_TRANSLATE_WITH_CONTEXT("none", "Groups list"), B_TRANSLATE_WITH_CONTEXT("none", "Groups list"),
new BMessage(M_GROUP_MENU))); new BMessage(M_GROUP_MENU)));
item->SetEnabled(false); item->SetEnabled(false);
} }
@@ -234,6 +273,9 @@ PersonView::CreateFile(const entry_ref* ref)
bool bool
PersonView::IsSaved() const PersonView::IsSaved() const
{ {
if (fPictureView && fPictureView->HasChanged())
return false;
for (int32 i = fControls.CountItems() - 1; i >= 0; i--) { for (int32 i = fControls.CountItems() - 1; i >= 0; i--) {
if (fControls.ItemAt(i)->HasChanged()) if (fControls.ItemAt(i)->HasChanged())
return false; return false;
@@ -254,6 +296,19 @@ PersonView::Save()
value, strlen(value) + 1); value, strlen(value) + 1);
control->Update(); control->Update();
} }
// Write the picture, if any, in the person file content
if (fPictureView) {
// trim previous content
fFile->Seek(0, SEEK_SET);
fFile->SetSize(0);
if (fPictureView->Bitmap()) {
BBitmapStream stream(fPictureView->Bitmap());
BTranslatorRoster* roster = BTranslatorRoster::Default();
roster->Translate(&stream, NULL, NULL, fFile, B_PNG_FORMAT,
B_TRANSLATOR_BITMAP);
}
}
} }
@@ -264,7 +319,7 @@ PersonView::AttributeValue(const char* attribute) const
if (fControls.ItemAt(i)->Attribute() == attribute) if (fControls.ItemAt(i)->Attribute() == attribute)
return fControls.ItemAt(i)->Text(); return fControls.ItemAt(i)->Text();
} }
return ""; return "";
} }
@@ -327,6 +382,14 @@ PersonView::SetAttribute(const char* attribute, const char* value,
} }
void
PersonView::UpdatePicture(const entry_ref* ref)
{
if (fPictureView)
fPictureView->Update(ref);
}
bool bool
PersonView::IsTextSelected() const PersonView::IsTextSelected() const
{ {
+5
View File
@@ -21,6 +21,7 @@
class AttributeTextControl; class AttributeTextControl;
class BFile; class BFile;
class BPopUpMenu; class BPopUpMenu;
class PictureView;
enum { enum {
M_SAVE = 'save', M_SAVE = 'save',
@@ -39,6 +40,7 @@ public:
virtual void MakeFocus(bool focus = true); virtual void MakeFocus(bool focus = true);
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
virtual void Draw(BRect updateRect);
void AddAttribute(const char* label, void AddAttribute(const char* label,
const char* attribute); const char* attribute);
@@ -55,6 +57,8 @@ public:
void SetAttribute(const char* attribute, void SetAttribute(const char* attribute,
const char* value, bool update); const char* value, bool update);
void UpdatePicture(const entry_ref* ref);
bool IsTextSelected() const; bool IsTextSelected() const;
private: private:
@@ -64,6 +68,7 @@ private:
AttributeList fControls; AttributeList fControls;
BString fCategoryAttribute; BString fCategoryAttribute;
PictureView* fPictureView;
}; };
#endif // PERSON_VIEW_H #endif // PERSON_VIEW_H
+24 -21
View File
@@ -62,7 +62,7 @@ PersonWindow::PersonWindow(BRect frame, const char* title,
menu->AddItem(new BMenuItem(B_TRANSLATE("Close"), menu->AddItem(new BMenuItem(B_TRANSLATE("Close"),
new BMessage(B_QUIT_REQUESTED), 'W')); new BMessage(B_QUIT_REQUESTED), 'W'));
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menu->AddItem(fSave = new BMenuItem(B_TRANSLATE("Save"), menu->AddItem(fSave = new BMenuItem(B_TRANSLATE("Save"),
new BMessage(M_SAVE), 'S')); new BMessage(M_SAVE), 'S'));
fSave->SetEnabled(FALSE); fSave->SetEnabled(FALSE);
menu->AddItem(new BMenuItem( menu->AddItem(new BMenuItem(
@@ -72,28 +72,28 @@ PersonWindow::PersonWindow(BRect frame, const char* title,
new BMessage(M_REVERT), 'R')); new BMessage(M_REVERT), 'R'));
fRevert->SetEnabled(FALSE); fRevert->SetEnabled(FALSE);
menu->AddSeparatorItem(); menu->AddSeparatorItem();
item = new BMenuItem(B_TRANSLATE("Quit"), item = new BMenuItem(B_TRANSLATE("Quit"),
new BMessage(B_QUIT_REQUESTED), 'Q'); new BMessage(B_QUIT_REQUESTED), 'Q');
item->SetTarget(be_app); item->SetTarget(be_app);
menu->AddItem(item); menu->AddItem(item);
menuBar->AddItem(menu); menuBar->AddItem(menu);
menu = new BMenu(B_TRANSLATE("Edit")); menu = new BMenu(B_TRANSLATE("Edit"));
menu->AddItem(fUndo = new BMenuItem(B_TRANSLATE("Undo"), menu->AddItem(fUndo = new BMenuItem(B_TRANSLATE("Undo"),
new BMessage(B_UNDO), 'Z')); new BMessage(B_UNDO), 'Z'));
fUndo->SetEnabled(false); fUndo->SetEnabled(false);
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menu->AddItem(fCut = new BMenuItem(B_TRANSLATE("Cut"), menu->AddItem(fCut = new BMenuItem(B_TRANSLATE("Cut"),
new BMessage(B_CUT), 'X')); new BMessage(B_CUT), 'X'));
menu->AddItem(fCopy = new BMenuItem(B_TRANSLATE("Copy"), menu->AddItem(fCopy = new BMenuItem(B_TRANSLATE("Copy"),
new BMessage(B_COPY), 'C')); new BMessage(B_COPY), 'C'));
menu->AddItem(fPaste = new BMenuItem(B_TRANSLATE("Paste"), menu->AddItem(fPaste = new BMenuItem(B_TRANSLATE("Paste"),
new BMessage(B_PASTE), 'V')); new BMessage(B_PASTE), 'V'));
BMenuItem* selectAllItem = new BMenuItem(B_TRANSLATE("Select all"), BMenuItem* selectAllItem = new BMenuItem(B_TRANSLATE("Select all"),
new BMessage(M_SELECT), 'A'); new BMessage(M_SELECT), 'A');
menu->AddItem(selectAllItem); menu->AddItem(selectAllItem);
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menu->AddItem(item = new BMenuItem(B_TRANSLATE("Configure attributes"), menu->AddItem(item = new BMenuItem(B_TRANSLATE("Configure attributes"),
new BMessage(M_CONFIGURE_ATTRIBUTES), 'F')); new BMessage(M_CONFIGURE_ATTRIBUTES), 'F'));
item->SetTarget(be_app); item->SetTarget(be_app);
menuBar->AddItem(menu); menuBar->AddItem(menu);
@@ -203,7 +203,7 @@ PersonWindow::MessageReceived(BMessage* msg)
} }
break; break;
} }
case B_NODE_MONITOR: case B_NODE_MONITOR:
{ {
int32 opcode; int32 opcode;
@@ -213,7 +213,7 @@ PersonWindow::MessageReceived(BMessage* msg)
// We lost our file. Close the window. // We lost our file. Close the window.
PostMessage(B_QUIT_REQUESTED); PostMessage(B_QUIT_REQUESTED);
break; break;
case B_ENTRY_MOVED: case B_ENTRY_MOVED:
{ {
// We may have renamed our entry. Obtain relevant data // We may have renamed our entry. Obtain relevant data
@@ -223,14 +223,14 @@ PersonWindow::MessageReceived(BMessage* msg)
int64 directory; int64 directory;
msg->FindInt64("to directory", &directory); msg->FindInt64("to directory", &directory);
int32 device; int32 device;
msg->FindInt32("device", &device); msg->FindInt32("device", &device);
// Update our ref. // Update our ref.
delete fRef; delete fRef;
fRef = new entry_ref(device, directory, name.String()); fRef = new entry_ref(device, directory, name.String());
// And our window title. // And our window title.
SetTitle(name); SetTitle(name);
@@ -246,7 +246,7 @@ PersonWindow::MessageReceived(BMessage* msg)
break; break;
} }
case B_ATTR_CHANGED: case B_ATTR_CHANGED:
{ {
// An attribute was updated. // An attribute was updated.
@@ -254,7 +254,10 @@ PersonWindow::MessageReceived(BMessage* msg)
if (msg->FindString("attr", &attr) == B_OK) if (msg->FindString("attr", &attr) == B_OK)
fView->SetAttribute(attr.String(), true); fView->SetAttribute(attr.String(), true);
break; break;
} }
case B_STAT_CHANGED:
fView->UpdatePicture(fRef);
break;
} }
} }
break; break;
@@ -273,7 +276,7 @@ PersonWindow::QuitRequested()
if (!fView->IsSaved()) { if (!fView->IsSaved()) {
result = (new BAlert("", B_TRANSLATE("Save changes before quitting?"), result = (new BAlert("", B_TRANSLATE("Save changes before quitting?"),
B_TRANSLATE("Cancel"), B_TRANSLATE("Quit"), B_TRANSLATE("Cancel"), B_TRANSLATE("Quit"),
B_TRANSLATE("Save")))->Go(); B_TRANSLATE("Save")))->Go();
if (result == 2) { if (result == 2) {
if (fRef) if (fRef)
@@ -294,7 +297,7 @@ PersonWindow::QuitRequested()
be_app->PostMessage(&message); be_app->PostMessage(&message);
be_app->Unlock(); be_app->Unlock();
} }
return true; return true;
} }
@@ -345,7 +348,7 @@ PersonWindow::SaveAs()
else else
fPanel->Window()->Activate(); fPanel->Window()->Activate();
fPanel->Window()->Unlock(); fPanel->Window()->Unlock();
} }
} }
@@ -391,10 +394,10 @@ PersonWindow::_WatchChanges(bool enable)
return; return;
node_ref nodeRef; node_ref nodeRef;
BNode node(fRef); BNode node(fRef);
node.GetNodeRef(&nodeRef); node.GetNodeRef(&nodeRef);
uint32 flags; uint32 flags;
BString action; BString action;
@@ -407,7 +410,7 @@ PersonWindow::_WatchChanges(bool enable)
flags = B_STOP_WATCHING; flags = B_STOP_WATCHING;
action = "stoping"; action = "stoping";
} }
if (watch_node(&nodeRef, flags, this) != B_OK) { if (watch_node(&nodeRef, flags, this) != B_OK) {
printf("Error %s node monitor.\n", action.String()); printf("Error %s node monitor.\n", action.String());
} }
+1 -1
View File
@@ -17,7 +17,7 @@
#define TITLE_BAR_HEIGHT 25 #define TITLE_BAR_HEIGHT 25
#define WIND_WIDTH 321 #define WIND_WIDTH 420
#define WIND_HEIGHT 340 #define WIND_HEIGHT 340