Notifications for new entries
This commit is contained in:
parent
15b0fc7d6b
commit
543292c825
2
TODO.txt
2
TODO.txt
|
@ -4,8 +4,6 @@
|
||||||
* Revamp configuration
|
* Revamp configuration
|
||||||
* Fix saving, etc.
|
* Fix saving, etc.
|
||||||
* Notifications
|
* Notifications
|
||||||
* On new entries
|
|
||||||
* Sound effect, too
|
|
||||||
* On failures
|
* On failures
|
||||||
* Show progress
|
* Show progress
|
||||||
* With progress bar
|
* With progress bar
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
|
|
||||||
|
|
||||||
Config::Config() {
|
Config::Config() {
|
||||||
Load();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,7 +32,7 @@ Config::Load()
|
||||||
BMessage storage;
|
BMessage storage;
|
||||||
storage.Unflatten(&file);
|
storage.Unflatten(&file);
|
||||||
|
|
||||||
updateInterval = storage.GetFloat("updateInterval", .5);
|
updateInterval = storage.GetInt64("updateInterval", 3600000000);
|
||||||
outDir = BString(storage.GetString("outDir", "/boot/home/feeds/"));
|
outDir = BString(storage.GetString("outDir", "/boot/home/feeds/"));
|
||||||
cacheDir = BString(storage.GetString("cacheDir",
|
cacheDir = BString(storage.GetString("cacheDir",
|
||||||
"/boot/home/config/cache/Pogger/"));
|
"/boot/home/config/cache/Pogger/"));
|
||||||
|
|
|
@ -40,7 +40,7 @@ Entry::Filetize(BDirectory outDir)
|
||||||
title.String(), title.CountChars());
|
title.String(), title.CountChars());
|
||||||
file->WriteAttr("Feed:description", B_STRING_TYPE, 0,
|
file->WriteAttr("Feed:description", B_STRING_TYPE, 0,
|
||||||
description.String(), description.CountChars());
|
description.String(), description.CountChars());
|
||||||
file->WriteAttr("FEED:source", B_STRING_TYPE, 0,
|
file->WriteAttr("Feed:source", B_STRING_TYPE, 0,
|
||||||
feedTitle.String(), feedTitle.CountChars());
|
feedTitle.String(), feedTitle.CountChars());
|
||||||
file->WriteAttr("META:url", B_STRING_TYPE, 0, postUrl.String(),
|
file->WriteAttr("META:url", B_STRING_TYPE, 0, postUrl.String(),
|
||||||
postUrl.CountChars());
|
postUrl.CountChars());
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "FeedController.h"
|
#include "FeedController.h"
|
||||||
|
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
|
#include <Notification.h>
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
@ -125,6 +126,7 @@ FeedController::_ParseLoop(void* ignored)
|
||||||
|
|
||||||
while (receive_data(&sender, (void*)feedBuffer, sizeof(Feed)) != 0) {
|
while (receive_data(&sender, (void*)feedBuffer, sizeof(Feed)) != 0) {
|
||||||
BList entries;
|
BList entries;
|
||||||
|
BString title;
|
||||||
BDirectory outDir = BDirectory(((App*)be_app)->cfg->outDir);
|
BDirectory outDir = BDirectory(((App*)be_app)->cfg->outDir);
|
||||||
|
|
||||||
if (feedBuffer->IsAtom()) {
|
if (feedBuffer->IsAtom()) {
|
||||||
|
@ -132,6 +134,7 @@ FeedController::_ParseLoop(void* ignored)
|
||||||
feed = new AtomFeed(feedBuffer);
|
feed = new AtomFeed(feedBuffer);
|
||||||
feed->Parse();
|
feed->Parse();
|
||||||
entries = feed->GetNewEntries();
|
entries = feed->GetNewEntries();
|
||||||
|
title = feed->GetTitle();
|
||||||
delete(feed);
|
delete(feed);
|
||||||
}
|
}
|
||||||
else if (feedBuffer->IsRss()) {
|
else if (feedBuffer->IsRss()) {
|
||||||
|
@ -139,12 +142,30 @@ FeedController::_ParseLoop(void* ignored)
|
||||||
feed = new RssFeed(feedBuffer);
|
feed = new RssFeed(feedBuffer);
|
||||||
feed->Parse();
|
feed->Parse();
|
||||||
entries = feed->GetNewEntries();
|
entries = feed->GetNewEntries();
|
||||||
|
title = feed->GetTitle();
|
||||||
delete(feed);
|
delete(feed);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (feedBuffer->IsAtom() || feedBuffer->IsRss())
|
if ((feedBuffer->IsAtom() || feedBuffer->IsRss())
|
||||||
|
&& entries.CountItems() > 0)
|
||||||
|
{
|
||||||
for (int i = 0; i < entries.CountItems(); i++)
|
for (int i = 0; i < entries.CountItems(); i++)
|
||||||
((Entry*)entries.ItemAt(i))->Filetize(outDir);
|
((Entry*)entries.ItemAt(i))->Filetize(outDir);
|
||||||
|
|
||||||
|
BNotification notifyNew = (B_INFORMATION_NOTIFICATION);
|
||||||
|
BString notifyLabel("New Feed Entries");
|
||||||
|
BString notifyText("%n% new entries from %source%");
|
||||||
|
|
||||||
|
BString numStr("");
|
||||||
|
numStr << entries.CountItems();
|
||||||
|
notifyText.ReplaceAll("%source%", title);
|
||||||
|
notifyText.ReplaceAll("%n%", numStr);
|
||||||
|
|
||||||
|
|
||||||
|
notifyNew.SetTitle(notifyLabel);
|
||||||
|
notifyNew.SetContent(notifyText);
|
||||||
|
notifyNew.Send();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete (feedBuffer);
|
delete (feedBuffer);
|
||||||
|
|
Ŝarĝante…
Reference in New Issue