Make 'Entries' tab settings functional

This commit is contained in:
Jaidyn Ann 2021-01-28 00:19:36 -06:00
parent afcbea6fba
commit 067679e34e
11 changed files with 183 additions and 53 deletions

View File

@ -2,8 +2,6 @@
* This way, if the user edits the feed after it is enqueued but before * This way, if the user edits the feed after it is enqueued but before
processing, the changes will be applied. processing, the changes will be applied.
* Support for clearing queue * Support for clearing queue
* Revamp configuration
* Fix saving, etc.
* Show progress * Show progress
* With progress bar * With progress bar
* Ran into a slight problem when trying to set the maxValue and * Ran into a slight problem when trying to set the maxValue and
@ -11,7 +9,8 @@
crash every time, without fail. Even with float constants that crash every time, without fail. Even with float constants that
work when used in MainWindow::_InitInterface. Weird, idk work when used in MainWindow::_InitInterface. Weird, idk
* With indicator in the feeds list * With indicator in the feeds list
* Configurations * File error-handling
* e.g., Utils.cpp's userFileError
* Remove unnecessary `new`-- make sure to delete everything * Remove unnecessary `new`-- make sure to delete everything
* Check if arg is a file or not (treat appropriately) * Check if arg is a file or not (treat appropriately)
* No hardcoded paths * No hardcoded paths
@ -29,3 +28,6 @@
* Using a proper queue list would give faster * Using a proper queue list would give faster
results to Notifer about how many feeds are results to Notifer about how many feeds are
enqueued (so things *feel* faster) enqueued (so things *feel* faster)
* Open With support
* Open As support
* File extension support

View File

