Pogger/src/App.cpp

119 lines
2.0 KiB
C++
Raw Normal View History

2020-12-30 22:07:54 -06:00
/*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#include "App.h"
2021-01-12 19:08:42 -06:00
#include <MessageRunner.h>
2020-07-03 19:13:41 -05:00
#include <StorageKit.h>
2020-08-16 23:22:15 -05:00
#include <String.h>
2020-12-30 22:07:54 -06:00
2020-08-16 23:22:15 -05:00
#include <getopt.h>
2020-12-30 22:07:54 -06:00
2020-08-16 23:22:15 -05:00
#include "AtomFeed.h"
2020-12-30 22:07:54 -06:00
#include "Config.h"
2020-08-16 23:22:15 -05:00
#include "Entry.h"
2020-12-30 22:07:54 -06:00
#include "Feed.h"
2021-01-09 16:53:39 -06:00
#include "FeedController.h"
2020-12-30 22:07:54 -06:00
#include "MainWindow.h"
2020-08-16 23:22:15 -05:00
#include "Mimetypes.h"
#include "Notifier.h"
2020-12-30 22:07:54 -06:00
#include "RssFeed.h"
2020-08-16 23:22:15 -05:00
#include "Util.h"
2020-07-03 19:13:41 -05:00
2020-08-16 23:22:15 -05:00
int
2020-12-30 22:07:54 -06:00
main(int argc, char** argv)
2020-08-16 23:22:15 -05:00
{
2021-01-12 15:30:21 -06:00
installMimeTypes();
2020-08-16 23:22:15 -05:00
2021-01-12 19:08:42 -06:00
App* app = new App();
2021-01-11 11:41:46 -06:00
app->Run();
2021-01-12 19:08:42 -06:00
app->cfg->Save();
2020-08-16 23:22:15 -05:00
return 0;
}
2020-12-30 22:07:54 -06:00
App::App() : BApplication("application/x-vnd.Pogger")
2020-08-16 23:22:15 -05:00
{
2021-01-12 19:08:42 -06:00
cfg = new Config;
cfg->Load();
2021-01-09 16:53:39 -06:00
fMainWindow = new MainWindow();
fNotifier = new Notifier();
2021-01-09 16:53:39 -06:00
fFeedController = new FeedController();
fMainWindow->Show();
2021-01-12 19:08:42 -06:00
BMessage* updateMessage = new BMessage(kUpdateSubscribed);
MessageReceived(updateMessage);
fUpdateRunner = new BMessageRunner(this, updateMessage,
cfg->updateInterval);
2021-01-09 16:53:39 -06:00
}
void
App::MessageReceived(BMessage* msg)
{
switch (msg->what)
{
case kEnqueueFeed:
{
fFeedController->MessageReceived(msg);
break;
}
2021-01-12 15:30:21 -06:00
case kUpdateSubscribed:
{
fFeedController->MessageReceived(msg);
break;
}
2021-01-09 16:53:39 -06:00
case kClearQueue:
{
break;
}
case kParseFail:
2021-01-09 16:53:39 -06:00
{
fNotifier->MessageReceived(msg);
fFeedController->MessageReceived(msg);
break;
}
case kDownloadFail:
{
fNotifier->MessageReceived(msg);
fFeedController->MessageReceived(msg);
break;
2021-01-09 16:53:39 -06:00
}
case kDownloadComplete:
{
fFeedController->MessageReceived(msg);
break;
2021-01-09 16:53:39 -06:00
}
default:
{
// BApplication::MessageReceived(msg);
break;
}
}
2020-08-16 23:22:15 -05:00
}
2020-07-03 19:13:41 -05:00
2020-07-07 20:17:52 -05:00
2021-01-11 11:41:46 -06:00
void
App::ArgvReceived(int32 argc, char** argv)
{
for (int i = 1; i < argc; i++) {
2021-01-11 18:08:15 -06:00
if (BUrl(argv[i]).IsValid()) {
Feed* newFeed = new Feed(BUrl(argv[i]));
2021-01-11 11:41:46 -06:00
2021-01-11 18:08:15 -06:00
BMessage* enqueue = new BMessage(kEnqueueFeed);
enqueue->AddData("feeds", B_RAW_TYPE, (void*)newFeed, sizeof(Feed));
2021-01-11 11:41:46 -06:00
2021-01-11 18:08:15 -06:00
MessageReceived(enqueue);
}
2021-01-11 11:41:46 -06:00
}
}
2020-08-16 23:22:15 -05:00
const char* configPath = "/boot/home/config/settings/Pogger/";
2021-01-11 11:41:46 -06:00