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
+8 -3
View File
@@ -1,15 +1,19 @@
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
@@ -17,4 +21,5 @@ DoCatalogs People :
PeopleApp.cpp PeopleApp.cpp
PersonView.cpp PersonView.cpp
PersonWindow.cpp PersonWindow.cpp
# PictureView.cpp
; ;
+72 -9
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()
{ {
@@ -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);
}
}
} }
@@ -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
+3
View File
@@ -255,6 +255,9 @@ PersonWindow::MessageReceived(BMessage* msg)
fView->SetAttribute(attr.String(), true); fView->SetAttribute(attr.String(), true);
break; break;
} }
case B_STAT_CHANGED:
fView->UpdatePicture(fRef);
break;
} }
} }
break; break;
+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