From d1901581f44663de3630b1be0d2c3b221c4b4d81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sat, 19 Mar 2011 16:38:30 +0000 Subject: [PATCH] Introduced DataSource::InternalName(), which must be implemented by all derived classes. This is now used for storing and restoring DataSources in/from the ActivityView archive. Fixes replicant restoration after switching the preferred system language. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41027 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/activitymonitor/ActivityView.cpp | 5 +- src/apps/activitymonitor/DataSource.cpp | 117 ++++++++++++++++++++-- src/apps/activitymonitor/DataSource.h | 18 +++- 3 files changed, 130 insertions(+), 10 deletions(-) diff --git a/src/apps/activitymonitor/ActivityView.cpp b/src/apps/activitymonitor/ActivityView.cpp index d0054c687e..e7d98e7a56 100644 --- a/src/apps/activitymonitor/ActivityView.cpp +++ b/src/apps/activitymonitor/ActivityView.cpp @@ -643,9 +643,8 @@ ActivityView::_Init(const BMessage* settings) fHistoryBackgroundColor = *color; const char* name; - for (int32 i = 0; settings->FindString("source", i, &name) == B_OK; i++) { + for (int32 i = 0; settings->FindString("source", i, &name) == B_OK; i++) AddDataSource(DataSource::FindSource(name), settings); - } } @@ -700,7 +699,7 @@ ActivityView::SaveState(BMessage& state) const DataSource* source = fSources.ItemAt(i); if (!source->PerCPU() || source->CPU() == 0) - status = state.AddString("source", source->Name()); + status = state.AddString("source", source->InternalName()); if (status != B_OK) return status; diff --git a/src/apps/activitymonitor/DataSource.cpp b/src/apps/activitymonitor/DataSource.cpp index 347aa4d13f..b4609a9316 100644 --- a/src/apps/activitymonitor/DataSource.cpp +++ b/src/apps/activitymonitor/DataSource.cpp @@ -149,14 +149,14 @@ DataSource::Print(BString& text, int64 value) const const char* -DataSource::Name() const +DataSource::ShortLabel() const { return Label(); } const char* -DataSource::ShortLabel() const +DataSource::Name() const { return Label(); } @@ -243,11 +243,11 @@ DataSource::SourceAt(int32 index) /*static*/ const DataSource* -DataSource::FindSource(const char* name) +DataSource::FindSource(const char* internalName) { for (uint32 i = 0; i < kSourcesCount; i++) { const DataSource* source = kSources[i]; - if (!strcmp(source->Name(), name)) + if (!strcmp(source->InternalName(), internalName)) return source; } @@ -330,6 +330,13 @@ UsedMemoryDataSource::NextValue(SystemInfo& info) } +const char* +UsedMemoryDataSource::InternalName() const +{ + return "Used memory"; +} + + const char* UsedMemoryDataSource::Label() const { @@ -379,6 +386,13 @@ CachedMemoryDataSource::NextValue(SystemInfo& info) } +const char* +CachedMemoryDataSource::InternalName() const +{ + return "Cached memory"; +} + + const char* CachedMemoryDataSource::Label() const { @@ -431,6 +445,13 @@ SwapSpaceDataSource::NextValue(SystemInfo& info) } +const char* +SwapSpaceDataSource::InternalName() const +{ + return "Swap space"; +} + + const char* SwapSpaceDataSource::Label() const { @@ -486,6 +507,13 @@ BlockCacheDataSource::NextValue(SystemInfo& info) } +const char* +BlockCacheDataSource::InternalName() const +{ + return "Block cache memory"; +} + + const char* BlockCacheDataSource::Label() const { @@ -533,6 +561,13 @@ SemaphoresDataSource::NextValue(SystemInfo& info) } +const char* +SemaphoresDataSource::InternalName() const +{ + return "Semaphores"; +} + + const char* SemaphoresDataSource::Label() const { @@ -587,6 +622,13 @@ PortsDataSource::NextValue(SystemInfo& info) } +const char* +PortsDataSource::InternalName() const +{ + return "Ports"; +} + + const char* PortsDataSource::Label() const { @@ -634,6 +676,13 @@ ThreadsDataSource::NextValue(SystemInfo& info) } +const char* +ThreadsDataSource::InternalName() const +{ + return "Threads"; +} + + const char* ThreadsDataSource::Label() const { @@ -681,6 +730,13 @@ TeamsDataSource::NextValue(SystemInfo& info) } +const char* +TeamsDataSource::InternalName() const +{ + return "Teams"; +} + + const char* TeamsDataSource::Label() const { @@ -728,6 +784,13 @@ RunningAppsDataSource::NextValue(SystemInfo& info) } +const char* +RunningAppsDataSource::InternalName() const +{ + return "Running applications"; +} + + const char* RunningAppsDataSource::Label() const { @@ -840,6 +903,13 @@ CPUUsageDataSource::ShortLabel() const } +const char* +CPUUsageDataSource::InternalName() const +{ + return "CPU usage"; +} + + const char* CPUUsageDataSource::Name() const { @@ -982,6 +1052,13 @@ CPUCombinedUsageDataSource::ShortLabel() const } +const char* +CPUCombinedUsageDataSource::InternalName() const +{ + return "CPU usage (combined)"; +} + + const char* CPUCombinedUsageDataSource::Name() const { @@ -1081,6 +1158,13 @@ PageFaultsDataSource::ShortLabel() const } +const char* +PageFaultsDataSource::InternalName() const +{ + return "Page faults"; +} + + const char* PageFaultsDataSource::Name() const { @@ -1183,6 +1267,13 @@ NetworkUsageDataSource::ShortLabel() const } +const char* +NetworkUsageDataSource::InternalName() const +{ + return fIn ? "Network receive" : "Network send"; +} + + const char* NetworkUsageDataSource::Name() const { @@ -1253,11 +1344,18 @@ ClipboardSizeDataSource::NextValue(SystemInfo& info) } +const char* +ClipboardSizeDataSource::InternalName() const +{ + return fText ? "Text clipboard size" : "Raw clipboard size"; +} + + const char* ClipboardSizeDataSource::Label() const { - return fText ? - B_TRANSLATE("Text clipboard size") : B_TRANSLATE("Raw clipboard size"); + return fText ? B_TRANSLATE("Text clipboard size") + : B_TRANSLATE("Raw clipboard size"); } @@ -1308,6 +1406,13 @@ MediaNodesDataSource::NextValue(SystemInfo& info) } +const char* +MediaNodesDataSource::InternalName() const +{ + return "Media nodes"; +} + + const char* MediaNodesDataSource::Label() const { diff --git a/src/apps/activitymonitor/DataSource.h b/src/apps/activitymonitor/DataSource.h index 0a6d3ef9e8..8698b34dc1 100644 --- a/src/apps/activitymonitor/DataSource.h +++ b/src/apps/activitymonitor/DataSource.h @@ -38,6 +38,7 @@ public: virtual int64 NextValue(SystemInfo& info); virtual void Print(BString& text, int64 value) const; + virtual const char* InternalName() const = 0; virtual const char* Name() const; virtual const char* Label() const; virtual const char* ShortLabel() const; @@ -52,7 +53,7 @@ public: static int32 CountSources(); static const DataSource* SourceAt(int32 index); - static const DataSource* FindSource(const char* name); + static const DataSource* FindSource(const char* internalName); static int32 IndexOf(const DataSource* source); protected: @@ -81,6 +82,7 @@ public: virtual DataSource* Copy() const; virtual int64 NextValue(SystemInfo& info); + virtual const char* InternalName() const; virtual const char* Label() const; virtual const char* ShortLabel() const; virtual bool Primary() const; @@ -95,6 +97,7 @@ public: virtual DataSource* Copy() const; virtual int64 NextValue(SystemInfo& info); + virtual const char* InternalName() const; virtual const char* Label() const; virtual const char* ShortLabel() const; virtual bool Primary() const; @@ -109,6 +112,7 @@ public: virtual DataSource* Copy() const; virtual int64 NextValue(SystemInfo& info); + virtual const char* InternalName() const; virtual const char* Label() const; virtual const char* ShortLabel() const; virtual bool Primary() const; @@ -123,6 +127,7 @@ public: virtual DataSource* Copy() const; virtual int64 NextValue(SystemInfo& info); + virtual const char* InternalName() const; virtual const char* Label() const; virtual const char* ShortLabel() const; }; @@ -136,6 +141,7 @@ public: virtual DataSource* Copy() const; virtual int64 NextValue(SystemInfo& info); + virtual const char* InternalName() const; virtual const char* Label() const; virtual const char* ShortLabel() const; virtual bool AdaptiveScale() const; @@ -150,6 +156,7 @@ public: virtual DataSource* Copy() const; virtual int64 NextValue(SystemInfo& info); + virtual const char* InternalName() const; virtual const char* Label() const; virtual bool AdaptiveScale() const; }; @@ -163,6 +170,7 @@ public: virtual DataSource* Copy() const; virtual int64 NextValue(SystemInfo& info); + virtual const char* InternalName() const; virtual const char* Label() const; virtual bool AdaptiveScale() const; }; @@ -176,6 +184,7 @@ public: virtual DataSource* Copy() const; virtual int64 NextValue(SystemInfo& info); + virtual const char* InternalName() const; virtual const char* Label() const; virtual bool AdaptiveScale() const; }; @@ -189,6 +198,7 @@ public: virtual DataSource* Copy() const; virtual int64 NextValue(SystemInfo& info); + virtual const char* InternalName() const; virtual const char* Label() const; virtual const char* ShortLabel() const; virtual bool AdaptiveScale() const; @@ -207,6 +217,7 @@ public: virtual void Print(BString& text, int64 value) const; virtual int64 NextValue(SystemInfo& info); + virtual const char* InternalName() const; virtual const char* Name() const; virtual const char* Label() const; virtual const char* ShortLabel() const; @@ -238,6 +249,7 @@ public: virtual void Print(BString& text, int64 value) const; virtual int64 NextValue(SystemInfo& info); + virtual const char* InternalName() const; virtual const char* Name() const; virtual const char* Label() const; virtual const char* ShortLabel() const; @@ -263,6 +275,7 @@ public: virtual void Print(BString& text, int64 value) const; virtual int64 NextValue(SystemInfo& info); + virtual const char* InternalName() const; virtual const char* Name() const; virtual const char* Label() const; virtual const char* ShortLabel() const; @@ -287,6 +300,7 @@ public: virtual void Print(BString& text, int64 value) const; virtual int64 NextValue(SystemInfo& info); + virtual const char* InternalName() const; virtual const char* Name() const; virtual const char* Label() const; virtual const char* ShortLabel() const; @@ -312,6 +326,7 @@ public: virtual int64 NextValue(SystemInfo& info); + virtual const char* InternalName() const; virtual const char* Label() const; virtual const char* Unit() const; virtual bool AdaptiveScale() const; @@ -328,6 +343,7 @@ public: virtual DataSource* Copy() const; + virtual const char* InternalName() const; virtual int64 NextValue(SystemInfo& info); virtual const char* Label() const; virtual bool AdaptiveScale() const;