From 6f6ba87580e5a06ad8b4e9eb3e509426351fa77a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 18 Apr 2008 11:08:34 +0000 Subject: [PATCH] =?UTF-8?q?*=20Amazing:=20Fran=C3=A7ois=20writes=20almost?= =?UTF-8?q?=20style=20compliant=20code!=20:-)=20*=20Minor=20cleanup=20-=20?= =?UTF-8?q?I=20haven't=20written=20SystemInfoHandler,=20Fran=C3=A7ois=20di?= =?UTF-8?q?d.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25017 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/activitymonitor/ActivityView.cpp | 8 +- src/apps/activitymonitor/SystemInfo.cpp | 8 +- .../activitymonitor/SystemInfoHandler.cpp | 74 ++++++++++--------- src/apps/activitymonitor/SystemInfoHandler.h | 12 ++- 4 files changed, 53 insertions(+), 49 deletions(-) diff --git a/src/apps/activitymonitor/ActivityView.cpp b/src/apps/activitymonitor/ActivityView.cpp index bf59a05199..4f3a21ebf1 100644 --- a/src/apps/activitymonitor/ActivityView.cpp +++ b/src/apps/activitymonitor/ActivityView.cpp @@ -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; } diff --git a/src/apps/activitymonitor/SystemInfo.cpp b/src/apps/activitymonitor/SystemInfo.cpp index 157c4add8e..f84b238476 100644 --- a/src/apps/activitymonitor/SystemInfo.cpp +++ b/src/apps/activitymonitor/SystemInfo.cpp @@ -10,12 +10,12 @@ #include #include #include -#include #include #include +#include -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(); diff --git a/src/apps/activitymonitor/SystemInfoHandler.cpp b/src/apps/activitymonitor/SystemInfoHandler.cpp index 612484bd1f..8ef5d294f0 100644 --- a/src/apps/activitymonitor/SystemInfoHandler.cpp +++ b/src/apps/activitymonitor/SystemInfoHandler.cpp @@ -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 +#include +#include + #include #include #include #include #include -#include -#include -#include 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(); } diff --git a/src/apps/activitymonitor/SystemInfoHandler.h b/src/apps/activitymonitor/SystemInfoHandler.h index a83dfa7926..bd7512b32a 100644 --- a/src/apps/activitymonitor/SystemInfoHandler.h +++ b/src/apps/activitymonitor/SystemInfoHandler.h @@ -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 #include 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;