118d3e65eSAxel Dörfler/*
22603848dSAxel Dörfler * Copyright 2008-2015, Axel D��rfler, axeld@pinc-software.de.
318d3e65eSAxel Dörfler * Distributed under the terms of the MIT License.
418d3e65eSAxel Dörfler */
518d3e65eSAxel Dörfler
618d3e65eSAxel Dörfler
718d3e65eSAxel Dörfler#include "ActivityWindow.h"
818d3e65eSAxel Dörfler
918d3e65eSAxel Dörfler#include <stdio.h>
1018d3e65eSAxel Dörfler
1118d3e65eSAxel Dörfler#include <Application.h>
124840a72fSPhilippe Houdoin#include <Catalog.h>
1318d3e65eSAxel Dörfler#include <File.h>
1418d3e65eSAxel Dörfler#include <FindDirectory.h>
15cbd4bc95SFrançois Revol#ifdef __HAIKU__
163a4a2141SAxel Dörfler#include <GroupLayout.h>
17cbd4bc95SFrançois Revol#endif
1818d3e65eSAxel Dörfler#include <Menu.h>
1918d3e65eSAxel Dörfler#include <MenuBar.h>
2018d3e65eSAxel Dörfler#include <MenuItem.h>
2118d3e65eSAxel Dörfler#include <Path.h>
2218d3e65eSAxel Dörfler#include <Roster.h>
2318d3e65eSAxel Dörfler
2418d3e65eSAxel Dörfler#include "ActivityMonitor.h"
2518d3e65eSAxel Dörfler#include "ActivityView.h"
2651591198SAxel Dörfler#include "DataSource.h"
271bb87bd0SAxel Dörfler#include "SettingsWindow.h"
2818d3e65eSAxel Dörfler
29546208a5SOliver Tappe#undef B_TRANSLATION_CONTEXT
30546208a5SOliver Tappe#define B_TRANSLATION_CONTEXT "ActivityWindow"
3118d3e65eSAxel Dörfler
32f4b00418SRyan Leavengood
333f315b26SAxel Dörflerstatic const uint32 kMsgAddView = 'advw';
346cf270f8SDancsó Róbertstatic const uint32 kMsgAlwaysOnTop = 'alot';
35f4b00418SRyan Leavengoodstatic const uint32 kMsgShowSettings = 'shst';
363a4a2141SAxel Dörfler
373a4a2141SAxel Dörfler
3818d3e65eSAxel DörflerActivityWindow::ActivityWindow()
3947798a10SJonas Sundström	:
40560ff447SJonas Sundström	BWindow(BRect(100, 100, 500, 350), B_TRANSLATE_SYSTEM_NAME("ActivityMonitor"),
4147798a10SJonas Sundström	B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE)
4218d3e65eSAxel Dörfler{
4318d3e65eSAxel Dörfler	BMessage settings;
4418d3e65eSAxel Dörfler	_LoadSettings(settings);
4518d3e65eSAxel Dörfler
4618d3e65eSAxel Dörfler	BRect frame;
4718d3e65eSAxel Dörfler	if (settings.FindRect("window frame", &frame) == B_OK) {
4818d3e65eSAxel Dörfler		MoveTo(frame.LeftTop());
4918d3e65eSAxel Dörfler		ResizeTo(frame.Width(), frame.Height());
502603848dSAxel Dörfler	} else {
512603848dSAxel Dörfler		float scaling = be_plain_font->Size() / 12.0f;
522603848dSAxel Dörfler		ResizeTo(Frame().Width() * scaling, Frame().Height() * scaling);
532603848dSAxel Dörfler		CenterOnScreen();
543a4a2141SAxel Dörfler	}
553a4a2141SAxel Dörfler
56cbd4bc95SFrançois Revol#ifdef __HAIKU__
578b0cc2eaSAlex Wilson	BGroupLayout* layout = new BGroupLayout(B_VERTICAL, 0);
583a4a2141SAxel Dörfler	SetLayout(layout);
5918d3e65eSAxel Dörfler
6018d3e65eSAxel Dörfler	// create GUI
6118d3e65eSAxel Dörfler
623a4a2141SAxel Dörfler	BMenuBar* menuBar = new BMenuBar("menu");
633a4a2141SAxel Dörfler	layout->AddView(menuBar);
6418d3e65eSAxel Dörfler
653a4a2141SAxel Dörfler	fLayout = new BGroupLayout(B_VERTICAL);
663a4a2141SAxel Dörfler	float inset = ceilf(be_plain_font->Size() * 0.7);
67d0ac6099SHumdinger	fLayout->SetInsets(B_USE_WINDOW_SPACING);
683a4a2141SAxel Dörfler	fLayout->SetSpacing(inset);
6918d3e65eSAxel Dörfler
703a4a2141SAxel Dörfler	BView* top = new BView("top", 0, fLayout);
713a4a2141SAxel Dörfler	layout->AddView(top);
72fa19dd44Slooncraz	top->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
733a4a2141SAxel Dörfler
743a4a2141SAxel Dörfler	BMessage viewState;
753a4a2141SAxel Dörfler	int32 count = 0;
763a4a2141SAxel Dörfler	for (int32 i = 0; settings.FindMessage("activity view", i, &viewState)
773a4a2141SAxel Dörfler			== B_OK; i++) {
78065e8de0SAxel Dörfler		ActivityView* view = new ActivityView("ActivityMonitor", &viewState);
79065e8de0SAxel Dörfler		fLayout->AddItem(view->CreateHistoryLayoutItem());
80065e8de0SAxel Dörfler		fLayout->AddItem(view->CreateLegendLayoutItem());
813a4a2141SAxel Dörfler		count++;
823a4a2141SAxel Dörfler	}
83065e8de0SAxel Dörfler	if (count == 0) {
8451591198SAxel Dörfler		// Add default views (memory & CPU usage)
8551591198SAxel Dörfler		_AddDefaultView();
8651591198SAxel Dörfler		_AddDefaultView();
87065e8de0SAxel Dörfler	}
8851591198SAxel Dörfler#else	// !__HAIKU__
89cbd4bc95SFrançois Revol	BView *layout = new BView(Bounds(), "topmost", B_FOLLOW_NONE, 0);
90cbd4bc95SFrançois Revol	AddChild(layout);
9100d5cfaaSAxel Dörfler
92cbd4bc95SFrançois Revol	// create GUI
93cbd4bc95SFrançois Revol	BRect mbRect(Bounds());
94cbd4bc95SFrançois Revol	mbRect.bottom = 10;
95cbd4bc95SFrançois Revol	BMenuBar* menuBar = new BMenuBar(mbRect, "menu");
96cbd4bc95SFrançois Revol	layout->AddChild(menuBar);
97cbd4bc95SFrançois Revol
98cbd4bc95SFrançois Revol	BRect topRect(Bounds());
99cbd4bc95SFrançois Revol	topRect.top = menuBar->Bounds().bottom + 1;
100cbd4bc95SFrançois Revol
101cbd4bc95SFrançois Revol	BView* top = new BView(topRect, "top", B_FOLLOW_ALL, 0);
102cbd4bc95SFrançois Revol	layout->AddChild(top);
103cbd4bc95SFrançois Revol
104cbd4bc95SFrançois Revol	BMessage viewState;
105cbd4bc95SFrançois Revol	int32 count = 0;
106cbd4bc95SFrançois Revol	ActivityView *aview;
107cbd4bc95SFrançois Revol	BRect rect;
108cbd4bc95SFrançois Revol	for (int32 i = 0; settings.FindMessage("activity view", i, &viewState)
109cbd4bc95SFrançois Revol			== B_OK; i++) {
110cbd4bc95SFrançois Revol		aview = new ActivityView("ActivityMonitor", &viewState);
111cbd4bc95SFrançois Revol		if (!rect.IsValid())
112cbd4bc95SFrançois Revol			rect = aview->Bounds();
113cbd4bc95SFrançois Revol		else
114cbd4bc95SFrançois Revol			rect.OffsetBySelf(0.0, aview->Bounds().Height());
115cbd4bc95SFrançois Revol		top->AddChild(aview);
116cbd4bc95SFrançois Revol		count++;
117cbd4bc95SFrançois Revol	}
118cbd4bc95SFrançois Revol	if (count == 0)
119cbd4bc95SFrançois Revol		top->AddChild(new ActivityView("ActivityMonitor", NULL));
120cbd4bc95SFrançois Revol
121cbd4bc95SFrançois Revol#endif
12218d3e65eSAxel Dörfler	// add menu
12318d3e65eSAxel Dörfler
12418d3e65eSAxel Dörfler	// "File" menu
1254840a72fSPhilippe Houdoin	BMenu* menu = new BMenu(B_TRANSLATE("File"));
1264840a72fSPhilippe Houdoin	menu->AddItem(new BMenuItem(B_TRANSLATE("Add graph"),
1274840a72fSPhilippe Houdoin		new BMessage(kMsgAddView)));
1283a4a2141SAxel Dörfler	menu->AddSeparatorItem();
1293a4a2141SAxel Dörfler
1304840a72fSPhilippe Houdoin	menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"),
1314840a72fSPhilippe Houdoin		new BMessage(B_QUIT_REQUESTED), 'Q'));
13218d3e65eSAxel Dörfler	menu->SetTargetForItems(this);
13318d3e65eSAxel Dörfler	menuBar->AddItem(menu);
1341bb87bd0SAxel Dörfler
1351bb87bd0SAxel Dörfler	// "Settings" menu
1364840a72fSPhilippe Houdoin	menu = new BMenu(B_TRANSLATE("Settings"));
1374840a72fSPhilippe Houdoin	menu->AddItem(new BMenuItem(B_TRANSLATE("Settings" B_UTF8_ELLIPSIS),
1381bb87bd0SAxel Dörfler		new BMessage(kMsgShowSettings)));
139f4b00418SRyan Leavengood
1406cf270f8SDancsó Róbert	menu->AddSeparatorItem();
1416cf270f8SDancsó Róbert	fAlwaysOnTop = new BMenuItem(B_TRANSLATE("Always on top"), new BMessage(kMsgAlwaysOnTop));
14257ad8744SRyan Leavengood	_SetAlwaysOnTop(settings.GetBool("always on top", false));
1436cf270f8SDancsó Róbert	menu->AddItem(fAlwaysOnTop);
144f4b00418SRyan Leavengood
1451bb87bd0SAxel Dörfler	menu->SetTargetForItems(this);
1461bb87bd0SAxel Dörfler	menuBar->AddItem(menu);
14718d3e65eSAxel Dörfler}
14818d3e65eSAxel Dörfler
14918d3e65eSAxel Dörfler
15018d3e65eSAxel DörflerActivityWindow::~ActivityWindow()
15118d3e65eSAxel Dörfler{
15218d3e65eSAxel Dörfler}
15318d3e65eSAxel Dörfler
15418d3e65eSAxel Dörfler
1551bb87bd0SAxel Dörflervoid
1561bb87bd0SAxel DörflerActivityWindow::MessageReceived(BMessage* message)
1571bb87bd0SAxel Dörfler{
1581bb87bd0SAxel Dörfler	if (message->WasDropped()) {
1591bb87bd0SAxel Dörfler		_MessageDropped(message);
1601bb87bd0SAxel Dörfler		return;
1611bb87bd0SAxel Dörfler	}
1621bb87bd0SAxel Dörfler
1631bb87bd0SAxel Dörfler	switch (message->what) {
1641bb87bd0SAxel Dörfler		case B_REFS_RECEIVED:
1651bb87bd0SAxel Dörfler		case B_SIMPLE_DATA:
1661bb87bd0SAxel Dörfler			_MessageDropped(message);
1671bb87bd0SAxel Dörfler			break;
1681bb87bd0SAxel Dörfler
1691bb87bd0SAxel Dörfler		case kMsgAddView:
1701bb87bd0SAxel Dörfler		{
1711bb87bd0SAxel Dörfler#ifdef __HAIKU__
1721bb87bd0SAxel Dörfler			BView* firstView = fLayout->View()->ChildAt(0);
1731bb87bd0SAxel Dörfler
1741bb87bd0SAxel Dörfler			_AddDefaultView();
1751bb87bd0SAxel Dörfler
1761bb87bd0SAxel Dörfler			if (firstView != NULL)
1771bb87bd0SAxel Dörfler				ResizeBy(0, firstView->Bounds().Height() + fLayout->Spacing());
1781bb87bd0SAxel Dörfler#endif
1791bb87bd0SAxel Dörfler			break;
1801bb87bd0SAxel Dörfler		}
1811bb87bd0SAxel Dörfler
1821bb87bd0SAxel Dörfler		case kMsgRemoveView:
1831bb87bd0SAxel Dörfler		{
1841bb87bd0SAxel Dörfler#ifdef __HAIKU__
1851bb87bd0SAxel Dörfler			BView* view;
1861bb87bd0SAxel Dörfler			if (message->FindPointer("view", (void**)&view) != B_OK)
1871bb87bd0SAxel Dörfler				break;
1881bb87bd0SAxel Dörfler
1891bb87bd0SAxel Dörfler			view->RemoveSelf();
1901bb87bd0SAxel Dörfler			ResizeBy(0, -view->Bounds().Height() - fLayout->Spacing());
1911bb87bd0SAxel Dörfler			delete view;
1921bb87bd0SAxel Dörfler#endif
1931bb87bd0SAxel Dörfler			break;
1941bb87bd0SAxel Dörfler		}
1951bb87bd0SAxel Dörfler
1961bb87bd0SAxel Dörfler		case kMsgShowSettings:
1971bb87bd0SAxel Dörfler		{
1981bb87bd0SAxel Dörfler			if (fSettingsWindow.IsValid()) {
1991bb87bd0SAxel Dörfler				// Just bring the window to front (via scripting)
2001bb87bd0SAxel Dörfler				BMessage toFront(B_SET_PROPERTY);
2011bb87bd0SAxel Dörfler				toFront.AddSpecifier("Active");
2021bb87bd0SAxel Dörfler				toFront.AddBool("data", true);
2031bb87bd0SAxel Dörfler				fSettingsWindow.SendMessage(&toFront);
2041bb87bd0SAxel Dörfler			} else {
2051bb87bd0SAxel Dörfler				// Open new settings window
2061bb87bd0SAxel Dörfler				BWindow* window = new SettingsWindow(this);
2071bb87bd0SAxel Dörfler				window->Show();
2081bb87bd0SAxel Dörfler
2091bb87bd0SAxel Dörfler				fSettingsWindow = window;
2101bb87bd0SAxel Dörfler			}
2111bb87bd0SAxel Dörfler			break;
2121bb87bd0SAxel Dörfler		}
213b58ffb0bSMatt Madia
2146cf270f8SDancsó Róbert		case kMsgAlwaysOnTop:
2156cf270f8SDancsó Róbert		{
216f4b00418SRyan Leavengood			_SetAlwaysOnTop(!fAlwaysOnTop->IsMarked());
2176cf270f8SDancsó Róbert			break;
2186cf270f8SDancsó Róbert		}
2191bb87bd0SAxel Dörfler
2201bb87bd0SAxel Dörfler		case kMsgTimeIntervalUpdated:
2211bb87bd0SAxel Dörfler			BroadcastToActivityViews(message);
2221bb87bd0SAxel Dörfler			break;
2231bb87bd0SAxel Dörfler
2241bb87bd0SAxel Dörfler		default:
2251bb87bd0SAxel Dörfler			BWindow::MessageReceived(message);
2261bb87bd0SAxel Dörfler			break;
2271bb87bd0SAxel Dörfler	}
2281bb87bd0SAxel Dörfler}
2291bb87bd0SAxel Dörfler
2301bb87bd0SAxel Dörfler
2311bb87bd0SAxel Dörflerbool
2321bb87bd0SAxel DörflerActivityWindow::QuitRequested()
2331bb87bd0SAxel Dörfler{
2341bb87bd0SAxel Dörfler	_SaveSettings();
2351bb87bd0SAxel Dörfler	be_app->PostMessage(B_QUIT_REQUESTED);
2361bb87bd0SAxel Dörfler	return true;
2371bb87bd0SAxel Dörfler}
2381bb87bd0SAxel Dörfler
2391bb87bd0SAxel Dörfler
2401bb87bd0SAxel Dörflerint32
2411bb87bd0SAxel DörflerActivityWindow::ActivityViewCount() const
2421bb87bd0SAxel Dörfler{
2431bb87bd0SAxel Dörfler#ifdef __HAIKU__
2441bb87bd0SAxel Dörfler	return fLayout->View()->CountChildren();
2451bb87bd0SAxel Dörfler#else
2461bb87bd0SAxel Dörfler	return 1;
2471bb87bd0SAxel Dörfler#endif
2481bb87bd0SAxel Dörfler}
2491bb87bd0SAxel Dörfler
2501bb87bd0SAxel Dörfler
2511bb87bd0SAxel DörflerActivityView*
2521bb87bd0SAxel DörflerActivityWindow::ActivityViewAt(int32 index) const
2531bb87bd0SAxel Dörfler{
2541bb87bd0SAxel Dörfler	return dynamic_cast<ActivityView*>(fLayout->View()->ChildAt(index));
2551bb87bd0SAxel Dörfler}
2561bb87bd0SAxel Dörfler
2571bb87bd0SAxel Dörfler
25889e0a7fbSFreeman Loubool
25989e0a7fbSFreeman LouActivityWindow::IsAlwaysOnTop() const
26089e0a7fbSFreeman Lou{
2612031159eSJérôme Duval	return fAlwaysOnTop->IsMarked();
26289e0a7fbSFreeman Lou}
26389e0a7fbSFreeman Lou
26489e0a7fbSFreeman Lou
2651bb87bd0SAxel Dörflervoid
2661bb87bd0SAxel DörflerActivityWindow::BroadcastToActivityViews(BMessage* message, BView* exceptToView)
2671bb87bd0SAxel Dörfler{
2681bb87bd0SAxel Dörfler	BView* view;
2691bb87bd0SAxel Dörfler	for (int32 i = 0; (view = ActivityViewAt(i)) != NULL; i++) {
2701bb87bd0SAxel Dörfler		if (view != exceptToView)
2711bb87bd0SAxel Dörfler			PostMessage(message, view);
2721bb87bd0SAxel Dörfler	}
2731bb87bd0SAxel Dörfler}
2741bb87bd0SAxel Dörfler
2751bb87bd0SAxel Dörfler
2761bb87bd0SAxel Dörflerbigtime_t
2771bb87bd0SAxel DörflerActivityWindow::RefreshInterval() const
2781bb87bd0SAxel Dörfler{
2791bb87bd0SAxel Dörfler	ActivityView* view = ActivityViewAt(0);
2801bb87bd0SAxel Dörfler	if (view != 0)
2811bb87bd0SAxel Dörfler		return view->RefreshInterval();
2821bb87bd0SAxel Dörfler
2831bb87bd0SAxel Dörfler	return 100000;
2841bb87bd0SAxel Dörfler}
2851bb87bd0SAxel Dörfler
2861bb87bd0SAxel Dörfler
28718d3e65eSAxel Dörflerstatus_t
28818d3e65eSAxel DörflerActivityWindow::_OpenSettings(BFile& file, uint32 mode)
28918d3e65eSAxel Dörfler{
29018d3e65eSAxel Dörfler	BPath path;
29118d3e65eSAxel Dörfler	if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
29218d3e65eSAxel Dörfler		return B_ERROR;
29318d3e65eSAxel Dörfler
29418d3e65eSAxel Dörfler	path.Append("ActivityMonitor settings");
29518d3e65eSAxel Dörfler
29618d3e65eSAxel Dörfler	return file.SetTo(path.Path(), mode);
29718d3e65eSAxel Dörfler}
29818d3e65eSAxel Dörfler
29918d3e65eSAxel Dörfler
30018d3e65eSAxel Dörflerstatus_t
30118d3e65eSAxel DörflerActivityWindow::_LoadSettings(BMessage& settings)
30218d3e65eSAxel Dörfler{
30318d3e65eSAxel Dörfler	BFile file;
30418d3e65eSAxel Dörfler	status_t status = _OpenSettings(file, B_READ_ONLY);
30518d3e65eSAxel Dörfler	if (status < B_OK)
30618d3e65eSAxel Dörfler		return status;
30718d3e65eSAxel Dörfler
30818d3e65eSAxel Dörfler	return settings.Unflatten(&file);
30918d3e65eSAxel Dörfler}
31018d3e65eSAxel Dörfler
31118d3e65eSAxel Dörfler
31218d3e65eSAxel Dörflerstatus_t
31318d3e65eSAxel DörflerActivityWindow::_SaveSettings()
31418d3e65eSAxel Dörfler{
31518d3e65eSAxel Dörfler	BFile file;
31618d3e65eSAxel Dörfler	status_t status = _OpenSettings(file, B_WRITE_ONLY | B_CREATE_FILE
31718d3e65eSAxel Dörfler		| B_ERASE_FILE);
31818d3e65eSAxel Dörfler	if (status < B_OK)
31918d3e65eSAxel Dörfler		return status;
32018d3e65eSAxel Dörfler
32118d3e65eSAxel Dörfler	BMessage settings('actm');
32218d3e65eSAxel Dörfler	status = settings.AddRect("window frame", Frame());
3233a4a2141SAxel Dörfler	if (status != B_OK)
3243a4a2141SAxel Dörfler		return status;
3253a4a2141SAxel Dörfler
32657ad8744SRyan Leavengood	status = settings.SetBool("always on top", fAlwaysOnTop->IsMarked());
327f4b00418SRyan Leavengood	if (status != B_OK)
328f4b00418SRyan Leavengood		return status;
329f4b00418SRyan Leavengood
330cbd4bc95SFrançois Revol#ifdef __HAIKU__
33100d5cfaaSAxel Dörfler	BView* top = fLayout->View();
332cbd4bc95SFrançois Revol#else
33300d5cfaaSAxel Dörfler	BView* top = ChildAt(0);
334cbd4bc95SFrançois Revol#endif
3353a4a2141SAxel Dörfler	int32 count = top->CountChildren();
3363a4a2141SAxel Dörfler	for (int32 i = 0; i < count; i++) {
3373a4a2141SAxel Dörfler		ActivityView* view = dynamic_cast<ActivityView*>(top->ChildAt(i));
3383a4a2141SAxel Dörfler		if (view == NULL)
3393a4a2141SAxel Dörfler			continue;
3403a4a2141SAxel Dörfler
3418361c0f1SMichael Lotz		BMessage viewState;
3428361c0f1SMichael Lotz		status = view->SaveState(viewState);
3433a4a2141SAxel Dörfler		if (status == B_OK)
3448361c0f1SMichael Lotz			status = settings.AddMessage("activity view", &viewState);
3458361c0f1SMichael Lotz		if (status != B_OK)
3463a4a2141SAxel Dörfler			break;
3473a4a2141SAxel Dörfler	}
3483a4a2141SAxel Dörfler
34918d3e65eSAxel Dörfler	if (status == B_OK)
35018d3e65eSAxel Dörfler		status = settings.Flatten(&file);
35118d3e65eSAxel Dörfler
35218d3e65eSAxel Dörfler	return status;
35318d3e65eSAxel Dörfler}
35418d3e65eSAxel Dörfler
35518d3e65eSAxel Dörfler
35651591198SAxel Dörflervoid
35751591198SAxel DörflerActivityWindow::_AddDefaultView()
35851591198SAxel Dörfler{
359e3bf105aSPhilippe Saint-Pierre	BMessage settings;
360e3bf105aSPhilippe Saint-Pierre	settings.AddInt64("refresh interval", RefreshInterval());
361e3bf105aSPhilippe Saint-Pierre
362e3bf105aSPhilippe Saint-Pierre	ActivityView* view = new ActivityView("ActivityMonitor", &settings);
36351591198SAxel Dörfler
36451591198SAxel Dörfler	switch (ActivityViewCount()) {
36551591198SAxel Dörfler		case 0:
36651591198SAxel Dörfler			// The first view defaults to memory usage
36751591198SAxel Dörfler			view->AddDataSource(new UsedMemoryDataSource());
36851591198SAxel Dörfler			view->AddDataSource(new CachedMemoryDataSource());
36985200a1cSAugustin Cavalier			view->AddDataSource(new SwapSpaceDataSource());
37051591198SAxel Dörfler			break;
37151591198SAxel Dörfler		case 2:
37251591198SAxel Dörfler			// The third view defaults to network in/out
37351591198SAxel Dörfler			view->AddDataSource(new NetworkUsageDataSource(true));
37451591198SAxel Dörfler			view->AddDataSource(new NetworkUsageDataSource(false));
37551591198SAxel Dörfler			break;
37651591198SAxel Dörfler		case 1:
37751591198SAxel Dörfler		default:
37851591198SAxel Dörfler			// Everything beyond that defaults to a CPU usage view
37951591198SAxel Dörfler			view->AddDataSource(new CPUUsageDataSource());
38051591198SAxel Dörfler			break;
38151591198SAxel Dörfler	}
38251591198SAxel Dörfler
38351591198SAxel Dörfler	fLayout->AddItem(view->CreateHistoryLayoutItem());
38451591198SAxel Dörfler	fLayout->AddItem(view->CreateLegendLayoutItem());
38551591198SAxel Dörfler}
38651591198SAxel Dörfler
38751591198SAxel Dörfler
38818d3e65eSAxel Dörflervoid
3891bb87bd0SAxel DörflerActivityWindow::_MessageDropped(BMessage* message)
39018d3e65eSAxel Dörfler{
3911bb87bd0SAxel Dörfler	entry_ref ref;
3921bb87bd0SAxel Dörfler	if (message->FindRef("refs", &ref) != B_OK) {
3931bb87bd0SAxel Dörfler		// TODO: If app, then launch it, and add ActivityView for this one?
39418d3e65eSAxel Dörfler	}
39518d3e65eSAxel Dörfler}
39618d3e65eSAxel Dörfler
397f4b00418SRyan Leavengood
398f4b00418SRyan Leavengoodvoid
399f4b00418SRyan LeavengoodActivityWindow::_SetAlwaysOnTop(bool alwaysOnTop)
400f4b00418SRyan Leavengood{
401f4b00418SRyan Leavengood	SetFeel(alwaysOnTop ? B_FLOATING_ALL_WINDOW_FEEL : B_NORMAL_WINDOW_FEEL);
402f4b00418SRyan Leavengood	fAlwaysOnTop->SetMarked(alwaysOnTop);
4032031159eSJérôme Duval	if (fSettingsWindow.IsValid() && alwaysOnTop) {
4042031159eSJérôme Duval		// Change the settings window feel to modal (via scripting)
4052031159eSJérôme Duval		BMessage toFront(B_SET_PROPERTY);
4062031159eSJérôme Duval		toFront.AddSpecifier("Feel");
4072031159eSJérôme Duval		toFront.AddInt32("data", B_MODAL_ALL_WINDOW_FEEL);
4082031159eSJérôme Duval		fSettingsWindow.SendMessage(&toFront);
4092031159eSJérôme Duval	}
410f4b00418SRyan Leavengood}
411