xref: /haiku/src/preferences/backgrounds/Backgrounds.cpp (revision 1d9d47fc72028bb71b5f232a877231e59cfe2438)
1 /*
2  * Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Jerome Duval (jerome.duval@free.fr)
7  *		Axel Dörfler, axeld@pinc-software.de
8  */
9 
10 
11 #include "BackgroundsView.h"
12 
13 #include <Application.h>
14 #include <TrackerAddOn.h>
15 #include <Window.h>
16 
17 
18 static const char *kSignature = "application/x-vnd.haiku-backgrounds";
19 
20 
21 class BackgroundsApplication : public BApplication {
22 	public:
23 		BackgroundsApplication();
24 };
25 
26 class BackgroundsWindow : public BWindow {
27 	public:
28 		BackgroundsWindow(BRect frame, bool standalone = true);
29 
30 		void ProcessRefs(entry_ref dir, BMessage* refs);
31 
32 	protected:
33 		virtual	bool QuitRequested();
34 		virtual void WorkspaceActivated(int32 oldWorkspaces, bool active);
35 
36 		BackgroundsView *fBackgroundsView;
37 		bool fIsStandalone;
38 };
39 
40 
41 //	#pragma mark -
42 
43 
44 BackgroundsApplication::BackgroundsApplication()
45 	: BApplication(kSignature)
46 {
47 	BWindow* window = new BackgroundsWindow(BRect(100, 100, 570, 325));
48 	window->Show();
49 }
50 
51 
52 //	#pragma mark -
53 
54 
55 BackgroundsWindow::BackgroundsWindow(BRect frame, bool standalone)
56 	: BWindow(frame, "Backgrounds", B_TITLED_WINDOW,
57 		B_NOT_RESIZABLE | B_NOT_ZOOMABLE, B_ALL_WORKSPACES),
58 		fIsStandalone(standalone)
59 {
60 	fBackgroundsView = new BackgroundsView(Bounds(), "BackgroundsView",
61 		B_FOLLOW_ALL, B_WILL_DRAW);
62 	AddChild(fBackgroundsView);
63 }
64 
65 
66 bool
67 BackgroundsWindow::QuitRequested()
68 {
69 	fBackgroundsView->SaveSettings();
70 	if (fIsStandalone)
71 		be_app->PostMessage(B_QUIT_REQUESTED);
72 
73 	return true;
74 }
75 
76 
77 void
78 BackgroundsWindow::WorkspaceActivated(int32 oldWorkspaces, bool active)
79 {
80 	fBackgroundsView->WorkspaceActivated(oldWorkspaces, active);
81 }
82 
83 
84 void
85 BackgroundsWindow::ProcessRefs(entry_ref dir, BMessage* refs)
86 {
87 	fBackgroundsView->ProcessRefs(dir, refs);
88 }
89 
90 
91 //	#pragma mark -
92 
93 
94 /*!
95 	\brief Tracker add-on entry
96 */
97 void
98 process_refs(entry_ref dir, BMessage* refs, void* /*reserved*/)
99 {
100 	BackgroundsWindow* window = new BackgroundsWindow(BRect(100, 100, 570, 325), false);
101 	window->ProcessRefs(dir, refs);
102 	snooze(500);
103 	window->Show();
104 
105 	status_t status;
106 	wait_for_thread(window->Thread(), &status);
107 }
108 
109 
110 int
111 main(int argc, char** argv)
112 {
113 	BApplication* app = new BackgroundsApplication;
114 
115 	// This function doesn't return until the application quits
116 	app->Run();
117 	delete app;
118 
119 	return 0;
120 }
121 
122 
123