xref: /haiku/src/apps/expander/ExpanderApp.cpp (revision 97901ec593ec4dd50ac115c1c35a6d72f6e489a5)
1 /*
2  * Copyright 2004-2006, Jérôme DUVAL. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include "ExpanderApp.h"
8 #include "ExpanderWindow.h"
9 
10 #include <Alert.h>
11 #include <Catalog.h>
12 #include <Locale.h>
13 #include <TextView.h>
14 
15 ExpanderApp::ExpanderApp()
16 	: BApplication("application/x-vnd.Haiku-Expander")
17 {
18 	be_locale->GetAppCatalog(&fCatalog);
19 
20 	BPoint windowPosition = fSettings.Message().FindPoint("window_position");
21 	BRect windowFrame(0, 0, 450, 120);
22 	windowFrame.OffsetBy(windowPosition);
23 	BMessage settings(fSettings.Message());
24 	fWindow = new ExpanderWindow(windowFrame, NULL, &settings);
25 }
26 
27 
28 #undef B_TRANSLATE_CONTEXT
29 #define B_TRANSLATE_CONTEXT "About"
30 
31 void
32 ExpanderApp::AboutRequested()
33 {
34 	BString appName = B_TRANSLATE("Expander");
35 	int nameLength = appName.CountChars();
36 	BAlert* alert = new BAlert("about",
37 		appName.Append(B_TRANSLATE("\n\twritten by Jérôme Duval\n"
38 			"\tCopyright 2004-2006, Haiku Inc.\n\noriginal Be version by \n"
39 			"Dominic, Hiroshi, Peter, Pavel and Robert\n")),
40 		B_TRANSLATE("OK"));
41 	BTextView* view = alert->TextView();
42 	BFont font;
43 
44 	view->SetStylable(true);
45 
46 	view->GetFont(&font);
47 	font.SetSize(18);
48 	font.SetFace(B_BOLD_FACE);
49 	view->SetFontAndColor(0, nameLength, &font);
50 
51 	alert->Go();
52 }
53 
54 
55 void
56 ExpanderApp::ReadyToRun()
57 {
58 }
59 
60 
61 void
62 ExpanderApp::ArgvReceived(int32 argc, char **argv)
63 {
64 	BMessage* msg = NULL;
65 	for (int32 i = 1; i < argc; i++) {
66 		entry_ref ref;
67 		status_t err = get_ref_for_path(argv[i], &ref);
68 		if (err == B_OK) {
69 			if (!msg) {
70 				msg = new BMessage;
71 				msg->what = B_REFS_RECEIVED;
72 			}
73 			msg->AddRef("refs", &ref);
74 		}
75 	}
76 	if (msg)
77 		RefsReceived(msg);
78 }
79 
80 
81 void
82 ExpanderApp::RefsReceived(BMessage* msg)
83 {
84 	BMessenger messenger(fWindow);
85 	msg->AddBool("fromApp", true);
86 	messenger.SendMessage(msg);
87 }
88 
89 
90 void
91 ExpanderApp::UpdateSettingsFrom(BMessage* message)
92 {
93 	fSettings.UpdateFrom(message);
94 }
95 
96 
97 //	#pragma mark -
98 
99 
100 int
101 main(int, char **)
102 {
103 	ExpanderApp theApp;
104 	theApp.Run();
105 	return 0;
106 }
107