Skip to content

Commit

Permalink
Coding style
Browse files Browse the repository at this point in the history
Style cleanup for remaining AutoFiler source.
  • Loading branch information
Humdinger committed May 4, 2016
1 parent 94f1a50 commit 6bb90c1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 42 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
2 changes: 1 addition & 1 deletion sources/RefStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ LoadFolders()

entry_ref tempRef;
int32 i = 0;
while (msg.FindRef("refs",i,&tempRef) == B_OK)
while (msg.FindRef("refs", i, &tempRef) == B_OK)
{
i++;
RefStorage* refholder = new RefStorage(tempRef);
Expand Down
4 changes: 0 additions & 4 deletions sources/RefStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ extern BList gRefStructList;
extern BLocker gRefLock;
extern const char gPrefsPath[];

enum
{
M_REFRESH_FOLDERS = 'rffl'
};

class RefStorage
{
Expand Down

0 comments on commit 6bb90c1

Please sign in to comment.