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 AddToTranslatorsList("/system/add-ons/Translators", 54 SYSTEM_TRANSLATOR); 55 AddToTranslatorsList("/boot/home/config/add-ons/Translators", 56 USER_TRANSLATOR); 57 58 // Show application window 59 BRect rect(100, 100, 500, 400); 60 ImageWindow *pwin = new ImageWindow(rect, IMAGEWINDOW_TITLE); 61 pwin->Show(); 62 } 63 64 void 65 InspectorApp::AddToTranslatorsList(const char *folder, int32 group) 66 { 67 BDirectory dir; 68 if (dir.SetTo(folder) == B_OK) { 69 70 BEntry ent; 71 while (dir.GetNextEntry(&ent) == B_OK) { 72 BPath path; 73 if (ent.GetPath(&path) == B_OK) 74 flstTranslators.AddItem( 75 new BTranslatorItem(path.Leaf(), path.Path(), group)); 76 } 77 } 78 } 79 80 void 81 InspectorApp::MessageReceived(BMessage *pmsg) 82 { 83 switch (pmsg->what) { 84 case M_ACTIVE_TRANSLATORS_WINDOW: 85 if (!fpActivesWin) 86 fpActivesWin = new ActiveTranslatorsWindow( 87 BRect(625, 350, 800, 600), 88 B_TRANSLATE("Active Translators"), 89 GetTranslatorsList()); 90 break; 91 case M_ACTIVE_TRANSLATORS_WINDOW_QUIT: 92 fpActivesWin = NULL; 93 break; 94 95 case M_INFO_WINDOW: 96 if (!fpInfoWin) 97 fpInfoWin = new InfoWindow(BRect(625, 50, 800, 300), 98 B_TRANSLATE_COMMENT("Info Win", 99 "This is a quite narrow info window and title 'Info Win' " 100 "is therefore shortened."), fbstrInfo.String()); 101 break; 102 case M_INFO_WINDOW_QUIT: 103 fpInfoWin = NULL; 104 break; 105 case M_INFO_WINDOW_TEXT: 106 // If image view is telling me to 107 // update the info window... 108 pmsg->FindString("text", &fbstrInfo); 109 if (fpInfoWin) 110 fpInfoWin->PostMessage(pmsg); 111 break; 112 113 default: 114 BApplication::MessageReceived(pmsg); 115 break; 116 } 117 } 118 119 void 120 InspectorApp::RefsReceived(BMessage *pmsg) 121 { 122 pmsg->what = M_OPEN_FILE_PANEL; 123 BWindow *pwin = WindowAt(0); 124 if (pwin) 125 pwin->PostMessage(pmsg); 126 } 127 128 BList * 129 InspectorApp::GetTranslatorsList() 130 { 131 return &flstTranslators; 132 } 133 134 int main(int argc, char **argv) 135 { 136 InspectorApp *papp = new InspectorApp(); 137 138 papp->Run(); 139 140 delete papp; 141 papp = NULL; 142 143 return 0; 144 } 145 146