Skip to content

Commit

Permalink
Merge pull request #6 from humdingerb/settings
Browse files Browse the repository at this point in the history
Settings and Replicant tweaks
  • Loading branch information
waddlesplash committed May 4, 2016
2 parents 6be06ed + 6bb90c1 commit b0c2849
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 64 deletions.
62 changes: 33 additions & 29 deletions sources/AutoFiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,30 @@
Written by DarkWyrm <darkwyrm@gmail.com>, Copyright 2008
Released under the MIT license.
*/
#include "AutoFiler.h"

#include <NodeMonitor.h>
#include <Roster.h>
#include <String.h>

#include "AutoFiler.h"
#include "FilerDefs.h"
#include "RefStorage.h"

App::App(void)
: BApplication("application/x-vnd.dw-AutoFiler")
App::App()
:
BApplication(kAutoFilerSignature)
{
LoadFolders();
StartWatching();
}


void
App::MessageReceived(BMessage *msg)
App::MessageReceived(BMessage* msg)
{
switch(msg->what)
{
case M_REFRESH_FOLDERS:
case MSG_REFRESH_FOLDERS:
{
StopWatching();
ReloadFolders();
Expand All @@ -42,25 +46,25 @@ App::MessageReceived(BMessage *msg)


void
App::StartWatching(void)
App::StartWatching()
{
gRefLock.Lock();

for (int32 i = 0; i < gRefStructList.CountItems(); i++)
{
RefStorage *refholder = (RefStorage*)gRefStructList.ItemAt(i);
watch_node(&refholder->nref,B_WATCH_ALL,this);
RefStorage* refholder = (RefStorage*)gRefStructList.ItemAt(i);
watch_node(&refholder->nref, B_WATCH_ALL, this);
}

gRefLock.Unlock();
}


void
App::HandleNodeMonitoring(BMessage *msg)
App::HandleNodeMonitoring(BMessage* msg)
{
int32 op;
msg->FindInt32("opcode",&op);
msg->FindInt32("opcode", &op);

switch (op)
{
Expand All @@ -69,30 +73,30 @@ App::HandleNodeMonitoring(BMessage *msg)
BString name;
entry_ref ref;

msg->FindInt32("device",&ref.device);
msg->FindInt64("directory",&ref.directory);
msg->FindString("name",&name);
msg->FindInt32("device", &ref.device);
msg->FindInt64("directory", &ref.directory);
msg->FindString("name", &name);
ref.set_name(name.String());

BMessage args(B_REFS_RECEIVED);
args.AddRef("refs",&ref);
be_roster->Launch("application/x-vnd.dw-Filer",&args);
args.AddRef("refs", &ref);
be_roster->Launch(kFilerSignature, &args);
break;
}
case B_ENTRY_MOVED:
{
// We only care if we're monitoring the "to" directory because
// the Filer doesn't care about files that aren't there anymore
node_ref nref;
msg->FindInt32("device",&nref.device);
msg->FindInt64("to directory",&nref.node);
msg->FindInt32("device", &nref.device);
msg->FindInt64("to directory", &nref.node);

gRefLock.Lock();

bool match = false;
for (int32 i = 0; i < gRefStructList.CountItems(); i++)
{
RefStorage *refholder = (RefStorage*)gRefStructList.ItemAt(i);
RefStorage* refholder = (RefStorage*)gRefStructList.ItemAt(i);
if (nref == refholder->nref)
{
match = true;
Expand All @@ -106,31 +110,31 @@ App::HandleNodeMonitoring(BMessage *msg)
{
BString name;
entry_ref ref;
msg->FindString("name",&name);
msg->FindString("name", &name);
ref.device = nref.device;
ref.directory = nref.node;
ref.set_name(name.String());

BMessage args(B_REFS_RECEIVED);
args.AddRef("refs",&ref);
be_roster->Launch("application/x-vnd.dw-Filer",&args);
args.AddRef("refs", &ref);
be_roster->Launch(kFilerSignature, &args);
}
break;
}
case B_STAT_CHANGED:
case B_ATTR_CHANGED:
{
node_ref nref;
msg->FindInt32("device",&nref.device);
msg->FindInt64("node",&nref.node);
msg->FindInt32("device", &nref.device);
msg->FindInt64("node", &nref.node);

gRefLock.Lock();

bool match = false;
entry_ref ref;
for (int32 i = 0; i < gRefStructList.CountItems(); i++)
{
RefStorage *refholder = (RefStorage*)gRefStructList.ItemAt(i);
RefStorage* refholder = (RefStorage*)gRefStructList.ItemAt(i);
if (nref == refholder->nref)
{
ref = refholder->ref;
Expand All @@ -144,8 +148,8 @@ App::HandleNodeMonitoring(BMessage *msg)
if (match)
{
BMessage args(B_REFS_RECEIVED);
args.AddRef("refs",&ref);
be_roster->Launch("application/x-vnd.dw-Filer",&args);
args.AddRef("refs", &ref);
be_roster->Launch(kFilerSignature, &args);
}
break;
}
Expand All @@ -156,16 +160,16 @@ App::HandleNodeMonitoring(BMessage *msg)


void
App::StopWatching(void)
App::StopWatching()
{
stop_watching(this);
}


int
main(int argc, char **argv)
main(int argc, char** argv)
{
App *app = new App;
App* app = new App;
app->Run();
delete app;

Expand Down
17 changes: 9 additions & 8 deletions sources/AutoFiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@
Written by DarkWyrm <darkwyrm@gmail.com>, Copyright 2008
Released under the MIT license.
*/
#ifndef MAIN_H
#define MAIN_H

#ifndef AUTOFILER_H
#define AUTOFILER_H

#include <Application.h>
#include <Message.h>

class App : public BApplication
{
public:
App(void);
void MessageReceived(BMessage *msg);
App();
void MessageReceived(BMessage* msg);

private:
void HandleNodeMonitoring(BMessage *msg);
void StartWatching(void);
void StopWatching(void);
void HandleNodeMonitoring(BMessage* msg);
void StartWatching();
void StopWatching();
};

#endif
#endif // AUTOFILER_H
58 changes: 42 additions & 16 deletions sources/AutoFilerTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@

AutoFilerTab::AutoFilerTab()
:
BView("AutoFiler", B_SUPPORTS_LAYOUT)
BView("AutoFiler", B_SUPPORTS_LAYOUT),
fDirtySettings(false)
{
LoadFolders();
_BuildLayout();
Expand Down Expand Up @@ -75,7 +76,8 @@ AutoFilerTab::_BuildLayout()
fFolderList->SetInvocationMessage(new BMessage(MSG_SHOW_EDIT_PANEL));

fAutorunBox = new BCheckBox("autorunbox",
"Run AutoFiler on system startup", new BMessage);
"Run AutoFiler on system startup",
new BMessage(MSG_AUTOFILER_AUTORUN));

fStartStop = new BButton("startstop", "Start AutoFiler",
new BMessage(MSG_STARTSTOP_AUTOFILER));
Expand Down Expand Up @@ -132,8 +134,7 @@ AutoFilerTab::_BuildLayout()
void
AutoFilerTab::AttachedToWindow()
{
// SetFlags(Flags() | B_FULL_UPDATE_ON_RESIZE | B_NAVIGABLE);

fAutorunBox->SetTarget(this);
fStartStop->SetTarget(this);
fAddButton->SetTarget(this);
fEditButton->SetTarget(this);
Expand All @@ -157,6 +158,9 @@ AutoFilerTab::AttachedToWindow()
void
AutoFilerTab::DetachedFromWindow()
{
if (!fDirtySettings)
return;

SaveFolders();

// save autorun value
Expand All @@ -171,18 +175,7 @@ AutoFilerTab::DetachedFromWindow()
node.WriteAttr("autorun", B_BOOL_TYPE, 0,
(void*)&autorun, sizeof(bool));
}
if (autorun)
EnableAutorun();
else
DisableAutorun();

// if AutoFiler is running, tell it to refresh its folders
if (be_roster->IsRunning("application/x-vnd.dw-AutoFiler"))
{
BMessage msg(MSG_REFRESH_FOLDERS);
BMessenger msgr("application/x-vnd.dw-AutoFiler");
msgr.SendMessage(&msg);
}
ToggleAutorun(autorun);
}


Expand All @@ -191,6 +184,11 @@ AutoFilerTab::MessageReceived(BMessage* msg)
{
switch (msg->what)
{
case MSG_AUTOFILER_AUTORUN:
{
ToggleAutorun(fAutorunBox->Value() == B_CONTROL_ON);
break;
}
case MSG_STARTSTOP_AUTOFILER:
{
ToggleAutoFiler();
Expand Down Expand Up @@ -234,6 +232,8 @@ AutoFilerTab::MessageReceived(BMessage* msg)
RefStorage* refholder = (RefStorage*)gRefStructList.RemoveItem(selection);
delete refholder;
gRefLock.Unlock();

UpdateAutoFilerFolders();
break;
}
case MSG_FOLDER_SELECTED:
Expand Down Expand Up @@ -272,6 +272,8 @@ AutoFilerTab::MessageReceived(BMessage* msg)

item->SetText(BPath(&ref).Path());
fFolderList->Invalidate();

UpdateAutoFilerFolders();
break;
}
default:
Expand Down Expand Up @@ -305,6 +307,30 @@ AutoFilerTab::UpdateAutoFilerLabel()
}


void
AutoFilerTab::UpdateAutoFilerFolders()
{
fDirtySettings = true;
// if AutoFiler is running, tell it to refresh its folders
if (be_roster->IsRunning(kAutoFilerSignature)) {
BMessage msg(MSG_REFRESH_FOLDERS);
BMessenger msgr(kAutoFilerSignature);
msgr.SendMessage(&msg);
}
}


void
AutoFilerTab::ToggleAutorun(bool autorun)
{
fDirtySettings = true;
if (autorun)
EnableAutorun();
else
DisableAutorun();
}


void
AutoFilerTab::EnableAutorun()
{
Expand Down
4 changes: 4 additions & 0 deletions sources/AutoFilerTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class AutoFilerTab : public BView
private:
void _BuildLayout();

void UpdateAutoFilerFolders();
void ToggleAutorun(bool autorun);
void EnableAutorun();
void DisableAutorun();

Expand All @@ -51,6 +53,8 @@ class AutoFilerTab : public BView
BFilePanel* fFilePanel;
TypedRefFilter* fRefFilter;
BMessageRunner* fRunner;

bool fDirtySettings;
};

#endif // AUTOFILERTAB_H
Loading

0 comments on commit b0c2849

Please sign in to comment.