1/*****************************************************************************/ 2// InspectorApp 3// Written by Michael Wilber, Haiku 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 Haiku 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_TRANSLATION_CONTEXT 44#define B_TRANSLATION_CONTEXT "InspectorApp" 45 46 47InspectorApp::InspectorApp() 48 : BApplication(APP_SIG) 49{ 50 fpActivesWin = NULL; 51 fpInfoWin = NULL; 52 53 AddToTranslatorsList("/system/add-ons/Translators", 54 SYSTEM_TRANSLATOR); 55 AddToTranslatorsList( 56 "/boot/home/config/add-ons/Translators", 57 USER_TRANSLATOR); 58 59 // Show application window 60 BRect rect(100, 100, 500, 400); 61 ImageWindow *pwin = new ImageWindow(rect, IMAGEWINDOW_TITLE); 62 pwin->Show(); 63} 64 65void 66InspectorApp::AddToTranslatorsList(const char *folder, int32 group) 67{ 68 BDirectory dir; 69 if (dir.SetTo(folder) == B_OK) { 70 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)); 77 } 78 } 79} 80 81void 82InspectorApp::MessageReceived(BMessage *pmsg) 83{ 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; 95 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; 113 114 default: 115 BApplication::MessageReceived(pmsg); 116 break; 117 } 118} 119 120void 121InspectorApp::RefsReceived(BMessage *pmsg) 122{ 123 pmsg->what = M_OPEN_FILE_PANEL; 124 BWindow *pwin = WindowAt(0); 125 if (pwin) 126 pwin->PostMessage(pmsg); 127} 128 129BList * 130InspectorApp::GetTranslatorsList() 131{ 132 return &flstTranslators; 133} 134 135int main(int argc, char **argv) 136{ 137 InspectorApp *papp = new InspectorApp(); 138 139 papp->Run(); 140 141 delete papp; 142 papp = NULL; 143 144 return 0; 145} 146 147