Adapted fortune filter to the new mail API.
This commit is contained in:
@@ -1,17 +1,21 @@
|
|||||||
/* ConfigView - the configuration view for the Fortune filter
|
/*
|
||||||
**
|
* Copyright 2004-2012, Haiku, Inc. All rights reserved.
|
||||||
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
|
* Copyright 2001, Dr. Zoidberg Enterprises. All rights reserved.
|
||||||
*/
|
*
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "ConfigView.h"
|
#include "ConfigView.h"
|
||||||
|
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <TextControl.h>
|
#include <LayoutBuilder.h>
|
||||||
#include <String.h>
|
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
|
#include <String.h>
|
||||||
|
#include <TextControl.h>
|
||||||
|
|
||||||
#include <FileConfigView.h>
|
|
||||||
|
using namespace BPrivate;
|
||||||
|
|
||||||
|
|
||||||
#undef B_TRANSLATION_CONTEXT
|
#undef B_TRANSLATION_CONTEXT
|
||||||
@@ -20,74 +24,45 @@
|
|||||||
|
|
||||||
ConfigView::ConfigView()
|
ConfigView::ConfigView()
|
||||||
:
|
:
|
||||||
BView(BRect(0, 0, 20, 20), "fortune_filter", B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
BView("fortune_filter", 0)
|
||||||
0)
|
|
||||||
{
|
{
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
// determine font height
|
fFileView = new MailFileConfigView(B_TRANSLATE("Fortune file:"),
|
||||||
font_height fontHeight;
|
"fortune_file", false, "", B_FILE_NODE);
|
||||||
GetFontHeight(&fontHeight);
|
fTagControl = new BTextControl("tag_line", B_TRANSLATE("Tag line:"),
|
||||||
float itemHeight = (int32)(fontHeight.ascent + fontHeight.descent
|
NULL, NULL);
|
||||||
+ fontHeight.leading) + 13;
|
|
||||||
|
|
||||||
BRect rect(5,4,250,25);
|
BLayoutBuilder::Group<>(this, B_VERTICAL)
|
||||||
rect.bottom = rect.top - 2 + itemHeight;
|
.Add(fFileView)
|
||||||
BMailFileConfigView *fview = new BMailFileConfigView(
|
.Add(fTagControl);
|
||||||
B_TRANSLATE("Fortune file:"), "fortune_file", false, "", B_FILE_NODE);
|
|
||||||
AddChild(fview);
|
|
||||||
|
|
||||||
rect.top = rect.bottom + 8;
|
|
||||||
rect.bottom = rect.top - 2 + itemHeight;
|
|
||||||
BTextControl * control = new BTextControl(rect, "tag_line",
|
|
||||||
B_TRANSLATE("Tag line:"), NULL, NULL);
|
|
||||||
control->SetDivider(control->StringWidth(control->Label()) + 6);
|
|
||||||
AddChild(control);
|
|
||||||
|
|
||||||
ResizeToPreferred();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ConfigView::SetTo(const BMessage *archive)
|
void
|
||||||
|
ConfigView::SetTo(const BMessage* archive)
|
||||||
{
|
{
|
||||||
BMailFileConfigView* control = (BMailFileConfigView*)FindView(
|
fFileView->SetTo(archive, NULL);
|
||||||
"fortune_file");
|
|
||||||
if (control != NULL)
|
|
||||||
control->SetTo(archive, NULL);
|
|
||||||
|
|
||||||
BString path = archive->FindString("tag_line");
|
BString path = archive->FindString("tag_line");
|
||||||
if (!archive->HasString("tag_line"))
|
if (!archive->HasString("tag_line"))
|
||||||
path = B_TRANSLATE("Fortune cookie says:\n\n");
|
path = B_TRANSLATE("Fortune cookie says:\n\n");
|
||||||
|
|
||||||
path.Truncate(path.Length() - 2);
|
path.Truncate(path.Length() - 2);
|
||||||
if (BTextControl *control = (BTextControl *)FindView("tag_line"))
|
fTagControl->SetText(path.String());
|
||||||
control->SetText(path.String());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t ConfigView::Archive(BMessage *into,bool) const
|
status_t
|
||||||
|
ConfigView::Archive(BMessage* into, bool /*deep*/) const
|
||||||
{
|
{
|
||||||
if (BMailFileConfigView *control = (BMailFileConfigView
|
fFileView->Archive(into);
|
||||||
*)FindView("fortune_file"))
|
|
||||||
{
|
BString line = fTagControl->Text();
|
||||||
control->Archive(into);
|
if (line != B_EMPTY_STRING)
|
||||||
}
|
line << "\n\n";
|
||||||
|
if (into->ReplaceString("tag_line", line.String()) != B_OK)
|
||||||
|
into->AddString("tag_line", line.String());
|
||||||
|
|
||||||
if (BTextControl *control = (BTextControl *)FindView("tag_line"))
|
|
||||||
{
|
|
||||||
BString line = control->Text();
|
|
||||||
if (line != B_EMPTY_STRING)
|
|
||||||
line << "\n\n";
|
|
||||||
if (into->ReplaceString("tag_line", line.String()) != B_OK)
|
|
||||||
into->AddString("tag_line", line.String());
|
|
||||||
}
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ConfigView::GetPreferredSize(float *width, float *height)
|
|
||||||
{
|
|
||||||
*width = 258;
|
|
||||||
*height = (ChildAt(0)->Bounds().Height() + 8) * CountChildren();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,27 @@
|
|||||||
#ifndef CONFIG_VIEW
|
/*
|
||||||
#define CONFIG_VIEW
|
* Copyright 2004-2012, Haiku, Inc. All rights reserved.
|
||||||
/* ConfigView - the configuration view for the Folder filter
|
* Copyright 2001, Dr. Zoidberg Enterprises. All rights reserved.
|
||||||
**
|
*
|
||||||
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
#ifndef CONFIG_VIEW_H
|
||||||
|
#define CONFIG_VIEW_H
|
||||||
|
|
||||||
|
|
||||||
#include <View.h>
|
#include <FileConfigView.h>
|
||||||
|
|
||||||
|
|
||||||
class ConfigView : public BView
|
class ConfigView : public BView {
|
||||||
{
|
public:
|
||||||
public:
|
ConfigView();
|
||||||
ConfigView();
|
void SetTo(const BMessage* archive);
|
||||||
void SetTo(const BMessage *archive);
|
|
||||||
|
|
||||||
virtual status_t Archive(BMessage *into, bool deep = true) const;
|
virtual status_t Archive(BMessage* into, bool deep = true) const;
|
||||||
virtual void GetPreferredSize(float *width, float *height);
|
|
||||||
|
private:
|
||||||
|
BPrivate::MailFileConfigView* fFileView;
|
||||||
|
BTextControl* fTagControl;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* CONFIG_VIEW */
|
|
||||||
|
#endif // CONFIG_VIEW_H
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
SubDir HAIKU_TOP src add-ons mail_daemon outbound_filters fortune ;
|
SubDir HAIKU_TOP src add-ons mail_daemon outbound_filters fortune ;
|
||||||
|
|
||||||
|
|
||||||
UsePrivateHeaders mail shared ;
|
UsePrivateHeaders mail shared ;
|
||||||
UsePublicHeaders [ FDirName add-ons mail_daemon ] ;
|
UsePublicHeaders [ FDirName add-ons mail_daemon ] ;
|
||||||
|
|
||||||
@@ -19,4 +18,5 @@ DoCatalogs Fortune :
|
|||||||
x-vnd.Haiku-Fortune
|
x-vnd.Haiku-Fortune
|
||||||
:
|
:
|
||||||
ConfigView.cpp
|
ConfigView.cpp
|
||||||
|
filter.cpp
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -1,15 +1,21 @@
|
|||||||
/* Add Fortune - adds fortunes to your mail
|
/*
|
||||||
**
|
* Copyright 2004-2012, Haiku, Inc. All rights reserved.
|
||||||
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
|
* Copyright 2001, Dr. Zoidberg Enterprises. All rights reserved.
|
||||||
*/
|
*
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
//! Adds fortunes to your mail
|
||||||
|
|
||||||
|
|
||||||
#include "ConfigView.h"
|
#include "ConfigView.h"
|
||||||
|
|
||||||
|
#include <Catalog.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <MailAddon.h>
|
#include <MailFilter.h>
|
||||||
#include <MailMessage.h>
|
#include <MailMessage.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -17,46 +23,59 @@
|
|||||||
#include "NodeMessage.h"
|
#include "NodeMessage.h"
|
||||||
|
|
||||||
|
|
||||||
class FortuneFilter : public MailFilter
|
#undef B_TRANSLATION_CONTEXT
|
||||||
{
|
#define B_TRANSLATION_CONTEXT "FortuneFilter"
|
||||||
|
|
||||||
|
|
||||||
|
class FortuneFilter : public BMailFilter {
|
||||||
public:
|
public:
|
||||||
FortuneFilter(MailProtocol& protocol,
|
FortuneFilter(BMailProtocol& protocol,
|
||||||
AddonSettings* settings);
|
BMailAddOnSettings* settings);
|
||||||
void MessageReadyToSend(const entry_ref& ref,
|
|
||||||
|
virtual BString DescriptiveName() const;
|
||||||
|
|
||||||
|
virtual void MessageReadyToSend(const entry_ref& ref,
|
||||||
BFile* file);
|
BFile* file);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
FortuneFilter::FortuneFilter(MailProtocol& protocol, AddonSettings* settings)
|
FortuneFilter::FortuneFilter(BMailProtocol& protocol,
|
||||||
|
BMailAddOnSettings* settings)
|
||||||
:
|
:
|
||||||
MailFilter(protocol, settings)
|
BMailFilter(protocol, settings)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BString
|
||||||
|
FortuneFilter::DescriptiveName() const
|
||||||
|
{
|
||||||
|
return filter_name();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FortuneFilter::MessageReadyToSend(const entry_ref& ref, BFile* file)
|
FortuneFilter::MessageReadyToSend(const entry_ref& ref, BFile* file)
|
||||||
{
|
{
|
||||||
// What we want to do here is to change the message body. To do that we use the
|
// What we want to do here is to change the message body. To do that we use the
|
||||||
// framework we already have by creating a new BEmailMessage based on the
|
// framework we already have by creating a new BEmailMessage based on the
|
||||||
// BPositionIO, changing the message body and rendering it back to disk. Of course
|
// BPositionIO, changing the message body and rendering it back to disk. Of course
|
||||||
// this method ends up not being super-efficient, but it works. Ideas on how to
|
// this method ends up not being super-efficient, but it works. Ideas on how to
|
||||||
// improve this are welcome.
|
// improve this are welcome.
|
||||||
BString fortuneFile;
|
BString fortuneFile;
|
||||||
BString tagLine;
|
BString tagLine;
|
||||||
|
|
||||||
const BMessage* settings = &fAddonSettings->Settings();
|
|
||||||
// Obtain relevant settings
|
// Obtain relevant settings
|
||||||
settings->FindString("fortune_file", &fortuneFile);
|
fSettings->FindString("fortune_file", &fortuneFile);
|
||||||
settings->FindString("tag_line", &tagLine);
|
fSettings->FindString("tag_line", &tagLine);
|
||||||
|
|
||||||
// Add command to be executed
|
// Add command to be executed
|
||||||
fortuneFile.Prepend("/bin/fortune ");
|
fortuneFile.Prepend("/bin/fortune ");
|
||||||
|
|
||||||
char buffer[768];
|
char buffer[768];
|
||||||
FILE *fd;
|
FILE *fd;
|
||||||
|
|
||||||
fd = popen(fortuneFile.String(), "r");
|
fd = popen(fortuneFile.String(), "r");
|
||||||
if (!fd) {
|
if (!fd) {
|
||||||
printf("Could not open pipe to fortune!\n");
|
printf("Could not open pipe to fortune!\n");
|
||||||
@@ -83,18 +102,28 @@ FortuneFilter::MessageReadyToSend(const entry_ref& ref, BFile* file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MailFilter*
|
// #pragma mark -
|
||||||
instantiate_mailfilter(MailProtocol& protocol, AddonSettings* settings)
|
|
||||||
|
|
||||||
|
BString
|
||||||
|
filter_name()
|
||||||
|
{
|
||||||
|
return B_TRANSLATE("Fortune");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BMailFilter*
|
||||||
|
instantiate_filter(BMailProtocol& protocol, BMailAddOnSettings* settings)
|
||||||
{
|
{
|
||||||
return new FortuneFilter(protocol, settings);
|
return new FortuneFilter(protocol, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BView*
|
BView*
|
||||||
instantiate_filter_config_panel(AddonSettings& settings)
|
instantiate_filter_config_panel(BMailAddOnSettings& settings)
|
||||||
{
|
{
|
||||||
ConfigView *view = new ConfigView();
|
ConfigView* view = new ConfigView();
|
||||||
view->SetTo(&settings.Settings());
|
view->SetTo(&settings);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user