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