@ -10,10 +10,16 @@
#include <Message.h> #include <Message.h>
#include <LayoutBuilder.h> #include <LayoutBuilder.h>
#include <PopUpMenu.h> #include <PopUpMenu.h>
#include <StringList.h>
#include <RadioButton.h> #include <RadioButton.h>
#include <StringView.h> #include <StringView.h>
#include <TextControl.h> #include <TextControl.h>
#include <iostream>
#include "App.h"
#include "Util.h"
EntriesView::EntriesView(const char* name) EntriesView::EntriesView(const char* name)
: :
@ -30,6 +36,7 @@ EntriesView::AttachedToWindow()
fEntryFolderBrowseButton->SetTarget(this); fEntryFolderBrowseButton->SetTarget(this);
fFileExtText->SetTarget(this); fFileExtText->SetTarget(this);
fOpenAsAutoRadio->SetTarget(this);
fOpenAsHtmlRadio->SetTarget(this); fOpenAsHtmlRadio->SetTarget(this);
fOpenAsUrlRadio->SetTarget(this); fOpenAsUrlRadio->SetTarget(this);
fOpenWithSelectButton->SetTarget(this); fOpenWithSelectButton->SetTarget(this);
@ -41,9 +48,43 @@ EntriesView::MessageReceived(BMessage* msg)
{ {
switch (msg->what) switch (msg->what)
{ {
case kEntryFolderText:
{
status_t result = ((App*)be_app)->fPreferences->SetEntryDir(
fEntryFolderText->Text());
if (result != B_OK)
userFileError(result, fEntryFolderText->Text());
break;
}
case kEntryExtText:
{
((App*)be_app)->fPreferences->fEntryFileExt = fFileExtText->Text();
break;
}
case kOpenHtmlRadio:
{
((App*)be_app)->fPreferences->fOpenAs = kOpenAsHtml;
break;
}
case kOpenUrlRadio:
{
((App*)be_app)->fPreferences->fOpenAs = kOpenAsUrl;
break;
}
case kOpenAutoRadio:
{
((App*)be_app)->fPreferences->fOpenAs = kOpenAsAuto;
break;
}
case kOpenWithSelect:
{
((App*)be_app)->fPreferences->SetEntryOpenWith(
fOpenWithMenuField->MenuItem()->Label());
break;
}
default: default:
{ {
// BWindow::MessageReceived(msg); BGroupView::MessageReceived(msg);
break; break;
} }
} }
@ -58,28 +99,47 @@ EntriesView::_InitInterface()
fSavingBox->SetLabel("Saving"); fSavingBox->SetLabel("Saving");
fEntryFolderLabel = new BStringView("entryFolderLabel", "Entry folder:"); fEntryFolderLabel = new BStringView("entryFolderLabel", "Entry folder:");
fEntryFolderText = new BTextControl("entryFolder", "", fEntryFolderText = new BTextControl("entryFolder", "", "",
"/boot/home/feeds/", new BMessage('ssss')); new BMessage(kEntryFolderText));
fEntryFolderBrowseButton = new BButton("entryFolderBrowse", "Browse…", fEntryFolderBrowseButton = new BButton("entryFolderBrowse", "Browse…",
new BMessage('mmmm')); new BMessage(kEntryFolderBrowse));
fFileExtLabel = new BStringView("fileExtLabel", "File extension:"); fFileExtLabel = new BStringView("fileExtLabel", "File extension:");
fFileExtText = new BTextControl("fileExt", "", "", new BMessage('ffff')); fFileExtText = new BTextControl("fileExt", "", "",
new BMessage(kEntryExtText));
// Opening // Opening
fOpeningBox = new BBox("opening"); fOpeningBox = new BBox("opening");
fOpeningBox->SetLabel("Opening"); fOpeningBox->SetLabel("Opening");
fOpenAsLabel = new BStringView("openAsLabel", "Open as:"); fOpenAsLabel = new BStringView("openAsLabel", "Open as:");
fOpenAsHtmlRadio = new BRadioButton("asHtml", "HTML", new BMessage('ii')); fOpenAsAutoRadio = new BRadioButton("asAuto", "Auto",
fOpenAsUrlRadio = new BRadioButton("asUrl", "URL", new BMessage('ii')); new BMessage(kOpenAutoRadio));
fOpenAsHtmlRadio = new BRadioButton("asHtml", "HTML",
new BMessage(kOpenHtmlRadio));
fOpenAsUrlRadio = new BRadioButton("asUrl", "URL",
new BMessage(kOpenUrlRadio));
fOpenWithLabel = new BStringView("openWithLabel", "Open with:"); fOpenWithLabel = new BStringView("openWithLabel", "Open with:");
fOpenWithMenu = new BPopUpMenu("openWith"); fOpenWithMenu = new BPopUpMenu("openWith");
fOpenWithMenuField = new BMenuField("openWithMenu", NULL, fOpenWithMenu); fOpenWithMenuField = new BMenuField("openWithMenu", NULL, fOpenWithMenu);
fOpenWithMenu->AddItem(new BMenuItem("WebPositive", new BMessage('wwww')));
fOpenWithSelectButton = new BButton("openWithSelect", "Select…", fOpenWithSelectButton = new BButton("openWithSelect", "Select…",
new BMessage('mmmm')); new BMessage(kOpenWithBrowse));
// Display current settings
Preferences* prefs = ((App*)be_app)->fPreferences;
if (prefs->fOpenAs == kOpenAsHtml)
fOpenAsHtmlRadio->SetValue(B_CONTROL_ON);
else if (prefs->fOpenAs == kOpenAsUrl)
fOpenAsUrlRadio->SetValue(B_CONTROL_ON);
else
fOpenAsAutoRadio->SetValue(B_CONTROL_ON);
fFileExtText->SetText(prefs->fEntryFileExt);
fEntryFolderText->SetText(prefs->EntryDir());
_PopulateOpenWithMenu();
BLayoutBuilder::Group<>(fSavingBox, B_HORIZONTAL) BLayoutBuilder::Group<>(fSavingBox, B_HORIZONTAL)
@ -109,6 +169,7 @@ EntriesView::_InitInterface()
.AddGroup(B_VERTICAL, B_USE_DEFAULT_SPACING) .AddGroup(B_VERTICAL, B_USE_DEFAULT_SPACING)
.SetInsets(0, 20, B_USE_ITEM_INSETS, 0) .SetInsets(0, 20, B_USE_ITEM_INSETS, 0)
.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING) .AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING)
.Add(fOpenAsAutoRadio)
.Add(fOpenAsHtmlRadio) .Add(fOpenAsHtmlRadio)
.Add(fOpenAsUrlRadio) .Add(fOpenAsUrlRadio)
.AddGlue() .AddGlue()
@ -130,3 +191,27 @@ EntriesView::_InitInterface()
} }
void
EntriesView::_PopulateOpenWithMenu()
{
BString preferred = ((App*)be_app)->fPreferences->EntryOpenWith();
BMimeType html("text/html");
BStringList signatures;
BMessage types;
html.GetSupportingApps(&types);
if (types.FindStrings("applications", &signatures) != B_OK)
return;
for (int i = 0; i < signatures.CountStrings(); i++) {
BString string = signatures.StringAt(i);
if (string != preferred)
fOpenWithMenu->AddItem(
new BMenuItem(string, new BMessage(kOpenWithSelect)));
}
fOpenWithMenu->AddItem(
new BMenuItem(preferred, new BMessage(kOpenWithSelect)), 0);
}

