* Amazing: François writes almost style compliant code! :-)

* Minor cleanup - I haven't written SystemInfoHandler, François did.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25017 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2008-04-18 11:08:34 +00:00
parent aa01c3e72e
commit 6f6ba87580
4 changed files with 53 additions and 49 deletions
+5 -3
View File
@@ -184,7 +184,7 @@ ActivityView::_Init(const BMessage* settings)
fDrawInterval = kInitialRefreshInterval * 2; fDrawInterval = kInitialRefreshInterval * 2;
fLastRefresh = 0; fLastRefresh = 0;
fDrawResolution = 1; fDrawResolution = 1;
fSystemInfoHandler = new SystemInfoHandler; fSystemInfoHandler = new SystemInfoHandler;
if (settings == NULL if (settings == NULL
@@ -354,7 +354,8 @@ void
ActivityView::AttachedToWindow() ActivityView::AttachedToWindow()
{ {
Looper()->AddHandler(fSystemInfoHandler); Looper()->AddHandler(fSystemInfoHandler);
fSystemInfoHandler->StartWatchingStuff(); fSystemInfoHandler->StartWatching();
BMessage refresh(kMsgRefresh); BMessage refresh(kMsgRefresh);
fRunner = new BMessageRunner(this, &refresh, fRefreshInterval); fRunner = new BMessageRunner(this, &refresh, fRefreshInterval);
@@ -365,8 +366,9 @@ ActivityView::AttachedToWindow()
void void
ActivityView::DetachedFromWindow() ActivityView::DetachedFromWindow()
{ {
fSystemInfoHandler->StopWatchingStuff(); fSystemInfoHandler->StopWatching();
Looper()->RemoveHandler(fSystemInfoHandler); Looper()->RemoveHandler(fSystemInfoHandler);
delete fRunner; delete fRunner;
} }
+4 -4
View File
@@ -10,12 +10,12 @@
#include <net/if.h> #include <net/if.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/sockio.h> #include <sys/sockio.h>
#include <unistd.h>
SystemInfo::SystemInfo(SystemInfoHandler *handler) SystemInfo::SystemInfo(SystemInfoHandler* handler)
: :
fTime(system_time()), fTime(system_time()),
fRetrievedNetwork(false), fRetrievedNetwork(false),
@@ -24,8 +24,8 @@ SystemInfo::SystemInfo(SystemInfoHandler *handler)
fClipboardTextSize(0) fClipboardTextSize(0)
{ {
get_system_info(&fSystemInfo); get_system_info(&fSystemInfo);
if (handler) { if (handler != NULL) {
fRunningApps = handler->RunningApps(); fRunningApps = handler->RunningApps();
fClipboardSize = handler->ClipboardSize(); fClipboardSize = handler->ClipboardSize();
fClipboardTextSize = handler->ClipboardTextSize(); fClipboardTextSize = handler->ClipboardTextSize();
+39 -35
View File
@@ -1,19 +1,20 @@
/* /*
* Copyright 2008, Axel Dörfler, [email protected]. All rights reserved. * Copyright 2008, François Revol, [email protected]. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include "SystemInfoHandler.h" #include "SystemInfoHandler.h"
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <Clipboard.h> #include <Clipboard.h>
#include <Handler.h> #include <Handler.h>
#include <List.h> #include <List.h>
#include <Messenger.h> #include <Messenger.h>
#include <Roster.h> #include <Roster.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
SystemInfoHandler::SystemInfoHandler() SystemInfoHandler::SystemInfoHandler()
@@ -28,7 +29,7 @@ SystemInfoHandler::~SystemInfoHandler()
status_t status_t
SystemInfoHandler::Archive(BMessage *data, bool deep) const SystemInfoHandler::Archive(BMessage* data, bool deep) const
{ {
// we don't want ourselves to be archived at all... // we don't want ourselves to be archived at all...
// return BHandler::Archive(data, deep); // return BHandler::Archive(data, deep);
@@ -37,16 +38,16 @@ SystemInfoHandler::Archive(BMessage *data, bool deep) const
void void
SystemInfoHandler::StartWatchingStuff() SystemInfoHandler::StartWatching()
{ {
fRunningApps = 0; fRunningApps = 0;
fClipboardSize = 0; fClipboardSize = 0;
fClipboardTextSize = 0; fClipboardTextSize = 0;
// running applications count // running applications count
BList teamList; BList teamList;
if (be_roster) { if (be_roster) {
be_roster->StartWatching(BMessenger(this), be_roster->StartWatching(BMessenger(this),
B_REQUEST_LAUNCHED | B_REQUEST_QUIT); B_REQUEST_LAUNCHED | B_REQUEST_QUIT);
be_roster->GetAppList(&teamList); be_roster->GetAppList(&teamList);
fRunningApps = teamList.CountItems(); fRunningApps = teamList.CountItems();
@@ -62,7 +63,7 @@ SystemInfoHandler::StartWatchingStuff()
void void
SystemInfoHandler::StopWatchingStuff() SystemInfoHandler::StopWatching()
{ {
if (be_roster) if (be_roster)
be_roster->StopWatching(BMessenger(this)); be_roster->StopWatching(BMessenger(this));
@@ -72,22 +73,22 @@ SystemInfoHandler::StopWatchingStuff()
void void
SystemInfoHandler::MessageReceived(BMessage *message) SystemInfoHandler::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
case B_SOME_APP_LAUNCHED: case B_SOME_APP_LAUNCHED:
fRunningApps++; fRunningApps++;
// XXX: maybe resync periodically in case we miss one // TODO: maybe resync periodically in case we miss one
break; break;
case B_SOME_APP_QUIT: case B_SOME_APP_QUIT:
fRunningApps--; fRunningApps--;
// XXX: maybe resync periodically in case we miss one // TODO: maybe resync periodically in case we miss one
break; break;
case B_CLIPBOARD_CHANGED: case B_CLIPBOARD_CHANGED:
_UpdateClipboardData(); _UpdateClipboardData();
break; break;
default: default:
BHandler::MessageReceived(message); BHandler::MessageReceived(message);
} }
} }
@@ -118,18 +119,21 @@ SystemInfoHandler::_UpdateClipboardData()
{ {
fClipboardSize = 0; fClipboardSize = 0;
fClipboardTextSize = 0; fClipboardTextSize = 0;
if (be_clipboard && be_clipboard->Lock()) {
BMessage *data = be_clipboard->Data(); if (be_clipboard == NULL || !be_clipboard->Lock())
if (data) { return;
ssize_t size = data->FlattenedSize();
const void *text; BMessage* data = be_clipboard->Data();
ssize_t textSize; if (data) {
fClipboardSize = (size < 0) ? 0 : (uint32)size; ssize_t size = data->FlattenedSize();
if (data->FindData("text/plain", B_MIME_TYPE, &text, &textSize) fClipboardSize = size < 0 ? 0 : (uint32)size;
>= B_OK)
fClipboardTextSize = textSize; const void* text;
} ssize_t textSize;
be_clipboard->Unlock(); if (data->FindData("text/plain", B_MIME_TYPE, &text, &textSize) >= B_OK)
fClipboardTextSize = textSize;
} }
be_clipboard->Unlock();
} }
+5 -7
View File
@@ -1,27 +1,25 @@
/* /*
* Copyright 2008, Axel Dörfler, [email protected]. All rights reserved. * Copyright 2008, François Revol, [email protected]. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef SYSTEM_INFO_HANDLER_H #ifndef SYSTEM_INFO_HANDLER_H
#define SYSTEM_INFO_HANDLER_H #define SYSTEM_INFO_HANDLER_H
#include <OS.h>
#include <Handler.h> #include <Handler.h>
class SystemInfoHandler : public BHandler { class SystemInfoHandler : public BHandler {
public: public:
SystemInfoHandler(); SystemInfoHandler();
//SystemInfoHandler(BMessage *data);
virtual ~SystemInfoHandler(); virtual ~SystemInfoHandler();
virtual status_t Archive(BMessage *data, bool deep = true) const; virtual status_t Archive(BMessage* data, bool deep = true) const;
void StartWatchingStuff(); void StartWatching();
void StopWatchingStuff(); void StopWatching();
void MessageReceived(BMessage *message); void MessageReceived(BMessage* message);
uint32 RunningApps() const; uint32 RunningApps() const;
uint32 ClipboardSize() const; uint32 ClipboardSize() const;