* 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

View File

@ -184,7 +184,7 @@ ActivityView::_Init(const BMessage* settings)
fDrawInterval = kInitialRefreshInterval * 2;
fLastRefresh = 0;
fDrawResolution = 1;
fSystemInfoHandler = new SystemInfoHandler;
if (settings == NULL
@ -354,7 +354,8 @@ void
ActivityView::AttachedToWindow()
{
Looper()->AddHandler(fSystemInfoHandler);
fSystemInfoHandler->StartWatchingStuff();
fSystemInfoHandler->StartWatching();
BMessage refresh(kMsgRefresh);
fRunner = new BMessageRunner(this, &refresh, fRefreshInterval);
@ -365,8 +366,9 @@ ActivityView::AttachedToWindow()
void
ActivityView::DetachedFromWindow()
{
fSystemInfoHandler->StopWatchingStuff();
fSystemInfoHandler->StopWatching();
Looper()->RemoveHandler(fSystemInfoHandler);
delete fRunner;
}

View File

@ -10,12 +10,12 @@
#include <net/if.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/sockio.h>
#include <unistd.h>
SystemInfo::SystemInfo(SystemInfoHandler *handler)
SystemInfo::SystemInfo(SystemInfoHandler* handler)
:
fTime(system_time()),
fRetrievedNetwork(false),
@ -24,8 +24,8 @@ SystemInfo::SystemInfo(SystemInfoHandler *handler)
fClipboardTextSize(0)
{
get_system_info(&fSystemInfo);
if (handler) {
if (handler != NULL) {
fRunningApps = handler->RunningApps();
fClipboardSize = handler->ClipboardSize();
fClipboardTextSize = handler->ClipboardTextSize();

View File

@ -1,19 +1,20 @@
/*
* Copyright 2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
* Copyright 2008, François Revol, revol@free.fr. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include "SystemInfoHandler.h"
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <Clipboard.h>
#include <Handler.h>
#include <List.h>
#include <Messenger.h>
#include <Roster.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
SystemInfoHandler::SystemInfoHandler()
@ -28,7 +29,7 @@ SystemInfoHandler::~SystemInfoHandler()
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...
// return BHandler::Archive(data, deep);
@ -37,16 +38,16 @@ SystemInfoHandler::Archive(BMessage *data, bool deep) const
void
SystemInfoHandler::StartWatchingStuff()
SystemInfoHandler::StartWatching()
{
fRunningApps = 0;
fClipboardSize = 0;
fClipboardTextSize = 0;
// running applications count
BList teamList;
if (be_roster) {
be_roster->StartWatching(BMessenger(this),
be_roster->StartWatching(BMessenger(this),
B_REQUEST_LAUNCHED | B_REQUEST_QUIT);
be_roster->GetAppList(&teamList);
fRunningApps = teamList.CountItems();
@ -62,7 +63,7 @@ SystemInfoHandler::StartWatchingStuff()
void
SystemInfoHandler::StopWatchingStuff()
SystemInfoHandler::StopWatching()
{
if (be_roster)
be_roster->StopWatching(BMessenger(this));
@ -72,22 +73,22 @@ SystemInfoHandler::StopWatchingStuff()
void
SystemInfoHandler::MessageReceived(BMessage *message)
SystemInfoHandler::MessageReceived(BMessage* message)
{
switch (message->what) {
case B_SOME_APP_LAUNCHED:
fRunningApps++;
// XXX: maybe resync periodically in case we miss one
break;
case B_SOME_APP_QUIT:
fRunningApps--;
// XXX: maybe resync periodically in case we miss one
break;
case B_CLIPBOARD_CHANGED:
_UpdateClipboardData();
break;
default:
BHandler::MessageReceived(message);
case B_SOME_APP_LAUNCHED:
fRunningApps++;
// TODO: maybe resync periodically in case we miss one
break;
case B_SOME_APP_QUIT:
fRunningApps--;
// TODO: maybe resync periodically in case we miss one
break;
case B_CLIPBOARD_CHANGED:
_UpdateClipboardData();
break;
default:
BHandler::MessageReceived(message);
}
}
@ -118,18 +119,21 @@ SystemInfoHandler::_UpdateClipboardData()
{
fClipboardSize = 0;
fClipboardTextSize = 0;
if (be_clipboard && be_clipboard->Lock()) {
BMessage *data = be_clipboard->Data();
if (data) {
ssize_t size = data->FlattenedSize();
const void *text;
ssize_t textSize;
fClipboardSize = (size < 0) ? 0 : (uint32)size;
if (data->FindData("text/plain", B_MIME_TYPE, &text, &textSize)
>= B_OK)
fClipboardTextSize = textSize;
}
be_clipboard->Unlock();
if (be_clipboard == NULL || !be_clipboard->Lock())
return;
BMessage* data = be_clipboard->Data();
if (data) {
ssize_t size = data->FlattenedSize();
fClipboardSize = size < 0 ? 0 : (uint32)size;
const void* text;
ssize_t textSize;
if (data->FindData("text/plain", B_MIME_TYPE, &text, &textSize) >= B_OK)
fClipboardTextSize = textSize;
}
be_clipboard->Unlock();
}

View File

@ -1,27 +1,25 @@
/*
* Copyright 2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
* Copyright 2008, François Revol, revol@free.fr. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef SYSTEM_INFO_HANDLER_H
#define SYSTEM_INFO_HANDLER_H
#include <OS.h>
#include <Handler.h>
class SystemInfoHandler : public BHandler {
public:
SystemInfoHandler();
//SystemInfoHandler(BMessage *data);
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 StopWatchingStuff();
void StartWatching();
void StopWatching();
void MessageReceived(BMessage *message);
void MessageReceived(BMessage* message);
uint32 RunningApps() const;
uint32 ClipboardSize() const;