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:
@@ -7,6 +7,7 @@
|
|||||||
#include "DataSource.h"
|
#include "DataSource.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
@@ -25,7 +26,9 @@ const DataSource* kSources[] = {
|
|||||||
new CPUUsageDataSource(),
|
new CPUUsageDataSource(),
|
||||||
new CPUCombinedUsageDataSource(),
|
new CPUCombinedUsageDataSource(),
|
||||||
new NetworkUsageDataSource(true),
|
new NetworkUsageDataSource(true),
|
||||||
new NetworkUsageDataSource(false)
|
new NetworkUsageDataSource(false),
|
||||||
|
new ClipboardSizeDataSource(false),
|
||||||
|
new ClipboardSizeDataSource(true)
|
||||||
};
|
};
|
||||||
const size_t kSourcesCount = sizeof(kSources) / sizeof(kSources[0]);
|
const size_t kSourcesCount = sizeof(kSources) / sizeof(kSources[0]);
|
||||||
|
|
||||||
@@ -880,3 +883,68 @@ NetworkUsageDataSource::AdaptiveScale() const
|
|||||||
{
|
{
|
||||||
return true;
|
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;
|
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
|
#endif // DATA_SOURCE_H
|
||||||
|
|||||||
@@ -19,12 +19,16 @@ SystemInfo::SystemInfo(SystemInfoHandler *handler)
|
|||||||
:
|
:
|
||||||
fTime(system_time()),
|
fTime(system_time()),
|
||||||
fRetrievedNetwork(false),
|
fRetrievedNetwork(false),
|
||||||
fRunningApps(0)
|
fRunningApps(0),
|
||||||
|
fClipboardSize(0),
|
||||||
|
fClipboardTextSize(0)
|
||||||
{
|
{
|
||||||
get_system_info(&fSystemInfo);
|
get_system_info(&fSystemInfo);
|
||||||
|
|
||||||
if (handler) {
|
if (handler) {
|
||||||
fRunningApps = handler->RunningApps();
|
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
|
void
|
||||||
SystemInfo::_RetrieveNetwork()
|
SystemInfo::_RetrieveNetwork()
|
||||||
{
|
{
|
||||||
@@ -205,3 +195,33 @@ SystemInfo::NetworkSent()
|
|||||||
_RetrieveNetwork();
|
_RetrieveNetwork();
|
||||||
return fBytesSent;
|
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 UsedTeams() const;
|
||||||
uint32 MaxTeams() const;
|
uint32 MaxTeams() const;
|
||||||
|
|
||||||
uint32 UsedRunningApps() const;
|
|
||||||
uint32 MaxRunningApps() const;
|
|
||||||
|
|
||||||
bigtime_t Time() const { return fTime; }
|
bigtime_t Time() const { return fTime; }
|
||||||
uint32 CPUCount() const { return fSystemInfo.cpu_count; }
|
uint32 CPUCount() const { return fSystemInfo.cpu_count; }
|
||||||
const system_info& Info() const { return fSystemInfo; }
|
const system_info& Info() const { return fSystemInfo; }
|
||||||
@@ -42,6 +39,12 @@ public:
|
|||||||
uint64 NetworkReceived();
|
uint64 NetworkReceived();
|
||||||
uint64 NetworkSent();
|
uint64 NetworkSent();
|
||||||
|
|
||||||
|
uint32 UsedRunningApps() const;
|
||||||
|
uint32 MaxRunningApps() const;
|
||||||
|
|
||||||
|
uint32 ClipboardSize() const;
|
||||||
|
uint32 ClipboardTextSize() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _RetrieveNetwork();
|
void _RetrieveNetwork();
|
||||||
|
|
||||||
@@ -51,6 +54,8 @@ private:
|
|||||||
uint64 fBytesReceived;
|
uint64 fBytesReceived;
|
||||||
uint64 fBytesSent;
|
uint64 fBytesSent;
|
||||||
uint32 fRunningApps;
|
uint32 fRunningApps;
|
||||||
|
uint32 fClipboardSize;
|
||||||
|
uint32 fClipboardTextSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SYSTEM_INFO_H
|
#endif // SYSTEM_INFO_H
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "SystemInfoHandler.h"
|
#include "SystemInfoHandler.h"
|
||||||
|
|
||||||
|
#include <Clipboard.h>
|
||||||
#include <Handler.h>
|
#include <Handler.h>
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
#include <Messenger.h>
|
#include <Messenger.h>
|
||||||
@@ -39,23 +40,34 @@ void
|
|||||||
SystemInfoHandler::StartWatchingStuff()
|
SystemInfoHandler::StartWatchingStuff()
|
||||||
{
|
{
|
||||||
fRunningApps = 0;
|
fRunningApps = 0;
|
||||||
|
fClipboardSize = 0;
|
||||||
|
fClipboardTextSize = 0;
|
||||||
|
|
||||||
// running applications count
|
// running applications count
|
||||||
BList teamList;
|
BList teamList;
|
||||||
be_roster->StartWatching(BMessenger(this),
|
if (be_roster) {
|
||||||
B_REQUEST_LAUNCHED | B_REQUEST_QUIT);
|
be_roster->StartWatching(BMessenger(this),
|
||||||
be_roster->GetAppList(&teamList);
|
B_REQUEST_LAUNCHED | B_REQUEST_QUIT);
|
||||||
fRunningApps = teamList.CountItems();
|
be_roster->GetAppList(&teamList);
|
||||||
teamList.MakeEmpty();
|
fRunningApps = teamList.CountItems();
|
||||||
|
teamList.MakeEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
//
|
// useless clipboard size
|
||||||
|
if (be_clipboard) {
|
||||||
|
be_clipboard->StartWatching(BMessenger(this));
|
||||||
|
_UpdateClipboardData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SystemInfoHandler::StopWatchingStuff()
|
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--;
|
fRunningApps--;
|
||||||
// XXX: maybe resync periodically in case we miss one
|
// XXX: maybe resync periodically in case we miss one
|
||||||
break;
|
break;
|
||||||
|
case B_CLIPBOARD_CHANGED:
|
||||||
|
_UpdateClipboardData();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
BHandler::MessageReceived(message);
|
BHandler::MessageReceived(message);
|
||||||
}
|
}
|
||||||
@@ -83,3 +98,38 @@ SystemInfoHandler::RunningApps() const
|
|||||||
return fRunningApps;
|
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);
|
void MessageReceived(BMessage *message);
|
||||||
|
|
||||||
uint32 RunningApps() const;
|
uint32 RunningApps() const;
|
||||||
|
uint32 ClipboardSize() const;
|
||||||
|
uint32 ClipboardTextSize() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void _UpdateClipboardData();
|
||||||
|
|
||||||
uint32 fRunningApps;
|
uint32 fRunningApps;
|
||||||
|
uint32 fClipboardSize;
|
||||||
|
uint32 fClipboardTextSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SYSTEM_INFO_HANDLER_H
|
#endif // SYSTEM_INFO_HANDLER_H
|
||||||
|
|||||||
Reference in New Issue
Block a user