Missing from previous commit. The files for notifications are quite scattered all around...

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43115 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adrien Destugues
2011-11-02 15:08:00 +00:00
parent 4ec6c3a042
commit 279ca67d6e
7 changed files with 278 additions and 138 deletions
+3 -5
View File
@@ -19,12 +19,12 @@
class BMessage;
class NotificationReceived;
typedef std::map<BString, NotificationReceived*> notify_t;
typedef std::map<BString, NotificationReceived*> notification_t;
class AppUsage : public BFlattenable {
public:
AppUsage();
AppUsage(entry_ref ref, const char* name,
AppUsage(const char* name,
bool allow = true);
~AppUsage();
@@ -36,7 +36,6 @@ public:
virtual status_t Unflatten(type_code code, const void* buffer,
ssize_t numBytes);
entry_ref Ref();
const char* Name();
bool Allowed(const char* title, notification_type type);
bool Allowed();
@@ -45,10 +44,9 @@ public:
void AddNotification(NotificationReceived* notification);
private:
entry_ref fRef;
BString fName;
bool fAllow;
notify_t fNotifications;
notification_t fNotifications;
};
#endif // _APP_USAGE_H
@@ -12,12 +12,6 @@
// Messages
const uint32 kNotificationMessage = 'nssm';
// Notification layout
enum infoview_layout {
TitleAboveIcon = 0,
AllTextRightOfIcon = 1
};
// Settings constants
extern const char* kSettingsDirectory;
extern const char* kFiltersSettings;
@@ -40,6 +34,5 @@ extern const char* kLayoutName;
// Display default settings
const float kDefaultWidth = 300.0f;
const icon_size kDefaultIconSize = B_LARGE_ICON;
const infoview_layout kDefaultLayout = TitleAboveIcon;
#endif // _NOTIFICATIONS_H
+1
View File
@@ -17,6 +17,7 @@ if $(RUN_WITHOUT_APP_SERVER) != 0 {
SubDirC++Flags $(defines) ;
}
UseLibraryHeaders icon ;
UsePrivateHeaders shared app interface kernel notification ;
UsePrivateSystemHeaders ;
+273 -7
View File
@@ -4,7 +4,7 @@
*
* Authors:
* Pier Luigi Fiorini, [email protected]
* Stephan Aßmus <[email protected]>
* Stephan Aßmus, [email protected]
*/
@@ -15,19 +15,76 @@
#include <stdlib.h>
#include <string.h>
#include <notification/Notifications.h>
#include <Bitmap.h>
#include <Message.h>
BNotification::BNotification(notification_type type)
:
BArchivable(),
fInitStatus(B_OK),
fType(type),
fProgress(0),
fProgress(0.f),
fFile(NULL),
fBitmap(NULL)
{
}
BNotification::BNotification(BMessage* archive)
:
BArchivable(archive),
fInitStatus(B_OK),
fProgress(0.0f),
fFile(NULL),
fBitmap(NULL)
{
int32 type;
if (archive->FindInt32("_type", &type) == B_OK)
fType = (notification_type)type;
else
fInitStatus = B_ERROR;
BString group;
if (archive->FindString("_group", &group) == B_OK)
SetGroup(group);
BString title;
if (archive->FindString("_title", &title) == B_OK)
SetTitle(title);
BString content;
if (archive->FindString("_content", &content) == B_OK)
SetContent(content);
BString messageID;
if (archive->FindString("_messageID", &messageID) == B_OK)
SetMessageID(messageID);
float progress;
if (type == B_PROGRESS_NOTIFICATION
&& archive->FindFloat("_progress", &progress) == B_OK)
SetProgress(progress);
BString onClickApp;
if (archive->FindString("_onClickApp", &onClickApp) == B_OK)
SetOnClickApp(onClickApp);
entry_ref onClickFile;
if (archive->FindRef("_onClickFile", &onClickFile) == B_OK)
SetOnClickFile(&onClickFile);
status_t ret = B_OK;
BMessage icon;
if ((ret = archive->FindMessage("_icon", &icon)) == B_OK) {
BBitmap bitmap(&icon);
ret = bitmap.InitCheck();
if (ret == B_OK)
ret = SetIcon(&bitmap);
}
}
BNotification::~BNotification()
{
@@ -42,6 +99,106 @@ BNotification::~BNotification()
}
/*! \brief Returns initialization status.
*/
status_t
BNotification::InitCheck() const
{
return fInitStatus;
}
/*! \brief Returns a new BNotification object from @archive.
Returns a new BNotification object, allocated by new and created
with the version of the constructor that takes BMessage archive.
However, if the message doesn't contain an archived data for a
BNotification object, this method returns NULL.
\return BNotification object from @archive or NULL if it doesn't
contain a valid BNotification object.
*/
BArchivable*
BNotification::Instantiate(BMessage* archive)
{
if (validate_instantiation(archive, "BNotification"))
return new(std::nothrow) BNotification(archive);
return NULL;
}
/*! \brief Archives the BNotification in the BMessages @archive.
\sa BArchivable::Archive(), Instantiate() static function.
\return
- \c B_OK: Everything went fine.
- \c Other errors: Archiving has failed.
*/
status_t
BNotification::Archive(BMessage* archive, bool deep) const
{
status_t status = BArchivable::Archive(archive, deep);
if (status == B_OK)
status = archive->AddInt32("_type", (int32)fType);
if (status == B_OK && Group() != NULL)
status = archive->AddString("_group", Group());
if (status == B_OK && Title() != NULL)
status = archive->AddString("_title", Title());
if (status == B_OK && Content() != NULL)
status = archive->AddString("_content", Content());
if (status == B_OK && MessageID() != NULL)
status = archive->AddString("_messageID", MessageID());
if (status == B_OK && Type() == B_PROGRESS_NOTIFICATION)
status = archive->AddFloat("_progress", Progress());
if (status == B_OK && OnClickApp() != NULL)
status = archive->AddString("_onClickApp", OnClickApp());
if (status == B_OK && OnClickFile() != NULL)
status = archive->AddRef("_onClickFile", OnClickFile());
if (status == B_OK) {
for (int32 i = 0; i < CountOnClickRefs(); i++) {
status = archive->AddRef("_onClickRef", OnClickRefAt(i));
if (status != B_OK)
break;
}
}
if (status == B_OK) {
for (int32 i = 0; i < CountOnClickArgs(); i++) {
status = archive->AddString("_onClickArgv", OnClickArgAt(i));
if (status != B_OK)
break;
}
}
if (status == B_OK) {
const BBitmap* icon = Icon();
if (icon != NULL) {
BMessage iconArchive;
status = icon->Archive(&iconArchive);
if (status == B_OK)
archive->AddMessage("_icon", &iconArchive);
}
}
return status;
}
/*! \brief Notification's type.
\return A value of the notification_type enum that represents
notification type.
*/
notification_type
BNotification::Type() const
{
@@ -49,27 +206,45 @@ BNotification::Type() const
}
/*! \brief Returns notification's group.
\return Notification's group.
*/
const char*
BNotification::Application() const
BNotification::Group() const
{
return fAppName;
if (fGroup == "")
return NULL;
return fGroup;
}
/*! \brief Sets notification's group.
Notifications can be grouped together setting the same group.
*/
void
BNotification::SetApplication(const BString& app)
BNotification::SetGroup(const BString& group)
{
fAppName = app;
fGroup = group;
}
/*! \brief Returns notification's title.
\return Notification's title.
*/
const char*
BNotification::Title() const
{
if (fTitle == "")
return NULL;
return fTitle;
}
/*! \brief Set notification's title.
*/
void
BNotification::SetTitle(const BString& title)
{
@@ -77,13 +252,21 @@ BNotification::SetTitle(const BString& title)
}
/*! \brief Returns notification's message.
\return Notification's message.
*/
const char*
BNotification::Content() const
{
if (fContent == "")
return NULL;
return fContent;
}
/*! \brief Sets notification's message.
*/
void
BNotification::SetContent(const BString& content)
{
@@ -91,13 +274,21 @@ BNotification::SetContent(const BString& content)
}
/*! \brief Returns notification's message identifier.
\return Notification's message identifier.
*/
const char*
BNotification::MessageID() const
{
if (fID == "")
return NULL;
return fID;
}
/*! \brief Sets notification's message identifier.
*/
void
BNotification::SetMessageID(const BString& id)
{
@@ -105,23 +296,49 @@ BNotification::SetMessageID(const BString& id)
}
/*! \brief Returns progress information.
If notification's type is \c B_PROGRESS_NOTIFICATION, returns a value
between 0.0 and 1.0 that represent progress percentage.
If notification's type is not \c B_PROGRESS_NOTIFICATION, returns -1.
\return Percentage if notification's type is B_PROGRESS_NOTIFICATION
or otherwise -1.
*/
float
BNotification::Progress() const
{
if (fType != B_PROGRESS_NOTIFICATION)
return -1;
return fProgress;
}
/*! \brief Sets progress information.
Sets progress percentage, this information will be used only
if notification's type is \c B_PROGRESS_NOTIFICATION.
The value of @progress must be between 0.0 and 1.0.
*/
void
BNotification::SetProgress(float progress)
{
fProgress = progress;
if (progress < 0)
fProgress = 0;
else if (progress > 1)
fProgress = 1;
else
fProgress = progress;
}
const char*
BNotification::OnClickApp() const
{
if (fApp == "")
return NULL;
return fApp;
}
@@ -209,6 +426,10 @@ BNotification::OnClickArgAt(int32 index) const
}
/*! \brief Notification's icon.
\return Notification's icon.
*/
const BBitmap*
BNotification::Icon() const
{
@@ -216,6 +437,17 @@ BNotification::Icon() const
}
/*! \brief Sets notification's icon.
Sets notification's icon.
This method takes ownership of @icon.
\param icon Icon
\return
- \c B_OK: Everything went fine.
- \c B_NO_MEMORY: Allocation of @icon copy has failed.
- \c Other errors: Creation of @icon copy failed for some reason.
*/
status_t
BNotification::SetIcon(const BBitmap* icon)
{
@@ -231,3 +463,37 @@ BNotification::SetIcon(const BBitmap* icon)
fBitmap = NULL;
return B_OK;
}
/*! \brief Sends a notification to the notification_server.
The notification is delivered asynchronously to the notification_server,
which will display it according to its settings and filters.
\param timeout Microseconds after the message fades out.
\return
- \c B_OK: Everything went fine.
- \c B_BAD_PORT_ID: A connection to notification_server could not be
established or the server is not up and running anymore.
- \c Other errors: Building the message from the notification failed.
*/
status_t
BNotification::Send(bigtime_t timeout)
{
BMessage msg(kNotificationMessage);
// Archive notification
status_t ret = Archive(&msg);
// Custom time out
if (ret == B_OK && timeout > 0)
ret = msg.AddInt64("timeout", timeout);
// Send message
if (ret == B_OK) {
BMessenger server(kNotificationServerSignature);
ret = server.SendMessage(&msg);
}
return ret;
}
-79
View File
@@ -37,8 +37,6 @@
#include <Mime.h>
#include <Node.h>
#include <NodeInfo.h>
#include <Notification.h>
#include <notification/Notifications.h>
#include <OS.h>
#include <Path.h>
#include <Query.h>
@@ -1654,83 +1652,6 @@ BRoster::AddToRecentFolders(const entry_ref* folder, const char* appSig) const
DBG(OUT("WARNING: BRoster::AddToRecentDocuments() failed with error 0x%lx\n", err));
}
/*! \brief Sends a notification to the notification_server.
The notification is delivered asynchronously to the notification_server,
which will displays it according to its settings and filters.
\param notification Notification message.
\param timeout Seconds after the message fades out.
\return
- \c B_OK: Everything went fine.
- \c B_BAD_PORT_ID: A connection to notification_server could not be
established or the server is not up and running anymore.
- \c Other errors: Building the message from the notification failed.
*/
status_t
BRoster::Notify(const BNotification& notification, bigtime_t timeout) const
{
// TODO: Add BArchivable support to BNotification and use it here.
BMessage msg(kNotificationMessage);
status_t ret = msg.AddInt32("type", (int32)notification.Type());
if (ret == B_OK)
ret = msg.AddString("app", notification.Application());
if (ret == B_OK)
ret = msg.AddString("title", notification.Title());
if (ret == B_OK)
ret = msg.AddString("content", notification.Content());
if (ret == B_OK && notification.MessageID() != NULL)
ret = msg.AddString("messageID", notification.MessageID());
if (ret == B_OK && notification.Type() == B_PROGRESS_NOTIFICATION)
ret = msg.AddFloat("progress", notification.Progress());
if (ret == B_OK && notification.OnClickApp() != NULL)
ret = msg.AddString("onClickApp", notification.OnClickApp());
if (ret == B_OK && notification.OnClickFile() != NULL)
ret = msg.AddRef("onClickFile", notification.OnClickFile());
if (ret == B_OK) {
for (int32 i = 0; i < notification.CountOnClickRefs(); i++) {
ret = msg.AddRef("onClickRef", notification.OnClickRefAt(i));
if (ret != B_OK)
break;
}
}
if (ret == B_OK) {
for (int32 i = 0; i < notification.CountOnClickArgs(); i++) {
ret = msg.AddString("onClickArgv", notification.OnClickArgAt(i));
if (ret != B_OK)
break;
}
}
if (ret == B_OK) {
const BBitmap* icon = notification.Icon();
if (icon != NULL) {
BMessage archive;
ret = icon->Archive(&archive);
if (ret == B_OK)
ret = msg.AddMessage("icon", &archive);
}
}
// Custom time out
if (ret == B_OK && timeout > 0)
ret = msg.AddInt64("timeout", timeout);
// Send message
if (ret == B_OK) {
BMessenger server(kNotificationServerSignature);
ret = server.SendMessage(&msg);
}
return ret;
}
// #pragma mark - Private or reserved
+1 -38
View File
@@ -52,16 +52,6 @@ DisplayView::DisplayView(SettingsHost* host)
fIconSize->SetLabelFromMarked(true);
fIconSizeField = new BMenuField(B_TRANSLATE("Icon size:"), fIconSize);
// Title position
fTitlePosition = new BMenu("titlePosition");
fTitlePosition->AddItem(new BMenuItem(B_TRANSLATE("Above icon"),
new BMessage(kSettingChanged)));
fTitlePosition->AddItem(new BMenuItem(B_TRANSLATE("Right of icon"),
new BMessage(kSettingChanged)));
fTitlePosition->SetLabelFromMarked(true);
fTitlePositionField = new BMenuField(B_TRANSLATE("Title position:"),
fTitlePosition);
// Load settings
Load();
@@ -74,9 +64,7 @@ DisplayView::DisplayView(SettingsHost* host)
.Add(fWindowWidth->CreateTextViewLayoutItem(), 1, 0)
.Add(fIconSizeField->CreateLabelLayoutItem(), 0, 1)
.Add(fIconSizeField->CreateMenuBarLayoutItem(), 1, 1)
.Add(fTitlePositionField->CreateLabelLayoutItem(), 0, 2)
.Add(fTitlePositionField->CreateMenuBarLayoutItem(), 1, 2)
.Add(BSpaceLayoutItem::CreateGlue(), 0, 3, 2, 1)
.Add(BSpaceLayoutItem::CreateGlue(), 0, 2, 2, 1)
);
}
@@ -86,7 +74,6 @@ DisplayView::AttachedToWindow()
{
fWindowWidth->SetTarget(this);
fIconSize->SetTargetForItems(this);
fTitlePosition->SetTargetForItems(this);
}
@@ -150,25 +137,6 @@ DisplayView::Load()
if (item)
item->SetMarked(true);
infoview_layout layout;
if (settings.FindInt32(kLayoutName, &setting) != B_OK)
layout = kDefaultLayout;
else {
switch (setting) {
case 0:
layout = TitleAboveIcon;
break;
case 1:
layout = AllTextRightOfIcon;
break;
default:
layout = kDefaultLayout;
}
}
item = fTitlePosition->ItemAt(layout);
if (item)
item->SetMarked(true);
return B_OK;
}
@@ -199,11 +167,6 @@ DisplayView::Save()
}
settings.AddInt32(kIconSizeName, (int32)iconSize);
int32 layout = fTitlePosition->IndexOf(fTitlePosition->FindMarked());
if (layout == B_ERROR)
layout = (int32)kDefaultLayout;
settings.AddInt32(kLayoutName, layout);
// Save settings file
BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
status_t ret = settings.Flatten(&file);
@@ -28,8 +28,6 @@ private:
BTextControl* fWindowWidth;
BMenu* fIconSize;
BMenuField* fIconSizeField;
BMenu* fTitlePosition;
BMenuField* fTitlePositionField;
};