xref: /haiku/src/tools/translation/inspector/InspectorApp.cpp (revision e7d5c75dce28921de0dc981ed840205a67a0c0e5)
1 /*****************************************************************************/
2 // InspectorApp
3 // Written by Michael Wilber, OBOS Translation Kit Team
4 //
5 // InspectorApp.cpp
6 //
7 // BApplication object for the Inspector application.  The purpose of
8 // Inspector is to provide the user with as much relevant information as
9 // possible about the currently open document.
10 //
11 //
12 // Copyright (c) 2003 OpenBeOS Project
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 /*****************************************************************************/
32 
33 #include "Constants.h"
34 #include "InspectorApp.h"
35 #include "ImageWindow.h"
36 #include "TranslatorItem.h"
37 
38 #include <Directory.h>
39 #include <Message.h>
40 #include <String.h>
41 #include <Window.h>
42 
43 #undef B_TRANSLATE_CONTEXT
44 #define B_TRANSLATE_CONTEXT "InspectorApp"
45 
46 
47 InspectorApp::InspectorApp()
48 	: BApplication(APP_SIG)
49 {
50 	fpActivesWin = NULL;
51 	fpInfoWin = NULL;
52 
53 	be_locale->GetAppCatalog(&fAppCatalog);
54 
55 	AddToTranslatorsList("/system/add-ons/Translators",
56 		SYSTEM_TRANSLATOR);
57 	AddToTranslatorsList("/boot/home/config/add-ons/Translators",
58 		USER_TRANSLATOR);
59 
60 	// Show application window
61 	BRect rect(100, 100, 500, 400);
62 	ImageWindow *pwin = new ImageWindow(rect, IMAGEWINDOW_TITLE);
63 	pwin->Show();
64 }
65 
66 void
67 InspectorApp::AddToTranslatorsList(const char *folder, int32 group)
68 {
69 	BDirectory dir;
70 	if (dir.SetTo(folder) == B_OK) {
71 
72 		BEntry ent;
73 		while (dir.GetNextEntry(&ent) == B_OK) {
74 			BPath path;
75 			if (ent.GetPath(&path) == B_OK)
76 				flstTranslators.AddItem(
77 					new BTranslatorItem(path.Leaf(), path.Path(), group));
78 		}
79 	}
80 }
81 
82 void
83 InspectorApp::MessageReceived(BMessage *pmsg)
84 {
85 	switch (pmsg->what) {
86 		case M_ACTIVE_TRANSLATORS_WINDOW:
87 			if (!fpActivesWin)
88 				fpActivesWin = new ActiveTranslatorsWindow(
89 					BRect(625, 350, 800, 600),
90 					B_TRANSLATE("Active Translators"),
91 					GetTranslatorsList());
92 			break;
93 		case M_ACTIVE_TRANSLATORS_WINDOW_QUIT:
94 			fpActivesWin = NULL;
95 			break;
96 
97 		case M_INFO_WINDOW:
98 			if (!fpInfoWin)
99 				fpInfoWin = new InfoWindow(BRect(625, 50, 800, 300),
100 					B_TRANSLATE_COMMENT("Info Win",
101 					"This is a quite narrow info window and title 'Info Win' "
102 					"is therefore shortened."), fbstrInfo.String());
103 			break;
104 		case M_INFO_WINDOW_QUIT:
105 			fpInfoWin = NULL;
106 			break;
107 		case M_INFO_WINDOW_TEXT:
108 			// If image view is telling me to
109 			// update the info window...
110 			pmsg->FindString("text", &fbstrInfo);
111 			if (fpInfoWin)
112 				fpInfoWin->PostMessage(pmsg);
113 			break;
114 
115 		default:
116 			BApplication::MessageReceived(pmsg);
117 			break;
118 	}
119 }
120 
121 void
122 InspectorApp::RefsReceived(BMessage *pmsg)
123 {
124 	pmsg->what = M_OPEN_FILE_PANEL;
125 	BWindow *pwin = WindowAt(0);
126 	if (pwin)
127 		pwin->PostMessage(pmsg);
128 }
129 
130 BList *
131 InspectorApp::GetTranslatorsList()
132 {
133 	return &flstTranslators;
134 }
135 
136 int main(int argc, char **argv)
137 {
138 	InspectorApp *papp = new InspectorApp();
139 
140 	papp->Run();
141 
142 	delete papp;
143 	papp = NULL;
144 
145 	return 0;
146 }
147 
148