xref: /haiku/src/preferences/screensaver/ScreenSaverApp.cpp (revision f73f5d4c42a01ece688cbb57b5d332cc0f68b2c6)
1 /*
2  * Copyright 2003-2013 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Jérôme Duval, jerome.duval@free.fr
7  *		Michael Phipps
8  */
9 
10 
11 #include <Application.h>
12 #include <Entry.h>
13 #include <Path.h>
14 
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <unistd.h>
18 
19 #include "ScreenSaverWindow.h"
20 
21 
22 class ScreenSaverApp : public BApplication {
23 public:
24 	ScreenSaverApp();
25 	virtual void RefsReceived(BMessage* message);
26 
27 private:
28 	BWindow* fScreenSaverWindow;
29 };
30 
31 
32 //	#pragma mark - ScreenSaverApp
33 
34 
35 ScreenSaverApp::ScreenSaverApp()
36 	:
37 	BApplication("application/x-vnd.Haiku-ScreenSaver")
38 {
39 	fScreenSaverWindow = new ScreenSaverWindow();
40 	fScreenSaverWindow->Show();
41 }
42 
43 
44 void
45 ScreenSaverApp::RefsReceived(BMessage* message)
46 {
47 	entry_ref ref;
48 	if (message->FindRef("refs", &ref) != B_OK)
49 		return;
50 
51 	// Install the screen saver by copying it to the add-ons directory
52 	// TODO: the translator have a similar mechanism - this could be cleaned
53 	//       up and have one nicely working solution
54 	// TODO: should test if the dropped ref is really a screen saver!
55 	// TODO: you can receive more than one ref at a time...
56 
57 	BEntry entry;
58 	entry.SetTo(&ref, true);
59 	if (entry.InitCheck() != B_OK)
60 		return;
61 
62 	BPath path;
63 	entry.GetPath(&path);
64 
65 	// TODO: find_directory() anyone??
66 	char temp[B_PATH_NAME_LENGTH * 2];
67 	sprintf(temp, "cp %s '/boot/home/config/add-ons/Screen Savers/'\n",
68 		path.Path());
69 	system(temp);
70 
71 	fScreenSaverWindow->PostMessage(kMsgUpdateList);
72 }
73 
74 
75 //	#pragma mark - main()
76 
77 
78 int
79 main()
80 {
81 	ScreenSaverApp app;
82 	app.Run();
83 	return 0;
84 }
85