xref: /haiku/src/apps/login/DesktopWindow.cpp (revision 3798bf90cb8e5e55b3b5ec15f22dbc0dd0735fd0)
1 /*
2  * Copyright 2008, François Revol, <revol@free.fr>. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <string.h>
8 #include <stdio.h>
9 
10 #include <Catalog.h>
11 #include <Directory.h>
12 #include <Entry.h>
13 #include <FindDirectory.h>
14 #include <Path.h>
15 #include <Screen.h>
16 #include <View.h>
17 #include <WindowPrivate.h>
18 
19 #include "LoginApp.h"
20 #include "DesktopWindow.h"
21 
22 #undef B_TRANSLATION_CONTEXT
23 #define B_TRANSLATION_CONTEXT "Desktop Window"
24 
25 
DesktopWindow(BRect frame,bool editMode)26 DesktopWindow::DesktopWindow(BRect frame, bool editMode)
27 	: BWindow(frame, B_TRANSLATE("Desktop"),
28 		kDesktopWindowLook,
29 		kDesktopWindowFeel,
30 		B_NOT_MOVABLE | B_NOT_CLOSABLE | B_NOT_ZOOMABLE
31 		 | B_NOT_MINIMIZABLE | B_NOT_RESIZABLE
32 		 | B_ASYNCHRONOUS_CONTROLS,
33 		editMode?B_CURRENT_WORKSPACE:B_ALL_WORKSPACES),
34 	  fEditShelfMode(editMode)
35 {
36 	BScreen screen;
37 	BView *desktop = new BView(Bounds(), "desktop", B_FOLLOW_NONE, 0);
38 	desktop->SetViewColor(screen.DesktopColor());
39 	AddChild(desktop);
40 
41 	// load the shelf
42 	BPath path;
43 	status_t err;
44 	entry_ref ref;
45 	err = find_directory(B_SYSTEM_SETTINGS_DIRECTORY, &path, true);
46 	if (err >= B_OK) {
47 		BDirectory dir(path.Path());
48 		if (!dir.Contains("x-vnd.Haiku-Login", B_DIRECTORY_NODE))
49 			dir.CreateDirectory("x-vnd.Haiku-Login", NULL);
50 		path.Append("x-vnd.Haiku-Login");
51 		dir.SetTo(path.Path());
52 		if (!dir.Contains("Shelf", B_FILE_NODE))
53 			dir.CreateFile("Shelf", NULL);
54 		path.Append("Shelf");
55 		get_ref_for_path(path.Path(), &ref);
56 	}
57 
58 	fDesktopShelf = new BShelf(&ref, desktop, fEditShelfMode, "DesktopShelf");
59 	if (fDesktopShelf)
60 		fDesktopShelf->SetDisplaysZombies(true);
61 }
62 
63 
~DesktopWindow()64 DesktopWindow::~DesktopWindow()
65 {
66 	delete fDesktopShelf;
67 }
68 
69 
70 bool
QuitRequested()71 DesktopWindow::QuitRequested()
72 {
73 	status_t err;
74 	err = fDesktopShelf->Save();
75 	printf(B_TRANSLATE_COMMENT("error %s\n",
76 		"A return message from fDesktopShelf->Save(). It can be \"B_OK\""),
77 		strerror(err));
78 	return BWindow::QuitRequested();
79 }
80 
81 
82 void
DispatchMessage(BMessage * message,BHandler * handler)83 DesktopWindow::DispatchMessage(BMessage *message, BHandler *handler)
84 {
85 	switch (message->what) {
86 		case B_MOUSE_DOWN:
87 		case B_MOUSE_UP:
88 		case B_MOUSE_MOVED:
89 		case B_KEY_DOWN:
90 		case B_KEY_UP:
91 		case B_UNMAPPED_KEY_DOWN:
92 		case B_UNMAPPED_KEY_UP:
93 			/* don't allow interacting with the replicants */
94 			if (!fEditShelfMode)
95 				break;
96 		default:
97 		BWindow::DispatchMessage(message, handler);
98 	}
99 }
100 
101 
102