Custom entry mimetype; remove --mimetype

This commit is contained in:
Jaidyn Ann 2020-08-02 03:29:56 -05:00
parent 0438c097bf
commit 21ad59927f
8 changed files with 77 additions and 25 deletions

View File

@ -34,6 +34,7 @@ SRCS = \
src/AtomFeed.cpp, \
src/RssFeed.cpp, \
src/ProtocolListener.cpp, \
src/Mimetypes.cpp, \
src/Config.cpp, \
src/Util.cpp, \
src/Pogger.cpp
@ -41,7 +42,7 @@ SRCS = \
# Specify the resource definition files to use. Full or relative paths can be
# used.
RDEFS = # \
# src/calendar.rdef \
# src/Pogger.rdef \
# Specify the resource files to use. Full or relative paths can be used.

View File

@ -24,8 +24,6 @@ Config::Load ()
BMessage storage;
storage.Unflatten( file );
if ( mimetype == NULL)
mimetype = BString( storage.GetString("mimetype", "text/xml") );
if ( outDir == NULL)
outDir = BString( storage.GetString("outDir", "/boot/home/feeds/") );
if ( cacheDir == NULL)
@ -55,7 +53,6 @@ Config::Save ()
BFile* file = new BFile( filename.String(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
status_t result = file->InitCheck();
storage.AddString( "mimetype", mimetype.String() );
storage.AddString( "outDir", outDir.String() );
storage.AddString( "cacheDir", cacheDir.String() );

View File

@ -9,7 +9,6 @@ class Config {
public:
bool verbose;
bool daemon;
BString mimetype;
BString outDir;
BList targetFeeds; // strings of files or urls

View File

@ -20,27 +20,24 @@ Entry::Filetize ( Config* cfg, bool onlyIfNew = false )
{
BDirectory* dir = new BDirectory( outputDir );
BFile* file = new BFile( title.String(), B_READ_WRITE );
time_t tt_date = date.Time_t();
dir->CreateFile( title.String(), file );
BString betype = cfg->mimetype;
if ( date != NULL ) {
int32 unixDate = (int32)date.Time_t();
file->WriteAttr( "unixDate", B_INT32_TYPE, 0,
&unixDate, sizeof(int32) );
file->WriteAttr( "date", B_STRING_TYPE, 0,
dateTo3339String(date).String(),
dateTo3339String(date).CountChars() );
}
BString betype = BString("text/x-feed-entry");
file->WriteAttr( "BEOS:TYPE", B_MIME_STRING_TYPE, 0,
betype.String(), betype.CountChars() + 1 );
file->WriteAttr( "META:title", B_STRING_TYPE, 0,
file->WriteAttr( "FEED:name", B_STRING_TYPE, 0,
title.String(), title.CountChars() );
file->WriteAttr( "description", B_STRING_TYPE, 0,
file->WriteAttr( "FEED:description", B_STRING_TYPE, 0,
description.String(), description.CountChars() );
file->WriteAttr( "META:url", B_STRING_TYPE, 0,
postUrl.String(), postUrl.CountChars() );
file->WriteAttr( "BEOS:TYPE", B_STRING_TYPE, 0,
betype.String(), betype.CountChars() );
if ( date != NULL ) {
file->WriteAttr( "FEED:when", B_TIME_TYPE, 0,
&tt_date, sizeof(time_t) );
}
file->Write(content.String(), content.Length());
return false;

47
src/Mimetypes.cpp Normal file
View File

@ -0,0 +1,47 @@
// borrowed significantly from mailserver. thanks! <3
#include <DateTime.h>
#include <Message.h>
#include <MimeType.h>
#include "Mimetypes.h"
bool
feedMimeType ( )
{
BMessage info;
BMimeType mime( "text/x-feed-entry" );
if ( mime.InitCheck() != B_OK ) {
return false;
}
if ( !mime.IsInstalled() ) {
mime.Delete();
mime.Install();
addAttribute( info, "FEED:name", "Name" );
addAttribute( info, "FEED:description", "Description" );
addAttribute( info, "META:url", "URL" );
addAttribute( info, "FEED:when", "When", B_TIME_TYPE, true, false, 150 );
mime.SetAttrInfo(&info);
mime.SetShortDescription("Feed Entry");
mime.SetLongDescription("RSS/Atom Feed Entry");
}
return true;
}
// -------------------------------------
static void
addAttribute
( BMessage& msg, const char* name, const char* publicName, int32 type, bool viewable, bool editable,
int32 width)
{
msg.AddString( "attr:name", name );
msg.AddString( "attr:public_name", publicName );
msg.AddInt32( "attr:type", type );
msg.AddBool( "attr:viewable", viewable );
msg.AddBool( "attr:editable", editable );
msg.AddInt32( "attr:width", width );
}

14
src/Mimetypes.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef MIME_H
#define MIME_H
#include <Message.h>
#include <String.h>
bool feedMimeType ( );
static void addAttribute
( BMessage&, const char*, const char*, int32 type = B_STRING_TYPE, bool viewable = true,
bool editable = false, int32 width = 200);
#endif

View File

@ -5,6 +5,7 @@
#include "RssFeed.h"
#include "Feed.h"
#include "Entry.h"
#include "Mimetypes.h"
#include "Config.h"
#include "Util.h"
#include "Pogger.h"
@ -14,6 +15,7 @@ main ( int argc, char** argv )
{
main_cfg = new Config;
usageMsg.ReplaceAll("%app%", "Pogger");
feedMimeType();
invocation( argc, argv, &main_cfg );
main_cfg->Load();
@ -49,7 +51,6 @@ invocation ( int argc, char** argv, Config** cfgPtr )
{ "before", required_argument, 0, 't' },
{ "after", required_argument, 0, 'T' },
{ "output", required_argument, 0, 'O' },
{ "mimetype", required_argument, 0, 'm' },
{ "foreground", no_argument, 0, 'D' },
{ 0, 0, 0, 0 }
};
@ -72,9 +73,6 @@ invocation ( int argc, char** argv, Config** cfgPtr )
break;
case 's':
cfg->will_save = true;
case 'm':
cfg->mimetype = BString( optarg );
break;
case 't':
minDate = dateRfc3339ToBDate( optarg );
if ( minDate != NULL )

View File

@ -16,15 +16,14 @@ const char* configPath = "/boot/home/config/settings/Pogger/";
BString usageMsg =
"Usage: %app% [-hvDus] [-m mimetype] [-tT datetime] [-cCO path] \n"
" %app% [-hvs] [-mtTcCO] ( <text/xml file> | <META:url file> | <url> )\n"
"Usage: %app% [-hvDus] [-tT datetime] [-cCO path] \n"
" %app% [-hvs] [-tTcCO] ( <text/xml file> | <META:url file> | <url> )\n"
"\n"
"%app%, a RSS and Atom feed parser/daemon.\n"
"\n"
"Options:\n"
" -h, --help - Print this usage info.\n"
" -v, --verbose - Print verbose (debug) info.\n"
" -m, --mimetype - Mimetype of new item files. (Default: text/xml)\n"
" -O, --output - Output dir for item files. (Default: ~/feeds/)\n"
" -t, --before - Only return items published before this datetime.\n"
" -T, --after - Only return items published after this datetime.\n"