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