xref: /haiku/src/tools/translation/inspector/InspectorApp.cpp (revision 93aeb8c3bc3f13cb1f282e3e749258a23790d947)
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 "InspectorApp.h"
34 #include "Constants.h"
35 #include "ImageWindow.h"
36 #include "TranslatorItem.h"
37 #include <Window.h>
38 #include <Message.h>
39 #include <String.h>
40 #include <Directory.h>
41 
42 InspectorApp::InspectorApp()
43 	: BApplication(APP_SIG)
44 {
45 	fpActivesWin = NULL;
46 	fpInfoWin = NULL;
47 
48 	AddToTranslatorsList("/system/add-ons/Translators",
49 		SYSTEM_TRANSLATOR);
50 	AddToTranslatorsList("/boot/home/config/add-ons/Translators",
51 		USER_TRANSLATOR);
52 
53 	// Show application window
54 	BRect rect(100, 100, 500, 400);
55 	ImageWindow *pwin = new ImageWindow(rect, IMAGEWINDOW_TITLE);
56 	pwin->Show();
57 }
58 
59 void
60 InspectorApp::AddToTranslatorsList(const char *folder, int32 group)
61 {
62 	BDirectory dir;
63 	if (dir.SetTo(folder) == B_OK) {
64 
65 		BEntry ent;
66 		while (dir.GetNextEntry(&ent) == B_OK) {
67 			BPath path;
68 			if (ent.GetPath(&path) == B_OK)
69 				flstTranslators.AddItem(
70 					new BTranslatorItem(path.Leaf(), path.Path(), group));
71 		}
72 	}
73 }
74 
75 void
76 InspectorApp::MessageReceived(BMessage *pmsg)
77 {
78 	switch (pmsg->what) {
79 		case M_ACTIVE_TRANSLATORS_WINDOW:
80 			if (!fpActivesWin)
81 				fpActivesWin = new ActiveTranslatorsWindow(
82 					BRect(625, 350, 800, 600), "Active Translators",
83 					GetTranslatorsList());
84 			break;
85 		case M_ACTIVE_TRANSLATORS_WINDOW_QUIT:
86 			fpActivesWin = NULL;
87 			break;
88 
89 		case M_INFO_WINDOW:
90 			if (!fpInfoWin)
91 				fpInfoWin = new InfoWindow(BRect(625, 50, 800, 300),
92 					"Info Win", fbstrInfo.String());
93 			break;
94 		case M_INFO_WINDOW_QUIT:
95 			fpInfoWin = NULL;
96 			break;
97 		case M_INFO_WINDOW_TEXT:
98 			// If image view is telling me to
99 			// update the info window...
100 			pmsg->FindString("text", &fbstrInfo);
101 			if (fpInfoWin)
102 				fpInfoWin->PostMessage(pmsg);
103 			break;
104 
105 		default:
106 			BApplication::MessageReceived(pmsg);
107 			break;
108 	}
109 }
110 
111 void
112 InspectorApp::RefsReceived(BMessage *pmsg)
113 {
114 	pmsg->what = M_OPEN_FILE_PANEL;
115 	BWindow *pwin = WindowAt(0);
116 	if (pwin)
117 		pwin->PostMessage(pmsg);
118 }
119 
120 BList *
121 InspectorApp::GetTranslatorsList()
122 {
123 	return &flstTranslators;
124 }
125 
126 int main(int argc, char **argv)
127 {
128 	InspectorApp *papp = new InspectorApp();
129 	papp->Run();
130 
131 	delete papp;
132 	papp = NULL;
133 
134 	return 0;
135 }
136 
137