1 /* 2 * Copyright (c) 2007-2009, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT license. 4 * 5 * Author: 6 * Łukasz 'Sil2100' Zemczak <sil2100@vexillium.org> 7 */ 8 9 10 #include "PackageWindow.h" 11 12 #include <Alert.h> 13 #include <Application.h> 14 #include <Autolock.h> 15 #include <Catalog.h> 16 #include <Entry.h> 17 #include <FilePanel.h> 18 #include <List.h> 19 #include <Locale.h> 20 #include <TextView.h> 21 22 #include <stdio.h> 23 24 #undef B_TRANSLATE_CONTEXT 25 #define B_TRANSLATE_CONTEXT "Packageinstaller main" 26 27 class PackageInstaller : public BApplication { 28 public: 29 PackageInstaller(); 30 ~PackageInstaller(); 31 32 void RefsReceived(BMessage *msg); 33 void ArgvReceived(int32 argc, char **argv); 34 void ReadyToRun(); 35 36 void MessageReceived(BMessage *msg); 37 38 void AboutRequested(); 39 40 private: 41 BFilePanel *fOpen; 42 uint32 fWindowCount; 43 }; 44 45 46 PackageInstaller::PackageInstaller() 47 : BApplication("application/x-vnd.Haiku-PackageInstaller"), 48 fOpen(NULL), 49 fWindowCount(0) 50 { 51 fOpen = new BFilePanel(B_OPEN_PANEL); 52 } 53 54 55 PackageInstaller::~PackageInstaller() 56 { 57 } 58 59 60 void 61 PackageInstaller::ReadyToRun() 62 { 63 // We're ready to run - if no windows are yet visible, this means that 64 // we should show a open panel 65 if (fWindowCount == 0) { 66 fOpen->Show(); 67 } 68 } 69 70 71 void 72 PackageInstaller::RefsReceived(BMessage *msg) 73 { 74 uint32 type; 75 int32 i, count; 76 status_t ret = msg->GetInfo("refs", &type, &count); 77 if (ret != B_OK || type != B_REF_TYPE) 78 return; 79 80 entry_ref ref; 81 PackageWindow *iter; 82 for (i = 0; i < count; i++) { 83 if (msg->FindRef("refs", i, &ref) == B_OK) { 84 iter = new PackageWindow(&ref); 85 fWindowCount++; 86 iter->Show(); 87 } 88 } 89 } 90 91 92 void 93 PackageInstaller::ArgvReceived(int32 argc, char **argv) 94 { 95 int i; 96 BPath path; 97 entry_ref ref; 98 status_t ret = B_OK; 99 PackageWindow *iter = 0; 100 101 for (i = 1; i < argc; i++) { 102 if (path.SetTo(argv[i]) != B_OK) { 103 fprintf(stderr, 104 B_TRANSLATE("Error! \"%s\" is not a valid path.\n"), 105 argv[i]); 106 continue; 107 } 108 109 ret = get_ref_for_path(path.Path(), &ref); 110 if (ret != B_OK) { 111 fprintf(stderr, 112 B_TRANSLATE("Error (%s)! Could not open \"%s\".\n"), 113 strerror(ret), argv[i]); 114 continue; 115 } 116 117 iter = new PackageWindow(&ref); 118 fWindowCount++; 119 iter->Show(); 120 } 121 } 122 123 124 void 125 PackageInstaller::MessageReceived(BMessage *msg) 126 { 127 switch (msg->what) { 128 case P_WINDOW_QUIT: 129 fWindowCount--; 130 case B_CANCEL: 131 if (fWindowCount == 0) { 132 BAutolock lock(this); 133 if (lock.IsLocked()) 134 Quit(); 135 } 136 break; 137 default: 138 BApplication::MessageReceived(msg); 139 } 140 } 141 142 143 void 144 PackageInstaller::AboutRequested() 145 { 146 BAlert *about = new BAlert("about", 147 B_TRANSLATE("PackageInstaller\n" 148 "BeOS legacy .pkg file installer for Haiku.\n\n" 149 "Copyright 2007,\nŁukasz 'Sil2100' Zemczak\n\n" 150 "Copyright (c) 2007 Haiku, Inc. \n"), 151 B_TRANSLATE("OK")); 152 153 BTextView *view = about->TextView(); 154 BFont font; 155 view->SetStylable(true); 156 view->GetFont(&font); 157 font.SetFace(B_BOLD_FACE); 158 font.SetSize(font.Size() * 1.5); 159 view->SetFontAndColor(0, 17, &font); 160 161 about->Go(); 162 } 163 164 165 int 166 main(void) 167 { 168 PackageInstaller app; 169 app.Run(); 170 171 return 0; 172 } 173 174