View File

@ -18,6 +18,19 @@ class BStringView;
class BTextControl; class BTextControl;
enum
{
kEntryFolderText = 'txef',
kEntryFolderBrowse = 'tbef',
kEntryExtText = 'txee',
kOpenHtmlRadio = 'rdow',
kOpenUrlRadio = 'roow',
kOpenAutoRadio = 'raow',
kOpenWithSelect = 'mnow',
kOpenWithBrowse = 'tbow'
};
class EntriesView : public BGroupView { class EntriesView : public BGroupView {
public: public:
EntriesView(const char* name); EntriesView(const char* name);
@ -27,6 +40,7 @@ public:
private: private:
void _InitInterface(); void _InitInterface();
void _PopulateOpenWithMenu();
BBox* fSavingBox; BBox* fSavingBox;
@ -38,6 +52,7 @@ private:
BBox* fOpeningBox; BBox* fOpeningBox;
BStringView* fOpenAsLabel; BStringView* fOpenAsLabel;
BRadioButton* fOpenAsAutoRadio;
BRadioButton* fOpenAsHtmlRadio; BRadioButton* fOpenAsHtmlRadio;
BRadioButton* fOpenAsUrlRadio; BRadioButton* fOpenAsUrlRadio;
BStringView* fOpenWithLabel; BStringView* fOpenWithLabel;

View File

@ -150,7 +150,7 @@ FeedController::_ParseLoop(void* ignored)
BList entries; BList entries;
BString feedTitle; BString feedTitle;
BUrl feedUrl = feedBuffer->GetXmlUrl(); BUrl feedUrl = feedBuffer->GetXmlUrl();
BDirectory outDir = BDirectory(((App*)be_app)->fPreferences->fEntryDir); BDirectory outDir = BDirectory(((App*)be_app)->fPreferences->EntryDir());
if (feedBuffer->IsAtom()) { if (feedBuffer->IsAtom()) {
AtomFeed* feed = (AtomFeed*)malloc(sizeof(AtomFeed)); AtomFeed* feed = (AtomFeed*)malloc(sizeof(AtomFeed));

View File

@ -47,6 +47,11 @@ MainWindow::MessageReceived(BMessage *msg)
fFeedsView->MessageReceived(msg); fFeedsView->MessageReceived(msg);
break; break;
} }
case kOpenWithSelect:
{
fEntriesView->MessageReceived(msg);
break;
}
case kProgress: case kProgress:
{ {
int32 max = 0; int32 max = 0;

View File

@ -73,7 +73,7 @@ Notifier::MessageReceived(BMessage* msg)
void void
Notifier::_NewEntryNotification(BString feedName, int32 entryCount) Notifier::_NewEntryNotification(BString feedName, int32 entryCount)
{ {
if (((App*)be_app)->fPreferences->NotifyOnNew() == false) if (((App*)be_app)->fPreferences->fNewNotify == false)
return; return;
BNotification notifyNew(B_INFORMATION_NOTIFICATION); BNotification notifyNew(B_INFORMATION_NOTIFICATION);
@ -94,7 +94,7 @@ Notifier::_NewEntryNotification(BString feedName, int32 entryCount)
void void
Notifier::_ParseFailNotification(BString feedUrl) Notifier::_ParseFailNotification(BString feedUrl)
{ {
if (((App*)be_app)->fPreferences->NotifyOnFailure() == false) if (((App*)be_app)->fPreferences->fFailureNotify == false)
return; return;
BNotification notifyError(B_ERROR_NOTIFICATION); BNotification notifyError(B_ERROR_NOTIFICATION);
@ -114,7 +114,7 @@ Notifier::_ParseFailNotification(BString feedUrl)
void void
Notifier::_DownloadFailNotification(BString feedUrl) Notifier::_DownloadFailNotification(BString feedUrl)
{ {
if (((App*)be_app)->fPreferences->NotifyOnFailure() == false) if (((App*)be_app)->fPreferences->fFailureNotify == false)
return; return;
BNotification notifyError(B_ERROR_NOTIFICATION); BNotification notifyError(B_ERROR_NOTIFICATION);

View File

@ -34,8 +34,9 @@ Preferences::Load()
fEntryDir = BString(storage.GetString("entryDir", "/boot/home/feeds/")); fEntryDir = BString(storage.GetString("entryDir", "/boot/home/feeds/"));
fEntryFileExt = BString(storage.GetString("entryExt", "")); fEntryFileExt = BString(storage.GetString("entryExt", ""));
fOpenAsHtml = storage.GetBool("openAsHtml", false); fOpenAs = storage.GetInt8("openAs", kOpenAsUrl);
fOpenWith = BString(storage.GetString("openWith", "WebPositive")); fOpenWith = BString(storage.GetString("openWith",
"application/x-vnd.Haiku-WebPositive"));
fNewNotify = storage.GetBool("notifyNew", true); fNewNotify = storage.GetBool("notifyNew", true);
fFailureNotify = storage.GetBool("notifyFailure", true); fFailureNotify = storage.GetBool("notifyFailure", true);
@ -67,8 +68,8 @@ Preferences::Save()
storage.AddString("entryDir", fEntryDir.String()); storage.AddString("entryDir", fEntryDir.String());
storage.AddString("entryExt", fEntryFileExt.String()); storage.AddString("entryExt", fEntryFileExt.String());
storage.AddBool("openAsHtml", fOpenAsHtml);
storage.AddString("openWith", fOpenWith.String()); storage.AddString("openWith", fOpenWith.String());
storage.AddInt8("openAs", fOpenAs);
storage.AddBool("notifyNew", fNewNotify); storage.AddBool("notifyNew", fNewNotify);
storage.AddBool("notifyFailure", fFailureNotify); storage.AddBool("notifyFailure", fFailureNotify);
@ -109,31 +110,38 @@ Preferences::SetUpdateIntervalIndex(int8 index)
} }
bool BString
Preferences::NotifyOnFailure() Preferences::EntryDir()
{ {
return fFailureNotify; return fEntryDir;
} }
bool status_t
Preferences::NotifyOnNew() Preferences::SetEntryDir(const char* path)
{ {
return fNewNotify; status_t testStatus = BEntry(path).InitCheck();
if (testStatus == B_OK)
fEntryDir = BString(path);
return testStatus;
} }
void BString
Preferences::SetNotifyOnFailure(bool value) Preferences::EntryOpenWith()
{ {
fFailureNotify = value; return fOpenWith;
} }
void status_t
Preferences::SetNotifyOnNew(bool value) Preferences::SetEntryOpenWith(const char* binPath)
{ {
fNewNotify = value; // status_t testStatus = BEntry(binPath).InitCheck();
// if (testStatus == B_OK)
fOpenWith = BString(binPath);
return B_OK;
// return testStatus;
} }

View File

@ -5,13 +5,19 @@
#ifndef PREFS_H #ifndef PREFS_H
#define PREFS_H #define PREFS_H
#include <DateTime.h> #include <DateTime.h>
#include <String.h> #include <String.h>
#include <StorageKit.h> #include <StorageKit.h>
const int64 HOUR_IN_MICROSECONDS = 3600000000; static const int64 HOUR_IN_MICROSECONDS = 3600000000;
enum
{
kOpenAsAuto = 0,
kOpenAsHtml = 1,
kOpenAsUrl = 2
};
class Preferences { class Preferences {
@ -26,23 +32,23 @@ public:
int UpdateIntervalIndex(); int UpdateIntervalIndex();
void SetUpdateIntervalIndex(int8 index); void SetUpdateIntervalIndex(int8 index);
bool NotifyOnFailure(); BString EntryDir();
bool NotifyOnNew(); status_t SetEntryDir(const char* path);
void SetNotifyOnFailure(bool value);
void SetNotifyOnNew(bool value); BString EntryOpenWith();
status_t SetEntryOpenWith(const char* binPath);
BString fEntryDir;
BString fEntryFileExt; BString fEntryFileExt;
bool fOpenAsHtml; bool fNewNotify;
BString fOpenWith; bool fFailureNotify;
int8 fOpenAs;
private: private:
int8 fUpdateInterval; int8 fUpdateInterval;
bool fNewNotify; BString fEntryDir;
bool fFailureNotify; BString fOpenWith;
}; };

View File

@ -42,17 +42,17 @@ UpdatesView::MessageReceived(BMessage* msg)
case kNotifyNewCheckbox: case kNotifyNewCheckbox:
{ {
if (fNotifyNewCheck->Value() == B_CONTROL_ON) if (fNotifyNewCheck->Value() == B_CONTROL_ON)
((App*)be_app)->fPreferences->SetNotifyOnNew(true); ((App*)be_app)->fPreferences->fNewNotify = true;
else else
((App*)be_app)->fPreferences->SetNotifyOnNew(false); ((App*)be_app)->fPreferences->fNewNotify = false;
break; break;
} }
case kNotifyFailCheckbox: case kNotifyFailCheckbox:
{ {
if (fNotifyFailCheck->Value() == B_CONTROL_ON) if (fNotifyFailCheck->Value() == B_CONTROL_ON)
((App*)be_app)->fPreferences->SetNotifyOnFailure(true); ((App*)be_app)->fPreferences->fFailureNotify = true;
else else
((App*)be_app)->fPreferences->SetNotifyOnFailure(false); ((App*)be_app)->fPreferences->fFailureNotify = false;
break; break;
} }
case kIntervalChanged: case kIntervalChanged:
@ -82,7 +82,6 @@ UpdatesView::_InitInterface()
fNotifyFailCheck = new BCheckBox("errorNotify", fNotifyFailCheck = new BCheckBox("errorNotify",
"Notify about update failures", new BMessage(kNotifyFailCheckbox)); "Notify about update failures", new BMessage(kNotifyFailCheckbox));
// Update scheduling // Update scheduling
fSchedulingBox = new BBox("scheduling"); fSchedulingBox = new BBox("scheduling");
fSchedulingBox->SetLabel("Scheduling"); fSchedulingBox->SetLabel("Scheduling");
@ -96,13 +95,15 @@ UpdatesView::_InitInterface()
fIntervalSlider->SetLimitLabels("Never", "24 hours"); fIntervalSlider->SetLimitLabels("Never", "24 hours");
fIntervalSlider->SetModificationMessage(new BMessage('iiii')); fIntervalSlider->SetModificationMessage(new BMessage('iiii'));
// Display current settings // Display current settings
if (((App*)be_app)->fPreferences->NotifyOnNew() == true) Preferences* prefs = ((App*)be_app)->fPreferences;
if (prefs->fNewNotify == true)
fNotifyNewCheck->SetValue(B_CONTROL_ON); fNotifyNewCheck->SetValue(B_CONTROL_ON);
if (((App*)be_app)->fPreferences->NotifyOnFailure() == true) if (prefs->fFailureNotify == true)
fNotifyFailCheck->SetValue(B_CONTROL_ON); fNotifyFailCheck->SetValue(B_CONTROL_ON);
fIntervalSlider->SetValue(((App*)be_app)->fPreferences->UpdateIntervalIndex()); fIntervalSlider->SetValue(prefs->UpdateIntervalIndex());
_UpdateIntervalLabel(); _UpdateIntervalLabel();

View File

@ -140,3 +140,9 @@ fetch(BUrl url, BDataIO* reply, BString* hash, int timeout)
} }
void
userFileError(status_t status, const char* path)
{
}

View File

@ -27,6 +27,8 @@ BString urlToFilename(BUrl url);
int32 fetch(BUrl url, BDataIO* reply, BString* hash, int timeout); int32 fetch(BUrl url, BDataIO* reply, BString* hash, int timeout);
void userFileError(status_t status, const char* path);
#endif
#endif // UTIL_H