Really really useless clipboard size data source (both flattened message size and plain text size). I should rather go to sleep than write useless code :D
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25014 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
e8fa461ae7
commit
e034d18f42
@ -7,6 +7,7 @@
|
||||
#include "DataSource.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <OS.h>
|
||||
#include <String.h>
|
||||
@ -25,7 +26,9 @@ const DataSource* kSources[] = {
|
||||
new CPUUsageDataSource(),
|
||||
new CPUCombinedUsageDataSource(),
|
||||
new NetworkUsageDataSource(true),
|
||||
new NetworkUsageDataSource(false)
|
||||
new NetworkUsageDataSource(false),
|
||||
new ClipboardSizeDataSource(false),
|
||||
new ClipboardSizeDataSource(true)
|
||||
};
|
||||
const size_t kSourcesCount = sizeof(kSources) / sizeof(kSources[0]);
|
||||
|
||||
@ -880,3 +883,68 @@ NetworkUsageDataSource::AdaptiveScale() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
ClipboardSizeDataSource::ClipboardSizeDataSource(bool text)
|
||||
{
|
||||
fMinimum = 0;
|
||||
fMaximum = UINT32_MAX;
|
||||
fText = text;
|
||||
|
||||
fColor = (rgb_color){0, 150, 255};
|
||||
}
|
||||
|
||||
|
||||
ClipboardSizeDataSource::ClipboardSizeDataSource(
|
||||
const ClipboardSizeDataSource& other)
|
||||
: DataSource(other)
|
||||
{
|
||||
fText = other.fText;
|
||||
}
|
||||
|
||||
|
||||
ClipboardSizeDataSource::~ClipboardSizeDataSource()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DataSource*
|
||||
ClipboardSizeDataSource::Copy() const
|
||||
{
|
||||
return new ClipboardSizeDataSource(*this);
|
||||
}
|
||||
|
||||
|
||||
int64
|
||||
ClipboardSizeDataSource::NextValue(SystemInfo& info)
|
||||
{
|
||||
if (fText)
|
||||
return info.ClipboardTextSize()/* / 1024*/;
|
||||
return info.ClipboardSize()/* / 1024*/;
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
ClipboardSizeDataSource::Label() const
|
||||
{
|
||||
return fText ? "Text Clipboard Size" : "Raw Clipboard Size";
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
ClipboardSizeDataSource::Unit() const
|
||||
{
|
||||
return "bytes"/*"KB"*/;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
ClipboardSizeDataSource::AdaptiveScale() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -227,4 +227,24 @@ private:
|
||||
bigtime_t fPreviousTime;
|
||||
};
|
||||
|
||||
|
||||
class ClipboardSizeDataSource : public DataSource {
|
||||
public:
|
||||
ClipboardSizeDataSource(bool text);
|
||||
ClipboardSizeDataSource(
|
||||
const ClipboardSizeDataSource& other);
|
||||
virtual ~ClipboardSizeDataSource();
|
||||
|
||||
virtual DataSource* Copy() const;
|
||||
|
||||
virtual int64 NextValue(SystemInfo& info);
|
||||
|
||||
virtual const char* Label() const;
|
||||
virtual const char* Unit() const;
|
||||
virtual bool AdaptiveScale() const;
|
||||
|
||||
private:
|
||||
bool fText;
|
||||
};
|
||||
|
||||
#endif // DATA_SOURCE_H
|
||||
|
@ -19,12 +19,16 @@ SystemInfo::SystemInfo(SystemInfoHandler *handler)
|
||||
:
|
||||
fTime(system_time()),
|
||||
fRetrievedNetwork(false),
|
||||
fRunningApps(0)
|
||||
fRunningApps(0),
|
||||
fClipboardSize(0),
|
||||
fClipboardTextSize(0)
|
||||
{
|
||||
get_system_info(&fSystemInfo);
|
||||
|
||||
if (handler) {
|
||||
fRunningApps = handler->RunningApps();
|
||||
fClipboardSize = handler->ClipboardSize();
|
||||
fClipboardTextSize = handler->ClipboardTextSize();
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,20 +119,6 @@ SystemInfo::MaxTeams() const
|
||||
}
|
||||
|
||||
|
||||
uint32
|
||||
SystemInfo::UsedRunningApps() const
|
||||
{
|
||||
return fRunningApps;
|
||||
}
|
||||
|
||||
|
||||
uint32
|
||||
SystemInfo::MaxRunningApps() const
|
||||
{
|
||||
return fSystemInfo.max_teams;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SystemInfo::_RetrieveNetwork()
|
||||
{
|
||||
@ -205,3 +195,33 @@ SystemInfo::NetworkSent()
|
||||
_RetrieveNetwork();
|
||||
return fBytesSent;
|
||||
}
|
||||
|
||||
|
||||
uint32
|
||||
SystemInfo::UsedRunningApps() const
|
||||
{
|
||||
return fRunningApps;
|
||||
}
|
||||
|
||||
|
||||
uint32
|
||||
SystemInfo::MaxRunningApps() const
|
||||
{
|
||||
return fSystemInfo.max_teams;
|
||||
}
|
||||
|
||||
|
||||
uint32
|
||||
SystemInfo::ClipboardSize() const
|
||||
{
|
||||
return fClipboardSize;
|
||||
}
|
||||
|
||||
|
||||
uint32
|
||||
SystemInfo::ClipboardTextSize() const
|
||||
{
|
||||
return fClipboardTextSize;
|
||||
}
|
||||
|
||||
|
||||
|
@ -32,9 +32,6 @@ public:
|
||||
uint32 UsedTeams() const;
|
||||
uint32 MaxTeams() const;
|
||||
|
||||
uint32 UsedRunningApps() const;
|
||||
uint32 MaxRunningApps() const;
|
||||
|
||||
bigtime_t Time() const { return fTime; }
|
||||
uint32 CPUCount() const { return fSystemInfo.cpu_count; }
|
||||
const system_info& Info() const { return fSystemInfo; }
|
||||
@ -42,6 +39,12 @@ public:
|
||||
uint64 NetworkReceived();
|
||||
uint64 NetworkSent();
|
||||
|
||||
uint32 UsedRunningApps() const;
|
||||
uint32 MaxRunningApps() const;
|
||||
|
||||
uint32 ClipboardSize() const;
|
||||
uint32 ClipboardTextSize() const;
|
||||
|
||||
private:
|
||||
void _RetrieveNetwork();
|
||||
|
||||
@ -51,6 +54,8 @@ private:
|
||||
uint64 fBytesReceived;
|
||||
uint64 fBytesSent;
|
||||
uint32 fRunningApps;
|
||||
uint32 fClipboardSize;
|
||||
uint32 fClipboardTextSize;
|
||||
};
|
||||
|
||||
#endif // SYSTEM_INFO_H
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "SystemInfoHandler.h"
|
||||
|
||||
#include <Clipboard.h>
|
||||
#include <Handler.h>
|
||||
#include <List.h>
|
||||
#include <Messenger.h>
|
||||
@ -39,23 +40,34 @@ void
|
||||
SystemInfoHandler::StartWatchingStuff()
|
||||
{
|
||||
fRunningApps = 0;
|
||||
fClipboardSize = 0;
|
||||
fClipboardTextSize = 0;
|
||||
|
||||
// running applications count
|
||||
BList teamList;
|
||||
be_roster->StartWatching(BMessenger(this),
|
||||
B_REQUEST_LAUNCHED | B_REQUEST_QUIT);
|
||||
be_roster->GetAppList(&teamList);
|
||||
fRunningApps = teamList.CountItems();
|
||||
teamList.MakeEmpty();
|
||||
if (be_roster) {
|
||||
be_roster->StartWatching(BMessenger(this),
|
||||
B_REQUEST_LAUNCHED | B_REQUEST_QUIT);
|
||||
be_roster->GetAppList(&teamList);
|
||||
fRunningApps = teamList.CountItems();
|
||||
teamList.MakeEmpty();
|
||||
}
|
||||
|
||||
//
|
||||
// useless clipboard size
|
||||
if (be_clipboard) {
|
||||
be_clipboard->StartWatching(BMessenger(this));
|
||||
_UpdateClipboardData();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SystemInfoHandler::StopWatchingStuff()
|
||||
{
|
||||
be_roster->StopWatching(BMessenger(this));
|
||||
if (be_roster)
|
||||
be_roster->StopWatching(BMessenger(this));
|
||||
if (be_clipboard)
|
||||
be_clipboard->StopWatching(BMessenger(this));
|
||||
}
|
||||
|
||||
|
||||
@ -71,6 +83,9 @@ SystemInfoHandler::MessageReceived(BMessage *message)
|
||||
fRunningApps--;
|
||||
// XXX: maybe resync periodically in case we miss one
|
||||
break;
|
||||
case B_CLIPBOARD_CHANGED:
|
||||
_UpdateClipboardData();
|
||||
break;
|
||||
default:
|
||||
BHandler::MessageReceived(message);
|
||||
}
|
||||
@ -83,3 +98,38 @@ SystemInfoHandler::RunningApps() const
|
||||
return fRunningApps;
|
||||
}
|
||||
|
||||
|
||||
uint32
|
||||
SystemInfoHandler::ClipboardSize() const
|
||||
{
|
||||
return fClipboardSize;
|
||||
}
|
||||
|
||||
|
||||
uint32
|
||||
SystemInfoHandler::ClipboardTextSize() const
|
||||
{
|
||||
return fClipboardTextSize;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,10 +24,15 @@ public:
|
||||
void MessageReceived(BMessage *message);
|
||||
|
||||
uint32 RunningApps() const;
|
||||
uint32 ClipboardSize() const;
|
||||
uint32 ClipboardTextSize() const;
|
||||
|
||||
private:
|
||||
void _UpdateClipboardData();
|
||||
|
||||
uint32 fRunningApps;
|
||||
uint32 fClipboardSize;
|
||||
uint32 fClipboardTextSize;
|
||||
};
|
||||
|
||||
#endif // SYSTEM_INFO_HANDLER_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user