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 #include "main.h" 10 11 #include "PackageWindow.h" 12 #include "UninstallWindow.h" 13 14 #include <Alert.h> 15 #include <Application.h> 16 #include <Autolock.h> 17 #include <Catalog.h> 18 #include <Entry.h> 19 #include <List.h> 20 #include <Locale.h> 21 #include <Path.h> 22 #include <TextView.h> 23 24 #include <stdio.h> 25 26 27 #undef B_TRANSLATION_CONTEXT 28 #define B_TRANSLATION_CONTEXT "Packageinstaller main" 29 30 31 bool gVerbose = false; 32 33 34 PackageInstaller::PackageInstaller() 35 : 36 BApplication("application/x-vnd.Haiku-PackageInstaller"), 37 fWindowCount(0) 38 { 39 } 40 41 42 PackageInstaller::~PackageInstaller() 43 { 44 } 45 46 47 void 48 PackageInstaller::ReadyToRun() 49 { 50 // We're ready to run - if no windows are yet visible, this means that 51 // we should show the UninstallWindow 52 if (fWindowCount == 0) { 53 (new UninstallWindow)->Show(); 54 fWindowCount++; 55 } 56 } 57 58 59 void 60 PackageInstaller::RefsReceived(BMessage* message) 61 { 62 entry_ref ref; 63 for (int32 i = 0; message->FindRef("refs", i, &ref) == B_OK; i++) 64 _NewWindow(&ref); 65 } 66 67 68 void 69 PackageInstaller::ArgvReceived(int32 argc, char** argv) 70 { 71 for (int i = 1; i < argc; i++) { 72 if (strcmp("--verbose", argv[i]) == 0 || strcmp("-v", argv[i]) == 0) { 73 gVerbose = true; 74 continue; 75 } 76 77 BPath path; 78 if (path.SetTo(argv[i]) != B_OK) { 79 fprintf(stderr, B_TRANSLATE("Error! \"%s\" is not a valid path.\n"), 80 argv[i]); 81 continue; 82 } 83 84 entry_ref ref; 85 status_t ret = get_ref_for_path(path.Path(), &ref); 86 if (ret != B_OK) { 87 fprintf(stderr, B_TRANSLATE("Error (%s)! Could not open \"%s\".\n"), 88 strerror(ret), argv[i]); 89 continue; 90 } 91 92 _NewWindow(&ref); 93 } 94 } 95 96 97 void 98 PackageInstaller::MessageReceived(BMessage* message) 99 { 100 switch (message->what) { 101 case P_WINDOW_QUIT: 102 fWindowCount--; 103 // fall through 104 case B_CANCEL: 105 if (fWindowCount == 0) 106 PostMessage(B_QUIT_REQUESTED); 107 break; 108 109 default: 110 BApplication::MessageReceived(message); 111 } 112 } 113 114 115 void 116 PackageInstaller::_NewWindow(const entry_ref* ref) 117 { 118 PackageWindow* window = new PackageWindow(ref); 119 window->Show(); 120 121 fWindowCount++; 122 } 123 124 125 int 126 main(void) 127 { 128 PackageInstaller app; 129 app.Run(); 130 131 return 0; 132 } 133 134