Fix FreeBSD build.
[haiku.git] / src / tools / translation / inspector / InspectorApp.cpp
blob35e9c83140b87035057701fb9d2d2bf696278c14
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.
12 // Copyright (c) 2003 OpenBeOS Project
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:
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
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 /*****************************************************************************/
33 #include "Constants.h"
34 #include "InspectorApp.h"
35 #include "ImageWindow.h"
36 #include "TranslatorItem.h"
38 #include <Directory.h>
39 #include <Message.h>
40 #include <String.h>
41 #include <Window.h>
43 #undef B_TRANSLATION_CONTEXT
44 #define B_TRANSLATION_CONTEXT "InspectorApp"
47 InspectorApp::InspectorApp()
48 : BApplication(APP_SIG)
50 fpActivesWin = NULL;
51 fpInfoWin = NULL;
53 AddToTranslatorsList("/system/add-ons/Translators",
54 SYSTEM_TRANSLATOR);
55 AddToTranslatorsList(
56 "/boot/home/config/add-ons/Translators",
57 USER_TRANSLATOR);
59 // Show application window
60 BRect rect(100, 100, 500, 400);
61 ImageWindow *pwin = new ImageWindow(rect, IMAGEWINDOW_TITLE);
62 pwin->Show();
65 void
66 InspectorApp::AddToTranslatorsList(const char *folder, int32 group)
68 BDirectory dir;
69 if (dir.SetTo(folder) == B_OK) {
71 BEntry ent;
72 while (dir.GetNextEntry(&ent) == B_OK) {
73 BPath path;
74 if (ent.GetPath(&path) == B_OK)
75 flstTranslators.AddItem(
76 new BTranslatorItem(path.Leaf(), path.Path(), group));
81 void
82 InspectorApp::MessageReceived(BMessage *pmsg)
84 switch (pmsg->what) {
85 case M_ACTIVE_TRANSLATORS_WINDOW:
86 if (!fpActivesWin)
87 fpActivesWin = new ActiveTranslatorsWindow(
88 BRect(625, 350, 800, 600),
89 B_TRANSLATE("Active Translators"),
90 GetTranslatorsList());
91 break;
92 case M_ACTIVE_TRANSLATORS_WINDOW_QUIT:
93 fpActivesWin = NULL;
94 break;
96 case M_INFO_WINDOW:
97 if (!fpInfoWin)
98 fpInfoWin = new InfoWindow(BRect(625, 50, 800, 300),
99 B_TRANSLATE_COMMENT("Info Win",
100 "This is a quite narrow info window and title 'Info Win' "
101 "is therefore shortened."), fbstrInfo.String());
102 break;
103 case M_INFO_WINDOW_QUIT:
104 fpInfoWin = NULL;
105 break;
106 case M_INFO_WINDOW_TEXT:
107 // If image view is telling me to
108 // update the info window...
109 pmsg->FindString("text", &fbstrInfo);
110 if (fpInfoWin)
111 fpInfoWin->PostMessage(pmsg);
112 break;
114 default:
115 BApplication::MessageReceived(pmsg);
116 break;
120 void
121 InspectorApp::RefsReceived(BMessage *pmsg)
123 pmsg->what = M_OPEN_FILE_PANEL;
124 BWindow *pwin = WindowAt(0);
125 if (pwin)
126 pwin->PostMessage(pmsg);
129 BList *
130 InspectorApp::GetTranslatorsList()
132 return &flstTranslators;
135 int main(int argc, char **argv)
137 InspectorApp *papp = new InspectorApp();
139 papp->Run();
141 delete papp;
142 papp = NULL;
144 return 0;