vfs: check userland buffers before reading them.
[haiku.git] / src / apps / login / DesktopWindow.cpp
blob374f83896b027c511b5051852cb1f13578c4ec23
1 /*
2 * Copyright 2008, François Revol, <revol@free.fr>. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
7 #include <string.h>
8 #include <stdio.h>
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>
19 #include "LoginApp.h"
20 #include "DesktopWindow.h"
22 #undef B_TRANSLATION_CONTEXT
23 #define B_TRANSLATION_CONTEXT "Desktop Window"
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)
36 BScreen screen;
37 BView *desktop = new BView(Bounds(), "desktop", B_FOLLOW_NONE, 0);
38 desktop->SetViewColor(screen.DesktopColor());
39 AddChild(desktop);
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);
58 fDesktopShelf = new BShelf(&ref, desktop, fEditShelfMode, "DesktopShelf");
59 if (fDesktopShelf)
60 fDesktopShelf->SetDisplaysZombies(true);
64 DesktopWindow::~DesktopWindow()
66 delete fDesktopShelf;
70 bool
71 DesktopWindow::QuitRequested()
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();
82 void
83 DesktopWindow::DispatchMessage(BMessage *message, BHandler *handler)
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);