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