Adapted fortune filter to the new mail API.
This commit is contained in:
parent
715bf3d17a
commit
794a013e9b
@ -1,17 +1,21 @@
|
||||
/* ConfigView - the configuration view for the Fortune filter
|
||||
**
|
||||
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2004-2012, Haiku, Inc. All rights reserved.
|
||||
* Copyright 2001, Dr. Zoidberg Enterprises. All rights reserved.
|
||||
*
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include "ConfigView.h"
|
||||
|
||||
#include <Catalog.h>
|
||||
#include <TextControl.h>
|
||||
#include <String.h>
|
||||
#include <LayoutBuilder.h>
|
||||
#include <Message.h>
|
||||
#include <String.h>
|
||||
#include <TextControl.h>
|
||||
|
||||
#include <FileConfigView.h>
|
||||
|
||||
using namespace BPrivate;
|
||||
|
||||
|
||||
#undef B_TRANSLATION_CONTEXT
|
||||
@ -20,74 +24,45 @@
|
||||
|
||||
ConfigView::ConfigView()
|
||||
:
|
||||
BView(BRect(0, 0, 20, 20), "fortune_filter", B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||
0)
|
||||
BView("fortune_filter", 0)
|
||||
{
|
||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
|
||||
// determine font height
|
||||
font_height fontHeight;
|
||||
GetFontHeight(&fontHeight);
|
||||
float itemHeight = (int32)(fontHeight.ascent + fontHeight.descent
|
||||
+ fontHeight.leading) + 13;
|
||||
fFileView = new MailFileConfigView(B_TRANSLATE("Fortune file:"),
|
||||
"fortune_file", false, "", B_FILE_NODE);
|
||||
fTagControl = new BTextControl("tag_line", B_TRANSLATE("Tag line:"),
|
||||
NULL, NULL);
|
||||
|
||||
BRect rect(5,4,250,25);
|
||||
rect.bottom = rect.top - 2 + itemHeight;
|
||||
BMailFileConfigView *fview = new BMailFileConfigView(
|
||||
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();
|
||||
BLayoutBuilder::Group<>(this, B_VERTICAL)
|
||||
.Add(fFileView)
|
||||
.Add(fTagControl);
|
||||
}
|
||||
|
||||
|
||||
void ConfigView::SetTo(const BMessage *archive)
|
||||
void
|
||||
ConfigView::SetTo(const BMessage* archive)
|
||||
{
|
||||
BMailFileConfigView* control = (BMailFileConfigView*)FindView(
|
||||
"fortune_file");
|
||||
if (control != NULL)
|
||||
control->SetTo(archive, NULL);
|
||||
fFileView->SetTo(archive, NULL);
|
||||
|
||||
BString path = archive->FindString("tag_line");
|
||||
if (!archive->HasString("tag_line"))
|
||||
path = B_TRANSLATE("Fortune cookie says:\n\n");
|
||||
|
||||
path.Truncate(path.Length() - 2);
|
||||
if (BTextControl *control = (BTextControl *)FindView("tag_line"))
|
||||
control->SetText(path.String());
|
||||
fTagControl->SetText(path.String());
|
||||
}
|
||||
|
||||
|
||||
status_t ConfigView::Archive(BMessage *into,bool) const
|
||||
status_t
|
||||
ConfigView::Archive(BMessage* into, bool /*deep*/) const
|
||||
{
|
||||
if (BMailFileConfigView *control = (BMailFileConfigView
|
||||
*)FindView("fortune_file"))
|
||||
{
|
||||
control->Archive(into);
|
||||
}
|
||||
fFileView->Archive(into);
|
||||
|
||||
BString line = fTagControl->Text();
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
/* ConfigView - the configuration view for the Folder filter
|
||||
**
|
||||
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2004-2012, Haiku, Inc. 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
|
||||
{
|
||||
public:
|
||||
ConfigView();
|
||||
void SetTo(const BMessage *archive);
|
||||
class ConfigView : public BView {
|
||||
public:
|
||||
ConfigView();
|
||||
void SetTo(const BMessage* archive);
|
||||
|
||||
virtual status_t Archive(BMessage *into, bool deep = true) const;
|
||||
virtual void GetPreferredSize(float *width, float *height);
|
||||
virtual status_t Archive(BMessage* into, bool deep = true) const;
|
||||
|
||||
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 ;
|
||||
|
||||
|
||||
UsePrivateHeaders mail shared ;
|
||||
UsePublicHeaders [ FDirName add-ons mail_daemon ] ;
|
||||
|
||||
@ -19,4 +18,5 @@ DoCatalogs Fortune :
|
||||
x-vnd.Haiku-Fortune
|
||||
:
|
||||
ConfigView.cpp
|
||||
filter.cpp
|
||||
;
|
||||
|
@ -1,15 +1,21 @@
|
||||
/* Add Fortune - adds fortunes to your mail
|
||||
**
|
||||
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2004-2012, Haiku, Inc. 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 <Catalog.h>
|
||||
#include <Message.h>
|
||||
#include <Entry.h>
|
||||
#include <String.h>
|
||||
#include <MailAddon.h>
|
||||
#include <MailFilter.h>
|
||||
#include <MailMessage.h>
|
||||
|
||||
#include <stdio.h>
|
||||
@ -17,46 +23,59 @@
|
||||
#include "NodeMessage.h"
|
||||
|
||||
|
||||
class FortuneFilter : public MailFilter
|
||||
{
|
||||
#undef B_TRANSLATION_CONTEXT
|
||||
#define B_TRANSLATION_CONTEXT "FortuneFilter"
|
||||
|
||||
|
||||
class FortuneFilter : public BMailFilter {
|
||||
public:
|
||||
FortuneFilter(MailProtocol& protocol,
|
||||
AddonSettings* settings);
|
||||
void MessageReadyToSend(const entry_ref& ref,
|
||||
FortuneFilter(BMailProtocol& protocol,
|
||||
BMailAddOnSettings* settings);
|
||||
|
||||
virtual BString DescriptiveName() const;
|
||||
|
||||
virtual void MessageReadyToSend(const entry_ref& ref,
|
||||
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
|
||||
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
|
||||
// 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
|
||||
// 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.
|
||||
BString fortuneFile;
|
||||
BString tagLine;
|
||||
|
||||
const BMessage* settings = &fAddonSettings->Settings();
|
||||
// Obtain relevant settings
|
||||
settings->FindString("fortune_file", &fortuneFile);
|
||||
settings->FindString("tag_line", &tagLine);
|
||||
|
||||
fSettings->FindString("fortune_file", &fortuneFile);
|
||||
fSettings->FindString("tag_line", &tagLine);
|
||||
|
||||
// Add command to be executed
|
||||
fortuneFile.Prepend("/bin/fortune ");
|
||||
|
||||
|
||||
char buffer[768];
|
||||
FILE *fd;
|
||||
|
||||
|
||||
fd = popen(fortuneFile.String(), "r");
|
||||
if (!fd) {
|
||||
printf("Could not open pipe to fortune!\n");
|
||||
@ -83,18 +102,28 @@ FortuneFilter::MessageReadyToSend(const entry_ref& ref, BFile* file)
|
||||
}
|
||||
|
||||
|
||||
MailFilter*
|
||||
instantiate_mailfilter(MailProtocol& protocol, AddonSettings* settings)
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
BString
|
||||
filter_name()
|
||||
{
|
||||
return B_TRANSLATE("Fortune");
|
||||
}
|
||||
|
||||
|
||||
BMailFilter*
|
||||
instantiate_filter(BMailProtocol& protocol, BMailAddOnSettings* settings)
|
||||
{
|
||||
return new FortuneFilter(protocol, settings);
|
||||
}
|
||||
|
||||
|
||||
BView*
|
||||
instantiate_filter_config_panel(AddonSettings& settings)
|
||||
instantiate_filter_config_panel(BMailAddOnSettings& settings)
|
||||
{
|
||||
ConfigView *view = new ConfigView();
|
||||
view->SetTo(&settings.Settings());
|
||||
ConfigView* view = new ConfigView();
|
||||
view->SetTo(&settings);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user